-
-
Notifications
You must be signed in to change notification settings - Fork 22.3k
[Bugfix] Gracefully handle unsupported reasoning_effort in chat templates #54022
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ | |
| 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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should try to extract the reason for the error if possible, instead of just copying the whole error message
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
OK,Good point. Two things:
|
||
| # `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)}" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.