Skip to content

Sym ite prim op#20681

Open
psiddh wants to merge 3 commits into
pytorch:mainfrom
psiddh:sym-ite-prim-op
Open

Sym ite prim op#20681
psiddh wants to merge 3 commits into
pytorch:mainfrom
psiddh:sym-ite-prim-op

Conversation

@psiddh

@psiddh psiddh commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Adds Python op registration, mapping entry, and C++ kernel handling with tests

Copilot AI review requested due to automatic review settings July 1, 2026 22:08
@pytorch-bot

pytorch-bot Bot commented Jul 1, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 3 New Failures

As of commit bba0931 with merge base 71a80d7 (image):

NEW FAILURES - The following jobs have 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 Jul 1, 2026
@github-actions

github-actions Bot commented Jul 1, 2026

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.

@psiddh psiddh requested a review from GregoryComer July 1, 2026 22:09

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 support for the torch.sym_ite symbolic conditional by registering a new executorch_prim::sym_ite.Scalar prim op, wiring it into the EXIR prim-op registry, and adding C++/Python coverage to validate both registration and end-to-end emission/runtime behavior.

Changes:

  • Register a new prim op kernel: executorch_prim::sym_ite.Scalar(bool b, Scalar t, Scalar f) -> Scalar in the prim ops registry.
  • Extend prim-ops C++ tests to validate sym_ite registration and runtime selection across int/double/bool.
  • Bind torch.sym_ite to the ExecuTorch prim op and add an emit test exercising dynamic shape behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
kernels/prim_ops/test/prim_ops_test.cpp Adds registration + correctness tests for executorch_prim::sym_ite.Scalar.
kernels/prim_ops/register_prim_ops.cpp Registers the sym_ite prim op kernel implementation.
exir/passes/executorch_prim_ops_registry.py Binds the sym_ite pattern and maps torch.sym_ite to the backend op overload.
exir/emit/test/test_emit.py Adds an end-to-end emit/runtime test that uses torch.sym_ite with dynamic shapes.

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

Comment on lines +2476 to +2483
exported_program = torch.export.export(
model, (test_inputs[0],), dynamic_shapes=dynamic_shapes
)

edge_program = to_edge(
exported_program,
compile_config=exir.EdgeCompileConfig(_check_ir_validity=False),
)
@psiddh psiddh force-pushed the sym-ite-prim-op branch from 16418db to 58cd130 Compare July 2, 2026 00:29
Implements the ternary sym_ite(condition, true_val, false_val) op,
needed by torch.export with Dim.AUTO when models contain conditional
symbolic shape logic.
Copilot AI review requested due to automatic review settings July 2, 2026 02:07
@psiddh psiddh force-pushed the sym-ite-prim-op branch from 58cd130 to 2bf3bb2 Compare July 2, 2026 02:07
torch.sym_ite enforces type(t) == type(f). The original test passed
a SymInt (n) and a plain int (6), which fails the type check. Use a
second dynamic shape dimension (m) so both branches are SymInt.

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.

Copilot AI review requested due to automatic review settings July 2, 2026 02:10

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 2 comments.

Comment thread exir/emit/test/test_emit.py Outdated
torch.randn(3, 4),
torch.randn(8, 4),
]
]
Comment on lines +137 to +141
@bind_pattern_to_op(
executorch_prims_lib, "sym_ite.Scalar(Scalar b, Scalar t, Scalar f) -> Scalar"
)
def sym_ite(b: _SymScalar, t: _SymScalar, f: _SymScalar) -> _SymScalar:
return t if b else f # pyre-ignore
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.

2 participants