pip3 install wheel pyyaml typing_extensions expecttest
此安装方式为二进制包安装。若用户采用源码编译,请参见源码安装PyTorch安装PyTorch。
pip3 install https://repo.huaweicloud.com/kunpeng/archive/Ascend/PyTorch/torch-1.8.1-cp37-cp37m-linux_aarch64.whl
pip3 install https://repo.huaweicloud.com/kunpeng/archive/Ascend/PyTorch/torch-1.8.1-cp38-cp38-linux_aarch64.whl
pip3 install https://repo.huaweicloud.com/kunpeng/archive/Ascend/PyTorch/torch-1.8.1-cp39-cp39-linux_aarch64.whl
pip3 install https://repo.huaweicloud.com/kunpeng/archive/Ascend/PyTorch/torch-1.11.0-cp37-cp37m-linux_aarch64.whl
pip3 install https://repo.huaweicloud.com/kunpeng/archive/Ascend/PyTorch/torch-1.11.0-cp38-cp38-linux_aarch64.whl
pip3 install https://repo.huaweicloud.com/kunpeng/archive/Ascend/PyTorch/torch-1.11.0-cp39-cp39-linux_aarch64.whl
pip3 install torch==2.0.1
wget https://gitee.com/ascend/pytorch/releases/download/v5.0.rc2-pytorch1.8.1/torch_npu-1.8.1.post2-cp37-cp37m-linux_aarch64.whl pip3 install torch_npu-1.8.1.post2-cp37-cp37m-linux_aarch64.whl
wget https://gitee.com/ascend/pytorch/releases/download/v5.0.rc2-pytorch1.8.1/torch_npu-1.8.1.post2-cp38-cp38-linux_aarch64.whl pip3 install torch_npu-1.8.1.post2-cp38-cp38-linux_aarch64.whl
wget https://gitee.com/ascend/pytorch/releases/download/v5.0.rc2-pytorch1.8.1/torch_npu-1.8.1.post2-cp39-cp39-linux_aarch64.whl pip3 install torch_npu-1.8.1.post2-cp39-cp39-linux_aarch64.whl
wget https://gitee.com/ascend/pytorch/releases/download/v5.0.rc2-pytorch1.11.0/torch_npu-1.11.0.post1-cp37-cp37m-linux_aarch64.whl pip3 install torch_npu-1.11.0.post1-cp37-cp37m-linux_aarch64.whl
wget https://gitee.com/ascend/pytorch/releases/download/v5.0.rc2-pytorch1.11.0/torch_npu-1.11.0.post1-cp38-cp38-linux_aarch64.whl pip3 install torch_npu-1.11.0.post1-cp38-cp38-linux_aarch64.whl
wget https://gitee.com/ascend/pytorch/releases/download/v5.0.rc2-pytorch1.11.0/torch_npu-1.11.0.post1-cp39-cp39-linux_aarch64.whl pip3 install torch_npu-1.11.0.post1-cp39-cp39-linux_aarch64.whl
wget https://gitee.com/ascend/pytorch/releases/download/v5.0.rc2-pytorch2.0.1/torch_npu-2.0.1rc1-cp38-cp38-linux_aarch64.whl pip3 install torch_npu-2.0.1rc1-cp38-cp38-linux_aarch64.whl
wget https://gitee.com/ascend/pytorch/releases/download/v5.0.rc2-pytorch2.0.1/torch_npu-2.0.1rc1-cp39-cp39-linux_aarch64.whl pip3 install torch_npu-2.0.1rc1-cp39-cp39-linux_aarch64.whl
如果使用wget命令下载whl包时出现ERROR: cannot verify gitee.com's certificate报错,可在下载命令后加上--no-check-certificate参数避免此问题。
命令示例如下。
wget https://gitee.com/ascend/pytorch/releases/download/v5.0.rc2-pytorch1.8.1/torch_npu-1.8.1.post2-cp37-cp37m-linux_aarch64.whl --no-check-certificate
python3 -c "import torch;import torch_npu;print(torch_npu.npu.is_available())"
#PyTorch 1.8.1需安装0.9.1版本,PyTorch 1.11.0需安装0.12.0版本,PyTorch 2.0.1版本需安装0.15.2版本 pip3 install torchvision==0.9.1
混合精度训练是在训练时混合使用单精度(float32)与半精度(float16)数据类型,将两者结合在一起,并使用相同的超参数实现了与float32几乎相同的精度。用户需要开启混合精度,可以提升模型的性能。APEX混合精度模块是一个集优化性能、精度收敛于一身的综合优化库,可以提供不同场景下的混合精度训练支持。
编译源码包安装APEX模块步骤如下。
以CentOS与Ubuntu操作系统为例。其它操作系统请参见表1,选择相应的安装命令进行安装。
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
yum install -y patch libjpeg-turbo-devel dos2unix openblas git
若出现“ModuleNotFoundError: No module named 'dnf'”报错信息,请参见No module named 'dnf'解决。
git clone -b master https://gitee.com/ascend/apex.git
如果返回类似以下报错信息:
fatal: unable to access 'https://gitee.com/ascend/apex.git/': SSL certificate problem: self signed certificate in certificate chain
则执行如下命令关闭证书检验后,再执行上述命令获取源码。
git config --global http.sslVerify "false"
cd apex bash scripts/build.sh
请确保NPU版本的PyTorch可以正常使用,否则会影响APEX的编译。
cd apex/dist pip3 install apex-0.1_ascend-*.whl