[Reasoning] [Bugfix] Reject invalid thinking_token_budget values (#43402)

Signed-off-by: linzm1007 <linzm1007@126.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
linzm1007
2026-05-26 03:37:30 -07:00
committed by GitHub
co-authored by mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent 5d09f471f4
commit 739af5c7e1
5 changed files with 152 additions and 5 deletions
@@ -41,6 +41,7 @@ from vllm.sampling_params import (
RequestOutputKind,
SamplingParams,
StructuredOutputsParams,
ThinkingTokenBudget,
)
from vllm.utils import random_uuid
@@ -225,7 +226,7 @@ class ChatCompletionRequest(OpenAIBaseModel):
"part of the standard OpenAI API specification."
),
)
thinking_token_budget: int | None = None
thinking_token_budget: ThinkingTokenBudget = None
include_reasoning: bool = True
parallel_tool_calls: bool | None = True
@@ -29,6 +29,7 @@ from vllm.sampling_params import (
RequestOutputKind,
SamplingParams,
StructuredOutputsParams,
ThinkingTokenBudget,
)
from vllm.utils import random_uuid
@@ -185,11 +186,12 @@ class CompletionRequest(OpenAIBaseModel):
"can detect such behavior and terminate early, saving time and tokens.",
)
thinking_token_budget: int | None = Field(
thinking_token_budget: ThinkingTokenBudget = Field(
default=None,
description=(
"Maximum number of tokens allowed for thinking operations "
"(reasoning models). -1 = unlimited."
"(reasoning models). Non-negative integer sets the limit; "
"-1 means unlimited (treated as unset)."
),
)
+35 -1
View File
@@ -7,9 +7,10 @@ import json as json_mod
from dataclasses import field
from enum import Enum, IntEnum
from functools import cached_property
from typing import Any
from typing import Annotated, Any
import msgspec
from pydantic import BeforeValidator
from pydantic.dataclasses import dataclass
import vllm.envs as envs
@@ -30,6 +31,35 @@ MAX_LOGPROB_TOKEN_IDS = 128
the per-request row width allocated by the sampler's `LogprobTokenIdsState`."""
def validate_thinking_token_budget(value: int | float | bool | None) -> int | None:
"""Validate ``thinking_token_budget``; return ``None`` if unset."""
if value is None:
return None
if isinstance(value, (bool, float)) or not isinstance(value, int):
raise VLLMValidationError(
"`thinking_token_budget` must be a non-negative integer "
"or -1 for unlimited.",
parameter="thinking_token_budget",
value=value,
)
if value == -1:
return None
if value < 0:
raise VLLMValidationError(
"`thinking_token_budget` must be a non-negative integer "
"or -1 for unlimited.",
parameter="thinking_token_budget",
value=value,
)
return value
ThinkingTokenBudget = Annotated[
int | None,
BeforeValidator(validate_thinking_token_budget),
]
class SamplingType(IntEnum):
GREEDY = 0
RANDOM = 1
@@ -409,6 +439,10 @@ class SamplingParams(
if self.seed == -1:
self.seed = None
self.thinking_token_budget = validate_thinking_token_budget(
self.thinking_token_budget
)
if self.stop is None:
self.stop = []
elif isinstance(self.stop, str):