okami.mom/strata

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

Niko1221Merge branch 'f-139b-par' into f-139-relf5410ae2b

main
3.2 KiB53 linesraw
1"""#465: setup's recommendation for "parallel" (several requests decoded together in the engine's batch slots).
2No GPU or download needed: python tools/test_setup_parallel.py"""
3import sys
4import unittest
5from pathlib import Path
6
7sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
8import setup as S  # noqa: E402
9
10
11class Parallel(unittest.TestCase):
12    def test_slot_size(self):
13        # measured: a slot's session at 32K, int8 KV: 0.56 GiB = 0.60 GB
14        self.assertAlmostEqual(S.parallel_slot_gb(32768, "int8", False), 0.59, delta=0.03)
15        # KV streaming keeps only the attention's 32K positions in VRAM, whatever the context
16        self.assertEqual(S.parallel_slot_gb(262144, "int8", True), S.parallel_slot_gb(32768, "int8", False))
17        self.assertLess(S.parallel_slot_gb(32768, "q4_0", False), S.parallel_slot_gb(32768, "int8", False))
18
19    def test_recommendation_only_where_the_experts_mostly_fit(self):
20        q2, iq3s = S.MODELS["Q2_0"]["arena_gb"], S.MODELS["IQ3_S"]["arena_gb"]
21        # most experts on the CPU: slots cost speed per request (measured on the 12 GB 5070) - none recommended
22        self.assertEqual(S.parallel_recommend(12, q2, 32768, "int8", False), 0)
23        self.assertEqual(S.parallel_recommend(16, q2, 32768, "int8", False), 0)
24        self.assertEqual(S.parallel_recommend(24, iq3s, 32768, "int8", False), 0)
25        # the cache holds most of the experts beside the slots: recommended
26        self.assertEqual(S.parallel_recommend(24, q2, 32768, "int8", False), 3)
27        self.assertEqual(S.parallel_recommend(48, q2, 32768, "int8", False), 4)       # capped at 4
28        self.assertEqual(S.parallel_recommend([24, 24], iq3s, 32768, "int8", False), 4)   # a layer split: every card
29        self.assertEqual(S.parallel_recommend([16, 16], q2, 32768, "int8", False), 4)
30        self.assertEqual(S.parallel_recommend(32, q2, 262144, "int8", False), 0)      # a 262K KV per slot: no
31        self.assertEqual(S.parallel_recommend(32, q2, 262144, "int8", True), 4)       # ... unless it streams
32
33    def test_notes_recommend_never_force(self):
34        q2 = S.MODELS["Q2_0"]["arena_gb"]
35        # 12 GB: left at one, with the reason
36        note = S.parallel_note(None, 12, q2, 32768, "int8", False)
37        self.assertEqual(len(note), 1)
38        self.assertIn("one at a time", note[0])
39        self.assertIn("costs about 10-25% speed per request on this card", note[0])
40        self.assertIn("--parallel 3", S.parallel_note(None, 24, q2, 32768, "int8", False)[0])
41        # asked on 12 GB: kept, with the cost said
42        lines = S.parallel_note(4, 12, q2, 32768, "int8", False)
43        self.assertIn("4 at once", lines[0])
44        self.assertTrue(any("one at a time" in x and "kept as you chose" in x and "10-25%" in x for x in lines))
45        # asked above the recommendation where it pays
46        lines = S.parallel_note(4, 24, q2, 32768, "int8", False)
47        self.assertTrue(any("recommended for this card: 3" in x for x in lines))
48        self.assertTrue(any("at most 8" in x for x in S.parallel_note(12, 48, q2, 32768, "int8", False)))
49        self.assertEqual(len(S.parallel_note(3, 24, q2, 32768, "int8", False)), 1)   # as recommended: no warning
50
51
52if __name__ == "__main__":
53    unittest.main()