okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
aba4ddaca
main
1"""One drafter per run, from every way in (owner, 2026-11-02): DFlash2 alone or the MTP alone, never both. 2 3strata_control/drafting.py decides; the app (apps/host, through Control and serve/server.py) and the Terminal (strata launch, its Drafting step, a saved preset) 4both end at serve/server.py engine_args(). These tests lock in the engine arguments of every choice on the main backends, the old saved values, and the Terminal 5path from the launch settings to the argument list. (tests/terminal/test_drafting.py has the table, the flags and the downloads one by one.) 6""" 7 8from __future__import annotations 9 10import tempfile 11import unittest 12from pathlib import Path 13from unittest import mock 14 15from strata_cli .launch import settings as S 16from strata_cli .launch .runner import derive_config 17from strata_control import drafting 18 19NAMES = {"qwen" :"qwen3.8-flash-next-iq3_s" ,"gyro" :"qwen3.8-flash-next-gyro-gyro-s" ,"unsloth" :"qwen3.8-flash-next-unsloth-ud-q4_k_xl" , 20"coder" :"qwen3.8-flash-next-coder-iq1_m" ,"nvfp4" :"qwen3.8-flash-next-nvfp4-nvfp4" ,"swift" :"qwen3.8-flash-next-swift-q4_k_m" } 21HARDWARE = (("cuda" , ["sm_120" ]), ("cuda" , ["sm_86" ]), ("cuda" , ["sm_89" ]), ("hip" , ["gfx1151" ]), ("hip" , ["gfx1201" ]), ("metal" , []), ("sycl" , ["arc_a" ])) 22MTP_ONLY = ("--mtp" ,"--mtp-q4" ,"--batch-mtp" ,"--spec-min-p" ,"--mtp-draft-vocab" ) 23 24 25def flag (args ,name ): 26return args [args .index (name )+ 1 ]if name in args and args .index (name )+ 1 < len (args )else None 27 28 29def loaded (args ): 30"""The drafters this argument list loads: 'dflash2' for `--draft dflash2`, 'mtp' for an MTP layer folder (`--mtp <folder>` with no DFlash2).""" 31found = set () 32if flag (args ,"--draft" )== "dflash2" : 33found .add ("dflash2" ) 34elif "--mtp" in args : 35found .add ("mtp" ) 36return found 37 38 39class Base (unittest .TestCase ): 40def setUp (self ): 41self .tmp = tempfile .TemporaryDirectory () 42self .addCleanup (self .tmp .cleanup ) 43self .data = Path (self .tmp .name )/ "data" 44 (self .data / "dflash2" ).mkdir (parents = True ) 45 (self .data / "mtp" / "rt" ).mkdir (parents = True ) 46 (self .data / "packs" / "tag" ).mkdir (parents = True ) 47 (self .data / "dflash2" / drafting .PACK_NAME ).write_bytes (b"x" * (2 << 20 )) 48 (self .data / "dflash2" / drafting .VOCAB_NAME ).write_bytes (b"v" * 100 ) 49 (self .data / "mtp" / "rt" / "experts.bin" ).write_bytes (b"e" * 100 ) 50 (self .data / "mtp" / "rt" / drafting .VOCAB_NAME ).write_bytes (b"v" * 100 ) 51self .exe = Path (self .tmp .name )/ "strata-engine" 52self .exe .write_bytes (b"--mtp-draft-vocab FILE (or --mtp DIR ... --draft-fallback" )# an engine of the usual form (rc1 and later) 53self .args = ["--native" ,"m.gguf" ,"--pack" ,str (self .data / "packs" / "tag" ),"--mtp" ,str (self .data / "mtp" / "rt" ),"--spec" ,"4" ,"--batch-mtp" , 54"--mtp-q4" ,"all" ,"--spec-min-p" ,"0.5" ,"--max-context" ,"131072" ] 55 56def cfg (self ,family = "qwen" ,** extra ): 57return {"model_name" :NAMES [family ],"args" :list (self .args ),** extra } 58 59def apply (self ,cfg ,family = "qwen" ,backend = "cuda" ,archs = ("sm_120" ,),** kw ): 60d = drafting .apply (cfg ,data_dir = self .data ,family = family ,backend = backend ,archs = list (archs ),engine = self .exe ,** kw ) 61return d ,cfg ["args" ] 62 63 64class EveryChoiceOnEveryBackend (Base ): 65def test_auto_dflash2_and_the_unset_choice_load_dflash2_alone (self ): 66for backend ,archs in HARDWARE : 67for family in ("qwen" ,"gyro" ,"unsloth" ): 68for mode in (None ,"auto" ,"dflash2" ): 69cfg = self .cfg (family ,** ({}if mode is None else {"drafting" :mode })) 70d ,args = self .apply (cfg ,family ,backend ,archs ) 71where = (backend ,archs ,family ,mode ) 72if archs == ["gfx1201" ]and mode != "dflash2" :# Auto on gfx1201 is the MTP until PE-RDNA4's fix (drafting.AUTO_MTP) 73self .assertEqual ((d .drafter ,loaded (args )), ("mtp" , {"mtp" }),where ) 74continue 75if (backend ,family )== ("metal" ,"qwen" )and mode != "dflash2" :# IQ3_S on a Mac: the MTP until the owner says otherwise (drafting.SET_DEFAULTS) 76self .assertEqual ((d .drafter ,loaded (args )), ("mtp" , {"mtp" }),where ) 77continue 78self .assertEqual (d .drafter ,"dflash2" ,where ) 79self .assertEqual (loaded (args ), {"dflash2" },where ) 80self .assertEqual (flag (args ,"--draft-fallback" ),"none" ,where ) 81self .assertEqual (flag (args ,"--draft-model" ),str (drafting .pack_path (self .data ,self .exe )),where ) 82self .assertTrue (flag (args ,"--mtp-draft-vocab" ),where ) 83for name in ("--mtp" ,"--mtp-q4" ,"--batch-mtp" ,"--spec-min-p" ): 84self .assertNotIn (name ,args , (name ,where )) 85 86def test_mtp_loads_the_mtp_alone (self ): 87for backend ,archs in HARDWARE : 88for family in ("qwen" ,"gyro" ,"unsloth" ): 89d ,args = self .apply (self .cfg (family ,drafting = "mtp" ),family ,backend ,archs ) 90where = (backend ,archs ,family ) 91self .assertEqual ((d .drafter ,loaded (args )), ("mtp" , {"mtp" }),where ) 92self .assertFalse ([a for a in args if a .startswith ("--draft" )],where ) 93self .assertNotIn ("dflash2" ," " .join (args ),where ) 94 95def test_off_loads_neither (self ): 96for backend ,archs in HARDWARE : 97d ,args = self .apply (self .cfg (drafting = "off" ),"qwen" ,backend ,archs ) 98self .assertEqual ((d .drafter ,loaded (args )), ("off" ,set ()), (backend ,archs )) 99self .assertFalse ([a for a in args if a in MTP_ONLY or a .startswith ("--draft" )]) 100 101def test_no_engine_with_the_code_means_the_mtp_for_auto (self ): 102for backend in (None ,"cpu" ): 103for mode in (None ,"auto" ,"dflash2" ): 104d ,args = self .apply (self .cfg (** ({}if mode is None else {"drafting" :mode })),"qwen" ,backend , ()) 105self .assertEqual ((d .drafter ,loaded (args )), ("mtp" , {"mtp" }), (backend ,mode )) 106 107def test_other_families_never_get_dflash2_whatever_is_saved (self ): 108for family in ("coder" ,"nvfp4" ,"swift" ): 109for mode in (None ,"auto" ,"mtp" ,"dflash2" ): 110cfg = self .cfg (family ,** ({}if mode is None else {"drafting" :mode })) 111d ,args = self .apply (cfg ,family ,"cuda" , ("sm_120" ,)) 112self .assertNotIn ("--draft" ,args , (family ,mode )) 113self .assertEqual (loaded (args ), {"mtp" }, (family ,mode )) 114 115def test_several_requests_load_the_mtp_alone_for_auto (self ): 116for mode in (None ,"auto" ): 117d ,args = self .apply (self .cfg (** ({}if mode is None else {"drafting" :mode })),slots = 4 ) 118self .assertEqual ((d .drafter ,d .note ,loaded (args )), ("mtp" ,drafting .NOT_HERE , {"mtp" }),mode ) 119self .assertFalse ([a for a in args if a .startswith ("--draft" )]) 120d ,args = self .apply (self .cfg (drafting = "mtp" ),slots = 4 ) 121self .assertEqual ((d .drafter ,d .note ,loaded (args )), ("mtp" ,"" , {"mtp" })) 122 123def test_several_requests_keep_dflash2_when_the_person_chose_it_by_name (self ): 124"""Owner 2026-11-03: the person's own choice wins (DFlash2 named + a number of requests = DFlash2 with that many), on every backend that runs it.""" 125for backend ,archs in HARDWARE : 126for slots in (2 ,4 ,8 ): 127d ,args = self .apply (self .cfg (drafting = "dflash2" ),"qwen" ,backend ,archs ,slots = slots ) 128if backend == "metal" : 129# the Metal engine has no per-request drafters: DFlash2 beside request slots would draft nothing, so today's behaviour stays (owner 2026-11-03) 130self .assertEqual ((d .drafter ,d .note ,loaded (args )), ("mtp" ,drafting .NOT_HERE , {"mtp" }), (backend ,slots )) 131self .assertFalse ([a for a in args if a .startswith ("--draft" )]) 132continue 133self .assertEqual ((d .drafter ,d .note ,loaded (args )), ("dflash2" ,"" , {"dflash2" }), (backend ,slots )) 134self .assertNotIn ("--mtp" ,args ) 135d ,args = self .apply (self .cfg (drafting = "dflash2" ),"qwen" ,"metal" , (),slots = 1 ) 136self .assertEqual ((d .drafter ,d .note ), ("dflash2" ,"" ),"one request on Metal is DFlash2 as before" ) 137self .assertTrue (drafting .blocked_by ([],slots = 4 ,named = True ,backend = "metal" )) 138self .assertTrue (drafting .blocked_by (["--batch" ,"3" ],named = True ,backend = "Metal" )) 139self .assertFalse (drafting .blocked_by ([],slots = 4 ,named = True ,backend = "cuda" )) 140 141def test_a_layer_split_runs_dflash2_alone_like_one_card (self ): 142"""Owner 2026-11-02: Auto is DFlash2 on a layer split over several cards too (the 0.1.56 engine runs it; paired decode 1.014 against the MTP).""" 143for backend ,archs in (("cuda" , ["sm_120" ]), ("cuda" , ["sm_86" ]), ("hip" , ["gfx1151" ]), ("hip" , ["gfx1100" ])):# (gfx1201: Auto is the MTP for now, drafting.AUTO_MTP; test_drafting_auto_mtp.py) 144for mode in (None ,"auto" ,"dflash2" ): 145cfg = self .cfg (** ({}if mode is None else {"drafting" :mode })) 146one ,args_one = self .apply (dict (cfg ,args = list (cfg ["args" ])),"qwen" ,backend ,archs ) 147two ,args_two = self .apply (dict (cfg ,args = list (cfg ["args" ])),"qwen" ,backend ,archs ,split = True ) 148self .assertEqual ((two .drafter ,two .note ,loaded (args_two )), ("dflash2" ,"" , {"dflash2" }), (backend ,mode )) 149self .assertEqual (args_two ,args_one ,"the same arguments as one card" ) 150self .assertNotIn ("--mtp" ,args_two ) 151d ,args = self .apply (self .cfg (drafting = "mtp" ),"qwen" ,backend ,archs ,split = True ) 152self .assertEqual ((d .drafter ,d .note ,loaded (args )), ("mtp" ,"" , {"mtp" }),backend ) 153self .assertFalse ([a for a in args if a .startswith ("--draft" )]) 154# a saved argument list that already names the layer split changes nothing either 155d ,args = self .apply (self .cfg (args = [* self .args ,"--layer-split" ,"auto" ],drafting = "auto" )) 156self .assertEqual ((d .drafter ,loaded (args )), ("dflash2" , {"dflash2" })) 157self .assertEqual (flag (args ,"--layer-split" ),"auto" ) 158 159def test_a_missing_file_runs_the_other_drafter_alone_and_says_so (self ): 160 (self .data / "dflash2" / drafting .PACK_NAME ).unlink () 161for mode in (None ,"auto" ,"dflash2" ): 162d ,args = self .apply (self .cfg (** ({}if mode is None else {"drafting" :mode }))) 163self .assertEqual ((d .drafter ,d .note ,loaded (args )), ("mtp" ,drafting .NOT_DOWNLOADED , {"mtp" }),mode ) 164 (self .data / "dflash2" / drafting .PACK_NAME ).write_bytes (b"x" * (2 << 20 )) 165 (self .data / "mtp" / "rt" / "experts.bin" ).unlink () 166d ,args = self .apply (self .cfg (drafting = "mtp" )) 167self .assertEqual ((d .drafter ,d .note ,loaded (args )), ("dflash2" ,drafting .NO_MTP , {"dflash2" })) 168 169 170class OldSavedValues (Base ): 171def test_a_value_nobody_writes_any_more_is_auto (self ): 172for old in ("both" ,"mtp+dflash2" ,"dflash2+mtp" ,"dflash" ,"" ,None ,True ,1 ,"fastest" ): 173self .assertEqual (drafting .normalize (old ),"auto" ,old ) 174for same in ("DFlash2" ," dflash2 " ): 175self .assertEqual (drafting .normalize (same ),"dflash2" ,same ) 176for same in ("MTP" ," mtp " ): 177self .assertEqual (drafting .normalize (same ),"mtp" ,same ) 178 179def test_every_old_value_loads_one_drafter (self ): 180for old in ("both" ,"mtp+dflash2" ,"dflash2+mtp" ,"dflash" ,"" ,None ,True ,"DFlash2" ,"MTP" ): 181d ,args = self .apply (self .cfg (drafting = old )) 182self .assertEqual (len (loaded (args )),1 ,old ) 183self .assertEqual (loaded (args ), {"mtp" }if str (old ).strip ().lower ()== "mtp" else {"dflash2" },old ) 184 185def test_a_saved_argument_list_that_names_both_drafters_starts_with_the_one_chosen (self ): 186both = [* self .args ,"--draft" ,"dflash2" ,"--draft-model" ,"old.pack" ,"--draft-fallback" ,"mtp" ,"--draft-conf" ,"0.5" ] 187for mode ,want in ((None ,"dflash2" ), ("auto" ,"dflash2" ), ("dflash2" ,"dflash2" ), ("mtp" ,"mtp" ), ("both" ,"dflash2" )): 188cfg = {"model_name" :NAMES ["qwen" ],"args" :list (both ),** ({}if mode is None else {"drafting" :mode })} 189d ,args = self .apply (cfg ) 190self .assertEqual (loaded (args ), {want },mode ) 191if want == "dflash2" : 192self .assertEqual (flag (args ,"--draft-fallback" ),"none" ,mode ) 193self .assertNotIn ("--mtp" ,args ,mode ) 194else : 195self .assertNotIn ("--draft" ,args ,mode ) 196self .assertNotIn ("--draft-fallback" ,args ,mode ) 197 198def test_the_mtp_switch_off_with_no_choice_is_no_drafter_but_a_choice_wins (self ): 199d ,args = self .apply (self .cfg (mtp = False )) 200self .assertEqual ((d .drafter ,loaded (args )), ("off" ,set ())) 201d ,args = self .apply (self .cfg (mtp = False ,drafting = "mtp" )) 202self .assertEqual ((d .drafter ,loaded (args )), ("mtp" , {"mtp" })) 203d ,args = self .apply (self .cfg (mtp = False ,drafting = "dflash2" )) 204self .assertEqual ((d .drafter ,loaded (args )), ("dflash2" , {"dflash2" })) 205 206 207class TheServerAndTheTerminalEndAtTheSameArguments (Base ): 208"""serve/server.py engine_args() is where the app's Load (through Control's saved profile), `strata launch` and the Terminal's steps all arrive.""" 209 210def server_args (self ,cfg ,backend = "cuda" ,archs = ("sm_120" ,)): 211from serve .server import engine_args 212with mock .patch .object (drafting ,"detect_hardware" ,return_value = (backend ,list (archs ))),mock .patch ("serve.server.drafting_vram_mib" ,return_value = None ), \ 213mock .patch .object (drafting ,"installed_engine_exe" ,return_value = self .exe ): 214return engine_args (cfg ,str (self .exe ),announce = False ) 215 216def test_each_choice_through_the_server (self ): 217for backend ,archs in HARDWARE : 218for mode ,want in ((None , {"dflash2" }), ("auto" , {"dflash2" }), ("dflash2" , {"dflash2" }), ("mtp" , {"mtp" }), ("off" ,set ())): 219args = self .server_args (self .cfg (** ({}if mode is None else {"drafting" :mode })),backend ,archs ) 220if backend == "metal" and mode in (None ,"auto" ):# NAMES["qwen"] is IQ3_S: the MTP on a Mac (drafting.SET_DEFAULTS) 221want = {"mtp" } 222if archs == ["gfx1201" ]and mode in (None ,"auto" ):# Auto on gfx1201 is the MTP until PE-RDNA4's fix (drafting.AUTO_MTP) 223want = {"mtp" } 224self .assertEqual (loaded (args ),want , (backend ,archs ,mode )) 225if want == {"dflash2" }: 226self .assertNotIn ("--mtp" ,args ) 227elif want == {"mtp" }: 228self .assertFalse ([a for a in args if a .startswith ("--draft" )]) 229 230def test_a_layer_split_through_the_server (self ): 231for backend ,archs in (("cuda" , ["sm_120" ]), ("cuda" , ["sm_86" ]), ("hip" , ["gfx1100" ])): 232for mode ,want in ((None , {"dflash2" }), ("auto" , {"dflash2" }), ("dflash2" , {"dflash2" }), ("mtp" , {"mtp" }), ("off" ,set ())): 233cfg = self .cfg (gpu = [0 ,1 ],** ({}if mode is None else {"drafting" :mode })) 234args = self .server_args (cfg ,backend ,archs ) 235where = (backend ,archs ,mode ) 236self .assertEqual (loaded (args ),want ,where ) 237self .assertIn ("--layer-split" ,args ,where ) 238if want == {"dflash2" }: 239self .assertEqual (flag (args ,"--draft-fallback" ),"none" ,where ) 240self .assertNotIn ("--mtp" ,args ,where ) 241elif want == {"mtp" }: 242self .assertFalse ([a for a in args if a .startswith ("--draft" )],where ) 243 244def test_a_layer_split_with_several_requests_is_the_mtp_alone_for_auto_and_dflash2_with_dflash2_by_name (self ): 245args = self .server_args (self .cfg (gpu = [0 ,1 ],parallel = 4 ,drafting = "auto" )) 246self .assertEqual (loaded (args ), {"mtp" },"Auto" ) 247self .assertFalse ([a for a in args if a .startswith ("--draft" )],"Auto" ) 248args = self .server_args (self .cfg (gpu = [0 ,1 ],parallel = 4 ,drafting = "dflash2" )) 249self .assertEqual (loaded (args ), {"dflash2" },"named" ) 250self .assertEqual ((flag (args ,"--draft-fallback" ),flag (args ,"--batch" )), ("none" ,"4" )) 251self .assertIn ("--layer-split" ,args ) 252self .assertNotIn ("--mtp" ,args ) 253 254def test_metal_named_dflash2_with_requests_starts_the_mtp_exactly_as_0_2_10_did (self ): 255"""Metal has no per-request drafters, so a DFlash2 chosen by name with several requests is the MTP there, with the MTP's own --batch-mtp (the saved one, or Expert mode's 256wish, which the app adds to the arguments) kept: the same arguments the MTP chosen by name gets, which is what 0.2.10 started for this case.""" 257for parallel in (2 ,4 ,8 ): 258named = self .server_args (self .cfg (drafting = "dflash2" ,parallel = parallel ),"metal" , ()) 259self .assertEqual (named ,self .server_args (self .cfg (drafting = "mtp" ,parallel = parallel ),"metal" , ()),parallel ) 260self .assertEqual (named ,self .server_args (self .cfg (parallel = parallel ),"metal" , ()),"and the same as Auto" ) 261self .assertIn ("--batch-mtp" ,named ) 262self .assertEqual ((flag (named ,"--batch" ),flag (named ,"--mtp" ),"--draft" in named ), (str (parallel ),str (self .data / "mtp" / "rt" ),False )) 263# the same saved arguments on CUDA: DFlash2 with the requests, the MTP's slot switch is taken out 264cuda = self .server_args (self .cfg (drafting = "dflash2" ,parallel = 4 )) 265self .assertEqual ((loaded (cuda ),"--batch-mtp" in cuda ,flag (cuda ,"--batch" )), ({"dflash2" },False ,"4" )) 266 267def test_the_all_cards_split_engine_still_runs_its_mtp (self ): 268from tests .split import test_split_engine as TS 269 (Path (self .tmp .name )/ "data" ).mkdir (exist_ok = True ) 270 (Path (self .tmp .name )/ "data" / "draft_vocab_en.bin" ).write_bytes (b"x" ) 271for mode in (None ,"auto" ,"mtp" ): 272cfg = {"exe" :"component:strata-engine" ,"args" : ["--pack" ,str (self .data / "packs" / "tag" ),"--native" ,"/m/a-00001-of-00004.gguf" ,"--mtp" ,str (self .data / "mtp" / "rt" ), 273"--max-context" ,"131072" ,"--layer-split" ,"auto" ], 274"cwd" :self .tmp .name ,"tokenizer" :"tok" ,"port" :8080 ,"gpu" : [0 ,1 ],"env" : {},"model_name" :NAMES ["qwen" ]} 275if mode : 276cfg ["drafting" ]= mode 277d = TS .S .apply_to_config (cfg ,exe_for_cards = lambda n ,cc = None :"/e/strata-split-2" ,system = "linux" ,probe = lambda idx :TS .cards (),ram = lambda : (125.0 ,80.0 ), 278scan = lambda path :TS .udq4 ()) 279self .assertTrue (d .use_split , (mode ,d .reasons )) 280args = self .server_args (cfg ) 281self .assertEqual (loaded (args ), {"mtp" },mode ) 282self .assertNotIn ("--draft" ,args ,mode )# (the split engine's own --draft-vocab is its draft head file, not the DFlash2 drafter) 283cfg = {"exe" :"component:strata-engine" ,"args" : ["--pack" ,str (self .data / "packs" / "tag" ),"--native" ,"/m/a-00001-of-00004.gguf" ,"--mtp" ,str (self .data / "mtp" / "rt" ),"--layer-split" ,"auto" ], 284"cwd" :self .tmp .name ,"tokenizer" :"tok" ,"port" :8080 ,"gpu" : [0 ,1 ],"env" : {},"drafting" :"dflash2" ,"model_name" :NAMES ["qwen" ]} 285d = TS .S .apply_to_config (cfg ,exe_for_cards = lambda n ,cc = None :"/e/strata-split-2" ,system = "linux" ,probe = lambda idx :TS .cards (),ram = lambda : (125.0 ,80.0 ), 286scan = lambda path :TS .udq4 ()) 287self .assertFalse (d .use_split ,"an explicit DFlash2 keeps the layer split, now with DFlash2" ) 288self .assertEqual (loaded (self .server_args (cfg )), {"dflash2" }) 289 290def test_deepseek_gets_no_drafter_arguments (self ): 291cfg = {"model_name" :"deepseek-v4.1-flash" ,"arch" :"deepseek41" ,"args" : ["--pack" ,"/d/ds" ,"--spec" ,"2" ],"drafting" :"dflash2" } 292args = self .server_args (cfg ) 293self .assertEqual ((loaded (args ), [a for a in args if a .startswith ("--draft" )]), (set (), [])) 294 295def test_the_terminal_choices_reach_the_engine_alone (self ): 296base = {"exe" :"component:strata-engine" ,"model_name" :NAMES ["qwen" ],"port" :8080 ,"args" :list (self .args )} 297for choice ,want in ((None , {"dflash2" }), ("auto" , {"dflash2" }), ("dflash2" , {"dflash2" }), ("mtp" , {"mtp" }), ("off" ,set ())): 298with mock .patch .object (drafting ,"detect_hardware" ,return_value = ("cuda" , ["sm_120" ])): 299cfg = derive_config (base ,S .LaunchSettings (drafting = choice ),bool_flags = frozenset ()) 300args = self .server_args (cfg ) 301self .assertEqual (loaded (args ),want ,choice ) 302 303def test_auto_in_the_terminal_overrides_a_choice_the_app_saved_in_the_model_file (self ): 304"""The app writes its Drafting choice into the model's own settings file; the Terminal derives its run config from that file. Choosing Auto in the Terminal's 305Drafting step has to mean Auto, not the app's older choice (the step stores what modelstate.drafting_to_save says).""" 306from strata_cli .launch import modelstate 307for saved ,key ,want in (("mtp" ,"auto" , {"dflash2" }), ("off" ,"auto" , {"dflash2" }), ("dflash2" ,"mtp" , {"mtp" }), ("mtp" ,"dflash2" , {"dflash2" }), 308 ("mtp" ,"off" ,set ()), (None ,"auto" , {"dflash2" }), ("auto" ,"auto" , {"dflash2" }), (None ,"mtp" , {"mtp" })): 309base = {"exe" :"component:strata-engine" ,"model_name" :NAMES ["qwen" ],"port" :8080 ,"args" :list (self .args ),** ({}if saved is None else {"drafting" :saved })} 310with mock .patch .object (drafting ,"detect_hardware" ,return_value = ("cuda" , ["sm_120" ])): 311cfg = derive_config (base ,S .LaunchSettings (drafting = modelstate .drafting_to_save (key ,saved )),bool_flags = frozenset ()) 312self .assertEqual (loaded (self .server_args (cfg )),want , (saved ,key )) 313 314def test_the_step_writes_nothing_for_auto_unless_the_file_holds_another_choice (self ): 315from strata_cli .launch import modelstate 316for saved in (None ,"auto" ,"AUTO" ,"both" ,"fastest" ,"" ): 317self .assertIsNone (modelstate .drafting_to_save ("auto" ,saved )if drafting .normalize (saved )== "auto" else None ,saved ) 318for saved in ("mtp" ,"dflash2" ,"off" ,"MTP" ): 319self .assertEqual (modelstate .drafting_to_save ("auto" ,saved ),"auto" ,saved ) 320for key in ("mtp" ,"dflash2" ,"off" ): 321self .assertEqual (modelstate .drafting_to_save (key ,"mtp" ),key ) 322 323 324if __name__ == "__main__" : 325unittest .main ()