Jetson orin nx build torchvision from source fail

hello, I’m having trouble when trying to compile torchvision from source. I mainly followed the instructions from PyTorch for Jetson - Jetson & Embedded Systems / Jetson Nano - NVIDIA Developer Forums

After I successfully installed pytorch 1.13.0 in miniconda env, I tried it and cuda is usable (torch.cuda.is_available() returns true), but when I cloned codes from pytorch/vision: Datasets, Transforms and Models specific to Computer Vision (github.com) and run setup.py, it won’t succeed, showing something wrong with c++ std ‘clamp’. Though I have looked into it, it seems nobody is having the same trouble and I really don’t know how to handle…can you help me please?

here’s basic info and error log

Python 3.8.10

cuda 11.4.315

cudnn 8.6.0.166

L4T: 35.3.1 Jetpack: 5.1.1

log

(pytorch113) sputnik-orin@sputnik-jetson-orin:~/vision-main$ python setup.py install --user
setup.py:10: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  from pkg_resources import DistributionNotFound, get_distribution, parse_version
fatal: not a git repository (or any of the parent directories): .git
Building wheel torchvision-0.14.0
Compiling extensions with following flags:
  FORCE_CUDA: False
  FORCE_MPS: False
  DEBUG: False
  TORCHVISION_USE_PNG: True
  TORCHVISION_USE_JPEG: True
  TORCHVISION_USE_NVJPEG: True
  TORCHVISION_USE_FFMPEG: True
  TORCHVISION_USE_VIDEO_CODEC: True
  NVCC_FLAGS: 
Compiling with debug mode OFF
Found PNG library
Building torchvision with PNG image support
  libpng version: 1.6.37
  libpng include path: /usr/include/libpng16
Running build on conda-build: False
Running build on conda: True
Building torchvision with JPEG image support
  libjpeg include path: /home/sputnik-orin/miniconda3/envs/pytorch113/include
  libjpeg lib path: /home/sputnik-orin/miniconda3/envs/pytorch113/lib
Building torchvision without NVJPEG image support
Building torchvision without ffmpeg support
Building torchvision without video codec support
running install
/home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/setuptools/_distutils/cmd.py:66: SetuptoolsDeprecationWarning: setup.py install is deprecated.
!!

        ********************************************************************************
        Please avoid running ``setup.py`` directly.
        Instead, use pypa/build, pypa/installer or other
        standards-based tools.

        See https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html for details.
        ********************************************************************************

!!
  self.initialize_options()
/home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/setuptools/_distutils/cmd.py:66: EasyInstallDeprecationWarning: easy_install command is deprecated.
!!

        ********************************************************************************
        Please avoid running ``setup.py`` and ``easy_install``.
        Instead, use pypa/build, pypa/installer or other
        standards-based tools.

        See https://github.com/pypa/setuptools/issues/917 for details.
        ********************************************************************************

!!
  self.initialize_options()
running bdist_egg
running egg_info
writing torchvision.egg-info/PKG-INFO
writing dependency_links to torchvision.egg-info/dependency_links.txt
writing requirements to torchvision.egg-info/requires.txt
writing top-level names to torchvision.egg-info/top_level.txt
/home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/utils/cpp_extension.py:472: UserWarning: Attempted to use ninja as the BuildExtension backend but we could not find ninja.. Falling back to using the slow distutils backend.
  warnings.warn(msg.format('we could not find ninja.'))
reading manifest file 'torchvision.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no previously-included files matching '__pycache__' found under directory '*'
warning: no previously-included files matching '*.py[co]' found under directory '*'
adding license file 'LICENSE'
writing manifest file 'torchvision.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-aarch64/egg
running install_lib
running build_py
copying torchvision/version.py -> build/lib.linux-aarch64-cpython-38/torchvision
running build_ext
building 'torchvision.image' extension
creating build/temp.linux-aarch64-cpython-38/home
creating build/temp.linux-aarch64-cpython-38/home/sputnik-orin
creating build/temp.linux-aarch64-cpython-38/home/sputnik-orin/vision-main
creating build/temp.linux-aarch64-cpython-38/home/sputnik-orin/vision-main/torchvision
creating build/temp.linux-aarch64-cpython-38/home/sputnik-orin/vision-main/torchvision/csrc
creating build/temp.linux-aarch64-cpython-38/home/sputnik-orin/vision-main/torchvision/csrc/io
creating build/temp.linux-aarch64-cpython-38/home/sputnik-orin/vision-main/torchvision/csrc/io/image
creating build/temp.linux-aarch64-cpython-38/home/sputnik-orin/vision-main/torchvision/csrc/io/image/cpu
creating build/temp.linux-aarch64-cpython-38/home/sputnik-orin/vision-main/torchvision/csrc/io/image/cuda
gcc -pthread -B /home/sputnik-orin/miniconda3/envs/pytorch113/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DPNG_FOUND=1 -DJPEG_FOUND=1 -DNVJPEG_FOUND=0 -I/home/sputnik-orin/vision-main/torchvision/csrc -I/usr/include/libpng16 -I/home/sputnik-orin/vision-main/torchvision/csrc -I/home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include -I/home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include/torch/csrc/api/include -I/home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include/TH -I/home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include/THC -I/usr/local/cuda/include -I/home/sputnik-orin/vision-main/torchvision/csrc/io/image -I/home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include -I/home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include/torch/csrc/api/include -I/home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include/TH -I/home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include/THC -I/usr/local/cuda/include -I/home/sputnik-orin/miniconda3/envs/pytorch113/include/python3.8 -c /home/sputnik-orin/vision-main/torchvision/csrc/io/image/cpu/common_jpeg.cpp -o build/temp.linux-aarch64-cpython-38/home/sputnik-orin/vision-main/torchvision/csrc/io/image/cpu/common_jpeg.o -g0 -DTORCH_API_INCLUDE_EXTENSION_H -DPYBIND11_COMPILER_TYPE=\"_gcc\" -DPYBIND11_STDLIB=\"_libstdcpp\" -DPYBIND11_BUILD_ABI=\"_cxxabi1013\" -DTORCH_EXTENSION_NAME=image -D_GLIBCXX_USE_CXX11_ABI=1 -std=c++14
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
gcc -pthread -B /home/sputnik-orin/miniconda3/envs/pytorch113/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DPNG_FOUND=1 -DJPEG_FOUND=1 -DNVJPEG_FOUND=0 -I/home/sputnik-orin/vision-main/torchvision/csrc -I/usr/include/libpng16 -I/home/sputnik-orin/vision-main/torchvision/csrc -I/home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include -I/home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include/torch/csrc/api/include -I/home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include/TH -I/home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include/THC -I/usr/local/cuda/include -I/home/sputnik-orin/vision-main/torchvision/csrc/io/image -I/home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include -I/home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include/torch/csrc/api/include -I/home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include/TH -I/home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include/THC -I/usr/local/cuda/include -I/home/sputnik-orin/miniconda3/envs/pytorch113/include/python3.8 -c /home/sputnik-orin/vision-main/torchvision/csrc/io/image/cpu/decode_image.cpp -o build/temp.linux-aarch64-cpython-38/home/sputnik-orin/vision-main/torchvision/csrc/io/image/cpu/decode_image.o -g0 -DTORCH_API_INCLUDE_EXTENSION_H -DPYBIND11_COMPILER_TYPE=\"_gcc\" -DPYBIND11_STDLIB=\"_libstdcpp\" -DPYBIND11_BUILD_ABI=\"_cxxabi1013\" -DTORCH_EXTENSION_NAME=image -D_GLIBCXX_USE_CXX11_ABI=1 -std=c++14
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
gcc -pthread -B /home/sputnik-orin/miniconda3/envs/pytorch113/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DPNG_FOUND=1 -DJPEG_FOUND=1 -DNVJPEG_FOUND=0 -I/home/sputnik-orin/vision-main/torchvision/csrc -I/usr/include/libpng16 -I/home/sputnik-orin/vision-main/torchvision/csrc -I/home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include -I/home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include/torch/csrc/api/include -I/home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include/TH -I/home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include/THC -I/usr/local/cuda/include -I/home/sputnik-orin/vision-main/torchvision/csrc/io/image -I/home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include -I/home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include/torch/csrc/api/include -I/home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include/TH -I/home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include/THC -I/usr/local/cuda/include -I/home/sputnik-orin/miniconda3/envs/pytorch113/include/python3.8 -c /home/sputnik-orin/vision-main/torchvision/csrc/io/image/cpu/decode_jpeg.cpp -o build/temp.linux-aarch64-cpython-38/home/sputnik-orin/vision-main/torchvision/csrc/io/image/cpu/decode_jpeg.o -g0 -DTORCH_API_INCLUDE_EXTENSION_H -DPYBIND11_COMPILER_TYPE=\"_gcc\" -DPYBIND11_STDLIB=\"_libstdcpp\" -DPYBIND11_BUILD_ABI=\"_cxxabi1013\" -DTORCH_EXTENSION_NAME=image -D_GLIBCXX_USE_CXX11_ABI=1 -std=c++14
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
/home/sputnik-orin/vision-main/torchvision/csrc/io/image/cpu/decode_jpeg.cpp: In function ‘unsigned char vision::image::{anonymous}::clamped_cmyk_rgb_convert(unsigned char, unsigned char)’:
/home/sputnik-orin/vision-main/torchvision/csrc/io/image/cpu/decode_jpeg.cpp:77:15: error: ‘clamp’ is not a member of ‘std’
   77 |   return std::clamp(k - v, 0, 255);
      |               ^~~~~
/home/sputnik-orin/vision-main/torchvision/csrc/io/image/cpu/decode_jpeg.cpp:77:15: note: suggested alternatives:
In file included from /home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include/ATen/Functions.h:476,
                 from /home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include/ATen/ATen.h:13,
                 from /home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include/torch/csrc/api/include/torch/types.h:3,
                 from /home/sputnik-orin/vision-main/torchvision/csrc/io/image/cpu/decode_jpeg.h:3,
                 from /home/sputnik-orin/vision-main/torchvision/csrc/io/image/cpu/decode_jpeg.cpp:1:
/home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include/ATen/ops/clamp.h:31:19: note:   ‘at::clamp’
   31 | inline at::Tensor clamp(const at::Tensor & self, const c10::optional<at::Tensor> & min={}, const c10::optional<at::Tensor> & max={}) {
      |                   ^~~~~
In file included from /home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include/ATen/MethodOperators.h:100,
                 from /home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include/ATen/core/TensorBody.h:40,
                 from /home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include/ATen/core/Tensor.h:3,
                 from /home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include/ATen/DeviceGuard.h:3,
                 from /home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include/ATen/ATen.h:9,
                 from /home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include/torch/csrc/api/include/torch/types.h:3,
                 from /home/sputnik-orin/vision-main/torchvision/csrc/io/image/cpu/decode_jpeg.h:3,
                 from /home/sputnik-orin/vision-main/torchvision/csrc/io/image/cpu/decode_jpeg.cpp:1:
/home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torch/include/ATen/ops/clamp_ops.h:17:18: note:   ‘at::_ops::clamp’
   17 | struct TORCH_API clamp {
      |                  ^~~~~
error: command '/usr/bin/gcc' failed with exit code 1

By the way, my gcc and g++ version is 9.4, which by default supports c++14.

Hi,

The error seems related to the C++17 version.

Is C++17 available in your environment?
If not, could you turn off the FFMPEG support and try it again?

Thanks.

Thank u for your answer. I tried as you said, switching the “TORCHVISION_USE_FFMPEG” to 0 and run it again. But the std ‘clamp’ error still appears! ! Which really depresses me.

So I tried to went further : when I look into this time’s error log again, I find:

cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
/home/sputnik-orin/vision-main/torchvision/csrc/io/image/cpu/decode_jpeg.cpp: In function ‘unsigned char vision::image::{anonymous}::clamped_cmyk_rgb_convert(unsigned char, unsigned char)’:
/home/sputnik-orin/vision-main/torchvision/csrc/io/image/cpu/decode_jpeg.cpp:77:15: error: ‘clamp’ is not a member of ‘std’
   77 |   return std::clamp(k - v, 0, 255);
      |               ^~~~~

So i really SUSPECT that rather than ffmpeg support, the JPEG support also requires c++17 .

At this moment, I set the extensions as followed:

print("Compiling extensions with following flags:")
    force_cuda = os.getenv("FORCE_CUDA", "0") == "1"
    print(f"  FORCE_CUDA: {force_cuda}")
    force_mps = os.getenv("FORCE_MPS", "0") == "1"
    print(f"  FORCE_MPS: {force_mps}")
    debug_mode = os.getenv("DEBUG", "0") == "1"
    print(f"  DEBUG: {debug_mode}")
    use_png = os.getenv("TORCHVISION_USE_PNG", "1") == "1"
    print(f"  TORCHVISION_USE_PNG: {use_png}")
    use_jpeg = os.getenv("TORCHVISION_USE_JPEG", "1") == "0"
    print(f"  TORCHVISION_USE_JPEG: {use_jpeg}")
    use_nvjpeg = os.getenv("TORCHVISION_USE_NVJPEG", "1") == "0"
    print(f"  TORCHVISION_USE_NVJPEG: {use_nvjpeg}")
    use_ffmpeg = os.getenv("TORCHVISION_USE_FFMPEG", "1") == "0"
    print(f"  TORCHVISION_USE_FFMPEG: {use_ffmpeg}")
    use_video_codec = os.getenv("TORCHVISION_USE_VIDEO_CODEC", "1") == "0"
    print(f"  TORCHVISION_USE_VIDEO_CODEC: {use_video_codec}")

    nvcc_flags = os.getenv("NVCC_FLAGS", "")
    print(f"  NVCC_FLAGS: {nvcc_flags}")
  

Run setup.py, compile succeeded. So I made this by disabling many important functions of torchvision.

However, it is obvious that this torchvision I built was bad. When I tried to import it in Conda env, it says:

(pytorch113) sputnik-orin@sputnik-jetson-orin:~/SPUTNIK/YoV2 _10_17_sptvideo$ python
Python 3.8.0 | packaged by conda-forge | (default, Nov 22 2019, 19:09:18) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> import torchvision
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torchvision-0.14.0-py3.8-linux-aarch64.egg/torchvision/__init__.py", line 6, in <module>
    from torchvision import _meta_registrations, datasets, io, models, ops, transforms, utils
  File "/home/sputnik-orin/miniconda3/envs/pytorch113/lib/python3.8/site-packages/torchvision-0.14.0-py3.8-linux-aarch64.egg/torchvision/_meta_registrations.py", line 4, in <module>
    import torch._custom_ops
ModuleNotFoundError: No module named 'torch._custom_ops'

But wait…Did I saw GCC 7.3.0 ? Why is it here…Which GCC did I used to compile this torchvision on, 9.4 or 7.3?

Hi,

Do you use a custom compiler?
We have tested the default JetPack setting and it can work normally.

Is container a solution for you?
We have a container with TorchVision preinstalled so you don’t need to build it from the source:

Thanks.

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