Skip to content

[Bugfix] Fix inverted condition causing thinking_token_budget to be silently ignored - #41674

Merged
DarkLight1337 merged 9 commits into
vllm-project:mainfrom
JasonKeyiL:fix/thinking-token-budget-inverted-condition
May 15, 2026
Merged

[Bugfix] Fix inverted condition causing thinking_token_budget to be silently ignored#41674
DarkLight1337 merged 9 commits into
vllm-project:mainfrom
JasonKeyiL:fix/thinking-token-budget-inverted-condition

Conversation

@JasonKeyiL

@JasonKeyiL JasonKeyiL commented May 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #41672.

Root cause: an inverted boolean condition (or not thinking_budget_tracks_reqs instead of or thinking_budget_tracks_reqs) in gpu_input_batch.py. The condition is logically backwards: it sets needs_output_token_ids = True when there are no budget-tracking requests, and fails to contribute True when there are budget-tracking requests.

In practice the bug is currently masked — self.logitsprocs_need_output_token_ids is set to True at init whenever reasoning_config is not None (introduced in the same commit), so output_token_ids is never empty and the budget works correctly end-to-end. The fix corrects the latent logical error and removes the unnecessary population of output_token_ids when no budget-tracking requests are in the batch.

Fix: remove the erroneous not (single-token change in gpu_input_batch.py).

Changes

  • vllm/v1/worker/gpu_input_batch.py: remove not from or not thinking_budget_tracks_reqs
  • tests/v1/logits_processors/test_correctness.py: add regression test test_thinking_budget_enforced_without_penalties that directly exercises ThinkingBudgetStateHolder with an empty vs. live output_token_ids list, verifying in_end is raised after the budget is exhausted

Test commands run

pre-commit run ruff-check --files vllm/v1/worker/gpu_input_batch.py tests/v1/logits_processors/test_correctness.py
pre-commit run ruff-format --files vllm/v1/worker/gpu_input_batch.py tests/v1/logits_processors/test_correctness.py

.venv/bin/python -m pytest tests/v1/logits_processors/test_correctness.py::test_thinking_budget_enforced_without_penalties -v
# PASSED

…g_token_budget to be silently ignored

When a request uses `thinking_token_budget` but has no penalty/bad-words settings
(the common case), the previous code computed `needs_output_token_ids = False`
due to an inverted boolean condition (`or not thinking_budget_tracks_reqs` instead
of `or thinking_budget_tracks_reqs`).

This caused `SamplingMetadata.output_token_ids` to be an empty list, so every call
to `ThinkingBudgetStateHolder.update_state()` saw `seq_idx >= len([]) == 0` for
all requests and skipped `_update_think_state()` entirely.  As a result `in_end`
was never set to `True`, `apply_to_logits()` never forced the end token, and the
`thinking_token_budget` parameter had no effect.

Fix: remove the erroneous `not` so that output_token_ids is populated whenever the
thinking-budget state holder has any tracked requests.

Regression test added in test_correctness.py that exercises
ThinkingBudgetStateHolder directly, demonstrating the empty-list failure path and
verifying the corrected live-list path raises `in_end` after the budget is
exhausted.

Co-authored-by: Claude
Signed-off-by: JasonKeyiL <likey6688@gmail.com>

Signed-off-by: Keyi Li <likey6688@gmail.com>
@JasonKeyiL
JasonKeyiL requested a review from njhill as a code owner May 4, 2026 22:28

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@mergify mergify Bot added v1 bug Something isn't working labels May 4, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request fixes a bug in gpu_input_batch.py where the thinking budget was not being enforced when no penalties or bad words were set. The logic for determining if output token IDs are needed was corrected by removing an incorrect negation, ensuring the thinking budget state holder receives the necessary data. Additionally, a regression test was added to verify that the budget is correctly enforced under these conditions. I have no feedback to provide.

@JasonKeyiL

Copy link
Copy Markdown
Contributor Author

Hi @njhill , could you please add the 'verified' label so CI can run? Thanks!

@@ -883,7 +876,7 @@ def _make_sampling_metadata(self) -> SamplingMetadata:
not self.no_penalties
or bool(self.bad_words_token_ids)
or self.logitsprocs_need_output_token_ids

@rishitdholakia13 rishitdholakia13 May 6, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @JasonKeyiL , Thanks for catching this and for the fix. I was wondering: with reasoning mode on, ReasoningConfig is not None, so I’d expect self.logitsprocs_need_output_token_ids to be set, since that was verified with the E2E test as well. How did we end up with thinking_budget_tracks_reqs being set to True while self.logitsprocs_need_output_token_ids was False?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reply and follow up! @rishitdholakia13
sorry I missed it, you are right, self.logitsprocs_need_output_token_ids is already True at first whenever reasoning_config is not None, output_token_ids shouldn't be empty in practice
but isn't the or not thinking_budget_tracks_reqs logically inverted? but given it's masked, is it worth fixing or should I close this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, definitely we can merge this fix.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, Hi @njhill Nick, would you be able to take a look and put a verify label? thanks!

@njhill njhill added the ready ONLY add when PR is ready to merge/full CI is needed label May 6, 2026
@njhill
njhill enabled auto-merge (squash) May 6, 2026 19:50
auto-merge was automatically disabled May 7, 2026 00:36

Head branch was pushed to by a user without write access

@JasonKeyiL

Copy link
Copy Markdown
Contributor Author

@njhill looks like a globe infra issue, CI failed with pytorch-compilation-unit-tests, pytorch-fullgraph-smoke-test, 3 times, could you manually merge it when you get a chance? Thanks you!

@JasonKeyiL
JasonKeyiL requested a review from njhill May 13, 2026 03:40
@DarkLight1337
DarkLight1337 merged commit bf610c2 into vllm-project:main May 15, 2026
59 checks passed
omerpaz95 pushed a commit to omerpaz95/vllm that referenced this pull request May 18, 2026
…ilently ignored (vllm-project#41674)

Signed-off-by: Keyi Li <likey6688@gmail.com>
Co-authored-by: Keyi Li <likey6688@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
omerpaz95 pushed a commit to omerpaz95/vllm that referenced this pull request May 18, 2026
…ilently ignored (vllm-project#41674)

Signed-off-by: Keyi Li <likey6688@gmail.com>
Co-authored-by: Keyi Li <likey6688@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
mfylcek pushed a commit to mfylcek/vllm that referenced this pull request May 19, 2026
…ilently ignored (vllm-project#41674)

Signed-off-by: Keyi Li <likey6688@gmail.com>
Co-authored-by: Keyi Li <likey6688@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
jhu960213 pushed a commit to jhu960213/vllm that referenced this pull request May 20, 2026
…ilently ignored (vllm-project#41674)

Signed-off-by: Keyi Li <likey6688@gmail.com>
Co-authored-by: Keyi Li <likey6688@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
h1t35h pushed a commit to h1t35h/vllm that referenced this pull request May 21, 2026
…ilently ignored (vllm-project#41674)

Signed-off-by: Keyi Li <likey6688@gmail.com>
Co-authored-by: Keyi Li <likey6688@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Liuweixiong0118 pushed a commit to Liuweixiong0118/vllm that referenced this pull request Jun 1, 2026
…ilently ignored (vllm-project#41674)

Signed-off-by: Keyi Li <likey6688@gmail.com>
Co-authored-by: Keyi Li <likey6688@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Signed-off-by: Liuweixiong0118 <lwx34158427@gmail.com>
mvanhorn pushed a commit to mvanhorn/vllm that referenced this pull request Jun 4, 2026
…ilently ignored (vllm-project#41674)

Signed-off-by: Keyi Li <likey6688@gmail.com>
Co-authored-by: Keyi Li <likey6688@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
andakai pushed a commit to andakai/vllm that referenced this pull request Jun 4, 2026
…ilently ignored (vllm-project#41674)

Signed-off-by: Keyi Li <likey6688@gmail.com>
Co-authored-by: Keyi Li <likey6688@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
knight0528 pushed a commit to knight0528/vllm that referenced this pull request Jun 8, 2026
…ilently ignored (vllm-project#41674)

Signed-off-by: Keyi Li <likey6688@gmail.com>
Co-authored-by: Keyi Li <likey6688@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
MingqiWang-coder added a commit to vLLM-HUST/vllm-hust that referenced this pull request Jun 30, 2026
Cherry-pick 62 bugfix/security PRs from upstream vllm-project/vllm main
(2026-05-03 to 2026-06-17), covering scheduler, engine core, model runner,
worker, attention, KV cache, compilation, and structured output fixes.

Security (4): vllm-project#43286 vllm-project#44744 vllm-project#45118 vllm-project#45252
Bugfix (56): vllm-project#35536 vllm-project#36616 vllm-project#38895 vllm-project#39155 vllm-project#39324 vllm-project#39562 vllm-project#39805 vllm-project#40398 vllm-project#40726
vllm-project#40727 vllm-project#40737 vllm-project#40749 vllm-project#40961 vllm-project#41119 vllm-project#41133 vllm-project#41233 vllm-project#41237 vllm-project#41411 vllm-project#41496 vllm-project#41549
vllm-project#41674 vllm-project#41873 vllm-project#41895 vllm-project#42040 vllm-project#42112 vllm-project#42289 vllm-project#42479 vllm-project#42585 vllm-project#42692 vllm-project#42706 vllm-project#42709
vllm-project#42739 vllm-project#42967 vllm-project#43001 vllm-project#43079 vllm-project#43125 vllm-project#43160 vllm-project#43616 vllm-project#43669 vllm-project#43719 vllm-project#43768 vllm-project#43808
vllm-project#43961 vllm-project#43982 vllm-project#43988 vllm-project#43998 vllm-project#44057 vllm-project#44560 vllm-project#44574 vllm-project#44568 vllm-project#44603 vllm-project#44744 vllm-project#45195
vllm-project#45345 vllm-project#45383 vllm-project#45487 vllm-project#45564 vllm-project#45673
Runner fix (2): vllm-project#44568 vllm-project#44603

Skipped: vllm-project#43781 (ROCm-specific, not applicable to Ascend NPU)

Conflict resolutions:
- Manual merge: vllm-project#43286 vllm-project#45118 vllm-project#42112 vllm-project#43160 vllm-project#43719 vllm-project#44560
- Upstream-preferred (-X theirs): vllm-project#43808 vllm-project#43988 vllm-project#42967 vllm-project#35536 vllm-project#45195
- Test files (--theirs): vllm-project#44744 vllm-project#41895 vllm-project#42040 vllm-project#41233 vllm-project#45345 vllm-project#43982

Co-authored-by: GitHub Copilot
Signed-off-by: MingqiWang-coder <mingqiwang@hust.edu.cn>
MingqiWang-coder added a commit to vLLM-HUST/vllm-hust that referenced this pull request Jun 30, 2026
Cherry-pick 62 bugfix/security PRs from upstream vllm-project/vllm main
(2026-05-03 to 2026-06-17), covering scheduler, engine core, model runner,
worker, attention, KV cache, compilation, and structured output fixes.

Security (4): vllm-project#43286 vllm-project#44744 vllm-project#45118 vllm-project#45252
Bugfix (56): vllm-project#35536 vllm-project#36616 vllm-project#38895 vllm-project#39155 vllm-project#39324 vllm-project#39562 vllm-project#39805 vllm-project#40398 vllm-project#40726
vllm-project#40727 vllm-project#40737 vllm-project#40749 vllm-project#40961 vllm-project#41119 vllm-project#41133 vllm-project#41233 vllm-project#41237 vllm-project#41411 vllm-project#41496 vllm-project#41549
vllm-project#41674 vllm-project#41873 vllm-project#41895 vllm-project#42040 vllm-project#42112 vllm-project#42289 vllm-project#42479 vllm-project#42585 vllm-project#42692 vllm-project#42706 vllm-project#42709
vllm-project#42739 vllm-project#42967 vllm-project#43001 vllm-project#43079 vllm-project#43125 vllm-project#43160 vllm-project#43616 vllm-project#43669 vllm-project#43719 vllm-project#43768 vllm-project#43808
vllm-project#43961 vllm-project#43982 vllm-project#43988 vllm-project#43998 vllm-project#44057 vllm-project#44560 vllm-project#44574 vllm-project#44568 vllm-project#44603 vllm-project#44744 vllm-project#45195
vllm-project#45345 vllm-project#45383 vllm-project#45487 vllm-project#45564 vllm-project#45673
Runner fix (2): vllm-project#44568 vllm-project#44603

Skipped: vllm-project#43781 (ROCm-specific, not applicable to Ascend NPU)

Conflict resolutions:
- Manual merge: vllm-project#43286 vllm-project#45118 vllm-project#42112 vllm-project#43160 vllm-project#43719 vllm-project#44560
- Upstream-preferred (-X theirs): vllm-project#43808 vllm-project#43988 vllm-project#42967 vllm-project#35536 vllm-project#45195
- Test files (--theirs): vllm-project#44744 vllm-project#41895 vllm-project#42040 vllm-project#41233 vllm-project#45345 vllm-project#43982

Co-authored-by: GitHub Copilot
Signed-off-by: MingqiWang-coder <mingqiwang@hust.edu.cn>
philippesic pushed a commit to philippesic/vllm-semantic-cache that referenced this pull request Jul 19, 2026
…ilently ignored (vllm-project#41674)

Signed-off-by: Keyi Li <likey6688@gmail.com>
Co-authored-by: Keyi Li <likey6688@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
plasticchris pushed a commit to plasticchris/vllm that referenced this pull request Jul 20, 2026
…ilently ignored (vllm-project#41674)

Signed-off-by: Keyi Li <likey6688@gmail.com>
Co-authored-by: Keyi Li <likey6688@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ready ONLY add when PR is ready to merge/full CI is needed v1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: thinking_token_budget silently ignored when no penalties are set (inverted condition in gpu_input_batch.py)

4 participants