Repository navigation
npu: measure the MTP draft loop (matched-position acceptance, 3 estimators) and stop asking for logits it throws away - #838
Conversation
…plain decode, depth counts)
The live summary reported every acceptance number and none of the cost ones, so a
serve decision had to be made from arithmetic on old timings. It now times the plain
greedy decode and the draft loop on the same prompt in the same process and prints:
chain N.NN tokens/pass (accept-len N.NN + the committed token); plain X s =
X s/tok, draft Y s = Y s/tok (speedup R.RRx)
and the summary repeats tokens/pass against base passes, so the two costs that decide
a switch are in the log rather than derivable from it. It also removes a units trap:
the live 'accept-len' is accepted/iterations while the offline line labelled 'expected
tokens per pass (chain)' is 1 + sum(hit[d]) -- they differ by the committed token, and
comparing them directly reads as a shortfall that is not there (live prompt 0 is 2.20
accept-len = 3.20 tokens/pass against the offline 3.19, not 2.20 against 3.19).
Two things found by using it on the real model, both fixed here:
* depth counts existed only in the run summary, so a ticket cut at its hold (or a
slice run) lost them entirely and the 8-prompt table could not be assembled. Each
prompt now prints its own 'per-depth pN: 1 a/b 2 a/b ...' line.
* the per-prompt line printed the SLICE index, not the prompt index, so with
--prompt-base 5 the log said 'prompt 0' for prompt 5 -- a trap for pairing two
tickets' tables. It prints the prompt index.
Measurement only: no loop logic changes. Prompt 0 reproduces bit-for-bit across three
binaries and three tickets (44/80 accepted, passes/token 0.625, stream 72 rows, 0
mismatch, 90/65/35/30 % per depth), which is the control that this is not a logic
change.
Measured with it on the real 27B (pb16i-exact, sealed M=16 ELFs, npu-hold tickets,
amdxdna errors 0 after every ticket): the draft route is 0.35x-0.70x of plain decode
across eight prompts, because each draft costs one full-vocab logits call (~0.3-0.5 s,
the engine's lm head: 15 ternary-image dispatches at M=16 with one useful row) and one
iteration needs k+1+accepted of them. Break-even is accept-len > ~3.75; the offline
protocol measures 2.19.
run_offline accumulated only a run-wide per-depth table, so the live loop (measured in slice tickets, prompts differing by 2.5x in chain length) could only be compared to it aggregate-vs-aggregate -- which mixes prompt composition with any real drift in the loop. It now prints 'per-depth pN: 1 a/b 2 a/b ...' per prompt, the same form the live path prints, so the two can be joined prompt by prompt. Measured with it: the offline protocol reproduces the published 8-prompt table exactly this session (69.366 / 58.571 / 49.638 / 41.360 %, chain 3.19), which is the environment control for the live comparison.
…fy batch fidelity, conditional acceptance) Two assumptions the loop rests on had never been measured on the device, and both can be false while the emitted text stays byte-identical (a wrongly rejected draft costs a pass, never a token): --batchcheck: does the deferred M=nd verify batch report the same thing plain decode does? Pass A decodes greedily recording the argmax and the hidden at every position; pass B walks the same stream in nd-row batches, committing every row (they are the stream's own tokens), and diffs each row's argmax AND its hidden against pass A. Measured on prompts 1, 2, 3: 0 of 63 rows differ in argmax -- the batch is faithful, so acceptance is not being robbed by the verify path. run_offline now reports per-depth acceptance under BOTH denominators: unconditional (depth j scored at every position -- the published 3.19, and the same estimator the live loop produces, since it drafts the whole chain before verifying) and conditional on the accepted prefix (the ceiling a correctly fed loop can reach). Measured, same run and positions: unconditional 69.366 / 58.571 / 49.638 / 41.360 % = 3.19 chain, conditional 69.366 / 78.036 / 82.095 / 86.192 % = 4.16 chain. Comparing a live table against the wrong one of those is a factor-1.3 error, which is why the tool prints both.
commit_rows() and prime() advance the drafter's stream and discard the logits, but each such row made a full-vocabulary lm_head call -- ~0.4 s of array dispatch chain (15 ternary-image dispatches at M=16 for one useful row). Around a draft chain of k that is 1 + accepted extra calls per iteration, i.e. 3.2 of 7.2 measured calls at k=4 / accept 2.2, all discarded. next_row() already had the no-lm-head branch (it still computes the head hidden and writes the KV row, so "next" and the cache are identical); it now also takes it when the caller does not need logits, which commit_rows/prime set via need_logits_. lm_calls() counts the calls that remain, and the live report prints them per iteration, so the effect is measured rather than argued. Measured on the real 27B (pb16i-exact, sealed M=16 ELFs, npu-hold ticket, amdxdna 0): prompt 0, k=4, 64 tokens -- logits calls 80 over 20 iterations = 4.00/iter (k, exactly the drafting calls), acceptance IDENTICAL to the three previous runs (44/80 accepted, passes/token 0.625, stream 72 rows, 0 mismatch, per-depth 18/20 13/20 7/20 6/20), draft phase 52.8 s against 31.4 s of plain decode = 0.60x. At the same base-step cost the old path needed ~79 s for the same work, so this removes ~33 % of the draft route's wall clock -- and it is still a loss: break-even needs a cheaper per-call lm head (P3), not a smaller number of calls.
PR Reviewer Guide 🔍(Review updated until commit ee9ed29)Here are some key observations to aid the review process:
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: CHANGES at 1beaa69 — the cost fix and --batchcheck are real and reproduce from the lane's own logs;
the new conditional table's "chain" is not a chain, and the sentence about which estimator the live loop produces
is inverted. Both are small; the code path is fine.
Verified here (built and ran, no device): NPU lane at this head, Release / gcc-16,
-DONEBIT_NPU=ON -DONEBIT_NPU_RUNTIME=own -DONEBIT_NPU_RT_DIR=<private rt> -> mtp_acceptance and
mtp_draft_test link, rc 0; the build's only warning is the pre-existing npu/forward/src/q4nx_forward.cpp:1872
stringop one, none from the three changed files. ctest -R mtp_draft -> 1/1, and the binary itself prints every
check PASS including "stream: per-depth counters add up to the totals". tools/copyright.py --check rc 0.
The fix does what it says, and head_step(..., nullptr, logits) leaves the row intact: the K/V append
(npu/mtp/mtp_head.cpp:228-234), out_hidden (:276) and the return value (:279) do not depend on lm_head,
so next and the drafter cache are unchanged and only the vocabulary projection is skipped. The call arithmetic in
the body re-derives exactly: draft() makes k calls with logits, run() makes 1 in commit_rows({t1}, ...) plus
one per accepted row in commit_rows(accepted, ...) -> 4 + 1 + 2.20 = 7.20 before, 4.00 after. Measured in
~/wt/mtp-window/ticket-live-p0-logitsfix-20261102-135902.log: logits calls 80 over 20 iterations (4.00/iter),
draft 52.76 s against plain 31.44 s (0.60x), with acceptance untouched (44/80, passes/token 0.625, 72 rows, 0
mismatch, per-depth 18/20 13/20 7/20 6/20) — i.e. -33 % wall from removing 3.2 of 7.2 calls.
--batchcheck reproduces too (ticket-batchcheck-p1-3-20261102-135025.log,
ticket-batchcheck-hidden-p1-3-20261102-135440.log): 0 of 63 rows differ on prompts 1-3, and
64 rows, min cos 1.000000 (position 8), max |diff| 0.000e+00. The 63 (not 64) is right — the last row's
prediction has no sequential reference, and the code skips it.
Item 1 — the live per-depth table is the joint one, not the conditional one. npu/mtp/draft.h:243 increments
drafted_at[i] for every row of the verify batch (for i < nd), before any acceptance is known, so the live
denominator is iterations where a draft was offered at that depth, not chains that arrived with an accepted
prefix. The lane's own logs show one denominator per prompt at every depth:
ticket-confirm-live-p5-7-20261102-123806.log has per-depth p1: 1 22/36 2 4/36 3 3/36 4 0/36 and
per-depth p3: 1 14/16 2 12/16 3 12/16 4 12/16. And summing accepted-at-depth over iterations gives accept-len
(44/20 = 2.20 for p0; 1.874 for the 8-prompt run, chain 2.874) — which is the joint quantity, the same one
d_hit/d_tot reports. So tools/mtp_acceptance.cpp:149 ("which is exactly what the live loop does (a reject ends
the chain)") and the body's "the live loop only produces [the conditional] one" are backwards: a reject ends the
acceptance scan, not the drafting. Consequence: the live 2.874 chain is directly comparable with the
unconditional 3.189 (with the body's own 9-18 pp clustered SE), not with 4.16.
Item 2 — c_expected sums conditional rates, so chain 4.16 is not an expected value.
tools/mtp_acceptance.cpp:187-194 adds c_hit[j]/c_tot[j] per depth, but a conditional rate is not a marginal.
E[accept-len] = sum_j P(accepted at depth j) = sum_j c_hit[j]/N. From the same run
(ticket-offline-8p-conditional-20261102-133752.log, 394/568, 302/387, 243/296, 206/239):
$ python3 -c 'h=[394,302,243,206]; print(1+sum(h)/568, 1+sum([394/568,302/387,243/296,206/239]))'
3.015845070422535 4.156894361075343
The conditional table's chain is 3.02, not 4.16 — and then live 2.87, conditional 3.02 and unconditional 3.19
are all within 0.35 tokens, so the "factor-1.3 error" is an artifact of the summation rather than a units trap
(this PR's own subject). Fix: print 1 + sum(c_hit[j])/c_tot[0] (or label the line "mean conditional rate, not a
chain"), and correct that paragraph plus the "ceiling a correctly fed loop can reach" sentence: the live loop is
correctly fed (0 mismatches on 8/8) and reaches 2.874, so it is not catching up to a 4.16 ceiling.
Nits. (1) %.1f ms/call of the draft phase divides the whole draft phase — base steps, verify batch, priming —
by the logits count: 659.5 ms/call in the log, while npu/mtp/mtp_head.h:127 says one call is ~0.3-0.5 s. A reader
takes it as per-call latency; either say "including the base steps" or time head_step on its own. (2) No
automated test covers the changed branch: tests/mtp_draft_test.cpp:172 StreamDrafter overrides next_row, so
mtp_draft passes with or without need_logits_ and the only evidence for the fix is the 8-prompt device run —
fair enough, but worth saying in "Testing".
I took no NPU ticket for this: the owner's serve holds the device lock on :18097 and a measurement PR needs none
of the box's device time, so nothing below was re-run on hardware — every number above is either arithmetic or a
line in the lane's own archived ticket log.
…tions The 8-prompt comparison left one honest gap: run_offline chains from EVERY position (568 chains) and the live loop only from the ones it arrives at (183), so the two per-depth tables were different samples of the same drafter -- and the per-prompt rates are bimodal enough (depth 3: 8 % to 87 %) that the cluster-robust SE of the difference is 9-18 pp. The brief's 2 pp bar was not resolvable that way. So make the comparison matched: - npu/mtp/draft.h: Stats::chain_at records the stream position of every chain the loop opens (2 lines, no logic change), and tests/mtp_draft_test.cpp checks one entry per iteration, inside the stream, strictly advancing. - tools/mtp_acceptance.cpp: chain_stream() is the offline protocol factored out (prime the head's cache position by position, chain k drafts, score both estimators), used by --offline and by the live path. --positions-out writes where the live loop opened its chains; --offline --positions-in scores exactly those positions; --match does both in one process and prints live vs offline per depth with the bar.
…ERE live and offline differ The first --match ticket (prompts 0-1) made the brief's bar measurable for the first time and it did not pass at depth 2-4 on prompt 1 (p0 agreed exactly at depths 1-3). Aggregates can only say "less"; the draft tokens say which, so Stats now keeps each chain's drafts and accepted count beside its position, and chain_stream() can return per-position draft tokens and hits. --match then prints, per prompt, how many (position, depth) pairs both paths scored, how many draft TOKENS differ, and how many VERDICTS differ on the same token -- a verdict difference is a loop defect at a named position, a token difference points at the drafter's cache rows. Pairs offline cannot score (past the stream end) are excluded, not imputed.
…the matching one Ticket 2 proved the loop and the protocol compute IDENTICAL draft tokens at identical positions (draft tokens differ 0 over 389 pairs, prompts 0-3), so the remaining gap was the comparison, not the loop: accepted_at[d]/drafted_at[d] is a SURVIVAL (joint) rate, offline's published table is MARGINAL and its c_* table is CONDITIONAL. Comparing joint to marginal fails at depth 2+ by construction. --match now prints all three, headlines live-conditional vs offline-conditional at the same positions, and adds the form that needs no estimator at all: per chain position, the accepted prefix length on both sides, with the first position where they differ.
|
Persistent review updated to latest commit 66b0c37 |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: CHANGES, one item left at 66b0c37 — and it is the arithmetic one, not the naming one. Two of my three items are
closed properly, and the third survived the rework.
Closed, and better than what I asked for. The three-estimator comment names conditional / joint / marginal with the
formula for each; the live per-depth row is now labelled joint instead of being called conditional; and — the real fix —
the loop records its drafts, so the live table has a "reached" denominator and can print the conditional estimator
itself: depth 2: live 55.00 % (11/20, reached) offline conditional 52.63 % (10/19) delta +2.37 pp [live joint 42.31 %, offline marginal 40.00 %] (~/wt/mtp-window/ticket-match-p4-7-cond-20261102-154248.log). That comparison is the matched,
same-position, same-draft form I said the old two-table version could not produce, and it also produces the thing neither
table could: pairs 60: … verdicts differ 1 (1 of them on the SAME draft token) with the position named.
Still open — c_expected sums conditional rates. tools/mtp_acceptance.cpp still does
const double r = all.c_tot[j] ? (double)all.c_hit[j] / all.c_tot[j] : 0.0; // P(accept at j | prefix accepted)
c_expected += r;
...
std::printf(" expected tokens per pass (chain) %.2f\n", c_expected);and a conditional rate is not a marginal, so E[tokens per pass] = 1 + Σ_j P(accepted at depth j) = 1 + Σ_j
c_hit[j] / c_tot[0]. From the counters in the lane's own log (394/568, 302/387, 243/296, 206/239):
$ python3 -c 'h=[394,302,243,206]; print(1+sum(h)/568, 1+sum([394/568,302/387,243/296,206/239]))'
3.015845070422535 4.156894361075343
3.02, not 4.16 — so with this line fixed, live 2.87, conditional 3.02 and unconditional 3.19 are all inside 0.35 tokens,
and the "a conditional rate is 1.3x the right answer, which is the units trap" paragraph in the body loses its number.
Either print 1 + sum(c_hit)/c_tot[0], or relabel the line (it is the mean conditional rate, not a chain). The body
paragraph that leans on 4.16 needs the same edit.
Built and run here at this head: ninja mtp_acceptance mtp_draft_test rc 0, ctest -R mtp_draft 1/1, and the binary's
own all checks passed including "stream: per-depth counters add up to the totals" — so the counters agree with
themselves; it is only that one derived line that does not.
…the conditional rates Review item on #838: `c_expected` added up P(accepted at depth j | prefix accepted) across depths and printed the sum as "expected tokens per pass", which counts a conditional rate as a marginal. By linearity E[tokens/pass] = 1 + sum_j P(accepted at depth j) = 1 + sum_j c_hit[j]/c_tot[0], since P(accepted at j) = P(accepted at j | reached j) * P(reached j). From the same run the two formulas give 3.02 (new) and 4.16 (old) on counts 394/568, 302/387, 243/296, 206/239 -- so the "the live loop is 1.3 tokens below the drafter's ceiling" reading was the summation artifact, not a finding: live 2.874, conditional 3.02 and unconditional 3.189 are all inside 0.35 tokens. The mean conditional rate is still printed, labelled as a rate rather than a chain. Also relabel the logits timing: it divides the whole draft phase (base steps, verify batches, priming) by the call count, so it is an amortised phase cost, not one call's latency (~0.3-0.5 s).
|
Persistent review updated to latest commit 8b799fe |
|
Review item closed in Nit 1 taken too: the ms figure is labelled "ms of the whole draft phase per call" (with a comment saying one call alone is ~0.3-0.5 s), since it divides base steps + verify batches + priming by the call count. Verified here at this head: |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at 8b799fe2f — the estimator item from my last review is fixed, and correctly
What the fix does is the thing that was wrong: E[tokens per pass] = 1 + sum_j c_hit[j]/c_tot[0], with the
conditional rates kept but printed as mean conditional rate ... (rates at different depths are not additive, so this is not a chain). I checked it against the counters rather than the sentence: c_tot[j]/c_hit[j] are
incremented only while prefix_ok, so c_hit[j]/c_tot[0] is exactly P(drafts 0..j all accepted) and the sum
over j is the expectation by linearity; c_hit[j]/c_tot[j] is the conditional. The two forms are printed side
by side, so a reader can see one is a rate and the other an expectation.
From the run in the commit message (counts 394/568, 302/387, 243/296, 206/239): old sum-of-conditionals 4.16,
new 3.02, joint marginals 0.694 / 0.532 / 0.428 / 0.363 — i.e. the "live loop is 1.3 tokens below the
drafter's ceiling" reading was indeed the summation artifact.
Re-run at this head: mtp_draft_test builds rc 0, ctest -R mtp_draft -> 1/1 passed; mtp_acceptance compiles
in the NPU configuration (0 warnings from tools/mtp_acceptance.cpp); tools/copyright.py --check rc 0. I did
not re-run the model window — the change is a formula over counters that are already collected, and the counters'
semantics are what I verified.
Nit: the new line ends = 1 + sum_j c_hit[j]/c_tot[0], which is the formula in code notation; if the intent is
that a reader can recompute it from the printed per-depth counts, printing chains=N once above the block would
save them hunting for the denominator.
|
Persistent review updated to latest commit 5445bbc |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at 5445bbccf (re-posted; my verdict is a gate only at the head it names).
Head moved by update-branch only: 5445bbccf is Merge branch 'main' into npu/mtp-live-report, parents 8b799fe2f (the head I verdicted) and 1f2dfe99f. The PR's own commit is untouched and all five file blobs are identical at the two heads, so the earlier evidence applies verbatim: the new estimator is the linearity form, the counters' semantics checked in code, 4.16 -> 3.02 re-derived from the author's counts, mtp_draft 1/1, and mtp_acceptance compiles in the NPU config.
CI on this head: build SUCCESS, four Analyze jobs SUCCESS, hw_gate SKIPPED, pr_agent SUCCESS.
|
Persistent review updated to latest commit 16fad72 |
|
Re-gate evidence at 1. The patch is byte-identical at this head. 2. The loop re-measured on a binary built from p0 is the seventh reproduction of 44/80 / chain 3.20 / 18-13-7-6, across four binaries and seven tickets. 3. One correction to my own speed claim, in the PR's interest (the body says "the ratio is the stable quantity"): this ticket measured p0 at 0.94x of plain decode (plain 0.742 s/tok, draft 0.786 s/tok) where quiet-box tickets measured 0.60x (plain 0.49 s/tok), with load 11.3 and three foreign tickets queued. Plain decode pays a base pass per token; the loop pays 0.625 base passes plus 4 full-vocab logits calls, and the two mixes respond differently to a busy array. Measured range for the route is 0.32x-0.94x, still never a win, so the conclusion ( No new commit on this branch: a commit here would move the head off the gate for a print line. The one known wart ( |
|
Persistent review updated to latest commit e6cc667 |
|
Persistent review updated to latest commit ee9ed29 |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY
At ee9ed2909 (merge of current main into the branch; parents e6cc667ad + bc291cd15), superseding my line at
5445bbccf/16fad72cf.
The update adds no author change — the branch's own commits are untouched — so this is the content I verified: all five
files (npu/mtp/draft.h, npu/mtp/mtp_head.{cpp,h}, tests/mtp_draft_test.cpp, tools/mtp_acceptance.cpp) are
blob-identical to the head I ran, and mtp_draft_test passes there:
PASS positions: one chain start recorded per iteration
PASS positions: chain starts lie inside the stream and advance
PASS positions: the recorded chains add up to the totals (drafts + accepted)
PASS stream: legacy path is text-correct too (drafts only cost time)
PASS stream: legacy path is reported as out of step, not silently bad
PASS stream: legacy path collapses acceptance (the measured drift)
PASS stream: per-depth counters add up to the totals
all checks passed (rc 0)
and the estimator claim re-derives from the PR's own counters: c_expected = 1 + sum(c_hit)/c_tot[0] is 3.02 with
h=[394,302,243,206], N=568 — not 4.16, which was the summed-conditional-rates form I objected to. The three estimators
are now named in the tool, the live per-depth row is labelled joint, and the loop records its drafts so the conditional
estimate can be printed from live data.
CI at ee9ed2909: build success (checked at 02:12Z).
The MTP draft loop is correct (8/8 prompts byte-identical to plain greedy decode) and its acceptance now matches the offline protocol to within 2 pp at every depth on 8 prompts x 64 tokens — once the two are compared at the same positions. This PR is the measurement work that established it, plus the one real per-iteration waste it found.
No loop, cursor or engine logic changes.
npu/mtp/draft.hgains recording fields (Stats::chain_at,chain_drafts,chain_accepted);npu/mtp/mtp_head.{h,cpp}gainsneed_logits_/lm_calls()and stops asking the array for logitsprime()/commit_rows()throw away.Result (main's code + this PR's instrumentation, sealed M=16 pb16i ELFs,
amdxdnaerrors 0 on every run)Per-depth acceptance, live vs the offline protocol at the same positions, conditional on reaching the depth:
identical token — the loop and the protocol are the same computation.
TEXT IDENTICAL,stream 72 rows(= prompt + emitted), 0 cursor mismatches.head is cheap: an iteration costs 2 base passes (0.94 s) + k=4 full-vocab calls (~0.41 s each), i.e. 5.5 plain
tokens' worth for 2.87 tokens. Break-even needs accept-len > 4.5, unreachable at k=4.
Why the numbers only agree once matched (the part worth reviewing)
run_offlinechains from every position; the live loop only from the positions it arrives at (183 vs 568), and theper-prompt rates are bimodal (depth 3: 8 % to 87 %), so the unmatched delta has a cluster-robust SE of 9-18 pp and the
2 pp bar is unmeasurable that way.
chain_stream()is the offline protocol factored out and now serves both paths, so--matchscores the protocol at the live loop's own positions in the same process, and--positions-out/--positions-indo the same across processes.
Three estimators are named in the code and in the output because mixing them produced two false alarms in the lane's
own notes: marginal (every position — the published 3.19), conditional (prefix accepted — the drafter's quality
per depth), joint/survival (
accepted_at[d]/drafted_at[d]— a survival curve, not a rate). The live loop'sper-depth acceptance is the conditional one.
The chain for the conditional table is an expectation, not the sum of the rates: E[tokens/pass] =
1 + Σ_j P(accepted at depth j) = 1 + Σ_j
c_hit[j]/c_tot[0]. On this run's counts (394/568, 302/387, 243/296,206/239) that is 3.02; the earlier revision summed the conditional rates themselves and printed 4.16, which made a
0.35-token spread (live 2.874, conditional 3.02, marginal 3.189) look like a 1.3-token gap. Fixed in
8b799fe, with themean conditional rate still printed but labelled as a rate.
Also measured and asserted by
--batchcheck: the deferred verify batch reproduces sequential decode exactly (argmax0 of 63 rows differ; batch hidden rows bit-identical), and the deleted waste —
prime()/commit_rows()asked for fullvocabulary logits they discarded, 7.2 → 4.00 lm-head calls per iteration, measured.
Tests
ctest -R mtp_draft1/1: per-depth counters add up, one chain position recorded per iteration, positions advanceinside the committed stream, recorded drafts sum to
accepted. Plus the pre-existing toy red/green (primed 20/20 vslegacy_prime0/96) that fails on the old cursor path.Caveats
bonsai2-27b-pb16iwith the sealed M=16 ELFs and thepb16i-exacthead; absolute s/tok movewith box contention (plain decode measured 0.46-0.81 s/tok today), so speed claims are stated as ratios.
--matchpairs exclude positions the protocol cannot score (past the stream end) rather than imputing them.