pytorch - 💡(How to fix) Fix [Inductor] `get_non_view_def` in `pad_mm.py` never traverses through `getitem` nodes — dead code due to `node.op` vs `node.target` confusion [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
pytorch/pytorch#184410Fetched 2026-05-20 03:38:50
View on GitHub
Comments
0
Participants
1
Timeline
119
Reactions
0
Author
Participants
Timeline (top)
mentioned ×57subscribed ×57labeled ×5

Root Cause

In torch/_inductor/fx_passes/pad_mm.py, the function get_non_view_def() has a dead code branch intended to traverse through operator.getitem nodes. The branch never executes because it checks node.op is operator.getitem, but node.op is always a string (e.g. "call_function"), never a function object.

Fix Action

Fix

def get_non_view_def(node: torch.fx.Node) -> torch.fx.Node:
    if node.op == "call_function" and node.target is operator.getitem:
        return get_non_view_def(node.args[0])
    ...

Code Example

# torch/_inductor/fx_passes/pad_mm.py, line 364-375
def get_non_view_def(node: torch.fx.Node) -> torch.fx.Node:
    if node.op is operator.getitem:          # ← BUG: always False
        return get_non_view_def(node.args[0])

    if (
        node.op == "call_function"
        and isinstance(node.target, torch._ops.OpOverload)
        and utils.is_view(node.target)
    ):
        return get_non_view_def(node.all_input_nodes[0])

    return node

---

def get_non_view_def(node: torch.fx.Node) -> torch.fx.Node:
    if node.op == "call_function" and node.target is operator.getitem:
        return get_non_view_def(node.args[0])
    ...

---

PyTorch: 2.13.0.dev20260513+cu126
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

🐛 Describe the bug

In torch/_inductor/fx_passes/pad_mm.py, the function get_non_view_def() has a dead code branch intended to traverse through operator.getitem nodes. The branch never executes because it checks node.op is operator.getitem, but node.op is always a string (e.g. "call_function"), never a function object.

This causes should_exclude_padding_time() to potentially make suboptimal padding decisions when a matmul input comes from a multi-output operation (e.g. torch.sort, torch.max(dim=...)), since get_non_view_def stops at the getitem instead of traversing through it.

Code

# torch/_inductor/fx_passes/pad_mm.py, line 364-375
def get_non_view_def(node: torch.fx.Node) -> torch.fx.Node:
    if node.op is operator.getitem:          # ← BUG: always False
        return get_non_view_def(node.args[0])

    if (
        node.op == "call_function"
        and isinstance(node.target, torch._ops.OpOverload)
        and utils.is_view(node.target)
    ):
        return get_non_view_def(node.all_input_nodes[0])

    return node

node.op is always one of "placeholder", "call_function", "call_method", "call_module", "get_attr", "output". Comparing a string with operator.getitem via is always returns False.

Fix

def get_non_view_def(node: torch.fx.Node) -> torch.fx.Node:
    if node.op == "call_function" and node.target is operator.getitem:
        return get_non_view_def(node.args[0])
    ...

Impact

Performance only — this affects the pad_mm pass's heuristic for deciding whether to include padding overhead in benchmarks. Computation results are not affected.

Versions

Versions

PyTorch: 2.13.0.dev20260513+cu126

cc @jerryzh168 @chauhang @penguinwu @voznesenskym @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @aakhundov @coconutruben @jataylo

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING