Cannot install PyTorch on jetson nano for python 3.9

can’t install PyTorch with cuda for jetson nano with python 3.9. Found the wheels for 3.6 but the applications I am trying to use require python >= 3.7. Referred this Forum too but didnt help much since its also for 3.6. Is it true according to this that cuda torch is only for ubuntu 20? please help @dusty_nv

Edit: even the docker from above forum doesn’t have the cuda enabled.

me@me:~$ sudo docker run -it --rm --runtime nvidia --network host nvcr.io/nvidia/l4t-pytorch:r35.2.1-pth2.0-py3

root@me:/# 
root@me:/# ls
bin  boot  dev  etc  home  lib  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@me:/# python3
Python 3.8.10 (default, Nov 14 2022, 12:59:47) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch 
>>> print(torch.cuda.is_available())
/usr/local/lib/python3.8/dist-packages/torch/cuda/__init__.py:98: UserWarning: CUDA initialization: CUDA driver initialization failed, you might not have a CUDA gpu. (Triggered internally at /home/riship/old_pyt/pytorch/c10/cuda/CUDAFunctions.cpp:109.)
  return torch._C._cuda_getDeviceCount() > 0
False
>>> 

@brad007 it doesn’t work, because you are trying to run a container for JetPack 5 (L4T R35.x) on JetPack 4. Presuming that you have JetPack 4.6.1 or newer installed, you would run the L4T R32.7.x containers (those will have Python 3.6 though)

You would need to rebuilt PyTorch from source for Python 3.9. You can attempt to do that by following the Build from Source instructions from this topic. Just install the dev packages for the python version that you want, and call setup.py with the python version that you want (e.g. python3.9 setup.py bdist_wheel)

Seeing as PyTorch is normally built for Python 3.6 on Nano, you might run into some unforseen issues, but if you search that topic and others around the forum, others have been able to do it (for example, Install PyTorch with Python 3.8 on Jetpack 4.4.1)

Getting this error while trying to build using this solution. Tried to increase swap memory using this but didnt help same issue again

make[2]: *** [caffe2/CMakeFiles/torch_cuda.dir/__/aten/src/ATen/native/sparse/cuda/torch_cuda_generated_SoftMax.cu.o] Hangup
caffe2/CMakeFiles/torch_cuda.dir/build.make:59881: recipe for target 'caffe2/CMakeFiles/torch_cuda.dir/__/aten/src/ATen/native/sparse/cuda/torch_cuda_generated_SparseCUDATensor.cu.o' failed
make[2]: *** [caffe2/CMakeFiles/torch_cuda.dir/__/aten/src/ATen/native/sparse/cuda/torch_cuda_generated_SparseCUDATensor.cu.o] Hangup
CMakeFiles/Makefile2:5757: recipe for target 'caffe2/CMakeFiles/torch_cuda.dir/all' failed
make[1]: *** [caffe2/CMakeFiles/torch_cuda.dir/all] Hangup
Makefile:145: recipe for target 'all' failed
make: *** [all] Hangup
SIGHUP
CMake Error: Generator: execution of make failed. Make command was: /usr/bin/make -f Makefile -j 4 install && 
Building wheel torch-1.7.0a0
-- Building version 1.7.0a0
cmake --build . --target install --config Release -- -j 4
Traceback (most recent call last):
  File "setup.py", line 727, in <module>
    build_deps()
  File "setup.py", line 314, in build_deps
    build_caffe2(version=version,
  File "/home/rithvik/pytorch/tools/build_pytorch_libs.py", line 62, in build_caffe2
    cmake.build(my_env)
  File "/home/rithvik/pytorch/tools/setup_helpers/cmake.py", line 346, in build
    self.run(build_args, my_env)
  File "/home/rithvik/pytorch/tools/setup_helpers/cmake.py", line 141, in run
    check_call(command, cwd=self.build_dir, env=env)
  File "/usr/lib/python3.8/subprocess.py", line 364, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--target', 'install', '--config', 'Release', '--', '-j', '4']' returned non-zero exit status 1.

@brad007 try reducing the number of parallel build jobs it launches by running export MAX_JOBS=2 in your terminal first. Or try disabling ZRAM, mounting swap, and disabling the desktop GUI this way:

I tried this solution for the following error and still got the same

(env) rithvik@rithvik:~/pytorch$ echo $PATH
/home/rithvik/env/bin:/home/rithvik/.local/bin:/usr/local/cuda-11.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
(env) rithvik@rithvik:~/pytorch$ echo $LD_LIBRARY_PATH
/usr/local/cuda-11.0/lib64:/usr/local/cuda-11.0/lib64:/usr/local/cuda-11.0/lib64
(env) rithvik@rithvik:~/pytorch$ nvcc --version 
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Thu_Jun_11_22:26:42_PDT_2020
Cuda compilation tools, release 11.0, V11.0.194
Build cuda_11.0_bu.TC445_37.28540450_0
(env) rithvik@rithvik:~/pytorch$ ipython
Python 3.8.0 (default, Dec  9 2021, 17:53:27) 
Type 'copyright', 'credits' or 'license' for more information
IPython 8.12.2 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import torch

In [2]: torch.cuda.is_available()
/home/rithvik/pytorch/torch/cuda/__init__.py:52: UserWarning: CUDA initialization: CUDA unknown error - this may be due to an incorrectly set up environment, e.g. changing env variable CUDA_VISIBLE_DEVICES after program start. Setting the available devices to be zero. (Triggered internally at  /home/rithvik/pytorch/c10/cuda/CUDAFunctions.cpp:100.)
  return torch._C._cuda_getDeviceCount() > 0
Out[2]: False

Also was looking into this post and got this when I ran them on my device

(env) rithvik@rithvik:~/pytorch$ cat /sys/devices/gpu.0/gpu_powered_on
1
(env) rithvik@rithvik:~/pytorch$ cat /sys/devices/gpu.0/devfreq/57000000.gpu/power/runtime_enabled
disabled
(env) rithvik@rithvik:~/pytorch$ cd /usr/local/cuda/samples/0_Simple/vectorAdd
(env) rithvik@rithvik:/usr/local/cuda/samples/0_Simple/vectorAdd$ sudo make
[sudo] password for rithvik: 
/usr/local/cuda-11.0/bin/nvcc -ccbin g++ -I../../common/inc  -m64    -gencode arch=compute_61,code=sm_61 -gencode arch=compute_70,code=sm_70 -gencode arch=compute_75,code=sm_75 -gencode arch=compute_75,code=compute_75 -o vectorAdd.o -c vectorAdd.cu
/usr/local/cuda-11.0/bin/nvcc -ccbin g++   -m64      -gencode arch=compute_61,code=sm_61 -gencode arch=compute_70,code=sm_70 -gencode arch=compute_75,code=sm_75 -gencode arch=compute_75,code=compute_75 -o vectorAdd vectorAdd.o 
mkdir -p ../../bin/sbsa/linux/release
cp vectorAdd ../../bin/sbsa/linux/release
(env) rithvik@rithvik:/usr/local/cuda/samples/0_Simple/vectorAdd$ ./vectorAdd
[Vector addition of 50000 elements]
Failed to allocate device vector A (error code unknown error)!
(env) rithvik@rithvik:/usr/local/cuda/samples/0_Simple/vectorAdd$ 

Soon after you initiate the PyTorch build, it will print out a comprehensive summary of the build configuration, including if it detected CUDA, cuDNN, ect (and which versions). Check the build log for these, or next time you build it check it first for CUDA support before letting the build proceed.

It appears that you attempted to upgrade your Jetson Nano from CUDA 10.2 to CUDA 11 with the ARM SBSA packages, which will not work - ARM SBSA is intended for ARM servers that use discrete GPUs (i.e. over PCIe), as opposed to Jetson which uses an integrated GPU.

You’ll probably need to reflash your SD card to restore your environment to a known-working and supported configuration at this point.

But PyTorch says it can’t be installed with cuda 10 which is the default version with jetson nano

Then you would need to roll back and use an older version of PyTorch that does still support CUDA 10.2

Tried to install torch for 3.6 but getting these errors everytime

(env) rithvik@localhost:~$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Sun_Feb_28_22:34:44_PST_2021
Cuda compilation tools, release 10.2, V10.2.300
Build cuda_10.2_r440.TC440_70.29663091_0
(env) rithvik@localhost:~$ pip freeze | grep torch 
ptorch @ file:///home/rithvik/torch-1.8.0-cp36-cp36m-linux_aarch64.whl
(env) rithvik@localhost:~$ python3
Python 3.6.9 (default, Mar 10 2023, 16:46:00) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch 
Illegal instruction (core dumped)
(env) rithvik@localhost:~$ 

Do you get the same error when you import numpy ? If so, try running export OPENBLAS_CORETYPE=ARMV8 first:

Thank you, got it fixed I will try to downgrade my application to 3.6

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