-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat: Support deployment-level thinking defaults for chat templates #11047
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -22,6 +22,8 @@ | |
| from vllm.tool_parsers import ToolParser | ||
| from vllm.utils.async_utils import AsyncMicrobatchTokenizer | ||
|
|
||
| from .thinking import apply_default_thinking_mode_to_template_kwargs | ||
|
|
||
|
|
||
| class _Renderer(Protocol): | ||
| """Structural type for vLLM's chat-template renderer.""" | ||
|
|
@@ -90,6 +92,7 @@ def _prepare_request( | |
| tool_parser_class: type[ToolParser] | None, | ||
| exclude_tools_when_tool_choice_none: bool = True, | ||
| enable_auto_tool_choice: bool = False, | ||
| default_thinking_mode: str | None = None, | ||
| ) -> tuple[ChatCompletionRequest, ToolParser | None, dict[str, Any], Any, ChatParams]: | ||
| """Validate request and build arguments for template rendering. | ||
|
|
||
|
|
@@ -134,6 +137,11 @@ def _prepare_request( | |
| else None | ||
| ) | ||
| chat_template_kwargs = dict(request_for_sampling.chat_template_kwargs or {}) | ||
| chat_template_kwargs = apply_default_thinking_mode_to_template_kwargs( | ||
| chat_template_kwargs, | ||
| default_thinking_mode, | ||
| request_has_root_thinking=(isinstance(request, dict) and "thinking" in request), | ||
| ) | ||
| chat_template_kwargs["reasoning_effort"] = request_for_sampling.reasoning_effort | ||
|
Comment on lines
+140
to
145
Contributor
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. 🚩 Behavioral difference between SGLang and vLLM/Rust in how reasoning_effort interacts with default_thinking_mode In the SGLang path, In the vLLM path ( This is likely intentional — SGLang normalizes OpenAI thinking controls into template flags, while vLLM/Rust let the template interpret Was this helpful? React with 👍 or 👎 to provide feedback. |
||
|
|
||
| # Mistral warns that tokenize=False is unsafe for chat templates. | ||
|
|
@@ -178,6 +186,7 @@ async def preprocess_chat_request( | |
| tool_parser_class: type[ToolParser] | None, | ||
| exclude_tools_when_tool_choice_none: bool = True, | ||
| enable_auto_tool_choice: bool = False, | ||
| default_thinking_mode: str | None = None, | ||
| ) -> PreprocessResult: | ||
| ( | ||
| request_for_sampling, | ||
|
|
@@ -191,6 +200,7 @@ async def preprocess_chat_request( | |
| tool_parser_class=tool_parser_class, | ||
| exclude_tools_when_tool_choice_none=exclude_tools_when_tool_choice_none, | ||
| enable_auto_tool_choice=enable_auto_tool_choice, | ||
| default_thinking_mode=default_thinking_mode, | ||
| ) | ||
|
|
||
| _, engine_prompt = await renderer.render_messages_async(messages, chat_params) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Keep
WorkerConfigappend-only.Line 120 inserts
default_thinking_modebefore existing optional fields, but this class already documents that new fields must be appended to preserve positional callers. Any positionalWorkerConfig(...)call that usedexclude_tools_when_tool_choice_noneor anything after it will now silently bind the wrong values.Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents