okami.mom/strata

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

Niko1221Merge branch 'f-021-macvis' into f-021-intc23a78694

main
5.2 KiB100 linesraw
1"""Owner rule 2026-10-18: pictures are on by default wherever the model and the engine package can read them; the reader runs on the
2CPU under 24 GB of VRAM and on the GPU from 24 GB, on every make of card.  Checks setup.images_default and the shared rule.
3
4    python -m unittest tools.test_picture_defaults
5"""
6from __future__ import annotations
7
8import sys
9import unittest
10from pathlib import Path
11
12ROOT = Path(__file__).resolve().parents[1]
13sys.path.insert(0, str(ROOT))
14sys.path.insert(0, str(ROOT / "tools"))
15import setup  # noqa: E402
16from strata_control import vision_reader as VR  # noqa: E402
17
18
19class PictureDefaults(unittest.TestCase):
20    def test_unsloth_default_is_on_for_every_make_and_size(self):
21        models = [m for m, d in setup.MODELS.items() if d.get("budget") and d.get("vision") is not False]
22        self.assertTrue(models)
23        for m in models:
24            for gpu in ({"vram_gb": 10.0}, {"vram_gb": 12.0}, {"vram_gb": 16.0}, {"vram_gb": 32.0},
25                        {"vram_gb": 16.0, "arch": "gfx1201"}, {"vram_gb": 24.0, "arch": "gfx1100"}, {}):
26                for win in (False, True):
27                    old = setup.WIN
28                    setup.WIN = win
29                    try:
30                        self.assertTrue(setup.images_default(m, "unsloth", 64.0, gpu), (m, gpu, win))
31                        self.assertTrue(setup.images_default(m, "unsloth", 512.0, gpu), (m, gpu, win))
32                    finally:
33                        setup.WIN = old
34
35    def test_yes_means_pictures_on_for_qwen_swift_and_coder(self):
36        """setup --yes (and Enter at the question) on the original Flash-Next, Swift and Coder files: pictures on, the reader by the 24 GB rule,
37        and no VRAM reserve for the CPU reader."""
38        from test_setup_golden import PROFILES, install
39        for key, gpu in (("64GB-1x32GB", True), ("96GB-1x16GB", False)):          # 31.8 GB: the GPU reader; 15.9 GB: the CPU reader
40            ram, found = PROFILES[key]
41            for fam, model in (("qwen", "Q2_0"), ("swift", "IQ3_S"), ("coder", "IQ1_M")):
42                for answers in (None, ""):
43                    code, out, cfg, _ = install(ram, found, ["--family", fam, "--model", model, "--no-start"], answers=answers)
44                    where = (key, fam, model, answers)
45                    self.assertEqual(code, 0, (where, out[-1500:]))
46                    self.assertIn("--vision", cfg["args"], where)
47                    self.assertEqual(cfg["vision"]["gpu"], gpu, where)
48                    self.assertEqual("--vram-reserve-mib" in cfg["args"], gpu, where)       # only the GPU reader keeps VRAM free
49                    self.assertIn("images: on", out, where)
50
51    def test_pictures_off_stays_available(self):
52        from test_setup_golden import PROFILES, install
53        ram, found = PROFILES["64GB-1x32GB"]
54        for fam, model in (("qwen", "Q2_0"), ("swift", "IQ3_S"), ("coder", "IQ1_M")):
55            code, out, cfg, _ = install(ram, found, ["--family", fam, "--model", model, "--no-start", "--vision", "no"])
56            self.assertEqual(code, 0, out[-1500:])
57            self.assertNotIn("--vision", cfg["args"])
58            self.assertNotIn("vision", cfg)
59
60    def test_the_cpu_reader_takes_no_vram_reserve(self):
61        """So a card of 8 GB is no exception: the reserve is only for the GPU reader."""
62        self.assertEqual(setup.VISION["cpu"]["reserve_mib"], 0)
63        self.assertEqual(setup.VISION["gpu"]["reserve_mib"], 700)
64
65    def test_one_rule_for_the_reader(self):
66        self.assertEqual(setup.IMAGES_GPU_ENCODER_MIN_VRAM_GB, VR.GPU_MIN_VRAM_GB)
67        for vram, want in ((8, "cpu"), (16, "cpu"), (23.0, "cpu"), (24, "gpu"), (32, "gpu"), (None, "gpu")):
68            self.assertEqual(VR.default_mode(vram), want)
69            self.assertEqual(VR.wanted("yes", vram), want)
70            self.assertEqual(setup.hip_vision("yes", vram or 0.0), want if vram else "gpu")
71        self.assertEqual(setup.hip_vision(None, 16.0), "cpu")
72        self.assertEqual(setup.hip_vision("gpu", 16.0), "gpu")
73
74class MacPictureDefaults(unittest.TestCase):
75    """setup.py on a Mac: pictures on by default, on the Metal reader (strata_control/vision_reader.py)."""
76
77    def test_nothing_asked_means_the_gpu_reader_for_every_mac_size(self):
78        from strata_control import mac_fit as MF
79        for model in MF.MAC_MODELS:
80            for ram in (32.0, 64.0, 128.0):
81                self.assertEqual(setup.mac_vision(None, model, ram), "gpu", (model, ram))
82                self.assertEqual(setup.mac_vision("yes", model, ram), "gpu", (model, ram))
83
84    def test_off_and_cpu_are_kept_as_asked(self):
85        for off in ("no", "none", "off"):
86            self.assertEqual(setup.mac_vision(off, "Q2_0", 32.0), "none")
87        self.assertEqual(setup.mac_vision("cpu", "Q2_0", 32.0), "cpu")
88
89    def test_a_folder_without_the_reader_turns_pictures_off(self):
90        import tempfile
91        d = Path(tempfile.mkdtemp(prefix="macvis-"))
92        (d / "strata").write_bytes(b"x")
93        self.assertEqual(setup.mac_reader(d, "gpu").mode, "none")
94        (d / "strata-vision").write_bytes(b"x")
95        r = setup.mac_reader(d, "gpu")
96        self.assertEqual((r.mode, r.exe.name), ("gpu", "strata-vision"))
97
98
99if __name__ == "__main__":
100    unittest.main()