okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
c65b9f8be
main
1// tests/program/split_walk_test.cpp - the layer split's spill walk (include/strata/program/split_walk.hpp): who is short, who is not, and what is given up in which order. 2#include "strata/program/split_walk.hpp" 3 4#include <cstdint> 5#include <cstdio> 6#include <string> 7 8using namespace strata::program::split_walk ; 9 10namespace { 11int g_fail = 0 ; 12void check (bool ok ,const std::string & what ) { 13if (ok )return ; 14 std::fprintf (stderr ,"FAIL: %s\n" ,what .c_str ()); 15++ g_fail ; 16} 17// IQ3_S on Qwen3.8-Flash-Next, 128K, int8 KV, window 32768, MTP: the figures the 8 GB start log gave (3485 MiB dense set, 835 MiB draft layer, 410 MiB head) 18Model iq3s () { 19Model m ; 20m .dense_mib = 1466 + 2019 ; 21m .session_mib = 400 ; 22m .head_mib = 410 ; 23m .drafter_mib = 1000 ; 24m .slot_mib = 3 ; 25m .reserve_mib = 796 ; 26return m ; 27} 28}// namespace 29 30int main () { 31const Model m = iq3s (); 32// 1. the trim: 8 GB cards are short, 12 GB and bigger are not (a big card never reaches the walk) 33check (trim_needed (7635 ,m , true),"an 8 GB card holding the head and the drafter is short" ); 34check (trim_needed (7635 ,m , false),"an 8 GB card without them is short too" ); 35check (!trim_needed (12288 ,m , true),"a 12 GB card is not short" ); 36check (!trim_needed (16384 ,m , true),"a 16 GB card is not short" ); 37check (!trim_needed (97000 ,m , true),"a 96 GB card is never short" ); 38check (!trim_needed (0 ,m , true),"an unreadable card (0 free) decides nothing" ); 39check (untrimmed_need_mib (m , true)> untrimmed_need_mib (m , false),"the last stage needs more" ); 40// monotone in the card: the threshold is one number 41int64_t edge = 0 ; 42for (int64_t f = 1000 ;f < 40000 ;++ f ) 43if (!trim_needed (f ,m , true)) {edge = f ;break ; } 44check (edge == untrimmed_need_mib (m , true),"the threshold is the need" ); 45for (int64_t f = edge ;f < edge + 5000 ;f += 97 )check (!trim_needed (f ,m , true),"never short above the threshold" ); 46// a model with a smaller dense set (a smaller quant) is short later 47Model small = m ; 48small .dense_mib = 1500 ; 49check (!trim_needed (7635 ,small , false),"a small dense set fits an 8 GB card untrimmed" ); 50// 2. fewer cards 51check (!card_usable (2048 ),"a card with 2 GB free leaves the split" ); 52check (card_usable (4250 ),"a 6 GB card (4.15 GiB free) stays: the other steps make it fit" ); 53check (card_usable (7635 ),"an 8 GB card stays" ); 54check (card_usable (kMinCardMib )&& !card_usable (kMinCardMib - 1 ),"the edge" ); 55// 3. the draft layer: the single card's arithmetic, unchanged 56const uint64_t layer = 835ull <<20 ,head = 410ull <<20 ; 57check (draft_layer_need_bytes (layer ,head )== layer + head + (220ull <<20 )+ (1550ull <<20 ),"the single card's need" ); 58check (draft_layer_short (1830ull <<20 ,layer ,head ),"1.8 GiB free: the layer goes" ); 59check (!draft_layer_short (3640ull <<20 ,layer ,head ),"3.6 GiB free (trimmed 8 GB card): the layer stays" ); 60check (!draft_layer_short (0 ,layer ,head ),"0 free is an unreadable figure" ); 61check (dflash2_need_bytes (715ull <<20 ,213ull <<20 )< draft_layer_need_bytes (layer ,head ),"DFlash2 needs less than the draft layer" ); 62// 4. the KV window walks 32768 -> 20480 -> 8192 -> 4096 -> stop, and never goes past the context or the engine's minimum 63check (next_kv_window (32768 ,131072 ,4096 )== 20480 ,"32768 -> 20480" ); 64check (next_kv_window (20480 ,131072 ,4096 )== 8192 ,"20480 -> 8192" ); 65check (next_kv_window (8192 ,131072 ,4096 )== 4096 ,"8192 -> 4096" ); 66check (next_kv_window (4096 ,131072 ,4096 )== 0 ,"4096 is the last" ); 67check (next_kv_window (0 ,131072 ,4096 )== 20480 ,"the whole context in VRAM goes to 20480" ); 68check (next_kv_window (0 ,16384 ,4096 )== 8192 ,"a context of 16K has no 20480 step" ); 69check (next_kv_window (0 ,4096 ,4096 )== 0 ,"a context at the minimum has none" ); 70check (next_kv_window (8192 ,131072 ,8192 )== 0 ,"a larger engine minimum stops the walk" ); 71// 5. the shares of the layers 72int64_t fm [2 ]= {5000 ,5000 },out [2 ]= {0 ,0 }; 73proportional_layers (fm ,2 ,48 ,out ); 74check (out [0 ]== 24 && out [1 ]== 24 ,"two equal rooms share 48 layers 24/24" ); 75int64_t fm1 [2 ]= {5285 ,3875 }; 76proportional_layers (fm1 ,2 ,48 ,out ); 77check (out [0 ]+ out [1 ]== 48 && out [0 ]== 28 && out [1 ]== 20 ,"the card that carries the head and the drafter takes fewer layers (28/20)" ); 78int64_t fm2 [2 ]= {9000 ,5000 }; 79proportional_layers (fm2 ,2 ,48 ,out ); 80check (out [0 ]+ out [1 ]== 48 && out [0 ]> out [1 ],"the bigger room takes more layers" ); 81int64_t fm3 [3 ]= {5000 ,5000 ,5000 },out3 [3 ]; 82proportional_layers (fm3 ,3 ,48 ,out3 ); 83check (out3 [0 ]== 16 && out3 [1 ]== 16 && out3 [2 ]== 16 ,"three equal rooms 16/16/16" ); 84int64_t fm4 [2 ]= {90000 ,100 },out4 [2 ]; 85proportional_layers (fm4 ,2 ,48 ,out4 ); 86check (out4 [0 ]+ out4 [1 ]== 48 && out4 [0 ] >=2 && out4 [1 ] >=0 ,"a tiny room leaves the sum right" ); 87int64_t fm5 [2 ]= {0 ,0 },out5 [2 ]; 88proportional_layers (fm5 ,2 ,48 ,out5 ); 89check (out5 [0 ]+ out5 [1 ]== 48 ,"rooms of 0 still sum to the layers" ); 90// 6. fewer cards: feasible when the rooms plus the relief pay for every layer 91int64_t r8 [2 ]= {5200 ,5200 }; 92check (split_feasible (r8 ,2 ,48 ,90 ,1410 ),"two 8 GB cards (5.2 GiB of room each) hold the model" ); 93int64_t r6 [2 ]= {1744 ,1552 }; 94check (split_feasible (r6 ,2 ,48 ,87 ,1410 ),"two 6 GB cards hold it only with the drafter and the head moved off" ); 95check (!split_feasible (r6 ,2 ,48 ,87 ,0 ),"...and not without that relief" ); 96int64_t r3 [2 ]= {2000 ,100 }; 97check (!split_feasible (r3 ,2 ,48 ,90 ,1410 ),"two cards with 2 GB and 0.1 GB of room do not: fewer cards" ); 98if (g_fail == 0 ) std::printf ("split_walk_test: ok\n" ); 99return g_fail == 0 ?0 :1 ; 100}