RuntimeError: CuDNN error: CUDNN_STATUS_SUCCESS - pytorch

I am running code that UI downloaded from github. It is supposed to be working (I saw that other people managed to activate it). When I try to run it I get the following error message:
RuntimeError: CuDNN error: CUDNN_STATUS_SUCCESS
The code uses pytorch 0.4.1. I have cuda installed.
When I run the command cat /usr/local/cuda/version.txt
I get the answer:
CUDA Version 10.0.130
When I run the command conda list -n <my env name>
I see:
cudatoolkit ver 9.0
cudnn ver 7.6.5
And now, my question:
What should I do to avoid this error?
Do I need to use pip install for a more recent version of cudnn? If so, which one?

I also faced the same issue. In my case, the PyTorch version was 0.4.1, and the Cuda version was 9.0. I solved the issue by adding this piece of code:
torch.backends.cudnn.benchmark = True

try this
if torch.cuda.is_available():
device = torch.device("cuda")
print("working on gpu")
else:
device = torch.device("cpu")
print("working on cpu")

Related

Cannot import torch Error loading ..\caffe2_nvrtc.dll" or one of its dependencies

I am on a Windows 10 64 bit system.
Pytorch for cuda has been working successfully for some time.
Today I tried to upgrade to the latest version of Pytorch (1.13) using
conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia
Now I cannot import torch. I get the error:
OSError: [WinError 126] The specified module could not be found. Error loading "C:\Users\alan\anaconda3\lib\site-packages\torch\lib\caffe2_nvrtc.dll" or one of its dependencies.
I have tried both in a Jupyter notebook and in the Spyder IDE.
I have tried completely removing Anaconda and reinstalling afresh and then reinstalling Pytorch with no success.
I do not believe I have any other versions of python installed.
The offending dll (caffe2_nvrtc.dll) does seem to be in the file location specified.
I have found various similar problems reported but they all date back to 2020 or earlier and none of them seemed to have a satisfactory solution.
Can anyone point me in the correct direction
I still do not understand why using conda did not work but I tried again using pip
and that did work
I experienced the same problem as yours today.
It turns out that when I use the anaconda prompt then the problem disappears.
Anaconda prompt could do it
Then I speculated that the only difference between these two scenarios is that when I use the anaconda prompt, I use the base anaconda environment, probably somehow the conda environment in spyder is not activated.
So the solution is to open the spyder in anaconda prompt like this:
Then it works.
This picture will tell you the cause for the problem.
problem...

RuntimeError: cuDNN version incompatibility

I wrote an LSTM NLP classifier with PyTorch, in google colab and it worked well. Now, I run it on google colab pro, but I get this error:
RuntimeError: cuDNN version incompatibility: PyTorch was compiled against (8, 3, 2) but found runtime version (8, 0, 5). PyTorch already comes bundled with cuDNN. One option to resolving this error is to ensure PyTorch can find the bundled cuDNN.one possibility is that there is a conflicting cuDNN in LD_LIBRARY_PATH.
I have no idea how to fix this. I'm using GPU on colab pro.
I've tried this link and it didn't work.
How I declared device:
DEVICE = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
Fixed via upgrading cuDNN to 8.4
reference (https://github.com/JaidedAI/EasyOCR/issues/716)
if you are using google colab uae this command
!pip install --upgrade torch torchvision

Segfault in pytorch on M1: torch.from_numpy(X).float()

I'm using an M1.
I'm trying to use pytorch for a conv net.
I have a numpy array that I'm trying to turn into a torch tensor.
When I call
torch.from_numpy(X)
pytorch throws an error that it got a double when it expected a float.
When I call
torch.from_numpy(X).float() on a friends computer, everything is fine.
But when I call this command on my computer, I get a segfault.
Has anyone seen this / know what might be happening / know how to fix?
What's your pytorch vision? I've encountered the same problem on my Macbook Pro M1, and my pytorch version is 1.12.0 at first. The I downgraded it to version 1.10.0 and the problem is solved. I suspect this has something to do with the compatibility with M1 in newer torch versions.
Actually I first uninstalled torch using pip3 uninstall torch and then reinstalled with pip3 install torch==1.10.0
But if you are using torchvision or some other affiliated packages, you may also need to downgrade them too.

RuntimeError: Could not load cudnn library. Check your cudnn installation. Maybe using the Theano flag dnn.base_path can help you

enter image description here
I don't know how to solve the problem, although I searched google.
My computer OS is win10. And following installed in a virtual environment.
enter image description here
enter image description here
UserWarning: Your cuDNN version is more recent than
Theano. If you encounter problems, try updating Theano or downgrading cuDNN to a version >= v5 and <= v7.
  warnings.warn("Your cuDNN version is more recent than "
ERROR (theano.gpuarray): Could not initialize pygpu, support disabled
RuntimeError: Could not load cudnn library. Check your cudnn installation. Maybe using the Theano flag dnn.base_path can help you. Current value "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1"
I had the same problem, and I solved it like this:
Open dnn.py.
(My path is : F:\Anaconda3\envs\python2_7\Lib\site-packages\theano)
Add 'cudnn64_8.dll' in WIN32_CUDNN_NAMES. WIN32_CUDNN_NAMES = ['cudnn64_8.dll', 'cudnn64_7.dll', 'cudnn64_6.dll', 'cudnn64_5.dll']

Theano 0.10: Can not use cuDNN on context None: cannot compile with cuDNN

I just updated theano to 0.10 version with pip:
pip install --no-deps git+https://github.com/Theano/Theano.git#egg=Theano
But it cannot be imported successfully, with the error message as follows:
Can not use cuDNN on context None: cannot compile with cuDNN.
We got this error: c:\users\yl~1\appdata\local\temp\try_flags_jbgv_m.c:4:19:  
fatal error: cudnn.h: No such file or directory compilation terminated.   
Mapped name None to device cuda: GeForce 940M (0000:01:00.0)
I haven't configured theano to use cudnn. I feel theano should works without it.
My .theanorc is:
Without the .theanorc file, theano works fine.
I have also posted this issue at:
https://github.com/Theano/Theano/issues/6063#issuecomment-310064365
The best solution I have is to bypass cudnn by add in the .theanorc:
[dnn]
enabled = False
but at the price of the decreased computation speed

Resources