Skip to content

[exir] Rewrite operator.pow on SymInt to multiplication chain in EdgeToBackendOpsPass - #25768

Open
themanoj-025 wants to merge 2 commits into
pytorch:mainfrom
themanoj-025:fix-sym-pow-emitter
Open

themanoj-025 wants to merge 2 commits into
pytorch:mainfrom
themanoj-025:fix-sym-pow-emitter

Conversation

@themanoj-025

@themanoj-025 themanoj-025 commented Nov 27, 2026 •

Copy link
Copy Markdown

Summary

Fixes #25767
Part of huggingface/transformers#51303

When exporting models with dynamic shapes where a SymInt is raised to an integer power (e.g. x.shape[0] ** 2 in SeamlessM4T's relative positional bias calculation), lowering fails with:

executorch.exir.error.InternalError: Failed with error: invalid target for call_function <built-in function pow>

Because executorch_prim does not define a pow kernel, operator.pow remained an invalid target during emission. This PR updates EdgeToBackendOpsPass (executorch/exir/passes/replace_edge_with_backend_pass.py) to rewrite operator.pow(base, exp) for non-negative integer exponents into a multiplication chain using _PYTHON_SYM_OPS_TO_EXECUTORCH_SYM_OPS[operator.mul], with intermediate symbolic values correctly propagated.

Test plan

  1. Verified locally against the minimal reproduction script in [exir] operator.pow on a SymInt has no emitter target #25767:
import torch
from executorch.exir import to_edge_transform_and_lower

class M(torch.nn.Module):
    def forward(self, x):
        return x.new_zeros(x.shape[0] ** 2)

ep = torch.export.export(M(), (torch.randn(4),), dynamic_shapes=({0: torch.export.Dim.AUTO},))
to_edge_transform_and_lower(ep).to_executorch()
  1. Added unit test test_edge_to_backend_sym_pow in exir/tests/test_passes.py.

cc @nil-is-all

…ToBackendOpsPass

When exporting models with dynamic shapes where a SymInt is raised to an integer power (e.g. SeamlessM4T's relative position bias calculation x.shape[0] ** 2), to_executorch() fails with:
executorch.exir.error.InternalError: Failed with error: invalid target for call_function <built-in function pow>

Because executorch_prim does not have a pow operator, this commit rewrites operator.pow(base, exp) for non-negative integer exponents into a scalar multiplication chain using _PYTHON_SYM_OPS_TO_EXECUTORCH_SYM_OPS[operator.mul].

Tracked in huggingface/transformers#51303 (Item 1).
@pytorch-bot

pytorch-bot Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

⚠️ 21 Awaiting Approval

As of commit 67e90ff with merge base ddb19ca (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

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

@meta-cla

meta-cla Bot commented Nov 27, 2026

Copy link
Copy Markdown

Hi @themanoj-025!

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 [email protected]. Thanks!

@linux-foundation-easycla

linux-foundation-easycla Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

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

@themanoj-025

Copy link
Copy Markdown
Author

@pytorchbot label "release notes: none"

@pytorch-bot pytorch-bot Bot added the release notes: none Do not include this in the release notes label Nov 27, 2026
@meta-cla

meta-cla Bot commented Nov 27, 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 Nov 27, 2026
@executorch-triage executorch-triage Bot added the community: contribution PRs coming from community (excluding hardware partners) label Nov 27, 2026

@JacobSzwejbka JacobSzwejbka 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.

This branch has not been deployed

No deployments
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. community: contribution PRs coming from community (excluding hardware partners) release notes: none Do not include this in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[exir] operator.pow on a SymInt has no emitter target

2 participants