How to install Pytorch and torchvison on NVIDIA L4T Base from NGC catalog

Hi

I used the L4T Base from the NGC catalog to create the container. I’m trying to install Pytorch and torchvision in this created container, but it fails.

People tell me why not use the NVIDIA L4T PyTorch from the NGC catalog.

However, NVIDIA L4T PyTorch has a large file size. My disk is not so free.

I pulled the following to match my Orin’s Jetpack.

$ sudo docker pull nvcr.io/nvidia/l4t-base:r35.1.0

I used the following to install Pytorch and torchvision.

Inside the docker container, pytorch installation is fine. succeed.

Inside the Docker container, I ran the following in order on my torchvision installation:

# apt-get install libjpeg-dev zlib1g-dev libpython3-dev libavcodec-dev libavformat-dev libswscale-dev
# python3 setup.py install --user

Running setup.py outputs the following error:

root@ubuntu:/yolo/torchvision# python3 setup.py install --user
Traceback (most recent call last):
  File "setup.py", line 9, in <module>
    import torch
  File "/usr/local/lib/python3.8/dist-packages/torch/__init__.py", line 198, in <module>
    _load_global_deps()
  File "/usr/local/lib/python3.8/dist-packages/torch/__init__.py", line 151, in _load_global_deps
    ctypes.CDLL(lib_path, mode=ctypes.RTLD_GLOBAL)
  File "/usr/lib/python3.8/ctypes/__init__.py", line 373, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libcurand.so.10: cannot open shared object file: No such file or directory
root@ubuntu:/yolo/torchvision# 

What is the reason for this? help me.

Hi,

You can find the PyTorch package from the below link:
https://docs.nvidia.com/deeplearning/frameworks/install-pytorch-jetson-platform/index.html

Since PyTorch has a dependency on the CUDA, please also install the CUDA library via apt as well.

$ sudo apt install cuda

Thanks.

@AastaLLL

Thank you for your advice.
I ran the following inside a Docker container and the cuda installation was successful.

# apt install cuda 

cuda was installed in the following location:

root@ubuntu:/usr/local# ls
bin  cuda  cuda-11  cuda-11.4  etc  games  include  lib  man  sbin  share  src

I ran the torchvision setup again.

# python3 setup.py install --user
root@ubuntu:/yolo/torchvision# python3 setup.py install --user
Traceback (most recent call last):
  File "setup.py", line 9, in <module>
    import torch
  File "/usr/local/lib/python3.8/dist-packages/torch/__init__.py", line 198, in <module>
    _load_global_deps()
  File "/usr/local/lib/python3.8/dist-packages/torch/__init__.py", line 151, in _load_global_deps
    ctypes.CDLL(lib_path, mode=ctypes.RTLD_GLOBAL)
  File "/usr/lib/python3.8/ctypes/__init__.py", line 373, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libcudnn.so.8: cannot open shared object file: No such file or directory

There was a change in the situation with the cuda installation, but now I got a different error.
What’s wrong? Help me.

@Heartful-echo you need to install libcudnn8 package as well, along with any other dependencies that PyTorch needs. These are typically already installed into the l4t-jetpack base container, but since you are using l4t-base they are not. On JetPack 5, CUDA/cuDNN/ect need to be installed into the containers themselves (which is why they are larger in size than JetPack 4, which mounts those components into the containers)