This guide provides step-by-step instructions for installing PyTorch with support for Apple Metal Performance Shaders (MPS) including ConvTranspose3D operations, which aren't available in the standard PyTorch distribution.
- macOS with Apple Silicon (M1/M2/M3) or compatible GPU
- Python 3.7+
- Git
- Clone the PyTorch repository from GitHub:
git clone https://github.com/pytorch/pytorch- Install the specific CMake version required:
pip install cmake==3.26.4- Verify the CMake installation:
cmake --version- Navigate to the PyTorch directory:
cd pytorch- Fetch the specific pull request that adds ConvTranspose3D support for MPS:
git fetch origin pull/145366/head:ts_export- Checkout the branch with the necessary changes:
git checkout ts_export- Synchronize Git submodules:
git submodule sync- Initialize and update all submodules recursively:
git submodule update --init --recursive- Build and install PyTorch:
python setup.py installTo verify the installation has ConvTranspose3D support on MPS, you can run:
import torch
x = torch.randn(1, 3, 10, 10, 10).to('mps')
conv = torch.nn.ConvTranspose3d(3, 5, 3, stride=2, padding=1).to('mps')
output = conv(x)
print(f"Output shape: {output.shape}")- The installation process can take significant time (30-60 minutes depending on your system).
- This builds PyTorch from source, so you'll need sufficient disk space (10+ GB).
- The specific pull request referenced adds support for ConvTranspose3D operations on Apple's MPS backend.
If you encounter build errors:
- Ensure you have Xcode Command Line Tools installed
- Make sure you're using the correct version of CMake
- Try increasing the resources allocated to the build with
MAX_JOBS=8before the install command