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.
Python amdapple-siliconcudadeepseekexl3exllamav3glminferencellmllm-inferencelocal-llmnvidiaopenai-apiquantizationqwenrocmstrix-halo
GLM serving: EXL3_GLM_DYN=window,confidence turns on the calibrated dynamic draft depth for the MTP drafter (default off)
YanissAmza09f8d4a9ffe
diff --git a/tools/glm/serve.py b/tools/glm/serve.pyindex e7eea4c..6a43bb0 100644--- a/tools/glm/serve.py+++ b/tools/glm/serve.py@@ -451,6 +451,16 @@ class ResidentEngine:torch.set_grad_enabled(False)self.torch = torchself.Job = Job+ # EXL3_GLM_DYN = "window,confidence": the Generator's confidence-calibrated draft stop (dynamic_draft_tokens) for the+ # MTP drafter, `window` drafted tokens at most per round, drafting stops when the estimated probability that the next+ # position still contributes falls below `confidence`. Overrides --num-draft. "0" = fixed --num-draft depth+ dyn = os.environ.get("EXL3_GLM_DYN", "0").strip()+ self.dyn = None+ if dyn not in ("", "0") and num_draft > 0:+ w, c = dyn.split(",")+ self.dyn = (int(w), float(c))+ num_draft = self.dyn[0]+ max_history = max(max_history, num_draft)self.num_draft = num_draft# Concurrent requests batched through the one Generator. The recurrent (KDA) state is allocated per slot and per# history level (138 MiB each). The Cache default of 16 slots was allocated whatever --sessions said: 6.6 GiB at@@ -520,7 +530,8 @@ class ResidentEngine:model=self.model, cache=self.cache, tokenizer=self.tokenizer,draft_model=self.draft_model, draft_cache=self.draft_cache,num_draft_tokens=max(self.num_draft, lookup[1] if lookup else 0) or None, # buffers for the widest round- record_draft_stats=True)+ record_draft_stats=True,+ dynamic_draft_tokens=self.dyn is not None, draft_confidence=self.dyn[1] if self.dyn else 0.6)if lookup:qdir = str(Path(__file__).resolve().parent.parent / "qwen")if qdir not in sys.path:diff --git a/tools/qwen/spec_policy.py b/tools/qwen/spec_policy.pyindex d55dac4..22ffc69 100644--- a/tools/qwen/spec_policy.py+++ b/tools/qwen/spec_policy.py@@ -403,6 +403,8 @@ def install_lookup(g, ngram, stats=None):w = g.num_draft_tokens; g.num_draft_tokens = 1try: out = orig(results)finally: g.num_draft_tokens = w+ # the verified tokens are the copy, not the drafter's: its confidence record (one column) must not label them+ g._draft_conf_round = Noneif out is None: return Noneif stats is not None: stats["ng"] = stats.get("ng", 0) + 1; stats["ng_tokens"] = stats.get("ng_tokens", 0) + len(cont)return torch.tensor([cont], dtype=torch.long)diff --git a/tools/qwen/test_lookup_gate.py b/tools/qwen/test_lookup_gate.pyindex 0f4a0d1..3277b46 100644--- a/tools/qwen/test_lookup_gate.py+++ b/tools/qwen/test_lookup_gate.py@@ -26,6 +26,7 @@ class Gen:def enqueue(self, job): return Nonedef iterate_draftmodel_mtp_gen(self, results):self.draft_calls += 1+ self._draft_conf_round = {"window": self.num_draft_tokens} # the dynamic-depth record of this drafter roundreturn torch.tensor([[0] * self.num_draft_tokens], dtype=torch.long)def run(rounds, gain_ng, gain_dr, gate="1"):@@ -56,5 +57,19 @@ class LookupGate(unittest.TestCase):ng, gated = run(50, gain_ng=1, gain_dr=3, gate="0")self.assertEqual(ng, 50); self.assertEqual(gated, 0)+class LookupConfidence(unittest.TestCase):+ def test_lookup_round_drops_the_drafter_confidence_record(self):+ # A lookup round runs the drafter at window 1 but verifies the K copied tokens: the 1-column confidence record must+ # not label them (EXL3_GLM_DYN crashed on the first copy turn); a drafter round keeps its record+ os.environ["QWSPEC_NGRAM_GATE"] = "0"+ g = Gen(Sid(list(range(100, 140)) * 50)); stats = {}+ spec_policy.install_lookup(g, (2, 7, 16, 3), stats)+ g.iterate_draftmodel_mtp_gen(None)+ self.assertEqual(stats.get("ng"), 1); self.assertIsNone(g._draft_conf_round)+ g2 = Gen(Sid(list(range(100, 300)))); stats2 = {}+ spec_policy.install_lookup(g2, (2, 7, 16, 3), stats2)+ g2.iterate_draftmodel_mtp_gen(None)+ self.assertIsNone(stats2.get("ng")); self.assertEqual(g2._draft_conf_round, {"window": 2})+if __name__ == "__main__":unittest.main()