okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
3af562d54
main
1"""What the person is told while a model downloads and is prepared: ONE place for the words, read by the app (through 2tools/strata_mcp.py `install_progress`) and by the Terminal (`strata launch`, strata_cli/launch/runner.py). 3 4Setup prints its work in seven steps and the tools it runs print their command lines (`> python tools/strata_pack.py build ...`) 5and progress lines (`name: 1.20 / 5.04 GB (24%)`). Those titles are for people who read the setup log ("writing the start script", 6"preparing the model for Strata"), and the name in a progress line is a file name or an internal label ("MTP draft layer", 7"llama.cpp source"). This turns what setup last printed into one plain sentence that says what is really happening now. 8The sentences are English; the app translates them like its other texts. 9 10Nothing here reads a file or starts a process: it works on the last lines of setup's output. 11""" 12 13from __future__import annotations 14 15import re 16from dataclasses import dataclass 17 18STEP_RE = re .compile (r"=== Step (\d+): (.+?) ===" ) 19CHECKING_RE = re .compile (r"^\s*checking\b.*\bSHA-256\b" ,re .I ) 20PROGRESS_RE = re .compile (r"\s*(\S.*?): +([\d.]+) / ([\d.]+) GB \((\d+)%\)" ) 21try :# the network rule's own line and words (one place for them) 22from strata_control .netpolicy import WAITING_RE ,WORDS as _NET_WORDS 23WAITING_WORDS = _NET_WORDS ["waiting" ] 24except ImportError :# an older strata_control beside a newer reader: never waiting 25WAITING_RE = re .compile (r"(?!)" ) 26WAITING_WORDS = "" 27 28 29@dataclass( frozen = True ) 30class Words : 31phase :str # a short key for tests and for the app to pick an icon: check, helpers, engine, download, verify, pictures, 32# pack, tokenizer, draft_download, draft, settings, ... 33label :str # the sentence 34 35def as_dict (self )-> dict : 36return {"phase" :self .phase ,"label" :self .label } 37 38 39def _after_last_step (lines :list [str ])-> list [str ]: 40for i in range (len (lines )- 1 ,- 1 ,- 1 ): 41if STEP_RE .search (lines [i ]): 42return lines [i + 1 :] 43return lines 44 45 46def _last_matching (lines :list [str ],* needles :str )-> str | None : 47"""The newest line that holds one of the needles (lower case compare).""" 48for line in reversed (lines ): 49low = line .lower () 50if any (n in low for n in needles ): 51return line 52return None 53 54 55def describe (step :int | None ,lines :list [str ],download :dict | None = None )-> Words : 56"""The sentence for setup's step `step` (1 to 7; None when unknown) given the lines it printed since the step began and the 57download figure in them (`{"file": ..., "percent": ...}` or None).""" 58recent = _after_last_step (lines ) 59dl_file = str ((download or {}).get ("file" ,"" )).lower () 60last_line = next ((ln for ln in reversed (recent )if ln .strip ()),"" ) 61waiting = WAITING_RE .match (last_line ) 62if waiting :# a server has not answered yet (strata_control/netpolicy.py prints this line) 63return Words ("waiting" ,WAITING_WORDS .format (host = waiting .group ("host" ),seconds = waiting .group ("seconds" ))) 64if step is None : 65return Words ("working" ,"Getting your model ready" ) 66if step <= 2 : 67return Words ("check" ,"Checking your computer" ) 68if step == 3 : 69return Words ("helpers" ,"Getting the helper packages ready" ) 70if step == 4 : 71if "engine" in dl_file : 72return Words ("engine" ,"Downloading the engine for this PC" ) 73if "source" in dl_file or "llama.cpp" in dl_file : 74return Words ("helpers" ,"Downloading the small tools used to prepare models" ) 75return Words ("engine" ,"Checking the engine for this PC" ) 76if step == 5 : 77last = recent [- 1 ]if recent else "" 78for line in reversed (recent ):# a file with a wrong SHA-256 is read again and only the bad parts rewritten 79if "were damaged; downloading only those parts" in line : 80return Words ("repair" ,"Some parts of a model file were damaged; downloading only those parts again" ) 81if CHECKING_RE .search (line )or "were different and have been written again" in line : 82break 83if dl_file .startswith ("checking" )or CHECKING_RE .search (last ): 84return Words ("verify" ,"Checking that the model files are complete (a few minutes for a big model; nothing is downloaded)" ) 85if "vision" in dl_file or "picture" in dl_file or "mmproj" in dl_file : 86return Words ("pictures" ,"Downloading the picture reader" ) 87if download and not dl_file .startswith ("checking" ): 88return Words ("download" ,"Downloading the model files" ) 89if _last_matching (recent ,"already downloaded" ,"model files present" ): 90return Words ("verify" ,"The model files are on this computer; checking them" ) 91return Words ("download" ,"Getting the model files" ) 92if step == 6 : 93marker = _last_matching (recent ,"mtp_rt.py" ,"mtp_pack.py" ,"mtp_fetch.py" ,"mtp draft layer:" ,"strata_pack.py" ,"pack_index.py" , 94"strata_tokenizer.py" ,"iq_pack.py" ,"nvfp4_local_pack.py" ,"converting the q2_0 experts" , 95"writing the experts into one file" ,"of mtp tensors" ,"[ok] model prepared" ) 96low = (marker or "" ).lower () 97if not marker and dl_file .startswith ("mtp draft" ): 98low = "mtp draft layer:" 99if "[ok] mtp draft layer" in low : 100return Words ("draft" ,"Preparing the draft layer" ) 101if "mtp_fetch.py" in low or "mtp draft layer:" in low or "of mtp tensors" in low : 102return Words ("draft_download" ,"Downloading the draft layer (about 5 GB; it makes answers about twice as fast)" ) 103if "mtp_rt.py" in low or "mtp_pack.py" in low : 104return Words ("draft" ,"Preparing the draft layer" ) 105if "[ok] model prepared" in low or not marker :# nothing is being prepared (the model is prepared, or step 6 has only begun) and no draft-layer step runs: 106return Words ("verify" ,"The model files are on this computer; checking them" )# words that claim no preparation (0.2.14.1 check: no "(one time)" on every launch) 107if "strata_pack.py" in low or "converting the q2_0 experts" in low : 108return Words ("pack" ,"Packing the model's experts for your processor (one time, a few minutes)" ) 109if "pack_index.py" in low : 110return Words ("pack" ,"Indexing the packed experts" ) 111if "strata_tokenizer.py" in low : 112return Words ("tokenizer" ,"Preparing the tokenizer" ) 113if "writing the experts into one file" in low or ("iq_pack.py" in low and "--experts-bin" in low ): 114return Words ("pack" ,"Packing the experts into one file for low-memory mode (one time)" ) 115if "iq_pack.py" in low : 116return Words ("pack" ,"Preparing the model data for the engine (one time)" ) 117if "nvfp4_local_pack.py" in low : 118return Words ("pack" ,"Converting NVIDIA's FP4 checkpoint on this PC (20 to 40 minutes, one time)" ) 119return Words ("pack" ,"Preparing your model for Strata (one time)" ) 120return Words ("settings" ,"Saving the model's settings" ) 121 122 123def with_numbers (words :Words ,download :dict | None )-> str : 124"""The sentence with the figure after it when there is one: `Downloading the model files: 12.3 of 66.4 GB`.""" 125if not download : 126return words .label 127try : 128done ,total = float (download ["done_gb" ]),float (download ["total_gb" ]) 129except (KeyError ,TypeError ,ValueError ): 130return words .label 131if total <= 0.05 : 132return words .label 133return f" { words . label } : { done :.1f } of { total :.1f } GB"