Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Pytorch on Macbook pro (M1) GPU?

I tried to train a model using PyTorch on my Macbook pro. It uses the new generation apple M1 CPU. However, PyTorch couldn't recognize my GPUs.

GPU available: False, used: False
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs

Does anyone know any solution?

I have updated all the libraries to the latest versions.

like image 257
pesehr Avatar asked Aug 31 '25 10:08

pesehr


2 Answers

PyTorch added support for M1 GPU as of 2022-05-18 in the Nightly version. Read more about it in their blog post.

Simply install nightly: conda install pytorch -c pytorch-nightly --force-reinstall

Update: It's available in the stable version:

  • Conda:conda install pytorch torchvision torchaudio -c pytorch
  • pip: pip3 install torch torchvision torchaudio

To use (source):

mps_device = torch.device("mps")

# Create a Tensor directly on the mps device
x = torch.ones(5, device=mps_device)
# Or
x = torch.ones(5, device="mps")

# Any operation happens on the GPU
y = x * 2

# Move your model to mps just like any other device
model = YourFavoriteNet()
model.to(mps_device)

# Now every call runs on the GPU
pred = model(x)
like image 189
dominic Avatar answered Sep 03 '25 01:09

dominic


It looks like PyTorch support for the M1 GPU is in the works, but is not yet complete.

From @soumith on GitHub:

So, here's an update. We plan to get the M1 GPU supported. @albanD, @ezyang and a few core-devs have been looking into it. I can't confirm/deny the involvement of any other folks right now.

So, what we have so far is that we had a prototype that was just about okay. We took the wrong approach (more graph-matching-ish), and the user-experience wasn't great -- some operations were really fast, some were really slow, there wasn't a smooth experience overall. One had to guess-work which of their workflows would be fast.

So, we're completely re-writing it using a new approach, which I think is a lot closer to your good ole PyTorch, but it is going to take some time. I don't think we're going to hit a public alpha in the next ~4 months.

We will open up development of this backend as soon as we can.

That post: https://github.com/pytorch/pytorch/issues/47702#issuecomment-965625139

TL;DR: a public beta is at least 4 months out.

like image 32
Peter LaMantia Avatar answered Sep 03 '25 03:09

Peter LaMantia