okami.mom/strata

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

Niko1221Merge f-ds-out ac306afb2 into f-own-intaff3a132f

main
6.3 KiB92 linesraw
1"""0.2.13 (owner, 2026-11-08): one fit label for every family.  The model's files, download size MINUS the n-gram / PLE / Engram lookup table's file (the
2"Needs (RAM + VRAM)" column), against the graphics memory plus the RAM: "fits", else "may run slower".  Nothing else is said on those rows (no "SSD N GB", no
3"too big", no RAM floor), also with no card or a Mac with little memory.
4
5The screenshot PC: a Tesla V100-PCIE-32GB with 31 GB of RAM (63 GB together): every set up to 63 GB of weights said "fits"; the Unsloth sets said "too big" while
6IQ3_S, with the same 50 GB of experts, said "fits, a bit slower".
7"""
8from __future__ import annotations
9
10import unittest
11
12from strata_cli.launch.catalog import FITS, NO, SLOWER, verdict
13from strata_control import fit_label
14from tests.terminal.launch_support import HW_12, Home, catalog
15
16V100 = {"index": 0, "name": "Tesla V100-PCIE-32GB", "vram_gb": 32.0, "usable": True, "vendor": "nvidia", "arch": 70}
17HW_V100_31 = {**HW_12, "ram_gb": 31.0, "disk_free_gb": 5000.0, "gpus": [V100]}
18
19
20class TheRule(unittest.TestCase):
21    def test_the_table_file_is_taken_off_the_download(self):
22        import setup
23        want = {("qwen", "IQ3_S"): 54.8, ("swift", "IQ3_XXS"): 47.0, ("coder", "IQ1_M"): 29.6, ("unsloth", "UD-IQ4_XS-v31"): 64.9, ("unsloth", "UD-IQ4_XS"): 64.9,
24                ("unsloth", "UD-Q4_K_XL"): 82.5, ("unsloth", "UD-Q5_K_XL"): 103.9, ("unsloth", "Q8_0"): 133.8,      # the three big files carry a 54.4 GB Q8_0 table
25                ("gyro", "Gyro-S"): 27.6, ("gyro", "Gyro-M"): 35.0, ("nvfp4", "NVFP4"): 76.8}                         # Gyro: the table is inside the file, the catalog states the rest
26        for (family, model), gb in want.items():
27            self.assertEqual(fit_label.files_gb(family, model, setup.MODELS[model]), gb, (family, model))
28        self.assertEqual(fit_label.files_gb("nvfp4", "NVFP4-QAD", setup.MODELS["NVFP4-QAD"]), 76.8)               # the converted pack that runs, not the 102.2 GB checkpoint minus the table
29        self.assertEqual(fit_label.files_gb("nvfp4", "NVFP4-NVIDIA", setup.MODELS["NVFP4-NVIDIA"]), 76.8)
30        self.assertEqual(fit_label.files_gb("qwen36", "UD-Q6_K_XL", {"download_gb": 32.6, "ram_gb": 44}), 32.6)       # its own path: no table
31        self.assertEqual(fit_label.files_gb("somefeedmodel", "X", {"download_gb": 10.0, "ram_gb": 8}), 10.0)          # a family this module does not know counts its whole download
32
33    def test_the_label_is_the_weights_against_ram_plus_card(self):
34        self.assertEqual(fit_label.label(63.0, 31.0, 32.0), "fits")                 # exactly as much as there is
35        self.assertEqual(fit_label.label(63.1, 31.0, 32.0), "may run slower")
36        self.assertEqual(fit_label.label(35.0, 31.0, 0.0), "may run slower")        # no card: the RAM alone
37
38    def test_the_card_that_counts(self):
39        self.assertEqual(fit_label.card_room_gb([{"vram_gb": 12.0}, {"vram_gb": 24.0}]), 24.0)         # the largest card
40        self.assertEqual(fit_label.card_room_gb([{"vram_gb": 96.0, "uma": True, "dedicated_gb": 8.0}]), 8.0)   # a chip that shares the RAM: its carve-out only
41        self.assertEqual(fit_label.card_room_gb([]), 0.0)
42
43
44class TheTerminalMenu(unittest.TestCase):
45    def rows(self, hw):
46        with Home():
47            return {(r.family, r.model): r for r in catalog(hw).rows()}
48
49    def test_the_v100_screenshot(self):
50        rows = self.rows(HW_V100_31)
51        for (family, model), r in rows.items():
52            want = FITS if r.fit_gb <= 63.0 else SLOWER
53            self.assertEqual((r.verdict, r.words), (want, "fits" if want == FITS else "may run slower"), (family, model, r.fit_gb))
54        for m in ("UD-IQ1_M", "UD-Q2_0", "UD-IQ2_XS", "UD-Q2_K_XL", "UD-IQ3_XXS", "UD-Q3_K_XL"):         # the Unsloth sets that were "too big", 39 to 61 GB
55            self.assertEqual(rows[("unsloth", m)].words, "fits", m)
56        for m in ("UD-IQ4_XS", "UD-IQ4_XS-v31", "UD-Q4_K_XL", "UD-Q5_K_XL", "UD-Q6_K_XL", "Q8_0"):
57            self.assertEqual(rows[("unsloth", m)].words, "may run slower", m)
58        self.assertEqual(round(rows[("unsloth", "UD-IQ4_XS-v31")].fit_gb, 1), 64.9)                       # 93.7 - 28.8: over 63
59        self.assertEqual(rows[("qwen", "IQ3_S")].words, rows[("unsloth", "UD-IQ3_XXS")].words)             # same size, same word
60        self.assertEqual({rows[("nvfp4", m)].words for m in ("NVFP4", "NVFP4-NVIDIA", "NVFP4-QAD")}, {"may run slower"})      # QAD too: the pack that runs is 76.8 GB
61        self.assertEqual({round(rows[("nvfp4", m)].fit_gb, 1) for m in ("NVFP4", "NVFP4-NVIDIA", "NVFP4-QAD")}, {76.8})
62
63    def test_no_row_uses_the_old_words(self):
64        for hw in (HW_V100_31, HW_12, {**HW_12, "ram_gb": 16.0, "gpus": []}):
65            for key, r in self.rows(hw).items():
66                self.assertNotEqual(r.verdict, NO, key)                    # nothing is "too big" any more
67                for old in ("too big", "fits, a bit slower", "fits, part read from SSD", "much read from SSD", "does not fit", "slow here"):
68                    self.assertNotIn(old, r.words, (key, r.words))
69                self.assertIn(r.words, ("fits", "may run slower"), key)
70
71    def test_a_64_gb_pc_with_a_12_gb_card(self):
72        rows = self.rows({**HW_12, "disk_free_gb": 5000.0})                # 76 GB together
73        self.assertEqual(rows[("unsloth", "UD-IQ4_XS-v31")].words, "fits")                    # 64.9 GB
74        self.assertEqual(rows[("unsloth", "UD-Q4_K_XL")].words, "may run slower")           # 82.5 GB
75        self.assertEqual(rows[("nvfp4", "NVFP4")].words, "may run slower")                    # 76.8 GB against 75.9
76
77    def test_the_catalog_words(self):
78        with Home():
79            row = next(x for x in catalog(HW_V100_31).strata.model_table(HW_V100_31) if x["family"] == "unsloth")
80        by = {x["model"]: x["on_this_pc"] for x in row["sizes"]}
81        self.assertEqual({v for k, v in by.items()}, {"fits", "may run slower"})
82        self.assertEqual(by["UD-IQ3_XXS"], "fits")
83        self.assertEqual(by["UD-Q4_K_XL"], "may run slower")
84
85    def test_the_table_words_in_the_terminal(self):
86        self.assertEqual(verdict("fits"), (FITS, "fits"))
87        self.assertEqual(verdict("may run slower"), (SLOWER, "may run slower"))
88        self.assertEqual(verdict("does not fit: it needs one or more graphics cards"), (SLOWER, "may run slower"))      # an older Control's words
89
90
91if __name__ == "__main__":
92    unittest.main()