PyTorch for Jetson

Hmm I’m not sure, I haven’t built for Python 3.8 before - can you confirm that cmake is installed?

image

Hmm ok, first try cleaning the build tree:

python3 setup.py clean

Then try building again, but with debug info enabled, so maybe you can see what’s going on with CMake:

DISTUTILS_DEBUG=1 python3 setup.py bdist_wheel

@dusty_nv first of all, thanks for your help.

I am getting the same error:

I’m having problems getting Pytorch to install on my Nano out of the box.
I’ve flashed it with the latest SDcard release(nv-jetson-nano-sd-card-image-r32.4.2.zip) and am doing the “Hello AI World” tutorial
following the instructions here
I’m selecting to install Pytorch for Python3.6 but am getting the following error after wheel build:

 >>> import torch
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "/home/armadilo/.local/lib/python3.6/site-packages/torch/__init__.py", line 79, in <module>
 from torch._C import *
ImportError: libcudart.so.10.0: cannot open shared object file: No such file or directory
>>> `

It looks like CUDA 10.2 was automatically installed as part of the OS install, but Torch wants CUDA 10.0.0
Symlink-ing to the existing 10.2.89 libraries is not working and adjusting PATH/PYTHONPATH/LD_LIBRARY_PATH variables hasn’t helped either. The documentation I’ve read says that Jetpack “4.2 or later” is necessary and I’ve got 4.3 .
I’ve also downloaded the 1.4 and 1.5.0 whl files and tried to install those as well, with similar results.
How do I resolve this to where I can install and use Torch successfully ?
This seems pretty broken out of the box.
This is a new “B” model Nano, so I’m not sure if there’s a separate install or Jetpack I’m supposed to be using for this. Like I said up top, I’m using what was linked to on the “Getting Started” page to flash to my SD Card.

I seem to have fixed this with an answer provided by this post here:

with the real kick being to update /etc/apt/sources.list.d/nvidia-l4t-apt-source.list

and then installing the following packages via apt install:

    cuda-cudart-10-0
    cuda-cusparse-10-0
    cuda-cusparse-dev-10-0
    cuda-cudart-dev-10-0
    cuda-cufft-10-0
    cuda-cufft-dev-10-0
    cuda-curand-10-0
    cuda-curand-dev-10-0
    libcudnn7
    libcudnn7-dev
    cuda-cublas-10-0
    cuda-cublas-dev-10-0

yields:

    >>> import torch
    >>> from __future__ import print_function
    >>> x=torch.rand(5,3)
    >>> print(x)
    tensor([[0.5153, 0.3057, 0.0356],
            [0.1835, 0.2287, 0.6168],
            [0.4648, 0.2534, 0.7381],
            [0.8680, 0.3254, 0.3808],
            [0.6713, 0.3364, 0.7354]])
    >>> torch.cuda.is_available()
    True
    >>> 

It would be great to get an explanation for why PyTorch and CUDA are not sync’ed dependency-wise,but PyTorch seems to work now, at least to a first approximation.

Hi @espressobot

We are too facing same error,

from torch._C import *
ImportError: libcudart.so.10.0: cannot open shared object file: No such file or directory

being new to nano, could you please elaborate on steps to follow to solve the error

"with the real kick being to update /etc/apt/sources.list.d/nvidia-l4t-apt-source.list
"

by this do you mean to update this file to have to

deb https://repo.download.nvidia.com/jetson/common r32 main
deb https://repo.download.nvidia.com/jetson/t210 r32 main

Would this be enough to change to 10.0 from 10.2

Please share, it would help a lot

Thanks

if you update the /etc/apt/sources.list.d/nvidia-l4t-apt-source.list, it will make it possible to install the 10.0 packages I listed above. So, this doesn’t mean you can use CUDA 10.2, but that it will fix the dependency issues with PyTorch 1.x wanting 10.0 . So you can at least use some version of PyTorch.
The answer for using torch and CUDA 10.2 seems to be to build PyTorch from source, or wait for NVIDIA to update their .whl to use 10.2 .

I’m also getting started using PyTorch myself, so I’m fine with using CUDA 10.0, I just need something that works.
HTH

Hi @espressobot, are you sure that the wheel files you downloaded were for JetPack 4.4?

I recommend that you try removing/uninstalling PyTorch, and then try again:

# uninstall PyTorch
$ pip3 uninstall torch
$ sudo pip3 uninstall torch 

# make sure it is uninstalled
$ python3 -c 'import torch'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'torch'

Now, try reinstalling using the JetPack 4.4 wheels above. I don’t recommend trying to downgrade to CUDA 10.0, it is some other issue you were facing during the PyTorch install as opposed to needing CUDA 10.0 instead of 10.2.

Only the PyTorch wheels for JetPack 4.2/4.3 were linked against CUDA 10.0, so if you are seeing that libcudart.so.10.0 error, you have a wheel installed that was built for JetPack 4.2/4.3 instead of JetPack 4.4.

I’m using whatever JetPack is provided by this image:
nv-jetson-nano-sd-card-image-r32.4.2.zip
Which I downloaded from here:
https://developer.nvidia.com/jetson-nano-sd-card-image

That’s installing CUDA 10.2. Running the install_pytorch.sh script downloads a .whl that is looking for 10.0.0
I did some searching on the NVIDIA site and also some basic Googling and this looks like the only available image for the Nano. Which is fine, I get wanting users to install and run with the latest packages.
But the NVIDIA-provided installer fails to install PyTorch properly.
So the issue is that the resources you’re providing to users are not in sync with each other, forcing me to find a hack that will let me go back to 10.0 because everything I’ve been able to find says that I have compile PyTorch from source if I want it to run with CUDA 10.2, or come up with my own hack for getting it to work with 10.0.0

Maybe the SDcard image needs to be updated or the components in it, like install_pytorch.sh, need to be updated.
This is not technically complicated, it’s just soaking up time.
My essential point is, this is broken out-of-the-box and you’re forcing users to come up with their own solutions.

Running the install_pytorch.sh script downloads a .whl that is looking for 10.0.0

@espressobot, yes I have been working to update the install_pytorch.sh script from jetson-inference GitHub to automatically detect JetPack 4.4 and install the different pip wheels instead. I am testing it now and it should be checked in later today, sorry about that. The install_pytorch.sh script is not part of JetPack image, it is from GitHub.

everything I’ve been able to find says that I have compile PyTorch from source if I want it to run with CUDA 10.2

The PyTorch wheels for CUDA 10.2 (JetPack 4.4) are provided at the top of this thread and on the Jetson Zoo, and it is also available in the l4t-pytorch container image. You needn’t compile PyTorch from source for CUDA 10.2, as I have already done it for PyTorch v1.2 through v1.5 and posted the wheels.

As recommended above, you can install the correct wheels for JetPack 4.4 yourself or use the l4t-pytorch container image. Attempting to downgrade to CUDA 10.0 is not necessary or recommended.

OK, the install_pytorch.sh script from jetson-inference has been updated to detect JetPack 4.4 and install the appropriate wheels for CUDA 10.2. It was checked in with commit f1584c1.

Either pull or re-clone the repo to obtain the updated script. If you re-clone, run the Hello AI World install steps as normal. Whereas if you want to pull to update an existing install, instead do the following:

$ cd jetson-inference
$ git pull origin master
$ cd build
$ cmake ../   # needed to re-sync the install_pytorch.sh script with the copy in the build/ dir
$ ./install_pytorch.sh

Then when you are running on JetPack 4.4, you should see the updated PyTorch installer display L4T R32.4 and PyTorch v1.4.0 (as highlighed in the screenshot below):

This indicates that it has properly detected your JetPack 4.4 version, and will install the PyTorch wheels for CUDA 10.2 instead. Apologies again for the confusion with the script.

I’m having problems applying the patch for jetpack4.4:

and I think that maybe it’s the reason why I can’t build pytorch from the source

Hi @itay010197, I think the issue may be that your terminal’s current working directory is not in the folder containing the pytorch source. First you need to clone PyTorch v1.4.0, change to that directory, and then use git apply pytorch-diff-jetpack-4.4.patch

@dusty_nv Thank for your help. I have applied the patch, but now I’m having another issue:


I have tried to run setup.py clean.
cmake version - 3.10.2

I have followed all of your instructions for building from source

You might want to try manually removing CMakeCache.txt and CMakeFiles directory if they still exist, or if the issue persists, to do a fresh re-clone of PyTorch - haven’t run into this before myself.

Did the content of torch-1.5.0-cp36-cp36m-linux_aarch64.whl change??
I tried to install it lately from the wheel as per the instructions and inside the wheel instead of having torch-1.5.0 it has torch 1.4.0!!
And then when I import it in python I get and error:

ryan-jetson@ryan-jetson-nano:~$ python3
Python 3.6.9 (default, Apr 18 2020, 01:56:04)
[GCC 8.4.0] on linux
Type “help”, “copyright”, “credits” or “license” for more information.

import torch
Traceback (most recent call last):
File “”, line 1, in
File “/usr/local/lib/python3.6/dist-packages/torch/init.py”, line 81, in
from torch._C import *
ImportError: libcudart.so.10.0: cannot open shared object file: No such file or directory

I have cuda 10.2 on my Jetson Nano. And I wonder if that’s the issue. Instead of libcudart.so.10.0 I have libcudart.so.10.2. I wonder if torch 1.4.0 is looking for an older CUDA version??

I’m using Jetson Nano with Jetpack 4.4 DP

Hi @rsamvelyan, you appear to have installed one of the wheels for JetPack 4.2/4.3, not the wheel for JetPack 4.4.

Here is the URL for the PyTorch v1.5 wheel for JetPack 4.4: https://nvidia.box.com/shared/static/3ibazbiwtkl181n95n9em3wtrca7tdzp.whl

1 Like

Did you found solution ?- asking as i can’t use pytorch 1.5.0 without MAGMA for flowtron project :(

That’s bad news of having docker image from NVIDIA with Pytorch which doesn’t support MAGMA