-
Notifications
You must be signed in to change notification settings - Fork 2k
[https://nvbugs/5781589][fix] Implement pp skip forward for all spec worker. #10578
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?
Conversation
Signed-off-by: Yuxian Qiu <[email protected]>
|
/bot run --disable-fail-fast |
📝 WalkthroughWalkthroughReorganizes epilogue handling in speculative decoding models by relocating the skip_forward method from MTPWorker to SpecWorkerBase, removing epilogue extensions from DeepseekV3 and GLM models, adding them to SpecDecOneEngine, and refactoring weight removal logic in utilities. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In @tensorrt_llm/_torch/models/modeling_speculative.py:
- Around line 921-922: The code calls self.epilogue.extend(self.draft_model) but
draft_model is an nn.Module, not iterable, causing a TypeError; change this to
self.epilogue.append(self.draft_model) to add the whole draft model as a single
module, or if the intent was to add specific sublayers (as earlier code did with
draft_model.mtp_layers), replace extend argument with the iterable attribute
(e.g., draft_model.mtp_layers) instead.
🧹 Nitpick comments (1)
tensorrt_llm/_torch/models/modeling_utils.py (1)
306-306: Good refactor: enumerate is cleaner than range indexing.Switching from
range(num_hidden_layers)with manual indexing (self.layers[layer_idx]) toenumerate(self.layers)is more Pythonic and avoids redundant lookups. Thelayervariable is correctly used in the subsequentskip_forwardcall.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
tensorrt_llm/_torch/models/modeling_deepseekv3.pytensorrt_llm/_torch/models/modeling_glm.pytensorrt_llm/_torch/models/modeling_speculative.pytensorrt_llm/_torch/models/modeling_utils.pytensorrt_llm/_torch/speculative/interface.pytensorrt_llm/_torch/speculative/mtp.py
💤 Files with no reviewable changes (3)
- tensorrt_llm/_torch/models/modeling_glm.py
- tensorrt_llm/_torch/models/modeling_deepseekv3.py
- tensorrt_llm/_torch/speculative/mtp.py
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
**/*.py: The code developed for TensorRT-LLM should conform to Python 3.8+
Indent Python code with 4 spaces. Do not use tabs
Always maintain the namespace when importing Python modules, even if only one class or function from a module is used
Python filenames should use snake_case (e.g.,some_file.py)
Python classes should use PascalCase (e.g.,class SomeClass)
Python functions and methods should use snake_case (e.g.,def my_awesome_function():)
Python local variables should use snake_case, with prefixkfor variable names that start with a number (e.g.,k_99th_percentile)
Python global variables should use upper snake_case with prefixG(e.g.,G_MY_GLOBAL)
Python constants should use upper snake_case (e.g.,MY_CONSTANT)
Avoid shadowing variables declared in an outer scope in Python
Initialize all externally visible members of a Python class in the constructor
For Python interfaces that may be used outside a file, prefer docstrings over comments
Use comments in Python for code within a function, or interfaces that are local to a file
Use Google-style docstrings for Python classes and functions, which can be parsed by Sphinx
Python attributes and variables can be documented inline with the format"""<type>: Description"""
Avoid using reflection in Python when functionality can be easily achieved without reflection
When using try-except blocks in Python, limit the except clause to the smallest set of errors possible
When using try-except blocks in Python to handle multiple possible variable types (duck-typing), keep the body of the try as small as possible and use the else block for the main logic
Files:
tensorrt_llm/_torch/models/modeling_speculative.pytensorrt_llm/_torch/models/modeling_utils.pytensorrt_llm/_torch/speculative/interface.py
**/*.{cpp,cc,cxx,h,hpp,hxx,cu,cuh,py}
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
All TensorRT-LLM source files (.cpp, .h, .cu, .py, and other source files) should contain an NVIDIA copyright header with the year of latest meaningful modification
Files:
tensorrt_llm/_torch/models/modeling_speculative.pytensorrt_llm/_torch/models/modeling_utils.pytensorrt_llm/_torch/speculative/interface.py
🧠 Learnings (2)
📚 Learning: 2025-08-19T12:45:11.997Z
Learnt from: amitz-nv
Repo: NVIDIA/TensorRT-LLM PR: 7033
File: tensorrt_llm/_torch/pyexecutor/model_engine.py:0-0
Timestamp: 2025-08-19T12:45:11.997Z
Learning: In tensorrt_llm/_torch/pyexecutor/model_engine.py, DoRA (Delta Orthogonal Rank Adaptation) functionality was removed from the PyTorch flow to eliminate issues with inverted DoRA detection logic. The original is_dora condition was checking if scaling_vec_pointer == 0, which was potentially incorrect.
Applied to files:
tensorrt_llm/_torch/models/modeling_utils.py
📚 Learning: 2025-08-18T08:42:02.640Z
Learnt from: samuellees
Repo: NVIDIA/TensorRT-LLM PR: 6974
File: tensorrt_llm/serve/scripts/benchmark_dataset.py:558-566
Timestamp: 2025-08-18T08:42:02.640Z
Learning: In TensorRT-LLM's RandomDataset (tensorrt_llm/serve/scripts/benchmark_dataset.py), when using --random-token-ids option, sequence length accuracy is prioritized over semantic correctness for benchmarking purposes. The encode/decode operations should use skip_special_tokens=True and add_special_tokens=False to ensure exact target token lengths.
Applied to files:
tensorrt_llm/_torch/speculative/interface.py
🧬 Code graph analysis (2)
tensorrt_llm/_torch/models/modeling_speculative.py (1)
tensorrt_llm/_torch/models/modeling_mistral.py (1)
draft_model(635-636)
tensorrt_llm/_torch/speculative/interface.py (6)
tensorrt_llm/_torch/models/modeling_utils.py (1)
skip_forward(152-165)tensorrt_llm/_torch/models/modeling_mistral.py (1)
draft_model(635-636)tensorrt_llm/_torch/attention_backend/interface.py (1)
num_seqs(254-258)tensorrt_llm/_torch/speculative/mtp.py (1)
max_draft_len(359-360)tensorrt_llm/_torch/speculative/eagle3.py (1)
max_draft_len(367-368)tensorrt_llm/_torch/models/modeling_llama.py (1)
dtype(1109-1110)
🪛 Ruff (0.14.10)
tensorrt_llm/_torch/speculative/interface.py
385-385: Unused method argument: input_ids
(ARG002)
386-386: Unused method argument: position_ids
(ARG002)
387-387: Unused method argument: hidden_states
(ARG002)
390-390: Unused method argument: spec_metadata
(ARG002)
391-391: Unused method argument: draft_model
(ARG002)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Pre-commit Check
🔇 Additional comments (3)
tensorrt_llm/_torch/models/modeling_utils.py (1)
160-161: LGTM! Explicit weight removal for DecoderModelForCausalLM.The new branch explicitly handles
DecoderModelForCausalLMinstances by removing weights even when theskip_forwardattribute is absent. This ensures consistent weight cleanup during pipeline parallelism setup.tensorrt_llm/_torch/speculative/interface.py (2)
383-412: Stub implementation with unused parameters is intentional.The new
skip_forwardmethod inSpecWorkerBaseprovides a default implementation that creates empty tensors without using most input parameters. This appears intentional as a fallback for subclasses that don't need full skip_forward logic during pipeline parallelism.Static analysis correctly identifies unused parameters (
input_ids,position_ids,hidden_states,spec_metadata,draft_model), but these are required for interface consistency with subclass implementations that will override this method.Note: The empty tensors returned here serve as placeholders. Ensure that calling code can handle these placeholder tensors correctly or that subclasses override this method when actual functionality is needed.
417-417: LGTM! Explicit return value improves clarity.Changing
set_guided_decoderto explicitly returnTrue(rather than implicitly returningNone) improves code clarity and aligns with the return type expectation documented in the calling code (e.g., Line 1015 in modeling_speculative.py checks the boolean return value).
| self.epilogue.extend(self.draft_model) | ||
| self.epilogue.append(self.spec_worker) |
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.
Potential runtime error: extending epilogue with non-iterable draft_model.
Line 921 calls self.epilogue.extend(self.draft_model), but draft_model (returned by get_draft_model()) is an nn.Module instance (e.g., Eagle3ForCausalLM, MTPForCausalLM), not a list or iterable. The extend() method expects an iterable and will raise a TypeError at runtime.
Based on the AI summary, other models previously used epilogue.extend(draft_model.mtp_layers) but removed it. This suggests the intent might be to append the entire draft model as a single module.
🔧 Proposed fix
Replace extend with append to add the draft model as a single module:
- self.epilogue.extend(self.draft_model)
+ self.epilogue.append(self.draft_model)
self.epilogue.append(self.spec_worker)Alternatively, if you need to extend with specific layers from certain draft models:
- self.epilogue.extend(self.draft_model)
+ if isinstance(self.draft_model, MTPForCausalLM):
+ self.epilogue.extend(self.draft_model.mtp_layers)
+ else:
+ self.epilogue.append(self.draft_model)
self.epilogue.append(self.spec_worker)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| self.epilogue.extend(self.draft_model) | |
| self.epilogue.append(self.spec_worker) | |
| self.epilogue.append(self.draft_model) | |
| self.epilogue.append(self.spec_worker) |
🤖 Prompt for AI Agents
In @tensorrt_llm/_torch/models/modeling_speculative.py around lines 921 - 922,
The code calls self.epilogue.extend(self.draft_model) but draft_model is an
nn.Module, not iterable, causing a TypeError; change this to
self.epilogue.append(self.draft_model) to add the whole draft model as a single
module, or if the intent was to add specific sublayers (as earlier code did with
draft_model.mtp_layers), replace extend argument with the iterable attribute
(e.g., draft_model.mtp_layers) instead.
|
PR_Github #31250 [ run ] triggered by Bot. Commit: |
|
PR_Github #31250 [ run ] completed with state
|
Signed-off-by: Yuxian Qiu <[email protected]>
|
/bot run --disable-fail-fast |
|
PR_Github #31305 [ run ] triggered by Bot. Commit: |
|
PR_Github #31305 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #31400 [ run ] triggered by Bot. Commit: |
|
PR_Github #31400 [ run ] completed with state |
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.
Description
Test Coverage
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
/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...Provide a user friendly way for developers to interact with a Jenkins server.
Run
/bot [-h|--help]to print this help message.See details below for each supported subcommand.
Details
run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental)]Launch build/test pipelines. All previously running jobs will be killed.
--reuse-test (optional)pipeline-id(OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.--disable-reuse-test(OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.--disable-fail-fast(OPTIONAL) : Disable fail fast on build/tests/infra failures.--skip-test(OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.--stage-list "A10-PyTorch-1, xxx"(OPTIONAL) : Only run the specified test stages. Examples: "A10-PyTorch-1, xxx". Note: Does NOT update GitHub check status.--gpu-type "A30, H100_PCIe"(OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.--test-backend "pytorch, cpp"(OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.--only-multi-gpu-test(OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.--disable-multi-gpu-test(OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.--add-multi-gpu-test(OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.--post-merge(OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx"(OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx".--detailed-log(OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.--debug(OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in thestage-listparameter to access the appropriate container environment. Note: Does NOT update GitHub check status.For guidance on mapping tests to stage names, see
docs/source/reference/ci-overview.mdand the
scripts/test_to_stage_mapping.pyhelper.kill
killKill all running builds associated with pull request.
skip
skip --comment COMMENTSkip testing for latest commit on pull request.
--comment "Reason for skipping build/test"is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.reuse-pipeline
reuse-pipelineReuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.