[None][fix] Fix GPT-OSS router token identity#16760
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (7)
🚧 Files skipped from review as they are similar to previous changes (3)
WalkthroughChat request tokenization is centralized for Harmony and tokenizer-template paths. OpenAI server handling and router block hashing use shared helpers, with model-type, explicit, and environment-based Harmony selection. Router configuration now propagates model paths, and tests cover token parity, gating, errors, and template arguments. ChangesServing chat tokenization
Estimated code review effort: 4 (Complex) | ~45 minutes Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant ChatCompletionRequest
participant BlockHashMixin
participant tokenize_chat_request_for_serving
participant HarmonyAdapter
participant tokenizer.apply_chat_template
BlockHashMixin->>tokenize_chat_request_for_serving: tokenize request with model-type resolver
alt Harmony selected
tokenize_chat_request_for_serving->>HarmonyAdapter: convert messages and tools
HarmonyAdapter-->>tokenize_chat_request_for_serving: return token IDs
else Harmony disabled or non-Harmony model
tokenize_chat_request_for_serving->>tokenizer.apply_chat_template: render messages, tools, documents, and template
tokenizer.apply_chat_template-->>tokenize_chat_request_for_serving: return rendered text or token IDs
end
tokenize_chat_request_for_serving-->>BlockHashMixin: return and store prompt token IDs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
tensorrt_llm/serve/chat_tokenization.py (2)
19-19: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valuePrefer
collections.abc.Callableovertyping.Callable.
Callableis imported fromtyping; PEP 585 deprecatedtyping.Callablein favor ofcollections.abc.Callable, which this repo's target Python (3.10+) supports natively.As per coding guidelines, "prefer built-in generic types and |, use precise Callable types."
♻️ Proposed fix
-from typing import TYPE_CHECKING, Callable, Optional, cast +from collections.abc import Callable +from typing import TYPE_CHECKING, Optional, cast🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tensorrt_llm/serve/chat_tokenization.py` at line 19, Replace the Callable import from typing with collections.abc.Callable in chat_tokenization.py, while retaining the other typing imports and existing precise Callable annotations unchanged.Source: Coding guidelines
29-158: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winNo dedicated unit tests for this new shared module.
infer_model_type_from_name,uses_harmony_tokenization's precedence rules (env gate > explicituse_harmony> inferred model type), andget_chat_completion_tool_dicts's type-branching are only exercised indirectly throughtest_router.py. Since this module now determines token identity for both the router and the server, direct unit tests would make regressions easier to catch.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tensorrt_llm/serve/chat_tokenization.py` around lines 29 - 158, add dedicated unit tests for infer_model_type_from_name, uses_harmony_tokenization, and get_chat_completion_tool_dicts. Cover model-name normalization and non-matches, precedence of DISABLE_HARMONY_ADAPTER over explicit use_harmony over inferred model type, and each supported tool representation plus unsupported types; keep existing router coverage unchanged.tests/unittest/disaggregated/test_router.py (1)
1865-2013: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a ConversationRouter Harmony-path assertion
test_gpt_oss_router_tokens_match_chat_harmony_server_input(new),test_gpt_oss_router_respects_disable_harmony_adapter(new), andtest_tokenize_forwards_tools_and_chat_template_kwargs(modified) are listed intests/integration/test_lists/test-db/l0_a10.ymlandtests/integration/test_lists/test-db/l0_h100.yml.- The Harmony-specific checks only cover
KvCacheAwareRouter;ConversationRouteris only covered by the shared token-forwarding test, so add a Harmony-path case ifuse_harmonyshould behave the same there.- Coverage verdict: insufficient.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/unittest/disaggregated/test_router.py` around lines 1865 - 2013, Add a ConversationRouter-specific test covering the Harmony tokenization path, mirroring test_gpt_oss_router_tokens_match_chat_harmony_server_input. Verify ConversationRouter._tokenize produces the same Harmony token IDs as the server path and forwards the expected request inputs, while preserving the existing KvCacheAwareRouter coverage.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tensorrt_llm/serve/openai_server.py`:
- Around line 2045-2055: Update the exception diagnostics around
tokenize_harmony_chat_request so recomputing get_chat_completion_tool_dicts
cannot interrupt handling of the original exception. Guard the tools_dict
diagnostic computation separately, ensure the request log still executes, and
preserve the original exception via the existing re-raise.
---
Nitpick comments:
In `@tensorrt_llm/serve/chat_tokenization.py`:
- Line 19: Replace the Callable import from typing with collections.abc.Callable
in chat_tokenization.py, while retaining the other typing imports and existing
precise Callable annotations unchanged.
- Around line 29-158: add dedicated unit tests for infer_model_type_from_name,
uses_harmony_tokenization, and get_chat_completion_tool_dicts. Cover model-name
normalization and non-matches, precedence of DISABLE_HARMONY_ADAPTER over
explicit use_harmony over inferred model type, and each supported tool
representation plus unsupported types; keep existing router coverage unchanged.
In `@tests/unittest/disaggregated/test_router.py`:
- Around line 1865-2013: Add a ConversationRouter-specific test covering the
Harmony tokenization path, mirroring
test_gpt_oss_router_tokens_match_chat_harmony_server_input. Verify
ConversationRouter._tokenize produces the same Harmony token IDs as the server
path and forwards the expected request inputs, while preserving the existing
KvCacheAwareRouter coverage.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 14c034d7-cb1c-412f-89d0-fbc30ae7f496
📒 Files selected for processing (5)
tensorrt_llm/serve/chat_tokenization.pytensorrt_llm/serve/openai_server.pytensorrt_llm/serve/router.pytensorrt_llm/serve/router_utils.pytests/unittest/disaggregated/test_router.py
KV-cache-aware routing previously tokenized chat requests through the generic tokenizer chat template, while the OpenAI server sends GPT-OSS chat requests through the Harmony adapter. That split means the router can hash a different token sequence than the one the executor actually receives, which breaks prefix identity for routing and cache reuse decisions. Add a shared serving chat-tokenization helper so the router and server use the same Harmony request conversion for GPT-OSS while preserving the general tokenizer flow for other models. Cover router/server token parity and the DISABLE_HARMONY_ADAPTER fallback path. Signed-off-by: Simeng Liu <simengl@nvidia.com>
Signed-off-by: Simeng Liu <simengl@nvidia.com>
120165e to
aff6281
Compare
|
/bot run --disable-fail-fast |
|
PR_Github #61382 [ run ] triggered by Bot. Commit: |
|
PR_Github #61382 [ run ] completed with state
|
KV-cache-aware routing previously tokenized chat requests through the generic tokenizer chat template, while the OpenAI server sends GPT-OSS chat requests through the Harmony adapter. That split means the router can hash a different token sequence than the one the executor actually receives, which breaks prefix identity for routing and cache reuse decisions.
Add a shared serving chat-tokenization helper so the router and server use the same Harmony request conversion for GPT-OSS while preserving the general tokenizer flow for other models. Cover router/server token parity and the DISABLE_HARMONY_ADAPTER fallback path.
Dev Engineer Review
DISABLE_HARMONY_ADAPTERhandling.model_paththrough KV-cache router configuration and checkpoint-based model-type detection.QA Engineer Review
test_router_model_type_uses_checkpoint_configtest_gpt_oss_router_tokens_match_chat_harmony_server_inputtest_gpt_oss_router_respects_disable_harmony_adaptertest_chat_harmony_preserves_original_tool_conversion_errortest_extract_router_config_propagates_kv_model_pathdocumentsandchat_template.tests/integration/test_lists/test-db or QA files.Description
Test Coverage
disaggregated/test_router.py::test_gpt_oss_router_tokens_match_chat_harmony_server_input
disaggregated/test_router.py::test_gpt_oss_router_respects_disable_harmony_adapter
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)
If PR introduces API changes, an appropriate PR label is added - either
api-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin the PR title.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.