The pre-built package is https://github.com/wangkuiyi/pytorch-rpi and https://github.com/ljk53/pytorch-rpi.
Alternative 1
The steps to build it include:
- Log in to an NVIDIA Jetson Nano.
- Operating System: Ubuntu 18.04 for a recent Python.
- Install Clang with
sudo apt install -y clang
. - Set environment variables:
export USE_CUDA=1 export USE_CUDNN=1 export MAX_JOBS=4 export USE_NNPACK=0 export USE_QNNPACK=0 export USE_PYTORCH_QNNPACK=0 export BUILD_CAFFE2_OPS=0 export USE_MKLDNN=0 export USE_OPENCV=0
- Run
./build_libtorch.sh
to build and pack the zip file.
Alternative 2
The steps to get libtorch.so with GNU C++ compiler:
- Visit Nvidia forum here. Download PyTorch what do you want, for example PyTorch v1.7.0 (Python 3.6 - torch-1.7.0-cp36-cp36m-linux_aarch64.whl)
- Follow command below:
$ sudo apt install python3-pip $ sudo pip3 install torch-1.7.0-cp36-cp36m-linux_aarch64.whl $ pip3 show torch # to check path of the installed torch
- After installation, check libtorch.so in path:
$ cd /usr/local/lib/python3.6/dist-packages/torch/lib/ # that's consistent with output of command above $ ls
- Sett CMakeLists.txt like below
set(CMAKE_PREFIX_PATH "/usr/local/lib/python3.6/dist-packages/torch") find_package(Torch REQUIRED) if (Torch_FOUND) message(STATUS "Torch library found!") message(STATUS " include path: ${TORCH_INCLUDE_DIRS}" \n) else () message(FATAL_ERROR "Could not locate Torch" \n) endif()
Alternative 3
The steps to get libtorch.so with Clang C++ compiler:
-
Visit Qengineering repo here. Download PyTorch what do you want, for example PyTorch v1.7.0 (Python 3.6 - torch-1.7.0a0-cp36-cp36m-linux_aarch64.whl and torchvision-0.8.1a0+45f960c-cp36-cp36m-linux_aarch64.whl)
-
Follow command below:
$ sudo apt install python3-pip $ sudo pip3 install torch-1.7.0a0-cp36-cp36m-linux_aarch64.whl $ sudo pip3 install torchvision-0.8.1a0+45f960c-cp36-cp36m-linux_aarch64.whl $ pip3 show torch # to check path of the installed torch
-
After installation, check libtorch.so in path:
$ cd /usr/local/lib/python3.6/dist-packages/torch/lib/ # that's consistent with output of command above $ ls $ export CC=/usr/bin/clang $ export CXX=/usr/bin/clang++
-
Comment script in TorchConfig.cmake in file torch/share/cmake/Torch/
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") #set(TORCH_CXX_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=0") endif()
-
Sett CMakeLists.txt like below
set(CMAKE_CXX_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=1") set(CMAKE_PREFIX_PATH "/usr/local/lib/python3.6/dist-packages/torch") find_package(Torch REQUIRED) if (Torch_FOUND) message(STATUS "Torch library found!") message(STATUS " include path: ${TORCH_INCLUDE_DIRS}" \n) else () message(FATAL_ERROR "Could not locate Torch" \n) endif()
The steps to build it include:
- Log in to an NVIDIA Drive PX2 computer.
- Upgrade the system from Ubuntu 16.04 to Ubuntu 18.04 for a recent Python.
- Install Clang with
sudo apt install -y clang
. - Set environment variables:
export USE_CUDA=0 export USE_QNNPACK=0 export USE_PYTORCH_QNNPACK=0
- Run
./build_libtorch.sh
to build and pack the zip file.
- Install the latest Raspberry Pi OS (32-bit).
- Run
sudo apt update && sudo apt upgrade
. - Run
git clone git@github.com:ljk53/pytorch-rpi && cd pytorch-rpi
. - Run
LIBTORCH_VARIANT=armv7l-cxx11-abi-shared-without-deps ./build_libtorch.sh
.
- Install the latest 64-bit Ubuntu 20.04 for Raspberry Pi.
- Run
sudo apt update && sudo apt upgrade
. - Run
git clone git@github.com:ljk53/pytorch-rpi && cd pytorch-rpi
. - Run
MAX_JOBS=2 LIBTORCH_VARIANT=aarch64-cxx11-abi-shared-without-deps ./build_libtorch.sh
. Note: set the max number of concurrent build jobs to 2 to avoid running out of the RAM.
- Pre-built LibTorch for ARM32/64 Systems (torch and libtorch) Tested Ubuntu: https://github.com/ljk53/pytorch-rpi
- pytorch-arm-builds (torch and torchvision) Tested Fedora: https://github.com/nmilosev/pytorch-arm-builds
- Q-engineering: https://github.com/Qengineering
- PyTorch-Raspberry-Pi-64-OS: https://github.com/Qengineering/PyTorch-Raspberry-Pi-64-OS
- PyTorch-Jetson-Nano: https://github.com/Qengineering/PyTorch-Jetson-Nano
- Nvidia PyTorch for Jetson - version 1.11 now available: https://forums.developer.nvidia.com/t/pytorch-for-jetson-version-1-11-now-available/72048