Skip to content

Fix optimized binary op broadcast rank mismatch#21052

Open
Kilbex wants to merge 2 commits into
pytorch:mainfrom
Kilbex:fix-optimized-binary-broadcast-rank-10959
Open

Fix optimized binary op broadcast rank mismatch#21052
Kilbex wants to merge 2 commits into
pytorch:mainfrom
Kilbex:fix-optimized-binary-broadcast-rank-10959

Conversation

@Kilbex

@Kilbex Kilbex commented Jul 21, 2026

Copy link
Copy Markdown

Summary

The optimized last-dimension and planned broadcast paths resize out to one input's shape after the operator has already selected the broadcast target. When leading dimensions of size one make the target rank larger, that second resize tries to change the immutable rank and fails at runtime.

Resize out to the broadcast target in both paths and add regression coverage for add and mul in both argument orders.

Fixes #10959

Test plan

./cmake-out/kernels/test/optimized_kernels_test --gtest_brief=1

lintrunner kernels/optimized/cpu/binary_ops.cpp kernels/optimized/cpu/binary_ops.h kernels/test/op_add_test.cpp kernels/test/op_mul_test.cpp

cc @larryliu0820 @manuelcandales

The treat-as-1D path already resizes out to the broadcast target, but the last-dimension and planned broadcast paths still resize it to an operand shape. With leading dimensions of size one, that can change the immutable output rank and fail with InvalidArgument.

Use the broadcast target for those paths and cover both operand orders in add and mul.

Fixes pytorch#10959
@pytorch-bot

pytorch-bot Bot commented Jul 21, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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:

✅ No Failures

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

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

@meta-cla

meta-cla Bot commented Jul 21, 2026

Copy link
Copy Markdown

Hi @Kilbex!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jul 21, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: Kilbex / name: Maya Bennett (c10d441)

@Kilbex

Kilbex commented Jul 21, 2026

Copy link
Copy Markdown
Author

@pytorchbot label "release notes: ops & kernels"

@pytorch-bot pytorch-bot Bot added the release notes: ops & kernels Changes to the opset and any new / changed kernel implementations label Jul 21, 2026
@meta-cla

meta-cla Bot commented Jul 21, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 21, 2026
@Kilbex
Kilbex marked this pull request as ready for review July 21, 2026 06:43
@Kilbex
Kilbex requested a review from manuelcandales as a code owner July 21, 2026 06:43
@nil-is-all nil-is-all added module: kernels Issues related to kernel libraries and utilities, and code under kernels/ backend tester This bug was found by the backend test suite. labels Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend tester This bug was found by the backend test suite. CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. module: kernels Issues related to kernel libraries and utilities, and code under kernels/ release notes: ops & kernels Changes to the opset and any new / changed kernel implementations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimized add fails fails at runtime with rank error when broadcasting

2 participants