源码安装PyTorch
编译安装前准备
安装PyTorch依赖前请确保依赖列表中的OS依赖已全部安装。
安装系统依赖。
- CentOS 7.6、CTyunOS 22.06、CUlinux 3.0、Kylin V10 SP2、Kylin V10 SP3、UOS V20(1050u2e)
yum install -y patch libjpeg-turbo-devel dos2unix git
- Ubuntu 22.04
apt-get install -y patch build-essential libbz2-dev libreadline-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev liblzma-dev m4 dos2unix libopenblas-dev git
查看gcc和cmake版本。
gcc --version cmake --version
- 要求7.3.0版本及以上gcc,如果版本低于7.3.0,请参见安装7.3.0版本gcc安装;若用户需要安装1.11.0版本PyTorch,则gcc需为7.5.0版本以上,请参见安装7.3.0版本gcc安装(用户将命令中的“7.3.0”修改为“7.5.0”即可)。
- 要求3.12.0版本及以上cmake,如果版本低于3.12.0,请参见安装3.12.0版本cmake安装。
源码编译安装PyTorch
- 安装torch包。
- PyTorch 1.11.0
- Python3.7.x(3.7.5及以上)
wget https://download.pytorch.org/whl/torch-1.11.0-cp37-cp37m-manylinux2014_aarch64.whl pip3 install torch-1.11.0-cp37-cp37m-manylinux2014_aarch64.whl
- Python3.8.x
wget https://download.pytorch.org/whl/torch-1.11.0-cp38-cp38-manylinux2014_aarch64.whl pip3 install torch-1.11.0-cp38-cp38-manylinux2014_aarch64.whl
- Python3.9.x
wget https://download.pytorch.org/whl/torch-1.11.0-cp39-cp39-manylinux2014_aarch64.whl pip3 install torch-1.11.0-cp39-cp39-manylinux2014_aarch64.whl
- Python3.10.x
wget https://download.pytorch.org/whl/torch-1.11.0-cp310-cp310-manylinux2014_aarch64.whl pip3 install torch-1.11.0-cp310-cp310-manylinux2014_aarch64.whl
- Python3.7.x(3.7.5及以上)
- PyTorch 2.1.0
- Python3.8.x
wget https://download.pytorch.org/whl/cpu/torch-2.1.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl pip3 install torch-2.1.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Python3.9.x
wget https://download.pytorch.org/whl/cpu/torch-2.1.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl pip3 install torch-2.1.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Python3.10.x
wget https://download.pytorch.org/whl/cpu/torch-2.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl pip3 install torch-2.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Python3.8.x
- PyTorch 2.2.0
- Python3.8.x
wget https://download.pytorch.org/whl/cpu/torch-2.2.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl pip3 install torch-2.2.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Python3.9.x
wget https://download.pytorch.org/whl/cpu/torch-2.2.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl pip3 install torch-2.2.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Python3.10.x
wget https://download.pytorch.org/whl/cpu/torch-2.2.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl pip3 install torch-2.2.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Python3.8.x
- PyTorch 1.11.0
- 编译生成torch_npu插件的二进制安装包。
- 下载对应PyTorch版本分支代码(以PyTorch 2.1.0为例,分支名称为v2.1.0-6.0.rc1,其它版本的代码分支名称如表1所示),进入插件根目录。
git clone -b v2.1.0-6.0.rc1 https://gitee.com/ascend/pytorch.git cd pytorch
- 编译生成二进制安装包。
# 指定Python版本编包方式,以Python3.8为例,其他Python版本请使用 --python=3.7、--python3.9、--python3.10 bash ci/build.sh --python=3.8
- 下载对应PyTorch版本分支代码(以PyTorch 2.1.0为例,分支名称为v2.1.0-6.0.rc1,其它版本的代码分支名称如表1所示),进入插件根目录。
- 安装pytorch/dist目录下生成的插件torch_npu包。
# 请用户根据实际情况更改命令中的torch_npu包名 pip3 install --upgrade dist/torch_npu-2.1.0.post3-cp38-cp38-linux_aarch64.whl
- 验证是否安装成功。
python3 -c "import torch;import torch_npu; a = torch.randn(3, 4).npu(); print(a + a);"
显示如下回显证明PyTorch框架与插件安装成功。
父主题: 参考信息