Can I use the pytorch.cuda documentation and code on an Apple Silicon Machine? #489
-
Can I use the I have an Apple silicon machine, and I installed the supported PyTorch packages, I have verified that the GPU is available and I am able to transfer some of the tensors to the GPU, however in the PyTorch documentation and in the course, the An example is in the exercises chapter in the book (First Chapter, PyTorch Fundamentals), there is a task to find the manual_seed equivalent to the GPU, however that was for the CUDA GPUs, How can I transfer that to Apple Silicon? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @pypdeveloper ,
For Apple Silicon devices, you'll want to use See the documentation here: https://pytorch.org/docs/stable/notes/mps.html Also for manual seed on MPS, you'll want to use To setup your device for Apple Silicon, you can use the example code: import torch
import numpy as np
import pandas as pd
import sklearn
import matplotlib.pyplot as plt
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}") I took the code from my GitHub on setting up PyTorch for Mac: https://github.com/mrdbourke/pytorch-apple-silicon |
Beta Was this translation helpful? Give feedback.
Hi @pypdeveloper ,
torch.cuda
is specifically targeted for NVIDIA devices with CUDA enabled.For Apple Silicon devices, you'll want to use
torch.mps
(MPS = metal performance shaders).See the documentation here: https://pytorch.org/docs/stable/notes/mps.html
Also for manual seed on MPS, you'll want to use
torch.mps.manual_seed(42)
(you can use any number, I just used 42 as an example), see the docs: https://pytorch.org/docs/stable/generated/torch.mps.manual_seed.html#torch.mps.manual_seedTo setup your device for Apple Silicon, you can use the example code: