pytorch - ✅(Solved) Fix MPS ComplexDouble (complex128) Support Inconsistency [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
pytorch/pytorch#176981Fetched 2026-04-08 00:23:20
View on GitHub
Comments
1
Participants
2
Timeline
86
Reactions
0
Author
Participants
Timeline (top)
mentioned ×33subscribed ×33labeled ×10referenced ×4

Error Message

import torch device = torch.device("mps")

1. Incorrectly allows move to MPS

x = torch.randn(2, 2, dtype=torch.cdouble, device="cpu").to(device) print(x.dtype) # torch.complex128 on mps

2. Crash on operation

RuntimeError: Undefined type ComplexDouble

y = x * x

3. Correctly blocks conversion (Inconsistent with above)

TypeError: Trying to convert ComplexDouble to the MPS backend...

z = torch.randn(2, 2, device=device).to(torch.cdouble)

Fix Action

Fixed

PR fix notes

PR #176985: [MPS] Error out if one tries to create torch.cdouble tensor

Description (problem / solution / changelog)

Which is not supported, same as double

Fixes https://github.com/pytorch/pytorch/issues/176981

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo

Changed files

  • aten/src/ATen/mps/EmptyTensor.cpp (modified, +1/-1)
  • test/inductor/test_aot_inductor.py (modified, +5/-1)
  • test/test_sparse.py (modified, +6/-4)
  • torch/testing/_internal/common_methods_invocations.py (modified, +0/-8)

Code Example

import torch
device = torch.device("mps")

# 1. Incorrectly allows move to MPS
x = torch.randn(2, 2, dtype=torch.cdouble, device="cpu").to(device) 
print(x.dtype) # torch.complex128 on mps

# 2. Crash on operation
# RuntimeError: Undefined type ComplexDouble
y = x * x 

# 3. Correctly blocks conversion (Inconsistent with above)
# TypeError: Trying to convert ComplexDouble to the MPS backend...
z = torch.randn(2, 2, device=device).to(torch.cdouble)
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

torch.cdouble (complex128) tensors can be moved to the mps device without error via .to(device), but subsequent operations fail. Direct conversion to complex128 on the mps device is correctly blocked by a TypeError.

Reproduction

import torch
device = torch.device("mps")

# 1. Incorrectly allows move to MPS
x = torch.randn(2, 2, dtype=torch.cdouble, device="cpu").to(device) 
print(x.dtype) # torch.complex128 on mps

# 2. Crash on operation
# RuntimeError: Undefined type ComplexDouble
y = x * x 

# 3. Correctly blocks conversion (Inconsistent with above)
# TypeError: Trying to convert ComplexDouble to the MPS backend...
z = torch.randn(2, 2, device=device).to(torch.cdouble)

Expected Behavior

.to(device) should raise a TypeError when attempting to move a complex128 tensor to the MPS backend, as it is unsupported. Error messages should be consistent across conversion methods.

Versions

PyTorch: 2.10.0 OS: macOS (Apple Silicon, MPS enabled) Device: MPS

cc @malfet @ezyang @anjali411 @dylanbespalko @mruberry @nikitaved @amjames @kulinseth @DenisVieriu97 @jhavukainen @aditvenk

extent analysis

Fix Plan

1. Update PyTorch to the latest version

Ensure you're running the latest version of PyTorch. This issue might be fixed in a newer version.

2. Modify torch.randn to use torch.complex128 directly on the MPS device

import torch
device = torch.device("mps")

# Correct way to create complex128 tensor on MPS
x = torch.randn(2, 2, dtype=torch.complex128, device=device)
print(x.dtype)  # torch.complex128 on mps

# Perform operations on x
y = x * x

3. Update torch.randn to raise a TypeError when moving complex128 to MPS

import torch
device = torch.device("mps")

# Incorrectly allows move to MPS (fix this)
def custom_randn(*args, **kwargs):
    if args[0].dtype == torch.cdouble and device.type == "mps":
        raise TypeError("Cannot move complex128 to MPS")
    return torch.randn(*args, **kwargs)

x = custom_randn(2, 2, dtype=torch.cdouble, device="cpu").to(device)
try:
    print(x.dtype)  # Should raise TypeError
except TypeError as e:
    print(e)

4. Verify the fix

Run the reproduction code again and ensure it raises a TypeError when moving complex128 to MPS.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING