okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge main c1ff07f1a into f-own-intfefaa985c

main
3.5 KiB69 linesraw
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):
20    def test_one_session_takes_its_fp32_cache_and_the_shared_fp16_copy(self):
21        fam = setup.OWN_PATH_FAMILIES["qwen36"]
22        self.assertEqual(fam["kv_bytes_per_token"], 45056)                 # a session's (a parallel slot's) K / V: unchanged
23        self.assertEqual(F.BYTES_PER_TOKEN, fam["kv_bytes_per_token"] + 2048)
24        self.assertEqual(F.BYTES_PER_TOKEN, 47104)
25        self.assertAlmostEqual(F.cache_gib(32768), 1.4375)
26
27    def test_the_figure_follows_the_engines_allocations(self):
28        src = 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)
30        self.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
32        self.assertEqual(len(re.findall(r"[kv]16 = dalloc_t<__half>\(\(size_t\) g\.n_head_kv \* ctx \* g\.head_dim\)", src)), 2)
33
34    def test_inputs_for_the_sizes_and_nothing_for_other_models(self):
35        self.assertEqual(Q4, {"bytes_per_token": 47104, "fixed_gb": round(8.55 + 1256 / 1024 + 0.07e9 / 2 ** 30, 4)})
36        self.assertEqual(F.inputs("qwen3.6-35b-a3b", "Q8_0"), Q6)
37        self.assertIsNone(F.inputs("qwen3.6-35b-a3b", "UD-Q2_K"))
38        self.assertIsNone(F.inputs("some-feed-model", "UD-Q4_K_XL"))
39        self.assertEqual(F.from_model_name("qwen3.6-35b-a3b-ud-q4_k_xl"), Q4)
40        self.assertEqual(F.from_model_name("qwen3.6-35b-a3b-q8_0"), Q6)
41        self.assertIsNone(F.from_model_name("qwen3.8-flash-next-iq3_s"))
42        self.assertIsNone(F.from_model_name(None))
43        for name in ("qwen36",):
44            self.assertEqual(setup.OWN_PATH_FAMILIES[name]["name"], F.FAMILY_NAME)
45            self.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
51    def test_rtx_5070_12gb_5715(self):
52        self.assertTrue(F.fits(Q4, 11.94, 32768))          # ran (VRAM 10.5 / 12 GB)
53        self.assertFalse(F.fits(Q4, 11.94, 65536))         # "not enough VRAM left for the hybrid experts' buffers"
54        self.assertFalse(F.fits(Q4, 11.94, 131072))        # the bare out-of-memory line
55
56    def test_rtx_5060ti_16gb_3303(self):
57        self.assertTrue(F.fits(Q4, 15.93, 100000))         # started, 3.93 GiB free
58        self.assertFalse(F.fits(Q4, 15.93, 262144))        # out of memory
59
60    def test_rtx_3060_12gb_q6_3687(self):
61        self.assertTrue(F.fits(Q6, 12.0, 32768))           # started
62        self.assertFalse(F.fits(Q6, 12.0, 131072))         # 1760 MiB needed, 0 free
63
64    def test_rtx_3080_10gb_q8_2747(self):
65        self.assertFalse(F.fits(F.inputs("qwen3.6-35b-a3b", "Q8_0"), 10.0, 32768))   # the staging pair failed
66
67
68if __name__ == "__main__":
69    unittest.main()