Repository navigation
Closed
Labels
enhancementNew feature or request
Description
What FLM does (v1.0.11, the spec)
logprobs and top_logprobs on /v1/chat/completions, streamed or not, as in the OpenAI API:
top_logprobsaccepts 0 to 100.- Values are the model's log-probabilities before penalties, constraints, temperature and top-k/p — same
convention as OpenAI and vLLM. - Only
contenttokens get entries: reasoning, tool-call markup and template markup get none. - Speculative decoding is supported (qwen3.8-mtp), speculated tokens included; FLM notes the values can
differ slightly from plain decoding and offersFLM_DISABLE_SPECULATION=1to compare. - v1.0.11 also added
seed,continue_final_messageandrepeat_last_non the same endpoint, and made
max_tokensexact (a reply used to be one token longer than asked).
What we do today
logprobs / top_logprobs appear nowhere in app/ or npu/ (grep -rn "logprobs" app/ npu/ → no
hits). The sampler in app/npu_sampling.h:79 (sample_token) sees full logits and returns only the chosen
id, so the information exists at the sampler and is thrown away. app/forward_serve.cpp builds the response
message from text only.
Smallest implementation
SampleParamsgainslogprobs(bool) andtop_logprobs(0..100, default 0) inapp/npu_sampling.h, parsed
inoptions_from_body()next totemperature/top_k.sample_token()already has the logits vector and already applies penalties/masks internally — return an
optional(chosen, top: vector<(id, logp)>)captured before penalties and temperature are applied, which
is the one ordering detail that matters for matching OpenAI/vLLM.- Answer assembly in
app/forward_serve.cpp: for each generated token whose piece lands incontent(i.e.
outside the reasoning/tool-call regions — which only exists once the parser gap in the constrained-decoding
issue lands), emitlogprobs.content[i] = {token, logprob, top_logprobs[]}; streaming gets one
choice.logprobs.content[0]per chunk. max_tokensexactness: cap the loop atmax_tokensrather than at "≤ max_tokens" — check the count in the
same place thefinish_reasonis decided.
Refs: FLM v1.0.11 release notes ("OpenAI API: logprobs, seed, continue_final_message and repeat_last_n")
No code before Sunday (2026-11-01 06:00 ADT).
Metadata
Metadata
Assignees
Labels
enhancementNew feature or request
Activity
bong-water-water-bong commentedon Oct 31, 2026
Triage:
enhancement. Confirmed absent atorigin/main31d52e1:and the sampler is the shape the issue describes —
sample_token()inapp/npu_sampling.happlies masks,penalties and temperature internally and returns only the chosen id.
Held to Sunday 2026-11-01 06:00 ADT (issue's own line). Order after that, and the reason for it:
max_tokensexactness are both host-only andtestable without the device: the capture is a new return type at the sampler with a golden-tensor test that
the logprobs are the pre-penalty ones (temperature 0 vs 1.5 on the same logits must give the same values),
and item 4 is the loop cap in the same place
finish_reasonis decided.contenttokens get entries" is unimplementable until a parser can tellcontent from reasoning/tool markup; without it every
<think>token gets an entry, which is the one thingthe FLM spec explicitly does not do. Landing item 3 early would ship a wrong shape that later has to change.
Acceptance I would write into the PR: for one prompt,
logprobs.content[i].logprob == logprob of content[i].tokenwithin 1e-6,top_logprobssorted descending and ≤ requested n, and no entry for a tokeninside a reasoning region.
bong-water-water-bong commentedon Nov 1, 2026
Items 2 and 4 are up as #733 (
1bit/npu-logprobs, 0925b26):logprobs/top_logprobson/v1/chat/completionsstreamed and not, with the values taken from the untouched logits (pre-top_k/top_p/temperatureand pre-grammar-mask, measured: a masked-in token reports −19.53 whiletop_logprobs[0]is −0.0013), andmax_tokensexactness as a test row rather than a code change (logprobs.content.size()= 1/3/8 formax_tokens1/3/8).Item 3 is not in it, on purpose: the
content-only boundary needs the answer parser from #652 items 2-3, and Qwen3-0.6B answers open with a<think>block, so entries currently cover reasoning tokens too. Item 4's/v1/completionslegacy logprobs shape is refused by name instead of silently dropped.npu: logprobs and top_logprobs on /v1/chat/completions, so a client c…
bong-water-water-bong commentedon Nov 1, 2026
Item 3 is up as #748 (
1bit/npu-logprob-content), stacked on the answer parser #747 — which is what unblocked it: without a content boundary there was nothing to report entries for, exactly as this issue's dependency note said.The boundary is a function, not a convention:
content_mask(pieces, family, tools_sent)inapp/npu_answer_parser.hruns the sameAnswerStreamthe reply is split with, so what logprobs claims is content cannot drift from whatcontentactually contains. Measured by ctest: reasoning tokens and the</think>token get no entry, the answer's tokens do, a straddling token (hmm</think>The) counts as content, and<tool_call>markup gets no entry whentoolswas sent but does when it was not.That closes #651 items 2, 3 and 4: values from the untouched distribution, entries for content only, and
max_tokensexactness proven rather than changed.npu: logprobs entries only for content tokens, now that the parser sa…
npu: logprobs entries only for content tokens, now that the parser sa…
npu: logprobs entries only for content tokens, now that the parser sa…
bong-water-water-bong commentedon Nov 1, 2026
Closed on merge, in two pieces: #733 →
33775afe9(items 2+4) and #748 →44d849df9(item 3, the content-only entries that were blocked on the answer parser).logprobs/top_logprobson/v1/chat/completions, streamed and not. Before:logprobs: true, top_logprobs: 3returned 200 with the fields silently dropped. After:choices[0].logprobs.content[]populated;max_tokens1 / 3 / 8 giveslogprobs.content.size()= 1 / 3 / 8 withfinish_reason: length; the streamed deltas add up to the non-streamed reply by construction (a FIFO aligned with the held-back stop-sequence bytes). Values are pre-top_k/top_p/temperature and pre-grammar-mask (read from the sampler's own logits vector, sosample_token()and its 20+ call sites are untouched).top_logprobsrange 0..100;top_logprobswithoutlogprobs: trueis a 400;/v1/completionsrefuses the field and names the chat endpoint.content_mask()inapp/npu_answer_parser.h— one bit per token, 1 only when that token's text reachescontent, computed by the sameAnswerStreamthe reply is split with, so the logprob boundary cannot drift from the content boundary. ctestnpu_samplingPASS, 5 new assertions covering<think>, the</think>token itself (markup, no entry), a straddlinghmm</think>The(entry — its text reached the caller),<tool_call>with and withouttoolssent, and text held back to the end.npu: forward-serve honours chat_template_kwargs.enable_thinking (#832)
npu: forward-serve honours chat_template_kwargs.enable_thinking (#832) (