Repository navigation
[exir] Rewrite operator.pow on SymInt to multiplication chain in EdgeToBackendOpsPass - #25768
themanoj-025 wants to merge 2 commits into
Conversation
…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).
🔗 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.
|
|
Hi @themanoj-025! Thank you for your pull request and welcome to our community. Action RequiredIn 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. ProcessIn 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 If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
|
@pytorchbot label "release notes: none" |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
JacobSzwejbka
left a comment
There was a problem hiding this comment.
Thanks for looking into this. I would rather just define the pow op though.
https://github.com/pytorch/executorch/blob/main/exir/passes/executorch_prim_ops_registry.py
https://github.com/pytorch/executorch/blob/main/kernels/prim_ops/register_prim_ops.cpp
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] ** 2in SeamlessM4T's relative positional bias calculation), lowering fails with:Because
executorch_primdoes not define apowkernel,operator.powremained an invalid target during emission. This PR updatesEdgeToBackendOpsPass(executorch/exir/passes/replace_edge_with_backend_pass.py) to rewriteoperator.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
test_edge_to_backend_sym_powinexir/tests/test_passes.py.cc @nil-is-all