Compare commits

..
48 Commits
Author SHA1 Message Date
i-robot 3a8e6f8c86 !1037 网络模型移植与训练指南修改
Merge pull request !1037 from 彭子荣/2.0.2.tr5
2022-07-11 12:15:32 +00:00
pengzirong 0db8c607b6 网络模型移植与训练指南新增硬件支持说明 2022-07-11 14:52:23 +08:00
weili10 5e0fc864a2 !908 安装指南资料修改
Merge pull request !908 from 彭子荣/2.0.2.tr5
2022-06-15 07:14:12 +00:00
pengzirong accb0ba603 修改下载昇腾适配的apex源码命令 2022-06-14 17:17:48 +08:00
weili10 39849cf72d update README.zh.md. 2021-11-19 08:24:55 +00:00
weili10 129f42c911 update docs/zh/RELEASENOTE/RELEASENOTE.md. 2021-09-04 06:51:09 +00:00
yinzijun 7977e5737e !48 修复英文文档链接不跳转的问题
Merge pull request !48 from yinzijun/2.0.2.tr5
2021-08-26 12:29:47 +00:00
ZijunYin dae2415d1e update menu 2021-08-26 20:14:48 +08:00
ZijunYin 118987cbb1 解决目录链接不跳转问题 2021-08-26 20:07:52 +08:00
yinzijun 1fcf3a003c !45 修复中文文档链接不跳转的问题
* 修改链接显示问题
* 修改链接跳转问题
* 删除链接跳转中的括号
* 处理括号使链接跳转失败的问题›
* 修改内部文件链接跳转问题
* 修改 分布式训练修改 链接跳转问题
* 修改链接跳转失败问题
* 修改链接显示问题
* 使目录连接生效
* solve the problem of anchor link - installation guide
2021-08-24 10:33:38 +00:00
yinzijun 4fb3c0c667 !42 新增英文手册
Merge pull request !42 from yinzijun/2.0.2.tr5
2021-08-11 02:11:48 +00:00
ZijunYin 67c590693e 新增英文手册 2021-08-10 23:51:19 +08:00
weili10 b2c0e583d8 调整安装python依赖库位置 2021-08-09 03:25:55 +00:00
i-robot 8757692989 !40 在README中增加版本配套信息
Merge pull request !40 from yinzijun/2.0.2.tr5
2021-08-06 09:09:23 +00:00
ZijunYin df5ed40e13 Merge branch '2.0.2.tr5' of https://gitee.com/yinzijun/pytorch into 2.0.2.tr5 2021-08-05 17:57:29 +08:00
ZijunYin 2d65cb41ed 在README中增加版本配套关系 2021-08-05 17:56:23 +08:00
i-robot 471afd84a8 !36 更新算子文档
Merge pull request !36 from yinzijun/2.0.2.tr5
2021-08-03 08:35:22 +00:00
weili10 f43426a4c5 update OWNERS. 2021-07-31 08:00:52 +00:00
ZijunYin bb7f740c87 更新算子开发指南和适配算子清单 2021-07-30 18:10:33 +08:00
i-robot 7c3acf31cf !33 同步 3cd6fe790d2af7fc618bde1f17ae347c42438c83
Merge pull request !33 from weili10/2.0.2.tr5
2021-07-29 09:33:05 +00:00
i-robot 7d7070c344 !27 文档修改命名格式归档
Merge pull request !27 from yinzijun/2.0.2.tr5
2021-07-29 09:17:03 +00:00
张昱杰 18396d4937 update scripts/mkdirs.sh. 2021-07-29 09:12:39 +00:00
weili10 7a563bcc03 同步3cd6fe790d2af7fc618bde1f17ae347c42438c83 2021-07-29 17:01:23 +08:00
ZijunYin ac4e725c80 add RELEASENOTE 2021-07-29 16:51:58 +08:00
ZijunYin 68eac297da change name of releasenote 2021-07-29 16:49:07 +08:00
i-robot 49347eadd2 !32 增加版权声明
Merge pull request !32 from weili10/2.0.2.tr5
2021-07-29 08:01:07 +00:00
weili10 36bc73fc7c 增加版权声明 2021-07-29 15:51:35 +08:00
weili10 def54c93b6 update README.zh.md. 2021-07-29 06:46:26 +00:00
i-robot 2ef2eed751 !31 解决原生pytorch中dos编码文件打patch报错问题
Merge pull request !31 from weili10/2.0.2.tr5
2021-07-29 03:27:04 +00:00
weili10 c757565613 解决原生pytorch中dos编码文件打patch报错问题 2021-07-29 10:53:20 +08:00
i-robot a933722394 !28 增加开源软件使用说明
Merge pull request !28 from weili10/2.0.2.tr5
2021-07-29 01:15:03 +00:00
weili10 a584a4e5f2 增加开源软件使用说明 2021-07-28 21:50:56 +08:00
ZijunYin 2f58ad99a0 update docs, add releasenote 2021-07-28 20:45:59 +08:00
ZijunYin 3323c4eecb update docs with new file name and icons 2021-07-27 17:03:50 +08:00
weili10 92f2f166e4 update README.zh.md. 2021-07-27 06:53:49 +00:00
weili10 98ffda59bb update README.zh.md. 2021-07-27 06:50:50 +00:00
weili10 c0989a8a1f update README.zh.md. 2021-07-27 06:50:08 +00:00
weili10 2141b0eb57 !20 同步062fd2fe1728234949b75ce9d1b07267074a8243
Merge pull request !20 from weili10/2.0.2.tr5
2021-07-17 11:46:01 +00:00
weili10 34b3fd413d 同步062fd2fe1728234949b75ce9d1b07267074a8243 2021-07-17 19:42:55 +08:00
weili10 424e4d3c91 update LICENSE. 2021-07-16 13:43:16 +00:00
weili10 982bf7a05b !18 同步c59af4f05ca3150b272cfc2bfa956cf37b7f6291
Merge pull request !18 from weili10/2.0.2.tr5
2021-07-16 13:42:18 +00:00
weili10 54606dd727 同步c59af4f05ca3150b272cfc2bfa956cf37b7f6291 2021-07-16 18:43:32 +08:00
weili10 1a0abe14d7 !15 [Task]新版本文档归档
Merge pull request !15 from fenghaolin/2.02tr5
2021-07-14 13:52:03 +00:00
fenghaolin 1f2e7c6d71 新版本资料归档 2021-07-14 21:40:06 +08:00
weili10 2f43a92d76 !12 同步 16c245707319972d9ae24d6c4e0863abdeaca6b6
Merge pull request !12 from weili10/2.0.2.tr5
2021-07-14 06:18:00 +00:00
weili10 7f158abe29 同步 16c245707319972d9ae24d6c4e0863abdeaca6b6 2021-07-14 14:13:54 +08:00
weili10 1f2771b747 update LICENSE. 2021-07-14 05:52:26 +00:00
weili10 bbdfd6c0ea update LICENSE. 2021-07-14 03:54:54 +00:00
2277 changed files with 20936 additions and 226280 deletions
+1 -3
View File
@@ -14,6 +14,4 @@ reviewers:
- yskhhh
- lvpeiyuan
- xchu42
- weili10
- goodjobwubai
- fairwarning
- weili10
+28 -59
View File
@@ -10,7 +10,7 @@ gcc版本: 7.3.0(只在编译场景要求)
cmake版本:3.12.0以上版本(只在编译场景要求)
python版本:3.7.5 和 3.8.x(编译方法有差别,详见脚本编译章节)
python版本:3.7.x
# 系统依赖库
@@ -29,19 +29,16 @@ apt-get install -y gcc g++ make build-essential libssl-dev zlib1g-dev libbz2-dev
| AscendPyTorch版本 | CANN版本 | 支持PyTorch版本 |
| :------------ | :----------- | :----------- |
| 2.0.2 | CANN 5.0.2 | 1.5.0 |
| 2.0.3 | CANN 5.0.3 | 1.5.0,1.8.1(仅支持resnet50模型) |
# 使用方式 --生成全量代码并编译
## 获取原生PyTorch源代码和third_party代码
当前支持pytorch 1.5.0和1.8.1的版本。根据需求,在当前仓库根目录pytorch/下获取原生PyTorch的源代码
在当前仓库根目录pytorch/下获取原生PyTorch的源代码
```sh
// 1.5.0 版本
git clone -b v1.5.0 --depth=1 https://github.com/pytorch/pytorch.git
// 1.8.1 版本
git clone -b v1.8.1 --depth=1 https://github.com/pytorch/pytorch.git
```
进入到pytorch/pytorch/目录下, 获取PyTorch被动依赖代码(获取时间较长,请耐心等待)。
@@ -55,13 +52,10 @@ git submodule update --init --recursive
## 生成适配昇腾AI处理器的PyTorch代码。
进入到pytorch/scripts目录,根据选择的版本执行,执行脚本(注意:下载原生Pytorch源代码和下面版本要对应,否则可能出错)
进入到pytorch/scripts目录,执行
```sh
// 默认为1.5.0版本
bash gen.sh
// 对于1.8.1版本,则通过-v 参数指定
bash gen.sh -v 1.8.1
```
会在pytorch/pytorch/目录中生成npu适配全量代码
@@ -81,26 +75,18 @@ pip3 install -r requirements.txt
进入到pytorch/pytorch/目录,执行
```sh
# python3.7版本
bash build.sh
或者
bash build.sh --python=3.7(推荐)
# python3.8版本
bash build.sh --python=3.8
```
生成的二进制包在pytorch/pytorch/dist/目录下
# 安装
### (以1.5.0版本为例,1.8.1版本同理)
**x86_64:**
torch-1.5.0+ascend-cp37-cp37m-linux_x86_64.whl (实际可能附带小版本号例如torch-1.5.0.post2+ascend-cp37-cp37m-linux_x86_64.whl)
```shell
```python
pip3 uninstall torch
pip3 install --upgrade torch-1.5.0+ascend-cp37-cp37m-linux_x86_64.whl
```
@@ -110,7 +96,7 @@ pip3 install --upgrade torch-1.5.0+ascend-cp37-cp37m-linux_x86_64.whl
torch-1.5.0+ascend-cp37-cp37m-linux_aarch64.whl (实际可能附带小版本号例如torch-1.5.0.post2+ascend-cp37-cp37m-linux_aarch64.whl)
```shell
```python
pip3 uninstall torch
pip3 install --upgrade torch-1.5.0+ascend-cp37-cp37m-linux_aarch64.whl
```
@@ -123,7 +109,7 @@ pip3 install --upgrade torch-1.5.0+ascend-cp37-cp37m-linux_aarch64.whl
在当前仓库根目录中执行设置环境变量脚本
```
source pytorch/env.sh
source src/env.sh
```
@@ -151,52 +137,38 @@ export DYNAMIC_OP="ADD#MUL" # 算子实现,ADD和MUL算子在不同场景下
验证运行, 输出结果OK
```shell
// 根据前述版本,选择对应的测试脚本,以下为1.5.0版本
python3 pytorch1.5.0/test/test_npu/test_div.py
// 以下为1.8.1版本
python3 pytorch1.8.1/test/test_npu/test_div.py
```python
python3 test/test_npu/test_div.py
```
# 文档
# 路标
有关安装指南、模型迁移和训练/推理教程和API列表等更多详细信息,请参考[用户文档](docs/zh)。
以下将展示AscendPyTorch近期的计划,我们会根据用户的反馈诉求,持续调整计划的优先级。
# 建议与交流
总体而言,我们会努力在以下几个方面不断改进。
热忱希望各位在用户社区加入讨论,并贡献您的建议,我们会尽快给您回复。
1、pytorch AICPU多核能力补齐
2、pytorch单算子模式const节点输入
3、pytorch场景支持算子非连续输入
4、pytorch单算子模式支持动态shape
5、NLP网络格式转化方案完善
6、pytorch的基线格式调整
7、reshapeType总体方案梳理优化
8、AICPU针对pytorch方案梳理优化
# 分支维护策略
热忱希望各位在用户社区加入讨论,并贡献您的建议。
Ascend PyTorch的版本分支有以下几种维护阶段:
| **状态** | **持续时间** | **说明** |
|-------------|---------------|--------------------------------------------------|
| Planning | 1 - 3 months | 特性规划。 |
| Development | 3 months | 特性开发。 |
| Maintained | 6 - 12 months | 允许所有问题修复的合入,并发布版本。 |
| Unmaintained| 0 - 3 months | 允许所有问题修复的合入,无专人维护,不再发布版本。 |
| End Of Life (EOL) | N/A | 不再接受修改合入该分支。 |
# 现有分支维护状态
| **分支名** | **当前状态** | **上线时间** | **后续状态** | **EOL 日期**|
|------------|--------------|----------------------|----------------------------------------|------------|
| **v2.0.2** | Maintained | 2021-07-29 | Unmaintained <br> 2022-07-29 estimated | |
| **v2.0.3** | Maintained | 2021-10-15 | Unmaintained <br> 2022-10-15 estimated | |
# FAQ
## 编译过程执行bash build.sh报错no module named yaml/typing_extensions.
pytorch编译依赖 yaml库和typing_extensions库,需要手动安装。
pip3 install pyyaml
pip3 install typing_extensions
安装成功后,注意需要执行make clean在执行bash build.sh进行编译,否则可能因缓存出现未知编译错误。
## 运行遇到找不到te问题
开发态:
@@ -251,6 +223,3 @@ Ubuntu环境
apt install libopenblas-dev
```
# 版本说明
版本说明请参阅[ReleseNote](docs/zh/RELEASENOTE)
@@ -1,5 +1,6 @@
# Copyright (c) 2020 Huawei Technologies Co., Ltd
# All rights reserved.
# -*- coding: UTF-8 -*-
# Copyright (c) 2020, Huawei Technologies.All rights reserved.
#
# Licensed under the BSD 3-Clause License (the "License");
# you may not use this file except in compliance with the License.
@@ -12,7 +13,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# -*- coding: UTF-8 -*-
import os
import re
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff

Before

Width:  |  Height:  |  Size: 580 B

After

Width:  |  Height:  |  Size: 580 B

Before

Width:  |  Height:  |  Size: 580 B

After

Width:  |  Height:  |  Size: 580 B

Before

Width:  |  Height:  |  Size: 394 B

After

Width:  |  Height:  |  Size: 394 B

Before

Width:  |  Height:  |  Size: 406 B

After

Width:  |  Height:  |  Size: 406 B

Before

Width:  |  Height:  |  Size: 253 B

After

Width:  |  Height:  |  Size: 253 B

Before

Width:  |  Height:  |  Size: 580 B

After

Width:  |  Height:  |  Size: 580 B

File diff suppressed because it is too large Load Diff
@@ -1,42 +1,42 @@
# PyTorch Installation Guide
- [Overview](#overviewmd)
- [Manual Build and Installation](#manual-build-and-installationmd)
- [Prerequisites](#prerequisitesmd)
- [Installing the PyTorch Framework](#installing-the-pytorch-frameworkmd)
- [Configuring Environment Variables](#configuring-environment-variablesmd)
- [Installing the Mixed Precision Module](#installing-the-mixed-precision-modulemd)
- [References](#referencesmd)
- [Installing CMake](#installing-cmakemd)
- [How Do I Install GCC 7.3.0?](#how-do-i-install-gcc-7-3-0md)
- [What Do I Do If "torch 1.5.0xxxx" and "torchvision" Do Not Match When torch-\*.whl Is Installed?](#what-do-i-do-if-torch-1-5-0xxxx-and-torchvision-do-not-match-when-torch--whl-is-installedmd)
<h2 id="overviewmd">Overview</h2>
# FrameworkPTAdapter 2.0.2 PyTorch Installation Guide
- [Overview](#overview)
- [Manual Build and Installation](#manual-build-and-installation)
- [Prerequisites](#prerequisites)
- [Installing the PyTorch Framework](#installing-the-pytorch-framework)
- [Configuring Environment Variables](#configuring-environment-variables)
- [Installing the Mixed Precision Module](#installing-the-mixed-precision-module)
- [Using the Ascend Hub Image](#using-the-ascend-hub-image)
- [Obtaining the PyTorch Image from the Ascend Hub](#obtaining-the-pytorch-image-from-the-ascend-hub)
- [Configuring Environment Variables](#configuring-environment-variables-0)
- [References](#references)
- [Installing CMake](#installing-cmake)
- [How Do I Install GCC 7.3.0?](#how-do-i-install-gcc-7-3-0)
- [What Do I Do If "torch 1.5.0xxxx" and "torchvision" Do Not Match When torch-\*.whl Is Installed?](#what-do-i-do-if-torch-1-5-0xxxx-and-torchvision-do-not-match-when-torch--whl-is-installed)
<h2 id="overview">Overview</h2>
When setting up the environment for PyTorch model development and running, you can manually build and install the modules adapted to the PyTorch framework on a server.
When setting up the environment for PyTorch model porting and training, you can manually build and install the modules adapted to the PyTorch framework on a training server, or use the base image provided by the Ascend Hub image center \(the PyTorch module and mixed precision module have been installed in the image\).
**Figure 1** Environment setup process<a name="en-us_topic_0000001119176876_fig1938918396117"></a>
![](figures/environment-setup-process.png "environment-setup-process")
<h2 id="manual-build-and-installation">Manual Build and Installation</h2>
- **[Prerequisites](#prerequisites)**
- **[Installing the PyTorch Framework](#installing-the-pytorch-framework)**
- **[Configuring Environment Variables](#configuring-environment-variables)**
- **[Installing the Mixed Precision Module](#installing-the-mixed-precision-module)**
![](figures/210926103326800.png)
<h2 id="prerequisites">Prerequisites</h2>
<h2 id="manual-build-and-installationmd">Manual Build and Installation</h2>
- **[Prerequisites](#prerequisitesmd)**
- **[Installing the PyTorch Framework](#installing-the-pytorch-frameworkmd)**
- **[Configuring Environment Variables](#configuring-environment-variablesmd)**
- **[Installing the Mixed Precision Module](#installing-the-mixed-precision-modulemd)**
<h3 id="prerequisitesmd">Prerequisites</h3>
#### Prerequisites<a name="en-us_topic_0000001105856382_en-us_topic_0275872734_section108914373254"></a>
## Prerequisites<a name="en-us_topic_0000001105856382_en-us_topic_0275872734_section108914373254"></a>
- The development or operating environment of CANN has been installed. For details, see the _CANN Software Installation Guide_.
- CMake 3.12.0 or later has been installed. For details about how to install CMake, see [Installing CMake](#installing-cmakemd).
- GCC 7.3.0 or later has been installed. For details about how to install and use GCC 7.3.0, see [How Do I Install GCC 7.3.0?](#how-do-i-install-gcc-7-3-0md).
- Python 3.7.5 or 3.8 has been installed.
- CMake 3.12.0 or later has been installed. For details about how to install CMake, see [Installing CMake](#installing-cmake).
- GCC 7.3.0 or later has been installed. For details about how to install and use GCC 7.3.0, see [How Do I Install GCC 7.3.0?](#how-do-i-install-gcc-7-3-0).
- The Patch and Git tools have been installed in the environment. To install the tools for Ubuntu and CentOS, run the following commands:
- Ubuntu
@@ -54,9 +54,9 @@ When setting up the environment for PyTorch model development and running, you c
<h3 id="installing-the-pytorch-frameworkmd">Installing the PyTorch Framework</h3>
<h2 id="installing-the-pytorch-framework">Installing the PyTorch Framework</h2>
#### Installation Process<a name="en-us_topic_0000001152776301_section1611810384557"></a>
## Installation Process<a name="en-us_topic_0000001152776301_section1611810384557"></a>
1. Log in to the server as the **root** user or a non-root user.
2. Run the following commands in sequence to install the PyTorch dependencies.
@@ -79,32 +79,36 @@ When setting up the environment for PyTorch model development and running, you c
The directory structure of the downloaded source code is as follows:
```
├── patch # Directory of the patch adapted to Ascend AI Processors
│ ├── pytorch1.5.0_npu.patch # Patch for PyTorch 1.5.0
│ └── pytorch1.8.1_npu.patch # Patch for PyTorch 1.8.1
├── pytorch1.5.0 # Source code and test directory for PyTorch 1.5.0
│ ├── access_control_test.py
│ ├── src # Source code directory
│ └── test # Directory for storing test cases
├── pytorch1.8.1 # Source code and test directory for PyTorch 1.8.1
│ ├── access_control_test.py
│ ├── src # Source code directory
│ └── test # Directory for storing test cases
└── scripts # Build and create a directory.
pytorch
│ ├─patch # Directory of the patch adapted to Ascend AI Processors
│ ├─npu.patch
│ ├─scripts # Build and create a directory.
│ ├─gen.sh
│ ├─src # Source code directory
│ ├─test # Directory for storing test cases
│ ├─README.md
```
2. Obtain the native PyTorch source code from the root directory **/pytorch** of the current repository.
- If PyTorch 1.5.0 is installed, run the following command:
2. Run the following commands to go to the **pytorch** directory and obtain the native PyTorch source code:
```
git clone -b v1.5.0 --depth=1 https://github.com/pytorch/pytorch.git
```
```
cd pytorch
git clone -b v1.5.0 --depth=1 https://github.com/pytorch/pytorch.git
```
- If PyTorch 1.8.1 is installed, run the following command:
After the native PyTorch source code is downloaded, the main directory structure of the code is as follows:
```
git clone -b v1.8.1 --depth=1 https://github.com/pytorch/pytorch.git
```
```
pytorch
│ ├─patch # Directory of the patch adapted to Ascend AI Processors
│ ├─npu.patch
│ ├─pytorch # Directory for storing the native PyTorch code
│ ├─scripts # Build and create a directory.
│ ├─gen.sh
│ ├─src # Source code directory
│ ├─test # Directory for storing test cases
│ ├─README.md
```
3. Run the following commands to go to the native PyTorch code directory **pytorch** and obtain the PyTorch passive dependency code:
@@ -122,37 +126,26 @@ When setting up the environment for PyTorch model development and running, you c
```
cd ../scripts
# If PyTorch 1.5.0 is installed:
bash gen.sh
# If PyTorch 1.8.1 is installed:
bash gen.sh -v 1.8.1
```
The full code adapted to Ascend AI Processors is generated in the **pytorch/pytorch** directory.
2. Go to the **pytorch/pytorch/** directory and install the dependency library.
2. Go to the full code directory **pytorch/pytorch**, and compile and generate the binary installation package of PyTorch.
```
cd ../pytorch
pip3 install -r requirements.txt
bash build.sh
```
3. Build and generate the binary installation package of PyTorch.
```
bash build.sh --python=3.7
or
bash build.sh --python=3.8
```
Specify the Python version in the environment for build. The generated binary package is stored in the current dist directory **pytorch/pytorch/dist**.
The generated binary package is stored in the current dist directory **pytorch/pytorch/dist**.
5. <a name="en-us_topic_0000001152776301_li49671667141"></a>Install PyTorch.
Go to the **pytorch/pytorch/dist** directory and run the following command to install PyTorch:
```
pip3 install --upgrade torch-1.5.0+ascend.post3-cp37-cp37m-linux_{arch}.whl
pip3 install --upgrade torch-1.5.0+ascend-cp37-cp37m-linux_{arch}.whl
```
_\{**arch\}**_ indicates the architecture information. The value can be **aarch64** or **x86\_64**.
@@ -162,42 +155,62 @@ When setting up the environment for PyTorch model development and running, you c
>**pip3 list | grep torch**
<h3 id="configuring-environment-variablesmd">Configuring Environment Variables</h3>
<h2 id="configuring-environment-variables">Configuring Environment Variables</h2>
After the software packages are installed, configure environment variables to use Ascend PyTorch. For details about the environment variables, see [Table 1](#en-us_topic_0000001152616261_table42017516135).
After the software packages are installed, configure environment variables to use Ascend PyTorch. You are advised to build a startup script, for example, the **set\_env.sh** script, and run **source set\_env.sh** to configure the environment variables. The content of the **set\_env.sh** script is as follows \(the **root** user is used as the installation user and the default installation path is used\):
1. Configure the operating environment variables by running the following command in the **root** directory of the PyTorch source code adapted to Ascend AI Processors:
```
cpu_type=$(echo $HOSTTYPE)
```
source pytorch/env.sh
```
if [ x"${cpu_type}" == x"x86_64" ];then
cpu_type=x86_64-linux
else
cpu_type=arm64-linux
fi
if [ -d /usr/local/Ascend/nnae/latest ];then
export LD_LIBRARY_PATH=/usr/local/:/usr/local/python3.7.5/lib/:/usr/local/openblas/lib:/usr/local/lib/:/usr/lib64/:/usr/lib/:/usr/local/Ascend/nnae/latest/fwkacllib/lib64/:/usr/local/Ascend/driver/lib64/common/:/usr/local/Ascend/driver/lib64/driver/:/usr/local/Ascend/add-ons/:/usr/lib/aarch64_64-linux-gnu:$LD_LIBRARY_PATH
export PATH=$PATH:/usr/local/Ascend/nnae/latest/fwkacllib/ccec_compiler/bin/:/usr/local/Ascend/nnae/latest/toolkit/tools/ide_daemon/bin/
export ASCEND_OPP_PATH=/usr/local/Ascend/nnae/latest/opp/
export OPTION_EXEC_EXTERN_PLUGIN_PATH=/usr/local/Ascend/nnae/latest/fwkacllib/lib64/plugin/opskernel/libfe.so:/usr/local/Ascend/nnae/latest/fwkacllib/lib64/plugin/opskernel/libaicpu_engine.so:/usr/local/Ascend/nnae/latest/fwkacllib/lib64/plugin/opskernel/libge_local_engine.so
export PYTHONPATH=/usr/local/Ascend/nnae/latest/fwkacllib/python/site-packages/:/usr/local/Ascend/nnae/latest/fwkacllib/python/site-packages/auto_tune.egg/auto_tune:/usr/local/Ascend/nnae/latest/fwkacllib/python/site-packages/schedule_search.egg:$PYTHONPATH
export ASCEND_AICPU_PATH=/usr/local/Ascend/nnae/latest/
else
export LD_LIBRARY_PATH=/usr/local/:/usr/local/lib/:/usr/lib64/:/usr/lib/:/usr/local/python3.7.5/lib/:/usr/local/openblas/lib:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/lib64/:/usr/local/Ascend/driver/lib64/common/:/usr/local/Ascend/driver/lib64/driver/:/usr/local/Ascend/add-ons/:/usr/lib/aarch64-linux-gnu:$LD_LIBRARY_PATH
export PATH=$PATH:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/ccec_compiler/bin/:/usr/local/Ascend/ascend-toolkit/latest/toolkit/tools/ide_daemon/bin/
export ASCEND_OPP_PATH=/usr/local/Ascend/ascend-toolkit/latest/opp/
export OPTION_EXEC_EXTERN_PLUGIN_PATH=/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libfe.so:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libaicpu_engine.so:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libge_local_engine.so
export PYTHONPATH=/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/python/site-packages/:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/python/site-packages/auto_tune.egg/auto_tune:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/python/site-packages/schedule_search.egg:$PYTHONPATH
export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest/${cpu_type}
fi
path_lib=$(python3.7 -c """
import sys
import re
result=''
for index in range(len(sys.path)):
match_sit = re.search('-packages', sys.path[index])
if match_sit is not None:
match_lib = re.search('lib', sys.path[index])
if match_lib is not None:
end=match_lib.span()[1]
result += sys.path[index][0:end] + ':'
result+=sys.path[index] + '/torch/lib:'
print(result)"""
)
export LD_LIBRARY_PATH=/usr/local/python3.7.5/lib/:${path_lib}:$LD_LIBRARY_PATH
export TASK_QUEUE_ENABLE=1
2. Select a proper HCCL initialization mode based on the actual scenario and configure the corresponding environment variables.
# (Optional) If the system is openEuler, run this command to cancel CPU core binding.
# unset GOMP_CPU_AFFINITY
```
# Scenario 1: Single-node scenario
export HCCL_WHITELIST_DISABLE=1 # Disable the HCCL trustlist.
# Scenario 2: Multi-node scenario
export HCCL_WHITELIST_DISABLE=1 # Disable the HCCL trustlist.
export HCCL_IF_IP="1.1.1.1" # 1.1.1.1 is the NIC IP address of the host. Change it based on the site requirements. Ensure that the NIC IP addresses in use can communicate with each other in the cluster.
```
3. \(Optional\) Configure function or performance environment variables in the NPU scenario. The variables are disabled by default.
```
export DYNAMIC_COMPILE_ENABLE=1 # (Optional) Dynamic shape feature, which is used when the shape changes. To enable this function, set the value to 1. (PyTorch 1.8.1 does not support this environment variable.)
export COMBINED_ENABLE=1 # (Optional) Optimizes the scenario where two inconsecutive operators are combined. To enable this function, set the value to 1.
export TRI_COMBINED_ENABLE=1 # (Optional) Optimizes the scenario where three inconsecutive operators are combined. To enable this function, set the value to 1.
export ACL_DUMP_DATA=1 # (Optional) Operator data dump function, which is used for debugging. To enable this function, set the value to 1.
export DYNAMIC_OP="ADD#MUL" # (Optional) Operator implementation. The performance of the ADD and MUL operators varies depending on the scenarios.
```
4. \(Optional\) If the system is openEuler or its inherited OS, such as UOS, run the following command to cancel CPU core binding.
```
# unset GOMP_CPU_AFFINITY
```
# Select an HCCL initialization method and configure the corresponding environment variables in the following scenarios. The details are as follows:
# Scenario 1: Single-node scenario
export HCCL_WHITELIST_DISABLE=1 # Disable the HCCL trustlist.
# Scenario 2: Multi-node scenario
export HCCL_WHITELIST_DISABLE=1 # Disable the HCCL trustlist.
export HCCL_IF_IP="1.1.1.1" # 1.1.1.1 is the NIC IP address of the host. Change it based on the site requirements. Ensure that the NIC IP addresses used can communicate with each other in the cluster.
```
[Table 1](#en-us_topic_0000001152616261_table42017516135) describes related variables.
**Table 1** Description of environment variables
@@ -211,7 +224,7 @@ After the software packages are installed, configure environment variables to us
<tbody><tr id="en-us_topic_0000001152616261_row6882121917329"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="en-us_topic_0000001152616261_p688241953218"><a name="en-us_topic_0000001152616261_p688241953218"></a><a name="en-us_topic_0000001152616261_p688241953218"></a>LD_LIBRARY_PATH</p>
</td>
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="en-us_topic_0000001152616261_p1888291915322"><a name="en-us_topic_0000001152616261_p1888291915322"></a><a name="en-us_topic_0000001152616261_p1888291915322"></a>Dynamic library search path. Set this variable based on the preceding example.</p>
<p id="p1292181892120"><a name="p1292181892120"></a><a name="p1292181892120"></a>If you need to upgrade GCC in OSs such as CentOS, Debian, and BC-Linux, add <strong id="b6163826603"><a name="b6163826603"></a><a name="b6163826603"></a><em id="i161631926505"><a name="i161631926505"></a><a name="i161631926505"></a>${install_path}</em>/lib64</strong> to the <span class="parmname" id="parmname161637265015"><a name="parmname161637265015"></a><a name="parmname161637265015"></a><b>LD_LIBRARY_PATH</b></span> variable of the dynamic library search path. Replace <em id="i01649261704"><a name="i01649261704"></a><a name="i01649261704"></a><strong id="b1216317261109"><a name="b1216317261109"></a><a name="b1216317261109"></a>{install_path}</strong></em> with the GCC installation path. For details, see <a href="#how-do-i-install-gcc-7-3-0md#en-us_topic_0000001135347812_en-us_topic_0000001173199577_en-us_topic_0000001172534867_en-us_topic_0276688294_li9745165315131">5</a>.</p>
<p id="p1292181892120"><a name="p1292181892120"></a><a name="p1292181892120"></a>If you need to upgrade GCC in OSs such as CentOS, Debian, and BC-Linux, add <strong id="b6163826603"><a name="b6163826603"></a><a name="b6163826603"></a><em id="i161631926505"><a name="i161631926505"></a><a name="i161631926505"></a>${install_path}</em>/lib64</strong> to the <span class="parmname" id="parmname161637265015"><a name="parmname161637265015"></a><a name="parmname161637265015"></a><b>LD_LIBRARY_PATH</b></span> variable of the dynamic library search path. Replace <em id="i01649261704"><a name="i01649261704"></a><a name="i01649261704"></a><strong id="b1216317261109"><a name="b1216317261109"></a><a name="b1216317261109"></a>{install_path}</strong></em> with the GCC installation path. For details, see <a href="#how-do-i-install-gcc-7-3-0#en-us_topic_0000001135347812_en-us_topic_0000001173199577_en-us_topic_0000001172534867_en-us_topic_0276688294_li9745165315131">5</a>.</p>
</td>
</tr>
<tr id="en-us_topic_0000001152616261_row16194175523010"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="en-us_topic_0000001152616261_p16195185523019"><a name="en-us_topic_0000001152616261_p16195185523019"></a><a name="en-us_topic_0000001152616261_p16195185523019"></a>PYTHONPATH</p>
@@ -258,70 +271,22 @@ After the software packages are installed, configure environment variables to us
<p id="en-us_topic_0000001152616261_p1167163719217"><a name="en-us_topic_0000001152616261_p1167163719217"></a><a name="en-us_topic_0000001152616261_p1167163719217"></a>By default, the host communication NICs are selected in the following sequence: NICs other than Docker/local NICs (in ascending alphabetical order of NIC names) &gt; Docker NICs &gt; local NICs.</p>
</td>
</tr>
<tr id="en-us_topic_0000001152616261_row1371356152313"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p15106173103120"><a name="p15106173103120"></a><a name="p15106173103120"></a>PTCOPY_ENABLE</p>
<tr id="en-us_topic_0000001152616261_row1371356152313"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="en-us_topic_0000001152616261_p16711563237"><a name="en-us_topic_0000001152616261_p16711563237"></a><a name="en-us_topic_0000001152616261_p16711563237"></a>unset GOMP_CPU_AFFINITY</p>
</td>
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p71055317311"><a name="p71055317311"></a><a name="p71055317311"></a>Use the PTCopy operator mode to accelerate the operation of converting non-contiguous tensors to contiguous tensors and copy process. You are advised to set the value to <strong id="b114621515513"><a name="b114621515513"></a><a name="b114621515513"></a>1</strong> to enable this function. </p>
</td>
</tr>
<tr id="row743212132309"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p17433111312307"><a name="p17433111312307"></a><a name="p17433111312307"></a>ASCEND_SLOG_PRINT_TO_STDOUT</p>
</td>
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p6433151393018"><a name="p6433151393018"></a><a name="p6433151393018"></a>(Optional) Whether to enable the log printing function.</p>
<a name="ul760201917473"></a><a name="ul760201917473"></a><ul id="ul760201917473"><li><strong id="b1955232216215"><a name="b1955232216215"></a><a name="b1955232216215"></a>0</strong>: uses the default log output mode.</li><li><strong id="b22913272211"><a name="b22913272211"></a><a name="b22913272211"></a>1</strong>: prints the logs to the screen.</li><li>Other values: invalid</li></ul>
</td>
</tr>
<tr id="row19237171814300"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p14238161893019"><a name="p14238161893019"></a><a name="p14238161893019"></a>ASCEND_GLOBAL_LOG_LEVEL</p>
</td>
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p223841810303"><a name="p223841810303"></a><a name="p223841810303"></a>Sets the global log level of app logs.</p>
<a name="ul175714586453"></a><a name="ul175714586453"></a><ul id="ul175714586453"><li><strong id="b94698561835"><a name="b94698561835"></a><a name="b94698561835"></a>0</strong>: DEBUG</li><li><strong id="b1612516597314"><a name="b1612516597314"></a><a name="b1612516597314"></a>1</strong>: INFO</li><li><strong id="b82051911547"><a name="b82051911547"></a><a name="b82051911547"></a>2</strong>: WARNING</li><li><strong id="b04351021945"><a name="b04351021945"></a><a name="b04351021945"></a>3</strong>: ERROR</li><li><strong id="b116153316418"><a name="b116153316418"></a><a name="b116153316418"></a>4</strong>: NULL (no log output)</li><li>Other values: invalid</li></ul>
</td>
</tr>
<tr id="row1348192313303"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p1734815235305"><a name="p1734815235305"></a><a name="p1734815235305"></a>ASCEND_GLOBAL_EVENT_ENABLE</p>
</td>
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p12348202373018"><a name="p12348202373018"></a><a name="p12348202373018"></a>Whether to enable event logging for apps.</p>
<a name="ul416352114610"></a><a name="ul416352114610"></a><ul id="ul416352114610"><li><strong id="b425610311940"><a name="b425610311940"></a><a name="b425610311940"></a>0</strong>: disabled</li><li><strong id="b198984321741"><a name="b198984321741"></a><a name="b198984321741"></a>1</strong>: enabled</li><li>Other values: invalid</li></ul>
</td>
</tr>
<tr id="row17878184693015"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p1878194683016"><a name="p1878194683016"></a><a name="p1878194683016"></a>DYNAMIC_COMPILE_ENABLE</p>
</td>
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p1887894620304"><a name="p1887894620304"></a><a name="p1887894620304"></a>(Optional) Dynamic shape feature, which is used when the shape changes. To enable this function, set the value to <strong id="b11281447194117"><a name="b11281447194117"></a><a name="b11281447194117"></a>1</strong>. (PyTorch 1.8.1 does not support this environment variable.)</p>
</td>
</tr>
<tr id="row78312162301"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p1832171673019"><a name="p1832171673019"></a><a name="p1832171673019"></a>COMBINED_ENABLE</p>
</td>
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p583261643014"><a name="p583261643014"></a><a name="p583261643014"></a>(Optional) Optimizes the scenario where two inconsecutive operators are combined. To enable this function, set the value to <strong id="b19824817612"><a name="b19824817612"></a><a name="b19824817612"></a>1</strong>.</p>
</td>
</tr>
<tr id="row17630155212342"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p66309527341"><a name="p66309527341"></a><a name="p66309527341"></a>RI_COMBINED_ENABLE</p>
</td>
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p19630185220345"><a name="p19630185220345"></a><a name="p19630185220345"></a>(Optional) Optimizes the scenario where three inconsecutive operators are combined. To enable this function, set the value to <strong id="b10522121418612"><a name="b10522121418612"></a><a name="b10522121418612"></a>1</strong>.</p>
</td>
</tr>
<tr id="row183041355123411"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p730435533415"><a name="p730435533415"></a><a name="p730435533415"></a>ACL_DUMP_DATA</p>
</td>
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p16304105533412"><a name="p16304105533412"></a><a name="p16304105533412"></a>(Optional) Operator data dump function, which is used for debugging. To enable this function, set the value to <strong id="b1861154419918"><a name="b1861154419918"></a><a name="b1861154419918"></a>1</strong>.</p>
</td>
</tr>
<tr id="row27481914203518"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p674813144357"><a name="p674813144357"></a><a name="p674813144357"></a>DYNAMIC_OP</p>
</td>
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p974891414353"><a name="p974891414353"></a><a name="p974891414353"></a>(Optional) Operator implementation. The performance of the ADD and MUL operators varies depending on the scenarios. This parameter is not set by default.</p>
</td>
</tr>
<tr id="row19173161510309"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="en-us_topic_0000001152616261_p16711563237"><a name="en-us_topic_0000001152616261_p16711563237"></a><a name="en-us_topic_0000001152616261_p16711563237"></a>unset GOMP_CPU_AFFINITY</p>
</td>
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="en-us_topic_0000001152616261_p0711356152317"><a name="en-us_topic_0000001152616261_p0711356152317"></a><a name="en-us_topic_0000001152616261_p0711356152317"></a>(Optional) If the system is openEuler or its inherited OS, such as UOS, run this command to cancel CPU core binding.</p>
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="en-us_topic_0000001152616261_p0711356152317"><a name="en-us_topic_0000001152616261_p0711356152317"></a><a name="en-us_topic_0000001152616261_p0711356152317"></a>(Optional) If the system is openEuler, run this command to cancel CPU core binding.</p>
</td>
</tr>
</tbody>
</table>
<h3 id="installing-the-mixed-precision-modulemd">Installing the Mixed Precision Module</h3>
<h2 id="installing-the-mixed-precision-module">Installing the Mixed Precision Module</h2>
#### Prerequisites<a name="en-us_topic_0000001106176190_section3225481020"></a>
## Prerequisites<a name="en-us_topic_0000001106176190_section3225481020"></a>
1. Ensure that the PyTorch framework adapted to Ascend AI Processors in the operating environment can be used properly.
2. Before building and installing Apex, you have configured the environment variables on which the build depends. See [Configuring Environment Variables](#configuring-environment-variablesmd).
2. Before building and installing Apex, you have configured the environment variables on which the build depends. See [Configuring Environment Variables](#configuring-environment-variables).
#### Installation Process<a name="en-us_topic_0000001106176190_section11880164819567"></a>
## Installation Process<a name="en-us_topic_0000001106176190_section11880164819567"></a>
1. Log in to the server as the **root** user or a non-root user.
2. Obtain the Apex source code.
@@ -329,7 +294,7 @@ After the software packages are installed, configure environment variables to us
1. Run the following command to obtain the Apex source code adapted to Ascend AI Processors:
```
git clone https://gitee.com/ascend/apex.git
git clone -b 2.0.2.tr5 https://gitee.com/ascend/apex.git
```
The directory structure of the downloaded source code is as follows:
@@ -342,6 +307,7 @@ After the software packages are installed, configure environment variables to us
│ ├─gen.sh
│ ├─src # Source code directory
│ ├─tests # Directory for storing test cases
│ ├─README.md
```
2. Run the following commands to go to the **apex** directory and obtain the native Apex source code:
@@ -362,6 +328,7 @@ After the software packages are installed, configure environment variables to us
│ ├─gen.sh
│ ├─src # Source code directory
│ ├─tests # Directory for storing test cases
│ ├─README.md
```
3. Go to the native Apex code directory, that is, **apex/apex**. Switch to the code branch whose commit ID is 4ef930c1c884fdca5f472ab2ce7cb9b505d26c1a.
@@ -369,6 +336,7 @@ After the software packages are installed, configure environment variables to us
```
cd apex
git checkout 4ef930c1c884fdca5f472ab2ce7cb9b505d26c1a
cd ..
```
>![](public_sys-resources/icon-note.gif) **NOTE:**
@@ -391,14 +359,14 @@ After the software packages are installed, configure environment variables to us
python3 setup.py --cpp_ext --npu_float_status bdist_wheel
```
The Python version must be the same as that used by PyTorch. The generated binary package is stored in the current **dist** directory, that is, **apex/apex/dist**.
The generated binary package is stored in the current dist directory **apex/apex/dist**.
4. <a name="en-us_topic_0000001106176190_li425495374416"></a>Install Apex.
Go to the **apex/apex/dist** directory and run the following command to install Apex:
```
pip3 install --upgrade apex-0.1+ascend-cp37-cp37m-linux_{arch}.whl
pip3.7 install --upgrade apex-0.1+ascend-cp37-cp37m-linux_{arch}.whl
```
_\{**arch\}**_ indicates the architecture information. The value can be **aarch64** or **x86\_64**.
@@ -408,16 +376,61 @@ After the software packages are installed, configure environment variables to us
>**pip3 list | grep apex**
<h2 id="referencesmd">References</h2>
<h2 id="using-the-ascend-hub-image">Using the Ascend Hub Image</h2>
- **[Installing CMake](#installing-cmakemd)**
- **[Obtaining the PyTorch Image from the Ascend Hub](#obtaining-the-pytorch-image-from-the-ascend-hub)**
- **[How Do I Install GCC 7.3.0?](#how-do-i-install-gcc-7-3-0md)**
- **[What Do I Do If "torch 1.5.0xxxx" and "torchvision" Do Not Match When torch-\*.whl Is Installed?](#what-do-i-do-if-torch-1-5-0xxxx-and-torchvision-do-not-match-when-torch--whl-is-installedmd)**
- **[Configuring Environment Variables](#configuring-environment-variables-0)**
<h3 id="installing-cmakemd">Installing CMake</h3>
<h2 id="obtaining-the-pytorch-image-from-the-ascend-hub">Obtaining the PyTorch Image from the Ascend Hub</h2>
## Prerequisites<a name="en-us_topic_0000001118701830_en-us_topic_0275872734_section108914373254"></a>
- The development or operating environment of CANN has been installed. For details, see the _CANN Software Installation Guide_.
- Docker has been installed on the host.
## Obtaining and Using an Image<a name="en-us_topic_0000001118701830_section108941734162613"></a>
Log in to the [Ascend Hub](https://ascendhub.huawei.com/#/home) to obtain the required image. \(Activate the account when applying for an image for the first time.\)
[Table 1](#en-us_topic_0000001118701830_en-us_topic_0000001074498056_table1519011227314) lists the supported images. Select an image that you want.
**Table 1** Image list
<a name="en-us_topic_0000001118701830_en-us_topic_0000001074498056_table1519011227314"></a>
<table><thead align="left"><tr id="en-us_topic_0000001118701830_en-us_topic_0000001074498056_row0190152218319"><th class="cellrowborder" valign="top" width="55.00000000000001%" id="mcps1.2.4.1.1"><p id="en-us_topic_0000001118701830_en-us_topic_0000001074498056_p1419132211315"><a name="en-us_topic_0000001118701830_en-us_topic_0000001074498056_p1419132211315"></a><a name="en-us_topic_0000001118701830_en-us_topic_0000001074498056_p1419132211315"></a>Image Name</p>
</th>
<th class="cellrowborder" valign="top" width="20%" id="mcps1.2.4.1.2"><p id="en-us_topic_0000001118701830_en-us_topic_0000001074498056_p75071327115313"><a name="en-us_topic_0000001118701830_en-us_topic_0000001074498056_p75071327115313"></a><a name="en-us_topic_0000001118701830_en-us_topic_0000001074498056_p75071327115313"></a>Image Version</p>
</th>
<th class="cellrowborder" valign="top" width="25%" id="mcps1.2.4.1.3"><p id="en-us_topic_0000001118701830_en-us_topic_0000001074498056_p1024411406234"><a name="en-us_topic_0000001118701830_en-us_topic_0000001074498056_p1024411406234"></a><a name="en-us_topic_0000001118701830_en-us_topic_0000001074498056_p1024411406234"></a>CANN Version</p>
</th>
</tr>
</thead>
<tbody><tr id="en-us_topic_0000001118701830_en-us_topic_0000001074498056_row71915221134"><td class="cellrowborder" valign="top" width="55.00000000000001%" headers="mcps1.2.4.1.1 "><a name="en-us_topic_0000001118701830_en-us_topic_0000001074498056_ul81691515131910"></a><a name="en-us_topic_0000001118701830_en-us_topic_0000001074498056_ul81691515131910"></a><ul id="en-us_topic_0000001118701830_en-us_topic_0000001074498056_ul81691515131910"><li>ARM architecture: <a href="https://ascendhub.huawei.com/#/detail?name=ascend-pytorch-arm" target="_blank" rel="noopener noreferrer">ascend-pytorch-arm</a></li><li>x86 architecture: <a href="https://ascendhub.huawei.com/#/detail?name=ascend-pytorch-x86" target="_blank" rel="noopener noreferrer">ascend-pytorch-x86</a></li></ul>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.4.1.2 "><p id="en-us_topic_0000001118701830_en-us_topic_0000001074498056_p14648161414516"><a name="en-us_topic_0000001118701830_en-us_topic_0000001074498056_p14648161414516"></a><a name="en-us_topic_0000001118701830_en-us_topic_0000001074498056_p14648161414516"></a>21.0.2</p>
</td>
<td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.4.1.3 "><p id="en-us_topic_0000001118701830_en-us_topic_0000001074498056_p1264815147514"><a name="en-us_topic_0000001118701830_en-us_topic_0000001074498056_p1264815147514"></a><a name="en-us_topic_0000001118701830_en-us_topic_0000001074498056_p1264815147514"></a><a href="https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373" target="_blank" rel="noopener noreferrer">5.0.2</a></p>
</td>
</tr>
</tbody>
</table>
<h2 id="configuring-environment-variables-0">Configuring Environment Variables</h2>
After starting and entering the image container, configure the environment variables on which model training depends by referring to [Configuring Environment Variables](#configuring-environment-variables).
<h2 id="references">References</h2>
- **[Installing CMake](#installing-cmake)**
- **[How Do I Install GCC 7.3.0?](#how-do-i-install-gcc-7-3-0)**
- **[What Do I Do If "torch 1.5.0xxxx" and "torchvision" Do Not Match When torch-\*.whl Is Installed?](#what-do-i-do-if-torch-1-5-0xxxx-and-torchvision-do-not-match-when-torch--whl-is-installed)**
<h2 id="installing-cmake">Installing CMake</h2>
Procedure for upgrading CMake to 3.12.1
@@ -456,7 +469,7 @@ Procedure for upgrading CMake to 3.12.1
If the message "cmake version 3.12.1" is displayed, the installation is successful.
<h3 id="how-do-i-install-gcc-7-3-0md">How Do I Install GCC 7.3.0?</h3>
<h2 id="how-do-i-install-gcc-7-3-0">How Do I Install GCC 7.3.0?</h2>
Perform the following steps as the **root** user.
@@ -537,19 +550,19 @@ Perform the following steps as the **root** user.
>Skip this step if you do not need to use the compilation environment with GCC upgraded.
<h3 id="what-do-i-do-if-torch-1-5-0xxxx-and-torchvision-do-not-match-when-torch--whl-is-installedmd">What Do I Do If "torch 1.5.0xxxx" and "torchvision" Do Not Match When torch-\*.whl Is Installed?</h3>
<h2 id="what-do-i-do-if-torch-1-5-0xxxx-and-torchvision-do-not-match-when-torch--whl-is-installed">What Do I Do If "torch 1.5.0xxxx" and "torchvision" Do Not Match When torch-\*.whl Is Installed?</h2>
#### Symptom<a name="en-us_topic_0000001105856364_en-us_topic_0175549220_section197270431505"></a>
## Symptom<a name="en-us_topic_0000001105856364_en-us_topic_0175549220_section197270431505"></a>
During the installation of **torch-**_\*_**.whl**, the message "ERROR: torchvision 0.6.0 has requirement torch==1.5.0, but you'll have torch 1.5.0a0+1977093 which is incompatible" " is displayed.
![](figures/en-us_image_0000001190081735.png)
![](figures/en-us_image_0000001180656411.png)
#### Possible Causes<a name="en-us_topic_0000001105856364_en-us_topic_0175549220_section169499490501"></a>
## Possible Causes<a name="en-us_topic_0000001105856364_en-us_topic_0175549220_section169499490501"></a>
When the PyTorch is installed, the version check is automatically triggered. The version of the torchvision installed in the environment is 0.6.0. During the check, it is found that the version of the **torch-**_\*_**.whl** is inconsistent with the required version 1.5.0. As a result, an error message is displayed, but the installation is successful.
#### Solution<a name="en-us_topic_0000001105856364_section108142031907"></a>
## Solution<a name="en-us_topic_0000001105856364_section108142031907"></a>
This problem has no impact on the actual result, and no action is required.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 329 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 394 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 406 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 253 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 580 B

@@ -1,48 +1,48 @@
# PyTorch Online Inference Guide
- [Application Scenario](#application-scenariomd)
- [Basic Workflow](#basic-workflowmd)
- [Prerequisites](#prerequisitesmd)
- [Online Inference Process](#online-inference-processmd)
- [Environment Variable Configuration](#environment-variable-configurationmd)
- [Sample Reference](#sample-referencemd)
- [Special Topics](#special-topicsmd)
- [Mixed Precision](#mixed-precisionmd)
- [How Do I Install GCC 7.3.0?](#how-do-i-install-gcc-7-3-0md)
<h2 id="application-scenariomd">Application Scenario</h2>
- [Application Scenario](#application-scenario)
- [Basic Workflow](#basic-workflow)
- [Prerequisites](#prerequisites)
- [Online Inference Process](#online-inference-process)
- [Environment Variable Configuration](#environment-variable-configuration)
- [Sample Reference](#sample-reference)
- [Special Topics](#special-topics)
- [Mixed Precision](#mixed-precision)
- [How Do I Install GCC 7.3.0?](#how-do-i-install-gcc-7-3-0)
<h2 id="application-scenario">Application Scenario</h2>
Online inference, unlike offline inference, allows developers to perform inference directly with PyTorch models using the **model.eval\(\)** method.
In this way, PyTorch-based inference apps can be directly ported to the Ascend AI Processor, which is especially useful in the data center inference scenarios.
### Supported Processors<a name="section15598658104219"></a>
## Supported Processors<a name="section15598658104219"></a>
Ascend 910 AI Processor
Ascend 710 AI Processor
<h2 id="basic-workflowmd">Basic Workflow</h2>
<h2 id="basic-workflow">Basic Workflow</h2>
- **[Prerequisites](#prerequisitesmd)**
- **[Prerequisites](#prerequisites)**
- **[Online Inference Process](#online-inference-processmd)**
- **[Online Inference Process](#online-inference-process)**
- **[Environment Variable Configuration](#environment-variable-configurationmd)**
- **[Environment Variable Configuration](#environment-variable-configuration)**
- **[Sample Reference](#sample-referencemd)**
- **[Sample Reference](#sample-reference)**
<h3 id="prerequisitesmd">Prerequisites</h3>
<h2 id="prerequisites">Prerequisites</h2>
The PyTorch framework and mixed precision module have been installed. For details, see the _PyTorch Installation Guide_.
The PyTorch framework and mixed precision module have been installed. For details, see the .
<h3 id="online-inference-processmd">Online Inference Process</h3>
<h2 id="online-inference-process">Online Inference Process</h2>
[Figure 1](#fig13802941161818) shows the online inference process.
**Figure 1** Online inference process<a name="fig13802941161818"></a>
![](figures/online-inference-process.png "online-inference-process")
<h3 id="environment-variable-configurationmd">Environment Variable Configuration</h3>
<h2 id="environment-variable-configuration">Environment Variable Configuration</h2>
The following are the environment variables required for starting the inference process on PyTorch:
@@ -60,7 +60,7 @@ export LD_LIBRARY_PATH=/usr/local/python3.7.5/lib:$LD_LIBRARY_PATH
# Sets the logical ID of a processor.
export ASCEND_DEVICE_ID=0
# Outputs log information. Replace it as required.
# Output log information. Replace it as required.
export ASCEND_SLOG_PRINT_TO_STDOUT=1
export ASCEND_GLOBAL_LOG_LEVEL=0
@@ -82,7 +82,7 @@ export TASK_QUEUE_ENABLE=0
<tbody><tr id="row2732273481"><td class="cellrowborder" valign="top" width="46.75467546754676%" headers="mcps1.2.4.1.1 "><p id="p57382719481"><a name="p57382719481"></a><a name="p57382719481"></a>LD_LIBRARY_PATH</p>
</td>
<td class="cellrowborder" valign="top" width="43.18431843184319%" headers="mcps1.2.4.1.2 "><p id="p07319271480"><a name="p07319271480"></a><a name="p07319271480"></a>Dynamic library search path. Set this variable based on the preceding example.</p>
<div class="note" id="note119943144912"><a name="note119943144912"></a><a name="note119943144912"></a><span class="notetitle"> NOTE: </span><div class="notebody"><p id="p49933104915"><a name="p49933104915"></a><a name="p49933104915"></a>If GCC 7.3.0 is installed in OSs such as CentOS 7.6, Debian, and BC-Linux, configure the related environment variables. For details, see <a href="#how-do-i-install-gcc-7-3-0md#en-us_topic_0000001146754749_en-us_topic_0000001072593337_l5e5c9395407d46439788b12f0e6342bc">5</a>.</p>
<div class="note" id="note119943144912"><a name="note119943144912"></a><a name="note119943144912"></a><span class="notetitle"> NOTE: </span><div class="notebody"><p id="p49933104915"><a name="p49933104915"></a><a name="p49933104915"></a>If GCC 7.3.0 is installed in OSs such as CentOS 7.6, Debian, and BCLinux, configure the related environment variable. For details, see <a href="#how-do-i-install-gcc-7-3-0.md#en-us_topic_0000001146754749_en-us_topic_0000001072593337_l5e5c9395407d46439788b12f0e6342bc">5</a>.</p>
</div></div>
</td>
<td class="cellrowborder" valign="top" width="10.061006100610062%" headers="mcps1.2.4.1.3 "><p id="p187352744817"><a name="p187352744817"></a><a name="p187352744817"></a>Required</p>
@@ -106,7 +106,7 @@ export TASK_QUEUE_ENABLE=0
<tr id="row203705529819"><td class="cellrowborder" valign="top" width="46.75467546754676%" headers="mcps1.2.4.1.1 "><p id="p53705522810"><a name="p53705522810"></a><a name="p53705522810"></a>ASCEND_SLOG_PRINT_TO_STDOUT</p>
</td>
<td class="cellrowborder" valign="top" width="43.18431843184319%" headers="mcps1.2.4.1.2 "><p id="en-us_topic_0000001073203258_p763102116322"><a name="en-us_topic_0000001073203258_p763102116322"></a><a name="en-us_topic_0000001073203258_p763102116322"></a>Enables or disables log printing. Values:</p>
<a name="en-us_topic_0000001073203258_ul95291245104113"></a><a name="en-us_topic_0000001073203258_ul95291245104113"></a><ul id="en-us_topic_0000001073203258_ul95291245104113"><li><strong id="b1877191971104041"><a name="b1877191971104041"></a><a name="b1877191971104041"></a>0</strong> or not configured: disabled</li><li><strong id="b737654378104041"><a name="b737654378104041"></a><a name="b737654378104041"></a>1</strong>: enabled</li></ul>
<a name="en-us_topic_0000001073203258_ul95291245104113"></a><a name="en-us_topic_0000001073203258_ul95291245104113"></a><ul id="en-us_topic_0000001073203258_ul95291245104113"><li><strong id="b1877191971104041"><a name="b1877191971104041"></a><a name="b1877191971104041"></a>0</strong> or not configured: disabled.</li><li><strong id="b737654378104041"><a name="b737654378104041"></a><a name="b737654378104041"></a>1</strong>: enabled.</li></ul>
</td>
<td class="cellrowborder" valign="top" width="10.061006100610062%" headers="mcps1.2.4.1.3 "><p id="p6370125217818"><a name="p6370125217818"></a><a name="p6370125217818"></a>Optional</p>
</td>
@@ -133,9 +133,9 @@ export TASK_QUEUE_ENABLE=0
>![](public_sys-resources/icon-note.gif) **NOTE:**
>For more log information, see the _CANN Log Reference_.
<h3 id="sample-referencemd">Sample Reference</h3>
<h2 id="sample-reference">Sample Reference</h2>
#### Sample Code<a name="section2017032418274"></a>
## Sample Code<a name="section2017032418274"></a>
Try to minimize the initialization frequency across the app lifetime during inference. The inference mode is set using the **model.eval\(\)** method, and the inference process must run under the code branch **with torch.no\_grad\(\):**.
@@ -406,7 +406,7 @@ if __name__ == '__main__':
main()
```
#### Sample Running<a name="section340764716270"></a>
## Sample Running<a name="section340764716270"></a>
The following uses the ResNet-50 model as an example to describe how to perform online inference.
@@ -420,7 +420,7 @@ The following uses the ResNet-50 model as an example to describe how to perform
3. Run inference.
Set environment variables by referring to [Environment Variable Configuration](#environment-variable-configurationmd) and then run the following command:
Set environment variables by referring to [Environment Variable Configuration](#environment-variable-configuration) and then run the following command:
```
python3 pytorch-resnet50-apex.py --data /data/imagenet \
@@ -433,14 +433,14 @@ The following uses the ResNet-50 model as an example to describe how to perform
>The preceding command is an example only. Modify the arguments as needed.
<h2 id="special-topicsmd">Special Topics</h2>
<h2 id="special-topics">Special Topics</h2>
- **[Mixed Precision](#mixed-precisionmd)**
- **[Mixed Precision](#mixed-precision)**
<h3 id="mixed-precisionmd">Mixed Precision</h3>
<h2 id="mixed-precision">Mixed Precision</h2>
#### Overview<a name="section14734122962615"></a>
## Overview<a name="section14734122962615"></a>
Based on the architecture features of the NPU, mixed precision is involved in the model computing, that is, the scenario where the float16 and float32 data types are used together. Replacing float32 with float16 has the following advantages:
@@ -450,7 +450,7 @@ Based on the architecture features of the NPU, mixed precision is involved in th
However, the mixed precision training is limited by the precision range expressed by float16. If float32 is converted into float16, the training convergence is affected. To use float16 for acceleration in some computations and ensure training convergence, the mixed precision module Apex is used. The mixed precision module Apex is a comprehensive optimization library that features high optimization performance and precision.
#### Supported Features<a name="section175201458521"></a>
## Supported Features<a name="section175201458521"></a>
[Table 1](#en-us_topic_0278765773_table10717173813332) describes the functions and optimization of the mixed precision module.
@@ -489,7 +489,7 @@ However, the mixed precision training is limited by the precision range expresse
>![](public_sys-resources/icon-note.gif) **NOTE:**
>In the current version, Apex is implemented using Python and does not support AscendCL or CUDA optimization.
#### Initializing the Mixed Precision Model<a name="section18178125518268"></a>
## Initializing the Mixed Precision Model<a name="section18178125518268"></a>
1. To use the mixed precision module Apex, you need to import the amp module from the Apex library as follows:
@@ -503,20 +503,20 @@ However, the mixed precision training is limited by the precision range expresse
model, optimizer = amp.initialize(model, optimizer)
```
For details, see "Initialize the mixed precision model."# in [Sample Code](#sample-referencemd).
For details, see "Initialize the mixed precision model."# in [Sample Code](#sample-reference).
```
model, optimizer = amp.initialize(model, optimizer, opt_level="O2", loss_scale=1024, verbosity=1)
```
#### Mixed Precision Inference<a name="section818071513288"></a>
## Mixed Precision Inference<a name="section818071513288"></a>
After the mixed precision model is initialized, perform model forward propagation.
Sample code: For details, see the implementation of **validate\(val\_loader, model, args\)** in [Sample Code](#sample-referencemd).
Sample code: For details, see the implementation of **validate\(val\_loader, model, args\)** in [Sample Code](#sample-reference).
<h2 id="how-do-i-install-gcc-7-3-0md">How Do I Install GCC 7.3.0?</h2>
<h2 id="how-do-i-install-gcc-7-3-0">How Do I Install GCC 7.3.0?</h2>
Perform the following steps as the **root** user.

Before

Width:  |  Height:  |  Size: 580 B

After

Width:  |  Height:  |  Size: 580 B

Before

Width:  |  Height:  |  Size: 580 B

After

Width:  |  Height:  |  Size: 580 B

Before

Width:  |  Height:  |  Size: 394 B

After

Width:  |  Height:  |  Size: 394 B

Before

Width:  |  Height:  |  Size: 406 B

After

Width:  |  Height:  |  Size: 406 B

Before

Width:  |  Height:  |  Size: 253 B

After

Width:  |  Height:  |  Size: 253 B

Before

Width:  |  Height:  |  Size: 580 B

After

Width:  |  Height:  |  Size: 580 B

@@ -1,40 +1,37 @@
# PyTorch Operator Development Guide
- [Introduction](#introductionmd)
- [Operator Development Process](#operator-development-processmd)
- [Operator Development Preparations](#operator-development-preparationsmd)
- [Setting Up the Environment](#setting-up-the-environmentmd)
- [Looking Up Operators](#looking-up-operatorsmd)
- [Operator Adaptation](#operator-adaptationmd)
- [Prerequisites](#prerequisitesmd)
- [Obtaining the PyTorch Source Code](#obtaining-the-pytorch-source-codemd)
- [Registering an Operator](#registering-an-operatormd)
- [Overview](#overviewmd)
- [Registering an Operator for PyTorch 1.5.0](#registering-an-operator-for-pytorch-1-5-0md)
- [Registering an Operator for PyTorch 1.8.1](#registering-an-operator-for-pytorch-1-8-1md)
- [Developing an Operator Adaptation Plugin](#developing-an-operator-adaptation-pluginmd)
- [Compiling and Installing the PyTorch Framework](#compiling-and-installing-the-pytorch-frameworkmd)
- [Operator Function Verification](#operator-function-verificationmd)
- [Overview](#overview-0md)
- [Implementation](#implementationmd)
- [FAQs](#faqsmd)
- [Pillow==5.3.0 Installation Failed](#pillow-5-3-0-installation-failedmd)
- [pip3.7 install torchvision Installation Failed](#pip3-7-install-torchvision-installation-failedmd)
- ["torch 1.5.0xxxx" and "torchvision" Do Not Match When torch-\*.whl Is Installed](#torch-1-5-0xxxx-and-torchvision-do-not-match-when-torch--whl-is-installedmd)
- [How Do I View Test Run Logs?](#how-do-i-view-test-run-logsmd)
- [Why Cannot the Custom TBE Operator Be Called?](#why-cannot-the-custom-tbe-operator-be-calledmd)
- [How Do I Determine Whether the TBE Operator Is Correctly Called for PyTorch Adaptation?](#how-do-i-determine-whether-the-tbe-operator-is-correctly-called-for-pytorch-adaptationmd)
- [PyTorch Compilation Fails and the Message "error: ld returned 1 exit status" Is Displayed](#pytorch-compilation-fails-and-the-message-error-ld-returned-1-exit-status-is-displayedmd)
- [PyTorch Compilation Fails and the Message "error: call of overload...." Is Displayed](#pytorch-compilation-fails-and-the-message-error-call-of-overload-is-displayedmd)
- [Appendixes](#appendixesmd)
- [Installing CMake](#installing-cmakemd)
- [Exporting a Custom Operator](#exporting-a-custom-operatormd)
<h2 id="introductionmd">Introduction</h2>
- [Introduction](#introduction)
- [Operator Development Process](#operator-development-process)
- [Operator Development Preparations](#operator-development-preparations)
- [Setting Up the Environment](#setting-up-the-environment)
- [Looking Up Operators](#looking-up-operators)
- [Operator Adaptation](#operator-adaptation)
- [Prerequisites](#prerequisites)
- [Obtaining the PyTorch Source Code](#obtaining-the-pytorch-source-code)
- [Registering Operator Development](#registering-operator-development)
- [Developing an Operator Adaptation Plugin](#developing-an-operator-adaptation-plugin)
- [Compiling and Installing the PyTorch Framework](#compiling-and-installing-the-pytorch-framework)
- [Operator Function Verification](#operator-function-verification)
- [Overview](#overview)
- [Implementation](#implementation)
- [FAQs](#faqs)
- [Pillow==5.3.0 Installation Failed](#pillow-5-3-0-installation-failed)
- [pip3.7 install torchvision Installation Failed](#pip3-7-install-torchvision-installation-failed)
- ["torch 1.5.0xxxx" and "torchvision" Do Not Match When torch-\*.whl Is Installed](#torch-1-5-0xxxx-and-torchvision-do-not-match-when-torch--whl-is-installed)
- [What Is the Meaning Of The NPU Error Code Output During the Test? Is There Any Corresponding Explanation?](#what-is-the-meaning-of-the-npu-error-code-output-during-the-test-is-there-any-corresponding-explanat)
- [Why Cannot the Custom TBE Operator Be Called?](#why-cannot-the-custom-tbe-operator-be-called)
- [How Do I Determine Whether the TBE Operator Is Correctly Called for PyTorch Adaptation?](#how-do-i-determine-whether-the-tbe-operator-is-correctly-called-for-pytorch-adaptation)
- [PyTorch Compilation Fails and the Message "error: ld returned 1 exit status" Is Displayed](#pytorch-compilation-fails-and-the-message-error-ld-returned-1-exit-status-is-displayed)
- [PyTorch Compilation Fails and the Message "error: call of overload...." Is Displayed](#pytorch-compilation-fails-and-the-message-error-call-of-overload-is-displayed)
- [Appendixes](#appendixes)
- [Installing CMake](#installing-cmake)
- [Exporting a Custom Operator](#exporting-a-custom-operator)
<h2 id="introduction">Introduction</h2>
### Overview<a name="en-us_topic_0000001125558589_section7405182695312"></a>
## Overview<a name="en-us_topic_0000001125558589_section7405182695312"></a>
To enable the PyTorch deep learning framework to run on Ascend AI Processors, you need to use Tensor Boost Engine \(TBE\) to customize the framework operators.
<h2 id="operator-development-processmd">Operator Development Process</h2>
<h2 id="operator-development-process">Operator Development Process</h2>
PyTorch operator development includes TBE operator development and operator adaptation to the PyTorch framework.
@@ -69,7 +66,7 @@ PyTorch operator development includes TBE operator development and operator adap
</td>
<td class="cellrowborder" valign="top" width="55.55123090396029%" headers="mcps1.2.5.1.3 "><p id="en-us_topic_0000001105032530_p1381018121891"><a name="en-us_topic_0000001105032530_p1381018121891"></a><a name="en-us_topic_0000001105032530_p1381018121891"></a>Set up the development and operating environments required for operator development, execution, and verification.</p>
</td>
<td class="cellrowborder" rowspan="2" valign="top" width="19.772307093509777%" headers="mcps1.2.5.1.4 "><p id="en-us_topic_0000001105032530_p1498205181013"><a name="en-us_topic_0000001105032530_p1498205181013"></a><a name="en-us_topic_0000001105032530_p1498205181013"></a><a href="#operator-development-preparationsmd">Operator Development Preparations</a></p>
<td class="cellrowborder" rowspan="2" valign="top" width="19.772307093509777%" headers="mcps1.2.5.1.4 "><p id="en-us_topic_0000001105032530_p1498205181013"><a name="en-us_topic_0000001105032530_p1498205181013"></a><a name="en-us_topic_0000001105032530_p1498205181013"></a><a href="#operator-development-preparations">Operator Development Preparations</a></p>
</td>
</tr>
<tr id="en-us_topic_0000001105032530_row194671091290"><td class="cellrowborder" valign="top" headers="mcps1.2.5.1.1 "><p id="en-us_topic_0000001105032530_p3467169594"><a name="en-us_topic_0000001105032530_p3467169594"></a><a name="en-us_topic_0000001105032530_p3467169594"></a>2</p>
@@ -86,7 +83,7 @@ PyTorch operator development includes TBE operator development and operator adap
</td>
<td class="cellrowborder" valign="top" width="55.55123090396029%" headers="mcps1.2.5.1.3 "><p id="en-us_topic_0000001105032530_en-us_topic_0228422310_p381282212"><a name="en-us_topic_0000001105032530_en-us_topic_0228422310_p381282212"></a><a name="en-us_topic_0000001105032530_en-us_topic_0228422310_p381282212"></a>Obtain the PyTorch source code from the Ascend Community.</p>
</td>
<td class="cellrowborder" rowspan="4" valign="top" width="19.772307093509777%" headers="mcps1.2.5.1.4 "><p id="en-us_topic_0000001105032530_p10679152717175"><a name="en-us_topic_0000001105032530_p10679152717175"></a><a name="en-us_topic_0000001105032530_p10679152717175"></a><a href="#operator-development-preparationsmd">Operator Adaptation</a></p>
<td class="cellrowborder" rowspan="4" valign="top" width="19.772307093509777%" headers="mcps1.2.5.1.4 "><p id="en-us_topic_0000001105032530_p10679152717175"><a name="en-us_topic_0000001105032530_p10679152717175"></a><a name="en-us_topic_0000001105032530_p10679152717175"></a><a href="#operator-development-preparations">Operator Adaptation</a></p>
</td>
</tr>
<tr id="en-us_topic_0000001105032530_row1184984391512"><td class="cellrowborder" valign="top" headers="mcps1.2.5.1.1 "><p id="en-us_topic_0000001105032530_p1054075616153"><a name="en-us_topic_0000001105032530_p1054075616153"></a><a name="en-us_topic_0000001105032530_p1054075616153"></a>4</p>
@@ -116,43 +113,55 @@ PyTorch operator development includes TBE operator development and operator adap
</td>
<td class="cellrowborder" valign="top" width="55.55123090396029%" headers="mcps1.2.5.1.3 "><p id="en-us_topic_0000001105032530_en-us_topic_0228422310_p4952132615216"><a name="en-us_topic_0000001105032530_en-us_topic_0228422310_p4952132615216"></a><a name="en-us_topic_0000001105032530_en-us_topic_0228422310_p4952132615216"></a>Verify the operator functions in the real-world hardware environment.</p>
</td>
<td class="cellrowborder" valign="top" width="19.772307093509777%" headers="mcps1.2.5.1.4 "><p id="en-us_topic_0000001105032530_en-us_topic_0228422310_p20908934557"><a name="en-us_topic_0000001105032530_en-us_topic_0228422310_p20908934557"></a><a name="en-us_topic_0000001105032530_en-us_topic_0228422310_p20908934557"></a><a href="#operator-function-verificationmd">Operator Function Verification</a></p>
<td class="cellrowborder" valign="top" width="19.772307093509777%" headers="mcps1.2.5.1.4 "><p id="en-us_topic_0000001105032530_en-us_topic_0228422310_p20908934557"><a name="en-us_topic_0000001105032530_en-us_topic_0228422310_p20908934557"></a><a name="en-us_topic_0000001105032530_en-us_topic_0228422310_p20908934557"></a><a href="#operator-function-verification">Operator Function Verification</a></p>
</td>
</tr>
</tbody>
</table>
<h2 id="operator-development-preparationsmd">Operator Development Preparations</h2>
<h2 id="operator-development-preparations">Operator Development Preparations</h2>
- **[Setting Up the Environment](#setting-up-the-environmentmd)**
- **[Setting Up the Environment](#setting-up-the-environment)**
- **[Looking Up Operators](#looking-up-operatorsmd)**
- **[Looking Up Operators](#looking-up-operators)**
<h3 id="setting-up-the-environmentmd">Setting Up the Environment</h3>
<h2 id="setting-up-the-environment">Setting Up the Environment</h2>
## Prerequisites<a name="en-us_topic_0000001125736787_section12464163765320"></a>
- The development or operating environment of CANN has been installed. For details, see the _CANN Software Installation Guide_.
- Python 3.7.5 or 3.8 has been installed.
- CMake 3.12.0 or later has been installed. For details, see [Installing CMake](#installing-cmakemd).
- CMake 3.12.0 or later has been installed. For details, see [Installing CMake](#installing-cmake).
- GCC 7.3.0 or later has been installed. For details about how to install and use GCC 7.3.0, see "Installing GCC 7.3.0" in the _CANN Software Installation Guide_.
- The Git tool has been installed. To install Git for Ubuntu and CentOS, run the following commands:
- Ubuntu
```
apt-get install patch
apt-get install git
```
- CentOS
```
yum install patch
yum install git
```
<h3 id="looking-up-operatorsmd">Looking Up Operators</h3>
## Installing the PyTorch Environment Dependencies<a name="en-us_topic_0000001125736787_section18699192116550"></a>
If you install Python and its dependencies as a non-root user, add **--user** at the end of each command to ensure that the installation is successful. Example command: **pip3.7 install pyyaml --user**
```
pip3.7 install pyyaml
pip3.7 install wheel
pip3.7 install Pillow==5.3.0
```
>![](public_sys-resources/icon-note.gif) **NOTE:**
>If an error is reported in the preceding process, rectify the fault by referring to [FAQs](#faqs).
<h2 id="looking-up-operators">Looking Up Operators</h2>
During operator development, you can query the list of operators supported by Ascend AI Processors and the list of operators adapted to PyTorch. Develop or adapt operators to PyTorch based on the query result.
@@ -163,49 +172,49 @@ During operator development, you can query the list of operators supported by As
The following describes how to query the operators supported by Ascend AI Processors as well as operators adapted to PyTorch.
- You can query the operators supported by Ascend AI Processors and the corresponding operator constraints in either of the following modes:
- For operator development on the command line, you can perform offline query. For details, see the _CANN Operator List \(Ascend 910\)_.
- For operator development using MindStudio, you can perform online query on MindStudio. For details, see "Supported Operators and Models" in the _MindStudio User Guide_.
- For operator development on the command line, you can perform offline lookup. For details, see the _CANN Operator List \(Ascend 910\)_.
- For operator development using MindStudio, you can perform online lookup on MindStudio. For details, see "Supported Operators and Models" in the _MindStudio User Guide_.
- For the list of operators adapted to PyTorch, see the _PyTorch Operator Support_.
- For the list of operators adapted to PyTorch, see the _PyTorch Adapted Operator List_.
<h2 id="operator-adaptationmd">Operator Adaptation</h2>
<h2 id="operator-adaptation">Operator Adaptation</h2>
- **[Prerequisites](#prerequisitesmd)**
- **[Prerequisites](#prerequisites)**
- **[Obtaining the PyTorch Source Code](#obtaining-the-pytorch-source-codemd)**
- **[Obtaining the PyTorch Source Code](#obtaining-the-pytorch-source-code)**
- **[Registering an Operator](#registering-an-operatormd)**
- **[Registering Operator Development](#registering-operator-development)**
- **[Developing an Operator Adaptation Plugin](#developing-an-operator-adaptation-pluginmd)**
- **[Developing an Operator Adaptation Plugin](#developing-an-operator-adaptation-plugin)**
- **[Compiling and Installing the PyTorch Framework](#compiling-and-installing-the-pytorch-frameworkmd)**
- **[Compiling and Installing the PyTorch Framework](#compiling-and-installing-the-pytorch-framework)**
<h3 id="prerequisitesmd">Prerequisites</h3>
<h2 id="prerequisites">Prerequisites</h2>
- The development and operating environments have been set up, and related dependencies have been installed. For details, see [Setting Up the Environment](#setting-up-the-environmentmd).
- The development and operating environments have been set up, and related dependencies have been installed. For details, see [Setting Up the Environment](#setting-up-the-environment).
- TBE operators have been developed and deployed. For details, see the _CANN TBE Custom Operator Development Guide_.
<h3 id="obtaining-the-pytorch-source-codemd">Obtaining the PyTorch Source Code</h3>
<h2 id="obtaining-the-pytorch-source-code">Obtaining the PyTorch Source Code</h2>
Currently, only PyTorch 1.5.0 and 1.8.1 are supported. To obtain the PyTorch source code, perform steps described in the "Installing the PyTorch Framework" in the _PyTorch Installation Guide_. The full code adapted to Ascend AI Processors is generated in the **pytorch/pytorch** directory. The PyTorch operator is also adapted and developed in this directory.
Visit [https://gitee.com/ascend/pytorch-develop](https://gitee.com/ascend/pytorch-develop) to obtain the PyTorch source code that adapts to the Ascend AI Processor. Run the following **git** command to download the source code:
<h3 id="registering-an-operatormd">Registering an Operator</h3>
```
git clone https://gitee.com/ascend/pytorch-develop.git --deepth=1
```
- **[Overview](#overviewmd)**
After the download is successful, the PyTorch file directory is generated.
- **[Registering an Operator for PyTorch 1.5.0](#registering-an-operator-for-pytorch-1-5-0md)**
>![](public_sys-resources/icon-note.gif) **NOTE:**
>If you do not have the permission to obtain the code, contact Huawei technical support to join the **Ascend** organization.
- **[Registering an Operator for PyTorch 1.8.1](#registering-an-operator-for-pytorch-1-8-1md)**
<h2 id="registering-operator-development">Registering Operator Development</h2>
<h4 id="overviewmd">Overview</h4>
## Overview<a name="en-us_topic_0000001125315887_section693616257599"></a>
Currently, the NPU adaptation dispatch principle is as follows: The NPU operator is directly dispatched as the NPU adaptation function without being processed by the common function of the framework. That is, the operator execution call stack contains only the function call of the NPU adaptation and does not contain the common function of the framework. During compilation, the PyTorch framework generates the calling description of the middle layer of the new operator based on the definition in **native\_functions.yaml** and the type and device dispatch principle defined in the framework. For NPUs, the description is generated in **build/aten/src/ATen/NPUType.cpp**.
<h4 id="registering-an-operator-for-pytorch-1-5-0md">Registering an Operator for PyTorch 1.5.0</h4>
##### Registering an Operator<a name="section575212111125"></a>
## Registering an Operator<a name="en-us_topic_0000001125315887_section16610942811"></a>
1. Open the **native\_functions.yaml** file.
@@ -218,7 +227,7 @@ Currently, the NPU adaptation dispatch principle is as follows: The NPU operator
- Custom operator that does not exist in the YAML file
The YAML file does not contain the operator information. Therefore, you need to manually add related functions, including the function names, parameters, and return types. For details about how to add a rule, see **pytorch/aten/src/ATen/native/README.md**.
The YAML file does not contain the operator information. Therefore, you need to manually add related functions, including the function names, parameters, and return types.
```
- func: operator name (input parameter information) -> return type
@@ -249,7 +258,7 @@ Currently, the NPU adaptation dispatch principle is as follows: The NPU operator
>The formats are for reference only. The function name during operator adaptation must be the same as **NPU\_Adapt\_Fun\_Name**.
##### Examples<a name="section434031421219"></a>
## Example<a name="en-us_topic_0000001125315887_section3651235962"></a>
The following uses the torch.add\(\) operator as an example to describe how to register an operator.
@@ -271,7 +280,7 @@ The following uses the torch.add\(\) operator as an example to describe how to r
SparseCPU: add_sparse
SparseCUDA: add_sparse
MkldnnCPU: mkldnn_add
# Add the dispatch description.
#Add the dispatch description.
npu_dispatch:
NPU: add_npu
supports_named_tensor: True
@@ -284,7 +293,7 @@ The following uses the torch.add\(\) operator as an example to describe how to r
use_c10_dispatcher: full
variants: function, method
supports_named_tensor: True
# Add the dispatch description.
#Add the dispatch description.
npu_dispatch:
NPU: add_npu
```
@@ -300,7 +309,7 @@ The following uses the torch.add\(\) operator as an example to describe how to r
SparseCPU: add_sparse_
SparseCUDA: add_sparse_
MkldnnCPU: mkldnn_add_
# Add the dispatch description.
#Add the dispatch description.
npu_dispatch:
NPU: add_npu_
supports_named_tensor: True
@@ -312,7 +321,7 @@ The following uses the torch.add\(\) operator as an example to describe how to r
- func: add_.Scalar(Tensor(a!) self, Scalar other, Scalar alpha=1) -> Tensor(a!)
variants: method
supports_named_tensor: True
# Add the dispatch description.
#Add the dispatch description.
npu_dispatch:
NPU: add_npu_
```
@@ -327,7 +336,7 @@ The following uses the torch.add\(\) operator as an example to describe how to r
SparseCPU: add_out_sparse_cpu
SparseCUDA: add_out_sparse_cuda
MkldnnCPU: mkldnn_add_out
# Add the dispatch description.
#Add the dispatch description.
npu_dispatch:
NPU: add_out_npu
supports_named_tensor: True
@@ -335,101 +344,13 @@ The following uses the torch.add\(\) operator as an example to describe how to r
<h4 id="registering-an-operator-for-pytorch-1-8-1md">Registering an Operator for PyTorch 1.8.1</h4>
<h2 id="developing-an-operator-adaptation-plugin">Developing an Operator Adaptation Plugin</h2>
##### Registering an Operator<a name="section575212111125"></a>
1. Open the **native\_functions.yaml** file.
The **native\_functions.yaml** file defines all operator function prototypes, including function names and parameters. Each operator function supports dispatch information of different hardware platforms. The file is in the **pytorch/aten/src/ATen/native/native\_functions.yaml** directory.
2. Determine the functions to be dispatched.
- Existing operator in the YAML file
Dispatch all functions related to the operator to be adapted.
- Custom operator that does not exist in the YAML file
The YAML file does not contain the operator information. Therefore, you need to manually add related functions, including the function names, parameters, and return types. For details about how to add a rule, see **pytorch/aten/src/ATen/native/README.md**.
```
- func: operator name (input parameter information) -> return type
```
##### Examples<a name="section434031421219"></a>
The following uses the torch.add\(\) operator as an example to describe how to register an operator.
1. Open the **native\_functions.yaml** file.
2. Search for related functions.
Search for **add** in the YAML file and find **func** that describes the add operator. The add operator is a built-in operator of PyTorch. Therefore, you do not need to manually add **func**. If the operator is a custom operator, you need to manually add **func**.
3. Determine the function description related to operator name and type.
- Dispatch description of **add.Tensor**
```
- func: add.Tensor(Tensor self, Tensor other, *, Scalar alpha=1) -> Tensor
structured_delegate: add.out
variants: function, method
dispatch:
SparseCPU, SparseCUDA: add_sparse
MkldnnCPU: mkldnn_add
```
- Dispatch description of **add.Scalar**
```
- func: add.Scalar(Tensor self, Scalar other, Scalar alpha=1) -> Tensor
variants: function, method
dispatch:
DefaultBackend: add
```
- Dispatch description of **add\_.Tensor**
```
- func: add_.Tensor(Tensor(a!) self, Tensor other, *, Scalar alpha=1) -> Tensor(a!)
variants: method
structured_delegate: add.out
dispatch:
SparseCPU, SparseCUDA: add_sparse_
MkldnnCPU: mkldnn_add_
```
- Dispatch description of **add\_.Scalar**
```
- func: add_.Scalar(Tensor(a!) self, Scalar other, Scalar alpha=1) -> Tensor(a!)
variants: method
dispatch:
DefaultBackend: add_
```
- Dispatch description of **add.out**
```
- func: add.out(Tensor self, Tensor other, *, Scalar alpha=1, Tensor(a!) out) -> Tensor(a!)
structured: True
structured_inherits: TensorIteratorBase
dispatch:
CPU, CUDA: add_out
SparseCPU: add_out_sparse_cpu
SparseCUDA: add_out_sparse_cuda
MkldnnCPU: mkldnn_add_out
```
<h3 id="developing-an-operator-adaptation-pluginmd">Developing an Operator Adaptation Plugin</h3>
#### Overview<a name="en-us_topic_0000001125315877_section16410139174517"></a>
## Overview<a name="en-us_topic_0000001125315877_section16410139174517"></a>
You can develop an operator adaptation plugin to convert the formats of the input parameters, output parameters, and attributes of the PyTorch native operators so that the obtained formats are the same as the formats of the input parameters, output parameters, and attributes of the TBE operators. The PyTorch source code that is adapted to Ascend AI Processors provides methods related to adaptation association, type conversion and discrimination, and dynamic shape processing for users.
#### Adaptation Plugin Implementation<a name="en-us_topic_0000001125315877_section1174074518456"></a>
## Adaptation Plugin Implementation<a name="en-us_topic_0000001125315877_section1174074518456"></a>
1. Create an adaptation plugin file.
@@ -450,23 +371,8 @@ You can develop an operator adaptation plugin to convert the formats of the inpu
Implement the operator adaptation theme function and construct the corresponding input, output, and attributes based on the TBE operator prototype.
5. Use the **TORCH\_LIBRARY\_IMPL** macro to associate the operator description func in the **native\_functions.yaml** file generated during the operator registration. \(Only PyTorch 1.8.1 requires this step.\)
**TORCH\_LIBRARY\_IMPL** is a macro provided by PyTorch for registered operator distribution. To use it, perform the following steps:
```
Torch_LIBRARY_IMPL(aten, PrivateUse1, m){
m.impl("Operator func name in YAML 1", TORCH_FN("Corresponding main adaptation function 1"))
m.impl("Operator func name in YAML 2", TORCH_FN("Corresponding main adaptation function 2"))
}
```
- **aten** is the namespace, which can be customized based on the namespace of the implementation file.
- **PrivateUse1** is **dispatchKey**, which is used to set the NPU.
- **m** is a fixed field.
#### Example<a name="en-us_topic_0000001125315877_section18021337113012"></a>
## Example<a name="en-us_topic_0000001125315877_section18021337113012"></a>
The following uses the torch.add\(\) operator as an example to describe how to adapt an operator.
@@ -618,85 +524,79 @@ The following uses the torch.add\(\) operator as an example to describe how to a
}
```
5. Use the **TORCH\_LIBRARY\_IMPL** macro to associate the registered operator. \(Only PyTorch 1.8.1 requires this step.\)
```
TORCH_LIBRARY_IMPL(aten, NPU, m) {
m.impl("add.Tensor", TORCH_FN(add_npu));
m.impl("add_.Tensor", TORCH_FN(add_npu_));
m.impl("add.out", TORCH_FN(add_out_npu));}
```
>![](public_sys-resources/icon-note.gif) **NOTE:**
>For details about the implementation code of **AddKernelNpu.cpp**, see the **pytorch/aten/src/ATen/native/npu/AddKernelNpu.cpp** document.
<h3 id="compiling-and-installing-the-pytorch-frameworkmd">Compiling and Installing the PyTorch Framework</h3>
<h2 id="compiling-and-installing-the-pytorch-framework">Compiling and Installing the PyTorch Framework</h2>
#### Compiling the PyTorch Framework<a name="en-us_topic_0000001125736777_section470105143317"></a>
## Compiling the PyTorch Framework<a name="en-us_topic_0000001125736777_section470105143317"></a>
1. Go to the PyTorch working directory **pytorch/pytorch**.
2. Install the dependency.
1. Go to the PyTorch working directory **pytorch**.
2. Set permission for the script file.
**chmod +x build.sh**
3. Run the following command to perform compilation:
**./build.sh**
>![](public_sys-resources/icon-note.gif) **NOTE:**
>The first compilation takes a long time, which may exceed 30 minutes. You are advised not to run the **make clean** command unless necessary.
4. After the compilation is successful, the **torch-**_\*_**.whl** package is generated in **pytorch/dist**, for example, **torch-1.5.0a0-cp37-cp37m-linux\_x86.whl**.
## Installing the PyTorch Framework<a name="en-us_topic_0000001125736777_section119821419153412"></a>
1. Upload the **torch-**_\*_**.whl** package generated in [Compiling and Installing the PyTorch Framework](#compiling-and-installing-the-pytorch-framework) to any path on the server.
2. Go to the directory where **torch-**_\*_**.whl** is located and run the **pip** command to install PyTorch.
If the current user is the **root** user, run the following command:
```
pip3 install -r requirements.txt
pip3.7 install torch-*.whl
```
3. Compile and generate the binary installation package of PyTorch.
If the current user is a non-root user, run the following command:
```
bash build.sh --python=3.7
or
bash build.sh --python=3.8
pip3.7 install torch-*.whl --user
```
Specify the Python version in the environment for compilation. After the compilation is successful, the binary package **torch-\*.whl** is generated in the **pytorch/pytorch/dist** directory, for example, **torch-1.5.0+ascend.post3-cp37-cp37m-linux\_x86.whl** or **torch-1.8.1+ascend-cp37-cp37m-linux\_x86.whl**.
#### Installing the PyTorch Framework<a name="en-us_topic_0000001125736777_section119821419153412"></a>
Go to the **pytorch/pytorch/dist** directory and run the following command to install PyTorch:
```
pip3 install --upgrade torch-1.5.0+ascend.post3-cp37-cp37m-linux_{arch}.whl
```
_**\{arch\}**_ indicates the architecture information. The value can be **aarch64** or **x86\_64**.
>![](public_sys-resources/icon-note.gif) **NOTE:**
>If PyTorch has been installed in the environment, uninstall the PyTorch software package first. You can run the following command to check whether PyTorch has been installed in the environment:
>**pip3 list | grep torch**
>- After the code has been modified, you need to re-compile and re-install PyTorch.
>- During the installation, the system may display a message indicating that the TorchVision 0.6.0 version does not match PyTorch. This problem has no impact and can be ignored.
After the code has been modified, you need to re-compile and re-install PyTorch.
<h2 id="operator-function-verification">Operator Function Verification</h2>
<h2 id="operator-function-verificationmd">Operator Function Verification</h2>
- **[Overview](#overview)**
- **[Overview](#overview-0md)**
- **[Implementation](#implementationmd)**
- **[Implementation](#implementation)**
<h3 id="overview-0md">Overview</h3>
<h2 id="overview">Overview</h2>
#### Introduction<a name="en-us_topic_0000001117556616_section29881459155718"></a>
## Introduction<a name="en-us_topic_0000001117556616_section29881459155718"></a>
After operator adaptation is complete, you can run the PyTorch operator adapted to Ascend AI Processor to verify the operator running result.
Operator verification involves all deliverables generated during operator development, including the implementation files, operator prototype definitions, operator information library, and operator plugins. This section describes only the verification method.
#### Test Cases and Records<a name="en-us_topic_0000001117556616_section158972351160"></a>
## Test Cases and Records<a name="en-us_topic_0000001117556616_section158972351160"></a>
Use the PyTorch frontend to construct the custom operator function and run the function to verify the custom operator functions.
The test cases and test tools are provided in the **pytorch/test/test\_npu** directory at **https://gitee.com/ascend/pytorch**.
The test cases and test tools are provided in the **pytorch/test/test\_npu/test\_network\_ops** directory at **https://gitee.com/ascend/pytorch-develop**.
<h3 id="implementationmd">Implementation</h3>
<h2 id="implementation">Implementation</h2>
#### Introduction<a name="en-us_topic_0000001164276377_section29881459155718"></a>
## Introduction<a name="en-us_topic_0000001164276377_section29881459155718"></a>
This section describes how to test the functions of a PyTorch operator.
#### Procedure<a name="en-us_topic_0000001164276377_section02504494109"></a>
## Procedure<a name="en-us_topic_0000001164276377_section02504494109"></a>
1. Set environment variables.
@@ -705,6 +605,8 @@ This section describes how to test the functions of a PyTorch operator.
. /home/HwHiAiUser/Ascend/ascend-toolkit/set_env.sh
```
Replace **_install\_path_** with the actual Toolkit installation path.
2. Compile test scripts. Take the add operator as an example. Compile the test script file **test\_add.py** in the **pytorch/test/test\_npu/test\_network\_ops** directory.
The following is only a simple example. The implementation of a test case must be completely covered based on the operator definition to ensure that the function is basically correct.
@@ -733,7 +635,7 @@ This section describes how to test the functions of a PyTorch operator.
output = output.numpy()
return output
# Define a general function for the add scenario. This function is used to input data and compare the compute results of the CPU and NPU.
# Define a general function for the add scenario. This function is used to compare the input data of the scenario and the return results of the CPU and NPU.
def add_result(self, shape_format):
for item in shape_format:
cpu_input1, npu_input1 = create_common_tensor(item, 0, 100)
@@ -756,7 +658,10 @@ This section describes how to test the functions of a PyTorch operator.
instantiate_device_type_tests(TestAdd, globals(), except_for="cpu")
if __name__ == "__main__":
torch.npu.set_device("npu:0")
run_tests()
```
3. Execute the test case script.
@@ -768,36 +673,36 @@ This section describes how to test the functions of a PyTorch operator.
```
<h2 id="faqsmd">FAQs</h2>
<h2 id="faqs">FAQs</h2>
- **[Pillow==5.3.0 Installation Failed](#pillow-5-3-0-installation-failedmd)**
- **[Pillow==5.3.0 Installation Failed](#pillow-5-3-0-installation-failed)**
- **[pip3.7 install torchvision Installation Failed](#pip3-7-install-torchvision-installation-failedmd)**
- **[pip3.7 install torchvision Installation Failed](#pip3-7-install-torchvision-installation-failed)**
- **["torch 1.5.0xxxx" and "torchvision" Do Not Match When torch-\*.whl Is Installed](#torch-1-5-0xxxx-and-torchvision-do-not-match-when-torch--whl-is-installedmd)**
- **["torch 1.5.0xxxx" and "torchvision" Do Not Match When torch-\*.whl Is Installed](#torch-1-5-0xxxx-and-torchvision-do-not-match-when-torch--whl-is-installed)**
- **[How Do I View Test Run Logs?](#how-do-i-view-test-run-logsmd)**
- **[What Is the Meaning Of The NPU Error Code Output During the Test? Is There Any Corresponding Explanation?](#what-is-the-meaning-of-the-npu-error-code-output-during-the-test-is-there-any-corresponding-explanat)**
- **[Why Cannot the Custom TBE Operator Be Called?](#why-cannot-the-custom-tbe-operator-be-calledmd)**
- **[Why Cannot the Custom TBE Operator Be Called?](#why-cannot-the-custom-tbe-operator-be-called)**
- **[How Do I Determine Whether the TBE Operator Is Correctly Called for PyTorch Adaptation?](#how-do-i-determine-whether-the-tbe-operator-is-correctly-called-for-pytorch-adaptationmd)**
- **[How Do I Determine Whether the TBE Operator Is Correctly Called for PyTorch Adaptation?](#how-do-i-determine-whether-the-tbe-operator-is-correctly-called-for-pytorch-adaptation)**
- **[PyTorch Compilation Fails and the Message "error: ld returned 1 exit status" Is Displayed](#pytorch-compilation-fails-and-the-message-error-ld-returned-1-exit-status-is-displayedmd)**
- **[PyTorch Compilation Fails and the Message "error: ld returned 1 exit status" Is Displayed](#pytorch-compilation-fails-and-the-message-error-ld-returned-1-exit-status-is-displayed)**
- **[PyTorch Compilation Fails and the Message "error: call of overload...." Is Displayed](#pytorch-compilation-fails-and-the-message-error-call-of-overload-is-displayedmd)**
- **[PyTorch Compilation Fails and the Message "error: call of overload...." Is Displayed](#pytorch-compilation-fails-and-the-message-error-call-of-overload-is-displayed)**
<h3 id="pillow-5-3-0-installation-failedmd">Pillow==5.3.0 Installation Failed</h3>
<h2 id="pillow-5-3-0-installation-failed">Pillow==5.3.0 Installation Failed</h2>
#### Symptom<a name="en-us_topic_0000001125315879_en-us_topic_0175549220_section197270431505"></a>
## Symptom<a name="en-us_topic_0000001125315879_en-us_topic_0175549220_section197270431505"></a>
**Pillow==5.3.0** installation failed.
#### Possible Cause<a name="en-us_topic_0000001125315879_en-us_topic_0175549220_section169499490501"></a>
## Possible Cause<a name="en-us_topic_0000001125315879_en-us_topic_0175549220_section169499490501"></a>
Necessary dependencies are missing, such as libjpeg, python-devel, zlib-devel, and libjpeg-turbo-devel.
#### Solutions<a name="en-us_topic_0000001125315879_section108142031907"></a>
## Solutions<a name="en-us_topic_0000001125315879_section108142031907"></a>
Run the following command to install the required dependencies:
@@ -805,17 +710,17 @@ Run the following command to install the required dependencies:
apt-get install libjpeg python-devel zlib-devel libjpeg-turbo-devel
```
<h3 id="pip3-7-install-torchvision-installation-failedmd">pip3.7 install torchvision Installation Failed</h3>
<h2 id="pip3-7-install-torchvision-installation-failed">pip3.7 install torchvision Installation Failed</h2>
#### Symptom<a name="en-us_topic_0000001125641109_en-us_topic_0175549220_section197270431505"></a>
## Symptom<a name="en-us_topic_0000001125641109_en-us_topic_0175549220_section197270431505"></a>
**pip3.7 install torchvision** installation failed.
#### Possible Cause<a name="en-us_topic_0000001125641109_en-us_topic_0175549220_section169499490501"></a>
## Possible Cause<a name="en-us_topic_0000001125641109_en-us_topic_0175549220_section169499490501"></a>
The versions of PyTorch and TorchVision do not match.
#### Solutions<a name="en-us_topic_0000001125641109_section108142031907"></a>
## Solutions<a name="en-us_topic_0000001125641109_section108142031907"></a>
Run the following command:
@@ -823,60 +728,43 @@ Run the following command:
pip3.7 install torchvision --no-deps
```
<h3 id="torch-1-5-0xxxx-and-torchvision-do-not-match-when-torch--whl-is-installedmd">"torch 1.5.0xxxx" and "torchvision" Do Not Match When torch-\*.whl Is Installed</h3>
<h2 id="torch-1-5-0xxxx-and-torchvision-do-not-match-when-torch--whl-is-installed">"torch 1.5.0xxxx" and "torchvision" Do Not Match When torch-\*.whl Is Installed</h2>
#### Symptom<a name="en-us_topic_0000001125315883_en-us_topic_0175549220_section197270431505"></a>
## Symptom<a name="en-us_topic_0000001125315883_en-us_topic_0175549220_section197270431505"></a>
During the installation of **torch-**_\*_**.whl**, the message "ERROR: torchvision 0.6.0 has requirement torch==1.5.0, but you'll have torch 1.5.0a0+1977093 which is incompatible" " is displayed.
![](figures/en-us_image_0000001144082048.png)
![](figures/en-us_image_0000001172886189.png)
However, the installation is successful.
#### Possible Cause<a name="en-us_topic_0000001125315883_en-us_topic_0175549220_section169499490501"></a>
## Possible Cause<a name="en-us_topic_0000001125315883_en-us_topic_0175549220_section169499490501"></a>
When the PyTorch is installed, the version check is automatically triggered. The version of the torchvision installed in the environment is 0.6.0. During the check, it is found that the version of the **torch-**_\*_**.whl** is inconsistent with the required version 1.5.0. As a result, an error message is displayed.
#### Solutions<a name="en-us_topic_0000001125315883_section108142031907"></a>
## Solutions<a name="en-us_topic_0000001125315883_section108142031907"></a>
This problem has no impact on the actual result, and no action is required.
<h3 id="how-do-i-view-test-run-logsmd">How Do I View Test Run Logs?</h3>
<h2 id="what-is-the-meaning-of-the-npu-error-code-output-during-the-test-is-there-any-corresponding-explanat">What Is the Meaning Of The NPU Error Code Output During the Test? Is There Any Corresponding Explanation?</h2>
When an error message is displayed during the test, but the reference information is insufficient, how can we view more detailed run logs?
For details, see [aclError](https://support.huaweicloud.com/intl/en-us/adevg-A800_3000_3010/atlasdevelopment_01_0256.html).
Output the logs to the screen and redirect them to a specified text file.
<h2 id="why-cannot-the-custom-tbe-operator-be-called">Why Cannot the Custom TBE Operator Be Called?</h2>
1. Set the environment variable to display the logs of the current user on the screen.
```
export SLOG_PRINT_TO_STDOUT=1
```
After the setting is complete, run the test case to output related logs to the screen. To facilitate viewing and backtracking, you are advised to perform [2](#en-us_topic_0000001125315889_li168732325719) as required.
2. <a name="en-us_topic_0000001125315889_li168732325719"></a>Redirect the logs to a specified file when a test case is executed.
```
python3.7 test_add.py > test_log.txt
```
<h3 id="why-cannot-the-custom-tbe-operator-be-calledmd">Why Cannot the Custom TBE Operator Be Called?</h3>
#### Symptom<a name="en-us_topic_0000001125736795_en-us_topic_0175549220_section197270431505"></a>
## Symptom<a name="en-us_topic_0000001125736795_en-us_topic_0175549220_section197270431505"></a>
The custom TBE operator has been developed and adapted to PyTorch. However, the newly developed operator cannot be called during test case execution.
#### Possible Cause<a name="en-us_topic_0000001125736795_en-us_topic_0175549220_section169499490501"></a>
## Possible Cause<a name="en-us_topic_0000001125736795_en-us_topic_0175549220_section169499490501"></a>
- The environment variables are not set correctly.
- An error occurs in the YAML file. As a result, the operator is not correctly dispatched.
- The implementation of the custom TBE operator is incorrect. As a result, the operator cannot be called.
#### Solutions<a name="en-us_topic_0000001125736795_section108142031907"></a>
## Solutions<a name="en-us_topic_0000001125736795_section108142031907"></a>
1. Set the operating environment by referring to [Verifying Operator Functions](#operator-function-verificationmd). Pay special attention to the following settings:
1. Set the operating environment by referring to [Verifying Operator Functions](#operator-function-verification). Pay special attention to the following settings:
```
. /home/HwHiAiUser/Ascend/ascend-toolkit/set_env.sh
@@ -888,7 +776,7 @@ The custom TBE operator has been developed and adapted to PyTorch. However, the
"pytorch/aten/src/ATen/native/npu/AddKernelNpu.cpp"
![](figures/en-us_image_0000001144082088.png)
![](figures/en-us_image_0000001126846510.png)
2. After the compilation and installation steps are complete, call **python3.7 test\_add.py** to perform the test.
@@ -916,7 +804,7 @@ The custom TBE operator has been developed and adapted to PyTorch. However, the
<h3 id="how-do-i-determine-whether-the-tbe-operator-is-correctly-called-for-pytorch-adaptationmd">How Do I Determine Whether the TBE Operator Is Correctly Called for PyTorch Adaptation?</h3>
<h2 id="how-do-i-determine-whether-the-tbe-operator-is-correctly-called-for-pytorch-adaptation">How Do I Determine Whether the TBE Operator Is Correctly Called for PyTorch Adaptation?</h2>
Both the custom and built-in operators are stored in the installation directory as .py source code after installation. Therefore, you can edit the source code and add logs at the API entry to print the input parameters, and determine whether the input parameters are correct.
@@ -934,7 +822,7 @@ The following uses the **zn\_2\_nchw** operator in the built-in operator packa
The .py source code file of the corresponding operator is read-only, that is, the file cannot be edited.
![](figures/en-us_image_0000001190081791.png)
![](figures/en-us_image_0000001127006336.png)
2. Modify the attributes of the .py source code file of the operator and add the write permission.
@@ -943,7 +831,7 @@ The following uses the **zn\_2\_nchw** operator in the built-in operator packa
ll
```
![](figures/en-us_image_0000001190081803.png)
![](figures/en-us_image_0000001172886191.png)
3. Open the .py source code file of the operator, add logs, save the file, and exit.
@@ -951,7 +839,7 @@ The following uses the **zn\_2\_nchw** operator in the built-in operator packa
vi zn_2_nchw.py
```
![](figures/en-us_image_0000001190201951.png)
![](figures/en-us_image_0000001173046109.png)
In the preceding example, only an identifier is added. In actual commissioning, you can add the input parameters to be printed.
@@ -963,61 +851,61 @@ The following uses the **zn\_2\_nchw** operator in the built-in operator packa
sudo chmod -w zn_2_nchw.py
```
![](figures/en-us_image_0000001144082072.png)
![](figures/en-us_image_0000001126846512.png)
<h3 id="pytorch-compilation-fails-and-the-message-error-ld-returned-1-exit-status-is-displayedmd">PyTorch Compilation Fails and the Message "error: ld returned 1 exit status" Is Displayed</h3>
<h2 id="pytorch-compilation-fails-and-the-message-error-ld-returned-1-exit-status-is-displayed">PyTorch Compilation Fails and the Message "error: ld returned 1 exit status" Is Displayed</h2>
#### Symptom<a name="en-us_topic_0000001125315885_en-us_topic_0175549220_section197270431505"></a>
## Symptom<a name="en-us_topic_0000001125315885_en-us_topic_0175549220_section197270431505"></a>
PyTorch compilation fails and the message "error: ld returned 1 exit status" is displayed.
![](figures/en-us_image_0000001190201973.png)
![](figures/en-us_image_0000001127006338.png)
#### Possible Cause<a name="en-us_topic_0000001125315885_en-us_topic_0175549220_section169499490501"></a>
## Possible Cause<a name="en-us_topic_0000001125315885_en-us_topic_0175549220_section169499490501"></a>
According to the log analysis, the possible cause is that the adaptation function implemented in _xxxx_**KernelNpu.cpp** does not match the dispatch implementation API parameters required by the PyTorch framework operator. In the preceding example, the function is **binary\_cross\_entropy\_npu**. Open the corresponding _xxxx_**KernelNpu.cpp** file and find the adaptation function.
![](figures/en-us_image_0000001144241896.png)
![](figures/en-us_image_0000001172886193.png)
In the implementation, the type of the last parameter is **int**, which does not match the required **long**.
#### Solutions<a name="en-us_topic_0000001125315885_section108142031907"></a>
## Solutions<a name="en-us_topic_0000001125315885_section108142031907"></a>
Modify the adaptation function implemented in _xxxx_**KernelNpu.cpp**. In the preceding example, change the type of the last parameter in the **binary\_cross\_entropy\_npu** function to **int64\_t** \(use **int64\_t** instead of **long** in the .cpp file\).
<h3 id="pytorch-compilation-fails-and-the-message-error-call-of-overload-is-displayedmd">PyTorch Compilation Fails and the Message "error: call of overload...." Is Displayed</h3>
<h2 id="pytorch-compilation-fails-and-the-message-error-call-of-overload-is-displayed">PyTorch Compilation Fails and the Message "error: call of overload...." Is Displayed</h2>
#### Symptom<a name="en-us_topic_0000001125641113_en-us_topic_0175549220_section197270431505"></a>
## Symptom<a name="en-us_topic_0000001125641113_en-us_topic_0175549220_section197270431505"></a>
PyTorch compilation fails and the message "error: call of overload...." is displayed.
![](figures/en-us_image_0000001144082056.png)
![](figures/en-us_image_0000001173046111.png)
![](figures/en-us_image_0000001190201935.png)
![](figures/en-us_image_0000001126846514.png)
#### Possible Cause<a name="en-us_topic_0000001125641113_en-us_topic_0175549220_section169499490501"></a>
## Possible Cause<a name="en-us_topic_0000001125641113_en-us_topic_0175549220_section169499490501"></a>
According to the log analysis, the error is located in line 30 in the _xxxx_**KernelNpu.cpp** file, indicating that the **NPUAttrDesc** parameter is invalid. In the preceding example, the function is **binary\_cross\_entropy\_attr**. Open the corresponding _xxxx_**KernelNpu.cpp** file and find the adaptation function.
![](figures/en-us_image_0000001144082064.png)
![](figures/en-us_image_0000001127006340.png)
In the implementation, the type of the second input parameter of **NPUAttrDesc** is **int**, which does not match the definition of **NPUAttrDesc**.
#### Solutions<a name="en-us_topic_0000001125641113_section108142031907"></a>
## Solutions<a name="en-us_topic_0000001125641113_section108142031907"></a>
1. Replace the incorrect code line in the **binary\_cross\_entropy\_attr\(\)** function with the code in the preceding comment.
2. Change the input parameter type of **binary\_cross\_entropy\_attr\(\)** to **int64\_t**.
<h2 id="appendixesmd">Appendixes</h2>
<h2 id="appendixes">Appendixes</h2>
- **[Installing CMake](#installing-cmakemd)**
- **[Installing CMake](#installing-cmake)**
- **[Exporting a Custom Operator](#exporting-a-custom-operatormd)**
- **[Exporting a Custom Operator](#exporting-a-custom-operator)**
<h3 id="installing-cmakemd">Installing CMake</h3>
<h2 id="installing-cmake">Installing CMake</h2>
The following describes how to upgrade CMake to 3.12.1.
@@ -1056,17 +944,17 @@ The following describes how to upgrade CMake to 3.12.1.
If the message "cmake version 3.12.1" is displayed, the installation is successful.
<h3 id="exporting-a-custom-operatormd">Exporting a Custom Operator</h3>
<h2 id="exporting-a-custom-operator">Exporting a Custom Operator</h2>
#### Overview<a name="en-us_topic_0000001136292799_section13121145561615"></a>
## Overview<a name="en-us_topic_0000001136292799_section13121145561615"></a>
A PyTorch model contains a custom operator. You can export the custom operator as an ONNX single-operator model, which can be easily ported to other AI frameworks. Three types of custom operator export are available: NPU-adapted TBE operator export, C++ operator export, and pure Python operator export.
#### Prerequisites<a name="en-us_topic_0000001136292799_section6744175713010"></a>
## Prerequisites<a name="en-us_topic_0000001136292799_section6744175713010"></a>
You have installed the PyTorch framework.
#### TBE Operator Export<a name="en-us_topic_0000001136292799_section17568113818325"></a>
## TBE Operator Export<a name="en-us_topic_0000001136292799_section17568113818325"></a>
A TBE operator can be exported using either of the following methods:
@@ -1221,7 +1109,7 @@ Method 2:
>![](public_sys-resources/icon-note.gif) **NOTE:**
>For details about the implementation code, see [test\_custom\_ops\_npu\_demo.py](https://gitee.com/ascend/pytorch/blob/master/test/test_npu/test_onnx/torch.onnx/custom_ops_demo/test_custom_ops_npu_demo.py). If you do not have the permission to obtain the code, contact Huawei technical support to join the **Ascend** organization.
#### C++ Operator Export<a name="en-us_topic_0000001136292799_section1465619203319"></a>
## C++ Operator Export<a name="en-us_topic_0000001136292799_section1465619203319"></a>
1. Customize an operator.
@@ -1287,7 +1175,7 @@ Method 2:
>![](public_sys-resources/icon-note.gif) **NOTE:**
>For details about the implementation code, see [test\_custom\_ops\_demo.py](https://gitee.com/ascend/pytorch/blob/master/test/test_npu/test_onnx/torch.onnx/custom_ops_demo/test_custom_ops_demo.py). If you do not have the permission to obtain the code, contact Huawei technical support to join the **Ascend** organization.
#### Pure Python Operator Export<a name="en-us_topic_0000001136292799_section98044317326"></a>
## Pure Python Operator Export<a name="en-us_topic_0000001136292799_section98044317326"></a>
1. Customize an operator.
File diff suppressed because it is too large Load Diff
+20 -292
View File
@@ -1,287 +1,15 @@
# FrameworkPTAdapter 2.0.3 Release Notes
- [FrameworkPTAdapter 2.0.3](#frameworkptadapter-2-0-3md)
- [Before You Start](#before-you-startmd)
- [New Features](#new-featuresmd)
- [Modified Features](#modified-featuresmd)
- [Resolved Issues](#resolved-issuesmd)
- [Known Issues](#known-issuesmd)
- [Compatibility](#compatibilitymd)
- [FrameworkPTAdapter 2.0.2](#frameworkptadapter-2-0-2md)
- [Before You Start](#before-you-start-0md)
- [New Features](#new-features-1md)
- [Modified Features](#modified-features-2md)
- [Resolved Issues](#resolved-issues-3md)
- [Known Issues](#known-issues-4md)
- [Compatibility](#compatibility-5md)
<h2 id="frameworkptadapter-2-0-3md">FrameworkPTAdapter 2.0.3</h2>
- **[Before You Start](#before-you-startmd)**
- **[New Features](#new-featuresmd)**
- **[Modified Features](#modified-featuresmd)**
- **[Resolved Issues](#resolved-issuesmd)**
- **[Known Issues](#known-issuesmd)**
- **[Compatibility](#compatibilitymd)**
<h3 id="before-you-startmd">Before You Start</h3>
This framework is modified based on the open-source PyTorch 1.5.0 developed by Facebook, inherits native PyTorch features, and uses NPUs for dynamic image training. Models are adapted by operator granularity, code can be reused, and current networks can be ported and used on NPUs with only device types or data types modified.
PyTorch 1.8.1 is supported by this version and later, and this version inherits the features of PyTorch 1.5.0 and provides the same functions, except for the profiling tool. In addition, it optimizes the backend operator adaptation. Currently, PyTorch 1.8.1 supports only the ResNet-50 network model.
<h3 id="new-featuresmd">New Features</h3>
**Table 1** Features supported by PyTorch
<a name="t76c34275cbb74753970f7c5a9eb594fa"></a>
<table><thead align="left"><tr id="r0c10e7163bf54fe8816ab5ca2d77ccc4"><th class="cellrowborder" valign="top" width="10.459999999999999%" id="mcps1.2.4.1.1"><p id="a7888762cf8294977b7d114b1c898d1bd"><a name="a7888762cf8294977b7d114b1c898d1bd"></a><a name="a7888762cf8294977b7d114b1c898d1bd"></a>Level-1 Feature</p>
</th>
<th class="cellrowborder" valign="top" width="26.27%" id="mcps1.2.4.1.2"><p id="a4581ffde4a5f455faadfba144243a9d4"><a name="a4581ffde4a5f455faadfba144243a9d4"></a><a name="a4581ffde4a5f455faadfba144243a9d4"></a>Level-2 Feature</p>
</th>
<th class="cellrowborder" valign="top" width="63.27%" id="mcps1.2.4.1.3"><p id="a2a1562364b09433a83133fa10b3cf2b3"><a name="a2a1562364b09433a83133fa10b3cf2b3"></a><a name="a2a1562364b09433a83133fa10b3cf2b3"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row7979351559"><td class="cellrowborder" rowspan="5" valign="top" width="10.459999999999999%" headers="mcps1.2.4.1.1 "><p id="p69836331553"><a name="p69836331553"></a><a name="p69836331553"></a>PyTorch features adapted to NPUs</p>
</td>
<td class="cellrowborder" valign="top" width="26.27%" headers="mcps1.2.4.1.2 "><p id="p149831333357"><a name="p149831333357"></a><a name="p149831333357"></a>PyTorch 1.8.1</p>
</td>
<td class="cellrowborder" valign="top" width="63.27%" headers="mcps1.2.4.1.3 "><p id="p1398313336511"><a name="p1398313336511"></a><a name="p1398313336511"></a>Added PyTorch 1.8.1. Currently, only the ResNet-50 network is supported, including the training scenario for distributed data parallel (DDP).</p>
</td>
</tr>
<tr id="row109719353511"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p18983183315515"><a name="p18983183315515"></a><a name="p18983183315515"></a>Python 3.8</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p836221112812"><a name="p836221112812"></a><a name="p836221112812"></a>Supported compilation and use of Python 3.8.</p>
</td>
</tr>
<tr id="row13971435754"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p79831331353"><a name="p79831331353"></a><a name="p79831331353"></a>Operator overflow/underflow detection tool</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p109832331055"><a name="p109832331055"></a><a name="p109832331055"></a>Supported IR-level operator overflow/underflow detection in the PyTorch framework. When AI Core operator overflow/underflow occurs, the IR information is displayed.</p>
</td>
</tr>
<tr id="row185381431133610"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p953883153611"><a name="p953883153611"></a><a name="p953883153611"></a>OS compatibility</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p13538203153618"><a name="p13538203153618"></a><a name="p13538203153618"></a>Supported UOS 20 1020e ARM.</p>
</td>
</tr>
<tr id="row91681125173610"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p2168172519364"><a name="p2168172519364"></a><a name="p2168172519364"></a>Basic framework functions</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1416815259367"><a name="p1416815259367"></a><a name="p1416815259367"></a>Added the function of adapted operator development. For details, see the operator list.</p>
</td>
</tr>
<tr id="row11970351050"><td class="cellrowborder" rowspan="26" valign="top" width="10.459999999999999%" headers="mcps1.2.4.1.1 "><p id="p298314333514"><a name="p298314333514"></a><a name="p298314333514"></a>Model training</p>
</td>
<td class="cellrowborder" valign="top" width="26.27%" headers="mcps1.2.4.1.2 "><p id="p19984193312511"><a name="p19984193312511"></a><a name="p19984193312511"></a>CenterFace</p>
</td>
<td class="cellrowborder" valign="top" width="63.27%" headers="mcps1.2.4.1.3 "><p id="p7517351258"><a name="p7517351258"></a><a name="p7517351258"></a>-</p>
</td>
</tr>
<tr id="row9965351254"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1984033458"><a name="p1984033458"></a><a name="p1984033458"></a>PCBU</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p298411338513"><a name="p298411338513"></a><a name="p298411338513"></a>-</p>
</td>
</tr>
<tr id="row14966351959"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p198414331957"><a name="p198414331957"></a><a name="p198414331957"></a>Net++</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1798413331756"><a name="p1798413331756"></a><a name="p1798413331756"></a>-</p>
</td>
</tr>
<tr id="row20966351454"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p4984183317518"><a name="p4984183317518"></a><a name="p4984183317518"></a>FCN8S</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1698453311519"><a name="p1698453311519"></a><a name="p1698453311519"></a>-</p>
</td>
</tr>
<tr id="row19653517518"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1298483319512"><a name="p1298483319512"></a><a name="p1298483319512"></a>OSNetRetinaFace</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1798423312519"><a name="p1798423312519"></a><a name="p1798423312519"></a>-</p>
</td>
</tr>
<tr id="row39619351751"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1298414331513"><a name="p1298414331513"></a><a name="p1298414331513"></a>PSPnet</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p10984633254"><a name="p10984633254"></a><a name="p10984633254"></a>-</p>
</td>
</tr>
<tr id="row496335654"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p19984433351"><a name="p19984433351"></a><a name="p19984433351"></a>EDSR</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p898473314517"><a name="p898473314517"></a><a name="p898473314517"></a>-</p>
</td>
</tr>
<tr id="row17953357517"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p14984123312515"><a name="p14984123312515"></a><a name="p14984123312515"></a>Tsm</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p159841033855"><a name="p159841033855"></a><a name="p159841033855"></a>-</p>
</td>
</tr>
<tr id="row16951435551"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p19984933457"><a name="p19984933457"></a><a name="p19984933457"></a>pnasnet5large</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p89846335512"><a name="p89846335512"></a><a name="p89846335512"></a>-</p>
</td>
</tr>
<tr id="row2095113520514"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1798416331952"><a name="p1798416331952"></a><a name="p1798416331952"></a>Gaitset</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p098417336516"><a name="p098417336516"></a><a name="p098417336516"></a>-</p>
</td>
</tr>
<tr id="row89516351511"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p11985153312516"><a name="p11985153312516"></a><a name="p11985153312516"></a>fcn</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p169858331155"><a name="p169858331155"></a><a name="p169858331155"></a>-</p>
</td>
</tr>
<tr id="row5953353513"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p18985103311514"><a name="p18985103311514"></a><a name="p18985103311514"></a>Albert</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p2098513334519"><a name="p2098513334519"></a><a name="p2098513334519"></a>-</p>
</td>
</tr>
<tr id="row119533516513"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p598511336511"><a name="p598511336511"></a><a name="p598511336511"></a>AdvancedEast</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p119850331513"><a name="p119850331513"></a><a name="p119850331513"></a>-</p>
</td>
</tr>
<tr id="row39511356512"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p698553311512"><a name="p698553311512"></a><a name="p698553311512"></a>ReidStrongBaseline</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1198514331659"><a name="p1198514331659"></a><a name="p1198514331659"></a>-</p>
</td>
</tr>
<tr id="row129463518517"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p99851633158"><a name="p99851633158"></a><a name="p99851633158"></a>Fast-scnn</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1298514331359"><a name="p1298514331359"></a><a name="p1298514331359"></a>-</p>
</td>
</tr>
<tr id="row9942035757"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p109854331151"><a name="p109854331151"></a><a name="p109854331151"></a>RDN</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1198583317511"><a name="p1198583317511"></a><a name="p1198583317511"></a>-</p>
</td>
</tr>
<tr id="row79415357517"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p6985833351"><a name="p6985833351"></a><a name="p6985833351"></a>SRFlow</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p29851033350"><a name="p29851033350"></a><a name="p29851033350"></a>-</p>
</td>
</tr>
<tr id="row12947357514"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p149859334518"><a name="p149859334518"></a><a name="p149859334518"></a>MGN</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p19851833850"><a name="p19851833850"></a><a name="p19851833850"></a>-</p>
</td>
</tr>
<tr id="row3941735855"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p898533316518"><a name="p898533316518"></a><a name="p898533316518"></a>Roberta</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p998553318518"><a name="p998553318518"></a><a name="p998553318518"></a>-</p>
</td>
</tr>
<tr id="row1093335856"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1985533451"><a name="p1985533451"></a><a name="p1985533451"></a>RegNetY</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p59851033355"><a name="p59851033355"></a><a name="p59851033355"></a>-</p>
</td>
</tr>
<tr id="row49373518516"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p19986173311512"><a name="p19986173311512"></a><a name="p19986173311512"></a>VoVNet-39</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p798683310515"><a name="p798683310515"></a><a name="p798683310515"></a>-</p>
</td>
</tr>
<tr id="row5930351357"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p189862336515"><a name="p189862336515"></a><a name="p189862336515"></a>RegNetX</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1398618331651"><a name="p1398618331651"></a><a name="p1398618331651"></a>-</p>
</td>
</tr>
<tr id="row169312351655"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p149863337513"><a name="p149863337513"></a><a name="p149863337513"></a>RefineNet</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p2098615331959"><a name="p2098615331959"></a><a name="p2098615331959"></a>-</p>
</td>
</tr>
<tr id="row11931235957"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1198616331657"><a name="p1198616331657"></a><a name="p1198616331657"></a>RefineDet</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1698611332518"><a name="p1698611332518"></a><a name="p1698611332518"></a>-</p>
</td>
</tr>
<tr id="row189215359511"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p16986183319512"><a name="p16986183319512"></a><a name="p16986183319512"></a>AlignedReID</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1898715331055"><a name="p1898715331055"></a><a name="p1898715331055"></a>-</p>
</td>
</tr>
<tr id="row89213351858"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p119878330511"><a name="p119878330511"></a><a name="p119878330511"></a>FaceBoxes</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p129878331158"><a name="p129878331158"></a><a name="p129878331158"></a>-</p>
</td>
</tr>
</tbody>
</table>
<h3 id="modified-featuresmd">Modified Features</h3>
N/A
<h3 id="resolved-issuesmd">Resolved Issues</h3>
N/A
<h3 id="known-issuesmd">Known Issues</h3>
<a name="table1969972073016"></a>
<table><thead align="left"><tr id="row3699162017307"><th class="cellrowborder" valign="top" width="18.22%" id="mcps1.1.3.1.1"><p id="p16992020153010"><a name="p16992020153010"></a><a name="p16992020153010"></a>Known Issue</p>
</th>
<th class="cellrowborder" valign="top" width="81.78%" id="mcps1.1.3.1.2"><p id="p269919203308"><a name="p269919203308"></a><a name="p269919203308"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row9699142003011"><td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p1769932017300"><a name="p1769932017300"></a><a name="p1769932017300"></a>Data type</p>
</td>
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p13699152010301"><a name="p13699152010301"></a><a name="p13699152010301"></a>NPU does not support the input or output of the inf/nan data of the float16 type.</p>
</td>
</tr>
<tr id="row146991520153016"><td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p156997200308"><a name="p156997200308"></a><a name="p156997200308"></a>Data format</p>
</td>
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p10699182020308"><a name="p10699182020308"></a><a name="p10699182020308"></a>Dimensions cannot be reduced when the format larger than 4D is used.</p>
</td>
</tr>
<tr id="row11121205610549"><td class="cellrowborder" rowspan="3" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p1647216219558"><a name="p1647216219558"></a><a name="p1647216219558"></a>Restrictions on collective communication</p>
<p id="p0465121912402"><a name="p0465121912402"></a><a name="p0465121912402"></a></p>
</td>
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p3116115695415"><a name="p3116115695415"></a><a name="p3116115695415"></a>The graphs executed on different devices in a training job must be the same.</p>
</td>
</tr>
<tr id="row51211656105411"><td class="cellrowborder" valign="top" headers="mcps1.1.3.1.1 "><p id="p1311616560541"><a name="p1311616560541"></a><a name="p1311616560541"></a>Allocation at only 1, 2, 4, or 8 processors is supported.</p>
</td>
</tr>
<tr id="row8647195765419"><td class="cellrowborder" valign="top" headers="mcps1.1.3.1.1 "><p id="p2064225716544"><a name="p2064225716544"></a><a name="p2064225716544"></a>Only the int8, int32, float16, and float32 data types are supported.</p>
</td>
</tr>
<tr id="row4646195719548"><td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p4642195718541"><a name="p4642195718541"></a><a name="p4642195718541"></a>Apex function</p>
</td>
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p864205725412"><a name="p864205725412"></a><a name="p864205725412"></a>In the current version, Apex is implemented mainly using Python, and the customized optimization of CUDA kernel in Apex is not supported.</p>
</td>
</tr>
</tbody>
</table>
<h3 id="compatibilitymd">Compatibility</h3>
Atlas 800 \(model 9010\): CentOS 7.6, Ubuntu 18.04, BC-Linux 7.6, Debian 9.9, Debian 10, and openEuler 20.03 LTS.
Atlas 800 \(model 9000\): CentOS 7.6, Euler 2.8, Kylin v10, BC-Linux 7.6, OpenEuler 20.03 LTS, and UOS 20 1020e.
<h2 id="frameworkptadapter-2-0-2md">FrameworkPTAdapter 2.0.2</h2>
- **[Before You Start](#before-you-start-0md)**
- **[New Features](#new-features-1md)**
- **[Modified Features](#modified-features-2md)**
- **[Resolved Issues](#resolved-issues-3md)**
- **[Known Issues](#known-issues-4md)**
- **[Compatibility](#compatibility-5md)**
<h3 id="before-you-start-0md">Before You Start</h3>
# PyTorch Release Notes 2.0.2
- [Before You Start](#before-you-start)
- [New Features](#new-features)
- [Modified Features](#modified-features)
- [Resolved Issues](#resolved-issues)
- [Known Issues](#known-issues)
- [Compatibility](#compatibility)
<h2 id="before-you-start">Before You Start</h2>
This framework is modified based on the open-source PyTorch 1.5.0 primarily developed by Facebook, inherits native PyTorch features, and uses NPUs for dynamic image training. Models are adapted by operator granularity, code can be reused, and current networks can be ported and used on NPUs with only device types or data types modified.
<h3 id="new-features-1md">New Features</h3>
<h2 id="new-features">New Features</h2>
**Table 1** Features supported by PyTorch
@@ -333,38 +61,38 @@ This framework is modified based on the open-source PyTorch 1.5.0 primarily deve
</tr>
<tr id="row9627165910386"><td class="cellrowborder" rowspan="4" valign="top" width="10.489999999999998%" headers="mcps1.2.4.1.1 "><p id="p1561535993811"><a name="p1561535993811"></a><a name="p1561535993811"></a>PyTorch features adapted to NPUs</p>
</td>
<td class="cellrowborder" valign="top" width="26.3%" headers="mcps1.2.4.1.2 "><p id="p136151659163819"><a name="p136151659163819"></a><a name="p136151659163819"></a>Basic Framework Functions</p>
<td class="cellrowborder" valign="top" width="26.3%" headers="mcps1.2.4.1.2 "><p id="p136151659163819"><a name="p136151659163819"></a><a name="p136151659163819"></a>Basic framework functions</p>
</td>
<td class="cellrowborder" valign="top" width="63.21%" headers="mcps1.2.4.1.3 "><p id="p1661535983813"><a name="p1661535983813"></a><a name="p1661535983813"></a>Added the function of adapted operator development. For details, see the operator list.</p>
</td>
</tr>
<tr id="row7627155917380"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1561525916383"><a name="p1561525916383"></a><a name="p1561525916383"></a>Model Accuracy Analyzer</p>
<tr id="row7627155917380"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1561525916383"><a name="p1561525916383"></a><a name="p1561525916383"></a>Model accuracy analyzer</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p19616115953816"><a name="p19616115953816"></a><a name="p19616115953816"></a>Added model accuracy analyzers and supported training accuracy demarcation.</p>
</td>
</tr>
<tr id="row46269593383"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p0616559163819"><a name="p0616559163819"></a><a name="p0616559163819"></a>Ascend 710 AI Processor</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p186161459193813"><a name="p186161459193813"></a><a name="p186161459193813"></a>Supported the online inference on the Ascend 710 AI Processor.</p>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p186161459193813"><a name="p186161459193813"></a><a name="p186161459193813"></a>Supported the online inference for the Ascend 710 AI Processor.</p>
</td>
</tr>
<tr id="row76261059153817"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p11616175953812"><a name="p11616175953812"></a><a name="p11616175953812"></a>OS Compatibility</p>
<tr id="row76261059153817"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p11616175953812"><a name="p11616175953812"></a><a name="p11616175953812"></a>OS compatibility</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p8935115971714"><a name="p8935115971714"></a><a name="p8935115971714"></a>Supported Ubuntu 18.04.5 and openEuler 20.03 LTS.</p>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p8935115971714"><a name="p8935115971714"></a><a name="p8935115971714"></a>Supported Ubunta 18.04.5 and openEuler 20.03 LTS.</p>
</td>
</tr>
</tbody>
</table>
<h3 id="modified-features-2md">Modified Features</h3>
<h2 id="modified-features">Modified Features</h2>
N/A
<h3 id="resolved-issues-3md">Resolved Issues</h3>
<h2 id="resolved-issues">Resolved Issues</h2>
N/A
<h3 id="known-issues-4md">Known Issues</h3>
<h2 id="known-issues">Known Issues</h2>
<a name="table1969972073016"></a>
<table><thead align="left"><tr id="row3699162017307"><th class="cellrowborder" valign="top" width="18.22%" id="mcps1.1.3.1.1"><p id="p16992020153010"><a name="p16992020153010"></a><a name="p16992020153010"></a>Known Issue</p>
@@ -375,7 +103,7 @@ N/A
</thead>
<tbody><tr id="row9699142003011"><td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p1769932017300"><a name="p1769932017300"></a><a name="p1769932017300"></a>Data type</p>
</td>
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p13699152010301"><a name="p13699152010301"></a><a name="p13699152010301"></a>The NPU does not support the input or output of the inf/nan data of the float16 type.</p>
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p13699152010301"><a name="p13699152010301"></a><a name="p13699152010301"></a>NPU does not support the input or output of the inf/nan data of the float16 type.</p>
</td>
</tr>
<tr id="row146991520153016"><td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p156997200308"><a name="p156997200308"></a><a name="p156997200308"></a>Data format</p>
@@ -403,9 +131,9 @@ N/A
</tbody>
</table>
<h3 id="compatibility-5md">Compatibility</h3>
<h2 id="compatibility">Compatibility</h2>
Atlas 800 \(model 9010\): CentOS 7.6/Ubuntu 18.04/BC-Linux 7.6/Debian 9.9/Debian 10/openEuler 20.03 LTS
Atlas 800 \(model 9000\): CentOS 7.6/EulerOS 2.8/Kylin v10/BC-Linux 7.6/openEuler 20.03 LTS
Atlas 800 \(model 9000\): CentOS 7.6/Euler 2.8/Kylin v10/BC-Linux 7.6/openEuler 20.03 LTS
Binary file not shown.

Before

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 394 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 406 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 253 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 580 B

File diff suppressed because it is too large Load Diff
@@ -1,48 +1,48 @@
# PyTorch在线推理指南
- [使用场景](#使用场景md)
- [基本使用流程](#基本使用流程md)
- [前提条件](#前提条件md)
- [在线推理流程](#在线推理流程md)
- [环境变量配置](#环境变量配置md)
- [样例参考](#样例参考md)
- [专题](#专题md)
- [混合精度](#混合精度md)
- [安装7.3.0版本gcc](#安装7-3-0版本gccmd)
<h2 id="使用场景md">使用场景</h2>
- [使用场景](#使用场景)
- [基本使用流程](#基本使用流程)
- [前提条件](#前提条件)
- [在线推理流程](#在线推理流程)
- [环境变量配置](#环境变量配置)
- [样例参考](#样例参考)
- [专题](#专题)
- [混合精度](#混合精度)
- [安装7.3.0版本gcc](#安装7-3-0版本gcc)
<h2 id="使用场景">使用场景</h2>
在线推理是在AI框架内执行推理的场景,例如在PyTorch框架上,加载模型后,通过“model.eval\(\)“将模型切换为推理模式。
相比于离线推理场景,使用在线推理可以方便将原来基于PyTorch框架做推理的应用快速迁移到昇腾AI处理器,适用于数据中心推理场景。
### 支持的芯片型号<a name="section15598658104219"></a>
## 支持的芯片型号<a name="section15598658104219"></a>
昇腾910 AI处理器
昇腾710 AI处理器
<h2 id="基本使用流程md">基本使用流程</h2>
<h2 id="基本使用流程">基本使用流程</h2>
- **[前提条件](#前提条件md)**
- **[前提条件](#前提条件)**
- **[在线推理流程](#在线推理流程md)**
- **[在线推理流程](#在线推理流程)**
- **[环境变量配置](#环境变量配置md)**
- **[环境变量配置](#环境变量配置)**
- **[样例参考](#样例参考md)**
- **[样例参考](#样例参考)**
<h3 id="前提条件md">前提条件</h3>
<h2 id="前提条件">前提条件</h2>
已完成PyTorch框架及混合精度模块的安装,详情请参见《PyTorch安装指南》进行PyTorch相关运行环境搭建。
已完成PyTorch框架及混合精度模块的安装,详情请参见[《PyTorch安装指南》](https://gitee.com/ascend/pytorch/blob/2.0.2.tr5/docs/zh/PyTorch%E5%AE%89%E8%A3%85%E6%8C%87%E5%8D%97/PyTorch%E5%AE%89%E8%A3%85%E6%8C%87%E5%8D%97.md)进行PyTorch相关运行环境搭建。
<h3 id="在线推理流程md">在线推理流程</h3>
<h2 id="在线推理流程">在线推理流程</h2>
在线推理流程如[图1](#fig13802941161818)所示。
**图 1** 在线推理流程图<a name="fig13802941161818"></a>
![](figures/在线推理流程图.png "在线推理流程图")
<h3 id="环境变量配置md">环境变量配置</h3>
<h2 id="环境变量配置">环境变量配置</h2>
PyTorch在线推理进程启动所依赖的环境变量:
@@ -82,7 +82,7 @@ export TASK_QUEUE_ENABLE=0
<tbody><tr id="row2732273481"><td class="cellrowborder" valign="top" width="35.51355135513551%" headers="mcps1.2.4.1.1 "><p id="p57382719481"><a name="p57382719481"></a><a name="p57382719481"></a>LD_LIBRARY_PATH</p>
</td>
<td class="cellrowborder" valign="top" width="54.42544254425443%" headers="mcps1.2.4.1.2 "><p id="p07319271480"><a name="p07319271480"></a><a name="p07319271480"></a>动态库的查找路径,参考上述举例配置。</p>
<div class="note" id="note119943144912"><a name="note119943144912"></a><a name="note119943144912"></a><span class="notetitle"> 说明: </span><div class="notebody"><p id="p49933104915"><a name="p49933104915"></a><a name="p49933104915"></a>若系统环境安装了gcc7.3.0(例如CentOS7.6、Debian和BClinux系统),需要配置gcc相关环境变量,详情请参见<a href="#安装7-3-0版本gccmd#zh-cn_topic_0000001146754749_zh-cn_topic_0000001072593337_l5e5c9395407d46439788b12f0e6342bc">5</a>。</p>
<div class="note" id="note119943144912"><a name="note119943144912"></a><a name="note119943144912"></a><span class="notetitle"> 说明: </span><div class="notebody"><p id="p49933104915"><a name="p49933104915"></a><a name="p49933104915"></a>若系统环境安装了gcc7.3.0(例如CentOS7.6、Debian和BClinux系统),需要配置gcc相关环境变量,详情请参见<a href="#安装7-3-0版本gcc.md#zh-cn_topic_0000001146754749_zh-cn_topic_0000001072593337_l5e5c9395407d46439788b12f0e6342bc">5</a>。</p>
</div></div>
</td>
<td class="cellrowborder" valign="top" width="10.061006100610062%" headers="mcps1.2.4.1.3 "><p id="p187352744817"><a name="p187352744817"></a><a name="p187352744817"></a>必选</p>
@@ -131,11 +131,11 @@ export TASK_QUEUE_ENABLE=0
</table>
>![](public_sys-resources/icon-note.gif) **说明:**
>更多日志信息,请参见《CANN 日志参考》。
>更多日志信息,请参见[《CANN 日志参考》](https://support.huawei.com/enterprise/zh/doc/EDOC1100206691?idPath=23710424%7C251366513%7C22892968%7C251168373)。
<h3 id="样例参考md">样例参考</h3>
<h2 id="样例参考">样例参考</h2>
#### 样例代码<a name="section2017032418274"></a>
## 样例代码<a name="section2017032418274"></a>
在进行推理应用时,应尽量保证应用在生命周期内不频繁初始化。推理模式通过模型model.eval\(\)进行设置,并且推理过程要在“with torch.no\_grad\(\):”代码分支下运行。
@@ -406,7 +406,7 @@ if __name__ == '__main__':
main()
```
#### 样例执行<a name="section340764716270"></a>
## 样例执行<a name="section340764716270"></a>
以ResNet50模型为例,执行在线推理样例。
@@ -420,7 +420,7 @@ if __name__ == '__main__':
3. 执行推理。
参考[环境变量配置](#环境变量配置md)设置环境变量,并执行命令:
参考[环境变量配置](#环境变量配置)设置环境变量,并执行命令:
```
python3 pytorch-resnet50-apex.py --data /data/imagenet \
@@ -433,14 +433,14 @@ if __name__ == '__main__':
>上述为样例输入,用户可根据实际修改传入参数。
<h2 id="专题md">专题</h2>
<h2 id="专题">专题</h2>
- **[混合精度](#混合精度md)**
- **[混合精度](#混合精度)**
<h3 id="混合精度md">混合精度</h3>
<h2 id="混合精度">混合精度</h2>
#### 概述<a name="section14734122962615"></a>
## 概述<a name="section14734122962615"></a>
基于NPU芯片的架构特性,模型运算会涉及到混合精度,即混合使用float16和float32数据类型的应用场景。使用float16代替float32有如下好处:
@@ -450,7 +450,7 @@ if __name__ == '__main__':
但是,混合精度训练受限于float16表达的精度范围,单纯将float32转换成float16会影响训练收敛情况,为了保证部分计算使用float16来进行加速的同时能保证训练收敛,这里采用混合精度模块Apex来达到以上效果。混合精度模块Apex是一个集优化性能、精度收敛于一身的综合优化库。
#### 特性支持<a name="section175201458521"></a>
## 特性支持<a name="section175201458521"></a>
混合精度模块功能和优化描述如[表1](#zh-cn_topic_0278765773_table10717173813332)所示。
@@ -465,12 +465,12 @@ if __name__ == '__main__':
</thead>
<tbody><tr id="zh-cn_topic_0278765773_row1571763813334"><td class="cellrowborder" valign="top" width="32.269999999999996%" headers="mcps1.2.3.1.1 "><p id="zh-cn_topic_0278765773_p4502732153412"><a name="zh-cn_topic_0278765773_p4502732153412"></a><a name="zh-cn_topic_0278765773_p4502732153412"></a>O1配置模式</p>
</td>
<td class="cellrowborder" valign="top" width="67.73%" headers="mcps1.2.3.1.2 "><p id="zh-cn_topic_0278765773_p640053920348"><a name="zh-cn_topic_0278765773_p640053920348"></a><a name="zh-cn_topic_0278765773_p640053920348"></a>Conv, Matmul等使用float16计算,其他如Softmax、BN使用float32。</p>
<td class="cellrowborder" valign="top" width="67.73%" headers="mcps1.2.3.1.2 "><p id="zh-cn_topic_0278765773_p640053920348"><a name="zh-cn_topic_0278765773_p640053920348"></a><a name="zh-cn_topic_0278765773_p640053920348"></a>Conv, Matmul等使用<span>float16</span>计算,其他如Softmax、BN使用<span>float32</span>。</p>
</td>
</tr>
<tr id="zh-cn_topic_0278765773_row3717173817336"><td class="cellrowborder" valign="top" width="32.269999999999996%" headers="mcps1.2.3.1.1 "><p id="zh-cn_topic_0278765773_p11503103210344"><a name="zh-cn_topic_0278765773_p11503103210344"></a><a name="zh-cn_topic_0278765773_p11503103210344"></a>O2配置模式</p>
</td>
<td class="cellrowborder" valign="top" width="67.73%" headers="mcps1.2.3.1.2 "><p id="zh-cn_topic_0278765773_p164001639143419"><a name="zh-cn_topic_0278765773_p164001639143419"></a><a name="zh-cn_topic_0278765773_p164001639143419"></a>BN使用float32,其他绝大部分使用float16。</p>
<td class="cellrowborder" valign="top" width="67.73%" headers="mcps1.2.3.1.2 "><p id="zh-cn_topic_0278765773_p164001639143419"><a name="zh-cn_topic_0278765773_p164001639143419"></a><a name="zh-cn_topic_0278765773_p164001639143419"></a>BN使用<span>float32</span>,其他绝大部分使用<span>float16</span>。</p>
</td>
</tr>
<tr id="zh-cn_topic_0278765773_row14717193815334"><td class="cellrowborder" valign="top" width="32.269999999999996%" headers="mcps1.2.3.1.1 "><p id="zh-cn_topic_0278765773_p1950318328349"><a name="zh-cn_topic_0278765773_p1950318328349"></a><a name="zh-cn_topic_0278765773_p1950318328349"></a>静态Loss Scale功能</p>
@@ -489,7 +489,7 @@ if __name__ == '__main__':
>![](public_sys-resources/icon-note.gif) **说明:**
>当前版本的实现方式主要为python实现,不支持AscendCL或者CUDA优化。
#### 混合精度模型初始化<a name="section18178125518268"></a>
## 混合精度模型初始化<a name="section18178125518268"></a>
1. 使用apex混合精度模块需要首先从apex库中导入amp,代码如下:
@@ -503,20 +503,20 @@ if __name__ == '__main__':
model, optimizer = amp.initialize(model, optimizer)
```
也可参考[样例代码](#样例参考md)中的“初始化混合精度模型”:
也可参考[样例代码](#样例参考)中的“初始化混合精度模型”:
```
model, optimizer = amp.initialize(model, optimizer, opt_level="O2", loss_scale=1024, verbosity=1)
```
#### 混合精度推理<a name="section818071513288"></a>
## 混合精度推理<a name="section818071513288"></a>
按混合精度模型初始化后,正常执行模型正向计算即可。
参考代码:可参考[样例代码](#样例参考md)实现。
参考代码:可参考[样例代码](#样例参考)实现。
<h2 id="安装7-3-0版本gccmd">安装7.3.0版本gcc</h2>
<h2 id="安装7-3-0版本gcc">安装7.3.0版本gcc</h2>
以下步骤请在root用户下执行。
+182 -169
View File
@@ -1,42 +1,42 @@
# PyTorch安装指南
- [简介](#简介md)
- [手动编译安装](#手动编译安装md)
- [前提条件](#前提条件md)
- [安装PyTorch框架](#安装PyTorch框架md)
- [配置环境变量](#配置环境变量md)
- [安装混合精度模块](#安装混合精度模块md)
- [参考信息](#参考信息md)
- [CMake安装方法](#CMake安装方法md)
- [安装7.3.0版本gcc](#安装7-3-0版本gccmd)
- [安装“torch-\*.whl ”提示“torch 1.5.0xxxx”与“torchvision”所依赖的版本不匹配](#安装-torch--whl-提示-torch-1-5-0xxxx-与-torchvision-所依赖的版本不匹配md)
<h2 id="简介md">简介</h2>
- [简介](#简介)
- [手动编译安装](#手动编译安装)
- [前提条件](#前提条件)
- [安装PyTorch框架](#安装PyTorch框架)
- [配置环境变量](#配置环境变量)
- [安装混合精度模块](#安装混合精度模块)
- [使用Ascend Hub镜像](#使用Ascend-Hub镜像)
- [Ascend Hub获取PyTorch镜像](#Ascend-Hub获取PyTorch镜像)
- [配置环境变量](#配置环境变量-0)
- [参考信息](#参考信息)
- [CMake安装方法](#CMake安装方法)
- [安装7.3.0版本gcc](#安装7-3-0版本gcc)
- [安装“torch-\*.whl ”提示“torch 1.5.0xxxx”与“torchvision”所依赖的版本不匹配](#安装-torch--whl-提示-torch-1-5-0xxxx-与-torchvision-所依赖的版本不匹配)
<h2 id="简介">简介</h2>
用户在准备相关环境进行基于PyTorch框架模型的开发、运行时,可以选择在服务器中手动编译安装PyTorch框架相关模块。
用户在准备相关环境进行PyTorch模型的移植及训练时,可以选择在训练服务器中手动编译安装PyTorch框架相关模块,或直接获取Ascend Hub镜像中心提供的基础镜像(镜像中已安装PyTorch模块和混合精度模块),进行模型的移植与训练。
**图 1** 环境准备流程图<a name="zh-cn_topic_0000001119176876_fig1938918396117"></a>
![](figures/环境准备流程图.png "环境准备流程图")
<h2 id="手动编译安装">手动编译安装</h2>
- **[前提条件](#前提条件)**
- **[安装PyTorch框架](#安装PyTorch框架)**
- **[配置环境变量](#配置环境变量)**
- **[安装混合精度模块](#安装混合精度模块)**
![](figures/210926103326800.png)
<h2 id="前提条件">前提条件</h2>
<h2 id="手动编译安装md">手动编译安装</h2>
## 前提条件<a name="zh-cn_topic_0000001105856382_zh-cn_topic_0275872734_section108914373254"></a>
- **[前提条件](#前提条件md)**
- **[安装PyTorch框架](#安装PyTorch框架md)**
- **[配置环境变量](#配置环境变量md)**
- **[安装混合精度模块](#安装混合精度模块md)**
<h3 id="前提条件md">前提条件</h3>
#### 前提条件<a name="zh-cn_topic_0000001105856382_zh-cn_topic_0275872734_section108914373254"></a>
- 需完成CANN开发或运行环境的安装,具体操作请参考《CANN 软件安装指南》。
- 需安装3.12.0以上版本的CMake,安装方法请参考[CMake安装方法](#CMake安装方法md)。
- 需确保已安装7.3.0以上版本的gcc,7.3.0版本gcc具体安装及使用方式请参考[安装7.3.0版本gcc](#安装7-3-0版本gccmd)。
- 需安装python版本为3.7.5或3.8。
- 需完成CANN开发或运行环境的安装,具体操作请参考《[CANN 软件安装指南](https://support.huawei.com/enterprise/zh/doc/EDOC1100206656?idPath=23710424%7C251366513%7C22892968%7C251168373)》。
- 需安装3.12.0以上版本的CMake,安装方法请参考[CMake安装方法](#CMake安装方法)。
- 需确保已安装7.3.0以上版本的gcc,7.3.0版本gcc具体安装及使用方式请参考[安装7.3.0版本gcc](#安装7-3-0版本gcc)。
- 需确保环境中已安装patch、git工具,以Ubuntu和CentOS系统为例,命令如下:
- Ubuntu系统
@@ -54,9 +54,9 @@
<h3 id="安装PyTorch框架md">安装PyTorch框架</h3>
<h2 id="安装PyTorch框架">安装PyTorch框架</h2>
#### 安装流程<a name="zh-cn_topic_0000001152776301_section1611810384557"></a>
## 安装流程<a name="zh-cn_topic_0000001152776301_section1611810384557"></a>
1. 以root或非root用户登录服务器。
2. 依次执行如下命令安装PyTorch依赖环境。
@@ -79,32 +79,36 @@
下载的源码主要目录结构如下所示:
```
├── patch # 昇腾AI处理器适配补丁目录
│ ├── pytorch1.5.0_npu.patch # pytorch1.5.0版本补丁
│ └── pytorch1.8.1_npu.patch # pytorch1.8.1版本补丁
├── pytorch1.5.0 # pytorch1.5.0源码及测试目录
│ ├── access_control_test.py
│ ├── src # 源码目录
│ └── test # 测试用例存放目录
├── pytorch1.8.1 # pytorch1.8.1源码及测试目录
│ ├── access_control_test.py
│ ├── src # 源码目录
│ └── test # 测试用例存放目录
└── scripts # 编译构建目录
pytorch
│ ├─patch # 昇腾AI处理器适配补丁目录
│ ├─npu.patch
│ ├─scripts # 编译构建目录
│ ├─gen.sh
│ ├─src # 源码目录
│ ├─test # 测试用例存放目录
│ ├─README.md
```
2. 在当前仓根目录“/pytorch“下获取原生PyTorch源代码。
- 若安装pytorch1.5.0版本,执行如下命令。
2. 运行如下命令,进入“pytorch“目录,并获取原生PyTorch源代码。
```
git clone -b v1.5.0 --depth=1 https://github.com/pytorch/pytorch.git
```
```
cd pytorch
git clone -b v1.5.0 --depth=1 https://github.com/pytorch/pytorch.git
```
- 若安装pytorch1.8.1版本,执行如下命令。
下载原生pytorch源码后,代码主要目录结构如下所示:
```
git clone -b v1.8.1 --depth=1 https://github.com/pytorch/pytorch.git
```
```
pytorch
│ ├─patch # 昇腾AI处理器适配补丁目录
│ ├─npu.patch
│ ├─pytorch # 原生pytorch代码目录
│ ├─scripts # 编译构建目录
│ ├─gen.sh
│ ├─src # 源码目录
│ ├─test # 测试用例存放目录
│ ├─README.md
```
3. 运行如下命令,进入原生pytorch代码目录“pytorch“,并获取PyTorch被动依赖代码。
@@ -122,37 +126,26 @@
```
cd ../scripts
# 若安装1.5.0版本
bash gen.sh
# 若安装1.8.1版本
bash gen.sh -v 1.8.1
```
将在"pytorch/pytorch"目录中生成适配昇腾AI处理器的全量代码。
2. 进入到“pytorch/pytorch/“目录,依赖库安装。
2. 进入适配后的全量代码目录,即“pytorch/pytorch“目录,编译生成pytorch的二进制安装包。
```
cd ../pytorch
pip3 install -r requirements.txt
bash build.sh
```
3. 编译生成pytorch的二进制安装包。
```
bash build.sh --python=3.7
或
bash build.sh --python=3.8
```
请指定环境中python版本进行编译。生成的二进制包在当前的dist目录下,即“pytorch/pytorch/dist”文件夹目录下。
生成的二进制包在当前的dist目录下,即“pytorch/pytorch/dist”文件夹目录下。
5. <a name="zh-cn_topic_0000001152776301_li49671667141"></a>安装PyTorch。
进入“pytorch/pytorch/dist“文件夹目录,执行如下命令安装。
```
pip3 install --upgrade torch-1.5.0+ascend.post3-cp37-cp37m-linux_{arch}.whl
pip3 install --upgrade torch-1.5.0+ascend-cp37-cp37m-linux_{arch}.whl
```
**\{arch\}**表示架构信息,为aarch64或x86\_64。
@@ -162,42 +155,62 @@
>**pip3 list | grep torch**
<h3 id="配置环境变量md">配置环境变量</h3>
<h2 id="配置环境变量">配置环境变量</h2>
安装完软件包后,需要配置环境变量才能正常使用昇腾PyTorch。相关环境变量介绍参见[表1](#zh-cn_topic_0000001152616261_table42017516135)。
安装完软件包后,需要配置环境变量才能正常使用昇腾PyTorch。建议构建启动脚本,例如构建set\_env.sh脚本,使用source set\_env.sh配置当前窗口的环境变量。set\_env.sh脚本内容如下(以root用户安装,安装路径为默认路径为例)。
1. 配置运行环境变量,在适配昇腾AI处理器的PyTorch源代码根目录中运行如下命令。
```
cpu_type=$(echo $HOSTTYPE)
```
source pytorch/env.sh
```
if [ x"${cpu_type}" == x"x86_64" ];then
cpu_type=x86_64-linux
else
cpu_type=arm64-linux
fi
if [ -d /usr/local/Ascend/nnae/latest ];then
export LD_LIBRARY_PATH=/usr/local/:/usr/local/python3.7.5/lib/:/usr/local/openblas/lib:/usr/local/lib/:/usr/lib64/:/usr/lib/:/usr/local/Ascend/nnae/latest/fwkacllib/lib64/:/usr/local/Ascend/driver/lib64/common/:/usr/local/Ascend/driver/lib64/driver/:/usr/local/Ascend/add-ons/:/usr/lib/aarch64_64-linux-gnu:$LD_LIBRARY_PATH
export PATH=$PATH:/usr/local/Ascend/nnae/latest/fwkacllib/ccec_compiler/bin/:/usr/local/Ascend/nnae/latest/toolkit/tools/ide_daemon/bin/
export ASCEND_OPP_PATH=/usr/local/Ascend/nnae/latest/opp/
export OPTION_EXEC_EXTERN_PLUGIN_PATH=/usr/local/Ascend/nnae/latest/fwkacllib/lib64/plugin/opskernel/libfe.so:/usr/local/Ascend/nnae/latest/fwkacllib/lib64/plugin/opskernel/libaicpu_engine.so:/usr/local/Ascend/nnae/latest/fwkacllib/lib64/plugin/opskernel/libge_local_engine.so
export PYTHONPATH=/usr/local/Ascend/nnae/latest/fwkacllib/python/site-packages/:/usr/local/Ascend/nnae/latest/fwkacllib/python/site-packages/auto_tune.egg/auto_tune:/usr/local/Ascend/nnae/latest/fwkacllib/python/site-packages/schedule_search.egg:$PYTHONPATH
export ASCEND_AICPU_PATH=/usr/local/Ascend/nnae/latest/
else
export LD_LIBRARY_PATH=/usr/local/:/usr/local/lib/:/usr/lib64/:/usr/lib/:/usr/local/python3.7.5/lib/:/usr/local/openblas/lib:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/lib64/:/usr/local/Ascend/driver/lib64/common/:/usr/local/Ascend/driver/lib64/driver/:/usr/local/Ascend/add-ons/:/usr/lib/aarch64-linux-gnu:$LD_LIBRARY_PATH
export PATH=$PATH:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/ccec_compiler/bin/:/usr/local/Ascend/ascend-toolkit/latest/toolkit/tools/ide_daemon/bin/
export ASCEND_OPP_PATH=/usr/local/Ascend/ascend-toolkit/latest/opp/
export OPTION_EXEC_EXTERN_PLUGIN_PATH=/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libfe.so:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libaicpu_engine.so:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/lib64/plugin/opskernel/libge_local_engine.so
export PYTHONPATH=/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/python/site-packages/:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/python/site-packages/auto_tune.egg/auto_tune:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/python/site-packages/schedule_search.egg:$PYTHONPATH
export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest/${cpu_type}
fi
path_lib=$(python3.7 -c """
import sys
import re
result=''
for index in range(len(sys.path)):
match_sit = re.search('-packages', sys.path[index])
if match_sit is not None:
match_lib = re.search('lib', sys.path[index])
if match_lib is not None:
end=match_lib.span()[1]
result += sys.path[index][0:end] + ':'
result+=sys.path[index] + '/torch/lib:'
print(result)"""
)
export LD_LIBRARY_PATH=/usr/local/python3.7.5/lib/:${path_lib}:$LD_LIBRARY_PATH
export TASK_QUEUE_ENABLE=1
2. 请依据实际场景,选择合适的HCCL初始化方式,并配置相应环境变量。
# (可选)当系统为openeuler时,需设置此命令,取消CPU绑核。
# unset GOMP_CPU_AFFINITY
```
# 场景一:单机场景
export HCCL_WHITELIST_DISABLE=1 # 关闭HCCL通信白名单
# 场景二:多机场景。
export HCCL_WHITELIST_DISABLE=1 # 关闭HCCL通信白名单
export HCCL_IF_IP="1.1.1.1" # “1.1.1.1”为示例使用的host网卡IP,请根据实际修改。需要保证使用的网卡IP在集群内是互通的。
```
3. (可选)NPU场景下配置功能或性能环境变量。默认为不开启。
```
export DYNAMIC_COMPILE_ENABLE=1 # 动态shape特性功能,针对shape变化场景,可选,开启设置为1(PyTorch1.8.1不支持该环境变量)
export COMBINED_ENABLE=1 # 非连续两个算子组合类场景优化,可选,开启设置为1
export TRI_COMBINED_ENABLE=1 # 非连续三个算子组合类场景优化,可选,开启设置为1
export ACL_DUMP_DATA=1 # 算子数据dump功能,调试时使用,可选,开启设置为1
export DYNAMIC_OP="ADD#MUL" # 算子实现,ADD和MUL算子在不同场景下有不同的性能表现。可选
```
4. (可选)当系统为openEuler及其继承操作系统时,如UOS,需设置此命令,取消CPU绑核。
```
# unset GOMP_CPU_AFFINITY
```
# 请依据实际,在下列场景中选择合适的HCCL初始化方式,并配置相应环境变量。具体如下:
# 场景一:单机场景
export HCCL_WHITELIST_DISABLE=1 # 关闭HCCL通信白名单
# 场景二:多机场景。
export HCCL_WHITELIST_DISABLE=1 # 关闭HCCL通信白名单
export HCCL_IF_IP="1.1.1.1" # “1.1.1.1”为示例使用的host网卡IP,请根据实际修改。需要保证使用的网卡IP在集群内是互通的。
```
相关参数介绍参见[表1](#zh-cn_topic_0000001152616261_table42017516135)。
**表 1** 环境变量说明
@@ -211,7 +224,7 @@
<tbody><tr id="zh-cn_topic_0000001152616261_row6882121917329"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="zh-cn_topic_0000001152616261_p688241953218"><a name="zh-cn_topic_0000001152616261_p688241953218"></a><a name="zh-cn_topic_0000001152616261_p688241953218"></a>LD_LIBRARY_PATH</p>
</td>
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="zh-cn_topic_0000001152616261_p1888291915322"><a name="zh-cn_topic_0000001152616261_p1888291915322"></a><a name="zh-cn_topic_0000001152616261_p1888291915322"></a>动态库的查找路径,参考上述举例配置。</p>
<p id="p1292181892120"><a name="p1292181892120"></a><a name="p1292181892120"></a>若训练所在系统环境需要升级gcc(例如CentOS、Debian和BClinux系统),则<span class="parmname" id="parmname795020446318"><a name="parmname795020446318"></a><a name="parmname795020446318"></a>“LD_LIBRARY_PATH”</span>配置项处动态库查找路径需要添加<span class="filepath" id="zh-cn_topic_0256062644_filepath115819811512"><a name="zh-cn_topic_0256062644_filepath115819811512"></a><a name="zh-cn_topic_0256062644_filepath115819811512"></a>“${install_path}/lib64”</span>,其中<span class="filepath" id="zh-cn_topic_0256062644_filepath195951574421"><a name="zh-cn_topic_0256062644_filepath195951574421"></a><a name="zh-cn_topic_0256062644_filepath195951574421"></a>“{install_path}”</span>为gcc升级安装路径。请参见<a href="#安装7-3-0版本gccmd#zh-cn_topic_0000001135347812_zh-cn_topic_0000001173199577_zh-cn_topic_0000001172534867_zh-cn_topic_0276688294_li9745165315131">5</a>。</p>
<p id="p1292181892120"><a name="p1292181892120"></a><a name="p1292181892120"></a>若训练所在系统环境需要升级gcc(例如CentOS、Debian和BClinux系统),则<span class="parmname" id="parmname795020446318"><a name="parmname795020446318"></a><a name="parmname795020446318"></a>“LD_LIBRARY_PATH”</span>配置项处动态库查找路径需要添加<span class="filepath" id="zh-cn_topic_0256062644_filepath115819811512"><a name="zh-cn_topic_0256062644_filepath115819811512"></a><a name="zh-cn_topic_0256062644_filepath115819811512"></a>“${install_path}/lib64”</span>,其中<span class="filepath" id="zh-cn_topic_0256062644_filepath195951574421"><a name="zh-cn_topic_0256062644_filepath195951574421"></a><a name="zh-cn_topic_0256062644_filepath195951574421"></a>“{install_path}”</span>为gcc升级安装路径。请参见<a href="#安装7-3-0版本gcc#zh-cn_topic_0000001135347812_zh-cn_topic_0000001173199577_zh-cn_topic_0000001172534867_zh-cn_topic_0276688294_li9745165315131">5</a>。</p>
</td>
</tr>
<tr id="zh-cn_topic_0000001152616261_row16194175523010"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="zh-cn_topic_0000001152616261_p16195185523019"><a name="zh-cn_topic_0000001152616261_p16195185523019"></a><a name="zh-cn_topic_0000001152616261_p16195185523019"></a>PYTHONPATH</p>
@@ -258,70 +271,22 @@
<p id="zh-cn_topic_0000001152616261_p1167163719217"><a name="zh-cn_topic_0000001152616261_p1167163719217"></a><a name="zh-cn_topic_0000001152616261_p1167163719217"></a>缺省时,按照以下优先级选定host通信网卡名:docker/local以外网卡(网卡名字字典序升序排列)&gt;docker 网卡 &gt; local网卡</p>
</td>
</tr>
<tr id="zh-cn_topic_0000001152616261_row1371356152313"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p15106173103120"><a name="p15106173103120"></a><a name="p15106173103120"></a>PTCOPY_ENABLE</p>
<tr id="zh-cn_topic_0000001152616261_row1371356152313"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="zh-cn_topic_0000001152616261_p16711563237"><a name="zh-cn_topic_0000001152616261_p16711563237"></a><a name="zh-cn_topic_0000001152616261_p16711563237"></a>unset GOMP_CPU_AFFINITY</p>
</td>
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p71055317311"><a name="p71055317311"></a><a name="p71055317311"></a>使用PTCopy算子模式,加速转连续及copy等过程,建议开启,开启设置为1</p>
</td>
</tr>
<tr id="row743212132309"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p17433111312307"><a name="p17433111312307"></a><a name="p17433111312307"></a>ASCEND_SLOG_PRINT_TO_STDOUT</p>
</td>
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p6433151393018"><a name="p6433151393018"></a><a name="p6433151393018"></a>(可选)设置是否开启日志打屏。</p>
<a name="ul760201917473"></a><a name="ul760201917473"></a><ul id="ul760201917473"><li>0:表示采用日志的默认输出方式。</li><li>1:表示日志打屏显示。</li><li>其他值为非法值。</li></ul>
</td>
</tr>
<tr id="row19237171814300"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p14238161893019"><a name="p14238161893019"></a><a name="p14238161893019"></a>ASCEND_GLOBAL_LOG_LEVEL</p>
</td>
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p223841810303"><a name="p223841810303"></a><a name="p223841810303"></a>设置应用类日志的全局日志级别。</p>
<a name="ul175714586453"></a><a name="ul175714586453"></a><ul id="ul175714586453"><li>0:对应DEBUG级别。</li><li>1:对应INFO级别。</li><li>2:对应WARNING级别。</li><li>3:对应ERROR级别。</li><li>4:对应NULL级别,不输出日志。</li><li>其他值为非法值。</li></ul>
</td>
</tr>
<tr id="row1348192313303"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p1734815235305"><a name="p1734815235305"></a><a name="p1734815235305"></a>ASCEND_GLOBAL_EVENT_ENABLE</p>
</td>
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p12348202373018"><a name="p12348202373018"></a><a name="p12348202373018"></a>设置应用类日志是否开启Event日志。</p>
<a name="ul416352114610"></a><a name="ul416352114610"></a><ul id="ul416352114610"><li>0:不开启Event日志。</li><li>1:开启Event日志。</li><li>其他值为非法值。</li></ul>
</td>
</tr>
<tr id="row17878184693015"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p1878194683016"><a name="p1878194683016"></a><a name="p1878194683016"></a>DYNAMIC_COMPILE_ENABLE</p>
</td>
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p1887894620304"><a name="p1887894620304"></a><a name="p1887894620304"></a>(可选)动态shape特性功能,针对shape变化场景,开启设置为1(PyTorch1.8.1不支持该环境变量)。</p>
</td>
</tr>
<tr id="row78312162301"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p1832171673019"><a name="p1832171673019"></a><a name="p1832171673019"></a>COMBINED_ENABLE</p>
</td>
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p583261643014"><a name="p583261643014"></a><a name="p583261643014"></a>(可选)非连续两个算子组合类场景优化,开启设置为1。</p>
</td>
</tr>
<tr id="row17630155212342"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p66309527341"><a name="p66309527341"></a><a name="p66309527341"></a>RI_COMBINED_ENABLE</p>
</td>
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p19630185220345"><a name="p19630185220345"></a><a name="p19630185220345"></a>(可选)非连续三个算子组合类场景优化,开启设置为1。</p>
</td>
</tr>
<tr id="row183041355123411"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p730435533415"><a name="p730435533415"></a><a name="p730435533415"></a>ACL_DUMP_DATA</p>
</td>
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p16304105533412"><a name="p16304105533412"></a><a name="p16304105533412"></a>(可选)算子数据dump功能,调试时使用,开启设置为1。</p>
</td>
</tr>
<tr id="row27481914203518"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p674813144357"><a name="p674813144357"></a><a name="p674813144357"></a>DYNAMIC_OP</p>
</td>
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p974891414353"><a name="p974891414353"></a><a name="p974891414353"></a>(可选)算子实现,ADD和MUL算子在不同场景下有不同的性能表现。默认不设置。</p>
</td>
</tr>
<tr id="row19173161510309"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="zh-cn_topic_0000001152616261_p16711563237"><a name="zh-cn_topic_0000001152616261_p16711563237"></a><a name="zh-cn_topic_0000001152616261_p16711563237"></a>unset GOMP_CPU_AFFINITY</p>
</td>
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="zh-cn_topic_0000001152616261_p0711356152317"><a name="zh-cn_topic_0000001152616261_p0711356152317"></a><a name="zh-cn_topic_0000001152616261_p0711356152317"></a>(可选)当系统为openEuler及其继承操作系统时,如UOS,需设置此命令,取消CPU绑核。</p>
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="zh-cn_topic_0000001152616261_p0711356152317"><a name="zh-cn_topic_0000001152616261_p0711356152317"></a><a name="zh-cn_topic_0000001152616261_p0711356152317"></a>(可选)当系统为openeuler时,需设置此命令,取消CPU绑核。</p>
</td>
</tr>
</tbody>
</table>
<h3 id="安装混合精度模块md">安装混合精度模块</h3>
<h2 id="安装混合精度模块">安装混合精度模块</h2>
#### 前提条件<a name="zh-cn_topic_0000001106176190_section3225481020"></a>
## 前提条件<a name="zh-cn_topic_0000001106176190_section3225481020"></a>
1. 请确保运行环境中适配昇腾AI处理器的PyTorch框架能正常使用。
2. 编译安装Apex前,需参见[配置环境变量](#配置环境变量md)配置好编译过程依赖的环境变量。
2. 编译安装Apex前,需参见[配置环境变量](#配置环境变量)配置好编译过程依赖的环境变量。
#### 安装流程<a name="zh-cn_topic_0000001106176190_section11880164819567"></a>
## 安装流程<a name="zh-cn_topic_0000001106176190_section11880164819567"></a>
1. 以root或非root用户登录服务器。
2. 获取apex源代码。
@@ -329,7 +294,7 @@
1. 运行如下命令,获取适配昇腾AI处理器的apex源代码。
```
git clone https://gitee.com/ascend/apex.git
git clone -b 2.0.2.tr5 https://gitee.com/ascend/apex.git
```
下载的源码主要目录结构如下所示:
@@ -342,6 +307,7 @@
│ ├─gen.sh
│ ├─src # 源码目录
│ ├─tests # 测试用例存放目录
│ ├─README.md
```
2. 运行如下命令,进入“apex“目录,并获取原生apex源代码。
@@ -362,6 +328,7 @@
│ ├─gen.sh
│ ├─src # 源码目录
│ ├─tests # 测试用例存放目录
│ ├─README.md
```
3. 进入原生apex代码目录,即“apex/apex“目录。切换至commitid为4ef930c1c884fdca5f472ab2ce7cb9b505d26c1a的代码分支。
@@ -369,6 +336,7 @@
```
cd apex
git checkout 4ef930c1c884fdca5f472ab2ce7cb9b505d26c1a
cd ..
```
>![](public_sys-resources/icon-note.gif) **说明:**
@@ -391,14 +359,14 @@
python3 setup.py --cpp_ext --npu_float_status bdist_wheel
```
Python版本需与PyTorch使用的Python一致,生成的二进制包在当前的dist目录下,即“apex/apex/dist”文件夹目录下。
生成的二进制包在当前的dist目录下,即“apex/apex/dist”文件夹目录下。
4. <a name="zh-cn_topic_0000001106176190_li425495374416"></a>安装apex。
进入“apex/apex/dist“文件夹目录,执行如下命令安装。
```
pip3 install --upgrade apex-0.1+ascend-cp37-cp37m-linux_{arch}.whl
pip3.7 install --upgrade apex-0.1+ascend-cp37-cp37m-linux_{arch}.whl
```
**\{arch\}**表示架构信息,为aarch64或x86\_64。
@@ -408,16 +376,61 @@
>**pip3 list | grep apex**
<h2 id="参考信息md">参考信息</h2>
<h2 id="使用Ascend-Hub镜像">使用Ascend Hub镜像</h2>
- **[CMake安装方法](#CMake安装方法md)**
- **[Ascend Hub获取PyTorch镜像](#Ascend-Hub获取PyTorch镜像)**
- **[安装7.3.0版本gcc](#安装7-3-0版本gccmd)**
- **[安装“torch-\*.whl ”提示“torch 1.5.0xxxx”与“torchvision”所依赖的版本不匹配](#安装-torch--whl-提示-torch-1-5-0xxxx-与-torchvision-所依赖的版本不匹配md)**
- **[配置环境变量](#配置环境变量-0)**
<h3 id="CMake安装方法md">CMake安装方法</h3>
<h2 id="Ascend-Hub获取PyTorch镜像">Ascend Hub获取PyTorch镜像</h2>
## 前提条件<a name="zh-cn_topic_0000001118701830_zh-cn_topic_0275872734_section108914373254"></a>
- 已完成CANN开发或运行环境的安装,具体操作请参考《[CANN 软件安装指南](https://support.huawei.com/enterprise/zh/doc/EDOC1100206656?idPath=23710424%7C251366513%7C22892968%7C251168373)》。
- 宿主机上已安装Docker。
## 获取并使用镜像<a name="zh-cn_topic_0000001118701830_section108941734162613"></a>
用户可登录[Ascend Hub](https://ascendhub.huawei.com/#/home)获取相应镜像(首次申请需要激活账号)。
当前支持的镜像列表如[表1](#zh-cn_topic_0000001118701830_zh-cn_topic_0000001074498056_table1519011227314)所示。用户可根据实际选择所需的镜像进行下载并使用。
**表 1** 镜像列表
<a name="zh-cn_topic_0000001118701830_zh-cn_topic_0000001074498056_table1519011227314"></a>
<table><thead align="left"><tr id="zh-cn_topic_0000001118701830_zh-cn_topic_0000001074498056_row0190152218319"><th class="cellrowborder" valign="top" width="55.00000000000001%" id="mcps1.2.4.1.1"><p id="zh-cn_topic_0000001118701830_zh-cn_topic_0000001074498056_p1419132211315"><a name="zh-cn_topic_0000001118701830_zh-cn_topic_0000001074498056_p1419132211315"></a><a name="zh-cn_topic_0000001118701830_zh-cn_topic_0000001074498056_p1419132211315"></a>镜像名称</p>
</th>
<th class="cellrowborder" valign="top" width="20%" id="mcps1.2.4.1.2"><p id="zh-cn_topic_0000001118701830_zh-cn_topic_0000001074498056_p75071327115313"><a name="zh-cn_topic_0000001118701830_zh-cn_topic_0000001074498056_p75071327115313"></a><a name="zh-cn_topic_0000001118701830_zh-cn_topic_0000001074498056_p75071327115313"></a>镜像版本</p>
</th>
<th class="cellrowborder" valign="top" width="25%" id="mcps1.2.4.1.3"><p id="zh-cn_topic_0000001118701830_zh-cn_topic_0000001074498056_p1024411406234"><a name="zh-cn_topic_0000001118701830_zh-cn_topic_0000001074498056_p1024411406234"></a><a name="zh-cn_topic_0000001118701830_zh-cn_topic_0000001074498056_p1024411406234"></a>配套CANN版本</p>
</th>
</tr>
</thead>
<tbody><tr id="zh-cn_topic_0000001118701830_zh-cn_topic_0000001074498056_row71915221134"><td class="cellrowborder" valign="top" width="55.00000000000001%" headers="mcps1.2.4.1.1 "><a name="zh-cn_topic_0000001118701830_zh-cn_topic_0000001074498056_ul81691515131910"></a><a name="zh-cn_topic_0000001118701830_zh-cn_topic_0000001074498056_ul81691515131910"></a><ul id="zh-cn_topic_0000001118701830_zh-cn_topic_0000001074498056_ul81691515131910"><li>ARM架构:<a href="https://ascendhub.huawei.com/#/detail?name=ascend-pytorch-arm" target="_blank" rel="noopener noreferrer">ascend-pytorch-arm</a></li><li>x86架构:<a href="https://ascendhub.huawei.com/#/detail?name=ascend-pytorch-x86" target="_blank" rel="noopener noreferrer">ascend-pytorch-x86</a></li></ul>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0000001118701830_zh-cn_topic_0000001074498056_p14648161414516"><a name="zh-cn_topic_0000001118701830_zh-cn_topic_0000001074498056_p14648161414516"></a><a name="zh-cn_topic_0000001118701830_zh-cn_topic_0000001074498056_p14648161414516"></a>21.0.2</p>
</td>
<td class="cellrowborder" valign="top" width="25%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0000001118701830_zh-cn_topic_0000001074498056_p1264815147514"><a name="zh-cn_topic_0000001118701830_zh-cn_topic_0000001074498056_p1264815147514"></a><a name="zh-cn_topic_0000001118701830_zh-cn_topic_0000001074498056_p1264815147514"></a><a href="https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373" target="_blank" rel="noopener noreferrer">5.0.2</a></p>
</td>
</tr>
</tbody>
</table>
<h2 id="配置环境变量-0">配置环境变量</h2>
启动并进入镜像容器后,请参见[配置环境变量](#配置环境变量)配置模型训练依赖的环境变量。
<h2 id="参考信息">参考信息</h2>
- **[CMake安装方法](#CMake安装方法)**
- **[安装7.3.0版本gcc](#安装7-3-0版本gcc)**
- **[安装“torch-\*.whl ”提示“torch 1.5.0xxxx”与“torchvision”所依赖的版本不匹配](#安装-torch--whl-提示-torch-1-5-0xxxx-与-torchvision-所依赖的版本不匹配)**
<h2 id="CMake安装方法">CMake安装方法</h2>
CMake版本升级为3.12.1的方法
@@ -456,7 +469,7 @@ CMake版本升级为3.12.1的方法
如显示“cmake version 3.12.1”则表示安装成功。
<h3 id="安装7-3-0版本gccmd">安装7.3.0版本gcc</h3>
<h2 id="安装7-3-0版本gcc">安装7.3.0版本gcc</h2>
以下步骤请在root用户下执行。
@@ -537,19 +550,19 @@ CMake版本升级为3.12.1的方法
>本步骤为用户在需要用到gcc升级后的编译环境时才配置环境变量。
<h3 id="安装-torch--whl-提示-torch-1-5-0xxxx-与-torchvision-所依赖的版本不匹配md">安装“torch-\*.whl ”提示“torch 1.5.0xxxx”与“torchvision”所依赖的版本不匹配</h3>
<h2 id="安装-torch--whl-提示-torch-1-5-0xxxx-与-torchvision-所依赖的版本不匹配">安装“torch-\*.whl ”提示“torch 1.5.0xxxx”与“torchvision”所依赖的版本不匹配</h2>
#### 现象描述<a name="zh-cn_topic_0000001105856364_zh-cn_topic_0175549220_section197270431505"></a>
## 现象描述<a name="zh-cn_topic_0000001105856364_zh-cn_topic_0175549220_section197270431505"></a>
安装“torch-\*.whl”时,提示"ERROR:torchvision 0.6.0 has requirement torch==1.5.0, but you'll have torch 1.5.0a0+1977093 which is incompatible"。
![](figures/zh-cn_image_0000001190081735.png)
![](figures/zh-cn_image_0000001180656411.png)
#### 可能原因<a name="zh-cn_topic_0000001105856364_zh-cn_topic_0175549220_section169499490501"></a>
## 可能原因<a name="zh-cn_topic_0000001105856364_zh-cn_topic_0175549220_section169499490501"></a>
安装torch时,会自动触发torchvision进行依赖版本检查,环境中安装的torchvision版本为0.6.0,检查时发现我们安装的torch-\*.whl的版本号与要求的1.5.0不一致,所以提示报错,但实际安装成功 。
#### 处理方法<a name="zh-cn_topic_0000001105856364_section108142031907"></a>
## 处理方法<a name="zh-cn_topic_0000001105856364_section108142031907"></a>
对实际结果无影响,无需处理。
Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

@@ -1,46 +1,43 @@
# PyTorch算子开发指南
- [简介](#简介md)
- [算子开发流程](#算子开发流程md)
- [算子开发准备](#算子开发准备md)
- [环境准备](#环境准备md)
- [算子速查](#算子速查md)
- [算子适配开发](#算子适配开发md)
- [前提条件](#前提条件md)
- [获取PyTorch源码](#获取PyTorch源码md)
- [注册算子开发](#注册算子开发md)
- [概述](#概述md)
- [PyTorch1.5.0 注册算子开发](#PyTorch1-5-0-注册算子开发md)
- [PyTorch1.8.1 注册算子开发](#PyTorch1-8-1-注册算子开发md)
- [算子适配插件开发](#算子适配插件开发md)
- [编译和安装PyTorch框架](#编译和安装PyTorch框架md)
- [算子功能验证](#算子功能验证md)
- [概述](#概述-0md)
- [实现过程](#实现过程md)
- [FAQ](#FAQmd)
- [Pillow==5.3.0安装失败](#Pillow-5-3-0安装失败md)
- [pip3.7 install torchvision安装失败](#pip3-7-install-torchvision安装失败md)
- [安装“torch-\*.whl ”提示“torch 1.5.0xxxx”与“torchvision”所依赖的版本不匹配](#安装-torch--whl-提示-torch-1-5-0xxxx-与-torchvision-所依赖的版本不匹配md)
- [如何查看测试的运行日志](#如何查看测试的运行日志md)
- [为什么我实现的“自定义TBE算子”无法调用到?](#为什么我实现的-自定义TBE算子-无法调用到md)
- [如何确定“TBE算子”是否被“PyTorch适配”正确调用](#如何确定-TBE算子-是否被-PyTorch适配-正确调用md)
- [PyTorch编译失败,提示“error: ld returned 1 exit status”](#PyTorch编译失败-提示-error-ld-returned-1-exit-statusmd)
- [PyTorch编译失败,提示“error: call of overload ....”](#PyTorch编译失败-提示-error-call-of-overloadmd)
- [附录](#附录md)
- [CMake安装方法](#CMake安装方法md)
- [自定义算子导出方法](#自定义算子导出方法md)
<h2 id="简介md">简介</h2>
- [简介](#简介)
- [算子开发流程](#算子开发流程)
- [算子开发准备](#算子开发准备)
- [环境准备](#环境准备)
- [算子速查](#算子速查)
- [算子适配开发](#算子适配开发)
- [前提条件](#前提条件)
- [获取PyTorch源码](#获取PyTorch源码)
- [注册算子开发](#注册算子开发)
- [算子适配插件开发](#算子适配插件开发)
- [编译和安装PyTorch框架](#编译和安装PyTorch框架)
- [算子功能验证](#算子功能验证)
- [概述](#概述)
- [实现过程](#实现过程)
- [FAQ](#FAQ)
- [Pillow==5.3.0安装失败](#Pillow-5-3-0安装失败)
- [pip3.7 install torchvision安装失败](#pip3-7-install-torchvision安装失败)
- [安装“torch-\*.whl ”提示“torch 1.5.0xxxx”与“torchvision”所依赖的版本不匹配](#安装-torch--whl-提示-torch-1-5-0xxxx-与-torchvision-所依赖的版本不匹配)
- [如何查看测试的运行日志](#如何查看测试的运行日志)
- [为什么我实现的“自定义TBE算子”无法调用到?](#为什么我实现的-自定义TBE算子-无法调用到)
- [如何确定“TBE算子”是否被“PyTorch适配”正确调用](#如何确定-TBE算子-是否被-PyTorch适配-正确调用)
- [PyTorch编译失败,提示“error: ld returned 1 exit status”](#PyTorch编译失败-提示-error-ld-returned-1-exit-status)
- [PyTorch编译失败,提示“error: call of overload ....”](#PyTorch编译失败-提示-error-call-of-overload)
- [附录](#附录)
- [CMake安装方法](#CMake安装方法)
- [自定义算子导出方法](#自定义算子导出方法)
<h2 id="简介">简介</h2>
### 概述<a name="zh-cn_topic_0000001125558589_section7405182695312"></a>
## 概述<a name="zh-cn_topic_0000001125558589_section7405182695312"></a>
为了实现PyTorch深度学习框架在昇腾AI处理器上运行,需要将框架算子用TBE自定义开发。
<h2 id="算子开发流程md">算子开发流程</h2>
<h2 id="算子开发流程">算子开发流程</h2>
PyTorch算子开发包含TBE算子开发和PyTorch框架下的算子适配。
Pytorch算子开发包含TBE算子开发和PyTorch框架下的算子适配。
1. TBE算子开发:昇腾AI软件栈中不包含相应的算子,需要先完成TBE算子的开发,再进行PyTorch框架下的算子适配。
TBE算子开发流程及方法请参见《CANN TBE自定义算子开发指南》。
TBE算子开发流程及方法请参见《CANN TBE自定义算子开发指南](https://support.huawei.com/enterprise/zh/doc/EDOC1100206660)》。
2. PyTorch框架下的算子适配:昇腾AI软件栈中已实现了相应的TBE算子,可直接进行PyTorch框架适配。
@@ -69,7 +66,7 @@ PyTorch算子开发包含TBE算子开发和PyTorch框架下的算子适配。
</td>
<td class="cellrowborder" valign="top" width="55.55123090396029%" headers="mcps1.2.5.1.3 "><p id="zh-cn_topic_0000001105032530_p1381018121891"><a name="zh-cn_topic_0000001105032530_p1381018121891"></a><a name="zh-cn_topic_0000001105032530_p1381018121891"></a>准备算子开发及运行验证所依赖的开发环境与运行环境。</p>
</td>
<td class="cellrowborder" rowspan="2" valign="top" width="19.772307093509777%" headers="mcps1.2.5.1.4 "><p id="zh-cn_topic_0000001105032530_p1498205181013"><a name="zh-cn_topic_0000001105032530_p1498205181013"></a><a name="zh-cn_topic_0000001105032530_p1498205181013"></a><a href="#算子开发准备md">算子开发准备</a></p>
<td class="cellrowborder" rowspan="2" valign="top" width="19.772307093509777%" headers="mcps1.2.5.1.4 "><p id="zh-cn_topic_0000001105032530_p1498205181013"><a name="zh-cn_topic_0000001105032530_p1498205181013"></a><a name="zh-cn_topic_0000001105032530_p1498205181013"></a><a href="#算子开发准备">算子开发准备</a></p>
</td>
</tr>
<tr id="zh-cn_topic_0000001105032530_row194671091290"><td class="cellrowborder" valign="top" headers="mcps1.2.5.1.1 "><p id="zh-cn_topic_0000001105032530_p3467169594"><a name="zh-cn_topic_0000001105032530_p3467169594"></a><a name="zh-cn_topic_0000001105032530_p3467169594"></a>2</p>
@@ -86,7 +83,7 @@ PyTorch算子开发包含TBE算子开发和PyTorch框架下的算子适配。
</td>
<td class="cellrowborder" valign="top" width="55.55123090396029%" headers="mcps1.2.5.1.3 "><p id="zh-cn_topic_0000001105032530_zh-cn_topic_0228422310_p381282212"><a name="zh-cn_topic_0000001105032530_zh-cn_topic_0228422310_p381282212"></a><a name="zh-cn_topic_0000001105032530_zh-cn_topic_0228422310_p381282212"></a>获取昇腾社区PyTorch源码。</p>
</td>
<td class="cellrowborder" rowspan="4" valign="top" width="19.772307093509777%" headers="mcps1.2.5.1.4 "><p id="zh-cn_topic_0000001105032530_p10679152717175"><a name="zh-cn_topic_0000001105032530_p10679152717175"></a><a name="zh-cn_topic_0000001105032530_p10679152717175"></a><a href="#算子开发准备md">算子适配开发</a></p>
<td class="cellrowborder" rowspan="4" valign="top" width="19.772307093509777%" headers="mcps1.2.5.1.4 "><p id="zh-cn_topic_0000001105032530_p10679152717175"><a name="zh-cn_topic_0000001105032530_p10679152717175"></a><a name="zh-cn_topic_0000001105032530_p10679152717175"></a><a href="#算子开发准备">算子适配开发</a></p>
</td>
</tr>
<tr id="zh-cn_topic_0000001105032530_row1184984391512"><td class="cellrowborder" valign="top" headers="mcps1.2.5.1.1 "><p id="zh-cn_topic_0000001105032530_p1054075616153"><a name="zh-cn_topic_0000001105032530_p1054075616153"></a><a name="zh-cn_topic_0000001105032530_p1054075616153"></a>4</p>
@@ -116,43 +113,55 @@ PyTorch算子开发包含TBE算子开发和PyTorch框架下的算子适配。
</td>
<td class="cellrowborder" valign="top" width="55.55123090396029%" headers="mcps1.2.5.1.3 "><p id="zh-cn_topic_0000001105032530_zh-cn_topic_0228422310_p4952132615216"><a name="zh-cn_topic_0000001105032530_zh-cn_topic_0228422310_p4952132615216"></a><a name="zh-cn_topic_0000001105032530_zh-cn_topic_0228422310_p4952132615216"></a>在真实的硬件环境中验证算子功能。</p>
</td>
<td class="cellrowborder" valign="top" width="19.772307093509777%" headers="mcps1.2.5.1.4 "><p id="zh-cn_topic_0000001105032530_zh-cn_topic_0228422310_p20908934557"><a name="zh-cn_topic_0000001105032530_zh-cn_topic_0228422310_p20908934557"></a><a name="zh-cn_topic_0000001105032530_zh-cn_topic_0228422310_p20908934557"></a><a href="#算子功能验证md">算子功能验证</a></p>
<td class="cellrowborder" valign="top" width="19.772307093509777%" headers="mcps1.2.5.1.4 "><p id="zh-cn_topic_0000001105032530_zh-cn_topic_0228422310_p20908934557"><a name="zh-cn_topic_0000001105032530_zh-cn_topic_0228422310_p20908934557"></a><a name="zh-cn_topic_0000001105032530_zh-cn_topic_0228422310_p20908934557"></a><a href="#算子功能验证">算子功能验证</a></p>
</td>
</tr>
</tbody>
</table>
<h2 id="算子开发准备md">算子开发准备</h2>
<h2 id="算子开发准备">算子开发准备</h2>
- **[环境准备](#环境准备md)**
- **[环境准备](#环境准备)**
- **[算子速查](#算子速查md)**
- **[算子速查](#算子速查)**
<h3 id="环境准备md">环境准备</h3>
<h2 id="环境准备">环境准备</h2>
- 需完成CANN开发或运行环境的安装,具体操作请参考《CANN 软件安装指南》。
- 需安装python版本为3.7.5或3.8。
- 需安装3.12.0及以上版本的CMake,安装方法请参考[CMake安装方法](#CMake安装方法md)。
- 需确保已安装7.3.0以上版本的gcc,7.3.0版本gcc具体安装及使用方式请参见《CANN 软件安装指南》中的“安装7.3.0版本gcc”章节。
## 前提条件<a name="zh-cn_topic_0000001125736787_section12464163765320"></a>
- 需完成CANN开发或运行环境的安装,具体操作请参考《CANN 软件安装指南](https://support.huawei.com/enterprise/zh/doc/EDOC1100206656?idPath=23710424%7C251366513%7C22892968%7C251168373)》。
- 需安装3.12.0及以上版本的CMake,安装方法请参考[CMake安装方法](#CMake安装方法)。
- 需确保已安装7.3.0以上版本的gcc,7.3.0版本gcc具体安装及使用方式请参见《CANN 软件安装指南](https://support.huawei.com/enterprise/zh/doc/EDOC1100206656?idPath=23710424%7C251366513%7C22892968%7C251168373)》中的“安装7.3.0版本gcc”章节。
- 需确保环境中已安装git工具,以Ubuntu和CentOS系统为例,命令如下:
- Ubuntu系统
```
apt-get install patch
apt-get install git
```
- CentOS系统
```
yum install patch
yum install git
```
<h3 id="算子速查md">算子速查</h3>
## 安装PyTorch依赖环境<a name="zh-cn_topic_0000001125736787_section18699192116550"></a>
如果使用非root用户安装Python及其依赖,用户需要在每句命令末尾加上**--user**,保证安装的正常进行。命令示例为:**pip3.7 install pyyaml --user**
```
pip3.7 install pyyaml
pip3.7 install wheel
pip3.7 install Pillow==5.3.0
```
>![](public_sys-resources/icon-note.gif) **说明:**
>若以上过程出错,请参考[FAQ](#FAQ)尝试解决问题。
<h2 id="算子速查">算子速查</h2>
进行算子开发时,您可以查询当前昇腾AI处理器中支持的算子列表和当前PyTorch适配的算子列表。根据查询结果进行算子开发或PyTorch算子适配。
@@ -163,49 +172,49 @@ PyTorch算子开发包含TBE算子开发和PyTorch框架下的算子适配。
昇腾AI处理器和PyTorch适配的算子查询方式如下。
- 当前昇腾AI处理器中支持的算子以及对应的算子约束可以通过以下两种方式查询。
- 命令行开发方式下,您可以参见《CANN 算子清单 \(Ascend 910\)》进行离线查询。
- MindStudio开发方式下,您可以通过MindStudio进行在线查询,详细查看方法可参见《MindStudio 用户指南》中的“算子&模型速查”章节。
- 命令行开发方式下,您可以参见《[CANN 算子清单 \(Ascend 910\)](https://support.huawei.com/enterprise/zh/doc/EDOC1100206663)》进行离线查询。
- MindStudio开发方式下,您可以通过MindStudio进行在线查询,详细查看方法可参见《[MindStudio 用户指南](https://support.huaweicloud.com/mindstudio302/)》中的“算子&模型速查”章节。
- 当前PyTorch适配的算子列表可以参见《PyTorch适配算子清单》。
- 当前PyTorch适配的算子列表可以参见《[PyTorch适配算子清单](https://gitee.com/ascend/pytorch/blob/2.0.2.tr5/docs/zh/PyTorch%E9%80%82%E9%85%8D%E7%AE%97%E5%AD%90%E6%B8%85%E5%8D%95/PyTorch%E9%80%82%E9%85%8D%E7%AE%97%E5%AD%90%E6%B8%85%E5%8D%95.md)》。
<h2 id="算子适配开发md">算子适配开发</h2>
<h2 id="算子适配开发">算子适配开发</h2>
- **[前提条件](#前提条件md)**
- **[前提条件](#前提条件)**
- **[获取PyTorch源码](#获取PyTorch源码md)**
- **[获取PyTorch源码](#获取PyTorch源码)**
- **[注册算子开发](#注册算子开发md)**
- **[注册算子开发](#注册算子开发)**
- **[算子适配插件开发](#算子适配插件开发md)**
- **[算子适配插件开发](#算子适配插件开发)**
- **[编译和安装PyTorch框架](#编译和安装PyTorch框架md)**
- **[编译和安装PyTorch框架](#编译和安装PyTorch框架)**
<h3 id="前提条件md">前提条件</h3>
<h2 id="前提条件">前提条件</h2>
- 完成开发及运行环境准备及相关依赖的安装,详情请参见[环境准备](#环境准备md)。
- 完成相关的TBE算子开发及部署,详情请参见《CANN TBE自定义算子开发指南》。
- 完成开发及运行环境准备及相关依赖的安装,详情请参见[环境准备](#环境准备)。
- 完成相关的TBE算子开发及部署,详情请参见《[CANN TBE自定义算子开发指南](https://support.huawei.com/enterprise/zh/doc/EDOC1100206660)》。
<h3 id="获取PyTorch源码md">获取PyTorch源码</h3>
<h2 id="获取PyTorch源码">获取PyTorch源码</h2>
目前只支持PyTorch1.5.0和1.8.1版本,PyTorch源码获取请参见《PyTorch安装指南》中“安装PyTorch框架”章节,完成在"pytorch/pytorch"目录生成适配昇腾AI处理器的全量代码步骤。将在pytorch/pytorch目录中进行PyTorch 算子适配开发。
从gitee上获取适配昇腾AI处理器的PyTorch源代码,获取地址为: [https://gitee.com/ascend/pytorch-develop](https://gitee.com/ascend/pytorch-develop) 。用户可以通过执行下面git命令行下载源代码。
<h3 id="注册算子开发md">注册算子开发</h3>
```
git clone https://gitee.com/ascend/pytorch-develop.git --deepth=1
```
- **[概述](#概述md)**
下载成功后,得到pytorch文件目录。
- **[PyTorch1.5.0 注册算子开发](#PyTorch1-5-0-注册算子开发md)**
>![](public_sys-resources/icon-note.gif) **说明:**
>如无权限获取代码,请联系华为技术支持申请加入“Ascend”组织。
- **[PyTorch1.8.1 注册算子开发](#PyTorch1-8-1-注册算子开发md)**
<h2 id="注册算子开发">注册算子开发</h2>
<h4 id="概述md">概述</h4>
## 概述<a name="zh-cn_topic_0000001125315887_section693616257599"></a>
当前制定的NPU适配派发原则是NPU算子的派发不经过框架公共函数,直接派发成NPU适配的函数,即算子执行调用栈中只包含NPU适配的函数调用,不包含框架公共函数。PyTorch框架在编译时,会根据 native\_functions.yaml 的定义,按框架中定义的类型和设备分发原则,生成相应的新算子的中间层的调用说明。对于NPU,会生成在 build/aten/src/ATen/NPUType.cpp。
<h4 id="PyTorch1-5-0-注册算子开发md">PyTorch1.5.0 注册算子开发</h4>
##### 注册算子开发方法<a name="section575212111125"></a>
## 注册算子开发方法<a name="zh-cn_topic_0000001125315887_section16610942811"></a>
1. 打开native\_functions.yaml文件。
@@ -218,7 +227,7 @@ PyTorch算子开发包含TBE算子开发和PyTorch框架下的算子适配。
- yaml中未存在的自定义算子
由于yaml中没有相关算子的信息,需要手动添加相关函数,包括函数名,参数信息,返回类型信息。添加规则及方法请参见“pytorch/aten/src/ATen/native/README.md“。
由于yaml中没有相关算子的信息,需要手动添加相关函数,包括函数名,参数信息,返回类型信息。
```
- func:适配算子名称(输入参数信息) -> 返回类型
@@ -249,7 +258,7 @@ PyTorch算子开发包含TBE算子开发和PyTorch框架下的算子适配。
>该格式供参考,算子适配开发过程中的函数名需与NPU\_Adapt\_Fun\_Name保持一致。
##### 示例<a name="section434031421219"></a>
## 示例<a name="zh-cn_topic_0000001125315887_section3651235962"></a>
以torch.add\(\)算子为例介绍注册算子开发过程。
@@ -335,101 +344,13 @@ PyTorch算子开发包含TBE算子开发和PyTorch框架下的算子适配。
<h4 id="PyTorch1-8-1-注册算子开发md">PyTorch1.8.1 注册算子开发</h4>
<h2 id="算子适配插件开发">算子适配插件开发</h2>
##### 注册算子开发方法<a name="section575212111125"></a>
1. 打开native\_functions.yaml文件。
native\_functions.yaml 文件中,定义了所有算子函数原型,包括函数名称和参数等信息,每个算子函数支持不同硬件平台的派发信息。该文件所在路径为pytorch/aten/src/ATen/native/native\_functions.yaml。
2. 确定需要派发函数。
- yaml 中已存在的算子
将所有与待适配算子相关的函数进行派发。
- yaml中未存在的自定义算子
由于yaml中没有相关算子的信息,需要手动添加相关函数,包括函数名,参数信息,返回类型信息。添加规则及方法请参见“pytorch/aten/src/ATen/native/README.md“。
```
- func:适配算子名称(输入参数信息) -> 返回类型
```
##### 示例<a name="section434031421219"></a>
以torch.add\(\)算子为例介绍注册算子开发过程。
1. 打开native\_functions.yaml文件。
2. 搜索相关函数。
在yaml中搜索add,找到与add算子相关的函数描述func。由于add是PyTorch内置算子,不需要手动添加func。若是自定义算子,需要手动添加func。
3. 确定算子相关函数名称及其类型的func描述。
- add.Tensor 的函数分发描述。
```
- func: add.Tensor(Tensor self, Tensor other, *, Scalar alpha=1) -> Tensor
structured_delegate: add.out
variants: function, method
dispatch:
SparseCPU, SparseCUDA: add_sparse
MkldnnCPU: mkldnn_add
```
- add.Scalar 的函数分发描述。
```
- func: add.Scalar(Tensor self, Scalar other, Scalar alpha=1) -> Tensor
variants: function, method
dispatch:
DefaultBackend: add
```
- add\_.Tensor 的函数分发描述。
```
- func: add_.Tensor(Tensor(a!) self, Tensor other, *, Scalar alpha=1) -> Tensor(a!)
variants: method
structured_delegate: add.out
dispatch:
SparseCPU, SparseCUDA: add_sparse_
MkldnnCPU: mkldnn_add_
```
- add\_.Scalar 的函数分发描述。
```
- func: add_.Scalar(Tensor(a!) self, Scalar other, Scalar alpha=1) -> Tensor(a!)
variants: method
dispatch:
DefaultBackend: add_
```
- add.out 的函数分发描述。
```
- func: add.out(Tensor self, Tensor other, *, Scalar alpha=1, Tensor(a!) out) -> Tensor(a!)
structured: True
structured_inherits: TensorIteratorBase
dispatch:
CPU, CUDA: add_out
SparseCPU: add_out_sparse_cpu
SparseCUDA: add_out_sparse_cuda
MkldnnCPU: mkldnn_add_out
```
<h3 id="算子适配插件开发md">算子适配插件开发</h3>
#### 简介<a name="zh-cn_topic_0000001125315877_section16410139174517"></a>
## 简介<a name="zh-cn_topic_0000001125315877_section16410139174517"></a>
用户通过开发算子适配插件,实现PyTorch原生算子的输入参数、输出参数和属性的格式转换,使转换后的格式与TBE算子的输入参数、输出参数和属性的格式相同。适配昇腾AI处理器的PyTorch源代码中提供了适配关联、类型转换和判别、处理动态shape等相关的方法供用户使用。
#### 适配插件实现<a name="zh-cn_topic_0000001125315877_section1174074518456"></a>
## 适配插件实现<a name="zh-cn_topic_0000001125315877_section1174074518456"></a>
1. 创建适配插件文件。
@@ -450,23 +371,8 @@ PyTorch算子开发包含TBE算子开发和PyTorch框架下的算子适配。
实现算子适配主题函数,根据TBE算子原型构造得到对应的input、output、attr。
5. (仅1.8.1版本需要操作该步骤)使用TORCH\_LIBRARY\_IMPL宏关联注册算子开发中native\_functions.yaml文件的算子描述func。
TORCH\_LIBRARY\_IMPL是PyTorch提供的用于注册算子分发的宏,使用方法如下。
```
Torch_LIBRARY_IMPL(aten, PrivateUse1, m){
m.impl("yaml中算子func方法名1", TORCH_FN("对应的适配主体函数名1"))
m.impl("yaml中算子func方法名2", TORCH_FN("对应的适配主体函数名2"))
}
```
- aten为命名空间,可以根据实现文件命名空间自行定义。
- PrivateUse1为dispatchKey, 固定设置NPU。
- m为固定字段。
#### 示例<a name="zh-cn_topic_0000001125315877_section18021337113012"></a>
## 示例<a name="zh-cn_topic_0000001125315877_section18021337113012"></a>
以torch.add\(\)算子为例介绍算子适配开发过程。
@@ -618,85 +524,79 @@ PyTorch算子开发包含TBE算子开发和PyTorch框架下的算子适配。
}
```
5. (仅1.8.1版本需要操作该步骤)使用TORCH\_LIBRARY\_IMPL宏关联注册算子。
```
TORCH_LIBRARY_IMPL(aten, NPU, m) {
m.impl("add.Tensor", TORCH_FN(add_npu));
m.impl("add_.Tensor", TORCH_FN(add_npu_));
m.impl("add.out", TORCH_FN(add_out_npu));}
```
>![](public_sys-resources/icon-note.gif) **说明:**
>AddKernelNpu.cpp的详细实现代码请参见pytorch/aten/src/ATen/native/npu/AddKernelNpu.cpp文档。
<h3 id="编译和安装PyTorch框架md">编译和安装PyTorch框架</h3>
<h2 id="编译和安装PyTorch框架">编译和安装PyTorch框架</h2>
#### 编译PyTorch框架<a name="zh-cn_topic_0000001125736777_section470105143317"></a>
## 编译PyTorch框架<a name="zh-cn_topic_0000001125736777_section470105143317"></a>
1. 进入PyTorch工作目录 :“pytorch/pytorch“。
2. 依赖库安装。
1. 进入PyTorch工作目录 :“pytorch“。
2. 给脚本文件赋权限:
**chmod +x build.sh**
3. 执行如下命令进行编译:
**./build.sh**
>![](public_sys-resources/icon-note.gif) **说明:**
>首次编译持续的时间较长,可能超过30分钟,建议:若无必要,无需执行"make clean"。
4. 编译成功后,会在“**pytorch/dist**” 下生成 torch-\*.whl 包,例如:torch-1.5.0a0-cp37-cp37m-linux\_x86.whl。
## 安装PyTorch框架<a name="zh-cn_topic_0000001125736777_section119821419153412"></a>
1. 将[编译和安装PyTorch框架](#编译和安装PyTorch框架)生成的torch-\*.whl包上传到服务器任一路径。
2. 进入torch-\*.whl 所在的目录,使用pip命令完成torch安装。
当前登录用户为root用户时,执行:
```
pip3 install -r requirements.txt
pip3.7 install torch-*.whl
```
3. 编译生成pytorch的二进制安装包。
当前登录用户为非root用户时,执行:
```
bash build.sh --python=3.7
或
bash build.sh --python=3.8
pip3.7 install torch-*.whl --user
```
请指定环境中python版本进行编译。编译成功后,会在pytorch/pytorch/dist”文件夹目录下生成二进制包 torch-\*.whl ,例如:torch-1.5.0+ascend.post3-cp37-cp37m-linux\_x86.whl或者torch-1.8.1+ascend-cp37-cp37m-linux\_x86.whl。
#### 安装PyTorch框架<a name="zh-cn_topic_0000001125736777_section119821419153412"></a>
进入“pytorch/pytorch/dist“文件夹目录,执行如下命令安装。
```
pip3 install --upgrade torch-1.5.0+ascend.post3-cp37-cp37m-linux_{arch}.whl
```
**\{arch\}**表示架构信息,为aarch64或x86\_64。
>![](public_sys-resources/icon-note.gif) **说明:**
>若环境中已安装PyTorch时,需要先卸载环境中已安装的PyTorch软件包再执行,可以通过执行如下命令查询环境上是否已安装PyTorch。
>**pip3 list | grep torch**
>- 修改代码之后,需要重新执行“编译”和“安装”PyTorch过程。
>- 安装过程中,可能会出现错误提示"torchvision 0.6.0" 版本不匹配,此问题无影响,忽略即可。
修改代码之后,需要重新执行“编译”和“安装”PyTorch过程。
<h2 id="算子功能验证">算子功能验证</h2>
<h2 id="算子功能验证md">算子功能验证</h2>
- **[概述](#概述)**
- **[概述](#概述-0md)**
- **[实现过程](#实现过程md)**
- **[实现过程](#实现过程)**
<h3 id="概述-0md">概述</h3>
<h2 id="概述">概述</h2>
#### 简介<a name="zh-cn_topic_0000001117556616_section29881459155718"></a>
## 简介<a name="zh-cn_topic_0000001117556616_section29881459155718"></a>
完成算子适配开发后,可通过运行适配昇腾处理器的PyTorch算子,验证算子运行结果是否正确。
算子功能验证会覆盖算子开发的所有交付件,包含实现文件,算子原型定义、算子信息库以及算子适配插件。本节仅对验证的方法做介绍。
#### 测试用例及测试工具<a name="zh-cn_topic_0000001117556616_section158972351160"></a>
## 测试用例及测试工具<a name="zh-cn_topic_0000001117556616_section158972351160"></a>
进行自定义算子功能验证,通过PyTorch前端构造自定义算子的函数并运行验证。
在https://gitee.com/ascend/pytorch中 "pytorch/test/test\_npu"目录下提供了测试用例及测试工具,供用户参考。
在https://gitee.com/ascend/pytorch-develop中 "pytorch/test/test\_npu/test\_network\_ops"目录下提供了测试用例及测试工具,供用户参考。
<h3 id="实现过程md">实现过程</h3>
<h2 id="实现过程">实现过程</h2>
#### 简介<a name="zh-cn_topic_0000001164276377_section29881459155718"></a>
## 简介<a name="zh-cn_topic_0000001164276377_section29881459155718"></a>
本章通过具体例子,完成PyTorch算子的功能测试步骤。
#### 操作步骤<a name="zh-cn_topic_0000001164276377_section02504494109"></a>
## 操作步骤<a name="zh-cn_topic_0000001164276377_section02504494109"></a>
1. 设置环境变量。
@@ -705,6 +605,8 @@ pip3 install --upgrade torch-1.5.0+ascend.post3-cp37-cp37m-linux_{arch}.whl
. /home/HwHiAiUser/Ascend/ascend-toolkit/set_env.sh
```
install\_path请修改为Toolkit的实际安装路径。
2. 编写测试脚本。以add算子为例,在“pytorch/test/test\_npu/test\_network\_ops“路径下编写测试脚本文件: test\_add.py。
以下示例仅为一个简单的用例实现供用户参考,具体测试用例的实现,需要根据算子定义进行完整的覆盖才能保证功能的基本正确。
@@ -733,7 +635,7 @@ pip3 install --upgrade torch-1.5.0+ascend.post3-cp37-cp37m-linux_{arch}.whl
output = output.numpy()
return output
# 定义add对应场景通用函数,该函数负责输入数据并对比CPU和NPU的计算结果
# 定义add对应场景通用函数,该函数中负责场景对应输入数据和对比CPU和NPU返回结果
def add_result(self, shape_format):
for item in shape_format:
cpu_input1, npu_input1 = create_common_tensor(item, 0, 100)
@@ -756,7 +658,10 @@ pip3 install --upgrade torch-1.5.0+ascend.post3-cp37-cp37m-linux_{arch}.whl
instantiate_device_type_tests(TestAdd, globals(), except_for="cpu")
if __name__ == "__main__":
torch.npu.set_device("npu:0")
run_tests()
```
3. 执行测试用例脚本
@@ -768,36 +673,36 @@ pip3 install --upgrade torch-1.5.0+ascend.post3-cp37-cp37m-linux_{arch}.whl
```
<h2 id="FAQmd">FAQ</h2>
<h2 id="FAQ">FAQ</h2>
- **[Pillow==5.3.0安装失败](#Pillow-5-3-0安装失败md)**
- **[Pillow==5.3.0安装失败](#Pillow-5-3-0安装失败)**
- **[pip3.7 install torchvision安装失败](#pip3-7-install-torchvision安装失败md)**
- **[pip3.7 install torchvision安装失败](#pip3-7-install-torchvision安装失败)**
- **[安装“torch-\*.whl ”提示“torch 1.5.0xxxx”与“torchvision”所依赖的版本不匹配](#安装-torch--whl-提示-torch-1-5-0xxxx-与-torchvision-所依赖的版本不匹配md)**
- **[安装“torch-\*.whl ”提示“torch 1.5.0xxxx”与“torchvision”所依赖的版本不匹配](#安装-torch--whl-提示-torch-1-5-0xxxx-与-torchvision-所依赖的版本不匹配)**
- **[如何查看测试的运行日志](#如何查看测试的运行日志md)**
- **[如何查看测试的运行日志](#如何查看测试的运行日志)**
- **[为什么我实现的“自定义TBE算子”无法调用到?](#为什么我实现的-自定义TBE算子-无法调用到md)**
- **[为什么我实现的“自定义TBE算子”无法调用到?](#为什么我实现的-自定义TBE算子-无法调用到)**
- **[如何确定“TBE算子”是否被“PyTorch适配”正确调用](#如何确定-TBE算子-是否被-PyTorch适配-正确调用md)**
- **[如何确定“TBE算子”是否被“PyTorch适配”正确调用](#如何确定-TBE算子-是否被-PyTorch适配-正确调用)**
- **[PyTorch编译失败,提示“error: ld returned 1 exit status”](#PyTorch编译失败-提示-error-ld-returned-1-exit-statusmd)**
- **[PyTorch编译失败,提示“error: ld returned 1 exit status”](#PyTorch编译失败-提示-error-ld-returned-1-exit-status)**
- **[PyTorch编译失败,提示“error: call of overload ....”](#PyTorch编译失败-提示-error-call-of-overloadmd)**
- **[PyTorch编译失败,提示“error: call of overload ....”](#PyTorch编译失败-提示-error-call-of-overload)**
<h3 id="Pillow-5-3-0安装失败md">Pillow==5.3.0安装失败</h3>
<h2 id="Pillow-5-3-0安装失败">Pillow==5.3.0安装失败</h2>
#### 现象描述<a name="zh-cn_topic_0000001125315879_zh-cn_topic_0175549220_section197270431505"></a>
## 现象描述<a name="zh-cn_topic_0000001125315879_zh-cn_topic_0175549220_section197270431505"></a>
pillow==5.3.0安装失败。
#### 可能原因<a name="zh-cn_topic_0000001125315879_zh-cn_topic_0175549220_section169499490501"></a>
## 可能原因<a name="zh-cn_topic_0000001125315879_zh-cn_topic_0175549220_section169499490501"></a>
缺少必要的依赖,如:libjpeg、python-devel、 zlib-devel 、libjpeg-turbo-devel等等。
#### 处理方法<a name="zh-cn_topic_0000001125315879_section108142031907"></a>
## 处理方法<a name="zh-cn_topic_0000001125315879_section108142031907"></a>
执行以下命令安装所需依赖。
@@ -805,17 +710,17 @@ pillow==5.3.0安装失败。
apt-get install libjpeg python-devel zlib-devel libjpeg-turbo-devel
```
<h3 id="pip3-7-install-torchvision安装失败md">pip3.7 install torchvision安装失败</h3>
<h2 id="pip3-7-install-torchvision安装失败">pip3.7 install torchvision安装失败</h2>
#### 现象描述<a name="zh-cn_topic_0000001125641109_zh-cn_topic_0175549220_section197270431505"></a>
## 现象描述<a name="zh-cn_topic_0000001125641109_zh-cn_topic_0175549220_section197270431505"></a>
pip3.7 install torchvision安装失败。
#### 可能原因<a name="zh-cn_topic_0000001125641109_zh-cn_topic_0175549220_section169499490501"></a>
## 可能原因<a name="zh-cn_topic_0000001125641109_zh-cn_topic_0175549220_section169499490501"></a>
torch与torchvision版本不匹配。
#### 处理方法<a name="zh-cn_topic_0000001125641109_section108142031907"></a>
## 处理方法<a name="zh-cn_topic_0000001125641109_section108142031907"></a>
执行以下命令。
@@ -823,25 +728,25 @@ torch与torchvision版本不匹配。
pip3.7 install torchvision --no-deps
```
<h3 id="安装-torch--whl-提示-torch-1-5-0xxxx-与-torchvision-所依赖的版本不匹配md">安装“torch-\*.whl ”提示“torch 1.5.0xxxx”与“torchvision”所依赖的版本不匹配</h3>
<h2 id="安装-torch--whl-提示-torch-1-5-0xxxx-与-torchvision-所依赖的版本不匹配">安装“torch-\*.whl ”提示“torch 1.5.0xxxx”与“torchvision”所依赖的版本不匹配</h2>
#### 现象描述<a name="zh-cn_topic_0000001125315883_zh-cn_topic_0175549220_section197270431505"></a>
## 现象描述<a name="zh-cn_topic_0000001125315883_zh-cn_topic_0175549220_section197270431505"></a>
安装“torch-\*.whl”时,提示"ERROR:torchvision 0.6.0 has requirement torch==1.5.0, but you'll have torch 1.5.0a0+1977093 which is incompatible"。
![](figures/zh-cn_image_0000001144082048.png)
![](figures/zh-cn_image_0000001172886189.png)
但实际安装成功
#### 可能原因<a name="zh-cn_topic_0000001125315883_zh-cn_topic_0175549220_section169499490501"></a>
## 可能原因<a name="zh-cn_topic_0000001125315883_zh-cn_topic_0175549220_section169499490501"></a>
安装torch时,会自动触发torchvision进行依赖版本检查,环境中安装的torchvision版本为0.6.0,检查时发现我们安装的torch-\*.whl的版本号与要求的1.5.0不一致,所以提示了一条错误 。
#### 处理方法<a name="zh-cn_topic_0000001125315883_section108142031907"></a>
## 处理方法<a name="zh-cn_topic_0000001125315883_section108142031907"></a>
对实际结果无影响,无需处理。
<h3 id="如何查看测试的运行日志md">如何查看测试的运行日志</h3>
<h2 id="如何查看测试的运行日志">如何查看测试的运行日志</h2>
测试运行过程提示错误,但直接可参考的信息太少,如何才能看到更详细的运行日志?
@@ -862,21 +767,21 @@ pip3.7 install torchvision --no-deps
```
<h3 id="为什么我实现的-自定义TBE算子-无法调用到md">为什么我实现的“自定义TBE算子”无法调用到?</h3>
<h2 id="为什么我实现的-自定义TBE算子-无法调用到">为什么我实现的“自定义TBE算子”无法调用到?</h2>
#### 现象描述<a name="zh-cn_topic_0000001125736795_zh-cn_topic_0175549220_section197270431505"></a>
## 现象描述<a name="zh-cn_topic_0000001125736795_zh-cn_topic_0175549220_section197270431505"></a>
完成“自定义TBE算子”开发,和“PyTorch”适配开发,但执行测试用例,发现无法调用到新开发的算子。
#### 可能原因<a name="zh-cn_topic_0000001125736795_zh-cn_topic_0175549220_section169499490501"></a>
## 可能原因<a name="zh-cn_topic_0000001125736795_zh-cn_topic_0175549220_section169499490501"></a>
- 环境变量没有正确设置。
- yaml存在错误,导致没有正确分发。
- 自定义TBE算子实现存在问题,导致无法调用到。
#### 处理方法<a name="zh-cn_topic_0000001125736795_section108142031907"></a>
## 处理方法<a name="zh-cn_topic_0000001125736795_section108142031907"></a>
1. 参考“[算子功能验证](#算子功能验证md)”章节,完成运行环境设置,特别注意:
1. 参考“[算子功能验证](#算子功能验证)”章节,完成运行环境设置,特别注意:
```
. /home/HwHiAiUser/Ascend/ascend-toolkit/set_env.sh
@@ -888,7 +793,7 @@ pip3.7 install torchvision --no-deps
"pytorch/aten/src/ATen/native/npu/AddKernelNpu.cpp"
![](figures/zh-cn_image_0000001144082088.png)
![](figures/zh-cn_image_0000001126846510.png)
2. 完成上两步的编译、安装,调用“python3.7 test\_add.py”进行测试。
@@ -916,7 +821,7 @@ pip3.7 install torchvision --no-deps
<h3 id="如何确定-TBE算子-是否被-PyTorch适配-正确调用md">如何确定“TBE算子”是否被“PyTorch适配”正确调用</h3>
<h2 id="如何确定-TBE算子-是否被-PyTorch适配-正确调用">如何确定“TBE算子”是否被“PyTorch适配”正确调用</h2>
不管是“custom”算子,还是“built-in”算子,在安装后,都是以\*.py源码的方式存放在安装目录下,所以我们可以通过编辑源码,在API入口增加日志的方式,打印输出入参,确定输入的参数是否正确。
@@ -934,7 +839,7 @@ pip3.7 install torchvision --no-deps
可以看到相应的算子\*.py源码文件均为“只读”,即此时不可编辑。
![](figures/zh-cn_image_0000001190081791.png)
![](figures/zh-cn_image_0000001127006336.png)
2. 修改算子\*.py源码文件属性,增加“可写”权限。
@@ -943,7 +848,7 @@ pip3.7 install torchvision --no-deps
ll
```
![](figures/zh-cn_image_0000001190081803.png)
![](figures/zh-cn_image_0000001172886191.png)
3. 打开算子\*.py源码文件,增加日志,保存退出。
@@ -951,7 +856,7 @@ pip3.7 install torchvision --no-deps
vi zn_2_nchw.py
```
![](figures/zh-cn_image_0000001190201951.png)
![](figures/zh-cn_image_0000001173046109.png)
上面例子只加了个标识,实际调测时,可以增加打印输入参数信息。
@@ -963,61 +868,61 @@ pip3.7 install torchvision --no-deps
sudo chmod -w zn_2_nchw.py
```
![](figures/zh-cn_image_0000001144082072.png)
![](figures/zh-cn_image_0000001126846512.png)
<h3 id="PyTorch编译失败-提示-error-ld-returned-1-exit-statusmd">PyTorch编译失败,提示“error: ld returned 1 exit status”</h3>
<h2 id="PyTorch编译失败-提示-error-ld-returned-1-exit-status">PyTorch编译失败,提示“error: ld returned 1 exit status”</h2>
#### 现象描述<a name="zh-cn_topic_0000001125315885_zh-cn_topic_0175549220_section197270431505"></a>
## 现象描述<a name="zh-cn_topic_0000001125315885_zh-cn_topic_0175549220_section197270431505"></a>
PyTorch编译失败,提示“ error: ld returned 1 exit status”。
![](figures/zh-cn_image_0000001190201973.png)
![](figures/zh-cn_image_0000001127006338.png)
#### 可能原因<a name="zh-cn_topic_0000001125315885_zh-cn_topic_0175549220_section169499490501"></a>
## 可能原因<a name="zh-cn_topic_0000001125315885_zh-cn_topic_0175549220_section169499490501"></a>
通过日志分析,大概原因为XxxxKernelNpu.cpp中实现的适配函数,与PyTorch框架算子要求的分发实现接口参数不匹配。在上面的例子中,是“binary\_cross\_entropy\_npu”,打开对应的XxxxKernelNpu.cpp文件,找到相应的适配函数。
![](figures/zh-cn_image_0000001144241896.png)
![](figures/zh-cn_image_0000001172886193.png)
可以看出实现中,最后一个参数是"int" ,与要求的“long”不匹配。
#### 处理方法<a name="zh-cn_topic_0000001125315885_section108142031907"></a>
## 处理方法<a name="zh-cn_topic_0000001125315885_section108142031907"></a>
修改XxxxKernelNpu.cpp中实现的适配函数,在上面的例子中,修改“binary\_cross\_entropy\_npu”方法最后一个参数类型为“int64\_t”\(cpp中“long”的类型使用"int64\_t"\)。
<h3 id="PyTorch编译失败-提示-error-call-of-overloadmd">PyTorch编译失败,提示“error: call of overload ....”</h3>
<h2 id="PyTorch编译失败-提示-error-call-of-overload">PyTorch编译失败,提示“error: call of overload ....”</h2>
#### 现象描述<a name="zh-cn_topic_0000001125641113_zh-cn_topic_0175549220_section197270431505"></a>
## 现象描述<a name="zh-cn_topic_0000001125641113_zh-cn_topic_0175549220_section197270431505"></a>
PyTorch编译失败,提示“error: call of overload ....”。
![](figures/zh-cn_image_0000001144082056.png)
![](figures/zh-cn_image_0000001173046111.png)
![](figures/zh-cn_image_0000001190201935.png)
![](figures/zh-cn_image_0000001126846514.png)
#### 可能原因<a name="zh-cn_topic_0000001125641113_zh-cn_topic_0175549220_section169499490501"></a>
## 可能原因<a name="zh-cn_topic_0000001125641113_zh-cn_topic_0175549220_section169499490501"></a>
通过日志分析,错误出在XxxxKernelNpu.cpp中30行位置,NPUAttrDesc的参数不合法。在上面的例子中,是“binary\_cross\_entropy\_attr”,打开对应的XxxxKernelNpu.cpp文件,找到相应的适配函数。
![](figures/zh-cn_image_0000001144082064.png)
![](figures/zh-cn_image_0000001127006340.png)
可以看出实现中,NPUAttrDesc的入参,第二个参数是"int" ,与NPUAttrDesc定义不匹配。
#### 处理方法<a name="zh-cn_topic_0000001125641113_section108142031907"></a>
## 处理方法<a name="zh-cn_topic_0000001125641113_section108142031907"></a>
1、将binary\_cross\_entropy\_attr\(\)中错误的行代码替换为上面的注释中的代码
2、binary\_cross\_entropy\_attr\(\)入参类型修改为 int64\_t。
<h2 id="附录md">附录</h2>
<h2 id="附录">附录</h2>
- **[CMake安装方法](#CMake安装方法md)**
- **[CMake安装方法](#CMake安装方法)**
- **[自定义算子导出方法](#自定义算子导出方法md)**
- **[自定义算子导出方法](#自定义算子导出方法)**
<h3 id="CMake安装方法md">CMake安装方法</h3>
<h2 id="CMake安装方法">CMake安装方法</h2>
以CMake版本升级为3.12.1为例说明。
@@ -1056,17 +961,17 @@ PyTorch编译失败,提示“error: call of overload ....”。
显示“cmake version 3.12.1”则表示安装成功。
<h3 id="自定义算子导出方法md">自定义算子导出方法</h3>
<h2 id="自定义算子导出方法">自定义算子导出方法</h2>
#### 简介<a name="zh-cn_topic_0000001136292799_section13121145561615"></a>
## 简介<a name="zh-cn_topic_0000001136292799_section13121145561615"></a>
PyTorch训练模型中包含自定义算子,将自定义算子导出成onnx单算子模型,方便转移到其他AI框架中使用。自定义算子导出有三种形式,适配NPU的TBE算子导出、C++算子导出、纯Python算子导出。
#### 前提条件<a name="zh-cn_topic_0000001136292799_section6744175713010"></a>
## 前提条件<a name="zh-cn_topic_0000001136292799_section6744175713010"></a>
安装PyTorch框架。
#### TBE算子导出<a name="zh-cn_topic_0000001136292799_section17568113818325"></a>
## TBE算子导出<a name="zh-cn_topic_0000001136292799_section17568113818325"></a>
TBE算子导出有两种方式。
@@ -1221,7 +1126,7 @@ TBE算子导出有两种方式。
>![](public_sys-resources/icon-note.gif) **说明:**
>详细实现代码请参见[test\_custom\_ops\_npu\_demo.py](https://gitee.com/ascend/pytorch/blob/master/test/test_npu/test_onnx/torch.onnx/custom_ops_demo/test_custom_ops_npu_demo.py),如无权限获取代码,请联系华为技术支持申请加入“Ascend”组织。
#### C++算子导出<a name="zh-cn_topic_0000001136292799_section1465619203319"></a>
## C++算子导出<a name="zh-cn_topic_0000001136292799_section1465619203319"></a>
1. 自定义算子
@@ -1287,7 +1192,7 @@ TBE算子导出有两种方式。
>![](public_sys-resources/icon-note.gif) **说明:**
>详细实现代码请参见[test\_custom\_ops\_demo.py](https://gitee.com/ascend/pytorch/blob/master/test/test_npu/test_onnx/torch.onnx/custom_ops_demo/test_custom_ops_demo.py),如无权限获取代码,请联系华为技术支持申请加入“Ascend”组织。
#### 纯Python算子导出<a name="zh-cn_topic_0000001136292799_section98044317326"></a>
## 纯Python算子导出<a name="zh-cn_topic_0000001136292799_section98044317326"></a>
1. 自定义算子

Before

Width:  |  Height:  |  Size: 43 KiB

After

Width:  |  Height:  |  Size: 43 KiB

Before

Width:  |  Height:  |  Size: 7.6 KiB

After

Width:  |  Height:  |  Size: 7.6 KiB

Before

Width:  |  Height:  |  Size: 50 KiB

After

Width:  |  Height:  |  Size: 50 KiB

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 28 KiB

Before

Width:  |  Height:  |  Size: 78 KiB

After

Width:  |  Height:  |  Size: 78 KiB

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 28 KiB

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 44 KiB

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 329 KiB

File diff suppressed because it is too large Load Diff
+15 -263
View File
@@ -1,263 +1,15 @@
# FrameworkPTAdapter 2.0.3 版本说明书
- [FrameworkPTAdapter 2.0.3](#FrameworkPTAdapter-2-0-3md)
- [用户须知](#用户须知md)
- [新增特性](#新增特性md)
- [特性修改](#特性修改md)
- [已修复问题](#已修复问题md)
- [已知问题](#已知问题md)
- [兼容性](#兼容性md)
- [FrameworkPTAdapter 2.0.2](#FrameworkPTAdapter-2-0-2md)
- [用户须知](#用户须知-0md)
- [新增特性](#新增特性-1md)
- [特性修改](#特性修改-2md)
- [已修复问题](#已修复问题-3md)
- [已知问题](#已知问题-4md)
- [兼容性](#兼容性-5md)
<h2 id="FrameworkPTAdapter-2-0-3md">FrameworkPTAdapter 2.0.3</h2>
<h3 id="用户须知md">用户须知</h3>
# PyTorch版本说明书 2.0.2
- [用户须知](#用户须知)
- [新增特性](#新增特性)
- [特性修改](#特性修改)
- [已修复问题](#已修复问题)
- [已知问题](#已知问题)
- [兼容性](#兼容性)
<h2 id="用户须知">用户须知</h2>
本框架基于Facebook主导的开源PyTorch1.5.0进行修改,延续原生的PyTorch特性,使用NPU进行动态图训练;以算子粒度进行模型适配,代码重用性好,支持现有的网络只修改设备类型或数据类型,即可迁移到NPU上使用。
从此版本开始,PyTorch1.8.1版本提供支持,此版本延续PyTorch1.5.0特性,功能保持一致(profiling工具除外)。除此之外,对后端算子适配提供较好开发体验。当期1.8.1版本仅支持Resent50网络模型。
<h3 id="新增特性md">新增特性</h3>
**表 1** PyTorch支持的版本特性列表
<a name="t76c34275cbb74753970f7c5a9eb594fa"></a>
<table><thead align="left"><tr id="r0c10e7163bf54fe8816ab5ca2d77ccc4"><th class="cellrowborder" valign="top" width="10.459999999999999%" id="mcps1.2.4.1.1"><p id="a7888762cf8294977b7d114b1c898d1bd"><a name="a7888762cf8294977b7d114b1c898d1bd"></a><a name="a7888762cf8294977b7d114b1c898d1bd"></a>一级特性</p>
</th>
<th class="cellrowborder" valign="top" width="26.27%" id="mcps1.2.4.1.2"><p id="a4581ffde4a5f455faadfba144243a9d4"><a name="a4581ffde4a5f455faadfba144243a9d4"></a><a name="a4581ffde4a5f455faadfba144243a9d4"></a>二级特性</p>
</th>
<th class="cellrowborder" valign="top" width="63.27%" id="mcps1.2.4.1.3"><p id="a2a1562364b09433a83133fa10b3cf2b3"><a name="a2a1562364b09433a83133fa10b3cf2b3"></a><a name="a2a1562364b09433a83133fa10b3cf2b3"></a>说明</p>
</th>
</tr>
</thead>
<tbody><tr id="row7979351559"><td class="cellrowborder" rowspan="5" valign="top" width="10.459999999999999%" headers="mcps1.2.4.1.1 "><p id="p69836331553"><a name="p69836331553"></a><a name="p69836331553"></a>适配NPU的PyTorch特性</p>
</td>
<td class="cellrowborder" valign="top" width="26.27%" headers="mcps1.2.4.1.2 "><p id="p149831333357"><a name="p149831333357"></a><a name="p149831333357"></a>支持PyTorch1.8.1版本</p>
</td>
<td class="cellrowborder" valign="top" width="63.27%" headers="mcps1.2.4.1.3 "><p id="p1398313336511"><a name="p1398313336511"></a><a name="p1398313336511"></a>增加PyTorch1.8.1版本, 当前仅支持resnet50网络,包括其DDP分布式训练场景。</p>
</td>
</tr>
<tr id="row109719353511"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p18983183315515"><a name="p18983183315515"></a><a name="p18983183315515"></a>支持python3.8</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p836221112812"><a name="p836221112812"></a><a name="p836221112812"></a>支持python3.8环境编译及使用。</p>
</td>
</tr>
<tr id="row13971435754"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p79831331353"><a name="p79831331353"></a><a name="p79831331353"></a>提供算子溢出检测工具</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p109832331055"><a name="p109832331055"></a><a name="p109832331055"></a>支持框架IR级别算子溢出检测,在发生AICORE算子溢出时,提示溢出的IR信息。</p>
</td>
</tr>
<tr id="row185381431133610"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p953883153611"><a name="p953883153611"></a><a name="p953883153611"></a>OS兼容性</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p13538203153618"><a name="p13538203153618"></a><a name="p13538203153618"></a>新增支持UOS 20 1020e arm系统</p>
</td>
</tr>
<tr id="row91681125173610"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p2168172519364"><a name="p2168172519364"></a><a name="p2168172519364"></a>框架基础功能</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1416815259367"><a name="p1416815259367"></a><a name="p1416815259367"></a>新增适配算子开发(详见算子清单)</p>
</td>
</tr>
<tr id="row11970351050"><td class="cellrowborder" rowspan="26" valign="top" width="10.459999999999999%" headers="mcps1.2.4.1.1 "><p id="p298314333514"><a name="p298314333514"></a><a name="p298314333514"></a>训练模型</p>
</td>
<td class="cellrowborder" valign="top" width="26.27%" headers="mcps1.2.4.1.2 "><p id="p19984193312511"><a name="p19984193312511"></a><a name="p19984193312511"></a>CenterFace</p>
</td>
<td class="cellrowborder" valign="top" width="63.27%" headers="mcps1.2.4.1.3 "><p id="p7517351258"><a name="p7517351258"></a><a name="p7517351258"></a>-</p>
</td>
</tr>
<tr id="row9965351254"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1984033458"><a name="p1984033458"></a><a name="p1984033458"></a>PCBU</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p298411338513"><a name="p298411338513"></a><a name="p298411338513"></a>-</p>
</td>
</tr>
<tr id="row14966351959"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p198414331957"><a name="p198414331957"></a><a name="p198414331957"></a>Net++</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1798413331756"><a name="p1798413331756"></a><a name="p1798413331756"></a>-</p>
</td>
</tr>
<tr id="row20966351454"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p4984183317518"><a name="p4984183317518"></a><a name="p4984183317518"></a>FCN8S</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1698453311519"><a name="p1698453311519"></a><a name="p1698453311519"></a>-</p>
</td>
</tr>
<tr id="row19653517518"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1298483319512"><a name="p1298483319512"></a><a name="p1298483319512"></a>OSNetRetinaFace</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1798423312519"><a name="p1798423312519"></a><a name="p1798423312519"></a>-</p>
</td>
</tr>
<tr id="row39619351751"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1298414331513"><a name="p1298414331513"></a><a name="p1298414331513"></a>PSPnet</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p10984633254"><a name="p10984633254"></a><a name="p10984633254"></a>-</p>
</td>
</tr>
<tr id="row496335654"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p19984433351"><a name="p19984433351"></a><a name="p19984433351"></a>EDSR</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p898473314517"><a name="p898473314517"></a><a name="p898473314517"></a>-</p>
</td>
</tr>
<tr id="row17953357517"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p14984123312515"><a name="p14984123312515"></a><a name="p14984123312515"></a>Tsm</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p159841033855"><a name="p159841033855"></a><a name="p159841033855"></a>-</p>
</td>
</tr>
<tr id="row16951435551"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p19984933457"><a name="p19984933457"></a><a name="p19984933457"></a>pnasnet5large</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p89846335512"><a name="p89846335512"></a><a name="p89846335512"></a>-</p>
</td>
</tr>
<tr id="row2095113520514"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1798416331952"><a name="p1798416331952"></a><a name="p1798416331952"></a>Gaitset</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p098417336516"><a name="p098417336516"></a><a name="p098417336516"></a>-</p>
</td>
</tr>
<tr id="row89516351511"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p11985153312516"><a name="p11985153312516"></a><a name="p11985153312516"></a>fcn</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p169858331155"><a name="p169858331155"></a><a name="p169858331155"></a>-</p>
</td>
</tr>
<tr id="row5953353513"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p18985103311514"><a name="p18985103311514"></a><a name="p18985103311514"></a>Albert</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p2098513334519"><a name="p2098513334519"></a><a name="p2098513334519"></a>-</p>
</td>
</tr>
<tr id="row119533516513"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p598511336511"><a name="p598511336511"></a><a name="p598511336511"></a>AdvancedEast</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p119850331513"><a name="p119850331513"></a><a name="p119850331513"></a>-</p>
</td>
</tr>
<tr id="row39511356512"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p698553311512"><a name="p698553311512"></a><a name="p698553311512"></a>ReidStrongBaseline</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1198514331659"><a name="p1198514331659"></a><a name="p1198514331659"></a>-</p>
</td>
</tr>
<tr id="row129463518517"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p99851633158"><a name="p99851633158"></a><a name="p99851633158"></a>Fast-scnn</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1298514331359"><a name="p1298514331359"></a><a name="p1298514331359"></a>-</p>
</td>
</tr>
<tr id="row9942035757"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p109854331151"><a name="p109854331151"></a><a name="p109854331151"></a>RDN</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1198583317511"><a name="p1198583317511"></a><a name="p1198583317511"></a>-</p>
</td>
</tr>
<tr id="row79415357517"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p6985833351"><a name="p6985833351"></a><a name="p6985833351"></a>SRFlow</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p29851033350"><a name="p29851033350"></a><a name="p29851033350"></a>-</p>
</td>
</tr>
<tr id="row12947357514"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p149859334518"><a name="p149859334518"></a><a name="p149859334518"></a>MGN</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p19851833850"><a name="p19851833850"></a><a name="p19851833850"></a>-</p>
</td>
</tr>
<tr id="row3941735855"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p898533316518"><a name="p898533316518"></a><a name="p898533316518"></a>Roberta</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p998553318518"><a name="p998553318518"></a><a name="p998553318518"></a>-</p>
</td>
</tr>
<tr id="row1093335856"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1985533451"><a name="p1985533451"></a><a name="p1985533451"></a>RegNetY</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p59851033355"><a name="p59851033355"></a><a name="p59851033355"></a>-</p>
</td>
</tr>
<tr id="row49373518516"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p19986173311512"><a name="p19986173311512"></a><a name="p19986173311512"></a>VoVNet-39</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p798683310515"><a name="p798683310515"></a><a name="p798683310515"></a>-</p>
</td>
</tr>
<tr id="row5930351357"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p189862336515"><a name="p189862336515"></a><a name="p189862336515"></a>RegNetX</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1398618331651"><a name="p1398618331651"></a><a name="p1398618331651"></a>-</p>
</td>
</tr>
<tr id="row169312351655"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p149863337513"><a name="p149863337513"></a><a name="p149863337513"></a>RefineNet</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p2098615331959"><a name="p2098615331959"></a><a name="p2098615331959"></a>-</p>
</td>
</tr>
<tr id="row11931235957"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1198616331657"><a name="p1198616331657"></a><a name="p1198616331657"></a>RefineDet</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1698611332518"><a name="p1698611332518"></a><a name="p1698611332518"></a>-</p>
</td>
</tr>
<tr id="row189215359511"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p16986183319512"><a name="p16986183319512"></a><a name="p16986183319512"></a>AlignedReID</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1898715331055"><a name="p1898715331055"></a><a name="p1898715331055"></a>-</p>
</td>
</tr>
<tr id="row89213351858"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p119878330511"><a name="p119878330511"></a><a name="p119878330511"></a>FaceBoxes</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p129878331158"><a name="p129878331158"></a><a name="p129878331158"></a>-</p>
</td>
</tr>
</tbody>
</table>
<h3 id="特性修改md">特性修改</h3>
不涉及
<h3 id="已修复问题md">已修复问题</h3>
不涉及
<h3 id="已知问题md">已知问题</h3>
<a name="table1969972073016"></a>
<table><thead align="left"><tr id="row3699162017307"><th class="cellrowborder" valign="top" width="18.22%" id="mcps1.1.3.1.1"><p id="p16992020153010"><a name="p16992020153010"></a><a name="p16992020153010"></a>已知问题</p>
</th>
<th class="cellrowborder" valign="top" width="81.78%" id="mcps1.1.3.1.2"><p id="p269919203308"><a name="p269919203308"></a><a name="p269919203308"></a>问题描述</p>
</th>
</tr>
</thead>
<tbody><tr id="row9699142003011"><td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p1769932017300"><a name="p1769932017300"></a><a name="p1769932017300"></a>数据类型支持</p>
</td>
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p13699152010301"><a name="p13699152010301"></a><a name="p13699152010301"></a>NPU不支持float16类型的inf/nan数据输入输出。</p>
</td>
</tr>
<tr id="row146991520153016"><td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p156997200308"><a name="p156997200308"></a><a name="p156997200308"></a>数据Format</p>
</td>
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p10699182020308"><a name="p10699182020308"></a><a name="p10699182020308"></a>出现4D以上的format时不能降维。</p>
</td>
</tr>
<tr id="row11121205610549"><td class="cellrowborder" rowspan="3" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p1647216219558"><a name="p1647216219558"></a><a name="p1647216219558"></a>集合通信约束</p>
<p id="p0465121912402"><a name="p0465121912402"></a><a name="p0465121912402"></a></p>
</td>
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p3116115695415"><a name="p3116115695415"></a><a name="p3116115695415"></a>要求一次训练任务中不同device上执行的图相同。</p>
</td>
</tr>
<tr id="row51211656105411"><td class="cellrowborder" valign="top" headers="mcps1.1.3.1.1 "><p id="p1311616560541"><a name="p1311616560541"></a><a name="p1311616560541"></a>当前只支持1/2/4/8P粒度的分配。</p>
</td>
</tr>
<tr id="row8647195765419"><td class="cellrowborder" valign="top" headers="mcps1.1.3.1.1 "><p id="p2064225716544"><a name="p2064225716544"></a><a name="p2064225716544"></a>只支持int8,int32,float16和float32数据类型。</p>
</td>
</tr>
<tr id="row4646195719548"><td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p4642195718541"><a name="p4642195718541"></a><a name="p4642195718541"></a>Apex功能支持</p>
</td>
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p864205725412"><a name="p864205725412"></a><a name="p864205725412"></a>Apex当前版本的实现方式主要为python实现,不支持APEX中的自定义优化CUDA Kernel。</p>
</td>
</tr>
</tbody>
</table>
<h3 id="兼容性md">兼容性</h3>
A800-9010:CentOS 7.6/Ubuntu 18.04/BC-Linux 7.6/Debian 9.9/Debian 10/OpenEuler 20.03 LTS
A800-9000:CentOS 7.6/Euler 2.8/Kylin v10/BC-Linux 7.6/OpenEuler 20.03 LTS/UOS 20 1020e
<h2 id="FrameworkPTAdapter-2-0-2md">FrameworkPTAdapter 2.0.2</h2>
<h3 id="用户须知-0md">用户须知</h3>
本框架基于Facebook主导的开源PyTorch1.5.0进行修改,延续原生的PyTorch特性,使用NPU进行动态图训练;以算子粒度进行模型适配,代码重用性好,支持现有的网络只修改设备类型或数据类型,即可迁移到NPU上使用。
<h3 id="新增特性-1md">新增特性</h3>
<h2 id="新增特性">新增特性</h2>
**表 1** PyTorch支持的版本特性列表
@@ -297,12 +49,12 @@ A800-9000:CentOS 7.6/Euler 2.8/Kylin v10/BC-Linux 7.6/OpenEuler 20.03 LTS/UOS
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p10828241123917"><a name="p10828241123917"></a><a name="p10828241123917"></a>-</p>
</td>
</tr>
<tr id="row16912221171"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p6913132676"><a name="p6913132676"></a><a name="p6913132676"></a>Densenset161</p>
<tr id="row16912221171"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p6913132676"><a name="p6913132676"></a><a name="p6913132676"></a>Densenet161</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p209131221474"><a name="p209131221474"></a><a name="p209131221474"></a>-</p>
</td>
</tr>
<tr id="row1016073314719"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p3160153320717"><a name="p3160153320717"></a><a name="p3160153320717"></a>Densenset191</p>
<tr id="row1016073314719"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p3160153320717"><a name="p3160153320717"></a><a name="p3160153320717"></a>Densenet191</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1516012331173"><a name="p1516012331173"></a><a name="p1516012331173"></a>-</p>
</td>
@@ -332,15 +84,15 @@ A800-9000:CentOS 7.6/Euler 2.8/Kylin v10/BC-Linux 7.6/OpenEuler 20.03 LTS/UOS
</tbody>
</table>
<h3 id="特性修改-2md">特性修改</h3>
<h2 id="特性修改">特性修改</h2>
不涉及
<h3 id="已修复问题-3md">已修复问题</h3>
<h2 id="已修复问题">已修复问题</h2>
不涉及
<h3 id="已知问题-4md">已知问题</h3>
<h2 id="已知问题">已知问题</h2>
<a name="table1969972073016"></a>
<table><thead align="left"><tr id="row3699162017307"><th class="cellrowborder" valign="top" width="18.22%" id="mcps1.1.3.1.1"><p id="p16992020153010"><a name="p16992020153010"></a><a name="p16992020153010"></a>已知问题</p>
@@ -379,7 +131,7 @@ A800-9000:CentOS 7.6/Euler 2.8/Kylin v10/BC-Linux 7.6/OpenEuler 20.03 LTS/UOS
</tbody>
</table>
<h3 id="兼容性-5md">兼容性</h3>
<h2 id="兼容性">兼容性</h2>
A800-9010:CentOS 7.6/Ubuntu 18.04/BC-Linux 7.6/Debian 9.9/Debian 10/OpenEuler 20.03 LTS
Binary file not shown.

Before

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 394 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 406 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 253 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 394 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 406 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 253 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 580 B

File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More