[Perf][Frontend] Defer reasoning usage recounts for non-continuous chat streams - #56067
Open
positive666 wants to merge 3 commits into
Open
positive666 wants to merge 3 commits into
positive666 wants to merge 3 commits into
Conversation
Count once per choice when continuous usage is disabled, while preserving final middleware usage and continuous reporting. Co-authored-by: Codex <noreply@openai.com> Signed-off-by: Cheng Rui <286040359@qq.com>
positive666
requested review from
AndreasKaratzas,
DarkLight1337,
NickLucche,
aarnphm,
chaunceyjiang,
robertgshaw2-redhat and
russellb
as code owners
September 9, 2026 11:29
Signed-off-by: Cheng Rui <286040359@qq.com>
Keep continuous/forced recounts per delta, count once before final usage, and freeze cancel, error, and empty-choice behavior. Signed-off-by: Cheng Rui <286040359@qq.com>
Contributor
Author
|
Follow-up on current
Happy to rebase again if review wants a different test split. |
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
Chat streaming recounts reasoning tokens from the full generated history on every delta, even when continuous usage is disabled. For Qwen's parser with thinking disabled, this falls back to repeatedly decoding and parsing the entire history.
Count once per nonempty choice before final usage and middleware metadata. Preserve per-delta counting for continuous/forced usage, and skip accounting-only work when reasoning usage details are disabled. No changes to parser counting rules, sampling, or model computation.
Results
Historical A/B, pinned source
114abd1c; one L40S, TP1, existingQwen3.8-27B-FP8model directory (config:Qwen3_5ForConditionalGeneration). Same environment and default compile/CUDA graphs for both versions. Reverse-order repeat:CPU seconds measure API-process user+system time, not request wall time. No meaningful model-throughput gain was observed. Requests used temperature=0, seed=42 and ignore_eos for fixed lengths; this is serving validation, not a task-accuracy benchmark.
All single-request scenarios matched token IDs, text and usage. Replaying the same 25,344 model tokens through both frontends produced identical SSE and final usage in all five scenarios.
Tests
Branch is merged with current
main(1596fa5f). The serving hunk still matches HEAD: per-deltacount_reasoning_tokensonly when continuous/forced usage is on; otherwise one recount per nonempty choice before final usage.Linux CPU re-run on GitHub main
1c3ef2adplus this patch (CUDA_VISIBLE_DEVICESempty,VLLM_TARGET_DEVICE=cpu):n, details on/off, continuous/forced/none).finish_reason=error, cancel, andaclose.Related work
No same-scope open fix. #55216 optimizes membership checks inside reasoning extraction, not usage recount frequency. #44398 is an older reasoning-usage feature with a final-counting precedent; this patch optimizes the already-merged implementation while preserving continuous usage. #54238/#54585/#50240 change parser counting rules, not how often serving recounts. #56129 covers the reasoning field round-trip, not usage accounting.
AI assistance was used for implementation and validation. The submitter reviewed the changes and reran the relevant tests.