[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:
co-authored by
mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent
5d09f471f4
commit
739af5c7e1
+35
-1
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user