Sym not prim op#20641
Conversation
🔗 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 PendingAs of commit 3971399 with merge base f95486d ( NEW FAILURE - The following job has failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
There was a problem hiding this comment.
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.Scalarin the Python prim ops registry and maptorch.sym_notto it during lowering. - Add the corresponding C++ runtime kernel in the prim-ops registry.
- Add Python e2e coverage in
test_emit.pyand 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.
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.
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.
|
all failures in the lone ci job failed due torchvision::nms, unrelated to this PR. |
Summary
Register
torch.sym_notin ExecuTorch's prim ops registry so that modelsshapes) can be exported and executed on-device.
This was the root cause of ~53% of HuggingFace exporter test failures when
using
Dim.AUTOdynamic shapes —sym_notappeared in the exported graphbut had no ET registration or runtime kernel.
executorch_prim_ops_registry.pyregister_prim_ops.cpptest_emit.pyprim_ops_test.cppTest plan
python -m pytest exir/emit/test/test_emit.py::TestEmit::test_emit_sym_not -xvsSymNotReturnsCorrectValueandOpRegisteredtests