RuntimeError: cuDNN error: CUDNN_STATUS_NOT_INITIALIZED using pytorch

We Are Going To Discuss About RuntimeError: cuDNN error: CUDNN_STATUS_NOT_INITIALIZED using pytorch. So lets Start this Python Article.

RuntimeError: cuDNN error: CUDNN_STATUS_NOT_INITIALIZED using pytorch

  1. How to solve RuntimeError: cuDNN error: CUDNN_STATUS_NOT_INITIALIZED using pytorch

    There is some discussion regarding this here. I had the same issue but using cuda 11.1 resolved it for me.
    This is the exact pip command
    pip install torch==1.8.0+cu111 torchvision==0.9.0+cu111 torchaudio==0.8.0 -f https://download.pytorch.org/whl/torch_stable.html

  2. RuntimeError: cuDNN error: CUDNN_STATUS_NOT_INITIALIZED using pytorch

    There is some discussion regarding this here. I had the same issue but using cuda 11.1 resolved it for me.
    This is the exact pip command
    pip install torch==1.8.0+cu111 torchvision==0.9.0+cu111 torchaudio==0.8.0 -f https://download.pytorch.org/whl/torch_stable.html

Solution 1

There is some discussion regarding this here. I had the same issue but using cuda 11.1 resolved it for me.

This is the exact pip command

pip install torch==1.8.0+cu111 torchvision==0.9.0+cu111 torchaudio==0.8.0 -f https://download.pytorch.org/whl/torch_stable.html

Original Author saturn660 Of This Content

Solution 2

In my case it actually had nothing do with the PyTorch/CUDA/cuDNN version. PyTorch initializes cuDNN lazily whenever a convolution is executed for the first time. However, in my case there was not enough GPU memory left to initialize cuDNN because PyTorch itself already held the entire memory in its internal cache. One can release the cache manually with “torch.cuda.empty_cache()” right before the first convolution that is executed. A cleaner solution is to force cuDNN initialization at the beginning by doing a mock convolution:

def force_cudnn_initialization():
    s = 32
    dev = torch.device('cuda')
    torch.nn.functional.conv2d(torch.zeros(s, s, s, s, device=dev), torch.zeros(s, s, s, s, device=dev))

Calling the above function at the very beginning of the program solved the problem for me.

Original Author creiser Of This Content

Solution 3

I am also using Cuda 10.2. I had the exact same error when upgrading torch and torchvision to the latest version (torch-1.8.0 and torchvision-0.9.0). Which version are you using?

I guess this is not the best solution but by downgrading to torch-1.7.1 and torchvision-0.8.2 it works just fine.

Original Author Marie Duc Of This Content

Solution 4

In my cases this error occurred when trying to estimate loss.
I used a mixed bce-dice loss.
It turned out that my output was linear instead of sigmoid.
I then used the sigmoid predictions as of bellow and worked fine.

output = torch.nn.Sigmoid()(output)
loss = criterion1(output, target)

Original Author Ioannis Nasios Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

ittutorial team

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment