Skip to content

[https://nvbugs/6473161][fix] Detect v2 at the call site (is_v2 = is_call_function(node…#16624

Closed
trtllm-agent wants to merge 2 commits into
NVIDIA:mainfrom
tensorrt-cicd:repair-bot-bug6473161
Closed

[https://nvbugs/6473161][fix] Detect v2 at the call site (is_v2 = is_call_function(node…#16624
trtllm-agent wants to merge 2 commits into
NVIDIA:mainfrom
tensorrt-cicd:repair-bot-bug6473161

Conversation

@trtllm-agent

@trtllm-agent trtllm-agent commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Root cause: remove_copy_for_mutates_args never propagated is_v2=True for auto_functionalized_v2 nodes, and the existing v2 reconstruction path keyed into _all_bases by op-arg position instead of the __base_index kwarg — so mutable args like 'query'/'key' were missing (KeyError) or wrongly indexed (IndexError) under torch 2.11's AOT-autograd graph.
  • Fix: Detect v2 at the call site (is_v2 = is_call_function(node, auto_functionalized_v2)); in the v2 branch, resolve each mutable arg via node.kwargs[f"_{arg_name}_base_index"] into _all_bases, treating a None index as a None tensor so optional inplace args (e.g. output_sf) are preserved.
  • Automated fix generated by repair-bot

Test plan

  • Verify fix on the same GPU type as the original failure
  • Check for regressions in related tests

Links

Summary

Dev Engineer Review

  • Updated tensorrt_llm/_torch/compilation/remove_copy_pass.py to fix auto_functionalized_v2 handling in remove_copy_for_mutates_args:
    • The nested remove_functionalize_inner now detects auto_functionalized_v2 directly and rebuilds the mutates-args replacement tensors using node.kwargs["_all_bases"] plus per-arg _{arg_name}_base_index indices.
    • Optional mutable args are preserved as None when their _{arg_name}_base_index is None, preventing mis-indexed/missing outputs (e.g., query, key, output_sf) in Torch 2.11 AOT-autograd graphs.
  • Potential correctness issue to address: remove_functionalize_inner signature no longer accepts an is_v2 parameter, but the call still passes is_v2=... (would raise TypeError when the functionalization node path is executed). The callsite should be updated to stop passing is_v2.

QA Engineer Review

  • Test list updates:
    • tests/integration/test_lists/waives.txt: removed four waiver lines for full:L40S/accuracy/test_llm_api_pytorch.py::TestLlama3_1_8BInstruct::test_fp8_4gpus (and related test_fp8 coverage) with attn_backend=FLASHINFER and torch_compile=True, for fp8kv=False and fp8kv=True.
  • Verdict: needs follow-up (no CBTS coverage data provided for this change).

CI/Verification

  • CI was retried after initial L0 pipeline failures; the third run completed successfully (L0 pipeline #49439 success).

Torch 2.11 AOT-autograd emits auto_functionalized_v2 HOP nodes for
mutable-arg ops even when inductor's enable_auto_functionalized_v2 is
False (that flag only affects Inductor lowering). In v2 nodes, mutable
tensors live in _all_bases and each mutable arg has its own
_<name>_base_index kwarg; direct kwargs like 'query'/'key' are absent.

Previously remove_copy_for_mutates_args never set is_v2=True at the call
site, and the v2 branch itself keyed into _all_bases by the mutates_args
positional index (k-1) rather than by the _<name>_base_index kwarg,
which is unrelated to op-arg position. Both bugs together caused
KeyError('query') / IndexError on flashinfer_apply_rope_with_cos_sin_cache_inplace
and similar ops under torch.compile+FLASHINFER.

Detect auto_functionalized_v2 at the call site and, for each mutable
arg, resolve its base tensor via _<arg>_base_index into _all_bases,
mapping a missing/None index to None so optional mutable args are
preserved.

Signed-off-by: trtllm-agent <296075020+trtllm-agent@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The copy-removal pass now derives auto_functionalized_v2 mutation bases from per-argument indices. Four related L40S FP8 integration-test waivers are removed.

Changes

Functionalization copy removal

Layer / File(s) Summary
Update v2 mutation base mapping
tensorrt_llm/_torch/compilation/remove_copy_pass.py
The helper detects auto_functionalized_v2 nodes directly and selects mutation bases using per-argument base-index fields; an existing call still passes the removed is_v2 argument.
Remove obsolete integration waivers
tests/integration/test_lists/waives.txt
Four L40S FP8 FLASHINFER torch_compile waiver entries are removed for the Llama 3.1 test.

Estimated code review effort: 3 (Moderate) | ~15–30 minutes

Suggested reviewers: liji-nv

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is specific and matches the main change: fixing v2 detection at the call site for remove_copy_for_mutates_args.
Description check ✅ Passed The description covers the issue, fix, test plan, and bug link, but it omits the template's explicit Description, Test Coverage, and PR Checklist sections.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tensorrt_llm/_torch/compilation/remove_copy_pass.py (1)

20-20: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a precise return and mapping type annotation.

This non-returning helper lacks -> None, and dict hides the contract that keys are output indices and values are mutable argument names. The coding guidelines require every function to be annotated.

Suggested change
-    def remove_functionalize_inner(node: Node, mutates_args: dict):
+    def remove_functionalize_inner(
+        node: Node, mutates_args: dict[int, str]
+    ) -> None:

Based on learnings, this repository supports Python 3.10+ built-in generic annotations.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tensorrt_llm/_torch/compilation/remove_copy_pass.py` at line 20, Update
remove_functionalize_inner with a complete type signature: annotate its return
as None and replace the unparameterized mutates_args dict with a built-in
generic mapping whose keys are output indices and values are mutable argument
names, using the repository’s Python 3.10+ annotation style.

Sources: Coding guidelines, Learnings

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tensorrt_llm/_torch/compilation/remove_copy_pass.py`:
- Line 20: Update remove_functionalize_inner with a complete type signature:
annotate its return as None and replace the unparameterized mutates_args dict
with a built-in generic mapping whose keys are output indices and values are
mutable argument names, using the repository’s Python 3.10+ annotation style.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 57317104-0dfe-4fea-9826-6c48cff080fb

📥 Commits

Reviewing files that changed from the base of the PR and between 5d8a786 and e578919.

📒 Files selected for processing (2)
  • tensorrt_llm/_torch/compilation/remove_copy_pass.py
  • tests/integration/test_lists/waives.txt
💤 Files with no reviewable changes (1)
  • tests/integration/test_lists/waives.txt

@BowenFu BowenFu left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM — the fix detects auto_functionalized_v2 in-function and rebuilds the mutable-arg kwargs; the sole caller never set is_v2, so the v2 branch was dead/crashing (KeyError under torch 2.11) before, and non-v2 (auto_functionalized) nodes are byte-identical. Strictly a fix (un-waives 4 FLASHINFER+torch_compile tests).

@BowenFu
BowenFu marked this pull request as draft July 21, 2026 11:48
@BowenFu
BowenFu marked this pull request as ready for review July 21, 2026 11:49
@lori-ren

Copy link
Copy Markdown
Contributor

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60851 [ run ] triggered by Bot. Commit: e578919 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60851 [ run ] completed with state SUCCESS. Commit: e578919
/LLM/main/L0_MergeRequest_PR pipeline #49124 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@lori-ren

Copy link
Copy Markdown
Contributor

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60903 [ run ] triggered by Bot. Commit: e578919 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60903 [ run ] completed with state SUCCESS. Commit: e578919
/LLM/main/L0_MergeRequest_PR pipeline #49171 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@lori-ren

Copy link
Copy Markdown
Contributor

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61191 [ run ] triggered by Bot. Commit: e578919 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61191 [ run ] completed with state SUCCESS. Commit: e578919
/LLM/main/L0_MergeRequest_PR pipeline #49439 completed with status: 'SUCCESS'

CI Report

Link to invocation

Signed-off-by: Lori Ren <lorir@nvidia.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
tensorrt_llm/_torch/compilation/remove_copy_pass.py (1)

34-34: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add precise function annotations.

The nested helper is non-returning but lacks -> None, and bare dict does not describe its key/value types. Use precise Python 3.10+ annotations, such as dict[int, str].

As per coding guidelines, every function must be annotated and non-returning functions must use None as the return type.

Proposed fix
-    def remove_functionalize_inner(node: Node, mutates_args: dict):
+    def remove_functionalize_inner(
+        node: Node, mutates_args: dict[int, str]
+    ) -> None:
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tensorrt_llm/_torch/compilation/remove_copy_pass.py` at line 34, Update the
nested helper remove_functionalize_inner with a Python 3.10+ return annotation
of None and replace the bare mutates_args: dict annotation with the precise
key/value type dict[int, str], preserving its existing behavior.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tensorrt_llm/_torch/compilation/remove_copy_pass.py`:
- Line 34: Remove the stale is_v2 keyword argument from every call to
remove_functionalize_inner in the functionalized-node handling path, especially
the calls around lines 76-80. Keep the existing node and mutates_args arguments
unchanged so recognized nodes proceed to the copy-removal logic without a
TypeError.

---

Nitpick comments:
In `@tensorrt_llm/_torch/compilation/remove_copy_pass.py`:
- Line 34: Update the nested helper remove_functionalize_inner with a Python
3.10+ return annotation of None and replace the bare mutates_args: dict
annotation with the precise key/value type dict[int, str], preserving its
existing behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 0a8dd450-b121-40dd-9ccc-9aeaf990606f

📥 Commits

Reviewing files that changed from the base of the PR and between e578919 and 549dc03.

📒 Files selected for processing (1)
  • tensorrt_llm/_torch/compilation/remove_copy_pass.py

nodes_to_remove: list[Node] = []

def remove_functionalize_inner(node: Node, mutates_args: dict, is_v2=False):
def remove_functionalize_inner(node: Node, mutates_args: dict):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Remove the stale is_v2 keyword argument.

remove_functionalize_inner no longer accepts is_v2, but Lines 76-80 still pass it. Every recognized functionalized node will therefore fail with TypeError: unexpected keyword argument 'is_v2' before the copy-removal logic executes.

Proposed fix
         remove_functionalize_inner(
             node,
             inplace_map[inplace_func],
-            is_v2=node.target == auto_functionalized_v2,
         )

Also applies to: 76-80

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tensorrt_llm/_torch/compilation/remove_copy_pass.py` at line 34, Remove the
stale is_v2 keyword argument from every call to remove_functionalize_inner in
the functionalized-node handling path, especially the calls around lines 76-80.
Keep the existing node and mutates_args arguments unchanged so recognized nodes
proceed to the copy-removal logic without a TypeError.

@lori-ren

Copy link
Copy Markdown
Contributor

Closing as duplicated (see #16410, #16824)

@lori-ren lori-ren closed this Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants