-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[https://nvbugs/5441438][fix] Set correct draft length for the cuda graph dummy request #6701
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
Conversation
📝 WalkthroughWalkthroughThis change refactors speculative decoding configuration in the PyTorch backend by introducing a dynamic heuristic function, Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant LLM
participant suggest_spec_config
participant Drafter
participant Scheduler
User->>LLM: Request LLM with spec_mode="AUTO"
LLM->>suggest_spec_config: suggest_spec_config(max_batch_size)
suggest_spec_config-->>LLM: Returns NGramDecodingConfig (dynamic params)
LLM->>Drafter: Initialize with max_concurrency
LLM->>Scheduler: Schedule batch (with/without speculation)
Scheduler->>Drafter: should_use_spec_decode(requests)
Drafter-->>Scheduler: True/False (based on max_concurrency)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~18 minutes Possibly related PRs
Suggested reviewers
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. ✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
/bot run |
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
🧹 Nitpick comments (1)
tensorrt_llm/llmapi/llm.py (1)
1019-1021
: LGTM - Good refactoring for modularity.The dynamic configuration suggestion using
suggest_spec_config()
properly replaces the hardcoded heuristic logic. This improves modularity and maintainability.Consider moving the import to the top level for better performance if this code path is frequently executed:
+from tensorrt_llm._torch.speculative import suggest_spec_config from tensorrt_llm._torch.pyexecutor.config import update_executor_config spec_config = self.args.speculative_config max_batch_size = self._executor_config.max_batch_size if spec_config is not None and spec_config.decoding_type == "AUTO": - from tensorrt_llm._torch.speculative import suggest_spec_config spec_config = suggest_spec_config(max_batch_size)
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (12)
tensorrt_llm/_torch/pyexecutor/model_engine.py
(1 hunks)tensorrt_llm/_torch/pyexecutor/py_executor.py
(1 hunks)tensorrt_llm/_torch/pyexecutor/py_executor_creator.py
(1 hunks)tensorrt_llm/_torch/speculative/__init__.py
(2 hunks)tensorrt_llm/_torch/speculative/auto_heuristic.py
(1 hunks)tensorrt_llm/_torch/speculative/drafter.py
(2 hunks)tensorrt_llm/_torch/speculative/model_drafter.py
(1 hunks)tensorrt_llm/_torch/speculative/ngram.py
(1 hunks)tensorrt_llm/llmapi/llm.py
(2 hunks)tensorrt_llm/llmapi/llm_args.py
(2 hunks)tests/integration/defs/accuracy/accuracy_core.py
(1 hunks)tests/integration/defs/accuracy/test_llm_api_pytorch.py
(2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py
📄 CodeRabbit Inference Engine (CODING_GUIDELINES.md)
**/*.py
: Python code should conform to Python 3.8+.
Indent Python code with 4 spaces. Do not use tabs.
Always maintain the namespace when importing in Python, 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. Prefix k for variable names that start with a number (e.g., k_99th_percentile).
Python global variables should use upper snake_case and prefix G (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 interfaces that may be used outside a Python file, prefer docstrings over comments.
Comments in Python should be reserved 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.
Attributes and variables in Python can be documented inline; attribute docstrings will be rendered under the class docstring.
Avoid using reflection in Python when functionality can be easily achieved without it.
When using try-except blocks in Python, limit the except to the smallest set of errors possible.
When using try-except blocks to handle multiple possible variable types in Python, keep the body of the try as small as possible, using the else block to implement the logic.
Files:
tests/integration/defs/accuracy/accuracy_core.py
tensorrt_llm/_torch/pyexecutor/model_engine.py
tensorrt_llm/_torch/speculative/model_drafter.py
tensorrt_llm/_torch/speculative/drafter.py
tensorrt_llm/_torch/speculative/__init__.py
tensorrt_llm/llmapi/llm.py
tensorrt_llm/_torch/pyexecutor/py_executor.py
tests/integration/defs/accuracy/test_llm_api_pytorch.py
tensorrt_llm/_torch/pyexecutor/py_executor_creator.py
tensorrt_llm/_torch/speculative/ngram.py
tensorrt_llm/_torch/speculative/auto_heuristic.py
tensorrt_llm/llmapi/llm_args.py
**/*.{cpp,h,hpp,cc,cxx,cu,py}
📄 CodeRabbit Inference Engine (CODING_GUIDELINES.md)
All TensorRT-LLM Open Source Software code should contain an NVIDIA copyright header that includes the current year. This includes .cpp, .h, .cu, .py, and any other source files which are compiled or interpreted.
Files:
tests/integration/defs/accuracy/accuracy_core.py
tensorrt_llm/_torch/pyexecutor/model_engine.py
tensorrt_llm/_torch/speculative/model_drafter.py
tensorrt_llm/_torch/speculative/drafter.py
tensorrt_llm/_torch/speculative/__init__.py
tensorrt_llm/llmapi/llm.py
tensorrt_llm/_torch/pyexecutor/py_executor.py
tests/integration/defs/accuracy/test_llm_api_pytorch.py
tensorrt_llm/_torch/pyexecutor/py_executor_creator.py
tensorrt_llm/_torch/speculative/ngram.py
tensorrt_llm/_torch/speculative/auto_heuristic.py
tensorrt_llm/llmapi/llm_args.py
🧠 Learnings (5)
📚 Learning: in tensorrt-llm's multimodal processing pipeline, shared tensor recovery using `from_shared_tensor()...
Learnt from: yechank-nvidia
PR: NVIDIA/TensorRT-LLM#6254
File: tensorrt_llm/_torch/pyexecutor/model_engine.py:1201-1204
Timestamp: 2025-07-22T09:22:14.726Z
Learning: In TensorRT-LLM's multimodal processing pipeline, shared tensor recovery using `from_shared_tensor()` is only needed during the context phase. Generation requests reuse the already-recovered tensor data and only need to call `strip_for_generation()` to remove unnecessary multimodal data while preserving the recovered tensors. This avoids redundant tensor recovery operations during generation.
Applied to files:
tensorrt_llm/llmapi/llm.py
tests/integration/defs/accuracy/test_llm_api_pytorch.py
📚 Learning: in tensorrt-llm testing, it's common to have both cli flow tests (test_cli_flow.py) and pytorch api ...
Learnt from: moraxu
PR: NVIDIA/TensorRT-LLM#6303
File: tests/integration/test_lists/qa/examples_test_list.txt:494-494
Timestamp: 2025-07-28T17:06:08.621Z
Learning: In TensorRT-LLM testing, it's common to have both CLI flow tests (test_cli_flow.py) and PyTorch API tests (test_llm_api_pytorch.py) for the same model. These serve different purposes: CLI flow tests validate the traditional command-line workflow, while PyTorch API tests validate the newer LLM API backend. Both are legitimate and should coexist.
Applied to files:
tests/integration/defs/accuracy/test_llm_api_pytorch.py
📚 Learning: in tensorrt-llm, test files (files under tests/ directories) do not require nvidia copyright headers...
Learnt from: galagam
PR: NVIDIA/TensorRT-LLM#6487
File: tests/unittest/_torch/auto_deploy/unit/singlegpu/test_ad_trtllm_bench.py:1-12
Timestamp: 2025-08-06T13:58:07.506Z
Learning: In TensorRT-LLM, test files (files under tests/ directories) do not require NVIDIA copyright headers, unlike production source code files. Test files typically start directly with imports, docstrings, or code.
Applied to files:
tests/integration/defs/accuracy/test_llm_api_pytorch.py
📚 Learning: in tensorrt-llm, examples directory can have different dependency versions than the root requirement...
Learnt from: yibinl-nvidia
PR: NVIDIA/TensorRT-LLM#6506
File: examples/models/core/mixtral/requirements.txt:3-3
Timestamp: 2025-08-01T15:14:45.673Z
Learning: In TensorRT-LLM, examples directory can have different dependency versions than the root requirements.txt file. Version conflicts between root and examples dependencies are acceptable because examples are designed to be standalone and self-contained.
Applied to files:
tests/integration/defs/accuracy/test_llm_api_pytorch.py
📚 Learning: in tensorrt_llm/executor/worker.py, the lora adapter cache optimization logic that checks `is_adapte...
Learnt from: amitz-nv
PR: NVIDIA/TensorRT-LLM#5616
File: tensorrt_llm/executor/worker.py:375-384
Timestamp: 2025-07-17T09:01:27.402Z
Learning: In tensorrt_llm/executor/worker.py, the LoRA adapter cache optimization logic that checks `is_adapter_in_cpu_cache()` and conditionally passes None for weights/config has a known race condition issue that cannot be solved with simple error handling or verification checks. This is a known limitation that requires a more comprehensive solution.
Applied to files:
tests/integration/defs/accuracy/test_llm_api_pytorch.py
tensorrt_llm/_torch/pyexecutor/py_executor_creator.py
🪛 Ruff (0.12.2)
tensorrt_llm/_torch/speculative/auto_heuristic.py
1-1: Undefined name DecodingBaseConfig
(F821)
🔇 Additional comments (15)
tensorrt_llm/_torch/speculative/__init__.py (1)
1-1
: LGTM! Clean addition to the module's public API.The import and export of
suggest_spec_config
follows Python conventions and properly exposes the new heuristic function for AUTO speculation mode configuration.Also applies to: 27-27
tests/integration/defs/accuracy/accuracy_core.py (1)
158-159
: LGTM! Proper normalization of AUTO speculation mode.The conditional mapping of 'AUTO' to 'NGram' ensures consistency in accuracy testing and aligns with the standardization of AUTO speculation mode across the codebase.
tensorrt_llm/_torch/pyexecutor/py_executor.py (1)
874-877
: LGTM! Excellent documentation of draft request behavior.The comment clearly explains the dual behavior of
_prepare_draft_requests()
for both enabled and disabled speculation modes, improving code readability and maintainability.tensorrt_llm/_torch/speculative/model_drafter.py (1)
49-50
: LGTM! Proper superclass initialization added.The addition of the superclass
__init__
call withspec_config.max_concurrency
is correctly placed at the beginning of the constructor, before parameter validation and other initialization logic. This follows Python best practices for inheritance and aligns with the broader framework update to add concurrency control to speculative decoding.tensorrt_llm/_torch/pyexecutor/model_engine.py (1)
878-883
: LGTM! Correctly handles draft length based on speculative decoding state.The conditional assignment ensures that
max_draft_len
is set to 0 when speculative decoding is disabled, preventing unnecessary draft token allocation for CUDA graph dummy requests. This aligns with the PR objective of fixing the draft length parameter handling.tensorrt_llm/_torch/speculative/drafter.py (2)
12-13
: LGTM! Well-designed constructor with appropriate type hints.The constructor properly accepts an optional
max_concurrency
parameter and stores it as an instance attribute. The type annotation and default value are appropriate.
31-32
: LGTM! Proper concurrency control logic with backward compatibility.The conditional check correctly implements concurrency-based speculation control while maintaining backward compatibility. When
max_concurrency
is set, speculative decoding is disabled when the number of requests exceeds the limit.tests/integration/defs/accuracy/test_llm_api_pytorch.py (2)
22-25
: LGTM: Import addition follows conventionsThe
AutoDecodingConfig
import is properly added to the existing import statement and maintains alphabetical ordering.
325-340
: LGTM: Well-structured test for automatic speculative decodingThe test properly validates the new automatic speculative decoding functionality:
- Appropriate GPU architecture requirement with
@skip_pre_hopper
- Consistent configuration with
max_batch_size
matching CUDA graph batch sizes- Uses
AutoDecodingConfig()
to test the automatic speculation feature- Follows established patterns from other speculative decoding tests in the file
tensorrt_llm/_torch/pyexecutor/py_executor_creator.py (1)
172-179
: Validate availability & naming ofsupport_overlap_scheduler()
across all speculation modesThe new guard relies on every
spec_dec_mode
object implementing asupport_overlap_scheduler()
method.
Please double-check that:
- All concrete
SpecDecMode
implementations in the codebase expose that exact method name (verb support, singular support vs. supports).- No
None
values can propagate intospec_config.spec_dec_mode
, otherwise this will raise anAttributeError
.If either condition might fail, consider a safer check:
-if not spec_config.spec_dec_mode.support_overlap_scheduler(): +if spec_config.spec_dec_mode is None or \ + not getattr(spec_config.spec_dec_mode, "support_overlap_scheduler", lambda: False)():tensorrt_llm/llmapi/llm_args.py (2)
344-347
: LGTM! Well-documented concurrency control field.The
max_concurrency
field is properly implemented with clear documentation explaining its PyTorch-specific usage for controlling speculation based on batch size.
539-542
: LGTM! Improved docstring clarity.The updated docstring is more concise and accurately reflects the automatic selection behavior without hardcoded heuristic details.
tensorrt_llm/_torch/speculative/ngram.py (1)
170-170
: LGTM! Proper integration with concurrency control.The constructor correctly passes
max_concurrency
from the spec config to the parentDrafter
class, enabling flexible concurrency-based speculation control.tensorrt_llm/_torch/speculative/auto_heuristic.py (1)
10-17
: LGTM! Well-designed heuristic function.The function provides a good balance between speculation aggressiveness and batch size, with smaller batches getting more aggressive speculation. The
max_concurrency=32
parameter correctly enforces the batch size limit mentioned in the docstring.tensorrt_llm/llmapi/llm.py (1)
35-36
: LGTM - Clean import optimization.Removing
NGramDecodingConfig
from the import list is appropriate since it's no longer used directly in this file after the refactoring to usesuggest_spec_config()
.
PR_Github #14449 [ run ] triggered by Bot |
PR_Github #14449 [ run ] completed with state |
…ummy request Signed-off-by: ziyixiong-nv <[email protected]>
405f809
to
9c5d663
Compare
/bot run |
PR_Github #14522 [ run ] triggered by Bot |
PR_Github #14522 [ run ] completed with state |
/bot run |
PR_Github #14544 [ run ] triggered by Bot |
Signed-off-by: ziyixiong-nv <[email protected]>
/bot run |
PR_Github #14596 [ run ] triggered by Bot |
PR_Github #14544 [ run ] completed with state |
PR_Github #14596 [ run ] completed with state |
…e cuda graph dummy request (NVIDIA#6701)" This reverts commit b4fcd5f.
Summary by CodeRabbit
New Features
Improvements
Bug Fixes
Documentation
Tests
Description
The speculative decoding could be disabled in some conditions. The
max_draft_len
of cuda graph dummy request should be set accordingly.This PR is based on @mikeiovine 's PR #6676 , so only the last commit needs to be reviewed.
Test Coverage
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.
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-list
parameter 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.md
and the
scripts/test_to_stage_mapping.py
helper.kill
kill
Kill all running builds associated with pull request.
skip
skip --comment COMMENT
Skip 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-pipeline
Reuse 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.