How to test if installed torch is supported with CUDA

I am using windows and pycharm, Pytorch is installed by annaconda3 (conda install -c perterjc123 pytorch). My python is 3.6.2 and pytorch installed is pytorch 0.3.0.

I am trying to rerun this repository (https://github.com/vvanirudh/srnn-pytorch) but found the error “Torch not compiled with CUDA enabled”

I have no idea is my pytorch is not supported with CUDA or there is something I should change in the code.

2 Likes

Do you have an NVIDIA GPU? Have you installed cuda on this NVIDIA GPU? If not, then pytorch will not find cuda. It is not mandatory, you can use your cpu instead. Every time you see in the code something like tensor = tensor.cuda(), simply remove that line and the tensor will reside on the CPU. The problem is that it will be incredibly slow to the point of being unusable.

You can also explicitly check by doing
torch.cuda.is_available()
If it returns False, it means that CUDA is not available on your machine

8 Likes

Great thanks to your reply. I had GTX 1070 graphic card and it has GPU.

I followed the link to install cudatoolkit in python (https://developer.nvidia.com/how-to-cuda-python) and run the sample test successfully. However, torch.cuda.is_available() still shows False. It will be appreciated If you could tell me how to make CUDA work with torch.

Which OS are you using?

Why did you use that command to install torch? On the website it’s written you should use

conda install pytorch torchvision cuda90 -c pytorch

for CUDA 9.0, otherwise
conda install pytorch torchvision -c pytorch

Try removing it and installing it with these two commands. Otherwise you can try installing from source, check out the instructions on the pytorch github page.

Does PyTorch uses it own CUDA or uses the system installed CUDA?

As I said in the post, I use Windows with Annaconda3. Thanks for the two command lines. However, the package is not for Windows (package missing in current channels).

Ah, I see. Then have you tried installing it from source? Where did you find the windows package? Maybe you can ask the author to see if there is CUDA support

I just made it work now! I checked the developed post (https://github.com/pytorch/pytorch/issues/494), and some guy made it work and I installed it from his source. Only cuda80 works in my desktop. And also thanks for your reply!

1 Like

When installing PyTorch on Windows, should I install CUDA for nVidia site or it will be installed by pip installer?

I’m using Windows 10 (Installing PyTorch 0.4.1 on Windows 10 [WinPython]).

pip install http://download.pytorch.org/whl/cu90/torch-0.4.1-cp36-cp36m-win_amd64.whl 
pip install torchvision

just pip will do the job

I’m not sure you’re right.
If the user didn’t install system wide CUDA it seems it won’t work.

I couldn’t get official answer whether the pip install should take care of the CUDA or not.

Yes, you should install at least one system-wide CUDA installation on Windows when you use the GPU package. It’s recommended that you install the same version of CUDA that PyTorch compiles with. It will work even when the two versions mismatch. But you’ll then have to pay attention to the version of the GPU drivers.

Does PyTorch uses it own CUDA or uses the system installed CUDA?
Well, it uses both the local and the system-wide CUDA library on Windows, the system part is nvcuda.dll and nvfatbinaryloader.dll. They are located in the %systemroot%, so I’m afraid we could not put them in the package due to some potential permission issues. The reason why we use the local CUDA installation is to prevent dll load failure. e.g. Some users don’t have CUDNN installed. I don’t think the missing of any optional CUDA dependency should be a barrier to use our package on Windows.

Should pip install s take care of the CUDA or not?
No, at least the answer is no on Windows. We don’t use pip to install CUDA on Windows. We just use pip to select the package you want. For most users, it may be no differences using cuda80/cuda90. But if you are using some new or legacy cards, then you can only use specific CUDA distributions.

I’m not sure I understood all.
Could we get away with installing the CUDA Toolkit on Windows and have all installed by pip only for PyTorch?

I don’t need CUDA on my computer besides for PyTorch so I’d be happy if PyTorch could be independent and self sustained (All its dependencies supplied in the pip downloaded).

Once you install cuda, a quick way to test if CUDA is available is using the line below

python -c 'import torch; print(torch.cuda.is_available())'

That’s nearly an impossible task. Did you read my post? Some DLLs are installed to the system directory. pip or any python package cannot do this. Because there are permission issues.

@peterjc123, couldn’t we put the DLL’s in other folders on the path?
Like those dedicated to Python?

Well, I don’t know exactly the answer. Because I have never tried this before. But according to some posts, these two files will get updated with the Graphics driver. So the problem will become a little bit complex. For users that don’t have CUDA installed, I just don’t know if the DLLs will still work when drivers get updated. But we could try your suggestion because it doesn’t affect the users that have CUDA installed. See document from MSDN. Anyway, thanks for your suggestion.

1 Like

Yep,
I think it is the right policy to take.
First try to make it work out of the box independent of anything.
If it works, you reduced the the level of frustration for new users.

In case of any issue with CUDA still the first step would be - Install the latest CUDA drivers.

Thank You.

I tried everything to only the following steps works: The cuda 10 is too new for my graphic card.

(1)go to previous version of cuda & pytorch here:


(2)following the page instruction and download *.whl file suitable for my python version and platform. for me it’s python 3.6 , windows
(3)install *.whl file
(4)test if torch.cuda.is_available() returns True

I am running windows 10 with Nvidia GTX 1070

CUDA10 supports the GTX1070. Which CUDA version did you install in the end?