Conversation
…ds4) QA tooling needs per-token log probabilities to run the margin bench against dflash_server. Add logprobs/top_logprobs (0-20) to /v1/chat/completions as an opt-in that forces the autoregressive path and a full logits readback per committed token, computes a raw-logit log-softmax (before penalties and temperature), and returns OpenAI-shaped entries whose token text concatenates exactly to message.content and reasoning_content. Nothing changes for requests that do not ask for it. Scope is intentionally narrow: non-streaming, single-slot, qwen35 and deepseek4 only; other backends, the scheduler and stream=true return 400. Spec-decode-path logprobs, streaming, scheduler support and the KLD dump are follow-ups. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Graffioh
force-pushed
the
devin/chat-logprobs-ar
branch
from
September 17, 2026 06:51
9f69f6d to
5340691
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
logprobs/top_logprobsto/v1/chat/completionsas a QA-only, opt-in feature so the fidelity tooling inluce_box/lucebox_qa(Luce-Org/luce_box#168) can run a margin bench againstdflash_server. Nothing changes for requests that do not setlogprobs: true.logprobs: bool(default false),top_logprobs: int0–20 (default 0, requireslogprobs: true).choices[0].logprobs = {content: [...], reasoning_content: [...]}with OpenAI-shaped entries (token,token_id,logprob,bytes,top_logprobs). Invariant:join(content[].token) == message.content, same forreasoning_content; stop-sequence truncation keeps it.server/docs/API.md→ "Logprobs".force_ar_decode(existing knob) and bypasses the GPU-argmax / GPU-sampler shortcuts so the full logits row is read to the CPU each step; it also skips prefix-cache restore/save (an exact-hit restore yields the first token with no logits row).common/logprobs.{h,cpp}(compute_token_logprob),GenerateRequest::logprobs_top_k,DaemonIO::emit_with_logits+on_token_logprob,ModelBackend::supports_logprobs()(true for qwen35 and deepseek4). The response builder fails with 500 if the record count does not match committed tokens, so a missed commit site can never serve shifted probabilities.Scope / limits (400 with a clear message)
stream: true+logprobs→ 400)--max-concurrency> 1 / scheduler path → 400logprobs requires --max-concurrency 1)Follow-ups (not in this PR)
lucebox_qa/logit_toolsneeds)Cost
qwen35 (Qwen3.8-27B IQ4_XS, R9700): AR 30.9–31.0 tok/s → 29.7–30.0 tok/s with logprobs (~3–4%, the forced logits D2H per step). deepseek4 hybrid: ~0.4% (its AR path already keeps logits CPU-side). Both vs. the spec-decode default the request opts out of.
Test plan
test_server_unit: 592/592 (newtest_logprobs.cpp: log-softmax normalisation, argmax max, top-K order + tie-break, K=0/K>vocab, ±1e4 finite; newparse_request_logprobsvalidation cases)server/tests/test_server_logprobs.pyagainst a real qwen35 server (Qwen3.8-27B + DFlash2 draft, block 16, gfx1201): 27/27 — shape, key absent when unrequested, bounds, top-K ordering and greedy chosen == top[0], concatenation invariants incl. thinking on, byte-identicalmessage.contentwith and without logprobs (spec vs forced AR), six 400 cases, stop-sequence truncation--max-concurrency 4: logprobs → 400, plain → 20017 + 25 = 42vs57, first token at logprob ≈ −0.98). Pre-existing numerics divergence unrelated to this change; the test has--allow-spec-divergenceto record it as a warning whenusage.spec_decode_ranis true--paged-attention; sampled-mode spot check OKlucebox_qa/logit_tools/vendor/probe_router.pyagainst this and record the first margin panelGenerated with Devin