Skip to content

Fix bug in le broadcast for single element broadcast#11922

Merged
kimishpatel merged 1 commit intomainfrom
fix_le_broadcast
Jun 25, 2025
Merged

Fix bug in le broadcast for single element broadcast#11922
kimishpatel merged 1 commit intomainfrom
fix_le_broadcast

Conversation

@kimishpatel
Copy link
Copy Markdown
Contributor

Summary:
Really comparison ops cannot be handled in the same way as other binary ops for broadcasting because output tensor dtype is different than input tensor dtype.

As a result we just have to fall back to portable.

Even the current vectorized impl for le, ge etc. assumes that the output type of compare is same as input type. That might actually be a bug.

A potential way to handle this maybe via vectorized compare natively supporting binary output vector

Test Plan:
Tests added which fail before and passes after

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.

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Jun 24, 2025

🔗 Helpful Links

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

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

✅ You can merge normally! (3 Unrelated Failures)

As of commit 35caf87 with merge base 44ab83a (image):

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

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 24, 2025
@github-actions
Copy link
Copy Markdown

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.

@kimishpatel
Copy link
Copy Markdown
Contributor Author

This also fixes the garbage output issue in optimum-executorch models

Copy link
Copy Markdown
Contributor

@guangy10 guangy10 left a comment

Choose a reason for hiding this comment

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

LGTM. Accepted to unblock the work in optimum-executorch.

Summary:
Really comparison ops cannot be handled in the same way as other binary
ops for broadcasting because output tensor dtype is different than input
tensor dtype.

As a result we just have to fall back to portable.

Even the current vectorized impl for le, ge etc. assumes that the output
type of compare is same as input type. That might actually be a bug.

A potential way to handle this maybe via vectorized compare natively
supporting binary output vector

Test Plan:
Tests added which fail before and passes after

Reviewers:

Subscribers:

Tasks:

Tags:
@kimishpatel
Copy link
Copy Markdown
Contributor Author

failures are not related

@kimishpatel kimishpatel merged commit 542ea56 into main Jun 25, 2025
93 of 96 checks passed
@kimishpatel kimishpatel deleted the fix_le_broadcast branch June 25, 2025 00:52
hinriksnaer pushed a commit to hinriksnaer/executorch that referenced this pull request Jun 26, 2025
Summary:
Really comparison ops cannot be handled in the same way as other binary
ops for broadcasting because output tensor dtype is different than input
tensor dtype.

As a result we just have to fall back to portable.

Even the current vectorized impl for le, ge etc. assumes that the output
type of compare is same as input type. That might actually be a bug.

A potential way to handle this maybe via vectorized compare natively
supporting binary output vector

Test Plan:
Tests added which fail before and passes after

Reviewers:

Subscribers:

Tasks:

Tags:

### Summary
[PLEASE REMOVE] See [CONTRIBUTING.md's Pull
Requests](https://github.com/pytorch/executorch/blob/main/CONTRIBUTING.md#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: <area>" label.
For a list of available release notes labels, check out
[CONTRIBUTING.md's Pull
Requests](https://github.com/pytorch/executorch/blob/main/CONTRIBUTING.md#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.
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