You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
npu mtp: an M-row verify batch costs ~0.37-0.64 s/row, so the draft loop's "two passes per iteration" is really ~2.9 -- the batch, not the drafter, is what keeps the draft route slower than plain decode #972
tools/mtp_acceptance --batchcheck (PR #968 adds the sweep) replays one 16-token greedy stream in batches of
M rows on bonsai2-27b-pb16i (sealed M=16 pb16i ELFs), one npu-hold ticket, exit 0, amdxdna errors 0:
Same stream as the argmax/hidden comparison in the same run (0 of 15 rows differ, batch hidden bit-identical to
sequential), so these are the loop's own verify rows, not a synthetic batch.
Why it matters
The draft loop computes passes/token = 2/(1+accept-len) by counting an M=nd verify batch as one pass. This
curve says a 5-row batch costs 2.9x a 1-row pass, so on prompt 3 (k=4, accept-len 3.12, 5.12 tokens per
iteration) the measured 3.08 s iteration decomposes as:
term
measured
one plain step (the committed token)
0.64 s
the M=5 verify batch
1.85 s
the drafter's 6+accept host head steps @ 57-71 ms
~0.55 s
the drafter's 4 array logits calls @ 29.3 ms
0.12 s
total
3.16 s vs 3.08 s measured
(i.e. the cost model is now closed; before this ticket ~1.4 s/iteration was unaccounted for.)
Consequence, and it is the decision the serve switch was waiting on: a batch row costs 258-644 ms while plain
decode costs 484-588 ms/token on the same prompts. The loop must verify M rows to emit 1 + accept-len tokens, so
its best case (prompt 3, accept-len 3.12) is 5 rows per 4.12 tokens = 1.21 rows/token plus one extra full step per
iteration — 0.77 s/token measured against plain's 0.48 s/token (0.63x). No (k, tau) fixes that: k=2, k=4,
k=8 and --tau 0.6 all land between 0.6x and 0.8x, and raising k grows M, which is the term that costs.
What would change it
A cheaper M-row batch path. If an M=5 batch cost one pass (0.64 s) instead of 2.9, the same loop on prompt 3
would be ~1.4x faster than plain decode with no loop or model change. The per-row work is presumably the
recurrent/GDN path (gdn_layer_batch) and the per-row loops in Q4nxNpuForward::step_batch
(npu/forward/src/q4nx_forward.cpp:3291+), which run per row while the projections are batched.
Or a drafter whose acceptance does not need 5 rows to convert 4 tokens.
Not claimed here: the cause inside step_batch — this issue is the measurement (curve + closed cost model) and the
break-even arithmetic. Loop-side numbers are from TMTPLOOP-STATE.md 2026-11-04; the same ticket re-proved the
correctness arms (TEXT IDENTICAL, 0 mismatch, 44/80 p0, 50/64 p3).
Measurement update from the MTP lane (pi-mtploop), because the base moved under this issue in two ways, plus one
hypothesis tested and rejected.
#944 rewrote the term this issue is about.gdn_layer_batch (npu/forward/src/q4nx_forward.cpp, straight to eda7542e) now runs the 48-head delta rule behind #pragma omp parallel for (region at :2335, inside the per-row
loop at :2273), with the loops exchanged to walk state contiguously and capped at 3/4 of the cores. Its author
measured prefill 6.0 -> 21.0 tok/s and decode flat. The curve quoted in the issue body (258-644 ms/row) is therefore pre-#944 and should not be read as current.
Re-measured tonight, and what it does / does not say (one npu-hold ticket, lone holder, sealed M=16 pb16i ELFs, amdxdna errors 0, :18097 untouched):
One hypothesis tested and rejected, so nobody chases it: the region sits inside the row loop, so an M-row batch
enters 48 x M parallel regions, which looked like a plausible per-row cost. Host probe, no device, no weights
(~/wt/mtp-window/probes/omp_region_bench.cpp, body = one head's delta rule at the source's shapes): at the 24-thread
cap the forward computes, a region costs 0.1-0.8 ms under this load -> 24-190 ms of a ~1.85 s M=5 batch, i.e. real
but an order of magnitude short of the term this issue is about. At 32 threads the same probe collapses to 6.2-8.6 ms per region (30-70x), which is independent support for #944's 3/4 cap: do not raise it.
Caveat stated plainly: load 48-67 also makes those probe figures noisy (the serial arm alone varied 3x between reps),
so treat them as an order of magnitude, not a number.
The measurement this issue needs, sized to fit a normal ticket (all four widths, n = 8 + 24 = 32 rows:
32/16/6/2 batches, ~55 s of batches + 4 prefills, so a 4-min hold is comfortable on a quiet box):
The one number to read off it: whether an M=5 batch has fallen from ~1.85 s towards one plain step (~0.5-0.6 s).
If it has, the draft loop's prompt-3 iteration goes from 3.08 s to ~1.2 s and the route flips from 0.63x to ~1.4x
against plain decode with no change to the loop — that is the serve decision this issue is blocking. My lane owns the
drafter, not step_batch, so I am reporting the measurement and not proposing a patch here.
The quiet-box curve, re-taken after #944 — it is 34-38 % cheaper at wide M, but still ~2.3 passes per 5 rows, so the draft route stays a 0.86x loss
The number this issue was waiting for, measured properly this time: one npu-hold -t 6 ticket, lone holder, sealed M=16 pb16i ELFs, exit 0 after 113 s inside the hold, amdxdna errors 0, taken behind a written wait-for-load1<8 gate (every earlier attempt was at load 23-67 and was reported as unusable rather than quoted). Tree = main f17cc61f; argv identical to the pre-#944 sweep, --batchcheck --prompts 1 --prompt-base 0 --tokens 16 --k 4, widths swept internally at 1/2/5/16.
Correctness on the same ticket, unchanged by #944: 0 of 15 rows differ from sequential argmax, hidden rows min cos 1.000000, max |diff| 0.000e+00.
What the curve fits.batch(M) ≈ 465 + 141·M ms, i.e. a fixed cost of about one plain step (this boot: 509 ms/token) plus 141 ms per additional row = 28 % of a step per row. So a 5-row verify batch is ~2.1 steps' worth of work, not one pass: the "one M=k+1 batch = one pass" accounting the draft loop was costed on is wrong by ~2.3x at M=5 and ~6.8x at M=16.
And the closed cost model, which is why I trust the curve. Prompt 0, k=4, 64 tokens, measured in the same session on the same box (0.509 s/tok plain):
20 single steps x 0.509 s = 10.18 s
20 verify batches (M=5) = 22.99 s <- 61 % of the draft route
80 head steps (residual) = 4.79 s <- 12 %
--------
37.96 s = the measured draft wall clock, exactly
plain decode, 64 tokens = 32.59 s -> 0.86x
No unexplained term is left. (Before #944 the batch term alone was 20 × 1.852 s = 37.0 s, i.e. larger than the entire 32.6 s plain run — which is why the route measured 0.63-0.71x.)
What would flip it, as arithmetic on measured numbers, not a projection:
if the M=5 batch cost
draft total
per token
vs plain
today (1149 ms)
37.96 s
0.593 s
0.86x
1.5 passes (764 ms)
30.25 s
0.473 s
1.08x
1 pass (509 ms)
25.16 s
0.393 s
1.30x
Note what is not the lever: putting the head on the array (#968 already got the host matvec 6x cheaper; a fully array-side head at ~5 ms/draft saves 4.4 s) lands at 0.97x — still a loss. Only the batch term moves the route from "no" to "yes", and a batch at one pass with the head on the array would be 1.57x.
So the ask in this issue is unchanged and now quantified from the right end: the fixed dispatch cost is already about one step, which is what a same-weights M-row batch should cost; the term to attack is the 141 ms per extra row (28 % of a step) in Q4nxNpuForward::step_batch's per-row work. If a marginal row were nearly free — which it should be, since the extra rows reuse the same weight stream — a 5-row batch would be ~1.05 steps and the draft loop already in main would turn ~1.25x faster than plain decode with no change to the loop, the drafter or the model.
I own the drafter, not step_batch, so this is evidence and not a patch. Reproducer: mtp_acceptance --batchcheck --prompts 1 --prompt-base 0 --tokens 16 --k 4 under one npu-hold -t 6 ticket, ~113 s including model load.
Cause found, and it was not in step_batch — it was the deferred commit's replay
Closing note from the MTP lane (pi-mtploop), since this issue's one open sentence was "not claimed here: the cause
inside step_batch". The measurement stands, but the attribution was off by one call site: the tool's per-row window
includes commit_verify(), and gdn_apply_rows() — the per-row half of a verify batch, which restores the snapshot
and re-applies the recurrence for the accepted rows only — was still in the pre-#944 shape: one thread, and the rank-1
update walking the state row with stride VHD, so every touch was a different cache line, over 48 GDN layers x 48 heads
x 128x128 state (144 MB) per row.
Measured with NPU_PHASE_PROF bracketed around the two terms, one npu-hold claim, arms A/C = before and B = after in
the same window (sealed M=16 pb16i ELFs):
before
after
replay, per accepted row
63-153 ms (median 85)
5.2-13.5 ms (5.3 at the k=4 accept widths, 13.5 at M=16)
snapshot restore (M-independent)
11-15 ms/commit
11-15 ms/commit (untouched, as predicted)
live loop, whole draft phase
41.45 s (replay 4030 ms of it)
720 ms of replay
verify batch M=1 / 2 / 5 / 16
589 / 720 / 1149 / 2721 ms
436 / 505 / 627 / 1336 ms
M=1 lands on before-minus-measured-replay to the tenth of a millisecond (436 vs 435.95), which is what makes the
attribution a measurement rather than a story. step_batch's own host work is ~41 ms/row at M=16 and already
head-parallel; the array's M-row cost stays M-independent within a pb16i launch.
Fix: #1022 (closes #972) — loops exchanged exactly as #944 exchanged them in gdn_layer_batch, one parallel region per replay with the per-row preparation in an omp single. Correctness is
asserted at the seam rather than assumed: NPU_REPLAY_CHECK=1 compares the replayed recurrent + conv state against the
state the batch's own recurrence left, max |diff| 0.000e+00 on every full-accept commit. Acceptance, text and the
drafter's stream are untouched (44/80, chain 3.20 t/pass, per-depth 90/65/35/30, TEXT IDENTICAL, 0 mismatches).
What this does not change: the draft route is still not a win on this box — it moves 0.69x → 0.75-0.93x across
windows (parity on the quietest), because the remaining cost is the array's M-row batch plus one plain step per
iteration, not the replay. --draft none stays the default and the remaining lever is the loop's pass count per token,
not this function.
Activity
bong-water-water-bong commentedon Nov 4, 2026
Measurement update from the MTP lane (pi-mtploop), because the base moved under this issue in two ways, plus one
hypothesis tested and rejected.
#944 rewrote the term this issue is about.
gdn_layer_batch(npu/forward/src/q4nx_forward.cpp, straight toeda7542e) now runs the 48-head delta rule behind#pragma omp parallel for(region at:2335, inside the per-rowloop at
:2273), with the loops exchanged to walk state contiguously and capped at 3/4 of the cores. Its authormeasured prefill 6.0 -> 21.0 tok/s and decode flat. The curve quoted in the issue body (258-644 ms/row) is therefore
pre-#944 and should not be read as current.
Re-measured tonight, and what it does / does not say (one
npu-holdticket, lone holder, sealed M=16 pb16i ELFs,amdxdnaerrors 0,:18097untouched):0 of 63 rows differvs sequential argmax, hidden rowsmin cos 1.000000,max |diff| 0.000e+00. npu: the GDN head loop goes parallel, contiguous and off the whole box (prefill 6.0 -> 21.0 tok/s) #944 did not perturb the deferred verify.M=2 (1403 ms/batch) because the box was at load average 48-67 (another lane's
forward-serveon:18099, a GPUllama-bench, CPU perplexity, qemu, concurrent builds). Those two numbers are load-inflated and are not offered as a
curve. What survives is the shape:
M=2/M=1= 1.51 today vs 1.42 pre-npu: the GDN head loop goes parallel, contiguous and off the whole box (prefill 6.0 -> 21.0 tok/s) #944 -> still near-linear, only the interceptmoved. So nothing here claims npu: the GDN head loop goes parallel, contiguous and off the whole box (prefill 6.0 -> 21.0 tok/s) #944 did or did not fix the batch.
One hypothesis tested and rejected, so nobody chases it: the region sits inside the row loop, so an M-row batch
enters 48 x M parallel regions, which looked like a plausible per-row cost. Host probe, no device, no weights
(
~/wt/mtp-window/probes/omp_region_bench.cpp, body = one head's delta rule at the source's shapes): at the 24-threadcap the forward computes, a region costs 0.1-0.8 ms under this load -> 24-190 ms of a ~1.85 s M=5 batch, i.e. real
but an order of magnitude short of the term this issue is about. At 32 threads the same probe collapses to
6.2-8.6 ms per region (30-70x), which is independent support for #944's 3/4 cap: do not raise it.
Caveat stated plainly: load 48-67 also makes those probe figures noisy (the serial arm alone varied 3x between reps),
so treat them as an order of magnitude, not a number.
The measurement this issue needs, sized to fit a normal ticket (all four widths,
n = 8 + 24 = 32rows:32/16/6/2 batches, ~55 s of batches + 4 prefills, so a 4-min hold is comfortable on a quiet box):
The one number to read off it: whether an M=5 batch has fallen from ~1.85 s towards one plain step (~0.5-0.6 s).
If it has, the draft loop's prompt-3 iteration goes from 3.08 s to ~1.2 s and the route flips from 0.63x to ~1.4x
against plain decode with no change to the loop — that is the serve decision this issue is blocking. My lane owns the
drafter, not
step_batch, so I am reporting the measurement and not proposing a patch here.bong-water-water-bong commentedon Nov 4, 2026
The quiet-box curve, re-taken after #944 — it is 34-38 % cheaper at wide M, but still ~2.3 passes per 5 rows, so the draft route stays a 0.86x loss
The number this issue was waiting for, measured properly this time: one
npu-hold -t 6ticket, lone holder, sealed M=16 pb16i ELFs, exit 0 after 113 s inside the hold,amdxdnaerrors 0, taken behind a written wait-for-load1<8 gate (every earlier attempt was at load 23-67 and was reported as unusable rather than quoted). Tree = mainf17cc61f; argv identical to the pre-#944 sweep,--batchcheck --prompts 1 --prompt-base 0 --tokens 16 --k 4, widths swept internally at 1/2/5/16.Correctness on the same ticket, unchanged by #944: 0 of 15 rows differ from sequential argmax, hidden rows
min cos 1.000000,max |diff| 0.000e+00.What the curve fits.
batch(M) ≈ 465 + 141·M ms, i.e. a fixed cost of about one plain step (this boot: 509 ms/token) plus 141 ms per additional row = 28 % of a step per row. So a 5-row verify batch is ~2.1 steps' worth of work, not one pass: the "one M=k+1 batch = one pass" accounting the draft loop was costed on is wrong by ~2.3x at M=5 and ~6.8x at M=16.And the closed cost model, which is why I trust the curve. Prompt 0, k=4, 64 tokens, measured in the same session on the same box (0.509 s/tok plain):
No unexplained term is left. (Before #944 the batch term alone was 20 × 1.852 s = 37.0 s, i.e. larger than the entire 32.6 s plain run — which is why the route measured 0.63-0.71x.)
What would flip it, as arithmetic on measured numbers, not a projection:
Note what is not the lever: putting the head on the array (#968 already got the host matvec 6x cheaper; a fully array-side head at ~5 ms/draft saves 4.4 s) lands at 0.97x — still a loss. Only the batch term moves the route from "no" to "yes", and a batch at one pass with the head on the array would be 1.57x.
So the ask in this issue is unchanged and now quantified from the right end: the fixed dispatch cost is already about one step, which is what a same-weights M-row batch should cost; the term to attack is the 141 ms per extra row (28 % of a step) in
Q4nxNpuForward::step_batch's per-row work. If a marginal row were nearly free — which it should be, since the extra rows reuse the same weight stream — a 5-row batch would be ~1.05 steps and the draft loop already in main would turn ~1.25x faster than plain decode with no change to the loop, the drafter or the model.I own the drafter, not
step_batch, so this is evidence and not a patch. Reproducer:mtp_acceptance --batchcheck --prompts 1 --prompt-base 0 --tokens 16 --k 4under onenpu-hold -t 6ticket, ~113 s including model load.npu: the deferred-commit replay ran the GDN recurrence single-threade…
bong-water-water-bong commentedon Nov 4, 2026
Cause found, and it was not in
step_batch— it was the deferred commit's replayClosing note from the MTP lane (pi-mtploop), since this issue's one open sentence was "not claimed here: the cause
inside
step_batch". The measurement stands, but the attribution was off by one call site: the tool's per-row windowincludes
commit_verify(), andgdn_apply_rows()— the per-row half of a verify batch, which restores the snapshotand re-applies the recurrence for the accepted rows only — was still in the pre-#944 shape: one thread, and the rank-1
update walking the state row with stride
VHD, so every touch was a different cache line, over 48 GDN layers x 48 headsx 128x128 state (144 MB) per row.
Measured with
NPU_PHASE_PROFbracketed around the two terms, onenpu-holdclaim, arms A/C = before and B = after inthe same window (sealed M=16 pb16i ELFs):
M=1 lands on before-minus-measured-replay to the tenth of a millisecond (436 vs 435.95), which is what makes the
attribution a measurement rather than a story.
step_batch's own host work is ~41 ms/row at M=16 and alreadyhead-parallel; the array's M-row cost stays M-independent within a pb16i launch.
Fix: #1022 (
closes #972) — loops exchanged exactly as #944 exchanged them ingdn_layer_batch, one parallel region per replay with the per-row preparation in anomp single. Correctness isasserted at the seam rather than assumed:
NPU_REPLAY_CHECK=1compares the replayed recurrent + conv state against thestate the batch's own recurrence left,
max |diff| 0.000e+00on every full-accept commit. Acceptance, text and thedrafter's stream are untouched (44/80, chain 3.20 t/pass, per-depth 90/65/35/30, TEXT IDENTICAL, 0 mismatches).
What this does not change: the draft route is still not a win on this box — it moves 0.69x → 0.75-0.93x across
windows (parity on the quietest), because the remaining cost is the array's M-row batch plus one plain step per
iteration, not the replay.
--draft nonestays the default and the remaining lever is the loop's pass count per token,not this function.
npu: the deferred-commit replay ran the GDN recurrence single-threade…