Skip to content

[None][feat] Clean up ngram auto mode, add max_concurrency to configs #6676

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

Merged
merged 1 commit into from
Aug 7, 2025

Conversation

mikeiovine
Copy link
Collaborator

@mikeiovine mikeiovine commented Aug 6, 2025

Description

Address some followups from the initial ngram auto PR.

  • Move heuristic to _torch/speculative/auto_heuristic.py.
  • Get rid of a bunch of comments. The NGramDecoding config is self-explanatory. We also should not be leaking these details in user-facing docstrings.
  • Get rid of unused is_auto_heuristic in NGramDecodingConfig
  • Add a max_concurrency field to DecodingBaseConfig. Drafter will now disable speculation if the number of active requests goes above this number. If no max_concurrency is given, speculation will always be on (default).
  • Fix some faulty logic in the ngram drafter. should_use_spec_decode should be used to turn ngram off.
  • Overlap scheduler now gets disabled if you accidentally leave it on for a speculation mode that doesn't support it. A warning is emitted if this happens. This improves overall UX since overlap scheduler is on by default.

Test Coverage

Existing tests cover ngram and auto. Tried to add a new accuracy tests but there are CUDA graph bugs to address. Opened https://nvbugspro.nvidia.com/bug/5441438 to follow up.

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 the stage-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.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced automatic suggestion of speculative decoding configurations based on batch size.
    • Added a new option to control the maximum concurrency for speculative decoding in PyTorch.
  • Improvements

    • Speculative decoding configuration is now automatically selected for "AUTO" mode, streamlining setup.
    • Speculative decoding is now gated by a configurable concurrency limit for better performance control.
    • Overlap scheduler is automatically disabled if incompatible with speculative decoding settings.
    • Removed manual batch size limits on speculative decoding heuristics for more flexible processing.
  • Bug Fixes

    • Improved handling of speculative decoding for large batch sizes.
  • Documentation

    • Updated class descriptions and comments for clarity regarding speculative decoding behavior and configuration.

Copy link
Contributor

coderabbitai bot commented Aug 6, 2025

📝 Walkthrough

Walkthrough

This update introduces a concurrency-aware heuristic for automatically configuring speculative decoding in the PyTorch backend. It adds a new function to generate default speculative configs based on batch size, updates class constructors and logic to support a max_concurrency parameter, and simplifies the integration of auto speculation in the LLM API. Minor documentation and import adjustments accompany these changes.

Changes

Cohort / File(s) Change Summary
PyExecutor Comment Update
tensorrt_llm/_torch/pyexecutor/py_executor.py
Added a clarifying comment in _prepare_and_schedule_batch about the behavior of _prepare_draft_requests() regarding speculation status. No functional code changes.
Executor Config and Overlap Scheduler
tensorrt_llm/_torch/pyexecutor/py_executor_creator.py
Added logic in _mangle_executor_config to automatically disable the overlap scheduler if the selected speculative decoding mode does not support it, with a warning.
Public API Exports
tensorrt_llm/_torch/speculative/__init__.py
Imported and exported suggest_spec_config from .auto_heuristic in the package’s __all__.
Auto Speculation Heuristic
tensorrt_llm/_torch/speculative/auto_heuristic.py
Added suggest_spec_config function to provide a default speculative decoding configuration based on max_batch_size.
Drafter Concurrency Gating
tensorrt_llm/_torch/speculative/drafter.py
Added max_concurrency parameter to the Drafter class and used it to gate speculative decoding in should_use_spec_decode.
ModelDrafter Constructor Update
tensorrt_llm/_torch/speculative/model_drafter.py
Modified ModelDrafter constructor to call the superclass constructor with spec_config.max_concurrency.
NGramDrafter Constructor and Heuristic
tensorrt_llm/_torch/speculative/ngram.py
Updated NGramDrafter constructor to call superclass with max_concurrency; removed the batch size gating logic from prepare_draft_tokens.
LLM API Auto Speculation Integration
tensorrt_llm/llmapi/llm.py
Replaced manual heuristic and config construction for auto speculation with a call to suggest_spec_config. Adjusted logic to use the new function and removed direct handling of overlap scheduler and manual config.
Speculative Config Data Model
tensorrt_llm/llmapi/llm_args.py
Added max_concurrency to DecodingBaseConfig, removed is_auto_heuristic from NGramDecodingConfig, updated AutoDecodingConfig docstring, and retained "AUTO" decoding type.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant LLMAPI
    participant suggest_spec_config
    participant Drafter
    participant Scheduler

    User->>LLMAPI: Request model with AUTO speculative config
    LLMAPI->>suggest_spec_config: Call with max_batch_size
    suggest_spec_config-->>LLMAPI: Return NGramDecodingConfig
    LLMAPI->>Drafter: Initialize with max_concurrency
    LLMAPI->>Scheduler: Pass spec_config and drafter
    Scheduler->>Drafter: should_use_spec_decode(requests)
    Drafter-->>Scheduler: Return True/False based on max_concurrency
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Possibly related PRs

Suggested labels

Community want to contribute

Suggested reviewers

  • wili-65535
  • syuoni
  • litaotju
  • HuiGao-NV
  • pcastonguay

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d8c9081 and 95b2c55.

📒 Files selected for processing (9)
  • 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)
✅ Files skipped from review due to trivial changes (1)
  • tensorrt_llm/_torch/speculative/init.py
🚧 Files skipped from review as they are similar to previous changes (7)
  • tensorrt_llm/_torch/speculative/ngram.py
  • tensorrt_llm/_torch/speculative/drafter.py
  • tensorrt_llm/_torch/pyexecutor/py_executor_creator.py
  • tensorrt_llm/_torch/speculative/model_drafter.py
  • tensorrt_llm/llmapi/llm.py
  • tensorrt_llm/_torch/pyexecutor/py_executor.py
  • tensorrt_llm/llmapi/llm_args.py
🧰 Additional context used
🪛 Ruff (0.12.2)
tensorrt_llm/_torch/speculative/auto_heuristic.py

1-1: Undefined name DecodingBaseConfig

(F821)

⏰ 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 (1)
tensorrt_llm/_torch/speculative/auto_heuristic.py (1)

10-17: LGTM! Well-designed heuristic logic.

The parameter selection based on batch size is well-reasoned:

  • Smaller batch sizes (≤4) get longer draft sequences (max_draft_len=5) but smaller n-gram sizes (max_matching_ngram_size=3)
  • Larger batch sizes get shorter drafts (max_draft_len=3) but larger n-gram sizes (max_matching_ngram_size=5)
  • The max_concurrency=32 effectively disables speculation for batch sizes ≥32 as documented

This balances speculation benefits with computational overhead appropriately.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
tensorrt_llm/llmapi/llm_args.py (1)

539-543: Fix docstring formatting per coding standards.

The simplified docstring content looks good and aligns with the PR objective of reducing excessive documentation. However, the docstring format needs a blank line between the summary and description.

Apply this diff to fix the docstring formatting:

 """
 Configuration for auto speculative decoding.
+
 This config will automatically select a good, draft-model free
 speculation algorithm with some heuristic.

 Attributes that are inherited from the base class are ignored.
 """
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a16ba64 and 533a6fe.

📒 Files selected for processing (9)
  • 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 (3 hunks)
🧰 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 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 class in the constructor in Python.
For interfaces that may be used outside a file, prefer docstrings over comments in Python.
Comments in Python should be reserved for code within a function, or interfaces that are local to a file.
Use Google style docstrings for classes and functions in Python, which can be parsed by Sphinx.
Attributes and variables in Python can be documented inline; attribute docstrings will be rendered under the docstring for the class.
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:

  • tensorrt_llm/_torch/speculative/__init__.py
  • tensorrt_llm/_torch/speculative/drafter.py
  • tensorrt_llm/_torch/pyexecutor/py_executor.py
  • tensorrt_llm/_torch/pyexecutor/py_executor_creator.py
  • tensorrt_llm/_torch/speculative/model_drafter.py
  • tensorrt_llm/_torch/speculative/auto_heuristic.py
  • tensorrt_llm/llmapi/llm_args.py
  • tensorrt_llm/llmapi/llm.py
  • tensorrt_llm/_torch/speculative/ngram.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:

  • tensorrt_llm/_torch/speculative/__init__.py
  • tensorrt_llm/_torch/speculative/drafter.py
  • tensorrt_llm/_torch/pyexecutor/py_executor.py
  • tensorrt_llm/_torch/pyexecutor/py_executor_creator.py
  • tensorrt_llm/_torch/speculative/model_drafter.py
  • tensorrt_llm/_torch/speculative/auto_heuristic.py
  • tensorrt_llm/llmapi/llm_args.py
  • tensorrt_llm/llmapi/llm.py
  • tensorrt_llm/_torch/speculative/ngram.py
🧠 Learnings (6)
📚 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:

  • tensorrt_llm/_torch/pyexecutor/py_executor.py
  • tensorrt_llm/_torch/pyexecutor/py_executor_creator.py
📚 Learning: applies to **/*.py : the code developed for tensorrt-llm should conform to python 3.8+....
Learnt from: CR
PR: NVIDIA/TensorRT-LLM#0
File: CODING_GUIDELINES.md:0-0
Timestamp: 2025-08-06T08:45:40.701Z
Learning: Applies to **/*.py : The code developed for TensorRT-LLM should conform to Python 3.8+.

Applied to files:

  • tensorrt_llm/llmapi/llm_args.py
  • tensorrt_llm/llmapi/llm.py
📚 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
📚 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:

  • tensorrt_llm/llmapi/llm.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:

  • tensorrt_llm/llmapi/llm.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:

  • tensorrt_llm/llmapi/llm.py
🪛 Ruff (0.12.2)
tensorrt_llm/_torch/speculative/auto_heuristic.py

1-1: Undefined name DecodingBaseConfig

(F821)

tensorrt_llm/llmapi/llm_args.py

546-548: 1 blank line required between summary line and description

(D205)

⏰ 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 (12)
tensorrt_llm/_torch/speculative/__init__.py (1)

1-1: LGTM! Clean integration of the new heuristic function.

The import and export of suggest_spec_config properly exposes the centralized heuristic logic for automatic speculative decoding configuration, aligning with the PR's goal of moving heuristic logic to a dedicated module.

Also applies to: 27-27

tensorrt_llm/_torch/pyexecutor/py_executor.py (1)

874-877: LGTM! Helpful clarifying comment.

This comment clearly explains the conditional behavior of _prepare_draft_requests() based on speculation state, improving code readability and maintainability.

tensorrt_llm/_torch/speculative/ngram.py (1)

170-170: LGTM! Proper integration with concurrency gating.

The constructor correctly passes spec_config.max_concurrency to the parent Drafter class, enabling concurrency-based control of speculative decoding for NGram drafters.

tensorrt_llm/_torch/speculative/model_drafter.py (1)

49-50: LGTM! Consistent integration with concurrency gating.

The constructor properly passes spec_config.max_concurrency to the parent Drafter class, maintaining consistency with other drafter implementations and enabling concurrency-based speculation control.

tensorrt_llm/_torch/speculative/drafter.py (1)

12-13: LGTM! Clean addition of concurrency configuration.

The __init__ method properly accepts and stores the max_concurrency parameter, enabling concurrency-based control of speculative decoding across drafter implementations.

tensorrt_llm/_torch/speculative/auto_heuristic.py (1)

9-17: LGTM! Solid heuristic implementation.

The batch-size-based heuristic logic is well-designed:

  • Smaller batches (≤4) get longer draft lengths (max_draft_len=5) for better speculation
  • Larger batches (>4) get shorter draft lengths (max_draft_len=3) to reduce overhead
  • max_concurrency=32 effectively disables speculation for large batch sizes as documented
  • Local import avoids potential circular dependency issues
tensorrt_llm/llmapi/llm.py (2)

35-36: LGTM! Clean import removal.

Correctly removed the unused NGramDecodingConfig import since the manual heuristic logic has been replaced with the centralized suggest_spec_config function.


1019-1021: Excellent refactoring to centralize speculation heuristics.

The replacement of manual heuristic logic with the centralized suggest_spec_config function improves maintainability and consistency. The local import pattern avoids potential circular dependencies.

Note: The case change from "AUTO" to "Auto" should be consistent with changes in the AutoDecodingConfig class.

tensorrt_llm/_torch/pyexecutor/py_executor_creator.py (1)

172-178: LGTM! Excellent defensive compatibility check.

This addition properly handles the interaction between speculative decoding and the overlap scheduler:

  • Defensive checks prevent unnecessary modifications when overlap scheduler is already disabled
  • Uses the appropriate support_overlap_scheduler() method to determine compatibility
  • Provides clear warning message when automatic adjustment occurs
  • Prevents potential runtime issues from incompatible feature combinations
tensorrt_llm/llmapi/llm_args.py (3)

344-347: LGTM! Clean addition of concurrency control.

The new max_concurrency field is well-implemented with proper typing, clear documentation, and appropriate default value. The PyTorch-specific comment helps clarify its scope of usage.


549-549: LGTM! Consistent with mapping change.

The decoding_type change from "AUTO" to "Auto" maintains consistency with the updated from_dict mapping and follows a more conventional casing pattern.


551-552: LGTM! Proper backend restriction implementation.

The supports_backend method correctly restricts AutoDecodingConfig to the PyTorch backend only, which aligns with the auto speculation functionality being PyTorch-specific. The implementation follows the established pattern used by other decoding configuration classes.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
tensorrt_llm/_torch/speculative/auto_heuristic.py (1)

1-1: Fix the return type annotation and import.

The return type annotation uses "DecodingBaseConfig" but the function actually returns NGramDecodingConfig. Additionally, DecodingBaseConfig is not imported, causing the static analysis error.

Apply this diff to fix the type annotation:

+from tensorrt_llm.llmapi.llm_args import NGramDecodingConfig
+
-def suggest_spec_config(max_batch_size: int) -> "DecodingBaseConfig":
+def suggest_spec_config(max_batch_size: int) -> NGramDecodingConfig:
🧹 Nitpick comments (1)
tensorrt_llm/_torch/speculative/auto_heuristic.py (1)

9-17: Consider moving the import to module level.

The import is currently inside the function, which works but is unconventional. Moving it to the top would improve readability and follows standard Python conventions.

+from tensorrt_llm.llmapi.llm_args import NGramDecodingConfig
+
 def suggest_spec_config(max_batch_size: int) -> NGramDecodingConfig:
     """
     Suggests a reasonable draft model free speculation scheme.
     Used when the user specifies spec_mode == AUTO.

     For now, we always use an ngram scheme that gets disabled at
     BS>=32.
     """
-    from tensorrt_llm.llmapi.llm_args import NGramDecodingConfig
     return NGramDecodingConfig(
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 533a6fe and d8c9081.

📒 Files selected for processing (9)
  • 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)
✅ Files skipped from review due to trivial changes (1)
  • tensorrt_llm/_torch/pyexecutor/py_executor.py
🚧 Files skipped from review as they are similar to previous changes (6)
  • tensorrt_llm/_torch/speculative/init.py
  • tensorrt_llm/llmapi/llm.py
  • tensorrt_llm/_torch/speculative/ngram.py
  • tensorrt_llm/_torch/pyexecutor/py_executor_creator.py
  • tensorrt_llm/_torch/speculative/model_drafter.py
  • tensorrt_llm/llmapi/llm_args.py
🧰 Additional context used
🧠 Learnings (1)
📚 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:

  • tensorrt_llm/_torch/speculative/drafter.py
🪛 Ruff (0.12.2)
tensorrt_llm/_torch/speculative/auto_heuristic.py

1-1: Undefined name DecodingBaseConfig

(F821)

⏰ 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/speculative/drafter.py (2)

12-13: LGTM! Constructor correctly initializes concurrency parameter.

The __init__ method properly accepts and stores the optional max_concurrency parameter, enabling concurrency-aware gating in the drafter.


31-32: LGTM! Concurrency gating logic is now correct.

The logic correctly disables speculation when the number of requests reaches or exceeds max_concurrency, which aligns with the PR objectives. This addresses the previous review concern about inverted logic.

tensorrt_llm/_torch/speculative/auto_heuristic.py (1)

10-17: LGTM! Heuristic parameters are well-tuned.

The heuristic logic appropriately adjusts parameters based on batch size:

  • Smaller batches (≤4) get more aggressive speculation with longer drafts
  • Larger batches get shorter drafts to balance performance
  • Fixed max_concurrency=32 effectively disables speculation at high batch sizes as intended

The boolean flags are consistently set to enable optimal ngram behavior.

@mikeiovine
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #14334 [ run ] triggered by Bot

Copy link
Collaborator

@Superjomn Superjomn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM from the llmapi perspective

Copy link
Collaborator

@syuoni syuoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @mikeiovine !

@tensorrt-cicd
Copy link
Collaborator

PR_Github #14334 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #10831 completed with status: 'SUCCESS'
Pipeline passed with automatic retried tests. Check the rerun report for details.

@mikeiovine
Copy link
Collaborator Author

/bot reuse-pipeline

@mikeiovine mikeiovine enabled auto-merge (squash) August 7, 2025 16:28
@tensorrt-cicd
Copy link
Collaborator

PR_Github #14494 [ reuse-pipeline ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #14494 [ reuse-pipeline ] completed with state SUCCESS
Reusing PR_Github #14334 for commit 27c401e

@mikeiovine mikeiovine merged commit e968f98 into NVIDIA:main Aug 7, 2025
4 checks passed
@mikeiovine mikeiovine deleted the fix-ngram-auto branch August 7, 2025 16:52
Shunkangz pushed a commit to hcyezhang/TensorRT-LLM that referenced this pull request Aug 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants