mindstudio-probe 1.1.0__py3-none-any.whl → 1.2.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 (299) hide show
  1. {mindstudio_probe-1.1.0.dist-info → mindstudio_probe-1.2.1.dist-info}/METADATA +7 -6
  2. mindstudio_probe-1.2.1.dist-info/RECORD +396 -0
  3. {mindstudio_probe-1.1.0.dist-info → mindstudio_probe-1.2.1.dist-info}/WHEEL +1 -1
  4. {mindstudio_probe-1.1.0.dist-info → mindstudio_probe-1.2.1.dist-info}/entry_points.txt +0 -1
  5. msprobe/CMakeLists.txt +5 -0
  6. msprobe/README.md +51 -20
  7. msprobe/config.json +2 -3
  8. msprobe/core/advisor/advisor.py +8 -3
  9. msprobe/core/common/const.py +264 -15
  10. msprobe/core/common/exceptions.py +27 -3
  11. msprobe/core/common/file_utils.py +176 -26
  12. msprobe/core/common/inplace_op_checker.py +15 -0
  13. msprobe/core/common/inplace_ops.yaml +3 -0
  14. msprobe/core/common/log.py +27 -9
  15. msprobe/core/common/utils.py +204 -77
  16. msprobe/core/common_config.py +49 -14
  17. msprobe/core/compare/acc_compare.py +274 -198
  18. msprobe/core/compare/check.py +32 -33
  19. msprobe/core/compare/compare_cli.py +32 -14
  20. msprobe/core/compare/highlight.py +283 -127
  21. msprobe/core/compare/layer_mapping/__init__.py +19 -0
  22. msprobe/core/compare/layer_mapping/data_scope_parser.py +246 -0
  23. msprobe/core/compare/layer_mapping/layer_mapping.py +249 -0
  24. msprobe/core/compare/layer_mapping/postprocess_pass.py +95 -0
  25. msprobe/core/compare/merge_result/merge_result.py +380 -0
  26. msprobe/core/compare/merge_result/merge_result_cli.py +31 -0
  27. msprobe/core/compare/multiprocessing_compute.py +2 -2
  28. msprobe/core/compare/npy_compare.py +135 -144
  29. msprobe/core/compare/utils.py +419 -274
  30. msprobe/core/data_dump/data_collector.py +60 -28
  31. msprobe/core/data_dump/data_processor/base.py +84 -36
  32. msprobe/core/data_dump/data_processor/factory.py +5 -3
  33. msprobe/core/data_dump/data_processor/mindspore_processor.py +152 -18
  34. msprobe/core/data_dump/data_processor/pytorch_processor.py +267 -110
  35. msprobe/core/data_dump/json_writer.py +29 -1
  36. msprobe/core/data_dump/scope.py +119 -39
  37. msprobe/core/grad_probe/constant.py +27 -13
  38. msprobe/core/grad_probe/grad_compare.py +18 -1
  39. msprobe/core/grad_probe/utils.py +30 -2
  40. msprobe/core/overflow_check/abnormal_scene.py +189 -0
  41. msprobe/core/overflow_check/api_info.py +55 -0
  42. msprobe/core/overflow_check/checker.py +138 -0
  43. msprobe/core/overflow_check/filter.py +157 -0
  44. msprobe/core/overflow_check/ignore_rules.yaml +55 -0
  45. msprobe/core/overflow_check/level.py +22 -0
  46. msprobe/core/overflow_check/utils.py +28 -0
  47. msprobe/docs/01.installation.md +96 -7
  48. msprobe/docs/02.config_introduction.md +50 -23
  49. msprobe/docs/03.config_examples.md +2 -9
  50. msprobe/docs/04.kernel_dump_PyTorch.md +73 -0
  51. msprobe/docs/05.data_dump_PyTorch.md +93 -61
  52. msprobe/docs/06.data_dump_MindSpore.md +200 -95
  53. msprobe/docs/07.accuracy_checker_PyTorch.md +28 -28
  54. msprobe/docs/08.accuracy_checker_online_PyTorch.md +1 -6
  55. msprobe/docs/09.accuracy_checker_MindSpore.md +44 -8
  56. msprobe/docs/10.accuracy_compare_PyTorch.md +114 -50
  57. msprobe/docs/11.accuracy_compare_MindSpore.md +340 -48
  58. msprobe/docs/12.overflow_check_PyTorch.md +2 -2
  59. msprobe/docs/13.overflow_check_MindSpore.md +6 -6
  60. msprobe/docs/15.free_benchmarking_PyTorch.md +4 -5
  61. msprobe/docs/16.free_benchmarking_MindSpore.md +56 -37
  62. msprobe/docs/17.grad_probe.md +5 -6
  63. msprobe/docs/19.monitor.md +561 -0
  64. msprobe/docs/20.monitor_performance_baseline.md +52 -0
  65. msprobe/docs/21.visualization_PyTorch.md +466 -0
  66. msprobe/docs/22.visualization_MindSpore.md +481 -0
  67. msprobe/docs/23.generate_operator_PyTorch.md +107 -0
  68. msprobe/docs/24.code_mapping_Mindspore.md +28 -0
  69. msprobe/docs/25.tool_function_introduction.md +29 -0
  70. msprobe/docs/26.data_dump_PyTorch_baseline.md +37 -0
  71. msprobe/docs/27.dump_json_instruction.md +521 -0
  72. msprobe/docs/FAQ.md +29 -2
  73. msprobe/docs/accuracy_checker_MindSpore/accuracy_checker_MindSpore_baseline.md +14 -0
  74. msprobe/docs/data_dump_MindSpore/data_dump_MindSpore_baseline.md +22 -0
  75. msprobe/docs/data_dump_MindSpore/dynamic_graph_quick_start_example.md +211 -0
  76. msprobe/docs/img/compare_result.png +0 -0
  77. msprobe/docs/img/merge_result.png +0 -0
  78. msprobe/docs/img/monitor/cpu_info.png +0 -0
  79. msprobe/docs/img/visualization/fuzzy_match_ms.png +0 -0
  80. msprobe/docs/img/visualization/fuzzy_match_pt.png +0 -0
  81. msprobe/docs/img/visualization/tensorboard_1.png +0 -0
  82. msprobe/docs/img/visualization/tensorboard_2.png +0 -0
  83. msprobe/docs/img/visualization/vis_browser_1.png +0 -0
  84. msprobe/docs/img/visualization/vis_browser_2.png +0 -0
  85. msprobe/docs/img/visualization/vis_precision_info.png +0 -0
  86. msprobe/docs/img/visualization/vis_search_info.png +0 -0
  87. msprobe/docs/img/visualization/vis_show_info.png +0 -0
  88. msprobe/docs/img/visualization/vis_showcase.png +0 -0
  89. msprobe/docs/img/visualization/vis_unmatch_info.png +0 -0
  90. msprobe/docs/visualization/GPTModel.png +0 -0
  91. msprobe/docs/visualization/ParallelMLP.png +0 -0
  92. msprobe/docs/visualization/layer_mapping_example.md +132 -0
  93. msprobe/docs/visualization/mapping.png +0 -0
  94. msprobe/docs/visualization/mapping1.png +0 -0
  95. msprobe/docs/visualization/module_name.png +0 -0
  96. msprobe/docs/visualization/module_name1.png +0 -0
  97. msprobe/docs/visualization/no_mapping.png +0 -0
  98. msprobe/docs/visualization/no_mapping1.png +0 -0
  99. msprobe/docs/visualization/no_mapping_analyze.png +0 -0
  100. msprobe/docs/visualization/top_layer.png +0 -0
  101. msprobe/mindspore/__init__.py +25 -0
  102. msprobe/mindspore/api_accuracy_checker/api_accuracy_checker.py +151 -151
  103. msprobe/mindspore/api_accuracy_checker/api_info.py +21 -6
  104. msprobe/mindspore/api_accuracy_checker/api_runner.py +43 -18
  105. msprobe/mindspore/api_accuracy_checker/base_compare_algorithm.py +21 -7
  106. msprobe/mindspore/api_accuracy_checker/checker_support_api.yaml +77 -0
  107. msprobe/mindspore/api_accuracy_checker/cmd_parser.py +64 -1
  108. msprobe/mindspore/api_accuracy_checker/compute_element.py +64 -31
  109. msprobe/mindspore/api_accuracy_checker/data_manager.py +301 -0
  110. msprobe/mindspore/api_accuracy_checker/main.py +28 -3
  111. msprobe/mindspore/api_accuracy_checker/multi_api_accuracy_checker.py +212 -0
  112. msprobe/mindspore/api_accuracy_checker/multi_data_manager.py +60 -0
  113. msprobe/mindspore/api_accuracy_checker/type_mapping.py +22 -5
  114. msprobe/mindspore/api_accuracy_checker/utils.py +34 -17
  115. msprobe/mindspore/cell_processor.py +33 -12
  116. msprobe/mindspore/code_mapping/bind.py +264 -0
  117. msprobe/mindspore/code_mapping/cmd_parser.py +40 -0
  118. msprobe/mindspore/code_mapping/graph.py +49 -0
  119. msprobe/mindspore/code_mapping/graph_parser.py +226 -0
  120. msprobe/mindspore/code_mapping/main.py +24 -0
  121. msprobe/mindspore/code_mapping/processor.py +34 -0
  122. msprobe/mindspore/common/const.py +35 -13
  123. msprobe/mindspore/common/log.py +5 -9
  124. msprobe/mindspore/common/utils.py +88 -4
  125. msprobe/mindspore/compare/distributed_compare.py +22 -24
  126. msprobe/mindspore/compare/ms_compare.py +333 -268
  127. msprobe/mindspore/compare/ms_graph_compare.py +95 -52
  128. msprobe/mindspore/debugger/debugger_config.py +7 -1
  129. msprobe/mindspore/debugger/precision_debugger.py +87 -12
  130. msprobe/mindspore/dump/dump_tool_factory.py +3 -1
  131. msprobe/mindspore/dump/hook_cell/api_registry.py +95 -18
  132. msprobe/mindspore/dump/hook_cell/hook_cell.py +60 -38
  133. msprobe/mindspore/dump/hook_cell/primitive_hooks.py +45 -30
  134. msprobe/mindspore/dump/hook_cell/support_wrap_ops.yaml +36 -1
  135. msprobe/mindspore/dump/hook_cell/wrap_api.py +92 -1
  136. msprobe/mindspore/dump/jit_dump.py +17 -5
  137. msprobe/mindspore/dump/kernel_dump/kernel_config.py +33 -0
  138. msprobe/mindspore/dump/kernel_graph_dump.py +9 -4
  139. msprobe/mindspore/dump/kernel_kbyk_dump.py +2 -4
  140. msprobe/mindspore/dym_loader/hook_dynamic_loader.cc +140 -0
  141. msprobe/mindspore/dym_loader/hook_dynamic_loader.h +53 -0
  142. msprobe/mindspore/free_benchmark/api_pynative_self_check.py +156 -41
  143. msprobe/mindspore/free_benchmark/common/handler_params.py +1 -2
  144. msprobe/mindspore/free_benchmark/common/utils.py +19 -4
  145. msprobe/mindspore/free_benchmark/data/support_wrap_ops.yaml +0 -204
  146. msprobe/mindspore/free_benchmark/handler/base_handler.py +3 -3
  147. msprobe/mindspore/free_benchmark/handler/check_handler.py +4 -5
  148. msprobe/mindspore/free_benchmark/handler/fix_handler.py +4 -4
  149. msprobe/mindspore/free_benchmark/handler/handler_factory.py +4 -4
  150. msprobe/mindspore/free_benchmark/perturbation/add_noise.py +2 -2
  151. msprobe/mindspore/free_benchmark/perturbation/base_perturbation.py +15 -6
  152. msprobe/mindspore/free_benchmark/perturbation/bit_noise.py +2 -2
  153. msprobe/mindspore/free_benchmark/perturbation/exchange_value.py +2 -2
  154. msprobe/mindspore/free_benchmark/perturbation/improve_precision.py +13 -6
  155. msprobe/mindspore/free_benchmark/perturbation/perturbation_factory.py +2 -2
  156. msprobe/mindspore/free_benchmark/self_check_tool_factory.py +2 -2
  157. msprobe/mindspore/grad_probe/global_context.py +28 -8
  158. msprobe/mindspore/grad_probe/grad_analyzer.py +50 -24
  159. msprobe/mindspore/grad_probe/grad_monitor.py +16 -1
  160. msprobe/mindspore/grad_probe/grad_stat_csv.py +33 -5
  161. msprobe/mindspore/grad_probe/hook.py +35 -12
  162. msprobe/mindspore/grad_probe/utils.py +18 -5
  163. msprobe/mindspore/mindtorch/__init__.py +18 -0
  164. msprobe/mindspore/mindtorch/mindtorch_adaptor.py +255 -0
  165. msprobe/mindspore/ms_config.py +27 -16
  166. msprobe/mindspore/overflow_check/kernel_graph_overflow_check.py +9 -4
  167. msprobe/mindspore/runtime.py +15 -0
  168. msprobe/mindspore/service.py +285 -113
  169. msprobe/mindspore/task_handler_factory.py +15 -0
  170. msprobe/msprobe.py +48 -10
  171. msprobe/pytorch/__init__.py +8 -6
  172. msprobe/pytorch/api_accuracy_checker/common/config.py +62 -0
  173. msprobe/pytorch/api_accuracy_checker/common/utils.py +31 -16
  174. msprobe/pytorch/api_accuracy_checker/compare/algorithm.py +41 -8
  175. msprobe/pytorch/api_accuracy_checker/compare/api_precision_compare.py +103 -271
  176. msprobe/pytorch/api_accuracy_checker/compare/api_precision_standard.yaml +4 -1
  177. msprobe/pytorch/api_accuracy_checker/compare/compare.py +69 -68
  178. msprobe/pytorch/api_accuracy_checker/compare/compare_column.py +54 -0
  179. msprobe/pytorch/api_accuracy_checker/compare/compare_input.py +51 -0
  180. msprobe/pytorch/api_accuracy_checker/compare/compare_utils.py +2 -4
  181. msprobe/pytorch/api_accuracy_checker/generate_op_script/config_op.json +9 -0
  182. msprobe/pytorch/api_accuracy_checker/generate_op_script/op_generator.py +478 -0
  183. msprobe/pytorch/api_accuracy_checker/generate_op_script/operator_replication.template +365 -0
  184. msprobe/pytorch/api_accuracy_checker/precision_standard/absolute_threshold.py +106 -0
  185. msprobe/pytorch/api_accuracy_checker/precision_standard/accumulative_error_compare.py +107 -0
  186. msprobe/pytorch/api_accuracy_checker/precision_standard/base_standard.py +151 -0
  187. msprobe/pytorch/api_accuracy_checker/precision_standard/benchmark_compare.py +226 -0
  188. msprobe/pytorch/api_accuracy_checker/precision_standard/binary_consistency.py +68 -0
  189. msprobe/pytorch/api_accuracy_checker/precision_standard/standard_config.py +218 -0
  190. msprobe/pytorch/api_accuracy_checker/precision_standard/standard_register.py +104 -0
  191. msprobe/pytorch/api_accuracy_checker/precision_standard/thousandth_standard.py +63 -0
  192. msprobe/pytorch/api_accuracy_checker/precision_standard/ulp_compare.py +200 -0
  193. msprobe/pytorch/api_accuracy_checker/run_ut/data_generate.py +63 -2
  194. msprobe/pytorch/api_accuracy_checker/run_ut/multi_run_ut.py +21 -15
  195. msprobe/pytorch/api_accuracy_checker/run_ut/run_overflow_check.py +54 -22
  196. msprobe/pytorch/api_accuracy_checker/run_ut/run_ut.py +140 -71
  197. msprobe/pytorch/api_accuracy_checker/run_ut/run_ut_utils.py +49 -8
  198. msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/attl.py +9 -24
  199. msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/client.py +4 -12
  200. msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/device_dispatch.py +5 -3
  201. msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/dump_dispatch.py +9 -4
  202. msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/server.py +3 -11
  203. msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/utils.py +2 -2
  204. msprobe/pytorch/bench_functions/confusion_transpose.py +5 -1
  205. msprobe/pytorch/bench_functions/matmul_backward.py +12 -0
  206. msprobe/pytorch/bench_functions/npu_fusion_attention.py +142 -16
  207. msprobe/pytorch/bench_functions/rotary_mul.py +4 -0
  208. msprobe/pytorch/bench_functions/swiglu.py +10 -2
  209. msprobe/pytorch/common/parse_json.py +7 -6
  210. msprobe/pytorch/common/utils.py +101 -7
  211. msprobe/pytorch/compare/distributed_compare.py +17 -30
  212. msprobe/pytorch/compare/pt_compare.py +44 -22
  213. msprobe/pytorch/debugger/debugger_config.py +46 -27
  214. msprobe/pytorch/debugger/precision_debugger.py +42 -12
  215. msprobe/pytorch/dump/kernel_dump/kernel_config.py +33 -0
  216. msprobe/pytorch/dump/module_dump/module_dump.py +86 -0
  217. msprobe/pytorch/{module_processer.py → dump/module_dump/module_processer.py} +81 -10
  218. msprobe/pytorch/free_benchmark/common/constant.py +15 -0
  219. msprobe/pytorch/free_benchmark/common/counter.py +15 -0
  220. msprobe/pytorch/free_benchmark/common/enums.py +15 -0
  221. msprobe/pytorch/free_benchmark/common/params.py +10 -2
  222. msprobe/pytorch/free_benchmark/common/utils.py +29 -4
  223. msprobe/pytorch/free_benchmark/compare/grad_saver.py +20 -5
  224. msprobe/pytorch/free_benchmark/compare/single_benchmark.py +2 -0
  225. msprobe/pytorch/free_benchmark/perturbed_layers/npu/add_noise.py +3 -1
  226. msprobe/pytorch/free_benchmark/perturbed_layers/npu/bit_noise.py +6 -4
  227. msprobe/pytorch/free_benchmark/perturbed_layers/npu/change_value.py +2 -0
  228. msprobe/pytorch/free_benchmark/perturbed_layers/npu/improve_precision.py +4 -0
  229. msprobe/pytorch/free_benchmark/result_handlers/base_handler.py +41 -47
  230. msprobe/pytorch/free_benchmark/result_handlers/fix_handler.py +6 -5
  231. msprobe/pytorch/free_benchmark/result_handlers/preheat_handler.py +0 -4
  232. msprobe/pytorch/grad_probe/grad_monitor.py +23 -6
  233. msprobe/pytorch/grad_probe/grad_stat_csv.py +40 -10
  234. msprobe/pytorch/hook_module/__init__.py +1 -1
  235. msprobe/pytorch/hook_module/hook_module.py +14 -11
  236. msprobe/pytorch/hook_module/register_optimizer_hook.py +59 -0
  237. msprobe/pytorch/hook_module/support_wrap_ops.yaml +35 -0
  238. msprobe/pytorch/hook_module/wrap_distributed.py +6 -8
  239. msprobe/pytorch/hook_module/wrap_functional.py +0 -38
  240. msprobe/pytorch/monitor/__init__.py +0 -0
  241. msprobe/pytorch/monitor/anomaly_analyse.py +201 -0
  242. msprobe/pytorch/monitor/anomaly_detect.py +425 -0
  243. msprobe/pytorch/monitor/csv2tb.py +166 -0
  244. msprobe/pytorch/monitor/distributed/__init__.py +0 -0
  245. msprobe/pytorch/monitor/distributed/distributed_ops.yaml +19 -0
  246. msprobe/pytorch/monitor/distributed/stack_blacklist.yaml +5 -0
  247. msprobe/pytorch/monitor/distributed/wrap_distributed.py +283 -0
  248. msprobe/pytorch/monitor/features.py +108 -0
  249. msprobe/pytorch/monitor/module_hook.py +1076 -0
  250. msprobe/pytorch/monitor/module_metric.py +172 -0
  251. msprobe/pytorch/monitor/module_spec_verifier.py +95 -0
  252. msprobe/pytorch/monitor/optimizer_collect.py +333 -0
  253. msprobe/pytorch/monitor/unittest/__init__.py +0 -0
  254. msprobe/pytorch/monitor/unittest/test_monitor.py +160 -0
  255. msprobe/pytorch/monitor/utils.py +321 -0
  256. msprobe/pytorch/monitor/visualizer.py +59 -0
  257. msprobe/pytorch/online_dispatch/__init__.py +2 -3
  258. msprobe/pytorch/online_dispatch/compare.py +29 -38
  259. msprobe/pytorch/online_dispatch/dispatch.py +58 -27
  260. msprobe/pytorch/online_dispatch/dump_compare.py +21 -9
  261. msprobe/pytorch/online_dispatch/single_compare.py +53 -32
  262. msprobe/pytorch/online_dispatch/torch_ops_config.yaml +1 -1
  263. msprobe/pytorch/online_dispatch/utils.py +49 -21
  264. msprobe/pytorch/parse_tool/lib/compare.py +21 -27
  265. msprobe/pytorch/parse_tool/lib/config.py +6 -8
  266. msprobe/pytorch/parse_tool/lib/file_desc.py +15 -1
  267. msprobe/pytorch/parse_tool/lib/interactive_cli.py +10 -10
  268. msprobe/pytorch/parse_tool/lib/parse_exception.py +7 -7
  269. msprobe/pytorch/parse_tool/lib/parse_tool.py +12 -12
  270. msprobe/pytorch/parse_tool/lib/utils.py +33 -53
  271. msprobe/pytorch/parse_tool/lib/visualization.py +11 -10
  272. msprobe/pytorch/pt_config.py +31 -8
  273. msprobe/pytorch/service.py +188 -108
  274. msprobe/visualization/__init__.py +14 -0
  275. msprobe/visualization/builder/__init__.py +14 -0
  276. msprobe/visualization/builder/graph_builder.py +222 -0
  277. msprobe/visualization/builder/msprobe_adapter.py +227 -0
  278. msprobe/visualization/compare/__init__.py +14 -0
  279. msprobe/visualization/compare/graph_comparator.py +180 -0
  280. msprobe/visualization/compare/mode_adapter.py +197 -0
  281. msprobe/visualization/graph/__init__.py +14 -0
  282. msprobe/visualization/graph/base_node.py +119 -0
  283. msprobe/visualization/graph/distributed_analyzer.py +318 -0
  284. msprobe/visualization/graph/graph.py +209 -0
  285. msprobe/visualization/graph/node_colors.py +95 -0
  286. msprobe/visualization/graph/node_op.py +39 -0
  287. msprobe/visualization/graph_service.py +288 -0
  288. msprobe/visualization/utils.py +217 -0
  289. mindstudio_probe-1.1.0.dist-info/RECORD +0 -287
  290. msprobe/docs/04.acl_config_examples.md +0 -78
  291. msprobe/mindspore/compare/layer_mapping.py +0 -146
  292. msprobe/mindspore/compare/modify_mapping.py +0 -107
  293. msprobe/mindspore/free_benchmark/decorator/dec_forward.py +0 -57
  294. msprobe/mindspore/free_benchmark/decorator/decorator_factory.py +0 -122
  295. msprobe/pytorch/functional/module_dump.py +0 -84
  296. {mindstudio_probe-1.1.0.dist-info → mindstudio_probe-1.2.1.dist-info}/LICENSE +0 -0
  297. {mindstudio_probe-1.1.0.dist-info → mindstudio_probe-1.2.1.dist-info}/top_level.txt +0 -0
  298. /msprobe/mindspore/{free_benchmark/decorator → code_mapping}/__init__.py +0 -0
  299. /msprobe/pytorch/{functional → dump/module_dump}/__init__.py +0 -0
@@ -0,0 +1,481 @@
1
+ # MindSpore 场景的分级可视化构图比对
2
+
3
+ 分级可视化工具将msprobe工具dump的精度数据进行解析,还原模型图结构,实现模型各个层级的精度数据比对,方便用户理解模型结构、分析精度问题。
4
+
5
+ 工具支持MindSpore版本:2.4.0
6
+
7
+ ## 展示示例
8
+
9
+ 支持重建模型的层级结构;
10
+
11
+ 支持两个模型的结构差异比对;
12
+
13
+ 支持两个模型的精度数据比对,支持疑似有精度问题节点的快速搜索,自动跳转展开节点所在的层级。
14
+
15
+ ![vis_show](./img/visualization/vis_showcase.png)
16
+
17
+ ## 1.依赖安装
18
+
19
+ 分级可视化工具依赖**msprobe工具**和**tensorboard。**
20
+
21
+ ### 1.1 安装msprobe工具
22
+
23
+ [msprobe工具安装](https://gitee.com/ascend/mstt/blob/master/debug/accuracy_tools/msprobe/docs/01.installation.md)
24
+
25
+ ### 1.2 安装tb_graph_ascend
26
+
27
+ **请安装tb_graph_ascend,否则无法解析构图结果。**
28
+
29
+ ``pip3 install tb-graph-ascend``即可。
30
+
31
+ ## 2.模型结构数据采集
32
+ [MindSpore场景的精度数据采集](https://gitee.com/ascend/mstt/blob/master/debug/accuracy_tools/msprobe/docs/06.data_dump_MindSpore.md)
33
+
34
+ **仅支持动态图场景,需要选择level为L0(cell信息)或者mix(cell信息+api信息),才能采集到模型结构数据,即采集结果件construct.json内容不为空**。
35
+
36
+ ## 3.生成图结构文件
37
+
38
+ ### 3.1 构图命令行说明
39
+
40
+ **命令示例如下**:
41
+ ```
42
+ msprobe -f mindspore graph -i ./compare.json -o ./output
43
+ ```
44
+ **命令行参数说明**:
45
+
46
+ | 参数名 | 说明 | 是否必选 |
47
+ |-------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -------- |
48
+ | -i 或 --input_path | 指定比对文件,参考[比对文件说明](#313-比对文件说明) | 是 |
49
+ | -o 或 --output_path | 配置比对结果文件存盘目录,str 类型。文件名称基于时间戳自动生成,格式为:`compare_{timestamp}.vis或build_{timestamp}.vis`。 | 是 |
50
+ | -lm 或 --layer_mapping| 跨框架比对,MindSpore和PyTorch的比对场景。配置该参数时表示开启跨框架Layer层的比对功能,指定模型代码中的Layer层后,可以识别对应dump数据中的模块或API。需要指定自定义映射文件*.yaml。自定义映射文件的格式请参见[自定义映射文件(Layer)](#71-自定义映射文件layer), 如何配置自定义映射文件请参考[模型分级可视化如何配置layer mapping映射文件](./visualization/layer_mapping_example.md)。 | 否 |
51
+ | -oc 或 --overflow_check | 是否开启溢出检测模式,开启后会在输出vis文件中(`compare_{timestamp}.vis或build_{timestamp}.vis`)对每个溢出节点进行标记溢出等级,溢出等级说明参考[溢出等级说明](#312-溢出等级说明) | 否 |
52
+ | -f 或 --fuzzy_match | 是否开启模糊匹配,bool类型。模糊匹配说明参考[匹配说明](#311-匹配说明) | 否 |
53
+ | -cs 或 --complete_stack | 是否使用完整的堆栈信息,bool类型。默认使用精简的堆栈信息,数据量小有助于增加流畅度。完整堆栈和精简堆栈信息参考[堆栈信息说明](#72-堆栈信息说明) | 否 |
54
+
55
+ #### 3.1.1 匹配说明
56
+
57
+ **注:dump名称 = 名称 + 调用次数**,例如Functional.matmul.2.forward,matmul是名称,2是调用次数
58
+
59
+ 1.默认匹配
60
+ - 所有节点dump名称一致
61
+ - 节点输入输出参数数量一致,参数type、shape一致
62
+ - 节点的层级一致(父节点们一致)
63
+
64
+ 2.模糊匹配
65
+ - Cell节点dump名称一致,两个匹配上的Cell节点, 忽略各自节点下所有api的dump调用次数,按照名称一致+Cell节点内的调用顺序进行匹配
66
+ - ![fuzzy_match_ms.png](./img/visualization/fuzzy_match_ms.png)
67
+ - 参数shape一致
68
+
69
+ #### 3.1.2 溢出等级说明
70
+ - medium:输入异常,输出正常场景
71
+ - high:输入异常,输出异常;输出norm值相较于输入存在异常增大情况
72
+ - critical:输入正常,输出异常场景
73
+
74
+ #### 3.1.3 比对文件说明
75
+
76
+ 以在当前目录创建 ./compare.json 为例。
77
+ ```
78
+ {
79
+ "npu_path": "./npu_dump",
80
+ "bench_path": "./bench_dump",
81
+ "is_print_compare_log": true
82
+ }
83
+ ```
84
+ **比对文件参数说明**:
85
+
86
+ | 参数名 | 说明 | 是否必选 |
87
+ |-------------------|-------------------------------------------------------------------------------------------------------|------|
88
+ | npu_path | 指定待调试侧比对路径,str类型。工具根据路径格式自动进行单rank比对、多rank批量比对或多step批量比对,具体格式参考3.2 图构建和比对。 | 是 |
89
+ | bench_path | 指定标杆侧比对路径,str类型。单图构建场景可以不配置 | 否 |
90
+ | is_print_compare_log | 配置是否开启单个算子的日志打屏。可取值 true 或 false,默认为 true。关闭后则只输出常规日志,bool 类型。 | 否 |
91
+
92
+
93
+ ### 3.2 图构建和比对
94
+
95
+ **如果只是想查看一个模型的结构,请选择单图构建**;
96
+ **如果想比较两个模型的结构差异和精度数据差异,请选择双图比对**。
97
+
98
+ #### 3.2.1 单图构建
99
+
100
+ 展示模型结构、精度数据、堆栈信息。
101
+
102
+ **1. 准备比对文件**:
103
+
104
+ 以在当前目录创建 ./compare.json 为例。
105
+ ```
106
+ {
107
+ "npu_path": "./npu_dump",
108
+ "is_print_compare_log": true
109
+ }
110
+ ```
111
+ npu_path格式:必须包含dump.json、stack.json和construct.json,且construct.json不能为空。如果construct.json为空,请检查dump的level参数是否没有选择L0或者mix。
112
+ ```
113
+ ├── npu_path
114
+ │ ├── dump_tensor_data(配置dump的task参数选择tensor时存在)
115
+ | | ├── MintFunctional.relu.0.backward.input.0.npy
116
+ | | ├── Mint.abs.0.forward.input.0.npy
117
+ | | ...
118
+ | | └── Cell.relu.ReLU.forward.0.input.0.npy
119
+ | ├── dump.json # 数据信息
120
+ | ├── stack.json # 调用栈信息
121
+ | └── construct.json # 分层分级结构,level为L1时,construct.json内容为空
122
+ ```
123
+ **2. 执行命令**:
124
+ ```
125
+ msprobe -f mindspore graph -i ./compare.json -o ./output
126
+ ```
127
+ #### 3.2.2 双图比对
128
+
129
+ 展示模型结构、结构差异、精度数据和精度比对指标、精度是否疑似有问题(精度比对指标差异越大颜色越深)。
130
+
131
+ 当前比对支持三种类型的dump数据,分级可视化工具比对时会自动判断:
132
+
133
+ 1.统计信息:仅dump了API和Module的输入输出数据统计信息,占用磁盘空间小;
134
+
135
+ 2.真实数据:不仅dump了API和Module的输入输出数据统计信息,还将tensor进行存盘,占用磁盘空间大,但比对更加准确;
136
+
137
+ 3.md5:dump了API和Module的输入输出数据统计信息和md5信息。
138
+
139
+ dump类型如何配置见[数据采集配置文件介绍](https://gitee.com/ascend/mstt/blob/master/debug/accuracy_tools/msprobe/docs/02.config_introduction.md)
140
+
141
+ **1. 准备比对文件**:
142
+
143
+ 以在当前目录创建 ./compare.json 为例。
144
+ ```
145
+ {
146
+ "npu_path": "./npu_dump",
147
+ "bench_path": "./bench_dump",
148
+ "is_print_compare_log": true
149
+ }
150
+ ```
151
+ npu_path或bench_path格式:必须包含dump.json、stack.json和construct.json,且construct.json不能为空。如果construct.json为空,请检查dump的level参数是否没有选择L0或者mix。
152
+ ```
153
+ ├── npu_path或bench_path
154
+ │ ├── dump_tensor_data(配置dump的task参数选择tensor时存在)
155
+ | | ├── MintFunctional.relu.0.backward.input.0.npy
156
+ | | ├── Mint.abs.0.forward.input.0.npy
157
+ | | ...
158
+ | | └── Cell.relu.ReLU.forward.0.input.0.npy
159
+ | ├── dump.json # 数据信息
160
+ | ├── stack.json # 调用栈信息
161
+ | └── construct.json # 分层分级结构,level为L1时,construct.json内容为空
162
+ ```
163
+ **2. 执行命令**:
164
+ ```
165
+ msprobe -f mindspore graph -i ./compare.json -o ./output
166
+ ```
167
+
168
+ 比对完成后将在**output**下生成一个**vis后缀文件**。
169
+
170
+ #### 3.2.3 批量构建或比对
171
+ ##### 3.2.3.1 多rank批量构建或比对
172
+ 批量构建或比对一个step下的所有rank的数据
173
+
174
+ **1. 准备比对文件**:
175
+
176
+ 以在当前目录创建 ./compare.json 为例。
177
+ ```
178
+ {
179
+ "npu_path": "./npu_dump",
180
+ "bench_path": "./bench_dump", # 只进行图构建可不配置
181
+ "is_print_compare_log": true
182
+ }
183
+ ```
184
+ npu_path或bench_path格式:必须只包含rank+数字格式的文件夹,且每个rank文件夹中必须包含dump.json、stack.json和construct.json,且construct.json不能为空。如果construct.json为空,请检查dump的level参数是否没有选择L0或者mix。
185
+
186
+ 进行批量图比对时,npu_path和bench_path中包含的rank+数字格式的文件夹必须数量一致且能够一一对应。
187
+ ```
188
+ ├── npu_path或bench_path
189
+ | ├── rank0
190
+ | │ ├── dump_tensor_data(仅配置dump的task参数选择tensor时存在)
191
+ | | | ├── MintFunctional.relu.0.backward.input.0.npy
192
+ | | | ├── Mint.abs.0.forward.input.0.npy
193
+ | | | ...
194
+ | | | └── Cell.relu.ReLU.forward.0.input.0.npy
195
+ | | ├── dump.json # 数据信息
196
+ | | ├── stack.json # 算子调用栈信息
197
+ | | └── construct.json # 分层分级结构,level为L1时,construct.json内容为空
198
+ | ├── rank1
199
+ | | ├── dump_tensor_data
200
+ | | | └── ...
201
+ | | ├── dump.json
202
+ | | ├── stack.json
203
+ | | └── construct.json
204
+ | ├── ...
205
+ | |
206
+ | └── rankn
207
+ ```
208
+ **2. 执行命令**:
209
+ ```
210
+ msprobe -f mindspore graph -i ./compare.json -o ./output
211
+ ```
212
+ 比对完成后将在**output**下生成n个**vis后缀文件**。
213
+
214
+ 图构建:
215
+ ```
216
+ ├── build_rank0_{timestamp}.vis
217
+ ├── build_rank1_{timestamp}.vis
218
+ ├── build_rank2_{timestamp}.vis
219
+ ├── build_rank3_{timestamp}.vis
220
+ ├── ...
221
+ ├── build_rankn_{timestamp}.vis
222
+ ```
223
+ 图比对:
224
+ ```
225
+ ├── compare_rank0_{timestamp}.vis
226
+ ├── compare_rank1_{timestamp}.vis
227
+ ├── compare_rank2_{timestamp}.vis
228
+ ├── compare_rank3_{timestamp}.vis
229
+ ├── ...
230
+ ├── compare_rankn_{timestamp}.vis
231
+ ```
232
+ ##### 3.2.3.2 多step批量构建或比对
233
+ 批量构建或比对多个step下的所有rank的数据
234
+
235
+ **1. 准备比对文件**:
236
+
237
+ 以在当前目录创建 ./compare.json 为例。
238
+ ```
239
+ {
240
+ "npu_path": "./npu_dump",
241
+ "bench_path": "./bench_dump", # 只进行图构建可不配置
242
+ "is_print_compare_log": true
243
+ }
244
+ ```
245
+ npu_path或bench_path格式:必须只包含step+数字格式的文件夹,且每个step文件夹中必须只包含rank+数字格式的文件夹,每个rank文件夹中必须包含dump.json、stack.json和construct.json,且construct.json不能为空。如果construct.json为空,请检查dump的level参数是否没有选择L0或者mix。
246
+
247
+ 进行批量图比对时,npu_path和bench_path中包含的step+数字格式的文件夹必须数量一致且能够一一对应,每个step文件夹中包含的rank+数字格式的文件夹必须数量一致且能够一一对应。
248
+ ```
249
+ ├── npu_path或bench_path
250
+ │ ├── step0
251
+ │ | ├── rank0
252
+ │ | │ ├── dump_tensor_data(仅配置dump的task参数选择tensor时存在)
253
+ | | | | ├── MintFunctional.relu.0.backward.input.0.npy
254
+ | | | | ├── Mint.abs.0.forward.input.0.npy
255
+ | | | | ...
256
+ | | | | └── Cell.relu.ReLU.forward.0.input.0.npy
257
+ │ | | ├── dump.json # 数据信息
258
+ │ | | ├── stack.json # 调用栈信息
259
+ │ | | └── construct.json # 分层分级结构,level为L1时,construct.json内容为空
260
+ │ | ├── rank1
261
+ | | | ├── dump_tensor_data
262
+ | | | | └── ...
263
+ │ | | ├── dump.json
264
+ │ | | ├── stack.json
265
+ | | | └── construct.json
266
+ │ | ├── ...
267
+ │ | |
268
+ | | └── rankn
269
+ │ ├── step1
270
+ │ | ├── ...
271
+ │ ├── step2
272
+ ```
273
+ **2. 执行命令**:
274
+ ```
275
+ msprobe -f mindspore graph -i ./compare.json -o ./output
276
+ ```
277
+ 比对完成后将在**output**下生成若干个**vis后缀文件**。
278
+
279
+ 图构建:
280
+ ```
281
+ ├── build_step0_rank0_{timestamp}.vis
282
+ ├── build_step0_rank1_{timestamp}.vis
283
+ ├── build_step0_rank2_{timestamp}.vis
284
+ ├── build_step0_rank3_{timestamp}.vis
285
+ ├── build_step1_rank0_{timestamp}.vis
286
+ ├── build_step1_rank1_{timestamp}.vis
287
+ ├── build_step1_rank2_{timestamp}.vis
288
+ ├── build_step1_rank3_{timestamp}.vis
289
+ ├── ...
290
+ ├── build_stepn_rankn_{timestamp}.vis
291
+ ```
292
+ 图比对:
293
+ ```
294
+ ├── compare_step0_rank0_{timestamp}.vis
295
+ ├── compare_step0_rank1_{timestamp}.vis
296
+ ├── compare_step0_rank2_{timestamp}.vis
297
+ ├── compare_step0_rank3_{timestamp}.vis
298
+ ├── compare_step1_rank0_{timestamp}.vis
299
+ ├── compare_step1_rank1_{timestamp}.vis
300
+ ├── compare_step1_rank2_{timestamp}.vis
301
+ ├── compare_step1_rank3_{timestamp}.vis
302
+ ├── ...
303
+ ├── compare_stepn_rankn_{timestamp}.vis
304
+ ```
305
+
306
+ ## 4.启动tensorboard
307
+
308
+ ### 4.1 可直连的服务器
309
+
310
+ 将生成vis文件的路径**out_path**传入--logdir
311
+
312
+ ```
313
+ tensorboard --logdir out_path --bind_all --port [可选,端口号]
314
+ ```
315
+ 启动后会打印日志:
316
+
317
+ ![tensorboard_1](./img/visualization/tensorboard_1.png)
318
+
319
+ ubuntu是机器地址,6008是端口号。
320
+
321
+ **注意,ubuntu需要替换为真实的服务器地址,例如真实的服务器地址为10.123.456.78,则需要在浏览器窗口输入http://10.123.456.78:6008**
322
+
323
+ ### 4.2 不可直连的服务器
324
+ **如果链接打不开(服务器无法直连需要挂vpn才能连接等场景),可以尝试使用vscode连接服务器,在vscode终端输入:**
325
+
326
+ ```
327
+ tensorboard --logdir out_path
328
+ ```
329
+ ![tensorboard_2](./img/visualization/tensorboard_2.png)
330
+
331
+ 按住CTRL点击链接即可
332
+
333
+ ## 5.浏览器查看
334
+
335
+ ### 5.1 浏览器打开图
336
+ 推荐使用谷歌浏览器,在浏览器中输入机器地址+端口号回车,出现TensorBoard页面,其中/#graph_ascend会自动拼接。
337
+ ![vis_browser_1](./img/visualization/vis_browser_1.png)
338
+ 如果您切换了TensorBoard的其他功能,此时想回到模型分级可视化页面,可以点击左上方的**GRAPH_ASCEND**
339
+ ![vis_browser_2](./img/visualization/vis_browser_2.png)
340
+
341
+ ### 5.2 查看图
342
+ ![vis_show_info.png](./img/visualization/vis_show_info.png)
343
+
344
+ ### 5.3 名称搜索
345
+ ![vis_search_info.png](./img/visualization/vis_search_info.png)
346
+
347
+ ### 5.4 精度筛选
348
+ ![vis_precision_info.png](./img/visualization/vis_precision_info.png)
349
+
350
+ ### 5.5 未匹配节点筛选
351
+ 节点匹配规则:
352
+
353
+ 1.名称一致
354
+
355
+ 2.节点输入输出参数数量一致,参数type、shape一致
356
+
357
+ 3.节点的层级一致(父节点们一致)
358
+
359
+ ![vis_unmatch_info.png](./img/visualization/vis_unmatch_info.png)
360
+
361
+ ## 6.图比对说明
362
+
363
+ ### 颜色
364
+
365
+ 颜色越深,精度比对差异越大,越可疑,具体信息可见浏览器页面左下角颜色图例。
366
+
367
+ ### 疑似有精度问题判定
368
+
369
+ #### 真实数据模式
370
+ 节点中所有输入的最小双千指标和所有输出的最小双千分之一指标的差值,反映了双千指标的下降情况,**值越大精度差距越大,颜色标记越深**。
371
+
372
+ ``One Thousandth Err Ratio(双千分之一)精度指标:Tensor中的元素逐个与对应的标杆数据对比,相对误差小于千分之一的比例占总元素个数的比例,比例越接近1越好``
373
+
374
+ #### 统计信息模式
375
+ 节点中输出的统计量相对误差,**值越大精度差距越大,颜色标记越深**。
376
+
377
+ ``相对误差:abs((npu统计值 - bench统计值) / bench统计值)``
378
+
379
+ #### md5模式
380
+ 节点中任意输入输出的md5值不同。
381
+
382
+ ## 7.附录
383
+ ### 7.1 自定义映射文件(Layer)
384
+
385
+ 文件名格式:\*.yaml,*为文件名,可自定义。
386
+
387
+ 文件内容示例:
388
+
389
+ ```yaml
390
+ ParallelAttention: # Layer层名称
391
+ qkv_proj: query_key_value # 冒号左侧为MindSpore框架模型代码中嵌套的Layer层名称,冒号右侧为PyTorch框架模型代码中嵌套的Layer层名称
392
+ out_proj: dense
393
+
394
+ ParallelTransformerLayer:
395
+ attention: self_attention
396
+
397
+ Embedding:
398
+ dropout: embedding_dropout
399
+
400
+ ParallelMLP:
401
+ mapping: dense_h_to_4h
402
+ projection: dense_4h_to_h
403
+
404
+ PipelineCell:
405
+ model: module
406
+
407
+ Cell:
408
+ network_with_loss: module
409
+ ```
410
+
411
+ Layer层名称需要从模型代码中获取。
412
+
413
+ yaml文件中只需配置MindSpore与PyTorch模型代码中功能一致但名称不同的Layer层,名称相同的Layer层会被自动识别并映射。
414
+
415
+ 模型代码示例:
416
+
417
+ ![ms_dump](./img/ms_layer.png)
418
+
419
+ ### 7.2 堆栈信息说明
420
+
421
+ **精简堆栈**
422
+
423
+ 保留一条当前模块或api的调用信息
424
+
425
+ ```json
426
+ {
427
+ "Cell.model.language_model.embedding.word_embeddings.reduce_scatter_to_sp_region.ReduceScatterToSequenceParallelRegion.forward.0": [
428
+ "File /home/mindformers/experimental/distri_cores/tensor_parallel/layers.py, line 770, in construct, \n output = self.reduce_scatter_to_sp_region(output_parallel)"
429
+ ]
430
+ }
431
+ ```
432
+
433
+ **完整堆栈**
434
+
435
+ 当前模块或api完整的调用信息
436
+
437
+ ```json
438
+ {
439
+ "Cell.model.language_model.embedding.word_embeddings.reduce_scatter_to_sp_region.ReduceScatterToSequenceParallelRegion.forward.0": [
440
+ "File /home/mindspore/nn/cell.py, line 507, in _run_construct, \n output = self._run_forward_hook(inputs, output)",
441
+ "File /home/mindspore/nn/cell.py, line 759, in _complex_call, \n output = self._run_construct(*args, **kwargs)",
442
+ "File /home/mindspore/nn/cell.py, line 747, in __call__, \n return self._complex_call(*args, **kwargs)",
443
+ "File /home/mindformers/experimental/distri_cores/tensor_parallel/layers.py, line 770, in construct, \n output = self.reduce_scatter_to_sp_region(output_parallel)",
444
+ "File /home/mindspore/nn/cell.py, line 2462, in _backward_hook_construct, \n outputs = self.construct(outputs, **kwargs)",
445
+ "File /home/mindspore/nn/cell.py, line 498, in _run_construct, \n output = self._backward_hook_construct(*inputs, **kwargs)",
446
+ "File /home/mindspore/nn/cell.py, line 745, in __call__, \n return self._run_construct(*args, **kwargs)",
447
+ "File /home/mindformers/experimental/distri_cores/transformer/language_model.py, line 151, in construct, \n embeddings = self.word_embeddings(input_ids)",
448
+ "File /home/mindspore/nn/cell.py, line 2460, in _backward_hook_construct, \n outputs = self.construct(*outputs, **kwargs)",
449
+ "File /home/mindspore/nn/cell.py, line 498, in _run_construct, \n output = self._backward_hook_construct(*inputs, **kwargs)",
450
+ "File /home/mindspore/nn/cell.py, line 745, in __call__, \n return self._run_construct(*args, **kwargs)",
451
+ "File /home/mindformers/experimental/distri_cores/transformer/language_model.py, line 391, in construct, \n text_embedding_out = self.embedding(enc_input_ids, enc_position_ids,",
452
+ "File /home/mindspore/nn/cell.py, line 2460, in _backward_hook_construct, \n outputs = self.construct(*outputs, **kwargs)",
453
+ "File /home/mindspore/nn/cell.py, line 498, in _run_construct, \n output = self._backward_hook_construct(*inputs, **kwargs)",
454
+ "File /home/mindspore/nn/cell.py, line 745, in __call__, \n return self._run_construct(*args, **kwargs)",
455
+ "File /home/model/gpt_model.py, line 104, in construct, \n lm_output = self.language_model(tokens,",
456
+ "File /home/mindspore/nn/cell.py, line 2460, in _backward_hook_construct, \n outputs = self.construct(*outputs, **kwargs)",
457
+ "File /home/mindspore/nn/cell.py, line 498, in _run_construct, \n output = self._backward_hook_construct(*inputs, **kwargs)",
458
+ "File /home/mindspore/nn/cell.py, line 745, in __call__, \n return self._run_construct(*args, **kwargs)",
459
+ "File /home/mindformers/experimental/distri_cores/pipeline_parallel/pipeline_cell.py, line 429, in construct, \n return self.model(*inputs)",
460
+ "File /home/mindspore/nn/cell.py, line 757, in _complex_call, \n output = self.construct(*args, **kwargs)",
461
+ "File /home/mindspore/nn/cell.py, line 747, in __call__, \n return self._complex_call(*args, **kwargs)",
462
+ "File /home/mindformers/experimental/distri_cores/pipeline_parallel/schedules.py, line 121, in run_forward, \n output_tensor = model(*input_data, recv_data=None)",
463
+ "File /home/mindformers/experimental/distri_cores/pipeline_parallel/schedules.py, line 735, in forward_backward_pipelining_without_interleaving, \n micro_input_data = run_forward(*micro_input_data,",
464
+ "File /home/mindformers/experimental/distri_cores/training.py, line 409, in forward_backward_with_pipelining, \n loss, logits, grads = forward_backward_pipelining_without_interleaving(",
465
+ "File /home/mindformers/experimental/distri_cores/training.py, line 533, in construct, \n (loss, _), grads = self.forward_backward_func(*inputs_tuple, loss_scale=current_step_loss_scale, **inputs_dict)",
466
+ "File /home/mindspore/nn/cell.py, line 757, in _complex_call, \n output = self.construct(*args, **kwargs)",
467
+ "File /home/mindspore/nn/cell.py, line 747, in __call__, \n return self._complex_call(*args, **kwargs)",
468
+ "File /home/mindformers/experimental/distri_cores/training.py, line 655, in train, \n loss, is_finite, loss_scale, learning_rate = train_one_step_cell(**data)",
469
+ "File /home/model/pretrain_gpt.py, line 303, in main, \n train(",
470
+ "File /home/model/pretrain_gpt.py, line 316, in <module>, \n main()"
471
+ ]
472
+ }
473
+ ```
474
+ # FAQ
475
+ 1. 图比对场景,节点呈现灰色,且没有精度比对数据,怎么处理?
476
+
477
+ 节点呈现灰色,代表左边待调试侧节点与右边标杆侧节点没有匹配上,可能有以下几点原因:
478
+
479
+ - **标杆侧确实没有能与待调试侧匹配上的节点**,属于代码实现上的差异,请确认此差异是否正常,是否会影响到整网精度。
480
+ - **节点的输入或输出type、shape不一致,参数个数不一致,节点所在层级的父层级不一致**,导致节点无法匹配,具体匹配规则见[匹配说明](#311-匹配说明),可尝试使用模糊匹配功能,如何使用此功能请参考[构图命令行说明](#31-构图命令行说明)。如果是参数shape不一致,即使是模糊匹配功能也无法让节点匹配上,请检查参数shape不一致是否合理。
481
+ - **节点名称不一致**,导致节点无法匹配,可使用layer mapping功能,如何使用此功能请参考[构图命令行说明](#31-构图命令行说明),如何自定义映射文件请参考[模型分级可视化如何配置layer mapping映射文件](./visualization/layer_mapping_example.md)。
@@ -0,0 +1,107 @@
1
+ # 单算子API自动生成脚本
2
+
3
+ ## 1 简介
4
+
5
+ 单算子API自动生成脚本通过提取dump数据中的可疑算子,对其进行单API复现,输出单API精度的比对结果。具体而言,该工具可以从dump数据中提取可疑API的前反向信息,根据前反向数据生成单API的前反向过程,最后通过**新精度标准比对法**<sup>a</sup>将 NPU/GPU 和 CPU 的结果进行比对,从而给出不同比对方法下的比对结果。本工具支持**随机生成模式和真实数据模式**<sup>b</sup>。
6
+
7
+ a. 依据新精度标准,对不同的API采取不同的比对算法(包括绝对阈值法、标杆比对法、二进制一致法、ULP误差比对法和双千指标法),最终给定比对结果;
8
+
9
+ b. 在生成单API脚本时可以选择由工具构造随机数获得 dump 数据或选择真实输入的数据进行单API复现。随机生成模式(对应 task: "statistics")执行效率高,可以快速获得结果,但数据精度低,只能大致判断精度问题;真实数据模式(对应 task: "tensor")执行效率略低于随机生成模式,但是数据精度高,可以准确判断精度问题。
10
+
11
+ ## 2 使用方式
12
+
13
+ ### 前提
14
+ 1. 安装 msprobe。详见[ msprobe 安装](./01.installation.md)章节。
15
+ 2. 已完成对训练过程的dump,获得dump.json文件。
16
+ [PyTorch场景的数据采集](https://gitee.com/ascend/mstt/blob/master/debug/accuracy_tools/msprobe/docs/05.data_dump_PyTorch.md)
17
+
18
+ **目前仅支持复现API级的数据,故dump时level可选择L0(API信息)或者mix(module信息+API信息)。如需复现真实数据场景的API脚本,dump时task应选择tensor,如需复现随机数据场景的API脚本,dump时task选择statistics**。
19
+ 3. 发现某个算子疑似存在精度问题,并得知算子名,如Functional.softmax.3、Tensor.add.0、Torch.matmul.5等
20
+
21
+ ### 2.1 配置config_op.json
22
+ 单API复现参数配置如下(以复现softmax算子为例):
23
+ ```
24
+ {
25
+ "dump_json_path": "./dump.json",
26
+ "api_name": "Functional.softmax.0",
27
+ "extract_api_path": "./Functional.softmax.0.json",
28
+ "propagation": "forward",
29
+ "data_mode": "random_data",
30
+ "random_seed": 1234,
31
+ "iter_times": 1
32
+ }
33
+ ```
34
+ **配置文件参数说明**
35
+
36
+ | 参数名称 | 解释 | 是否必选 |
37
+ | ---------------------------- | ------------------------------------------------------------ | ---------------------------------- |
38
+ | dump_json_path | dump.json的文件路径,包含所有dump算子的信息;如果已经提取了可疑算子并保存可以不指定。 | 否 |
39
+ | api_name | 算子名,如Functional.softmax.3、Tensor.add.0、Torch.matmul.5等。如果已经提取了可疑算子并保存可以不指定 | 否 |
40
+ | extract_api_path | 提取可疑算子的json文件路径 | 是 |
41
+ | propagation | 选择复现算子的forward还是backward,默认为forward | 否 |
42
+ | data_mode | 选择复现算子的随机数据(random_data)还是真实数据(real_data)模式,默认为random_data | 否 |
43
+ | random_seed | 仅random_data模式有效,表示手动设定的随机种子,默认为1234 | 否 |
44
+ | iter_times | 仅random_data模式有效,表示单API运行的次数 | 否 |
45
+
46
+ ### 2.2 运行命令生成单API脚本
47
+ config_op.json配置好后,运行如下命令:
48
+ ```
49
+ msprobe -f pytorch op_generate -i ./config.json -o ./
50
+ ```
51
+ 或者
52
+
53
+ 进入到mstt的generate_op_script文件夹
54
+ ```
55
+ cd mstt/debug/accuracy_tools/msprobe/pytorch/api_accuracy_checker/generate_op_script
56
+ ```
57
+ 运行
58
+ ```
59
+ python op_generator.py -i ./config_op.json -o ./
60
+ ```
61
+ **参数说明**
62
+ | 参数名称 | 解释 | 是否必选 |
63
+ | ---------------------------- | ------------------------------------------------------------ | ---------------------------------- |
64
+ | -i 或 --config_input | config_op.json的路径 | 是 |
65
+ | -o 或 --api_output_path | 单API脚本的输出路径 | 是 |
66
+
67
+ ### 2.3 运行单API脚本
68
+ 运行完op_generator.py后,会在指定路径下生成api_name.py的单API脚本,例如Functional.softmax.3.backward.py、Tensor.add.0.forward.py、Torch.matmul.5.backward.py
69
+
70
+ 运行单API脚本即可获得不同比对方法下的比对结果
71
+ ```
72
+ python api_name.py
73
+ ```
74
+
75
+ **运行结果参数说明**
76
+ | 字段 | 含义 |
77
+ | ------------------- | ------------------------------------------------------------ |
78
+ | Shape | 单API输出结果的shape |
79
+ | Dtype of out_device | NPU 或 GPU 数据的 API 数据类型。 |
80
+ | Dtype of out_bench | 标杆数据的 API 数据类型。 |
81
+ | Compare Standard | 比对方法(包括绝对阈值法,标杆比对法、二进制一致法、ULP误差比对法和双千指标法 |
82
+ | Relative Error Ratio | 相对误差错误率。NPU 与标杆的正常值计算相对误差,其大于错误阈值的元素个数占正常值元素个数的比例。绝对阈值法指标。 |
83
+ | 相对误差判定结果 | 相对误差错误率判定结果,等于 0 标记为 pass,其余情况标记为 error。 |
84
+ | Absolute Error Ratio | 绝对误差错误率。NPU 与标杆的小值计算绝对误差,其大于错误阈值的元素个数占小值元素个数的比例。绝对阈值法指标。NPU 或 GPU 数据与标杆数据的最大绝对误差。 |
85
+ | 绝对误差判定结果 | 绝对误差错误率判定结果,等于 0 标记为 pass,其余情况标记为 error。 |
86
+ | Small Value Error Proportion | 小值域错误比值。NPU 与 CPU 的小值域的错误比率 / GPU 与 CPU 的小值域的错误比率。标杆比对法指标。 |
87
+ | 小值域错误判定结果 | 小值域错误比值小于等于 1 标记为 pass,1 ~ 2 之间标记为 warning,大于 2 标记为 error。 |
88
+ | Maximum Relative Error | 相对误差最大值比值。NPU 与 CPU 的相对误差最大值 / GPU 与 CPU 的相对误差最大值。标杆比对法指标。 |
89
+ | 相对误差最大值判定结果 | 相对误差最大值比值小于等于 1 标记为 pass,1 ~ 10 之间标记为 warning,大于 10 标记为 error。 |
90
+ | Mean Relative Error | 相对误差平均值比值。NPU 与 CPU 的相对误差的平均值 / GPU 与 CPU 的相对误差的平均值。标杆比对法指标。 |
91
+ | 相对误差平均值判定结果 | 相对误差平均值比值小于等于 1 标记为 pass,1 ~ 2 之间标记为 warning,大于 2 标记为 error。 |
92
+ | Root Mean Squared Error | 均方根误差比值。NPU 与 CPU 的均方根误差 / GPU 与 CPU 的均方根误差。标杆比对法指标。 |
93
+ | 均方根误差判定结果 | 均方根误差比值小于等于 1 标记为 pass,1~2 之间标记为 warning,大于 2 标记为 error。 |
94
+ | Error Balance | 误差均衡性比值。NPU 与 CPU 的误差均衡性 / GPU 与 CPU 的误差均衡性。标杆比对法指标。 |
95
+ | 误差均衡性判定结果 | 误差均衡性比值小于等于 1 标记为 pass,1 ~ 2 之间标记为 warning,大于 2 标记为 error。 |
96
+ | Error Rate | 二进制一致错误率。NPU 或 GPU 数据中每个 Tensor 精度不一致的数值的数量与 Tensor 中数值数量的比值。只有数据是 builtin 类型(bool、int、float、str)、torch.bool 和 torch 的 int 类型或者在新精度标准中使用二进制一致算法进行比对的 API 才会展示。二进制一致法指标。 |
97
+ | 二进制一致错误率判定结果 | 二进制一致错误率判定结果,等于 0 标记为 pass,其余情况标记为 error。 |
98
+ | Maximum ULP Error | ULP 误差最大值<sup>a</sup>。NPU 数据与标杆数据 ULP 误差的最大值(取绝对值后)。 |
99
+ | Mean ULP Error | ULP 误差平均值<sup>a</sup>。NPU 数据与标杆数据 ULP 误差的平均值(取绝对值后)。 |
100
+ | ULP Error Proportion |ULP 误差大于阈值占比比值<sup>a</sup>。NPU 与 CPU 的 ULP 误差大于阈值占比 / GPU 与 CPU 的 ULP 误差大于阈值占比。 |
101
+ | 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 误差大于阈值占比。 |
102
+ | Thousandth ratio |双千精度指标。是指 NPU 的 Tensor 中的元素逐个与对应的标杆数据对比,相对误差小于千分之一的个数占总元素个数的比例。测试通过标准为相对误差大于千分之一的个数占总元素个数的比例小于千分之一。仅 conv1d 和 conv2d 使用该指标。双千指标法指标。 |
103
+ | 双千指标判定结果 | 双千指标判定结果。双千指标大于 0.999 标记为 pass,否则标记为 error。 |
104
+
105
+ a:误差比对法指标。
106
+
107
+ 最终判定单API是否符合精度标准由开发者通过**算子精度标准**判断。
@@ -0,0 +1,28 @@
1
+ # MindSpore 场景的数码关联工具
2
+
3
+ 数码关联工具,用于 MindSpore 静态图场景下将IR图与dump数据进行关联,获取 dump 数据和代码调用栈的关联关系。
4
+
5
+ ## 安装
6
+
7
+ 请参见[《msprobe 工具安装指南》](./01.installation.md)。
8
+
9
+
10
+ ## 功能说明
11
+
12
+ 数码关联是指数据和代码调用栈的关联,数据一般意义上指静态图`O0`,`O1`,`O2`下dump下来的数据。
13
+
14
+ IR图使用推荐:IR图推荐使用`anf_after_graph_build`图。
15
+
16
+ 命令格式:
17
+
18
+ ```
19
+ msprobe -f mindspore code_mapping --ir <ir_file> --dump_data <dump_data> [--output <output_path>]
20
+ ```
21
+
22
+
23
+ | 参数名称 | 说明 |参数类型 | 是否必选 |
24
+ | ---------------------------- |-------------------------------------------------------------------------------------------------------------------------------------------|---------------------- | ---------------------------------- |
25
+ | --ir | 指定 MindSpore 静态图运行时生成的IR图文件。 | str | 是 |
26
+ | --dump_data | 指定dump数据文件(支持tensor或statistic模式的dump数据)。可指定单个dump数据 文件或dump数据文件的父目录,指定父目录表示关联目录下的所有dump数据文件。 | str | 是 |
27
+ | --output | 关联结果输出目录,默认为"./",只在tensor模式时生效,会把数据文件路径和代码调用栈的关联关系存到output路径下的code_mapping_{时间戳}.csv中。如果关联的是statistic模式,则会把statistic.csv中每个条目加上该条目对应的代码栈。 | str | 否 |
28
+