Skip to content

Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦

C

speculative decoding on by default: Qwen3.8's MTP head and prompt lookup, gated; the plan prices the MTP head

JustVugg1524528a2b8a
diff --git a/README.it.md b/README.it.md
index fec4ada5..7854b340 100644
--- a/README.it.md
+++ b/README.it.md
@@ -515,7 +515,8 @@ stesse sia che un expert risponda dalla VRAM, dalla RAM o dal disco.
senza un prompt da rileggere.
- **Speculazione che si ripaga.** La testa MTP int8 di GLM-5.2 propone 2.2-2.8
token per forward quando conviene; la testa MTP di Qwen3.8-Flash-Next,
- opt-in, aggiunge il 12-14% con lo stesso output. Dove il drafting costa più di
+ accesa di default, aggiunge il 16-20% con lo stesso output, e il lookup sul
+ prompt il 6-7% sulle modifiche al codice. Dove il drafting costa più di
quanto fa risparmiare (DeepSeek V4) resta spento
([tuning.md](docs/tuning.md#speculation-and-reproducibility)).
diff --git a/README.ja.md b/README.ja.md
index 997f419f..e70df26b 100644
--- a/README.ja.md
+++ b/README.ja.md
@@ -313,7 +313,7 @@ curl -s http://127.0.0.1:8000/v1/systemone -H 'Content-Type: application/json' -
- **複数の SSD。** `COLI_MODEL_MIRROR=/second/glm52_i4 ./coli chat --model /fast/glm52_i4` は、2 台目のドライブにあるコピーから読み込みます。独立したコントローラに接続された NVMe ドライブ 2 台で、デコード +37.5% を計測しました。より小さなドライブ上の部分ミラーでも動作します([multidisk.md](docs/multidisk.md))。
- **ラップトップからラックまで。** 25 GB のラップトップでは、すべてのエキスパートがディスクからストリーミングされ、遅いながらも正しく動きます。大きなホストではすべてのエキスパートが常駐し(`CUDA_EXPERT_GB=auto PIN_GB=all`)、ディスクはデコードから外れます。`COLI_NUMA=1` はマルチソケットのホストで、常駐する重みを複数のメモリコントローラに分散させます。ローカルクラスタモードは、ルーティングされるエキスパートをほかのマシンで実行します([cluster.md](docs/cluster.md))。
- **忠実なモデル。** すべてのエンジンは、CI で小さなフィクスチャを使い、そのモデルのリファレンス実装と照合されています。GLM-5.2 の MLA アテンションは圧縮された KV 状態(1 トークンあたり 32,768 個ではなく 576 個の浮動小数点数で、57 分の 1)を保持し、それは再起動をまたいで残るため、会話はプロンプトを読み直すことなく再開できます。
-- **元が取れるときだけの投機的デコード。** GLM-5.2 の int8 MTP ヘッドは、効果がある場合、フォワードあたり 2.2-2.8 トークンをドラフトします。Qwen3.8-Flash-Next の MTP ヘッドはオプトインで、同じ出力のまま速度を 12-14% 上げます。ドラフトのコストが節約を上回る場合(DeepSeek V4)はオフのままです([tuning.md](docs/tuning.md#speculation-and-reproducibility))。
+- **元が取れるときだけの投機的デコード。** GLM-5.2 の int8 MTP ヘッドは、効果がある場合、フォワードあたり 2.2-2.8 トークンをドラフトします。Qwen3.8-Flash-Next の MTP ヘッドはデフォルトで有効で、同じ出力のまま速度を 16-20% 上げます。プロンプトルックアップはコード編集で 6-7% 上げます。ドラフトのコストが節約を上回る場合(DeepSeek V4)はオフのままです([tuning.md](docs/tuning.md#speculation-and-reproducibility))。
エンジンは、共有ヘッダの上に、モデルファミリーごとに C ファイルを 1 つ置いた構成です(GLM-5.2 なら `c/colibri.c`)。BLAS は使わず、実行時に Python も使いません:Python が動かすのは、セットアップ、ランチャー、変換ツール、API ゲートウェイだけです。
diff --git a/README.md b/README.md
index e0040f92..35af295e 100644
--- a/README.md
+++ b/README.md
@@ -487,8 +487,8 @@ expert answered from VRAM, from RAM or from disk.
that survives restarts, so a conversation reopens with no prompt to read
again.
- **Speculation that earns its keep.** GLM-5.2's int8 MTP head drafts 2.2-2.8
- tokens per forward when it pays; Qwen3.8-Flash-Next's MTP head, opt-in, adds
- 12-14% with the same output. Where drafting costs more than it saves (DeepSeek V4)
+ tokens per forward when it pays; Qwen3.8-Flash-Next's MTP head, on by default, adds
+ 16-20% with the same output, and prompt lookup 6-7% on code edits. Where drafting costs more than it saves (DeepSeek V4)
it stays off ([tuning.md](docs/tuning.md#speculation-and-reproducibility)).
The engine is one C file per model family (`c/colibri.c` for GLM-5.2) over
diff --git a/README.zh-CN.md b/README.zh-CN.md
index c5bf00a4..a38f2ee3 100644
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@ -305,7 +305,7 @@ curl -s http://127.0.0.1:8000/v1/systemone -H 'Content-Type: application/json' -
- **不止一块 SSD。** `COLI_MODEL_MIRROR=/second/glm52_i4 ./coli chat --model /fast/glm52_i4` 会同时从第二块硬盘上的副本读取。两块接在独立控制器上的 NVMe 硬盘实测解码速度 +37.5%;放在较小硬盘上的部分镜像也可以([multidisk.md](docs/multidisk.md))。
- **从笔记本到机架。** 在 25 GB 的笔记本上,所有专家都从磁盘流式读取,慢,但结果正确;在大型主机上,所有专家都常驻(`CUDA_EXPERT_GB=auto PIN_GB=all`),磁盘完全退出解码过程。`COLI_NUMA=1` 把常驻权重分布到多路主机的各个内存控制器上,本地集群模式则可以在其他机器上运行路由专家([cluster.md](docs/cluster.md))。
- **忠实的模型。** 每个引擎都在 CI 中用一个微型 fixture 与其模型的参考实现进行对照检查。GLM-5.2 的 MLA 注意力保存压缩后的 KV 状态(每个 token 576 个浮点数,而不是 32,768 个,缩小 57 倍),并且在重启后依然保留,因此重新打开对话时无需再次读取提示词。
-- **物有所值的推测解码。** GLM-5.2 的 int8 MTP head 在划算时每次前向传播起草 2.2-2.8 个 token;Qwen3.8-Flash-Next 的 MTP head 需手动开启,在输出不变的情况下提速 12-14%。在起草成本高于节省的地方(DeepSeek V4),它保持关闭([tuning.md](docs/tuning.md#speculation-and-reproducibility))。
+- **物有所值的推测解码。** GLM-5.2 的 int8 MTP head 在划算时每次前向传播起草 2.2-2.8 个 token;Qwen3.8-Flash-Next 的 MTP head 默认开启,在输出不变的情况下提速 16-20%;提示词查找在代码编辑上提速 6-7%。在起草成本高于节省的地方(DeepSeek V4),它保持关闭([tuning.md](docs/tuning.md#speculation-and-reproducibility))。
引擎是每个模型家族一个 C 文件(GLM-5.2 是 `c/colibri.c`),建立在共享的头文件之上,运行时不需要 BLAS,也不需要 Python:Python 只用于安装程序、启动器、转换工具和 API gateway。
diff --git a/README.zh-TW.md b/README.zh-TW.md
index ad44f532..44a74942 100644
--- a/README.zh-TW.md
+++ b/README.zh-TW.md
@@ -478,8 +478,8 @@ curl -s http://127.0.0.1:8000/v1/systemone -H 'Content-Type: application/json' -
(每個 token 576 個浮點數,而非 32,768 個,小 57 倍),而且重新啟動後依然保留,
因此重新開啟對話時,不需要再讀一次提示。
- **值得才啟用的推測解碼**。GLM-5.2 的 int8 MTP head 在划算時,
- 每次前向傳遞可起草 2.2-2.8 個 token;Qwen3.8-Flash-Next 的 MTP head 需手動開啟,
- 在輸出完全相同的情況下提升 12-14%。在起草的成本高於節省的地方(DeepSeek V4),
+ 每次前向傳遞可起草 2.2-2.8 個 token;Qwen3.8-Flash-Next 的 MTP head 預設開啟,
+ 在輸出完全相同的情況下提升 16-20%;提示詞查找在程式碼編輯上提升 6-7%。在起草的成本高於節省的地方(DeepSeek V4),
它保持關閉([tuning.md](docs/tuning.md#speculation-and-reproducibility))。
引擎由每個模型家族各一個 C 檔案組成(GLM-5.2 為 `c/colibri.c`),
diff --git a/c/colibri.c b/c/colibri.c
index d6620c5d..72081b06 100644
--- a/c/colibri.c
+++ b/c/colibri.c
@@ -12568,7 +12568,7 @@ int main(int argc, char **argv){
g_mlock = getenv("MLOCK")?atoi(getenv("MLOCK")):-1; /* -1 auto (ON macOS), 0 off, 1 force / auto (ON macOS), 0 off, 1 force */
g_spec = getenv("SPEC")?atoi(getenv("SPEC")):1;
g_draft = getenv("DRAFT")?atoi(getenv("DRAFT")):-1;
- g_lookup = getenv("COLI_LOOKUP") && getenv("COLI_LOOKUP")[0]=='1';
+ g_lookup = !(getenv("COLI_LOOKUP") && getenv("COLI_LOOKUP")[0]=='0'); /* on by default, gated */
spec_gate_init(&g_lookup_gate, getenv("COLI_SPEC_GATE") && getenv("COLI_SPEC_GATE")[0]=='0');
g_no_fused_pair = getenv("COLI_NO_FUSED_PAIR")?atoi(getenv("COLI_NO_FUSED_PAIR")):0; /* -1 = auto: 3 se MTP, 0 senza */
g_looka = getenv("LOOKA")?atoi(getenv("LOOKA")):0; /* 1 = misura predicibilita' routing */
diff --git a/c/qwen36.c b/c/qwen36.c
index 9f60e7a4..1565d3af 100644
--- a/c/qwen36.c
+++ b/c/qwen36.c
@@ -4443,7 +4443,9 @@ static int q36_spec_force_mode(const char *v, int *row) {
static void q36_spec_begin(Model *m, Q36Spec *sp, const int *prompt, int np) {
memset(sp, 0, sizeof *sp);
const char *e = getenv("COLI_LOOKUP");
- sp->lookup = e && *e == '1';
+ /* on by default, always gated (docs/speculative.md): COLI_LOOKUP=0 turns it off */
+ int asked = e && *e == '1';
+ sp->lookup = !(e && *e == '0');
e = getenv("COLI_LOOKUP_DRAFTS");
sp->lookup_max = e && *e ? atoi(e) : Q36_SPEC_SNAPS;
if (sp->lookup_max < 1 || sp->lookup_max > Q36_SPEC_SNAPS) {
@@ -4454,7 +4456,7 @@ static void q36_spec_begin(Model *m, Q36Spec *sp, const int *prompt, int np) {
spec_gate_init(&sp->gate, e && *e == '0');
if (sp->lookup && (qt_ready() || g_cache_route || qq_active() || m->dn_dev)) {
static int said;
- if (!said) {
+ if (!said && asked) { /* the default stays quiet: nothing was asked for */
said = 1;
fprintf(stderr, "[qwen36] COLI_LOOKUP=1: no drafts under %s (its results depend on what is "
"resident, so a verify would not reproduce plain decoding)\n",
diff --git a/c/qwen38.c b/c/qwen38.c
index 29229130..ae93bcf4 100644
--- a/c/qwen38.c
+++ b/c/qwen38.c
@@ -1003,7 +1003,7 @@ static Q38Spec q38_spec_begin(Model *m, const int *prompt, int np) {
else if (depth[0] >= '1' && depth[0] <= '3' && !depth[1]) sp.depth = depth[0] - '0';
else { fprintf(stderr, "Q38_MTP_DRAFTS must be 1, 2, 3, or 0 (auto: the gate picks)\n"); exit(1); }
}
- sp.lookup = q38_env_bool("COLI_LOOKUP", 0);
+ sp.lookup = q38_env_bool("COLI_LOOKUP", 1); /* on by default, always gated (docs/speculative.md) */
sp.lookup_max = q38_env_positive_int("COLI_LOOKUP_DRAFTS", Q38_SPEC_ROWS - 1, Q38_SPEC_ROWS - 1);
sp.lk_force = q38_spec_force_mode("COLI_LOOKUP_FORCE", getenv("COLI_LOOKUP_FORCE"), Q38_SPEC_ROWS - 1, 1,
&sp.lk_force_row);
diff --git a/c/qwen38_core.h b/c/qwen38_core.h
index 6943489d..a1e00f7c 100644
--- a/c/qwen38_core.h
+++ b/c/qwen38_core.h
@@ -3728,17 +3728,30 @@ static float q38_mean(const float *x,int n) {
return n?(float)(sum/n):0.f;
}
-/* Q38_MTP=1: load the checkpoint's MTP head and draft with it. Unset or 0
- * leaves it unread, as every run before it. The CLI and serve engine attach
- * it after the model (the Segment and Edge adapters never do); a checkpoint
- * without a head this engine runs is refused rather than decoded without
- * one, so a benchmark cannot quietly measure plain decoding. The head's
+/* The checkpoint's MTP head drafts by default (Q38_MTP unset), when the checkpoint has
+ * one this engine runs and the whole model is loaded; otherwise plain decoding, with a
+ * line. Q38_MTP=0 leaves it unread. The CLI and serve engine attach it after the model
+ * (the Segment and Edge adapters never do). Q38_MTP=1 asks for it: a checkpoint without
+ * a head this engine runs is then refused rather than decoded without one, so a
+ * benchmark cannot quietly measure plain decoding. The head's
* routed experts stay the snapshot's (FP8 on the release): the int4-g64
* sidecar holds the model's layers, and the head's one layer, read on at
* most two rows per draft, is a small part of the expert traffic. */
static void q38_mtp_attach(Model *m,int cap) {
- if(!q38_env_bool("Q38_MTP",0))return;
+ /* On by default when the checkpoint has the head and the whole model is loaded
+ * (docs/speculative.md: +16 to +20% measured, the output plain decoding's); unset,
+ * a checkpoint without it decodes as before with a line. Q38_MTP=1 asks for it and
+ * refuses a checkpoint that cannot; Q38_MTP=0 turns it off. */
+ const char *asked=getenv("Q38_MTP");
+ int forced=asked&&*asked;
+ if(!q38_env_bool("Q38_MTP",1))return;
Cfg *c=&m->c;int H=c->hidden,W=c->hc_width;
+ if(!forced&&(m->range_begin!=0||m->range_end!=c->layers||!m->lm_head.rows||c->mtp_layers!=1)){
+ fprintf(stderr,"[qwen38] speculative decoding with the MTP head: off (%s; Q38_MTP=0 silences this)\n",
+ c->mtp_layers==0?"the checkpoint has no MTP head":c->mtp_layers!=1?"an MTP head this engine does not run":
+ "it needs the whole model loaded");
+ return;
+ }
if(m->range_begin!=0||m->range_end!=c->layers||!m->lm_head.rows){
fprintf(stderr,"Q38_MTP=1 needs the whole model loaded -- refusing\n");exit(1);
}
@@ -3765,6 +3778,11 @@ static void q38_mtp_attach(Model *m,int cap) {
snprintf(probe,sizeof probe,"%s.fc_embedding.weight",bases[i]);
if(st_has(&m->S,probe))found=bases[i];
}
+ if(!found&&!forced){ /* the config names a head the weights do not carry (a stripped container) */
+ fprintf(stderr,"[qwen38] speculative decoding with the MTP head: off (the checkpoint has no "
+ "mtp.fc_embedding.weight; Q38_MTP=0 silences this)\n");
+ return;
+ }
if(!found){fprintf(stderr,"Q38_MTP=1 but the checkpoint has no mtp.fc_embedding.weight -- refusing\n");exit(1);}
snprintf(m->mtp_prefix,sizeof m->mtp_prefix,"%s",found);
uint64_t resident_before=m->resident_weight_bytes;
diff --git a/c/resource_plan.py b/c/resource_plan.py
index df21cc43..b1e767c3 100644
--- a/c/resource_plan.py
+++ b/c/resource_plan.py
@@ -625,6 +625,54 @@ def qwen38_int4_sidecar(info):
expert_fixed_bytes=0, qwen38_int4_experts=True)
+def _q38_mtp_head(info, env):
+ """Price Qwen3.8's MTP head when the engine attaches it (qwen38_core.h,
+ q38_mtp_attach): on by default when the config names one head and the
+ checkpoint carries its weights, off with Q38_MTP=0. The head is one more
+ layer over the model's, which analyze_model does not count: its dense
+ tensors (attention with the indexer, the shared expert, the mixers, the two
+ fc projections) stay resident, priced here at their size on disk, and its
+ routed experts get their own cache of Q38_MTP_CAP slots, the layers' cap by
+ default, at the head's own record (the snapshot's FP8: the int4-g64 sidecar
+ holds the model's layers only). With the default that is one more expert per
+ cache slot; a fixed Q38_MTP_CAP is a fixed cost instead. Without this the
+ plan handed the cache about 0.9 GB the head then took (cap 161 on Qwen3.8
+ Flash Next: 161 FP8 experts of 4.69 MiB, and 173 MiB of head)."""
+ resolved = info["resolved_family"]
+ if resolved.descriptor.id != "qwen38" or (env.get("Q38_MTP") or "").strip() == "0":
+ return info
+ config = info.get("config") or {}
+ text = config.get("text_config", config) if isinstance(config, dict) else {}
+ if text.get("mtp_num_hidden_layers") != 1:
+ return info
+ dense, experts = 0, {}
+ try:
+ for shard in sorted(Path(info["path"]).glob("*.safetensors")):
+ for name, size, _dtype, _shape in _tensor_sizes(shard, with_shape=True):
+ if not (name.startswith("mtp.") or ".mtp." in name):
+ continue
+ expert = re.search(r"\.experts\.(\d+)\.", name)
+ if expert:
+ experts[int(expert[1])] = experts.get(int(expert[1]), 0) + size
+ else:
+ dense += size
+ except OSError:
+ return info
+ if not dense or not experts:
+ return info # a container without the head's weights: the engine decodes without it
+ record = max(experts.values())
+ fixed = info["expert_fixed_bytes"]
+ per_cap = info["per_cap_bytes"]
+ cap = (env.get("Q38_MTP_CAP") or "").strip()
+ if cap.isdigit() and int(cap) > 0:
+ fixed += min(int(cap), len(experts)) * record
+ else:
+ per_cap += record
+ return dict(info, dense_bytes=info["dense_bytes"] + dense, per_cap_bytes=per_cap,
+ expert_fixed_bytes=fixed, qwen38_mtp_head_bytes=dense,
+ qwen38_mtp_expert_bytes=record)
+
+
#: MEMORYSTATUSEX as Windows defines it, in order. Kept as data so a test can
#: pin the order without a Windows machine.
WINDOWS_MEMORYSTATUSEX_FIELDS = (
@@ -1822,6 +1870,7 @@ def build_plan(model, ram_gb=0, context=4096, gpu_indices=None, vram_gb=0,
info = qwen38_int4_sidecar(analyze_model(model))
env_now = os.environ if env is None else env
info = _q38_cpu_dense_tensors(info, env_now)
+ info = _q38_mtp_head(info, env_now)
info = _glm53_dense_tensors(info, env_now)
# Only the matrices a family's dho pass can release earn RAM credit. The
# embedding, norms, CPU-only components and unrecognized formats stay reserved.
diff --git a/c/tests/test_resource_plan.py b/c/tests/test_resource_plan.py
index 4c21d6e4..ba3407da 100644
--- a/c/tests/test_resource_plan.py
+++ b/c/tests/test_resource_plan.py
@@ -27,6 +27,13 @@ from resource_plan import (
)
+def analyze_qwen38_mtp(model, env):
+ """The analysis build_plan works from, after the MTP head's pricing."""
+ import resource_plan
+ info = resource_plan.qwen38_int4_sidecar(resource_plan.analyze_model(model))
+ return resource_plan._q38_mtp_head(info, env)
+
+
def write_shard(path, tensors):
offset = 0
header = {}
@@ -1068,6 +1075,40 @@ memInfo.free: 23.50 GB (97%)
))
write_shard(self.model / "model.safetensors", tensors)
+ def test_qwen38_mtp_head_is_priced_when_the_engine_attaches_it(self):
+ # qwen38_core.h attaches the checkpoint's MTP head by default: its dense
+ # tensors stay resident and its experts get a cache of the layers' cap
+ # (Q38_MTP_CAP), at the head's own record. The plan used to price neither.
+ self.write_qwen38()
+ config = json.loads((self.model / "config.json").read_text())
+ config["text_config"]["mtp_num_hidden_layers"] = 1
+ (self.model / "config.json").write_text(json.dumps(config))
+ head = [("mtp.fc_embedding.weight", 2048, "BF16", [32, 32]),
+ ("mtp.layers.0.self_attn.q_proj.weight", 1024, "BF16", [16, 32])]
+ for e in range(2):
+ for projection in ("gate_proj", "up_proj", "down_proj"):
+ head.append((f"mtp.layers.0.mlp.experts.{e}.{projection}.weight", 512, "F8_E4M3", [16, 32]))
+ write_shard(self.model / "model-mtp.safetensors", head)
+ kwargs = dict(context=64, ram_gb=4, available_memory=16 * GB, available_disk=16 * GB, gpus=[])
+ off = build_plan(self.model, env={"Q38_MTP": "0"}, **kwargs)
+ on = build_plan(self.model, env={}, **kwargs)
+ fixed = build_plan(self.model, env={"Q38_MTP_CAP": "2"}, **kwargs)
+ self.assertEqual(on["tiers"]["ram"]["dense_bytes"] - off["tiers"]["ram"]["dense_bytes"], 2048 + 1024)
+ self.assertEqual(fixed["tiers"]["ram"]["dense_bytes"], on["tiers"]["ram"]["dense_bytes"])
+ # the default: one head expert (3 x 512 bytes) more per cache slot, so a slot costs more
+ self.assertGreaterEqual(off["tiers"]["ram"]["cache_slots_per_layer"],
+ on["tiers"]["ram"]["cache_slots_per_layer"])
+ info_off = analyze_qwen38_mtp(self.model, {"Q38_MTP": "0"})
+ info_on = analyze_qwen38_mtp(self.model, {})
+ info_fixed = analyze_qwen38_mtp(self.model, {"Q38_MTP_CAP": "2"})
+ self.assertEqual(info_on["per_cap_bytes"] - info_off["per_cap_bytes"], 3 * 512)
+ self.assertEqual(info_fixed["per_cap_bytes"], info_off["per_cap_bytes"])
+ self.assertEqual(info_fixed["expert_fixed_bytes"] - info_off["expert_fixed_bytes"], 2 * 3 * 512)
+ # a config that names no head, or a container without its weights: nothing changes
+ config["text_config"]["mtp_num_hidden_layers"] = 0
+ (self.model / "config.json").write_text(json.dumps(config))
+ self.assertEqual(analyze_qwen38_mtp(self.model, {})["per_cap_bytes"], info_off["per_cap_bytes"])
+
def test_qwen38_plan_prices_heterogeneous_cache_exports_cap_and_plans_vram(self):
self.write_qwen38()
MiB = 1 << 20
diff --git a/docs/ENVIRONMENT.md b/docs/ENVIRONMENT.md
index 29dc4bce..26fd7bd3 100644
--- a/docs/ENVIRONMENT.md
+++ b/docs/ENVIRONMENT.md
@@ -348,7 +348,7 @@ These are for testing, benchmarking, or internal use — not part of the everyda
| `GRAMMAR` | unset | Path to a GBNF grammar file to constrain generation. Takes precedence over `SCHEMA`. |
| `SCHEMA` | unset | Path to a JSON-Schema file compiled to GBNF to constrain generation (consulted only when `GRAMMAR` is empty). |
| `GRAMMAR_DRAFT` | unset | Max grammar-forced draft span length. |
-| `COLI_LOOKUP` | `0` (off) | colibri without an MTP head: `=1` takes the n-gram drafts from the prompt lookup of [speculative.md](speculative.md) (the longest suffix of 4 down to 2 tokens seen before, its most recent occurrence) instead of the last bigram, up to `DRAFT` per verify (5 when `DRAFT` is unset), gated by the measured acceptance and forward times (`COLI_SPEC_GATE=0` drafts every proposal). Unset: the bigram source as before. |
+| `COLI_LOOKUP` | `1` (on) | colibri without an MTP head: takes the n-gram drafts from the prompt lookup of [speculative.md](speculative.md) (the longest suffix of 4 down to 2 tokens seen before, its most recent occurrence) instead of the last bigram, up to `DRAFT` per verify (5 when `DRAFT` is unset), gated by the measured acceptance and forward times (`COLI_SPEC_GATE=0` drafts every proposal). Unset: the bigram source as before. |
| `COLI_DRAFT_CORPUS` | unset | Path to a file of frozen token ids (whitespace-separated, `-1` separates spans) used as a speculative draft source: the engine proposes the continuation that followed the longest suffix of the live context found in the corpus. Off when unset. Build one from any run with `TOKENS=1`. See [corpus-draft.md](corpus-draft.md). |
| `COLI_CORPUS_K` | `8` (max 48) | Proposal depth for `COLI_DRAFT_CORPUS`. Deeper raises the forward multiplier and the per-forward cost. |
| `COLI_CORPUS_MINACC` | `50` | Acceptance floor (percent) for the corpus source. Below it over a 24-proposal window the source pauses for 256 tokens, then re-arms — rejected drafts cost real time. |
@@ -486,7 +486,7 @@ and the CPU/GPU execution split.
| `QWEN_EXPERT_KERNEL` | `1` (on) | Routed experts run through the shared `expert_ffn.h` kernel: the int4 stays packed in RAM (planar layout, half the expert-cache RSS of the int8 unpack), gate+up are one pass, and a layer is two OpenMP regions over (expert, row-chunk) items instead of 3 x top-k GEMV regions. Takes effect on an int4 gs=64 container whose hidden and expert widths are multiples of 64, and not under the CUDA expert tier. `=0` restores the unpack-to-int8 path; the two produce the same tokens (1024-token decode on the real container byte-identical; pinned on the tiny int4 fixture in CI), only the f32 accumulation order inside a dot differs. Measured at cap 256 on the real container: 12.8 -> 15.7 tok/s, peak RSS 29 -> 17 GB. |
| `QWEN_DENSE_BATCH` | `1` (on) | On AVX2/FMA, reuse each dense-int8 weight decode across two prompt rows. `=0` restores one GEMV call per row. Decode `S=1` is unchanged. |
| `QWEN_SHARED_BATCH` | bounded by 32 MiB scratch | Batch the CPU shared expert across prompt rows. `=0` restores scalar calls; a positive integer caps rows per chunk. The CUDA-tier overlap path is unchanged. |
-| `COLI_LOOKUP` | `0` (off) | `=1`: prompt-lookup drafts. When the recent tokens repeat an n-gram (4 down to 2 tokens) of the prompt or the output, the tokens that followed it are drafted and checked in one verify forward; the output is that of plain decoding, greedy or sampled. A gate drafts only where the measured acceptance and verify cost say it pays. Off under the CUDA tier, `CACHE_ROUTE` and qpack. See [speculative.md](speculative.md). |
+| `COLI_LOOKUP` | `1` (on) | Prompt-lookup drafts (`0` turns them off). When the recent tokens repeat an n-gram (4 down to 2 tokens) of the prompt or the output, the tokens that followed it are drafted and checked in one verify forward; the output is that of plain decoding, greedy or sampled. A gate drafts only where the measured acceptance and verify cost say it pays. Off under the CUDA tier, `CACHE_ROUTE` and qpack. See [speculative.md](speculative.md). |
| `COLI_LOOKUP_DRAFTS` | `5` | Lookup drafts per verify at most (1..5); a verify of `k` drafts copies the DeltaNet state after `k` rows (63 MiB each on the 35B). |
| `COLI_SPEC_GATE` | `1` (on) | `=0`: every proposal drafted in full, the gate's estimates ignored (tests). |
| `COLI_LOOKUP_FORCE` | unset | Tests only, `ref.json` mode: the reference's tokens as the proposal; `accept`, `mixed`, `cycle`, `row1`..`row5` as for `Q38_MTP_FORCE`. |
@@ -508,12 +508,12 @@ checkpoint layout and the text-only capability boundary.
| `Q38_NATIVE_FP8` | `1` (on) | Keep routed E4M3 expert bytes and their F32 128×128 block scales native in the LRU. `=0` restores expanded-FP32 slots for A/B validation. |
| `Q38_NATIVE_BF16` | `1` (on) | Keep resident and routed BF16 matrices in two-byte storage while retaining FP32 activations/accumulation. `=0` restores the expanded-FP32 reference. |
| `Q38_EXPERT_INT4` | auto | Routed experts from `<snap>/experts-int4g64/`, the int4-g64 sidecar `tools/convert_qwen38_experts_int4.py` writes next to the FP8 shards: 2.76 MB per expert instead of 4.92 MB, so the same RAM holds 1.78x the experts and a miss reads 56% of the bytes. Unset: used when its `index.json` says the conversion is complete (an incomplete one is skipped with a line on stderr; one that disagrees with the model is refused). `=0` keeps the snapshot's FP8 experts; `=1` refuses to start without a complete sidecar. The CUDA expert tier streams FP8 only and stays off with int4 experts; `coli plan` / `--auto-tier` size the cap with the sidecar's records. See [qwen38.md](qwen38.md#routed-experts-as-int4-g64). |
-| `Q38_MTP` | `0` (off) | `=1` loads the checkpoint's MTP head and decodes speculatively: the head drafts the next token and one forward over two rows verifies it; a rejected draft rolls the DeltaNet/PLE state back to a copy taken after the first row. The output is that of plain decoding, greedy or sampled. A checkpoint without an MTP head is refused. Acceptance and tokens/forward go to stderr at the end of a run and after every served turn. Measured on the release with the int4-g64 sidecar: 1.94 tokens/forward and 12-14% more tokens/s, the expert reads from disk being the same with and without it. See [qwen38.md](qwen38.md#speculative-decoding-with-the-mtp-head). |
+| `Q38_MTP` | on when the checkpoint has the head | Loads the checkpoint's MTP head and decodes speculatively (`0`: plain decoding, the head unread; `1`: required, a checkpoint without it is refused; unset, a checkpoint without it decodes plainly with a line): the head drafts the next token and one forward over two rows verifies it; a rejected draft rolls the DeltaNet/PLE state back to a copy taken after the first row. The output is that of plain decoding, greedy or sampled. A checkpoint without an MTP head is refused. Acceptance and tokens/forward go to stderr at the end of a run and after every served turn. Measured on the release with the int4-g64 sidecar: 1.94 tokens/forward and 12-14% more tokens/s, the expert reads from disk being the same with and without it. See [qwen38.md](qwen38.md#speculative-decoding-with-the-mtp-head). |
| `Q38_MTP_WIRING` | `b` | How the MTP head normalizes the model's four streams before `fc_hidden`, which the tensors leave open: `b` one norm per stream (the reading the trained weights agree with: 94-96% of drafts accepted on the release), `a` one norm over all four streams as one vector (85-92%; a diagnostic). Only the acceptance rate depends on it, never the output. |
| `Q38_MTP_CAP` | the cap | Expert cache of the MTP head's layer. Its experts are the snapshot's FP8 even beside the int4-g64 sidecar; the startup line prints what the cache costs full. |
-| `Q38_MTP_DRAFTS` | `2` | With `Q38_MTP=1`: the MTP head's drafts per verify, `1` to `3` (the deeper ones read the head's own streams), or `0` / `auto` to let the gate pick 0 to 3 per verify from the measured acceptance and verify cost. A verify of `k` drafts copies the recurrent state after `k` rows (113 MiB each). The default 2 measured fastest on a Ryzen 7 PRO 8700GE, on the CPU and in the Vulkan dense chain; `1` is the one-draft verify that came before. See [speculative.md](speculative.md). |
+| `Q38_MTP_DRAFTS` | `2` | With the MTP head on: the MTP head's drafts per verify, `1` to `3` (the deeper ones read the head's own streams), or `0` / `auto` to let the gate pick 0 to 3 per verify from the measured acceptance and verify cost. A verify of `k` drafts copies the recurrent state after `k` rows (113 MiB each). The default 2 measured fastest on a Ryzen 7 PRO 8700GE, on the CPU and in the Vulkan dense chain; `1` is the one-draft verify that came before. See [speculative.md](speculative.md). |
| `Q38_MTP_FORCE`, `Q38_MTP_DUMP` | unset | Tests only: `reject` rolls back every draft, `accept` / `mixed` draft the reference's next token (always, every other verify) in `ref.json` mode, `cycle` moves the wrong draft over the rows verify by verify, `row1`..`row3` makes that draft wrong; `Q38_MTP_DUMP=<file>` writes every first draft's row, token and logits. |
-| `COLI_LOOKUP`, `COLI_LOOKUP_DRAFTS`, `COLI_SPEC_GATE`, `COLI_LOOKUP_FORCE` | `0`, `5`, `1`, unset | Prompt-lookup drafts, as for qwen36 below; on qwen38 combined with the MTP head (a verify carries the proposal worth more per unit of time). |
+| `COLI_LOOKUP`, `COLI_LOOKUP_DRAFTS`, `COLI_SPEC_GATE`, `COLI_LOOKUP_FORCE` | `1`, `5`, `1`, unset | Prompt-lookup drafts, as for qwen36 below; on qwen38 combined with the MTP head (a verify carries the proposal worth more per unit of time). |
| `Q38_PREFILL_BATCH` | `1` (on) | Route prompt rows in bounded expert-major chunks and batch resident shared-expert/DeltaNet projections. `=0` restores row-at-a-time prompt execution for A/B diagnosis; decode is unchanged. |
| `Q38_TRUNK_CPU_INT8` | `1` (on) | The dense trunk (DeltaNet and attention projections, hyper-connection mixers, shared expert, router, lm_head; every matrix of at least `Q38_TRUNK_MIN_KB`) is kept on the CPU as int8 rows with one scale per row and the BF16 copy is released; `q38_weight_matmul` quantizes the activation to int8 and uses the integer kernels of `idot.h` for decode and prefill. `=0` keeps the BF16 rows and the f32 kernel (the numeric reference). See [qwen38.md](qwen38.md#the-trunk-on-the-cpu-int8-rows). |
| `COLI_MAP_EXPERTS` | `0` | Point the native-FP8 routed-expert slots (or the int4-g64 sidecar's records) at a read-only mapping of their shard instead of copying 14 MB per miss into a slab. Same variable as in `glm53`. |
diff --git a/docs/qwen36.md b/docs/qwen36.md
index 3a31475b..8f8c6c33 100644
--- a/docs/qwen36.md
+++ b/docs/qwen36.md
@@ -107,10 +107,10 @@ measurements and what they leave out are in
9.94 tok/s against the CPU's 6.01 and the 512-token prompt 9.5 s
([vulkan.md](vulkan.md#the-chain-on-a-radeon-780m)).
-## Prompt-lookup drafts (`COLI_LOOKUP=1`, off by default)
+## Prompt-lookup drafts (on by default, `COLI_LOOKUP=0` turns them off)
When the recent tokens repeat an n-gram of the prompt or the output (a code edit, a
-quote, repeated structure), `COLI_LOOKUP=1` drafts the up to 5 tokens that followed it
+quote, repeated structure), the engine drafts the up to 5 tokens that followed it
and checks them in one verify forward. The DeltaNet state is copied after each verify
row, so a rejected draft rolls back by swapping a copy in. A gate drafts only where the
measured acceptance and verify cost say it pays. The output is that of plain decoding,
diff --git a/docs/qwen38.md b/docs/qwen38.md
index e377ef66..9a110e56 100644
--- a/docs/qwen38.md
+++ b/docs/qwen38.md
@@ -4,8 +4,8 @@
[`Qwen/Qwen3.8-Flash-Next-FP8`](https://huggingface.co/Qwen/Qwen3.8-Flash-Next-FP8)
directly from the official safetensors shards. No conversion or second copy of
the weights is required. The engine supports text and images through the
-checkpoint's vision encoder; see **Vision** below. The checkpoint's optional
-MTP layer drafts tokens for speculative decoding under `Q38_MTP=1`; see
+checkpoint's vision encoder; see **Vision** below. The checkpoint's MTP layer
+drafts tokens for speculative decoding, on by default (`Q38_MTP=0` turns it off); see
[Speculative decoding with the MTP head](#speculative-decoding-with-the-mtp-head).
The upstream language model has 125B ordinary parameters with 6B activated,
@@ -264,10 +264,11 @@ experts on the fake backend.
## Speculative decoding with the MTP head
-Optional, off by default. The release carries one more decoder layer under
+On by default from 1.13.0 when the checkpoint has it (`Q38_MTP=0` turns it off, and
+`Q38_MTP=1` refuses a checkpoint without it). The release carries one more decoder layer under
`mtp.*` that reads the model's four hyper-connection streams at a position
together with the next token's embedding and predicts the token after it.
-`Q38_MTP=1` loads it and decodes speculatively: after each token the head
+The engine loads it and decodes speculatively: after each token the head
drafts the next one, and one forward over both (S=2) returns the logits of the
first as a plain decode step would while it checks the draft. When the token
picked from those logits equals the draft, the second row's logits answer the
@@ -349,7 +350,7 @@ first reads the head's own streams from the row before, with the draft just prop
The verify copies the DeltaNet and PLE state after each of its rows but the last, so a
rejection after row `k` restores the state after row `k`. `Q38_MTP_DRAFTS=0` lets a gate
pick the depth per verify from the measured acceptance by position and the measured
-cost of a verify by its rows. `COLI_LOOKUP=1` adds prompt-lookup drafts (up to 5, from
+cost of a verify by its rows. Prompt lookup (on by default) adds drafts (up to 5, from
the context's n-grams), and a verify carries whichever proposal is worth more. The
output stays that of plain decoding. Measured on the release with the int4-g64 sidecar: 4.94 tok/s at two drafts against 4.71 at one and 4.12 without MTP on the CPU (2.75 tokens per forward), 4.55 against 4.39 and 3.91 with the Vulkan tier and chain on a Radeon 780M, so two drafts is the default. The details, the settings and the
tests are in [speculative.md](speculative.md).
diff --git a/docs/speculative.md b/docs/speculative.md
index ee968c3c..9b408b0a 100644
--- a/docs/speculative.md
+++ b/docs/speculative.md
@@ -11,9 +11,9 @@ What runs where:
| Engine | Draft sources | Verify |
|---|---|---|
-| `qwen38` (Qwen3.8 Flash Next) | the checkpoint's MTP head, up to 3 drafts (`Q38_MTP=1`, `Q38_MTP_DRAFTS`); prompt lookup, up to 5 (`COLI_LOOKUP=1`) | up to 6 rows, on the CPU or in the Vulkan dense chain |
-| `qwen36` (Qwen3.6, Qwen3-Coder, Qwen3.8-27B) | prompt lookup, up to 5 (`COLI_LOOKUP=1`) | up to 6 rows, on the CPU or in the Vulkan dense chain |
-| `colibri` (GLM-5.2) | its MTP head and n-gram drafts as before; with `COLI_LOOKUP=1` and no head, the n-gram drafts come from the prompt lookup below and its gate | as before |
+| `qwen38` (Qwen3.8 Flash Next) | the checkpoint's MTP head, up to 3 drafts (on by default when the checkpoint has it; `Q38_MTP=0` off, `Q38_MTP_DRAFTS`); prompt lookup, up to 5 (on by default; `COLI_LOOKUP=0` off) | up to 6 rows, on the CPU or in the Vulkan dense chain |
+| `qwen36` (Qwen3.6, Qwen3-Coder, Qwen3.8-27B) | prompt lookup, up to 5 (on by default; `COLI_LOOKUP=0` off) | up to 6 rows, on the CPU or in the Vulkan dense chain |
+| `colibri` (GLM-5.2) | its MTP head as before; without a head, the n-gram drafts come from the prompt lookup below and its gate by default (`COLI_LOOKUP=0`: its own n-gram drafts as before) | as before |
## How a verify works
@@ -60,8 +60,8 @@ per copy, each ending on its row. The state crosses between them through memory
so the rows get the bits of the single dispatch.
Drafting stays off where a row's result depends on what is resident: qwen36 under the
-CUDA expert tier, `CACHE_ROUTE` or a qpack container (`[qwen36] COLI_LOOKUP=1: no
-drafts under ...`). One case stays inside the gate but changes the last bits: with the
+CUDA expert tier, `CACHE_ROUTE` or a qpack container (with `COLI_LOOKUP=1` asked for, a
+`[qwen36] COLI_LOOKUP=1: no drafts under ...` line says so; the default stays quiet). One case stays inside the gate but changes the last bits: with the
Vulkan expert tier on, a verify's rows, the rejected drafts' included, feed the tier's
history, so which experts are on the device follows what was drafted. An expert on the
device sums in a different order than on the CPU, so the logits of a run with drafts and
@@ -77,7 +77,9 @@ not a recommendation to freeze the tier for normal use.
## The MTP head's drafts (qwen38)
-`Q38_MTP=1` loads the head (see [qwen38.md](qwen38.md#speculative-decoding-with-the-mtp-head)).
+The engine loads the head by default when the checkpoint has one and the whole model is
+loaded, and says so when it cannot; `Q38_MTP=0` leaves it unread, and `Q38_MTP=1` refuses a
+checkpoint without one (see [qwen38.md](qwen38.md#speculative-decoding-with-the-mtp-head)).
Its first draft reads the model's four streams at the last fed position with the picked
token. Each next draft reads the head's own streams from the row before, in place of the
model's (only the verify computes those), with the draft just proposed. Those deeper
@@ -91,7 +93,8 @@ fastest (below). `Q38_MTP_DRAFTS=1` is the one-draft verify that came before.
## Prompt lookup
-`COLI_LOOKUP=1` looks for the longest n-gram of 4 down to 2 tokens that ends the token
+Prompt lookup (on by default; `COLI_LOOKUP=0` turns it off) looks for the longest n-gram of
+4 down to 2 tokens that ends the token
history (prompt and output so far) and also occurs earlier in it, at its most recent
earlier occurrence. The up to 5 tokens that followed it there are the proposal
(`COLI_LOOKUP_DRAFTS` caps it, 1 to 5). Code edits, quotes and repeated structure give
@@ -144,8 +147,9 @@ state is the one plain decoding leaves.
| Variable | Default | Effect |
|---|---|---|
-| `Q38_MTP_DRAFTS` | `2` | qwen38 with `Q38_MTP=1`: the MTP head's drafts per verify, `1` to `3`, or `0` / `auto` for the gate's pick. |
-| `COLI_LOOKUP` | `0` | `1`: prompt-lookup drafts (qwen38, qwen36), and colibri's n-gram drafts from the same lookup and gate when it has no MTP head. |
+| `Q38_MTP` | on when the checkpoint has the head | `0`: plain decoding, the head unread; `1`: the head, and a checkpoint without one is refused. The RAM plan (`coli plan`) prices the head when it is on: its dense tensors and its own expert cache (`Q38_MTP_CAP`, the layers' cap by default, at the head's FP8 record). |
+| `Q38_MTP_DRAFTS` | `2` | qwen38 with the MTP head on: the MTP head's drafts per verify, `1` to `3`, or `0` / `auto` for the gate's pick. |
+| `COLI_LOOKUP` | `1` | Prompt-lookup drafts (qwen38, qwen36), and colibri's n-gram drafts from the same lookup and gate when it has no MTP head; always gated. `0` turns them off. |
| `COLI_LOOKUP_DRAFTS` | `5` | Lookup drafts per verify at most, `1` to `5`. |
| `COLI_SPEC_GATE` | `1` | `0`: every proposal drafted in full, the gate's estimates ignored (tests). |
| `Q38_MTP_FORCE`, `COLI_LOOKUP_FORCE` | unset | Tests: in `ref.json` mode, `accept` drafts the reference's tokens, `mixed` makes every other verify's first draft wrong, `cycle` moves the wrong draft over the rows verify by verify, `rowN` makes draft `N` wrong; `Q38_MTP_FORCE=reject` also refuses every draft. |
@@ -201,10 +205,9 @@ against 10.37 and 10.47.
So lookup pays where the output repeats the context (+6 to 7% on the edit) and costs
nothing where it does not. With the MTP head attached, the head's drafts were worth more
-than lookup's on this edit (100% acceptance). `COLI_LOOKUP` stays off by default anyway:
-without `COLI_VULKAN` every engine's default must stay what it was, and qwen36's serve
-`PROF` frame counts the forwards a turn took, which drafts change. Turn it on for code
-editing and other copy-heavy work.
+than lookup's on this edit (100% acceptance). Since it costs nothing where it
+does not pay, lookup is on by default from 1.13.0, like the MTP head; `COLI_LOOKUP=0` turns
+it off. A turn's `PROF` frame counts the forwards it took, which drafts change.
**Vulkan follow-up, existing int4-g64 sidecar.** On the same 780M, with the code-edit
prompt above (241 prompt tokens), 128 generated tokens, cap 170, eight threads and
@@ -266,7 +269,7 @@ in RAM, and any discrete GPU (none was available).
- `spec_gate_draft_cost(&gate, source, seconds)` per extra draft, for a source whose
deeper drafts cost time.
-colibri's n-gram source does exactly this under `COLI_LOOKUP=1` (`spec_decode` in
+colibri's n-gram source does exactly this by default (`COLI_LOOKUP=0`: its own drafts; `spec_decode` in
`c/colibri.c`). GLM-5.2 is attention only, so its verify needs no copies: a rejection
rewinds `kv` and the next forward overwrites the rows. DeepSeek V4.1's DSpark drafter
(`c/deepseek_v41.c`) has a verify path of its own, with the window rings' undo rows; its