Cannot install Pytorch 2.x with CUDA support

I need to install Pytorch 2.x with CUDA support on my Jetson Orin Nano. I’ve followed the instructions specified here:

https://docs.nvidia.com/deeplearning/frameworks/install-pytorch-jetson-platform/index.html

But after importing Pytorch I got the following error:

>>> import torch
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/<username>/miniconda3/envs/<envname>/lib/python3.8/site-packages/torch/__init__.py", line 229, in <module>
    from torch._C import *  # noqa: F403
ImportError: libcudnn.so.8: cannot open shared object file: No such file or directory

Here are my specs:

  • Device: Jetson Orin Nano
  • OS: Ubuntu 20.04.6 LTS 64bits
  • JetPack version: 5.3 (nvidia-l4t-core 35.3.1-xxx)
  • CUDA version: 11.4
  • Python version: 3.8

This is the .whl that I want to install:
(from PyTorch for Jetson)

Note that I can install Pytorch successfully with the following pip command:

pip3 install --pre torch==2.1 --extra-index-url https://developer.download.nvidia.com/compute/redist/jp/v53

However, for some reason CUDA support is not there:

>>> import torch
>>> torch.cuda.is_available()
False

(I want to install it in a Conda venv but I have the same result after installing it without using a venv.)

Please, any help will be appreciated.

Hi,

Could you share the output of below command with us?

$ sudo apt show nvidia-jetpack
$ python -c "import torch; print(torch.__version__); print(torch.backends.cudnn.version())"

Thanks.

Thanks for the response!

This is the output for apt show nvidia-jetpack:

Package: nvidia-jetpack
Version: 5.1.1-b56
Priority: standard
Section: metapackages
Maintainer: NVIDIA Corporation
Installed-Size: 199 kB
Depends: nvidia-jetpack-runtime (= 5.1.1-b56), nvidia-jetpack-dev (= 5.1.1-b56)
Homepage: http://developer.nvidia.com/jetson
Download-Size: 29,3 kB
APT-Sources: https://repo.download.nvidia.com/jetson/common r35.3/main arm64 Packages
Description: NVIDIA Jetpack Meta Package

When I install PyTorch following the guide from docs.nvidia.com I got the error right after importing torch library so I cannot print output of torch and cudnn versions:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/.../miniconda3/envs/.../lib/python3.8/site-packages/torch/__init__.py", line 229, in <module>
    from torch._C import *  # noqa: F403
ImportError: libcudnn.so.8: cannot open shared object file: No such file or directory

If I install PyTorch with the alternative command I mentioned I got the following outputs:

2.1.0
None

I was installing PyTorch compilation for JP v5.3 but it seems I actually have v5.1. However, I got the same outputs if I install PyTorch from:
pip3 install --pre torch==2.1 --extra-index-url https://developer.download.nvidia.com/compute/redist/jp/v51

Just in case, this is the output from nvcc --version:

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Sun_Oct_23_22:16:07_PDT_2022
Cuda compilation tools, release 11.4, V11.4.315
Build cuda_11.4.r11.4/compiler.31964100_0

I hope these details could help to solve the problem.

Thank you.

Hi,

It looks like you have a CPU version of PyTorch.
Could you try if our package works outside of the virtual environment?

Thanks.

I tried installing it outside of the virtual environment following the installation guide but I’m still having the same error after importing PyTorch:

>>> import torch
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/<username>/.local/lib/python3.8/site-packages/torch/__init__.py", line 229, in <module>
    from torch._C import *  # noqa: F403
ImportError: libcudnn.so.8: cannot open shared object file: No such file or directory

I’m also using Python 3.8 outside of the virtual environment.

It seems that some file or directory related with cudnn is missing so I added this to my ~/.bashrc but it made no effect:

export PATH=/usr/local/cuda-11.4/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-11.4/lib64:$LD_LIBRARY_PATH

Hi,

Could you try the below command to see if it works?

$ wget https://developer.download.nvidia.cn/compute/redist/jp/v512/pytorch/torch-2.1.0a0+41361538.nv23.06-cp38-cp38-linux_aarch64.whl -O torch-2.1.0a0+41361538.nv23.06-cp38-cp38-linux_aarch64.whl 
$ pip3 install ./torch-2.1.0a0+41361538.nv23.06-cp38-cp38-linux_aarch64.whl

Thanks.

I tried but I’m still having the same error.

I tried to reinstall cuDNN but it had no effect neither:

wget https://developer.download.nvidia.com/compute/cudnn/9.3.0/local_installers/cudnn-local-tegra-repo-ubuntu2004-9.3.0_1.0-1_arm64.deb
sudo dpkg -i cudnn-local-tegra-repo-ubuntu2004-9.3.0_1.0-1_arm64.deb
sudo cp /var/cudnn-local-tegra-repo-ubuntu2004-9.3.0/cudnn-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cudnn

(from NVIDIA webpage)

Hi,

It looks like you upgraded the cuDNN version from the website.

But our prebuilt package is built with the default cuDNN version.
For JetPack 5.1.2, it should be 8.6.0.

Please uninstall cuDNN 9.3.0, install the cuDNN from JetPack, and try it again.
Thanks.

Great! That solved the problem, thank you so much!

I removed my current cuDNN installation:

$ dpkg -l | grep cudnn
...
cudnn-local-tegra-repo-ubuntu2004-9.3.0
...
$ sudo apt-get purge cudnn-local-tegra-repo-ubuntu2004-9.3.0

After that I installed cuDNN 8.6.0:

$ sudo apt-get install libcudnn8 libcudnn8-dev libcudnn8-samples
$ dpkg -l | grep cudnn
ii  libcudnn8                                  8.6.0.166-1+cuda11.4                  arm64        cuDNN runtime libraries
ii  libcudnn8-dev                              8.6.0.166-1+cuda11.4                  arm64        cuDNN development libraries and headers
ii  libcudnn8-samples                          8.6.0.166-1+cuda11.4                  arm64        cuDNN samples

Now I can import PyTorch with CUDA support:

$ python
>>> import torch
>>> torch.cuda.is_available()
True
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.