okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
b82a36810
main
1"""A feed model of another shape than the shipped expert profile gets a neutral profile (found by the Q4-P8 rehearsal: the engine refused the shipped 48x512 one for a 4x256 model).""" 2import struct 3import sys 4import tempfile 5import unittest 6from pathlib import Path 7 8ROOT = Path (__file__ ).resolve ().parents [1 ] 9sys .path .insert (0 ,str (ROOT )) 10from strata_control import setup_config # noqa: E402 11 12 13class Fake : 14def __init__ (self ,layers ,experts ): 15self .metadata = {"qwen4exp.block_count" :layers ,"qwen4exp.expert_count" :experts ,"general.name" :"x" } 16 17def __call__ (self ,path ): 18return self 19 20 21class NeutralProfile (unittest .TestCase ): 22def test_the_shipped_shape_keeps_the_shipped_profile (self ): 23shipped = ROOT / "data" / "expert-profile.bin" 24with tempfile .TemporaryDirectory ()as d : 25self .assertEqual (setup_config .neutral_profile_if_other_shape (shipped ,"x.gguf" ,d ,Fake (48 ,512 )),shipped ) 26self .assertEqual (list (Path (d ).iterdir ()), []) 27 28def test_another_shape_gets_every_pair_once_in_the_engines_format (self ): 29shipped = ROOT / "data" / "expert-profile.bin" 30with tempfile .TemporaryDirectory ()as d : 31said = [] 32out = setup_config .neutral_profile_if_other_shape (shipped ,"x.gguf" ,d ,Fake (4 ,256 ),said .append ) 33self .assertEqual (out .name ,"expert-profile-4x256.bin" ) 34blob = out .read_bytes () 35self .assertEqual (blob [:4 ],b"STRP" ) 36ver ,nl ,ne ,slots ,n = struct .unpack_from ("<5I" ,blob ,4 ) 37self .assertEqual ((ver ,nl ,ne ,slots ,n ), (1 ,4 ,256 ,1024 ,1024 )) 38pairs = [struct .unpack_from ("<HH" ,blob ,24 + 4 * i )for i in range (n )] 39self .assertEqual (len (set (pairs )),1024 ) 40self .assertEqual (pairs [:5 ], [(0 ,0 ), (1 ,0 ), (2 ,0 ), (3 ,0 ), (0 ,1 )])# interleaved across the layers 41self .assertEqual (len (blob ),24 + 4 * n + 4 * nl * ne ) 42self .assertEqual (said , [" This model's shape differs from Flash-Next, so a neutral expert profile is used." ])# the owner's wording 43 44 45if __name__ == "__main__" : 46unittest .main ()