-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Zq/add specified autocompare #785
base: main
Are you sure you want to change the base?
Changes from 20 commits
60eb031
76d96f6
63a4ff7
538cf2f
5348043
6d8a8e3
4790315
ba73de3
e97db80
8e95f2f
1ba0e04
f27200b
e534ce2
f2d7ff9
5598c1b
3c63c9f
5cdba1a
9d9923e
458233c
389a267
c8dbb34
8d40cf9
d5a38d0
16585db
0a5cd89
17ce56f
5413aec
6931b62
dedb0c5
94b98f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,9 +158,10 @@ sh ./tests/python/run_tests.sh | |
|
||
### 算子库拓展功能 | ||
|
||
#### 算子 Fallback | ||
#### 算子Fallback功能 | ||
|
||
Fallback 给定算子: | ||
Fallback指的是使用算子的CPU实现,而非设备实现。 | ||
Fallback给定算子: | ||
|
||
```bash | ||
export DIPU_FORCE_FALLBACK_OPS_LIST=add.out,conv2d | ||
|
@@ -181,20 +182,13 @@ export DIPU_FORCE_FALLBACK_OPS_LIST='.*' | |
python -c "import torch_dipu" | ||
``` | ||
|
||
#### 算子精度自动对比功能介绍 | ||
#### 算子精度自动对比功能 | ||
|
||
由于该功能默认不开启,使用该功能时需要打开该功能并重新编译DIPU。 | ||
|
||
可以通过设置环境变量USE_AUTOCOMPARE=ON,来开启该功能,然后需要重新编译DIPU。 | ||
|
||
```shell | ||
export USE_AUTOCOMPARE=ON | ||
``` | ||
|
||
以上方法是对所有算子开启自动精度对比。如果只需要对特定算子做精度对比,也可只给需要的算子做精度对比,只需要在相关的配置文件(如 `dipu/scripts/autogen_diopi_wrapper/diopi_functions.yaml`)给相应的算子添加 `autocompare: True` 即可。 | ||
算子精度自动对比功能(autocompare)用于确保算子计算结果的正确性,通过将设备参数拷贝到CPU上,对比CPU和设备的计算结果来判断精度是否达标。以下是算子精度自动对比功能的使用例子: | ||
|
||
```shell | ||
$ unset DIPU_FORCE_FALLBACK_OPS_LIST # 主要是确保要比较的算子没有强制 fallback 到 cpu, 可选 | ||
$ unset DIPU_FORCE_FALLBACK_OPS_LIST # 主要是确保要比较的算子没有强制 fallback 到 CPU, 可选 | ||
$ export DIPU_AUTOCOMPARE_OPS_LIST=add.out # 对add.out算子开启autocompare功能 | ||
$ python | ||
>>> import torch | ||
>>> import torch_dipu | ||
|
@@ -220,11 +214,33 @@ autocompare: add.out other: allclose | |
>>> | ||
``` | ||
|
||
可以看到,CPU 计算结果与设备计算结果 `allclose`,也能看到 CPU 和设备计算结果的 `shape`、`dtype` 等信息。特别的,需要注意以下几个问题: | ||
可以看到,输出包括 CPU 和设备计算结果的 `shape`、`stride`、`dtype` 等信息, 最终结果是CPU和设备的self和out都是allclose的。 | ||
|
||
##### 算子精度自动对比功能的设置 | ||
|
||
算子精度自动对比功能默认不开启,可以设置环境变量`DIPU_AUTOCOMPARE_OPS_LIST`来控制该功能,在开启算子自动对比功能前,必须unset `DIPU_FORCE_FALLBACK_OPS_LIST` | ||
|
||
- 可以通过设置环境变量`SPECIFIED_AUTOCOMPARE_OPS_LIST=‘.*’`,开启全局的精度对比,这种情况下所有调用的算子都会进行精度对比。 | ||
|
||
```shell | ||
# 开启全局的算子精度自动对比功能 | ||
export SPECIFIED_AUTOCOMPARE_OPS_LIST=‘.*’ | ||
``` | ||
|
||
- 可以设置`DIPU_AUTOCOMPARE_OPS_LIST`来指定算子开启自动精度对比,支持正则表达式匹配,也可以指定多个算子开启自动精度对比。算子名可以参考[diopi_functions.yaml](https://github.com/DeepLink-org/deeplink.framework/blob/main/dipu/scripts/autogen_diopi_wrapper/diopi_functions.yaml)。 | ||
|
||
```shell | ||
# 指定匹配add.*?的算子进行自动精度对比 | ||
export DIPU_AUTOCOMPARE_OPS_LIST=add.*? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 我还是很奇怪, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 问号是对匹配结果造成影响是吧,这么看来这这里是多余的? |
||
# 指定add.out、sub.out算子进行自动精度对比 | ||
export DIPU_AUTOCOMPARE_OPS_LIST="add.out, sub.out" | ||
``` | ||
|
||
NOTE: | ||
|
||
1. `dipu/scripts/autogen_diopi_wrapper/diopi_functions.yaml` 中配置了 `autograd:True` 的算子 (`cross_entropy_loss`、`conv2d`、`dropout`、`dropout_`、`linear`) 暂不支持 *backward* 的精度自动对比。如模型精度对不齐,可根据需要先将这几个算子 fallback 到 CPU 来确定问题。 | ||
2. 随机数生成相关的算子(`dipu/scripts/autogen_diopi_wrapper/diopi_functions.yaml` 中配置了 `autocompare:False`)没有做 `autocompare`,因为结果总是 `not_allclose`。 | ||
3. 对输入做检查是确保算子输入不被意外修改。 | ||
1. 部分算子并不支持自动精度对比功能,可以查看[diopi_functions.yaml](https://github.com/DeepLink-org/deeplink.framework/blob/main/dipu/scripts/autogen_diopi_wrapper/diopi_functions.yaml),其中的`autocompare`配置项为`disable`即不支持自动精度对比功能,同时也可以修改`diopi_functions.yaml`,将某些算子的`autocompare`配置项设置为`disable`来禁用自动对比功能。 | ||
2. `dipu/scripts/autogen_diopi_wrapper/diopi_functions.yaml` 中配置了 `autograd:True` 的算子 (`cross_entropy_loss`、`conv2d`、`dropout`、`dropout_`、`linear`) 暂不支持 *backward* 的精度自动对比。如模型精度对不齐,可根据需要先将这几个算子 fallback 到 CPU 来确定问题。 | ||
3. 对输入参数(self)做检查是确保算子的输入不被意外修改。 | ||
|
||
#### 抓取算子参数 | ||
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里忘了删吧 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done