pytorch
runtime_error
ai_generated
true
RuntimeError: MPS backend out of memory (MPS backend does not support float64, falling back to float32)
ID: pytorch/mps-scalar-type-mismatch
82%Fix Rate
88%Confidence
1Evidence
2023-09-15First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| torch>=2.0.0 | active | — | — | — |
| macOS>=13.0 | active | — | — | — |
| MPS>=1.0 | active | — | — | — |
Root Cause
MPS (Metal Performance Shaders) backend on Apple Silicon does not support float64 (double precision) tensors, causing fallback or crash when operations require double precision.
generic中文
Apple Silicon上的MPS(Metal Performance Shaders)后端不支持float64(双精度)张量,当操作需要双精度时会导致回退或崩溃。
Official Documentation
https://pytorch.org/docs/stable/notes/mps.htmlWorkarounds
-
95% success Explicitly cast tensors to float32 before MPS operations: tensor = tensor.float()
Explicitly cast tensors to float32 before MPS operations: tensor = tensor.float()
-
80% success Use CPU or CUDA backend for parts of model requiring float64, then move back: model.to('cpu').double()
Use CPU or CUDA backend for parts of model requiring float64, then move back: model.to('cpu').double() -
90% success Disable MPS fallback: torch.set_default_dtype(torch.float32) and ensure all model parameters are float32
Disable MPS fallback: torch.set_default_dtype(torch.float32) and ensure all model parameters are float32
中文步骤
Explicitly cast tensors to float32 before MPS operations: tensor = tensor.float()
Use CPU or CUDA backend for parts of model requiring float64, then move back: model.to('cpu').double()Disable MPS fallback: torch.set_default_dtype(torch.float32) and ensure all model parameters are float32
Dead Ends
Common approaches that don't work:
-
95% fail
This only affects memory allocation limits, not type support; float64 operations still fail.
-
99% fail
MPS hardware/driver inherently lacks float64 support; no software update can add it.