okami.mom/strata

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

Niko1221Merge f-1441-perf (Responses/Codex honours reasoning_effort; setup keeps the installed size on a re-run) into f-1441296b59d2f

main
5.3 KiB104 linesraw
1"""0.1.44.1: setup run again over an installed model keeps its size.
2
30.1.44 made IQ3_S the recommended Qwen size on a PC with 64 GB or more (IQ3_S: about 15% slower decode than IQ3_XXS on an
4RTX 5070, docs/MODELS.md, and about 7 GB more RAM).  A first install takes the recommendation; SETUP.bat / --setup on a
5folder that already has a model pre-selects the installed size (and `--yes` takes it), so Enter never moves a working
6install to a slower size.  The recommended size stays marked, every size stays a choice.
7
8    python -m unittest tools.test_setup_rerun_size
9"""
10from __future__ import annotations
11
12import sys
13import unittest
14from pathlib import Path
15
16ROOT = Path(__file__).resolve().parents[1]
17sys.path.insert(0, str(ROOT))
18sys.path.insert(0, str(ROOT / "tools"))
19import setup  # noqa: E402
20import test_setup_golden as g  # noqa: E402
21
22PC64 = (63.7, [g.card(0, "NVIDIA GeForce RTX 5070", 11.9, "120")])
23
24
25def earlier(model: str, family_tag: str = "") -> tuple:
26    tag = f"{family_tag}{model.lower()}"
27    return (f"strata-{tag}.json", {"exe": "x", "args": ["--pack", f"p/{tag}", "--max-context", "32768"], "cwd": ".",
28                                   "tokenizer": "t", "model_name": f"qwen3.8-flash-next-{tag}", "log": "l", "port": 8080})
29
30
31class RerunKeepsSize(unittest.TestCase):
32    def run_setup(self, argv, configs, answers=""):
33        ram, found = PC64
34        code, out, cfg, asked = g.install(ram, found, argv, answers=answers, configs=configs)
35        self.assertEqual(code, 0, out[-2000:])
36        return out, cfg, asked
37
38    def test_first_install_takes_the_recommendation(self):
39        out, cfg, _ = self.run_setup(["--family", "qwen", "--no-start"], [])
40        self.assertEqual(cfg["model_name"], "qwen3.8-flash-next-iq3_s")
41        self.assertNotIn("(installed)", out)
42
43    def test_enter_over_an_installed_iq3_xxs_keeps_it(self):
44        out, cfg, asked = self.run_setup(["--family", "qwen", "--setup", "--no-start"], [earlier("IQ3_XXS")])
45        self.assertEqual(cfg["model_name"], "qwen3.8-flash-next-iq3_xxs", out[-1500:])
46        line_s = next(x for x in out.splitlines() if " IQ3_S " in x or " IQ3_S\t" in x or "IQ3_S    " in x)
47        self.assertIn("(recommended)", line_s)            # still marked, still a choice
48        line_xxs = next(x for x in out.splitlines() if "IQ3_XXS" in x and "download" in x)
49        self.assertIn("(installed)", line_xxs)
50        self.assertTrue(any("Which size?" in a for a in asked))
51
52    def test_yes_over_an_installed_size_keeps_it_too(self):
53        _, cfg, asked = self.run_setup(["--family", "qwen", "--setup", "--no-start"], [earlier("Q2_0")], answers=None)
54        self.assertEqual(cfg["model_name"], "qwen3.8-flash-next-q2_0")
55        self.assertEqual(asked, [])
56
57    def test_a_named_size_still_wins(self):
58        _, cfg, _ = self.run_setup(["--family", "qwen", "--model", "IQ3_S", "--setup", "--no-start"], [earlier("IQ3_XXS")])
59        self.assertEqual(cfg["model_name"], "qwen3.8-flash-next-iq3_s")
60
61    def test_another_family_is_not_touched(self):
62        # a Qwen IQ3_XXS install does not pre-select anything for the Unsloth family
63        _, cfg, _ = self.run_setup(["--family", "unsloth", "--setup", "--no-start"], [earlier("IQ3_XXS")])
64        self.assertIn("unsloth", cfg["model_name"])
65
66    def test_the_helper_prefers_the_most_recent_config_of_the_family(self):
67        import json
68        import tempfile
69        with tempfile.TemporaryDirectory() as tmp:
70            t = Path(tmp)
71            paths = []
72            for name, cfg in (earlier("IQ3_S"), earlier("Q2_0")):
73                p = t / name
74                p.write_text(json.dumps(cfg))
75                paths.append(p)
76            names = [m for m in setup.MODELS if "qwen" in setup.MODELS[m].get("families", ("qwen", "swift"))]
77            self.assertEqual(setup.installed_size("qwen", names, paths), "IQ3_S")       # first = most recently used
78            self.assertEqual(setup.installed_size("qwen", names, paths[1:]), "Q2_0")
79            self.assertIsNone(setup.installed_size("qwen", names, []))
80
81
82class RerunKeepsOwnEnv(unittest.TestCase):
83    """0.1.44 put STRATA_MMQ_KQ / STRATA_HC_Q8 / STRATA_ROUTE_TAIL_SKIP into SETUP_ENV (the entries setup writes, which a
84    setup run again does not carry over): a GSQ-RCO config of the user's own STRATA_ROUTE_TAIL_SKIP=0 was dropped with them.
85    Those three are setup's only in an Unsloth config."""
86
87    OLD = {"env": {"STRATA_ROUTE_TAIL_SKIP": "0", "STRATA_MMQ_KQ": "1", "STRATA_HC_Q8": "0", "STRATA_RESIDENT_PIN": "0",
88                   "MY_VAR": "1"}}
89
90    def test_a_gsq_rco_config_keeps_the_users_values(self):
91        new = {"model_name": "qwen3.8-flash-next-iq3_xxs"}
92        kept = setup.carry_over(dict(self.OLD), new)
93        self.assertEqual(new["env"], {"STRATA_ROUTE_TAIL_SKIP": "0", "STRATA_MMQ_KQ": "1", "STRATA_HC_Q8": "0", "MY_VAR": "1"})
94        self.assertIn("env STRATA_ROUTE_TAIL_SKIP", kept)
95        self.assertNotIn("env STRATA_RESIDENT_PIN", kept)             # the older entries stay setup's own
96
97    def test_an_unsloth_config_gets_setups_values_not_the_old_ones(self):
98        new = {"model_name": "qwen3.8-flash-next-unsloth-ud-q4_k_xl", "env": {"STRATA_HC_Q8": "1"}}
99        setup.carry_over(dict(self.OLD), new)
100        self.assertEqual(new["env"], {"STRATA_HC_Q8": "1", "MY_VAR": "1"})
101
102
103if __name__ == "__main__":
104    unittest.main()