prain: int8/int4 experts quantized once on the GPU, rounds through vLLM's expert_map, [miss] min_weight skips experts not in VRAM; scripts: tune_moe, quality (answer NLL on identical token ids), bench --context, measure --quant

This commit is contained in:
2026-10-28 22:07:25 +01:00
parent 3ae9bd73a7
commit 708e152549
15 changed files with 703 additions and 120 deletions
+17
View File
@@ -107,6 +107,23 @@ mode = "auto"
self.assertEqual(config.stats_path, os.path.expanduser("~/s.json"))
self.assertEqual(config.trace_path, "/abs/t.gz")
def test_miss_min_weight(self):
config = mc.load_config(self.write("m.toml", 'pack_dir = "/p"\n[miss]\nmin_weight = 0.7\n'))
self.assertEqual(config.miss.min_weight, 0.7)
self.assertEqual(mc.Miss().min_weight, 1.0) # default: compute every routed expert
with self.assertRaisesRegex(ValueError, "min_weight must be a number in"):
mc.load_config(self.write("m2.toml", 'pack_dir = "/p"\n[miss]\nmin_weight = 1.5\n'))
def test_quant_key_and_expert_sizes(self):
self.assertEqual(mc.load_config(self.write("q.toml", 'pack_dir = "/p"\nquant = "int4"\n')).quant, "int4")
self.assertEqual(mc.load_config(self.write("b.toml", 'pack_dir = "/p"\n')).quant, "bf16")
with self.assertRaisesRegex(ValueError, "quant must be one of"):
mc.load_config(self.write("bad.toml", 'pack_dir = "/p"\nquant = "int3"\n'))
h, i = 2816, 704
self.assertEqual(mc.expert_bytes(h, i), 3 * h * i * 2)
self.assertEqual(mc.expert_bytes(h, i, "int8"), 3 * h * i + 4 * (2 * i + h)) # fp32 row scales
self.assertEqual(mc.expert_bytes(h, i, "int4"), 3 * h * i // 2 + 2 * 3 * h * i // 64)
def test_serve_and_draft_tables(self):
config = mc.load_config(self.write("s.toml", 'pack_dir = "/p"\n[serve]\nmax_requests = 4\n'
'kv_cache_gib = 1.5\n[draft]\nfull_requests = 2\n'