okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
d59dc3e6f
main
1// Few-row experts on the FP16 prompt path (fewrows.hpp): the research switch STRATA_PF_FEWROWS and the rule that picks the 2// experts. Header-only, no GPU. 3#include <cstdio> 4 5#include "strata/prefill/fewrows.hpp" 6 7using strata::prefill::fewrows_switch ; 8using strata::prefill::fewrows_takes ; 9using strata::prefill::kFewRows ; 10using strata::prefill::kFewRowsRecBytes ; 11 12static int failed = 0 ; 13#define CHECK (x ) do { if (!(x)) { std::fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #x); ++failed; } } while (0) 14 15int main () { 16// the switch: unset or empty = the default the caller passes; "0" off; anything else on 17CHECK (!fewrows_switch (nullptr , false)); 18CHECK (fewrows_switch (nullptr , true)); 19CHECK (!fewrows_switch ("" , false)); 20CHECK (fewrows_switch ("" , true)); 21CHECK (!fewrows_switch ("0" , true)); 22CHECK (!fewrows_switch ("0" , false)); 23CHECK (fewrows_switch ("1" , false)); 24CHECK (fewrows_switch ("12" , false));// a number is not a row count any more: any non-zero value is "on" 25CHECK (fewrows_switch ("on" , false)); 26 27// the constant and the plan record: 12 rows, 24 bytes of header + one int32 destination per row 28CHECK (kFewRows == 12 ); 29CHECK (kFewRowsRecBytes == 24 + 4 * 12 ); 30CHECK (kFewRowsRecBytes %8 == 0 );// the u64 blob pointer at the start of the next record stays aligned 31 32// the rule: switch on, FP16 path, native pack, no APR, 1..kFewRows rows 33CHECK (fewrows_takes (true, true, true, false,1 )); 34CHECK (fewrows_takes (true, true, true, false,kFewRows )); 35CHECK (!fewrows_takes (true, true, true, false,0 ));// an expert with no rows is skipped elsewhere 36CHECK (!fewrows_takes (true, true, true, false,kFewRows + 1 ));// 13 rows and up: dequantize + GEMMs 37CHECK (!fewrows_takes (true, true, true, false,600 )); 38CHECK (!fewrows_takes (false, true, true, false,6 ));// switch off 39CHECK (!fewrows_takes (true, false, true, false,6 ));// MMQ or the fused kernels take the layer 40CHECK (!fewrows_takes (true, true, false, false,6 ));// a Strata pack's blob 41CHECK (!fewrows_takes (true, true, true, true,6 ));// APR: the FP16 path rotates itself 42CHECK (!fewrows_takes (true, true, true, false,-1 )); 43 44if (failed ) { 45 std::fprintf (stderr ,"fewrows_rule_test: %d failed\n" ,failed ); 46return 1 ; 47 } 48 std::printf ("fewrows_rule_test: ok\n" ); 49return 0 ; 50}