Skip to content

[https://nvbugs/6478707][fix] detect v2 inside remove_functionalize_inner, resolve each mutates_args via…#16629

Open
trtllm-agent wants to merge 1 commit into
NVIDIA:mainfrom
tensorrt-cicd:repair-bot-bug6478707
Open

[https://nvbugs/6478707][fix] detect v2 inside remove_functionalize_inner, resolve each mutates_args via…#16629
trtllm-agent wants to merge 1 commit into
NVIDIA:mainfrom
tensorrt-cicd:repair-bot-bug6478707

Conversation

@trtllm-agent

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

Copy link
Copy Markdown
Collaborator

Summary

  • Root cause: remove_copy_pass never treated auto_functionalized_v2 HOP nodes as v2, so kwargs["output"] raised KeyError since v2 stores mutable args in _all_bases
  • Fix: detect v2 inside remove_functionalize_inner, resolve each mutates_args via _<arg>_base_index into _all_bases (None-safe), and register the two additional mla_custom_op_inplace mutable args (dsv4_output, dsv4_output_sf) in inplace_info
  • 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

Dev Engineer Review

  • Updated remove_copy_pass handling for auto_functionalized_v2 nodes to resolve mutable arguments through _all_bases using _<arg>_base_index, including None handling.
  • Registered dsv4_output and dsv4_output_sf as mutable outputs for mla_custom_op_inplace.
  • Addresses KeyError failures caused by v2 nodes storing mutable arguments indirectly.
  • No configuration, public API, or test-list changes identified.

QA Engineer Review

No test changes.

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: fa000fff-29f0-4f13-8592-ba79e49700d3

📥 Commits

Reviewing files that changed from the base of the PR and between d7dfd7f and 613e5eb.

📒 Files selected for processing (1)
  • tensorrt_llm/_torch/compilation/utils.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • tensorrt_llm/_torch/compilation/utils.py

Walkthrough

The MLA custom operation’s inplace metadata now records dsv4_output and dsv4_output_sf alongside the existing output entry.

Changes

MLA inplace metadata

Layer / File(s) Summary
Additional mutated output mappings
tensorrt_llm/_torch/compilation/utils.py
mla_custom_op_inplace now maps indices 2 and 3 to dsv4_output and dsv4_output_sf.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Suggested reviewers: brnguyen2, mikeiovine, tburt-nv

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is specific and matches the main fix: v2 detection and mutable-arg resolution in remove_functionalize_inner.
Description check ✅ Passed The description covers summary, test plan, and bug link, but it does not follow the full template sections exactly.
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.

@mikeiovine
mikeiovine requested review from mikeiovine and removed request for pcastonguay and schetlur-nv July 20, 2026 15:22
@lori-ren

Copy link
Copy Markdown
Contributor

Some changes are already done by #16624, should we merge #16624 before this one?

@JunyiXu-nv

Copy link
Copy Markdown
Collaborator

Some changes are already done by #16624, should we merge #16624 before this one?

I see. I'll hold this PR before #16624 get merged.

Torch 2.12 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 'output' are absent.

Previously remove_copy_for_mutates_args never detected v2 nodes at the
call site, so kwargs["output"] raised KeyError. The v2 branch itself
keyed into _all_bases by mutates_args positional index (k-1) rather
than by the _<name>_base_index kwarg, which is unrelated to op-arg
position.

Detect auto_functionalized_v2 inside the inner helper 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. Also register the two additional mutable args
(dsv4_output, dsv4_output_sf) for mla_custom_op_inplace in
inplace_info() so the reconstructed op call carries them.

This unblocks TestDeepSeekV3Lite::test_nvfp4_4gpus with torch_compile
under moe_backend=TRTLLM on B200.

Signed-off-by: trtllm-agent <296075020+trtllm-agent@users.noreply.github.com>
@trtllm-agent
trtllm-agent force-pushed the repair-bot-bug6478707 branch from d7dfd7f to 613e5eb Compare July 24, 2026 08:48
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.

5 participants