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

qwen38 MTP: wiring b by default, measured on the release; wiring c removed

JustVuggaf2a522edc44
diff --git a/c/Makefile b/c/Makefile
index 667d5098..dd2957c8 100644
--- a/c/Makefile
+++ b/c/Makefile
@@ -1396,8 +1396,9 @@ qwen38-tiny-int4-check: qwen38-tiny-int4-generate qwen38-tiny-fp8-generate qwen3
# model and its references do not change) and a byte tokenizer for the text
# and serve gates. tests/test_qwen38_mtp.py checks:
# (a) the head's draft logits equal tools/qwen38_mtp_ref.py's float32
-# reference for every Q38_MTP_WIRING, through the one-row and the
-# two-row (after an accepted draft) paths, on BF16 and FP8 experts;
+# reference for the default wiring b and the diagnostic a, through the
+# one-row and the two-row (after an accepted draft) paths, on BF16 and
+# FP8 experts;
# (b) decoding with drafts is byte-identical to Q38_MTP=0 (stdout and last
# logits) at caps 1/2/8, prefill batching on and off, BF16 and int8
# trunk, on BF16, FP8 and int4-g64 experts, in the normal mode and with
diff --git a/c/qwen38_core.h b/c/qwen38_core.h
index 2fbe1b86..d5157847 100644
--- a/c/qwen38_core.h
+++ b/c/qwen38_core.h
@@ -2983,24 +2983,25 @@ static float *q38_forward(Model *m,const int *ids,int S,int pos_base,int nlogits
* [hidden, hidden]; the token's embedding meets pre_fc_norm_embedding
* [hidden] and fc_embedding [hidden, hidden]. Two square projections add (a
* single fc over the concatenation [e; h] is the same sum split in two), and
- * the sum is a stream. Q38_MTP_WIRING picks one reading of the rest:
- * a (default) pre_fc_norm_hidden normalizes the 4*hidden vector as one
- * vector -- q38_rms0 over all of it, the way pre_fc_norm_embedding
- * normalizes its input; neither norm belongs to a GatedResidual -- then
- * fc_hidden maps each stream and fc_embedding(norm(e)) is added to all
- * four, as q38_forward puts a token's embedding in all four streams;
- * b as a, but the norm is per stream: q38_rms0 over each hidden-wide
- * stream with its slice of the weight, the grouping hc_norm has in
+ * the sum is a stream: fc_hidden maps each of the four streams and
+ * fc_embedding(norm(e)) is added to all four, as q38_forward puts a token's
+ * embedding in all four streams. What the shapes do not say is how
+ * pre_fc_norm_hidden [4*hidden] groups its input; Q38_MTP_WIRING picks:
+ * b (default) a norm per stream: q38_rms0 over each hidden-wide stream
+ * with its slice of the weight, the grouping hc_norm has in
* q38_gr_read;
- * c the per-stream norm of b, the four streams averaged into one vector,
- * fc_hidden on that, plus fc_embedding(norm(e)), and the result copied
- * into the four streams as q38_forward does with an embedding.
+ * a one norm over the whole 4*hidden vector, the way
+ * pre_fc_norm_embedding normalizes its input.
* The output is the same whichever is chosen (the verify decides every
- * token); the wirings differ in how often a draft is right, which only the
- * trained weights can say, and the acceptance rate measures. Each norm is
- * zero-centered (q38_rms0) like every Qwen4-Exp text RMSNorm but DeltaNet's
- * gated one; q38_mtp_attach prints the mean of each norm weight, near 0 for
- * that reading and near 1 for a plain norm. The pair (streams at p, token at
+ * token); only how often a draft is right differs, and only the trained
+ * weights can say which reading they were trained with. Measured on the
+ * release (docs/qwen38.md), b accepts 94-96% of the drafts and a 85-92%.
+ * A third reading, the normalized streams averaged into one vector before a
+ * single fc_hidden, accepted 63-78% and is gone. Each norm is zero-centered
+ * (q38_rms0) like every Qwen4-Exp text RMSNorm but DeltaNet's gated one;
+ * q38_mtp_attach prints the mean of each norm weight, which on the release
+ * are -0.76, -0.33 and 3.79 (embedding, hidden, mixer): far from the 1 a
+ * plain norm's weights start from. The pair (streams at p, token at
* p+1) is the head's row p: its K/V row and its RoPE position are p.
* Counting it at p+1 instead would change no score beyond rounding, since
* RoPE and the indexer's block scores depend on distances only.
@@ -3010,7 +3011,7 @@ static float *q38_forward(Model *m,const int *ids,int S,int pos_base,int nlogits
* forward waits in mtp_pend, a draft runs the pending rows with the token
* the caller just picked, and the rows of a verify wait until the caller's
* next pick settles which of them stand. */
-enum { Q38_MTP_WHOLE_NORM='a', Q38_MTP_STREAM_NORM='b', Q38_MTP_STREAM_MEAN='c' };
+enum { Q38_MTP_WHOLE_NORM='a', Q38_MTP_STREAM_NORM='b' };
/* Q38_MTP_FORCE (tests): 'r' rejects every draft, a right one too, so the
* rollback runs on every token; 'a' drafts the reference's next token
@@ -3035,25 +3036,12 @@ static void q38_mtp_input(Model *m,const float *streams,const int *next,int S,in
else for(int b=0;b<C;b++)
q38_rms0(y+(int64_t)b*H,x+(int64_t)b*H,m->mtp_norm_hid+(int64_t)b*H,H,c->eps);
}
- if(m->mtp_wiring==Q38_MTP_STREAM_MEAN){
- float *mean=falloc((int64_t)S*H),*fh=falloc((int64_t)S*H);
- for(int s=0;s<S;s++)for(int d=0;d<H;d++){
- float v=0.f;for(int b=0;b<C;b++)v+=hn[(int64_t)s*W+(int64_t)b*H+d];
- mean[(int64_t)s*H+d]=v/C;
- }
- q38_dense_matmul(m,fh,mean,&m->mtp_fc_hid,S,H,H);
- for(int s=0;s<S;s++)for(int b=0;b<C;b++)for(int d=0;d<H;d++)
- hyper[(int64_t)s*W+(int64_t)b*H+d]=fh[(int64_t)s*H+d]+fe[(int64_t)s*H+d];
- free(mean);free(fh);
- } else {
- /* fc_hidden on every stream: S rows of four streams are S*C rows of hidden */
- float *fh=falloc((int64_t)S*W);
- q38_dense_matmul(m,fh,hn,&m->mtp_fc_hid,S*C,H,H);
- for(int s=0;s<S;s++)for(int b=0;b<C;b++)for(int d=0;d<H;d++)
- hyper[(int64_t)s*W+(int64_t)b*H+d]=fh[(int64_t)s*W+(int64_t)b*H+d]+fe[(int64_t)s*H+d];
- free(fh);
- }
- free(en);free(fe);free(row);free(hn);
+ /* fc_hidden on every stream: S rows of four streams are S*C rows of hidden */
+ float *fh=falloc((int64_t)S*W);
+ q38_dense_matmul(m,fh,hn,&m->mtp_fc_hid,S*C,H,H);
+ for(int s=0;s<S;s++)for(int b=0;b<C;b++)for(int d=0;d<H;d++)
+ hyper[(int64_t)s*W+(int64_t)b*H+d]=fh[(int64_t)s*W+(int64_t)b*H+d]+fe[(int64_t)s*H+d];
+ free(fh);free(en);free(fe);free(row);free(hn);
}
/* The head over S pairs at rows pos_base..pos_base+S-1: their K/V/indexer
@@ -3271,10 +3259,9 @@ static void q38_mtp_attach(Model *m,int cap) {
exit(1);
}
const char *wiring=getenv("Q38_MTP_WIRING");
- m->mtp_wiring=wiring&&*wiring?wiring[0]:Q38_MTP_WHOLE_NORM;
- if((wiring&&*wiring&&wiring[1])||(m->mtp_wiring!=Q38_MTP_WHOLE_NORM&&
- m->mtp_wiring!=Q38_MTP_STREAM_NORM&&m->mtp_wiring!=Q38_MTP_STREAM_MEAN)){
- fprintf(stderr,"Q38_MTP_WIRING must be a, b or c (qwen38_core.h, the MTP head)\n");exit(1);
+ m->mtp_wiring=wiring&&*wiring?wiring[0]:Q38_MTP_STREAM_NORM;
+ if((wiring&&*wiring&&wiring[1])||(m->mtp_wiring!=Q38_MTP_WHOLE_NORM&&m->mtp_wiring!=Q38_MTP_STREAM_NORM)){
+ fprintf(stderr,"Q38_MTP_WIRING must be b (the default) or a (qwen38_core.h, the MTP head)\n");exit(1);
}
/* the release keeps the head at the top level, next to model.* */
char probe[96];const char *found=NULL;
@@ -3312,9 +3299,8 @@ static void q38_mtp_attach(Model *m,int cap) {
snprintf(nm,sizeof nm,"%s.layers.0.mlp.experts.0.gate_proj.weight",found);
st_tensor *expert=st_find(&m->S,nm);
double expert_bytes=expert?3.0*(double)expert->nbytes:0.0; /* gate, up and down are the same size */
- const char *how=m->mtp_wiring==Q38_MTP_WHOLE_NORM?"one norm over the four streams, fc_hidden per stream":
- m->mtp_wiring==Q38_MTP_STREAM_NORM?"a norm per stream, fc_hidden per stream":
- "a norm per stream, the streams averaged, one fc_hidden";
+ const char *how=m->mtp_wiring==Q38_MTP_STREAM_NORM?"a norm per stream, fc_hidden per stream":
+ "one norm over the four streams, fc_hidden per stream (diagnostic; b is the default)";
fprintf(stderr,"[qwen38] MTP head %s.*: wiring %c (%s), RoPE base %g, %.2f MiB resident; "
"routed experts %s from the snapshot%s, cache %d (Q38_MTP_CAP) x %.2f MiB = %.2f GiB full\n",
found,m->mtp_wiring,how,(double)c->mtp_theta,
@@ -3322,7 +3308,7 @@ static void q38_mtp_attach(Model *m,int cap) {
expert?st_dtype_name(expert->dtype):"(fused)",m->x4?" (the int4-g64 sidecar covers the model's layers)":"",
mtp_cap,expert_bytes/1048576.0,expert_bytes*mtp_cap/1073741824.0);
fprintf(stderr,"[qwen38] MTP norm weights, mean: embedding %.4f, hidden %.4f, mixer %.4f "
- "(q38_rms0 scales by 1+w: near 0 fits it, near 1 would mean a plain norm)\n",
+ "(q38_rms0 scales by 1+w; a plain norm's weights would sit near 1)\n",
q38_mean(m->mtp_norm_emb,H),q38_mean(m->mtp_norm_hid,W),q38_mean(m->mtp_mixer.norm,W));
}
diff --git a/c/tests/test_qwen38_mtp.py b/c/tests/test_qwen38_mtp.py
index b78f855d..2e8f748e 100644
--- a/c/tests/test_qwen38_mtp.py
+++ b/c/tests/test_qwen38_mtp.py
@@ -7,9 +7,10 @@ serve). Gates:
head the engine's draft logits (Q38_MTP_DUMP, one record per draft)
equal tools/qwen38_mtp_ref.py's float32 reference of the head to
- float tolerance, for each wiring of Q38_MTP_WIRING, through the
- one-row and the two-row (after an accepted draft) paths; and the
- wirings really differ.
+ float tolerance, for the default wiring b and the diagnostic a
+ (Q38_MTP_WIRING), through the one-row and the two-row (after an
+ accepted draft) paths, each closer to its own reference than to
+ the other's.
lossless with the head drafting, stdout and the last logits (DUMP) are
byte-identical to Q38_MTP=0 at caps 1/2/8, prefill batching on
and off, BF16 and int8 trunk, in the normal mode and in the three
@@ -114,22 +115,22 @@ def check_head(engine, model):
data = json.loads((model / "ref.json").read_text(encoding="utf-8"))
ids, vocab = data["full_ids"], len(data["final_logits"])
print(f"head: {model}")
- references = {w: ref.mtp_logits(model, ids, w).numpy() for w in "abc"}
- for a, b in (("a", "b"), ("a", "c"), ("b", "c")):
- gap = float(np.abs(references[a] - references[b]).max())
- check(gap > 2e-6, f"wirings {a} and {b} give different logits (max |diff| {gap:.3g})")
+ references = {w: ref.mtp_logits(model, ids, w).numpy() for w in "ba"}
+ gap = float(np.abs(references["a"] - references["b"]).max())
+ check(gap > 2e-6, f"wirings b and a give different logits (max |diff| {gap:.3g})")
with tempfile.TemporaryDirectory() as tmp:
- for wiring in "abc":
+ # b with Q38_MTP_WIRING unset, as the engine runs by default; a by name
+ for wiring, knob in (("b (default)", {}), ("a", {"Q38_MTP_WIRING": "a"})):
rows_seen = set()
for mode in ("reject", "mixed"):
- dump = Path(tmp) / f"{wiring}-{mode}.f32"
+ dump = Path(tmp) / f"{wiring[0]}-{mode}.f32"
# reject drafts at every token (rows past the prompt, one pending
# row each); mixed reaches the head with two pending rows after
# each accepted draft. The BF16 trunk: every fixture matrix is
# under the 1 MiB int8 threshold.
r = run(engine, model, [2, 8, model / "ref.json"],
- {"Q38_MTP": "1", "Q38_MTP_WIRING": wiring, "Q38_MTP_FORCE": mode,
- "Q38_MTP_DUMP": str(dump), "Q38_TRUNK_MIN_KB": "1024"})
+ dict(knob, Q38_MTP="1", Q38_MTP_FORCE=mode,
+ Q38_MTP_DUMP=str(dump), Q38_TRUNK_MIN_KB="1024"))
if r.returncode:
check(False, f"wiring {wiring} {mode}: engine exit {r.returncode}\n"
+ r.stderr.decode(errors="replace")[-2000:])
@@ -140,15 +141,16 @@ def check_head(engine, model):
check(False, f"wiring {wiring} {mode}: draft row {row} paired token {token}, "
f"the sequence has {ids[row + 1]}")
continue
- errors = {w: float(np.abs(logits - references[w][row]).max()) for w in "abc"}
- worst = max(worst, errors[wiring])
- nearest_other = min(nearest_other, *(e for w, e in errors.items() if w != wiring))
- argmax_ok &= int(logits.argmax()) == int(references[wiring][row].argmax())
+ own = wiring[0]
+ errors = {w: float(np.abs(logits - references[w][row]).max()) for w in "ba"}
+ worst = max(worst, errors[own])
+ nearest_other = min(nearest_other, *(e for w, e in errors.items() if w != own))
+ argmax_ok &= int(logits.argmax()) == int(references[own][row].argmax())
rows += 1
rows_seen.add(row)
check(rows > 0 and worst <= 1e-6 and 20 * worst <= nearest_other and argmax_ok,
f"wiring {wiring} {mode}: {rows} draft rows within {worst:.2g} of the reference "
- f"(the other wirings' are {nearest_other:.2g} away), argmax {'equal' if argmax_ok else 'DIFFERS'}")
+ f"(the other wiring's is {nearest_other:.2g} away), argmax {'equal' if argmax_ok else 'DIFFERS'}")
check(rows_seen >= set(range(len(data["prompt_ids"]) - 1, len(ids) - 3)),
f"wiring {wiring}: rows {sorted(rows_seen)} compared")
@@ -191,7 +193,7 @@ def check_lossless(engine, model, ref_name, extra=None):
+ on.stdout.decode(errors="replace") + on.stderr.decode(errors="replace")[-1500:])
configs += 1
off = run(engine, model, [8, 8, model / ref_name], dict(extra))
- for knob in ({"Q38_MTP_WIRING": "b"}, {"Q38_MTP_WIRING": "c"}, {"Q38_MTP_CAP": "1"}):
+ for knob in ({"Q38_MTP_WIRING": "a"}, {"Q38_MTP_CAP": "1"}):
on = run(engine, model, [8, 8, model / ref_name], dict(extra, Q38_MTP="1", **knob))
name = " ".join(f"{k}={v}" for k, v in knob.items())
check(on.returncode == 0 and on.stdout == off.stdout, f"{name}: output equals MTP off")
@@ -349,7 +351,7 @@ def main():
if FAILS:
print(f"qwen38 MTP: {len(FAILS)} check(s) failed")
return 1
- print("qwen38 MTP: head matches the reference for wirings a, b, c; decoding with drafts is "
+ print("qwen38 MTP: head matches the reference for wirings b (default) and a; decoding with drafts is "
"byte-identical to decoding without them")
return 0
diff --git a/c/tools/qwen38_mtp_ref.py b/c/tools/qwen38_mtp_ref.py
index 414207fe..ba6bcb47 100644
--- a/c/tools/qwen38_mtp_ref.py
+++ b/c/tools/qwen38_mtp_ref.py
@@ -7,8 +7,9 @@ qwen38_core.h documents next to q38_mtp_input (the MTP head):
* the model's four hyper-connection streams at position p -- the
``hidden_size * hc_count`` vector the final mixer reads, captured here as the
input of ``model.hyper_connection_mixer`` -- and the embedding of the token
- at p+1 become four streams through ``pre_fc_norm_*`` and ``fc_*``, in one of
- the wirings a, b or c (``fuse`` below);
+ at p+1 become four streams through ``pre_fc_norm_*`` and ``fc_*``, with
+ ``pre_fc_norm_hidden`` grouped per stream (wiring b, the engine's default)
+ or over the whole vector (wiring a; ``fuse`` below);
* those streams run through one decoder layer with the tensors under
``mtp.layers.0`` -- the transformers ``Qwen4ExpTextDecoderLayer``, the oracle
the engine's own layers are checked against, built as an attention layer
@@ -25,7 +26,7 @@ times the block's ``weight_scale_inv`` in f32, so the reference sees the
engine's weights and not the BF16 rounding the fixture generator kept in
memory.
- python tools/qwen38_mtp_ref.py --model ./qwen38_tiny_mtp --wiring a
+ python tools/qwen38_mtp_ref.py --model ./qwen38_tiny_mtp --wiring b
"""
import argparse
@@ -142,22 +143,21 @@ def rms0(x, weight, eps):
def fuse(streams, embedded, weights, config, wiring):
"""The head's input streams [S, hc_count*H] from the model's streams at p
- [S, hc_count*H] and the embeddings of the tokens at p+1 [S, H]."""
+ [S, hc_count*H] and the embeddings of the tokens at p+1 [S, H]: fc_hidden
+ on every normalized stream, fc_embedding of the normalized embedding added
+ to all four."""
C, H, eps = config.hc_count, config.hidden_size, config.rms_norm_eps
w_hid = weights["mtp.pre_fc_norm_hidden.weight"]
fe = rms0(embedded, weights["mtp.pre_fc_norm_embedding.weight"], eps) @ weights["mtp.fc_embedding.weight"].T
fc_hidden = weights["mtp.fc_hidden.weight"]
S = streams.shape[0]
- if wiring == "a": # one norm over the whole vector, fc_hidden per stream, embedding into all four
+ if wiring == "b": # a norm per stream
+ normed = rms0(streams.view(S, C, H), w_hid.view(C, H), eps)
+ elif wiring == "a": # one norm over the whole vector
normed = rms0(streams, w_hid, eps).view(S, C, H)
- return (normed @ fc_hidden.T + fe[:, None, :]).reshape(S, C * H)
- per_stream = rms0(streams.view(S, C, H), w_hid.view(C, H), eps)
- if wiring == "b": # a norm per stream, fc_hidden per stream, embedding into all four
- return (per_stream @ fc_hidden.T + fe[:, None, :]).reshape(S, C * H)
- if wiring == "c": # a norm per stream, the streams' mean, one fc_hidden, copied to all four
- one = per_stream.mean(1) @ fc_hidden.T + fe
- return one.repeat(1, C)
- raise ValueError(f"wiring {wiring!r}: a, b or c")
+ else:
+ raise ValueError(f"wiring {wiring!r}: b or a")
+ return (normed @ fc_hidden.T + fe[:, None, :]).reshape(S, C * H)
def mtp_layer(config, cfg, weights):
@@ -211,7 +211,7 @@ def mtp_logits(model_dir, ids, wiring):
def main():
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument("--model", required=True, type=Path)
- parser.add_argument("--wiring", default="a", choices="abc")
+ parser.add_argument("--wiring", default="b", choices="ba")
parser.add_argument("--ids", help="comma-separated ids (default: ref.json full_ids)")
args = parser.parse_args()
ids = ([int(x) for x in args.ids.split(",")] if args.ids else
diff --git a/docs/ENVIRONMENT.md b/docs/ENVIRONMENT.md
index e80baa85..9d19b1a0 100644
--- a/docs/ENVIRONMENT.md
+++ b/docs/ENVIRONMENT.md
@@ -445,8 +445,8 @@ 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. See [qwen38.md](qwen38.md#speculative-decoding-with-the-mtp-head). |
-| `Q38_MTP_WIRING` | `a` | How the head's two inputs become its four streams, which the tensors leave open: `a` one norm over the 4 x hidden streams, `b` one norm per stream, `c` per-stream norms averaged before `fc_hidden` (`c/qwen38_core.h`, "the MTP head"). Only the acceptance rate depends on it. |
+| `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_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_FORCE`, `Q38_MTP_DUMP` | unset | Tests only: `reject` rolls back every draft, `accept` / `mixed` draft the reference's next token (always, every other one) in `ref.json` mode; `Q38_MTP_DUMP=<file>` writes every draft's row, token and logits. |
| `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. |
diff --git a/docs/qwen38.md b/docs/qwen38.md
index bea6d1dc..8392388d 100644
--- a/docs/qwen38.md
+++ b/docs/qwen38.md
@@ -285,17 +285,18 @@ order follows which experts are resident when.
The head is built only from blocks the engine already runs for its own layers:
the decoder layer is a QSA attention layer with its indexer, gated residuals,
the MoE with its shared expert, the head's own hyper-connection mixer and the
-shared `lm_head`. How its two inputs become the four streams that layer reads
-is not fixed by the tensors, so `Q38_MTP_WIRING` selects a reading (`c/qwen38_core.h`,
-"the MTP head"): `a` (default) normalizes the 4 x 2560 streams as one vector,
-`b` normalizes each stream, `c` averages the normalized streams before
-`fc_hidden`. The output does not depend on the choice; the acceptance rate does,
-and it is what tells which reading the trained weights agree with.
+shared `lm_head`. The tensors do not say how `pre_fc_norm_hidden` (4 x 2560
+wide) groups the model's four streams before `fc_hidden` maps each of them, so
+`Q38_MTP_WIRING` selects it (`c/qwen38_core.h`, "the MTP head"): `b`, the
+default, normalizes each stream on its own, the way the hyper-connection norms
+do; `a` normalizes the four streams as one vector and stays as a diagnostic.
+The output does not depend on the choice. The acceptance rate does, and on the
+release it picks `b`.
Every run prints its line, and a served request prints one per turn, on stderr:
```
-[qwen38 MTP] run: 1.75 tokens/forward (4 forwards per 7 tokens) | acceptance 100.0% (3/3 drafts) | wiring a
+[qwen38 MTP] run: 1.94 tokens/forward (51 forwards per 99 tokens) | acceptance 94.1% (48/51 drafts) | wiring b
```
Tokens are the decode tokens after the prompt and forwards the forwards that
@@ -304,9 +305,46 @@ without the int4-g64 sidecar (one layer read for at most two rows per draft is
a small share of the expert traffic); their cache holds `Q38_MTP_CAP` experts,
by default the cap every layer has, and the startup line prints what it costs.
+### Measured
+
+On the release with the int4-g64 sidecar (Ryzen 7 PRO 8700GE, 16 threads,
+61 GiB, NVMe; model files dropped from the page cache before every run, load
+average under 2, `OMP_NUM_THREADS=8`, 100 new tokens). Greedy output was
+byte-identical to MTP off in every run.
+
+| prompt, cap | wiring | acceptance | tokens/forward | tok/s |
+|---|---|---|---|---|
+| raw text prompt, cap 96 | MTP off | | | 3.57 |
+| | a | 92.2% (47/51) | 1.90 | 3.97 |
+| | **b** | **96.0% (48/50)** | **1.94** | **4.01 (+12%)** |
+| | c | 78.2% (43/55) | 1.77 | 3.76 |
+| chat-template coding prompt, cap 170 | MTP off | | | 4.15 |
+| | a | 84.9% (45/53) | 1.83 | 4.58 |
+| | **b** | **94.1% (48/51)** | **1.94** | **4.74 (+14%)** |
+| | c | 63.3% (38/60) | 1.62 | 4.21 |
+
+`c` was a third reading (the normalized streams averaged into one vector
+before a single `fc_hidden`). It came last on both prompts and was removed.
+The means of the head's norm weights are -0.76 (embedding), -0.33 (hidden) and
+3.79 (mixer), consistent with norms that scale by 1 + w like every other norm
+of the model.
+
+Nearly two tokens per forward gives only 12-14% more tokens per second here
+because the forward is not where the time goes. A verify forward feeds two
+tokens, and each token routes its own 10 experts per layer. Consecutive tokens
+share on average 3.2 of their 10 experts per layer (measured on a
+`ROUTE_TRACE` of 199 tokens), so a pair needs almost twice the experts of a
+single token. At cap 170 the cache missed 74 experts per token whether the
+tokens went one at a time or in accepted pairs. The disk reads for experts are
+therefore the same with MTP and without it. What MTP saves is the dense part
+of the forward, read once per forward instead of once per token: the trunk
+matrices, DeltaNet, attention and `lm_head`. Where the routed experts fit in
+RAM, those disk reads go away and the dense part is a larger share of each
+token, so the gain should be larger. That case has not been measured.
+
`make -C c qwen38-tiny-mtp-check` adds a head with random weights under the
release's names to the three tiny fixtures and gates on the head's draft
-logits against a float32 reference of each wiring
+logits against a float32 reference of both wirings
(`c/tools/qwen38_mtp_ref.py`), and on byte-identical output with drafts and
without them across caps, prefill batching, both trunk formats, BF16, FP8 and
int4 experts, text and serve, with drafts all rejected, all accepted and