okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
e3bd5cfde
main
1"""The per-card DFlash2 window and confidence of 0.2.13 (owner 11-08, RESULTS-CONF.md): Strix Halo window 8 (conf 0.35), Blackwell cc 12.0 with >= 48 GB window 8 and conf 0.55. 2 3Every other card keeps conf and --spec 6, so its EFFECTIVE window (--spec lowered to the engine's cap, include/strata/core/draft_cap.hpp) is what it was. 4""" 5 6from __future__import annotations 7 8import hashlib 9import tempfile 10import unittest 11from pathlib import Path 12from unittest import mock 13 14from strata_control import drafting 15 16IQ3S = "qwen3.8-flash-next-iq3_s" 17Q4 = "qwen3.8-flash-next-unsloth-ud-q4_k_xl" 18V31 = "qwen3.8-flash-next-unsloth-ud-iq4_xs-v31" 19 20GIB = 1 << 30 21TUNED = b"tuned-pack-" * 200_000 22 23 24def old_cap (uma ,major ):# include/strata/core/draft_cap.hpp before 11-08 25return 5 if uma else 6 if major == 12 else 0 26 27 28def new_cap (uma ,major ,minor ,vram_bytes ):# the same file after (mirrored here; src/core/draft_cap_test.cpp tests the C++) 29if uma : 30return 8 31if major == 12 : 32return 8 if (minor == 0 and vram_bytes >= 48_000_000_000 )else 6 33return 0 34 35 36def effective (spec ,cap ): 37return min (spec ,cap )if cap > 0 else spec 38 39 40class CardWindow (unittest .TestCase ): 41def setUp (self ): 42self .tmp = tempfile .TemporaryDirectory () 43self .addCleanup (self .tmp .cleanup ) 44self .data = Path (self .tmp .name ) 45 (self .data / "dflash2" ).mkdir () 46 (self .data / "dflash2" / drafting .PACK_NAME ).write_bytes (b"s" * (2 << 20 )) 47 (self .data / "dflash2" / drafting .VOCAB_NAME ).write_bytes (b"v" * 100 ) 48self .exe = self .data / "strata" 49self .exe .write_bytes (b"--mtp-draft-vocab FILE (or --mtp DIR ... --draft-fallback ... selector codebooks: Q4_0 rows" ) 50for patcher in (mock .patch .object (drafting ,"ENGINE_SERVES_DFLASH2" ,True ), 51mock .patch .multiple (drafting ,TUNED_BYTES = len (TUNED ),TUNED_SHA256 = hashlib .sha256 (TUNED ).hexdigest ())): 52patcher .start () 53self .addCleanup (patcher .stop ) 54 55def flags (self ,name ,backend ,archs ,vram ,extra = (),user_args = None ,tuned = False ): 56tuned_file = self .data / "dflash2" / drafting .TUNED_NAME 57if tuned : 58tuned_file .write_bytes (TUNED ) 59else : 60tuned_file .unlink (missing_ok = True ) 61cfg = {"model_name" :name ,"args" : ["--native" ,"m.gguf" ,* extra ],"drafting" :"dflash2" } 62if user_args : 63cfg ["user_args" ]= list (user_args ) 64with mock .patch .object (drafting ,"detect_hardware" ,return_value = (backend ,list (archs ))): 65d = drafting .apply (cfg ,data_dir = self .data ,backend = backend ,archs = list (archs ),engine = self .exe ,vram_mib = vram ) 66self .assertEqual (d .drafter ,"dflash2" ) 67a = cfg ["args" ] 68return a [a .index ("--spec" )+ 1 ],a [a .index ("--draft-conf" )+ 1 ] 69 70def test_the_constants (self ): 71self .assertEqual ((drafting .SPEC_WINDOW ,drafting .WIDE_WINDOW ,drafting .DRAFT_CONF ), (6 ,8 ,0.35 )) 72self .assertEqual (drafting .BIG_CARD_BYTES ,48_000_000_000 ) 73 74def test_strix_halo_window_8_conf_unchanged (self ): 75for name in (IQ3S ,Q4 ,V31 ): 76self .assertEqual (self .flags (name ,"hip" , ["gfx1151" ],None ), ("8" ,"0.35" ),name ) 77 78def test_blackwell_cc_12_0_with_48_gb_or_more (self ): 79"""Window 8 for every set; conf 0.55 for IQ3_S only (the set measured there) and only with the tuned pack.""" 80for mib in (73728 ,73415 ,49152 ,49140 ,98304 ,45777 ):# 72 GB, the l620 reading, 48 GiB, an RTX A6000-class 48 GB, 96 GB, the 48e9 byte line 81self .assertEqual (self .flags (IQ3S ,"cuda" , ["sm_120" ],mib ,tuned = True ), ("8" ,"0.55" ),mib ) 82self .assertEqual (self .flags (IQ3S ,"cuda" , ["sm_120" ],mib ), ("8" ,"0.35" ),"the stock pack was not measured at 0.55" ) 83for name in (V31 ,Q4 ): 84self .assertEqual (self .flags (name ,"cuda" , ["sm_120" ],mib ,tuned = True ), ("8" ,"0.35" ), (name ,mib )) 85self .assertEqual (self .flags (name ,"cuda" , ["sm_120" ],mib ), ("8" ,"0.35" ), (name ,mib )) 86 87def test_blackwell_cc_12_0_under_48_gb_keeps_today (self ): 88for mib in (32768 ,24576 ,16384 ,12288 ,45776 ,None ):# RTX 5090 32 GB .. 5070 12 GB, just under the line, memory unknown (several cards) 89self .assertEqual (self .flags (IQ3S ,"cuda" , ["sm_120" ],mib ,tuned = True ), ("6" ,f" { drafting . conf_for ( 'cuda' , drafting . slots_of ([], mib )):g } " ),mib )# the slot rule, as before 90self .assertEqual (self .flags (IQ3S ,"cuda" , ["sm_120" ],32768 )[1 ],"0.35" ) 91 92def test_the_spark_is_unchanged (self ): 93for tuned in (False ,True ): 94self .assertEqual (self .flags (IQ3S ,"cuda" , ["sm_121" ],None ,tuned = tuned ), ("6" ,"0.35" )) 95self .assertEqual (self .flags (V31 ,"cuda" , ["sm_121" ],None ,tuned = tuned ), ("6" ,"0.35" )) 96self .assertEqual (self .flags (IQ3S ,"cuda" , ["sm_121" ],131072 ,tuned = tuned ), ("6" ,"0.35" ),"even when a reading of its pool is passed" ) 97 98def test_the_big_card_with_a_small_expert_cache_keeps_the_slot_rule (self ): 99self .assertEqual (self .flags (IQ3S ,"cuda" , ["sm_120" ],73728 ,extra = ["--expert-cache" ,"1000" ],tuned = True ), ("6" ,"0.8" )) 100 101def test_other_cards_are_unchanged (self ): 102for backend ,archs ,mib in (("cuda" , ["sm_86" ],12288 ), ("cuda" , ["sm_89" ],24576 ), ("cuda" , ["sm_90" ],81920 ), ("cuda" , ["sm_86" ],49152 ), ("hip" , ["gfx1201" ],32768 ), 103 ("hip" , ["gfx1100" ],24576 ), ("hip" , ["gfx1103" ],None ), ("sycl" , ["arc_a" ],None ), ("metal" , [],None )): 104spec ,conf = self .flags (Q4 if backend == "hip" else V31 ,backend ,archs ,mib ) 105self .assertEqual (spec ,"6" , (backend ,archs )) 106self .assertEqual (conf ,f" { drafting . conf_for ( backend , drafting . slots_of ([], mib )):g } " , (backend ,archs ))# the stock pack here: the backend's own rule 107 108def test_the_persons_own_flags_win (self ): 109self .assertEqual (self .flags (IQ3S ,"cuda" , ["sm_120" ],73728 ,user_args = ["--draft-conf" ,"0.4" ,"--spec" ,"5" ],extra = ["--draft-conf" ,"0.4" ,"--spec" ,"5" ],tuned = True )[1 ],"0.4" ) 110cfg = {"model_name" :IQ3S ,"args" : ["--native" ,"m.gguf" ,"--spec" ,"5" ],"user_args" : ["--spec" ,"5" ],"drafting" :"dflash2" } 111with mock .patch .object (drafting ,"detect_hardware" ,return_value = ("hip" , ["gfx1151" ])): 112drafting .apply (cfg ,data_dir = self .data ,backend = "hip" ,archs = ["gfx1151" ],engine = self .exe ) 113self .assertEqual (cfg ["args" ].count ("--spec" ),1 ) 114self .assertEqual (cfg ["args" ][cfg ["args" ].index ("--spec" )+ 1 ],"5" ) 115 116def test_no_card_but_the_two_classes_changes_its_effective_window (self ): 117"""--spec as written, lowered to the engine's cap: the same number as before for every card but Strix Halo (5 -> 8) and the large Blackwell class (6 -> 8).""" 118cards = [("hip" , ["gfx1151" ],None ,True ,0 ,0 ,0 )] 119for mib ,major ,minor in ((73728 ,12 ,0 ), (98304 ,12 ,0 ), (49152 ,12 ,0 ), (32768 ,12 ,0 ), (16384 ,12 ,0 ), (12288 ,12 ,0 ), (None ,12 ,0 ), (131072 ,12 ,1 ), (None ,12 ,1 ), 120 (12288 ,8 ,6 ), (24576 ,8 ,9 ), (81920 ,9 ,0 ), (49152 ,8 ,6 ), (73728 ,10 ,0 )): 121cards .append (("cuda" , [f"sm_ { major } { minor } " ],mib ,False ,major ,minor , (mib or 0 )* (1 << 20 ))) 122for backend ,archs ,mib ,uma ,major ,minor ,vram in (* cards , ("hip" , ["gfx1201" ],32768 ,False ,0 ,0 ,0 ), ("hip" , ["gfx1100" ],24576 ,False ,0 ,0 ,0 ), ("sycl" , ["arc_a" ],None ,False ,0 ,0 ,0 ), ("metal" , [],None ,False ,0 ,0 ,0 )): 123spec = int (self .flags (IQ3S if backend != "hip" else Q4 ,backend ,archs ,mib )[0 ]) 124old = effective (6 ,old_cap (uma ,major )) 125new = effective (spec ,new_cap (uma ,major ,minor ,vram )) 126big = backend == "cuda" and major == 12 and minor == 0 and vram >= 48_000_000_000 127want = 8 if (uma or big )else old 128self .assertEqual (new ,want , (backend ,archs ,mib ,"old" ,old )) 129 130 131if __name__ == "__main__" : 132unittest .main ()