Skip to content

Add ne, sym_and and sym_or prim ops for symbolic comparisons - #25911

Open
AxelNoun wants to merge 1 commit into
pytorch:mainfrom
AxelNoun:fix/et-1-sym-ne-and-or
Open

AxelNoun wants to merge 1 commit into
pytorch:mainfrom
AxelNoun:fix/et-1-sym-ne-and-or

Conversation

@AxelNoun

@AxelNoun AxelNoun commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

operator.ne, operator.and_ and operator.or_ on symbolic sizes had no executorch_prim op, so to_executorch() failed with invalid target for call_function (reproduction in #25910). This adds executorch_prim::ne.Scalar, on the model of eq.Scalar, and sym_and.Scalar / sym_or.Scalar, which take two bools like sym_not takes one.

A bitwise & or | between two SymInts is still not supported: the edge verifier now rejects it in to_edge(), as it already does for float sym_max / sym_min, instead of letting it lower to a kernel that would fail at run time.

This adds entries next to the ones #25773 adds for floor; whichever lands second, I will rebase it.

Fixes #25910

Test plan

test_emit_sym_ne_and_or exports a model using the three operators on a dynamic size, checks they are in the graph, lowers it with the default config and runs it for sizes that make each predicate true and false. test_int_sym_and_or_rejected checks the verifier error. The C++ tests check the kernels and their InvalidType errors. Before the change the Python tests failed and the C++ tests did not find the kernels.

pytest exir/emit/test/test_emit.py -k sym_ne_and_or
pytest exir/program/test/test_program.py -k int_sym_and_or_rejected
./cmake-out/kernels/prim_ops/test/kernels_prim_ops_test   # 30 tests passed
ctest --output-on-failure                                 # 90/90 passed

pytest exir runtime/test kernels/quantized/test fails only where it already fails on main in my build (XNNPACK and demo backends, not built).

This PR was authored with the help of Claude Code (Anthropic); I reviewed and tested it.

cc @nil-is-all

operator.ne, operator.and_ and operator.or_ on symbolic sizes had no executorch_prim op, so to_executorch() failed with an invalid target. Add ne.Scalar, and sym_and.Scalar and sym_or.Scalar for two bools, and reject a bitwise & or | between SymInts in the edge verifier instead of lowering it to a kernel that would fail at run time.
@pytorch-bot

pytorch-bot Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

⚠️ 21 Awaiting Approval

As of commit 5baa6f9 with merge base f748232 (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 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 Dec 1, 2026
@AxelNoun

AxelNoun commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "release notes: ops & kernels"

@pytorch-bot pytorch-bot Bot added the release notes: ops & kernels Changes to the opset and any new / changed kernel implementations label Dec 1, 2026
@executorch-triage executorch-triage Bot added the community: contribution PRs coming from community (excluding hardware partners) label Dec 1, 2026

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: ops & kernels Changes to the opset and any new / changed kernel implementations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

to_executorch() fails on !=, & and | between symbolic sizes

1 participant