okami.mom/strata

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

Niko1221setup: the multi-GPU default follows the fit rule (largest card + RAM first, the split recommended only when the model does not fit one card), goldens re-recorded, setup tests1d8d830af

main
4.5 KiB98 linesraw
1"""0.1.39b (#578): setup recommends --remote-expert-opt for a config on two or more GPUs, never for one, and keeps it
2out when asked (setup's --no-remote-expert-opt, or "remote_expert_opt": false in the config).
3
4    python -m unittest tools.test_setup_remote_opt
5"""
6from __future__ import annotations
7
8import sys
9import unittest
10from pathlib import Path
11from unittest import mock
12
13ROOT = Path(__file__).resolve().parents[1]
14sys.path.insert(0, str(ROOT))
15sys.path.insert(0, str(ROOT / "tools"))
16import setup  # noqa: E402
17from test_setup_golden import PROFILES, install  # noqa: E402
18
19FLAG = "--remote-expert-opt"
20HELPER = ["--expert-cache-device1", "auto"]
21
22
23class Rule(unittest.TestCase):
24    def setUp(self):
25        p = mock.patch.object(setup, "ok", lambda *a: None)
26        p.start()
27        self.addCleanup(p.stop)
28
29    def test_two_gpus_get_it_once(self):
30        cfg = {"args": ["--spec", "4"] + HELPER, "gpu": [0, 1]}
31        setup.recommend_remote_expert_opt(cfg)
32        setup.recommend_remote_expert_opt(cfg)
33        self.assertEqual(cfg["args"], ["--spec", "4"] + HELPER + [FLAG])
34
35    def test_no_helper_cache_no_flag(self):
36        """#1447: on a plain layer split there is no helper cache for the flag to act on, so setup does not write it."""
37        cfg = {"args": ["--spec", "4"], "gpu": [0, 1]}
38        setup.recommend_remote_expert_opt(cfg)
39        self.assertEqual(cfg["args"], ["--spec", "4"])
40        kept = {"args": [FLAG], "gpu": [0, 1]}                # a flag already there is the user's: left alone
41        setup.recommend_remote_expert_opt(kept)
42        self.assertEqual(kept["args"], [FLAG])
43        eq = {"args": ["--expert-cache-device2=auto"], "gpu": [0, 1, 2]}
44        setup.recommend_remote_expert_opt(eq)
45        self.assertIn(FLAG, eq["args"])
46
47    def test_one_gpu_is_untouched(self):
48        for gpu in (None, 0, [0]):
49            cfg = {"args": ["--spec", "4"]} if gpu is None else {"args": ["--spec", "4"], "gpu": gpu}
50            setup.recommend_remote_expert_opt(cfg)
51            self.assertEqual(cfg["args"], ["--spec", "4"], gpu)
52
53    def test_overrides(self):
54        cfg = {"args": ["--spec", "4", FLAG], "gpu": [0, 1]}
55        setup.recommend_remote_expert_opt(cfg, off=True)
56        self.assertEqual(cfg["args"], ["--spec", "4"])
57        cfg = {"args": ["--spec", "4"] + HELPER, "gpu": [0, 1, 2], "remote_expert_opt": False}
58        setup.recommend_remote_expert_opt(cfg)
59        self.assertEqual(cfg["args"], ["--spec", "4"] + HELPER)
60
61    def test_pipeline_windows_wins(self):
62        """#1352: the two exclude each other (the engine drops the pipeline beside the helper caches), so setup
63        does not add the flag to a config that asks for the pipeline, and says so when both are there."""
64        cfg = {"args": ["--spec", "4", "--pipeline-windows", "2"] + HELPER, "gpu": [0, 1]}
65        setup.recommend_remote_expert_opt(cfg)
66        self.assertEqual(cfg["args"], ["--spec", "4", "--pipeline-windows", "2"] + HELPER)
67        both = {"args": [FLAG, "--pipeline-windows", "2"], "gpu": [0, 1]}
68        with mock.patch.object(setup, "warn") as w:
69            setup.recommend_remote_expert_opt(both)
70        self.assertEqual(both["args"], [FLAG, "--pipeline-windows", "2"])    # a recommendation, never forced
71        self.assertEqual(w.call_count, 1)
72        off = {"args": ["--pipeline-windows", "0"] + HELPER, "gpu": [0, 1]}   # 0: no pipeline asked for
73        setup.recommend_remote_expert_opt(off)
74        self.assertIn(FLAG, off["args"])
75
76    def test_the_users_key_is_kept_on_a_rerun(self):
77        self.assertNotIn("remote_expert_opt", setup.SETUP_KEYS)   # #629: carried over, so the opt-out survives
78
79
80class Install(unittest.TestCase):
81    def test_install_on_two_gpus(self):
82        """#1447: a plain two-GPU install has no helper cache, so no --remote-expert-opt is written."""
83        ram, found = PROFILES["47GB-2x16GB"]
84        args = ["--family", "qwen", "--no-start", "--model", "Q2_0", "--gpus", "0,1"]      # named: since the fit rule the default is the largest card + RAM
85        code, text, cfg, _ = install(ram, found, args)
86        self.assertEqual(code, 0, text)
87        self.assertIsInstance(cfg.get("gpu"), list)
88        self.assertNotIn(FLAG, cfg["args"])
89
90    def test_install_on_one_gpu(self):
91        ram, found = PROFILES["96GB-1x16GB"]
92        code, text, cfg, _ = install(ram, found, ["--family", "qwen", "--no-start", "--model", "Q2_0"])
93        self.assertEqual(code, 0, text)
94        self.assertNotIn(FLAG, cfg["args"])
95
96
97if __name__ == "__main__":
98    unittest.main()