Newbie question: What are the prerequisites for running PyTorch with GPU?

Hi everyone, I’m new to deep learning libraries, so apologies in advance if this is something I’m already supposed to know.

I’ve used Theano before but guides for setting up the GPU there were very straightforward, also I was doing this using a WinPy instance on Windows. I come from a MATLAB background where I’m used to being able to play around with the variables and initialize things quickly, so naturally I felt like PyTorch may have more to offer.

But there isn’t that much documentation on how to set things up from scratch with PyTorch. I have Anaconda installed on Ubuntu and have tried the basic functionality of PyTorch that way, but I’m not sure how to get it working with CUDA. Any advice would be appreciated!

1 Like

Hi, welcome to PyTorch world.
Tensorflow’s installation guide’s NVIDIA requirements to run TensorFlow with GPU support would be helpful. It tells you how to install CUDA etc. Edited by moderator, pytorch does not need manual CUDA install

Then choose PyTorch with CUDA here.

1 Like

if you want to use pytorch with an NVIDIA GPU, all you need to do is install pytorch binaries and start using it. We ship with everything in-built (pytorch binaries include CUDA, CuDNN, NCCL, MKL, etc.).

So it’s a one-touch install:

  • Install pytorch from binaries ( http://pytorch.org has instructions)
  • Try a simple program with CUDA:
import torch
a = torch.randn(10).cuda()
print(a)
print(a + 2)
12 Likes

@smth thank you for your moderation. I used Tensorflow before installing PyTorch, so I misunderstood that they are needed.
These installations are complicated so PyTorch’s everything-in-build is cool.

1 Like

@smth Thanks for the reply! Is installing from the binaries the same as following the instructions on the front page? Because I’ve done this but I get a CUDA library error when running

a = torch.randn(10).cuda()

Just to make sure, I updated Pytorch with my Anaconda installation via the following

conda install pytorch torchvision cuda80 -c soumith

Still I get the following error:

Thanks again for the support!

Just wanted to report that I’ve installed CUDA 8.0 from the NVIDIA website and now .cuda() works. Thanks a lot for the help!

1 Like

Yup. You have to first do the CUDA binaries installation.

For UBUNTU:
https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1604&target_type=debnetwork

After that go to:
http://pytorch.org
and install required packages. it will work like charm.

Also, you can do the simple test as described by Soumith.
import torch
torch.cuda.is_available()

if the above lines return True then you have Cuda working else not.

Hi, this could be a very naive question because I am new to this.
So if I install PyTorch first, I wouldn’t have to manually install the NVIDIA software for TensorFlow later. Correct?

1 Like