MPS_NOT_AVAILABLE pytorch config_error ai_generated true

RuntimeError: MPS backend is not available. Please install PyTorch with MPS support or use CPU/CUDA.

ID: pytorch/mps-backend-unavailable

Also available as: JSON · Markdown · 中文
85%Fix Rate
90%Confidence
1Evidence
2023-04-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
torch>=1.12 active
macOS>=12.3 active
MPS>=1.0 active

Root Cause

PyTorch was built without MPS (Metal Performance Shaders) support, or the system lacks a compatible Apple GPU/macOS version.

generic

中文

PyTorch编译时未启用MPS(Metal Performance Shaders)支持,或系统缺少兼容的Apple GPU/macOS版本。

Official Documentation

https://pytorch.org/docs/stable/mps.html

Workarounds

  1. 90% success Install PyTorch with MPS support: pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/mps. Then verify with: import torch; print(torch.backends.mps.is_available())
    Install PyTorch with MPS support: pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/mps. Then verify with: import torch; print(torch.backends.mps.is_available())
  2. 95% success Fall back to CPU: device = torch.device('cuda' if torch.cuda.is_available() else ('mps' if torch.backends.mps.is_available() else 'cpu'))
    Fall back to CPU: device = torch.device('cuda' if torch.cuda.is_available() else ('mps' if torch.backends.mps.is_available() else 'cpu'))

中文步骤

  1. 安装支持MPS的PyTorch:pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/mps。然后验证:import torch; print(torch.backends.mps.is_available())
  2. 回退到CPU:device = torch.device('cuda' if torch.cuda.is_available() else ('mps' if torch.backends.mps.is_available() else 'cpu'))

Dead Ends

Common approaches that don't work:

  1. conda install pytorch -c pytorch 70% fail

    Installing PyTorch from conda default channel often ships CPU-only build; user must explicitly select MPS variant.

  2. export PYTORCH_MPS_HIGH_WATERMARK_RATIO=0.0 90% fail

    Setting environment variable PYTORCH_MPS_HIGH_WATERMARK_RATIO=0.0 does not enable MPS; it only controls memory threshold.