okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
cd9745050
main
1"""Lane NET item 4: the plan says what the start does. 2 34a. A copy of the model installed in another data folder is not what a launch with --data-dir uses (installed_serves_request): the start runs setup 4with the given folder, and setup takes model files only from there and from the folders it reuses (the remembered data folder, Strata's own). The plan 5counted the other copy as installed ("About 1.2 GB": the start then fetched 112 GB, lane 10 on the V100 box). 64b. The plan took any mmproj*.gguf as the picture reader; setup takes only the family's pinned file name (beside a person's own files by name, in the folder 7above it or its models/ only at the pinned size) and downloads 0.9 GB otherwise. Which file setup accepts is NOT changed here. 8Nothing is started, probed or downloaded.""" 9 10from __future__import annotations 11 12import json 13import tempfile 14import unittest 15from pathlib import Path 16from unittest import mock 17 18from strata_cli .launch import modelstate 19from strata_cli .launch import settings as S 20from strata_cli .launch .catalog import Catalog 21from strata_cli .launch .runner import Runner 22from tests .terminal .launch_support import HW_12 ,Home ,catalog ,not_intel 23from tests .terminal .test_own_files import IQ3XXS ,gguf_bytes 24 25PINNED = "mmproj-Qwen3.8-Flash-Next-BF16.gguf" 26PINNED_SIZE = 907543008 27 28 29class Base (unittest .TestCase ): 30def setUp (self ): 31self .home = Home ().__enter__ () 32self .addCleanup (self .home .__exit__ ,None ,None ,None ) 33p = mock .patch .object (Catalog ,"hardware" ,lambda self ,fresh = False :dict (HW_12 ,disk_free_gb = 500.0 )) 34p .start () 35self .addCleanup (p .stop ) 36not_intel (self )# the plan asks the machine that runs the test whether the engine is the Intel one (p1006 has an Arc card: its plan drops the picture reader) 37t = tempfile .TemporaryDirectory (prefix = "strata-nettruth-" ) 38self .addCleanup (t .cleanup ) 39self .base = Path (t .name ) 40 41def model_files (self ,folder :Path )-> Path : 42folder .mkdir (parents = True ,exist_ok = True ) 43for n in IQ3XXS : 44 (folder / n ).write_bytes (gguf_bytes (["IQ3_XXS" ])) 45return folder 46 47def installed_in (self ,data :Path )-> Path : 48"""An installed IQ3_XXS whose files are all in `data` (models/, packs/), its run config written there.""" 49folder = self .model_files (data / "models" / "IQ3_XXS" ) 50pack = data / "packs" / "iq3_xxs" 51pack .mkdir (parents = True ,exist_ok = True ) 52cfg = data / "strata-iq3_xxs.json" 53cfg .write_text (json .dumps ({"exe" :"x" ,"args" : ["--native" ,str (folder / IQ3XXS [0 ]),"--pack" ,str (pack )]}),encoding = "utf-8" ) 54return cfg 55 56def runner (self ,cfg :Path | None ,remembered :Path ,** kw )-> Runner : 57r = Runner (S .LaunchSettings (family = "qwen" ,model = "IQ3_XXS" ,vision = "off" ,mtp = "off" ,drafting = "off" ,context = 32768 ,** kw ), 58catalog = catalog (HW_12 )) 59for p in (mock .patch .object (Runner ,"installed_state" ,lambda self : (cfg , {"images" :"off" })if cfg else (None ,None )), 60mock .patch .object (Catalog ,"data_dir" ,lambda self :remembered )): 61p .start () 62self .addCleanup (p .stop ) 63return r 64 65 66class PlanUsesTheGivenDataDir (Base ): 67def test_a_copy_in_another_folder_is_not_counted (self ): 68other ,new = self .base / "other" ,self .base / "new" 69cfg = self .installed_in (other ) 70r = self .runner (cfg ,self .base / "remembered" ,data_dir = str (new )) 71self .assertFalse (r .installed_serves_request (cfg )) 72self .assertEqual (r .other_copy (),other ) 73st = r .model_state () 74self .assertFalse (st .installed ) 75self .assertEqual ([p .kind for p in st .parts ], ["weights" ]) 76self .assertGreater (st .remaining_gb ,10 ) 77plan = r .download_plan () 78self .assertTrue (plan ["text" ].startswith (f"About { plan [ 'gb' ]:.1f } GB to download into { new } : the model (" ),plan ["text" ]) 79self .assertIn (f"The copy in { other } is not used with this --data-dir." ,plan ["text" ]) 80 81def test_a_copy_in_the_remembered_folder_is_what_setup_reuses (self ): 82remembered ,new = self .base / "remembered" ,self .base / "new" 83cfg = self .installed_in (remembered ) 84r = self .runner (cfg ,remembered ,data_dir = str (new )) 85self .assertFalse (r .installed_serves_request (cfg )) 86self .assertIsNone (r .other_copy ())# setup.data_folder_for keeps it as a source: nothing is fetched again 87self .assertTrue (r .model_state ().installed ) 88self .assertNotIn ("is not used with this --data-dir" ,r .download_plan ()["text" ]) 89 90def test_the_same_folder_is_the_installed_copy_as_before (self ): 91other = self .base / "other" 92cfg = self .installed_in (other ) 93r = self .runner (cfg ,self .base / "remembered" ,data_dir = str (other )) 94self .assertTrue (r .installed_serves_request (cfg )) 95self .assertIsNone (r .other_copy ()) 96self .assertTrue (r .model_state ().installed ) 97 98def test_no_data_dir_is_the_installed_copy_as_before (self ): 99cfg = self .installed_in (self .base / "other" ) 100r = self .runner (cfg ,self .base / "remembered" ) 101self .assertIsNone (r .other_copy ()) 102self .assertTrue (r .model_state ().installed ) 103 104 105class PictureReaderBySetupsRule (Base ): 106def sparse (self ,path :Path ,size :int )-> Path : 107path .parent .mkdir (parents = True ,exist_ok = True ) 108with open (path ,"wb" )as f : 109f .truncate (size ) 110return path 111 112def test_reader_present_follows_setup (self ): 113c = catalog (HW_12 ) 114own = self .model_files (self .base / "mine" / "IQ3_XXS" ) 115self .assertEqual (modelstate .mmproj_size (c ,"qwen" ,PINNED ),PINNED_SIZE ) 116 (own / "mmproj-F16.gguf" ).write_bytes (b"x" ) 117self .assertFalse (modelstate .reader_present (c ,"qwen" , [],own = own ),"another picture file is not the one setup takes" ) 118self .sparse (self .base / "mine" / PINNED ,1000 ) 119self .assertFalse (modelstate .reader_present (c ,"qwen" , [],own = own ),"the folder above: only at the pinned size" ) 120self .sparse (self .base / "mine" / PINNED ,PINNED_SIZE ) 121self .assertTrue (modelstate .reader_present (c ,"qwen" , [],own = own )) 122 (self .base / "mine" / PINNED ).unlink () 123 (own / PINNED ).write_bytes (b"x" ) 124self .assertTrue (modelstate .reader_present (c ,"qwen" , [],own = own ),"beside the files: by name, as setup's mmproj_beside" ) 125data = self .base / "data" 126self .assertFalse (modelstate .reader_present (c ,"qwen" , [data ])) 127 (data / "models" ).mkdir (parents = True ) 128 (data / "models" / "mmproj-F16.gguf" ).write_bytes (b"x" ) 129self .assertFalse (modelstate .reader_present (c ,"qwen" , [data ])) 130 (data / "models" / PINNED ).write_bytes (b"x" ) 131self .assertTrue (modelstate .reader_present (c ,"qwen" , [data ])) 132 133def test_the_plan_counts_the_reader_when_only_another_picture_file_is_there (self ): 134own = self .model_files (self .base / "mine" / "IQ3_XXS" ) 135 (own / "mmproj-F16.gguf" ).write_bytes (b"x" )# Unsloth's file beside the shards (the V100 box's layout) 136r = Runner (S .LaunchSettings (family = "qwen" ,model = "IQ3_XXS" ,vision = "gpu" ,mtp = "off" ,drafting = "off" ,context = 32768 , 137model_path = str (own ),data_dir = str (self .base / "data" )),catalog = catalog (HW_12 )) 138remembered = self .base / "remembered" 139with mock .patch .object (Catalog ,"data_dir" ,lambda _cat :remembered ): 140kinds = [p ["kind" ]for p in r .download_plan ()["parts" ]] 141self .assertIn ("mmproj" ,kinds ,"setup downloads the pinned reader: the plan says so" ) 142 (own / PINNED ).write_bytes (b"x" ) 143kinds = [p ["kind" ]for p in r .download_plan ()["parts" ]] 144self .assertNotIn ("mmproj" ,kinds ) 145 146 147if __name__ == "__main__" : 148unittest .main ()