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,255 @@
1
+ # From PyTorch:
2
+
3
+ # Copyright (c) 2025 Huawei Technologies Co., Ltd
4
+ # Copyright (c) 2016- Facebook, Inc (Adam Paszke)
5
+ # Copyright (c) 2014- Facebook, Inc (Soumith Chintala)
6
+ # Copyright (c) 2011-2014 Idiap Research Institute (Ronan Collobert)
7
+ # Copyright (c) 2012-2014 Deepmind Technologies (Koray Kavukcuoglu)
8
+ # Copyright (c) 2011-2012 NEC Laboratories America (Koray Kavukcuoglu)
9
+ # Copyright (c) 2011-2013 NYU (Clement Farabet)
10
+ # Copyright (c) 2006-2010 NEC Laboratories America (Ronan Collobert, Leon Bottou, Iain Melvin, Jason Weston)
11
+ # Copyright (c) 2006 Idiap Research Institute (Samy Bengio)
12
+ # Copyright (c) 2001-2004 Idiap Research Institute (Ronan Collobert, Samy Bengio, Johnny Mariethoz)
13
+
14
+ # From Caffe2:
15
+
16
+ # Copyright (c) 2016-present, Facebook Inc. All rights reserved.
17
+
18
+ # All contributions by Facebook:
19
+ # Copyright (c) 2016 Facebook Inc.
20
+
21
+ # All contributions by Google:
22
+ # Copyright (c) 2015 Google Inc.
23
+ # All rights reserved.
24
+
25
+ # All contributions by Yangqing Jia:
26
+ # Copyright (c) 2015 Yangqing Jia
27
+ # All rights reserved.
28
+
29
+ # All contributions by Kakao Brain:
30
+ # Copyright 2019-2020 Kakao Brain
31
+
32
+ # All contributions by Cruise LLC:
33
+ # Copyright (c) 2022 Cruise LLC.
34
+ # All rights reserved.
35
+
36
+ # All contributions by Tri Dao:
37
+ # Copyright (c) 2024 Tri Dao.
38
+ # All rights reserved.
39
+
40
+ # All contributions by Arm:
41
+ # Copyright (c) 2021, 2023-2024 Arm Limited and/or its affiliates
42
+
43
+ # All contributions from Caffe:
44
+ # Copyright(c) 2013, 2014, 2015, the respective contributors
45
+ # All rights reserved.
46
+
47
+ # All other contributions:
48
+ # Copyright(c) 2015, 2016 the respective contributors
49
+ # All rights reserved.
50
+
51
+ # Caffe2 uses a copyright model similar to Caffe: each contributor holds
52
+ # copyright over their contributions to Caffe2. The project versioning records
53
+ # all such contribution and copyright details. If a contributor wants to further
54
+ # mark their specific copyright on a particular contribution, they should
55
+ # indicate their copyright solely in the commit message of the change when it is
56
+ # committed.
57
+
58
+ # All rights reserved.
59
+
60
+ # Redistribution and use in source and binary forms, with or without
61
+ # modification, are permitted provided that the following conditions are met:
62
+
63
+ # 1. Redistributions of source code must retain the above copyright
64
+ # notice, this list of conditions and the following disclaimer.
65
+
66
+ # 2. Redistributions in binary form must reproduce the above copyright
67
+ # notice, this list of conditions and the following disclaimer in the
68
+ # documentation and/or other materials provided with the distribution.
69
+
70
+ # 3. Neither the names of Facebook, Deepmind Technologies, NYU, NEC Laboratories
71
+ # America, IDIAP Research Institute and Huawei nor the names of its contributors
72
+ # may be used to endorse or promote products derived from this software without
73
+ # specific prior written permission.
74
+
75
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
76
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
77
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
78
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
79
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
80
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
81
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
82
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
83
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
84
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
85
+ # POSSIBILITY OF SUCH DAMAGE.
86
+
87
+ import warnings
88
+
89
+ import mindspore as ms
90
+ from mindspore.ops.operations import _inner_ops as inner
91
+ from torch.nn.modules.module import (_global_backward_pre_hooks, _global_backward_hooks,
92
+ _global_is_full_backward_hook, _global_forward_pre_hooks,
93
+ _global_forward_hooks, _global_forward_hooks_always_called)
94
+ from torch.utils.hooks import RemovableHandle
95
+
96
+
97
+ def _call_impl(self, *args, **kwargs):
98
+ forward_call = self.forward
99
+ if self.__ms_class__:
100
+ return forward_call(*args, **kwargs)
101
+
102
+ # If we don't have any hooks, we want to skip the rest of the logic in
103
+ # this function, and just call forward.
104
+ if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
105
+ or _global_backward_pre_hooks or _global_backward_hooks
106
+ or _global_forward_hooks or _global_forward_pre_hooks):
107
+ return forward_call(*args, **kwargs)
108
+
109
+ try:
110
+ result = None
111
+ called_always_called_hooks = set()
112
+
113
+ if self._backward_pre_hooks or _global_backward_pre_hooks:
114
+ _get_backward_pre_hooks(self)
115
+
116
+ if self._backward_hooks or _global_backward_hooks:
117
+ _get_backward_hooks(self)
118
+
119
+ if _global_forward_pre_hooks or self._forward_pre_hooks:
120
+ for hook_id, hook in (
121
+ *_global_forward_pre_hooks.items(),
122
+ *self._forward_pre_hooks.items(),
123
+ ):
124
+ if hook_id in self._forward_pre_hooks_with_kwargs:
125
+ args_kwargs_result = hook(self, args, kwargs) # type: ignore[misc]
126
+ if args_kwargs_result is not None:
127
+ if isinstance(args_kwargs_result, tuple) and len(args_kwargs_result) == 2:
128
+ args, kwargs = args_kwargs_result
129
+ else:
130
+ raise RuntimeError(
131
+ "forward pre-hook must return None or a tuple "
132
+ f"of (new_args, new_kwargs), but got {args_kwargs_result}."
133
+ )
134
+ else:
135
+ args_result = hook(self, args)
136
+ if args_result is not None:
137
+ if not isinstance(args_result, tuple):
138
+ args_result = (args_result,)
139
+ args = args_result
140
+
141
+ bw_hook = None
142
+ if self._backward_hooks:
143
+ bw_hook = inner.CellBackwardHook(self.__class__.__name__ + "(" + str(id(self)) + ")",
144
+ self, self._backward_hooks)
145
+ bw_hook.register_backward_hook()
146
+ args = apply_backward_hook_on_tensors(bw_hook, args)
147
+
148
+ result = forward_call(*args, **kwargs)
149
+ if _global_forward_hooks or self._forward_hooks:
150
+ for hook_id, hook in (
151
+ *_global_forward_hooks.items(),
152
+ *self._forward_hooks.items(),
153
+ ):
154
+ # mark that always called hook is run
155
+ if hook_id in self._forward_hooks_always_called or hook_id in _global_forward_hooks_always_called:
156
+ called_always_called_hooks.add(hook_id)
157
+
158
+ if hook_id in self._forward_hooks_with_kwargs:
159
+ hook_result = hook(self, args, kwargs, result)
160
+ else:
161
+ hook_result = hook(self, args, result)
162
+
163
+ if hook_result is not None:
164
+ result = hook_result
165
+
166
+ if bw_hook:
167
+ if not isinstance(result, (ms.Tensor, tuple)):
168
+ warnings.warn("For backward hooks to be called,"
169
+ " module output should be a Tensor or a tuple of Tensors"
170
+ f" but received {type(result)}")
171
+ result = apply_backward_hook_on_tensors(bw_hook, result)
172
+
173
+ if self._backward_pre_hooks:
174
+ bw_pre_hook = inner.CellBackwardHook(self.__class__.__name__ + "(" + str(id(self)) + ")",
175
+ self, self._backward_pre_hooks)
176
+ bw_pre_hook.register_backward_pre_hook()
177
+ result = apply_backward_hook_on_tensors(bw_pre_hook, result)
178
+
179
+ return result
180
+ except Exception:
181
+ # run always called hooks if they have not already been run
182
+ # For now only forward hooks have the always_call option but perhaps
183
+ # this functionality should be added to full backward hooks as well.
184
+ for hook_id, hook in _global_forward_hooks.items():
185
+ # type: ignore[possibly-undefined]
186
+ if hook_id in _global_forward_hooks_always_called and hook_id not in called_always_called_hooks:
187
+ try:
188
+ hook_result = hook(self, args, result) # type: ignore[possibly-undefined]
189
+ if hook_result is not None:
190
+ result = hook_result
191
+ except Exception as e:
192
+ warnings.warn("global module forward hook with ``always_call=True`` raised an exception "
193
+ f"that was silenced as another error was raised in forward: {str(e)}")
194
+ continue
195
+
196
+ for hook_id, hook in self._forward_hooks.items():
197
+ # type: ignore[possibly-undefined]
198
+ if hook_id in self._forward_hooks_always_called and hook_id not in called_always_called_hooks:
199
+ try:
200
+ if hook_id in self._forward_hooks_with_kwargs:
201
+ hook_result = hook(self, args, kwargs, result) # type: ignore[possibly-undefined]
202
+ else:
203
+ hook_result = hook(self, args, result) # type: ignore[possibly-undefined]
204
+ if hook_result is not None:
205
+ result = hook_result
206
+ except Exception as e:
207
+ warnings.warn("module forward hook with ``always_call=True`` raised an exception "
208
+ f"that was silenced as another error was raised in forward: {str(e)}")
209
+ continue
210
+ # raise exception raised in try block
211
+ raise
212
+
213
+
214
+ def register_full_backward_pre_hook(self, hook, prepend: bool = False) -> RemovableHandle:
215
+ handle = RemovableHandle(self._backward_pre_hooks)
216
+ self._backward_pre_hooks[handle.id] = hook
217
+ if prepend:
218
+ self._backward_pre_hooks.move_to_end(handle.id, last=False) # type: ignore[attr-defined]
219
+ return handle
220
+
221
+
222
+ def register_full_backward_hook(self, hook, prepend: bool = False) -> RemovableHandle:
223
+ if self._is_full_backward_hook is False:
224
+ raise RuntimeError(
225
+ "Cannot use both regular backward hooks and full backward hooks on a "
226
+ "single Module. Please use only one of them."
227
+ )
228
+
229
+ self._is_full_backward_hook = True
230
+
231
+ handle = RemovableHandle(self._backward_hooks)
232
+ self._backward_hooks[handle.id] = hook
233
+ if prepend:
234
+ self._backward_hooks.move_to_end(handle.id, last=False) # type: ignore[attr-defined]
235
+ return handle
236
+
237
+
238
+ def _get_backward_pre_hooks(self):
239
+ self._backward_pre_hooks.update(_global_backward_pre_hooks)
240
+
241
+
242
+ def _get_backward_hooks(self):
243
+ if (_global_is_full_backward_hook is True):
244
+ self._backward_hooks.update(_global_backward_hooks)
245
+
246
+
247
+ def apply_backward_hook_on_tensors(cell_backward_hook, args):
248
+ is_tuple = True
249
+ if not isinstance(args, tuple):
250
+ args = (args,)
251
+ is_tuple = False
252
+ hooked_args = cell_backward_hook(*args)
253
+ if is_tuple and len(args) == 1:
254
+ hooked_args = (hooked_args, )
255
+ return hooked_args
@@ -1,12 +1,26 @@
1
- import json
1
+ # Copyright (c) 2024-2024, Huawei Technologies Co., Ltd.
2
+ # All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
2
15
 
3
- from msprobe.core.common_config import CommonConfig, BaseConfig
4
- from msprobe.core.common.file_utils import FileOpen
5
16
  from msprobe.core.common.const import Const
6
- from msprobe.mindspore.common.const import FreeBenchmarkConst
7
- from msprobe.mindspore.common.log import logger
17
+ from msprobe.core.common.file_utils import load_json
18
+ from msprobe.core.common.utils import is_int
19
+ from msprobe.core.common_config import BaseConfig, CommonConfig
8
20
  from msprobe.core.grad_probe.constant import level_adp
9
21
  from msprobe.core.grad_probe.utils import check_numeral_list_ascend
22
+ from msprobe.mindspore.common.const import FreeBenchmarkConst
23
+ from msprobe.mindspore.common.log import logger
10
24
 
11
25
 
12
26
  class TensorConfig(BaseConfig):
@@ -18,9 +32,6 @@ class TensorConfig(BaseConfig):
18
32
  self._check_config()
19
33
 
20
34
  def _check_config(self):
21
- if self.data_mode is not None and len(self.data_mode) > 0:
22
- if len(self.data_mode) > 1 or self.data_mode[0] not in ["all", "input", "output"]:
23
- raise Exception("data_mode must be all, input or output")
24
35
  if self.file_format and self.file_format not in ["npy", "bin"]:
25
36
  raise Exception("file_format is invalid")
26
37
 
@@ -34,10 +45,11 @@ class StatisticsConfig(BaseConfig):
34
45
  self._check_config()
35
46
 
36
47
  def _check_config(self):
37
- if self.data_mode is not None and len(self.data_mode) > 0:
38
- if len(self.data_mode) > 1 or self.data_mode[0] not in ["all", "input", "output"]:
39
- raise Exception("data_mode must be all, input or output")
40
- if self.summary_mode and self.summary_mode not in ["statistics", "md5"]:
48
+ single_opt = ["statistics", "md5"]
49
+ muti_opt = ["md5", "max", "min", "mean", "l2norm"]
50
+ if isinstance(self.summary_mode, str) and self.summary_mode not in single_opt:
51
+ raise Exception("summary_mode is invalid")
52
+ if isinstance(self.summary_mode, list) and not all(opt in muti_opt for opt in self.summary_mode):
41
53
  raise Exception("summary_mode is invalid")
42
54
 
43
55
 
@@ -48,7 +60,7 @@ class OverflowCheckConfig(BaseConfig):
48
60
  self._check_config()
49
61
 
50
62
  def _check_config(self):
51
- if self.overflow_nums is not None and not isinstance(self.overflow_nums, int):
63
+ if self.overflow_nums is not None and not is_int(self.overflow_nums):
52
64
  raise Exception("overflow_nums is invalid, it should be an integer")
53
65
  if self.overflow_nums is not None and self.overflow_nums != -1 and self.overflow_nums <= 0:
54
66
  raise Exception("overflow_nums should be -1 or positive integer")
@@ -72,7 +84,7 @@ class FreeBenchmarkConfig(BaseConfig):
72
84
  if self.fuzz_level and self.fuzz_level not in FreeBenchmarkConst.DUMP_LEVEL_LIST:
73
85
  raise Exception("fuzz_level must be L1 or empty")
74
86
  if self.fuzz_stage and self.fuzz_stage not in FreeBenchmarkConst.STAGE_LIST:
75
- raise Exception("fuzz_stage must be forward or empty")
87
+ raise Exception("fuzz_stage must be forward, backward or empty")
76
88
  if self.if_preheat or self.preheat_step or self.max_sample:
77
89
  logger.warning("'if_preheat', 'preheat_step' and 'max_sample' settings "
78
90
  "are not supported for mindspore free benchmark task.")
@@ -119,8 +131,7 @@ def parse_task_config(task, json_config):
119
131
  def parse_json_config(json_file_path):
120
132
  if not json_file_path:
121
133
  raise Exception("json file path is None")
122
- with FileOpen(json_file_path, 'r') as file:
123
- json_config = json.load(file)
134
+ json_config = load_json(json_file_path)
124
135
  common_config = parse_common_config(json_config)
125
136
  if not common_config.task:
126
137
  common_config.task = Const.STATISTICS
@@ -13,10 +13,9 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
- import json
17
16
  import os
18
17
 
19
- from msprobe.core.common.file_utils import FileOpen, create_directory
18
+ from msprobe.core.common.file_utils import create_directory, save_json
20
19
  from msprobe.mindspore.common.log import logger
21
20
  from msprobe.mindspore.debugger.debugger_config import DebuggerConfig
22
21
 
@@ -47,13 +46,19 @@ class KernelGraphOverflowCheck:
47
46
  self.dump_json["common_dump_settings"]["op_debug_mode"] = 2
48
47
 
49
48
  def handle(self):
49
+ try:
50
+ from msprobe.lib import _msprobe_c
51
+ return
52
+ except ImportError:
53
+ # 如果没有_msprobe_ce_c走MindSpore老流程
54
+ logger.info("Module _msprobe_c has not been installed, use interface in mindspore instead.")
55
+
50
56
  if os.getenv("GRAPH_OP_RUN") == "1":
51
57
  raise Exception("Must run in graph mode, not kbk mode")
52
58
  json_path = self.dump_json["common_dump_settings"]["path"]
53
59
  create_directory(json_path)
54
60
  json_path = os.path.join(json_path, "kernel_graph_overflow_check.json")
55
- with FileOpen(json_path, 'w') as f:
56
- json.dump(self.dump_json, f)
61
+ save_json(json_path, self.dump_json, indent=4)
57
62
  logger.info(json_path + " has been created.")
58
63
  os.environ["MINDSPORE_DUMP_CONFIG"] = json_path
59
64
  if "MS_ACL_DUMP_CFG_PATH" in os.environ:
@@ -1,3 +1,18 @@
1
+ # Copyright (c) 2024-2024, Huawei Technologies Co., Ltd.
2
+ # All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
1
16
  class Runtime:
2
17
  step_count: int = 0
3
18
  rank_id: int = -1