mindstudio-probe 1.0.1__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 (228) hide show
  1. mindstudio_probe-1.0.1.dist-info/LICENSE +201 -0
  2. mindstudio_probe-1.0.1.dist-info/METADATA +30 -0
  3. mindstudio_probe-1.0.1.dist-info/RECORD +228 -0
  4. mindstudio_probe-1.0.1.dist-info/WHEEL +5 -0
  5. mindstudio_probe-1.0.1.dist-info/entry_points.txt +2 -0
  6. mindstudio_probe-1.0.1.dist-info/top_level.txt +1 -0
  7. msprobe/README.md +182 -0
  8. msprobe/__init__.py +0 -0
  9. msprobe/config/README.md +397 -0
  10. msprobe/config/config.json +28 -0
  11. msprobe/config/img/free_benchmark.png +0 -0
  12. msprobe/core/common/const.py +241 -0
  13. msprobe/core/common/exceptions.py +88 -0
  14. msprobe/core/common/file_check.py +265 -0
  15. msprobe/core/common/log.py +55 -0
  16. msprobe/core/common/utils.py +516 -0
  17. msprobe/core/common_config.py +58 -0
  18. msprobe/core/data_dump/data_collector.py +140 -0
  19. msprobe/core/data_dump/data_processor/base.py +245 -0
  20. msprobe/core/data_dump/data_processor/factory.py +61 -0
  21. msprobe/core/data_dump/data_processor/pytorch_processor.py +346 -0
  22. msprobe/core/data_dump/json_writer.py +116 -0
  23. msprobe/core/data_dump/scope.py +178 -0
  24. msprobe/mindspore/__init__.py +1 -0
  25. msprobe/mindspore/debugger/__init__.py +0 -0
  26. msprobe/mindspore/debugger/debugger_config.py +51 -0
  27. msprobe/mindspore/debugger/precision_debugger.py +32 -0
  28. msprobe/mindspore/doc/dump.md +65 -0
  29. msprobe/mindspore/dump/__init__.py +0 -0
  30. msprobe/mindspore/dump/api_kbk_dump.py +55 -0
  31. msprobe/mindspore/dump/dump_tool_factory.py +38 -0
  32. msprobe/mindspore/dump/kernel_graph_dump.py +60 -0
  33. msprobe/mindspore/ms_config.py +78 -0
  34. msprobe/mindspore/overflow_check/__init__.py +0 -0
  35. msprobe/mindspore/overflow_check/kernel_graph_overflow_check.py +45 -0
  36. msprobe/mindspore/overflow_check/overflow_check_tool_factory.py +32 -0
  37. msprobe/mindspore/task_handler_factory.py +21 -0
  38. msprobe/msprobe.py +67 -0
  39. msprobe/pytorch/__init__.py +4 -0
  40. msprobe/pytorch/advisor/advisor.py +124 -0
  41. msprobe/pytorch/advisor/advisor_const.py +59 -0
  42. msprobe/pytorch/advisor/advisor_result.py +58 -0
  43. msprobe/pytorch/api_accuracy_checker/.keep +0 -0
  44. msprobe/pytorch/api_accuracy_checker/__init__.py +0 -0
  45. msprobe/pytorch/api_accuracy_checker/common/.keep +0 -0
  46. msprobe/pytorch/api_accuracy_checker/common/__init__.py +0 -0
  47. msprobe/pytorch/api_accuracy_checker/common/config.py +50 -0
  48. msprobe/pytorch/api_accuracy_checker/common/utils.py +224 -0
  49. msprobe/pytorch/api_accuracy_checker/compare/__init__.py +0 -0
  50. msprobe/pytorch/api_accuracy_checker/compare/algorithm.py +216 -0
  51. msprobe/pytorch/api_accuracy_checker/compare/api_precision_compare.py +545 -0
  52. msprobe/pytorch/api_accuracy_checker/compare/api_precision_standard.yaml +133 -0
  53. msprobe/pytorch/api_accuracy_checker/compare/api_precision_threshold.yaml +390 -0
  54. msprobe/pytorch/api_accuracy_checker/compare/compare.py +345 -0
  55. msprobe/pytorch/api_accuracy_checker/compare/compare_column.py +74 -0
  56. msprobe/pytorch/api_accuracy_checker/compare/compare_utils.py +249 -0
  57. msprobe/pytorch/api_accuracy_checker/config.yaml +4 -0
  58. msprobe/pytorch/api_accuracy_checker/run_ut/.keep +0 -0
  59. msprobe/pytorch/api_accuracy_checker/run_ut/__init__.py +0 -0
  60. msprobe/pytorch/api_accuracy_checker/run_ut/data_generate.py +328 -0
  61. msprobe/pytorch/api_accuracy_checker/run_ut/multi_run_ut.py +203 -0
  62. msprobe/pytorch/api_accuracy_checker/run_ut/run_overflow_check.py +127 -0
  63. msprobe/pytorch/api_accuracy_checker/run_ut/run_ut.py +493 -0
  64. msprobe/pytorch/api_accuracy_checker/run_ut/run_ut_utils.py +7 -0
  65. msprobe/pytorch/api_accuracy_checker/run_ut/torch_ut_setting.json +5 -0
  66. msprobe/pytorch/common/__init__.py +2 -0
  67. msprobe/pytorch/common/compare_script.template +14 -0
  68. msprobe/pytorch/common/log.py +32 -0
  69. msprobe/pytorch/common/parse_json.py +37 -0
  70. msprobe/pytorch/common/utils.py +224 -0
  71. msprobe/pytorch/compare/acc_compare.py +1024 -0
  72. msprobe/pytorch/compare/distributed_compare.py +111 -0
  73. msprobe/pytorch/compare/highlight.py +100 -0
  74. msprobe/pytorch/compare/mapping.yaml +607 -0
  75. msprobe/pytorch/compare/match.py +36 -0
  76. msprobe/pytorch/compare/npy_compare.py +244 -0
  77. msprobe/pytorch/debugger/__init__.py +0 -0
  78. msprobe/pytorch/debugger/debugger_config.py +86 -0
  79. msprobe/pytorch/debugger/precision_debugger.py +95 -0
  80. msprobe/pytorch/doc/FAQ.md +193 -0
  81. msprobe/pytorch/doc/api_accuracy_checker.md +269 -0
  82. msprobe/pytorch/doc/atat/321/207/342/226/223/342/225/233/321/205/342/225/221/320/266/321/205/342/225/226/320/265/321/205/320/225/342/225/226/321/206/320/245/342/226/221/321/206/320/235/320/276dump/321/206/320/260/320/227/321/205/320/227/320/226/321/206/320/220/320/267/321/210/320/223/342/225/234/321/205/320/257/342/225/221/321/207/342/225/221/342/224/220/321/206/320/232/320/265/321/205/320/241/320/232.md +182 -0
  83. msprobe/pytorch/doc/dump.md +207 -0
  84. msprobe/pytorch/doc/img/BLOOM-7B_1.png +0 -0
  85. msprobe/pytorch/doc/img/BLOOM-7B_2.png +0 -0
  86. msprobe/pytorch/doc/img/BLOOM-7B_3.png +0 -0
  87. msprobe/pytorch/doc/img/BLOOM-7B_4.png +0 -0
  88. msprobe/pytorch/doc/img/GPT-3_1.png +0 -0
  89. msprobe/pytorch/doc/img/GPT-3_2.png +0 -0
  90. msprobe/pytorch/doc/img/GPT-3_3.png +0 -0
  91. msprobe/pytorch/doc/img/GPT-3_4.png +0 -0
  92. msprobe/pytorch/doc/img/GPT-3_5.png +0 -0
  93. msprobe/pytorch/doc/img/GPT-3_6.png +0 -0
  94. msprobe/pytorch/doc/img/GPT-3_7.png +0 -0
  95. msprobe/pytorch/doc/img/GPT-3_8.png +0 -0
  96. msprobe/pytorch/doc/img/YOLOV5S_1.png +0 -0
  97. msprobe/pytorch/doc/img/YOLOV5S_2.png +0 -0
  98. msprobe/pytorch/doc/img/accuracy_checking_details.png +0 -0
  99. msprobe/pytorch/doc/img/accuracy_checking_result.png +0 -0
  100. msprobe/pytorch/doc/img/api_precision_compare_details.png +0 -0
  101. msprobe/pytorch/doc/img/api_precision_compare_result.png +0 -0
  102. msprobe/pytorch/doc/img/auto_analyze_log.png +0 -0
  103. msprobe/pytorch/doc/img/compare_result_pkl.png +0 -0
  104. msprobe/pytorch/doc/img/compare_result_pkl_md5.png.png +0 -0
  105. msprobe/pytorch/doc/img/cpu_info.png +0 -0
  106. msprobe/pytorch/doc/img/module_compare.png +0 -0
  107. msprobe/pytorch/doc/parse_tool.md +286 -0
  108. msprobe/pytorch/doc/ptdbg_ascend_compare.md +176 -0
  109. msprobe/pytorch/doc/ptdbg_ascend_overview.md +68 -0
  110. msprobe/pytorch/doc/ptdbg_ascend_quickstart.md +381 -0
  111. msprobe/pytorch/doc/run_overflow_check.md +25 -0
  112. msprobe/pytorch/doc//321/205/320/254/320/270/321/207/342/225/221/342/224/220/321/207/342/226/223/342/225/233/321/205/342/225/221/320/266/321/206/320/277/320/244/321/205/320/277/342/225/243.md +90 -0
  113. msprobe/pytorch/free_benchmark/__init__.py +8 -0
  114. msprobe/pytorch/free_benchmark/common/__init__.py +0 -0
  115. msprobe/pytorch/free_benchmark/common/constant.py +67 -0
  116. msprobe/pytorch/free_benchmark/common/counter.py +72 -0
  117. msprobe/pytorch/free_benchmark/common/enums.py +37 -0
  118. msprobe/pytorch/free_benchmark/common/params.py +129 -0
  119. msprobe/pytorch/free_benchmark/common/utils.py +98 -0
  120. msprobe/pytorch/free_benchmark/compare/grad_saver.py +183 -0
  121. msprobe/pytorch/free_benchmark/compare/single_benchmark.py +104 -0
  122. msprobe/pytorch/free_benchmark/main.py +102 -0
  123. msprobe/pytorch/free_benchmark/perturbed_layers/__init__.py +0 -0
  124. msprobe/pytorch/free_benchmark/perturbed_layers/base_layer.py +13 -0
  125. msprobe/pytorch/free_benchmark/perturbed_layers/layer_factory.py +41 -0
  126. msprobe/pytorch/free_benchmark/perturbed_layers/npu/__init__.py +0 -0
  127. msprobe/pytorch/free_benchmark/perturbed_layers/npu/add_noise.py +90 -0
  128. msprobe/pytorch/free_benchmark/perturbed_layers/npu/bit_noise.py +104 -0
  129. msprobe/pytorch/free_benchmark/perturbed_layers/npu/change_value.py +63 -0
  130. msprobe/pytorch/free_benchmark/perturbed_layers/npu/improve_precision.py +68 -0
  131. msprobe/pytorch/free_benchmark/perturbed_layers/npu/no_change.py +28 -0
  132. msprobe/pytorch/free_benchmark/perturbed_layers/npu/npu_base_layser.py +45 -0
  133. msprobe/pytorch/free_benchmark/perturbed_layers/run_cpu.py +19 -0
  134. msprobe/pytorch/free_benchmark/result_handlers/__init__.py +0 -0
  135. msprobe/pytorch/free_benchmark/result_handlers/base_handler.py +203 -0
  136. msprobe/pytorch/free_benchmark/result_handlers/check_handler.py +39 -0
  137. msprobe/pytorch/free_benchmark/result_handlers/fix_handler.py +24 -0
  138. msprobe/pytorch/free_benchmark/result_handlers/handler_factory.py +31 -0
  139. msprobe/pytorch/free_benchmark/result_handlers/preheat_handler.py +170 -0
  140. msprobe/pytorch/functional/__init__.py +0 -0
  141. msprobe/pytorch/functional/data_processor.py +0 -0
  142. msprobe/pytorch/functional/dump_module.py +39 -0
  143. msprobe/pytorch/hook_module/__init__.py +1 -0
  144. msprobe/pytorch/hook_module/api_registry.py +161 -0
  145. msprobe/pytorch/hook_module/hook_module.py +109 -0
  146. msprobe/pytorch/hook_module/support_wrap_ops.yaml +1876 -0
  147. msprobe/pytorch/hook_module/utils.py +29 -0
  148. msprobe/pytorch/hook_module/wrap_aten.py +100 -0
  149. msprobe/pytorch/hook_module/wrap_distributed.py +75 -0
  150. msprobe/pytorch/hook_module/wrap_functional.py +108 -0
  151. msprobe/pytorch/hook_module/wrap_npu_custom.py +73 -0
  152. msprobe/pytorch/hook_module/wrap_tensor.py +72 -0
  153. msprobe/pytorch/hook_module/wrap_torch.py +88 -0
  154. msprobe/pytorch/hook_module/wrap_vf.py +64 -0
  155. msprobe/pytorch/module_processer.py +98 -0
  156. msprobe/pytorch/online_dispatch/__init__.py +20 -0
  157. msprobe/pytorch/online_dispatch/compare.py +236 -0
  158. msprobe/pytorch/online_dispatch/dispatch.py +274 -0
  159. msprobe/pytorch/online_dispatch/dump_compare.py +186 -0
  160. msprobe/pytorch/online_dispatch/single_compare.py +391 -0
  161. msprobe/pytorch/online_dispatch/torch_ops_config.yaml +50 -0
  162. msprobe/pytorch/online_dispatch/utils.py +187 -0
  163. msprobe/pytorch/parse.py +4 -0
  164. msprobe/pytorch/parse_tool/__init__.py +0 -0
  165. msprobe/pytorch/parse_tool/cli.py +32 -0
  166. msprobe/pytorch/parse_tool/lib/__init__.py +0 -0
  167. msprobe/pytorch/parse_tool/lib/compare.py +259 -0
  168. msprobe/pytorch/parse_tool/lib/config.py +51 -0
  169. msprobe/pytorch/parse_tool/lib/file_desc.py +31 -0
  170. msprobe/pytorch/parse_tool/lib/interactive_cli.py +102 -0
  171. msprobe/pytorch/parse_tool/lib/parse_exception.py +54 -0
  172. msprobe/pytorch/parse_tool/lib/parse_tool.py +158 -0
  173. msprobe/pytorch/parse_tool/lib/utils.py +367 -0
  174. msprobe/pytorch/parse_tool/lib/visualization.py +90 -0
  175. msprobe/pytorch/pt_config.py +93 -0
  176. msprobe/pytorch/service.py +167 -0
  177. msprobe/test/core_ut/common/test_utils.py +345 -0
  178. msprobe/test/core_ut/data_dump/test_data_collector.py +47 -0
  179. msprobe/test/core_ut/data_dump/test_json_writer.py +183 -0
  180. msprobe/test/core_ut/data_dump/test_scope.py +151 -0
  181. msprobe/test/core_ut/test_common_config.py +152 -0
  182. msprobe/test/core_ut/test_file_check.py +218 -0
  183. msprobe/test/core_ut/test_log.py +109 -0
  184. msprobe/test/mindspore_ut/test_api_kbk_dump.py +51 -0
  185. msprobe/test/mindspore_ut/test_debugger_config.py +42 -0
  186. msprobe/test/mindspore_ut/test_dump_tool_factory.py +51 -0
  187. msprobe/test/mindspore_ut/test_kernel_graph_dump.py +66 -0
  188. msprobe/test/mindspore_ut/test_kernel_graph_overflow_check.py +63 -0
  189. msprobe/test/mindspore_ut/test_ms_config.py +69 -0
  190. msprobe/test/mindspore_ut/test_overflow_check_tool_factory.py +51 -0
  191. msprobe/test/mindspore_ut/test_precision_debugger.py +56 -0
  192. msprobe/test/mindspore_ut/test_task_handler_factory.py +58 -0
  193. msprobe/test/pytorch_ut/advisor/test_advisor.py +83 -0
  194. msprobe/test/pytorch_ut/api_accuracy_checker/common/test_common_utils.py +108 -0
  195. msprobe/test/pytorch_ut/api_accuracy_checker/common/test_config.py +39 -0
  196. msprobe/test/pytorch_ut/api_accuracy_checker/compare/test_algorithm.py +112 -0
  197. msprobe/test/pytorch_ut/api_accuracy_checker/compare/test_api_precision_compare.py +77 -0
  198. msprobe/test/pytorch_ut/api_accuracy_checker/compare/test_compare.py +125 -0
  199. msprobe/test/pytorch_ut/api_accuracy_checker/compare/test_compare_column.py +10 -0
  200. msprobe/test/pytorch_ut/api_accuracy_checker/compare/test_compare_utils.py +43 -0
  201. msprobe/test/pytorch_ut/api_accuracy_checker/run_ut/dump.json +179 -0
  202. msprobe/test/pytorch_ut/api_accuracy_checker/run_ut/forward.json +63 -0
  203. msprobe/test/pytorch_ut/api_accuracy_checker/run_ut/test_data_generate.py +99 -0
  204. msprobe/test/pytorch_ut/api_accuracy_checker/run_ut/test_multi_run_ut.py +115 -0
  205. msprobe/test/pytorch_ut/api_accuracy_checker/run_ut/test_run_ut.py +72 -0
  206. msprobe/test/pytorch_ut/compare/test_acc_compare.py +17 -0
  207. msprobe/test/pytorch_ut/free_benchmark/perturbed_layers/test_perturbed_layser.py +105 -0
  208. msprobe/test/pytorch_ut/free_benchmark/result_handlers/test_result_handler.py +121 -0
  209. msprobe/test/pytorch_ut/free_benchmark/test_main.py +101 -0
  210. msprobe/test/pytorch_ut/functional/test_dump_module.py +15 -0
  211. msprobe/test/pytorch_ut/hook_module/test_api_registry.py +130 -0
  212. msprobe/test/pytorch_ut/hook_module/test_hook_module.py +42 -0
  213. msprobe/test/pytorch_ut/hook_module/test_wrap_aten.py +65 -0
  214. msprobe/test/pytorch_ut/hook_module/test_wrap_distributed.py +35 -0
  215. msprobe/test/pytorch_ut/hook_module/test_wrap_functional.py +20 -0
  216. msprobe/test/pytorch_ut/hook_module/test_wrap_tensor.py +35 -0
  217. msprobe/test/pytorch_ut/hook_module/test_wrap_torch.py +43 -0
  218. msprobe/test/pytorch_ut/hook_module/test_wrap_vf.py +11 -0
  219. msprobe/test/pytorch_ut/test_pt_config.py +69 -0
  220. msprobe/test/pytorch_ut/test_service.py +59 -0
  221. msprobe/test/resources/advisor.txt +3 -0
  222. msprobe/test/resources/compare_result_20230703104808.csv +9 -0
  223. msprobe/test/resources/compare_result_without_accuracy.csv +9 -0
  224. msprobe/test/resources/config.yaml +3 -0
  225. msprobe/test/resources/npu_test.pkl +8 -0
  226. msprobe/test/run_test.sh +30 -0
  227. msprobe/test/run_ut.py +58 -0
  228. msprobe/test/test_module_processer.py +64 -0
msprobe/README.md ADDED
@@ -0,0 +1,182 @@
1
+ # MindStudio精度调试工具
2
+
3
+ MindStudio精度调试工具(MindStudio Probe),简称msprobe,是MindStudio Training Tools工具链下精度调试部分的工具包。主要包括精度预检和精度比对等子工具,当前适配场景包括PyTorch和MindSpore。
4
+
5
+ ## 工具安装
6
+
7
+ 精度工具合一软件包名称:`mindstudio_probe-{version}-py3-none-any.whl`
8
+
9
+ ### pip安装
10
+ ```shell
11
+ pip install mindstudio-probe
12
+ ```
13
+ 说明
14
+ 1. 使用`pip install mindstudio-probe==版本号`可安装指定版本的包
15
+ 2. pip命令会自动安装包及其依赖
16
+ 3. 安装成功后,日志会显示`Successfully installed mindstudio-probe-版本号`
17
+
18
+ ### 下载whl包安装
19
+ 1. 使用pip命令安装numpy、openpyxl、pandas、PyYAML、rich、torch、tqdm依赖。
20
+
21
+ 若环境中已安装部分依赖,不需要重复安装。
22
+
23
+ 2. whl包获取。
24
+
25
+ 请通过下表链接下载工具whl包。
26
+
27
+ | 版本 | 发布日期 | 支持PyTorch版本 | 下载链接 | 校验码 |
28
+ | ----- | ---------- | --------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
29
+ | 1.0 | 2024-07-09 | 2.0/2.1/2.2 | [ascend_training_accuracy_tools-1.0-py3-none-any.whl](https://ptdbg.obs.myhuaweicloud.com/att/1.0/ascend_training_accuracy_tools-1.0-py3-none-any.whl) | 5016dfe886c5d340ec6f60a959673355855f313c91f100680da814efb49f8e81 |
30
+ | 0.0.3 | 2024-06-11 | 2.0/2.1/2.2 | [ascend_training_accuracy_tools-0.0.3-py3-none-any.whl](https://ptdbg.obs.myhuaweicloud.com/att/0.0/ascend_training_accuracy_tools-0.0.3-py3-none-any.whl) | f46d9714704859e2d67861a65bbb3c76b0a250cf6e238b978b5b959ab1fe125a |
31
+ | 0.0.2 | 2024-05-23 | 2.0/2.1/2.2 | [ascend_training_accuracy_tools-0.0.2-py3-none-any.whl](https://ptdbg.obs.myhuaweicloud.com/att/0.0/ascend_training_accuracy_tools-0.0.2-py3-none-any.whl) | 2e35809bde559e9c4d2f16a02ccde779ed9e436bb65fded0b7ebaf6ac2c88d93 |
32
+ | 0.0.1 | 2024-03-15 | 2.0/2.1 | [ascend_training_accuracy_tools-0.0.1-py3-none-any.whl](https://ptdbg.obs.myhuaweicloud.com/att/0.0/ascend_training_accuracy_tools-0.0.1-py3-none-any.whl) | 5801510d4e827e4859bc9a5aca021e4d30c2ea42d60a4c8ad0c2baab1b7782c9 |
33
+
34
+ 3. whl包校验。
35
+
36
+ 1. 根据以上下载链接下载whl包到Linux安装环境。
37
+
38
+ 2. 进入whl包所在目录,执行如下命令。
39
+
40
+ ```bash
41
+ sha256sum {name}.whl
42
+ ```
43
+
44
+ {name}为whl包名称。
45
+
46
+ 若回显呈现对应版本whl包一致的**校验码**,则表示下载了正确的ptdbg_ascend精度工具whl安装包。示例如下:
47
+
48
+ ```bash
49
+ sha256sum ascend_training_accuracy_tools-0.0.1-py3-none-any.whl
50
+ 5801510d4e827e4859bc9a5aca021e4d30c2ea42d60a4c8ad0c2baab1b7782c9 *ascend_training_accuracy_tools-0.0.1-py3-none-any.whl
51
+ ```
52
+
53
+ 4. 执行如下命令进行安装。
54
+
55
+ ```bash
56
+ pip3 install ./mindstudio_probe-{version}-py3-none-any.whl
57
+ ```
58
+
59
+ 若为覆盖安装,请在命令行末尾增加“--force-reinstall”参数强制安装,例如:
60
+
61
+ ```bash
62
+ pip3 install ./mindstudio_probe-{version}-py3-none-any.whl --force-reinstall
63
+ ```
64
+
65
+ 提示如下信息则表示安装成功。
66
+
67
+ ```bash
68
+ Successfully installed mindstudio_probe-{version}
69
+ ```
70
+
71
+ ### 从源码安装
72
+ 1. 克隆或者下载项目源代码
73
+
74
+ ```shell
75
+ git clone https://gitee.com/ascend/mstt.git
76
+ cd debug/accuracy_tools
77
+ ```
78
+
79
+ 2. 安装setuptools和wheel
80
+
81
+ ```shell
82
+ pip install setuptools wheel
83
+ ```
84
+
85
+ 3. 安装msprobe
86
+
87
+ ```shell
88
+ python setup.py install
89
+ ```
90
+ 提示出现如下信息则表示源码安装成功。
91
+ ```shell
92
+ Finished processing dependencies for mindstudio-probe=={version}
93
+ ```
94
+
95
+ ## 工具使用
96
+
97
+ 安装msprobe工具后,可以按照如下思路选择合适的子工具进行精度调试:
98
+
99
+ 1. 判断框架场景。
100
+
101
+ 当前支持PyTorch和MindSpore场景。
102
+
103
+ 2. 执行数据采集。
104
+
105
+ 工具通过在训练脚本中添加PrecisionDebugger接口的方式对API执行精度数据dump操作。
106
+
107
+ PyTorch场景:详见[PyTorch_精度数据采集](./pytorch/doc/dump.md)。
108
+
109
+ MindSpore场景:详见[MindSpore_精度数据采集](./mindspore/doc/dump.md)。
110
+
111
+ 3. 执行精度预检。
112
+
113
+ 在昇腾NPU上扫描用户训练模型中所有API,进行API复现,给出精度情况的诊断和分析。
114
+
115
+ PyTorch场景:详见[PyTorch_精度预检工具](./pytorch/doc/api_accuracy_checker.md)。
116
+
117
+ MindSpore场景:暂不支持。
118
+
119
+ 4. 执行精度比对。
120
+
121
+ 进行PyTorch整网API粒度的数据dump、精度比对和溢出检测,从而定位训练场景下的精度问题。
122
+
123
+ PyTorch场景:详见[PyTorch_精度比对工具](./pytorch/doc/ptdbg_ascend_overview.md)。
124
+
125
+ MindSpore场景:暂不支持。
126
+
127
+ 5. 执行溢出解析。
128
+
129
+ 溢出解析是在执行精度数据dump时,配置了溢出检测dump,那么对于输入正常但输出存在溢出的API,可以判断是否为正常溢出。
130
+
131
+ PyTorch场景:详见[PyTorch_溢出解析工具](./pytorch/doc/run_overflow_check.md)。
132
+
133
+ MindSpore场景:暂不支持。
134
+
135
+ 6. 执行数据解析。
136
+
137
+ 用于比对前后两次NPU ACL层级dump数据的一致性。
138
+
139
+ PyTorch场景:详见[PyTorch_数据解析工具](./pytorch/doc/parse_tool.md)。
140
+
141
+ MindSpore场景:暂不支持。
142
+
143
+ 上述流程中的工具均为msprobe工具的子工具,使用相同的命令行,格式如下:
144
+
145
+ 精度预检工具
146
+
147
+ ```bash
148
+ msprobe -f <framework> run_ut [-h]
149
+ ```
150
+
151
+ ```bash
152
+ msprobe -f <framework> multi_run_ut [-h]
153
+ ```
154
+
155
+ ```bash
156
+ msprobe -f <framework> api_precision_compare [-h]
157
+ ```
158
+
159
+ 溢出解析工具
160
+
161
+ ```bash
162
+ msprobe -f <framework> run_overflow_check [-h]
163
+ ```
164
+
165
+ 数据解析工具
166
+
167
+ ```bash
168
+ msprobe -f <framework> parse [-h]
169
+ ```
170
+
171
+ | 参数 | 说明 |
172
+ | ---- | ------------------------------------------------------ |
173
+ | -f | 框架,请按所使用框架配置,当前支持pytorch或mindspore。 |
174
+ | -h | 帮助信息。 |
175
+
176
+ ## 贡献
177
+
178
+ push代码前,请务必保证已经完成了基础功能测试和网络测试。
179
+
180
+ ## Release Notes
181
+
182
+ Release Notes请参见[RELEASE](RELEASE.md)。
msprobe/__init__.py ADDED
File without changes
@@ -0,0 +1,397 @@
1
+ # 配置文件说明
2
+
3
+ 当前配置文件主要为PrecisionDebugger接口执行dump或无标杆比对操作时调用的配置,当PrecisionDebugger接口未指定该配置文件时,使用该文件的默认配置。配置文件详见[config.json](./config.json)。
4
+
5
+ ## 参数说明
6
+
7
+ ### **通用配置参数**
8
+
9
+ | 参数名 | 说明 | 是否必选 |
10
+ | ----------------- | ------------------------------------------------------------ | -------- |
11
+ | task | dump的任务类型,str类型。可取值"free_benchmark"(无标杆比对,仅PyTorch场景支持)、"statistics"(仅dump API统计信息,默认值)、"tensor"(dump API统计信息和完全复刻整网的API运行情况的真实数据)、"overflow_check"(溢出检测)。配置示例:"task": "tensor"。根据task参数取值的不同,可以配置不同场景参数,详见:“**task配置为free_benchmark**”,“**task配置为statistics**”,“**task配置为tensor**”,“**task配置为overflow_check**”。 | 否 |
12
+ | dump_path | 设置dump数据目录路径,str类型。配置示例:"dump_path": "./dump_path"。MindSpore场景仅支持绝对路径。 | 是 |
13
+ | rank | 指定对某张卡上的数据进行dump,list[int]类型,默认未配置(表示dump所有卡的数据),应配置为大于等于0的整数,且须配置实际可用的Rank ID。配置示例:"rank": [1]。<br> 对于PyTorch场景,Rank ID从0开始计数,最大取值为所有节点可用卡总数-1,若所配置的值大于实际训练所运行的卡的Rank ID,则dump数据为空,比如当前环境Rank ID为0到7,实际训练运行0到3卡,此时若配置Rank ID为4或不存在的10等其他值,此时dump数据为空。<br/> 对于MindSpore场景,所有节点的Rank ID均从0开始计数,最大取值为每个节点可用卡总数-1,config.json配置一次rank参数对所有节点同时生效。 | 否 |
14
+ | step | 指定dump某个step的数据,list[int]类型。默认未配置,表示dump所有step数据。dump特定step时,须指定为训练脚本中存在的step。step为list格式,可配置逐个step,例如:"step": [0,1,2]。 | 否 |
15
+ | level | dump级别,str类型,根据不同级别dump不同数据。可取值"L0"(dump module模块级精度数据,仅PyTorch场景支持,使用背景详见“**模块级精度数据dump说明**”)、"L1"(dump API级精度数据,默认值)、"L2"(dump kernel级精度数据,须配置acl_config参数)、"mix"(dump module模块级和API级精度数据,即"L0"+"L1",仅PyTorch场景支持)。配置示例:"level": "L1"。 | 否 |
16
+ | acl_config | kernel dump的配置文件,str类型。level取"L2"时,该参数必选;level为其他值时,该参数不选。参数示例:acl_config='./acl_config.json'。acl_config.json配置文件详细介绍请参见“**acl_config.json配置文件说明**”。 | 否 |
17
+ | seed | 随机种子数,int类型,默认值为:1234,仅PyTorch场景支持。通过固定随机数保证模型的输入或输出一致,可固定的随机数详见“**固定随机数范围**”。配置示例:"seed": 1234。 | 否 |
18
+ | is_deterministic | 确定性计算模式,bool类型,仅PyTorch场景支持。可取值true(开启)或false(关闭),默认关闭。配置示例:"is_deterministic": true。<br/>即使在相同的硬件和输入下,API多次执行的结果也可能不同,开启确定性计算是为了保证在相同的硬件和输入下,API多次执行的结果相同。<br/>确定性计算会导致API执行性能降低,建议在发现模型多次执行结果不同的情况下开启。<br/>rnn类算子、ReduceSum、ReduceMean等算子可能与确定性计算存在冲突,若开启确定性计算后多次执行的结果不相同,则考虑存在这些算子。 | 否 |
19
+ | enable_dataloader | 自动控制开关,bool类型,仅PyTorch场景支持。可取值true(开启)或false(关闭),默认为false。配置为True后自动识别step参数指定的迭代,并在该迭代执行完成后退出训练,此时start、stop和step函数可不配置,开启该开关要求训练脚本是通过torch.utils.data.dataloader方式加载数据。仅支持PyTorch单卡训练使用,分布式训练场景下存在数据dump不全问题,**下个版本即将废弃该功能**。 | 否 |
20
+
21
+ ### task配置为free_benchmark
22
+
23
+ 仅PyTorch场景支持。
24
+
25
+ task配置为free_benchmark时,开启**无标杆比对**,在NPU环境下通过对当前模型API的输入添加扰动因子,二次执行,将得到的输出与未添加扰动因子前的输出进行比对,从而**得出该模型中可能因迁移等变化导致精度降低的API**。
26
+
27
+ 无标杆比对优势在于省去了从GPU环境获取dump数据并执行的步骤,也省去了在NPU环境执行dump的操作,降低了精度比对的操作难度。
28
+
29
+ 建议配置白名单(配置scope或list)控制少量API进行无标杆比对,一次对过多API执行无标杆比对可能导致显存溢出或性能膨胀。
30
+
31
+ | 参数名 | 说明 | 是否必选 |
32
+ | ------------ | ------------------------------------------------------------ | -------- |
33
+ | scope | PyTorch场景dump范围,list[str]类型,默认未配置(list也未配置时表示dump所有API的数据)。需要在[]内配置两个模块名或API名,用于锁定区间,dump该范围内的数据。配置示例:"scope": ["MyModuleOP1", "MyModuleOP2"]。与level参数取值相关,level为L0和mix级别时,可配置模块名;level为L1级别时,可配置API名。与list参数不能同时配置。 | 否 |
34
+ | list | 自定义dump范围,list[str]类型,默认未配置(scope也未配置时表示dump所有API的数据)。包含如下配置方法:<br> PyTorch场景配置具体的API全称,dump该API数据。配置示例:"list": ["Tensor.permute.1.forward", "Tensor.transpose.2.forward", "Torch.relu.3.backward"]。<br/> PyTorch场景指定某一类API,dump某一类的API级别输入输出数据。配置示例:"list": ["relu"]。<br/> PyTorch场景配置kernel_api,dump前向和反向API的kernel_api级别数据,其中dump反向API时需要配置**backward_input**参数。前向API配置示例:"list": ["Tensor.permute.1.forward"];反向API配置示例:"list": ["Tensor.permute.1.forward"], "backward.input": "./npu_dump/step0/rank0/Functional.conv2d.1.backward.input.0.pt"]。<br/>与scope参数不能同时配置。 | 否 |
35
+ | fuzz_device | 标杆设备,str类型。可取值:<br/> "npu":无标杆,通过添加扰动因子进行比对,默认值。<br/> "cpu":以CPU为标杆,pert_mode须配置为"to_cpu"。<br/>配置示例:"fuzz_device": "cpu"。 | 否 |
36
+ | pert_mode | 无标杆扰动因子,str类型。可取值:<br/> "improve_precision":对输入做升精度,默认值。<br/> "add_noise":对输入增加噪声。<br/> "no_change":不加扰动直接二次执行。<br/> "bit_noise":输入的末位比特翻转。<br/> "change_value":输入的张量首尾值调换。<br/> "to_cpu":在CPU等价执行。<br/>配置示例:"pert_mode": "to_cpu"。 | 否 |
37
+ | handler_type | 处理类型,可取值:"check"(进行无标杆比对检查,默认值)、"fix"(将扰动后的API输出结果覆盖原始API输出结果,尝试将Loss曲线恢复正常,该模式下不支持预热if_preheat)。配置示例:"handler_type": "fix"。 | 否 |
38
+ | fuzz_level | 无标杆数据dump级别,即选择比对结果文件应输出的表头属性,当前仅支持取值为:"L1"。输出结果详见“**无标杆比对数据存盘格式**”。 | 否 |
39
+ | fuzz_stage | 前反向,选择对API前向或反向进行无标杆比对,可取值:"forward"(前向,默认值)、"backward"(反向)。配置示例:"fuzz_stage": "backward"。 | 否 |
40
+ | if_preheat | 预热功能,开启功能后工具可以根据每次迭代的输出调整精度算法的阈值,从而更准确找出存在精度问题的API,bool类型。可取值true(开启)或false(关闭),默认关闭。配置示例:"if_preheat": "true"。"handler_type": "fix"不支持预热。 | 否 |
41
+ | preheat_step | 开启预热的迭代数量,int类型,默认值为15。须配置"if_preheat": "true"。 | 否 |
42
+ | max_sample | 每个算子预热的采样次数的最大阈值,int类型,默认值为20。须配置"if_preheat": "true"。 | 否 |
43
+
44
+ #### 无标杆比对数据存盘格式
45
+
46
+ 无标杆比对在dump_path目录下输出结果文件free_benchmark.csv,如下示例:
47
+
48
+ ![free_benchmark](./img/free_benchmark.png)
49
+
50
+ | 字段 | 说明 |
51
+ | ------------ | ------------------------------------------------------------ |
52
+ | rank | Rank ID,int类型。 |
53
+ | pert_mode | 扰动因子的类型,string类型。 |
54
+ | stage | 前向或反向,string类型。 |
55
+ | step | 迭代数,int类型。 |
56
+ | api_name | API名称,string类型。 |
57
+ | max_rel | 输出对比最大相对误差,float类型。 |
58
+ | dtype | 输入的dtype,string类型。 |
59
+ | shape | 输入的shape,tuple类型。 |
60
+ | Output_index | 如果输出为列表或元组,其中一个元素检测不一致,则会有该元素的index,否则为空,int类型。 |
61
+
62
+ ### task配置为statistics
63
+
64
+ | 参数名 | 说明 | 是否必选 |
65
+ | ------------ | ------------------------------------------------------------ | -------- |
66
+ | scope | PyTorch场景dump范围,list[str]类型,默认未配置(list也未配置时表示dump所有API的数据)。需要在[]内配置两个模块名或API名,用于锁定区间,dump该范围内的数据。配置示例:"scope": ["MyModuleOP1", "MyModuleOP2"]。与level参数取值相关,level为L0和mix级别时,可配置模块名;level为L1级别时,可配置API名。 | 否 |
67
+ | list | 自定义dump范围,list[str]类型,默认未配置(scope也未配置时表示dump所有API的数据)。包含如下配置方法:<br> PyTorch场景配置具体的API全称,dump该API数据。配置示例:"list": ["Tensor.permute.1.forward", "Tensor.transpose.2.forward", "Torch.relu.3.backward"]。<br/> PyTorch场景指定某一类API,dump某一类的API级别输入输出数据。配置示例:"list": ["relu"]。<br/> MindSpore场景配置kernel_name,可以是算子的名称列表,也可以指定算子类型("level": "L2"时不支持),还可以配置算子名称的正则表达式(当字符串符合”name-regex(xxx)”格式时,后台则会将其作为正则表达式。例如,”name-regex(Default/.+)”可匹配算子名称以”Default/”开头的所有算子)。 | 否 |
68
+ | data_mode | dump数据过滤,str类型。可取值"all"、"forward"、"backward"、"input"和"output",表示仅保存dump的数据中文件名包含"forward"、"backward"、"input"和"output"的前向、反向、输入或输出的dump文件。配置示例"data_mode": ["backward"]或"data_mode": ["forward", "backward"]。默认为["all"],即保存所有dump的数据。除了all参数只能单独配置外,其他参数可以自由组合。<br/>MindSpore场景仅支持"all"、"input"和"output"参数,且各参数只能单独配置,不支持自由组合。 | 否 |
69
+ | summary_mode | 控制dump文件输出的模式,str类型,仅PyTorch场景支持,可取值md5(dump输出包含md5值以及API统计信息的dump.json文件,用于验证数据的完整性)、statistics(dump仅输出包含API统计信息的dump.json文件,默认值)。配置示例:"summary_mode": "md5"。 | 否 |
70
+
71
+ ### task配置为tensor
72
+
73
+ | 参数名 | 说明 | 是否必选 |
74
+ | -------------- | ------------------------------------------------------------ | -------- |
75
+ | scope | PyTorch场景dump范围,list[str]类型,默认未配置(list也未配置时表示dump所有API的数据)。需要在[]内配置两个模块名或API名,用于锁定区间,dump该范围内的数据。配置示例:"scope": ["MyModuleOP1", "MyModuleOP2"]。与level参数取值相关,level为L0和mix级别时,可配置模块名;level为L1级别时,可配置API名。 | 否 |
76
+ | list | 自定义dump范围,list[str]类型,默认未配置(scope也未配置时表示dump所有API的数据)。包含如下配置方法:<br> PyTorch场景配置具体的API全称,dump该API数据。配置示例:"list": ["Tensor.permute.1.forward", "Tensor.transpose.2.forward", "Torch.relu.3.backward"]。<br/> PyTorch场景指定某一类API,dump某一类的API级别输入输出数据。配置示例:"list": ["relu"]。<br/> PyTorch场景配置kernel_api,dump前向和反向API的kernel_api级别数据,其中dump反向API时需要配置**backward_input**参数。前向API配置示例:"list": ["Tensor.permute.1.forward"];反API配置示例:"list": ["Tensor.permute.1.forward"], "backward.input": "./npu_dump/step0/rank0/Functional.conv2d.1.backward.input.0.pt"]。<br/> MindSpore场景配置kernel_name,可以是算子的名称列表,也可以指定算子类型("level": "L2"时不支持),还可以配置算子名称的正则表达式(当字符串符合”name-regex(xxx)”格式时,后台则会将其作为正则表达式。例如,”name-regex(Default/.+)”可匹配算子名称以”Default/”开头的所有算子)。 | 否 |
77
+ | backward_input | 该输入文件为首次运行训练dump得到反向API输入的dump文件,str类型,仅PyTorch场景支持,默认未配置。例如若需要dump Functional.conv2d.1 API的反向过程的输入输出,则需要在dump目录下查找命名包含Functional.conv2d.1、backward和input字段的dump文件。配置示例:"backward_input": "./npu_dump/step0/rank0/Functional.conv2d.1.backward.input.0.pt"] | 否 |
78
+ | data_mode | dump数据过滤,str类型。可取值"all"、"forward"、"backward"、"input"和"output",表示仅保存dump的数据中文件名包含"forward"、"backward"、"input"和"output"的前向、反向、输入或输出的dump文件。配置示例"data_mode": ["backward"]或"data_mode": ["forward", "backward"]。默认为["all"],即保存所有dump的数据。除了all参数只能单独配置外,其他参数可以自由组合。<br/>MindSpore场景仅支持"all"、"input"和"output"参数,且各参数只能单独配置,不支持自由组合。 | 否 |
79
+ | file_format | MindSpore场景真实tensor数据的保存格式,str类型,可取值"bin"(dump的tensor文件为二进制格式,"level": "L1"时不支持)、"npy"(dump的tensor文件后缀为.npy,默认值)。 | 否 |
80
+
81
+ ### task配置为overflow_check
82
+
83
+ | 参数名 | 说明 | 是否必选 |
84
+ | ------------- | ------------------------------------------------------------ | -------- |
85
+ | overflow_nums | 控制溢出次数,int类型,仅PyTorch场景支持,表示第N次溢出时,停止训练,过程中检测到溢出API对应kernel数据均dump。配置示例:"overflow_nums": 3。默认为1,即检测到1次溢出,训练停止,配置为-1时,表示持续检测溢出直到训练结束。 | 否 |
86
+ | check_mode | MindSpore场景kernel级别的溢出检测,str类型,可取值"aicore"(开启AI Core的溢出检测)、"atomic"(开启Atomic的溢出检测)、"all"(开启AI Core和Atomic的溢出检测,默认值)。配置示例"check_mode": "aicore"。 | 否 |
87
+
88
+ ## 配置示例
89
+
90
+ 以下示例包含当前支持的所有场景可配置的完整参数。
91
+
92
+ ### PyTorch场景task配置为free_benchmark
93
+
94
+ ```json
95
+ {
96
+ "task": "free_benchmark",
97
+ "dump_path": "/home/data_dump",
98
+ "rank": [],
99
+ "step": [],
100
+ "level": "L1",
101
+ "seed": 1234,
102
+ "is_deterministic": false,
103
+ "enable_dataloader": false,
104
+
105
+ "free_benchmark": {
106
+ "scope": [],
107
+ "list": ["conv2d"],
108
+ "fuzz_device": "npu",
109
+ "pert_mode": "improve_precision",
110
+ "handler_type": "check",
111
+ "fuzz_level": "L1",
112
+ "fuzz_stage": "forward",
113
+ "if_preheat": false,
114
+ "preheat_step": 15,
115
+ "max_sample": 20
116
+ }
117
+ }
118
+ ```
119
+
120
+ ### PyTorch场景task配置为statistics
121
+
122
+ ```json
123
+ {
124
+ "task": "statistics",
125
+ "dump_path": "/home/data_dump",
126
+ "rank": [],
127
+ "step": [],
128
+ "level": "L1",
129
+ "seed": 1234,
130
+ "is_deterministic": false,
131
+ "enable_dataloader": false,
132
+
133
+ "statistics": {
134
+ "scope": [],
135
+ "list": [],
136
+ "data_mode": ["all"],
137
+ "summary_mode": "statistics"
138
+ }
139
+ }
140
+ ```
141
+
142
+ ### PyTorch场景task配置为tensor
143
+
144
+ ```json
145
+ {
146
+ "task": "tensor",
147
+ "dump_path": "/home/data_dump",
148
+ "rank": [],
149
+ "step": [],
150
+ "level": "L1",
151
+ "seed": 1234,
152
+ "is_deterministic": false,
153
+ "enable_dataloader": false,
154
+
155
+ "tensor": {
156
+ "scope": [],
157
+ "list":[],
158
+ "data_mode": ["all"],
159
+ "backward_input": ""
160
+ }
161
+ }
162
+ ```
163
+
164
+ ### PyTorch场景task配置为overflow_check
165
+
166
+ ```json
167
+ {
168
+ "task": "overflow_check",
169
+ "dump_path": "/home/data_dump",
170
+ "rank": [],
171
+ "step": [],
172
+ "level": "L1",
173
+ "seed": 1234,
174
+ "is_deterministic": false,
175
+ "enable_dataloader": false,
176
+
177
+ "overflow_check": {
178
+ "overflow_nums": 1
179
+ }
180
+ }
181
+ ```
182
+
183
+ ### MindSpore场景task配置为statistics
184
+
185
+ ```json
186
+ {
187
+ "task": "statistics",
188
+ "dump_path": "/home/data_dump",
189
+ "rank": [],
190
+ "step": [],
191
+ "level": "L1",
192
+ "seed": 1234,
193
+ "is_deterministic": false,
194
+
195
+ "statistics": {
196
+ "list": [],
197
+ "data_mode": ["all"],
198
+ "summary_mode": "statistics"
199
+ }
200
+ }
201
+ ```
202
+
203
+ ### MindSpore场景task配置为tensor
204
+
205
+ ```json
206
+ {
207
+ "task": "tensor",
208
+ "dump_path": "/home/data_dump",
209
+ "rank": [],
210
+ "step": [],
211
+ "level": "L1",
212
+ "seed": 1234,
213
+ "is_deterministic": false,
214
+
215
+ "tensor": {
216
+ "list":[],
217
+ "data_mode": ["all"],
218
+ "backward_input": ""
219
+ }
220
+ }
221
+ ```
222
+
223
+ ### MindSpore场景task配置为overflow_check
224
+
225
+ ```json
226
+ {
227
+ "task": "overflow_check",
228
+ "dump_path": "/home/data_dump",
229
+ "rank": [],
230
+ "step": [],
231
+ "level": "L1",
232
+ "seed": 1234,
233
+ "is_deterministic": false,
234
+
235
+ "overflow_check": {
236
+ "overflow_nums": 1,
237
+ "check_mode": "all"
238
+ }
239
+ }
240
+ ```
241
+
242
+ ## 附录
243
+
244
+ ### 模块级精度数据dump说明
245
+
246
+ 仅PyTorch场景支持。
247
+
248
+ 大模型场景下,通常不是简单的利用自动迁移能力实现GPU到NPU的训练脚本迁移,而是会对NPU网络进行一系列针对性的适配,因此,常常会造成迁移后的NPU模型存在部分子结构不能与GPU原始模型完全对应。模型结构不一致导致API调用类型及数量不一致,若直接按照API粒度进行精度数据dump和比对,则无法完全比对所有的API。
249
+
250
+ 本节介绍的功能是对模型中的大粒度模块进行数据dump,使其比对时,对于无法以API粒度比对的模块可以直接以模块粒度进行比对。
251
+
252
+ 模块指的是继承自nn.Module类模块,通常情况下这类模块就是一个小模型,可以被视为一个整体,dump数据时以模块为粒度进行dump。
253
+
254
+ ### acl_config.json配置文件说明
255
+
256
+ #### [config.json](./config.json)配置示例
257
+
258
+ 当level取"L2"时,须配置acl_config参数,并指定acl_config.json文件(用于指定L2 kernel级dump的配置),此时config.json文件配置示例如下:
259
+
260
+ - 前向kernel dump配置示例:
261
+
262
+ "scope"配置为前向API名称,仅支持配置一个API。
263
+
264
+ ```json
265
+ {
266
+ "task": "tensor",
267
+ "dump_path": "/home/data_dump",
268
+ "level": "L2",
269
+ "rank": [0],
270
+ "step": [0],
271
+ "is_deterministic": false,
272
+ "tensor": {
273
+ "scope": ["Tensor.__mul__.10.forward"],
274
+ "list":[],
275
+ "data_mode": ["all"],
276
+ "backward_input": [""],
277
+ "file_format": "npy"
278
+ },
279
+ "acl_config": "acl_config.json"
280
+ }
281
+ ```
282
+
283
+ - 反向kernel dump配置示例:
284
+
285
+ 执行反向kernel dump前需要先使用工具dump该API的反向输入,保存pt文件,在"backward_input"参数中传入该pt文件路径。
286
+
287
+ "scope"配置为反向API名称,仅支持配置一个API。
288
+
289
+ ```json
290
+ {
291
+ "task": "tensor",
292
+ "dump_path": "/home/data_dump",
293
+ "level": "L2",
294
+ "rank": [0],
295
+ "step": [0],
296
+ "is_deterministic": false,
297
+ "tensor": {
298
+ "scope": ["Tensor.__mul__.10.backward"],
299
+ "list":[],
300
+ "data_mode": ["all"],
301
+ "backward_input": ["Tensor.__mul__.10.backward.input.0.pt"],
302
+ "file_format": "npy"
303
+ },
304
+ "acl_config": "acl_config.json"
305
+ }
306
+ ```
307
+
308
+ #### acl_config.json配置示例
309
+
310
+ acl_config.json文件须自行创建,配置示例如下:
311
+
312
+ ```
313
+ {
314
+ "dump":
315
+ {
316
+ "dump_list":[],
317
+ "dump_path":"./dump/output",
318
+ "dump_mode":"all",
319
+ "dump_op_switch":"on"
320
+ }
321
+ }
322
+ ```
323
+
324
+ **acl_config.json参数说明**
325
+
326
+ | 字段名 | 说明 |
327
+ | -------------- | ------------------------------------------------------------ |
328
+ | dump_list | 待dump数据的API模型。为空,无需配置。 |
329
+ | dump_path | dump数据文件存储到运行环境的目录,主要用于指定kernel dump数据路径。支持配置绝对路径或相对路径。dump_path须为已存在目录。 |
330
+ | dump_mode | dump数据模式,配置如下: output:dump API的输出数据。默认值。 input:dump API的输入数据。 all:dump API的输入、输出数据。 |
331
+ | dump_op_switch | 单API模型dump数据开关,配置如下:<br> off:关闭单API模型dump,默认值。<br> on:开启单API模型dump。 |
332
+
333
+ **dump目录说明**
334
+
335
+ 配置register_hook的dump_config后,采集的dump数据会在{dump_path}/{time}/{deviceid}/{model_id}目录下生成,例如“/home/HwHiAiUser/output/20200808163566/0/0”
336
+
337
+ ```
338
+ ├── 20230131172437
339
+ │ └── 1
340
+ │ ├── 0
341
+ │ │ ├── Add.Add.45.0.1675157077183551
342
+ │ │ ├── Cast.trans_Cast_0.31.0.1675157077159449
343
+ │ │ ├── Cast.trans_Cast_5.43.0.1675157077180129
344
+ │ │ ├── MatMul.MatMul.39.0.1675157077172961
345
+ │ │ ├── Mul.Mul.29.0.1675157077155731
346
+ │ │ ├── NPUAllocFloatStatus.NPUAllocFloatStatus.24.0.1675157077145262
347
+ │ │ ├── TransData.trans_TransData_1.33.0.1675157077162791
348
+ │ │ └── TransData.trans_TransData_4.41.0.1675157077176648
349
+ │ ├── 1701737061
350
+ │ │ └── Cast.trans_Cast_2.35.0.1675157077166214
351
+ │ ├── 25
352
+ │ │ └── NPUClearFloatStatus.NPUClearFloatStatus.26.0.1675157077150342
353
+ │ └── 68
354
+ │ └── TransData.trans_TransData_3.37.0.1675157077169473
355
+ ```
356
+
357
+ ### 固定随机数范围
358
+
359
+ 仅PyTorch场景支持。
360
+
361
+ seed_all函数可固定随机数的范围如下表。
362
+
363
+ | API | 固定随机数 |
364
+ | ---------------------------------------- | --------------------------- |
365
+ | os.environ['PYTHONHASHSEED'] = str(seed) | 禁止Python中的hash随机化 |
366
+ | random.seed(seed) | 设置random随机生成器的种子 |
367
+ | np.random.seed(seed) | 设置numpy中随机生成器的种子 |
368
+ | torch.manual_seed(seed) | 设置当前CPU的随机种子 |
369
+ | torch.cuda.manual_seed(seed) | 设置当前GPU的随机种子 |
370
+ | torch.cuda.manual_seed_all(seed) | 设置所有GPU的随机种子 |
371
+ | torch_npu.npu.manual_seed(seed) | 设置当前NPU的随机种子 |
372
+ | torch_npu.npu.manual_seed_all(seed) | 设置所有NPU的随机种子 |
373
+ | torch.backends.cudnn.enable=False | 关闭cuDNN |
374
+ | torch.backends.cudnn.benchmark=False | cuDNN确定性地选择算法 |
375
+ | torch.backends.cudnn.deterministic=True | cuDNN仅使用确定性的卷积算法 |
376
+
377
+ 需要保证CPU或GPU以及NPU的模型输入完全一致,dump数据的比对才有意义,seed_all并不能保证模型输入完全一致,如下表所示场景需要保证输入的一致性。
378
+
379
+ | 场景 | 固定方法 |
380
+ | --------------- | ------------- |
381
+ | 数据集的shuffle | 关闭shuffle。 |
382
+ | dropout | 关闭dropout。 |
383
+
384
+ 关闭shuffle示例:
385
+
386
+ ```Python
387
+ train_loader = torch.utils.data.DataLoader(
388
+ train_dataset,
389
+ batch_size = batch_size,
390
+ shuffle = False,
391
+ num_workers = num_workers
392
+ )
393
+ ```
394
+
395
+ 关闭dropout:
396
+
397
+ 在使用from msprobe.pytorch import PrecisionDebugger后,工具会自动将torch.nn.functional.dropout、torch.nn.functional.dropout2d、torch.nn.functional.dropout3d、torch.nn.Dropout、torch.nn.Dropout2d、torch.nn.Dropout3d的接口参数p置为0。
@@ -0,0 +1,28 @@
1
+ {
2
+ "task": "statistics",
3
+ "dump_path": "./dump_path",
4
+ "rank": [],
5
+ "step": [],
6
+ "level": "L1",
7
+ "seed": 1234,
8
+ "is_deterministic": false,
9
+ "enable_dataloader": false,
10
+ "acl_config": "",
11
+ "tensor": {
12
+ "scope": [],
13
+ "list":[],
14
+ "data_mode": ["all"],
15
+ "backward_input": [],
16
+ "file_format": "npy"
17
+ },
18
+ "statistics": {
19
+ "scope": [],
20
+ "list":[],
21
+ "data_mode": ["all"],
22
+ "summary_mode": "statistics"
23
+ },
24
+ "overflow_check": {
25
+ "overflow_nums": 1,
26
+ "check_mode":"all"
27
+ }
28
+ }
Binary file