Skip to content

Sym not prim op#20641

Merged
psiddh merged 5 commits into
pytorch:mainfrom
psiddh:sym-not-prim-op
Jul 1, 2026
Merged

Sym not prim op#20641
psiddh merged 5 commits into
pytorch:mainfrom
psiddh:sym-not-prim-op

Conversation

@psiddh

@psiddh psiddh commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Register torch.sym_not in ExecuTorch's prim ops registry so that models
shapes) can be exported and executed on-device.

This was the root cause of ~53% of HuggingFace exporter test failures when
using Dim.AUTO dynamic shapes — sym_not appeared in the exported graph
but had no ET registration or runtime kernel.

  • Python op definition + mapping in executorch_prim_ops_registry.py
  • C++ kernel in register_prim_ops.cpp
  • Python e2e test in test_emit.py
  • C++ unit test in prim_ops_test.cpp

Test plan

  • python -m pytest exir/emit/test/test_emit.py::TestEmit::test_emit_sym_not -xvs
  • C++ prim_ops_test SymNotReturnsCorrectValue and OpRegistered tests
  • HuggingFace exporter test suite — sym_not failures should be resolved

Copilot AI review requested due to automatic review settings June 30, 2026 17:59
@pytorch-bot

pytorch-bot Bot commented Jun 30, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 1 New Failure, 1 Pending

As of commit 3971399 with merge base f95486d (image):

NEW FAILURE - The following job has failed:

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 Jun 30, 2026
@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 30, 2026

Copy link
Copy Markdown

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

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

Copilot AI 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.

Pull request overview

This PR adds ExecuTorch prim-op support for torch.sym_not so exported programs using dynamic shapes (e.g., Dim.AUTO) can lower and run on-device without missing-op failures.

Changes:

  • Register executorch_prim::sym_not.Scalar in the Python prim ops registry and map torch.sym_not to it during lowering.
  • Add the corresponding C++ runtime kernel in the prim-ops registry.
  • Add Python e2e coverage in test_emit.py and a C++ unit test validating registration and correctness.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
kernels/prim_ops/test/prim_ops_test.cpp Adds registration check and a correctness test for executorch_prim::sym_not.Scalar.
kernels/prim_ops/register_prim_ops.cpp Registers the executorch_prim::sym_not.Scalar kernel and enforces bool input at runtime.
exir/passes/executorch_prim_ops_registry.py Defines the prim op schema and maps torch.sym_not to the ExecuTorch prim op.
exir/emit/test/test_emit.py Adds an end-to-end export+run test covering dynamic-shape usage of sym_not.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread exir/passes/executorch_prim_ops_registry.py
Comment thread exir/emit/test/test_emit.py
@psiddh psiddh requested review from Gasoonjia and digantdesai June 30, 2026 18:07
psiddh added 2 commits June 30, 2026 11:07
Register `torch.sym_not` in ExecuTorch's prim ops so that models
using symbolic boolean negation (e.g. causal attention masks with
dynamic shapes) can be exported and executed on-device.

Changes:
- Python op definition + mapping in executorch_prim_ops_registry.py
- C++ kernel in register_prim_ops.cpp
- Python e2e test in test_emit.py
- C++ unit test in prim_ops_test.cpp

This was the root cause of ~53% of HuggingFace exporter test failures
when using Dim.AUTO dynamic shapes — sym_not appeared in the exported
graph but had no ET registration or runtime kernel.
Use sym_float(sym_not(...)) to add a scalar value to the tensor
output, which keeps sym_not alive in the graph without creating
data-dependent output shapes that torch.export cannot handle.
@psiddh psiddh force-pushed the sym-not-prim-op branch from 541e638 to ea93a05 Compare June 30, 2026 18:08
Copilot AI review requested due to automatic review settings June 30, 2026 18:29

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

sym_float.Scalar only handled Int and Double inputs, but sym_not
returns a Bool. This caused a runtime failure when chaining
sym_not → sym_float in the test model. Add Bool handling to match
Python semantics where float(True) == 1.0.
Copilot AI review requested due to automatic review settings July 1, 2026 03:45

Copilot AI 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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@psiddh

psiddh commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

all failures in the lone ci job failed due torchvision::nms, unrelated to this PR.

@psiddh psiddh merged commit e17700a into pytorch:main Jul 1, 2026
179 of 180 checks passed
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