-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
[Frontend] Expand tools even if tool_choice="none" #17177
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 10 commits
ba347cd
5b1b5e7
38eea42
bc031d9
b5e4164
e3733a9
1ffd7f0
e282ebb
b51c7b9
0a0920a
90eabb2
8a45fa8
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 |
---|---|---|
|
@@ -62,6 +62,7 @@ def __init__( | |
return_tokens_as_token_ids: bool = False, | ||
reasoning_parser: str = "", | ||
enable_auto_tools: bool = False, | ||
expand_tools_even_if_tool_choice_none: bool = False, | ||
tool_parser: Optional[str] = None, | ||
enable_prompt_tokens_details: bool = False, | ||
) -> None: | ||
|
@@ -108,6 +109,8 @@ def __init__( | |
raise TypeError("Error: --enable-auto-tool-choice requires " | ||
f"tool_parser:'{tool_parser}' which has not " | ||
"been registered") from e | ||
self.expand_tools_even_if_tool_choice_none = ( | ||
expand_tools_even_if_tool_choice_none) | ||
|
||
self.enable_prompt_tokens_details = enable_prompt_tokens_details | ||
self.default_sampling_params = ( | ||
|
@@ -172,9 +175,25 @@ async def create_chat_completion( | |
"--enable-auto-tool-choice and --tool-call-parser to be set" | ||
) | ||
|
||
tool_dicts = None if request.tools is None else [ | ||
tool.model_dump() for tool in request.tools | ||
] | ||
if request.tools is None: | ||
tool_dicts = None | ||
elif (request.tool_choice == "none" | ||
and not self.expand_tools_even_if_tool_choice_none): | ||
assert request.tools is not None | ||
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. Let's not use assert in performance path here, if this is mostly for types the we can gate it in 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. @aarnphm Thanks for the review! I understand the performance concern, but I'd like to keep the assert here for a specific reason. This assert serves as a defensive programming guard rather than just type checking. The logic is:
The assert ensures that if someone modifies the first condition in the future (e.g., adds another OR condition), we'll catch the logic error immediately with a clear AssertionError, rather than getting a confusing While I understand the performance concern, in the context of vLLM's request processing pipeline, this single assertion check is dwarfed by the actual bottlenecks like model inference, GPU operations, and network I/O. The cost of one conditional check per request is negligible compared to the milliseconds/seconds spent on actual LLM processing. Given that trade-off, I think the defensive programming benefit outweighs the minimal performance cost. What do you think? 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. @aarnphm You're absolutely right. Looking at this again, adding TYPE_CHECKING import just for this assert would be overkill, and the assert itself isn't really necessary here. Let me remove it and keep the code simple. Thanks for the guidance! |
||
if len(request.tools) > 0: | ||
logger.warning( | ||
okdshin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"Tools are specified but tool_choice is set to 'none' " | ||
"and --expand-tools-even-if-tool-choice-none is not " | ||
"enabled. Tool definitions will be excluded from the " | ||
"prompt. This behavior will change in vLLM v0.10 where " | ||
"tool definitions will be included by default even " | ||
"with tool_choice='none'. To adopt the new behavior " | ||
"now, use --expand-tools-even-if-tool-choice-none. " | ||
"To suppress this warning, either remove tools from " | ||
"the request or set tool_choice to a different value.") | ||
tool_dicts = None | ||
else: | ||
tool_dicts = [tool.model_dump() for tool in request.tools] | ||
|
||
( | ||
conversation, | ||
|
Uh oh!
There was an error while loading. Please reload this page.