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

Before You Start

  • Remove any existing Intel/Rosetta Anaconda or Anaconda Navigator installations first, since Anaconda and arm64 Miniforge 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 ship mps support in the default stable wheel, though the isolated Miniforge workflow below remains the cleanest way to avoid x86_64 wheel mismatches.

Install Miniforge

  1. Install Miniforge via Homebrew: brew install miniforge
  2. Create an isolated environment: conda create -n pt122
  3. Activate it: conda activate pt122
  4. Install native arm64 Python: conda install python

Install PyTorch

  1. Install torch, torchvision, and torchaudio with Metal support: pip install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu
  2. Add notebook dependencies for quick testing: pip install pandas jupyterlab
  3. Re-activate the environment if needed: conda activate pt122

Verify the Installation

  1. Launch JupyterLab with jupyter-lab.
  2. 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.