Skip to content

Fix bug in add op to ignore alpha != 1 (fixes: #11683) #11777

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

abhinaykukkadapu
Copy link
Contributor

@abhinaykukkadapu abhinaykukkadapu commented Jun 18, 2025

Summary

Add node of XNNPack backend doesn't consider alpha value, this fixes the bug by falling back to portable ops and avoid partitioning the node.

(fixes: #11683)

Test plan

python -m unittest backends/xnnpack/test/ops/test_add.py

----------------------------------------------------------------------
Ran 11 tests in 26.689s

OK
import torch
from executorch.backends.xnnpack.partition.xnnpack_partitioner import XnnpackPartitioner
from executorch.exir import to_edge_transform_and_lower
from executorch.extension.pybindings.portable_lib import _load_for_executorch_from_buffer

class Model(torch.nn.Module):
    def forward(self, x, y):
        return torch.add(x, y, alpha=10)

inputs = (
    torch.randn(10),
    torch.randn(10),
)
model = Model()

ep = torch.export.export(model, inputs)
lowered = to_edge_transform_and_lower(
    ep,
    partitioner=[XnnpackPartitioner()],
).to_executorch()

et_model = _load_for_executorch_from_buffer(lowered.buffer)

eager_output = model(*inputs)
et_output = et_model([*inputs])[0]

tolerance=1e-5
if torch.allclose(eager_output, et_output, atol=tolerance):
    print("Outputs are within the tolerance level.")
else:
    print("Outputs differ beyond the tolerance level.")

Output of above run (tolerance = 1e-5)

Outputs are within the tolerance level.

Copy link

pytorch-bot bot commented Jun 18, 2025

🔗 Helpful Links

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

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 6e12599 with merge base f072e64 (image):

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

BROKEN TRUNK - The following jobs failed but was present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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 18, 2025
@abhinaykukkadapu abhinaykukkadapu force-pushed the fix_bug_add_ignore_alpha branch 3 times, most recently from 42cbcbb to 826d3eb Compare June 18, 2025 15:56
@abhinaykukkadapu abhinaykukkadapu force-pushed the fix_bug_add_ignore_alpha branch from 826d3eb to aa624e8 Compare June 18, 2025 17:22
@abhinaykukkadapu abhinaykukkadapu marked this pull request as ready for review June 18, 2025 17:26
@abhinaykukkadapu abhinaykukkadapu changed the title Fix bug add ignore alpha (fixes: #11683) Fix bug in sub op to ignore alpha != 1 (fixes: #11683) Jun 18, 2025
Copy link
Member

@GregoryComer GregoryComer left a comment

Choose a reason for hiding this comment

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

Thanks for taking this. Looks good.

@facebook-github-bot
Copy link
Contributor

@abhinaykukkadapu has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@manuelcandales manuelcandales assigned mcr229 and GregoryComer and unassigned mcr229 Jun 18, 2025
@manuelcandales manuelcandales changed the title Fix bug in sub op to ignore alpha != 1 (fixes: #11683) Fix bug in add op to ignore alpha != 1 (fixes: #11683) Jun 18, 2025
@manuelcandales manuelcandales added the release notes: xnnpack Changes to the XNNPack backend delegate label Jun 18, 2025
@abhinaykukkadapu abhinaykukkadapu force-pushed the fix_bug_add_ignore_alpha branch 8 times, most recently from c2243e2 to 15c8a57 Compare June 23, 2025 23:35
@facebook-github-bot
Copy link
Contributor

@abhinaykukkadapu has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@abhinaykukkadapu abhinaykukkadapu force-pushed the fix_bug_add_ignore_alpha branch from 15c8a57 to c691722 Compare June 23, 2025 23:41
@facebook-github-bot
Copy link
Contributor

@abhinaykukkadapu has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@abhinaykukkadapu abhinaykukkadapu force-pushed the fix_bug_add_ignore_alpha branch 2 times, most recently from 3b3dfd2 to 220d6a3 Compare June 24, 2025 01:02
@abhinaykukkadapu abhinaykukkadapu force-pushed the fix_bug_add_ignore_alpha branch from 220d6a3 to b345382 Compare June 24, 2025 01:03
@facebook-github-bot
Copy link
Contributor

@abhinaykukkadapu has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

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. release notes: xnnpack Changes to the XNNPack backend delegate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

XNNPACK add ignores alpha value
5 participants