mindstudio-probe 1.0.4__py3-none-any.whl → 1.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mindstudio_probe-1.0.4.dist-info → mindstudio_probe-1.1.0.dist-info}/METADATA +1 -1
- mindstudio_probe-1.1.0.dist-info/RECORD +287 -0
- msprobe/README.md +46 -16
- msprobe/__init__.py +16 -1
- msprobe/config.json +0 -2
- msprobe/core/advisor/advisor.py +8 -8
- msprobe/core/advisor/advisor_const.py +6 -7
- msprobe/core/advisor/advisor_result.py +12 -12
- msprobe/core/common/const.py +64 -3
- msprobe/core/common/exceptions.py +2 -2
- msprobe/core/common/file_utils.py +54 -9
- msprobe/core/common/inplace_op_checker.py +38 -0
- msprobe/core/common/inplace_ops.yaml +251 -0
- msprobe/core/common/log.py +21 -11
- msprobe/core/common/utils.py +153 -167
- msprobe/core/common_config.py +18 -25
- msprobe/core/compare/acc_compare.py +209 -36
- msprobe/core/compare/check.py +102 -17
- msprobe/core/compare/compare_cli.py +21 -1
- msprobe/core/compare/highlight.py +41 -5
- msprobe/core/compare/multiprocessing_compute.py +33 -8
- msprobe/core/compare/npy_compare.py +21 -6
- msprobe/core/compare/utils.py +82 -48
- msprobe/core/data_dump/data_collector.py +31 -32
- msprobe/core/data_dump/data_processor/base.py +45 -22
- msprobe/core/data_dump/data_processor/factory.py +20 -3
- msprobe/core/data_dump/data_processor/mindspore_processor.py +11 -5
- msprobe/core/data_dump/data_processor/pytorch_processor.py +24 -7
- msprobe/core/data_dump/json_writer.py +63 -42
- msprobe/core/data_dump/scope.py +32 -16
- msprobe/core/grad_probe/constant.py +4 -0
- msprobe/core/grad_probe/grad_compare.py +2 -3
- msprobe/core/grad_probe/utils.py +16 -3
- msprobe/docs/01.installation.md +19 -9
- msprobe/docs/02.config_introduction.md +52 -80
- msprobe/docs/03.config_examples.md +3 -13
- msprobe/docs/04.acl_config_examples.md +11 -9
- msprobe/docs/05.data_dump_PyTorch.md +140 -12
- msprobe/docs/06.data_dump_MindSpore.md +47 -5
- msprobe/docs/07.accuracy_checker_PyTorch.md +57 -34
- msprobe/docs/08.accuracy_checker_online_PyTorch.md +51 -11
- msprobe/docs/09.accuracy_checker_MindSpore.md +8 -8
- msprobe/docs/10.accuracy_compare_PyTorch.md +181 -99
- msprobe/docs/11.accuracy_compare_MindSpore.md +162 -31
- msprobe/docs/13.overflow_check_MindSpore.md +1 -1
- msprobe/docs/15.free_benchmarking_PyTorch.md +59 -53
- msprobe/docs/16.free_benchmarking_MindSpore.md +140 -0
- msprobe/docs/17.grad_probe.md +14 -16
- msprobe/docs/18.online_dispatch.md +89 -0
- msprobe/docs/{FAQ_PyTorch.md → FAQ.md} +22 -10
- msprobe/docs/img/ms_dump.png +0 -0
- msprobe/docs/img/ms_layer.png +0 -0
- msprobe/docs/img/pt_dump.png +0 -0
- msprobe/mindspore/__init__.py +1 -0
- msprobe/mindspore/api_accuracy_checker/api_accuracy_checker.py +35 -11
- msprobe/mindspore/api_accuracy_checker/api_info.py +7 -0
- msprobe/mindspore/cell_processor.py +27 -3
- msprobe/mindspore/common/const.py +2 -0
- msprobe/mindspore/common/utils.py +18 -2
- msprobe/mindspore/compare/distributed_compare.py +9 -22
- msprobe/mindspore/compare/layer_mapping.py +146 -0
- msprobe/mindspore/compare/modify_mapping.py +107 -0
- msprobe/mindspore/compare/ms_compare.py +173 -35
- msprobe/mindspore/compare/ms_graph_compare.py +27 -11
- msprobe/mindspore/debugger/debugger_config.py +16 -13
- msprobe/mindspore/debugger/precision_debugger.py +37 -13
- msprobe/mindspore/dump/dump_tool_factory.py +16 -1
- msprobe/mindspore/dump/hook_cell/api_registry.py +11 -1
- msprobe/mindspore/dump/hook_cell/primitive_hooks.py +206 -0
- msprobe/mindspore/dump/hook_cell/support_wrap_ops.yaml +82 -10
- msprobe/mindspore/dump/hook_cell/wrap_api.py +21 -13
- msprobe/mindspore/dump/jit_dump.py +41 -17
- msprobe/mindspore/dump/kernel_graph_dump.py +19 -3
- msprobe/mindspore/dump/kernel_kbyk_dump.py +19 -4
- msprobe/mindspore/free_benchmark/api_pynative_self_check.py +19 -4
- msprobe/mindspore/free_benchmark/common/config.py +15 -0
- msprobe/mindspore/free_benchmark/common/handler_params.py +15 -0
- msprobe/mindspore/free_benchmark/common/utils.py +19 -5
- msprobe/mindspore/free_benchmark/decorator/dec_forward.py +16 -2
- msprobe/mindspore/free_benchmark/decorator/decorator_factory.py +18 -3
- msprobe/mindspore/free_benchmark/handler/base_handler.py +18 -3
- msprobe/mindspore/free_benchmark/handler/check_handler.py +18 -3
- msprobe/mindspore/free_benchmark/handler/fix_handler.py +15 -0
- msprobe/mindspore/free_benchmark/handler/handler_factory.py +18 -3
- msprobe/mindspore/free_benchmark/perturbation/add_noise.py +22 -7
- msprobe/mindspore/free_benchmark/perturbation/base_perturbation.py +15 -0
- msprobe/mindspore/free_benchmark/perturbation/bit_noise.py +22 -7
- msprobe/mindspore/free_benchmark/perturbation/exchange_value.py +44 -18
- msprobe/mindspore/free_benchmark/perturbation/improve_precision.py +18 -4
- msprobe/mindspore/free_benchmark/perturbation/no_change.py +16 -1
- msprobe/mindspore/free_benchmark/perturbation/perturbation_factory.py +20 -5
- msprobe/mindspore/free_benchmark/self_check_tool_factory.py +15 -0
- msprobe/mindspore/grad_probe/global_context.py +18 -8
- msprobe/mindspore/overflow_check/kernel_graph_overflow_check.py +20 -4
- msprobe/mindspore/overflow_check/overflow_check_tool_factory.py +15 -0
- msprobe/mindspore/service.py +42 -123
- msprobe/pytorch/__init__.py +20 -1
- msprobe/pytorch/api_accuracy_checker/common/config.py +19 -2
- msprobe/pytorch/api_accuracy_checker/common/utils.py +53 -21
- msprobe/pytorch/api_accuracy_checker/compare/algorithm.py +19 -2
- msprobe/pytorch/api_accuracy_checker/compare/api_precision_compare.py +47 -21
- msprobe/pytorch/api_accuracy_checker/compare/compare.py +51 -21
- msprobe/pytorch/api_accuracy_checker/compare/compare_column.py +23 -6
- msprobe/pytorch/api_accuracy_checker/compare/compare_utils.py +28 -8
- msprobe/pytorch/api_accuracy_checker/config.yaml +1 -1
- msprobe/pytorch/api_accuracy_checker/run_ut/data_generate.py +67 -32
- msprobe/pytorch/api_accuracy_checker/run_ut/multi_run_ut.py +26 -5
- msprobe/pytorch/api_accuracy_checker/run_ut/run_overflow_check.py +19 -2
- msprobe/pytorch/api_accuracy_checker/run_ut/run_ut.py +51 -125
- msprobe/pytorch/api_accuracy_checker/run_ut/run_ut_utils.py +146 -3
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/attl.py +21 -0
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/client.py +78 -33
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/device_dispatch.py +27 -4
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/dump_dispatch.py +110 -0
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/server.py +36 -11
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/torch_ops_config.yaml +63 -0
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/utils.py +44 -0
- msprobe/pytorch/bench_functions/__init__.py +18 -3
- msprobe/pytorch/bench_functions/apply_adam_w.py +15 -0
- msprobe/pytorch/bench_functions/confusion_transpose.py +15 -0
- msprobe/pytorch/bench_functions/fast_gelu.py +15 -0
- msprobe/pytorch/bench_functions/layer_norm_eval.py +15 -0
- msprobe/pytorch/bench_functions/linear.py +15 -0
- msprobe/pytorch/bench_functions/matmul_backward.py +21 -6
- msprobe/pytorch/bench_functions/npu_fusion_attention.py +180 -151
- msprobe/pytorch/bench_functions/rms_norm.py +15 -0
- msprobe/pytorch/bench_functions/rotary_mul.py +28 -9
- msprobe/pytorch/bench_functions/scaled_mask_softmax.py +15 -0
- msprobe/pytorch/bench_functions/swiglu.py +20 -5
- msprobe/pytorch/common/__init__.py +15 -0
- msprobe/pytorch/common/log.py +18 -6
- msprobe/pytorch/common/parse_json.py +26 -11
- msprobe/pytorch/common/utils.py +40 -35
- msprobe/pytorch/compare/distributed_compare.py +11 -11
- msprobe/pytorch/compare/match.py +15 -0
- msprobe/pytorch/compare/pt_compare.py +38 -6
- msprobe/pytorch/debugger/debugger_config.py +52 -39
- msprobe/pytorch/debugger/precision_debugger.py +72 -24
- msprobe/pytorch/free_benchmark/__init__.py +20 -5
- msprobe/pytorch/free_benchmark/common/enums.py +28 -0
- msprobe/pytorch/free_benchmark/common/params.py +15 -0
- msprobe/pytorch/free_benchmark/common/utils.py +17 -1
- msprobe/pytorch/free_benchmark/compare/grad_saver.py +28 -7
- msprobe/pytorch/free_benchmark/compare/single_benchmark.py +15 -0
- msprobe/pytorch/free_benchmark/main.py +19 -4
- msprobe/pytorch/free_benchmark/perturbed_layers/base_layer.py +15 -0
- msprobe/pytorch/free_benchmark/perturbed_layers/layer_factory.py +19 -4
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/add_noise.py +15 -0
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/bit_noise.py +15 -0
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/change_value.py +26 -2
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/improve_precision.py +15 -0
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/no_change.py +15 -0
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/npu_base_layser.py +15 -0
- msprobe/pytorch/free_benchmark/perturbed_layers/run_cpu.py +15 -0
- msprobe/pytorch/free_benchmark/result_handlers/base_handler.py +55 -16
- msprobe/pytorch/free_benchmark/result_handlers/check_handler.py +15 -0
- msprobe/pytorch/free_benchmark/result_handlers/fix_handler.py +15 -0
- msprobe/pytorch/free_benchmark/result_handlers/handler_factory.py +15 -0
- msprobe/pytorch/free_benchmark/result_handlers/preheat_handler.py +19 -4
- msprobe/pytorch/function_factory.py +17 -2
- msprobe/pytorch/functional/module_dump.py +84 -0
- msprobe/pytorch/grad_probe/grad_stat_csv.py +2 -2
- msprobe/pytorch/hook_module/__init__.py +16 -1
- msprobe/pytorch/hook_module/api_registry.py +13 -8
- msprobe/pytorch/hook_module/hook_module.py +17 -19
- msprobe/pytorch/hook_module/utils.py +4 -6
- msprobe/pytorch/hook_module/wrap_aten.py +12 -11
- msprobe/pytorch/hook_module/wrap_distributed.py +6 -7
- msprobe/pytorch/hook_module/wrap_functional.py +10 -11
- msprobe/pytorch/hook_module/wrap_npu_custom.py +9 -17
- msprobe/pytorch/hook_module/wrap_tensor.py +4 -6
- msprobe/pytorch/hook_module/wrap_torch.py +4 -6
- msprobe/pytorch/hook_module/wrap_vf.py +4 -6
- msprobe/pytorch/module_processer.py +17 -2
- msprobe/pytorch/online_dispatch/compare.py +11 -12
- msprobe/pytorch/online_dispatch/single_compare.py +7 -7
- msprobe/pytorch/online_dispatch/torch_ops_config.yaml +8 -0
- msprobe/pytorch/online_dispatch/utils.py +1 -4
- msprobe/pytorch/parse.py +15 -0
- msprobe/pytorch/parse_tool/cli.py +5 -6
- msprobe/pytorch/parse_tool/lib/compare.py +9 -10
- msprobe/pytorch/parse_tool/lib/parse_tool.py +3 -0
- msprobe/pytorch/parse_tool/lib/utils.py +28 -24
- msprobe/pytorch/parse_tool/lib/visualization.py +1 -1
- msprobe/pytorch/pt_config.py +167 -38
- msprobe/pytorch/service.py +97 -32
- mindstudio_probe-1.0.4.dist-info/RECORD +0 -276
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/ssl_config.py +0 -10
- msprobe/pytorch/functional/data_processor.py +0 -0
- msprobe/pytorch/functional/dump_module.py +0 -39
- {mindstudio_probe-1.0.4.dist-info → mindstudio_probe-1.1.0.dist-info}/LICENSE +0 -0
- {mindstudio_probe-1.0.4.dist-info → mindstudio_probe-1.1.0.dist-info}/WHEEL +0 -0
- {mindstudio_probe-1.0.4.dist-info → mindstudio_probe-1.1.0.dist-info}/entry_points.txt +0 -0
- {mindstudio_probe-1.0.4.dist-info → mindstudio_probe-1.1.0.dist-info}/top_level.txt +0 -0
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
- 同一模型,从 CPU 或 GPU 移植到 NPU 中存在精度下降问题,对比 NPU 芯片中的 API 计算数值与 CPU 或 GPU 芯片中的 API 计算数值,进行问题定位。
|
|
16
16
|
- 同一模型,进行迭代(模型、框架版本升级或设备硬件升级)时存在的精度下降问题,对比相同模型在迭代前后版本的 API 计算数值,进行问题定位。
|
|
17
|
+
- 以上两个场景下,当存在无法自动匹配的API和模块时,则通过用户手动指定可以比对的API或模块来自定义映射关系,进行比对。
|
|
17
18
|
|
|
18
19
|
**注意事项**:
|
|
19
20
|
|
|
@@ -21,46 +22,81 @@
|
|
|
21
22
|
- NPU 与 CPU 或 GPU 的计算结果误差可能会随着模型的执行不断累积,最终会出现同一个 API 因为输入的数据差异较大而无法比对的情况。
|
|
22
23
|
- CPU 或 GPU 与 NPU 中两个相同的 API 会因为调用次数不同导致无法比对或比对到错误的 API,不影响整体运行,该 API 忽略。
|
|
23
24
|
|
|
24
|
-
**API匹配条件**:
|
|
25
|
+
**API 匹配条件**:
|
|
25
26
|
|
|
26
|
-
进行精度比对时,需要判断CPU或GPU的API与NPU的API
|
|
27
|
+
进行精度比对时,需要判断 CPU 或 GPU 的 API 与 NPU 的 API 是否可以比对,须满足以下匹配条件:
|
|
27
28
|
|
|
28
|
-
- 两个API的名称相同,API命名规则:`{api_type}.{api_name}.{api调用次数}.{正反向}.{输入输出}.index`,如:Functional.conv2d.1.backward.input.0。
|
|
29
|
-
- 两个API
|
|
29
|
+
- 两个 API 的名称相同,API 命名规则:`{api_type}.{api_name}.{api调用次数}.{正反向}.{输入输出}.{index}`,如:Functional.conv2d.1.backward.input.0。
|
|
30
|
+
- 两个 API 输入输出的 Tensor 数量相同且各个 Tensor 的 Shape 相同。
|
|
30
31
|
|
|
31
|
-
通常满足以上两个条件,工具就认为是同一个API,成功进行API
|
|
32
|
+
通常满足以上两个条件,工具就认为是同一个 API,成功进行 API 的匹配,后续进行相应的计算。
|
|
32
33
|
|
|
33
34
|
## 2 精度比对操作指导
|
|
34
35
|
|
|
35
36
|
### 2.1 命令行方式
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
#### 2.1.1 比对命令说明
|
|
38
39
|
|
|
39
|
-
|
|
40
|
+
命令示例如下:
|
|
40
41
|
|
|
41
|
-
|
|
42
|
+
```shell
|
|
43
|
+
msprobe -f pytorch compare -i ./compare.json -o ./output -s
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**完整参数说明**:
|
|
47
|
+
|
|
48
|
+
| 参数名 | 说明 | 是否必选 |
|
|
49
|
+
|-------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -------- |
|
|
50
|
+
| -i 或 --input_path | 指定[比对文件](#211-比对文件),str 类型。 | 是 |
|
|
51
|
+
| -o 或 --output_path | 配置比对结果文件存盘目录,str 类型。文件名称基于时间戳自动生成,格式为:`compare_result_{timestamp}.xlsx`。 | 是 |
|
|
52
|
+
| -s 或 --stack_mode | 配置 stack_mode 的开关,bool 类型。仅当[比对文件](#214-比对文件)配置 stack_path 需要开启。通过直接配置该参数开启,默认未配置,表示关闭。 | 否 |
|
|
53
|
+
| -c 或 --compare_only | 仅比对开关,bool 类型。该参数默认未配置,会启用自动精度分析,工具自动针对比对结果进行分析,识别到第一个精度可能不达标节点(在比对结果文件中的 Accuracy Reached or Not 列显示为 No),并给出问题可能产生的原因(打屏展示并生成 `advisor_{timestamp}.txt` 文件)。通过配置该参数取消自动精度分析,仅输出比对结果表格。 | 否 |
|
|
54
|
+
| -f 或 --fuzzy_match | 模糊匹配,bool 类型。开启后,对于网络中同一层级且命名仅调用次数不同的 API,可匹配并进行比对。通过直接配置该参数开启,默认未配置,表示关闭。 | 否 |
|
|
55
|
+
| -dm或--data_mapping | 自定义映射关系比对。需要指定自定义映射文件*.yaml。自定义映射文件的格式请参见[自定义映射文件](#215-自定义映射文件)。仅[API和模块无法自动匹配场景](#213-API和模块无法自动匹配场景)需要配置。仅支持逐卡比对,即使用[比对文件](#214-比对文件)的单卡场景示例。 | 否 |
|
|
56
|
+
|
|
57
|
+
#### 2.1.2 整网比对场景
|
|
58
|
+
|
|
59
|
+
整网比对场景是包含:CPU 或 GPU 与 NPU环境的 API 计算数值的整网数据比对;相同模型不同迭代版本的 API 计算数值的整网数据比对。
|
|
60
|
+
|
|
61
|
+
支持单卡和多卡,可同时比对多卡的 dump 数据。多机场景需要每个设备单独执行比对操作。
|
|
42
62
|
|
|
43
|
-
1.
|
|
63
|
+
1. 配置[config.json](https://gitee.com/ascend/mstt/blob/8914fbb31ff6da3898c3bb7b97ba99e23b0f1d38/debug/accuracy_tools/msprobe/config.json)文件。
|
|
44
64
|
|
|
45
|
-
2.
|
|
65
|
+
2. 参见 [PyTorch 场景下的数据采集](./05.data_dump_PyTorch.md)章节完成 CPU 或 GPU 与 NPU 的精度数据 dump。
|
|
66
|
+
|
|
67
|
+
3. 创建[比对文件](#211-比对文件)。
|
|
68
|
+
|
|
69
|
+
4. 运行命令:
|
|
46
70
|
|
|
47
71
|
```shell
|
|
48
72
|
msprobe -f pytorch compare -i ./compare.json -o ./output -s
|
|
49
73
|
```
|
|
50
74
|
|
|
51
|
-
|
|
75
|
+
5. 查看比对结果,请参见 [3 精度比对结果分析](#3-精度比对结果分析)。
|
|
76
|
+
|
|
77
|
+
#### 2.1.3 API和模块无法自动匹配场景
|
|
78
|
+
|
|
79
|
+
当存在无法自动匹配的API和模块时,则用户可以通过提供自定义映射关系的配置文件来告知工具可匹配的API或模块,进行比对。
|
|
52
80
|
|
|
53
|
-
|
|
54
|
-
|-------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -------- |
|
|
55
|
-
| -i 或 --input_path | 指定[比对文件](#211-比对文件)。 | 是 |
|
|
56
|
-
| -o 或 --output_path | 配置比对结果文件存盘目录。文件名称基于时间戳自动生成,格式为:`compare_result_{timestamp}.xlsx`。 | 是 |
|
|
57
|
-
| -s 或 --stack_mode | 配置 stack_mode 的开关。仅当[比对文件](#211-比对文件)配置 stack_path 需要开启。通过直接配置该参数开启,默认未配置,表示关闭。 | 否 |
|
|
58
|
-
| -c 或 --compare_only | 仅比对开关。未配置默认关闭仅比对,使用自动精度分析,工具自动针对比对结果进行分析,识别到第一个精度不达标节点(在比对结果文件中的 Accuracy Reached or Not 列显示为 No),并给出问题可能产生的原因(打屏展示并生成 `advisor_{timestamp}.txt` 文件)。该参数默认未配置,使用自动精度分析,通过配置该参数开启仅比对,关闭自动精度分析,仅输出比对结果表格。 | 否 |
|
|
59
|
-
| -f 或 --fuzzy_match | 模糊匹配。开启后,对于网络中同一层级且命名仅调用次数不同的 API,可匹配并进行比对。通过直接配置该参数开启,默认未配置,表示关闭。 | 否 |
|
|
81
|
+
1. [config.json](https://gitee.com/ascend/mstt/blob/8914fbb31ff6da3898c3bb7b97ba99e23b0f1d38/debug/accuracy_tools/msprobe/config.json)文件level配置为L0或L1、task配置为tensor或statistics并指定需要dump的API或模块名。
|
|
60
82
|
|
|
61
|
-
|
|
83
|
+
2. 参见[PyTorch 场景下的数据采集](./05.data_dump_PyTorch.md)章节完成 CPU 或 GPU 与 NPU 的精度数据 dump。
|
|
62
84
|
|
|
63
|
-
|
|
85
|
+
3. 创建[比对文件](#211-比对文件)(单卡场景示例)。
|
|
86
|
+
|
|
87
|
+
4. 运行命令:
|
|
88
|
+
|
|
89
|
+
```shell
|
|
90
|
+
msprobe -f pytorch compare -i ./compare.json -o ./output -s -dm data_mapping.yaml
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
data_mapping.yaml文件配置请参见[自定义映射文件](#215-自定义映射文件)。
|
|
94
|
+
|
|
95
|
+
该场景不支持-f模糊匹配。
|
|
96
|
+
|
|
97
|
+
5. 查看比对结果,请参见 [3 精度比对结果分析](#3-精度比对结果分析)。
|
|
98
|
+
|
|
99
|
+
#### 2.1.4 比对文件
|
|
64
100
|
|
|
65
101
|
以在当前目录创建 ./compare.json 为例。
|
|
66
102
|
|
|
@@ -87,42 +123,46 @@
|
|
|
87
123
|
|
|
88
124
|
**参数说明**:
|
|
89
125
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
126
|
+
| 参数名 | 说明 | 是否必选 |
|
|
127
|
+
| -------------------- | ------------------------------------------------------------ | ------------------ |
|
|
128
|
+
| npu_path | 配置 NPU 环境下的 dump.json 文件(单卡场景)或真实数据目录(多卡场景),str 类型。 | 是 |
|
|
129
|
+
| bench_path | 配置 CPU、GPU 或 NPU 环境下的 dump.json 文件(单卡场景)或真实数据目录(多卡场景),str 类型。 | 是 |
|
|
130
|
+
| stack_path | 配置 NPU dump 目录下的 stack.json 文件,str 类型。 | 单卡必选,多卡不选 |
|
|
131
|
+
| is_print_compare_log | 配置是否开启单个算子的日志打屏。可取值 true 或 false,默认为 true。关闭后则只输出常规日志,bool 类型。 | 否 |
|
|
96
132
|
|
|
97
|
-
|
|
133
|
+
#### 2.1.5 自定义映射文件
|
|
98
134
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
此函数将 CPU 或 GPU 与 NPU 的 dump 文件进行比对,支持单卡和多卡,可同时比对多卡的 dump 数据。多机场景需要每个设备单独执行比对操作。可自动检索和匹配对应卡和进程所 dump 的数据文件,再调用 compare 进行比对。单机单卡时与 compare 函数二选一。
|
|
135
|
+
文件名格式:*.yaml,*为文件名,可自定义。
|
|
102
136
|
|
|
103
|
-
|
|
137
|
+
文件内容格式:
|
|
104
138
|
|
|
105
|
-
```
|
|
106
|
-
|
|
139
|
+
```yaml
|
|
140
|
+
# API
|
|
141
|
+
{api_type}.{api_name}.{API调用次数}.{前向反向}.{input/output}.{参数序号}: {api_type}.{api_name}.{API调用次数}.{前向反向}.{input/output}.{参数序号}
|
|
142
|
+
# 模块
|
|
143
|
+
{Module}.{module_name}.{前向反向}.{index}.{input/output}.{参数序号}: {Module}.{module_name}.{前向反向}.{index}.{input/output}.{参数序号}
|
|
107
144
|
```
|
|
108
145
|
|
|
109
|
-
|
|
146
|
+
冒号左侧和右侧分别为PyTorch框架不同版本或不同芯片环境的API的名称和module模块名称。
|
|
110
147
|
|
|
111
|
-
|
|
112
|
-
| -------------- | ------------------------------------------------------------ | -------- |
|
|
113
|
-
| npu_dump_dir | 配置 NPU 环境下的 dump 目录。str 类型。dump 数据目录须指定到 step 级。<br/>**配置示例**:'./npu_dump/step0'。 | 是 |
|
|
114
|
-
| bench_dump_dir | 配置 CPU、GPU 或 NPU 环境下的 dump 目录。str 类型。<br/>**配置示例**:'./gpu_dump/step0'。 | 是 |
|
|
115
|
-
| output_path | 配置比对结果文件存盘目录。需要预先创建 output_path 目录。str 类型。<br/>**配置示例**:'./output'。文件名称基于时间戳自动生成,格式为:`compare_result_rank{npu_ID}-rank{cpu/gpu/npu_ID}_{timestamp}.xlsx`。 | 是 |
|
|
116
|
-
| **kwargs | 支持 compare 的所有可选参数。 | 否 |
|
|
148
|
+
API和模块名称请从《[PyTorch 场景的精度数据采集](https://gitee.com/ascend/mstt/blob/8914fbb31ff6da3898c3bb7b97ba99e23b0f1d38/debug/accuracy_tools/msprobe/docs/05.data_dump_PyTorch.md)》中的dump.json文件获取。
|
|
117
149
|
|
|
118
|
-
|
|
150
|
+
文件内容示例:
|
|
119
151
|
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
|
|
152
|
+
```yaml
|
|
153
|
+
# API
|
|
154
|
+
NPU.npu_fusion_attention.4.forward.input.0: NPU.npu_fusion_attention.4.forward.input.0
|
|
155
|
+
# 模块
|
|
156
|
+
Module.module.language_model.embedding.word_embedding.VocabParallelEmbedding.forward.0.input.0: Module.module.language_model.embedding.word_embedding.VocabParallelEmbedding.forward.0.input.0
|
|
123
157
|
```
|
|
124
158
|
|
|
125
|
-
|
|
159
|
+
API和模块名称在dump.json文件中的“data_name”字段展示,如下图红框处所示:
|
|
160
|
+
|
|
161
|
+

|
|
162
|
+
|
|
163
|
+
### 2.2 比对函数方式
|
|
164
|
+
|
|
165
|
+
#### 2.2.1 compare 函数
|
|
126
166
|
|
|
127
167
|
此函数将 CPU 或 GPU 与 NPU 的 dump 文件进行比对,仅支持单机单卡。
|
|
128
168
|
|
|
@@ -136,10 +176,10 @@ compare(input_param, output_path, stack_mode=False, auto_analyze=True, fuzzy_mat
|
|
|
136
176
|
|
|
137
177
|
| 参数名 | 说明 | 是否必选 |
|
|
138
178
|
| ------------ | ------------------------------------------------------------ | -------- |
|
|
139
|
-
| input_param | 配置 dump 数据文件及目录,dict 类型。配置参数包括:<br> "npu_json_path":指定 NPU dump 目录下的 dump.json 文件。<br/>**配置示例**:"npu_json_path": "./npu_dump/dump.json"。<br/> "bench_json_path":指定 CPU、GPU 或 NPU dump 目录下的 dump.json 文件。<br/>**配置示例**:"bench_json_path": "./bench_dump/dump.json"。<br/> "stack_json_path":指定 NPU dump 目录下的 stack.json 文件。<br/>**配置示例**:"stack_json_path": "./npu_dump/stack.json"。<br/> "is_print_compare_log"
|
|
179
|
+
| input_param | 配置 dump 数据文件及目录,dict 类型。配置参数包括:<br> "npu_json_path":指定 NPU dump 目录下的 dump.json 文件。<br/>**配置示例**:"npu_json_path": "./npu_dump/dump.json"。<br/> "bench_json_path":指定 CPU、GPU 或 NPU dump 目录下的 dump.json 文件。<br/>**配置示例**:"bench_json_path": "./bench_dump/dump.json"。<br/> "stack_json_path":指定 NPU dump 目录下的 stack.json 文件。<br/>**配置示例**:"stack_json_path": "./npu_dump/stack.json"。<br/> "is_print_compare_log":配置是否开启单个算子的日志打屏。<br/>**配置示例**:True 或 False。 | 是 |
|
|
140
180
|
| output_path | 配置比对结果文件存盘目录,str 类型。<br/>**配置示例**:'./output'。文件名称基于时间戳自动生成,格式为:`compare_result_{timestamp}.xlsx`。 | 是 |
|
|
141
181
|
| stack_mode | 配置 stack_mode 的开关,bool 类型。仅当配置 stack_json_path 时需要开启。<br/>**配置示例**:stack_mode=True,默认为 False。 | 否 |
|
|
142
|
-
| auto_analyze | 自动精度分析,bool
|
|
182
|
+
| auto_analyze | 自动精度分析,bool 类型。开启后工具自动针对比对结果进行分析,识别到第一个精度可能不达标节点(在比对结果文件中的 Accuracy Reached or Not 列显示为 No),并给出问题可能产生的原因(打屏展示并生成 advisor_{timestamp}.txt 文件)。<br/>**配置示例**:auto_analyze=False,默认为 True。 | 否 |
|
|
143
183
|
| fuzzy_match | 模糊匹配,bool 类型。开启后,对于网络中同一层级且命名仅调用次数不同的 API,可匹配并进行比对。<br/>**配置示例**:fuzzy_match=True,默认为 False。 | 否 |
|
|
144
184
|
|
|
145
185
|
**函数示例**:
|
|
@@ -157,89 +197,131 @@ input_param={
|
|
|
157
197
|
compare(input_param, output_path="./output", stack_mode=True)
|
|
158
198
|
```
|
|
159
199
|
|
|
160
|
-
#### 2.2.
|
|
200
|
+
#### 2.2.2 compare_distributed 函数
|
|
201
|
+
|
|
202
|
+
此函数将 CPU 或 GPU 与 NPU 的 dump 文件进行比对,支持单卡和多卡,可同时比对多卡的 dump 数据。多机场景需要每个设备单独执行比对操作。可自动检索和匹配对应卡和进程所 dump 的数据文件,再调用 compare 进行比对。单机单卡时与 compare 函数二选一。
|
|
203
|
+
|
|
204
|
+
**函数原型**:
|
|
205
|
+
|
|
206
|
+
```Python
|
|
207
|
+
compare_distributed(npu_dump_dir, bench_dump_dir, output_path, **kwargs)
|
|
208
|
+
```
|
|
161
209
|
|
|
162
|
-
|
|
210
|
+
**参数说明**:
|
|
163
211
|
|
|
164
|
-
|
|
212
|
+
| 参数名 | 说明 | 是否必选 |
|
|
213
|
+
| -------------- | ------------------------------------------------------------ | -------- |
|
|
214
|
+
| npu_dump_dir | 配置 NPU 环境下的 dump 目录。str 类型。dump 数据目录须指定到 step 级。<br/>**配置示例**:'./npu_dump/step0'。 | 是 |
|
|
215
|
+
| bench_dump_dir | 配置 CPU、GPU 或 NPU 环境下的 dump 目录。str 类型。<br/>**配置示例**:'./gpu_dump/step0'。 | 是 |
|
|
216
|
+
| output_path | 配置比对结果文件存盘目录。需要预先创建 output_path 目录。str 类型。<br/>**配置示例**:'./output'。文件名称基于时间戳自动生成,格式为:`compare_result_rank{npu_ID}-rank{cpu/gpu/npu_ID}_{timestamp}.xlsx`。 | 是 |
|
|
217
|
+
| **kwargs | 支持 compare 的所有可选参数。 | 否 |
|
|
165
218
|
|
|
166
|
-
|
|
219
|
+
**函数示例**:
|
|
167
220
|
|
|
168
221
|
```Python
|
|
169
|
-
from msprobe.pytorch import
|
|
170
|
-
|
|
171
|
-
"npu_json_path": "./npu_dump/dump.json",
|
|
172
|
-
"bench_json_path": "./bench_dump/dump.json",
|
|
173
|
-
"stack_json_path": "./npu_dump/stack.json",
|
|
174
|
-
"is_print_compare_log": True
|
|
175
|
-
}
|
|
176
|
-
compare(input_param, output_path="./output", stack_mode=True)
|
|
222
|
+
from msprobe.pytorch import *
|
|
223
|
+
compare_distributed('./npu_dump/step0', './gpu_dump/step0', './output')
|
|
177
224
|
```
|
|
178
225
|
|
|
179
|
-
|
|
226
|
+
## 3 精度比对结果分析
|
|
180
227
|
|
|
181
|
-
|
|
228
|
+
PyTorch 精度比对是以 CPU 或 GPU 的计算结果为标杆,通过计算精度评价指标判断 API 在运行时是否存在精度问题。
|
|
182
229
|
|
|
183
|
-
-
|
|
230
|
+
- `advisor_{timestamp}.txt` 文件中给出了可能存在精度问题的 API 的专家建议。
|
|
184
231
|
|
|
185
|
-
|
|
232
|
+
- `compare_result_{timestamp}.xlsx` 文件列出了所有执行精度比对的 API 详细信息和比对结果,示例如下:
|
|
186
233
|
|
|
187
|
-
|
|
234
|
+

|
|
188
235
|
|
|
189
|
-
-
|
|
236
|
+
- **提示**:比对结果通过颜色标记、比对结果(Result)、计算精度达标情况(Accuracy Reached no Not)、错误信息提示(Err_Message)定位可疑算子,但鉴于每种指标都有对应的判定标准,还需要结合实际情况进行判断。
|
|
190
237
|
|
|
191
|
-
|
|
238
|
+
### 3.1 指标说明
|
|
192
239
|
|
|
193
|
-
|
|
240
|
+
精度比对从三个层面评估 API 的精度,依次是:真实数据模式、统计数据模式和 MD5 模式。比对结果分别有不同的表头。
|
|
194
241
|
|
|
195
|
-
|
|
242
|
+
**公共表头**:
|
|
196
243
|
|
|
197
|
-
|
|
244
|
+
|dump 数据模式|NPU Name (NPU 的 API 名)|Bench Name (bench 的 API 名)|NPU Dtype (NPU 数据类型)|Bench Dtype (bench 数据类型)|NPU Tensor Shape (NPU 张量形状)|Bench Tensor Shape (bench 张量形状)|
|
|
245
|
+
|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
|
|
246
|
+
|真实数据模式|√|√|√|√|√|√|
|
|
247
|
+
|统计数据模式|√|√|√|√|√|√|
|
|
248
|
+
|MD5 模式|√|√|√|√|√|√|
|
|
198
249
|
|
|
199
|
-
|
|
250
|
+
**个性表头**:
|
|
200
251
|
|
|
201
|
-
|
|
252
|
+
统计量有 4 种:最大值(max)、最小值(min)、平均值(mean)和 L2-范数(L2 norm)。
|
|
202
253
|
|
|
203
|
-
|
|
254
|
+
|dump 数据模式|Cosine (tensor 余弦相似度)|MaxAbsErr (tensor 最大绝对误差)|MaxRelativeErr (tensor 最大相对误差)|One Thousandth Err Ratio (tensor 相对误差小于千分之一的比例)|Five Thousandth Err Ratio (tensor 相对误差小于千分之五的比例)|NPU 和 bench 的统计量绝对误差 (max, min, mean, L2 norm) diff| NPU 和 bench 的统计量相对误差 (max, min, mean, L2 norm) RelativeErr |NPU 和 bench 的统计量 (max, min, mean, L2 norm)|NPU MD5 (NPU 数据 MD5 值)|BENCH MD5 (bench 数据 MD5 值)|Result (比对结果)|Accuracy Reached or Not (计算精度是否达标)|Err_message (错误信息提示)|NPU_Stack_Info (堆栈信息)|Data_Name (NPU 真实数据名)|
|
|
255
|
+
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
|
|
256
|
+
|真实数据模式|√|√|√|√|√|||√||||√|√|√|√|
|
|
257
|
+
|统计数据模式||||||√|√|√|||√||√|√||
|
|
258
|
+
|MD5 模式|||||||||√|√|√|||√||
|
|
204
259
|
|
|
205
|
-
|
|
260
|
+
### 3.2 颜色标记——真实数据模式、统计数据模式
|
|
206
261
|
|
|
207
|
-
|
|
262
|
+
红色标记情况:
|
|
263
|
+
1. 一个 API 或模块的 One Thousandth Err Ratio 的 input > 0.9 同时 output < 0.6(真实数据模式);
|
|
264
|
+
2. 一个 API 或模块的 output 的最大值相对误差 (Max diff 除以 max(0.01, Bench max)) > 0.5(统计数据模式);
|
|
265
|
+
3. 一个 API 或模块的 NPU 的最大值或最小值中存在 nan/inf/-inf(真实数据模式、统计数据模式);
|
|
266
|
+
4. 一个 API 或模块的最大值绝对误差大于 1e+10(真实数据模式,统计数据模式)。
|
|
208
267
|
|
|
209
|
-
|
|
268
|
+
黄色标记情况:
|
|
269
|
+
1. 一个 API 或模块的 One Thousandth Err Ratio 的 input - output > 0.1(真实数据模式);
|
|
270
|
+
2. 一个 API 或模块的 Cosine 的 input - output > 0.1(真实数据模式);
|
|
271
|
+
3. 一个 API 或模块的 output 的最大值相对误差 > 0.1 同时 input < 0.01(真实数据模式,统计数据模式);
|
|
272
|
+
4. 一个 API 或模块的 input 与 output 的最大值绝对误差都大于 1,同时 output 比 input 大一个数量级以上(真实数据模式、统计数据模式)。
|
|
210
273
|
|
|
211
|
-
|
|
212
|
-
2. Cosine < 0.9,精度不达标,标记为 No。
|
|
213
|
-
3. MaxAbsError > 1,精度不达标,标记为 No。
|
|
214
|
-
4. 其余情况下记为精度达标,标记为 Yes。
|
|
274
|
+
### 3.3 比对结果(Result)——统计数据模式、MD5 模式
|
|
215
275
|
|
|
216
|
-
|
|
276
|
+
统计数据模式:
|
|
277
|
+
1. Warning 情况:4种统计值至少一种相对误差 > 0.5,要重点检查该 API;
|
|
278
|
+
2. 空情况:相对误差 ≤ 0.5,可以不需要重点关注,但不代表不存在精度问题;
|
|
279
|
+
3. N/A 情况:API 没有匹配上。
|
|
217
280
|
|
|
218
|
-
|
|
281
|
+
MD5 模式:
|
|
282
|
+
1. Pass 情况:NPU 与标杆的 MD5 值一致,即 API 数据完全一致;
|
|
283
|
+
2. Different 情况:NPU 与标杆的 MD5 值不一致,即 API 数据不完全一致;
|
|
284
|
+
3. N/A 情况:API 没有匹配上。
|
|
219
285
|
|
|
220
|
-
|
|
286
|
+
### 3.4 判断计算精度达标情况(Accuracy Reached or Not)——真实数据模式
|
|
221
287
|
|
|
222
|
-
|
|
288
|
+
标记为 `No`,表示精度不达标:
|
|
289
|
+
1. Cosine < 0.99 且 MaxAbsError > 0.001;
|
|
290
|
+
2. Cosine < 0.9;
|
|
291
|
+
3. MaxAbsError > 1;
|
|
292
|
+
4. Cosine 或 MaxAbsError 计算结果为 N/A(NPU 和 Bench 的数据有 nan/inf)。
|
|
223
293
|
|
|
224
|
-
|
|
294
|
+
标记为 `None`:
|
|
295
|
+
1. Cosine 或 MaxAbsError 计算结果为 None(读取到的数据为空);
|
|
296
|
+
2. Cosine 或 MaxAbsError 计算结果无法转换为浮点型。
|
|
225
297
|
|
|
226
|
-
|
|
298
|
+
标记为 `Unmatched`:
|
|
299
|
+
1. Cosine 计算结果为 `shape unmatched`(NPU 和 Bench 的数据结构不一致)。
|
|
300
|
+
|
|
301
|
+
标记为 `Yes`,表示精度达标:
|
|
302
|
+
1. 除以上情况外的其余情况。
|
|
227
303
|
|
|
228
|
-
### 3.
|
|
304
|
+
### 3.5 错误信息提示(Err_message)——真实数据模式、统计数据模式
|
|
229
305
|
|
|
230
|
-
|
|
306
|
+
1. "Need double check api accuracy.":四个统计值中至少 1 个相对误差 > 0.5(统计数据模式);
|
|
307
|
+
2. "Fuzzy matching data, the comparison arruracy may be affected.":NPU 或 Bench 的真实数据名没有匹配上(真实数据模式);
|
|
308
|
+
3. "Dump file: {} not found.":NPU 真实数据不存在或者读取出错(真实数据模式);
|
|
309
|
+
4. "No bench data matched.":Bench 的 API 没有匹配上、Bench 真实数据不存在或读取出错(真实数据模式);
|
|
310
|
+
5. "This is empty data, can not compare.":读取到的数据为空(真实数据模式);
|
|
311
|
+
6. "Shape of NPU and bench Tensor do not match. Skipped.":NPU 和 Bench 的数据结构不一致(真实数据模式);
|
|
312
|
+
7. "The Position of inf or nan in NPU and bench Tensor do not match.":NPU 和 Bench 的数据有 nan/inf(真实数据模式);
|
|
313
|
+
8. "This is type of scalar data, can not compare.":NPU 为标量(真实数据模式);
|
|
314
|
+
9. "Dtype of NPU and bench Tensor do not match.":NPU 和 Bench 数据的数据类型不同(真实数据模式);
|
|
315
|
+
10. "":除以上情况的其余情况(真实数据模式、统计数据模式)。
|
|
231
316
|
|
|
232
|
-
|
|
233
|
-
- NPU max 或 NPU min 信息中存在 nan/inf;
|
|
234
|
-
- Max diff存在大于1e+10的值;
|
|
235
|
-
- 统计数据中output的Max diff除以max(0.01, Bench max) > 0.5;
|
|
236
|
-
- 真实数据中One Thousandth Err Ratio的input > 0.9同时output < 0.6。
|
|
237
|
-
- 黄色可能出现的情况有:
|
|
238
|
-
- Max diff的input与output都大于1,同时output比input大一个数量级以上;
|
|
239
|
-
- 统计数据Max diff除以max(0.01, Bench max)的output > 0.1同时input < 0.01;
|
|
240
|
-
- 真实数据One Thousandth Err Ratio的input - output > 0.1;
|
|
241
|
-
- 真实数据Cosine的input - output > 0.1。
|
|
317
|
+
### 3.6 计算精度评价指标分析
|
|
242
318
|
|
|
243
|
-
|
|
319
|
+
1. Cosine:通过计算两个向量的余弦值来判断其相似度,数值越接近于 1 说明计算出的两个张量越相似,实际可接受阈值为大于 0.99。在计算中可能会存在 nan,主要由于可能会出现其中一个向量为 0。
|
|
320
|
+
|
|
321
|
+
2. MaxAbsErr:当最大绝对误差越接近 0 表示其计算的误差越小,实际可接受阈值为小于 0.001。
|
|
244
322
|
|
|
245
|
-
|
|
323
|
+
3. MaxRelativeErr:当最大相对误差越接近 0 表示其计算的误差越小。
|
|
324
|
+
|
|
325
|
+
当 dump 数据中存在 0 或 Nan 时,比对结果中最大相对误差则出现 inf 或 Nan 的情况,属于正常现象。
|
|
326
|
+
|
|
327
|
+
4. One Thousandth Err Ratio(双千分之一)、Five Thousandths Err Ratio(双千分之五)精度指标:是指 NPU 的 Tensor 中的元素逐个与对应的标杆数据对比,相对误差大于千分之一、千分之五的比例占总元素个数的比例小于千分之一、千分之五。该数据仅作为精度下降趋势的参考,并不参与计算精度是否通过的判定。
|