okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
361c8d94a
main
1"""Tests for setup.py's Qwen3.6-35B-A3B install (a family with its own engine path: OWN_PATH_FAMILIES): the pinned and 2hashed files, the menu entry, steps 2-7 of install_own_path (size, context, the engine's --families check, the 3download, the tokenizer, the config) and reading such a config back. Mocked engine, downloads and processes - 4nothing is built, fetched or started. 5 6python -m unittest tools.test_setup_qwen36 7""" 8from __future__import annotations 9 10import argparse 11import contextlib 12import io 13import json 14import re 15import sys 16import tempfile 17import unittest 18from pathlib import Path 19from unittest import mock 20 21ROOT = Path (__file__ ).resolve ().parents [1 ] 22sys .path .insert (0 ,str (ROOT )) 23sys .path .insert (0 ,str (ROOT / "tools" )) 24import setup # noqa: E402 25 26SHA = re .compile (r"/resolve/[0-9a-f]{40}/" ) 27REPO = "unsloth/Qwen3.6-35B-A3B-MTP-GGUF" 28 29 30def args (** kw ): 31base = dict (family = "qwen36" ,model = None ,check = False ,yes = True ,vision = None ,models_dir = None ,gguf_dir = None , 32context = None ,rope_scaling = None ,rope_scale = None ,kv = None ,resident_budget_gib = None ,low_ram = "auto" , 33vram_reserve_mib = None ,host = None ,api_key = None ,browser = None ,no_start = True ,data_dir = None ,gpu = None ) 34base .update (kw ) 35return argparse .Namespace (** base ) 36 37 38def run (fn ,* a ,** kw ): 39out = io .StringIO () 40with contextlib .redirect_stdout (out ): 41try : 42return fn (* a ,** kw ),out .getvalue () 43except SystemExit as e : 44return e .code ,out .getvalue () 45 46 47class Qwen36Entries (unittest .TestCase ): 48def test_pinned_and_hashed (self ): 49fam = setup .OWN_PATH_FAMILIES ["qwen36" ] 50self .assertIs (setup .PREVIEW_FAMILIES ,setup .OWN_PATH_FAMILIES )# the earlier name still works 51self .assertEqual (setup .HF_REVISIONS [REPO ],"5bc3e238d916f48a861bac2f8a1990a0e9b7e98d" ) 52for key in ("hf" ,"mmproj_hf" ): 53self .assertRegex (fam [key ],SHA ) 54self .assertIn (REPO ,fam [key ]) 55self .assertEqual (fam ["arch" ],"qwen35moe" ) 56self .assertEqual (list (fam ["models" ]), ["UD-Q4_K_XL" ,"UD-Q6_K_XL" ,"Q8_0" ]) 57for m in fam ["models" ]: 58size ,sha = fam ["sha256" ][fam ["file" ].format (q = m )] 59self .assertGreater (size ,20e9 ) 60self .assertRegex (sha ,r"^[0-9a-f]{64}$" ) 61self .assertEqual (fam ["sha256" ]["Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf" ][0 ],22853663008 ) 62 63def test_not_a_pack_family (self ): 64# FAMILIES are Flash-Next files with packs; Qwen3.6 is installed by install_own_path 65self .assertNotIn ("qwen36" ,setup .FAMILIES ) 66for m ,d in setup .MODELS .items (): 67self .assertNotIn ("qwen36" ,d .get ("families" , ())) 68 69def test_size_recommendation (self ): 70fam = setup .OWN_PATH_FAMILIES ["qwen36" ] 71self .assertEqual (setup .own_path_size (fam ,24.0 ),"UD-Q4_K_XL" )# none fits: the smallest 72self .assertEqual (setup .own_path_size (fam ,32.0 ),"UD-Q4_K_XL" ) 73self .assertEqual (setup .own_path_size (fam ,46.0 ),"UD-Q6_K_XL" ) 74self .assertEqual (setup .own_path_size (fam ,64.0 ),"Q8_0" ) 75 76def test_context_recommendation (self ): 77fam = setup .OWN_PATH_FAMILIES ["qwen36" ] 78# 128K (owner, 2026-11-01) where it fits the card; else the largest size that does (#5715); the smallest when none does 79want = {("UD-Q4_K_XL" ,11.94 ):32768 , ("UD-Q4_K_XL" ,15.93 ):131072 , ("UD-Q4_K_XL" ,23.99 ):131072 , ("UD-Q4_K_XL" ,32.0 ):131072 , 80 ("UD-Q6_K_XL" ,11.94 ):32768 , ("UD-Q6_K_XL" ,15.93 ):65536 , ("Q8_0" ,15.93 ):65536 , ("UD-Q6_K_XL" ,23.99 ):131072 , 81 ("UD-Q4_K_XL" ,8.0 ):8192 , ("Q8_0" ,10.0 ):8192 } 82for (model ,vram ),ctx in want .items (): 83self .assertEqual (setup .own_path_context (fam ,vram ,model ),ctx , (model ,vram )) 84self .assertEqual (setup .own_path_context (fam ,0.0 ,"UD-Q4_K_XL" ),131072 )# no card known: as before 85self .assertEqual (setup .own_path_context (fam ,12.0 ),131072 )# no size: as before 86self .assertEqual (setup .own_path_context ({** fam ,"name" :"another-model" },12.0 ,"UD-Q4_K_XL" ),131072 )# a feed model: as before 87 88def test_the_menu_is_the_rules_menu (self ): 89from strata_control import own_path_fit 90self .assertEqual (setup .own_path_contexts (),own_path_fit .MENU ) 91 92def test_context_warning (self ): 93fam = setup .OWN_PATH_FAMILIES ["qwen36" ] 94self .assertEqual (setup .own_path_context_warning (fam ,"UD-Q4_K_XL" ,11.94 ,131072 ), 95"At 128K, this model's conversation memory needs about 5.8 GB of graphics memory. With the model itself that is more than " 96"this card's 12 GB, so it will probably not start. 32K fits on this card: choose 32K or less." ) 97self .assertTrue (setup .own_path_context_warning (fam ,"UD-Q6_K_XL" ,15.93 ,131072 ).endswith ( 98"this card's 16 GB, so it will probably not start. 64K fits on this card: choose 64K or less." )) 99self .assertIsNone (setup .own_path_context_warning (fam ,"UD-Q4_K_XL" ,11.94 ,32768 ))# fits 100self .assertIsNone (setup .own_path_context_warning (fam ,"UD-Q4_K_XL" ,8.0 ,131072 ))# nothing fits: no sentence (none approved for it) 101self .assertIsNone (setup .own_path_context_warning (fam ,"UD-Q4_K_XL" ,0.0 ,131072 ))# no card known 102 103 104class InstallOwnPath (unittest .TestCase ): 105def setUp (self ): 106self .tmp = tempfile .TemporaryDirectory () 107self .addCleanup (self .tmp .cleanup ) 108self .root = Path (self .tmp .name ) 109self .calls = [] 110self .families = {"qwen4exp" ,"qwen35moe" } 111self .hip_reader = True 112eng = self .root / "engine" 113self .cfg = {} 114 115def engine_step (a ,gpu ,hip ,amd ,cuda_tk ,vision ): 116self .calls .append (("engine" ,vision )) 117if vision != "none" :# the image encoder beside the engine 118eng .mkdir (parents = True ,exist_ok = True ) 119 (eng / setup .VEXE ).write_text ("x" ) 120if hip and self .hip_reader :# an AMD engine package carries the GPU reader too 121 (eng / setup .HVEXE ).write_text ("x" ) 122return self .root / "llama" ,eng , {"version" :"0.1.44" }, ["/libs" ],gpu ,vision 123 124def write_cfg (path ,cfg ,source = None ,explicit = None ): 125self .cfg = cfg 126self .calls .append (("config" ,path .name )) 127 128patches = [mock .patch .object (setup ,"download" ,lambda url ,dst ,what = None :self .calls .append (("get" ,url ,dst ))), 129mock .patch .object (setup ,"verify_sha256" ,lambda s ,size ,sha ,own = False :self .calls .append (("sha" ,s .name ))), 130mock .patch .object (setup ,"free_gb" ,lambda p :500.0 ), 131mock .patch .object (setup ,"pip_install" ,lambda * a ,** k :None ), 132mock .patch .object (setup ,"engine_step" ,engine_step ), 133mock .patch .object (setup ,"engine_families" ,lambda e :self .families ), 134mock .patch .object (setup ,"run" ,lambda cmd ,** k :self .calls .append (("run" ,cmd ))), 135mock .patch .object (setup ,"data_folder" ,lambda d ,* a ,** k : (self .root / "data" , [])), 136mock .patch .object (setup ,"write_setup_config" ,write_cfg ), 137mock .patch .object (setup ,"write_run_script" ,lambda tag ,p ,port ,o = True :self .root / f"run- { tag } .sh" ), 138mock .patch .object (setup ,"recommend_pool_workers" ,lambda a :a ), 139mock .patch .object (setup ,"ROOT" ,self .root )] 140for p in patches : 141p .start () 142self .addCleanup (p .stop ) 143 144def install (self ,ram = 64.0 ,vram = 16.0 ,hip = False ,** kw ): 145gpu = {"index" :0 ,"count" :1 ,"vram_gb" :vram ,"name" :"Test GPU" } 146return run (setup .install_own_path ,args (models_dir = str (self .root / "models" ),** kw ),"qwen36" ,gpu ,hip , [], 14713 , [],8080 ,ram ,None ) 148 149def test_installs_the_pinned_file_and_writes_the_config (self ): 150rc ,out = self .install (model = "UD-Q4_K_XL" ,vision = "no" ) 151self .assertEqual (rc ,0 ,out ) 152get = [c for c in self .calls if c [0 ]== "get" ] 153self .assertEqual (len (get ),1 ) 154gguf = self .root / "models" / "qwen36-UD-Q4_K_XL" / "Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf" 155self .assertEqual (get [0 ][1 ],setup .hf (REPO )+ gguf .name ) 156self .assertEqual (get [0 ][2 ],gguf ) 157self .assertIn (("sha" ,gguf .name ),self .calls ) 158self .assertIn (("engine" ,"none" ),self .calls )# --vision no: no image encoder 159self .assertNotIn ("--vision" ,self .cfg ["args" ]) 160self .assertNotIn ("vision" ,self .cfg ) 161tok = [c for c in self .calls if c [0 ]== "run" ] 162self .assertTrue (tok and "strata_tokenizer.py" in str (tok [0 ][1 ])) 163a = self .cfg ["args" ] 164self .assertEqual (a [a .index ("--native" )+ 1 ],str (gguf )) 165self .assertEqual (a [a .index ("--max-context" )+ 1 ],"131072" )# 128K on every card, the 16 GB one too 166self .assertEqual (a [a .index ("--mtp" )+ 1 ],"2" ) 167self .assertNotIn ("--pack" ,a ) 168self .assertNotIn ("--expert-cache" ,a ) 169self .assertEqual (self .cfg ["arch" ],"qwen35moe" ) 170self .assertEqual (self .cfg ["model_name" ],"qwen3.6-35b-a3b-ud-q4_k_xl" ) 171self .assertEqual (Path (self .cfg ["exe" ]).parent ,self .root / "engine" ) 172self .assertIn (("config" ,"strata-qwen36-ud-q4_k_xl.json" ),self .calls ) 173 174def test_gguf_dir_takes_the_persons_own_files_that_have_no_finish_mark (self ): 175folder = self .root / "own" 176folder .mkdir () 177for name in ("Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf" ,"mmproj-F16.gguf" ): 178 (folder / name ).write_text ("x" )# no <name>.done: verify_sha256 checks the file and marks it 179with mock .patch .object (setup ,"free_gb" ,lambda p :1.0 ):# nothing to download: no disk needed 180rc ,out = self .install (model = "UD-Q4_K_XL" ,vision = "cpu" ,gguf_dir = str (folder )) 181self .assertEqual (rc ,0 ,out ) 182self .assertEqual ([c for c in self .calls if c [0 ]== "get" ], []) 183self .assertIn (("sha" ,"Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf" ),self .calls ) 184self .assertIn (("sha" ,"mmproj-F16.gguf" ),self .calls ) 185 186def test_gguf_dir_without_the_file_still_says_it_is_missing (self ): 187folder = self .root / "empty" 188folder .mkdir () 189rc ,out = self .install (model = "UD-Q4_K_XL" ,vision = "no" ,gguf_dir = str (folder )) 190self .assertEqual (rc ,1 ) 191self .assertIn ("is missing" ,out ) 192 193def test_default_size_follows_the_ram (self ): 194rc ,out = self .install (ram = 64.0 ) 195self .assertEqual (rc ,0 ,out ) 196self .assertIn ("Recommended for 64 GB of RAM: Q8_0" ,out ) 197self .assertTrue (self .cfg ["args" ][self .cfg ["args" ].index ("--native" )+ 1 ].endswith ("Qwen3.6-35B-A3B-Q8_0.gguf" )) 198rc ,out = self .install (ram = 46.0 ) 199self .assertTrue (self .cfg ["args" ][self .cfg ["args" ].index ("--native" )+ 1 ].endswith ("UD-Q6_K_XL.gguf" )) 200 201def test_a_bigger_size_than_the_ram_is_asked_not_refused (self ): 202with mock .patch .object (setup ,"confirm_risk" ,lambda * a ,** k :None ): 203rc ,out = self .install (ram = 32.0 ,model = "Q8_0" ) 204self .assertEqual (rc ,0 ,out ) 205self .assertIn ("installing Q8_0 with 32 GB of RAM, as you chose" ,out ) 206 207def test_an_engine_without_the_family_is_refused_before_the_download (self ): 208self .families = {"qwen4exp" } 209rc ,out = self .install (model = "UD-Q4_K_XL" ) 210self .assertEqual (rc ,1 ) 211self .assertIn ("does not run Qwen3.6-35B-A3B yet" ,out ) 212self .assertEqual ([c for c in self .calls if c [0 ]== "get" ], []) 213 214def test_the_app_with_no_engine_yet_downloads_as_flash_next_does (self ): 215# DL99: the app fetches the engine beside the model on a first run; while it is not there, control_engine_step answers a placeholder 216# (component "missing") and Flash-Next goes on. Qwen3.6 asked that missing program for its families, got {"qwen4exp"} and stopped 217# ("this engine (99.0.0) does not run ..."), 4 s into the app's first install. 218self .families = {"qwen4exp" }# what engine_families answers when the program is not there 219 220def no_engine_yet (a ,gpu ,hip ,amd ,cuda_tk ,vision ): 221self .calls .append (("engine" ,vision )) 222return self .root / "llama" ,self .root / "engine" , {"version" :"99.0.0" ,"source" :"local" ,"component" :"missing" }, [],gpu ,"none" 223with mock .patch .object (setup ,"CONTROL" ,True ),mock .patch .object (setup ,"engine_step" ,no_engine_yet ): 224rc ,out = self .install (model = "UD-Q4_K_XL" ) 225self .assertEqual (rc ,0 ,out ) 226self .assertNotIn ("does not run Qwen3.6-35B-A3B yet" ,out ) 227self .assertEqual (len ([c for c in self .calls if c [0 ]== "get" ]),1 ,"the model is downloaded" ) 228self .assertEqual (self .cfg ["exe" ],"component:strata-engine" ,"the engine is looked up when the model loads" ) 229 230def test_the_app_with_an_engine_that_does_not_run_it_is_still_refused (self ): 231self .families = {"qwen4exp" } 232with mock .patch .object (setup ,"CONTROL" ,True ): 233rc ,out = self .install (model = "UD-Q4_K_XL" ) 234self .assertEqual (rc ,1 ) 235self .assertIn ("does not run Qwen3.6-35B-A3B yet" ,out ) 236self .assertEqual ([c for c in self .calls if c [0 ]== "get" ], []) 237 238def test_a_flash_next_size_is_refused (self ): 239rc ,out = self .install (model = "IQ3_XXS" ) 240self .assertEqual (rc ,1 ) 241self .assertIn ("has no IQ3_XXS" ,out ) 242self .assertEqual (self .calls , []) 243 244def test_too_little_disk (self ): 245with mock .patch .object (setup ,"free_gb" ,lambda p :10.0 ): 246rc ,out = self .install (model = "Q8_0" ) 247self .assertEqual (rc ,1 ) 248self .assertIn ("not enough free disk space" ,out ) 249 250def test_bigger_card_bigger_context (self ): 251rc ,out = self .install (model = "UD-Q4_K_XL" ,vram = 32.0 ,vision = "no" ) 252self .assertEqual (rc ,0 ,out ) 253a = self .cfg ["args" ] 254self .assertEqual (a [a .index ("--max-context" )+ 1 ],"131072" ) 255 256def test_a_12gb_card_gets_the_size_that_fits_and_a_bigger_choice_is_kept_with_the_warning (self ): 257# #5715: RTX 5070 12 GB; the menu marks 32K, --yes takes it 258with mock .patch .object (setup ,"ask" ,lambda question ,choices ,default ,yes :default ):# Enter at every question 259rc ,out = self .install (model = "UD-Q4_K_XL" ,vram = 11.94 ,vision = "no" ,yes = False ) 260self .assertEqual (rc ,0 ,out ) 261self .assertIn ("2) 32K tokens (recommended for your GPU)" ,out ) 262self .assertIn ("4) 128K tokens\n" ,out ) 263a = self .cfg ["args" ] 264self .assertEqual (a [a .index ("--max-context" )+ 1 ],"32768" ) 265self .assertNotIn ("will probably not start" ,out ) 266# a bigger choice is kept, with the sentence before the start 267for ctx in (65536 ,131072 ): 268rc ,out = self .install (model = "UD-Q4_K_XL" ,vram = 11.94 ,vision = "no" ,context = ctx ) 269self .assertEqual (rc ,0 ,out ) 270a = self .cfg ["args" ] 271self .assertEqual (a [a .index ("--max-context" )+ 1 ],str (ctx )) 272self .assertIn (f"At { ctx // 1024 } K, this model's conversation memory needs about" ,out ) 273self .assertIn ("32K fits on this card: choose 32K or less." ,out ) 274# a card where nothing fits: the smallest size is marked, no sentence 275rc ,out = self .install (model = "UD-Q4_K_XL" ,vram = 8.0 ,vision = "no" ,context = 131072 ) 276self .assertEqual (rc ,0 ,out ) 277self .assertNotIn ("will probably not start" ,out ) 278 279def test_images_by_default_on_a_24gb_plus_nvidia_card_use_the_gpu_encoder (self ): 280rc ,out = self .install (model = "UD-Q4_K_XL" ,vram = 24.0 )# --yes: the question's default answer (yes) 281self .assertEqual (rc ,0 ,out ) 282self .assertIn (("engine" ,"gpu" ),self .calls ) 283mm = self .root / "models" / "qwen36-UD-Q4_K_XL" / "mmproj-F16.gguf" 284self .assertIn (("get" ,setup .hf (REPO )+ "mmproj-F16.gguf" ,mm ),self .calls ) 285self .assertIn (("sha" ,"mmproj-F16.gguf" ),self .calls )# pinned: size + SHA-256 (899283584 bytes) 286self .assertEqual (setup .OWN_PATH_FAMILIES ["qwen36" ]["sha256" ]["mmproj-F16.gguf" ][0 ],899283584 ) 287a = self .cfg ["args" ] 288self .assertIn ("--vision" ,a ) 289v = self .cfg ["vision" ] 290self .assertTrue (v ["gpu" ]) 291self .assertEqual (v ["mmproj" ],str (mm )) 292self .assertTrue (v ["model" ].endswith ("Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf" ))# the text model, opened vocab-only 293self .assertEqual (Path (v ["exe" ]).name ,setup .VEXE ) 294self .assertEqual (v ["max_tokens" ],1024 ) 295self .assertIn ("images: on" ,out ) 296 297def test_a_12gb_card_is_recommended_the_cpu_encoder_never_forced (self ): 298rc ,out = self .install (model = "UD-Q4_K_XL" ,vram = 12.0 )# the default answer is yes, with the CPU encoder 299self .assertEqual (rc ,0 ,out ) 300self .assertFalse (self .cfg ["vision" ]["gpu" ]) 301rc ,out = self .install (model = "UD-Q4_K_XL" ,vram = 16.0 )# the 24 GB rule, not the old 16 GB one 302self .assertEqual (rc ,0 ,out ) 303self .assertFalse (self .cfg ["vision" ]["gpu" ]) 304rc ,out = self .install (model = "UD-Q4_K_XL" ,vram = 12.0 ,vision = "yes" )# yes: the CPU encoder, said why 305self .assertEqual (rc ,0 ,out ) 306self .assertFalse (self .cfg ["vision" ]["gpu" ]) 307self .assertEqual (self .cfg ["vision" ]["max_tokens" ],300 ) 308self .assertIn ("threads" ,self .cfg ["vision" ]) 309rc ,out = self .install (model = "UD-Q4_K_XL" ,vram = 12.0 ,vision = "gpu" )# gpu asked for: kept, with a note 310self .assertEqual (rc ,0 ,out ) 311self .assertTrue (self .cfg ["vision" ]["gpu" ]) 312self .assertIn ("kept as you chose" ,out ) 313 314def test_amd_reads_pictures_on_the_gpu_with_the_cpu_reader_behind_it (self ): 315for win ,suffix in ((False ,"" ), (True ,".exe" )): 316with mock .patch .object (setup ,"WIN" ,win ),mock .patch .object (setup ,"VEXE" ,"strata-vision" + suffix ),mock .patch .object (setup ,"HVEXE" ,"strata-vision-hip" + suffix ): 317rc ,out = self .install (model = "UD-Q4_K_XL" ,vram = 32.0 ,hip = True ,vision = "yes" ) 318self .assertEqual (rc ,0 ,out ) 319v = self .cfg ["vision" ] 320self .assertTrue (v ["gpu" ]) 321self .assertEqual (Path (v ["exe" ]).name ,"strata-vision-hip" + suffix ) 322self .assertEqual (Path (v ["cpu_exe" ]).name ,"strata-vision" + suffix ) 323self .assertIn ("--vision" ,self .cfg ["args" ]) 324rc ,out = self .install (model = "UD-Q4_K_XL" ,vram = 32.0 ,hip = True ,vision = "cpu" ) 325v = self .cfg ["vision" ] 326self .assertFalse (v ["gpu" ]) 327self .assertEqual (Path (v ["exe" ]).name ,"strata-vision" + suffix ) 328self .assertNotIn ("cpu_exe" ,v ) 329 330def test_amd_engine_without_the_gpu_reader_reads_pictures_on_the_cpu (self ): 331self .hip_reader = False 332with mock .patch .object (setup ,"WIN" ,False ),mock .patch .object (setup ,"VEXE" ,"strata-vision" ): 333rc ,out = self .install (model = "UD-Q4_K_XL" ,vram = 32.0 ,hip = True ,vision = "yes" ) 334self .assertEqual (rc ,0 ,out ) 335self .assertFalse (self .cfg ["vision" ]["gpu" ]) 336self .assertNotIn ("cpu_exe" ,self .cfg ["vision" ]) 337self .assertIn ("--vision" ,self .cfg ["args" ]) 338 339def test_amd_pictures_are_on_when_nothing_is_asked (self ): 340with mock .patch .object (setup ,"WIN" ,False ),mock .patch .object (setup ,"VEXE" ,"strata-vision" ),mock .patch .object (setup ,"HVEXE" ,"strata-vision-hip" ): 341rc ,out = self .install (model = "UD-Q4_K_XL" ,vram = 32.0 ,hip = True ) 342self .assertEqual (rc ,0 ,out ) 343self .assertTrue (self .cfg ["vision" ]["gpu" ]) 344 345def test_amd_under_24gb_reads_pictures_on_the_cpu_by_default (self ): 346with mock .patch .object (setup ,"WIN" ,False ),mock .patch .object (setup ,"VEXE" ,"strata-vision" ),mock .patch .object (setup ,"HVEXE" ,"strata-vision-hip" ): 347rc ,out = self .install (model = "UD-Q4_K_XL" ,vram = 16.0 ,hip = True ) 348self .assertEqual (rc ,0 ,out ) 349self .assertIn ("--vision" ,self .cfg ["args" ]) 350self .assertFalse (self .cfg ["vision" ]["gpu" ]) 351self .assertEqual (Path (self .cfg ["vision" ]["exe" ]).name ,"strata-vision" ) 352 353def test_parallel_is_opt_in_and_recommended_where_the_experts_fit (self ): 354fam = setup .OWN_PATH_FAMILIES ["qwen36" ] 355# nothing written without --parallel; the recommendation is said 356rc ,out = self .install (model = "UD-Q4_K_XL" ,vram = 32.0 ,vision = "no" ,context = 32768 ) 357self .assertEqual (rc ,0 ,out ) 358self .assertNotIn ("parallel" ,self .cfg ) 359self .assertIn ("--parallel 3" ,out ) 360# a 12 GB card runs the hybrid mode: parallel is offered there too, with its price said (never forced) 361# (measured: 12 GB at 8K, 4 slots: a request alone -4%; 16 GB at 32K, 2 slots -9 to -11%, 4 slots no gain together) 362self .assertEqual (setup .own_path_parallel_recommend (fam ,"UD-Q4_K_XL" ,12.0 ,8192 ),4 ) 363self .assertEqual (setup .own_path_parallel_recommend (fam ,"UD-Q4_K_XL" ,12.0 ,32768 ),0 ) 364self .assertEqual (setup .own_path_parallel_recommend (fam ,"UD-Q4_K_XL" ,16.0 ,32768 ),2 ) 365self .assertEqual (setup .own_path_parallel_recommend (fam ,"UD-Q4_K_XL" ,12.0 ,131072 ),0 ) 366self .assertEqual (setup .own_path_parallel_recommend (fam ,"UD-Q4_K_XL" ,8.0 ,32768 ),0 ) 367# a card that holds every expert for ONE session only is not offered more: 4 slots on a 32 GB R9700 at 128K left 368# 15 of 256 experts per layer in VRAM and decode ran 81 tok/s against ~180 369self .assertEqual (setup .own_path_parallel_recommend (fam ,"UD-Q4_K_XL" ,31.9 ,131072 ),0 ) 370rc ,out = self .install (model = "UD-Q4_K_XL" ,vram = 12.0 ,vision = "no" ,context = 8192 ) 371self .assertNotIn ("parallel" ,self .cfg ) 372self .assertIn ("--parallel 4" ,out ) 373self .assertIn ("does not hold every expert" ,out ) 374self .assertIn ("a request alone runs about 4-11% slower" ,out ) 375self .assertIn ("WITH the draft layer" ,out ) 376rc ,out = self .install (model = "UD-Q4_K_XL" ,vram = 12.0 ,vision = "no" ,context = 8192 ,parallel = 6 ) 377self .assertEqual (self .cfg ["parallel" ],6 ) 378self .assertIn ("recommended for this card: 4" ,out ) 379self .assertIn ("kept as you chose" ,out ) 380rc ,out = self .install (model = "UD-Q4_K_XL" ,vram = 8.0 ,vision = "no" ,parallel = 4 ,context = 131072 )# (8K, the 8 GB card's mark since #5715, has room for 2) 381self .assertEqual (self .cfg ["parallel" ],4 ) 382self .assertIn ("recommended for this card: one at a time" ,out ) 383self .assertIn ("kept as you chose" ,out ) 384rc ,out = self .install (model = "UD-Q4_K_XL" ,vram = 12.0 ,vision = "no" ,context = 8192 ,parallel = 1 ) 385self .assertEqual (self .cfg ["parallel" ],1 ) 386rc ,out = self .install (model = "UD-Q4_K_XL" ,vram = 32.0 ,vision = "no" ,parallel = 12 ) 387self .assertIn ("at most 8" ,out ) 388self .assertEqual (self .cfg ["parallel" ],12 )# written as asked; the server and the engine cap it 389self .assertGreater (setup .own_path_parallel_slot_gb (fam ,32768 ),1.4 ) 390 391def test_parallel_is_asked_when_attended_and_enter_keeps_one_at_a_time (self ): 392asked = [] 393 394def ask (question ,choices ,default ,yes ): 395if "requests at once" not in question : 396return default # size, context, images: the recommended answers 397asked .append ((question ,default )) 398return answers .pop (0 ) 399for answers ,want in ((["1" ],None ), (["3" ],3 )): 400self .cfg = {} 401with mock .patch .object (setup ,"ask" ,ask ): 402rc ,out = self .install (model = "UD-Q4_K_XL" ,vram = 12.0 ,vision = "no" ,context = 8192 ,yes = False ) 403self .assertEqual (rc ,0 ,out ) 404self .assertEqual (self .cfg .get ("parallel" ),want ) 405self .assertIn ("--parallel 4" ,out )# the offer and its price are said before the question 406self .assertEqual (out .count ("Several requests at once (opt-in)" ),1 ) 407self .assertTrue (all (d == "1" for _ ,d in asked ))# Enter = one at a time 408# a card with no room for a second session is not asked 409asked .clear () 410with mock .patch .object (setup ,"ask" ,ask ): 411rc ,out = self .install (model = "UD-Q4_K_XL" ,vram = 8.0 ,vision = "no" ,yes = False ,context = 131072 ) 412self .assertEqual (asked , []) 413self .assertNotIn ("parallel" ,self .cfg ) 414 415def test_config_read_back (self ): 416self .install (model = "UD-Q6_K_XL" ,context = 65536 ) 417p = self .root / "strata-qwen36-ud-q6_k_xl.json" 418p .write_text (json .dumps (self .cfg ),encoding = "utf-8" ) 419ch = setup .choices_from_config (p ) 420self .assertEqual ((ch ["family" ],ch ["model" ],ch ["context" ]), ("qwen36" ,"UD-Q6_K_XL" ,65536 )) 421self .assertEqual (ch ["vision" ],"cpu" )# 16 GB NVIDIA, the default answer: the CPU encoder under 24 GB 422self .assertTrue (setup .own_path_config (self .cfg )) 423self .assertEqual (setup .calibration_targets ([p ],None ,None ), [])# the tuning is Flash-Next's 424 425 426if __name__ == "__main__" : 427unittest .main ()