Skip to content

Kyojin: open-source engine that runs 100 GB-class open models (GLM-5.3, Qwen3.8, DeepSeek V4.1) on one desktop machine. AMD Strix Halo, NVIDIA RTX and Apple Mac. OpenAI API, built on ExLlamaV3.

qualify: a narrower tq format qualifies only if every wider one does

YanissAmz3e138736ff56
diff --git a/tools/qualify/rules.py b/tools/qualify/rules.py
index 6f9203d..8df7702 100644
--- a/tools/qualify/rules.py
+++ b/tools/qualify/rules.py
@@ -20,6 +20,8 @@ def choose_kv_mode(kl: dict[str, float], bits_per_val: dict[str, float], base: s
"""Q6 rule for the KV format: any candidate (e.g. tq6, tq5) whose decode-faithful KL vs k8v8 is <= the k6v6 baseline's qualifies;
the one with the fewest bytes per value wins (ties: lower KL), else k6v6. kl / bits_per_val: {format: value}, both holding `base`."""
ok = [n for n in kl if n != base and n in bits_per_val and kl[n] <= kl[base]]
+ # sanity: more bits can only help, so a format with fewer bits that beats the baseline while a wider tq format does not is measurement noise
+ ok = [n for n in ok if all(m in ok for m in kl if m != base and bits_per_val.get(m, 0) > bits_per_val[n])]
return min(ok, key=lambda n: (bits_per_val[n], kl[n])) if ok else base
diff --git a/tools/qualify/tests/test_plan.py b/tools/qualify/tests/test_plan.py
index 4016dbc..71f7f4e 100644
--- a/tools/qualify/tests/test_plan.py
+++ b/tools/qualify/tests/test_plan.py
@@ -243,6 +243,8 @@ class KvModeRule(unittest.TestCase):
self.assertEqual(rules.choose_kv_mode({"k6v6": 0.010, "tq6": 0.004, "tq5": 0.009}, bpv), "tq5")
# only tq6 qualifies
self.assertEqual(rules.choose_kv_mode({"k6v6": 0.010, "tq6": 0.008, "tq5": 0.020}, bpv), "tq6")
+ # tq5 below k6v6 but tq6 above it: noise, the baseline stays
+ self.assertEqual(rules.choose_kv_mode({"k6v6": 0.005, "tq6": 0.0125, "tq5": 0.0048}, bpv), "k6v6")
# none qualifies: the production format stays
self.assertEqual(rules.choose_kv_mode({"k6v6": 0.002, "tq6": 0.004, "tq5": 0.010}, bpv), "k6v6")
# a model without tq support (head_dim not a power of two): only the baseline was measured