okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
361c8d94a
main
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 ): 30p = strata_mcp .install_progress (lines ) 31return p ,p .get ("label" ),p .get ("phase" ) 32 33 34class StepWords (unittest .TestCase ): 35def test_checking_the_pc (self ): 36self .assertEqual (prog (HEAD [:3 ])[1 :], ("Checking your computer" ,"check" )) 37 38def test_the_engine_and_the_helper_download_have_their_own_words (self ): 39self .assertEqual (prog (HEAD + [" llama.cpp source: 0.01 / 0.04 GB (21%) " ])[2 ],"helpers" ) 40self .assertIn ("small tools" ,prog (HEAD + [" llama.cpp source: 0.01 / 0.04 GB (21%) " ])[1 ]) 41self .assertEqual (prog (HEAD + [" Strata engine: 0.20 / 0.90 GB (22%) " ])[1 ],"Downloading the engine for this PC" ) 42self .assertEqual (prog (HEAD )[2 ],"engine" ) 43 44def test_the_model_download (self ): 45_p ,label ,phase = prog (HEAD + STEP5 + [MODEL_PROGRESS ]) 46self .assertEqual ((label ,phase ), ("Downloading the model files" ,"download" )) 47 48def 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.""" 50p ,label ,phase = prog (HEAD + [" llama.cpp source: 0.04 / 0.04 GB (100%) " ]+ STEP5 ) 51self .assertNotIn ("download" ,p ) 52self .assertEqual (phase ,"download" ) 53self .assertEqual (label ,"Getting the model files" ) 54 55def test_the_hash_check_is_checking_not_downloading (self ): 56lines = HEAD + STEP5 + [MODEL_PROGRESS ," [ok] downloaded" ,CHECK ] 57p ,label ,phase = prog (lines ) 58self .assertEqual (phase ,"verify" ) 59self .assertIn ("Checking that the model files are complete" ,label ) 60self .assertNotIn ("Downloading" ,label ) 61# with its own figure 62p ,label ,phase = prog (lines + [" checking Qwen3.8-Flash-Next-Gyro-S-TQ1_0.gguf: 12.00 / 58.49 GB (20%) " ]) 63self .assertEqual (phase ,"verify" ) 64self .assertEqual (p ["download" ]["percent" ],20 ) 65 66def test_a_damaged_file_is_repaired_in_plain_words_and_the_second_check_is_checking (self ): 67damaged = " Some parts of Qwen3.8-Flash-Next-Gyro-S-TQ1_0.gguf were damaged; downloading only those parts again." 68lines = 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 ) 70self .assertEqual (phase ,"repair" ) 71self .assertEqual (label ,"Some parts of a model file were damaged; downloading only those parts again" ) 72done = lines + [" 2 of 1186 parts were different and have been written again; checking the whole file again ..." ] 73self .assertEqual (prog (done )[2 ],"download" ) 74 75def test_the_picture_reader (self ): 76lines = HEAD + STEP5 + [" [ok] model files present" ," vision encoder: 0.30 / 0.91 GB (33%) " ] 77self .assertEqual (prog (lines )[1 :], ("Downloading the picture reader" ,"pictures" )) 78 79def test_files_already_there (self ): 80lines = HEAD + STEP5 + [" [ok] Qwen3.8-Flash-Next-Q2_0-00001-of-00002.gguf already downloaded" ] 81self .assertEqual (prog (lines )[2 ],"verify" ) 82 83def test_step_six_packing_the_experts (self ): 84lines = 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" ] 86self .assertEqual (prog (lines )[1 :], ("Packing the model's experts for your processor (one time, a few minutes)" ,"pack" )) 87self .assertEqual (prog (lines + [" > python tools/pack_index.py --pack y" ])[1 ],"Indexing the packed experts" ) 88self .assertEqual (prog (lines + [" > python tools/strata_tokenizer.py --gguf x --out y" ])[1 ],"Preparing the tokenizer" ) 89 90def test_step_six_the_draft_layer_download_then_its_preparation (self ): 91fetch = [" [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%)" ] 94p ,label ,phase = prog (HEAD + STEP5 + STEP6 + fetch ) 95self .assertEqual (phase ,"draft_download" ) 96self .assertIn ("Downloading the draft layer" ,label ) 97# the download is over: the numbers it printed are stale, the next tool is running 98p ,label ,phase = prog (HEAD + STEP5 + STEP6 + fetch + [" MTP draft layer: 5.21 / 5.21 GB (100%)" ," > python tools/mtp_pack.py --src z" ]) 99self .assertEqual ((label ,phase ), ("Preparing the draft layer" ,"draft" )) 100p ,label ,phase = prog (HEAD + STEP5 + STEP6 + fetch + [" > python tools/mtp_rt.py --gguf g --out rt" ]) 101self .assertEqual (phase ,"draft" ) 102 103def 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 105for 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)" ]): 107with self .subTest (after = after ): 108p ,label ,phase = prog (HEAD + STEP5 + STEP6 + [" [ok] model prepared: y" ,* after ]) 109self .assertEqual ((label ,phase ), ("The model files are on this computer; checking them" ,"verify" )) 110 111def 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 113self .assertEqual (prog (HEAD + STEP5 + STEP6 )[1 :], ("The model files are on this computer; checking them" ,"verify" )) 114self .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" )) 116self .assertEqual (prog (HEAD + STEP5 + STEP6 + [" > python tools/strata_pack.py --gguf x --out y" ])[2 ],"pack" ) 117 118def test_step_six_with_everything_already_there (self ): 119lines = HEAD + STEP5 + STEP6 + [" [ok] model prepared: y" ," [ok] MTP draft layer: z" ] 120self .assertEqual (prog (lines )[2 ],"draft" ) 121 122def test_low_memory_mode_packing (self ): 123lines = 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" ] 125self .assertEqual (prog (lines )[1 ],"Packing the experts into one file for low-memory mode (one time)" ) 126 127def test_the_last_step (self ): 128lines = HEAD + STEP5 + STEP6 + ["=== Step 7: writing the start script ===" ," [ok] KV streaming on" ] 129self .assertEqual (prog (lines )[1 :], ("Saving the model's settings" ,"settings" )) 130 131def test_the_heading_is_found_even_after_hundreds_of_tool_lines (self ): 132lines = HEAD + STEP5 + STEP6 + [" > python tools/iq_pack.py --gguf x --out y" ]+ [f" layer { i } /40" for i in range (900 )] 133self .assertEqual (prog (lines )[2 ],"pack" ) 134 135def test_no_step_yet (self ): 136self .assertEqual (prog (["Strata - Qwen3.8-Flash-Next" ])[1 :], ("Getting your model ready" ,"working" )) 137 138def test_with_numbers (self ): 139w = W .describe (5 ,STEP5 , {"file" :"x.gguf" ,"done_gb" :12.34 ,"total_gb" :58.49 ,"percent" :21 }) 140self .assertEqual (W .with_numbers (w , {"done_gb" :12.34 ,"total_gb" :58.49 }),"Downloading the model files: 12.3 of 58.5 GB" ) 141self .assertEqual (W .with_numbers (w ,None ),"Downloading the model files" ) 142 143 144class CombinedFigure (unittest .TestCase ): 145def 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 147figure is the truth (the bar used to jump to 99%).""" 148import tempfile 149with tempfile .TemporaryDirectory ()as tmp : 150folder = Path (tmp ) 151part = folder / "m-00001-of-00002.gguf.part" 152part .write_bytes (b"\0" * 1000 ) 153files = [{"path" :str (folder / "m-00001-of-00002.gguf" ),"bytes" :1_000_000_000 ,"role" :"model" }] 154prog_ = {"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 156import os 157with open (part ,"r+b" )as f : 158f .truncate (1_000_000_000 ) 159out = strata_mcp .files_progress (prog_ , {"total_gb" :1.0 },files ) 160self .assertAlmostEqual (out ["download" ]["done_gb" ],0.5 ,places = 2 ) 161self .assertEqual (out ["download" ]["percent" ],50 ) 162 163def test_the_hash_check_has_its_own_figure (self ): 164lines = HEAD + STEP5 + [CHECK ," checking Qwen3.8-Flash-Next-Gyro-S-TQ1_0.gguf: 12.00 / 58.49 GB (20%) " ] 165p = strata_mcp .install_progress (lines ) 166out = strata_mcp .combined_progress (p , {"folder" :None ,"total_gb" :58.5 }) 167self .assertEqual (out ["download" ]["file" ],"checking files" ) 168self .assertEqual (out ["download" ]["percent" ],20 ) 169 170@staticmethod 171def _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 173the parallel pieces have already pushed to its full length.""" 174model = folder / "Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf" 175reader = folder / "mmproj-F16.gguf" 176for path ,size in ((model ,22_853_663_008 ), (reader if reader_done else reader .with_name (reader .name + ".part" ),899_283_584 )): 177with open (path ,"wb" )as f : 178f .truncate (size ) 179return [{"path" :str (model ),"bytes" :22_853_663_008 ,"role" :"model" }, 180 {"path" :str (reader ),"bytes" :899_283_584 ,"role" :"vision" }] 181 182def 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 184the parallel pieces) was counted whole: the bar said 99% while 16-48% of it had arrived (Boston, 2026-11-15).""" 185import tempfile 186with tempfile .TemporaryDirectory ()as tmp : 187files = self ._qwen36_files (Path (tmp ),reader_done = False ) 188prog_ = {"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 }} 190out = strata_mcp .files_progress (prog_ , {"total_gb" :22.9 },files ) 191reader = next (p for p in out ["parts" ]if p ["kind" ]== "vision" ) 192self .assertAlmostEqual (reader ["done_gb" ],0.43 ,places = 2 ) 193self .assertEqual (reader ["state" ],"downloading" ) 194self .assertLess (out ["download" ]["percent" ],99 ) 195 196def 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: 198the parts stay, all done (the app's bar is whole), and there is no download figure (setup prepares the files).""" 199import tempfile 200with tempfile .TemporaryDirectory ()as tmp : 201files = self ._qwen36_files (Path (tmp ),reader_done = True ) 202job = {"folder" :tmp ,"total_gb" :22.9 ,"files" :files } 203for lines in (HEAD + STEP5 + STEP6 ,HEAD + STEP5 + STEP6 + ["=== Step 7: writing the start script ===" ]): 204out = strata_mcp .combined_progress (strata_mcp .install_progress (lines ),job ) 205self .assertEqual ([(p ["kind" ],p ["state" ])for p in out .get ("parts" , [])], [("model" ,"done" ), ("vision" ,"done" )]) 206self .assertAlmostEqual (sum (p ["done_gb" ]for p in out ["parts" ]),23.753 ,places = 2 ) 207self .assertNotIn ("download" ,out ) 208# the download step itself, every file in: 100 209out = strata_mcp .combined_progress (strata_mcp .install_progress (HEAD + STEP5 + [" [ok] vision encoder downloaded" ]),job ) 210self .assertEqual (out ["download" ]["percent" ],100 ) 211# while a file is still missing the figure stays below 100 212Path (files [1 ]["path" ]).rename (files [1 ]["path" ]+ ".part" ) 213out = strata_mcp .combined_progress (strata_mcp .install_progress (HEAD + STEP5 + [MODEL_PROGRESS ]),job ) 214self .assertLessEqual (out ["download" ]["percent" ],99 ) 215# before the download step nothing is counted 216self .assertNotIn ("parts" ,strata_mcp .combined_progress (strata_mcp .install_progress (HEAD ),job )) 217 218 219if __name__ == "__main__" : 220unittest .main ()