-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[None][feat] AutoDeploy: dive deeper into token generation bugs + enable_block_reuse #8108
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
Signed-off-by: Lucas Liebenwein <11156568+lucaslie@users.noreply.github.com>
Signed-off-by: Lucas Liebenwein <11156568+lucaslie@users.noreply.github.com>
Signed-off-by: Lucas Liebenwein <11156568+lucaslie@users.noreply.github.com>
Debug configurations
Sample output NOW--> highlights all fixes NOW with duplicate call to
|
Signed-off-by: Lucas Liebenwein <11156568+lucaslie@users.noreply.github.com>
Accuracy results and speed-ups from AD accuracy testtorch-opt,
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
📝 WalkthroughWalkthroughThe changes introduce KV cache configuration fields, add KV cache reuse validation and revised context slicing in the AutoDeploy executor, adjust internal attention interfaces to use reset values and unique index selection, pass kv_cache_config through unchanged in serving, tweak a default prompt sampling parameter, add a completion log on weight load, and update tests to resolve model paths dynamically. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant User as Client
participant Serve as CLI Serve
participant LLM as AutoDeployLLM
participant Exec as AD Executor
participant Cache as KV Cache Manager
User->>Serve: Start with args (includes kv_cache_config)
Serve->>LLM: AutoDeployLLM(**llm_args with kv_cache_config passthrough)
LLM->>Exec: Initialize executor
Exec->>Exec: Validate kv_cache_config
alt Both block_reuse and partial_reuse true
Exec-->>LLM: Raise RuntimeError
else Block reuse enabled
Exec-->>LLM: Log warning (possible SSM incompat)
end
Exec->>Cache: Construct with kv_cache_config
User->>LLM: Inference request
LLM->>Exec: Prepare inputs
Exec->>Exec: Slice context tokens from request.context_current_position
Exec->>Cache: Allocate/resolve KV blocks
Exec-->>User: Return outputs
sequenceDiagram
autonumber
participant Upstream as Sequence Builder
participant Attn as attention_interface.SequenceInfo
Upstream->>Attn: nest_sequences(...)
note right of Attn: Use reset_val per field
Attn->>Attn: _store_arg(name, tnsr_like, reset_val=?)
opt cache_loc / slot_idx
Attn->>Attn: _get_unique_value(occupied, max_val)
Attn-->>Attn: Assign neutral unique indices
end
Attn-->>Upstream: Stored args with new reset semantics
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ 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: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (6)
examples/auto_deploy/build_and_run_ad.py (1)
1-1: Add project license header.Per coding guidelines, prepend the NVIDIA Apache‑2.0 header (2025).
Apply:
+# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + """Main entrypoint to build, test, and prompt AutoDeploy inference models."""tensorrt_llm/_torch/auto_deploy/models/factory.py (1)
1-1: Add project license header.Please prepend the NVIDIA Apache‑2.0 header (2025).
+# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + """The model factory interface used by auto-deploy to build custom models."""tensorrt_llm/_torch/auto_deploy/shim/ad_executor.py (2)
64-68: Fix logging call formatting.
ad_logger.infois passed an extra arg without a%placeholder; message won’t includeself.num_blocks.- ad_logger.info("Using fake cache manager with head_dim=0 and num pages:", self.num_blocks) + ad_logger.info("Using fake cache manager with head_dim=0 and num pages: %s", self.num_blocks)
1-1: Add project license header.Please prepend the NVIDIA Apache‑2.0 header (2025).
+# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + from collections import defaultdicttensorrt_llm/_torch/auto_deploy/llm_args.py (1)
1-1: Add project license header.Please prepend the NVIDIA Apache‑2.0 header (2025).
+# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + from importlib.resources import filestensorrt_llm/_torch/auto_deploy/custom_ops/attention_interface.py (1)
1-1: Add project license header.Please prepend the NVIDIA Apache‑2.0 header (2025).
+# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + """Attention Interface to handle various attention operators and cache operations.
🧹 Nitpick comments (3)
tensorrt_llm/_torch/auto_deploy/shim/ad_executor.py (1)
339-342: Compact exception message (ruff TRY003).Use a single-line message to avoid multi-part string concatenation.
- raise RuntimeError( - f"enable_block_reuse with {enable_partial_reuse=} set to True is NOT supported" - " in AutoDeploy. Please set it to False." - ) + raise RuntimeError("enable_block_reuse with enable_partial_reuse=True is NOT supported in AutoDeploy. Set enable_partial_reuse to False.")tensorrt_llm/_torch/auto_deploy/custom_ops/attention_interface.py (2)
621-625: Avoid full-tensor fill on every store; fill only the tail.Filling the whole device tensor each call is O(N) over the max capacity and can regress perf. Fill only the unused tail.
- if reset_val is not None: - tnsr_device.fill_(reset_val) - tnsr_device[: len(tnsr_like)].copy_(tnsr_host, non_blocking=True) + if reset_val is not None and tnsr_device.numel() > len(tnsr_like): + tnsr_device[len(tnsr_like):].fill_(reset_val) + tnsr_device[:len(tnsr_like)].copy_(tnsr_host, non_blocking=True)
642-653: Make unique-value choice deterministic.
set.pop()is non-deterministic across runs. Prefer smallest free value for stability.- full_range = set(range(max_val)) - free_values = full_range - occupied + full_range = set(range(max_val)) + free_values = sorted(full_range - occupied) out_of_range = occupied - full_range assert not out_of_range, f"Out of range values: {out_of_range}" - return free_values.pop() if free_values else 0 + return free_values[0] if free_values else 0
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
examples/auto_deploy/build_and_run_ad.py(1 hunks)tensorrt_llm/_torch/auto_deploy/custom_ops/attention_interface.py(8 hunks)tensorrt_llm/_torch/auto_deploy/llm_args.py(2 hunks)tensorrt_llm/_torch/auto_deploy/models/factory.py(1 hunks)tensorrt_llm/_torch/auto_deploy/shim/ad_executor.py(2 hunks)tensorrt_llm/commands/serve.py(0 hunks)tests/integration/defs/accuracy/test_llm_api_autodeploy.py(2 hunks)
💤 Files with no reviewable changes (1)
- tensorrt_llm/commands/serve.py
🧰 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:
tests/integration/defs/accuracy/test_llm_api_autodeploy.pytensorrt_llm/_torch/auto_deploy/models/factory.pyexamples/auto_deploy/build_and_run_ad.pytensorrt_llm/_torch/auto_deploy/custom_ops/attention_interface.pytensorrt_llm/_torch/auto_deploy/llm_args.pytensorrt_llm/_torch/auto_deploy/shim/ad_executor.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:
tests/integration/defs/accuracy/test_llm_api_autodeploy.pytensorrt_llm/_torch/auto_deploy/models/factory.pyexamples/auto_deploy/build_and_run_ad.pytensorrt_llm/_torch/auto_deploy/custom_ops/attention_interface.pytensorrt_llm/_torch/auto_deploy/llm_args.pytensorrt_llm/_torch/auto_deploy/shim/ad_executor.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:
tests/integration/defs/accuracy/test_llm_api_autodeploy.pytensorrt_llm/_torch/auto_deploy/models/factory.pyexamples/auto_deploy/build_and_run_ad.pytensorrt_llm/_torch/auto_deploy/custom_ops/attention_interface.pytensorrt_llm/_torch/auto_deploy/llm_args.pytensorrt_llm/_torch/auto_deploy/shim/ad_executor.py
🧬 Code graph analysis (3)
tests/integration/defs/accuracy/test_llm_api_autodeploy.py (1)
tests/integration/defs/accuracy/accuracy_core.py (1)
LlmapiAccuracyTestHarness(844-855)
tensorrt_llm/_torch/auto_deploy/custom_ops/attention_interface.py (1)
tensorrt_llm/_torch/attention_backend/flashinfer.py (1)
page_size(185-189)
tensorrt_llm/_torch/auto_deploy/llm_args.py (1)
tensorrt_llm/llmapi/llm_args.py (2)
KvCacheConfig(1058-1192)Field(70-97)
🪛 Ruff (0.13.2)
tensorrt_llm/_torch/auto_deploy/shim/ad_executor.py
339-342: Avoid specifying long messages outside the exception class
(TRY003)
⏰ 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 (5)
tensorrt_llm/_torch/auto_deploy/models/factory.py (1)
238-238: Nice completion log.Good for tracing init time boundaries. No behavior change.
tests/integration/defs/accuracy/test_llm_api_autodeploy.py (1)
27-37: Good: prefer local model dir with hub fallback.Improves portability of CI and developer runs.
Also applies to: 41-42
tensorrt_llm/_torch/auto_deploy/custom_ops/attention_interface.py (1)
698-706: Potential aliasing on fallback when no free pages/slots exist.
_get_unique_value(...)=0when set is full can alias a real page/slot. In cudagraph-padded batches this could write over a valid location. Consider reserving a dedicated “padding” page/slot or repeating the last valid location explicitly for dummies.Would you run a cudagraph case where
b<b_cudagraphandnum_pages == occupiedto confirm no cache pollution? If needed, I can draft a minimal repro.tensorrt_llm/_torch/auto_deploy/llm_args.py (1)
307-311: Override kv_cache_config defaults: confirm no conflict with BaseLlmArgs.LlmArgs redefines kv_cache_config (tensorrt_llm/_torch/auto_deploy/llm_args.py:307–311). Repo search returned many KvCacheConfig usages but did not locate a BaseLlmArgs or another Field definition for kv_cache_config — verify this override does not shadow a base-field or cause duplicate Pydantic validators/serialization, ensure serving code reads the intended attribute, and if intentional either move the default to the base or add a short inline justification for forcing enable_partial_reuse=False.
examples/auto_deploy/build_and_run_ad.py (1)
65-65: Default top_k=None — confirm callers and tests expect thisSamplingParams allows top_k: Optional[int] = None (tensorrt_llm/sampling_params.py), but runtime handling is mixed and at least one code path will fail if scfg.top_k is None (tensorrt_llm/runtime/generation.py ~1356–1363 uses torch.full with scfg.top_k). Also demollm and pyexecutor treat None differently. Run unit tests/CI and targeted tests that exercise generation and the auto_deploy shim; if the change is intentional, either add guards where scfg.top_k may be None or restore an explicit numeric default in the example and document the behavioral change.
|
NOTE: I am assuming we have never hit accuracy issues in our accuracy benchmark before since we always hit cudagraph with a batch_size for which we exactly have a stored cudagraph and don't need rounding up (checked the logs for that) |
tensorrt_llm/_torch/auto_deploy/custom_ops/attention_interface.py
Outdated
Show resolved
Hide resolved
Signed-off-by: Lucas Liebenwein <11156568+lucaslie@users.noreply.github.com>
|
/bot run |
|
PR_Github #20541 [ run ] triggered by Bot |
|
PR_Github #20541 [ run ] completed with state |
|
/bot run --disable-fail-fast |
|
PR_Github #20552 [ run ] triggered by Bot |
|
PR_Github #20552 [ run ] completed with state |
|
/bot run |
1 similar comment
|
/bot run |
|
PR_Github #20565 [ run ] triggered by Bot |
|
PR_Github #20564 [ run ] triggered by Bot |
|
PR_Github #20565 [ run ] completed with state |
|
PR_Github #20564 [ run ] completed with state |
|
/bot run |
|
PR_Github #20576 [ run ] triggered by Bot |
|
PR_Github #20576 [ run ] completed with state |
…ble_block_reuse (NVIDIA#8108) Signed-off-by: Lucas Liebenwein <11156568+lucaslie@users.noreply.github.com>
Summary by CodeRabbit
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.
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.