okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
cc3f9142e
main
1"""Auto on HIP gfx1201 (RX 9070 / R9700 class) starts the MTP until PE-RDNA4's fix for the open DFlash2 prompt stall lands (owner 11-06 ~10:30; drafting.AUTO_MTP, ONE entry). 2 3Only Auto changes. DFlash2 chosen by name still starts DFlash2; gfx1151, other AMD cards, CUDA, Metal and SYCL are what they were; the confidence tables are untouched. 4""" 5 6from __future__import annotations 7 8import json 9import tempfile 10import unittest 11from pathlib import Path 12from unittest import mock 13 14from strata_control import drafting 15 16ROOT = Path (__file__ ).resolve ().parents [2 ] 17IQ3S = "qwen3.8-flash-next-iq3_s" 18Q4 = "qwen3.8-flash-next-unsloth-ud-q4_k_xl" 19V31 = "qwen3.8-flash-next-unsloth-ud-iq4_xs-v31" 20GYRO = "qwen3.8-flash-next-gyro-gyro-s" 21R9700 = ("hip" , ["gfx1201" ],32768 ) 22 23 24def flag (args ,name ): 25return args [args .index (name )+ 1 ]if name in args and args .index (name )+ 1 < len (args )else None 26 27 28class Base (unittest .TestCase ): 29def setUp (self ): 30self .tmp = tempfile .TemporaryDirectory () 31self .addCleanup (self .tmp .cleanup ) 32self .root = Path (self .tmp .name ) 33self .data = self .root / "data" 34for sub in ("dflash2" ,"mtp/rt" ,"packs/tag" ): 35 (self .data / sub ).mkdir (parents = True ) 36 (self .data / "dflash2" / drafting .PACK_NAME ).write_bytes (b"s" * (2 << 20 )) 37 (self .data / "dflash2" / drafting .VOCAB_NAME ).write_bytes (b"v" * 100 ) 38 (self .data / "mtp" / "rt" / "experts.bin" ).write_bytes (b"e" * 100 ) 39 (self .data / "mtp" / "rt" / drafting .VOCAB_NAME ).write_bytes (b"v" * 100 ) 40self .exe = self .root / "strata" 41self .exe .write_bytes (b"--mtp-draft-vocab FILE (or --mtp DIR ... --draft-fallback ... selector codebooks: Q4_0 rows" ) 42self .args = ["--native" ,"m.gguf" ,"--pack" ,str (self .data / "packs" / "tag" ),"--mtp" ,str (self .data / "mtp" / "rt" ),"--spec" ,"4" ,"--max-context" ,"65536" ] 43patcher = mock .patch .object (drafting ,"ENGINE_SERVES_DFLASH2" ,True ) 44patcher .start () 45self .addCleanup (patcher .stop ) 46 47def apply (self ,name ,hardware ,** extra ): 48backend ,archs ,vram = hardware 49cfg = {"model_name" :name ,"args" :list (self .args ),** extra } 50decision = drafting .apply (cfg ,data_dir = self .data ,backend = backend ,archs = archs ,engine = self .exe ,vram_mib = vram ) 51return decision ,cfg ["args" ] 52 53 54class Gfx1201 (Base ): 55def test_auto_is_the_mtp_for_every_set (self ): 56for name in (IQ3S ,Q4 ,V31 ,GYRO ): 57for extra in ({}, {"drafting" :"auto" }): 58before = list (self .args ) 59d ,args = self .apply (name ,R9700 ,** extra ) 60self .assertEqual ((d .drafter ,d .note ), ("mtp" ,"" ), (name ,extra )) 61self .assertFalse ([a for a in args if a .startswith ("--draft" )], (name ,extra )) 62self .assertEqual (args ,before ,"the MTP arguments exactly as saved" ) 63 64def test_dflash2_chosen_by_name_still_wins (self ): 65d ,args = self .apply (IQ3S ,R9700 ,drafting = "dflash2" ) 66self .assertEqual ((d .drafter ,d .note ), ("dflash2" ,"" )) 67self .assertEqual (flag (args ,"--draft" ),"dflash2" ) 68self .assertEqual (flag (args ,"--draft-conf" ),"0.35" ,"the R9700's own conf (12,570 slots)" ) 69self .assertNotIn ("--mtp" ,args ) 70mine = ["--draft-conf" ,"0.5" ] 71d ,args = self .apply (IQ3S ,R9700 ,drafting = "dflash2" ,user_args = mine ) 72self .assertEqual (flag (args ,"--draft-conf" ),"0.5" ,"and the person's own conf over it" ) 73 74def test_the_other_choices_are_as_they_were (self ): 75for mode ,drafter in (("mtp" ,"mtp" ), ("off" ,"off" )): 76d ,args = self .apply (IQ3S ,R9700 ,drafting = mode ) 77self .assertEqual (d .drafter ,drafter ,mode ) 78 79def test_with_no_mtp_layer_on_disk_auto_is_not_dflash2_either (self ): 80 (self .data / "mtp" / "rt" / "experts.bin" ).unlink () 81d ,args = self .apply (IQ3S ,R9700 ) 82self .assertEqual ((d .drafter ,d .note ), ("off" ,drafting .NONE_HERE )) 83self .assertFalse ([a for a in args if a .startswith ("--draft" )]) 84d ,args = self .apply (IQ3S ,R9700 ,drafting = "dflash2" ) 85self .assertEqual (d .drafter ,"dflash2" ,"named: DFlash2 as before" ) 86 87def test_what_gets_fetched (self ): 88kw = dict (model_name = IQ3S ,backend = "hip" ,archs = ["gfx1201" ],data_dir = self .root / "empty" ) 89self .assertFalse (drafting .needs_pack ("auto" ,** kw ),"no DFlash2 download for Auto" ) 90self .assertTrue (drafting .needs_pack ("dflash2" ,** kw ),"but one for DFlash2 named" ) 91self .assertFalse (drafting .needs_tuned ("auto" ,** kw )) 92self .assertTrue (drafting .needs_mtp ("auto" ,mtp_here = False ,** {k :v for k ,v in kw .items ()if k != "data_dir" })) 93self .assertFalse (drafting .wants_one_request ("auto" ,model_name = IQ3S ,backend = "hip" ,archs = ["gfx1201" ])) 94self .assertTrue (drafting .wants_one_request ("dflash2" ,model_name = IQ3S ,backend = "hip" ,archs = ["gfx1201" ])) 95 96def test_the_support_line_says_it_in_plain_words (self ): 97support = drafting .hardware_support ("hip" , ["gfx1201" ],IQ3S ) 98self .assertEqual ((support .can_run ,support .level ,support .line ), (True ,"tested" ,drafting .LINE_AUTO_MTP )) 99self .assertEqual (drafting .LINE_AUTO_MTP ,"DFlash2 is off by default on this graphics card for now; choose it in Drafting to use it." ) 100for word in ("recommend" ,"best" ,"better" ,"should" ,"avoid" ): 101self .assertNotIn (word ,drafting .LINE_AUTO_MTP .lower ()) 102en = json .loads ((ROOT / "apps" / "host" / "src" / "locales" / "df2-en.json" ).read_text (encoding = "utf-8" )) 103self .assertEqual (en ["df22" ],drafting .LINE_AUTO_MTP ) 104 105def test_it_is_one_entry_and_removing_it_puts_auto_back (self ): 106self .assertEqual (list (drafting .AUTO_MTP ), [("hip" ,"gfx1201" )]) 107self .assertIn ("stall" ,drafting .AUTO_MTP [("hip" ,"gfx1201" )]) 108with mock .patch .dict (drafting .AUTO_MTP ,clear = True ): 109d ,args = self .apply (IQ3S ,R9700 ) 110self .assertEqual ((d .drafter ,flag (args ,"--draft" )), ("dflash2" ,"dflash2" )) 111self .assertEqual (drafting .hardware_support ("hip" , ["gfx1201" ],IQ3S ).line ,drafting .LINE_TESTED ) 112 113 114class EverythingElseIsUnchanged (Base ): 115def test_gfx1151_cuda_other_amd_metal_and_sycl_still_start_dflash2_under_auto (self ): 116for hardware in (("hip" , ["gfx1151" ],None ), ("hip" , ["gfx1100" ],24576 ), ("hip" , ["gfx1200" ],16384 ), ("cuda" , ["sm_120" ],73728 ), ("cuda" , ["sm_86" ],49152 ),# (a 12 GB card has its own entry: test_drafting_streaming_class.py) 117 118 ("cuda" , ["sm_121" ],None ), ("sycl" , ["arc_a" ],None )): 119d ,args = self .apply (IQ3S ,hardware ) 120self .assertEqual ((d .drafter ,flag (args ,"--draft" )), ("dflash2" ,"dflash2" ),hardware ) 121d ,args = self .apply (Q4 , ("metal" , [],None )) 122self .assertEqual ((d .drafter ,flag (args ,"--draft" )), ("dflash2" ,"dflash2" )) 123 124def test_the_confidence_tables_and_the_other_entries_are_what_they_were (self ): 125self .assertEqual (drafting .CONF_STEPS , ((12000 ,0.35 ), (7500 ,0.5 ), (3000 ,0.7 ), (0 ,0.8 ))) 126self .assertEqual (drafting .BACKEND_CONF , {"sycl" :0.6 ,"metal" :0.5 }) 127self .assertEqual ((drafting .DRAFT_CONF ,drafting .SPEC_WINDOW ), (0.35 ,6 )) 128self .assertEqual (drafting .conf_for ("hip" ,drafting .slots_of (self .args ,32768 )),0.35 ) 129self .assertEqual (drafting .choice_of ("auto" ,model_name = IQ3S ,backend = "hip" ,archs = ["gfx1151" ]),"dflash2" ) 130self .assertEqual (drafting .choice_of ("auto" ,model_name = IQ3S ,backend = "hip" ,archs = ["gfx1201" ]),"mtp" ) 131self .assertEqual (drafting .choice_of ("dflash2" ,model_name = IQ3S ,backend = "hip" ,archs = ["gfx1201" ]),"dflash2" ) 132self .assertEqual (drafting .choice_of ("auto" ,family = "qwen" ,backend = "hip" ),"dflash2" ,"no architecture known: as before" ) 133self .assertEqual (drafting .choice_of ("auto" ,model_name = IQ3S ,backend = "cuda" ,archs = ["gfx1201" ]),"dflash2" ,"the family matters: only hip" ) 134self .assertEqual (drafting .hardware_support ("hip" , ["gfx1151" ],IQ3S ).line ,drafting .LINE_TESTED ) 135self .assertEqual (drafting .hardware_support ("cuda" , ["sm_120" ],IQ3S ).line ,drafting .LINE_TESTED ) 136 137 138if __name__ == "__main__" : 139unittest .main ()