Skip to content

Add complex dtype support to edge dialect for specific ops#20828

Merged
psiddh merged 1 commit into
pytorch:mainfrom
psiddh:fix-verifier-complex-dtype
Jul 10, 2026
Merged

Add complex dtype support to edge dialect for specific ops#20828
psiddh merged 1 commit into
pytorch:mainfrom
psiddh:fix-verifier-complex-dtype

Conversation

@psiddh

@psiddh psiddh commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

The edge dialect dtype constraint tables did not include complex dtypes (ComplexFloat, ComplexDouble), causing the verifier to incorrectly reject models that use complex tensors. The runtime already supports these types (scalar_type.h indices 9-10).

Registers ComplexFloat and ComplexDouble as recognized dtype names and adds them to the following shape-manipulation ops that are dtype-agnostic: unsqueeze_copy, squeeze_copy, permute_copy,
slice_copy, expand_copy.

This was forcing downstream exporters to monkey-patch _check_tensor_args_matching_op_allowed_dtype to suppress SpecViolationError for complex dtype violations.

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

pytorch-bot Bot commented Jul 9, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ You can merge normally! (1 Unrelated Failure)

As of commit e86064f with merge base aceeb40 (image):

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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

linux-foundation-easycla Bot commented Jul 9, 2026

Copy link
Copy Markdown

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

  • ✅ login: psiddh / name: Siddartha Pothapragada (3024532)

@github-actions

github-actions Bot commented Jul 9, 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 force-pushed the fix-verifier-complex-dtype branch from b554261 to 3024532 Compare July 9, 2026 22:18

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 updates ExecuTorch’s Edge dialect dtype constraints so that aten::unsqueeze_copy correctly accepts complex tensors, aligning the verifier with runtime scalar type support and avoiding false SpecViolationError rejections during export-to-edge.

Changes:

  • Extend aten::unsqueeze_copy’s Edge dialect dtype alias to include ComplexFloat and ComplexDouble.
  • Add Torch dtype-to-Edge-scalar mappings for torch.complex64 and torch.complex128.
  • Add a verification test ensuring complex unsqueeze is accepted by EXIREdgeDialectVerifier.

Reviewed changes

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

File Description
exir/dialects/edge/edge.yaml Adds ComplexFloat/ComplexDouble to aten::unsqueeze_copy dtype constraints.
exir/dialects/edge/dtype/supported.py Maps torch.complex64/128 to Edge scalar type strings used by dtype constraint machinery.
exir/tests/test_verification.py Adds a regression test covering complex unsqueeze verification behavior.

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

Comment thread exir/tests/test_verification.py
Copilot AI review requested due to automatic review settings July 9, 2026 22:19

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 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread exir/tests/test_verification.py
Copilot AI review requested due to automatic review settings July 9, 2026 23:38
@psiddh psiddh force-pushed the fix-verifier-complex-dtype branch from 3024532 to 8672146 Compare July 9, 2026 23:38
@psiddh psiddh force-pushed the fix-verifier-complex-dtype branch from 8672146 to e545203 Compare July 9, 2026 23:39

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 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread exir/tests/test_verification.py
Copilot AI review requested due to automatic review settings July 9, 2026 23:41
@psiddh psiddh force-pushed the fix-verifier-complex-dtype branch from e545203 to e00b4b8 Compare July 9, 2026 23:42

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 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread exir/dialects/edge/edge.yaml
Comment thread exir/tests/test_verification.py
Copilot AI review requested due to automatic review settings July 9, 2026 23: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 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread exir/tests/test_verification.py
Copilot AI review requested due to automatic review settings July 9, 2026 23:51
@psiddh psiddh force-pushed the fix-verifier-complex-dtype branch from e00b4b8 to 2d4f4c3 Compare July 9, 2026 23:51
The edge dialect dtype constraint tables did not include complex
dtypes (ComplexFloat, ComplexDouble), causing the verifier to
incorrectly reject models that use complex tensors. The runtime
already supports these types (scalar_type.h indices 9-10).

Registers ComplexFloat and ComplexDouble as recognized dtype names
and adds them to the following shape-manipulation ops that are
dtype-agnostic: unsqueeze_copy, squeeze_copy, permute_copy,
slice_copy, expand_copy.

This was forcing downstream exporters to monkey-patch
_check_tensor_args_matching_op_allowed_dtype to suppress
SpecViolationError for complex dtype violations.
@psiddh psiddh changed the title Add complex dtype support to edge dialect for unsqueeze_copy Add complex dtype support to edge dialect for specific ops Jul 9, 2026
@psiddh psiddh force-pushed the fix-verifier-complex-dtype branch from 2d4f4c3 to e86064f Compare July 9, 2026 23:52

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 3 out of 3 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 9, 2026 23:54

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 3 out of 3 changed files in this pull request and generated 1 comment.

Comment on lines +304 to +326
class TestModel(torch.nn.Module):
def forward(self, x):
x = x.expand(4, 8)
x = x.permute(1, 0)
x = x[:, :2]
x = x.squeeze(0)
return x

m = TestModel()
edge_gm = (
to_edge(
export(
m,
(torch.randn(1, 8).to(dtype=torch.complex64),),
strict=True,
)
)
.exported_program()
.graph_module
)
verifier = EXIREdgeDialectVerifier()
verifier(edge_gm)
self.assertTrue(verifier.is_valid(edge_gm))
@psiddh psiddh merged commit ec52125 into pytorch:main Jul 10, 2026
182 of 183 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