PyTorch for Jetson

Thank u, i shifted to default python version and the wheel for torch looks working. do u know where to find an aarch64 version whl for torchvision?

We don’t release pip wheels for torchvision, so you would need to build those yourself. However torchvision does come pre-installed into the l4t-pytorch and l4t-ml containers if you are using those.

Hi @dusty_nv

for PyTorch 1.12 did you apply any patches? I’m trying to build 1.12 from source on jetpack 4.5.1 with python = 3.9, is this even possible?

Hi @gbetsos, I haven’t built PyTorch 1.12, another team has taken over building it. I would follow the patches that I used for PyTorch 1.11 and manually apply them to PyTorch 1.12. I’ve been using the same set of patches for a while now.

1 Like

I tried to build version 1.12 on JetPack 4.5.1. I created a new conda env then followed all instructions from this page (including applying patch pytorch-1.10-jetpack-4.5.1.patch).

Build unfortunately fails:

[4878/5630] Building CXX object caffe2/CMakeFiles/torch_cuda.dir//aten/src/ATen/native/cudnn/Conv_v8.cpp.o
FAILED: caffe2/CMakeFiles/torch_cuda.dir/
/aten/src/ATen/native/cudnn/Conv_v8.cpp.o
/usr/bin/c++ -DAT_PER_OPERATOR_HEADERS -DHAVE_MALLOC_USABLE_SIZE=1 -DHAVE_MMAP=1 -DHAVE_SHM_OPEN=1 -DHAVE_SHM_UNLINK=1 -DMINIZ_DISABLE_ZIP_READER_CRC32_CHECKS -DONNXIFI_ENABLE_EXT=1 -DONNX_ML=1 -DONNX_NAMESPACE=onnx_torch -DTORCH_CUDA_BUILD_MAIN_LIB -DUSE_CUDA -DUSE_EXPERIMENTAL_CUDNN_V8_API -DUSE_EXTERNAL_MZCRC -D_FILE_OFFSET_BITS=64 -Dtorch_cuda_EXPORTS -I/home/nvidia/repos/pytorch/build/aten/src -I/home/nvidia/repos/pytorch/aten/src -I/home/nvidia/repos/pytorch/build -I/home/nvidia/repos/pytorch -I/home/nvidia/repos/pytorch/cmake/…/third_party/benchmark/include -I/home/nvidia/repos/pytorch/cmake/…/third_party/cudnn_frontend/include -I/home/nvidia/repos/pytorch/third_party/onnx -I/home/nvidia/repos/pytorch/build/third_party/onnx -I/home/nvidia/repos/pytorch/third_party/foxi -I/home/nvidia/repos/pytorch/build/third_party/foxi -I/home/nvidia/repos/pytorch/build/include -I/home/nvidia/repos/pytorch/torch/csrc/distributed -I/home/nvidia/repos/pytorch/aten/src/THC -I/home/nvidia/repos/pytorch/aten/src/ATen/cuda -I/home/nvidia/repos/pytorch/build/caffe2/aten/src -I/home/nvidia/repos/pytorch/aten/…/third_party/catch/single_include -I/home/nvidia/repos/pytorch/aten/src/ATen/… -I/home/nvidia/repos/pytorch/c10/cuda/…/… -I/home/nvidia/repos/pytorch/c10/… -I/home/nvidia/repos/pytorch/torch/csrc/api -I/home/nvidia/repos/pytorch/torch/csrc/api/include -isystem /home/nvidia/repos/pytorch/cmake/…/third_party/googletest/googlemock/include -isystem /home/nvidia/repos/pytorch/cmake/…/third_party/googletest/googletest/include -isystem /home/nvidia/repos/pytorch/third_party/protobuf/src -isystem /home/nvidia/repos/pytorch/third_party/XNNPACK/include -isystem /home/nvidia/repos/pytorch/cmake/…/third_party/eigen -isystem /home/nvidia/repos/pytorch/cmake/…/third_party/cub -isystem /usr/local/cuda-10.2/include -Wno-deprecated -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -fopenmp -DNDEBUG -DUSE_KINETO -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -DEDGE_PROFILER_USE_KINETO -O2 -fPIC -Wno-narrowing -Wall -Wextra -Werror=return-type -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-unused-parameter -Wno-unused-function -Wno-unused-result -Wno-unused-local-typedefs -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-psabi -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -DMISSING_ARM_VST1 -DMISSING_ARM_VLD1 -Wno-stringop-overflow -O3 -DNDEBUG -DNDEBUG -fPIC -D__NEON__ -DTH_HAVE_THREAD -Wall -Wextra -Wno-unused-parameter -Wno-unused-function -Wno-unused-result -Wno-unused-local-typedefs -Wno-missing-field-initializers -Wno-write-strings -Wno-unknown-pragmas -Wno-type-limits -Wno-array-bounds -Wno-sign-compare -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-missing-braces -Wno-maybe-uninitialized -fvisibility=hidden -O2 -DTORCH_CUDA_BUILD_MAIN_LIB -pthread -std=gnu++14 -MD -MT caffe2/CMakeFiles/torch_cuda.dir//aten/src/ATen/native/cudnn/Conv_v8.cpp.o -MF caffe2/CMakeFiles/torch_cuda.dir//aten/src/ATen/native/cudnn/Conv_v8.cpp.o.d -o caffe2/CMakeFiles/torch_cuda.dir/__/aten/src/ATen/native/cudnn/Conv_v8.cpp.o -c /home/nvidia/repos/pytorch/aten/src/ATen/native/cudnn/Conv_v8.cpp
In file included from /home/nvidia/repos/pytorch/cmake/…/third_party/cudnn_frontend/include/cudnn_frontend_ConvDesc.h:35:0,
from /home/nvidia/repos/pytorch/cmake/…/third_party/cudnn_frontend/include/cudnn_frontend.h:100,
from /home/nvidia/repos/pytorch/aten/src/ATen/native/cudnn/Conv_v8.cpp:10:
/home/nvidia/repos/pytorch/cmake/…/third_party/cudnn_frontend/include/cudnn_frontend_utils.h: In function ‘std::__cxx11::string cudnn_frontend::to_string(cudnnDataType_t)’:
/home/nvidia/repos/pytorch/cmake/…/third_party/cudnn_frontend/include/cudnn_frontend_utils.h:93:14: error: ‘CUDNN_DATA_INT64’ was not declared in this scope
case CUDNN_DATA_INT64:
^~~~~~~~~~~~~~~~
/home/nvidia/repos/pytorch/cmake/…/third_party/cudnn_frontend/include/cudnn_frontend_utils.h:93:14: note: suggested alternative: ‘CUDNN_DATA_INT8x4’
case CUDNN_DATA_INT64:
^~~~~~~~~~~~~~~~

CUDNN_DATA_INT64 doesn’t appear to be in the cuDNN headers for cuDNN 8.0 that’s in JetPack 4.5.1, so it seems like PyTorch 1.12 requires a newer version of cuDNN.

It is however defined in the cuDNN 8.3 headers that are in JetPack 4.6 and newer.

1 Like

Thanks for this reply. This means I have to upgrade to JetPack 4.6. I’m using a custom carrier board and unfortunately have no support from manufacturer. Can I install JetPack 4.6 somehow on the board?

Sorry, I don’t know the specifics of the carrier or presumably custom device tree that it has. Could you use an older version of PyTorch?

Tried with new environment, cloned PyTorch 1.10 (Python=3.8)

Getting error:

(torch10) nvidia@nvidia-desktop:~/repos/pytorch$ python3 setup.py bdist_wheel
Building wheel torch-1.10.0
Traceback (most recent call last):
File “setup.py”, line 309, in
cmake = CMake()
File “/home/nvidia/repos/pytorch/tools/setup_helpers/cmake.py”, line 102, in init
self._cmake_command = CMake._get_cmake_command()
File “/home/nvidia/repos/pytorch/tools/setup_helpers/cmake.py”, line 126, in _get_cmake_command
elif cmake is not None and CMake._get_version(cmake) >= distutils.version.LooseVersion(“3.10.0”):
File “/home/nvidia/repos/pytorch/tools/setup_helpers/cmake.py”, line 137, in _get_version
return distutils.version.LooseVersion(line.strip().split(’ ')[2])
AttributeError: module ‘distutils’ has no attribute ‘version’

@dusty_nv nevermind, I was able to overcome the issue using:

$ pip3 install setuptools==59.5.0

I finally managed to build the wheel of 1.10. But when I try to install pytorch from it I get the following error:

(torch10) nvidia@nvidia-desktop:~/repos/pytorch/dist$ pip3 install torch-1.10.0-cp38-cp38-linux_aarch64.whl
/usr/lib/python3/dist-packages/secretstorage/dhcrypto.py:15: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
from cryptography.utils import int_from_bytes
/usr/lib/python3/dist-packages/secretstorage/util.py:19: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
from cryptography.utils import int_from_bytes
Defaulting to user installation because normal site-packages is not writeable
ERROR: torch-1.10.0-cp38-cp38-linux_aarch64.whl is not a supported wheel on this platform.

Please note that I applied patch pytorch-1.10-jetpack-4.5.1.patch before compiling.

What does your pip3 --version show? Maybe you are using Python 3.6 version of pip3 instead of Python 3.8 version of pip3?

1 Like

(torch10) nvidia@nvidia-desktop:~/repos/yolov5$ pip3 --version
pip 21.3.1 from /home/nvidia/.local/lib/python3.6/site-packages/pip (python 3.6)

I am a bit confused, torch10 is supposed to be a python=3.8 conda env. How then can I install the wheel inside the torch10 environment?

Please note that inside my env I get the following response:

(torch10) nvidia@nvidia-desktop:~/repos/yolov5$ python3 --version
Python 3.8.13

I finally found the solution, thanks to @dusty_nv :

(yolov5) nvidia@xavier:~/Downloads$ python3.8 -m pip install torch-1.10.0-cp38-cp38-linux_aarch64.whl
Processing ./torch-1.10.0-cp38-cp38-linux_aarch64.whl
Collecting typing-extensions
Downloading typing_extensions-4.3.0-py3-none-any.whl (25 kB)
Installing collected packages: typing-extensions, torch
Successfully installed torch-1.10.0 typing-extensions-4.3.0

I have tried to compile PyTorch 1.10.0 with Python=3.9. I created a new virtual env with venv module, then followed instructions from this post.

So, I have cloned v1.10.0 branch of PyTorch, then applied patch for v.1.10.

I then exported all build options. Unfortunately step:

$ pip3.9 install -r requirements.txt

fails with:

Ignoring dataclasses: markers ‘python_version < “3.7”’ don’t match your environment
Collecting astunparse
Downloading astunparse-1.6.3-py2.py3-none-any.whl (12 kB)
Collecting expecttest
Downloading expecttest-0.1.3-py3-none-any.whl (6.5 kB)
Collecting future
Downloading future-0.18.2.tar.gz (829 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 829.2/829.2 kB 9.9 MB/s eta 0:00:00
Preparing metadata (setup.py) … done
Requirement already satisfied: numpy in /home/nvidia/venvs/yolov7env/lib/python3.9/site-packages (from -r requirements.txt (line 5)) (1.23.1)
Collecting psutil
Using cached psutil-5.9.1.tar.gz (479 kB)
Installing build dependencies … done
Getting requirements to build wheel … done
Preparing metadata (pyproject.toml) … done
Requirement already satisfied: pyyaml in /home/nvidia/venvs/yolov7env/lib/python3.9/site-packages (from -r requirements.txt (line 7)) (6.0)
Requirement already satisfied: requests in /home/nvidia/venvs/yolov7env/lib/python3.9/site-packages (from -r requirements.txt (line 8)) (2.28.1)
Requirement already satisfied: setuptools in /home/nvidia/venvs/yolov7env/lib/python3.9/site-packages (from -r requirements.txt (line 9)) (58.1.0)
Requirement already satisfied: six in /home/nvidia/venvs/yolov7env/lib/python3.9/site-packages (from -r requirements.txt (line 10)) (1.16.0)
Collecting types-dataclasses
Downloading types_dataclasses-0.6.6-py3-none-any.whl (2.9 kB)
Collecting typing_extensions
Downloading typing_extensions-4.3.0-py3-none-any.whl (25 kB)
Collecting wheel<1.0,>=0.23.0
Using cached wheel-0.37.1-py2.py3-none-any.whl (35 kB)
Requirement already satisfied: certifi>=2017.4.17 in /home/nvidia/venvs/yolov7env/lib/python3.9/site-packages (from requests->-r requirements.txt (line 8)) (2022.6.15)
Requirement already satisfied: idna<4,>=2.5 in /home/nvidia/venvs/yolov7env/lib/python3.9/site-packages (from requests->-r requirements.txt (line 8)) (3.3)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /home/nvidia/venvs/yolov7env/lib/python3.9/site-packages (from requests->-r requirements.txt (line 8)) (1.26.11)
Requirement already satisfied: charset-normalizer<3,>=2 in /home/nvidia/venvs/yolov7env/lib/python3.9/site-packages (from requests->-r requirements.txt (line 8)) (2.1.0)
Using legacy ‘setup.py install’ for future, since package ‘wheel’ is not installed.
Building wheels for collected packages: psutil
Building wheel for psutil (pyproject.toml) … error
error: subprocess-exited-with-error

× Building wheel for psutil (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [46 lines of output]
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-aarch64-cpython-39
creating build/lib.linux-aarch64-cpython-39/psutil
copying psutil/_common.py → build/lib.linux-aarch64-cpython-39/psutil
copying psutil/_psosx.py → build/lib.linux-aarch64-cpython-39/psutil
copying psutil/_pswindows.py → build/lib.linux-aarch64-cpython-39/psutil
copying psutil/_psaix.py → build/lib.linux-aarch64-cpython-39/psutil
copying psutil/_pssunos.py → build/lib.linux-aarch64-cpython-39/psutil
copying psutil/_psposix.py → build/lib.linux-aarch64-cpython-39/psutil
copying psutil/_psbsd.py → build/lib.linux-aarch64-cpython-39/psutil
copying psutil/init.py → build/lib.linux-aarch64-cpython-39/psutil
copying psutil/_pslinux.py → build/lib.linux-aarch64-cpython-39/psutil
copying psutil/_compat.py → build/lib.linux-aarch64-cpython-39/psutil
creating build/lib.linux-aarch64-cpython-39/psutil/tests
copying psutil/tests/test_memleaks.py → build/lib.linux-aarch64-cpython-39/psutil/tests
copying psutil/tests/test_process.py → build/lib.linux-aarch64-cpython-39/psutil/tests
copying psutil/tests/test_aix.py → build/lib.linux-aarch64-cpython-39/psutil/tests
copying psutil/tests/test_osx.py → build/lib.linux-aarch64-cpython-39/psutil/tests
copying psutil/tests/test_testutils.py → build/lib.linux-aarch64-cpython-39/psutil/tests
copying psutil/tests/test_connections.py → build/lib.linux-aarch64-cpython-39/psutil/tests
copying psutil/tests/test_system.py → build/lib.linux-aarch64-cpython-39/psutil/tests
copying psutil/tests/test_windows.py → build/lib.linux-aarch64-cpython-39/psutil/tests
copying psutil/tests/main.py → build/lib.linux-aarch64-cpython-39/psutil/tests
copying psutil/tests/test_posix.py → build/lib.linux-aarch64-cpython-39/psutil/tests
copying psutil/tests/runner.py → build/lib.linux-aarch64-cpython-39/psutil/tests
copying psutil/tests/test_contracts.py → build/lib.linux-aarch64-cpython-39/psutil/tests
copying psutil/tests/init.py → build/lib.linux-aarch64-cpython-39/psutil/tests
copying psutil/tests/test_bsd.py → build/lib.linux-aarch64-cpython-39/psutil/tests
copying psutil/tests/test_misc.py → build/lib.linux-aarch64-cpython-39/psutil/tests
copying psutil/tests/foo.py → build/lib.linux-aarch64-cpython-39/psutil/tests
copying psutil/tests/test_unicode.py → build/lib.linux-aarch64-cpython-39/psutil/tests
copying psutil/tests/test_sunos.py → build/lib.linux-aarch64-cpython-39/psutil/tests
copying psutil/tests/test_linux.py → build/lib.linux-aarch64-cpython-39/psutil/tests
running build_ext
building ‘psutil._psutil_linux’ extension
creating build/temp.linux-aarch64-cpython-39
creating build/temp.linux-aarch64-cpython-39/psutil
aarch64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -DPSUTIL_POSIX=1 -DPSUTIL_SIZEOF_PID_T=4 -DPSUTIL_VERSION=591 -DPSUTIL_LINUX=1 -I/home/nvidia/venvs/yolov7env/include -I/usr/include/python3.9 -c psutil/_psutil_common.c -o build/temp.linux-aarch64-cpython-39/psutil/_psutil_common.o
psutil/_psutil_common.c:9:10: fatal error: Python.h: No such file or directory
include <Python.h>
^~~~~~~~~~
compilation terminated.
error: command ‘/usr/bin/aarch64-linux-gnu-gcc’ failed with exit code 1
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for psutil
Failed to build psutil
ERROR: Could not build wheels for psutil, which is required to install pyproject.toml-based projects

Hi @gbetsos, have you installed the dev packages for Python / CPython 3.9?

Thanks again @dusty_nv ,

$ sudo apt-get install python3.9-dev

solved the problem.

Building PyTorch 1.10.0 with python=3.9 and JetPack 4.5.1 failed:

(yolov7env) nvidia> @xavier:~/repos/pytorch$ python3.9 setup.py bdist_wheel

Building wheel torch-1.10.0
– Building version 1.10.0
cmake --build . --target install --config Release
[1/1068] Linking CXX shared library lib/libtorch_cpu.so
FAILED: lib/libtorch_cpu.so

ldl /usr/lib/aarch64-linux-gnu/libopenblas.so -lrt -lm lib/libnnpack.a lib/libcpuinfo.a sleef/lib/libsleef.a lib/libbreakpad_common.a -lgcc_s -lgcc /usr/lib/aarch64-linux-gnu/libopenblas.so -lm -Wl,–whole-archive,“/home/nvidia/repos/pytorch/build/lib/libcaffe2_protos.a” -Wl,–no-whole-archive lib/libpthreadpool.a lib/libclog.a /usr/lib/aarch64-linux-gnu/libm.so -ldl -Wl,–whole-archive,“/home/nvidia/repos/pytorch/build/lib/libonnx.a” -Wl,–no-whole-archive lib/libonnx_proto.a lib/libprotobuf.a -pthread && :
caffe2/CMakeFiles/torch_cpu.dir/__/aten/src/ATen/core/Dict.cpp.o: file not recognized: File truncated
collect2: error: ld returned 1 exit status
[2/1068] Linking CXX executable bin/vec_test_all_types_DEFAULT
ninja: build stopped: subcommand failed.

It seems some files were corrupted during a previous, interrupted, compilation attempt. I deleted these files and started build process again.

I finally managed to successfully build the wheel

torch-1.10.0a0+git36449ea-cp39-cp39-linux_aarch64.whl

on a custom board with JetPack 4.5.1.

I then installed torchvision using the instructions given in this post. Unfortunately:

$ python3 setup.py install --user

didn’t work for me. I was getting Module not found error. So I used:

$ python3 setup.py install

OK gotcha - glad that you were eventually able to get it working!