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.
Files changed (194) hide show
  1. {mindstudio_probe-1.0.4.dist-info → mindstudio_probe-1.1.0.dist-info}/METADATA +1 -1
  2. mindstudio_probe-1.1.0.dist-info/RECORD +287 -0
  3. msprobe/README.md +46 -16
  4. msprobe/__init__.py +16 -1
  5. msprobe/config.json +0 -2
  6. msprobe/core/advisor/advisor.py +8 -8
  7. msprobe/core/advisor/advisor_const.py +6 -7
  8. msprobe/core/advisor/advisor_result.py +12 -12
  9. msprobe/core/common/const.py +64 -3
  10. msprobe/core/common/exceptions.py +2 -2
  11. msprobe/core/common/file_utils.py +54 -9
  12. msprobe/core/common/inplace_op_checker.py +38 -0
  13. msprobe/core/common/inplace_ops.yaml +251 -0
  14. msprobe/core/common/log.py +21 -11
  15. msprobe/core/common/utils.py +153 -167
  16. msprobe/core/common_config.py +18 -25
  17. msprobe/core/compare/acc_compare.py +209 -36
  18. msprobe/core/compare/check.py +102 -17
  19. msprobe/core/compare/compare_cli.py +21 -1
  20. msprobe/core/compare/highlight.py +41 -5
  21. msprobe/core/compare/multiprocessing_compute.py +33 -8
  22. msprobe/core/compare/npy_compare.py +21 -6
  23. msprobe/core/compare/utils.py +82 -48
  24. msprobe/core/data_dump/data_collector.py +31 -32
  25. msprobe/core/data_dump/data_processor/base.py +45 -22
  26. msprobe/core/data_dump/data_processor/factory.py +20 -3
  27. msprobe/core/data_dump/data_processor/mindspore_processor.py +11 -5
  28. msprobe/core/data_dump/data_processor/pytorch_processor.py +24 -7
  29. msprobe/core/data_dump/json_writer.py +63 -42
  30. msprobe/core/data_dump/scope.py +32 -16
  31. msprobe/core/grad_probe/constant.py +4 -0
  32. msprobe/core/grad_probe/grad_compare.py +2 -3
  33. msprobe/core/grad_probe/utils.py +16 -3
  34. msprobe/docs/01.installation.md +19 -9
  35. msprobe/docs/02.config_introduction.md +52 -80
  36. msprobe/docs/03.config_examples.md +3 -13
  37. msprobe/docs/04.acl_config_examples.md +11 -9
  38. msprobe/docs/05.data_dump_PyTorch.md +140 -12
  39. msprobe/docs/06.data_dump_MindSpore.md +47 -5
  40. msprobe/docs/07.accuracy_checker_PyTorch.md +57 -34
  41. msprobe/docs/08.accuracy_checker_online_PyTorch.md +51 -11
  42. msprobe/docs/09.accuracy_checker_MindSpore.md +8 -8
  43. msprobe/docs/10.accuracy_compare_PyTorch.md +181 -99
  44. msprobe/docs/11.accuracy_compare_MindSpore.md +162 -31
  45. msprobe/docs/13.overflow_check_MindSpore.md +1 -1
  46. msprobe/docs/15.free_benchmarking_PyTorch.md +59 -53
  47. msprobe/docs/16.free_benchmarking_MindSpore.md +140 -0
  48. msprobe/docs/17.grad_probe.md +14 -16
  49. msprobe/docs/18.online_dispatch.md +89 -0
  50. msprobe/docs/{FAQ_PyTorch.md → FAQ.md} +22 -10
  51. msprobe/docs/img/ms_dump.png +0 -0
  52. msprobe/docs/img/ms_layer.png +0 -0
  53. msprobe/docs/img/pt_dump.png +0 -0
  54. msprobe/mindspore/__init__.py +1 -0
  55. msprobe/mindspore/api_accuracy_checker/api_accuracy_checker.py +35 -11
  56. msprobe/mindspore/api_accuracy_checker/api_info.py +7 -0
  57. msprobe/mindspore/cell_processor.py +27 -3
  58. msprobe/mindspore/common/const.py +2 -0
  59. msprobe/mindspore/common/utils.py +18 -2
  60. msprobe/mindspore/compare/distributed_compare.py +9 -22
  61. msprobe/mindspore/compare/layer_mapping.py +146 -0
  62. msprobe/mindspore/compare/modify_mapping.py +107 -0
  63. msprobe/mindspore/compare/ms_compare.py +173 -35
  64. msprobe/mindspore/compare/ms_graph_compare.py +27 -11
  65. msprobe/mindspore/debugger/debugger_config.py +16 -13
  66. msprobe/mindspore/debugger/precision_debugger.py +37 -13
  67. msprobe/mindspore/dump/dump_tool_factory.py +16 -1
  68. msprobe/mindspore/dump/hook_cell/api_registry.py +11 -1
  69. msprobe/mindspore/dump/hook_cell/primitive_hooks.py +206 -0
  70. msprobe/mindspore/dump/hook_cell/support_wrap_ops.yaml +82 -10
  71. msprobe/mindspore/dump/hook_cell/wrap_api.py +21 -13
  72. msprobe/mindspore/dump/jit_dump.py +41 -17
  73. msprobe/mindspore/dump/kernel_graph_dump.py +19 -3
  74. msprobe/mindspore/dump/kernel_kbyk_dump.py +19 -4
  75. msprobe/mindspore/free_benchmark/api_pynative_self_check.py +19 -4
  76. msprobe/mindspore/free_benchmark/common/config.py +15 -0
  77. msprobe/mindspore/free_benchmark/common/handler_params.py +15 -0
  78. msprobe/mindspore/free_benchmark/common/utils.py +19 -5
  79. msprobe/mindspore/free_benchmark/decorator/dec_forward.py +16 -2
  80. msprobe/mindspore/free_benchmark/decorator/decorator_factory.py +18 -3
  81. msprobe/mindspore/free_benchmark/handler/base_handler.py +18 -3
  82. msprobe/mindspore/free_benchmark/handler/check_handler.py +18 -3
  83. msprobe/mindspore/free_benchmark/handler/fix_handler.py +15 -0
  84. msprobe/mindspore/free_benchmark/handler/handler_factory.py +18 -3
  85. msprobe/mindspore/free_benchmark/perturbation/add_noise.py +22 -7
  86. msprobe/mindspore/free_benchmark/perturbation/base_perturbation.py +15 -0
  87. msprobe/mindspore/free_benchmark/perturbation/bit_noise.py +22 -7
  88. msprobe/mindspore/free_benchmark/perturbation/exchange_value.py +44 -18
  89. msprobe/mindspore/free_benchmark/perturbation/improve_precision.py +18 -4
  90. msprobe/mindspore/free_benchmark/perturbation/no_change.py +16 -1
  91. msprobe/mindspore/free_benchmark/perturbation/perturbation_factory.py +20 -5
  92. msprobe/mindspore/free_benchmark/self_check_tool_factory.py +15 -0
  93. msprobe/mindspore/grad_probe/global_context.py +18 -8
  94. msprobe/mindspore/overflow_check/kernel_graph_overflow_check.py +20 -4
  95. msprobe/mindspore/overflow_check/overflow_check_tool_factory.py +15 -0
  96. msprobe/mindspore/service.py +42 -123
  97. msprobe/pytorch/__init__.py +20 -1
  98. msprobe/pytorch/api_accuracy_checker/common/config.py +19 -2
  99. msprobe/pytorch/api_accuracy_checker/common/utils.py +53 -21
  100. msprobe/pytorch/api_accuracy_checker/compare/algorithm.py +19 -2
  101. msprobe/pytorch/api_accuracy_checker/compare/api_precision_compare.py +47 -21
  102. msprobe/pytorch/api_accuracy_checker/compare/compare.py +51 -21
  103. msprobe/pytorch/api_accuracy_checker/compare/compare_column.py +23 -6
  104. msprobe/pytorch/api_accuracy_checker/compare/compare_utils.py +28 -8
  105. msprobe/pytorch/api_accuracy_checker/config.yaml +1 -1
  106. msprobe/pytorch/api_accuracy_checker/run_ut/data_generate.py +67 -32
  107. msprobe/pytorch/api_accuracy_checker/run_ut/multi_run_ut.py +26 -5
  108. msprobe/pytorch/api_accuracy_checker/run_ut/run_overflow_check.py +19 -2
  109. msprobe/pytorch/api_accuracy_checker/run_ut/run_ut.py +51 -125
  110. msprobe/pytorch/api_accuracy_checker/run_ut/run_ut_utils.py +146 -3
  111. msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/attl.py +21 -0
  112. msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/client.py +78 -33
  113. msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/device_dispatch.py +27 -4
  114. msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/dump_dispatch.py +110 -0
  115. msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/server.py +36 -11
  116. msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/torch_ops_config.yaml +63 -0
  117. msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/utils.py +44 -0
  118. msprobe/pytorch/bench_functions/__init__.py +18 -3
  119. msprobe/pytorch/bench_functions/apply_adam_w.py +15 -0
  120. msprobe/pytorch/bench_functions/confusion_transpose.py +15 -0
  121. msprobe/pytorch/bench_functions/fast_gelu.py +15 -0
  122. msprobe/pytorch/bench_functions/layer_norm_eval.py +15 -0
  123. msprobe/pytorch/bench_functions/linear.py +15 -0
  124. msprobe/pytorch/bench_functions/matmul_backward.py +21 -6
  125. msprobe/pytorch/bench_functions/npu_fusion_attention.py +180 -151
  126. msprobe/pytorch/bench_functions/rms_norm.py +15 -0
  127. msprobe/pytorch/bench_functions/rotary_mul.py +28 -9
  128. msprobe/pytorch/bench_functions/scaled_mask_softmax.py +15 -0
  129. msprobe/pytorch/bench_functions/swiglu.py +20 -5
  130. msprobe/pytorch/common/__init__.py +15 -0
  131. msprobe/pytorch/common/log.py +18 -6
  132. msprobe/pytorch/common/parse_json.py +26 -11
  133. msprobe/pytorch/common/utils.py +40 -35
  134. msprobe/pytorch/compare/distributed_compare.py +11 -11
  135. msprobe/pytorch/compare/match.py +15 -0
  136. msprobe/pytorch/compare/pt_compare.py +38 -6
  137. msprobe/pytorch/debugger/debugger_config.py +52 -39
  138. msprobe/pytorch/debugger/precision_debugger.py +72 -24
  139. msprobe/pytorch/free_benchmark/__init__.py +20 -5
  140. msprobe/pytorch/free_benchmark/common/enums.py +28 -0
  141. msprobe/pytorch/free_benchmark/common/params.py +15 -0
  142. msprobe/pytorch/free_benchmark/common/utils.py +17 -1
  143. msprobe/pytorch/free_benchmark/compare/grad_saver.py +28 -7
  144. msprobe/pytorch/free_benchmark/compare/single_benchmark.py +15 -0
  145. msprobe/pytorch/free_benchmark/main.py +19 -4
  146. msprobe/pytorch/free_benchmark/perturbed_layers/base_layer.py +15 -0
  147. msprobe/pytorch/free_benchmark/perturbed_layers/layer_factory.py +19 -4
  148. msprobe/pytorch/free_benchmark/perturbed_layers/npu/add_noise.py +15 -0
  149. msprobe/pytorch/free_benchmark/perturbed_layers/npu/bit_noise.py +15 -0
  150. msprobe/pytorch/free_benchmark/perturbed_layers/npu/change_value.py +26 -2
  151. msprobe/pytorch/free_benchmark/perturbed_layers/npu/improve_precision.py +15 -0
  152. msprobe/pytorch/free_benchmark/perturbed_layers/npu/no_change.py +15 -0
  153. msprobe/pytorch/free_benchmark/perturbed_layers/npu/npu_base_layser.py +15 -0
  154. msprobe/pytorch/free_benchmark/perturbed_layers/run_cpu.py +15 -0
  155. msprobe/pytorch/free_benchmark/result_handlers/base_handler.py +55 -16
  156. msprobe/pytorch/free_benchmark/result_handlers/check_handler.py +15 -0
  157. msprobe/pytorch/free_benchmark/result_handlers/fix_handler.py +15 -0
  158. msprobe/pytorch/free_benchmark/result_handlers/handler_factory.py +15 -0
  159. msprobe/pytorch/free_benchmark/result_handlers/preheat_handler.py +19 -4
  160. msprobe/pytorch/function_factory.py +17 -2
  161. msprobe/pytorch/functional/module_dump.py +84 -0
  162. msprobe/pytorch/grad_probe/grad_stat_csv.py +2 -2
  163. msprobe/pytorch/hook_module/__init__.py +16 -1
  164. msprobe/pytorch/hook_module/api_registry.py +13 -8
  165. msprobe/pytorch/hook_module/hook_module.py +17 -19
  166. msprobe/pytorch/hook_module/utils.py +4 -6
  167. msprobe/pytorch/hook_module/wrap_aten.py +12 -11
  168. msprobe/pytorch/hook_module/wrap_distributed.py +6 -7
  169. msprobe/pytorch/hook_module/wrap_functional.py +10 -11
  170. msprobe/pytorch/hook_module/wrap_npu_custom.py +9 -17
  171. msprobe/pytorch/hook_module/wrap_tensor.py +4 -6
  172. msprobe/pytorch/hook_module/wrap_torch.py +4 -6
  173. msprobe/pytorch/hook_module/wrap_vf.py +4 -6
  174. msprobe/pytorch/module_processer.py +17 -2
  175. msprobe/pytorch/online_dispatch/compare.py +11 -12
  176. msprobe/pytorch/online_dispatch/single_compare.py +7 -7
  177. msprobe/pytorch/online_dispatch/torch_ops_config.yaml +8 -0
  178. msprobe/pytorch/online_dispatch/utils.py +1 -4
  179. msprobe/pytorch/parse.py +15 -0
  180. msprobe/pytorch/parse_tool/cli.py +5 -6
  181. msprobe/pytorch/parse_tool/lib/compare.py +9 -10
  182. msprobe/pytorch/parse_tool/lib/parse_tool.py +3 -0
  183. msprobe/pytorch/parse_tool/lib/utils.py +28 -24
  184. msprobe/pytorch/parse_tool/lib/visualization.py +1 -1
  185. msprobe/pytorch/pt_config.py +167 -38
  186. msprobe/pytorch/service.py +97 -32
  187. mindstudio_probe-1.0.4.dist-info/RECORD +0 -276
  188. msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/ssl_config.py +0 -10
  189. msprobe/pytorch/functional/data_processor.py +0 -0
  190. msprobe/pytorch/functional/dump_module.py +0 -39
  191. {mindstudio_probe-1.0.4.dist-info → mindstudio_probe-1.1.0.dist-info}/LICENSE +0 -0
  192. {mindstudio_probe-1.0.4.dist-info → mindstudio_probe-1.1.0.dist-info}/WHEEL +0 -0
  193. {mindstudio_probe-1.0.4.dist-info → mindstudio_probe-1.1.0.dist-info}/entry_points.txt +0 -0
  194. {mindstudio_probe-1.0.4.dist-info → mindstudio_probe-1.1.0.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,8 @@
1
1
  # MindSpore 场景的精度数据采集
2
2
 
3
- msprobe 工具主要通过在训练脚本内添加 dump 接口、启动训练的方式采集精度数据。目前,静态图场景仅支持 kernel 级数据采集,对应 config.json 配置中的 "L2" level;动态图场景支持cell、API、kernel级数据采集,对应 config.json 配置中的 "L0"、"L1" 、"L2" level。
3
+ msprobe 工具主要通过在训练脚本内添加 dump 接口、启动训练的方式采集精度数据。目前,静态图场景仅支持 kernel 级数据采集,对应 config.json 配置中的 "L2" level;动态图场景支持cell、API、kernel级数据采集,对应 config.json 配置中的 "L0"、"L1" 、"L2"、"mix" level。
4
+
5
+ 需要注意,**动态图 kernel 级**("L2" level)精度数据采集对象为被 PSJit 或 PIJit 装饰的 Cell 或 function 内的算子,其被装饰部分实际以**静态图**模式执行,所以此场景下的工具使用方式与静态图场景完全相同。下文无特殊说明时,介绍的动态图场景不包括 kernel 级("L2" level)dump 情形。
4
6
 
5
7
  精度数据采集功能的配置示例见[MindSpore 静态图场景下 task 配置为 statistics](https://gitee.com/ascend/mstt/blob/master/debug/accuracy_tools/msprobe/docs/03.config_examples.md#21-task-%E9%85%8D%E7%BD%AE%E4%B8%BA-statistics)、[MindSpore 静态图场景下 task 配置为 tensor](https://gitee.com/ascend/mstt/blob/master/debug/accuracy_tools/msprobe/docs/03.config_examples.md#22-task-%E9%85%8D%E7%BD%AE%E4%B8%BA-tensor)、[MindSpore 动态图场景下 task 配置为 statistics](https://gitee.com/ascend/mstt/blob/master/debug/accuracy_tools/msprobe/docs/03.config_examples.md#31-task-%E9%85%8D%E7%BD%AE%E4%B8%BA-statistics)、[MindSpore 动态图场景下 task 配置为 tensor](https://gitee.com/ascend/mstt/blob/master/debug/accuracy_tools/msprobe/docs/03.config_examples.md#32-task-%E9%85%8D%E7%BD%AE%E4%B8%BA-tensor)。
6
8
 
@@ -25,12 +27,13 @@ ops: # ops为算子类别,找到对应的类别,在该类别下按照下列
25
27
  PrecisionDebugger(config_path=None)
26
28
  ```
27
29
 
30
+ **参数说明**:
31
+
28
32
  1. config_path:指定 dump 配置文件路径,string 类型。参数示例:"./config.json"。未配置该路径时,默认使用 [config.json](../config.json) 文件的默认配置,配置选项含义可见 [config.json 介绍](./02.config_introduction.md)。
29
33
 
30
34
  #### 1.1.1 start
31
35
 
32
- **功能说明**:启动精度数据采集。需在模型执行模式(静态图/动态图、O0/O1/O2编译等级)设置后调用。
33
- 静态图场景下,必须在模型初始化及 mindspore.communication.init 调用前添加;动态图场景下,如果进行kernel级别("L2" level)dump或没有使用 [Model](https://www.mindspore.cn/tutorials/zh-CN/r2.3.1/advanced/model.html) 高阶 API 进行训练,则需要与 stop 函数一起添加在 for 循环内,否则只有需要传入model参数时,才使用该接口。
36
+ **功能说明**:启动精度数据采集。需在模型执行模式(静态图/动态图、O0/O1/O2编译等级)设置后调用。静态图场景下,必须在模型初始化及 mindspore.communication.init 调用前添加;动态图场景下,如果没有使用 [Model](https://gitee.com/link?target=https%3A%2F%2Fwww.mindspore.cn%2Ftutorials%2Fzh-CN%2Fr2.3.1%2Fadvanced%2Fmodel.html) 高阶 API 进行训练,则需要与 stop 函数一起添加在 for 循环内,否则只有需要传入model参数时,才使用该接口。
34
37
 
35
38
  **原型**:
36
39
 
@@ -38,6 +41,8 @@ PrecisionDebugger(config_path=None)
38
41
  start(model=None)
39
42
  ```
40
43
 
44
+ **参数说明**:
45
+
41
46
  1. model:指具体的 mindspore.nn.Cell,默认不配置。Cell级别("L0" level)dump 时,传入 model 可以采集 model 内的所有Cell 对象数据。API级别("L1" level)dump 时,传入 model 可以采集 model 内包含 primitive op 对象在内的所有 API 数据,若不传入 model 参数,则只采集非 primitive op 的 API 数据。
42
47
 
43
48
  #### 1.1.2 stop
@@ -60,6 +65,22 @@ stop()
60
65
  step()
61
66
  ```
62
67
 
68
+ #### 1.1.4 forward_backward_dump_end
69
+
70
+ **功能说明**:在 **start** 函数和在 **stop** 函数之间调用,表示采集 **start** 到 **forward_backward_dump_end**之间的L1级别的正反向数据。
71
+
72
+ **仅支持L1级别数据采集场景。**
73
+
74
+ **L1级别数据中的jit数据采集行为不受此接口影响**
75
+
76
+ **仅未使用 Model 高阶 API 的动态图场景支持。**
77
+
78
+ **原型**:
79
+
80
+ ```Python
81
+ forward_backward_dump_end()
82
+ ```
83
+
63
84
  ### 1.2 msprobe.mindspore.common.utils.MsprobeStep
64
85
 
65
86
  **功能说明**:MindSpore Callback类,自动在每个step开始时调用start()接口,在每个step结束时调用stop()、step()接口。实现使用 Model 高阶 API 的动态图场景下 L0、L1 级别的精度数据采集控制,控制粒度为单个 **Step** ,而 PrecisionDebugger.start, PrecisionDebugger.stop 接口的控制粒度任意训练代码段。
@@ -70,8 +91,25 @@ step()
70
91
  MsprobeStep(debugger)
71
92
  ```
72
93
 
94
+ **参数说明**:
95
+
73
96
  1. debugger:PrecisionDebugger对象。
74
97
 
98
+ ### 1.3 msprobe.mindspore.seed_all
99
+
100
+ **功能说明**:用于固定网络中的随机性和开启确定性计算。
101
+
102
+ **原型**:
103
+ ```python
104
+ seed_all(seed=1234, mode=False)
105
+ ```
106
+
107
+ **参数说明**:
108
+
109
+ 1. seed: 随机性种子,默认值:1234,非必选。参数示例: seed=1000。该参数用于 random、numpy.random, mindspore.common.Initializer、mindspore.nn.probability.distribution的随机数生成以及 Python 中 str、bytes、datetime 对象的 hash 算法。
110
+
111
+ 2. mode:确定性计算使能,可配置 True 或 False,默认值:False,非必选。参数示例:mode=True。该参数设置为 True 后,将会开启算子确定性运行模式与归约类通信算子(AllReduce、ReduceScatter、Reduce)的确定性计算。注意:确定性计算会导致API执行性能降低,建议在发现模型多次执行结果不同的情况下开启。
112
+
75
113
  ## 2 示例代码
76
114
 
77
115
  ### 2.1 MindSpore 静态图场景
@@ -204,8 +242,9 @@ dump结果目录结构示例如下:
204
242
  | | | | ├── MintFunctional.relu.0.backward.input.0.npy
205
243
  | | | | ├── Mint.abs.0.forward.input.0.npy
206
244
  | | | | ├── Functional.split.0.forward.input.0.npy
245
+ | | | | ├── Tensor.__add__.0.forward.output.0.npy
207
246
  | | | | ...
208
- | | | | └── Jit.AlexNet.0.forward.input.0.npy
247
+ | | | | ├── Jit.AlexNet.0.forward.input.0.npy
209
248
  | | | | └── Cell.relu.ReLU.forward.0.input.0.npy # config.json文件配置level为L0时dump的cell模块级数据,命名格式为{Cell}_{cell_name}_{class_name}_{前向反向}.{index}.{input/output}.{参数序号}
210
249
  │ | | ├── dump.json # 保存前反向算子、算子的统计量信息或溢出算子信息。包含dump数据的API名称(命名格式为:{api_type}_{api_name}_{API调用次数}_{前向反向}_{input/output}.{参数序号})、dtype、 shape、各数据的max、min、mean、L2norm统计信息以及当配置summary_mode="md5"时的md5数据。其中,“参数序号”表示该API下的第n个参数,例如1,则为第一个参数,若该参数为list格式,则根据list继续排序,例如1.1,表示该API的第1个参数的第1个子参数;L2norm表示L2范数(平方根)
211
250
  │ | | ├── stack.json # 算子调用栈信息
@@ -228,7 +267,10 @@ dump 过程中,npy 文件在对应算子或者模块被执行后就会落盘
228
267
 
229
268
  其中 rank 为设备上各卡的 ID,每张卡上 dump 的数据会生成对应 dump 目录。非分布式场景下没有 rank ID,目录名称为 rank。
230
269
 
231
- 动态图场景下使能 PSJit 或 PIJit,装饰特定 Cell 或 function,被装饰的部分会全部/部分使能**静态图**流程。PSJit 场景下 config.json 文件配置 level 为 L1 时,被 PSJit 装饰的部分也作为 API 被 dump 到对应目录;配置 level 为 L2 时,则只会 dump 用户网络中静态图流程下的相关 kernel, 其结果目录同jit_level 为 O0/O1 时的静态图 dump 相同。PIJit 场景开启 dump 工具后,会被还原为动态图,按 API 粒度进行 dump。
270
+ 动态图场景下使能 PSJit 或 PIJit,装饰特定 Cell 或 function,被装饰的部分会全部/部分使能**静态图**流程。
271
+
272
+ - PSJit 场景下 config.json 文件配置 level 为 L1 时,被 PSJit 装饰的部分也作为 API 被 dump 到对应目录;配置 level 为 L2 时,则只会 dump 用户网络中静态图流程下的相关 kernel,其结果目录同jit_level 为 O0/O1 时的静态图 dump 相同。
273
+ - PIJit 场景下 config.json 文件配置 level 为 L1 时,会被还原为动态图,按 API 粒度进行 dump;配置 level 为 L2 时,则只会 dump 用户网络中静态图流程下的相关 kernel。
232
274
 
233
275
  npy 文件保存的前缀和 MindSpore 对应关系如下:
234
276
 
@@ -2,19 +2,19 @@
2
2
 
3
3
  ## 1 简介
4
4
 
5
- **PyTorch 离线精度预检**<sup>a</sup>通过扫描昇腾 NPU 上用户训练模型中的所有 API,输出模型精度的诊断和分析结果。具体而言,该工具通过采集模型中所有 API 的前反向信息,构造相应的单元测试,将 NPU 输出与标杆(CPU 高精度)比对,从而计算对应的精度指标,该过程已封装为 run_ut.py 函数;将 NPU 环境下采集的预检数据拷贝至 GPU 环境,同样执行 run_ut.py;最后通过**新精度标准比对法**<sup>b</sup>将 NPU 和 GPU 的预检结果进行比对,从而找出 NPU 中存在精度问题的 API。同时,本工具支持随机生成模式和真实数据模式<sup>c</sup>。
5
+ **PyTorch 离线精度预检**通过扫描昇腾 NPU 上用户训练模型中的所有 API,输出模型精度的诊断和分析结果。具体而言,该工具通过采集模型中所有 API 的前反向信息,构造相应的单元测试,将 NPU 输出与标杆(CPU 高精度)比对,从而计算对应的精度指标,该过程通过子命令 run_ut 执行;将 NPU 环境下采集的预检数据拷贝至 GPU 环境,同样执行 run_ut;最后通过**新精度标准比对法**<sup>a</sup>将 NPU 和 GPU 的预检结果进行比对,从而找出 NPU 中存在精度问题的 API。同时,本工具支持**随机生成模式和真实数据模式**<sup>b</sup>。
6
6
 
7
- a. 支持 PyTorch 版本:1.11/2.0/2.1/2.2;
8
- b. 依据新精度标准,对不同的API采取不同的比对算法(包括绝对阈值法,标杆比对法、二进制一致法、ULP误差比对法和双千指标法),最终给定预检判定结果;
9
- c. 在预检 dump 时可以选择由工具构造随机数获得 dump 数据或选择真实输入的数据进行预检 dump 操作。随机生成模式执行效率高,可以快速获得结果,但数据精度低,只能大致判断精度问题;真实数据模式执行效率略低于随机生成模式,但是数据精度高,可以准确判断精度问题。
7
+ a. 依据新精度标准,对不同的API采取不同的比对算法(包括绝对阈值法,标杆比对法、二进制一致法、ULP误差比对法和双千指标法),最终给定预检判定结果;
8
+
9
+ b. 在预检 dump 时可以选择由工具构造随机数获得 dump 数据或选择真实输入的数据进行预检 dump 操作。随机生成模式(对应 task: "statistics")执行效率高,可以快速获得结果,但数据精度低,只能大致判断精度问题;真实数据模式(对应 task: "tensor")执行效率略低于随机生成模式,但是数据精度高,可以准确判断精度问题。
10
10
 
11
11
  ## 2 离线预检流程
12
12
 
13
13
  1. 在 NPU 和 GPU 环境下分别安装 msprobe。详见[ msprobe 安装](./01.installation.md)章节。
14
14
  2. 在 NPU 训练脚本内添加 msprobe 工具 dump 接口 PrecisionDebugger,采集待预检数据。注意需要配置 level="L1"。
15
15
  3. 将 NPU 环境下 dump 的预检数据拷贝至 GPU 环境。
16
- 4. 在 NPU 和 GPU 环境下分别执行 run_ut.py,生成的结果最终用于 api_precision_compare.py 函数的输入。详见 [3 离线预检操作指导](#3-离线预检操作指导)。
17
- 5. 将 NPU 和 GPU 执行 run_ut.py 生成的 `accuracy_checking_details_{timestamp}.csv` 结果文件拷贝至同一环境下。
16
+ 4. 在 NPU 和 GPU 环境下分别执行 run_ut,生成的结果最终用于 api_precision_compare.py 函数的输入。详见 [3 离线预检操作指导](#3-离线预检操作指导)。
17
+ 5. 将 NPU 和 GPU 执行 run_ut 生成的 `accuracy_checking_details_{timestamp}.csv` 结果文件拷贝至同一环境下。
18
18
  6. 运行 api_precision_compare.py,输出结果为预检操作的最终结果。详见 [5 预检结果比对](#5-预检结果比对)章节。
19
19
 
20
20
  ## 3 离线预检操作指导
@@ -23,10 +23,10 @@
23
23
 
24
24
  run_ut 预检操作包括以下两种方式:
25
25
 
26
- - 使用 run_ut.py 执行预检:适用于数据量较小的单卡场景。
27
- - 使用 multi_run_ut.py 执行多线程预检:适用于数据量较大的大模型场景。
26
+ - 使用 run_ut 子命令执行预检:适用于数据量较小的单卡场景。
27
+ - 使用 multi_run_ut 子命令执行多线程预检:适用于数据量较大的大模型场景。
28
28
 
29
- ### 3.1 使用 run_ut.py 执行预检
29
+ ### 3.1 使用 run_ut 执行预检
30
30
 
31
31
  将 API 信息输入到 run_ut 模块进行精度检测并比对,运行如下命令:
32
32
 
@@ -38,8 +38,7 @@ msprobe -f pytorch run_ut -api_info ./dump.json
38
38
  | ---------------------------- | ------------------------------------------------------------ | ---------------------------------- |
39
39
  | -api_info 或 --api_info_file | 指定 API 信息文件 dump.json。 | 是 |
40
40
  | -save_error_data | 保存精度未达标的 API 输入输出数据。 | 否 |
41
- | -o 或 --out_path | 指定 run_ut 执行结果存盘路径,默认“./”(相对于 run_ut 的路径)。 | 否 |
42
- | | | |
41
+ | -o 或 --out_path | 指定 run_ut 执行结果存盘路径,默认“./”。 | 否 |
43
42
  | -j 或 --jit_compile | 开启 jit 编译。 | 否 |
44
43
  | -d 或 --device | 指定 Device ID,选择 UT 代码运行所在的卡,默认值为 0。 | 否 |
45
44
  | -csv_path 或 --result_csv_path | 指定本次运行中断时生成的 `accuracy_checking_result_{timestamp}.csv` 文件路径,执行 run_ut 中断时,若想从中断处继续执行,配置此参数即可。需要指定为上次中断的 `accuracy_checking_result_{timestamp}.csv` 文件。详见 [3.3 断点续检](#33-断点续检)。 | run_ut 操作中断后继续执行场景下必须配置 |
@@ -47,19 +46,19 @@ msprobe -f pytorch run_ut -api_info ./dump.json
47
46
  | -config 或 --config_path | 指定离线预检操作过程中额外配置(包括黑名单、白名单等)的 [config.json](../config.json) 文件,默认未配置。config.json 文件的配置可参考[配置文件介绍](./02.config_introduction.md)。 | 否 |
48
47
 
49
48
  run_ut 执行结果包括 `accuracy_checking_result_{timestamp}.csv` 和 `accuracy_checking_details_{timestamp}.csv` 两个文件。`accuracy_checking_result_{timestamp}.csv` 属于 API 级,标明每个 API 是否通过测试。建议用户先查看 `accuracy_checking_result_{timestamp}.csv` 文件,对于其中没有通过测试的或者特定感兴趣的 API,根据其 API name 字段在 `accuracy_checking_details_{timestamp}.csv` 中查询其各个输出的达标情况以及比较指标。详细介绍请参见[ 4 预检结果](#4-预检结果)。
50
-
49
+
51
50
  如果需要保存比对不达标的输入和输出数据,可以在 run_ut 执行命令结尾添加 `-save_error_data`,例如:
52
51
 
53
52
  ```bash
54
53
  msprobe -f pytorch run_ut -api_info ./dump.json -save_error_data
55
54
  ```
56
55
 
57
- 数据默认会存盘到 './ut_error_data{timestamp}' 路径下(相对于启动 run_ut 的路径),如有需要,用户可以通过 error_data_path 参数来配置保存路径,error_data_path 参数在 [config.json](../config.json) 文件或 [config.yaml](../pytorch/api_accuracy_checker/config.yaml) 文件配置,config.json 文件需要在 run_ut 操作时通过 -config 参数指定,config.yaml 。
56
+ 数据默认会存盘到 './ut_error_data{timestamp}' 路径下,如有需要,用户可以通过 error_data_path 参数来配置保存路径,error_data_path 参数在 [config.json](../config.json) 文件或 [config.yaml](../pytorch/api_accuracy_checker/config.yaml) 文件配置,config.json 文件需要在 run_ut 操作时通过 -config 参数指定。
58
57
 
59
58
  #### 3.1.1 config.yaml 文件说明
60
59
 
61
60
  config.yaml 文件可以通过配置参数来控制 dump 和 run_ut 操作的白名单、黑名单等功能。操作步骤如下:
62
-
61
+
63
62
  - config.yaml 文件通常位于类似 /home/xxx/miniconda3/envs/xxx/lib/python3.8/site-packages/msprobe/pytorch/api_accuracy_checker/config.yaml 的路径中。
64
63
 
65
64
  - 进入 config.yaml 文件
@@ -88,15 +87,15 @@ msprobe -f pytorch run_ut -api_info ./dump.json -save_error_data
88
87
 
89
88
  #### 3.1.2 API 预检黑名单和白名单
90
89
 
91
- run_ut 过程支持 API 预检黑名单和白名单,通过如下文件配置 black_list(黑名单)或white_list(白名单)参数来指定不需要或需要预检的API名称:
90
+ run_ut 过程支持 API 预检黑名单和白名单,通过如下文件配置 black_list(黑名单)或 white_list(白名单)参数来指定不需要或需要预检的 API 名称:
92
91
 
93
92
  - 配置 [config.json](../config.json) 文件,该文件需要在 run_ut 操作时通过 -config 参数指定。
94
93
 
95
94
  - config.json 文件的优先级高于 config.yaml 文件,即执行 config.json 文件时,config.yaml 文件的配置不生效。
96
95
 
97
- ### 3.2 使用 multi_run_ut.py 执行多线程预检
96
+ ### 3.2 使用 multi_run_ut 执行多线程预检
98
97
 
99
- multi_run_ut.py 脚本,可以并行执行多个 run_ut 操作,从而减少预检耗时。示例如下:
98
+ multi_run_ut 脚本,可以并行执行多个 run_ut 操作,从而减少预检耗时。示例如下:
100
99
 
101
100
  ```bash
102
101
  msprobe -f pytorch multi_run_ut -api_info ./dump.json -n 32 -d 0 1 2 3
@@ -106,7 +105,7 @@ msprobe -f pytorch multi_run_ut -api_info ./dump.json -n 32 -d 0 1 2 3
106
105
  | ---------------------------- | ------------------------------------------------------------ | ---------------------------------- |
107
106
  | -api_info 或 --api_info_file | 指定 API 信息文件 dump.json。 | 是 |
108
107
  | -save_error_data | 保存精度未达标的 API 输入输出数据。 | 否 |
109
- | -o 或 --out_path | 指定 run_ut 执行结果存盘路径,默认“./”(相对于 run_ut 的路径)。 | 否 |
108
+ | -o 或 --out_path | 指定 run_ut 执行结果存盘路径,默认“./”。 | 否 |
110
109
  | -j 或 --jit_compile | 开启 jit 编译。 | 否 |
111
110
  | -n | 同时执行 run_ut 线程的数量,默认为 8,最大支持 64,但每个 Device 最大支持 8 个线程。当指定多个线程和多个 Device 时,线程数在每张卡上均分。 | 否 |
112
111
  | -d 或 --device | 指定 Device ID,选择 UT 代码运行所在的卡,默认值为 0,支持同时指定 0~7,共 8 个 Device。 | 否 |
@@ -146,7 +145,7 @@ msprobe -f pytorch run_ut -api_info ./dump.json -csv_path /home/xxx/ut/accuracy_
146
145
 
147
146
  Forward Test Success 和 Backward Test Success 是否通过测试是由 `accuracy_checking_details_{timestamp}.csv` 中的余弦相似度、最大绝对误差、双百双千双万指标判定结果决定的。
148
147
 
149
- 需要注意的是 `accuracy_checking_details_{timestamp}.csv` 中可能存在一个 API 的前向(反向)有多个输出,那么每个输出记录一行,而在 `accuracy_checking_result_{timestamp}.csv` 中的结果需要该 API 的所有结果均为 pass 才能标记为 pass,只要存在一个 error 则标记 error,仅存在 waring 和 pass 且不存在 error 则标记 waring
148
+ 需要注意的是 `accuracy_checking_details_{timestamp}.csv` 中可能存在一个 API 的前向(反向)有多个输出,那么每个输出记录一行,而在 `accuracy_checking_result_{timestamp}.csv` 中的结果需要该 API 的所有结果均为 pass 才能标记为 pass,只要存在一个 error 则标记 error,仅存在 warning 和 pass 且不存在 error 则标记 warning
150
149
 
151
150
  `accuracy_checking_details_{timestamp}.csv`
152
151
 
@@ -157,7 +156,7 @@ Forward Test Success 和 Backward Test Success 是否通过测试是由 `accurac
157
156
  | API name | NPU 或 GPU下的 API 名称。 |
158
157
  | Bench Dtype | 标杆数据的 API 数据类型。 |
159
158
  | DEVICE Dtype | NPU 或 GPU 数据的 API 数据类型。 |
160
- | Shape | API 的 Shape信息。 |
159
+ | Shape | API 的 Shape 信息。 |
161
160
  | 余弦相似度 | NPU 或 GPU 数据与标杆数据的余弦相似度。 |
162
161
  | 最大绝对误差 | NPU 或 GPU 数据与标杆数据的最大绝对误差。 |
163
162
  | 双百指标 | 双百精度指标。是指 NPU 或 GPU 的 Tensor 中的元素逐个与对应的标杆数据对比,相对误差小于百分之一的个数占总元素个数的比例。测试通过标准为相对误差大于百分之一的个数占总元素个数的比例小于百分之一。 |
@@ -173,25 +172,23 @@ Forward Test Success 和 Backward Test Success 是否通过测试是由 `accurac
173
172
  | 相对误差错误率 | NPU 与标杆的正常值计算相对误差,其大于错误阈值的元素个数占正常值元素个数的比例。 |
174
173
  | 绝对误差错误率 | NPU 与标杆的小值计算绝对误差,其大于错误阈值的元素个数占小值元素个数的比例。 |
175
174
  | ULP 误差最大值 | NPU 或 GPU 数据与标杆数据 ULP 误差的最大值(取绝对值后)。 |
176
- | ULP 误差平均值 | NPU 或 GPU 数据与标杆数据ULP误差的平均值(取绝对值后)。 |
175
+ | ULP 误差平均值 | NPU 或 GPU 数据与标杆数据 ULP 误差的平均值(取绝对值后)。 |
177
176
  | ULP 误差大于阈值占比 | NPU 或 GPU 数据与标杆数据的 ULP 误差(取绝对值后)大于阈值(当 NPU 或 GPU 数据类型为 float16 或 bfloat16 时,阈值为 1;当 NPU 或 GPU 数据类型为 float32 时,阈值为 32)的元素个数占总元素的个数比例。 |
178
177
  | Status | API 预检通过状态,pass 表示通过测试,error 表示未通过,warning 表示测试未通过双千或双万精度指标,SKIP 表示该 API 的某个参数的反向不要计算梯度,所以没有任何计算过程,其他信息均为空。 |
179
178
  | message | 提示信息。 |
180
179
 
181
- **\***:
182
-
183
180
  ### 4.1 API 预检指标
184
-
181
+
185
182
  API 预检指标是通过对 `accuracy_checking_details_{timestamp}.csv` 中的余弦相似度、最大绝对误差双百、双千、双万精度指标的数值进行判断,得出该 API 是否符合精度标准的参考指标。
186
183
 
187
- API预检通过测试,则在`accuracy_checking_details_{timestamp}.csv`文件中的 Status 列标记 pass,否则标记 error 或 warning,详细规则如下:
184
+ API 预检通过测试,则在`accuracy_checking_details_{timestamp}.csv`文件中的 Status 列标记 pass,否则标记 error 或 warning,详细规则如下:
188
185
 
189
186
  - 余弦相似度 > 0.99:≤ 0.99 为不达标,标记 error,> 0.99 达标,进行下一步;
190
187
  - 最大绝对误差 < 0.001:< 0.001 达标,标记 pass,≥ 0.001 为不达标,进行下一步;
191
188
  - 双百、双千、双万精度指标:
192
189
  + 对于 float16 和 bfloat16 数据:双百指标不通过,标记 error;双百指标通过,双千指标不通过,标记 warning;双百、双千指标均通过,标记 pass。
193
190
  + 对于 float32 和 float64 数据:双千指标不通过,标记 error;双千指标通过,双万指标不通过,标记 warning;双千、双万指标均通过,标记 pass。
194
- - 在 `accuracy_checking_result_{timestamp}.csv` 中以 Forward Test Success 和 Backward Test Success 字段统计该算子前向反向输出的测试结果,对于标记 pass 的算子,则在 `accuracy_checking_result_{timestamp}.csv` 中标记 TRUE 表示测试通过,对于标记 error 或 warning 的算子,则在 `accuracy_checking_result_{timestamp}.csv` 中标记 FALSE 表示测试不通过。由于一个算子可能有多个前向或反向的输入或输出,那么该类算子的输入或输出中必须全为 pass,才能在 `accuracy_checking_result_{timestamp}.csv` 中标记 TRUE,只要有一个输入或输出标记 error 或 warning,那么在`accuracy_checking_result_{timestamp}.csv`中标记 FALSE。
191
+ - 在 `accuracy_checking_result_{timestamp}.csv` 中以 Forward Test Success 和 Backward Test Success 字段统计该算子前向反向输出的测试结果,对于标记 pass 的算子,则在 `accuracy_checking_result_{timestamp}.csv` 中标记 TRUE 表示测试通过,对于标记 error 或 warning 的算子,则在 `accuracy_checking_result_{timestamp}.csv` 中标记 FALSE 表示测试不通过。由于一个算子可能有多个前向或反向的输入或输出,那么该类算子的输入或输出中必须全为 pass,才能在 `accuracy_checking_result_{timestamp}.csv` 中标记 TRUE,只要有一个输入或输出标记 error 或 warning,那么在 `accuracy_checking_result_{timestamp}.csv` 中标记 FALSE。
195
192
 
196
193
  ### 4.2 小值域阈值
197
194
 
@@ -246,15 +243,15 @@ Forward Test Success 和 Backward Test Success 是否通过测试是由 `api_pre
246
243
  | ------------------------ | ------------------------------------------------------------ |
247
244
  | API name | NPU 或 GPU 下的 API 名称。 |
248
245
  | 小值域错误比值 | NPU 与 CPU 的小值域的错误比率 / GPU 与 CPU 的小值域的错误比率。标杆比对法指标。 |
249
- | 小值域错误判定结果 | 小值域错误比值小于等于 1 标记为 pass,1 ~ 2 之间标记为 waring,大于 2 标记为 error。 |
246
+ | 小值域错误判定结果 | 小值域错误比值小于等于 1 标记为 pass,1 ~ 2 之间标记为 warning,大于 2 标记为 error。 |
250
247
  | 均方根误差比值 | NPU 与 CPU 的均方根误差 / GPU 与 CPU 的均方根误差。标杆比对法指标。 |
251
- | 均方根误差判定结果 | 均方根误差比值小于等于 1 标记为 pass,1~2 之间标记为 waring,大于 2 标记为 error。 |
248
+ | 均方根误差判定结果 | 均方根误差比值小于等于 1 标记为 pass,1~2 之间标记为 warning,大于 2 标记为 error。 |
252
249
  | 相对误差最大值比值 | NPU 与 CPU 的相对误差最大值 / GPU 与 CPU 的相对误差最大值。标杆比对法指标。 |
253
- | 相对误差最大值判定结果 | 相对误差最大值比值小于等于 1 标记为 pass,1 ~ 10 之间标记为 waring,大于 10 标记为 error。 |
250
+ | 相对误差最大值判定结果 | 相对误差最大值比值小于等于 1 标记为 pass,1 ~ 10 之间标记为 warning,大于 10 标记为 error。 |
254
251
  | 相对误差平均值比值 | NPU 与 CPU 的相对误差的平均值 / GPU 与 CPU 的相对误差的平均值。标杆比对法指标。 |
255
- | 相对误差平均值判定结果 | 相对误差平均值比值小于等于 1 标记为 pass,1 ~ 2 之间标记为 waring,大于 2 标记为 error。 |
252
+ | 相对误差平均值判定结果 | 相对误差平均值比值小于等于 1 标记为 pass,1 ~ 2 之间标记为 warning,大于 2 标记为 error。 |
256
253
  | 误差均衡性比值 | NPU 与 CPU 的误差均衡性 / GPU 与 CPU 的误差均衡性。标杆比对法指标。 |
257
- | 误差均衡性判定结果 | 误差均衡性比值小于等于 1 标记为 pass,1 ~ 2 之间标记为 waring,大于 2 标记为 error。该字段暂不参与 api_precision_compare_result 的结果判定。 |
254
+ | 误差均衡性判定结果 | 误差均衡性比值小于等于 1 标记为 pass,1 ~ 2 之间标记为 warning,大于 2 标记为 error。该字段暂不参与 api_precision_compare_result 的结果判定。 |
258
255
  | inf / nan 错误率 | NPU 与标杆 inf / nan 计算不一致的元素个数占总元素的个数比例。绝对阈值法指标。 |
259
256
  | inf / nan 判定结果 | inf / nan 错误率判定结果,等于 0 标记为 pass,其余情况标记为 error。 |
260
257
  | 相对误差错误率 | NPU 与标杆的正常值计算相对误差,其大于错误阈值的元素个数占正常值元素个数的比例。绝对阈值法指标。 |
@@ -263,12 +260,38 @@ Forward Test Success 和 Backward Test Success 是否通过测试是由 `api_pre
263
260
  | 绝对误差判定结果 | 绝对误差错误率判定结果,等于 0 标记为 pass,其余情况标记为 error。 |
264
261
  | 二进制一致错误率 | NPU 或 GPU 数据中每个 Tensor 精度不一致的数值的数量与 Tensor 中数值数量的比值。只有数据是 builtin 类型(bool、int、float、str)、torch.bool 和 torch 的 int 类型或者在新精度标准中使用二进制一致算法进行比对的 API 才会展示。二进制一致法指标。 |
265
262
  | 二进制一致错误率判定结果 | 二进制一致错误率判定结果,等于 0 标记为 pass,其余情况标记为 error。 |
266
- | ULP 误差平均值 | NPU 数据与标杆数据 ULP 误差的平均值(取绝对值后)。ULP 误差比对法指标。 |
267
- | ULP 误差大于阈值占比 | NPU 数据与标杆数据的 ULP 误差(取绝对值后)大于阈值(当 NPU 数据类型为 float16 或 bfloat16 时,阈值为 1;当 NPU 数据类型为 float32 时,阈值为 32)的元素个数占总元素的个数比例。ULP 误差比对法指标。 |
268
- | ULP 误差大于阈值占比比值 | NPU 与 CPU 的 ULP 误差大于阈值占比 / GPU 与 CPU 的 ULP 误差大于阈值占比。ULP 误差比对法指标。 |
263
+ | ULP 误差平均值<sup>a</sup> | NPU 数据与标杆数据 ULP 误差的平均值(取绝对值后)。 |
264
+ | ULP 误差大于阈值占比<sup>a</sup> | NPU 数据与标杆数据的 ULP 误差(取绝对值后)大于阈值(当 NPU 数据类型为 float16 或 bfloat16 时,阈值为 1;当 NPU 数据类型为 float32 时,阈值为 32)的元素个数占总元素的个数比例。 |
265
+ | ULP 误差大于阈值占比比值<sup>a</sup> | NPU 与 CPU 的 ULP 误差大于阈值占比 / GPU 与 CPU 的 ULP 误差大于阈值占比。 |
269
266
  | ULP 误差判定结果 | ULP 误差判定结果。<br/> 当 NPU 或 GPU 数据类型是 float16 或 bfloat16 时,以下两条标准满足其一标记为 pass,否则标记为 error:<br> NPU ULP 误差大于阈值占比小于 0.001;<br/> NPU ULP 误差大于阈值占比小于 GPU ULP 误差大于阈值占比。<br/> 当 NPU 或 GPU 数据类型是 float32 时,以下三条标准满足其一标记为 pass,否则标记为 error:<br/> NPU ULP 误差平均值小于 64;<br/> NPU ULP 误差大于阈值占比小于 0.05;<br/> NPU ULP 误差大于阈值占比小于 GPU ULP 误差大于阈值占比。 |
270
267
  | 双千指标 | 双千精度指标。是指 NPU 的 Tensor 中的元素逐个与对应的标杆数据对比,相对误差小于千分之一的个数占总元素个数的比例。测试通过标准为相对误差大于千分之一的个数占总元素个数的比例小于千分之一。仅 conv1d 和 conv2d 使用该指标。双千指标法指标。 |
271
268
  | 双千指标判定结果 | 双千指标判定结果。双千指标大于 0.999 标记为 pass,否则标记为 error。 |
272
269
  | 比对结果 | 综合所有指标的最终结果。如果比对指标中有 error,则标记为 error;有 warning,则标记为 warning;否则标记为 pass;SKIP 表示该 API 的数据类型不支持使用新精度标准进行比对,如 float64。 |
273
270
  | 比对算法 | API 使用的比对算法,为标杆比对法、二进制一致法、绝对阈值法和 ULP 误差比对法中的一种。 |
274
271
  | Message | 提示信息。当前提示该 API 比对结果为 error 或 warning 时对应不符合标准的指标。 |
272
+
273
+ a:误差比对法指标。
274
+
275
+ ## 6 支持的融合算子列表
276
+
277
+ 预检工具当前支持的融合算子如下:
278
+
279
+ - npu_apply_adam_w
280
+
281
+ - npu_confusion_transpose
282
+
283
+ - fast_gelu
284
+
285
+ - npu_layer_norm_eval
286
+
287
+ - npu_linear
288
+
289
+ - npu_fusion_attention(该算子在 GPU 上预检时,需要额外安装 flash_attn,请用户自行安装。)
290
+
291
+ - npu_rms_norm
292
+
293
+ - npu_rotary_mul
294
+
295
+ - npu_scaled_masked_softmax
296
+
297
+ - npu_swiglu
@@ -37,7 +37,7 @@ Host 与 GPU Host 设备间建立连接,将 NPU 上对应 API 的输入数据
37
37
  | host | 在线预检模式局域网场景信息接收端 IP,str 类型,用于 GPU 设备和 NPU 设备间进行通信,GPU 侧配置为本机地址 127.0.0.1 或本机局域网 IP。局域网场景时,不能配置 nfs_path 参数,否则局域网场景不生效。 | 否 |
38
38
  | port | 在线预检模式局域网场景信息接收端端口号,int 类型,用于 GPU 设备和 NPU 设备间进行通信,GPU 侧配置为本机可用端口。局域网场景时,不能配置 nfs_path 参数,否则局域网场景不生效。 | 否 |
39
39
  | rank_list | 指定在线预检的 Rank ID,默认值为 [0],list[int] 类型,应配置为大于等于 0 的整数,且须根据实际卡的 Rank ID 配置,若所配置的值大于实际训练所运行的卡的 Rank ID,则在线预检输出数据为空。GPU 和 NPU 须配置一致。 | 是 |
40
- | tls_path | 在线预检模式局域网场景 SSL 证书路径,该路径下包含私钥文件 server.key 和公钥文件 server.crt,str 类型,默认值为空,表示明文传输 api 数据,否则采用 TLS1.2 加密传输,加密传输时安全性较高,传输速率较低。 | 否 |
40
+ | tls_path | 在线预检模式局域网场景 SSL 证书路径,该路径下包含私钥文件 server.key 和公钥文件 server.crt,str 类型,未配置该参数时默认取值当前路径。tls_path配置为空字符串时,采用TCP协议明文传输api数据;当配置为路径时,采用TLS1.2协议加密传输数据,加密传输时安全性较高,传输速率较低。 | 否 |
41
41
 
42
42
 
43
43
  #### 3.1.2 NPU 侧在线预检配置说明
@@ -57,10 +57,11 @@ Host 与 GPU Host 设备间建立连接,将 NPU 上对应 API 的输入数据
57
57
  | nfs_path | 在线预检模式共享存储目录路径,str 类型,用于 GPU 设备和 NPU 设备间进行通信。配置该参数后 host 和 port 不生效。 | 否 |
58
58
  | host | 在线预检模式局域网场景信息接收端 IP,str 类型,用于 GPU 设备和 NPU 设备间进行通信,NPU 侧须配置为 GPU 侧的局域网 IP 地址。局域网场景时,不能配置 nfs_path 参数,否则局域网场景不生效。 | 否 |
59
59
  | port | 在线预检模式局域网场景信息接收端端口号,int 类型,用于 GPU 设备和 NPU 设备间进行通信,NPU 侧须配置为 GPU 侧的端口号。局域网场景时,不能配置 nfs_path 参数,否则局域网场景不生效。 | 否 |
60
+ | tls_path | 在线预检模式局域网场景 SSL 证书路径,该路径下包含私钥文件 client.key 和公钥文件 client.crt,str 类型,未配置该参数时默认取值当前路径。tls_path配置为空字符串时,采用TCP协议明文传输api数据;当配置为路径时,采用TLS1.2协议加密传输数据,加密传输时安全性较高,传输速率较低。 | 否 |
60
61
 
61
62
  #### 3.1.3 局域网场景配置示例
62
63
 
63
- 若采用TLS1.2协议加密传输api数据,需配置SSL证书,可参考如下生成自签名证书方法,仅供调试使用,生产环境请申请正式证书。
64
+ 若采用 TLS1.2 协议加密传输 api 数据,需配置 SSL 证书,可参考如下生成自签名证书方法,仅供调试使用,生产环境请申请正式证书。
64
65
  ```shell
65
66
  # 创建私钥文件server.key
66
67
  openssl genrsa -out server.key 2048
@@ -72,6 +73,19 @@ openssl req -new -key server.key -out server.csr
72
73
  openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
73
74
  ```
74
75
 
76
+ 注意:配置TLS协议时,传输性能受机器环境和网络质量的影响,可能触发NPU超时中断模型训练,为避免训练和预检中断,丢弃长时间未传输的api数据,同时NPU侧配置HCCL环境变量,配置方式如下:
77
+
78
+ a) 调整HCCL环境变量,关闭看门狗,避免WorkHCCL超时中断模型训练:
79
+ ```shell
80
+ export HCCL_DESYNC_DEBUG=0
81
+ export HCCL_ASYNC_ERROR_HANDLING=0
82
+ ```
83
+ b) 调整通信算子超时设置(以1800s举例):
84
+ ```shell
85
+ export HCCL_CONNECT_TIMEOUT=1800
86
+ export HCCL_EXEC_TIMEOUT=1800
87
+ ```
88
+
75
89
  GPU 侧:
76
90
 
77
91
  ```json
@@ -85,7 +99,8 @@ GPU 侧:
85
99
  "nfs_path": "",
86
100
  "host": "127.0.0.1",
87
101
  "port": 59208,
88
- "rank_list": [0]
102
+ "rank_list": [0],
103
+ "tls_path": ""
89
104
  }
90
105
  }
91
106
  ```
@@ -107,7 +122,8 @@ NPU 侧:
107
122
  "online_run_ut": true,
108
123
  "nfs_path": "",
109
124
  "host": "xx.xx.xx.x",
110
- "port": 59208
125
+ "port": 59208,
126
+ "tls_path": ""
111
127
  }
112
128
  }
113
129
  ```
@@ -127,7 +143,8 @@ GPU 侧:
127
143
  "nfs_path": "/nfs/xxx/data",
128
144
  "host": "",
129
145
  "port": -1,
130
- "rank_list": [0]
146
+ "rank_list": [0],
147
+ "tls_path": ""
131
148
  }
132
149
  }
133
150
  ```
@@ -149,7 +166,8 @@ NPU 侧:
149
166
  "online_run_ut": true,
150
167
  "nfs_path": "/nfs/xxx/data",
151
168
  "host": "",
152
- "port": -1
169
+ "port": -1,
170
+ "tls_path": ""
153
171
  }
154
172
  }
155
173
  ```
@@ -167,7 +185,7 @@ GPU 侧配置好 config.json 文件后执行 run_ut 命令,此时 GPU 处于
167
185
  - 局域网场景:当 NPU 侧启动训练后将预检的 API 输入和输出数据发送到 GPU 侧时,GPU 启动预检操作。
168
186
  - 共享存储场景:当 NPU 侧启动训练后将预检的 API 输入和输出数据发送到共享存储时,GPU 启动预检操作。
169
187
 
170
- ### 3.2 在 NPU 侧配置训练脚本
188
+ ### 3.3 在 NPU 侧配置训练脚本
171
189
 
172
190
  在 NPU 训练脚本中添加如下代码以获取 run_ut 操作的预检 API 输入和输出数据:
173
191
 
@@ -185,7 +203,7 @@ debugger.stop()
185
203
  debugger.step()
186
204
  ```
187
205
 
188
- ### 3.3 在 NPU 侧执行训练脚本
206
+ ### 3.4 在 NPU 侧执行训练脚本
189
207
 
190
208
  配置完 NPU 侧训练脚本后即可执行训练脚本,命令示例如下:
191
209
 
@@ -193,6 +211,28 @@ debugger.step()
193
211
  bash train.sh
194
212
  ```
195
213
 
196
- 训练脚本执行完毕后,在GPU侧dump_path目录下生成比对结果文件,
197
- `accuracy_checking_result_{timestamp}_rank{rank_id}.csv`和`accuracy_checking_details_{timestamp}_rank{rank_id}.csv`记录两方比对结果
198
- `api_precision_compare_result_{timestamp}_rank{rank_id}.csv`和`api_precision_compare_details_{timestamp}_rank{rank_id}.csv`记录三方比对结果。详细介绍请参见[离线精度预检中的 **4 预检结果**](./07.accuracy_checker_PyTorch.md#4-预检结果)。
214
+ 训练脚本执行完毕后,在GPU侧dump_path目录下生成比对结果文件,`accuracy_checking_result_{timestamp}_rank{rank_id}.csv`和`accuracy_checking_details_{timestamp}_rank{rank_id}.csv`记录两方比对结果,`api_precision_compare_result_{timestamp}_rank{rank_id}.csv`和`api_precision_compare_details_{timestamp}_rank{rank_id}.csv`记录三方比对结果。详细介绍请参见[离线精度预检中的 **4 预检结果**](./07.accuracy_checker_PyTorch.md#4-预检结果)。
215
+
216
+ ## 4 支持的融合算子列表
217
+
218
+ 预检工具当前支持的融合算子如下:
219
+
220
+ - npu_apply_adam_w
221
+
222
+ - npu_confusion_transpose
223
+
224
+ - fast_gelu
225
+
226
+ - npu_layer_norm_eval
227
+
228
+ - npu_linear
229
+
230
+ - npu_fusion_attention(该算子在 GPU 上预检时,需要额外安装 flash_attn,请用户自行安装。)
231
+
232
+ - npu_rms_norm
233
+
234
+ - npu_rotary_mul
235
+
236
+ - npu_scaled_masked_softmax
237
+
238
+ - npu_swiglu
@@ -2,10 +2,11 @@
2
2
 
3
3
  ## 1 简介
4
4
 
5
- **MindSpore 动态图精度预检**<sup>a</sup>通过扫描昇腾 NPU 上用户训练 MindSpore 模型中的所有 Mint API,输出精度情况的诊断和分析。工具以模型中所有 Mint API 前反向的 dump 结果为输入,构造相应的 API 单元测试,将 NPU 输出与标杆(CPU 高精度)比对,计算对应的精度指标,从而找出 NPU 中存在精度问题的 Mint API。本工具支持随机生成模式和真实数据模式<sup>b</sup>。
5
+ **MindSpore 动态图精度预检**<sup>a</sup>通过扫描昇腾 NPU 上用户训练 MindSpore 模型中的所有 Mint API,输出精度情况的诊断和分析。工具以模型中所有 Mint API 前反向的 dump 结果为输入,构造相应的 API 单元测试,将 NPU 输出与标杆(CPU 高精度)比对,计算对应的精度指标,从而找出 NPU 中存在精度问题的 Mint API。本工具支持**随机生成模式和真实数据模式**<sup>b</sup>。
6
6
 
7
- a. 支持 Mindspore 版本:2.4;
8
- b. 在预检 dump 时可以选择由工具构造随机数进行输入获得 dump 数据或选择获取真实输入数据进行预检 dump 操作。随机生成模式执行效率高,可以快速获得结果,但数据精度低,只能大致判断精度问题;真实数据模式执行效率略低于随机生成模式,但是数据精度高,可以准确判断精度问题。
7
+ a. 支持 Mindspore 版本:2.4;
8
+
9
+ b. 在预检 dump 时可以选择由工具构造随机数进行输入获得 dump 数据或选择获取真实输入数据进行预检 dump 操作。随机生成模式执行效率高,可以快速获得结果,但数据精度低,只能大致判断精度问题;真实数据模式执行效率略低于随机生成模式,但是数据精度高,可以准确判断精度问题。
9
10
 
10
11
  ## 2 离线预检流程
11
12
 
@@ -13,7 +14,7 @@
13
14
 
14
15
  1. 在 NPU 和 GPU 环境下分别安装 msprobe。详见[ msprobe 安装](./01.installation.md)章节。
15
16
  2. 在 NPU 训练脚本内添加 msprobe 工具 dump 接口 PrecisionDebugger,采集待预检数据。详见 [MindSpore 场景下的数据采集](./06.data_dump_MindSpore.md)章节,注意需要配置 level="L1"。
16
- 3. 执行预检操作,查看预检结果文件,分析预检不达标的API。
17
+ 3. 执行预检操作,查看预检结果文件,分析预检不达标的 API。
17
18
 
18
19
  ## 3 离线预检操作指导
19
20
 
@@ -47,7 +48,7 @@ msprobe -f mindspore run_ut -api_info ./dump.json -o ./checker_result
47
48
  | Status | API 预检通过状态,pass 表示通过测试,error 表示未通过。 |
48
49
  | message | 提示信息。 |
49
50
 
50
- 注意点:torch无法对dtype为整数类型的tensor进行反向求导,mindspore则支持。反向过程的预检仅比较dtype为浮点型的输出。
51
+ 注意:PyTorch 无法对 dtype 为整数类型的 tensor 进行反向求导,而 MindSpore 支持。反向过程的预检仅比较 dtype 为浮点型的输出。
51
52
 
52
53
  `accuracy_checking_result_{timestamp}.csv`
53
54
 
@@ -63,6 +64,5 @@ Forward Test Success 和 Backward Test Success 是否通过测试是由 `accurac
63
64
 
64
65
  ### 4.1 API 预检指标
65
66
 
66
- - API 预检指标是通过对`accuracy_checking_details_{timestamp}.csv`中的余弦相似度、最大绝对误差的数值进行判断,得出该API是否符合精度标准的参考指标。详细规则如下:
67
-
68
- - 余弦相似度大于0.99,并且最大绝对误差小于0.0001,标记“pass”,否则标记为“error”。
67
+ - API 预检指标是通过对 `accuracy_checking_details_{timestamp}.csv` 中的余弦相似度、最大绝对误差的数值进行判断,得出该 API 是否符合精度标准的参考指标。
68
+ - 余弦相似度大于 0.99,并且最大绝对误差小于 0.0001,标记“pass”,否则标记为“error”。