Repository navigation
Description
1bit forward-serve serves the NPU route with greedy decoding only and no output constraint. The
request parser takes max_completion_tokens/max_tokens and nothing else, and the sampler is a plain
argmax:
// app/forward_serve.cpp:134
const int max_tokens = body.value("max_completion_tokens", body.value("max_tokens", 256));
// app/forward_serve.cpp:167
auto argmax = [](const std::vector<float>& v) {
int a = 0; for (size_t i = 1; i < v.size(); i++) if (v[i] > v[a]) a = (int)i; return a; };grep -ril "gbnf\|grammar" app npu tools returns nothing, so there is no constrained decoding on this
route either.
Why this matters now
The reference NPU stack shipped enforced structured output on 2026-10-22 (FastFlowLM v1.0.10,
PR #790): constrained decoding through
xgrammar, driven by the standard OpenAI fields —
response_format: {"type":"json_object"|"json_schema"}, tool_choice: none|auto|required|{function},
parallel_tool_calls — enforced while generating, with 400 for a malformed request instead of a
silently ignored field. So "ask the NPU a question and get schema-valid JSON back" works there and
cannot be done on our route at all.
Concrete consequences here:
- no structured extraction demo on the NPU (a JSON row is the most convincing thing to show);
- no temperature/top-p, so no reproducibility story beyond greedy;
- callers with an OpenAI-shaped client see the fields accepted-and-ignored, which is the failure mode
FLM's release explicitly calls out.
Proposed scope (smallest useful step)
- Parse
response_format(json_object,json_schema) plustemperatureandtop_pin
app/forward_serve.cpp, and reject what is not implemented with a400rather than ignoring it. - Mask logits before the argmax (equivalently before any truncation — filtering after truncation can
leave zero candidates) and advance the grammar state after the sampled token. - Two traps to design in from the start, both seen in the FLM PR's review:
- all tokens masked → softmax/NaN: detect "no finite logit survives" and fall back
deterministically, and do not advance the grammar with a token outside it; - per-request state leaking: the grammar/constraint state is owned per request, so it must be
reset on every exit path (this tree already had exactly this bug class with the GDN
conv_state_/rec_state_inreset(), fixed in npu: prefill a GDN model in one chunk instead of one token at a time (#587) #624's fallout).
- all tokens masked → softmax/NaN: detect "no finite logit survives" and fall back
Out of scope for the first cut: GBNF/grammar passthrough (FLM calls theirs "coming later" too), lazy
grammars, and tool-call parsing — a JSON-schema path with the two traps handled is the useful subset.
Not a duplicate
#619 tracks the census/watch side of FastFlowLM capabilities and #574 seals kernel manifests; this is
the engine-side sampling and constraint surface on our own NPU route.
Activity
bong-water-water-bong commentedon Oct 28, 2026
Verified against
main(8d2b25d), cheaply, no device work:app/forward_serve.cppis 382 lines, the request has exactly one knob —const int max_tokens = body.value("max_completion_tokens", body.value("max_tokens", 256));atapp/forward_serve.cpp:134. Everything downstream is greedy:auto argmax = [](const std::vector<float>& v)atapp/forward_serve.cpp:163, called once per token atapp/forward_serve.cpp:191. Notemperature,top_p,top_k,seed,stophandling anywhere in the file.grep -rn "gbnf\|grammar" app/ npu/ tools/returns nothing, so there is no grammar path on the NPU route and nothing to hook aresponse_formatinto.167->163for the argmax lambda), everything else is accurate.Classification: actionable now — this is pure host-side C++ behind the HTTP surface, it needs no GPU or NPU to land, and it can be tested on the CPU route. The one caveat: sampling is per-request state, and the file is a single-shot forward loop, so the fix should carry the
#618/#624-class per-request-state lesson rather than adding globals. Suggested split:temperature/top_k/top_p/seed+stopfirst (host-side, testable without the device), grammar/response_formatsecond (needs a real GBNF parser in the engine, or a decision to defer to the HRX route).serve: sampling controls and GBNF/JSON output constraint on the NPU r…
bong-water-water-bong commentedon Oct 30, 2026
Closed by #635 (merged 2026-10-30, main 38e29a2): sampling controls (temperature/top_p/top_k/seed/stop) and a GBNF/JSON output constraint on the NPU forward-serve route.