Blog #pytorch #getting-started #machine-learning
Install PyTorch on Apple M1 (M1, Pro, Max) with GPU (Metal)
How to set up PyTorch with Apple Silicon Metal Performance Shaders (MPS) GPU acceleration on M1, M1 Pro, and M1 Max Macs using Miniforge.
- Published
- Updated
- Reading
- 1 min
- Author
- Sudhanva Narayana
Before You Start
- Remove any existing Intel/Rosetta Anaconda or Anaconda Navigator installations first, since Anaconda and
arm64Miniforge conflict over shell init blocks and library paths. - If you already have Miniforge installed from an earlier Apple Silicon setup, keep it and create a fresh conda environment below.
- When PyTorch first shipped Metal Performance Shaders (
mps) support in May 2022, it required the nightly wheel channel (--pre); modern PyTorch releases shipmpssupport in the default stable wheel, though the isolated Miniforge workflow below remains the cleanest way to avoidx86_64wheel mismatches.
Install Miniforge
- Install Miniforge via Homebrew:
brew install miniforge - Create an isolated environment:
conda create -n pt122 - Activate it:
conda activate pt122 - Install native
arm64Python:conda install python
Install PyTorch
- Install
torch,torchvision, andtorchaudiowith Metal support:pip install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu - Add notebook dependencies for quick testing:
pip install pandas jupyterlab - Re-activate the environment if needed:
conda activate pt122
Verify the Installation
- Launch JupyterLab with
jupyter-lab. - Run a quick tensor allocation check on the
"mps"device:
import torch
torch.device("mps")
torch.__version__
torch.tensor([1,2,3], device="mps")
Credits
Related work
Production ML context
See how this topic connects to production ML systems, infrastructure, and inference.