mindspore 2.3.0__cp39-cp39-win_amd64.whl → 2.4.0__cp39-cp39-win_amd64.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.

Potentially problematic release.


This version of mindspore might be problematic. Click here for more details.

Files changed (285) hide show
  1. mindspore/.commit_id +1 -1
  2. mindspore/__init__.py +3 -1
  3. mindspore/_c_dataengine.cp39-win_amd64.pyd +0 -0
  4. mindspore/_c_expression.cp39-win_amd64.pyd +0 -0
  5. mindspore/_c_mindrecord.cp39-win_amd64.pyd +0 -0
  6. mindspore/_checkparam.py +50 -9
  7. mindspore/_extends/parse/compile_config.py +41 -0
  8. mindspore/_extends/parse/parser.py +9 -7
  9. mindspore/_extends/parse/standard_method.py +52 -14
  10. mindspore/_extends/pijit/pijit_func_white_list.py +350 -24
  11. mindspore/amp.py +24 -10
  12. mindspore/avcodec-59.dll +0 -0
  13. mindspore/avdevice-59.dll +0 -0
  14. mindspore/avfilter-8.dll +0 -0
  15. mindspore/avformat-59.dll +0 -0
  16. mindspore/avutil-57.dll +0 -0
  17. mindspore/common/__init__.py +6 -4
  18. mindspore/common/_pijit_context.py +190 -0
  19. mindspore/common/_register_for_tensor.py +2 -1
  20. mindspore/common/_tensor_overload.py +139 -0
  21. mindspore/common/api.py +102 -87
  22. mindspore/common/dump.py +5 -6
  23. mindspore/common/generator.py +1 -7
  24. mindspore/common/hook_handle.py +14 -26
  25. mindspore/common/mindir_util.py +2 -2
  26. mindspore/common/parameter.py +46 -13
  27. mindspore/common/recompute.py +39 -9
  28. mindspore/common/sparse_tensor.py +7 -3
  29. mindspore/common/tensor.py +209 -29
  30. mindspore/communication/__init__.py +1 -1
  31. mindspore/communication/_comm_helper.py +38 -3
  32. mindspore/communication/comm_func.py +310 -55
  33. mindspore/communication/management.py +14 -14
  34. mindspore/context.py +123 -22
  35. mindspore/dataset/__init__.py +1 -1
  36. mindspore/dataset/audio/__init__.py +1 -1
  37. mindspore/dataset/core/config.py +7 -0
  38. mindspore/dataset/core/validator_helpers.py +7 -0
  39. mindspore/dataset/engine/cache_client.py +1 -1
  40. mindspore/dataset/engine/datasets.py +72 -44
  41. mindspore/dataset/engine/datasets_audio.py +7 -7
  42. mindspore/dataset/engine/datasets_standard_format.py +53 -3
  43. mindspore/dataset/engine/datasets_text.py +20 -20
  44. mindspore/dataset/engine/datasets_user_defined.py +174 -104
  45. mindspore/dataset/engine/datasets_vision.py +33 -33
  46. mindspore/dataset/engine/iterators.py +29 -0
  47. mindspore/dataset/engine/obs/util.py +7 -0
  48. mindspore/dataset/engine/queue.py +114 -60
  49. mindspore/dataset/engine/serializer_deserializer.py +2 -2
  50. mindspore/dataset/engine/validators.py +34 -14
  51. mindspore/dataset/text/__init__.py +1 -4
  52. mindspore/dataset/transforms/__init__.py +0 -3
  53. mindspore/dataset/utils/line_reader.py +2 -0
  54. mindspore/dataset/vision/__init__.py +1 -4
  55. mindspore/dataset/vision/utils.py +1 -1
  56. mindspore/dataset/vision/validators.py +2 -1
  57. mindspore/dnnl.dll +0 -0
  58. mindspore/{nn/extend → experimental/es}/__init__.py +4 -11
  59. mindspore/experimental/es/embedding_service.py +883 -0
  60. mindspore/{nn/layer → experimental/es}/embedding_service_layer.py +218 -30
  61. mindspore/experimental/llm_boost/__init__.py +21 -0
  62. mindspore/{nn/extend/layer → experimental/llm_boost/atb}/__init__.py +4 -8
  63. mindspore/experimental/llm_boost/atb/boost_base.py +211 -0
  64. mindspore/experimental/llm_boost/atb/llama_boost.py +115 -0
  65. mindspore/experimental/llm_boost/atb/qwen_boost.py +101 -0
  66. mindspore/experimental/llm_boost/register.py +129 -0
  67. mindspore/experimental/llm_boost/utils.py +31 -0
  68. mindspore/experimental/optim/adamw.py +85 -0
  69. mindspore/experimental/optim/optimizer.py +3 -0
  70. mindspore/hal/__init__.py +3 -3
  71. mindspore/hal/contiguous_tensors_handle.py +175 -0
  72. mindspore/hal/stream.py +18 -0
  73. mindspore/include/api/model_group.h +13 -1
  74. mindspore/include/api/types.h +10 -10
  75. mindspore/include/dataset/config.h +2 -2
  76. mindspore/include/dataset/constants.h +2 -2
  77. mindspore/include/dataset/execute.h +2 -2
  78. mindspore/include/dataset/vision.h +4 -0
  79. mindspore/jpeg62.dll +0 -0
  80. mindspore/log.py +1 -1
  81. mindspore/mindrecord/filewriter.py +68 -51
  82. mindspore/mindspore_backend.dll +0 -0
  83. mindspore/mindspore_common.dll +0 -0
  84. mindspore/mindspore_core.dll +0 -0
  85. mindspore/mindspore_glog.dll +0 -0
  86. mindspore/mindspore_np_dtype.dll +0 -0
  87. mindspore/mindspore_ops.dll +0 -0
  88. mindspore/mint/__init__.py +495 -46
  89. mindspore/mint/distributed/__init__.py +31 -0
  90. mindspore/mint/distributed/distributed.py +254 -0
  91. mindspore/mint/nn/__init__.py +266 -21
  92. mindspore/mint/nn/functional.py +125 -19
  93. mindspore/mint/nn/layer/__init__.py +39 -0
  94. mindspore/mint/nn/layer/activation.py +133 -0
  95. mindspore/mint/nn/layer/normalization.py +477 -0
  96. mindspore/mint/nn/layer/pooling.py +110 -0
  97. mindspore/mint/optim/adamw.py +28 -7
  98. mindspore/mint/special/__init__.py +63 -0
  99. mindspore/multiprocessing/__init__.py +2 -1
  100. mindspore/nn/__init__.py +0 -1
  101. mindspore/nn/cell.py +275 -93
  102. mindspore/nn/layer/activation.py +211 -44
  103. mindspore/nn/layer/basic.py +113 -3
  104. mindspore/nn/layer/embedding.py +120 -2
  105. mindspore/nn/layer/normalization.py +101 -5
  106. mindspore/nn/layer/padding.py +34 -48
  107. mindspore/nn/layer/pooling.py +161 -7
  108. mindspore/nn/layer/transformer.py +3 -3
  109. mindspore/nn/loss/__init__.py +2 -2
  110. mindspore/nn/loss/loss.py +84 -6
  111. mindspore/nn/optim/__init__.py +2 -1
  112. mindspore/nn/optim/adadelta.py +1 -1
  113. mindspore/nn/optim/adam.py +1 -1
  114. mindspore/nn/optim/lamb.py +1 -1
  115. mindspore/nn/optim/tft_wrapper.py +127 -0
  116. mindspore/nn/wrap/cell_wrapper.py +12 -23
  117. mindspore/nn/wrap/grad_reducer.py +5 -5
  118. mindspore/nn/wrap/loss_scale.py +17 -3
  119. mindspore/numpy/__init__.py +1 -1
  120. mindspore/numpy/array_creations.py +65 -68
  121. mindspore/numpy/array_ops.py +64 -60
  122. mindspore/numpy/fft.py +610 -75
  123. mindspore/numpy/logic_ops.py +11 -10
  124. mindspore/numpy/math_ops.py +85 -84
  125. mindspore/numpy/utils_const.py +4 -4
  126. mindspore/opencv_core452.dll +0 -0
  127. mindspore/opencv_imgcodecs452.dll +0 -0
  128. mindspore/opencv_imgproc452.dll +0 -0
  129. mindspore/ops/__init__.py +6 -4
  130. mindspore/ops/_grad_experimental/grad_comm_ops.py +47 -3
  131. mindspore/ops/_grad_experimental/grad_math_ops.py +0 -22
  132. mindspore/ops/_vmap/vmap_array_ops.py +2 -4
  133. mindspore/ops/_vmap/vmap_math_ops.py +17 -1
  134. mindspore/ops/_vmap/vmap_nn_ops.py +43 -2
  135. mindspore/ops/auto_generate/cpp_create_prim_instance_helper.py +85 -7
  136. mindspore/ops/auto_generate/gen_arg_dtype_cast.py +2 -0
  137. mindspore/ops/auto_generate/gen_extend_func.py +734 -13
  138. mindspore/ops/auto_generate/gen_ops_def.py +2420 -381
  139. mindspore/ops/auto_generate/gen_ops_prim.py +5196 -1659
  140. mindspore/ops/auto_generate/pyboost_inner_prim.py +176 -56
  141. mindspore/ops/composite/base.py +85 -48
  142. mindspore/ops/composite/multitype_ops/_compile_utils.py +1 -0
  143. mindspore/ops/composite/multitype_ops/not_in_impl.py +2 -2
  144. mindspore/ops/function/__init__.py +22 -0
  145. mindspore/ops/function/array_func.py +490 -153
  146. mindspore/ops/function/debug_func.py +113 -1
  147. mindspore/ops/function/fft_func.py +15 -2
  148. mindspore/ops/function/grad/grad_func.py +3 -2
  149. mindspore/ops/function/math_func.py +558 -207
  150. mindspore/ops/function/nn_func.py +817 -383
  151. mindspore/ops/function/other_func.py +3 -2
  152. mindspore/ops/function/random_func.py +184 -8
  153. mindspore/ops/function/reshard_func.py +13 -11
  154. mindspore/ops/function/sparse_unary_func.py +1 -1
  155. mindspore/ops/function/vmap_func.py +3 -2
  156. mindspore/ops/functional.py +24 -14
  157. mindspore/ops/op_info_register.py +3 -3
  158. mindspore/ops/operations/__init__.py +6 -1
  159. mindspore/ops/operations/_grad_ops.py +2 -76
  160. mindspore/ops/operations/_infer_ops.py +1 -1
  161. mindspore/ops/operations/_inner_ops.py +71 -94
  162. mindspore/ops/operations/array_ops.py +12 -146
  163. mindspore/ops/operations/comm_ops.py +42 -53
  164. mindspore/ops/operations/custom_ops.py +83 -19
  165. mindspore/ops/operations/debug_ops.py +42 -10
  166. mindspore/ops/operations/manually_defined/_inner.py +12 -0
  167. mindspore/ops/operations/manually_defined/ops_def.py +265 -10
  168. mindspore/ops/operations/math_ops.py +12 -223
  169. mindspore/ops/operations/nn_ops.py +20 -114
  170. mindspore/ops/operations/other_ops.py +7 -4
  171. mindspore/ops/operations/random_ops.py +46 -1
  172. mindspore/ops/primitive.py +18 -6
  173. mindspore/ops_generate/arg_dtype_cast.py +2 -0
  174. mindspore/ops_generate/gen_aclnn_implement.py +11 -11
  175. mindspore/ops_generate/gen_constants.py +36 -0
  176. mindspore/ops_generate/gen_ops.py +67 -52
  177. mindspore/ops_generate/gen_ops_inner_prim.py +1 -1
  178. mindspore/ops_generate/gen_pyboost_func.py +131 -47
  179. mindspore/ops_generate/op_proto.py +10 -3
  180. mindspore/ops_generate/pyboost_utils.py +14 -1
  181. mindspore/ops_generate/template.py +43 -21
  182. mindspore/parallel/__init__.py +3 -1
  183. mindspore/parallel/_auto_parallel_context.py +28 -8
  184. mindspore/parallel/_cell_wrapper.py +83 -0
  185. mindspore/parallel/_parallel_serialization.py +47 -19
  186. mindspore/parallel/_tensor.py +81 -11
  187. mindspore/parallel/_utils.py +13 -1
  188. mindspore/parallel/algo_parameter_config.py +5 -5
  189. mindspore/parallel/checkpoint_transform.py +46 -39
  190. mindspore/parallel/cluster/process_entity/__init__.py +1 -1
  191. mindspore/parallel/cluster/process_entity/_api.py +31 -23
  192. mindspore/parallel/cluster/process_entity/_utils.py +2 -27
  193. mindspore/parallel/parameter_broadcast.py +3 -4
  194. mindspore/parallel/shard.py +162 -31
  195. mindspore/parallel/transform_safetensors.py +993 -0
  196. mindspore/profiler/__init__.py +2 -1
  197. mindspore/profiler/common/constant.py +29 -0
  198. mindspore/profiler/common/registry.py +47 -0
  199. mindspore/profiler/common/util.py +28 -0
  200. mindspore/profiler/dynamic_profiler.py +694 -0
  201. mindspore/profiler/envprofiling.py +17 -19
  202. mindspore/profiler/parser/ascend_analysis/constant.py +18 -0
  203. mindspore/profiler/parser/ascend_analysis/file_manager.py +25 -4
  204. mindspore/profiler/parser/ascend_analysis/function_event.py +43 -19
  205. mindspore/profiler/parser/ascend_analysis/fwk_cann_parser.py +31 -26
  206. mindspore/profiler/parser/ascend_analysis/fwk_file_parser.py +56 -10
  207. mindspore/profiler/parser/ascend_analysis/msprof_timeline_parser.py +55 -8
  208. mindspore/profiler/parser/ascend_analysis/path_manager.py +313 -0
  209. mindspore/profiler/parser/ascend_analysis/profiler_info_parser.py +27 -20
  210. mindspore/profiler/parser/ascend_analysis/trace_event_manager.py +9 -2
  211. mindspore/profiler/parser/ascend_msprof_exporter.py +5 -4
  212. mindspore/profiler/parser/ascend_timeline_generator.py +27 -25
  213. mindspore/profiler/parser/base_timeline_generator.py +19 -25
  214. mindspore/profiler/parser/cpu_gpu_timeline_generator.py +25 -12
  215. mindspore/profiler/parser/framework_parser.py +1 -391
  216. mindspore/profiler/parser/gpu_analysis/__init__.py +14 -0
  217. mindspore/profiler/parser/gpu_analysis/function_event.py +44 -0
  218. mindspore/profiler/parser/gpu_analysis/fwk_file_parser.py +89 -0
  219. mindspore/profiler/parser/gpu_analysis/profiler_info_parser.py +72 -0
  220. mindspore/profiler/parser/memory_usage_parser.py +0 -154
  221. mindspore/profiler/parser/profiler_info.py +78 -6
  222. mindspore/profiler/profiler.py +153 -0
  223. mindspore/profiler/profiling.py +280 -412
  224. mindspore/rewrite/__init__.py +1 -2
  225. mindspore/rewrite/common/namespace.py +4 -4
  226. mindspore/rewrite/symbol_tree/symbol_tree.py +3 -3
  227. mindspore/run_check/_check_version.py +36 -103
  228. mindspore/safeguard/rewrite_obfuscation.py +591 -247
  229. mindspore/swresample-4.dll +0 -0
  230. mindspore/swscale-6.dll +0 -0
  231. mindspore/tinyxml2.dll +0 -0
  232. mindspore/train/__init__.py +4 -3
  233. mindspore/train/_utils.py +28 -2
  234. mindspore/train/amp.py +171 -53
  235. mindspore/train/callback/__init__.py +2 -2
  236. mindspore/train/callback/_callback.py +4 -4
  237. mindspore/train/callback/_checkpoint.py +85 -22
  238. mindspore/train/callback/_cluster_monitor.py +1 -1
  239. mindspore/train/callback/_flops_collector.py +1 -0
  240. mindspore/train/callback/_loss_monitor.py +3 -3
  241. mindspore/train/callback/_on_request_exit.py +134 -31
  242. mindspore/train/callback/_summary_collector.py +5 -5
  243. mindspore/train/callback/_tft_register.py +352 -0
  244. mindspore/train/dataset_helper.py +7 -3
  245. mindspore/train/metrics/metric.py +3 -3
  246. mindspore/train/metrics/roc.py +4 -4
  247. mindspore/train/mind_ir_pb2.py +44 -39
  248. mindspore/train/model.py +134 -58
  249. mindspore/train/serialization.py +336 -112
  250. mindspore/turbojpeg.dll +0 -0
  251. mindspore/utils/__init__.py +21 -0
  252. mindspore/utils/utils.py +60 -0
  253. mindspore/version.py +1 -1
  254. {mindspore-2.3.0.dist-info → mindspore-2.4.0.dist-info}/METADATA +6 -2
  255. {mindspore-2.3.0.dist-info → mindspore-2.4.0.dist-info}/RECORD +258 -252
  256. mindspore/include/c_api/ms/abstract.h +0 -67
  257. mindspore/include/c_api/ms/attribute.h +0 -197
  258. mindspore/include/c_api/ms/base/handle_types.h +0 -43
  259. mindspore/include/c_api/ms/base/macros.h +0 -32
  260. mindspore/include/c_api/ms/base/status.h +0 -33
  261. mindspore/include/c_api/ms/base/types.h +0 -283
  262. mindspore/include/c_api/ms/context.h +0 -102
  263. mindspore/include/c_api/ms/graph.h +0 -160
  264. mindspore/include/c_api/ms/node.h +0 -606
  265. mindspore/include/c_api/ms/tensor.h +0 -161
  266. mindspore/include/c_api/ms/value.h +0 -84
  267. mindspore/mindspore_shared_lib.dll +0 -0
  268. mindspore/nn/extend/basic.py +0 -140
  269. mindspore/nn/extend/embedding.py +0 -143
  270. mindspore/nn/extend/layer/normalization.py +0 -109
  271. mindspore/nn/extend/pooling.py +0 -117
  272. mindspore/nn/layer/embedding_service.py +0 -531
  273. mindspore/ops/_op_impl/aicpu/strided_slice_v2.py +0 -93
  274. mindspore/ops/_op_impl/aicpu/strided_slice_v2_grad.py +0 -66
  275. mindspore/ops/extend/__init__.py +0 -53
  276. mindspore/ops/extend/array_func.py +0 -218
  277. mindspore/ops/extend/math_func.py +0 -76
  278. mindspore/ops/extend/nn_func.py +0 -308
  279. mindspore/ops/silent_check.py +0 -162
  280. mindspore/profiler/parser/msadvisor_analyzer.py +0 -82
  281. mindspore/profiler/parser/msadvisor_parser.py +0 -240
  282. mindspore/train/callback/_mindio_ttp.py +0 -443
  283. {mindspore-2.3.0.dist-info → mindspore-2.4.0.dist-info}/WHEEL +0 -0
  284. {mindspore-2.3.0.dist-info → mindspore-2.4.0.dist-info}/entry_points.txt +0 -0
  285. {mindspore-2.3.0.dist-info → mindspore-2.4.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,89 @@
1
+ # Copyright 2024 Huawei Technologies Co., Ltd
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # ============================================================================
15
+ """MindSpore framework oprange file parser"""
16
+
17
+ import os
18
+ from collections import defaultdict
19
+
20
+ from mindspore import log as logger
21
+
22
+ from mindspore.profiler.parser.ascend_analysis.fwk_file_parser import FwkFileParser
23
+ from mindspore.profiler.parser.ascend_analysis.file_manager import FileManager
24
+ from mindspore.profiler.parser.ascend_analysis.tlv_decoder import TLVDecoder
25
+ from mindspore.profiler.parser.ascend_analysis.trace_event_manager import TraceEventManager
26
+ from mindspore.profiler.parser.ascend_analysis.constant import Constant
27
+
28
+ from mindspore.profiler.parser.gpu_analysis.function_event import GPUMindSporeOpEvent
29
+ from mindspore.profiler.parser.gpu_analysis.profiler_info_parser import GPUProfilerInfoParser
30
+ from mindspore.profiler.common.validator.validate_path import validate_and_normalize_path
31
+
32
+
33
+ class GPUFwkFileParser(FwkFileParser):
34
+ """Framework-side operator file parser."""
35
+
36
+ def __init__(self, source_path: str, rank_id: int):
37
+ """
38
+ source_path: The path of PROF_* directory
39
+ """
40
+ super(GPUFwkFileParser, self).__init__(source_path, rank_id)
41
+ GPUProfilerInfoParser.init_source_path(source_path)
42
+ GPUProfilerInfoParser.init_rank_id(rank_id)
43
+
44
+ def get_op_range_data(self, step_list=None):
45
+ """Read and decode all the mindspore oprange data."""
46
+ op_range_list = []
47
+ if os.path.exists(self._op_range_path):
48
+ op_range_bytes = FileManager.read_file_content(self._op_range_path, "rb")
49
+ op_range_list = TLVDecoder.decode(op_range_bytes, GPUMindSporeOpEvent, self._op_range_struct_size)
50
+ else:
51
+ logger.warning("Failed to find op_range data. skip parse host profiler data.")
52
+ return op_range_list
53
+
54
+ def get_fwk_trace_data(self, mindspore_op_data=None):
55
+ """Generate chrome trace format json data from decoded oprange data."""
56
+ if not mindspore_op_data:
57
+ mindspore_op_data = self.get_op_range_data()
58
+ tid_map = defaultdict(set)
59
+ fwk_x_event_list = []
60
+ dataset_op_data = []
61
+
62
+ for mindspore_op in mindspore_op_data:
63
+ if mindspore_op.name == Constant.FLOW_OP:
64
+ continue
65
+
66
+ if mindspore_op.name.split('::')[0] == 'Dataset':
67
+ dataset_op_data.append(mindspore_op)
68
+
69
+ tid_map[mindspore_op.pid].add(mindspore_op.tid)
70
+ if mindspore_op.dur > 0:
71
+ fwk_x_event_list.append(TraceEventManager.create_x_event(mindspore_op, "cpu_op"))
72
+ else:
73
+ fwk_x_event_list.append(TraceEventManager.create_i_event(mindspore_op))
74
+
75
+ fwk_m_event_list = []
76
+ for pid, tid_set in tid_map.items():
77
+ fwk_m_event_list.extend(TraceEventManager.create_m_event(pid, tid_set, pid))
78
+
79
+ self.calculate_dataset_item(dataset_op_data)
80
+
81
+ return fwk_x_event_list + fwk_m_event_list
82
+
83
+ def _init_framework_path(self, source_path: str):
84
+ """Init the oprange data path."""
85
+ source_path = validate_and_normalize_path(source_path)
86
+ if not os.path.exists(source_path):
87
+ raise FileNotFoundError("Input source_path does not exist!")
88
+ self._prof_root = source_path
89
+ self._op_range_path = os.path.join(source_path, self._op_range.format(self.rank_id))
@@ -0,0 +1,72 @@
1
+ # Copyright 2024 Huawei Technologies Co., Ltd
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # ============================================================================
15
+ """Profiler host information parser"""
16
+ import os
17
+ import json
18
+ from decimal import Decimal
19
+ from mindspore.profiler.common.validator.validate_path import validate_and_normalize_path
20
+ from mindspore.profiler.parser.ascend_analysis.constant import Constant
21
+ from mindspore.profiler.parser.profiler_info import ProfilerInfo
22
+
23
+
24
+ class GPUProfilerInfoParser:
25
+ """Parse files that record information, such as profiler_info.json"""
26
+
27
+ _freq = 2600000000
28
+ _system_time = 0
29
+ _system_cnt = 0
30
+ _s_to_ns = 1e9
31
+ # profiler information related files
32
+ _source_path = None
33
+ _loaded_frequency = False
34
+ _rank_id = 0
35
+
36
+ @classmethod
37
+ def init_source_path(cls, source_path: str):
38
+ """initialize the path of PROF_* directory."""
39
+ source_path = validate_and_normalize_path(source_path)
40
+ cls._source_path = source_path
41
+
42
+ @classmethod
43
+ def init_rank_id(cls, rank_id: int):
44
+ """initialize the rank id."""
45
+ cls._rank_id = rank_id
46
+
47
+ @classmethod
48
+ def get_local_time(cls, syscnt: int) -> Decimal:
49
+ """Convert syscnt to local time."""
50
+ if not cls._loaded_frequency:
51
+ profiler_info_path = os.path.join(cls._source_path, f"profiler_info_{cls._rank_id}.json")
52
+ if not os.path.isfile(profiler_info_path):
53
+ raise RuntimeError(f"Can`t find the file {profiler_info_path}, please check !")
54
+ with os.fdopen(os.open(profiler_info_path, os.O_RDONLY, 0o600),
55
+ 'r') as fr:
56
+ profiler_info_data = json.load(fr)
57
+ cls._system_cnt = profiler_info_data.get('system_cnt')
58
+ cls._system_time = profiler_info_data.get('system_time')
59
+ ProfilerInfo.set_system_time(cls._system_cnt)
60
+ ProfilerInfo.set_system_cnt(cls._system_time)
61
+ cls._loaded_frequency = True
62
+
63
+ start_ns = cls._get_timestamp(syscnt)
64
+ return Decimal(start_ns).quantize(Decimal('0.000')) * Decimal(Constant.NS_TO_US).quantize(Decimal('0.000'))
65
+
66
+ @classmethod
67
+ def _get_timestamp(cls, syscnt: int):
68
+ """Convert syscnt to time stamp."""
69
+ ratio = cls._freq / cls._s_to_ns
70
+ # The unit of timestamp is ns
71
+ timestamp = (syscnt - cls._system_cnt) / ratio + cls._system_time
72
+ return timestamp
@@ -14,169 +14,15 @@
14
14
  # ============================================================================
15
15
  """Memory Usage Parser."""
16
16
  from collections import OrderedDict
17
- import json
18
- import os
19
- import stat
20
-
21
- from google.protobuf.text_format import ParseError
22
17
 
23
18
  from mindspore import log as logger
24
- from mindspore.profiler.common.exceptions.exceptions import ProfilerIOException, \
25
- ProfilerFileNotFoundException, ProfilerRawFileException
26
- from mindspore.profiler.common.validator.validate_path import validate_and_normalize_path
27
19
  from mindspore.profiler.parser.container import MemoryGraph as Graph
28
20
  from mindspore.profiler.parser.container import MemoryNode as Node
29
21
  from mindspore.profiler.parser.container import MemoryTensor as Tensor
30
- import mindspore._c_expression as c_expression
31
-
32
- if not c_expression.security.enable_security():
33
- from mindspore.train.memory_profiling_pb2 import MemoryProto
34
- else:
35
- MemoryProto = None
36
22
 
37
23
  GIGABYTES = 1024 * 1024 * 1024
38
24
 
39
25
 
40
- class MemoryUsageParser:
41
- """MemoryUsageParser to parse memory raw data."""
42
-
43
- def __init__(self, profiling_dir, device_id, pretty=False):
44
- self._profiling_dir = profiling_dir
45
- self._device_id = device_id
46
- self._proto_file_path = 'memory_usage_{}.pb'
47
- self._summary_filename = 'memory_usage_summary_{}.json'
48
- self._details_filename = 'memory_usage_details_{}.json'
49
- self._graphs_dict = {}
50
- self._peak_mem = 0
51
- self._mem_summary = {
52
- 'capacity': 0,
53
- 'allocations': 0,
54
- 'deallocations': 0,
55
- 'peak_mem': 0,
56
- 'static_mem': 0
57
- }
58
- self._framework = {}
59
- self._points = {}
60
- self._pretty = pretty
61
-
62
- @property
63
- def indent(self):
64
- indent = 1 if self._pretty else None
65
- return indent
66
-
67
- @staticmethod
68
- def _process_framework_info(aicore_detail_data):
69
- """Process framework info."""
70
- framework_info_dict = {}
71
- for framework_obj in aicore_detail_data:
72
- op_name = framework_obj[0]
73
- op_full_name = framework_obj[4]
74
- op_info = framework_obj[5]
75
- framework_info_dict[op_name] = {
76
- 'fullname': op_full_name,
77
- 'name': op_name,
78
- 'args': op_info
79
- }
80
-
81
- return framework_info_dict
82
-
83
- def write_memory_files(self):
84
- """Write memory files."""
85
- logger.info('Start recording memory data into files...')
86
- # write memory summary to json file
87
- summary_filename = self._summary_filename.format(self._device_id)
88
- self._write_memory_files(summary_filename, self._mem_summary)
89
-
90
- # write memory details to json file
91
- details_filename = self._details_filename.format(self._device_id)
92
- self._write_memory_files(details_filename, self._graphs_dict)
93
- logger.info('Successfully write memory data into files.')
94
-
95
- def init_memory_usage_info(self, aicore_detail_data, points):
96
- """Init memory usage information."""
97
- logger.info("Start to load memory usage data from pb file")
98
- file_path = self._get_file_path()
99
- self._framework = self._process_framework_info(aicore_detail_data)
100
- self._points = points
101
-
102
- # Open memory protobuf file.
103
- try:
104
- with open(file_path, 'rb') as f:
105
- content = f.read()
106
- except (IOError, OSError) as err:
107
- logger.critical('Failed to read memory file: %s', err)
108
- raise ProfilerIOException from err
109
-
110
- # Parse memory raw data from file.
111
- if not c_expression.security.enable_security():
112
- if not MemoryProto:
113
- raise ProfilerRawFileException("Can not find memory profiling pb file.")
114
-
115
- memory_proto = MemoryProto()
116
- try:
117
- memory_proto.ParseFromString(content)
118
- except ParseError as err:
119
- msg = "Fail to parse memory proto file."
120
- logger.critical("Cannot parse the memory file. Please check the file schema.\n%s", err)
121
- raise ProfilerRawFileException(msg) from err
122
-
123
- # Parse memory details based on graphs in the network.
124
- graphs = memory_proto.graph_mem
125
- self._parse_graph_memory(graphs)
126
- # Update memory summary information.
127
- self._mem_summary['capacity'] = memory_proto.total_mem / GIGABYTES
128
- self._mem_summary['peak_mem'] = self._peak_mem
129
-
130
- logger.info('Finished processing memory usage data.')
131
-
132
- def _get_file_path(self):
133
- """Get the proto file path."""
134
- file_path = os.path.join(
135
- self._profiling_dir,
136
- self._proto_file_path.format(self._device_id)
137
- )
138
- file_path = validate_and_normalize_path(file_path)
139
-
140
- if not os.path.exists(file_path):
141
- logger.warning('The memory file does not exist! Please ignore the warning '
142
- 'if you are running heterogeneous training.')
143
- raise ProfilerFileNotFoundException(msg=file_path)
144
-
145
- return file_path
146
-
147
- def _parse_graph_memory(self, graphs):
148
- """Parse memory usage based on subgraphs."""
149
- for graph_proto in graphs:
150
- graph_id = graph_proto.graph_id
151
- if graph_id is None:
152
- logger.info('Graph id is missing, skipped the graph.')
153
- continue
154
-
155
- graph_parser = GraphMemoryParser(graph_proto, self._points, self._framework)
156
- graph, model_id = graph_parser.parse_graph()
157
- if graph and model_id != -1:
158
- self._graphs_dict[model_id] = graph
159
-
160
- # update global memory usage data
161
- self._peak_mem = max(self._peak_mem, graph_parser.peak_mem)
162
- self._mem_summary['static_mem'] += graph_parser.static_mem
163
- self._mem_summary['allocations'] += graph_parser.allocations
164
- self._mem_summary['deallocations'] += graph_parser.deallocations
165
-
166
- def _write_memory_files(self, filename, content):
167
- """Write the summary and top breakdowns of memory usage."""
168
- file_path = os.path.join(self._profiling_dir, filename)
169
- file_path = validate_and_normalize_path(file_path)
170
-
171
- try:
172
- with os.fdopen(os.open(file_path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600), 'w') as json_file:
173
- json.dump(content, json_file, indent=self.indent)
174
- os.chmod(file_path, stat.S_IREAD | stat.S_IWRITE)
175
- except (IOError, OSError) as err:
176
- logger.critical('Fail to write memory file.\n%s', err)
177
- raise ProfilerIOException from err
178
-
179
-
180
26
  class GraphMemoryParser:
181
27
  """Parse memory usage data for each graph."""
182
28
 
@@ -13,12 +13,13 @@
13
13
  # limitations under the License.
14
14
  # ============================================================================
15
15
  """Record profiler information"""
16
- import json
16
+ import glob
17
17
  import os
18
18
  import stat
19
19
 
20
20
  from mindspore.version import __version__ as ms_version
21
- from mindspore.profiler.common.validator.validate_path import validate_and_normalize_path
21
+ from mindspore.profiler.parser.ascend_analysis.file_manager import FileManager
22
+ from mindspore import log as logger
22
23
 
23
24
 
24
25
  class ProfilerInfo:
@@ -31,6 +32,7 @@ class ProfilerInfo:
31
32
  _file_name = "profiler_info_{}.json"
32
33
  _file_path = ""
33
34
  _profiler_info_dict = dict()
35
+ JIT_LEVEL = "jit_level"
34
36
 
35
37
  @staticmethod
36
38
  def init_info(context_mode, rank_id):
@@ -130,12 +132,82 @@ class ProfilerInfo:
130
132
  """Get the profiler info."""
131
133
  return ProfilerInfo._profiler_info_dict
132
134
 
135
+ @staticmethod
136
+ def set_profiling_options(profiling_options):
137
+ """Set profiling options to profiler info dict"""
138
+ ProfilerInfo._profiler_info_dict["profiling_options"] = profiling_options
139
+
140
+ @staticmethod
141
+ def set_jit_level(jit_level):
142
+ """Set jit_level to profiler info dict"""
143
+ ProfilerInfo._profiler_info_dict[ProfilerInfo.JIT_LEVEL] = jit_level
144
+
145
+ @staticmethod
146
+ def set_data_simplification(data_simplification):
147
+ """
148
+ Function Description:
149
+ Set the data simplification to profiler info dict
150
+ Parameter:
151
+ data_simplification: Whether data simplification is enabled
152
+ """
153
+ ProfilerInfo._profiler_info_dict["data_simplification"] = data_simplification
154
+
133
155
  @staticmethod
134
156
  def save(output_path):
135
157
  """Save the profiler info to file."""
136
158
  ProfilerInfo._file_path = os.path.join(output_path, ProfilerInfo._file_name)
137
- ProfilerInfo._file_path = validate_and_normalize_path(ProfilerInfo._file_path)
138
- with os.fdopen(os.open(ProfilerInfo._file_path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600),
139
- 'w') as json_file:
140
- json.dump(ProfilerInfo._profiler_info_dict, json_file)
159
+ FileManager.create_json_file(output_path, ProfilerInfo._profiler_info_dict, ProfilerInfo._file_name, indent=4)
141
160
  os.chmod(ProfilerInfo._file_path, stat.S_IREAD | stat.S_IWRITE)
161
+
162
+ @staticmethod
163
+ def load_profiler_info_dict(input_path):
164
+ """Load the profiler info from input path."""
165
+ ProfilerInfo._file_path = os.path.join(input_path, ProfilerInfo._file_name)
166
+ try:
167
+ load_info_dict = FileManager.read_json_file(ProfilerInfo._file_path)
168
+ except RuntimeError as err:
169
+ logger.warning(f"Cannot read file: {ProfilerInfo._file_path}, Error: {err}")
170
+ return
171
+ if not load_info_dict:
172
+ msg = f"Offline analysis failed load the ProfilerInfo._profiler_info_dict from: {ProfilerInfo._file_path}"
173
+ logger.warning(msg)
174
+ return
175
+ ProfilerInfo._profiler_info_dict = load_info_dict
176
+ os.chmod(ProfilerInfo._file_path, stat.S_IREAD | stat.S_IWRITE)
177
+
178
+ @staticmethod
179
+ def get_rank_id(profiler_dir: str):
180
+ """
181
+ Function Description:
182
+ Get rank id from profiler_info_*.json
183
+ Parameter:
184
+ profiler_dir: the directory path of profiler data, eg: rank_0/profiler
185
+ Return:
186
+ str type rank id
187
+ """
188
+ prof_info_path = os.path.join(profiler_dir, "profiler_info_*.json")
189
+ prof_info_path = glob.glob(prof_info_path)
190
+ if not prof_info_path:
191
+ logger.warning("Cannot find profiler_info.json in the profiler directory.")
192
+ return "-1"
193
+
194
+ info_data = FileManager.read_json_file(prof_info_path[0])
195
+ return info_data.get("rank_id", "-1")
196
+
197
+ @staticmethod
198
+ def get_device_id(prof_dir: str):
199
+ """
200
+ Function Description:
201
+ Get device id from PROF_XXX dir
202
+ Parameter:
203
+ prof_dir: the directory path of PROF_XXX
204
+ Return:
205
+ str type device id
206
+ """
207
+ device_dir = os.path.join(prof_dir, "device_*")
208
+ device_dir = glob.glob(device_dir)
209
+ if not device_dir:
210
+ logger.warning("Cannot find device_XXX in the %s.", prof_dir)
211
+ return "-1"
212
+
213
+ return device_dir[0].split("device_")[-1]
@@ -0,0 +1,153 @@
1
+ # Copyright 2020-2024 Huawei Technologies Co., Ltd
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # ============================================================================
15
+ """Profiling api file."""
16
+ from mindspore.profiler.common.registry import PROFILERS
17
+ from mindspore.profiler.common.constant import DeviceTarget
18
+ from mindspore.profiler.common.constant import ProfilerLevel
19
+ from mindspore.profiler.platform_profiler.prof_context import ProfContext
20
+
21
+
22
+ class NewProfiler:
23
+ """
24
+ Refactor profiler
25
+ """
26
+
27
+ def __init__(
28
+ self,
29
+ output_path: str = "./data",
30
+ profiler_level: ProfilerLevel = None,
31
+ op_time: bool = True,
32
+ profile_communication: bool = False,
33
+ profile_memory: bool = False,
34
+ parallel_strategy: bool = False,
35
+ start_profile: bool = True,
36
+ aicore_metrics: int = 0,
37
+ l2_cache: bool = False,
38
+ hbm_ddr: bool = False,
39
+ pcie: bool = False,
40
+ sync_enable: bool = True,
41
+ data_process: bool = False,
42
+ timeline_limit: int = 500,
43
+ profile_framework: str = None,
44
+ with_stack: bool = False,
45
+ data_simplification: bool = True,
46
+ **kwargs) -> None:
47
+
48
+ self._prof_context = ProfContext(
49
+ output_path=output_path,
50
+ profiler_level=profiler_level,
51
+ op_time=op_time,
52
+ profile_communication=profile_communication,
53
+ profile_memory=profile_memory,
54
+ parallel_strategy=parallel_strategy,
55
+ start_profile=start_profile,
56
+ aicore_metrics=aicore_metrics,
57
+ l2_cache=l2_cache,
58
+ hbm_ddr=hbm_ddr,
59
+ pcie=pcie,
60
+ sync_enable=sync_enable,
61
+ data_process=data_process,
62
+ timeline_limit=timeline_limit,
63
+ profile_framework=profile_framework,
64
+ with_stack=with_stack,
65
+ data_simplification=data_simplification
66
+ )
67
+
68
+ self._has_started = False
69
+
70
+ self._cpu_profiler = PROFILERS.get_modules().get(DeviceTarget.CPU.value)(
71
+ op_time=self._prof_context.op_time,
72
+ with_stack=self._prof_context.with_stack,
73
+ data_process=self._prof_context.data_process,
74
+ output_path=self._prof_context.output_path,
75
+ profile_memory=self._prof_context.profile_memory,
76
+ profile_framework=self._prof_context.profile_framework
77
+ )
78
+
79
+ self._device_target = self._prof_context.device_target
80
+ self._device_profiler = PROFILERS.get_modules().get(self._device_target)(
81
+ self._prof_context.get_args()
82
+ )
83
+
84
+ def start(self) -> None:
85
+ """
86
+ Used for Ascend, GPU, start profiling. Profiling can be turned on based on step and epoch.
87
+ """
88
+ if not self._has_started:
89
+ self._has_started = True
90
+ else:
91
+ raise RuntimeError("The profiler has already started. Do not turn on again in the open state.")
92
+
93
+ self._cpu_profiler.start()
94
+ self._device_profiler.start()
95
+
96
+ def stop(self) -> None:
97
+ """
98
+ Used for Ascend, GPU, stop profiling. Profiling can be turned off based on step and epoch.
99
+ """
100
+ if self._has_started:
101
+ self._has_started = False
102
+ else:
103
+ raise RuntimeError("The profiler has not started, so can not stop. Please call the start() method "
104
+ "before calling the stop() method.")
105
+
106
+ self._cpu_profiler.stop()
107
+ self._device_profiler.stop()
108
+
109
+ def analyse(self, offline_path=None, pretty=False, step_list=None, mode="sync") -> None:
110
+ """
111
+ Collect and analyze training performance data, support calls during and after training. The example shows above.
112
+
113
+ Args:
114
+ offline_path (Union[str, None], optional): The data path which need to be analyzed with offline mode.
115
+ Offline mode isused in abnormal exit scenario. This parameter should be set to ``None``
116
+ for online mode. Default: ``None``.
117
+ pretty (bool, optional): Whether to pretty json files. Default: ``False``.
118
+ step_list (list, optional): A list of steps that need to be analyzed. Default: ``None``.
119
+ By default, all steps will be analyzed.
120
+ mode (str, optional): Analysis mode, it must be one of ["sync", "async"]. Default: ``sync``.
121
+
122
+ - sync: analyse data in current process, it will block the current process.
123
+ - async: analyse data in subprocess, it will not the current process.Since the parsing process
124
+ will take up extra CPU resources, please enable this mode according to the actual resource situation.
125
+
126
+ """
127
+ self._cpu_profiler.stop(offline_path, pretty, step_list)
128
+ self._device_profiler.stop(offline_path, pretty, step_list, mode)
129
+
130
+ def op_analyse(self, op_name, device_id=None) -> None:
131
+ """
132
+ Profiler users can use this interface to obtain operator performance data.
133
+
134
+ Args:
135
+ op_name (str or list): The primitive operator name to query.
136
+ device_id (int, optional): ID of the target device. This parameter is optional during network training or
137
+ inference, and users can use device_id parameter to specify which card operator performance data to
138
+ parse. If this interface is used for offline data parsing, Default: ``0`` .
139
+ """
140
+
141
+ @classmethod
142
+ def offline_analyse(cls, path: str, pretty=False, step_list=None) -> None:
143
+ """
144
+ Analyze training performance data offline, which is invoked after performance data collection is completed.
145
+
146
+ Args:
147
+ path (str): The profiling data path which need to be analyzed offline.
148
+ There needs to be a profiler directory in this path.
149
+ pretty (bool, optional): Whether to pretty json files. Default: ``False``.
150
+ step_list (list, optional): A list of steps that need to be analyzed. Default: ``None``.
151
+ By default, all steps will be analyzed.
152
+ """
153
+ return