okami.mom/strata

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

Niko1221Merge f-dl99-fixes: the Qwen3.6 first-run download (no engine-race stop, no cancelled engine download, progress to 100%, the picture reader's real figure, the engine-not-ready sentence)361c8d94a

main
14.1 KiB220 linesraw
1"""0.2.2: the words for a model download and its preparation are plain and true (strata_control/progress_words.py), and the app's
2and the Terminal's progress read the same lines the same way (tools/strata_mcp.py install_progress / combined_progress).
3
4The excerpts are from real setup logs (Gyro-S on the RTX 5070 PC, 2026-10-19) and from the steps a Q2_0 install adds."""
5
6from __future__ import annotations
7
8import sys
9import unittest
10from pathlib import Path
11
12ROOT = Path(__file__).resolve().parents[2]
13sys.path.insert(0, str(ROOT))
14sys.path.insert(0, str(ROOT / "tools"))
15
16import strata_mcp  # noqa: E402
17from strata_control import progress_words as W  # noqa: E402
18
19HEAD = ["Strata - Qwen3.8-Flash-Next on a normal PC", "=== Step 1: checking your PC ===", "  [ok] GPU: NVIDIA GeForce RTX 5070",
20        "=== Step 2: your choices ===", "  [ok] size: Gyro-S", "=== Step 3: Python packages ===", "  [ok] numpy ...",
21        "=== Step 4: the Strata engine ==="]
22STEP5 = ["=== Step 5: downloading Qwen3.8-Flash-Next (Gyro) Gyro-S ===",
23         "  The model files go in C:\\Users\\x\\Documents\\Strata\\models\\gyro-Gyro-S"]
24MODEL_PROGRESS = "  Qwen3.8-Flash-Next-Gyro-S-TQ1_0.gguf:  30.53 / 58.49 GB (52%)   "
25CHECK = "  checking Qwen3.8-Flash-Next-Gyro-S-TQ1_0.gguf (SHA-256, 58.5 GB) ..."
26STEP6 = ["=== Step 6: preparing the model for Strata ==="]
27
28
29def prog(lines):
30    p = strata_mcp.install_progress(lines)
31    return p, p.get("label"), p.get("phase")
32
33
34class StepWords(unittest.TestCase):
35    def test_checking_the_pc(self):
36        self.assertEqual(prog(HEAD[:3])[1:], ("Checking your computer", "check"))
37
38    def test_the_engine_and_the_helper_download_have_their_own_words(self):
39        self.assertEqual(prog(HEAD + ["  llama.cpp source:   0.01 / 0.04 GB (21%)   "])[2], "helpers")
40        self.assertIn("small tools", prog(HEAD + ["  llama.cpp source:   0.01 / 0.04 GB (21%)   "])[1])
41        self.assertEqual(prog(HEAD + ["  Strata engine:   0.20 / 0.90 GB (22%)   "])[1], "Downloading the engine for this PC")
42        self.assertEqual(prog(HEAD)[2], "engine")
43
44    def test_the_model_download(self):
45        _p, label, phase = prog(HEAD + STEP5 + [MODEL_PROGRESS])
46        self.assertEqual((label, phase), ("Downloading the model files", "download"))
47
48    def test_a_figure_from_an_earlier_step_does_not_leak_into_the_next(self):
49        """Step 4's 'llama.cpp source' line must not make step 5 'Downloading ...' before any model line is printed."""
50        p, label, phase = prog(HEAD + ["  llama.cpp source:   0.04 / 0.04 GB (100%)   "] + STEP5)
51        self.assertNotIn("download", p)
52        self.assertEqual(phase, "download")
53        self.assertEqual(label, "Getting the model files")
54
55    def test_the_hash_check_is_checking_not_downloading(self):
56        lines = HEAD + STEP5 + [MODEL_PROGRESS, "  [ok] downloaded", CHECK]
57        p, label, phase = prog(lines)
58        self.assertEqual(phase, "verify")
59        self.assertIn("Checking that the model files are complete", label)
60        self.assertNotIn("Downloading", label)
61        # with its own figure
62        p, label, phase = prog(lines + ["  checking Qwen3.8-Flash-Next-Gyro-S-TQ1_0.gguf:  12.00 / 58.49 GB (20%)   "])
63        self.assertEqual(phase, "verify")
64        self.assertEqual(p["download"]["percent"], 20)
65
66    def test_a_damaged_file_is_repaired_in_plain_words_and_the_second_check_is_checking(self):
67        damaged = "  Some parts of Qwen3.8-Flash-Next-Gyro-S-TQ1_0.gguf were damaged; downloading only those parts again."
68        lines = HEAD + STEP5 + [MODEL_PROGRESS, CHECK, damaged, "  Qwen3.8-Flash-Next-Gyro-S-TQ1_0.gguf:  12.00 / 58.49 GB (20%)   "]
69        _p, label, phase = prog(lines)
70        self.assertEqual(phase, "repair")
71        self.assertEqual(label, "Some parts of a model file were damaged; downloading only those parts again")
72        done = lines + ["  2 of 1186 parts were different and have been written again; checking the whole file again ..."]
73        self.assertEqual(prog(done)[2], "download")
74
75    def test_the_picture_reader(self):
76        lines = HEAD + STEP5 + ["  [ok] model files present", "  vision encoder:   0.30 / 0.91 GB (33%)   "]
77        self.assertEqual(prog(lines)[1:], ("Downloading the picture reader", "pictures"))
78
79    def test_files_already_there(self):
80        lines = HEAD + STEP5 + ["  [ok] Qwen3.8-Flash-Next-Q2_0-00001-of-00002.gguf already downloaded"]
81        self.assertEqual(prog(lines)[2], "verify")
82
83    def test_step_six_packing_the_experts(self):
84        lines = HEAD + STEP5 + STEP6 + ["  Converting the Q2_0 experts for the AVX-512 kernel (one time, ~40 GB written, 2-5 min) ...",
85                                        "  > python tools/strata_pack.py build --gguf x --out y --skip-hash --force"]
86        self.assertEqual(prog(lines)[1:], ("Packing the model's experts for your processor (one time, a few minutes)", "pack"))
87        self.assertEqual(prog(lines + ["  > python tools/pack_index.py --pack y"])[1], "Indexing the packed experts")
88        self.assertEqual(prog(lines + ["  > python tools/strata_tokenizer.py --gguf x --out y"])[1], "Preparing the tokenizer")
89
90    def test_step_six_the_draft_layer_download_then_its_preparation(self):
91        fetch = ["  [ok] model prepared: y", "  The MTP draft layer (speculative decoding, ~2x faster output) comes from the original Qwen checkpoint:",
92                 "  only its ~5 GB of MTP tensors are downloaded.", "  > python tools/mtp_fetch.py fetch --out z",
93                 "  MTP draft layer:   1.65 / 5.21 GB (31%)"]
94        p, label, phase = prog(HEAD + STEP5 + STEP6 + fetch)
95        self.assertEqual(phase, "draft_download")
96        self.assertIn("Downloading the draft layer", label)
97        # the download is over: the numbers it printed are stale, the next tool is running
98        p, label, phase = prog(HEAD + STEP5 + STEP6 + fetch + ["  MTP draft layer:   5.21 / 5.21 GB (100%)", "  > python tools/mtp_pack.py --src z"])
99        self.assertEqual((label, phase), ("Preparing the draft layer", "draft"))
100        p, label, phase = prog(HEAD + STEP5 + STEP6 + fetch + ["  > python tools/mtp_rt.py --gguf g --out rt"])
101        self.assertEqual(phase, "draft")
102
103    def test_step_six_without_a_draft_layer_step_is_not_the_draft_layer(self):
104        # 0.2.14 (l620 offline / Off / Auto, Boston): every launch showed "Preparing the draft layer" after "[ok] model prepared", with no draft layer touched
105        for after in ([], ["  [ok] the draft layer (MTP) is off: its ~5 GB are not downloaded (`--mtp on` fetches it later)"],
106                      ["  [ok] DFlash2 is the drafter: the MTP draft layer's ~5 GB are not downloaded (choosing the MTP later fetches it once)"]):
107            with self.subTest(after=after):
108                p, label, phase = prog(HEAD + STEP5 + STEP6 + ["  [ok] model prepared: y", *after])
109                self.assertEqual((label, phase), ("The model files are on this computer; checking them", "verify"))
110
111    def test_step_six_claims_preparation_only_while_it_runs(self):
112        # 0.2.14.1 check (M5 Max): "Preparing your model for Strata (one time)" on every launch, also a 4-5 s restart with the model prepared
113        self.assertEqual(prog(HEAD + STEP5 + STEP6)[1:], ("The model files are on this computer; checking them", "verify"))
114        self.assertEqual(prog(HEAD + STEP5 + STEP6 + ["  > python tools/iq_pack.py --gguf x --out y"])[1:],
115                         ("Preparing the model data for the engine (one time)", "pack"))
116        self.assertEqual(prog(HEAD + STEP5 + STEP6 + ["  > python tools/strata_pack.py --gguf x --out y"])[2], "pack")
117
118    def test_step_six_with_everything_already_there(self):
119        lines = HEAD + STEP5 + STEP6 + ["  [ok] model prepared: y", "  [ok] MTP draft layer: z"]
120        self.assertEqual(prog(lines)[2], "draft")
121
122    def test_low_memory_mode_packing(self):
123        lines = HEAD + STEP5 + STEP6 + ["  Writing the experts into one file for the low-memory mode (one time, 80 GB) ...",
124                                        "  > python tools/iq_pack.py --gguf x --out y --experts-bin"]
125        self.assertEqual(prog(lines)[1], "Packing the experts into one file for low-memory mode (one time)")
126
127    def test_the_last_step(self):
128        lines = HEAD + STEP5 + STEP6 + ["=== Step 7: writing the start script ===", "  [ok] KV streaming on"]
129        self.assertEqual(prog(lines)[1:], ("Saving the model's settings", "settings"))
130
131    def test_the_heading_is_found_even_after_hundreds_of_tool_lines(self):
132        lines = HEAD + STEP5 + STEP6 + ["  > python tools/iq_pack.py --gguf x --out y"] + [f"  layer {i}/40" for i in range(900)]
133        self.assertEqual(prog(lines)[2], "pack")
134
135    def test_no_step_yet(self):
136        self.assertEqual(prog(["Strata - Qwen3.8-Flash-Next"])[1:], ("Getting your model ready", "working"))
137
138    def test_with_numbers(self):
139        w = W.describe(5, STEP5, {"file": "x.gguf", "done_gb": 12.34, "total_gb": 58.49, "percent": 21})
140        self.assertEqual(W.with_numbers(w, {"done_gb": 12.34, "total_gb": 58.49}), "Downloading the model files: 12.3 of 58.5 GB")
141        self.assertEqual(W.with_numbers(w, None), "Downloading the model files")
142
143
144class CombinedFigure(unittest.TestCase):
145    def test_a_part_file_the_pieces_filled_ahead_is_not_a_finished_download(self):
146        """The parallel download writes the last pieces early, so the .part is full length while the pieces done are 50%: the log's
147        figure is the truth (the bar used to jump to 99%)."""
148        import tempfile
149        with tempfile.TemporaryDirectory() as tmp:
150            folder = Path(tmp)
151            part = folder / "m-00001-of-00002.gguf.part"
152            part.write_bytes(b"\0" * 1000)
153            files = [{"path": str(folder / "m-00001-of-00002.gguf"), "bytes": 1_000_000_000, "role": "model"}]
154            prog_ = {"step": "5/7: downloading X", "download": {"file": "m-00001-of-00002.gguf", "done_gb": 0.5, "total_gb": 1.0, "percent": 50}}
155            # the .part says 1000 bytes here; make it say 1 GB without writing it
156            import os
157            with open(part, "r+b") as f:
158                f.truncate(1_000_000_000)
159            out = strata_mcp.files_progress(prog_, {"total_gb": 1.0}, files)
160            self.assertAlmostEqual(out["download"]["done_gb"], 0.5, places=2)
161            self.assertEqual(out["download"]["percent"], 50)
162
163    def test_the_hash_check_has_its_own_figure(self):
164        lines = HEAD + STEP5 + [CHECK, "  checking Qwen3.8-Flash-Next-Gyro-S-TQ1_0.gguf:  12.00 / 58.49 GB (20%)   "]
165        p = strata_mcp.install_progress(lines)
166        out = strata_mcp.combined_progress(p, {"folder": None, "total_gb": 58.5})
167        self.assertEqual(out["download"]["file"], "checking files")
168        self.assertEqual(out["download"]["percent"], 20)
169
170    @staticmethod
171    def _qwen36_files(folder: Path, reader_done: bool) -> list:
172        """A Qwen3.6 UD-Q4_K_XL install's files (sizes made sparse, nothing written): the model whole, the picture reader whole or as a .part
173        the parallel pieces have already pushed to its full length."""
174        model = folder / "Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf"
175        reader = folder / "mmproj-F16.gguf"
176        for path, size in ((model, 22_853_663_008), (reader if reader_done else reader.with_name(reader.name + ".part"), 899_283_584)):
177            with open(path, "wb") as f:
178                f.truncate(size)
179        return [{"path": str(model), "bytes": 22_853_663_008, "role": "model"},
180                {"path": str(reader), "bytes": 899_283_584, "role": "vision"}]
181
182    def test_the_picture_reader_counts_by_its_own_figure(self):
183        """DL99: setup names the picture reader "vision encoder" in its progress line, not by its file name, so its .part (filled ahead by
184        the parallel pieces) was counted whole: the bar said 99% while 16-48% of it had arrived (Boston, 2026-11-15)."""
185        import tempfile
186        with tempfile.TemporaryDirectory() as tmp:
187            files = self._qwen36_files(Path(tmp), reader_done=False)
188            prog_ = {"step": "5/7: downloading Qwen3.6-35B-A3B UD-Q4_K_XL",
189                     "download": {"file": "vision encoder", "done_gb": 0.43, "total_gb": 0.9, "percent": 48}}
190            out = strata_mcp.files_progress(prog_, {"total_gb": 22.9}, files)
191            reader = next(p for p in out["parts"] if p["kind"] == "vision")
192            self.assertAlmostEqual(reader["done_gb"], 0.43, places=2)
193            self.assertEqual(reader["state"], "downloading")
194            self.assertLess(out["download"]["percent"], 99)
195
196    def test_after_the_download_every_file_stays_counted_and_the_figure_is_whole(self):
197        """DL99: from step 6 on the parts were dropped, so the app counted the engine's part alone ("99% · 0.7 / 0.7 GB"). Every file is in:
198        the parts stay, all done (the app's bar is whole), and there is no download figure (setup prepares the files)."""
199        import tempfile
200        with tempfile.TemporaryDirectory() as tmp:
201            files = self._qwen36_files(Path(tmp), reader_done=True)
202            job = {"folder": tmp, "total_gb": 22.9, "files": files}
203            for lines in (HEAD + STEP5 + STEP6, HEAD + STEP5 + STEP6 + ["=== Step 7: writing the start script ==="]):
204                out = strata_mcp.combined_progress(strata_mcp.install_progress(lines), job)
205                self.assertEqual([(p["kind"], p["state"]) for p in out.get("parts", [])], [("model", "done"), ("vision", "done")])
206                self.assertAlmostEqual(sum(p["done_gb"] for p in out["parts"]), 23.753, places=2)
207                self.assertNotIn("download", out)
208            # the download step itself, every file in: 100
209            out = strata_mcp.combined_progress(strata_mcp.install_progress(HEAD + STEP5 + ["  [ok] vision encoder downloaded"]), job)
210            self.assertEqual(out["download"]["percent"], 100)
211            # while a file is still missing the figure stays below 100
212            Path(files[1]["path"]).rename(files[1]["path"] + ".part")
213            out = strata_mcp.combined_progress(strata_mcp.install_progress(HEAD + STEP5 + [MODEL_PROGRESS]), job)
214            self.assertLessEqual(out["download"]["percent"], 99)
215            # before the download step nothing is counted
216            self.assertNotIn("parts", strata_mcp.combined_progress(strata_mcp.install_progress(HEAD), job))
217
218
219if __name__ == "__main__":
220    unittest.main()