Installing PyTorch for Jetson Platform
This guide provides instructions for installing PyTorch for Jetson Platform.
PyTorch on Jetson Platform
PyTorch (for JetPack) is an optimized tensor library for deep learning, using GPUs and CPUs. Automatic differentiation is done with a tape-based system at both a functional and neural network layer level. This functionality brings a high level of flexibility, speed as a deep learning framework, and provides accelerated NumPy-like functionality. These NVIDIA-provided redistributables are Python pip wheel installers for PyTorch, with GPU-acceleration and support for cuDNN. The packages are intended to be installed on top of the specified version of JetPack as in the provided documentation.
Jetson AGX Xavier
The NVIDIA Jetson AGX Xavier developer kit for Jetson platform is the world's first AI computer for autonomous machines. The Jetson AGX Xavier delivers the performance of a GPU workstation in an embedded module under 30W.
Jetson AGX Orin
The NVIDIA Jetson AGX Orin Developer Kit includes a high-performance, power-efficient Jetson AGX Orin module, and can emulate the other Jetson modules. You now have up to 275 TOPS and 8X the performance of NVIDIA Jetson AGX Xavier in the same compact form-factor for developing advanced robots and other autonomous machine products.
Jetson Xavier NX
The NVIDIA Jetson Xavier NX brings supercomputer performance to the edge in a small form factor system-on-module. Up to 21 TOPS of accelerated computing delivers the horsepower to run modern neural networks in parallel and process data from multiple high-resolution sensors — a requirement for full AI systems.
Installing PyTorch for Jetson Platform provides you with the access to the latest version of the framework on a lightweight, mobile platform.
Install JetPack on your Jetson device.
Install system packages required by PyTorch:
sudo apt-get -y update; sudo apt-get -y install autoconf bc build-essential g++-8 gcc-8 clang-8 lld-8 gettext-base gfortran-8 iputils-ping libbz2-dev libc++-dev libcgal-dev libffi-dev libfreetype6-dev libhdf5-dev libjpeg-dev liblzma-dev libncurses5-dev libncursesw5-dev libpng-dev libreadline-dev libssl-dev libsqlite3-dev libxml2-dev libxslt-dev locales moreutils openssl python-openssl rsync scons python3-pip libopenblas-dev;
Next, install PyTorch with the following steps:
Export with the following command:
Or, download the wheel file and set.
python3 -m pip install --upgrade pip; python3 -m pip install aiohttp numpy=='1.19.4' scipy=='1.5.3' export "LD_LIBRARY_PATH=/usr/lib/llvm-8/lib:$LD_LIBRARY_PATH"; python3 -m pip install --upgrade protobuf; python3 -m pip install --no-cache $TORCH_INSTALL
If you want to install a specific version of PyTorch, replace
The major and minor version of JetPack you are using, such as
461for JetPack 4.6.1 or
50for JetPack 5.0.
- The released version of the PyTorch wheels, as given in the Compatibility Matrix.
If you want to have multiple versions of PyTorch available at the same time, this can be accomplished using virtual environments. See below.
Set up the Virtual Environment
First, install the
virtualenv package and create a new Python 3 virtual environment:
$ sudo apt-get install virtualenv $ python3 -m virtualenv -p python3 <chosen_venv_name>
Activate the Virtual Environment
Next, activate the virtual environment:
$ source <chosen_venv_name>/bin/activate
Install the desired version of PyTorch:
pip3 install --no-cache https://developer.download.nvidia.com/compute/redist/jp/v51/pytorch/<torch_version_desired>
Deactivate the Virtual Environment
Finally, deactivate the virtual environment:
Run a Specific Version of PyTorch
$ source <chosen_venv_name>/bin/activate $ <Run the desired PyTorch scripts> $ deactivate
To upgrade to a more recent release of PyTorch, if one is available, uninstall the current PyTorch version and refer to Prerequisites and Installation to install the new desired release.
About this task
To verify that PyTorch has been successfully installed on the Jetson platform, you’ll need to launch a Python prompt and import PyTorch.
- From the terminal, run:
$ export LD_LIBRARY_PATH=/usr/lib/llvm-8/lib:$LD_LIBRARY_PATH $ python3
- Import PyTorch:
>>> import torch
If PyTorch was installed correctly, this command should execute without error.
Join the NVIDIA Jetson and Embedded Systems community to discuss Jetson platform-specific issues.
This document is provided for information purposes only and shall not be regarded as a warranty of a certain functionality, condition, or quality of a product. NVIDIA Corporation (“NVIDIA”) makes no representations or warranties, expressed or implied, as to the accuracy or completeness of the information contained in this document and assumes no responsibility for any errors contained herein. NVIDIA shall have no liability for the consequences or use of such information or for any infringement of patents or other rights of third parties that may result from its use. This document is not a commitment to develop, release, or deliver any Material (defined below), code, or functionality.
NVIDIA products are sold subject to the NVIDIA standard terms and conditions of sale supplied at the time of order acknowledgement, unless otherwise agreed in an individual sales agreement signed by authorized representatives of NVIDIA and customer (“Terms of Sale”). NVIDIA hereby expressly objects to applying any customer general terms and conditions with regards to the purchase of the NVIDIA product referenced in this document. No contractual obligations are formed either directly or indirectly by this document.
NVIDIA products are not designed, authorized, or warranted to be suitable for use in medical, military, aircraft, space, or life support equipment, nor in applications where failure or malfunction of the NVIDIA product can reasonably be expected to result in personal injury, death, or property or environmental damage. NVIDIA accepts no liability for inclusion and/or use of NVIDIA products in such equipment or applications and therefore such inclusion and/or use is at customer’s own risk.
NVIDIA makes no representation or warranty that products based on this document will be suitable for any specified use. Testing of all parameters of each product is not necessarily performed by NVIDIA. It is customer’s sole responsibility to evaluate and determine the applicability of any information contained in this document, ensure the product is suitable and fit for the application planned by customer, and perform the necessary testing for the application in order to avoid a default of the application or the product. Weaknesses in customer’s product designs may affect the quality and reliability of the NVIDIA product and may result in additional or different conditions and/or requirements beyond those contained in this document. NVIDIA accepts no liability related to any default, damage, costs, or problem which may be based on or attributable to: (i) the use of the NVIDIA product in any manner that is contrary to this document or (ii) customer product designs.
No license, either expressed or implied, is granted under any NVIDIA patent right, copyright, or other NVIDIA intellectual property right under this document. Information published by NVIDIA regarding third-party products or services does not constitute a license from NVIDIA to use such products or services or a warranty or endorsement thereof. Use of such information may require a license from a third party under the patents or other intellectual property rights of the third party, or a license from NVIDIA under the patents or other intellectual property rights of NVIDIA.
Reproduction of information in this document is permissible only if approved in advance by NVIDIA in writing, reproduced without alteration and in full compliance with all applicable export laws and regulations, and accompanied by all associated conditions, limitations, and notices.
THIS DOCUMENT AND ALL NVIDIA DESIGN SPECIFICATIONS, REFERENCE BOARDS, FILES, DRAWINGS, DIAGNOSTICS, LISTS, AND OTHER DOCUMENTS (TOGETHER AND SEPARATELY, “MATERIALS”) ARE BEING PROVIDED “AS IS.” NVIDIA MAKES NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL NVIDIA BE LIABLE FOR ANY DAMAGES, INCLUDING WITHOUT LIMITATION ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE, OR CONSEQUENTIAL DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF ANY USE OF THIS DOCUMENT, EVEN IF NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Notwithstanding any damages that customer might incur for any reason whatsoever, NVIDIA’s aggregate and cumulative liability towards customer for the products described herein shall be limited in accordance with the Terms of Sale for the product.
HDMI, the HDMI logo, and High-Definition Multimedia Interface are trademarks or registered trademarks of HDMI Licensing LLC.
OpenCL is a trademark of Apple Inc. used under license to the Khronos Group Inc.
NVIDIA, the NVIDIA logo, and cuBLAS, CUDA, DALI, DGX, DGX-1, DGX-2, DGX Station, DLProf, Jetson, Kepler, Maxwell, NCCL, Nsight Compute, Nsight Systems, NvCaffe, PerfWorks, Pascal, SDK Manager, Tegra, TensorRT, Triton Inference Server, Tesla, TF-TRT, and Volta are trademarks and/or registered trademarks of NVIDIA Corporation in the U.S. and other countries. Other company and product names may be trademarks of the respective companies with which they are associated.