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
draft2s: load the pack on the host then copy, and build the head before warm-up (#161)
Yaniss Amazouzc2441ec63873
diff --git a/exllamav3/modules/draft2s.py b/exllamav3/modules/draft2s.pyindex 3be115b..de1ba02 100644--- a/exllamav3/modules/draft2s.py+++ b/exllamav3/modules/draft2s.py@@ -180,7 +180,8 @@ class Draft2SHead:from exllamav3.modules.quant.exl3 import dec_workspaceself.ext = extdev = inner.trellis.device- P = load_file(pack_path, device=str(dev))+ # Read on the host, then copy: safetensors' direct device load stalled warm-up on ROCm 7.13 (#125).+ P = {k: v.to(dev) for k, v in load_file(pack_path, device="cpu").items()}with safe_open(pack_path, "pt") as fm: self.M = int((fm.metadata() or {}).get("m", M))self.E, self.pcodes, self.pscale = P["E"].contiguous(), P["pcodes"].contiguous(), P["pscale"].float().contiguous()self.q3, self.q3s, self.had = P["q3"].contiguous(), P["q3s"].contiguous(), P["had"].contiguous()@@ -248,3 +249,10 @@ def head_for(lm, vocab):_heads[key] = Draft2SHead(path, inner, vocab) if ok else Noneprint(f" -- EXL3_DRAFT2S: {'two-stage draft head ON' if ok else 'head not eligible, OFF'} ({path})")return _heads[key]+++def preload(model):+ """Build the head of *model*'s logit layer now (load time) instead of inside the first draft step, so a slow or+ failing pack load shows at start-up, before warm-up, with its own log line. No-op when EXL3_DRAFT2S is off."""+ if not os.environ.get("EXL3_DRAFT2S"): return None+ return head_for(model.modules[model.logit_layer_idx], model.config.vocab_size)diff --git a/tools/qwen/serve.py b/tools/qwen/serve.pyindex 2884cdb..19749ee 100644--- a/tools/qwen/serve.py+++ b/tools/qwen/serve.py@@ -960,6 +960,11 @@ class QwenEngine:self.slot_store.generator = self.generatordef warmup(self) -> None:+ if self.draft_model is not None and self.draft_policy != "dflash":+ # The MTP drafter's two-stage head (EXL3_DRAFT2S) is built here, before the first step, not during warm-up (#125).+ from exllamav3.modules import draft2s+ with Heartbeat("loading the two-stage draft head"):+ draft2s.preload(self.model)# dense GEMM warm-up at load (EXL3_WARM_DENSE=0 = off): the first request at a new row-count class# no longer pays the rocBLAS solution screening (0.15-4 s per shape).from exllamav3.model.dense_warmup import warm_dense_gemmdiff --git a/tools/qwen/test_serve.py b/tools/qwen/test_serve.pyindex e584c7d..c5eb454 100644--- a/tools/qwen/test_serve.py+++ b/tools/qwen/test_serve.py@@ -99,6 +99,27 @@ def sse_events(raw: str):class ParserTests(unittest.TestCase):+ def test_draft2s_preload(self):+ # #125: the head is built at load time (before warm-up) for an MTP drafter, never for DFlash or with the head off+ from unittest import mock+ from exllamav3.modules import draft2s+ lm = object()+ model = types.SimpleNamespace(modules=["emb", lm], logit_layer_idx=1, config=types.SimpleNamespace(vocab_size=7))+ with mock.patch.object(draft2s, "head_for", return_value="head") as head_for:+ with mock.patch.dict(os.environ, {"EXL3_DRAFT2S": ""}):+ self.assertIsNone(draft2s.preload(model))+ with mock.patch.dict(os.environ, {"EXL3_DRAFT2S": "/p/draft2s.st"}):+ self.assertEqual(draft2s.preload(model), "head")+ head_for.assert_called_once_with(lm, 7)+ for policy, calls in (("mix", 2), ("dflash", 2)):+ engine = types.SimpleNamespace(draft_model=object(), draft_policy=policy, model=model,+ generator=types.SimpleNamespace(max_chunk_size=1))+ with mock.patch.dict(os.environ, {"EXL3_DRAFT2S": "/p/draft2s.st"}), \+ mock.patch("exllamav3.model.dense_warmup.warm_dense_gemm", side_effect=StopIteration):+ with self.assertRaises(StopIteration):+ serve.QwenEngine.warmup(engine)+ self.assertEqual(head_for.call_count, calls)+def test_draft2s_sidecar(self):import tempfilefrom unittest import mock