[TRTLLM-12520][perf] Reduce host overhead during scheduling and sampling#13843
Conversation
📝 WalkthroughWalkthroughThis PR migrates beam-width accesses across five pyexecutor modules from direct ChangesUnified Beam Width Property Migration
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tensorrt_llm/_torch/pyexecutor/llm_request.py (1)
691-691: 💤 Low valueConsider
int()instead ofcast()to guarantee a Python-nativeintat runtime.
typing.castis a type-checker annotation that is a no-op at runtime — it does not convert the value. All otherpy_*cached attributes (e.g.,py_min_length,py_prompt_len) use plain assignment withoutcast. pybind11 ordinarily maps C++ integral types to Pythonint, so this works in practice, but the inconsistency is worth noting. If the binding ever returns a pybind11 integer wrapper instead of a Pythonint, downstream code usingpy_beam_widthin arithmetic orisinstancechecks could see unexpected behaviour.Using
int(self.sampling_config.beam_width)is a one-character change, guarantees a true Pythonint, is self-documenting, and is consistent with how other cached scalar attributes are written in this class.♻️ Suggested alternative
- self.py_beam_width = cast(int, self.sampling_config.beam_width) + self.py_beam_width: int = int(self.sampling_config.beam_width)🤖 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/_torch/pyexecutor/llm_request.py` at line 691, The cached attribute py_beam_width is using typing.cast which is a no-op at runtime; replace the cast usage with an actual conversion by assigning py_beam_width = int(self.sampling_config.beam_width) so it becomes a native Python int at runtime (mirror how other cached scalars like py_min_length are set) — update the assignment in the llm_request class where py_beam_width is initialized to use int(...) instead of cast(int, ...).
🤖 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.
Nitpick comments:
In `@tensorrt_llm/_torch/pyexecutor/llm_request.py`:
- Line 691: The cached attribute py_beam_width is using typing.cast which is a
no-op at runtime; replace the cast usage with an actual conversion by assigning
py_beam_width = int(self.sampling_config.beam_width) so it becomes a native
Python int at runtime (mirror how other cached scalars like py_min_length are
set) — update the assignment in the llm_request class where py_beam_width is
initialized to use int(...) instead of cast(int, ...).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 4d866904-c5e6-4599-954b-9dec27767e40
📒 Files selected for processing (5)
tensorrt_llm/_torch/pyexecutor/llm_request.pytensorrt_llm/_torch/pyexecutor/model_engine.pytensorrt_llm/_torch/pyexecutor/py_executor.pytensorrt_llm/_torch/pyexecutor/resource_manager.pytensorrt_llm/_torch/pyexecutor/sampler.py
|
/bot run |
|
PR_Github #47295 [ run ] triggered by Bot. Commit: |
|
PR_Github #47295 [ run ] completed with state
|
|
/bot run |
|
PR_Github #47361 [ run ] triggered by Bot. Commit: |
|
PR_Github #47361 [ run ] completed with state |
d220f6b to
04e21ea
Compare
|
/bot run |
|
PR_Github #48084 [ run ] triggered by Bot. Commit: |
eopXD
left a comment
There was a problem hiding this comment.
The caching at Python level will fail silently if setBeamWidth is called and you have already cached it here. Push this caching to C++ level will fool-proof this and prevent us from a silent bug.
Are we calling TensorRT-LLM/tensorrt_llm/_torch/pyexecutor/llm_request.py Lines 630 to 740 in 04e21ea |
|
PR_Github #48084 [ run ] completed with state
|
|
/bot run |
|
PR_Github #48122 [ run ] triggered by Bot. Commit: |
|
PR_Github #48122 [ run ] completed with state
|
Signed-off-by: Yuan Tong <[email protected]>
04e21ea to
6fe4c73
Compare
|
/bot run --disable-fail-fast |
👎 Promotion blocked, new vulnerability foundVulnerability report
|
|
/bot run --disable-fail-fast |
|
PR_Github #48328 [ run ] triggered by Bot. Commit: |
|
PR_Github #48328 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #48561 [ run ] triggered by Bot. Commit: |
|
PR_Github #48561 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #48814 [ run ] triggered by Bot. Commit: |
|
/bot run --disable-fail-fast |
|
PR_Github #48850 [ run ] triggered by Bot. Commit: |
|
PR_Github #48814 [ run ] completed with state |
|
PR_Github #48850 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #49160 [ run ] triggered by Bot. Commit: |
|
PR_Github #49160 [ run ] completed with state |
…ing (NVIDIA#13843) Signed-off-by: Yuan Tong <[email protected]>
Summary by CodeRabbit
Release Notes
Description
Removed some high-overhead codes:
.sampling_config.beam_widthis 2 binding property access with temporal wrapper object. Cache the value in.py_beam_width.Test Coverage
Covered by current tests
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.