References

Enabling GPU on Mac OS for PyTorch

  1. Since I personally reinstalled GPU-supported PyTorch based on Anaconda, you can check whether Conda is installed by using the command conda --version. If it is installed, the output should confirm its presence. If not, you can download it from the Anaconda official website.
  2. (Optional) If you want to create a separate environment specifically for Python with GPU support, you can use the following command:
1
2
3
4
5
6
7
8
9
10
11
12
# Create an environment named 'torch-gpu' using Python version 3.10.9
conda create -n torch-gpu python=3.10.9

# Activate the created environment
conda activate torch-gpu

# List all environments to verify the 'torch-gpu' environment is created
conda env list

# Check if the current Python version matches the Python version in the activated environment
python --version

  1. According to the PyTorch official website, choose the corresponding version and copy the installation command.

  2. You can use a simple Python script to verify MPS (Multi-Process Service) support:

1
2
3
4
5
6
7
8
9
10
11
import torch
if torch.backends.mps.is_available():
mps_device = torch.device("mps")
x = torch.ones(1, device=mps_device)
print(x)
else:
print("MPS device not found.")

# Or
print(torch.backends.mps.is_available()) # True
print(torch.backends.mps.is_built()) # True

It’s important to note that if you’re using MPS on macOS, you should specify it as follows: device = torch.device("mps).