Blog #pytorch #getting-started #machine-learning
Install PyTorch on Apple M1 (M1, Pro, Max) with GPU (Metal)
Install PyTorch on Apple M1 (M1, Pro, Max) with GPU (Metal)
- Published
- Updated
- Reading
- 1 min
- Author
- Sudhanva Narayana
Note
- Uninstall Anaconda/Anaconda Navigator and any other conda-based installations.
- Anaconda and Miniforge cannot coexist.
- However, if you have previous installations of PyTorch with Miniforge, you can keep using it without uninstalling it.
- We will install the GPU version in a new
condaenvironment anyway. - The GPU version is still a nightly build, so expect breaking changes for the next couple of months.
Installing Miniforge
- Install miniforge from brew:
brew install miniforge - Create a conda environment:
conda create -n pt122 - Activate the environment:
conda activate pt122 - Install Python:
conda install python
Installing PyTorch
- Run:
pip install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cputo install PyTorch (Nightly) dependencies - Execute:
pip install pandas jupyterlabto install relevant dependencies to run sample code. - Run:
conda activate pt122
Verifying Installation
- Execute:
jupyter-labto open a Jupyter Notebook and run the following code:
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.