okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
fefaa985c
main
1"""Qwen3.6-35B-A3B's context against the card's memory (GitHub #5715, strata_control/own_path_fit.py): the per-token figure the engine really 2allocates, the formula's inputs where setup, the start and the app read them, and what it says about the field logs it was derived from.""" 3 4from __future__import annotations 5 6import re 7import unittest 8from pathlib import Path 9 10import setup 11from strata_control import own_path_fit as F 12 13ROOT = Path (__file__ ).resolve ().parents [2 ] 14ENGINE = ROOT / "src" / "qwen35" / "q36_engine.cu" 15Q4 = F .inputs ("qwen3.6-35b-a3b" ,"UD-Q4_K_XL" ) 16Q6 = F .inputs ("qwen3.6-35b-a3b" ,"UD-Q6_K_XL" ) 17 18 19class PerToken (unittest .TestCase ): 20def test_one_session_takes_its_fp32_cache_and_the_shared_fp16_copy (self ): 21fam = setup .OWN_PATH_FAMILIES ["qwen36" ] 22self .assertEqual (fam ["kv_bytes_per_token" ],45056 )# a session's (a parallel slot's) K / V: unchanged 23self .assertEqual (F .BYTES_PER_TOKEN ,fam ["kv_bytes_per_token" ]+ 2048 ) 24self .assertEqual (F .BYTES_PER_TOKEN ,47104 ) 25self .assertAlmostEqual (F .cache_gib (32768 ),1.4375 ) 26 27def test_the_figure_follows_the_engines_allocations (self ): 28src = ENGINE .read_text (encoding = "utf-8" ) 29# the session's fp32 K and V per attention layer and for the MTP block (4 calls at n_head_kv x ctx x head_dim floats) 30self .assertEqual (len (re .findall (r"ss\.[kv]c\.push_back\(dalloc\(\(size_t\) g\.n_head_kv \* ctx \* g\.head_dim\)\)" ,src )),4 ) 31# one fp16 copy of K and V at the full context 32self .assertEqual (len (re .findall (r"[kv]16 = dalloc_t<__half>\(\(size_t\) g\.n_head_kv \* ctx \* g\.head_dim\)" ,src )),2 ) 33 34def test_inputs_for_the_sizes_and_nothing_for_other_models (self ): 35self .assertEqual (Q4 , {"bytes_per_token" :47104 ,"fixed_gb" :round (8.55 + 1256 / 1024 + 0.07e9 / 2 ** 30 ,4 )}) 36self .assertEqual (F .inputs ("qwen3.6-35b-a3b" ,"Q8_0" ),Q6 ) 37self .assertIsNone (F .inputs ("qwen3.6-35b-a3b" ,"UD-Q2_K" )) 38self .assertIsNone (F .inputs ("some-feed-model" ,"UD-Q4_K_XL" )) 39self .assertEqual (F .from_model_name ("qwen3.6-35b-a3b-ud-q4_k_xl" ),Q4 ) 40self .assertEqual (F .from_model_name ("qwen3.6-35b-a3b-q8_0" ),Q6 ) 41self .assertIsNone (F .from_model_name ("qwen3.8-flash-next-iq3_s" )) 42self .assertIsNone (F .from_model_name (None )) 43for name in ("qwen36" ,): 44self .assertEqual (setup .OWN_PATH_FAMILIES [name ]["name" ],F .FAMILY_NAME ) 45self .assertEqual (sorted (setup .OWN_PATH_FAMILIES [name ]["models" ]),sorted (F .HYBRID_MIN_GIB )) 46 47 48class FieldLogs (unittest .TestCase ): 49"""The starts the figures were derived from and checked against (card memory as nvidia-smi gives it, GiB).""" 50 51def test_rtx_5070_12gb_5715 (self ): 52self .assertTrue (F .fits (Q4 ,11.94 ,32768 ))# ran (VRAM 10.5 / 12 GB) 53self .assertFalse (F .fits (Q4 ,11.94 ,65536 ))# "not enough VRAM left for the hybrid experts' buffers" 54self .assertFalse (F .fits (Q4 ,11.94 ,131072 ))# the bare out-of-memory line 55 56def test_rtx_5060ti_16gb_3303 (self ): 57self .assertTrue (F .fits (Q4 ,15.93 ,100000 ))# started, 3.93 GiB free 58self .assertFalse (F .fits (Q4 ,15.93 ,262144 ))# out of memory 59 60def test_rtx_3060_12gb_q6_3687 (self ): 61self .assertTrue (F .fits (Q6 ,12.0 ,32768 ))# started 62self .assertFalse (F .fits (Q6 ,12.0 ,131072 ))# 1760 MiB needed, 0 free 63 64def test_rtx_3080_10gb_q8_2747 (self ): 65self .assertFalse (F .fits (F .inputs ("qwen3.6-35b-a3b" ,"Q8_0" ),10.0 ,32768 ))# the staging pair failed 66 67 68if __name__ == "__main__" : 69unittest .main ()