Repository navigation
[Bugfix][Frontend] Report reasoning tokens in batched chat completions - #64935
Conversation
/v1/chat/completions/batch never set usage.completion_tokens_details, so batched requests to a server started with --reasoning-parser omitted the reasoning_tokens that /v1/chat/completions reports for the same conversation. Count each conversation's reasoning tokens with its parser, as the single-conversation path does, and sum them in the batch usage. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: GCSimba <44427703+GCSimba@users.noreply.github.com>
|
👋 Hi! Thank you for contributing to the vLLM project. 💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in PRs do not trigger a full CI run by default. Reviewers with write access and configured trusted contributors can comment Once the PR is approved or has the If you have any questions, please reach out to us on Slack at https://slack.vllm.ai. Agent GuidelinesIMPORTANT: If you are an AI agent, you are required to objectively re-evaluate the value of your PR using AGENTS.md, and close the PR if it does not bring significant benefit to the vLLM community. Failure to do so may result in an immediate ban. 🚀 |
|
Documentation preview: https://vllm--64935.org.readthedocs.build/en/64935/ |
The Rust frontend does not serve /v1/chat/completions/batch. Skip the test when VLLM_USE_RUST_FRONTEND is set instead of deselecting it in the Buildkite steps. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: GCSimba <44427703+GCSimba@users.noreply.github.com>
|
Thanks! |
|
/ci run |
|
✅ Triggered Buildkite CI #99182 for commit ℹ️ This PR is 50 commits behind upstream |
|
@DarkLight1337 The only failing required check is |
|
/ci retry |
|
✅ Triggered Buildkite CI #99937 for commit |
Overview
/v1/chat/completions/batchnever setsusage.completion_tokens_details, so a server started with--reasoning-parseromitsreasoning_tokensfrom batched responses while/v1/chat/completionsreports them for the same conversation. This counts and sums them per conversation, the way the single-conversation path does. Follows #64757, which added the prompt-sideprompt_tokens_detailsto the same endpoint.Claims
--reasoning-parser,/v1/chat/completions/batchreturnsusage.completion_tokens_details.reasoning_tokenssummed across conversations, including wheninclude_reasoning=false(hidden reasoning is still generated and billed), matching/v1/chat/completions.completion_tokens_detailsstaysnull, as on/v1/chat/completions.Validation
New test
test_batch_reasoning_tokens_in_usageintests/entrypoints/openai/chat_completion/test_include_reasoning.py, throughRemoteOpenAIServerwithQwen/Qwen3-0.6B --reasoning-parser qwen3(the module's existing server). It posts two conversations withinclude_reasoning=falseand checks0 < reasoning_tokens <= completion_tokens.Before the fix (main at cfa9f96):
After the fix:
1 passed, 6 deselected.Usage for the same conversation on the same server (
max_tokens=64,temperature=0,include_reasoning=false), after the fix; before it the batchcompletion_tokens_detailsisnull:/v1/chat/completions/v1/chat/completions/batch, the conversation twiceOther checks after the fix:
test_include_reasoning.py(whole file)VLLM_USE_RUST_FRONTEND=1, the new test onlytest_batched_chat_completions.py(-kthe six non-server tests)pre-commit run --files <changed files>Environment: CPU only (Intel i5-11300H, AVX-512), Ubuntu 24.04 on WSL2, Python 3.12,
--enforce-eager. The Python sources are this branch; the compiled CPU extensions come from the nightly CPU wheel for 2b009fc (20 commits behind, differing only in CUDA kernels). Validated on cfa9f96, then rebased onto 564ac0d; the commits in between only changerecipes/models/*.yaml.Not run locally: the server tests in
test_batched_chat_completions.py(they needQwen/Qwen2.5-1.5B-Instruct, which serves without a reasoning parser, so this path only adds anullfield there), and GPU CI. No model evaluation: model outputs are unchanged; only response usage changes.Details
chat_completion_full_generator_batchbuildsUsageInfowithoutcompletion_tokens_details, and never counts reasoning tokens even though each conversation already runs through its parser.OpenAIServingChat.chat_completion_full_generator: callparser.count_reasoning_tokens(output.token_ids)afterparse, and gate the details on_include_reasoning_tokens_details. It reuses_make_completion_tokens_details.OpenAIServingChatBatchwith__new__, so they now set_include_reasoning_tokens_details = False(as [Bugfix][Frontend] Report prompt_tokens_details in batched chat completions #64757 did forenable_prompt_tokens_details), and the fake parser gainscount_reasoning_tokens./v1/chat/completions/batchasnot_supported, so the new test is skipped whenVLLM_USE_RUST_FRONTENDis set, as the Rust frontend CI steps do (same pattern astest_thinking_token_budget.py). The Python-frontend steps run it.prompt_tokens_detailsnote for this endpoint inopenai_compatible_server.md.Not a duplicate: open and closed PRs and issues searched for "batch reasoning tokens", "completions/batch usage", "batched chat completions usage", "reasoning_tokens",
OpenAIServingChatBatchandbatch_serving. Related but different: #64757 (merged, prompt-side details only), #64041 (reasoning tokens on the derender endpoints), #58010 (hiding reasoning metadata in batch responses).AI assistance (GitHub Copilot) was used to find the bug, write the change and tests, and run the validation; I reviewed every changed line and the test results.
Pull Request Checklist
I used vLLM's
/pr-checklistskill. (Mandatory for agents, optional for humans).AI assistance was used during the creation of this PR.
Design Fit: Minimizes impact on core components, reuses existing functionality, and justifies added complexity.
Testing and Validation: Validates the change and ensures any added tests are meaningful and reliable, with CI coverage or documented CI resource constraints and validation performed outside CI.
Code Quality and Style: Keeps code and comments clear and concise, and updates relevant documentation and examples.
Pull Request Contents: Includes a brief summary and relevant links, supports claims with evidence, explains root causes and implementation trade-offs, and follows the contributing guide.