Add complex dtype support to edge dialect for specific ops#20828
Conversation
🔗 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 ( 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. |
|
|
This PR needs a
|
b554261 to
3024532
Compare
There was a problem hiding this comment.
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 includeComplexFloatandComplexDouble. - Add Torch dtype-to-Edge-scalar mappings for
torch.complex64andtorch.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.
3024532 to
8672146
Compare
8672146 to
e545203
Compare
e545203 to
e00b4b8
Compare
e00b4b8 to
2d4f4c3
Compare
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.
2d4f4c3 to
e86064f
Compare
| 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)) |
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.