Skip to main content

为 reComputer Jetson 安装 Pytorch

本 wiki 演示了如何在您的 reComputer 上安装 NVIDIA 优化的 PyTorch,匹配您的 JetPack 版本。还介绍了如何使用虚拟环境(conda)来管理多个 PyTorch 版本以进行开发和部署。

前提条件

  • 已安装 JetPack 的 reComputer
  • 互联网连接

为 reComputer 安装 PyTorch

在这里,我们将介绍如何在 Jetpack 5 和 Jetpack 6 这两个常用版本中安装支持 CUDA 的 PyTorch。

在 reComputer 中,Jetpack 5 的常用版本是 5.1.3。在这里,我们将使用它来介绍如何安装 PyTorch。

步骤 1. 更新系统并安装依赖项:

sudo apt-get -y update
sudo apt-get install -y python3-pip libopenblas-dev

Step 2. Download the official PyTorch wheel (example: torch-2.1.0 for JetPack 5.1.3, Python 3.8):

wget https://developer.download.nvidia.com/compute/redist/jp/v512/pytorch/torch-2.1.0a0+41361538.nv23.06-cp38-cp38-linux_aarch64.whl
pip install torch-2.1.0a0+41361538.nv23.06-cp38-cp38-linux_aarch64.whl
note

如果您需要支持 Jetpack 5.1.3 的更新版本的 torch,请从这里下载编译好的 wheel 文件(torch-2.2 for python3.8)。

步骤 3. 验证安装:

import torch
print(torch.cuda.is_available())
print(torch.__version__)

使用 Conda 管理多个 PyTorch 版本

Miniconda 是 Conda 包管理器的轻量级安装程序,提供了一个最小化环境来快速创建和管理 Python 环境和包。

步骤 1. 安装 Miniconda:

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-aarch64.sh
bash Miniconda3-latest-Linux-aarch64.sh
info
  • 按照说明操作并输入"yes"同意条款。
  • 安装路径建议使用默认设置,例如 ~/miniconda3。
  • 最后,提示是否自动添加到 .bashrc。建议输入"yes"。

步骤 2. 初始化和配置 conda:

source ~/.bashrc
# Verify if conda is functioning properly
conda --version
# Disable automatic entry into the conda base environment
conda config --set auto_activate_base false
# Close and reopen the terminal. By default, it will not enter the base environment.

Step 3. Create a new environment and install a specific PyTorch wheel:

conda create -n torch_2.0 python=3.8
conda activate torch_2.0

步骤 4. 下载并安装 PyTorch wheel 文件,如前面章节所示。

info

更多详细信息,请参阅 NVIDIA PyTorch 安装指南

资源

技术支持与产品讨论

感谢您选择我们的产品!我们在这里为您提供不同的支持,以确保您使用我们产品的体验尽可能顺畅。我们提供多种沟通渠道,以满足不同的偏好和需求。

Loading Comments...