macospytorchgpumacbookpro

GPU detected with Tensorflow but not with Pytorch on a Macbook Pro M2


I try to find out why the GPU is recognized with :

import tensorflow as tf
tf.test.is_gpu_available() #I'm getting TRUE as output

and not with:

import torch
torch.cuda.is_available() #I'm getting False as output

my 'pip list' output command concerning Pytorch is :

torch                         2.0.1
torchaudio                    2.0.2
torchvision                   0.15.2

How can I fix Pytorch so as it can detect the GPU ?

Thank you


Solution

  • A Mac with an M2 doesn't have a CUDA-capable GPU. However, you can use MPS acceleration:

    torch.backends.mps.is_available() # True
    device = torch.device("mps")
    x = torch.tensor([1,2,3], device=device) # This will use MPS acceleration.