Skip to content

Add aten::complex.out support for export and CPU execution - #24330

Open
mshr-h wants to merge 1 commit into
pytorch:mainfrom
mshr-h:add-aten-complex-out
Open

mshr-h wants to merge 1 commit into
pytorch:mainfrom
mshr-h:add-aten-complex-out

Conversation

@mshr-h

@mshr-h mshr-h commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Models using torch.complex(real, imag) currently fail the default to_edge() Core ATen check. Allowing the operator through that check still leaves CPU execution blocked by a missing aten::complex.out kernel.

This PR enables default export and CPU execution for matching FP16/32/64 inputs, producing complex32/64/128 outputs. The portable kernel supports broadcasting and output resizing, and requires default contiguous dimension order. Edge dtype mapping now includes complex32.

Note: aten.complex.default is temporarily allowed by the verifier while keeping IR validation enabled. A separate PyTorch change is needed to formally include it in Core ATen. This exception can be removed once all supported PyTorch versions include that change.

Fixes #24328

Test plan

Rebuild the native bindings and C++ tests from this branch, then

python -m unittest \
  executorch.extension.pybindings.test.test_pybindings.PybindingsTest.test_complex_construction \
  executorch.extension.pybindings.test.test_pybindings.PybindingsTest.test_complex_numpy_input \
  executorch.extension.pybindings.test.test_pybindings.PybindingsTest.test_complex_half_dlpack_input \
  executorch.exir.verification.test.test_verifier \
  executorch.exir.dialects.edge.test.test_edge_ops \
  executorch.exir.dialects.edge.test.test_edge_yaml

./cmake-out/kernels/test/portable_kernels_test \
  --gtest_filter='OpComplexOutTest.*'

ctest --test-dir cmake-out \
  -R '^portable_kernels_test$' --output-on-failure

Result: Python unittest reported 24 tests passed; GoogleTest reported 21/21 complex kernel tests passed; CTest reported 1/1 test target passed. No failures.

Copilot AI balanced review requested due to automatic review settings October 30, 2026 09:20
@pytorch-bot

pytorch-bot Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

⚠️ 25 Awaiting Approval

As of commit c2763d9 with merge base 87d6190 (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

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 Oct 30, 2026
@mshr-h
mshr-h force-pushed the add-aten-complex-out branch from f04e979 to c2763d9 Compare October 30, 2026 09:21

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.

🟢 Approval recommended

No active review issues are blocking approval of the complex operator support.

No open issues 🎉

What changed in this PR

Enables torch.complex(real, imag) through default Edge export and CPU execution, addressing #24328 for matching FP16, FP32, and FP64 inputs.

Changes:

  • Adds a portable complex.out kernel with broadcasting, output resizing, and default dimension-order validation.
  • Registers the operator and adds complex32 dtype mapping plus a temporary Core ATen verifier exception.
  • Adds kernel and Python integration tests covering supported types, broadcasting, and invalid inputs.
File Description
shim_et/​xplat/​executorch/​kernels/​portable/​op_registration_util.bzl Adds the portable kernel build target and broadcast dependency.
kernels/​test/​targets.bzl Registers complex tests for ATen and portable kernels.
kernels/​test/​op_complex_test.cpp Tests types, broadcasting, special values, resizing, and validation.
kernels/​test/​CMakeLists.txt Includes complex kernel tests in CMake builds.
kernels/​portable/​functions.yaml Registers the portable complex.out implementation.
kernels/​portable/​cpu/​op_complex.cpp Implements complex tensor construction on CPU.
kernels/​aten/​functions.yaml Registers complex.out for ATen builds.
extension/​pybindings/​test/​test_pybindings.py Adds end-to-end export and execution coverage.
exir/​verification/​verifier.py Temporarily allows complex.default through Core ATen validation.
exir/​dialects/​edge/​dtype/​supported.py Maps complex32 to ComplexHalf.

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 30, 2026 09:23

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.

🟢 Approval recommended

There are no active review issues blocking the complex-construction support change.

No open issues 🎉

Review effort: Balanced

@mshr-h

mshr-h commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "release notes: ops & kernels"

@pytorch-bot pytorch-bot Bot added the release notes: ops & kernels Changes to the opset and any new / changed kernel implementations label Oct 30, 2026

This branch has not been deployed

No deployments
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. release notes: ops & kernels Changes to the opset and any new / changed kernel implementations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

torch.complex fails Edge export and CPU execution

2 participants