okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
ba8745e13
main
1"""The long-prompt layer skip (STRATA_DS4_PROMPT_SKIP=1) against the full work: same answers within noise. 2 3Needs a GPU, a DeepSeek-V4.1 pack and the golden ids file, so it runs only when they are named: 4 5STRATA_DSV41_BIN=.../strata-dsv41 STRATA_DSV41_PACK=/data/pack2.00 STRATA_DSV41_IDS=.../logpos.ids.json \ 6python -m unittest tools.dsv41.test_prompt_skip 7 8The golden segments are joined, the first DS4_SCORE_PREFIX tokens (4200) are read as one prompt (the path a long prompt 9takes: logits of the last row only, where the skip applies), and the positions after them are scored teacher-forced. 10The skip changes only what the layers 20-39 compute for the prompt's early rows, so the scored rows' KL against the 11full work must stay at the noise of the experts' summing order. 12""" 13import os 14import pathlib 15import subprocess 16import sys 17import tempfile 18import unittest 19 20sys .path .insert (0 ,str (pathlib .Path (__file__ ).resolve ().parents [1 ])) 21import quant_quality # noqa: E402 22 23BIN = os .environ .get ("STRATA_DSV41_BIN" ) 24PACK = os .environ .get ("STRATA_DSV41_PACK" ) 25IDS = os .environ .get ("STRATA_DSV41_IDS" ) 26 27 28def keep_rows (nl = 40 ,yoco = 20 ,win = 128 ): 29"""The rows a long prompt keeps on layers yoco.. (the engine's forward_chunks): each layer looks back one window 30more than the layer before, so the last (nl - yoco) * (win - 1) + win rows.""" 31return (nl - yoco )* (win - 1 )+ win 32 33 34class PromptSkip (unittest .TestCase ): 35def test_keep_rows_is_the_chain_of_windows (self ): 36self .assertEqual (keep_rows (),2668 ) 37 38@ unittest . skipUnless ( BIN and PACK and IDS , "needs STRATA_DSV41_BIN / _PACK / _IDS" ) 39def test_scored_rows_after_a_skipped_prompt_match_the_full_work (self ): 40with tempfile .TemporaryDirectory ()as tmp : 41outs = {} 42for mode in ("0" ,"1" ): 43out = pathlib .Path (tmp )/ f"skip { mode } .tsv" 44env = dict (os .environ ,STRATA_DS4_PROMPT_SKIP = mode ,DS4_SCORE_PREFIX = "4200" ,DS4_CHUNK = "1024" ) 45subprocess .run ([BIN ,"--pack" ,PACK ,"--tp" ,"1" ,"--threads" ,"off" ,"--max-context" ,"6144" ,"--vision" , 46"off" ,"--dspark" ,"off" ,"--expert-profile" ,"none" ,"--window" ,"128" ,"--score" ,IDS , 47"--score-out" ,str (out )],check = True ,env = env ) 48outs [mode ]= quant_quality .read_run (str (out )) 49res = quant_quality .compare (outs ["0" ],outs ["1" ])["all" ] 50self .assertGreater (res ["positions" ],500 ) 51self .assertLess (res ["kl" ],0.002 ) 52self .assertGreaterEqual (res ["top1" ],0.99 ) 53 54 55if __name__ == "__main__" : 56unittest .main ()