Skip to content

npu: measure the MTP draft loop (matched-position acceptance, 3 estimators) and stop asking for logits it throws away - #838

Merged
bong-water-water-bong merged 12 commits into
mainfrom
npu/mtp-live-report
Nov 3, 2026
Merged

bong-water-water-bong merged 12 commits into
mainfrom
npu/mtp-live-report

Conversation

@bong-water-water-bong

@bong-water-water-bong bong-water-water-bong commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

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.h gains recording fields (Stats::chain_at, chain_drafts, chain_accepted); npu/mtp/mtp_head.{h,cpp} gains need_logits_/lm_calls() and stops asking the array for logits prime()/commit_rows() throw away.

Result (main's code + this PR's instrumentation, sealed M=16 pb16i ELFs, amdxdna errors 0 on every run)

Per-depth acceptance, live vs the offline protocol at the same positions, conditional on reaching the depth:

depth live offline delta bar
1 75.41 % (138/183) 75.14 % (136/181) +0.27 PASS
2 63.04 % (87/138) 62.69 % (84/134) +0.36 PASS
3 73.56 % (64/87) 73.17 % (60/82) +0.39 PASS
4 84.38 % (54/64) 83.05 % (49/59) +1.32 PASS
  • 181 of 181 chain positions accepted the identical prefix; 709 of 709 (position, depth) pairs drafted the
    identical token
    — the loop and the protocol are the same computation.
  • 8/8 prompts TEXT IDENTICAL, stream 72 rows (= prompt + emitted), 0 cursor mismatches.
  • chain 2.874 tokens/pass; 1.28 tokens per base pass (0.78 passes/token).
  • Speed: plain 1.98 tok/s, draft route 1.03 tok/s = 0.52x — the route is correct but slower until the per-call lm
    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_offline chains from every position; the live loop only from the positions it arrives at (183 vs 568), and the
per-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
--match scores the protocol at the live loop's own positions in the same process, and --positions-out/--positions-in
do 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's
per-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 the
mean conditional rate still printed but labelled as a rate.

Also measured and asserted by --batchcheck: the deferred verify batch reproduces sequential decode exactly (argmax
0 of 63 rows differ; batch hidden rows bit-identical), and the deleted waste — prime()/commit_rows() asked for full
vocabulary logits they discarded, 7.2 → 4.00 lm-head calls per iteration, measured.

Tests

ctest -R mtp_draft 1/1: per-depth counters add up, one chain position recorded per iteration, positions advance
inside the committed stream, recorded drafts sum to accepted. Plus the pre-existing toy red/green (primed 20/20 vs
legacy_prime 0/96) that fails on the old cursor path.

Caveats

  • All device numbers are on bonsai2-27b-pb16i with the sealed M=16 ELFs and the pb16i-exact head; absolute s/tok move
    with box contention (plain decode measured 0.46-0.81 s/tok today), so speed claims are stated as ratios.
  • --match pairs exclude positions the protocol cannot score (past the stream end) rather than imputing them.
  • The tail cells that do differ are ±1 chain on different denominators (e.g. p4 depth 2: live 20/26, offline 19/19).

pi-mtploop added 4 commits November 2, 2026 13:14
…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.
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit ee9ed29)

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Unnecessary Logits Computation

The next_row function in MtpDrafter was modified to skip logits computation when need_logits_ is false, which is a good optimization. However, the logic in prime and commit_rows functions sets need_logits_ to false before calling next_row and then back to true afterward. This pattern introduces a potential race condition or inconsistency if these functions are called in a multi-threaded context, or if the next_row function is called elsewhere without the proper setup. The change should be verified to ensure thread safety and correctness in all usage contexts.

need_logits_ = false;               // prime() keeps the row, never the logits
const bool ok = next_row(hidden.data(), token, pos, next, lg);
need_logits_ = true;
if (!ok) return false;
Potential Performance Regression

The introduction of --batchcheck functionality in mtp_acceptance.cpp adds a significant performance overhead by running a full batch verification process for each prompt. While this is useful for debugging, it can significantly slow down the overall execution time of the tool, especially when dealing with a large number of prompts or tokens. This could be problematic in automated testing or CI environments where performance is critical.

if (batchcheck) {
    // Does the deferred batch verify give the same answer as plain decode?
    //
    // This is the one engine property the draft loop rests on and the only one never checked directly: acceptance
    // compares a draft against the BASE's own choice at that position, and it reads that choice from the M=nd
    // verify batch (row i-1) for draft i, while draft 1 is read from a plain step.  So a batch whose per-row argmax
    // differs from sequential decode would leave depth 1 untouched and depress every deeper depth -- exactly the
    // signature the live loop shows.  Identical TEXT does not check this: the loop only ever emits from the row at
    // the accepted-prefix boundary, and a wrongly REJECTED draft costs a pass, never a token.
    //
    // Pass A decodes greedily, recording the argmax at every position.  Pass B walks the same stream in nd-row
    // batches (committing every row, since all of them are the stream's own tokens) and compares each row's argmax
    // with pass A's.  Cost: one decode plus one pass at 1/nd the step count.
    const int nd = std::min(k, base.max_batch_rows());
    for (int p = 0; p < prompts; p++) {
        const int pi = prompt_base + p;
        std::vector<int> ids;
        for (int i = 0; i < 8; i++) ids.push_back((pi * 977 + i * 131 + 17) % (base.vocab() - 1) + 1);
        fwd.reset();
        std::vector<float> lg;
        std::vector<int> stream = ids, seq;
        std::vector<std::vector<float>> hid_ref;   // pass A's hidden at every position
        for (size_t i = 0; i < ids.size(); i++) {
            if (!fwd.step(ids[i], (int)i, lg)) { std::fprintf(stderr, "prefill failed\n"); return 1; }
            hid_ref.push_back(residual ? fwd.last_residual() : fwd.last_hidden());
        }
        for (int t = 0; t < tokens; t++) {
            int best = 0;
            for (size_t i = 1; i < lg.size(); i++) if (lg[i] > lg[best]) best = (int)i;
            seq.push_back(best);
            stream.push_back(best);
            if (!fwd.step(best, (int)ids.size() + t, lg)) { std::fprintf(stderr, "step failed\n"); return 1; }
            hid_ref.push_back(residual ? fwd.last_residual() : fwd.last_hidden());
        }
        fwd.reset();
        const int n = (int)stream.size();
        int checked = 0, differ = 0, first_differ = -1;
        int hid_rows = 0, worst_pos = -1;
        double min_cos = 2.0, max_abs = 0;
        int pos = 0;
        // prefill the prompt one position at a time, so pass B starts from the same state pass A did
        for (size_t i = 0; i < ids.size(); i++)
            if (!fwd.step(ids[i], (int)i, lg)) { std::fprintf(stderr, "prefill failed\n"); return 1; }
        pos = (int)ids.size();
        std::vector<float> all;
        while (pos + nd <= n) {
            std::vector<int> rows(stream.begin() + pos, stream.begin() + pos + nd);
            if (!base.step_batch_all(rows, pos, all)) { std::fprintf(stderr, "batch failed\n"); return 1; }
            for (int m = 0; m < nd; m++) {
                int best = 0;
                const float* l = &all[(size_t)m * (size_t)base.vocab()];
                for (int i = 1; i < base.vocab(); i++) if (l[i] > l[best]) best = i;
                // row m's logits predict the token AFTER position pos+m; pass A recorded that as seq[pos+m-7]
                const int want_at = pos + m - (int)ids.size() + 1;
                if (want_at < 0 || want_at >= (int)seq.size()) continue;
                checked++;
                if (best != seq[(size_t)want_at]) {
                    differ++;
                    if (first_differ < 0) first_differ = pos + m + 1;   // the position row m predicts
                }
            }
            {
                // The other half of "is the batch the same as decode": the batch's per-row HIDDEN, which is what
                // the drafter commits into its stream (last_hidden_rows()[m]).  The same argmax over a slightly
                // different hidden would still poison every later draft, and only this comparison sees it.
                const std::vector<float>& rows_h = base.last_hidden_rows();
                const size_t H = (size_t)base.hidden_size();
                for (int m = 0; m < nd && (pos + m) < (int)hid_ref.size(); m++) {
                    if (rows_h.size() < (size_t)(m + 1) * H) break;
                    const float* a = &rows_h[(size_t)m * H];
                    const std::vector<float>& b = hid_ref[(size_t)pos + (size_t)m];
                    double dot = 0, na = 0, nb = 0, md = 0;
                    for (size_t q = 0; q < H && q < b.size(); q++) {
                        dot += (double)a[q] * b[q];
                        na += (double)a[q] * a[q];
                        nb += (double)b[q] * b[q];
                        const double d = std::fabs((double)a[q] - b[q]);
                        if (d > md) md = d;
                    }
                    const double cos = dot / std::sqrt(na * nb + 1e-30);
                    hid_rows++;
                    if (cos < min_cos) { min_cos = cos; worst_pos = pos + m; }
                    if (md > max_abs) max_abs = md;
                }
            }
            if (!base.commit_verify(nd)) { std::fprintf(stderr, "commit refused\n"); return 1; }
            pos += nd;
        }
        std::printf("prompt %d: batch argmax vs sequential argmax: %d of %d rows differ (first at position %d)\n",
                    pi, differ, checked, first_differ);
        std::printf("  batch hidden rows vs sequential hidden: %d rows, min cos %.6f (position %d), max |diff| %.3e\n",
                    hid_rows, min_cos, worst_pos, max_abs);
    }
    return 0;
}

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

agent added 3 commits November 2, 2026 15:10
…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.
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit 66b0c37

@bong-water-water-bong bong-water-water-bong changed the title npu: measure the MTP draft loop, and stop asking for logits the drafter throws away npu: measure the MTP draft loop (matched-position acceptance, 3 estimators) and stop asking for logits it throws away Nov 2, 2026

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit 8b799fe

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Review item closed in 8b799fe: the offline conditional chain is now printed as an expectation, 1 + sum_j c_hit[j]/c_tot[0], and the sum of the conditional rates is kept as a separate line labelled "mean conditional rate (rates at different depths are not additive, so this is not a chain)". On the counts you used (394/568, 302/387, 243/296, 206/239) the two formulas give 3.016 vs 4.157, so live 2.874 / conditional 3.02 / marginal 3.189 are inside 0.35 tokens and the 1.3-token reading is gone; the body paragraph that leaned on 4.16 now carries the correction instead.

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: ninja mtp_acceptance mtp_draft_test rc 0, ctest -R mtp_draft 1/1, CI green (build/CodeQL x4/pr_agent). Nit 2 (no automated coverage of the need_logits_ branch) I agree with and it is stated as a caveat rather than fixed here: the only device-free test of that branch would need the real head, and the two device logs measuring 4.00 calls/iteration are the evidence.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@bong-water-water-bong bong-water-water-bong added the tprs-ready TPRS: review verdict READY posted by the standing reviewer; merge gate satisfied label Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit 5445bbc

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit 16fad72

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Re-gate evidence at 16fad72c (the update-branch merges moved the head past the 8b799fe READY; the queued rule is "no content change expected — must be proven, not assumed").

1. The patch is byte-identical at this head. git diff 8b799fe 16fad72c -- npu/mtp tools/mtp_acceptance.cpp tests/mtp_draft_test.cpp is empty and 8b799fe is an ancestor. The only lane-adjacent file that differs is npu/forward/src/q4nx_forward.cpp (+115/−40), which is main's own #837/#843/#848 work; the 7-line accepted-prefix truncation this PR depends on is still at q4nx_forward.cpp:1956 (last_hidden_rows_.resize(stride * (size_t)accepted) in commit_verify_rows()), and the extracted bodies of begin_verify / commit_verify_rows / step_batch_all are md5-identical between the tree my numbers were taken on (40d96325) and 1347d4f0.

2. The loop re-measured on a binary built from 16fad72c — one npu-hold -t 6 ticket, lone holder, sealed M=16 pb16i ELFs, exit 0, amdxdna ERROR lines since the run's own start: 0. This is the first run against main's t2s v2 / q4nx_t2s_sealed_elf loader change, and it is the last open risk on the numbers:

p0: TEXT IDENTICAL, 44/80, stream 72 rows, 0 mismatch | chain 3.20 | 4.00 logits calls/iter
    match p0: 20/20 prefix equal, draft tokens differ 0 (80 pairs), depths 1-4 all +0.00 pp
p1: TEXT IDENTICAL, 29/144, stream 72 rows, 0 mismatch | chain 1.81
    match p1: 35/35 prefix equal, draft tokens differ 0 (138 pairs), +1.11 / -0.87 / +0.00 / +0.00 pp
pooled: 4 of 4 depths within 2 pp at the same positions; 55 of 55 positions with the same accepted prefix

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 (--draft none as the default) holds — but a ratio needs its contention quoted next to it and SERVE-RECIPE.md will say so.

No new commit on this branch: a commit here would move the head off the gate for a print line. The one known wart (--match without --positions-out prints chain positions: N written to with an empty path, because a default-constructed std::ofstream tests true) reproduced in this run and goes in as a follow-up PR off main after this merges.

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit e6cc667

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit ee9ed29

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@bong-water-water-bong
bong-water-water-bong merged commit 5f816a9 into main Nov 3, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Review effort 4/5 tprs-ready TPRS: review verdict READY posted by the standing reviewer; merge gate satisfied

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant