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
@@ -0,0 +1,224 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ # Copyright (C) 2024. Huawei Technologies Co., Ltd. All rights reserved.
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ """
17
+ import os
18
+ import random
19
+ import stat
20
+ import torch
21
+ import numpy as np
22
+ from functools import wraps
23
+ from msprobe.core.common.exceptions import DistributedNotInitializedError
24
+
25
+ try:
26
+ import torch_npu
27
+ except ImportError:
28
+ is_gpu = True
29
+ else:
30
+ is_gpu = False
31
+
32
+
33
+ torch_without_guard_version_list = ['2.1', '2.2']
34
+ for version in torch_without_guard_version_list:
35
+ if torch.__version__.startswith(version):
36
+ torch_without_guard_version = True
37
+ break
38
+ else:
39
+ torch_without_guard_version = False
40
+
41
+ if not is_gpu and not torch_without_guard_version:
42
+ from torch_npu.utils.device_guard import torch_device_guard as torch_npu_device_guard
43
+
44
+ npu_distributed_api = ['isend', 'irecv']
45
+
46
+
47
+ def parameter_adapter(func):
48
+
49
+ def handle_masked_select(input_tensor, indices):
50
+ masked_select_func = getattr(torch._C._VariableFunctionsClass, "masked_select")
51
+ if input_tensor.dtype == torch.bfloat16:
52
+ # masked_select在NPU上输入数据dtype类型为bfloat16会报错,提示不支持此类型
53
+ return masked_select_func(input_tensor.to(torch.float32), indices).to(torch.bfloat16)
54
+ else:
55
+ return masked_select_func(input_tensor, indices)
56
+
57
+ @wraps(func)
58
+ def inner(self, *args, **kwargs):
59
+ if self.op_name_ == "__getitem__" and len(args) > 1 and isinstance(args[1], torch.Tensor):
60
+ input_tensor = args[0]
61
+ indices = args[1]
62
+ if indices.dtype == torch.uint8:
63
+ indices = indices.bool()
64
+ if indices.dtype == torch.bool:
65
+ if indices.shape == input_tensor.shape:
66
+ return handle_masked_select(input_tensor, indices)
67
+ else:
68
+ indices = getattr(torch._C._VariableFunctionsClass, "nonzero")(indices, as_tuple=True)
69
+ return getattr(torch._C._TensorBase, "__getitem__")(input_tensor, indices)
70
+ elif indices.dtype != torch.bool:
71
+ if not indices.shape or len(indices.shape) == 1:
72
+ return func(self, input_tensor, indices.tolist())
73
+ elif len(indices.shape) == 2:
74
+ result = [func(self, input_tensor, index) for index in indices.tolist()]
75
+ return getattr(torch._C._VariableFunctionsClass, "stack")(result, 0)
76
+ else:
77
+ res = [input_tensor[tensor_index] for tensor_index in indices]
78
+ return getattr(torch._C._VariableFunctionsClass, "stack")(res, 0)
79
+ if self.op_name_ == "__eq__" and args[1] is None:
80
+ return False
81
+ return func(self, *args, **kwargs)
82
+ return inner
83
+
84
+
85
+ def torch_device_guard(func):
86
+ if is_gpu or torch_without_guard_version:
87
+ return func
88
+ # Parse args/kwargs matched torch.device objects
89
+
90
+ @torch_npu_device_guard
91
+ def wrapper(*args, **kwargs):
92
+ return func(*args, **kwargs)
93
+ return wrapper
94
+
95
+
96
+ def get_rank_if_initialized():
97
+ """
98
+ return rank id if it is initialized or raise Exception: DistributedNotInitializedError
99
+ """
100
+ if torch.distributed.is_initialized():
101
+ return torch.distributed.get_rank()
102
+ else:
103
+ raise DistributedNotInitializedError("torch distributed environment is not initialized")
104
+
105
+
106
+ def seed_all(seed=1234, mode=False):
107
+ random.seed(seed)
108
+ os.environ['PYTHONHASHSEED'] = str(seed)
109
+ np.random.seed(seed)
110
+ torch.manual_seed(seed)
111
+ torch.use_deterministic_algorithms(mode)
112
+ if is_gpu:
113
+ torch.cuda.manual_seed_all(seed)
114
+ torch.cuda.manual_seed(seed)
115
+ torch.backends.cudnn.deterministic = True
116
+ torch.backends.cudnn.enable = False
117
+ torch.backends.cudnn.benchmark = False
118
+ else:
119
+ torch_npu.npu.manual_seed_all(seed)
120
+ torch_npu.npu.manual_seed(seed)
121
+
122
+
123
+ class Const:
124
+ """
125
+ Class for const
126
+ """
127
+ SEP = "."
128
+ MODEL_TYPE = ['.onnx', '.pb', '.om']
129
+ DIM_PATTERN = r"^(-?[0-9]+)(,-?[0-9]+)*"
130
+ SEMICOLON = ";"
131
+ COLON = ":"
132
+ EQUAL = "="
133
+ COMMA = ","
134
+ DOT = "."
135
+ DUMP_RATIO_MAX = 100
136
+ SUMMERY_DATA_NUMS = 256
137
+ FLOAT_EPSILON = np.finfo(float).eps
138
+ SUPPORT_DUMP_MODE = ['api', 'acl']
139
+ ON = 'ON'
140
+ OFF = 'OFF'
141
+ KWARGS = 'kwargs'
142
+ INPUT = 'input'
143
+ OUTPUT = 'output'
144
+ BACKWARD = 'backward'
145
+ FORWARD = 'forward'
146
+ PRE_FORWARD = "pre_forward"
147
+ INPUT_ARGS = 'input_args'
148
+ INPUT_KWARGS = 'input_kwargs'
149
+ GRAD_INPUT = 'grad_input'
150
+ GRAD_OUTPUT = 'grad_output'
151
+ START = "start"
152
+ STOP = "stop"
153
+ MAX = 'Max'
154
+ MIN = 'Min'
155
+
156
+ # dump mode
157
+ ALL = "all"
158
+ LIST = "list"
159
+ RANGE = "range"
160
+ STACK = "stack"
161
+ ACL = "acl"
162
+ API_LIST = "api_list"
163
+ API_STACK = "api_stack"
164
+ DUMP_MODE = [ALL, LIST, RANGE, STACK, ACL, API_LIST, API_STACK]
165
+ AUTO = "auto"
166
+ ONLINE_DUMP_MODE = [ALL, LIST, AUTO, OFF]
167
+ SUMMARY = "summary"
168
+ MD5 = "md5"
169
+ SUMMARY_MODE = [ALL, SUMMARY, MD5]
170
+
171
+ WRITE_FLAGS = os.O_WRONLY | os.O_CREAT
172
+ OVERWRITE_FLAGS = os.O_WRONLY | os.O_CREAT | os.O_TRUNC
173
+ WRITE_MODES = stat.S_IWUSR | stat.S_IRUSR
174
+
175
+ PKL_SUFFIX = ".pkl"
176
+ NUMPY_SUFFIX = ".npy"
177
+ ONE_GB = 1 * 1024 * 1024 * 1024
178
+ TEN_GB = 10 * 1024 * 1024 * 1024
179
+ FILE_PATTERN = r'^[a-zA-Z0-9_./-]+$'
180
+ FILE_NAME_LENGTH = 255
181
+ DIRECTORY_LENGTH = 4096
182
+ DISTRIBUTED_PREFIX_LENGTH = 60
183
+ SUMMARY_COLUMN_NUM = 6
184
+ STACK_COLUMN_NUM = 2
185
+ # env dump path
186
+ ASCEND_WORK_PATH = "ASCEND_WORK_PATH"
187
+ DUMP_DIR = "dump_data"
188
+ DATA = "data"
189
+
190
+ ENV_ENABLE = "1"
191
+ ENV_DISABLE = "0"
192
+
193
+ MAX_SEED_VALUE = 2**32 - 1
194
+
195
+ INPLACE_LIST = ["broadcast", "all_reduce", "reduce", "all_gather", "gather", "scatter", "reduce_scatter",
196
+ "_reduce_scatter_base", "_all_gather_base", "all_to_all_single"]
197
+
198
+ TASK_LIST = ["tensor", "statistics", "overflow_check", "free_benchmark"]
199
+ LEVEL_LIST = ["L0", "L1", "L2", "mix"]
200
+ STATISTICS = "statistics"
201
+ TENSOR = "tensor"
202
+ OVERFLOW_CHECK = "overflow_check"
203
+ FREE_BENCHMARK = "free_benchmark"
204
+
205
+ ATTR_NAME_PREFIX = "wrap_"
206
+
207
+ FLOAT_TYPE = [np.half, np.single, float, np.double, np.float64, np.longdouble, np.float32, np.float16]
208
+ BOOL_TYPE = [bool, np.uint8]
209
+ INT_TYPE = [np.int32, np.int64]
210
+ NPU = 'NPU'
211
+ DISTRIBUTED = 'Distributed'
212
+
213
+ RAISE_PRECISION = {
214
+ torch.float16: torch.float32,
215
+ torch.bfloat16: torch.float32,
216
+ torch.float32: torch.float64
217
+ }
218
+ CONVERT = {
219
+ "int32_to_int64": ["torch.int32", "torch.int64"],
220
+ }
221
+
222
+ CONVERT_API = {
223
+ "int32_to_int64": ["cross_entropy"]
224
+ }