Blog #pytorch #getting-started #machine-learning

Install PyTorch on Apple M1 (M1, Pro, Max) with GPU (Metal)

Steps to install the PyTorch nightly build with Metal (MPS) GPU support on Apple M1, M1 Pro, and M1 Max, with Miniforge.

Published
Updated
Reading
1 min

Note

  • Uninstall Anaconda/Anaconda Navigator and all other conda-based installations.
  • Anaconda and Miniforge cannot coexist.
  • If you have a previous installation of PyTorch with Miniforge, you can continue to use it. You do not need to uninstall it.
  • We install the GPU version in a new conda environment.
  • The GPU version is still a nightly build, so expect breaking changes for the next couple of months.

Install Miniforge

  1. Install miniforge from brew: brew install miniforge
  2. Create a conda environment: conda create -n pt122
  3. Activate the environment: conda activate pt122
  4. Install Python: conda install python

Install PyTorch

  1. Run pip install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu to install the PyTorch (Nightly) dependencies.
  2. Run pip install pandas jupyterlab to install the dependencies for the sample code.
  3. Run conda activate pt122.

Verify the Installation

  1. Run jupyter-lab to open a Jupyter Notebook.
  2. Run this code in the notebook:
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.