Repository navigation
Conversation
When both the input and the output were complex, the kernel picked the C++ type from the input only, so complex64 to complex128 wrote wrong values and complex128 to complex64 wrote past the end of the output buffer. Switch on both complex types and convert the real and imaginary parts separately.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/25903
Note: Links to docs will display an error until the docs builds have been completed.
|
Contributor
Author
|
@pytorchbot label "release notes: ops & kernels" |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When both the input and the output were complex,
_to_dim_order_copypicked the C++ type from the input only, so complex64 to complex128 wrote wrong values and complex128 to complex64 wrote past the end of the output buffer (reproduction in #25902). This switches on both complex types and converts the real and imaginary parts separately, sincec10::complex<Half>cannot be constructed fromc10::complex<double>.Fixes #25902
Test plan
ComplexFloatToComplexDoubleandComplexDoubleToComplexFloatinkernels/test/op__to_dim_order_copy_test.cpp. Before the change the first one got wrong values and the second one aborted withdouble free or corruption. This test file is excluded from the CMake build (kernels/test/CMakeLists.txt, "requires rtti"), so it does not run in the CMake CI; I ran it by enabling it locally:From Python, complex64 to complex128 and complex128 to complex64 (4 and 4096 elements) now give the same values as eager.
ComplexHalfpairs are not exported byto_edge(mismatched dtypes) and no test builds aComplexHalftensor, so I checked complex128 to ComplexHalf and back with a local probe only: same values as eager, including overflow to inf.This PR was authored with the help of Claude Code (Anthropic); I reviewed and tested it.
cc @nil-is-all