[None][feat] Support tool-calling in KvCacheAwareRouter for disagg serving (feat/deepseek_v4)#14611
Merged
lfr-0531 merged 1 commit intoMay 28, 2026
Conversation
…rving KvCacheAwareRouter._tokenize pre-tokenizes ChatCompletionRequests to compute block hashes for cache-aware routing and sets request.prompt_token_ids so the worker skips re-tokenization. The current implementation only forwards 'messages' to tokenizer.apply_chat_template, ignoring 'tools' and chat_template_kwargs. For models whose chat templates render tools into the prompt (DeepSeek-V3.2 inlines a tool-schema system block via its custom template), this silently drops the whole tool block from the final prompt. Tool-calling requests are then run against a prompt that never saw the tools, which both degrades tool-use behavior and produces incorrect cache-aware routing decisions because block hashes are computed over a truncated prompt. Forward request.tools (unwrapped via model_dump) and request.chat_template_kwargs to apply_chat_template so router-side pre-tokenization matches what the worker would have produced. Signed-off-by: Shicheng Li <shicli@nvidia.com>
reasonsolo
approved these changes
May 27, 2026
Collaborator
Author
|
/bot run --add-multi-gpu-test |
Collaborator
|
PR_Github #50446 [ run ] triggered by Bot. Commit: |
Collaborator
|
PR_Github #50446 [ run ] completed with state
|
Collaborator
Author
|
/bot run --disable-fail-fast |
Collaborator
|
PR_Github #50566 [ run ] triggered by Bot. Commit: |
Collaborator
|
PR_Github #50566 [ run ] completed with state |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Cherry-pick of #13232 onto
feat/deepseek_v4.KvCacheAwareRouter._tokenizepre-tokenizesChatCompletionRequests to compute routing block-hashes, and setsrequest.prompt_token_idsso the worker server skips re-tokenization. Today it only forwardsrequest.messagestoapply_chat_template, ignoringrequest.toolsandrequest.chat_template_kwargs.For models whose chat templates materialize tools into the prompt (DeepSeek-V3.2 inlines a tool-schema system block via its custom template), this silently drops the entire tool block from the final prompt — even though the client provided
toolsin the API request. Tool-calling requests are then run against a prompt that never saw the tools, which both degrades tool-use behavior and produces incorrect cache-aware routing decisions (block hashes computed over a truncated prompt).Change
Forward
request.tools(unwrapped viamodel_dump()) andrequest.chat_template_kwargsintoapply_chat_template, so router-side pre-tokenization produces the same prompt token IDs the worker would have produced on its own — tools and template flags included. No behavior change for requests withouttoolsorchat_template_kwargs.Test Coverage
Reproduced on DeepSeek-V3.2 1P1D (DEP8 CTX + TEP8 GEN) with an agentic coding benchmark (12 tools per request,
chat_template_kwargs={"thinking": true}):PR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (see test instructions)
Any new dependencies have been scanned for license and vulnerabilities
CODEOWNERS updated if ownership changes
Documentation updated as needed
Update tava architecture diagram if there is a significant design change in PR.
The reviewers assigned automatically/manually are appropriate for the PR.
Please check this after reviewing the above items as appropriate for this PR.
GitHub Bot Help
To see a list of available CI bot commands, please comment
/bot help.