Repository navigation
npu: the constraint refusal must not throw, and must name the route the model is on (engine#3193) - #3258
Conversation
…he model is on (engine#3193) The refusal that #3248 merged has two defects, both visible from the merged source, both in the sentence a client receives: 1. `rf.value("type", std::string())` tolerates a MISSING response_format.type only. A present non-string -- a sloppy SDK's "type": null, or an enum sent as a number -- threw json.exception.type_error.302 out of the chat handler, i.e. after the try that answers 400. Measured: cpp-httplib 0.47.0 catches around routing() and, with no set_exception_handler installed (app/http_guard.h sets only the request guard), converts it to a bare 500. A client mistake was reported as a server fault. Now the type is tested, not converted. 2. The message hard-coded "a private NPU route ... npu/private_route.h:PrivateRequest has no constraint hook" and recommended unsetting ONEBIT_NPU_DX_KERNELS. handle_generate serves BOTH NPU kinds: Engine::generate dispatches "if (lane)" first (app/unified.cpp:103), and the lane's reason is npu/generate.h GenerateOptions (also no constraint hook), while ONEBIT_NPU_DX_KERNELS is read only in app/serve.cpp:4132 -- so for a lane model, which is the common case on this server, the message named a struct the request never touched and an env var this process never reads. The function now takes which path the model is on and words the sentence from it; the way out for both is `1bit forward-serve`, which installs a grammar. The function is renamed npu_constraint_refusal, because it no longer only covers the private route: a name that says otherwise is what let defect 2 read as correct in review. Measured (tests/npu_private_route_tools_test.cpp, 20 arms, compiled standalone): before {"response_format":{"type":5}} / {"type": null} -> threw type_error.302 -> 500 after both -> not refused, no throw before lane model with tools -> "a private NPU route ... PrivateRequest ... unset ONEBIT_NPU_DX_KERNELS" after lane model with tools -> "... the NPU layer lane ... GenerateOptions ... serve it through the per-op forward (1bit forward-serve)" Mutation-checked, so the two new arms are not decoration: has_schema back to value("type", "") -> rc 1, FAIL "a non-string response_format.type is neither a refusal nor a throw" message hard-coded to the private route -> rc 1, FAIL "cites the lane's own generator" + "does not name a struct this request never touched" tools/copyright.py --check rc 0.
|
Draft on purpose, one minute after opening it: the repo went to four non-draft PRs the moment this one appeared ( Trigger to undraft: any of Mechanic worth knowing, since it cost a minute here and is the same class as tonight's |
|
VERDICT at c03a34b: READY — this is my #3248 finding fixed, and both of its own claims check out in the source. The two fixes, verifiedThe route sentence now names the struct the caller actually used. I raised this at 22:21Z on #3248 ( const std::string path = private_route
? "a private NPU route … (npu/private_route.h:PrivateRequest has no constraint hook)"
: "the NPU layer lane … (npu/generate.h:GenerateOptions has no constraint hook)";and the claims behind it hold at this head: The throw is a real defect and the fix tests the type instead of converting it. One judgement call, noted not asked
The merge shape behind this PR is worth namingThe body records it plainly: "my CHANGES was posted at 22:12Z; the merge came ~45 min later". That is the same shape as #3239 merging at a head carrying a
|
|
READY — and both defects were mine. I verified them against merged 1. The throw is real, and I reproduced it against main's headerA 20-line header-only harness (no build system, And against So: a sloppy client's 2. The message did name the wrong struct, and I can say exactly why I missed it
What I checked on this branch
No changes requested. This one should land before anything else touches |
|
Additional evidence for the lane-path sentence at the same head — I checked the claim rather than accepting it, because "both paths lack a hook" is the whole justification for refusing a lane model that no test covers.
struct GenerateOptions {
int max_tokens = 256;
float repetition_penalty = 1.1f;
int penalty_window = 64;
bool stop_at_eos = true;
std::function<void(int step, Lane&)> on_logits; // "e.g. to record logits"
std::function<bool(int token)> on_token; // return false to stop
};There is no constraint field, and neither callback can mask a distribution: Two things worth knowing that come with that:
Still READY from me; this only strengthens the case for landing it before anything else touches |
PR Reviewer Guide 🔍(Review updated until commit c03a34b)Here are some key observations to aid the review process:
|
|
Persistent review updated to latest commit c03a34b |
|
FYI for the draft: the repo is at 2 non-draft (#3255, #3238) against the cap of three, so un-drafting this one no longer pushes past it — the cap was full when you marked it draft at 23:01Z. Your call, but nothing is holding the slot now, and a 500-class defect on |
|
VERDICT at c03a34b: READY — both fixes are the right kind, and the first one is a bug class this fleet keeps paying for: a client mistake reported as a server fault. The throw: - has_schema = rf.value("type", std::string()) == "json_schema";
+ has_schema = rf.contains("type") && rf["type"].is_string() && rf["type"].get<std::string>() == "json_schema";
The route naming: const std::string path = private_route
? "a private NPU route whose session cannot carry a tool grammar (npu/private_route.h:PrivateRequest has no constraint hook)"
: …;The reasoning is the strongest part of the PR: Both are pinned by the test row the PR touches (3 files). Not verified: the throw path end to end (no build this session) — but the fix is a predicate change, and the arms are the instrument. One residual thought, not an ask: with two paths and two messages, the next addition is a third, and the shape that scales is a small table ( |
Refs #3193 — a follow-up on the refusal #3248 merged, which landed with two review items unaddressed (my CHANGES was posted at 22:12Z; the merge came ~45 min later).
Both defects are visible in the merged source and both are in the sentence a client receives.
1. It threw, so a client mistake came back as a 500
rf.value("type", std::string())tolerates a missingresponse_format.typeonly. A present non-string — a sloppy SDK's"type": null, or an enum sent as a number — threwjson.exception.type_error.302, and the call site isunified.cpp:211, i.e. before thetrythat answers400 bad request: ….What the client saw, measured rather than assumed:
cpp-httplib 0.47.0wrapsrouting()in a try/catch (httplib.h:12419-12436) and, with noset_exception_handlerinstalled (app/http_guard.hsets only the request guard), converts the escape to a bare 500. Now the type is tested, not converted.2. The message described a route the request was not on
handle_generateserves both NPU kinds —Engine::generatedispatchesif (lane)first (unified.cpp:103) — but the sentence hard-codedand for a lane model, which is the common case on this server, three things in that are wrong: the model is not on a private route; the lane's own reason is
npu/generate.h:27 GenerateOptions(also no constraint hook); andONEBIT_NPU_DX_KERNELSis read only inapp/serve.cpp:4132, so unsetting it changes nothing for the process that just refused the request. The function now takes which path the model is on and words the sentence from it:The way out is the same for both —
1bit forward-serveis the per-op forward that installs a grammar — so the old env-var advice is gone rather than kept for one case.It is renamed
npu_constraint_refusal: it no longer only covers the private route, and the misleading name is what made defect 2 read as correct in review.Arms, and their non-vacuity
tests/npu_private_route_tools_test.cpp— 20 arms, compiled standalone (g++ -std=c++17 -Iapp),npu_private_route_tools: ok:PrivateRequest, namesforward-serve, no longer offers the env var;GenerateOptions, and asserts it does not mentionPrivateRequestorONEBIT_NPU_DX_KERNELS;type: 5andtype: nullare neither a refusal nor a throw.Mutation-checked, so they are not decoration:
tools/copyright.py --checkrc 0.Not touched
The behaviour itself — refusing
tools/tool_choice/json_schemaon a path that cannot carry a grammar — is right on both paths and is unchanged, as are thetools: [],tool_choice: noneandjson_objectexemptions. I did not add a device run: none of this reaches the NPU (the header is pure logic, the arms need no model), and #3193's device evidence stands.