okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge tag 'v0.2.9' into f-041-maya-b8ea5361bf

main
3.7 KiB80 linesraw
1"""Two Intel Arc Pro B65 cards (device id 0xe222): the Terminal must see both and name both for a launch that names none (fake sysfs, no hardware)."""
2from __future__ import annotations
3
4import sys
5import tempfile
6import unittest
7from pathlib import Path
8
9ROOT = Path(__file__).resolve().parents[2]
10sys.path.insert(0, str(ROOT))
11
12from strata_cli.launch import catalog as C, runner as R, settings as S      # noqa: E402
13
14
15def fake_drm(root: Path, ids: list[str]) -> None:
16    for i, did in enumerate(ids):
17        dev = root / f"card{i}" / "device"
18        dev.mkdir(parents=True)
19        (dev / "vendor").write_text("0x8086\n")
20        (dev / "device").write_text(did + "\n")
21
22
23class IntelCards(unittest.TestCase):
24    def cards(self, ids):
25        with tempfile.TemporaryDirectory() as d:
26            fake_drm(Path(d), ids)
27            return C.intel_arc_cards(d)
28
29    def test_two_b65_are_two_cards_of_32_gb(self):
30        cards = self.cards(["0xe222", "0xe222"])
31        self.assertEqual([(c["index"], c["vram_gb"]) for c in cards], [(0, 32.0), (1, 32.0)])
32        self.assertTrue(all("B65" in c["name"] for c in cards))
33
34    def test_the_other_battlemage_ids_are_listed(self):
35        for did in ("0xe221", "0xe211", "0xe212", "0xe20b", "0xe223"):
36            self.assertEqual(len(self.cards([did])), 1, did)
37
38    def test_an_integrated_intel_gpu_is_never_a_card(self):
39        for did in ("0x46a6", "0x7d55", "0xa7a0", "0x9a49", "0x4680", "0x64a0"):
40            self.assertEqual(self.cards([did]), [], did)
41        self.assertEqual(len(self.cards(["0x7d55", "0xe222"])), 1)       # an iGPU beside a B65: one card
42
43    def test_both_tables_list_the_same_discrete_ids(self):
44        import ast
45        src = (ROOT / "sycl" / "setup_intel.py").read_text(encoding="utf-8")
46        node = next(n for n in ast.parse(src).body if isinstance(n, ast.Assign) and getattr(n.targets[0], "id", "") == "INTEL_ARC")
47        theirs = {"0x" + k: v[0].replace("Arc ", "") for k, v in ast.literal_eval(node.value).items()}
48        ours = {k: v[0].replace("Arc ", "") for k, v in C.INTEL_ARC.items()}
49        self.assertEqual(set(theirs), set(ours))
50        self.assertEqual({k: v.replace(" ", "") for k, v in theirs.items()}, {k: v.replace(" ", "") for k, v in ours.items()})
51
52    def test_mixed_sizes_get_roles_like_any_other_pair(self):
53        cards = self.cards(["0xe222", "0xe20b"])                         # 32 GB + 12 GB
54        hw = {"ram_gb": 128.0, "os": "Linux", "cpu": {"avx2": True}, "gpus": cards}
55        cat = C.Catalog(root=Path(tempfile.mkdtemp()), hardware=hw)
56        cat.installed_backend = lambda: "sycl"
57        got = R.cards_for_launch(S.LaunchSettings(family="qwen", model="IQ3_S"), cat, base={})
58        self.assertEqual(sorted(got), [0, 1])
59
60    def test_one_card_names_nothing(self):
61        hw = {"ram_gb": 128.0, "os": "Linux", "cpu": {"avx2": True}, "gpus": self.cards(["0xe222"])}
62        cat = C.Catalog(root=Path(tempfile.mkdtemp()), hardware=hw)
63        cat.installed_backend = lambda: "sycl"
64        self.assertIsNone(R.cards_for_launch(S.LaunchSettings(family="qwen", model="IQ3_S"), cat, base={}))
65
66    def test_a_launch_that_names_no_card_gets_both_b65(self):
67        hw = {"ram_gb": 128.0, "os": "Linux", "cpu": {"avx2": True}, "gpus": self.cards(["0xe222", "0xe222"])}
68        cat = C.Catalog(root=Path(tempfile.mkdtemp()), hardware=hw)
69        cat.installed_backend = lambda: "sycl"
70        s = S.LaunchSettings(family="qwen", model="IQ3_S")
71        got = R.cards_for_launch(s, cat, base={})
72        self.assertEqual(sorted(got), [0, 1])
73        cfg = {}
74        R.apply_cards(cfg, got)
75        self.assertEqual(sorted(cfg["gpu"]), [0, 1])
76        self.assertEqual(cfg["layer_split"], "auto")
77
78
79if __name__ == "__main__":
80    unittest.main()