/
Building Pytorch from Source

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:

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:

  1. Plug in a USB drive

  2. Run the following commands (this will destroy anything on the USB drive!):

  3. 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!

 

 

 

Related content

CUDA and PyTorch
CUDA and PyTorch
More like this
Jetson Tx2 Setup
Jetson Tx2 Setup
More like this
Model Training Repository
Model Training Repository
More like this
CV Onsite Setup
CV Onsite Setup
More like this
Python wheel packaging
Python wheel packaging
More like this
Python setup and virtual environment
Python setup and virtual environment
More like this