okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
c65b9f8be
main
1"""The NVIDIA split's prompt-path defaults (src/split), as pictures of the sources (no GPU). 2 30.2.10.1 (owner 11-03, "do all 5"): 4* FNX_PF_ROWS: 8192 prompt rows a chunk on NVIDIA (the expert kernels cost ~30 percent less a token); FNX_PF_ROWS=4096 is the old chunk. 5* FNX_PF_HCSPLIT: the hyper-connection read of a chunk runs on one card's rows each. Mode 2 is the default, used only when every card's start-up calibration 6found the cublasLt algorithm (else the read stays on both cards); mode 1 is bit-identical to the unsplit read (whole 4096-row chunks only); 0 turns it off. 7* FNX_PFX_ATTN_I8 on, FNX_PFX_GDN_TC on except for the IQ3_S-type files (routed experts in IQ2_S/IQ3_XXS/IQ3_S/Q2_0), decided in the engine from the file; 8the variables override both ways. 9""" 10 11from __future__import annotations 12 13import re 14import unittest 15from pathlib import Path 16 17ROOT = Path (__file__ ).resolve ().parents [2 ] 18SRC = ROOT / "src" / "split" / "src" 19 20 21def text (name :str )-> str : 22return (SRC / name ).read_text (encoding = "utf-8" ) 23 24 25class HcSplit (unittest .TestCase ): 26def test_default_is_on_and_needs_the_calibrated_algorithm (self ): 27s = text ("prefill.cu" ) 28self .assertRegex (s ,r'p->hcs_mode = \(int\) env_int\("FNX_PF_HCSPLIT", 2\)' ) 29# the split runs on every card or on none, and only with the calibrated algorithm on every card (either mode) 30self .assertRegex (s ,r"all = all && pf_\[c\]->hcs && pf_\[c\]->down_lt;" ) 31# mode 1 (exact): a pass is split only when every chunk is a whole 4096 rows, the sizes the algorithm was calibrated at 32self .assertRegex (s ,r"hcs_mode == 1 && \(!pf_\[0\]->down_lt \|\| \(int\) ck\.tokens\.size\(\) != 4096\)" ) 33self .assertIn ("if (n != 4096 && n != 2048) return false;" ,s ) 34self .assertRegex (s ,r'env_int\("FNX_PF_HCSPLIT_MIN", 3\)' )# fewer than 3 chunks in a pass: not split 35 36def test_nvidia_only (self ): 37s = text ("prefill.cu" ) 38i = s .index ('p->hcs_mode = (int) env_int("FNX_PF_HCSPLIT"' ) 39self .assertIn ("#if !FNX_HIP" ,s [i - 200 :i ])# the AMD build never splits the read 40self .assertIn ("NCARD == 2" ,s [i :i + 400 ]) 41self .assertIn ("CUDA::cublasLt" , (ROOT / "src" / "split" / "CMakeLists.txt" ).read_text (encoding = "utf-8" )) 42 43def test_chunk_of_8192_rows_on_nvidia_only_and_sized_to_the_free_memory (self ): 44e = text ("engine.cu" ) 45i = e .index (" rows = 8192;" ) 46self .assertIn ("#if !FNX_HIP" ,e [i - 80 :i ])# the AMD build keeps 4096 47self .assertIn ('env_int("FNX_PF_ROWS", rows)' ,e )# set by hand: used as given 48# the sizes tried, largest first, with the bytes they take per card (measured): UD-Q4_K_XL on 2 x 48 GB keeps only 6.5 GB and must not take 8192 x 4 49self .assertIn ("{{8192, 4, 4148}, {8192, 2, 3028}, {4096, 4, 1673}, {4096, 2, 1112}}" ,e ) 50self .assertIn ("pf_pass_pick_ > 0 ? pf_pass_pick_" ,text ("prefill.cu" )) 51 52def test_the_sum_before_a_split_read_is_a_reduce_scatter_only (self ): 53s = text ("pf_common.cuh" ) 54self .assertIn ("bool own_out = false" ,s ) 55self .assertRegex (s ,r"o\.k == PfRingOp::PASS \|\| o\.k == PfRingOp::SIGNALA \|\| o\.k == PfRingOp::WAITA" ) 56 57def test_passes_stay_short_while_other_requests_decode (self ): 58sf = (ROOT / "src" / "split" / "tools" / "sfnx.cpp" ).read_text (encoding = "utf-8" ) 59self .assertEqual (len (re .findall (r"e\.set_pass_rows\(any_decoding\(\) \? 8192 : 0\)" ,sf )),2 )# solo and batch admissions 60self .assertIn ("void set_pass_rows(int rows)" ,text ("engine.hpp" )) 61 62 63class PerFileSwitches (unittest .TestCase ): 64def test_attention_int8_is_decided_by_the_files_expert_types (self ): 65k ,e = text ("kernels.cu" ),text ("engine.cu" ) 66# IQ3_S-type files: on (the suite shows no loss); the others (UD-Q4_K_XL lost agent-A8 and A10 with it): off; the variable overrides 67self .assertRegex (k ,r'i8_env = \(int\) env_int\("FNX_PFX_ATTN_I8", -1\)' ) 68self .assertRegex (k ,r"i8_env >= 0 \? i8_env != 0 : attn_i8_default\(\)" ) 69self .assertIn ("attn_i8_set_default(m_.g.iq_experts());" ,e ) 70 71def test_gdn_scan_is_decided_by_the_files_expert_types (self ): 72k ,g ,m = text ("kernels.cu" ),text ("gguf.cpp" ),text ("engine.cu" ) 73# the rule: IQ-type routed experts (the set convert_small_tensors converts) -> off; the variable overrides 74self .assertRegex (g ,r"mixed \|= kv\.second\.type == T_IQ2_S \|\| kv\.second\.type == T_IQ3_XXS \|\| kv\.second\.type == T_IQ3_S \|\| kv\.second\.type == T_Q2_0;" ) 75self .assertIn ("iq_experts_ = mixed;" ,g ) 76self .assertIn ("gdn_tc_set_default(!m_.g.iq_experts());" ,m ) 77self .assertRegex (k ,r'gdn_tc_env = \(int\) fnx::env_int\("FNX_PFX_GDN_TC", -1\)' ) 78self .assertRegex (k ,r"gdn_tc_env >= 0 \? gdn_tc_env != 0 : g_gdn_tc_default\.load\(\)" ) 79self .assertIn ("g_gdn_tc_default{true}" ,k ) 80 81def test_the_rule_in_python_terms (self ): 82"""The same rule as a function, over the type names a GGUF's routed experts carry (what strata_control/split_engine.py reads).""" 83iq = {"IQ2_S" ,"IQ3_XXS" ,"IQ3_S" ,"Q2_0" } 84 85def gdn_tc (expert_types ,env = None ): 86if env is not None : 87return env != "0" 88return not (set (expert_types )& iq ) 89 90self .assertFalse (gdn_tc ({"IQ4_NL" ,"IQ2_S" ,"IQ3_XXS" ,"IQ3_S" ,"Q4_0" }))# the ISTA IQ3_S set 91self .assertTrue (gdn_tc ({"Q4_K" ,"Q5_K" ,"Q5_1" ,"Q8_0" }))# UD-Q4_K_XL 92self .assertTrue (gdn_tc ({"Q8_0" })) 93self .assertTrue (gdn_tc ({"IQ3_S" },env = "1" )) 94self .assertFalse (gdn_tc ({"Q4_K" },env = "0" )) 95 96def test_one_hop_stays_a_screen_switch (self ): 97self .assertRegex (text ("engine.cu" ),r'env_int\("FNX_ONEHOP", 1\) == 2' ) 98 99 100if __name__ == "__main__" : 101unittest .main ()