MCPcopy Create free account
hub / github.com/Zefan-Cai/KVCache-Factory / QuantizationConfigTest

Class QuantizationConfigTest

tests/test_quantization.py:11–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9
10
11class QuantizationConfigTest(unittest.TestCase):
12 def test_normalize_empty_quant_method(self):
13 self.assertIsNone(normalize_quant_method(None))
14 self.assertIsNone(normalize_quant_method(""))
15 self.assertIsNone(normalize_quant_method("none"))
16
17 def test_rejects_unknown_quant_method(self):
18 with self.assertRaises(ValueError):
19 normalize_quant_method("unknown")
20
21 def test_builds_kivi_asymmetric_config(self):
22 config = build_quantized_cache_config("kivi", nbits=2, residual_length=128)
23 self.assertEqual(config["backend"], "hqq")
24 self.assertEqual(config["axis_key"], KIVI_AXIS_KEY)
25 self.assertEqual(config["axis_value"], KIVI_AXIS_VALUE)
26 self.assertEqual(config["nbits"], 2)
27 self.assertEqual(config["residual_length"], 128)
28 self.assertEqual(config["q_group_size"], 64)
29
30 def test_allows_axis_override_for_experiments(self):
31 config = build_quantized_cache_config(
32 "kvquant",
33 nbits=4,
34 residual_length=256,
35 axis_key=0,
36 axis_value=1,
37 q_group_size=32,
38 )
39 self.assertEqual(config["axis_key"], 0)
40 self.assertEqual(config["axis_value"], 1)
41 self.assertEqual(config["q_group_size"], 32)
42
43 def test_builds_gear_config_with_rank_and_outlier_ratio(self):
44 config = build_quantized_cache_config(
45 "gear",
46 nbits=3,
47 residual_length=128,
48 rank=8,
49 outlier_ratio=0.02,
50 )
51 self.assertEqual(config["nbits"], 3)
52 self.assertEqual(config["rank"], 8)
53 self.assertAlmostEqual(config["outlier_ratio"], 0.02)
54
55 def test_gear_config_rejects_bad_rank_and_outlier_ratio(self):
56 with self.assertRaises(ValueError):
57 build_quantized_cache_config("gear", nbits=4, residual_length=128, rank=0)
58 with self.assertRaises(ValueError):
59 build_quantized_cache_config("gear", nbits=4, residual_length=128, outlier_ratio=1.5)
60
61 def test_kivi_config_omits_gear_fields(self):
62 config = build_quantized_cache_config("kivi", nbits=2, residual_length=128)
63 self.assertNotIn("rank", config)
64 self.assertNotIn("outlier_ratio", config)
65
66
67if __name__ == "__main__":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected