Skip to content

Instantly share code, notes, and snippets.

@sriharshav
Created October 15, 2022 09:03
Show Gist options
  • Select an option

  • Save sriharshav/7d76dcc84edd19f31557a3d6fd4f8a0c to your computer and use it in GitHub Desktop.

Select an option

Save sriharshav/7d76dcc84edd19f31557a3d6fd4f8a0c to your computer and use it in GitHub Desktop.
PyTorch with Apple M1 MPS
import torch
print(f"PyTorch version: {torch.__version__}")
# Check PyTorch has access to MPS (Metal Performance Shader, Apple's GPU architecture)
print(f"Is MPS (Metal Performance Shader) built? {torch.backends.mps.is_built()}")
print(f"Is MPS available? {torch.backends.mps.is_available()}")
# Set the device
device = "mps" if torch.backends.mps.is_available() else "cpu"
print(f"Using device: {device}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment