Skip to content

Fix bug in optimized mul's broadcast handling #11590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2025
Merged

Conversation

kimishpatel
Copy link
Contributor

Summary:
When we have two tensors that match exactly in size but not in dims, the output resize does not work correctly in cases like this a[6] b[1, 1, 6] -> out [1, 1, 6] but current code tried to resize using a.sizes()

Test Plan:
tests added

Reviewers:

Subscribers:

Tasks:

Tags:

Summary

[PLEASE REMOVE] See CONTRIBUTING.md's Pull Requests for ExecuTorch PR guidelines.

[PLEASE REMOVE] If this PR closes an issue, please add a Fixes #<issue-id> line.

[PLEASE REMOVE] If this PR introduces a fix or feature that should be the upcoming release notes, please add a "Release notes: " label. For a list of available release notes labels, check out CONTRIBUTING.md's Pull Requests.

Test plan

[PLEASE REMOVE] How did you test this PR? Please write down any manual commands you used and note down tests that you have written if applicable.

Copy link

pytorch-bot bot commented Jun 12, 2025

🔗 Helpful Links

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

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

✅ No Failures

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

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

@facebook-github-bot facebook-github-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 Jun 12, 2025
Copy link

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

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

// broadcasting rule dictate that the tensor whose dimensionality matches
// the output is the one that we should pick.
// e.g. a[6] and b[1, 1, 6] would imply out = [1, 1, 6], but if we resize
// via a we will crash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a good catch, but I think the original error was to use resize_tensor() in the first place when this op was updated to support broadcasting. The right function to use is resize_to_broadcast_target_size(a, b, out), which is already being used inside some of the if/else. This should be moved out and to the top, before the case work begins.
by the way, this same error is now present in your other PR for le

Summary:
When we have two tensors that match exactly in size but not in dims, the
output resize does not work correctly in cases like this a[6] b[1, 1, 6]
-> out [1, 1, 6] but current code tried to resize using a.sizes()

Test Plan:
tests added

Reviewers:

Subscribers:

Tasks:

Tags:
@kimishpatel kimishpatel force-pushed the fix_op_mul_broadcast branch from 79aea79 to 2341203 Compare June 12, 2025 16:37
@kimishpatel kimishpatel merged commit 0536862 into main Jun 12, 2025
168 of 169 checks passed
@kimishpatel kimishpatel deleted the fix_op_mul_broadcast branch June 12, 2025 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants