-
Notifications
You must be signed in to change notification settings - Fork 2k
[None][chore] remove executor config in instantiate sampler #7516
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
[None][chore] remove executor config in instantiate sampler #7516
Conversation
0893c18 to
53a7be0
Compare
|
/bot run |
|
PR_Github #17632 [ run ] triggered by Bot |
|
PR_Github #17632 [ run ] completed with state |
|
/bot run |
|
PR_Github #17667 [ run ] triggered by Bot |
|
PR_Github #17667 [ run ] completed with state |
|
/bot run |
|
PR_Github #17770 [ run ] triggered by Bot |
|
PR_Github #17770 [ run ] completed with state |
fbaa9df to
dd02e91
Compare
|
/bot run |
683a64b to
dd02e91
Compare
|
/bot run |
|
PR_Github #17832 [ run ] triggered by Bot |
|
PR_Github #17831 [ run ] triggered by Bot |
|
PR_Github #17832 [ run ] completed with state |
📝 WalkthroughWalkthroughRefactors sampler creation to remove ExecutorConfig in favor of explicit parameters. Updates utilities to compute sampler args and decoding mode from provided configs. Adjusts py_executor_creator to pass new parameters, create/update sampler, and sync max_seq_len after KV cache setup. Sampler classes now accept and use max_seq_len, max_batch_size, max_beam_width, decoding_config, and kv_cache_config. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Creator as py_executor_creator
participant Util as _util.instantiate_sampler
participant Sampler as TRTLLMSampler
participant KV as KVCacheManager
Creator->>Util: instantiate_sampler(engine, mapping, max_batch_size, max_beam_width, max_seq_len, mm_encoder_only, speculative_config, decoding_config, kv_cache_config)
Util->>Util: get_decoding_mode(decoding_config, max_beam_width)
Util->>Sampler: __init__(..., decoding_mode, max_seq_len, max_batch_size, max_beam_width, decoding_config, kv_cache_config)
Sampler-->>Util: Sampler instance
Util-->>Creator: Sampler
note over Creator,KV: KV cache size estimation/finalization may adjust max_seq_len
Creator->>KV: create_or_estimate(max_seq_len, ...)
KV-->>Creator: updated max_seq_len
Creator->>Creator: update_sampler_max_seq_len(new_max_seq_len, sampler)
Creator->>Sampler: set max_seq_len (if TRTLLMSampler)
Sampler-->>Creator: ack
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
✨ 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. 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: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (6)
tensorrt_llm/_torch/pyexecutor/py_executor_creator.py (3)
1-1: Add NVIDIA Apache-2.0 header (2025).Per repo guidelines, prepend the standard NVIDIA Apache-2.0 header.
Apply:
+# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License.
30-34: Duplicate import of is_mla; remove the redundant one.Both ._util and .config_utils export is_mla; the latter should be used. Avoid shadowing.
-from ._util import (KvCacheCreator, _adjust_torch_mem_fraction, - create_py_executor_instance, instantiate_sampler, is_mla) +from ._util import (KvCacheCreator, _adjust_torch_mem_fraction, + create_py_executor_instance, instantiate_sampler)
8-8: Generalize update_sampler_max_seq_len and add types/docstring.Make it work for any sampler exposing max_seq_len; no hard dependency on TRTLLMSampler.
-from typing import Optional +from typing import Any, Optional @@ -def update_sampler_max_seq_len(max_seq_len, sampler): - # Originally, TRTLLMSampler is constructed with executor_config, but - # _create_kv_cache_manager (via build_managers) may later overwrite executor_config.max_seq_len. - # Because TRTLLMSampler.sample_async still needs the updated limit and executor_config is - # deprecated inside TRTLLMSampler, keep TRTLLMSampler.max_seq_len updated with - # with executor_config.max_seq_len. - if isinstance(sampler, TRTLLMSampler): - assert hasattr(sampler, "max_seq_len") - sampler.max_seq_len = max_seq_len +def update_sampler_max_seq_len(max_seq_len: int, sampler: Any) -> None: + """Propagate updated max_seq_len to the sampler if supported.""" + if hasattr(sampler, "max_seq_len"): + sampler.max_seq_len = max_seq_lenAlso applies to: 213-222
tensorrt_llm/_torch/pyexecutor/_util.py (1)
1-1: Add NVIDIA Apache-2.0 header (2025).Please prepend the standard header.
+# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License.tensorrt_llm/_torch/pyexecutor/sampler.py (2)
1-1: Add NVIDIA Apache-2.0 header (2025).Please prepend the standard header.
+# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License.
794-815: Guard kv_cache_config being None in TRTLLMSampler.init.Signature allows Optional[KvCacheConfig], but code dereferences unconditionally; NPE risk if future callers pass None.
- self.decoding_config = decoding_config if decoding_config else DecodingConfig( - decoding_mode) - max_attn_window = kv_cache_config.max_attention_window + self.decoding_config = decoding_config if decoding_config else DecucingConfig( + decoding_mode) + max_attn_window = getattr(kv_cache_config, "max_attention_window", None)
🧹 Nitpick comments (3)
tensorrt_llm/_torch/pyexecutor/_util.py (3)
674-681: Type hints: speculative_config is optional.Both the call sites and implementation handle None; reflect that in annotations.
-def create_torch_sampler_args(mapping: Mapping, *, max_seq_len: int, - enable_mixed_sampler: bool, max_batch_size: int, - speculative_config: SpeculativeConfig, - max_beam_width: int): +def create_torch_sampler_args(mapping: Mapping, *, max_seq_len: int, + enable_mixed_sampler: bool, max_batch_size: int, + speculative_config: Optional[SpeculativeConfig], + max_beam_width: int):
690-697: Allow None for decoding_config in signatures.Call sites may pass None; code already guards. Update annotations.
-def instantiate_sampler(engine: PyTorchModelEngine, - pytorch_backend_config: PyTorchConfig, mapping: Mapping, - max_batch_size: int, max_beam_width: int, - max_seq_len: int, mm_encoder_only: bool, - speculative_config: SpeculativeConfig, - decoding_config: trtllm.DecodingConfig, - kv_cache_config: trtllm.KvCacheConfig): +def instantiate_sampler(engine: PyTorchModelEngine, + pytorch_backend_config: PyTorchConfig, mapping: Mapping, + max_batch_size: int, max_beam_width: int, + max_seq_len: int, mm_encoder_only: bool, + speculative_config: Optional[SpeculativeConfig], + decoding_config: Optional[trtllm.DecodingConfig], + kv_cache_config: trtllm.KvCacheConfig): @@ -def get_decoding_mode( - decoding_config: trtllm.DecodingConfig, +def get_decoding_mode( + decoding_config: Optional[trtllm.DecodingConfig], max_beam_width: int, ) -> DecodingMode:Also applies to: 736-742
10-11: Duplicate ModelConfig imports.Both absolute and relative imports bring in ModelConfig. Keep one for clarity.
-from tensorrt_llm._torch.model_config import ModelConfig @@ -from ..model_config import ModelConfigAlso applies to: 21-22
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
tensorrt_llm/_torch/pyexecutor/_util.py(2 hunks)tensorrt_llm/_torch/pyexecutor/py_executor_creator.py(5 hunks)tensorrt_llm/_torch/pyexecutor/sampler.py(7 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{h,hpp,hh,hxx,cpp,cxx,cc,cu,cuh,py}
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
Use only spaces, no tabs; indent with 4 spaces.
Files:
tensorrt_llm/_torch/pyexecutor/py_executor_creator.pytensorrt_llm/_torch/pyexecutor/_util.pytensorrt_llm/_torch/pyexecutor/sampler.py
**/*.py
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
**/*.py: Python code must target Python 3.8+.
Indent Python code with 4 spaces; do not use tabs.
Maintain module namespace when importing; prefer 'from package.subpackage import foo' then 'foo.SomeClass()' instead of importing the class directly.
Python filenames should be snake_case (e.g., some_file.py).
Python classes use PascalCase names.
Functions and methods use snake_case names.
Local variables use snake_case; prefix 'k' for variables that start with a number (e.g., k_99th_percentile).
Global variables use upper SNAKE_CASE prefixed with 'G' (e.g., G_MY_GLOBAL).
Constants use upper SNAKE_CASE (e.g., MY_CONSTANT).
Avoid shadowing variables from an outer scope.
Initialize all externally visible members of a class in the constructor.
Prefer docstrings for interfaces that may be used outside a file; comments for in-function or file-local interfaces.
Use Google-style docstrings for classes and functions (Sphinx-parsable).
Document attributes and variables inline so they render under the class/function docstring.
Avoid reflection when a simpler, explicit approach suffices (e.g., avoid dict(**locals()) patterns).
In try/except, catch the most specific exceptions possible.
For duck-typing try/except, keep the try body minimal and use else for the main logic.
Files:
tensorrt_llm/_torch/pyexecutor/py_executor_creator.pytensorrt_llm/_torch/pyexecutor/_util.pytensorrt_llm/_torch/pyexecutor/sampler.py
**/*.{cpp,cxx,cc,h,hpp,hh,hxx,cu,cuh,py}
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
Prepend the NVIDIA Apache-2.0 copyright header with current year to the top of all source files (e.g., .cpp, .h, .cu, .py).
Files:
tensorrt_llm/_torch/pyexecutor/py_executor_creator.pytensorrt_llm/_torch/pyexecutor/_util.pytensorrt_llm/_torch/pyexecutor/sampler.py
🧠 Learnings (3)
📚 Learning: 2025-08-26T09:37:10.463Z
Learnt from: jiaganc
PR: NVIDIA/TensorRT-LLM#7031
File: tensorrt_llm/bench/dataclasses/configuration.py:90-104
Timestamp: 2025-08-26T09:37:10.463Z
Learning: In TensorRT-LLM, the `get_pytorch_perf_config()` method returns `self.pytorch_config` which can contain default `cuda_graph_config` values, so `llm_args` may already have this config before the extra options processing.
Applied to files:
tensorrt_llm/_torch/pyexecutor/_util.py
📚 Learning: 2025-08-14T15:38:01.771Z
Learnt from: MatthiasKohl
PR: NVIDIA/TensorRT-LLM#6904
File: cpp/tensorrt_llm/pybind/thop/bindings.cpp:55-57
Timestamp: 2025-08-14T15:38:01.771Z
Learning: In TensorRT-LLM Python bindings, tensor parameter collections like mla_tensor_params and spec_decoding_tensor_params are kept as required parameters without defaults to maintain API consistency, even when it might affect backward compatibility.
Applied to files:
tensorrt_llm/_torch/pyexecutor/_util.py
📚 Learning: 2025-08-26T09:37:10.463Z
Learnt from: jiaganc
PR: NVIDIA/TensorRT-LLM#7031
File: tensorrt_llm/bench/dataclasses/configuration.py:90-104
Timestamp: 2025-08-26T09:37:10.463Z
Learning: In TensorRT-LLM's bench configuration, the `get_pytorch_perf_config()` method returns `self.pytorch_config` which is a Dict[str, Any] that can contain default values including `cuda_graph_config`, making the fallback `llm_args["cuda_graph_config"]` safe to use.
Applied to files:
tensorrt_llm/_torch/pyexecutor/_util.py
🧬 Code graph analysis (3)
tensorrt_llm/_torch/pyexecutor/py_executor_creator.py (2)
tensorrt_llm/_torch/pyexecutor/sampler.py (1)
TRTLLMSampler(780-1243)tensorrt_llm/_torch/pyexecutor/_util.py (1)
instantiate_sampler(690-733)
tensorrt_llm/_torch/pyexecutor/_util.py (3)
tensorrt_llm/llmapi/llm_args.py (2)
SamplerType(2116-2120)KvCacheConfig(961-1092)tensorrt_llm/_torch/pyexecutor/sampler.py (3)
TorchSampler(358-751)Args(374-379)TRTLLMSampler(780-1243)tensorrt_llm/bench/dataclasses/configuration.py (1)
DecodingConfig(121-148)
tensorrt_llm/_torch/pyexecutor/sampler.py (5)
tensorrt_llm/llmapi/llm_args.py (1)
KvCacheConfig(961-1092)tensorrt_llm/_torch/attention_backend/trtllm.py (2)
max_seq_len(561-571)max_seq_len(574-578)tensorrt_llm/bench/dataclasses/configuration.py (1)
DecodingConfig(121-148)cpp/include/tensorrt_llm/batch_manager/decoderBuffers.h (1)
DecoderInputBuffers(36-72)cpp/tensorrt_llm/batch_manager/decoderBuffers.cpp (1)
DecoderInputBuffers(33-52)
⏰ 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/pyexecutor/py_executor_creator.py (2)
430-441: Sampler instantiation parameterization looks right.Passing max_batch_size/max_beam_width/max_seq_len/decoding_config/kv_cache_config is aligned with the executor_config-less API.
506-507: Good: keep sampler.max_seq_len in sync after KV cache changes.The post-build updates prevent stale limits during estimation/finalization.
Also applies to: 569-571
tensorrt_llm/_torch/pyexecutor/sampler.py (1)
846-867: LGTM: state/store sized by explicit max_ params.*Decoder buffers and state now use max_batch_size/max_beam_width/max_seq_len; consistent with the refactor.
dd02e91 to
1d761e1
Compare
|
/bot run |
|
PR_Github #17835 [ run ] triggered by Bot |
|
PR_Github #17831 [ run ] completed with state |
|
PR_Github #17835 [ run ] completed with state |
|
/bot run |
|
PR_Github #17840 [ run ] triggered by Bot |
|
PR_Github #17840 [ run ] completed with state |
Signed-off-by: leslie-fang25 <leslief@nvidia.com>
1d761e1 to
a452c11
Compare
|
/bot run |
|
PR_Github #17856 [ run ] triggered by Bot |
|
PR_Github #17856 [ run ] completed with state |
|
/bot run |
|
PR_Github #17872 [ run ] triggered by Bot |
|
PR_Github #17872 [ run ] completed with state |
|
/bot run |
|
PR_Github #17878 [ run ] triggered by Bot |
|
PR_Github #17878 [ run ] completed with state |
achartier
left a 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.
LGTM
QiJune
left a 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.
LGTM
Summary by CodeRabbit
New Features
Bug Fixes
Refactor
Description
This PR mainly removes
executor_configininstantiate_sampler.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
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.