Building Pytorch from Source
Overview
There is no Pytorch package for NVIDIA Jetson with Python 3.8 . These are the instructions to build the wheel from source for WARG use.
Pytorch 1.13.1 by WARG: https://uofwaterloo-my.sharepoint.com/:f:/r/personal/uwarg_uwaterloo_ca/Documents/Subteam Folders/Autonomy/Jetson Pytorch
Build resources:
https://forums.developer.nvidia.com/t/pytorch-for-jetson/72048
Patch based on:
pytorch-1.10-jetpack-4.5.1.patch
Jetson
Install Python 3.8 :
sudo apt-get update
sudo apt-get install python3.8
sudo apt-get install python3.8-dev # For psutils package build (required for ultralytics)
sudo apt-get install python3.8-venv
sudo apt-get autoremove
Clone Pytorch 1.13.1 and create virtual environment:
git clone --depth 1 --recursive --branch v1.13.1 https://github.com/pytorch/pytorch
cd pytorch
python3.8 -m venv venv/
source venv/bin/activate
pip install --upgrade pip
Install required modules:
pip install -r requirements.txt
pip install ninja scikit-build
Install compilers:
Download this patch: https://uofwaterloo-my.sharepoint.com/:u:/r/personal/uwarg_uwaterloo_ca/Documents/Subteam%20Folders/Autonomy/Jetson%20Pytorch/pytorch-1.13.1-jetpack-4.6.3.patch
Alternatively, copy the contents below into a
.patch
file
Apply the patch:
Set environment variables:
The build uses a lot of memory, more than the available RAM. Add a swapfile to use as memory:
Plug in a USB drive
Run the following commands (this will destroy anything on the USB drive!):
The output of the swapfile list should show the USB drive as a swapfile
Compile:
The compilation takes several hours. If the compilation is interrupted, set the environment variables again and run only the wheel command. Once the compilation is complete, the wheel is saved in pytorch/dist/
.
Remove the USB swapfile:
Done!
Â
Â
Â