KEMBAR78
[None][feat] AutoDeploy: graph/module inputs with kwargs instead of args by lucaslie · Pull Request #8137 · NVIDIA/TensorRT-LLM · GitHub
Skip to content

Conversation

@lucaslie
Copy link
Member

@lucaslie lucaslie commented Oct 3, 2025

Summary by CodeRabbit

  • Refactor
    • Removed strict-forward mode and related configuration/transform to simplify setup.
    • Standardized keyword-argument handling across build, compile, export, and KV cache paths for consistent invocation.
  • Bug Fixes
    • Improved export robustness by safely handling missing positional arguments.
    • Increased stability during compilation and KV cache resizing via unified kwargs flow.
  • Tests
    • Updated unit tests to use keyword arguments and reflect the new invocation patterns.

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

Signed-off-by: Lucas Liebenwein <11156568+lucaslie@users.noreply.github.com>
@lucaslie lucaslie requested a review from a team as a code owner October 3, 2025 19:27
@lucaslie lucaslie requested a review from Fridah-nv October 3, 2025 19:27
@lucaslie lucaslie self-assigned this Oct 3, 2025
@lucaslie lucaslie moved this from Backlog to In review in AutoDeploy Board Oct 3, 2025
@lucaslie
Copy link
Member Author

lucaslie commented Oct 3, 2025

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #20611 [ run ] triggered by Bot

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 3, 2025

📝 Walkthrough

Walkthrough

The changes remove strict args-only forward mechanisms and the forward_with_cached_sequence_interface transform, standardize keyword-argument invocation across build/export/compile/runtime paths, adjust export APIs to accept optional args, update KV-cache metadata paths, and modify graph utilities’ defaults to favor kwargs. Tests and configs are aligned accordingly.

Changes

Cohort / File(s) Summary of changes
Config: remove strict-forward and CSI transform
tensorrt_llm/_torch/auto_deploy/config/default.yaml, tensorrt_llm/_torch/auto_deploy/config/transformers.yaml
Removed use_strict_forward flags and the forward_with_cached_sequence_interface transform blocks/settings.
Remove CSI transform implementation
tensorrt_llm/_torch/auto_deploy/transform/library/forward_with_cached_sequence_interface.py
Deleted transform, config, wrapper, registry, and apply logic for forward_with_cached_sequence_interface.
Build/Export/Compile: switch to kwargs
tensorrt_llm/_torch/auto_deploy/transform/library/build_model.py, .../export_to_gm.py, .../compile_model.py
Dropped use_strict_forward config/enforcement; export/compile now pass args=() and kwargs=cm.named_args; dynamic shapes sourced from named_dynamic_shapes.
Export API: args optional
tensorrt_llm/_torch/auto_deploy/export/export.py
torch_export_to_gm now accepts args: Optional[Tuple]; internal handling defaults to empty tuple/dict when None.
Factories: remove strict-forward patching
tensorrt_llm/_torch/auto_deploy/models/factory.py, .../models/hf.py, .../models/mistral3.py
Removed _set_strict_forward and _strict_forward helpers from factory classes, including VLM-specific variant.
KV cache transform: kwargs and metadata inputs
tensorrt_llm/_torch/auto_deploy/transform/library/kvcache.py
Uses cm.info.args_for_prepare_metadata and cm.info.const_args_for_prepare_metadata; removed args_only config and _run_forward; always calls gm(**cm.named_args).
Attention interface: metadata arg split
tensorrt_llm/_torch/auto_deploy/custom_ops/attention_interface.py
Added Constant alias; introduced args_for_prepare_metadata property; updated const_args_for_prepare_metadata to align; removed duplicate alias.
Graph utilities: default kwargs
tensorrt_llm/_torch/auto_deploy/transformations/_graph.py
add_graph_input now defaults add_kwargs=True.
Runtime shim: kwargs invocation
tensorrt_llm/_torch/auto_deploy/shim/ad_executor.py
ADEngine calls model via **named_args instead of positional cm.
Tests: align with kwargs and removals
tests/unittest/_torch/auto_deploy/unit/singlegpu/models/test_llama4_vlm_patch.py, .../shim/test_engine.py, .../transformations/library/test_kv_cache.py
Removed strict-forward usage; switched model/export calls to kwargs; adjusted signatures/returns in test shim model.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User/Config
  participant Factory as ModelFactory
  participant GM as Export(torch_export_to_gm)
  participant Comp as Compile Backend
  participant Run as ADEngine/Runtime

  U->>Factory: build_model(...)
  Note over Factory: No strict-forward patching
  Factory-->>U: nn.Module

  U->>GM: torch_export_to_gm(model, args=(), kwargs=named_args, dynamic_shapes=named_dynamic_shapes)
  GM-->>U: GraphModule

  U->>Comp: compile(gm, args=(), kwargs=named_args, ...)
  Comp-->>U: Compiled artifact

  U->>Run: execute(named_args)
  Run->>Run: model(**named_args)
  Run-->>U: logits
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description remains the unpopulated template without any summary, Description content, or Test Coverage details and thus fails to explain the issue, the solution, or the tests that validate the changes. Please replace the template placeholders with an actual summary of the changes, fill in the Description section with a concise explanation of the problem and the solution, and list the relevant test cases under Test Coverage to ensure the PR is self-contained and reviewable.
Docstring Coverage ⚠️ Warning Docstring coverage is 42.11% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The title “[None][feat] AutoDeploy: graph/module inputs with kwargs instead of args” succinctly follows the required template and accurately captures the core change of switching from positional to keyword arguments for graph and module inputs. It is concise, specific, and directly related to the main theme of the pull request.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent 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 38da871 and 0aed9b8.

📒 Files selected for processing (17)
  • tensorrt_llm/_torch/auto_deploy/config/default.yaml (0 hunks)
  • tensorrt_llm/_torch/auto_deploy/config/transformers.yaml (0 hunks)
  • tensorrt_llm/_torch/auto_deploy/custom_ops/attention_interface.py (2 hunks)
  • tensorrt_llm/_torch/auto_deploy/export/export.py (2 hunks)
  • tensorrt_llm/_torch/auto_deploy/models/factory.py (0 hunks)
  • tensorrt_llm/_torch/auto_deploy/models/hf.py (0 hunks)
  • tensorrt_llm/_torch/auto_deploy/models/mistral3.py (0 hunks)
  • tensorrt_llm/_torch/auto_deploy/shim/ad_executor.py (1 hunks)
  • tensorrt_llm/_torch/auto_deploy/transform/library/build_model.py (0 hunks)
  • tensorrt_llm/_torch/auto_deploy/transform/library/compile_model.py (1 hunks)
  • tensorrt_llm/_torch/auto_deploy/transform/library/export_to_gm.py (1 hunks)
  • tensorrt_llm/_torch/auto_deploy/transform/library/forward_with_cached_sequence_interface.py (0 hunks)
  • tensorrt_llm/_torch/auto_deploy/transform/library/kvcache.py (2 hunks)
  • tensorrt_llm/_torch/auto_deploy/transformations/_graph.py (1 hunks)
  • tests/unittest/_torch/auto_deploy/unit/singlegpu/models/test_llama4_vlm_patch.py (2 hunks)
  • tests/unittest/_torch/auto_deploy/unit/singlegpu/shim/test_engine.py (2 hunks)
  • tests/unittest/_torch/auto_deploy/unit/singlegpu/transformations/library/test_kv_cache.py (2 hunks)
💤 Files with no reviewable changes (7)
  • tensorrt_llm/_torch/auto_deploy/config/transformers.yaml
  • tensorrt_llm/_torch/auto_deploy/models/hf.py
  • tensorrt_llm/_torch/auto_deploy/config/default.yaml
  • tensorrt_llm/_torch/auto_deploy/transform/library/build_model.py
  • tensorrt_llm/_torch/auto_deploy/models/mistral3.py
  • tensorrt_llm/_torch/auto_deploy/models/factory.py
  • tensorrt_llm/_torch/auto_deploy/transform/library/forward_with_cached_sequence_interface.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/unittest/_torch/auto_deploy/unit/singlegpu/transformations/library/test_kv_cache.py
  • tests/unittest/_torch/auto_deploy/unit/singlegpu/models/test_llama4_vlm_patch.py
  • tensorrt_llm/_torch/auto_deploy/shim/ad_executor.py
  • tensorrt_llm/_torch/auto_deploy/transform/library/compile_model.py
  • tensorrt_llm/_torch/auto_deploy/transformations/_graph.py
  • tests/unittest/_torch/auto_deploy/unit/singlegpu/shim/test_engine.py
  • tensorrt_llm/_torch/auto_deploy/custom_ops/attention_interface.py
  • tensorrt_llm/_torch/auto_deploy/transform/library/export_to_gm.py
  • tensorrt_llm/_torch/auto_deploy/transform/library/kvcache.py
  • tensorrt_llm/_torch/auto_deploy/export/export.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/unittest/_torch/auto_deploy/unit/singlegpu/transformations/library/test_kv_cache.py
  • tests/unittest/_torch/auto_deploy/unit/singlegpu/models/test_llama4_vlm_patch.py
  • tensorrt_llm/_torch/auto_deploy/shim/ad_executor.py
  • tensorrt_llm/_torch/auto_deploy/transform/library/compile_model.py
  • tensorrt_llm/_torch/auto_deploy/transformations/_graph.py
  • tests/unittest/_torch/auto_deploy/unit/singlegpu/shim/test_engine.py
  • tensorrt_llm/_torch/auto_deploy/custom_ops/attention_interface.py
  • tensorrt_llm/_torch/auto_deploy/transform/library/export_to_gm.py
  • tensorrt_llm/_torch/auto_deploy/transform/library/kvcache.py
  • tensorrt_llm/_torch/auto_deploy/export/export.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/unittest/_torch/auto_deploy/unit/singlegpu/transformations/library/test_kv_cache.py
  • tests/unittest/_torch/auto_deploy/unit/singlegpu/models/test_llama4_vlm_patch.py
  • tensorrt_llm/_torch/auto_deploy/shim/ad_executor.py
  • tensorrt_llm/_torch/auto_deploy/transform/library/compile_model.py
  • tensorrt_llm/_torch/auto_deploy/transformations/_graph.py
  • tests/unittest/_torch/auto_deploy/unit/singlegpu/shim/test_engine.py
  • tensorrt_llm/_torch/auto_deploy/custom_ops/attention_interface.py
  • tensorrt_llm/_torch/auto_deploy/transform/library/export_to_gm.py
  • tensorrt_llm/_torch/auto_deploy/transform/library/kvcache.py
  • tensorrt_llm/_torch/auto_deploy/export/export.py
🧬 Code graph analysis (7)
tests/unittest/_torch/auto_deploy/unit/singlegpu/transformations/library/test_kv_cache.py (3)
tensorrt_llm/_torch/auto_deploy/custom_ops/attention_interface.py (2)
  • named_args (286-295)
  • args (310-312)
tensorrt_llm/_torch/auto_deploy/shim/interface.py (2)
  • named_args (28-30)
  • args (23-25)
tensorrt_llm/_torch/auto_deploy/export/export.py (1)
  • torch_export_to_gm (198-273)
tensorrt_llm/_torch/auto_deploy/shim/ad_executor.py (2)
tensorrt_llm/_torch/auto_deploy/custom_ops/attention_interface.py (1)
  • named_args (286-295)
tensorrt_llm/_torch/auto_deploy/shim/interface.py (1)
  • named_args (28-30)
tensorrt_llm/_torch/auto_deploy/transform/library/compile_model.py (2)
tensorrt_llm/_torch/auto_deploy/custom_ops/attention_interface.py (2)
  • args (310-312)
  • named_args (286-295)
tensorrt_llm/_torch/auto_deploy/shim/interface.py (2)
  • args (23-25)
  • named_args (28-30)
tests/unittest/_torch/auto_deploy/unit/singlegpu/shim/test_engine.py (2)
tests/unittest/_torch/auto_deploy/unit/singlegpu/transformations/library/test_kv_cache.py (1)
  • forward (57-86)
tests/unittest/_torch/auto_deploy/_utils_test/_model_test_utils.py (9)
  • forward (75-95)
  • forward (107-109)
  • forward (131-136)
  • forward (155-160)
  • forward (185-204)
  • forward (221-223)
  • forward (233-235)
  • forward (248-254)
  • forward (273-276)
tensorrt_llm/_torch/auto_deploy/transform/library/export_to_gm.py (1)
tensorrt_llm/_torch/auto_deploy/custom_ops/attention_interface.py (4)
  • args (310-312)
  • named_args (286-295)
  • dynamic_shapes (372-374)
  • named_dynamic_shapes (347-369)
tensorrt_llm/_torch/auto_deploy/transform/library/kvcache.py (3)
tensorrt_llm/_torch/auto_deploy/transform/library/kvcache_transformers.py (1)
  • _process_get_metadata (212-223)
tensorrt_llm/_torch/auto_deploy/custom_ops/attention_interface.py (3)
  • args_for_prepare_metadata (315-328)
  • const_args_for_prepare_metadata (331-344)
  • named_args (286-295)
tensorrt_llm/_torch/auto_deploy/shim/interface.py (1)
  • named_args (28-30)
tensorrt_llm/_torch/auto_deploy/export/export.py (2)
tensorrt_llm/_torch/auto_deploy/custom_ops/attention_interface.py (1)
  • args (310-312)
tensorrt_llm/_torch/auto_deploy/transformations/_graph.py (1)
  • tree_to (71-75)
🪛 Ruff (0.13.2)
tests/unittest/_torch/auto_deploy/unit/singlegpu/shim/test_engine.py

25-25: Unused method argument: position_ids

(ARG002)

⏰ 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 (8)
tensorrt_llm/_torch/auto_deploy/transformations/_graph.py (1)

246-252: Validate add_graph_input call sites after default flip
In library/kvcache.py at lines 56 and 110, calls to add_graph_input(gm, name) now use add_kwargs=True by default. Verify these usages expect keyword-argument insertion or explicitly pass add_kwargs=False if they require the previous positional behavior.

tensorrt_llm/_torch/auto_deploy/export/export.py (2)

200-200: LGTM! Args parameter now optional.

Making args optional with a default of None aligns with the PR's shift toward keyword-argument-based invocation, where positional arguments may not be needed.


236-236: LGTM! Safe handling of optional args.

The pattern (args or (), kwargs or {}) correctly provides an empty tuple when args is None, ensuring tree_to receives valid inputs.

tensorrt_llm/_torch/auto_deploy/transform/library/kvcache.py (2)

160-162: LGTM! Metadata preparation updated correctly.

The metadata extraction now uses cm.info.args_for_prepare_metadata and cm.info.const_args_for_prepare_metadata, which provide a clear separation between tensor/node arguments and constant arguments. This aligns with the new interfaces defined in attention_interface.py.


277-277: LGTM! Simplified to kwargs-only invocation.

The forward pass now consistently uses gm(**cm.named_args), eliminating the conditional logic and removed _run_forward helper. This standardizes on keyword-argument invocation across the codebase.

tensorrt_llm/_torch/auto_deploy/custom_ops/attention_interface.py (3)

40-40: LGTM! Type alias for prepare_metadata constants.

The Constant type alias clearly defines the valid types for constant arguments passed to the prepare_metadata operation, which aligns with torch custom op restrictions.


315-328: LGTM! New property for tensor/node metadata arguments.

The args_for_prepare_metadata property provides the tensor/node argument names needed by the prepare_metadata operation. The implementation correctly returns keys from named_standard_args, and the docstring clearly explains its purpose and relationship with const_args_for_prepare_metadata.


331-344: LGTM! Updated constant arguments property.

The const_args_for_prepare_metadata property implementation is correct, returning constant values from _cached_constants. The updated docstring now references args_for_prepare_metadata, clearly documenting the two-part interface for metadata preparation.


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
Collaborator

@Fridah-nv Fridah-nv left a comment

Choose a reason for hiding this comment

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

LGTM.

@lucaslie lucaslie enabled auto-merge (squash) October 3, 2025 22:20
@tensorrt-cicd
Copy link
Collaborator

PR_Github #20611 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #15560 completed with status: 'SUCCESS'

@lucaslie lucaslie merged commit 9d098e3 into NVIDIA:main Oct 3, 2025
8 of 9 checks passed
@github-project-automation github-project-automation bot moved this from In review to Done in AutoDeploy Board Oct 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants