How to set up Metal GPU acceleration on macOS
Mac with Apple Silicon or AMD GPU, macOS 14 Sonoma or later
What this does
Enables the Metal framework as a GPU compute backend on macOS, allowing supported applications and AI runtimes to dispatch compute kernels to the integrated GPU on Apple Silicon. This is required for local model inference frameworks that target the Metal API.
Steps
Check the GPU configuration. This confirms the hardware and driver layer are healthy.
system_profiler SPDisplaysDataType | grep -A 5 "Chipset Model"Expected output: GPU identifier such as
Chipset Model: Apple M3 Pro.Install Xcode Command Line Tools. The Metal compiler headers are included in these tools.
xcode-select --installExpected output: Installation confirmed or "tool already present".
Install PyTorch with MPS support. Use the Metal Performance Shaders backend for GPU compute.
pip install torch python3 -c "import torch; print('MPS available:', torch.backends.mps.is_available()); print('MPS built:', torch.backends.mps.is_built())"Expected output:
MPS available: True / MPS built: True.Run a small GPU compute operation via Metal.
python3 -c " import torch device = torch.device('mps') a = torch.randn(2048, 2048, device=device) b = torch.randn(2048, 2048, device=device) c = torch.matmul(a, b) print('Metal compute succeeded, result shape:', c.shape) "Expected output:
Metal compute succeeded, result shape: torch.Size([2048, 2048]).
Verification
system_profiler SPDisplaysDataType 2>/dev/null | grep "Metal" | head -1
# Expected: Metal: Supported
Common failures
MPS available: Falseon Apple Silicon — macOS may be older than 14.0. Update via System Settings > General > Software Update.- MPS not supported for this build — CPU-only PyTorch variant installed. Use
pip install --upgrade torchfor the universal2 build. - Metal not shown as supported — Driver-level issue. Reinstall macOS updates.
- Segmentation fault on matmul with large tensors — MPS has alignment constraints on buffers exceeding 2 GB. Reduce tensor size.
xcode-select: command not found— Command Line Tools are missing. Runxcode-select --installwith GUI prompt.- Model inference slower than expected on MPS — Some operations fall back to CPU. Set environment variable
PYTORCH_MPS_HIGH_WATERMARK_RATIO=0.0to force full GPU offload.