Compare commits

..
29 Commits
Author SHA1 Message Date
weili10 2c0d282932 update README.en.md.
Signed-off-by: weili10 <liwei386@huawei.com>
2022-09-05 02:56:35 +00:00
weili10 ac3a639583 update README.zh.md.
Signed-off-by: weili10 <liwei386@huawei.com>
2022-09-05 02:49:22 +00:00
weili10 f7f2da79ec add usleep time to reduce the cpu usage
增加usleep时间,避免间隔太短导致循环频率过高占用cpu资源

Signed-off-by: weili10 <liwei386@huawei.com>
2022-09-01 15:52:21 +00:00
weili10 c60bbfba75 !1096 网络模型移植与训练指南修改
Merge pull request !1096 from 彭子荣/2.0.4.tr5
2022-08-05 08:49:12 +00:00
pengzirong 9477572064 更新跳转链接 2022-07-27 15:43:13 +08:00
weili10 473748343b !1039 网络模型移植与训练指南修改
Merge pull request !1039 from 彭子荣/2.0.4.tr5
2022-07-11 08:34:34 +00:00
pengzirong 228bec4413 网络模型移植与训练指南新增硬件支持说明 2022-07-11 14:53:57 +08:00
weili10 3377df86c6 !906 安装指南资料修改
Merge pull request !906 from 彭子荣/2.0.4.tr5
2022-06-15 07:23:56 +00:00
pengzirong fff7b1265c 修改下载昇腾适配的apex源码命令 2022-06-14 17:23:30 +08:00
weili10 27c077b266 update README.en.md. 2022-04-01 13:41:06 +00:00
weili10 fa53e4a2f2 update docs/zh/PyTorch安装指南/PyTorch安装指南.md. 2022-04-01 13:35:32 +00:00
weili10 2ae7e6f6a8 update docs/en/PyTorch Installation Guide/PyTorch Installation Guide.md. 2022-04-01 13:34:05 +00:00
weili10 dc9be59e5e update README.zh.md. 2022-04-01 13:19:23 +00:00
i-robot 35f57d00dd !483 Pytorch 安装指南 资料更新
Merge pull request !483 from 彭子荣/2.0.4.tr5
2022-03-22 11:31:55 +00:00
pengzirong 214f6f98e9 新增版本配套说明列表
update

update
2022-03-22 10:06:32 +08:00
i-robot 7c29f6fb57 !405 2.0.4.tr5资料合入3.7
Merge pull request !405 from 彭子荣/2.0.4.tr5
2022-03-08 02:15:33 +00:00
pengzirong d1d3cd7ffd update url of pytorch安装指南
删除文件 docs/en/RELEASENOTE/RELEASENOTE.md

Updated this file

update docs/en/RELEASENOTE/FrameworkPTAdapter 2.0.4 Release Notes.md.

修复拼写错误,增加路径说明

修复英文资料的路径和拼写错误

update OWNERS.

修改Dynamic选项描述

a=>A (with Autocast)
2022-03-07 16:47:36 +08:00
i-robot 7456ef2606 !371 2.0.4.tr5资料合入
Merge pull request !371 from 彭子荣/2.0.4.tr5
2022-03-05 03:23:24 +00:00
pengzirong 4a3f61f367 update AMP TOOLS user guide
update AMP tools user guide

update amp tools user  guide
2022-03-04 17:18:40 +08:00
pengzirong 9375223d4e update env var contents of PTCOPY_ENABLE
delete env var contents of PTCOPY_ENABLE
2022-03-03 11:56:18 +08:00
weili10 e5ece794f3 update OWNERS. 2022-03-02 09:22:12 +00:00
pengzirong 1eb74061f4 update 同master内容 更新AMP tools描述、图片等以及Pytroch安装指南URL链接等 2022-03-02 16:01:10 +08:00
i-robot 2b4e64ac77 !172 bugfix:修复英文资料的路径和拼写错误
Merge pull request !172 from shibo/2.0.4
2022-01-29 09:29:35 +00:00
shibo 4b771736c1 修复英文资料的路径和拼写错误 2022-01-29 16:49:57 +08:00
i-robot dc8ba1c8ac !167 bugfix: 修复资料中拼写错误
Merge pull request !167 from shibo/2.0.4
2022-01-29 08:37:35 +00:00
shibo abe5f8f9bb 修复拼写错误,增加路径说明 2022-01-29 15:24:36 +08:00
i-robot 8c08296e01 !113 资料合入2.0.4.tr5
Merge pull request !113 from 彭子荣/2.0.4.tr5
2022-01-25 12:32:39 +00:00
pengzirong b4366203ff Merge branch '2.0.4.tr5' of gitee.com:peng-zirong/pytorch into 2.0.4.tr5 2022-01-25 11:53:45 +08:00
pengzirong 8c4b448688 delete 2022-01-25 11:53:28 +08:00
30 changed files with 111 additions and 20447 deletions
+2 -1
View File
@@ -16,4 +16,5 @@ reviewers:
- lvpeiyuan
- xchu42
- goodjobwubai
- fairwarning
- fairwarning
- yinzijun
+21 -6
View File
@@ -38,6 +38,15 @@ apt-get install -y gcc g++ make build-essential libssl-dev zlib1g-dev libbz2-dev
Currently, PyTorch 1.5.0 and 1.8.1 are supported. Obtain the native PyTorch source code from the root directory **pytorch/** in the current repository as required.
```sh
git clone https://gitee.com/ascend/pytorch.git
# By default, the masterf branch is used. If other branches are required, run the git checkout command to switch to that branch.
cd pytorch
git checkout -b 2.0.4.tr5 remotes/origin/2.0.4.tr5
```
Obtain the native PyTorch source code from the root directory **/pytorch** of the current repository.
```sh
// Version 1.5.0
git clone -b v1.5.0 --depth=1 https://github.com/pytorch/pytorch.git
@@ -48,6 +57,7 @@ git clone -b v1.8.1 --depth=1 https://github.com/pytorch/pytorch.git
Go to the **pytorch/pytorch/** directory and obtain the passive dependency code of PyTorch. (It takes a long time to obtain the code.)
```sh
cd pytorch
git submodule sync
git submodule update --init --recursive
```
@@ -59,6 +69,7 @@ If no error is reported after the preceding operations are complete, the PyTorch
Go to the **pytorch/scripts** directory and run the script based on the selected version. (Note: The downloaded native PyTorch source code must match the following version. Otherwise, an error may occur.)
```sh
cd ../scripts
// The default version is 1.5.0.
bash gen.sh
// For version 1.8.1, use the -v option to specify the version number.
@@ -73,6 +84,7 @@ The full code adapted to NPUs is generated in the **pytorch/pytorch/** directory
Go to the **pytorch/pytorch/** directory and install the Python dependency.
```python3
cd ../pytorch
pip3 install -r requirements.txt
```
@@ -102,6 +114,7 @@ The generated binary package is in the **pytorch/pytorch/dist/** directory.
**torch-1.5.0+ascend-cp37-cp37m-linux_x86_64.whl** (The actual name may contain the minor version number, for example, **torch-1.5.0.post2+ascend-cp37-cp37m-linux_x86_64.whl**.)
```shell
cd dist
pip3 uninstall torch
pip3 install --upgrade torch-1.5.0+ascend-cp37-cp37m-linux_x86_64.whl
```
@@ -111,6 +124,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** (The actual name may contain the minor version number, for example, **torch-1.5.0.post2+ascend-cp37-cp37m-linux_aarch64.whl**.)
```shell
cd dist
pip3 uninstall torch
pip3 install --upgrade torch-1.5.0+ascend-cp37-cp37m-linux_aarch64.whl
```
@@ -123,7 +137,8 @@ pip3 install --upgrade torch-1.5.0+ascend-cp37-cp37m-linux_aarch64.whl
Run the script for setting environment variables in the root directory of the current repository.
```
source pytorch/env.sh
cd ../
source env.sh
```
@@ -132,7 +147,7 @@ source pytorch/env.sh
The following environment variables are function classes used in NPU scenarios or environment variables that can improve performance:
```
export TASK_QUEUE_ENABLE=1 # Delivered by an asynchronous task to asynchronously call the ACL interface. You are advised to enable this environment variable and set its value to 1.
export TASK_QUEUE_ENABLE=1 # Delivered by an asynchronous task to asynchronously call the ACL interface. You are advised to enable this environment variable and set its value to 1 when there is a bottleneck in the delivery of tasks.
export PTCOPY_ENABLE=1 # Use the PTCopy operator mode to accelerate continuous rotation and copy. You are advised to enable this environment variable and set its value to 1.
```
@@ -153,9 +168,9 @@ Verify the execution. The output result is OK.
```shell
// Select a test script that matches the preceding version. The following uses the 1.5.0 version as an example.
python3 pytorch1.5.0/test/test_npu/test_div.py
python3 pytorch1.5.0/test/test_npu/test_network_ops/test_div.py
// The following uses the 1.8.1 version as an example.
python3 pytorch1.8.1/test/test_npu/test_div.py
python3 pytorch1.8.1/test/test_npu/test_network_ops/test_div.py
```
# Documentation
@@ -205,13 +220,13 @@ After the installation is successful, run **make clean** and then **bash build.s
Development state:
```
cd /urs/local/ascend-toolkit/latest/fwkacllib/lib64
cd /urs/local/Ascend/ascend-toolkit/latest/{arch}-linux/lib64
```
User state:
```
cd /urs/local/nnae/latest/fwkacllib/lib64
cd /urs/local/Ascend/nnae/latest/{arch}-linux/lib64
pip3 install --upgrade topi-0.4.0-py3-none-any.whl
+14 -7
View File
@@ -40,8 +40,9 @@ apt-get install -y gcc g++ make build-essential libssl-dev zlib1g-dev libbz2-dev
```
git clone https://gitee.com/ascend/pytorch.git
# 默认是masterf分支,若需要其他分支请使用git checkout 命令切换
# git checkout -b 2.0.3.tr5 remotes/origin/2.0.3.tr5
# 默认是master分支,若需要其他分支请使用git checkout 命令切换
cd pytorch
git checkout -b 2.0.4.tr5 remotes/origin/2.0.4.tr5
```
## 获取原生PyTorch源代码和third_party代码
@@ -58,6 +59,7 @@ git clone -b v1.8.1 --depth=1 https://github.com/pytorch/pytorch.git
进入到pytorch/pytorch/目录下, 获取PyTorch被动依赖代码(获取时间较长,请耐心等待)。
```sh
cd pytorch
git submodule sync
git submodule update --init --recursive
```
@@ -69,6 +71,7 @@ git submodule update --init --recursive
进入到pytorch/scripts目录,根据选择的版本执行,执行脚本(注意:下载原生Pytorch源代码和下面版本要对应,否则可能出错)
```sh
cd ../scripts/
// 默认为1.5.0版本
bash gen.sh
// 对于1.8.1版本,则通过-v 参数指定
@@ -83,6 +86,7 @@ bash gen.sh -v 1.8.1
进入到pytorch/pytorch/目录,依赖库安装:
```python3
cd ../pytorch/
pip3 install -r requirements.txt
```
@@ -112,6 +116,7 @@ bash build.sh --python=3.8
torch-1.5.0+ascend-cp37-cp37m-linux_x86_64.whl (实际可能附带小版本号例如torch-1.5.0.post2+ascend-cp37-cp37m-linux_x86_64.whl)
```shell
cd dist/
pip3 uninstall torch
pip3 install --upgrade torch-1.5.0+ascend-cp37-cp37m-linux_x86_64.whl
```
@@ -122,6 +127,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
cd dist/
pip3 uninstall torch
pip3 install --upgrade torch-1.5.0+ascend-cp37-cp37m-linux_aarch64.whl
```
@@ -134,6 +140,7 @@ pip3 install --upgrade torch-1.5.0+ascend-cp37-cp37m-linux_aarch64.whl
在当前仓库根目录中执行设置环境变量脚本
```
cd ../
source pytorch/env.sh
```
@@ -143,7 +150,7 @@ source pytorch/env.sh
以下环境变量为NPU场景下使用的功能类或可以提升性能的环境变量:
```
export TASK_QUEUE_ENABLE=1 # 使用异步任务下发,异步调用acl接口,建议默认开启,开启设置为1
export TASK_QUEUE_ENABLE=1 # 使用异步任务下发,异步调用acl接口,主机侧任务下发出现瓶颈时建议开启,开启设置为1
export PTCOPY_ENABLE=1 # 使用PTCopy算子模式,加速转连续及copy等过程,建议默认开启,开启设置为1
```
@@ -164,9 +171,9 @@ export DYNAMIC_OP="ADD#MUL" # 算子实现,ADD和MUL算子在不同场景下
```shell
// 根据前述版本,选择对应的测试脚本,以下为1.5.0版本
python3 pytorch1.5.0/test/test_npu/test_div.py
python3 pytorch1.5.0/test/test_npu/test_network_ops/test_div.py
// 以下为1.8.1版本
python3 pytorch1.8.1/test/test_npu/test_div.py
python3 pytorch1.8.1/test/test_npu/test_network_ops/test_div.py
```
# 文档
@@ -213,11 +220,11 @@ pip3 install typing_extensions
开发态:
cd /urs/local/ascend-toolkit/latest/fwkacllib/lib64
cd /urs/local/Ascend/ascend-toolkit/latest/{arch}-linux/lib64
用户态:
cd /urs/local/nnae/latest/fwkacllib/lib64
cd /urs/local/Ascend/nnae/latest/{arch}-linux/lib64
pip3 install --upgrade topi-0.4.0-py3-none-any.whl
File diff suppressed because it is too large Load Diff
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
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

@@ -76,7 +76,8 @@ When setting up the environment for PyTorch model development and running, you c
```
git clone https://gitee.com/ascend/pytorch.git
# By default, the masterf branch is used. If other branches are required, run the git checkout command to switch to that branch.
# git checkout -b 2.0.3.tr5 remotes/origin/2.0.3.tr5
cd pytorch
git checkout -b 2.0.4.tr5 remotes/origin/2.0.4.tr5
```
@@ -149,7 +150,7 @@ When setting up the environment for PyTorch model development and running, you c
bash build.sh --python=3.8
or
bash build.sh --python=3.9 # PyTorch 1.5 does not support build and installation using Python 3.9.
```
Specify the Python version in the environment for build. The generated binary package is stored in the current dist directory **pytorch/pytorch/dist**.
@@ -159,6 +160,7 @@ When setting up the environment for PyTorch model development and running, you c
Go to the **pytorch/pytorch/dist** directory and run the following command to install PyTorch:
```
cd dist
pip3 install --upgrade torch-1.5.0+ascend.post3-cp37-cp37m-linux_{arch}.whl
```
@@ -176,7 +178,8 @@ After the software packages are installed, configure environment variables to us
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:
```
source pytorch/env.sh
cd ../
source env.sh
```
2. Select a proper HCCL initialization mode based on the actual scenario and configure the corresponding environment variables.
@@ -336,7 +339,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.4.tr5 https://gitee.com/ascend/apex.git
```
The directory structure of the downloaded source code is as follows:
@@ -2096,7 +2096,7 @@ The E2E prof tool integrates the framework-layer data obtained by the Profiling
Add the following with statement to enable the E2E prof function.
```
with torch.npu.profile(profiler_result_path="./result",use_e2e_profiler=Ture):
with torch.npu.profile(profiler_result_path="./result",use_e2e_profiler=True):
model_train()
```
@@ -2114,7 +2114,7 @@ The results obtained by using the E2E prof tool are raw data, which can be viewe
![](https://gitee.com/ascend/pytorch/raw/master/docs/zh/PyTorch%E7%BD%91%E7%BB%9C%E6%A8%A1%E5%9E%8B%E7%A7%BB%E6%A4%8D&%E8%AE%AD%E7%BB%83%E6%8C%87%E5%8D%97/figures/1.png)
2. Switch to the **./result** directory in the preceding figure and run the following script:
2. Switch to the **./results/PROF_**** directory in the preceding figure and run the following script, and the PROF_** folder is automatically generated.
```
/usr/local/Ascend/ascend-toolkit/latest/toolkit/tools/profiler/bin/msprof --export=on --output=./
File diff suppressed because it is too large Load Diff
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

@@ -35,6 +35,14 @@
- 需完成CANN开发或运行环境的安装,具体操作请参考《CANN 软件安装指南》。
| 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(1.8.1仅支持resnet50模型) |
| 2.0.4 | CANN 5.0.4 | 1.5.0/1.8.1(1.8.1仅支持resnet50模型) |
- 需安装3.12.0以上版本的CMake,安装方法请参考[CMake安装方法](#CMake安装方法md)。
- 需确保已安装7.3.0以上版本的gcc,7.3.0版本gcc具体安装及使用方式请参考[安装7.3.0版本gcc](#安装7-3-0版本gccmd)。
@@ -74,14 +82,15 @@
pip3 install wheel
```
3. 获取PyTorch源代码。
3. 获取PyTorch源代码。
1. 运行如下命令,获取适配昇腾AI处理器的PyTorch源代码,并切换到所需的分支。
```
git clone https://gitee.com/ascend/pytorch.git
# 默认是masterf分支,若需要其他分支请使用git checkout 命令切换
# git checkout -b 2.0.3.tr5 remotes/origin/2.0.3.tr5
cd pytorch
git checkout -b 2.0.4.tr5 remotes/origin/2.0.4.tr5
```
下载的源码主要目录结构如下所示:
@@ -162,6 +171,7 @@
进入“pytorch/pytorch/dist“文件夹目录,执行如下命令安装。
```
cd dist
pip3 install --upgrade torch-1.5.0+ascend.post3-cp37-cp37m-linux_{arch}.whl
```
@@ -179,7 +189,8 @@
1. 配置运行环境变量,在适配昇腾AI处理器的PyTorch源代码根目录中运行如下命令。
```
source pytorch/env.sh
cd ../
source env.sh
```
2. 请依据实际场景,选择合适的HCCL初始化方式,并配置相应环境变量。
@@ -268,9 +279,9 @@
<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_row234714854615"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="zh-cn_topic_0000001152616261_p2034724894619"><a name="zh-cn_topic_0000001152616261_p2034724894619"></a><a name="zh-cn_topic_0000001152616261_p2034724894619"></a>PTCOPY_ENABLE</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 class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="zh-cn_topic_0000001152616261_p53477489462"><a name="zh-cn_topic_0000001152616261_p53477489462"></a><a name="zh-cn_topic_0000001152616261_p53477489462"></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>
@@ -324,6 +335,8 @@
</tbody>
</table>
<h3 id="安装混合精度模块md">安装混合精度模块</h3>
#### 前提条件<a name="zh-cn_topic_0000001106176190_section3225481020"></a>
@@ -339,7 +352,7 @@
1. 运行如下命令,获取适配昇腾AI处理器的apex源代码。
```
git clone https://gitee.com/ascend/apex.git
git clone -b 2.0.4.tr5 https://gitee.com/ascend/apex.git
```
下载的源码主要目录结构如下所示:
@@ -158,15 +158,21 @@ ResNet50模型用到的算子已经在昇腾AI处理器上支持。
### 环境准备
请参见《PyTorch安装指南》进行CANN软件安装、PyTorch框架及混合精度模块安装,并配置环境变量。
请参见[《PyTorch安装指南》](https://gitee.com/ascend/pytorch/blob/2.0.4.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) 进行CANN软件安装、PyTorch框架及混合精度模块安装,并配置环境变量。
参考PyTorch [examples](https://github.com/pytorch/examples/tree/master/imagenet) 准备模型运行所需要的Python环境及依赖。
### 硬件支持
aarch64架构推荐使用:Atlas800-9000+kunpeng920+Ascend910+NVMe 3.2T+750GRAM
X86_64架构推荐使用:Atlas800-9010+Intel Platinum8260+Ascend910+NVMe 3.2T+750GRAM
### 模型迁移
在main.py训练脚本的基础上进行修改,实现模型的单卡训练和单机多卡训练迁移。
#### 单卡训练迁移
#### 单卡训练迁移<a name="单卡训练修改"></a>
1. 在main.py脚本中导入torch.npu模块。
@@ -310,7 +316,7 @@ ResNet50模型用到的算子已经在昇腾AI处理器上支持。
main()
```
#### 单机多卡训练修改
#### 单机多卡训练修改<a name="单机多卡训练修改"></a>
1. main.py增加头文件以支持基于PyTorch框架的模型在昇腾910 AI处理器上训练及进行混合精度训练。
@@ -717,7 +723,7 @@ python3 main.py /home/data/resnet50/imagenet --addr='1.1.1.1' \ #
<h2 id="环境准备md">环境准备</h2>
请参见《PyTorch安装指南》进行PyTorch及混合精度模块安装,并配置环境变量。
请参见[《PyTorch安装指南》](https://gitee.com/ascend/pytorch/blob/2.0.4.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及混合精度模块安装,并配置环境变量。
<h2 id="模型迁移md">模型迁移</h2>
@@ -1263,7 +1269,7 @@ Ascend平台提供了脚本转换工具使用户能通过命令行方式将训
target = target.to(CALCULATE_DEVICE)
```
更多迁移细节请参见[单P训练修改](#单P训练修改md)。
更多迁移细节请参见[单卡训练修改](#单卡训练修改)。
<h4 id="多P训练模型迁移md">多P训练模型迁移</h4>
@@ -1289,7 +1295,7 @@ def main():
lr_scheduler)
```
更多迁移细节请参见[分布式训练修改](#分布式训练修改md)。
更多迁移细节请参见[单机多卡训练修改](#单机多卡训练修改)。
<h4 id="PyTorch接口替换md">PyTorch接口替换</h4>
@@ -1580,6 +1586,34 @@ def main():
optimizer.step()
```
<h3 id="Pytorch1.8.1 AMP 在NPU上的使用说明md">Pytorch1.8.1 AMP 在NPU上的使用说明</h3>
<h4 id=总体说明md">总体说明</h4>
Pytorch1.8.1版本的AMP,类似于Apex AMP的O1模式(动态 loss scale),也是通过将部分算子的输入转换为fp16类型来实现混合精度的训练。
<h4 id="AMP使用场景md">AMP使用场景</h4>
1. 典型场景。
2. 梯度累加场景。
3. 多Models,Losses,and Optimizers场景。
4. DDP场景(one NPU per process)。
目前针对pytorch1.8.1框架仅支持以上4种场景,更多场景使用请参考pytorch官方操作指南。
<h4 id="NPU上AMP的使用方法md">NPU上AMP的使用方法</h4>
1. 模型从GPU适配到NPU时,torch.cuda.amp需要改为torch.npu.amp,with Autocast()需要改为with NpuAutocast(),scaler = GradScaler()需要改为scaler = NpuGradScaler()。
2. 当前Pytroch1.8.1 AMP工具中GradScaler增加了dynamic选项(默认为True),设置为False时,AMP能支持静态Loss Scale。
<h4 id="注意事项md">注意事项</h4>
1. 1.8.1中AMP使用装饰器的方式实现。在train与test时需要通过添加with NpuAutocast()将模型的入参转换为FP16,如果不添加,模型入参仍为FP32,在极限batchsize下,会出现内存不足的问题。
4. 当前1.8.1AMP不支持tensor融合功能。
<h2 id="模型训练md">模型训练</h2>
@@ -2059,12 +2093,12 @@ E2E prof工具是一个将pytorch框架的profiling工具和cann prof工具获
添加with语句使能E2E prof功能
```
with torch.npu.profile(profiler_result_path="./result",use_e2e_profiler=Ture):
with torch.npu.profile(profiler_result_path="./result",use_e2e_profiler=True):
model_train()
```
- profiler_result_path表示prof结果保存路径,默认为当前路径。
- profiler_result_path表示prof结果保存路径,默认为当前路径,若设置其他路径请确保路径已存在。
- use_e2e_profiler表示是否开启E2E prof功能,默认为False(仅开启CANN prof功能)。
(因NUP算子需要编译后才能执行,为保证数据的准确性,建议先运行10个step,在第十个step后再进行E2E prof操作,并且一般只需要profiling1个或者2个setp即可。)
@@ -2075,7 +2109,7 @@ with torch.npu.profile(profiler_result_path="./result",use_e2e_profiler=Ture):
1. 以使用教程中路径为例,工具会在profiler_result_path路径下创建文件夹以保存原始数据。![](figures/1.png)
2. 切换至如上图./result路径后,执行脚本。
2. 切换至如上图./results/PROF_***路径后,执行下述脚本,其中PROF_***文件夹为自动生成的文件夹。
```
/usr/local/Ascend/ascend-toolkit/latest/toolkit/tools/profiler/bin/msprof --export=on --output=./
@@ -2257,7 +2291,7 @@ with torch.npu.profile(profiler_result_path="./results", use_e2e_profiler=True
若使用模型算子精度对比功能,需要同时在NPU和GPU环境安装hdf5。否则,仅在NPU环境安装hdf5即可。
- 安装支持dump功能的Ascend PyTorch框架,编译前请修改build.sh脚本,其余操作请参见《PyTorch安装指南》。
- 安装支持dump功能的Ascend PyTorch框架,编译前请修改build.sh脚本,其余操作请参见[《PyTorch安装指南》](https://gitee.com/ascend/pytorch/blob/2.0.4.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) 。
- 在NPU环境PyTorch安装
@@ -2751,7 +2785,7 @@ if __name__ == "__main__":
<h4 id="网络迁移md">网络迁移</h4>
训练脚本迁移请参见[单P训练修改](#单P训练修改md)和[分布式训练修改](#分布式训练修改md)。脚本执行时注意选择参数--arch shufflenet\_v2\_x1\_0。
训练脚本迁移请参见[单卡训练修改](#单卡训练修改)和[单机多卡训练修改](#单机多卡训练修改)。脚本执行时注意选择参数--arch shufflenet\_v2\_x1\_0。
<h4 id="网络调测md">网络调测</h4>
+1 -1
View File
@@ -581,7 +581,7 @@ void ReleaseQueue::PopFromReleaseQueue() {
ChangeStatus(NEED_EXIT, CAN_EXIT);
break;
}
usleep(2);
usleep(5);
}
}
}