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
Spec policy: default 16-row verify budget for dense CUDA models
YanissAmz74e9f7a3efa6
diff --git a/tools/qwen/spec_policy.py b/tools/qwen/spec_policy.pyindex a22bee0..c868222 100644--- a/tools/qwen/spec_policy.py+++ b/tools/qwen/spec_policy.py@@ -355,12 +355,21 @@ def ngram_from_env(default=(2, 7, 16, 3)):if not (3 <= len(f) <= 4 and 1 <= g <= LMAX and k >= 1 and m >= g and min(f) >= 0): raise ValueError(f"QWSPEC_NGRAM={v}")return tuple(f)-def load_caps_from_env():+def dense_cuda_rows(model):+ """Verify-row budget for a model whose forward takes many rows at almost the cost of a few: a CUDA build without any+ block-sparse MoE layer (the MoE decode kernels stop at 8 rows, MAX_BSZN, and fall off a cliff above it). Qwen3.8-27B on an+ RTX 3090, 4 requests: target forward 25 ms at 2 rows, 29 ms at 8, 33 ms for 16 (4 x 4), so the uncapped solo depth rule+ (up to 8 rows per request, 32 rows) costs more than the tokens it drafts: 165 tok/s against 219 with a 16-row budget."""+ if torch.version.hip is not None or not torch.cuda.is_available(): return 0+ from exllamav3.modules import BlockSparseMLP+ return 0 if any(isinstance(m, BlockSparseMLP) for m in model) else 16++def load_caps_from_env(model=None):"""(table, rows) from QWSPEC_LOAD_CAPS = "N:D,N:D,..." (draft depth cap D, 0 = no draft, when N requests decode together)and QWSPEC_LOAD_ROWS = R (no table entry for N -> cap R // N - 1, the depth at which the N jobs' verify rows, N * (D + 1),fit one forward of the row-invariant grouped step: generator/row_groups.py runs one forward per 8 rows). Unset / 0 = noload cap, the solo depth rule at every N. Unset QWSPEC_LOAD_ROWS = EXL3_ROW_INV_GROUP_ROWS (8) when EXL3_ROW_INV_GROUPS=1,- else 0; QWSPEC_LOAD_ROWS=0 turns the cap off."""+ else dense_cuda_rows(model) (16 for a dense CUDA model, else 0); QWSPEC_LOAD_ROWS=0 turns the cap off."""v = os.environ.get("QWSPEC_LOAD_CAPS", "").strip()table = {}if v:@@ -369,7 +378,7 @@ def load_caps_from_env():rows = os.environ.get("QWSPEC_LOAD_ROWS", "")if rows.strip() == "": # default: on exactly when the grouped step is on, with its row capon = all(os.environ.get(k, d) not in ("", "0") for k, d in (("EXL3_ROW_INV_GROUPS", "0"), ("EXL3_ROW_INV", "1")))- rows = os.environ.get("EXL3_ROW_INV_GROUP_ROWS", "") or "8" if on else "0"+ rows = os.environ.get("EXL3_ROW_INV_GROUP_ROWS", "") or "8" if on else str(dense_cuda_rows(model) if model is not None else 0)return table, int(rows)def load_depth_cap(n, table, rows):@@ -560,7 +569,7 @@ def install(g, dm, model, thf=0.6, thv=0.3, maxd=3, ngram=None, stats=None, rulelog = list: logging arm. Drafts log_depth depths whatever the rule says, appends one dict per round(n, ng, ps, ids, keep) and verifies what `rule` would have kept (the stream is the baseline stream)."""lm = model.modules[model.logit_layer_idx]- load_table, load_rows = load_caps_from_env()+ load_table, load_rows = load_caps_from_env(model)if rule is None: rule = ProductRule(thf, thv, maxd)maxd = rule.maxd # the rule owns the depth capst = {"i": 0, "stop": False, "keep": None, "ps": [], "job": None, "n": None, "drafted": 0}diff --git a/tools/qwen/test_spec_rule.py b/tools/qwen/test_spec_rule.pyindex 4296c56..7f08f5e 100644--- a/tools/qwen/test_spec_rule.py+++ b/tools/qwen/test_spec_rule.py@@ -362,6 +362,21 @@ class TI(unittest.TestCase):try: self.assertEqual(sp.load_caps_from_env(), ({2: 5, 4: 0}, 8))finally: del os.environ["QWSPEC_LOAD_CAPS"], os.environ["QWSPEC_LOAD_ROWS"]+ def test_load_rows_default_dense_cuda(self):+ keep = {k: os.environ.pop(k, None) for k in ("QWSPEC_LOAD_ROWS", "QWSPEC_LOAD_CAPS", "EXL3_ROW_INV_GROUPS", "EXL3_ROW_INV_GROUP_ROWS")}+ try:+ cuda = sp.torch.version.hip is None and sp.torch.cuda.is_available()+ self.assertEqual(sp.load_caps_from_env([object(), object()]), ({}, 16 if cuda else 0)) # dense model: a 16-row budget on CUDA only+ os.environ["QWSPEC_LOAD_ROWS"] = "0"; self.assertEqual(sp.load_caps_from_env([object()]), ({}, 0))+ os.environ["QWSPEC_LOAD_ROWS"] = "12"; self.assertEqual(sp.load_caps_from_env([object()]), ({}, 12))+ del os.environ["QWSPEC_LOAD_ROWS"]+ from exllamav3.modules import BlockSparseMLP+ self.assertEqual(sp.load_caps_from_env([BlockSparseMLP.__new__(BlockSparseMLP)]), ({}, 0)) # a MoE layer keeps the old default (its decode kernels stop at 8 rows)+ finally:+ for k, v in keep.items():+ os.environ.pop(k, None)+ if v is not None: os.environ[k] = v+def test_load_rows_default_follows_groups(self):keep = {k: os.environ.pop(k, None) for k in ("QWSPEC_LOAD_ROWS", "QWSPEC_LOAD_CAPS", "EXL3_ROW_INV_GROUPS", "EXL3_ROW_INV_GROUP_ROWS")}try: