Skip to content

[https://nvbugs/5606166][fix] AutoDeploy: use tuples for cudagraph shape lookup#8772

Merged
MartinMarciniszyn merged 1 commit intoNVIDIA:release/1.1from
nv-auto-deploy:ll/release_shape_tuple_cudagraph
Oct 31, 2025
Merged

[https://nvbugs/5606166][fix] AutoDeploy: use tuples for cudagraph shape lookup#8772
MartinMarciniszyn merged 1 commit intoNVIDIA:release/1.1from
nv-auto-deploy:ll/release_shape_tuple_cudagraph

Conversation

@lucaslie
Copy link
Member

@lucaslie lucaslie commented Oct 30, 2025

Cherry-picked to release branch from #8658

Summary by CodeRabbit

  • Bug Fixes

    • Improved shape handling consistency in CUDA graph operations by normalizing shape key construction for batched inputs.
  • Tests

    • Enhanced CUDA graph batch size testing to better verify that the captured graph execution path is properly utilized across valid batch sizes.

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

@lucaslie lucaslie requested a review from a team as a code owner October 30, 2025 00:30
@lucaslie lucaslie self-assigned this Oct 30, 2025
@lucaslie lucaslie moved this from Backlog to In review in AutoDeploy Board Oct 30, 2025
@lucaslie
Copy link
Member Author

/bot run

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 30, 2025

📝 Walkthrough

Walkthrough

This change normalizes shape keys in torch CUDA graph capture to use explicit tuples and updates a test to force execution of the captured graph path instead of the underlying model's forward method.

Changes

Cohort / File(s) Summary
CUDA Graph Shape Normalization
tensorrt_llm/_torch/auto_deploy/compile/backends/torch_cudagraph.py
Converts input shapes to tuples using tuple(input.shape) and tuple(input.shape[1:]) when building graph dictionary keys to ensure consistent tuple-type keys instead of PyTorch shape objects across batched inputs.
Test Enhancement for Graph Path Verification
tests/unittest/_torch/auto_deploy/unit/singlegpu/compile/test_cuda_graph_batch_sizes.py
Adds _raise_error_for_forward static helper method and updates test_forward_uses_cuda_graph_for_valid_batch_sizes to temporarily replace model forward with the helper, forcing the test to verify captured graph execution for various batch sizes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify that converting shapes to tuples does not break downstream graph lookups or comparison logic
  • Confirm the test mock correctly validates that the captured graph path is invoked and not the underlying model forward
  • Check that the temporary helper replacement and restoration in the test does not introduce side effects

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The PR description is largely incomplete and does not meet the repository's template requirements. While the structural template is present, the critical "Description" and "Test Coverage" sections are entirely empty, containing only placeholder comments. The only substantive content provided is "Cherry-picked to release branch from #8658," which is insufficient to explain what changes are being made, why they are necessary, or what tests validate the changes. The PR Checklist is marked as complete but provides no explanations of the reviewed items. Without these key sections filled out, reviewers lack essential context about the fix for CUDA graph shape lookup, even though the raw summary indicates specific technical changes were made. The author should complete the PR description by filling in the "Description" section to explain the issue being fixed (shape lookup inconsistency in CUDA graphs) and the solution (converting shapes to tuples), and the "Test Coverage" section should list the specific tests that validate these changes, particularly test_forward_uses_cuda_graph_for_valid_batch_sizes which was modified. Each checklist item should also be individually verified and explained rather than simply checking a single box.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title "[https://nvbugs/5606166][fix] AutoDeploy: use tuples for cudagraph shape lookup" directly aligns with the primary changes in the changeset. According to the raw summary, the code modifications convert input shapes to tuples when building combined shapes in the torch_cudagraph.py file to ensure consistent shape key handling. The title is specific, clear, and follows the required template format with the NVBugs ticket, type indicator, and descriptive summary. A reviewer scanning the history would immediately understand that this PR addresses a shape lookup consistency issue in AutoDeploy's CUDA graph functionality.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • 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

Comment @coderabbitai help to get the list of available commands and usage tips.

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

🧹 Nitpick comments (1)
tensorrt_llm/_torch/auto_deploy/compile/backends/torch_cudagraph.py (1)

145-145: LGTM! Explicit tuple conversion matches the pattern from line 127.

The explicit tuple() conversion ensures consistent shape key types for graph lookup, preventing potential mismatches between torch.Size and plain tuples.

Optional: The static analysis tool suggests using iterable unpacking instead of tuple concatenation for a minor style improvement:

 rounded_shapes = [
-    (self.round_to_cuda_batch_size(input.shape[0]),) + tuple(input.shape[1:])
+    (*((self.round_to_cuda_batch_size(input.shape[0]),),), *input.shape[1:])
     for input in args_batched
 ]

However, the current form is clear and readable, so this refactor is entirely optional.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ec510ad and 8f2b8be.

📒 Files selected for processing (2)
  • tensorrt_llm/_torch/auto_deploy/compile/backends/torch_cudagraph.py (2 hunks)
  • tests/unittest/_torch/auto_deploy/unit/singlegpu/compile/test_cuda_graph_batch_sizes.py (2 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/auto_deploy/compile/backends/torch_cudagraph.py
  • tests/unittest/_torch/auto_deploy/unit/singlegpu/compile/test_cuda_graph_batch_sizes.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/auto_deploy/compile/backends/torch_cudagraph.py
  • tests/unittest/_torch/auto_deploy/unit/singlegpu/compile/test_cuda_graph_batch_sizes.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/auto_deploy/compile/backends/torch_cudagraph.py
  • tests/unittest/_torch/auto_deploy/unit/singlegpu/compile/test_cuda_graph_batch_sizes.py
🧠 Learnings (2)
📚 Learning: 2025-10-20T17:09:21.560Z
Learnt from: nvchenghaoz
PR: NVIDIA/TensorRT-LLM#8469
File: tensorrt_llm/_torch/auto_deploy/transform/library/rms_norm.py:180-182
Timestamp: 2025-10-20T17:09:21.560Z
Learning: In tensorrt_llm/_torch/auto_deploy/transform/library/rms_norm.py, the _gated_rmsnorm_replacement function does not need to cast the output of torch.ops.auto_deploy.torch_rmsnorm_gated back to the input dtype, even though the custom op returns fp32. The dtype handling is managed elsewhere or the fp32 output is acceptable for downstream consumers.

Applied to files:

  • tensorrt_llm/_torch/auto_deploy/compile/backends/torch_cudagraph.py
📚 Learning: 2025-09-04T07:33:10.618Z
Learnt from: MrGeva
PR: NVIDIA/TensorRT-LLM#7219
File: tensorrt_llm/_torch/auto_deploy/compile/backends/torch_cudagraph.py:162-168
Timestamp: 2025-09-04T07:33:10.618Z
Learning: When users explicitly provide cuda_graph_batch_sizes in TorchCudagraphCompiler, respect their choices and only sanitize the values (clamp, dedupe, sort) without forcing additional batch sizes like 1 or max_batch_size. Only add commonly-used batch sizes when falling back to the heuristic.

Applied to files:

  • tests/unittest/_torch/auto_deploy/unit/singlegpu/compile/test_cuda_graph_batch_sizes.py
🧬 Code graph analysis (1)
tests/unittest/_torch/auto_deploy/unit/singlegpu/compile/test_cuda_graph_batch_sizes.py (1)
tensorrt_llm/_torch/auto_deploy/compile/backends/torch_cudagraph.py (1)
  • forward (130-164)
🪛 Ruff (0.14.2)
tensorrt_llm/_torch/auto_deploy/compile/backends/torch_cudagraph.py

145-145: Consider iterable unpacking instead of concatenation

Replace with iterable unpacking

(RUF005)

tests/unittest/_torch/auto_deploy/unit/singlegpu/compile/test_cuda_graph_batch_sizes.py

39-39: Unused static method argument: args

(ARG004)


39-39: Unused static method argument: kwargs

(ARG004)


40-40: 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 (3)
tensorrt_llm/_torch/auto_deploy/compile/backends/torch_cudagraph.py (1)

127-127: LGTM! Explicit tuple conversion ensures consistent dictionary keys.

Converting input.shape (a torch.Size object) to an explicit tuple ensures reliable hashing and equality checks when using combined_shape as a dictionary key in self.graphs.

tests/unittest/_torch/auto_deploy/unit/singlegpu/compile/test_cuda_graph_batch_sizes.py (2)

38-40: LGTM! Test helper correctly forces CUDA graph path.

The _raise_error_for_forward helper is well-designed to ensure that the test exercises the captured graph path by preventing fallback to the model's forward method.

Note: The static analysis warnings about unused arguments and long error messages are false positives in this test context—the signature must match forward(*args, **kwargs) for the substitution to work correctly.


204-210: LGTM! Test modification correctly validates CUDA graph usage.

The temporary replacement of captured_graph.model.forward with the error-raising helper effectively verifies that the captured CUDA graph path is exercised. The try/finally block ensures proper cleanup.

This test change complements the shape key normalization fix in the main file by confirming that graph lookup works correctly for various batch sizes.

@tensorrt-cicd
Copy link
Collaborator

PR_Github #22940 [ run ] triggered by Bot. Commit: 8f2b8be

@tensorrt-cicd
Copy link
Collaborator

PR_Github #22940 [ run ] completed with state SUCCESS. Commit: 8f2b8be
/LLM/release-1.1/L0_MergeRequest_PR pipeline #311 completed with status: 'FAILURE'

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

…ape lookup

Signed-off-by: Lucas Liebenwein <11156568+lucaslie@users.noreply.github.com>
@lucaslie lucaslie force-pushed the ll/release_shape_tuple_cudagraph branch from 8f2b8be to a024d81 Compare October 30, 2025 20:05
@lucaslie
Copy link
Member Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23086 [ run ] triggered by Bot. Commit: a024d81

@lucaslie
Copy link
Member Author

NOTE: wait until #8621 is merged

@tensorrt-cicd
Copy link
Collaborator

PR_Github #23086 [ run ] completed with state SUCCESS. Commit: a024d81
/LLM/release-1.1/L0_MergeRequest_PR pipeline #325 completed with status: 'SUCCESS'

@MartinMarciniszyn MartinMarciniszyn merged commit 752cc3a into NVIDIA:release/1.1 Oct 31, 2025
5 checks passed
@github-project-automation github-project-automation bot moved this from In review to Done in AutoDeploy Board Oct 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants