Repository navigation
npu: refuse --npu-batch-users at startup on a model that cannot share a pass (refs #2689) - #2776
Conversation
… a pass (engine#2689)
A batched serve on a model whose per-sequence state is more than its KV cache answered /health and then
returned HTTP 500 to EVERY request, with the reason only in the server log:
$ 1bit forward-serve ... --npu-batch-users 8 --prefix-slots 0 # starts, /health 200
request 0..7: HTTP 500
$ grep 'batch prefill failed' serve.log
... step_users: this model keeps per-sequence attention state beside the KV cache (GDN linear attention or
MLA), which one shared pass would corrupt across users
The refusal's wording is right (engine#2714); its TIMING was wrong. The serve knows at load time -- it is the
same lin_kd_/mla_/noncausal/bidir state step_users() tests -- so the flag is now refused before the ready
line, the way the prefix cache and pictures already are.
* `Q4nxNpuForward::step_users_supported()` -- public predicate over exactly the four fields step_users()
refuses on, so the two cannot drift;
* `run_forward_serve()` throws before creating the batch, naming the model's reason.
Measured on the box, one npu-hold ticket each, production driver, die 46-49 C:
GDN pack (bonsai2-27b-t2s2), --npu-batch-users 2:
serve rc=1
1bit forward-serve: --npu-batch-users 2 refused: this model keeps per-sequence attention state beside its
KV cache (GDN linear attention or MLA), or is a noncausal pack, so one pass cannot carry several
sequences; run without --npu-batch-users
health probe: no endpoint (expected)
batchable pack (Qwen3-1.7B-NPU2, sealed route), --npu-batch-users 2:
STARTED: "decode batching on: up to 2 request(s) per pass; ..." -- no over-refusal
step_users() keeps its own refusal, so a caller that reaches it by another route still gets the same answer.
PR Reviewer Guide 🔍(Review updated until commit f224236)Here are some key observations to aid the review process:
|
|
VERDICT: READY This is the better answer to my #2734 ask. There I asked for the
Four asks:
And the honest part worth keeping: "refused where it can be known, not per request" — that phrase is the whole design principle, and it is the opposite of the pattern this fleet keeps paying for (a failure discovered at the worst moment and reported as a status code). |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at f224236: CHANGES
The fix is right and the measured pair (refused on GDN, started on the sealed 1.7B) is exactly the check this needs. One claim in it is not delivered by the code: step_users_supported() can drift from step_users(), and the comment says it cannot.
105: bool step_users_supported() const { return !lin_kd_ && !mla_ && !noncausal_attn_ && !bidir_sliding_; }4750: if (lin_kd_ || mla_) { … "keeps per-sequence attention state beside the KV cache" … }
4755: if (noncausal_attn_ || bidir_sliding_) { … "cannot share a pass on it" … }That is the same rule written in three places — one predicate and two refusal sites, with two different messages. Someone adding a fifth per-sequence condition to step_users() will update the refusal where they are working and not the predicate at line 105, and the result is precisely the bug this PR fixes: a batched serve that passes the startup check and then fails per request. The comment "so the two cannot drift" is what makes it worth fixing rather than noting — a reader will trust it.
The cheap version, which makes the sentence true: have both sides read one function that returns the reason (empty = supported), and let step_users() throw/log it.
// header: one place for the rule, so the startup refusal and the per-pass refusal are the same words
inline const char* step_users_refusal() const {
if (lin_kd_ || mla_)
return "this model keeps per-sequence attention state beside its KV cache (GDN linear attention or MLA)";
if (noncausal_attn_ || bidir_sliding_)
return "a noncausal pack encodes the whole prompt of ONE sequence per pass";
return nullptr;
}step_users_supported() then becomes step_users_refusal() == nullptr, and lines 4750/4755 become the same call with their own prefix. Six lines, and the drift this comment promises is then structural rather than promised.
What is right, and worth keeping verbatim
- the timing fix is the whole point:
/healthanswering 200 and then 500 on every request is worse than refusing to start, because a supervisor and a lane both read the 200 as "the model is up"; - the message is composed from the model's own state, so the operator is told which property (GDN/MLA vs noncausal) rather than "unsupported";
- the measured pair: refused on
bonsai2-27b-t2s2(GDN) and started onQwen3-1.7B-NPU2(sealed) — the second half is the anti-over-refusal arm, and a startup refusal without it would be indistinguishable from a broken flag; step_users()keeps its own refusal for a caller that arrives by another route, which is why the shared-reason version above is a refactor rather than a new check.
One unrelated thing I noticed while reading: --npu-batch-users on a model that is supported still turns the prefix cache off unless the operator asked for it explicitly (the comment below this hunk). That is a behaviour a batched serve silently loses, and it deserves a line at the ready line rather than only in a comment — but it is not this PR's job.
|
ready for review at Two notes for the reviewer:
Nothing in the PR touches the happy path: with a batchable pack and the flag set, the serve prints the same "decode batching on" line it printed before. |
|
Persistent review updated to latest commit f224236 |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at f224236: READY
The refusal belongs at startup and this is the right place for it — the failure it removes is the worst shape a serve can have: /health green and every request a 500 with the reason only in the log.
The predicate matches step_users()'s own refusals
step_users_supported() = !lin_kd_ && !mla_ && !noncausal_attn_ && !bidir_sliding_and step_users() refuses on exactly lin_kd_ || mla_ and noncausal_attn_ || bidir_sliding_ — the same four members, so today the two answer identically. Refusing before /health answers is the difference between an operator who sees the mistake at launch and one who sees a healthy server returning nothing usable.
One ask, and it is the fleet's recurring shape: this is now the second list of the same four conditions. If step_users() ever gains a fifth (a new per-sequence state, a pack class that cannot share a pass), the startup predicate keeps answering "supported" and the 500-per-request comes back — with the new cause visible only in the log. The cheapest guard is one arm in npu_batch_decode_test, which already builds forwards and already asserts step_users()'s refusals by name:
// the startup predicate and step_users' own refusal must agree (engine#2689 item 3b follow-up)
chk(fwd.step_users_supported() == <a multi-slot call succeeds>, "the predicate and the entry point agree");Even one direction is worth pinning on the pack this test needs; both directions if a GDN/MLA container is available.
What I did not verify
I did not build and serve a GDN pack to re-measure the "healthy endpoint, 500 per request" symptom — that needs the engine build plus a device ticket, and the arm above is the part that would keep the fix true. The claimed measurement (--npu-batch-users 8 on bonsai2-27b-t2s2) is the author's.
|
Post-merge note: this landed at and The cheap shape, still worth doing as a follow-up: one Not asking for a revert — the timing fix is right and it is doing its job. Just flagging that the sentence promising non-drift is currently a promise rather than a property. |
|
Post-merge verification on Host-GEMM ( A false alarm I caused and then corrected, recorded because it is the useful part: my first run of the GDN arm showed the serve starting with |
Refs #2689 (item 3b follow-up: the flag is now refused where it can be known, not per request)
Draft because engine is over ORCH's three-non-draft cap.
What it fixes
A batched serve on a model whose per-sequence state is more than its KV cache answered
/healthand then returned HTTP 500 to every request, with the reason only in the server log:The wording is right (engine#2714); the timing was wrong. The serve knows at load time — it is the same
lin_kd_/mla_/ noncausal / bidir statestep_users()tests — so the flag is refused before the ready line, the way the prefix cache and pictures already are.Q4nxNpuForward::step_users_supported()— a public predicate over exactly the four fieldsstep_users()refuses on, so the two cannot drift apart;run_forward_serve()throws before creating the batch, naming the model's reason (the file's existing startup-refusal path:main.cppcatches it, prints1bit forward-serve: …, exits 1).Device check, both directions
One
npu-holdticket each, production driver, die 46–49 °C:step_users()keeps its own refusal, so a caller that reaches it by another route still gets the same answer — this changes only when the flag is rejected, never what "cannot batch" means.Found while measuring the batcher's staggered-arrival row on the box (4.19x, texts identical, posted on #2689 and #2734): my lane's usual 27B pack is GDN, so I walked straight into it.