Skip to content

[inductor] Realize the addmm bias once for all autotune choices - #205740

Closed
oonyshch wants to merge 4 commits into
mainfrom
fix/inductor-addmm-noncontig-bias
Closed

oonyshch wants to merge 4 commits into
mainfrom
fix/inductor-addmm-noncontig-bias

Conversation

@oonyshch

@oonyshch oonyshch commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

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.

Test results

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.

@pytorch-bot

pytorch-bot Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

PR Status: Approved 🚀

Please fix all CI failures and trigger merge by commenting "@pytorchbot merge".

✅ AUTOMATED REVIEW - OUTDATED (earlier commit) - Ready for human review:

The PR realizes the addmm bias once, before mm_args, so on max-autotune a
MultiTemplateBuffer finalized to the extern ATen choice no longer reads a buffer
removed as dead code; the earlier blocking cpp_wrapper FileCheck failure is
fixed. Recommendation: Approve  the one remaining point is non-blocking test
hardening.

Findings (1):

[minor] test/inductor/test_max_autotune.py:1219
Non-blocking: in test_addmm_strided_bias_extern_fallback, the FileCheck shows
the ATen addmm kernel was emitted, but not that a MultiTemplateBuffer was
created and then finalized to it.
test_configs.force_extern_kernel_in_multi_template is only read in
Scheduler.finalize_multi_template_buffers. Without a MultiTemplateBuffer the
extern choice reads its own input and the bug can't occur, yet the FileCheck
still passes. No MultiTemplateBuffer is created if only one choice remains
(select_algorithm.py:4561-4565), TORCHINDUCTOR_BENCHMARK_TEMPLATE_FUSION=0 is
set, or deterministic is set. Fix: also assert the MultiTemplateBuffer exists,
like test_mutation_rename does (~lines 1850-1899): check "MultiTemplateBuffer"
in the ir_pre_fusion log and "ExternKernelSchedulerNode" in the ir_post_fusion
log. Mitigation: in today's CI the test does exercise the bug, because the suite
only runs under is_big_gpu() and the Triton template adds a second choice.

Reviewed commit: 427fd32 (NOT the current head c7292bf)

Review run

🐛 Report a bad review

🔗 Helpful Links

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

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

✅ No Failures

As of commit c7292bf with merge base 768d194 (image):
💚 Looks good so far! There are no failures yet. 💚

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 Nov 19, 2026
@oonyshch
oonyshch marked this pull request as ready for review November 21, 2026 17:24
@oonyshch oonyshch added the in progress PR is being worked on by the author, until the automated review accepts it label Nov 21, 2026
@oonyshch

Copy link
Copy Markdown
Collaborator Author

@pytorchbot review

@pytorch-bot pytorch-bot Bot added in progress PR is being worked on by the author, until the automated review accepts it and removed in progress PR is being worked on by the author, until the automated review accepts it labels Nov 21, 2026
github-actions[bot]

This comment was marked as outdated.

github-actions[bot]

This comment was marked as outdated.

@github-actions github-actions 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.

Automated review of 427fd32: nothing blocking; ready for human review.

The PR realizes the addmm bias once, before mm_args, so on max-autotune a MultiTemplateBuffer finalized to the extern ATen choice no longer reads a buffer removed as dead code; the earlier blocking cpp_wrapper FileCheck failure is fixed. Recommendation: Approve the one remaining point is non-blocking test hardening.

⚪ 1 non-blocking finding

FileCheck().check(addmm_call).run(code[0])

Non-blocking: in test_addmm_strided_bias_extern_fallback, the FileCheck shows the ATen addmm kernel was emitted, but not that a MultiTemplateBuffer was created and then finalized to it. test_configs.force_extern_kernel_in_multi_template is only read in Scheduler.finalize_multi_template_buffers. Without a MultiTemplateBuffer the extern choice reads its own input and the bug can't occur, yet the FileCheck still passes. No MultiTemplateBuffer is created if only one choice remains (select_algorithm.py:4561-4565), TORCHINDUCTOR_BENCHMARK_TEMPLATE_FUSION=0 is set, or deterministic is set. Fix: also assert the MultiTemplateBuffer exists, like test_mutation_rename does (~lines 1850-1899): check "MultiTemplateBuffer" in the ir_pre_fusion log and "ExternKernelSchedulerNode" in the ir_post_fusion log. Mitigation: in today's CI the test does exercise the bug, because the suite only runs under is_big_gpu() and the Triton template adds a second choice.

This review is AI-generated and advisory. Each new automated review replaces the previous one. Report a bad review

@github-actions
github-actions Bot dismissed stale reviews from themself November 21, 2026 20:12

Withdrawn: the automated review of 427fd32 found nothing blocking.

@pytorch-bot pytorch-bot Bot added ready for review Automated review passed, ready for a final review by a maintainer. and removed in progress PR is being worked on by the author, until the automated review accepts it labels Nov 21, 2026
@albanD albanD added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Nov 25, 2026
@oonyshch
oonyshch requested a review from eellison November 25, 2026 22:34
@eellison

Copy link
Copy Markdown
Contributor

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Nov 30, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: Remote end closed connection without response

Details for Dev Infra team

Raised by workflow job

@oonyshch

Copy link
Copy Markdown
Collaborator Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 2 jobs have failed, first few of them are: trunk / win-vs2022-cpu-py3 / test (default, 9, 12, windows.4xlarge.nonephemeral), trunk / win-vs2022-cpu-py3 / test (default, 11, 12, windows.4xlarge.nonephemeral)

Details for Dev Infra team

Raised by workflow job

@oonyshch

Copy link
Copy Markdown
Collaborator Author

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Successfully rebased fix/inductor-addmm-noncontig-bias onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via git checkout fix/inductor-addmm-noncontig-bias && git pull --rebase)

@pytorchmergebot
pytorchmergebot force-pushed the fix/inductor-addmm-noncontig-bias branch from 427fd32 to c7292bf Compare November 30, 2026 22:52
@oonyshch

Copy link
Copy Markdown
Collaborator Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

The merge job was canceled or timed out. This most often happen if two merge requests were issued for the same PR, or if merge job was waiting for more than 6 hours for tests to finish. In later case, please do not hesitate to reissue the merge command
For more information see pytorch-bot wiki.

@oonyshch

oonyshch commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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 Merged module: inductor open source ready for review Automated review passed, ready for a final review by a maintainer. release notes: inductor topic: bug fixes topic category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Inductor][CUDA] max_autotune generates an undefined buffer for a 1x1 convolution with non-contiguous tensors

5 participants