okami.mom/strata

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

Niko1221launch: a restart with no Drafting word keeps a saved "auto"d8278a0c0

main
4.6 KiB77 linesraw
1"""A restart with no Drafting word keeps the saved word (boxia d3d and l620 C2, 0.2.14.1: after `--drafting auto` and a restart with no word the launch's
2records said null where they said "auto"; the start still ran DFlash2, because null is Auto).  Nothing real is used (tests/snapshot/README.md).
3
4Proves on every machine and model set of the matrix: "auto" stays "auto" over two restarts with no word and the engine line does not change; a saved Off
5still holds (keep_saved_off); a choice the model's installed config holds (the app's Models screen) still decides a start with no word, so no "auto" is
6written over it; a first launch with no word still writes nothing (null = Auto, as before).
7
8  python -m pytest tests/snapshot/test_drafting_word_restart.py -q -p no:cacheprovider
9"""
10
11from __future__ import annotations
12
13import json
14import sys
15import unittest
16from pathlib import Path
17
18ROOT = Path(__file__).resolve().parents[2]
19if str(ROOT) not in sys.path:
20    sys.path.insert(0, str(ROOT))
21
22from tests.snapshot.matrix import MACHINES, MODEL_SETS, machine as get_machine, model_set as get_set  # noqa: E402
23from tests.snapshot.test_drafting_round_trip import argv, drafter, launches  # noqa: E402
24
25
26class AutoStaysAuto(unittest.TestCase):
27    maxDiff = None
28
29    def test_a_restart_without_a_word_keeps_auto(self):
30        for m in MACHINES:
31            for s in MODEL_SETS:
32                with self.subTest(machine=m.key, set=s.key):
33                    recs = launches(m, s, [("auto", False), (None, False), (None, False)])
34                    for later in recs[1:]:
35                        self.assertEqual(later["config_file"].get("drafting"), "auto", "the saved word stays as it was")
36                        self.assertEqual(drafter(later), drafter(recs[0]), "the same drafter as with the word")
37                    # (the first Auto start can fetch the drafter's pack; the restarts after it start alike)
38                    self.assertEqual(argv(recs[2]), argv(recs[1]), "the restarts start alike")
39                    same = launches(m, s, [("auto", False), ("auto", False)])
40                    self.assertEqual(argv(recs[1]), argv(same[1]), "a restart with no word starts as one with --drafting auto")
41
42    def test_a_saved_off_still_holds(self):
43        for mkey, skey in (("nv_12gb_streaming", "iq3_s"), ("nv_resident", "iq3_s"), ("strix_halo_win", "ud_q4_k_xl")):
44            with self.subTest(machine=mkey, set=skey):
45                recs = launches(get_machine(mkey), get_set(skey), [("auto", False), ("off", False), (None, False)])
46                self.assertEqual(recs[2]["config_file"].get("drafting"), "off")
47                self.assertEqual(argv(recs[2]), argv(recs[1]))
48
49    def test_null_is_auto_where_the_word_is_read(self):
50        from strata_control import drafting
51        self.assertEqual(drafting.normalize(None), "auto")
52        self.assertEqual(drafting.DEFAULT_MODE, "auto")
53        for backend, archs in (("cuda", ["sm_120"]), ("hip", ["gfx1201"]), ("metal", []), ("sycl", ["arc_a"])):
54            self.assertEqual(drafting.choice_of(None, family="qwen", backend=backend, archs=archs),
55                             drafting.choice_of("auto", family="qwen", backend=backend, archs=archs), backend)
56        host = (ROOT / "apps" / "host" / "server" / "native-control.mjs").read_text(encoding="utf-8")
57        self.assertIn("drafting:cfg.drafting??'auto'", host, "the app reads a missing word as Auto")
58
59    def test_a_first_launch_without_a_word_writes_nothing(self):
60        recs = launches(get_machine("nv_resident"), get_set("iq3_s"), [(None, False), (None, False)])
61        for rec in recs:
62            self.assertIsNone(rec["config_file"].get("drafting"), "no word, nothing chosen: null is Auto")
63        self.assertEqual(argv(recs[1]), argv(recs[0]))
64
65    def test_the_models_screen_choice_still_decides_a_start_without_a_word(self):
66        # the app saves its Drafting choice in the model's installed config; a later `strata launch` with no word runs that choice, as before
67        def models_screen_says_mtp(world):
68            cfg = json.loads(world.config_path.read_text(encoding="utf-8"))
69            cfg["drafting"] = "mtp"
70            world.config_path.write_text(json.dumps(cfg, indent=1), encoding="utf-8")
71        recs = launches(get_machine("nv_resident"), get_set("iq3_s"), [("auto", False), (None, False)], prepare=models_screen_says_mtp)
72        self.assertEqual(recs[0]["config_file"].get("drafting"), "auto", "the word given wins over the installed choice")
73        self.assertEqual(recs[1]["config_file"].get("drafting"), "mtp", "no word: the installed config's own choice, not an auto written over it")
74
75
76if __name__ == "__main__":
77    unittest.main()