Skip to content

How to fix ‘Runtimeerror: cudnn error: cudnn_status_not_initialized’?

  • by
  • 2 min read

Python is one of the easiest programming languages that even beginners can pick up and understand. At the same time, it’s also incredibly powerful, meaning it can be used for many applications. 

However, as far as programming has come in 2022, it’s still hard, and random bugs and glitches are the order of the day. In this article, we’re going over the “Runtimeerror: cudnn error: cudnn_status_not_initialized” error in Python when using PyTorch and giving you four ways to fix the problem. 

Also read: How to solve the Tower of Hanoi problem using Python?

Use the right CUDA version

The simplest way to fix this issue is by using the right CUDA version (11.1). You can use the pip command below to install CUDA before running your program. 

pip install torch==1.8.0+cu111 torchvision==0.9.0+cu111 torchaudio==0.8.0 -f

Downgrade to Torch-1.7.1

If you’re using another CUDA version and can’t upgrade (or downgrade) it, you can try downgrading Torch to version 1.7.1 and torchvision to version 0.8.2 by using the commands below.

pip install torch==1.7.1
pip install torchvision==0.8.2

Check your GPU memory

Another thing you need to keep in mind is that you should have enough GPU memory to run the program beforehand. You can do this by running the nvidia-smi command to see what processes are using GPU resources and then close them using the kill command and the process’ PID. 

Top 7 games for kids to learn coding | Candid.Technology

Force cuDNN initialisation

In some cases, you might find that you don’t have enough GPU memory available because PyTorch itself takes up a lot of GPU resources. To fix this, you can manually force cuDNN initialisation at the beginning of your script using a mock convolution as follows. 

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 aforementioned function forces cuDNN initialisation ignoring GPU limits and can help you fix the error. 

Also read: Fix: Python was not found; run without arguments to install 

Yadullah Abidi

Yadullah Abidi

Yadullah is a Computer Science graduate who writes/edits/shoots/codes all things cybersecurity, gaming, and tech hardware. When he's not, he streams himself racing virtual cars. He's been writing and reporting on tech and cybersecurity with websites like Candid.Technology and MakeUseOf since 2018. You can contact him here: