Pytorch import leads to libcudnn error

Hi,

I have been trying to install pytorch 2.6.0 in a new conda environment. I know pytorch install comes in with its own cuda bundle but the latest install I have been doing leads to following error when torch is imported.

I can resolve this by installing cudnn and cuda toolkit via conda but usually that leads to an older version install of cudnn.

I was wondering if this is a bug that I am encountering or if there is any issues with the way I am doing the torch installation.

Thanks for your help!

Do you see the needed nvidia runtime libs in your pip environment and did the logs show these were installed?

I did not notice cudnn in the conda environment after doing torch install so I ended up doing a conda install cudnn. Now, it does show the cudnn in the environment


but I am getting the same error while importing torch.

Conda packages are not built anymore since PyTorch 2.6 as we are releasing pip wheels going forward. Did you install a PyTorch binary from conda-forge?

Hi,

Thank you for your swift response. I did the original installation following the original command from pytorch website - pip3 install torch torchvision torchaudio. I selected Linux and CUDA 12.1 options.
The only way the import error was resolved if I did conda install cudnn which installed an older version of cudnn8.x and downgraded the cudatoolkit to 11.x in my torch env. That seemed to work but I installed timm which re-installed torch and broke the environment, re-installing cudnn did not fix the issue.

After further investigating I stumbled across this thread ImportError: libcudnn.so.8: cannot open shared object file: No such file or directory · Issue #104259 · pytorch/pytorch · GitHub and tried the following solutions

  1. conda env config vars set LD_LIBRARY_PATH=<your/path/to/missing/lib>
  2. sudo apt install cudnn

Both did not work. I noticed I already had a libcudnn9.so file in my torch env but for some reason it was not detected. I tried setting the path to the system libcudnn9.so it did not work.
sudo apt install cudnn did not work either.
Finally, I downgraded the cudatoolkit selection on torch website for torch installation - pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
this seemed to work and for now I am able to import torch successfully in the env.
I am wondering if there is an issue in the torch installatiion with cuda 12.1.

I don’t think the PyTorch wheel itself is broken and guess your environment might be. E.g. it doesn’t make sense to install an older cuDNN (version 8.x while PyTorch searches for 9.x) and CUDA (11.x instead of 12.x) to resolve any issues. I would recommend creating a new and empty virtual environment and installing PyTorch again there. If you see any issues, please let us know.

Makes sense! I created a new env and installed torch2.6+cu11.8 that seems to fix it. Thanks for your help.

Great, thanks for confirming!