-
Notifications
You must be signed in to change notification settings - Fork 2k
[https://nvbugs/5525849][fix] Cherry-pick to fix mismatch of max seq len between kv cache manager and dummy requests #7855
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
|
/bot run --disable-fail-fast |
📝 WalkthroughWalkthroughUpdates introduce lazy creation and synchronization of dummy context requests with max sequence length in KvCacheCreator, propagate max_seq_len from KV cache manager to executor configuration, and adjust dummy requests when SWA reduces max_seq_len. Resource manager logs now include computed max_tokens and memory details without changing logic. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant K as KvCacheCreator
participant EC as ExecutorConfig
participant KM as KVCacheManager
Note over K: Initialization
K->>K: __init__ (set _dummy_reqs = None)
Note over K: Token estimation
K->>K: _get_token_num_for_estimation()
alt _dummy_reqs is None
K->>K: Create dummy requests with len = max(1, _max_seq_len - 1)
end
Note over K,KM: KV cache manager path
K->>KM: _create_kv_cache_manager(...)
KM-->>K: return with max_seq_len
K->>EC: Set EC.max_seq_len = KM.max_seq_len
alt SWA enabled AND KM.max_seq_len < K._max_seq_len
K->>K: Regenerate dummy requests with len = max(1, KM.max_seq_len - 1)
K->>K: Update _max_seq_len = KM.max_seq_len
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20–30 minutes Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. 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
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
tensorrt_llm/_torch/pyexecutor/resource_manager.py (1)
1-1: Add NVIDIA Apache-2.0 header.Per coding guidelines, prepend the 2025 NVIDIA Apache-2.0 header to all source files.
+# 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/_util.py (1)
1-1: Add NVIDIA Apache-2.0 header.Per coding guidelines, prepend the 2025 NVIDIA Apache-2.0 header to all source files.
+# 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.
🧹 Nitpick comments (2)
tensorrt_llm/_torch/pyexecutor/resource_manager.py (1)
585-586: Fix GiB units and clarify the warning.Dividing by 1<<32 yields non-standard units. Use 1<<30 (or 1024**3). Also make the message explicit about user vs computed tokens.
- logger.warning( - f'Both free_gpu_memory_fraction and max_tokens are set (to {free_mem_fraction} and {max_tokens} with free memory {free_mem / (1 << 32)} of total memory {total_mem / (1<<32)}, respectively). The smaller value will be used.' - ) + computed_tokens = free_mem_fraction * free_mem / cache_size_bytes_per_token + chosen = min(kv_cache_config.max_tokens, computed_tokens) + logger.warning( + f"Both free_gpu_memory_fraction={free_mem_fraction} and max_tokens={kv_cache_config.max_tokens} are set. " + f"Free GPU memory {free_mem / (1 << 30):.2f} GiB / total {total_mem / (1 << 30):.2f} GiB. " + f"Using min={int(chosen)}." + )tensorrt_llm/_torch/pyexecutor/_util.py (1)
486-491: Regenerate dummy requests when max_seq_len changes in either direction.You only re-create when kv_cache_manager.max_seq_len decreases. If it increases, existing _dummy_reqs may underestimate capacity during estimation or warmup scenarios that expect alignment with the new max.
- if kv_cache_manager is not None: - if kv_cache_manager.max_seq_len < self._max_seq_len: - self._dummy_reqs = self._create_dummy_context_requests( - max(1, kv_cache_manager.max_seq_len - 1)) - self._max_seq_len = kv_cache_manager.max_seq_len + if kv_cache_manager is not None: + if kv_cache_manager.max_seq_len != self._max_seq_len: + self._dummy_reqs = self._create_dummy_context_requests( + max(1, kv_cache_manager.max_seq_len - 1)) + self._max_seq_len = kv_cache_manager.max_seq_len
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
tensorrt_llm/_torch/pyexecutor/_util.py(3 hunks)tensorrt_llm/_torch/pyexecutor/resource_manager.py(1 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/resource_manager.pytensorrt_llm/_torch/pyexecutor/_util.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/resource_manager.pytensorrt_llm/_torch/pyexecutor/_util.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/resource_manager.pytensorrt_llm/_torch/pyexecutor/_util.py
🧠 Learnings (3)
📚 Learning: 2025-08-14T21:04:50.248Z
Learnt from: thorjohnsen
PR: NVIDIA/TensorRT-LLM#6910
File: cpp/tensorrt_llm/batch_manager/kvCacheManager.cpp:0-0
Timestamp: 2025-08-14T21:04:50.248Z
Learning: In KV cache onboarding logic during prefill in cpp/tensorrt_llm/batch_manager/kvCacheManager.cpp, when calculating which blocks fall within the attention window, use getTokensPerBlock() to advance token indices rather than block->getUniqueTokens().size(), because the calculation needs to consider the post-prefill state where blocks will be filled to capacity, not their current token count.
Applied to files:
tensorrt_llm/_torch/pyexecutor/resource_manager.py
📚 Learning: 2025-08-20T06:56:02.889Z
Learnt from: eopXD
PR: NVIDIA/TensorRT-LLM#6768
File: cpp/tensorrt_llm/batch_manager/kvCacheManager.cpp:577-579
Timestamp: 2025-08-20T06:56:02.889Z
Learning: In cpp/tensorrt_llm/batch_manager/kvCacheManager.cpp, maxSequenceLength is now enforced as a non-optional argument in the BlockManager constructor, so concerns about std::nullopt defaulting to 0 are not applicable. When windowSize > maxSequenceLength, a warning should be added instead of handling optional parameter cases.
Applied to files:
tensorrt_llm/_torch/pyexecutor/resource_manager.py
📚 Learning: 2025-08-15T06:46:54.897Z
Learnt from: eopXD
PR: NVIDIA/TensorRT-LLM#6767
File: cpp/tensorrt_llm/batch_manager/kvCacheManager.cpp:0-0
Timestamp: 2025-08-15T06:46:54.897Z
Learning: In cpp/tensorrt_llm/batch_manager/kvCacheManager.cpp addToken function, newly allocated blocks are unshared by design. The beam search path in addToken (when sequence.getNumTokens() > windowSize) is currently broken/non-functional with SWA, so the block allocation doesn't follow a shared-then-unshared pattern.
Applied to files:
tensorrt_llm/_torch/pyexecutor/resource_manager.py
🧬 Code graph analysis (1)
tensorrt_llm/_torch/pyexecutor/_util.py (1)
tensorrt_llm/_torch/attention_backend/trtllm.py (2)
max_seq_len(566-576)max_seq_len(579-583)
🪛 Ruff (0.12.2)
tensorrt_llm/_torch/pyexecutor/_util.py
484-484: Undefined name executor_config
(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 (2)
tensorrt_llm/_torch/pyexecutor/_util.py (2)
76-76: LGTM: lazy init of _dummy_reqs.This matches the new lazy-creation flow and avoids unnecessary allocations in init.
199-201: LGTM: lazy creation of dummy requests on first use.The max(1, self._max_seq_len - 1) guard correctly avoids zero-length inputs.
Please confirm configure_kv_cache_capacity is only invoked after try_prepare_estimation (which initializes _dummy_reqs). If not guaranteed, add a defensive creation in configure_kv_cache_capacity before enqueue.
|
PR_Github #19268 [ run ] triggered by Bot |
|
/bot kill |
|
PR_Github #19292 [ kill ] triggered by Bot |
|
PR_Github #19268 [ run ] completed with state |
|
PR_Github #19292 [ kill ] completed with state |
|
/bot run --disable-fail-fast |
|
PR_Github #19300 [ run ] triggered by Bot |
562ed83 to
201b1fb
Compare
|
/bot kill |
|
/bot run --disable-fail-fast |
|
PR_Github #19300 [ run ] completed with state |
|
PR_Github #19350 [ kill ] triggered by Bot |
|
PR_Github #19350 [ kill ] completed with state |
|
PR_Github #19351 [ run ] triggered by Bot |
|
/bot kill |
|
PR_Github #19356 [ kill ] triggered by Bot |
|
PR_Github #19351 [ run ] completed with state |
|
PR_Github #19356 [ kill ] completed with state |
|
/bot run --disable-fail-fast |
|
PR_Github #19373 [ run ] triggered by Bot |
|
PR_Github #19373 [ run ] completed with state |
|
/bot run --disable-fail-fast |
|
PR_Github #19413 [ run ] triggered by Bot |
|
PR_Github #19413 [ run ] completed with state |
|
/bot run --only-multi-gpu-test --stage-list="DGX_B200-8_GPUs-PyTorch-1,GB200-4_GPUs-PyTorch-1" |
|
PR_Github #19437 [ run ] triggered by Bot |
|
PR_Github #19437 [ run ] completed with state |
|
GB200-4_GPUs-PyTorch-1 timed out. Need to rerun. |
|
/bot run --only-multi-gpu-test --stage-list="GB200-4_GPUs-PyTorch-1" |
|
PR_Github #19496 [ run ] triggered by Bot |
|
PR_Github #19496 [ run ] completed with state |
43737ea to
2b2dc5f
Compare
|
/bot skip --comment "all test cases have passed" |
|
PR_Github #19517 [ skip ] triggered by Bot |
…er and graph attn metadata (NVIDIA#7606) Signed-off-by: Hui Gao <huig@nvidia.com>
|
PR_Github #19517 [ skip ] completed with state |
2b2dc5f to
0862622
Compare
|
/bot run --disable-multi-gpu-test |
|
PR_Github #19522 [ run ] triggered by Bot |
|
PR_Github #19522 [ run ] completed with state |
|
PR_Github #19561 [ skip ] triggered by Bot |
|
PR_Github #19561 [ skip ] completed with state |
…len between kv cache manager and dummy requests (NVIDIA#7855) Signed-off-by: Hui Gao <huig@nvidia.com>
…len between kv cache manager and dummy requests (NVIDIA#7855) Signed-off-by: Hui Gao <huig@nvidia.com>
Summary by CodeRabbit
Bug Fixes
Chores
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
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.