Issues with getting cuda to work on torch, importing torch and cuda modules into Python

Question:

I’m having some basic issues running the torch and cuda modules in my Python script.

I think that this has something to do with the different versions of Python that I have installed. I have two versions of Python installed:

enter image description here

I think I have torch and cuda installed for the wrong one or something. I don’t know how to fix this.

Per the Pytorch website, I installed torch as follows:
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117

I’ve installed cuda as follows: pip3 install cuda-python==11.7 (It doesn’t matter if I use the newest version — I still get the same results.)

When I look up the versions, I get the following:
enter image description here

So it seems like it is all installed correctly.

However, if I run the following:

import torch

print(torch.cuda.is_available())

I get False.

If I try to run my code that uses torch, I get the following error:
enter image description here

I don’t get what I’m doing wrong. As far as I can tell, I’ve installed torch with CUDA enabled. So I’m not sure why it’s telling me otherwise.

Any ideas? Thanks for any help.

Edit: Here is the info for my GPU:
enter image description here

Asked By: ejn

||

Answers:

The issue had to do with the different versions of Python. I ended up using a Conda virtual environment, which solved this issue by ensuring I was using the correct version of Pytorch.

Answered By: ejn
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.