Repository navigation
mtp: a stop is a stop -- the accepted-prefix loop ends the run, and a full budget pays no verify batch - #997
Conversation
… full budget pays no verify batch
run()'s documented contract is "on_token returning false stops the loop", and the top-of-loop token
honoured it while the accepted-prefix loop did not: `if (!emit(d[i])) { r.tokens.pop_back(); break; }`
broke the INNER loop, so the while walked on and handed the consumer the base's own argmax at that
position again -- one delivery past its stop, which is exactly what a streaming serve cannot have
(EOS, or a client that went away, has to end the iteration it lands in).
The same block also ignored the caller's budget: with one token left, the iteration still paid the
step's head commit, the drafter's chain and a full M=k+1 verify batch, credited the accepted drafts,
and then emitted none of them.
Fixed in npu/mtp/draft.h, three lines of behaviour:
* a false from on_token sets `stopped`, the run breaks out of the while, and the refused token stays
emitted and committed exactly as a refusal on t1 does (npu/generate.cpp's emit keeps it too);
* the budget is checked straight after t1's step, before any draft is made -- the step is still
taken, so the base has consumed every token the caller was handed (no position is skipped);
* the end-of-iteration break also honours `stopped`.
tests/mtp_draft_test.cpp [11] states both defects, and the old code fails on them:
before after
consumer refuses the 3rd token 4 deliveries, the 3rd token delivered twice 3 deliveries, tokens 3
k=4, max_tokens=7 (odd budget) batches 4 (one paid for nothing) batches 3, consumed 11
Reproducer: `ninja mtp_draft_test && ./mtp_draft_test` -- "3 CHECK(S) FAILED" before, "all checks
passed" after (the 60-odd pre-existing checks, [1]-[10], unchanged). `ctest -R mtp_draft` 1/1,
`tools/copyright.py --check` rc 0, `mtp_acceptance` builds and links against the same header.
No published number moves: the added break can only trigger on an iteration that would have emitted
nothing, and the gate runs (prompt 0, 64 tokens, k=4) account for 20 iterations = 20 steps + 20
batches = 40 passes, i.e. no such iteration existed. Acceptance, per-depth tables and text identity
are untouched; the saving is one step + one batch per stopped or exactly-full run.
PR Reviewer Guide 🔍(Review updated until commit e3f0f1d)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: READY — I reproduced the three failures the PR claims, by swapping main's header back in under the same test.
Reviewed at f66969d69 (2 files, +65/-3: npu/mtp/draft.h, tests/mtp_draft_test.cpp).
The only evidence that matters here is whether [11] discriminates, so I built tests/mtp_draft_test.cpp against this
head's npu/mtp/* and then again with npu/mtp/draft.h taken from origin/main, same compiler and same flags:
this head: all checks passed (rc 0)
main's header: PASS stop: the refused token is in the output exactly once…
FAIL stop: no delivery after the consumer refused a token (the loop ends here)
FAIL stop: the consumer is never handed the same token twice by one stop
INFO stop: 4 deliveries (refusal at 3), tokens 3, iterations 1, batches 1
FAIL budget: no verify batch is paid for a chain that cannot emit a token
INFO budget: emitted 7, steps 8, batches 4, consumed 11 for a prompt of 4
3 CHECK(S) FAILED
Three failures on the old header and none on the new one — the count in the PR body is right — and the INFO lines show
both defects at once: 4 deliveries instead of 3 (the refused token handed back a second time) and 4 batches
instead of 3 (a verify batch paid for a chain that could not emit). The two checks that pass on the old header are the
right ones to pass (stop: the refused token is in the output exactly once), so the test is not just counting failures:
it pins the convention while allowing the bug.
Reading the fix, the three behaviour changes are each the smaller of the two options: stopped propagates out of the
while rather than re-entering it, the budget check sits after t1's step (so the base still consumed every token the
caller was handed — no skipped position), and the end-of-iteration break honours the same flag. The comment on
run()'s contract is now true of both loops, which is the actual defect: the header documented a contract that half the
loop did not keep.
Nit: the new checks live in [11], but the PR body's before/after block describes them as three failures of "the pre-fix
header" without saying which arm produced the budget INFO row; a reader re-running only [11] sees 4 lines of INFO and
has to guess the mapping. One sentence naming [11] there would close it.
|
Persistent review updated to latest commit 0de4264 |
|
Persistent review updated to latest commit 3eb9a9a |
|
Persistent review updated to latest commit 9146460 |
|
Persistent review updated to latest commit e3f0f1d |
Root cause
npu/mtp/draft.hrun()documents its contract one line above the loop: "on_tokenreturning false stops the loop". The top-of-loop token honoured it; the accepted-prefix loop did not.So a refusal during the accepted prefix walked back out to the top of the
while, which then emitted the base's own argmax for that position — the same token the consumer had just refused, a second time — and carried on untilmax_tokens. For a streaming serve that is the difference between stopping on EOS (or on a client that went away) in the iteration it lands in and stopping one iteration later with a duplicated token.The same block also ignored the caller's budget: an iteration that entered with exactly one token left paid t1's step, the drafter's chain and a full M=k+1 verify batch, credited the accepted drafts, and emitted none of them.
Fix (three lines of behaviour,
npu/mtp/draft.h)on_tokensetsstopped; the run breaks out of thewhile, and the refused token stays emitted and committed, exactly as a refusal ont1at the top of the loop already did (npu/generate.cpp'semitkeeps the stopping token too, so this matches the house convention);t1's step, before any draft is made. The step is still taken, so the base has consumed every token the caller was handed — no position is skipped;stopped.Measured before / after (host, toy base, no device, no weights)
tests/mtp_draft_test.cpp[11]states both defects; the pre-fix header fails 3 of its checks:f63af5f9)tokens 3, run endsmax_tokens = 7(odd budget, so the 7th token is a baret1)batches 3,consumed 11= prompt 4 + 7Reproducer:
ninja mtp_draft_test && ./mtp_draft_test→3 CHECK(S) FAILEDon the pre-fix header,all checks passedafter. Every pre-existing check[1]–[10]stays green (k=0 bit-identity, rollback fidelity, drafter stream/cursor, per-depth denominator, the 692-column matvec bit-identity).Also:
ctest -R mtp_draft1/1,mtp_acceptancebuilds and links against the same header,tools/copyright.py --checkrc 0.No published number moves
The added break can only trigger on an iteration that would have emitted nothing, and the gate runs (prompt 0, 64 tokens, k=4,
tau=0) account for 20 iterations = 40 passes = 20 steps + 20 batches — no such iteration existed in them. Acceptance, per-depth tables and byte-identical text are untouched; the saving is one step + one verify batch per run that stops early or fills its budget exactly ont1.No device was touched for this PR: it is a host-only test-suite change plus three lines of the loop. No issue exists for this; it came out of this lane's own
[11]reproducer.Parity note: this is what the shipped serve path already does
Both behaviours the draft loop was missing are in
app/forward_serve.cpp, on the plain decode route that is serving:18097today::387if (!on_text(out, take_held(emit))) break;— a failed delivery ends the loop, it does not walk back out to alater iteration;
:393if (n + 1 >= limit) break;— a budget that is already full does not pay for the decode step whose onlyoutput would be the next position's logits (the same waste, one step there, a step plus a verify batch here).
So #997 is not a new policy: it makes
mtp::run()behave the way the route it is meant to replace already behaves whenthe owner flips
--draft mtp.