New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tensor.abs() gives incorrect results on Complex64 when using MPS #125135
Comments
For any user needing a quick (probably unsafe) fix, the following worked for my use case:
Output:
|
Hi @bdhirsh ! |
Grabbing for myself, wish there was a proper doc for https://developer.apple.com/documentation/metalperformanceshadersgraph/mpsgraph/3564540-absolutewithtensor?language=objc |
@gambiTarun sorry, missed your comment. How familiar are you with ObjC/MPS framework? |
Hi @malfet, no worries! I鈥檓 not familiar with ObjC/MPS, but I鈥檓 willing to learn. If you could point me in the right direction for resolving this bug, or suggest some resources, I'd appreciate it! |
Hi @malfet! Wanted to add some context as I did have a brief discussion with some of the MPSGraph people regarding this issue and that particular op. My current hypothesis on what happens:
Unfortunately I'm drowning in other work this week so I'm more than happy to let anyone take a shot at this if they'd like. |
By calling `realPartOfTensor:` if input type is complex on Sonoma and fall back to `at::view_as_real` trick on Ventura. Split `unary_op` template into `unary_op` and `unary_op_noresize`, which skips resize and empty checks Marked `abs`, `isclose` and `nn.functional.softsign` OpInfo tests as supported by complex types Fixes #125135 Pull Request resolved: #125662 Approved by: https://github.com/kulinseth (cherry picked from commit 0fd1fc1)
[MPS] Fix `abs` for complex types (#125662) By calling `realPartOfTensor:` if input type is complex on Sonoma and fall back to `at::view_as_real` trick on Ventura. Split `unary_op` template into `unary_op` and `unary_op_noresize`, which skips resize and empty checks Marked `abs`, `isclose` and `nn.functional.softsign` OpInfo tests as supported by complex types Fixes #125135 Pull Request resolved: #125662 Approved by: https://github.com/kulinseth (cherry picked from commit 0fd1fc1) Co-authored-by: Nikita Shulga <[email protected]>
馃悰 Describe the bug
The abs() function gives incorrect results when using Complex64 tensors on an MPS device. It appears to be some kind of indexing issue per the example below.
Output:
Versions
Collecting environment information...
PyTorch version: 2.4.0.dev20240428
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A
OS: macOS 14.4.1 (arm64)
GCC version: Could not collect
Clang version: 15.0.0 (clang-1500.1.0.2.5)
CMake version: version 3.28.3
Libc version: N/A
Python version: 3.11.9 | packaged by conda-forge | (main, Apr 19 2024, 18:34:54) [Clang 16.0.6 ] (64-bit runtime)
Python platform: macOS-14.4.1-arm64-arm-64bit
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True
CPU:
Apple M2 Pro
Versions of relevant libraries:
[pip3] numpy==1.26.4
[pip3] torch==2.4.0.dev20240428
[pip3] torchaudio==2.2.0.dev20240428
[pip3] torchvision==0.19.0.dev20240428
[conda] numpy 1.26.4 py311h7125741_0 conda-forge
[conda] pytorch 2.4.0.dev20240428 py3.11_0 pytorch-nightly
[conda] torchaudio 2.2.0.dev20240428 py311_cpu pytorch-nightly
[conda] torchvision 0.19.0.dev20240428 py311_cpu pytorch-nightly
cc @ezyang @anjali411 @dylanbespalko @mruberry @lezcano @nikitaved @amjames @kulinseth @albanD @malfet @DenisVieriu97 @jhavukainen
The text was updated successfully, but these errors were encountered: