Repository navigation
npu: a noncausal pack refuses step_batch_all() too, so no draft path can verify it causally (Fixes #847) - #1282
Conversation
…can verify it causally (#847) step_batch_all() is the batched pass that returns every row's logits for a speculative decoder to check drafted tokens against. step() refuses a noncausal pack and step_batch() refuses a batch that starts above position 0, but step_batch_all() forwarded into step_batch() at start_pos 0, where a noncausal pass has every row attending to the rows after it -- so its per-row logits are not prefix-conditioned and no draft may be checked against them. Refused by name, same wording family as the other two; header and docs/npu.md carry the contract. docs/npu.md also still listed the mode itself as not implemented (stale since #861). Unreachable while a d3 pack ships no draft head; measured inert on the path it cannot reach: both mask arms, host-GEMM, 20/20 answers byte-identical to the pre-change arms, arm-vs-arm numbers unchanged.
|
#1282 ready for review at |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at 34de5656 — I compiled the changed translation unit at this head with this box's g++-16 against the real headers (rc 0), and the refusal is placed where a refusal has to be; the two doc claims re-read. Runtime behaviour is unexercised and I say why below.
Compile check of the change itself (npu/forward/src/q4nx_forward.cpp, the only C++ touched):
g++-16 -std=c++20 -fsyntax-only -DONEBIT_NPU_RUNTIME_OWN -Inpu -Inpu/forward/include -Inpu/forward \
-Inpu/target -Inpu/engine-src -I<nlohmann> npu/forward/src/q4nx_forward.cpp rc 0
That is the same TU that carries noncausal_attn_ (:534, set from plan_.noncausal()), so the member, the err_ convention and the includes are all real, not assumed.
The refusal is correctly shaped, checked against its siblings on the same file:
- it is the first statement in
step_batch_all(), beforebatch_all_out_is swapped or any KV work happens, so nothing is mutated on the refused path; - it fails the way
step()andstep_batch(start_pos > 0)do —err_ = "<named reason>",return false— and the message names the mode, says why (a noncausal batch's rows attend forward, so the per-row logits are not prefix-conditioned) and names the escape (step_batch()with the whole prompt at position 0). A caller that printserr_learns what to do, which is the house rule in this file.
Docs: the new bullet says what the code does; the second hunk retires an already-stale statement — "Also not implemented: … the pack's noncausal_full_attention attention mode" — which engine #861 made false on 2026-11-03 (gh issue view 861: MERGED 2026-11-03T01:59:34Z, "npu: attention.mode, so a noncausal_full_attention pack (d3-lite) is n…"). Correcting it to "is implemented; what is not measured is accuracy against upstream (engine#796's third rung)" is right, and it is the more useful sentence for the next reader.
What I did not do, and it is the interesting half: run it. There is no draft head on any d3 pack, so the branch is unreachable end to end by the PR's own account, and demonstrating it would need a d3 pack plus an NPU window — tonight's c31 hold excludes that for a six-line refusal. I also note there is no test arm for this refusal: tests/npu_plan_generate_test.py covers the plan-level ones (an unknown attention_mode is refused, not defaulted, and that a noncausal pack's decision_config.json sets the mode), but the runtime refusals of step()/step_batch() have no arm either, so this PR is consistent with the neighbours rather than weaker than them. If a draft head ever lands on a d3 pack, that is the moment the arm is worth writing — and the code comment says exactly that ("unreachable today … refused now so a pack that grows one cannot be silently verified through a mask it was not trained with").
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at 7de315b9 — main merges only; the reviewed content is byte-identical to the head I verdicted.
Checked rather than assumed: the PR's own added lines (own diff vs merge-base, which excludes everything main brought in) hash to d5111afe4941 at the head I reviewed and to the same value here, so no line of this PR's change moved — only its base did (the branch now sits on newer main).
Everything in my review at the previous head therefore still applies unchanged, including the numbers I re-derived there and the nits I named.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
What this changes
Q4nxNpuForward::step_batch_all()is the batched pass that returns every row's logits — the one aspeculative decoder compares drafted tokens against.
step_batch()already refuses a noncausal pack when abatch starts above position 0, and
step()refuses it outright, butstep_batch_all()forwarded straight intostep_batch()withstart_pos == 0, so on a pack withattention.mode: noncausal_full_attentionit wouldhappily return M rows of logits from a pass in which every row attended to the rows after it. Those are not
prefix-conditioned logits, so no draft may be checked against them.
Three lines of refusal, worded like the other two (the mode's name, what is wrong, and what to use instead),
plus the contract in the header comment and in
docs/npu.md.docs/npu.mdalso still listed the noncausal modeitself as not implemented — stale since #861 — so that paragraph now says what is true: the mode is
implemented and measured, and what is missing is an accuracy row against upstream (#796's third rung).
Nothing else moves: the refusal returns before any state is touched, it is unreachable while a d3 pack ships
no draft head (none does), and the prompt-encoding path is untouched — the regression row below is what says so.
Measured
ninja 1bitwith-DONEBIT_NPU=ONlinks (binarysha256 c6a38f4e…);tools/copyright.py --checkrc 0d3-lite-bf16+ its causal hardlink, host-GEMM, 20/20 answers byte-identical to the pre-change arms (worst |Δ| 0), onenpu-holdticket (108 s wait, 305 s held — inside the c31 10-minute cap), 0amdxdnaerrors, no device openedattention.mode noncausal_full_attention is a prompt-encoding mode and step() generates: …— the designed refusal, re-measured on this buildstep_batch_all()is unreachable on a noncausal pack. The proof is the compile plus the rows above showing the reachable path is untouched; there is no path to hang a device test on until a draft head exists.Closes #847
#847's acceptance, row by row, all measured on current
mainwith the engine and the reference on the sameweights (host-GEMM, no device in the loop):
mainsince #861 (attention.mode, optional, default causal;tools/npu_plan.pyreadsdecision_config.json;npu_plan_test/npu_plan_generate_testpin parse + refusal)full_attentionlayers, GDN recurrence untouchedmain(step_batch()fills K/V for every row first;step()/step_batch(start_pos>0)/nowstep_batch_all()refuse by name)score_three_levels); per-case table belowThe threshold row, per case rather than on the two worst-case scalars (
~/lb/847-main/mask_effect_percase.py; the band is the two arms' parity added, because an effect is a difference of two measured quantities):Every case's mask-effect delta is inside its own propagated band, and the case that sets the acceptance number is the one where the engine is 0.0032 short while its own causal-arm disagreement with the reference is 0.0056 — the shortfall is the forward's parity, not a smaller mask.
refs #847 (the hardening) — the acceptance rows above are what close the issue, and
step_batch_all()was theone path in it that could still answer a noncausal pack silently. If you read the 0.0032 against the literal
"at least 0.2869" as short rather than as inside the parity band, say so on the issue and I will produce a
same-weights reference comparison instead of fitting the mask to a number.