Skip to content

[Inductor] Don't expand bias for addmm in max-autotune mode (#180270) - #180270

Closed
PaulZhang12 wants to merge 1 commit into
pytorch:mainfrom
PaulZhang12:export-D100670723
Closed

PaulZhang12 wants to merge 1 commit into
pytorch:mainfrom
PaulZhang12:export-D100670723

Conversation

@PaulZhang12

@PaulZhang12 PaulZhang12 commented Apr 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

Relanding D100157470

Test Plan: test_addmm_1d_bias_no_reinterpret_tensor

Differential Revision: D100670723

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

@pytorch-bot

pytorch-bot Bot commented Apr 13, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/180270

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 2 New Failures, 3 Unrelated Failures

As of commit 9053f3b with merge base d90db5c (image):

NEW FAILURES - The following jobs have failed:

FLAKY - The following job failed but was likely due to flakiness present on trunk:

UNSTABLE - The following jobs are marked as unstable, possibly due to flakiness on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot Bot added ciflow/b200 ciflow/h100 ciflow/inductor ciflow/rocm-mi300 Trigger "default" config CI on ROCm MI300 ciflow/torchtitan Run TorchTitan integration tests module: inductor labels Apr 13, 2026
@pytorch-bot

pytorch-bot Bot commented Apr 13, 2026

Copy link
Copy Markdown

This PR needs a release notes: label

If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@meta-codesync

meta-codesync Bot commented Apr 13, 2026

Copy link
Copy Markdown

@PaulZhang12 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D100670723.

@PaulZhang12 PaulZhang12 added the topic: not user facing topic category label Apr 13, 2026
@meta-codesync meta-codesync Bot changed the title [Inductor] Don't expand bias for addmm in max-autotune mode [Inductor] Don't expand bias for addmm in max-autotune mode (#180270) Apr 13, 2026
@meta-codesync

meta-codesync Bot commented Apr 13, 2026

Copy link
Copy Markdown

@PaulZhang12 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D100670723.

pytorch-bot Bot pushed a commit that referenced this pull request Apr 13, 2026
Summary:
Pull Request resolved: #180270

Relanding D100157470

Test Plan: `test_addmm_1d_bias_no_reinterpret_tensor`

Differential Revision: D100670723
PaulZhang12 added a commit to PaulZhang12/pytorch that referenced this pull request Apr 13, 2026
…180270)

Summary:
Pull Request resolved: pytorch#180270

Relanding D100157470

Test Plan: `test_addmm_1d_bias_no_reinterpret_tensor`

Differential Revision: D100670723
…180270)

Summary:
Pull Request resolved: pytorch#180270

Relanding D100157470

Test Plan: `test_addmm_1d_bias_no_reinterpret_tensor`

Differential Revision: D100670723
@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Apr 13, 2026
@facebook-github-tools

Copy link
Copy Markdown

@pytorchbot merge -i

(Initiating merge automatically since Phabricator Diff has merged, merging with -i because oss signals were bypassed internally)

@pytorchmergebot pytorchmergebot added Reverted ci-no-td Do not run TD on this PR labels Apr 14, 2026
tenpercent added a commit that referenced this pull request Apr 14, 2026
…e_addmm

PR #180270 fixes the bias handling in addmm max-autotune so that 1D bias
no longer needs to be manually reshaped to 2D with broadcast stride.

Generated-by: Claude Code (claude-opus-4-5-20251101)
@PaulZhang12

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge -i "unit test failure fixed in #180349"

@pytorch-bot

pytorch-bot Bot commented Apr 14, 2026

Copy link
Copy Markdown

❌ 🤖 pytorchbot command failed:

@pytorchbot: error: unrecognized arguments: unit test failure fixed in https://github.com/pytorch/pytorch/pull/180349

usage: @pytorchbot [-h]
                   
                   {merge,revert,rebase,label,drci,lint,fix-lint,apply-lint,cherry-pick}
                   ...

Try @pytorchbot --help for more info.

@PaulZhang12

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge -i

tenpercent added a commit that referenced this pull request Apr 14, 2026
…e_addmm

PR #180270 fixes the bias handling in addmm max-autotune so that 1D bias
no longer needs to be manually reshaped to 2D with broadcast stride.

Generated-by: Claude Code (claude-opus-4-5-20251101)
BoyuanFeng pushed a commit that referenced this pull request Apr 15, 2026
…#180270)

Summary:

Relanding D100157470

Test Plan: `test_addmm_1d_bias_no_reinterpret_tensor`

Differential Revision: D100670723

Pull Request resolved: #180270
Approved by: https://github.com/atalman
BoyuanFeng pushed a commit that referenced this pull request Apr 15, 2026
…180270) (#180270)"

This reverts commit 043b807.

Reverted #180270 on behalf of https://github.com/pytorch-auto-revert due to Reverted automatically by pytorch's autorevert, to avoid this behaviour add the tag autorevert: disable ([comment](#180270 (comment)))
BoyuanFeng pushed a commit that referenced this pull request Apr 15, 2026
…#180270)

Summary:

Relanding D100157470

Test Plan: `test_addmm_1d_bias_no_reinterpret_tensor`

Differential Revision: D100670723

Pull Request resolved: #180270
Approved by: https://github.com/atalman
pytorchmergebot pushed a commit to scotts/pytorch that referenced this pull request Apr 15, 2026
…180270) (pytorch#180270)

Summary:

Relanding D100157470

Test Plan: `test_addmm_1d_bias_no_reinterpret_tensor`

Differential Revision: D100670723

Pull Request resolved: pytorch#180270
Approved by: https://github.com/atalman
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…180270) (pytorch#180270)

Summary:

Relanding D100157470

Test Plan: `test_addmm_1d_bias_no_reinterpret_tensor`

Differential Revision: D100670723

Pull Request resolved: pytorch#180270
Approved by: https://github.com/atalman
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…ytorch#180270) (pytorch#180270)"

This reverts commit 043b807.

Reverted pytorch#180270 on behalf of https://github.com/pytorch-auto-revert due to Reverted automatically by pytorch's autorevert, to avoid this behaviour add the tag autorevert: disable ([comment](pytorch#180270 (comment)))
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…180270) (pytorch#180270)

Summary:

Relanding D100157470

Test Plan: `test_addmm_1d_bias_no_reinterpret_tensor`

Differential Revision: D100670723

Pull Request resolved: pytorch#180270
Approved by: https://github.com/atalman
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…180270) (pytorch#180270)

Summary:

Relanding D100157470

Test Plan: `test_addmm_1d_bias_no_reinterpret_tensor`

Differential Revision: D100670723

Pull Request resolved: pytorch#180270
Approved by: https://github.com/atalman
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…ytorch#180270) (pytorch#180270)"

This reverts commit 043b807.

Reverted pytorch#180270 on behalf of https://github.com/pytorch-auto-revert due to Reverted automatically by pytorch's autorevert, to avoid this behaviour add the tag autorevert: disable ([comment](pytorch#180270 (comment)))
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…180270) (pytorch#180270)

Summary:

Relanding D100157470

Test Plan: `test_addmm_1d_bias_no_reinterpret_tensor`

Differential Revision: D100670723

Pull Request resolved: pytorch#180270
Approved by: https://github.com/atalman
imperatormk added a commit to imperatormk/pytorch that referenced this pull request Sep 4, 2026
tuned_addmm read inp.get_stride()[0] and only then checked that the bias is
2-D, so a 0-dim bias raised IndexError out of the lowering. Short-circuit
evaluation cannot help when the guard follows the access it protects.

The bias reaches this line unexpanded since pytorch#180270, which is what made a
scalar bias able to get here at all.

Claude-Session: https://claude.ai/code/session_017VFnedDBoeAQRMCayVzTmt
pytorchmergebot pushed a commit that referenced this pull request Dec 1, 2026
)

## Linked issue or supporting maintainer

Fixes #204950

## BC-breaking?

No

## Summary (human written only)

Compiling with `max_autotune` crashes on the first call (`NameError: buf3`) when an `addmm` has a non-contiguous bias.
The reporter hit it through a 1x1 convolution.
The change makes the bias realized once, and in the autotune path the ATen candidates read the same buffer the templates do.
The plain non-autotune path is unchanged, and so is `beta == 0` without autotuning.

## Agent details (if applicable)

Used tool is Cursor with Claude Opus 5.5: produced repro that showed `buf3` being dropped as dead code, initial patch draft, the regression test, and the GPU verification scripts.

Since #180270, `tuned_addmm` realizes the bias twice: the GEMM templates read the copy `mm_args` expands, and the ATen choices read a separate `realize_inputs(inp)` copy. The `MultiTemplateBuffer` depends only on the first, so the second is eliminated as dead, and finalizing to the ATen choice (forced in the issue by a layout conflict on the weight) emits `extern_kernels.addmm(buf3, ...)` with `buf3` never computed. `inp_expanded` is now a stride-0 view of the realized bias, and with `beta == 0` the autotune-path ATen choices read the zeros the templates read. That keeps an `[N]` zeros fill even when ATen is the only choice; switching ATen to the zeros only when a template is added, as `tuned_baddbmm` does, is left for a follow-up.

<details>
<summary>Test results</summary>

Run on H100 and GB200 against a nightly at cb41f4e (Triton 3.9.0), with the new test added before the fix:

```
test_max_autotune.py -k "addmm or bias or extern", test_mmdecomp.py   H100                   GB200
before the fix                                                        291 passed, 4 failed   259 passed, 4 failed
after the fix                                                         295 passed             263 passed
```

The 4 failures before the fix are `test_addmm_strided_bias_extern_fallback` (`beta` 0 and 1, in `TestMaxAutotune` and `TestMaxAutotuneAsyncPipelined`); no other test changes result. The reproducer from #204950 raises `NameError` before the fix and matches eager after it on both GPUs, as do its variants with contiguous inputs, ATen-only and Triton-only GEMM backends, `benchmark_template_fusion=False`, and an `addmm` whose bias is a view of a Triton GEMM input.

</details>

Pull Request resolved: #205740
Approved by: https://github.com/eellison
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-no-td Do not run TD on this PR ciflow/b200 ciflow/h100 ciflow/inductor ciflow/rocm-mi300 Trigger "default" config CI on ROCm MI300 ciflow/torchtitan Run TorchTitan integration tests ciflow/trunk Trigger trunk jobs on your pull request fb-exported Merged meta-exported module: inductor Reverted topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants