[Bugfix] Gracefully handle unsupported reasoning_effort in chat templates (#54022)
Signed-off-by: frankie <wangyongsheng686@gmail.com> Co-authored-by: Trae Agent <noreply@trae.ai>
This commit is contained in:
+20
-4
@@ -27,6 +27,7 @@ from vllm.entrypoints.chat_utils import (
|
||||
parse_chat_messages,
|
||||
parse_chat_messages_async,
|
||||
)
|
||||
from vllm.exceptions import VLLMValidationError
|
||||
from vllm.inputs import EmbedsPrompt
|
||||
from vllm.inputs.engine import MultiModalInput
|
||||
from vllm.logger import init_logger
|
||||
@@ -684,6 +685,18 @@ def resolve_chat_template_kwargs(
|
||||
return {k: v for k, v in chat_template_kwargs.items() if k in accept_vars}
|
||||
|
||||
|
||||
def _template_error_reason(exc: BaseException) -> str:
|
||||
# Extract the most specific reason from a chat template error chain.
|
||||
seen: set[int] = set()
|
||||
current: BaseException | None = exc
|
||||
while current is not None and id(current) not in seen:
|
||||
seen.add(id(current))
|
||||
if isinstance(current, jinja2.TemplateError):
|
||||
return str(current)
|
||||
current = current.__cause__ or current.__context__
|
||||
return str(exc)
|
||||
|
||||
|
||||
@overload
|
||||
def safe_apply_chat_template(
|
||||
model_config: ModelConfig,
|
||||
@@ -806,10 +819,13 @@ def safe_apply_chat_template(
|
||||
**resolved_kwargs,
|
||||
)
|
||||
except Exception as e:
|
||||
logger.exception(
|
||||
"An error occurred in `transformers` while applying chat template"
|
||||
)
|
||||
raise ValueError(str(e)) from e
|
||||
# Chat templates reject invalid user input (e.g. an unsupported
|
||||
# `reasoning_effort` value) by raising from within the template.
|
||||
# Surface those as a 400 Bad Request carrying the template's own
|
||||
# reason (which typically lists the supported values) instead of a
|
||||
# 500 or any generic upstream wrapper message.
|
||||
logger.warning("Chat template rejected the request: %s", e)
|
||||
raise VLLMValidationError(_template_error_reason(e)) from e
|
||||
|
||||
if return_assistant_tokens_mask:
|
||||
assert isinstance(plain, list), f"Expected list[int], got {type(plain)}"
|
||||
|
||||
Reference in New Issue
Block a user