mindspore 2.3.0__cp310-cp310-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.
Files changed (1400) hide show
  1. mindspore/.commit_id +1 -0
  2. mindspore/ConcurrencyCheck.dll +0 -0
  3. mindspore/CppBuildInsights.dll +0 -0
  4. mindspore/CppCoreCheck.dll +0 -0
  5. mindspore/EnumIndex.dll +0 -0
  6. mindspore/EspXEngine.dll +0 -0
  7. mindspore/HResultCheck.dll +0 -0
  8. mindspore/KernelTraceControl.dll +0 -0
  9. mindspore/LocalESPC.dll +0 -0
  10. mindspore/Microsoft.Diagnostics.Tracing.EventSource.dll +0 -0
  11. mindspore/Microsoft.VisualStudio.RemoteControl.dll +0 -0
  12. mindspore/Microsoft.VisualStudio.Telemetry.dll +0 -0
  13. mindspore/Microsoft.VisualStudio.Utilities.Internal.dll +0 -0
  14. mindspore/Newtonsoft.Json.dll +0 -0
  15. mindspore/System.Runtime.CompilerServices.Unsafe.dll +0 -0
  16. mindspore/VariantClear.dll +0 -0
  17. mindspore/__init__.py +51 -0
  18. mindspore/_c_dataengine.cp310-win_amd64.pyd +0 -0
  19. mindspore/_c_expression.cp310-win_amd64.pyd +0 -0
  20. mindspore/_c_mindrecord.cp310-win_amd64.pyd +0 -0
  21. mindspore/_check_jit_forbidden_api.py +106 -0
  22. mindspore/_checkparam.py +1378 -0
  23. mindspore/_extends/__init__.py +23 -0
  24. mindspore/_extends/builtin_operations.py +224 -0
  25. mindspore/_extends/graph_kernel/__init__.py +17 -0
  26. mindspore/_extends/graph_kernel/model/__init__.py +19 -0
  27. mindspore/_extends/graph_kernel/model/graph_parallel.py +311 -0
  28. mindspore/_extends/graph_kernel/model/graph_split.py +1348 -0
  29. mindspore/_extends/graph_kernel/model/model.py +553 -0
  30. mindspore/_extends/graph_kernel/model/model_builder.py +216 -0
  31. mindspore/_extends/graph_kernel/parallel_estimate.py +60 -0
  32. mindspore/_extends/graph_kernel/splitter.py +140 -0
  33. mindspore/_extends/graph_kernel/utils.py +28 -0
  34. mindspore/_extends/parallel_compile/__init__.py +19 -0
  35. mindspore/_extends/parallel_compile/akg_compiler/__init__.py +19 -0
  36. mindspore/_extends/parallel_compile/akg_compiler/akg_process.py +269 -0
  37. mindspore/_extends/parallel_compile/akg_compiler/build_tbe_kernel.py +529 -0
  38. mindspore/_extends/parallel_compile/akg_compiler/compiler.py +56 -0
  39. mindspore/_extends/parallel_compile/akg_compiler/gen_custom_op_files.py +96 -0
  40. mindspore/_extends/parallel_compile/akg_compiler/get_file_path.py +36 -0
  41. mindspore/_extends/parallel_compile/akg_compiler/tbe_topi.py +556 -0
  42. mindspore/_extends/parallel_compile/akg_compiler/util.py +159 -0
  43. mindspore/_extends/parse/__init__.py +49 -0
  44. mindspore/_extends/parse/compile_config.py +258 -0
  45. mindspore/_extends/parse/namespace.py +136 -0
  46. mindspore/_extends/parse/parser.py +1446 -0
  47. mindspore/_extends/parse/resources.py +213 -0
  48. mindspore/_extends/parse/standard_method.py +4437 -0
  49. mindspore/_extends/parse/trope.py +97 -0
  50. mindspore/_extends/pijit/__init__.py +23 -0
  51. mindspore/_extends/pijit/pijit_func_white_list.py +343 -0
  52. mindspore/_extends/remote/__init__.py +19 -0
  53. mindspore/_extends/remote/kernel_build_server.py +199 -0
  54. mindspore/_extends/remote/kernel_build_server_akg.py +55 -0
  55. mindspore/_extends/remote/kernel_build_server_akg_v2.py +55 -0
  56. mindspore/_extends/remote/kernel_build_server_ascend.py +75 -0
  57. mindspore/_extends/utils.py +68 -0
  58. mindspore/_install_custom.py +43 -0
  59. mindspore/_profiler.py +30 -0
  60. mindspore/amp.py +419 -0
  61. mindspore/atlprov.dll +0 -0
  62. mindspore/avcodec-59.dll +0 -0
  63. mindspore/avdevice-59.dll +0 -0
  64. mindspore/avfilter-8.dll +0 -0
  65. mindspore/avformat-59.dll +0 -0
  66. mindspore/avutil-57.dll +0 -0
  67. mindspore/boost/__init__.py +42 -0
  68. mindspore/boost/adasum.py +319 -0
  69. mindspore/boost/base.py +535 -0
  70. mindspore/boost/boost.py +400 -0
  71. mindspore/boost/boost_cell_wrapper.py +790 -0
  72. mindspore/boost/dim_reduce.py +323 -0
  73. mindspore/boost/grad_accumulation.py +79 -0
  74. mindspore/boost/grad_freeze.py +382 -0
  75. mindspore/boost/group_loss_scale_manager.py +166 -0
  76. mindspore/boost/less_batch_normalization.py +174 -0
  77. mindspore/c1.dll +0 -0
  78. mindspore/c1xx.dll +0 -0
  79. mindspore/c2.dll +0 -0
  80. mindspore/cfgpersist.dll +0 -0
  81. mindspore/clang_rt.asan_dbg_dynamic-x86_64.dll +0 -0
  82. mindspore/clang_rt.asan_dynamic-x86_64.dll +0 -0
  83. mindspore/common/__init__.py +84 -0
  84. mindspore/common/_auto_dynamic.py +68 -0
  85. mindspore/common/_decorator.py +50 -0
  86. mindspore/common/_jit_fallback_utils.py +110 -0
  87. mindspore/common/_monad.py +25 -0
  88. mindspore/common/_register_for_adapter.py +74 -0
  89. mindspore/common/_register_for_recompute.py +48 -0
  90. mindspore/common/_register_for_tensor.py +45 -0
  91. mindspore/common/_stub_tensor.py +210 -0
  92. mindspore/common/_utils.py +122 -0
  93. mindspore/common/api.py +2049 -0
  94. mindspore/common/auto_dynamic_shape.py +507 -0
  95. mindspore/common/dtype.py +422 -0
  96. mindspore/common/dump.py +131 -0
  97. mindspore/common/file_system.py +48 -0
  98. mindspore/common/generator.py +260 -0
  99. mindspore/common/hook_handle.py +155 -0
  100. mindspore/common/initializer.py +880 -0
  101. mindspore/common/jit_config.py +98 -0
  102. mindspore/common/lazy_inline.py +240 -0
  103. mindspore/common/mindir_util.py +111 -0
  104. mindspore/common/mutable.py +234 -0
  105. mindspore/common/no_inline.py +54 -0
  106. mindspore/common/np_dtype.py +25 -0
  107. mindspore/common/parameter.py +1048 -0
  108. mindspore/common/recompute.py +262 -0
  109. mindspore/common/seed.py +260 -0
  110. mindspore/common/sparse_tensor.py +1171 -0
  111. mindspore/common/symbol.py +122 -0
  112. mindspore/common/tensor.py +4859 -0
  113. mindspore/communication/__init__.py +37 -0
  114. mindspore/communication/_comm_helper.py +466 -0
  115. mindspore/communication/_hccl_management.py +297 -0
  116. mindspore/communication/comm_func.py +1140 -0
  117. mindspore/communication/management.py +673 -0
  118. mindspore/config/op_info.config +533 -0
  119. mindspore/context.py +1976 -0
  120. mindspore/d3dcompiler_47.dll +0 -0
  121. mindspore/dataset/__init__.py +90 -0
  122. mindspore/dataset/audio/__init__.py +61 -0
  123. mindspore/dataset/audio/transforms.py +3690 -0
  124. mindspore/dataset/audio/utils.py +386 -0
  125. mindspore/dataset/audio/validators.py +1172 -0
  126. mindspore/dataset/callback/__init__.py +20 -0
  127. mindspore/dataset/callback/ds_callback.py +368 -0
  128. mindspore/dataset/callback/validators.py +32 -0
  129. mindspore/dataset/core/__init__.py +13 -0
  130. mindspore/dataset/core/config.py +1088 -0
  131. mindspore/dataset/core/datatypes.py +101 -0
  132. mindspore/dataset/core/py_util_helpers.py +65 -0
  133. mindspore/dataset/core/validator_helpers.py +774 -0
  134. mindspore/dataset/debug/__init__.py +21 -0
  135. mindspore/dataset/debug/debug_hook.py +97 -0
  136. mindspore/dataset/debug/pre_defined_hook.py +67 -0
  137. mindspore/dataset/engine/__init__.py +124 -0
  138. mindspore/dataset/engine/cache_admin.py +47 -0
  139. mindspore/dataset/engine/cache_client.py +129 -0
  140. mindspore/dataset/engine/datasets.py +4554 -0
  141. mindspore/dataset/engine/datasets_audio.py +911 -0
  142. mindspore/dataset/engine/datasets_standard_format.py +493 -0
  143. mindspore/dataset/engine/datasets_text.py +2161 -0
  144. mindspore/dataset/engine/datasets_user_defined.py +1114 -0
  145. mindspore/dataset/engine/datasets_vision.py +4816 -0
  146. mindspore/dataset/engine/iterators.py +342 -0
  147. mindspore/dataset/engine/obs/__init__.py +23 -0
  148. mindspore/dataset/engine/obs/config_loader.py +68 -0
  149. mindspore/dataset/engine/obs/obs_mindrecord_dataset.py +508 -0
  150. mindspore/dataset/engine/obs/util.py +475 -0
  151. mindspore/dataset/engine/offload.py +596 -0
  152. mindspore/dataset/engine/queue.py +250 -0
  153. mindspore/dataset/engine/samplers.py +895 -0
  154. mindspore/dataset/engine/serializer_deserializer.py +159 -0
  155. mindspore/dataset/engine/validators.py +2875 -0
  156. mindspore/dataset/text/__init__.py +54 -0
  157. mindspore/dataset/text/transforms.py +1703 -0
  158. mindspore/dataset/text/utils.py +715 -0
  159. mindspore/dataset/text/validators.py +642 -0
  160. mindspore/dataset/transforms/__init__.py +48 -0
  161. mindspore/dataset/transforms/c_transforms.py +638 -0
  162. mindspore/dataset/transforms/py_transforms.py +393 -0
  163. mindspore/dataset/transforms/py_transforms_util.py +255 -0
  164. mindspore/dataset/transforms/transforms.py +1260 -0
  165. mindspore/dataset/transforms/validators.py +410 -0
  166. mindspore/dataset/utils/__init__.py +19 -0
  167. mindspore/dataset/utils/browse_dataset.py +190 -0
  168. mindspore/dataset/utils/line_reader.py +124 -0
  169. mindspore/dataset/vision/__init__.py +68 -0
  170. mindspore/dataset/vision/c_transforms.py +2641 -0
  171. mindspore/dataset/vision/py_transforms.py +2120 -0
  172. mindspore/dataset/vision/py_transforms_util.py +1660 -0
  173. mindspore/dataset/vision/transforms.py +7295 -0
  174. mindspore/dataset/vision/utils.py +863 -0
  175. mindspore/dataset/vision/validators.py +1482 -0
  176. mindspore/default_config.py +2 -0
  177. mindspore/dnnl.dll +0 -0
  178. mindspore/dpcmi.dll +0 -0
  179. mindspore/experimental/__init__.py +20 -0
  180. mindspore/experimental/map_parameter.py +309 -0
  181. mindspore/experimental/optim/__init__.py +40 -0
  182. mindspore/experimental/optim/adadelta.py +161 -0
  183. mindspore/experimental/optim/adagrad.py +168 -0
  184. mindspore/experimental/optim/adam.py +193 -0
  185. mindspore/experimental/optim/adamax.py +170 -0
  186. mindspore/experimental/optim/adamw.py +205 -0
  187. mindspore/experimental/optim/asgd.py +153 -0
  188. mindspore/experimental/optim/lr_scheduler.py +1371 -0
  189. mindspore/experimental/optim/nadam.py +157 -0
  190. mindspore/experimental/optim/optimizer.py +259 -0
  191. mindspore/experimental/optim/radam.py +194 -0
  192. mindspore/experimental/optim/rmsprop.py +154 -0
  193. mindspore/experimental/optim/rprop.py +164 -0
  194. mindspore/experimental/optim/sgd.py +156 -0
  195. mindspore/hal/__init__.py +40 -0
  196. mindspore/hal/_ascend.py +57 -0
  197. mindspore/hal/_base.py +57 -0
  198. mindspore/hal/_cpu.py +56 -0
  199. mindspore/hal/_gpu.py +57 -0
  200. mindspore/hal/device.py +356 -0
  201. mindspore/hal/event.py +179 -0
  202. mindspore/hal/memory.py +326 -0
  203. mindspore/hal/stream.py +339 -0
  204. mindspore/include/OWNERS +7 -0
  205. mindspore/include/api/allocator.h +97 -0
  206. mindspore/include/api/callback/callback.h +93 -0
  207. mindspore/include/api/callback/ckpt_saver.h +41 -0
  208. mindspore/include/api/callback/loss_monitor.h +33 -0
  209. mindspore/include/api/callback/lr_scheduler.h +51 -0
  210. mindspore/include/api/callback/time_monitor.h +34 -0
  211. mindspore/include/api/callback/train_accuracy.h +37 -0
  212. mindspore/include/api/cell.h +90 -0
  213. mindspore/include/api/cfg.h +82 -0
  214. mindspore/include/api/context.h +602 -0
  215. mindspore/include/api/data_type.h +47 -0
  216. mindspore/include/api/delegate.h +178 -0
  217. mindspore/include/api/delegate_api.h +75 -0
  218. mindspore/include/api/dual_abi_helper.h +208 -0
  219. mindspore/include/api/format.h +28 -0
  220. mindspore/include/api/graph.h +46 -0
  221. mindspore/include/api/kernel.h +58 -0
  222. mindspore/include/api/kernel_api.h +168 -0
  223. mindspore/include/api/metrics/accuracy.h +36 -0
  224. mindspore/include/api/metrics/metrics.h +41 -0
  225. mindspore/include/api/model.h +438 -0
  226. mindspore/include/api/model_group.h +79 -0
  227. mindspore/include/api/model_parallel_runner.h +168 -0
  228. mindspore/include/api/serialization.h +185 -0
  229. mindspore/include/api/status.h +192 -0
  230. mindspore/include/api/types.h +431 -0
  231. mindspore/include/api/visible.h +41 -0
  232. mindspore/include/c_api/context_c.h +179 -0
  233. mindspore/include/c_api/data_type_c.h +52 -0
  234. mindspore/include/c_api/format_c.h +46 -0
  235. mindspore/include/c_api/model_c.h +347 -0
  236. mindspore/include/c_api/ms/abstract.h +67 -0
  237. mindspore/include/c_api/ms/attribute.h +197 -0
  238. mindspore/include/c_api/ms/base/handle_types.h +43 -0
  239. mindspore/include/c_api/ms/base/macros.h +32 -0
  240. mindspore/include/c_api/ms/base/status.h +33 -0
  241. mindspore/include/c_api/ms/base/types.h +283 -0
  242. mindspore/include/c_api/ms/context.h +102 -0
  243. mindspore/include/c_api/ms/graph.h +160 -0
  244. mindspore/include/c_api/ms/node.h +606 -0
  245. mindspore/include/c_api/ms/tensor.h +161 -0
  246. mindspore/include/c_api/ms/value.h +84 -0
  247. mindspore/include/c_api/status_c.h +79 -0
  248. mindspore/include/c_api/tensor_c.h +146 -0
  249. mindspore/include/c_api/types_c.h +67 -0
  250. mindspore/include/dataset/config.h +163 -0
  251. mindspore/include/dataset/constants.h +363 -0
  252. mindspore/include/dataset/execute.h +196 -0
  253. mindspore/include/dataset/text.h +1092 -0
  254. mindspore/include/dataset/transforms.h +638 -0
  255. mindspore/include/dataset/vision.h +2125 -0
  256. mindspore/include/dataset/vision_ascend.h +206 -0
  257. mindspore/include/dataset/vision_lite.h +625 -0
  258. mindspore/jpeg62.dll +0 -0
  259. mindspore/log.py +633 -0
  260. mindspore/mindrecord/__init__.py +43 -0
  261. mindspore/mindrecord/common/__init__.py +17 -0
  262. mindspore/mindrecord/common/constant.py +20 -0
  263. mindspore/mindrecord/common/enums.py +44 -0
  264. mindspore/mindrecord/common/exceptions.py +311 -0
  265. mindspore/mindrecord/config.py +809 -0
  266. mindspore/mindrecord/filereader.py +174 -0
  267. mindspore/mindrecord/filewriter.py +705 -0
  268. mindspore/mindrecord/mindpage.py +210 -0
  269. mindspore/mindrecord/shardheader.py +141 -0
  270. mindspore/mindrecord/shardindexgenerator.py +74 -0
  271. mindspore/mindrecord/shardreader.py +117 -0
  272. mindspore/mindrecord/shardsegment.py +128 -0
  273. mindspore/mindrecord/shardutils.py +185 -0
  274. mindspore/mindrecord/shardwriter.py +237 -0
  275. mindspore/mindrecord/tools/__init__.py +17 -0
  276. mindspore/mindrecord/tools/cifar10.py +140 -0
  277. mindspore/mindrecord/tools/cifar100.py +153 -0
  278. mindspore/mindrecord/tools/cifar100_to_mr.py +185 -0
  279. mindspore/mindrecord/tools/cifar10_to_mr.py +177 -0
  280. mindspore/mindrecord/tools/csv_to_mr.py +200 -0
  281. mindspore/mindrecord/tools/imagenet_to_mr.py +206 -0
  282. mindspore/mindrecord/tools/mnist_to_mr.py +259 -0
  283. mindspore/mindrecord/tools/tfrecord_to_mr.py +360 -0
  284. mindspore/mindspore_backend.dll +0 -0
  285. mindspore/mindspore_common.dll +0 -0
  286. mindspore/mindspore_core.dll +0 -0
  287. mindspore/mindspore_glog.dll +0 -0
  288. mindspore/mindspore_np_dtype.dll +0 -0
  289. mindspore/mindspore_shared_lib.dll +0 -0
  290. mindspore/mint/__init__.py +1137 -0
  291. mindspore/mint/linalg/__init__.py +22 -0
  292. mindspore/mint/nn/__init__.py +512 -0
  293. mindspore/mint/nn/functional.py +573 -0
  294. mindspore/mint/optim/__init__.py +24 -0
  295. mindspore/mint/optim/adamw.py +185 -0
  296. mindspore/msobj140.dll +0 -0
  297. mindspore/mspdb140.dll +0 -0
  298. mindspore/mspdbcore.dll +0 -0
  299. mindspore/mspdbst.dll +0 -0
  300. mindspore/mspft140.dll +0 -0
  301. mindspore/msvcdis140.dll +0 -0
  302. mindspore/msvcp140.dll +0 -0
  303. mindspore/msvcp140_1.dll +0 -0
  304. mindspore/msvcp140_2.dll +0 -0
  305. mindspore/msvcp140_atomic_wait.dll +0 -0
  306. mindspore/msvcp140_codecvt_ids.dll +0 -0
  307. mindspore/multiprocessing/__init__.py +72 -0
  308. mindspore/nn/__init__.py +48 -0
  309. mindspore/nn/cell.py +2605 -0
  310. mindspore/nn/dynamic_lr.py +482 -0
  311. mindspore/nn/extend/__init__.py +29 -0
  312. mindspore/nn/extend/basic.py +140 -0
  313. mindspore/nn/extend/embedding.py +143 -0
  314. mindspore/nn/extend/layer/__init__.py +27 -0
  315. mindspore/nn/extend/layer/normalization.py +109 -0
  316. mindspore/nn/extend/pooling.py +117 -0
  317. mindspore/nn/grad/__init__.py +21 -0
  318. mindspore/nn/grad/cell_grad.py +196 -0
  319. mindspore/nn/layer/__init__.py +63 -0
  320. mindspore/nn/layer/activation.py +1655 -0
  321. mindspore/nn/layer/basic.py +1519 -0
  322. mindspore/nn/layer/channel_shuffle.py +90 -0
  323. mindspore/nn/layer/combined.py +248 -0
  324. mindspore/nn/layer/container.py +734 -0
  325. mindspore/nn/layer/conv.py +1505 -0
  326. mindspore/nn/layer/dense.py +204 -0
  327. mindspore/nn/layer/embedding.py +751 -0
  328. mindspore/nn/layer/embedding_service.py +531 -0
  329. mindspore/nn/layer/embedding_service_layer.py +393 -0
  330. mindspore/nn/layer/image.py +661 -0
  331. mindspore/nn/layer/math.py +1069 -0
  332. mindspore/nn/layer/normalization.py +1177 -0
  333. mindspore/nn/layer/padding.py +894 -0
  334. mindspore/nn/layer/pooling.py +2148 -0
  335. mindspore/nn/layer/rnn_cells.py +388 -0
  336. mindspore/nn/layer/rnns.py +849 -0
  337. mindspore/nn/layer/thor_layer.py +963 -0
  338. mindspore/nn/layer/timedistributed.py +155 -0
  339. mindspore/nn/layer/transformer.py +823 -0
  340. mindspore/nn/learning_rate_schedule.py +512 -0
  341. mindspore/nn/loss/__init__.py +36 -0
  342. mindspore/nn/loss/loss.py +2846 -0
  343. mindspore/nn/metrics.py +53 -0
  344. mindspore/nn/optim/__init__.py +44 -0
  345. mindspore/nn/optim/_dist_optimizer_registry.py +111 -0
  346. mindspore/nn/optim/ada_grad.py +217 -0
  347. mindspore/nn/optim/adadelta.py +206 -0
  348. mindspore/nn/optim/adafactor.py +448 -0
  349. mindspore/nn/optim/adam.py +1297 -0
  350. mindspore/nn/optim/adamax.py +220 -0
  351. mindspore/nn/optim/adasum.py +548 -0
  352. mindspore/nn/optim/asgd.py +216 -0
  353. mindspore/nn/optim/ftrl.py +401 -0
  354. mindspore/nn/optim/lamb.py +296 -0
  355. mindspore/nn/optim/lars.py +202 -0
  356. mindspore/nn/optim/lazyadam.py +533 -0
  357. mindspore/nn/optim/momentum.py +239 -0
  358. mindspore/nn/optim/optimizer.py +1034 -0
  359. mindspore/nn/optim/proximal_ada_grad.py +242 -0
  360. mindspore/nn/optim/rmsprop.py +264 -0
  361. mindspore/nn/optim/rprop.py +251 -0
  362. mindspore/nn/optim/sgd.py +237 -0
  363. mindspore/nn/optim/thor.py +1310 -0
  364. mindspore/nn/probability/__init__.py +22 -0
  365. mindspore/nn/probability/bijector/__init__.py +35 -0
  366. mindspore/nn/probability/bijector/bijector.py +337 -0
  367. mindspore/nn/probability/bijector/exp.py +65 -0
  368. mindspore/nn/probability/bijector/gumbel_cdf.py +144 -0
  369. mindspore/nn/probability/bijector/invert.py +126 -0
  370. mindspore/nn/probability/bijector/power_transform.py +196 -0
  371. mindspore/nn/probability/bijector/scalar_affine.py +167 -0
  372. mindspore/nn/probability/bijector/softplus.py +189 -0
  373. mindspore/nn/probability/bnn_layers/__init__.py +29 -0
  374. mindspore/nn/probability/bnn_layers/_util.py +46 -0
  375. mindspore/nn/probability/bnn_layers/bnn_cell_wrapper.py +112 -0
  376. mindspore/nn/probability/bnn_layers/conv_variational.py +267 -0
  377. mindspore/nn/probability/bnn_layers/dense_variational.py +302 -0
  378. mindspore/nn/probability/bnn_layers/layer_distribution.py +123 -0
  379. mindspore/nn/probability/distribution/__init__.py +56 -0
  380. mindspore/nn/probability/distribution/_utils/__init__.py +34 -0
  381. mindspore/nn/probability/distribution/_utils/custom_ops.py +96 -0
  382. mindspore/nn/probability/distribution/_utils/utils.py +362 -0
  383. mindspore/nn/probability/distribution/bernoulli.py +334 -0
  384. mindspore/nn/probability/distribution/beta.py +391 -0
  385. mindspore/nn/probability/distribution/categorical.py +435 -0
  386. mindspore/nn/probability/distribution/cauchy.py +383 -0
  387. mindspore/nn/probability/distribution/distribution.py +827 -0
  388. mindspore/nn/probability/distribution/exponential.py +350 -0
  389. mindspore/nn/probability/distribution/gamma.py +391 -0
  390. mindspore/nn/probability/distribution/geometric.py +335 -0
  391. mindspore/nn/probability/distribution/gumbel.py +257 -0
  392. mindspore/nn/probability/distribution/half_normal.py +133 -0
  393. mindspore/nn/probability/distribution/laplace.py +128 -0
  394. mindspore/nn/probability/distribution/log_normal.py +272 -0
  395. mindspore/nn/probability/distribution/logistic.py +379 -0
  396. mindspore/nn/probability/distribution/normal.py +336 -0
  397. mindspore/nn/probability/distribution/poisson.py +288 -0
  398. mindspore/nn/probability/distribution/student_t.py +149 -0
  399. mindspore/nn/probability/distribution/transformed_distribution.py +235 -0
  400. mindspore/nn/probability/distribution/uniform.py +375 -0
  401. mindspore/nn/reinforcement/__init__.py +24 -0
  402. mindspore/nn/reinforcement/_batch_read_write.py +142 -0
  403. mindspore/nn/reinforcement/_tensors_queue.py +152 -0
  404. mindspore/nn/reinforcement/tensor_array.py +145 -0
  405. mindspore/nn/sparse/__init__.py +23 -0
  406. mindspore/nn/sparse/sparse.py +147 -0
  407. mindspore/nn/wrap/__init__.py +49 -0
  408. mindspore/nn/wrap/cell_wrapper.py +979 -0
  409. mindspore/nn/wrap/grad_reducer.py +608 -0
  410. mindspore/nn/wrap/loss_scale.py +680 -0
  411. mindspore/numpy/__init__.py +121 -0
  412. mindspore/numpy/array_creations.py +2734 -0
  413. mindspore/numpy/array_ops.py +2625 -0
  414. mindspore/numpy/dtypes.py +185 -0
  415. mindspore/numpy/fft.py +431 -0
  416. mindspore/numpy/logic_ops.py +935 -0
  417. mindspore/numpy/math_ops.py +5910 -0
  418. mindspore/numpy/utils.py +214 -0
  419. mindspore/numpy/utils_const.py +565 -0
  420. mindspore/opencv_core452.dll +0 -0
  421. mindspore/opencv_imgcodecs452.dll +0 -0
  422. mindspore/opencv_imgproc452.dll +0 -0
  423. mindspore/ops/__init__.py +54 -0
  424. mindspore/ops/_constants.py +30 -0
  425. mindspore/ops/_grad_experimental/__init__.py +31 -0
  426. mindspore/ops/_grad_experimental/grad_array_ops.py +830 -0
  427. mindspore/ops/_grad_experimental/grad_base.py +143 -0
  428. mindspore/ops/_grad_experimental/grad_comm_ops.py +670 -0
  429. mindspore/ops/_grad_experimental/grad_debug_ops.py +31 -0
  430. mindspore/ops/_grad_experimental/grad_implementations.py +203 -0
  431. mindspore/ops/_grad_experimental/grad_inner_ops.py +79 -0
  432. mindspore/ops/_grad_experimental/grad_math_ops.py +824 -0
  433. mindspore/ops/_grad_experimental/grad_nn_ops.py +231 -0
  434. mindspore/ops/_grad_experimental/grad_quant_ops.py +238 -0
  435. mindspore/ops/_grad_experimental/grad_sparse.py +342 -0
  436. mindspore/ops/_grad_experimental/grad_sparse_ops.py +399 -0
  437. mindspore/ops/_grad_experimental/taylor_rule.py +220 -0
  438. mindspore/ops/_op_impl/__init__.py +23 -0
  439. mindspore/ops/_op_impl/_custom_op/__init__.py +39 -0
  440. mindspore/ops/_op_impl/_custom_op/_basic.py +158 -0
  441. mindspore/ops/_op_impl/_custom_op/batch_matmul_impl.py +279 -0
  442. mindspore/ops/_op_impl/_custom_op/batchnorm_fold.py +156 -0
  443. mindspore/ops/_op_impl/_custom_op/batchnorm_fold2.py +109 -0
  444. mindspore/ops/_op_impl/_custom_op/batchnorm_fold2_grad.py +125 -0
  445. mindspore/ops/_op_impl/_custom_op/batchnorm_fold2_grad_reduce.py +105 -0
  446. mindspore/ops/_op_impl/_custom_op/batchnorm_fold_grad.py +124 -0
  447. mindspore/ops/_op_impl/_custom_op/cholesky_trsm_impl.py +116 -0
  448. mindspore/ops/_op_impl/_custom_op/correction_mul.py +89 -0
  449. mindspore/ops/_op_impl/_custom_op/correction_mul_grad.py +196 -0
  450. mindspore/ops/_op_impl/_custom_op/dsd_back_impl.py +366 -0
  451. mindspore/ops/_op_impl/_custom_op/dsd_impl.py +162 -0
  452. mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perchannel.py +136 -0
  453. mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perchannel_grad.py +206 -0
  454. mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perchannel_grad_reduce.py +88 -0
  455. mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perlayer.py +128 -0
  456. mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perlayer_grad.py +199 -0
  457. mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perlayer_grad_reduce.py +88 -0
  458. mindspore/ops/_op_impl/_custom_op/fake_quant_perchannel.py +156 -0
  459. mindspore/ops/_op_impl/_custom_op/fake_quant_perchannel_grad.py +184 -0
  460. mindspore/ops/_op_impl/_custom_op/fake_quant_perlayer.py +143 -0
  461. mindspore/ops/_op_impl/_custom_op/fake_quant_perlayer_grad.py +169 -0
  462. mindspore/ops/_op_impl/_custom_op/fused_abs_max1_impl.py +548 -0
  463. mindspore/ops/_op_impl/_custom_op/img2col_impl.py +881 -0
  464. mindspore/ops/_op_impl/_custom_op/matmul_cube_dense_left_impl.py +278 -0
  465. mindspore/ops/_op_impl/_custom_op/matmul_cube_dense_right_impl.py +200 -0
  466. mindspore/ops/_op_impl/_custom_op/matmul_cube_fracz_left_cast_impl.py +334 -0
  467. mindspore/ops/_op_impl/_custom_op/matmul_cube_fracz_right_mul_impl.py +255 -0
  468. mindspore/ops/_op_impl/_custom_op/matmul_cube_impl.py +222 -0
  469. mindspore/ops/_op_impl/_custom_op/matmul_dds_grad_impl.py +644 -0
  470. mindspore/ops/_op_impl/_custom_op/matmul_dds_impl.py +488 -0
  471. mindspore/ops/_op_impl/_custom_op/matrix_combine_impl.py +87 -0
  472. mindspore/ops/_op_impl/_custom_op/minmax_update_perchannel.py +129 -0
  473. mindspore/ops/_op_impl/_custom_op/minmax_update_perlayer.py +121 -0
  474. mindspore/ops/_op_impl/_custom_op/transpose02314_impl.py +352 -0
  475. mindspore/ops/_op_impl/aicpu/__init__.py +441 -0
  476. mindspore/ops/_op_impl/aicpu/abs.py +36 -0
  477. mindspore/ops/_op_impl/aicpu/acos.py +32 -0
  478. mindspore/ops/_op_impl/aicpu/acos_grad.py +33 -0
  479. mindspore/ops/_op_impl/aicpu/acosh.py +34 -0
  480. mindspore/ops/_op_impl/aicpu/acosh_grad.py +35 -0
  481. mindspore/ops/_op_impl/aicpu/adaptive_avg_pool_2d.py +34 -0
  482. mindspore/ops/_op_impl/aicpu/adaptive_avg_pool_2d_grad.py +34 -0
  483. mindspore/ops/_op_impl/aicpu/adaptive_avg_pool_3d.py +39 -0
  484. mindspore/ops/_op_impl/aicpu/adaptive_avg_pool_3d_grad.py +39 -0
  485. mindspore/ops/_op_impl/aicpu/adaptive_max_pool_2d.py +37 -0
  486. mindspore/ops/_op_impl/aicpu/adaptive_max_pool_2d_grad.py +37 -0
  487. mindspore/ops/_op_impl/aicpu/adaptive_max_pool_3d.py +42 -0
  488. mindspore/ops/_op_impl/aicpu/adaptive_max_pool_3d_grad.py +152 -0
  489. mindspore/ops/_op_impl/aicpu/add.py +43 -0
  490. mindspore/ops/_op_impl/aicpu/add_n.py +41 -0
  491. mindspore/ops/_op_impl/aicpu/add_v2.py +40 -0
  492. mindspore/ops/_op_impl/aicpu/addcdiv.py +41 -0
  493. mindspore/ops/_op_impl/aicpu/addcmul.py +47 -0
  494. mindspore/ops/_op_impl/aicpu/adjust_contrastv2.py +32 -0
  495. mindspore/ops/_op_impl/aicpu/adjust_hue.py +31 -0
  496. mindspore/ops/_op_impl/aicpu/adjust_saturation.py +32 -0
  497. mindspore/ops/_op_impl/aicpu/affine_grid.py +33 -0
  498. mindspore/ops/_op_impl/aicpu/affine_grid_grad.py +35 -0
  499. mindspore/ops/_op_impl/aicpu/angle.py +31 -0
  500. mindspore/ops/_op_impl/aicpu/arg_max.py +75 -0
  501. mindspore/ops/_op_impl/aicpu/arg_min.py +75 -0
  502. mindspore/ops/_op_impl/aicpu/argmax_with_value.py +43 -0
  503. mindspore/ops/_op_impl/aicpu/argmin_with_value.py +43 -0
  504. mindspore/ops/_op_impl/aicpu/asin.py +32 -0
  505. mindspore/ops/_op_impl/aicpu/asin_grad.py +33 -0
  506. mindspore/ops/_op_impl/aicpu/asinh.py +34 -0
  507. mindspore/ops/_op_impl/aicpu/asinh_grad.py +35 -0
  508. mindspore/ops/_op_impl/aicpu/atanh.py +34 -0
  509. mindspore/ops/_op_impl/aicpu/avgpool_grad_v1.py +37 -0
  510. mindspore/ops/_op_impl/aicpu/avgpool_v1.py +36 -0
  511. mindspore/ops/_op_impl/aicpu/bartlett_window.py +36 -0
  512. mindspore/ops/_op_impl/aicpu/batch_matmul.py +43 -0
  513. mindspore/ops/_op_impl/aicpu/batch_norm_grad_grad.py +49 -0
  514. mindspore/ops/_op_impl/aicpu/bernoulli.py +48 -0
  515. mindspore/ops/_op_impl/aicpu/bessel_i0.py +31 -0
  516. mindspore/ops/_op_impl/aicpu/betainc.py +31 -0
  517. mindspore/ops/_op_impl/aicpu/bias_add.py +44 -0
  518. mindspore/ops/_op_impl/aicpu/bias_add_grad.py +42 -0
  519. mindspore/ops/_op_impl/aicpu/bincount.py +33 -0
  520. mindspore/ops/_op_impl/aicpu/blackman_window.py +36 -0
  521. mindspore/ops/_op_impl/aicpu/broadcast_to.py +58 -0
  522. mindspore/ops/_op_impl/aicpu/bucketize.py +34 -0
  523. mindspore/ops/_op_impl/aicpu/cache_swap_table.py +102 -0
  524. mindspore/ops/_op_impl/aicpu/cast.py +225 -0
  525. mindspore/ops/_op_impl/aicpu/cauchy.py +33 -0
  526. mindspore/ops/_op_impl/aicpu/channel_shuffle.py +40 -0
  527. mindspore/ops/_op_impl/aicpu/check_numerics.py +33 -0
  528. mindspore/ops/_op_impl/aicpu/cholesky.py +32 -0
  529. mindspore/ops/_op_impl/aicpu/cholesky_inverse.py +31 -0
  530. mindspore/ops/_op_impl/aicpu/cholesky_solve.py +33 -0
  531. mindspore/ops/_op_impl/aicpu/choleskygrad.py +32 -0
  532. mindspore/ops/_op_impl/aicpu/coalesce.py +37 -0
  533. mindspore/ops/_op_impl/aicpu/col2im.py +38 -0
  534. mindspore/ops/_op_impl/aicpu/combined_non_max_suppression.py +42 -0
  535. mindspore/ops/_op_impl/aicpu/compare_and_bitpack.py +37 -0
  536. mindspore/ops/_op_impl/aicpu/complex.py +32 -0
  537. mindspore/ops/_op_impl/aicpu/complex_abs.py +31 -0
  538. mindspore/ops/_op_impl/aicpu/compute_accidental_hits.py +44 -0
  539. mindspore/ops/_op_impl/aicpu/concat.py +57 -0
  540. mindspore/ops/_op_impl/aicpu/concat_offset.py +42 -0
  541. mindspore/ops/_op_impl/aicpu/concat_offset_v1.py +31 -0
  542. mindspore/ops/_op_impl/aicpu/conj.py +42 -0
  543. mindspore/ops/_op_impl/aicpu/conjugate_transpose.py +58 -0
  544. mindspore/ops/_op_impl/aicpu/cos.py +34 -0
  545. mindspore/ops/_op_impl/aicpu/cosh.py +34 -0
  546. mindspore/ops/_op_impl/aicpu/count_nonzero.py +43 -0
  547. mindspore/ops/_op_impl/aicpu/crop_and_resize.py +69 -0
  548. mindspore/ops/_op_impl/aicpu/crop_and_resize_grad_boxes.py +68 -0
  549. mindspore/ops/_op_impl/aicpu/crop_and_resize_grad_image.py +38 -0
  550. mindspore/ops/_op_impl/aicpu/cross.py +42 -0
  551. mindspore/ops/_op_impl/aicpu/csr_sparse_matrix_to_dense.py +48 -0
  552. mindspore/ops/_op_impl/aicpu/csr_sparse_matrix_to_sparse_tensor.py +51 -0
  553. mindspore/ops/_op_impl/aicpu/ctc_greedy_decoder.py +35 -0
  554. mindspore/ops/_op_impl/aicpu/ctc_loss_v2.py +43 -0
  555. mindspore/ops/_op_impl/aicpu/ctc_loss_v2_grad.py +45 -0
  556. mindspore/ops/_op_impl/aicpu/ctcloss.py +38 -0
  557. mindspore/ops/_op_impl/aicpu/cummax.py +41 -0
  558. mindspore/ops/_op_impl/aicpu/cumprod.py +58 -0
  559. mindspore/ops/_op_impl/aicpu/cumsum.py +58 -0
  560. mindspore/ops/_op_impl/aicpu/cumulative_logsumexp.py +36 -0
  561. mindspore/ops/_op_impl/aicpu/data_format_vec_permute.py +32 -0
  562. mindspore/ops/_op_impl/aicpu/deformable_offsets.py +38 -0
  563. mindspore/ops/_op_impl/aicpu/deformable_offsets_grad.py +43 -0
  564. mindspore/ops/_op_impl/aicpu/dense_to_csr_sparse_matrix.py +49 -0
  565. mindspore/ops/_op_impl/aicpu/dense_to_dense_set_operation.py +45 -0
  566. mindspore/ops/_op_impl/aicpu/dense_to_sparse_set_operation.py +48 -0
  567. mindspore/ops/_op_impl/aicpu/depth_to_space.py +44 -0
  568. mindspore/ops/_op_impl/aicpu/diag.py +36 -0
  569. mindspore/ops/_op_impl/aicpu/diag_part.py +36 -0
  570. mindspore/ops/_op_impl/aicpu/diagonal.py +35 -0
  571. mindspore/ops/_op_impl/aicpu/digamma.py +31 -0
  572. mindspore/ops/_op_impl/aicpu/div.py +41 -0
  573. mindspore/ops/_op_impl/aicpu/div_no_nan.py +35 -0
  574. mindspore/ops/_op_impl/aicpu/dropout2d.py +42 -0
  575. mindspore/ops/_op_impl/aicpu/dropout3d.py +42 -0
  576. mindspore/ops/_op_impl/aicpu/dropout_genmask.py +41 -0
  577. mindspore/ops/_op_impl/aicpu/dropout_genmask_v3.py +32 -0
  578. mindspore/ops/_op_impl/aicpu/dynamic_stitch.py +42 -0
  579. mindspore/ops/_op_impl/aicpu/edit_distance.py +56 -0
  580. mindspore/ops/_op_impl/aicpu/eig.py +35 -0
  581. mindspore/ops/_op_impl/aicpu/embedding_lookup.py +102 -0
  582. mindspore/ops/_op_impl/aicpu/end_of_sequence.py +30 -0
  583. mindspore/ops/_op_impl/aicpu/environ_create.py +28 -0
  584. mindspore/ops/_op_impl/aicpu/environ_destroy_all.py +28 -0
  585. mindspore/ops/_op_impl/aicpu/environ_get.py +41 -0
  586. mindspore/ops/_op_impl/aicpu/environ_set.py +40 -0
  587. mindspore/ops/_op_impl/aicpu/eps.py +32 -0
  588. mindspore/ops/_op_impl/aicpu/equal.py +41 -0
  589. mindspore/ops/_op_impl/aicpu/exp.py +37 -0
  590. mindspore/ops/_op_impl/aicpu/expand.py +45 -0
  591. mindspore/ops/_op_impl/aicpu/expand_dims.py +42 -0
  592. mindspore/ops/_op_impl/aicpu/expm1.py +34 -0
  593. mindspore/ops/_op_impl/aicpu/extract_glimpse.py +35 -0
  594. mindspore/ops/_op_impl/aicpu/eye.py +44 -0
  595. mindspore/ops/_op_impl/aicpu/fft_with_size.py +47 -0
  596. mindspore/ops/_op_impl/aicpu/fill_diagonal.py +39 -0
  597. mindspore/ops/_op_impl/aicpu/fill_v2.py +58 -0
  598. mindspore/ops/_op_impl/aicpu/flatten.py +43 -0
  599. mindspore/ops/_op_impl/aicpu/floor_div.py +38 -0
  600. mindspore/ops/_op_impl/aicpu/fmax.py +36 -0
  601. mindspore/ops/_op_impl/aicpu/fmin.py +37 -0
  602. mindspore/ops/_op_impl/aicpu/fractional_avg_pool.py +41 -0
  603. mindspore/ops/_op_impl/aicpu/fractional_avg_pool_grad.py +41 -0
  604. mindspore/ops/_op_impl/aicpu/fractional_max_pool.py +41 -0
  605. mindspore/ops/_op_impl/aicpu/fractional_max_pool3d_grad_with_fixed_ksize.py +43 -0
  606. mindspore/ops/_op_impl/aicpu/fractional_max_pool3d_with_fixed_ksize.py +65 -0
  607. mindspore/ops/_op_impl/aicpu/fractional_max_pool_grad.py +42 -0
  608. mindspore/ops/_op_impl/aicpu/fractional_max_pool_grad_with_fixed_ksize.py +42 -0
  609. mindspore/ops/_op_impl/aicpu/fractional_max_pool_with_fixed_ksize.py +49 -0
  610. mindspore/ops/_op_impl/aicpu/fse_decode.py +43 -0
  611. mindspore/ops/_op_impl/aicpu/fused_sparse_adam.py +46 -0
  612. mindspore/ops/_op_impl/aicpu/fused_sparse_ftrl.py +41 -0
  613. mindspore/ops/_op_impl/aicpu/fused_sparse_lazy_adam.py +46 -0
  614. mindspore/ops/_op_impl/aicpu/fused_sparse_proximal_adagrad.py +39 -0
  615. mindspore/ops/_op_impl/aicpu/gamma.py +38 -0
  616. mindspore/ops/_op_impl/aicpu/gather.py +46 -0
  617. mindspore/ops/_op_impl/aicpu/gather_d.py +79 -0
  618. mindspore/ops/_op_impl/aicpu/gather_d_grad_v2.py +79 -0
  619. mindspore/ops/_op_impl/aicpu/gather_grad.py +54 -0
  620. mindspore/ops/_op_impl/aicpu/gather_nd.py +56 -0
  621. mindspore/ops/_op_impl/aicpu/gcd.py +32 -0
  622. mindspore/ops/_op_impl/aicpu/generate_eod_mask.py +38 -0
  623. mindspore/ops/_op_impl/aicpu/geqrf.py +32 -0
  624. mindspore/ops/_op_impl/aicpu/get_next.py +39 -0
  625. mindspore/ops/_op_impl/aicpu/glu.py +33 -0
  626. mindspore/ops/_op_impl/aicpu/glu_grad.py +34 -0
  627. mindspore/ops/_op_impl/aicpu/greater.py +41 -0
  628. mindspore/ops/_op_impl/aicpu/greater_equal.py +41 -0
  629. mindspore/ops/_op_impl/aicpu/grid_sampler_2d.py +35 -0
  630. mindspore/ops/_op_impl/aicpu/grid_sampler_2d_grad.py +38 -0
  631. mindspore/ops/_op_impl/aicpu/grid_sampler_3d.py +34 -0
  632. mindspore/ops/_op_impl/aicpu/grid_sampler_3d_grad.py +38 -0
  633. mindspore/ops/_op_impl/aicpu/hamming_window.py +57 -0
  634. mindspore/ops/_op_impl/aicpu/hard_sigmoid.py +32 -0
  635. mindspore/ops/_op_impl/aicpu/hard_sigmoid_grad.py +33 -0
  636. mindspore/ops/_op_impl/aicpu/heaviside.py +40 -0
  637. mindspore/ops/_op_impl/aicpu/histogram.py +35 -0
  638. mindspore/ops/_op_impl/aicpu/hsv_to_rgb.py +32 -0
  639. mindspore/ops/_op_impl/aicpu/hypot.py +32 -0
  640. mindspore/ops/_op_impl/aicpu/identity.py +42 -0
  641. mindspore/ops/_op_impl/aicpu/identity_n.py +41 -0
  642. mindspore/ops/_op_impl/aicpu/igamma.py +30 -0
  643. mindspore/ops/_op_impl/aicpu/igammac.py +30 -0
  644. mindspore/ops/_op_impl/aicpu/igammagrada.py +30 -0
  645. mindspore/ops/_op_impl/aicpu/im2col.py +43 -0
  646. mindspore/ops/_op_impl/aicpu/imag.py +31 -0
  647. mindspore/ops/_op_impl/aicpu/index_fill.py +54 -0
  648. mindspore/ops/_op_impl/aicpu/index_put.py +50 -0
  649. mindspore/ops/_op_impl/aicpu/init_data_set_queue.py +27 -0
  650. mindspore/ops/_op_impl/aicpu/inplace_index_add.py +39 -0
  651. mindspore/ops/_op_impl/aicpu/instance_norm_v2.py +41 -0
  652. mindspore/ops/_op_impl/aicpu/instance_norm_v2_grad.py +44 -0
  653. mindspore/ops/_op_impl/aicpu/is_finite.py +40 -0
  654. mindspore/ops/_op_impl/aicpu/is_inf.py +31 -0
  655. mindspore/ops/_op_impl/aicpu/is_nan.py +31 -0
  656. mindspore/ops/_op_impl/aicpu/kldivloss.py +34 -0
  657. mindspore/ops/_op_impl/aicpu/kldivlossgrad.py +35 -0
  658. mindspore/ops/_op_impl/aicpu/layer_norm_grad_grad.py +47 -0
  659. mindspore/ops/_op_impl/aicpu/lcm.py +32 -0
  660. mindspore/ops/_op_impl/aicpu/left_shift.py +38 -0
  661. mindspore/ops/_op_impl/aicpu/less.py +41 -0
  662. mindspore/ops/_op_impl/aicpu/less_equal.py +41 -0
  663. mindspore/ops/_op_impl/aicpu/lgamma.py +33 -0
  664. mindspore/ops/_op_impl/aicpu/linear_sum_assignment.py +57 -0
  665. mindspore/ops/_op_impl/aicpu/linspace.py +33 -0
  666. mindspore/ops/_op_impl/aicpu/list_diff.py +50 -0
  667. mindspore/ops/_op_impl/aicpu/log.py +37 -0
  668. mindspore/ops/_op_impl/aicpu/log1p.py +34 -0
  669. mindspore/ops/_op_impl/aicpu/log_matrix_determinant.py +31 -0
  670. mindspore/ops/_op_impl/aicpu/log_normal_reverse.py +33 -0
  671. mindspore/ops/_op_impl/aicpu/log_uniform_candidate_sampler.py +37 -0
  672. mindspore/ops/_op_impl/aicpu/logical_xor.py +30 -0
  673. mindspore/ops/_op_impl/aicpu/logit.py +33 -0
  674. mindspore/ops/_op_impl/aicpu/logit_grad.py +34 -0
  675. mindspore/ops/_op_impl/aicpu/logspace.py +36 -0
  676. mindspore/ops/_op_impl/aicpu/lower_bound.py +47 -0
  677. mindspore/ops/_op_impl/aicpu/lstsq.py +34 -0
  678. mindspore/ops/_op_impl/aicpu/lu.py +39 -0
  679. mindspore/ops/_op_impl/aicpu/lu_solve.py +32 -0
  680. mindspore/ops/_op_impl/aicpu/lu_unpack.py +114 -0
  681. mindspore/ops/_op_impl/aicpu/lu_unpack_grad.py +49 -0
  682. mindspore/ops/_op_impl/aicpu/masked_fill.py +42 -0
  683. mindspore/ops/_op_impl/aicpu/masked_scatter.py +40 -0
  684. mindspore/ops/_op_impl/aicpu/masked_select.py +31 -0
  685. mindspore/ops/_op_impl/aicpu/masked_select_grad.py +35 -0
  686. mindspore/ops/_op_impl/aicpu/matmul.py +39 -0
  687. mindspore/ops/_op_impl/aicpu/matrix_band_part.py +59 -0
  688. mindspore/ops/_op_impl/aicpu/matrix_determinant.py +30 -0
  689. mindspore/ops/_op_impl/aicpu/matrix_diag_part_v3.py +54 -0
  690. mindspore/ops/_op_impl/aicpu/matrix_diag_v3.py +56 -0
  691. mindspore/ops/_op_impl/aicpu/matrix_exp.py +34 -0
  692. mindspore/ops/_op_impl/aicpu/matrix_inverse.py +31 -0
  693. mindspore/ops/_op_impl/aicpu/matrix_logarithm.py +31 -0
  694. mindspore/ops/_op_impl/aicpu/matrix_power.py +37 -0
  695. mindspore/ops/_op_impl/aicpu/matrix_set_diag_v3.py +54 -0
  696. mindspore/ops/_op_impl/aicpu/matrix_solve.py +35 -0
  697. mindspore/ops/_op_impl/aicpu/matrix_solve_ls.py +36 -0
  698. mindspore/ops/_op_impl/aicpu/matrix_triangular_solve.py +36 -0
  699. mindspore/ops/_op_impl/aicpu/max_pool3d_grad_with_argmax.py +60 -0
  700. mindspore/ops/_op_impl/aicpu/max_pool3d_with_argmax.py +59 -0
  701. mindspore/ops/_op_impl/aicpu/max_unpool2d.py +57 -0
  702. mindspore/ops/_op_impl/aicpu/max_unpool2d_grad.py +58 -0
  703. mindspore/ops/_op_impl/aicpu/max_unpool3d.py +57 -0
  704. mindspore/ops/_op_impl/aicpu/max_unpool3d_grad.py +58 -0
  705. mindspore/ops/_op_impl/aicpu/maximum_grad_grad.py +40 -0
  706. mindspore/ops/_op_impl/aicpu/maxpool_grad_v1.py +46 -0
  707. mindspore/ops/_op_impl/aicpu/maxpool_v1.py +42 -0
  708. mindspore/ops/_op_impl/aicpu/median.py +39 -0
  709. mindspore/ops/_op_impl/aicpu/median_grad.py +45 -0
  710. mindspore/ops/_op_impl/aicpu/meshgrid.py +41 -0
  711. mindspore/ops/_op_impl/aicpu/minimum_grad_grad.py +40 -0
  712. mindspore/ops/_op_impl/aicpu/mirror_pad.py +50 -0
  713. mindspore/ops/_op_impl/aicpu/mirror_pad_grad.py +48 -0
  714. mindspore/ops/_op_impl/aicpu/mul.py +43 -0
  715. mindspore/ops/_op_impl/aicpu/mul_no_nan.py +42 -0
  716. mindspore/ops/_op_impl/aicpu/multi_margin_loss.py +37 -0
  717. mindspore/ops/_op_impl/aicpu/multi_margin_loss_grad.py +41 -0
  718. mindspore/ops/_op_impl/aicpu/multilabel_margin_loss_grad.py +37 -0
  719. mindspore/ops/_op_impl/aicpu/multinomial.py +47 -0
  720. mindspore/ops/_op_impl/aicpu/multinomial_with_replacement.py +35 -0
  721. mindspore/ops/_op_impl/aicpu/mvlgamma.py +32 -0
  722. mindspore/ops/_op_impl/aicpu/mvlgamma_grad.py +33 -0
  723. mindspore/ops/_op_impl/aicpu/nan_to_num.py +34 -0
  724. mindspore/ops/_op_impl/aicpu/neg.py +36 -0
  725. mindspore/ops/_op_impl/aicpu/nextafter.py +32 -0
  726. mindspore/ops/_op_impl/aicpu/nllloss.py +38 -0
  727. mindspore/ops/_op_impl/aicpu/nllloss_grad.py +39 -0
  728. mindspore/ops/_op_impl/aicpu/no_repeat_ngram.py +34 -0
  729. mindspore/ops/_op_impl/aicpu/non_deterministic_ints.py +33 -0
  730. mindspore/ops/_op_impl/aicpu/non_max_suppression.py +36 -0
  731. mindspore/ops/_op_impl/aicpu/non_max_suppression_with_overlaps.py +35 -0
  732. mindspore/ops/_op_impl/aicpu/non_zero.py +43 -0
  733. mindspore/ops/_op_impl/aicpu/not_equal.py +39 -0
  734. mindspore/ops/_op_impl/aicpu/nth_element.py +39 -0
  735. mindspore/ops/_op_impl/aicpu/nuclear_norm.py +33 -0
  736. mindspore/ops/_op_impl/aicpu/one_hot.py +116 -0
  737. mindspore/ops/_op_impl/aicpu/ones_like.py +39 -0
  738. mindspore/ops/_op_impl/aicpu/orgqr.py +34 -0
  739. mindspore/ops/_op_impl/aicpu/pad_and_shift.py +33 -0
  740. mindspore/ops/_op_impl/aicpu/pad_v3.py +61 -0
  741. mindspore/ops/_op_impl/aicpu/pad_v3_grad.py +59 -0
  742. mindspore/ops/_op_impl/aicpu/padding.py +41 -0
  743. mindspore/ops/_op_impl/aicpu/parameterized_truncated_normal.py +54 -0
  744. mindspore/ops/_op_impl/aicpu/pdist_grad.py +33 -0
  745. mindspore/ops/_op_impl/aicpu/poisson.py +37 -0
  746. mindspore/ops/_op_impl/aicpu/polar.py +32 -0
  747. mindspore/ops/_op_impl/aicpu/polygamma.py +34 -0
  748. mindspore/ops/_op_impl/aicpu/pow.py +39 -0
  749. mindspore/ops/_op_impl/aicpu/print_tensor.py +39 -0
  750. mindspore/ops/_op_impl/aicpu/priority_replay_buffer.py +113 -0
  751. mindspore/ops/_op_impl/aicpu/qr.py +36 -0
  752. mindspore/ops/_op_impl/aicpu/quant_dtype_cast.py +40 -0
  753. mindspore/ops/_op_impl/aicpu/quantile.py +35 -0
  754. mindspore/ops/_op_impl/aicpu/ragged_range.py +49 -0
  755. mindspore/ops/_op_impl/aicpu/ragged_tensor_to_sparse.py +73 -0
  756. mindspore/ops/_op_impl/aicpu/ragged_tensor_to_tensor.py +74 -0
  757. mindspore/ops/_op_impl/aicpu/random_categorical.py +68 -0
  758. mindspore/ops/_op_impl/aicpu/random_choice_with_mask.py +36 -0
  759. mindspore/ops/_op_impl/aicpu/random_gamma.py +38 -0
  760. mindspore/ops/_op_impl/aicpu/random_poisson.py +134 -0
  761. mindspore/ops/_op_impl/aicpu/random_shuffle.py +47 -0
  762. mindspore/ops/_op_impl/aicpu/randperm.py +38 -0
  763. mindspore/ops/_op_impl/aicpu/randperm_v2.py +41 -0
  764. mindspore/ops/_op_impl/aicpu/range.py +36 -0
  765. mindspore/ops/_op_impl/aicpu/range_v2.py +35 -0
  766. mindspore/ops/_op_impl/aicpu/real.py +31 -0
  767. mindspore/ops/_op_impl/aicpu/real_div.py +40 -0
  768. mindspore/ops/_op_impl/aicpu/reciprocal.py +34 -0
  769. mindspore/ops/_op_impl/aicpu/reciprocal_grad.py +35 -0
  770. mindspore/ops/_op_impl/aicpu/reduce_mean.py +57 -0
  771. mindspore/ops/_op_impl/aicpu/reduce_prod.py +57 -0
  772. mindspore/ops/_op_impl/aicpu/reduce_sum.py +57 -0
  773. mindspore/ops/_op_impl/aicpu/relu_grad_v3.py +41 -0
  774. mindspore/ops/_op_impl/aicpu/relu_v3.py +38 -0
  775. mindspore/ops/_op_impl/aicpu/reservoir_replay_buffer.py +96 -0
  776. mindspore/ops/_op_impl/aicpu/reshape.py +42 -0
  777. mindspore/ops/_op_impl/aicpu/resize_area.py +40 -0
  778. mindspore/ops/_op_impl/aicpu/resize_bicubic.py +20 -0
  779. mindspore/ops/_op_impl/aicpu/resize_bicubic_grad.py +19 -0
  780. mindspore/ops/_op_impl/aicpu/resize_bilinear.py +32 -0
  781. mindspore/ops/_op_impl/aicpu/resize_bilinear_grad.py +32 -0
  782. mindspore/ops/_op_impl/aicpu/resize_nearest_neighbor_v2.py +36 -0
  783. mindspore/ops/_op_impl/aicpu/resize_nearest_neighbor_v2_grad.py +35 -0
  784. mindspore/ops/_op_impl/aicpu/resize_v2.py +68 -0
  785. mindspore/ops/_op_impl/aicpu/resize_v2_grad.py +68 -0
  786. mindspore/ops/_op_impl/aicpu/reverse_sequence.py +55 -0
  787. mindspore/ops/_op_impl/aicpu/reversev2.py +54 -0
  788. mindspore/ops/_op_impl/aicpu/rgb_to_hsv.py +32 -0
  789. mindspore/ops/_op_impl/aicpu/right_shift.py +38 -0
  790. mindspore/ops/_op_impl/aicpu/rnnt_loss.py +35 -0
  791. mindspore/ops/_op_impl/aicpu/round.py +34 -0
  792. mindspore/ops/_op_impl/aicpu/rsqrt.py +33 -0
  793. mindspore/ops/_op_impl/aicpu/rsqrt_grad.py +36 -0
  794. mindspore/ops/_op_impl/aicpu/sample_distorted_bounding_box_v2.py +49 -0
  795. mindspore/ops/_op_impl/aicpu/scale_and_translate.py +52 -0
  796. mindspore/ops/_op_impl/aicpu/scale_and_translate_grad.py +36 -0
  797. mindspore/ops/_op_impl/aicpu/scatter.py +79 -0
  798. mindspore/ops/_op_impl/aicpu/scatter_add_with_axis.py +53 -0
  799. mindspore/ops/_op_impl/aicpu/scatter_elements.py +39 -0
  800. mindspore/ops/_op_impl/aicpu/scatter_nd.py +59 -0
  801. mindspore/ops/_op_impl/aicpu/scatter_nd_max.py +54 -0
  802. mindspore/ops/_op_impl/aicpu/scatter_nd_min.py +54 -0
  803. mindspore/ops/_op_impl/aicpu/scatter_nd_update.py +59 -0
  804. mindspore/ops/_op_impl/aicpu/search_sorted.py +44 -0
  805. mindspore/ops/_op_impl/aicpu/segment_max.py +52 -0
  806. mindspore/ops/_op_impl/aicpu/segment_mean.py +56 -0
  807. mindspore/ops/_op_impl/aicpu/segment_min.py +52 -0
  808. mindspore/ops/_op_impl/aicpu/segment_prod.py +56 -0
  809. mindspore/ops/_op_impl/aicpu/segment_sum.py +56 -0
  810. mindspore/ops/_op_impl/aicpu/select.py +45 -0
  811. mindspore/ops/_op_impl/aicpu/self_adjoint_eig.py +34 -0
  812. mindspore/ops/_op_impl/aicpu/sequence_add.py +34 -0
  813. mindspore/ops/_op_impl/aicpu/sequence_add_offset.py +34 -0
  814. mindspore/ops/_op_impl/aicpu/sequence_addn.py +38 -0
  815. mindspore/ops/_op_impl/aicpu/sequence_concat.py +40 -0
  816. mindspore/ops/_op_impl/aicpu/sequence_stack.py +40 -0
  817. mindspore/ops/_op_impl/aicpu/set_size.py +38 -0
  818. mindspore/ops/_op_impl/aicpu/sign.py +36 -0
  819. mindspore/ops/_op_impl/aicpu/sin.py +34 -0
  820. mindspore/ops/_op_impl/aicpu/sinc.py +43 -0
  821. mindspore/ops/_op_impl/aicpu/sinh.py +34 -0
  822. mindspore/ops/_op_impl/aicpu/slice.py +59 -0
  823. mindspore/ops/_op_impl/aicpu/slice_grad.py +76 -0
  824. mindspore/ops/_op_impl/aicpu/smooth_l1_loss.py +35 -0
  825. mindspore/ops/_op_impl/aicpu/smooth_l1_loss_grad.py +37 -0
  826. mindspore/ops/_op_impl/aicpu/sort.py +39 -0
  827. mindspore/ops/_op_impl/aicpu/space_to_depth.py +44 -0
  828. mindspore/ops/_op_impl/aicpu/sparse_addmm.py +87 -0
  829. mindspore/ops/_op_impl/aicpu/sparse_apply_adagrad_da.py +80 -0
  830. mindspore/ops/_op_impl/aicpu/sparse_apply_centered_rms_prop.py +105 -0
  831. mindspore/ops/_op_impl/aicpu/sparse_apply_momentum.py +80 -0
  832. mindspore/ops/_op_impl/aicpu/sparse_apply_proximal_gradient_descent.py +79 -0
  833. mindspore/ops/_op_impl/aicpu/sparse_concat.py +59 -0
  834. mindspore/ops/_op_impl/aicpu/sparse_cross.py +42 -0
  835. mindspore/ops/_op_impl/aicpu/sparse_dense_cwise_add.py +58 -0
  836. mindspore/ops/_op_impl/aicpu/sparse_dense_cwise_div.py +58 -0
  837. mindspore/ops/_op_impl/aicpu/sparse_dense_cwise_mul.py +58 -0
  838. mindspore/ops/_op_impl/aicpu/sparse_fill_empty_rows.py +63 -0
  839. mindspore/ops/_op_impl/aicpu/sparse_fill_empty_rows_grad.py +45 -0
  840. mindspore/ops/_op_impl/aicpu/sparse_matrix_mat_mul.py +56 -0
  841. mindspore/ops/_op_impl/aicpu/sparse_matrix_nnz.py +81 -0
  842. mindspore/ops/_op_impl/aicpu/sparse_matrix_transpose.py +116 -0
  843. mindspore/ops/_op_impl/aicpu/sparse_reorder.py +56 -0
  844. mindspore/ops/_op_impl/aicpu/sparse_reshape.py +34 -0
  845. mindspore/ops/_op_impl/aicpu/sparse_segment_mean_grad.py +36 -0
  846. mindspore/ops/_op_impl/aicpu/sparse_segment_mean_with_num_segments.py +44 -0
  847. mindspore/ops/_op_impl/aicpu/sparse_segment_sqrt_n.py +43 -0
  848. mindspore/ops/_op_impl/aicpu/sparse_segment_sqrt_n_grad.py +38 -0
  849. mindspore/ops/_op_impl/aicpu/sparse_segment_sqrt_n_with_num_segments.py +44 -0
  850. mindspore/ops/_op_impl/aicpu/sparse_segment_sum.py +49 -0
  851. mindspore/ops/_op_impl/aicpu/sparse_segment_sum_with_num_segments.py +68 -0
  852. mindspore/ops/_op_impl/aicpu/sparse_slice.py +63 -0
  853. mindspore/ops/_op_impl/aicpu/sparse_slice_grad.py +61 -0
  854. mindspore/ops/_op_impl/aicpu/sparse_softmax.py +33 -0
  855. mindspore/ops/_op_impl/aicpu/sparse_softmax_cross_entropy_with_logits_v2.py +35 -0
  856. mindspore/ops/_op_impl/aicpu/sparse_sparse_maximum.py +53 -0
  857. mindspore/ops/_op_impl/aicpu/sparse_sparse_minimum.py +53 -0
  858. mindspore/ops/_op_impl/aicpu/sparse_tensor_dense_add.py +84 -0
  859. mindspore/ops/_op_impl/aicpu/sparse_tensor_dense_mat_mul.py +190 -0
  860. mindspore/ops/_op_impl/aicpu/sparse_tensor_to_csr_sparse_matrix.py +51 -0
  861. mindspore/ops/_op_impl/aicpu/sparse_to_dense_v2.py +73 -0
  862. mindspore/ops/_op_impl/aicpu/split.py +45 -0
  863. mindspore/ops/_op_impl/aicpu/sqrt.py +34 -0
  864. mindspore/ops/_op_impl/aicpu/sqrt_grad.py +35 -0
  865. mindspore/ops/_op_impl/aicpu/square.py +35 -0
  866. mindspore/ops/_op_impl/aicpu/squared_difference.py +37 -0
  867. mindspore/ops/_op_impl/aicpu/squeeze.py +42 -0
  868. mindspore/ops/_op_impl/aicpu/sspaddmm.py +97 -0
  869. mindspore/ops/_op_impl/aicpu/stack.py +45 -0
  870. mindspore/ops/_op_impl/aicpu/stack_push_pop.py +87 -0
  871. mindspore/ops/_op_impl/aicpu/standard_laplace.py +34 -0
  872. mindspore/ops/_op_impl/aicpu/standard_normal.py +34 -0
  873. mindspore/ops/_op_impl/aicpu/stateless_dropout_genmask.py +37 -0
  874. mindspore/ops/_op_impl/aicpu/stft.py +70 -0
  875. mindspore/ops/_op_impl/aicpu/strided_slice.py +43 -0
  876. mindspore/ops/_op_impl/aicpu/strided_slice_grad.py +50 -0
  877. mindspore/ops/_op_impl/aicpu/strided_slice_v2.py +93 -0
  878. mindspore/ops/_op_impl/aicpu/strided_slice_v2_grad.py +66 -0
  879. mindspore/ops/_op_impl/aicpu/sub.py +41 -0
  880. mindspore/ops/_op_impl/aicpu/sub_and_filter.py +36 -0
  881. mindspore/ops/_op_impl/aicpu/tan.py +34 -0
  882. mindspore/ops/_op_impl/aicpu/tanh.py +34 -0
  883. mindspore/ops/_op_impl/aicpu/tanh_grad.py +35 -0
  884. mindspore/ops/_op_impl/aicpu/tensor_scatter_update.py +59 -0
  885. mindspore/ops/_op_impl/aicpu/tile.py +56 -0
  886. mindspore/ops/_op_impl/aicpu/topk.py +34 -0
  887. mindspore/ops/_op_impl/aicpu/trace.py +40 -0
  888. mindspore/ops/_op_impl/aicpu/tracegrad.py +41 -0
  889. mindspore/ops/_op_impl/aicpu/trans_data.py +35 -0
  890. mindspore/ops/_op_impl/aicpu/transpose.py +58 -0
  891. mindspore/ops/_op_impl/aicpu/tridiagonal_matmul.py +42 -0
  892. mindspore/ops/_op_impl/aicpu/tridiagonal_solve.py +35 -0
  893. mindspore/ops/_op_impl/aicpu/tril.py +42 -0
  894. mindspore/ops/_op_impl/aicpu/tril_indices.py +34 -0
  895. mindspore/ops/_op_impl/aicpu/triplet_margin_loss.py +62 -0
  896. mindspore/ops/_op_impl/aicpu/triu.py +43 -0
  897. mindspore/ops/_op_impl/aicpu/triu_indices.py +34 -0
  898. mindspore/ops/_op_impl/aicpu/truncated_normal.py +39 -0
  899. mindspore/ops/_op_impl/aicpu/uniform.py +36 -0
  900. mindspore/ops/_op_impl/aicpu/uniform_candidate_sampler.py +41 -0
  901. mindspore/ops/_op_impl/aicpu/uniform_int.py +36 -0
  902. mindspore/ops/_op_impl/aicpu/uniform_real.py +33 -0
  903. mindspore/ops/_op_impl/aicpu/unique.py +31 -0
  904. mindspore/ops/_op_impl/aicpu/unique_consecutive.py +47 -0
  905. mindspore/ops/_op_impl/aicpu/unique_with_pad.py +32 -0
  906. mindspore/ops/_op_impl/aicpu/unravel_index.py +32 -0
  907. mindspore/ops/_op_impl/aicpu/unsorted_segment_prod.py +53 -0
  908. mindspore/ops/_op_impl/aicpu/unsorted_segment_sum.py +57 -0
  909. mindspore/ops/_op_impl/aicpu/unstack.py +45 -0
  910. mindspore/ops/_op_impl/aicpu/update_cache.py +44 -0
  911. mindspore/ops/_op_impl/aicpu/upper_bound.py +47 -0
  912. mindspore/ops/_op_impl/aicpu/upsample_nearest_3d.py +42 -0
  913. mindspore/ops/_op_impl/aicpu/upsample_nearest_3d_grad.py +49 -0
  914. mindspore/ops/_op_impl/aicpu/upsample_trilinear_3d.py +40 -0
  915. mindspore/ops/_op_impl/aicpu/upsample_trilinear_3d_grad.py +50 -0
  916. mindspore/ops/_op_impl/aicpu/xdivy.py +35 -0
  917. mindspore/ops/_op_impl/aicpu/xlogy.py +33 -0
  918. mindspore/ops/_op_impl/aicpu/zeros_like.py +42 -0
  919. mindspore/ops/_op_impl/aicpu/zeta.py +31 -0
  920. mindspore/ops/_op_impl/akg/__init__.py +19 -0
  921. mindspore/ops/_op_impl/akg/ascend/__init__.py +48 -0
  922. mindspore/ops/_op_impl/akg/ascend/abs.py +35 -0
  923. mindspore/ops/_op_impl/akg/ascend/add.py +42 -0
  924. mindspore/ops/_op_impl/akg/ascend/add_n.py +37 -0
  925. mindspore/ops/_op_impl/akg/ascend/batchmatmul.py +33 -0
  926. mindspore/ops/_op_impl/akg/ascend/cast.py +46 -0
  927. mindspore/ops/_op_impl/akg/ascend/equal.py +35 -0
  928. mindspore/ops/_op_impl/akg/ascend/exp.py +35 -0
  929. mindspore/ops/_op_impl/akg/ascend/expand_dims.py +33 -0
  930. mindspore/ops/_op_impl/akg/ascend/greater.py +34 -0
  931. mindspore/ops/_op_impl/akg/ascend/greater_equal.py +35 -0
  932. mindspore/ops/_op_impl/akg/ascend/less.py +31 -0
  933. mindspore/ops/_op_impl/akg/ascend/less_equal.py +35 -0
  934. mindspore/ops/_op_impl/akg/ascend/load_im2col.py +33 -0
  935. mindspore/ops/_op_impl/akg/ascend/log.py +34 -0
  936. mindspore/ops/_op_impl/akg/ascend/maximum.py +36 -0
  937. mindspore/ops/_op_impl/akg/ascend/minimum.py +39 -0
  938. mindspore/ops/_op_impl/akg/ascend/mul.py +41 -0
  939. mindspore/ops/_op_impl/akg/ascend/neg.py +37 -0
  940. mindspore/ops/_op_impl/akg/ascend/pow.py +35 -0
  941. mindspore/ops/_op_impl/akg/ascend/prod_force_se_a.py +33 -0
  942. mindspore/ops/_op_impl/akg/ascend/real_div.py +36 -0
  943. mindspore/ops/_op_impl/akg/ascend/reciprocal.py +32 -0
  944. mindspore/ops/_op_impl/akg/ascend/reduce_max.py +32 -0
  945. mindspore/ops/_op_impl/akg/ascend/reduce_min.py +32 -0
  946. mindspore/ops/_op_impl/akg/ascend/reduce_sum.py +37 -0
  947. mindspore/ops/_op_impl/akg/ascend/rsqrt.py +35 -0
  948. mindspore/ops/_op_impl/akg/ascend/select.py +37 -0
  949. mindspore/ops/_op_impl/akg/ascend/sqrt.py +35 -0
  950. mindspore/ops/_op_impl/akg/ascend/square.py +35 -0
  951. mindspore/ops/_op_impl/akg/ascend/sub.py +42 -0
  952. mindspore/ops/_op_impl/akg/cpu/__init__.py +23 -0
  953. mindspore/ops/_op_impl/akg/cpu/coo2csr.py +29 -0
  954. mindspore/ops/_op_impl/akg/cpu/csr2coo.py +29 -0
  955. mindspore/ops/_op_impl/akg/cpu/csr_gather.py +33 -0
  956. mindspore/ops/_op_impl/akg/cpu/csr_mm.py +34 -0
  957. mindspore/ops/_op_impl/akg/cpu/csr_mul.py +33 -0
  958. mindspore/ops/_op_impl/akg/cpu/csr_mv.py +33 -0
  959. mindspore/ops/_op_impl/akg/cpu/csr_reduce_sum.py +31 -0
  960. mindspore/ops/_op_impl/akg/gpu/__init__.py +24 -0
  961. mindspore/ops/_op_impl/akg/gpu/coo2csr.py +29 -0
  962. mindspore/ops/_op_impl/akg/gpu/csr2coo.py +29 -0
  963. mindspore/ops/_op_impl/akg/gpu/csr_div.py +36 -0
  964. mindspore/ops/_op_impl/akg/gpu/csr_gather.py +33 -0
  965. mindspore/ops/_op_impl/akg/gpu/csr_mm.py +37 -0
  966. mindspore/ops/_op_impl/akg/gpu/csr_mul.py +36 -0
  967. mindspore/ops/_op_impl/akg/gpu/csr_mv.py +36 -0
  968. mindspore/ops/_op_impl/akg/gpu/csr_reduce_sum.py +33 -0
  969. mindspore/ops/_op_impl/cpu/__init__.py +78 -0
  970. mindspore/ops/_op_impl/cpu/adam.py +49 -0
  971. mindspore/ops/_op_impl/cpu/adam_weight_decay.py +47 -0
  972. mindspore/ops/_op_impl/cpu/arg_max.py +30 -0
  973. mindspore/ops/_op_impl/cpu/arg_max_with_value.py +31 -0
  974. mindspore/ops/_op_impl/cpu/arg_min_with_value.py +31 -0
  975. mindspore/ops/_op_impl/cpu/buffer_append.py +28 -0
  976. mindspore/ops/_op_impl/cpu/buffer_get.py +28 -0
  977. mindspore/ops/_op_impl/cpu/buffer_sample.py +28 -0
  978. mindspore/ops/_op_impl/cpu/cast.py +171 -0
  979. mindspore/ops/_op_impl/cpu/concat_offset.py +38 -0
  980. mindspore/ops/_op_impl/cpu/conv2d.py +30 -0
  981. mindspore/ops/_op_impl/cpu/conv3d.py +30 -0
  982. mindspore/ops/_op_impl/cpu/div.py +32 -0
  983. mindspore/ops/_op_impl/cpu/dropout.py +31 -0
  984. mindspore/ops/_op_impl/cpu/dropout_grad.py +30 -0
  985. mindspore/ops/_op_impl/cpu/dynamic_shape.py +42 -0
  986. mindspore/ops/_op_impl/cpu/dynamic_stitch.py +41 -0
  987. mindspore/ops/_op_impl/cpu/equal_count.py +30 -0
  988. mindspore/ops/_op_impl/cpu/gather_d.py +49 -0
  989. mindspore/ops/_op_impl/cpu/gather_d_grad.py +38 -0
  990. mindspore/ops/_op_impl/cpu/gather_d_grad_v2.py +40 -0
  991. mindspore/ops/_op_impl/cpu/gather_v2.py +40 -0
  992. mindspore/ops/_op_impl/cpu/hsigmoid.py +33 -0
  993. mindspore/ops/_op_impl/cpu/hsigmoid_grad.py +34 -0
  994. mindspore/ops/_op_impl/cpu/hswish.py +32 -0
  995. mindspore/ops/_op_impl/cpu/hswish_grad.py +33 -0
  996. mindspore/ops/_op_impl/cpu/identity_n.py +40 -0
  997. mindspore/ops/_op_impl/cpu/is_finite.py +39 -0
  998. mindspore/ops/_op_impl/cpu/l2loss.py +30 -0
  999. mindspore/ops/_op_impl/cpu/layer_norm.py +36 -0
  1000. mindspore/ops/_op_impl/cpu/layer_norm_grad.py +38 -0
  1001. mindspore/ops/_op_impl/cpu/maximum.py +35 -0
  1002. mindspore/ops/_op_impl/cpu/maximum_grad.py +47 -0
  1003. mindspore/ops/_op_impl/cpu/minimum.py +40 -0
  1004. mindspore/ops/_op_impl/cpu/minimum_grad.py +51 -0
  1005. mindspore/ops/_op_impl/cpu/mirror_pad.py +36 -0
  1006. mindspore/ops/_op_impl/cpu/mirror_pad_grad.py +36 -0
  1007. mindspore/ops/_op_impl/cpu/mul.py +32 -0
  1008. mindspore/ops/_op_impl/cpu/one_hot.py +31 -0
  1009. mindspore/ops/_op_impl/cpu/pad.py +32 -0
  1010. mindspore/ops/_op_impl/cpu/pow.py +32 -0
  1011. mindspore/ops/_op_impl/cpu/priority_replay_buffer.py +42 -0
  1012. mindspore/ops/_op_impl/cpu/pyexecute.py +29 -0
  1013. mindspore/ops/_op_impl/cpu/pyfunc.py +29 -0
  1014. mindspore/ops/_op_impl/cpu/range.py +34 -0
  1015. mindspore/ops/_op_impl/cpu/real_div.py +33 -0
  1016. mindspore/ops/_op_impl/cpu/reduce_all.py +29 -0
  1017. mindspore/ops/_op_impl/cpu/reduce_any.py +29 -0
  1018. mindspore/ops/_op_impl/cpu/reduce_max.py +32 -0
  1019. mindspore/ops/_op_impl/cpu/reduce_mean.py +40 -0
  1020. mindspore/ops/_op_impl/cpu/reduce_min.py +32 -0
  1021. mindspore/ops/_op_impl/cpu/reduce_prod.py +40 -0
  1022. mindspore/ops/_op_impl/cpu/reduce_std.py +31 -0
  1023. mindspore/ops/_op_impl/cpu/reduce_sum.py +41 -0
  1024. mindspore/ops/_op_impl/cpu/space_to_batch_nd.py +38 -0
  1025. mindspore/ops/_op_impl/cpu/sparse_slice.py +62 -0
  1026. mindspore/ops/_op_impl/cpu/sparse_slice_grad.py +60 -0
  1027. mindspore/ops/_op_impl/cpu/split.py +34 -0
  1028. mindspore/ops/_op_impl/cpu/sspaddmm.py +95 -0
  1029. mindspore/ops/_op_impl/cpu/stack.py +38 -0
  1030. mindspore/ops/_op_impl/cpu/sub.py +32 -0
  1031. mindspore/ops/_op_impl/cpu/tensor_copy_slices.py +41 -0
  1032. mindspore/ops/_op_impl/cpu/tile.py +37 -0
  1033. mindspore/ops/_op_impl/cpu/top_k.py +31 -0
  1034. mindspore/ops/_op_impl/cpu/transpose.py +39 -0
  1035. mindspore/ops/_primitive_cache.py +90 -0
  1036. mindspore/ops/_register_for_op.py +73 -0
  1037. mindspore/ops/_utils/__init__.py +20 -0
  1038. mindspore/ops/_utils/utils.py +147 -0
  1039. mindspore/ops/_vmap/__init__.py +25 -0
  1040. mindspore/ops/_vmap/vmap_array_ops.py +2151 -0
  1041. mindspore/ops/_vmap/vmap_base.py +533 -0
  1042. mindspore/ops/_vmap/vmap_convolution_ops.py +441 -0
  1043. mindspore/ops/_vmap/vmap_debug_ops.py +50 -0
  1044. mindspore/ops/_vmap/vmap_grad_math_ops.py +274 -0
  1045. mindspore/ops/_vmap/vmap_grad_nn_ops.py +806 -0
  1046. mindspore/ops/_vmap/vmap_image_ops.py +194 -0
  1047. mindspore/ops/_vmap/vmap_math_ops.py +977 -0
  1048. mindspore/ops/_vmap/vmap_nn_ops.py +2209 -0
  1049. mindspore/ops/_vmap/vmap_other_ops.py +105 -0
  1050. mindspore/ops/_vmap/vmap_random_ops.py +122 -0
  1051. mindspore/ops/_vmap/vmap_sparse_ops.py +89 -0
  1052. mindspore/ops/auto_generate/__init__.py +31 -0
  1053. mindspore/ops/auto_generate/cpp_create_prim_instance_helper.py +231 -0
  1054. mindspore/ops/auto_generate/gen_arg_dtype_cast.py +250 -0
  1055. mindspore/ops/auto_generate/gen_arg_handler.py +197 -0
  1056. mindspore/ops/auto_generate/gen_extend_func.py +980 -0
  1057. mindspore/ops/auto_generate/gen_ops_def.py +6443 -0
  1058. mindspore/ops/auto_generate/gen_ops_prim.py +13167 -0
  1059. mindspore/ops/auto_generate/pyboost_inner_prim.py +429 -0
  1060. mindspore/ops/composite/__init__.py +71 -0
  1061. mindspore/ops/composite/base.py +1281 -0
  1062. mindspore/ops/composite/env_ops.py +41 -0
  1063. mindspore/ops/composite/math_ops.py +125 -0
  1064. mindspore/ops/composite/multitype_ops/__init__.py +77 -0
  1065. mindspore/ops/composite/multitype_ops/_compile_utils.py +1458 -0
  1066. mindspore/ops/composite/multitype_ops/_constexpr_utils.py +897 -0
  1067. mindspore/ops/composite/multitype_ops/add_impl.py +606 -0
  1068. mindspore/ops/composite/multitype_ops/bitwise_and_impl.py +56 -0
  1069. mindspore/ops/composite/multitype_ops/bitwise_or_impl.py +56 -0
  1070. mindspore/ops/composite/multitype_ops/bitwise_xor_impl.py +56 -0
  1071. mindspore/ops/composite/multitype_ops/div_impl.py +189 -0
  1072. mindspore/ops/composite/multitype_ops/equal_impl.py +335 -0
  1073. mindspore/ops/composite/multitype_ops/floordiv_impl.py +88 -0
  1074. mindspore/ops/composite/multitype_ops/getitem_impl.py +400 -0
  1075. mindspore/ops/composite/multitype_ops/greater_equal_impl.py +109 -0
  1076. mindspore/ops/composite/multitype_ops/greater_impl.py +110 -0
  1077. mindspore/ops/composite/multitype_ops/in_impl.py +196 -0
  1078. mindspore/ops/composite/multitype_ops/left_shift_impl.py +37 -0
  1079. mindspore/ops/composite/multitype_ops/less_equal_impl.py +111 -0
  1080. mindspore/ops/composite/multitype_ops/less_impl.py +112 -0
  1081. mindspore/ops/composite/multitype_ops/logic_not_impl.py +113 -0
  1082. mindspore/ops/composite/multitype_ops/logical_and_impl.py +60 -0
  1083. mindspore/ops/composite/multitype_ops/logical_or_impl.py +61 -0
  1084. mindspore/ops/composite/multitype_ops/mod_impl.py +86 -0
  1085. mindspore/ops/composite/multitype_ops/mul_impl.py +294 -0
  1086. mindspore/ops/composite/multitype_ops/negative_impl.py +79 -0
  1087. mindspore/ops/composite/multitype_ops/not_equal_impl.py +290 -0
  1088. mindspore/ops/composite/multitype_ops/not_in_impl.py +196 -0
  1089. mindspore/ops/composite/multitype_ops/ones_like_impl.py +96 -0
  1090. mindspore/ops/composite/multitype_ops/pow_impl.py +87 -0
  1091. mindspore/ops/composite/multitype_ops/right_shift_impl.py +37 -0
  1092. mindspore/ops/composite/multitype_ops/setitem_impl.py +884 -0
  1093. mindspore/ops/composite/multitype_ops/sub_impl.py +116 -0
  1094. mindspore/ops/composite/multitype_ops/uadd_impl.py +29 -0
  1095. mindspore/ops/composite/multitype_ops/zeros_like_impl.py +228 -0
  1096. mindspore/ops/deprecated.py +315 -0
  1097. mindspore/ops/extend/__init__.py +53 -0
  1098. mindspore/ops/extend/array_func.py +218 -0
  1099. mindspore/ops/extend/math_func.py +76 -0
  1100. mindspore/ops/extend/nn_func.py +308 -0
  1101. mindspore/ops/function/__init__.py +760 -0
  1102. mindspore/ops/function/array_func.py +6889 -0
  1103. mindspore/ops/function/clip_func.py +384 -0
  1104. mindspore/ops/function/debug_func.py +69 -0
  1105. mindspore/ops/function/fft_func.py +31 -0
  1106. mindspore/ops/function/grad/__init__.py +34 -0
  1107. mindspore/ops/function/grad/grad_func.py +1424 -0
  1108. mindspore/ops/function/image_func.py +292 -0
  1109. mindspore/ops/function/linalg_func.py +416 -0
  1110. mindspore/ops/function/math_func.py +11877 -0
  1111. mindspore/ops/function/nn_func.py +8175 -0
  1112. mindspore/ops/function/other_func.py +114 -0
  1113. mindspore/ops/function/parameter_func.py +134 -0
  1114. mindspore/ops/function/random_func.py +1539 -0
  1115. mindspore/ops/function/reshard_func.py +102 -0
  1116. mindspore/ops/function/sparse_func.py +884 -0
  1117. mindspore/ops/function/sparse_unary_func.py +2422 -0
  1118. mindspore/ops/function/spectral_func.py +150 -0
  1119. mindspore/ops/function/vmap_func.py +116 -0
  1120. mindspore/ops/functional.py +454 -0
  1121. mindspore/ops/op_info_register.py +1572 -0
  1122. mindspore/ops/operations/__init__.py +717 -0
  1123. mindspore/ops/operations/_csr_ops.py +403 -0
  1124. mindspore/ops/operations/_custom_grad.py +181 -0
  1125. mindspore/ops/operations/_embedding_cache_ops.py +307 -0
  1126. mindspore/ops/operations/_grad_ops.py +3052 -0
  1127. mindspore/ops/operations/_infer_ops.py +19 -0
  1128. mindspore/ops/operations/_inner_ops.py +2567 -0
  1129. mindspore/ops/operations/_map_tensor_ops.py +112 -0
  1130. mindspore/ops/operations/_ms_kernel.py +601 -0
  1131. mindspore/ops/operations/_ocr_ops.py +379 -0
  1132. mindspore/ops/operations/_opaque_predicate_registry.py +41 -0
  1133. mindspore/ops/operations/_pyfunc_registry.py +58 -0
  1134. mindspore/ops/operations/_quant_ops.py +1844 -0
  1135. mindspore/ops/operations/_rl_inner_ops.py +1231 -0
  1136. mindspore/ops/operations/_scalar_ops.py +106 -0
  1137. mindspore/ops/operations/_sequence_ops.py +1155 -0
  1138. mindspore/ops/operations/_sparse_grad_ops.py +56 -0
  1139. mindspore/ops/operations/_tensor_array.py +359 -0
  1140. mindspore/ops/operations/_thor_ops.py +807 -0
  1141. mindspore/ops/operations/array_ops.py +6258 -0
  1142. mindspore/ops/operations/comm_ops.py +1996 -0
  1143. mindspore/ops/operations/control_ops.py +127 -0
  1144. mindspore/ops/operations/custom_ops.py +1065 -0
  1145. mindspore/ops/operations/debug_ops.py +646 -0
  1146. mindspore/ops/operations/image_ops.py +1041 -0
  1147. mindspore/ops/operations/inner_ops.py +697 -0
  1148. mindspore/ops/operations/linalg_ops.py +95 -0
  1149. mindspore/ops/operations/manually_defined/__init__.py +24 -0
  1150. mindspore/ops/operations/manually_defined/_inner.py +61 -0
  1151. mindspore/ops/operations/manually_defined/ops_def.py +2016 -0
  1152. mindspore/ops/operations/math_ops.py +5306 -0
  1153. mindspore/ops/operations/nn_ops.py +9669 -0
  1154. mindspore/ops/operations/other_ops.py +871 -0
  1155. mindspore/ops/operations/random_ops.py +1243 -0
  1156. mindspore/ops/operations/reshard_ops.py +53 -0
  1157. mindspore/ops/operations/rl_ops.py +288 -0
  1158. mindspore/ops/operations/sparse_ops.py +2753 -0
  1159. mindspore/ops/operations/spectral_ops.py +111 -0
  1160. mindspore/ops/primitive.py +1034 -0
  1161. mindspore/ops/signature.py +54 -0
  1162. mindspore/ops/silent_check.py +162 -0
  1163. mindspore/ops/vm_impl_registry.py +91 -0
  1164. mindspore/ops_generate/__init__.py +27 -0
  1165. mindspore/ops_generate/arg_dtype_cast.py +250 -0
  1166. mindspore/ops_generate/arg_handler.py +197 -0
  1167. mindspore/ops_generate/gen_aclnn_implement.py +263 -0
  1168. mindspore/ops_generate/gen_ops.py +1084 -0
  1169. mindspore/ops_generate/gen_ops_inner_prim.py +131 -0
  1170. mindspore/ops_generate/gen_pyboost_func.py +968 -0
  1171. mindspore/ops_generate/gen_utils.py +209 -0
  1172. mindspore/ops_generate/op_proto.py +138 -0
  1173. mindspore/ops_generate/pyboost_utils.py +354 -0
  1174. mindspore/ops_generate/template.py +239 -0
  1175. mindspore/parallel/__init__.py +28 -0
  1176. mindspore/parallel/_auto_parallel_context.py +1466 -0
  1177. mindspore/parallel/_cell_wrapper.py +91 -0
  1178. mindspore/parallel/_cost_model_context.py +700 -0
  1179. mindspore/parallel/_dp_allreduce_fusion.py +159 -0
  1180. mindspore/parallel/_offload_context.py +275 -0
  1181. mindspore/parallel/_parallel_serialization.py +533 -0
  1182. mindspore/parallel/_ps_context.py +242 -0
  1183. mindspore/parallel/_recovery_context.py +110 -0
  1184. mindspore/parallel/_tensor.py +660 -0
  1185. mindspore/parallel/_transformer/__init__.py +35 -0
  1186. mindspore/parallel/_transformer/layers.py +765 -0
  1187. mindspore/parallel/_transformer/loss.py +251 -0
  1188. mindspore/parallel/_transformer/moe.py +693 -0
  1189. mindspore/parallel/_transformer/op_parallel_config.py +222 -0
  1190. mindspore/parallel/_transformer/transformer.py +3119 -0
  1191. mindspore/parallel/_utils.py +600 -0
  1192. mindspore/parallel/algo_parameter_config.py +400 -0
  1193. mindspore/parallel/checkpoint_transform.py +643 -0
  1194. mindspore/parallel/cluster/__init__.py +15 -0
  1195. mindspore/parallel/cluster/process_entity/__init__.py +18 -0
  1196. mindspore/parallel/cluster/process_entity/_api.py +344 -0
  1197. mindspore/parallel/cluster/process_entity/_utils.py +126 -0
  1198. mindspore/parallel/cluster/run.py +136 -0
  1199. mindspore/parallel/mpi/__init__.py +14 -0
  1200. mindspore/parallel/mpi/_mpi_config.py +116 -0
  1201. mindspore/parallel/parameter_broadcast.py +152 -0
  1202. mindspore/parallel/shard.py +350 -0
  1203. mindspore/perf_msvcbuildinsights.dll +0 -0
  1204. mindspore/pgodb140.dll +0 -0
  1205. mindspore/pgort140.dll +0 -0
  1206. mindspore/profiler/__init__.py +27 -0
  1207. mindspore/profiler/common/__init__.py +14 -0
  1208. mindspore/profiler/common/exceptions/__init__.py +14 -0
  1209. mindspore/profiler/common/exceptions/error_code.py +83 -0
  1210. mindspore/profiler/common/exceptions/exceptions.py +286 -0
  1211. mindspore/profiler/common/process_pool.py +41 -0
  1212. mindspore/profiler/common/singleton.py +28 -0
  1213. mindspore/profiler/common/struct_type.py +118 -0
  1214. mindspore/profiler/common/util.py +444 -0
  1215. mindspore/profiler/common/validator/__init__.py +14 -0
  1216. mindspore/profiler/common/validator/validate_path.py +84 -0
  1217. mindspore/profiler/envprofiling.py +256 -0
  1218. mindspore/profiler/parser/__init__.py +14 -0
  1219. mindspore/profiler/parser/aicpu_data_parser.py +272 -0
  1220. mindspore/profiler/parser/ascend_analysis/__init__.py +14 -0
  1221. mindspore/profiler/parser/ascend_analysis/constant.py +53 -0
  1222. mindspore/profiler/parser/ascend_analysis/file_manager.py +159 -0
  1223. mindspore/profiler/parser/ascend_analysis/function_event.py +161 -0
  1224. mindspore/profiler/parser/ascend_analysis/fwk_cann_parser.py +131 -0
  1225. mindspore/profiler/parser/ascend_analysis/fwk_file_parser.py +85 -0
  1226. mindspore/profiler/parser/ascend_analysis/msprof_timeline_parser.py +57 -0
  1227. mindspore/profiler/parser/ascend_analysis/profiler_info_parser.py +116 -0
  1228. mindspore/profiler/parser/ascend_analysis/tlv_decoder.py +86 -0
  1229. mindspore/profiler/parser/ascend_analysis/trace_event_manager.py +68 -0
  1230. mindspore/profiler/parser/ascend_cluster_generator.py +116 -0
  1231. mindspore/profiler/parser/ascend_communicate_generator.py +314 -0
  1232. mindspore/profiler/parser/ascend_flops_generator.py +116 -0
  1233. mindspore/profiler/parser/ascend_fpbp_generator.py +82 -0
  1234. mindspore/profiler/parser/ascend_hccl_generator.py +271 -0
  1235. mindspore/profiler/parser/ascend_integrate_generator.py +42 -0
  1236. mindspore/profiler/parser/ascend_memory_generator.py +185 -0
  1237. mindspore/profiler/parser/ascend_msprof_exporter.py +281 -0
  1238. mindspore/profiler/parser/ascend_msprof_generator.py +187 -0
  1239. mindspore/profiler/parser/ascend_op_generator.py +334 -0
  1240. mindspore/profiler/parser/ascend_steptrace_generator.py +94 -0
  1241. mindspore/profiler/parser/ascend_timeline_generator.py +543 -0
  1242. mindspore/profiler/parser/base_timeline_generator.py +489 -0
  1243. mindspore/profiler/parser/container.py +229 -0
  1244. mindspore/profiler/parser/cpu_gpu_timeline_generator.py +684 -0
  1245. mindspore/profiler/parser/flops_parser.py +531 -0
  1246. mindspore/profiler/parser/framework_enum.py +111 -0
  1247. mindspore/profiler/parser/framework_parser.py +854 -0
  1248. mindspore/profiler/parser/framework_struct.py +61 -0
  1249. mindspore/profiler/parser/hccl_parser.py +573 -0
  1250. mindspore/profiler/parser/hwts_log_parser.py +122 -0
  1251. mindspore/profiler/parser/integrator.py +526 -0
  1252. mindspore/profiler/parser/memory_usage_parser.py +431 -0
  1253. mindspore/profiler/parser/minddata_analyzer.py +800 -0
  1254. mindspore/profiler/parser/minddata_parser.py +186 -0
  1255. mindspore/profiler/parser/minddata_pipeline_parser.py +299 -0
  1256. mindspore/profiler/parser/msadvisor_analyzer.py +82 -0
  1257. mindspore/profiler/parser/msadvisor_parser.py +240 -0
  1258. mindspore/profiler/parser/op_intermediate_parser.py +149 -0
  1259. mindspore/profiler/parser/optime_parser.py +250 -0
  1260. mindspore/profiler/parser/profiler_info.py +141 -0
  1261. mindspore/profiler/parser/step_trace_parser.py +666 -0
  1262. mindspore/profiler/profiling.py +2054 -0
  1263. mindspore/rewrite/__init__.py +29 -0
  1264. mindspore/rewrite/api/__init__.py +17 -0
  1265. mindspore/rewrite/api/node.py +519 -0
  1266. mindspore/rewrite/api/node_type.py +53 -0
  1267. mindspore/rewrite/api/pattern_engine.py +490 -0
  1268. mindspore/rewrite/api/scoped_value.py +181 -0
  1269. mindspore/rewrite/api/symbol_tree.py +497 -0
  1270. mindspore/rewrite/ast_helpers/__init__.py +25 -0
  1271. mindspore/rewrite/ast_helpers/ast_converter.py +143 -0
  1272. mindspore/rewrite/ast_helpers/ast_finder.py +404 -0
  1273. mindspore/rewrite/ast_helpers/ast_flattener.py +268 -0
  1274. mindspore/rewrite/ast_helpers/ast_modifier.py +605 -0
  1275. mindspore/rewrite/ast_helpers/ast_replacer.py +79 -0
  1276. mindspore/rewrite/common/__init__.py +19 -0
  1277. mindspore/rewrite/common/config.py +24 -0
  1278. mindspore/rewrite/common/error_log.py +39 -0
  1279. mindspore/rewrite/common/event.py +28 -0
  1280. mindspore/rewrite/common/namer.py +271 -0
  1281. mindspore/rewrite/common/namespace.py +118 -0
  1282. mindspore/rewrite/common/observable.py +44 -0
  1283. mindspore/rewrite/common/observer.py +54 -0
  1284. mindspore/rewrite/node/__init__.py +22 -0
  1285. mindspore/rewrite/node/call_function.py +95 -0
  1286. mindspore/rewrite/node/cell_container.py +139 -0
  1287. mindspore/rewrite/node/control_flow.py +113 -0
  1288. mindspore/rewrite/node/node.py +1428 -0
  1289. mindspore/rewrite/node/node_manager.py +283 -0
  1290. mindspore/rewrite/node/node_topological_manager.py +223 -0
  1291. mindspore/rewrite/parsers/__init__.py +29 -0
  1292. mindspore/rewrite/parsers/arguments_parser.py +63 -0
  1293. mindspore/rewrite/parsers/assign_parser.py +852 -0
  1294. mindspore/rewrite/parsers/attribute_parser.py +57 -0
  1295. mindspore/rewrite/parsers/class_def_parser.py +289 -0
  1296. mindspore/rewrite/parsers/constant_parser.py +104 -0
  1297. mindspore/rewrite/parsers/container_parser.py +88 -0
  1298. mindspore/rewrite/parsers/expr_parser.py +55 -0
  1299. mindspore/rewrite/parsers/for_parser.py +61 -0
  1300. mindspore/rewrite/parsers/function_def_parser.py +84 -0
  1301. mindspore/rewrite/parsers/if_parser.py +85 -0
  1302. mindspore/rewrite/parsers/module_parser.py +117 -0
  1303. mindspore/rewrite/parsers/parser.py +43 -0
  1304. mindspore/rewrite/parsers/parser_register.py +86 -0
  1305. mindspore/rewrite/parsers/return_parser.py +37 -0
  1306. mindspore/rewrite/parsers/while_parser.py +59 -0
  1307. mindspore/rewrite/sparsify/__init__.py +0 -0
  1308. mindspore/rewrite/sparsify/sparse_transformer.py +457 -0
  1309. mindspore/rewrite/sparsify/sparsify.py +112 -0
  1310. mindspore/rewrite/sparsify/utils.py +179 -0
  1311. mindspore/rewrite/symbol_tree/__init__.py +20 -0
  1312. mindspore/rewrite/symbol_tree/symbol_tree.py +1819 -0
  1313. mindspore/rewrite/symbol_tree/symbol_tree_builder.py +76 -0
  1314. mindspore/rewrite/symbol_tree/symbol_tree_dumper.py +142 -0
  1315. mindspore/run_check/__init__.py +20 -0
  1316. mindspore/run_check/_check_version.py +574 -0
  1317. mindspore/run_check/run_check.py +66 -0
  1318. mindspore/safeguard/__init__.py +18 -0
  1319. mindspore/safeguard/rewrite_obfuscation.py +531 -0
  1320. mindspore/swresample-4.dll +0 -0
  1321. mindspore/swscale-6.dll +0 -0
  1322. mindspore/tbbmalloc.dll +0 -0
  1323. mindspore/tinyxml2.dll +0 -0
  1324. mindspore/train/__init__.py +47 -0
  1325. mindspore/train/_utils.py +439 -0
  1326. mindspore/train/amp.py +817 -0
  1327. mindspore/train/anf_ir_pb2.py +1517 -0
  1328. mindspore/train/callback/__init__.py +44 -0
  1329. mindspore/train/callback/_backup_and_restore.py +117 -0
  1330. mindspore/train/callback/_callback.py +613 -0
  1331. mindspore/train/callback/_checkpoint.py +751 -0
  1332. mindspore/train/callback/_cluster_monitor.py +201 -0
  1333. mindspore/train/callback/_dataset_graph.py +150 -0
  1334. mindspore/train/callback/_early_stop.py +239 -0
  1335. mindspore/train/callback/_flops_collector.py +238 -0
  1336. mindspore/train/callback/_history.py +92 -0
  1337. mindspore/train/callback/_lambda_callback.py +80 -0
  1338. mindspore/train/callback/_landscape.py +1049 -0
  1339. mindspore/train/callback/_loss_monitor.py +107 -0
  1340. mindspore/train/callback/_lr_scheduler_callback.py +76 -0
  1341. mindspore/train/callback/_mindio_ttp.py +443 -0
  1342. mindspore/train/callback/_on_request_exit.py +195 -0
  1343. mindspore/train/callback/_reduce_lr_on_plateau.py +226 -0
  1344. mindspore/train/callback/_summary_collector.py +1184 -0
  1345. mindspore/train/callback/_time_monitor.py +141 -0
  1346. mindspore/train/checkpoint_pb2.py +233 -0
  1347. mindspore/train/data_sink.py +219 -0
  1348. mindspore/train/dataset_helper.py +688 -0
  1349. mindspore/train/lineage_pb2.py +1260 -0
  1350. mindspore/train/loss_scale_manager.py +213 -0
  1351. mindspore/train/memory_profiling_pb2.py +298 -0
  1352. mindspore/train/metrics/__init__.py +175 -0
  1353. mindspore/train/metrics/accuracy.py +133 -0
  1354. mindspore/train/metrics/auc.py +129 -0
  1355. mindspore/train/metrics/bleu_score.py +170 -0
  1356. mindspore/train/metrics/confusion_matrix.py +700 -0
  1357. mindspore/train/metrics/cosine_similarity.py +109 -0
  1358. mindspore/train/metrics/dice.py +116 -0
  1359. mindspore/train/metrics/error.py +175 -0
  1360. mindspore/train/metrics/fbeta.py +167 -0
  1361. mindspore/train/metrics/hausdorff_distance.py +333 -0
  1362. mindspore/train/metrics/loss.py +97 -0
  1363. mindspore/train/metrics/mean_surface_distance.py +189 -0
  1364. mindspore/train/metrics/metric.py +373 -0
  1365. mindspore/train/metrics/occlusion_sensitivity.py +225 -0
  1366. mindspore/train/metrics/perplexity.py +133 -0
  1367. mindspore/train/metrics/precision.py +160 -0
  1368. mindspore/train/metrics/recall.py +159 -0
  1369. mindspore/train/metrics/roc.py +223 -0
  1370. mindspore/train/metrics/root_mean_square_surface_distance.py +191 -0
  1371. mindspore/train/metrics/topk.py +167 -0
  1372. mindspore/train/mind_ir_pb2.py +1903 -0
  1373. mindspore/train/model.py +2176 -0
  1374. mindspore/train/node_strategy_pb2.py +653 -0
  1375. mindspore/train/print_pb2.py +184 -0
  1376. mindspore/train/profiling_parallel_pb2.py +151 -0
  1377. mindspore/train/serialization.py +3101 -0
  1378. mindspore/train/summary/__init__.py +23 -0
  1379. mindspore/train/summary/_lineage_adapter.py +41 -0
  1380. mindspore/train/summary/_summary_adapter.py +496 -0
  1381. mindspore/train/summary/_writer_pool.py +207 -0
  1382. mindspore/train/summary/enums.py +56 -0
  1383. mindspore/train/summary/summary_record.py +581 -0
  1384. mindspore/train/summary/writer.py +167 -0
  1385. mindspore/train/summary_pb2.py +1165 -0
  1386. mindspore/train/train_thor/__init__.py +20 -0
  1387. mindspore/train/train_thor/convert_utils.py +268 -0
  1388. mindspore/train/train_thor/dataset_helper.py +192 -0
  1389. mindspore/train/train_thor/model_thor.py +257 -0
  1390. mindspore/turbojpeg.dll +0 -0
  1391. mindspore/vcmeta.dll +0 -0
  1392. mindspore/vcomp140.dll +0 -0
  1393. mindspore/vcruntime140.dll +0 -0
  1394. mindspore/vcruntime140_1.dll +0 -0
  1395. mindspore/version.py +1 -0
  1396. mindspore-2.3.0.dist-info/METADATA +351 -0
  1397. mindspore-2.3.0.dist-info/RECORD +1400 -0
  1398. mindspore-2.3.0.dist-info/WHEEL +5 -0
  1399. mindspore-2.3.0.dist-info/entry_points.txt +4 -0
  1400. mindspore-2.3.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,2054 @@
1
+ # Copyright 2020-2023 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
+ import os
17
+ import re
18
+ import shutil
19
+ import stat
20
+ import time
21
+ import json
22
+ from json import JSONDecodeError
23
+ import glob
24
+ import subprocess
25
+ import csv
26
+ import socket
27
+ from enum import Enum
28
+ from multiprocessing import Process
29
+ from typing import List
30
+ import numpy as np
31
+
32
+ from mindspore import log as logger, context
33
+ from mindspore.context import get_auto_parallel_context
34
+ from mindspore.communication.management import GlobalComm, get_rank, get_group_size, get_local_rank
35
+ import mindspore._c_expression as c_expression
36
+ import mindspore._c_dataengine as cde
37
+ from mindspore._c_expression import _framework_profiler_enable_mi
38
+ from mindspore.profiler.common.exceptions.exceptions import ProfilerFileNotFoundException, \
39
+ ProfilerIOException, ProfilerException, ProfilerRawFileException, ProfilerParamTypeErrorException
40
+ from mindspore.profiler.common.exceptions.exceptions import ProfilerPathErrorException
41
+ from mindspore.profiler.common.exceptions.exceptions import ProfilerDirNotFoundException
42
+ from mindspore.profiler.common.util import get_file_path, ProfilerPathManager
43
+ from mindspore.profiler.common.process_pool import MultiProcessPool
44
+ from mindspore.profiler.common.validator.validate_path import validate_and_normalize_path
45
+ from mindspore.profiler.parser.framework_parser import GpuFrameWorkParser, DynamicFrameWorkParser
46
+ from mindspore.profiler.parser.integrator import Integrator, DeviceTarget
47
+ from mindspore.profiler.parser.ascend_analysis.function_event import CANNEvent
48
+ from mindspore.profiler.parser.cpu_gpu_timeline_generator import GpuTimelineGenerator, CpuTimelineGenerator
49
+ from mindspore.profiler.parser.ascend_timeline_generator import AscendTimelineGenerator
50
+ from mindspore.profiler.parser.memory_usage_parser import MemoryUsageParser
51
+ from mindspore.profiler.parser.minddata_parser import MinddataParser
52
+ from mindspore.profiler.parser.minddata_analyzer import MinddataProfilingAnalyzer
53
+ from mindspore.profiler.parser.minddata_pipeline_parser import \
54
+ MinddataPipelineParser
55
+ from mindspore.profiler.parser.step_trace_parser import GpuStepTraceParser, AscendStepTraceParser
56
+ from mindspore.profiler.parser.msadvisor_analyzer import Msadvisor
57
+ from mindspore.profiler.parser.profiler_info import ProfilerInfo
58
+ from mindspore.common.api import _pynative_executor
59
+ from mindspore.profiler.parser.ascend_msprof_exporter import AscendMsprofExporter
60
+ from mindspore.profiler.parser.ascend_msprof_generator import AscendMsprofDataGenerator
61
+ from mindspore.profiler.parser.ascend_fpbp_generator import AscendFPBPGenerator
62
+ from mindspore.profiler.parser.ascend_op_generator import AscendOPGenerator
63
+ from mindspore.profiler.parser.ascend_steptrace_generator import AscendStepTraceGenerator
64
+ from mindspore.profiler.parser.ascend_flops_generator import AscendFlopsGenerator
65
+ from mindspore.profiler.parser.ascend_cluster_generator import AscendClusterGenerator
66
+ from mindspore.profiler.parser.ascend_hccl_generator import AscendHCCLGenerator
67
+ from mindspore.profiler.parser.ascend_communicate_generator import AscendCommunicationGenerator
68
+ from mindspore.profiler.parser.ascend_memory_generator import AscendMemoryGenerator
69
+ from mindspore.profiler.parser.ascend_integrate_generator import AscendIntegrateGenerator
70
+
71
+ INIT_OP_NAME = 'Default/InitDataSetQueue'
72
+
73
+ AICORE_METRICS_DICT = {
74
+ 0: "ArithmeticUtilization",
75
+ 1: "PipeUtilization",
76
+ 2: "Memory",
77
+ 3: "MemoryL0",
78
+ 4: "ResourceConflictRatio",
79
+ 5: "MemoryUB",
80
+ 6: "L2Cache",
81
+ -1: "None"
82
+ }
83
+
84
+
85
+ class ModelTraingMode(Enum):
86
+ PYNATIVE = 0
87
+ GRAPH = 1
88
+ KERNEL_BY_KERNEL = 2
89
+ UNKNOWN = 3
90
+
91
+
92
+ class ProfilerLevel(Enum):
93
+ Level0 = "Level0"
94
+ Level1 = "Level1"
95
+ Level2 = "Level2"
96
+
97
+
98
+ class DeviceSupportParam(Enum):
99
+ """The device target enum."""
100
+ CPU = ['start', 'start_profile', 'output_path', 'timeline_limit', 'profile_framework', 'op_time']
101
+ GPU = [
102
+ 'start', 'start_profile', 'output_path', 'data_process', 'timeline_limit', 'sync_enable', 'op_time',
103
+ 'profile_framework'
104
+ ]
105
+ ASCEND = [
106
+ 'start', 'start_profile', 'output_path', 'data_process', 'timeline_limit', 'profile_memory',
107
+ 'parallel_strategy', 'profile_communication', 'aicore_metrics', 'l2_cache', 'hbm_ddr', 'pcie', 'op_time',
108
+ 'ascend_job_id', 'profile_framework', 'host_stack', 'profiler_level', 'data_simplification'
109
+ ]
110
+
111
+
112
+ ALWAYS_VALID_PARAM = [
113
+ 'start', 'start_profile', 'output_path', 'data_process', 'parallel_strategy', 'l2_cache',
114
+ 'hbm_ddr', 'pcie', 'ascend_job_id', 'op_time', 'profile_framework', 'profiler_level'
115
+ ]
116
+
117
+
118
+ ANALYSIS_ASYNC_MODE = 'async'
119
+ ANALYSIS_SYNC_MODE = 'sync'
120
+ DEFAULT_MODEL_ID = 4294967295
121
+
122
+
123
+ def _environment_check():
124
+ if c_expression.security.enable_security():
125
+ raise RuntimeError("Profiler is not supported when MindSpore is compiled with \'-s on\'.")
126
+
127
+
128
+ class ExecutionCalculator:
129
+ """Calculate the average execution time and counts for each stage."""
130
+
131
+ def __init__(self, event, stage, custom_info):
132
+ self.event = event
133
+ self.stage = stage
134
+ self.custom_info = custom_info
135
+ self.count = 0
136
+ self.average_execution = 0
137
+
138
+
139
+ def _calculate_dataset_item(row, execution_time_map, ts_map):
140
+ """Calculate dataset execution time for one row."""
141
+ start_end = row['start_end']
142
+ event = row['event']
143
+ stage = row['stage']
144
+ custom_info = row['custom_info']
145
+ event_stage_tid_pid = event + '_' + stage + '_' + row['tid'] + '_' + row['pid']
146
+ if start_end == '1' and event_stage_tid_pid in ts_map:
147
+ title = event + '::' + stage + '::' + custom_info
148
+ ts_end = int(row['time_stamp(us)'])
149
+ ts = ts_map[event_stage_tid_pid]
150
+ dur = ts_end - ts
151
+ if title not in execution_time_map:
152
+ execution_time_map[title] = ExecutionCalculator(event=event, stage=stage, custom_info=custom_info)
153
+ execution_time_map[title].count += 1
154
+ if execution_time_map[title].count != 0:
155
+ execution_time_map[title].average_execution += \
156
+ (dur - execution_time_map[title].average_execution) / execution_time_map[title].count
157
+ del ts_map[event_stage_tid_pid]
158
+ elif start_end == '0':
159
+ ts = int(row['time_stamp(us)'])
160
+ ts_map[event_stage_tid_pid] = ts
161
+ elif start_end == '2':
162
+ logger.info("It is a instant event, skip to calculate execution time. item: %s.", row)
163
+ else:
164
+ logger.warning("Can not map the start time for item: %s.", row)
165
+
166
+
167
+ def _calculate_dataset_execution_time(input_file, output_file):
168
+ r"""
169
+ Parse the host info into timeline file, so as to show on UI.
170
+
171
+ Args:
172
+ input_file: the original host_info file, in csv format.
173
+ output_file: the output file, in csv format.
174
+ """
175
+ input_file = validate_and_normalize_path(input_file)
176
+ # execution_time_map is used to store the ExecutionCalculator for each stage.
177
+ execution_time_map = {}
178
+ # ts_map is used to store the start time of each event_stage_tid_pid.
179
+ ts_map = {}
180
+ with open(input_file, 'r') as f:
181
+ for row in csv.DictReader(f):
182
+ try:
183
+ module_name = row['module_name']
184
+ if module_name != 'Dataset':
185
+ continue
186
+ _calculate_dataset_item(row, execution_time_map, ts_map)
187
+ except KeyError as e:
188
+ logger.error("Error occur when analyse line: %s, Details is: %s", row, e)
189
+ continue
190
+ if ts_map:
191
+ logger.warning("Only start time is record for these items:")
192
+ for k, v in ts_map.items():
193
+ logger.warning("event_stage_tid_pid: %s, time: %d us.", k, v)
194
+ output_file = validate_and_normalize_path(output_file)
195
+ flags = os.O_WRONLY | os.O_CREAT | os.O_TRUNC
196
+ modes = stat.S_IWUSR | stat.S_IRUSR
197
+ with os.fdopen(os.open(output_file, flags, modes), 'w') as f:
198
+ csv_writer = csv.writer(f)
199
+ csv_writer.writerow(['Operation', 'Stage', 'Occurrences', 'Avg. time (us)', 'Custom Info'])
200
+ for _, v in execution_time_map.items():
201
+ csv_writer.writerow([v.event, v.stage, v.count, v.average_execution, v.custom_info])
202
+ os.chmod(output_file, modes)
203
+ logger.info('Successfully calculate the execution time and write it to file: %s.', output_file)
204
+
205
+
206
+ def _extract_timeline_item(row, time_line, ts_map):
207
+ """Process one row, try to extract a timeline item."""
208
+ start_end = row['start_end']
209
+ event_stage_tid_pid = row['event'] + '_' + row['stage'] + '_' + row['tid'] + '_' + row['pid']
210
+ # map start and end, put the mapped event into timeline.
211
+ if start_end == '1' and event_stage_tid_pid in ts_map:
212
+ title = row['event'] + '::' + row['stage']
213
+ event = {'name': title, 'cat': row['module_name']}
214
+ ts_end = int(row['time_stamp(us)'])
215
+ ts = ts_map[event_stage_tid_pid]
216
+ event['ts'] = ts
217
+ event['dur'] = ts_end - ts
218
+ event['ph'] = 'X'
219
+ event['pid'] = row['pid']
220
+ event['tid'] = row['tid']
221
+ event['args'] = {'parent_pid': row['parent_pid']}
222
+ time_line.append(event)
223
+ del ts_map[event_stage_tid_pid]
224
+ elif start_end == '0':
225
+ ts = int(row['time_stamp(us)'])
226
+ ts_map[event_stage_tid_pid] = ts
227
+ # Put the instance event into timeline.
228
+ elif start_end == '2':
229
+ title = row['event'] + '::' + row['stage']
230
+ event = {
231
+ 'name': title, 'cat': row['module_name'], 'ts': int(row['time_stamp(us)']), 'ph': 'i',
232
+ 'pid': row['pid'], 'tid': row['tid'], 'args': {'parent_pid': row['parent_pid']}
233
+ }
234
+ time_line.append(event)
235
+ else:
236
+ logger.warning("Can not map the start time for item: %s.", row)
237
+
238
+
239
+ def _parse_host_info(input_file, output_timeline_file, output_memory_file, is_develop_user=True):
240
+ r"""
241
+ Parse the host info into timeline file, so as to show on UI.
242
+
243
+ Args:
244
+ input_file: the original host_info file, in csv format.
245
+ output_timeline_file: the output timeline file, in json format.
246
+ output_memory_file: the output memory_usage file, in csv format.
247
+ is_develop_user: some data only shown to develop users, other users no need to analyse it.
248
+ """
249
+ input_file = validate_and_normalize_path(input_file)
250
+ time_line = []
251
+ # ts_map is used to store the start time of each event_stage_tid_pid
252
+ ts_map = {}
253
+ memory_header = [
254
+ 'tid', 'pid', 'parent_pid', 'module_name', 'event', 'stage', 'level', 'start_end', 'custom_info',
255
+ 'memory_usage(kB)', 'time_stamp(us)'
256
+ ]
257
+ memory_info = []
258
+ with open(input_file, 'r') as f:
259
+ for row in csv.DictReader(f):
260
+ try:
261
+ level = row['level']
262
+ if level == '0' and not is_develop_user:
263
+ continue
264
+ if int(row['time_stamp(us)']) > 0:
265
+ _extract_timeline_item(row, time_line, ts_map)
266
+ if int(row['memory_usage(kB)']) > 0:
267
+ memory_info.append(row)
268
+ except KeyError as e:
269
+ logger.error("Error occur when analyse line: %s, Details is: %s", row, e)
270
+ continue
271
+ if memory_info:
272
+ with os.fdopen(os.open(output_memory_file, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600), 'w') as csv_file:
273
+ csv_writer = csv.DictWriter(csv_file, fieldnames=memory_header)
274
+ csv_writer.writeheader()
275
+ for item in memory_info:
276
+ csv_writer.writerow(item)
277
+ os.chmod(output_memory_file, stat.S_IREAD | stat.S_IWRITE)
278
+ else:
279
+ logger.warning("No memory_usage is record in file: %s", input_file)
280
+
281
+ if ts_map:
282
+ logger.warning("Only start time is record for these items:")
283
+ for k, v in ts_map.items():
284
+ logger.warning("event_stage_tid_pid: %s, time: %d us.", k, v)
285
+ last_dash = k.rfind('_')
286
+ if last_dash == -1:
287
+ logger.error("Can't find pid in the event_stage_tid_pid string: %s", k)
288
+ continue
289
+ second_last_dash = k.rfind('_', 0, last_dash - 1)
290
+ if second_last_dash == -1:
291
+ logger.error("Can't find tid in the event_stage_tid_pid string: %s", k)
292
+ continue
293
+ pid = k[last_dash + 1:]
294
+ tid = k[second_last_dash + 1: last_dash]
295
+ title = k[:second_last_dash]
296
+ unfinished_timeline = {'name': title, 'pid': pid, 'tid': tid, 'ph': 'B', 'ts': int(v)}
297
+ time_line.append(unfinished_timeline)
298
+
299
+ if time_line:
300
+ timeline_file = validate_and_normalize_path(output_timeline_file)
301
+ with os.fdopen(os.open(timeline_file, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600), 'w') as json_file:
302
+ json.dump(time_line, json_file)
303
+ os.chmod(timeline_file, stat.S_IREAD | stat.S_IWRITE)
304
+ else:
305
+ logger.warning("No valid time_stamp is record in file: %s", input_file)
306
+
307
+
308
+ def _ascend_graph_msprof_generator(mindstudio_profiler_output, model_iteration_dict):
309
+ """Executing the msprof export mode."""
310
+ try:
311
+ ProfilerInfo.set_export_start_time(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
312
+ msprof_exporter = AscendMsprofExporter(mindstudio_profiler_output)
313
+ flag = msprof_exporter.export(model_iteration_dict)
314
+ ProfilerInfo.set_export_end_time(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
315
+ return flag
316
+ except (ProfilerException, TimeoutError, FileNotFoundError, RuntimeError) as err:
317
+ logger.warning(str(err))
318
+ return False
319
+
320
+
321
+ def _ascend_graph_msprof_analyse(mindstudio_profiler_output):
322
+ """
323
+ Ascend graph model msprof data analyse.
324
+
325
+ Returns:
326
+ list[obj]: The list is : df_op_summary, df_op_statistic, df_step_trace, df_step_trace_model
327
+ """
328
+ res = ([], [], [], [])
329
+ try:
330
+ msprof_analyser = AscendMsprofDataGenerator(mindstudio_profiler_output)
331
+ res = msprof_analyser.parse()
332
+ return res
333
+ except ProfilerException as err:
334
+ logger.warning(err.message)
335
+ finally:
336
+ pass
337
+ return res
338
+
339
+
340
+ class Profiler:
341
+ r"""
342
+ This class to enable the profiling of MindSpore neural networks.
343
+ MindSpore users can import the mindspore.Profiler, initialize the Profiler object to start profiling,
344
+ and use Profiler.analyse() to stop profiling and analyse the results.
345
+ Users can visualize the results using the `MindSpore Insight
346
+ <https://www.mindspore.cn/mindinsight/docs/en/master/index.html>`_ tool.
347
+ Now, Profiler supports AICORE operator, AICPU operator, HostCPU operator, memory,
348
+ correspondence, cluster, etc data analysis.
349
+
350
+ Args:
351
+ output_path (str, optional): Output data path. Default: ``"./data"`` .
352
+ profiler_level (ProfilerLevel, optional): (Ascend only) The level of profiling. Default: ``None``.
353
+
354
+ - Profiler.Level0: Leanest level of profiling data collection, collects information about the elapsed
355
+ time of the computational operators on the NPU and communication large operator information.
356
+ - Profiler.Level1: Collect more CANN layer AscendCL data and AICore performance metrics and communication
357
+ mini operator information based on Level0.
358
+ - Profiler.Level2: Collect GE and Runtime information in CANN layer on top of Level1
359
+
360
+ op_time (bool, optional): (Ascend/GPU) Whether to collect operators performance data. Default value: ``True``.
361
+ profile_communication (bool, optional): (Ascend only) Whether to collect communication performance data in
362
+ a multi devices training,collect when True. Setting this parameter has no effect during single card
363
+ training. When using this parameter, `op_time` must be set to ``True`` . Default: ``False`` .
364
+ profile_memory (bool, optional): (Ascend only) Whether to collect tensor memory data, collect when ``True`` .
365
+ When using this parameter, `op_time` must be set to True. Default: ``False`` .
366
+ parallel_strategy (bool, optional): (Ascend only) Whether to collect parallel policy performance data.
367
+ Default value: ``True`` .
368
+ start_profile (bool, optional): The start_profile parameter controls whether to enable or disable performance
369
+ data collection based on conditions. Default: ``True`` .
370
+ aicore_metrics (int, optional): (Ascend only) Types of AICORE performance data collected, when using this
371
+ parameter, `op_time` must be set to ``True`` , and the value must be in [-1, 0, 1, 2, 3, 4, 5, 6],
372
+ Default: ``0`` , the data items contained in each metric are as follows:
373
+
374
+ - -1: Does not collect AICORE data.
375
+ - 0: ArithmeticUtilization contains mac_fp16/int8_ratio, vec_fp32/fp16/int32_ratio, vec_misc_ratio etc.
376
+ - 1: PipeUtilization contains vec_ratio, mac_ratio, scalar_ratio, mte1/mte2/mte3_ratio, icache_miss_rate
377
+ etc.
378
+ - 2: Memory contains ub_read/write_bw, l1_read/write_bw, l2_read/write_bw, main_mem_read/write_bw etc.
379
+ - 3: MemoryL0 contains l0a_read/write_bw, l0b_read/write_bw, l0c_read/write_bw etc.
380
+ - 4: ResourceConflictRatio contains vec_bankgroup/bank/resc_cflt_ratio etc.
381
+ - 5: MemoryUB contains ub_read/write_bw_mte, ub_read/write_bw_vector, ub\_/write_bw_scalar etc.
382
+ - 6: L2Cache contains write_cache_hit, write_cache_miss_allocate, r0_read_cache_hit, r1_read_cache_hit etc.
383
+
384
+ l2_cache (bool, optional): (Ascend only) Whether to collect l2 cache data, collect when True.
385
+ Default: ``False`` .
386
+ hbm_ddr (bool, optional): (Ascend only) Whether to collect HBM/DDR read and write rate data, collect when True.
387
+ Default: ``False`` .
388
+ pcie (bool, optional): (Ascend only) Whether to collect PCIe bandwidth data, collect when True.
389
+ Default: ``False`` .
390
+ sync_enable (bool, optional): (GPU only) Whether the profiler collects operators in a synchronous way.
391
+ Default: ``True`` .
392
+
393
+ - True: The synchronous way. Before sending the operator to the GPU, the CPU records the start timestamp.
394
+ Then the operator is returned to the CPU after execution, and the end timestamp is recorded,
395
+ The duration of the operator is the difference between the two timestamps.
396
+ - False: The asynchronous way. The duration of the operator is that of sending from the CPU to the GPU.
397
+ This method can reduce the impact of adding profiler on overall training time.
398
+ data_process (bool, optional): (Ascend/GPU) Whether to collect data to prepare performance data.
399
+ Default value: ``True`` .
400
+ timeline_limit (int, optional): (Ascend/GPU) Set the maximum storage size of the timeline file (unit M).
401
+ When using this parameter, `op_time` must be set to True. Default value: ``500`` .
402
+ profile_framework (str, optional): (Ascend/GPU) The host information to collect, it must be one of
403
+ ["all", "time", "memory", None], When is not set to None, a subdirectory host_info will be generated in the
404
+ specified profiler directory, which stores the collected memory and time files on the Host side.
405
+ Default: "all".
406
+
407
+ - "all": Record both host timestamp and host memory usage.
408
+ - "time": Only record host timestamp.
409
+ - "memory": Only record host memory usage.
410
+ - None: Not record host information.
411
+ data_simplification (bool, optional): (Ascend only) Whether to remove FRAMEWORK data and other redundant data.
412
+ If set to True, only the delivery of profiler and the original performance data in the PROF_XXX
413
+ directory are retained to save disk space.
414
+ Default value: ``True`` .
415
+ host_stack (bool, optional): (Ascend) Whether to collect frame host call stack data.
416
+ Default value: ``True`` .
417
+
418
+ Raises:
419
+ RuntimeError: When the version of CANN does not match the version of MindSpore,
420
+ MindSpore cannot parse the generated ascend_job_id directory structure.
421
+
422
+ Supported Platforms:
423
+ ``Ascend`` ``GPU``
424
+
425
+ Examples:
426
+ >>> import numpy as np
427
+ >>> import mindspore as ms
428
+ >>> from mindspore import nn
429
+ >>> import mindspore.dataset as ds
430
+ >>> from mindspore import Profiler
431
+ >>>
432
+ >>> class Net(nn.Cell):
433
+ ... def __init__(self):
434
+ ... super(Net, self).__init__()
435
+ ... self.fc = nn.Dense(2,2)
436
+ ... def construct(self, x):
437
+ ... return self.fc(x)
438
+ >>>
439
+ >>> def generator():
440
+ ... for i in range(2):
441
+ ... yield (np.ones([2, 2]).astype(np.float32), np.ones([2]).astype(np.int32))
442
+ >>>
443
+ >>> def train(net):
444
+ ... optimizer = nn.Momentum(net.trainable_params(), 1, 0.9)
445
+ ... loss = nn.SoftmaxCrossEntropyWithLogits(sparse=True)
446
+ ... data = ds.GeneratorDataset(generator, ["data", "label"])
447
+ ... model = ms.train.Model(net, loss, optimizer)
448
+ ... model.train(1, data)
449
+ >>>
450
+ >>> if __name__ == '__main__':
451
+ ... # If the device_target is GPU, set the device_target to "GPU"
452
+ ... ms.set_context(mode=ms.GRAPH_MODE, device_target="Ascend")
453
+ ...
454
+ ... # Init Profiler
455
+ ... # Note that the Profiler should be initialized before model.train
456
+ ... profiler = Profiler()
457
+ ...
458
+ ... # Train Model
459
+ ... net = Net()
460
+ ... train(net)
461
+ ...
462
+ ... # Profiler end
463
+ ... profiler.analyse()
464
+ """
465
+
466
+ _hwts_output_filename_target = "output_format_data_hwts_"
467
+ _opcompute_output_filename_target = "output_op_compute_time_"
468
+ _aicpu_op_output_filename_target = "output_data_preprocess_aicpu_"
469
+ _has_analysed = False
470
+ _has_initialized = False
471
+ _ascend_profiling_options = ""
472
+ _ascend_job_id = ""
473
+ ENABLE_STATUS = "on"
474
+ DISABLE_STATUS = "off"
475
+
476
+ def __init__(self, **kwargs):
477
+ if os.getenv("PROFILING_MODE"):
478
+ raise RuntimeError("Profiling is already enabled by PROFILING_MODE env.")
479
+
480
+ self._dev_id = None
481
+ self._cpu_profiler = None
482
+ self._gpu_profiler = None
483
+ self._md_profiler = None
484
+ self._is_heterogeneous = False
485
+ self._profiler_manager = None
486
+ self._timeline_meta = []
487
+ self._init_time = None
488
+ self._ascend_job_id = ''
489
+ self._job_id_env = None
490
+ self._filt_optype_names = ''
491
+ self._output_path = ''
492
+ self._rank_size = 1
493
+ self._rank_id = 0
494
+ self._ascend_profiler = None
495
+ self._timeline_size_limit_byte = 500 * 1024 * 1024 # 500MB
496
+ self._parallel_strategy = True
497
+ self._model_iteration_dict = None
498
+ self._analyse_mode = ANALYSIS_SYNC_MODE
499
+ _environment_check()
500
+ # default aicore_metrics type is ArithmeticUtilization
501
+ self._aicore_metrics_id = 0
502
+ self._l2_cache = self.DISABLE_STATUS
503
+ self._hbm_ddr = self.DISABLE_STATUS
504
+ self._pcie = self.DISABLE_STATUS
505
+ self._data_process = True
506
+ self._op_time = True
507
+ self._profile_communication = False
508
+ self._has_started = False
509
+ self._has_started_twice = False
510
+ self.start_profile = True
511
+ self._profile_memory = False
512
+ self._sync_enable = True
513
+ self._stop_time = 0
514
+ self._dynamic_status = False
515
+ self._profile_framework = "all"
516
+ self._msprof_enable = os.getenv("PROFILER_SAMPLECONFIG")
517
+ self.profiler_level = None
518
+ self._pretty_json = False
519
+ self._analyse_only = kwargs.get("analyse_only", False)
520
+ self._data_simplification = kwargs.get("data_simplification", True)
521
+ self._host_stack = True
522
+ if self._msprof_enable:
523
+ return
524
+ self._start_time = int(time.time() * 1e6) # us
525
+ self._monotonic_time = int(time.monotonic() * 1e6) # us
526
+ logger.info("Profiling: start time: %d", self._start_time)
527
+ if kwargs.get("env_enable"):
528
+ self._profiler_init(kwargs)
529
+ return
530
+ Profiler._has_initialized = True
531
+ # get device_id and device_target
532
+ if self._analyse_only:
533
+ self._device_target = DeviceTarget.ASCEND.value
534
+ self._rank_id = kwargs.get("rank_id", 0)
535
+ else:
536
+ self._get_devid_rankid_and_devtarget()
537
+ self._parser_kwargs(kwargs)
538
+ self._get_output_path(kwargs)
539
+ self._decide_device_target(kwargs)
540
+ if self.start_profile:
541
+ self.start()
542
+
543
+ @staticmethod
544
+ def _get_prof_rank(prof_path: str):
545
+ """get rank id."""
546
+ sub_dirs = os.listdir(os.path.realpath(prof_path))
547
+ info_json_path = ""
548
+ for sub_dir in sub_dirs:
549
+ if sub_dir.startswith("device_"):
550
+ device_id = sub_dir.split("_")[-1]
551
+ info_json_path = os.path.join(prof_path, sub_dir, f"info.json.{device_id}")
552
+ if not os.path.exists(info_json_path):
553
+ return -1
554
+ rank_id, _ = Profiler._parse_info_json(info_json_path)
555
+ return rank_id
556
+
557
+ @staticmethod
558
+ def _check_output_path(output_path):
559
+ """Checking path validity."""
560
+ try:
561
+ output_path = validate_and_normalize_path(output_path)
562
+ except RuntimeError as err:
563
+ raise ProfilerPathErrorException(f'profiling data output path {output_path} is invalid.') from err
564
+ finally:
565
+ pass
566
+ if not os.path.isdir(output_path):
567
+ raise ProfilerDirNotFoundException(output_path)
568
+ return output_path
569
+
570
+ @staticmethod
571
+ def _parse_job_start_time(prof_dir):
572
+ """
573
+ Get the start time of the job.
574
+
575
+ Args:
576
+ input_file (str): The file path of the host start log file.
577
+
578
+ Returns:
579
+ str, job start time.
580
+ """
581
+ try:
582
+ AscendMsprofExporter.check_msprof_env()
583
+ script_path = AscendMsprofExporter.get_msprof_info_path()
584
+ if not script_path:
585
+ logger.warning("Can`t find get_msprof_info.py path, use single-export mode instead.")
586
+ return None
587
+ logger.info("get_msprof_info.py path is : %s", script_path)
588
+ host_dir = os.path.join(prof_dir, 'host')
589
+ cmd = ['python', script_path, '-dir', host_dir]
590
+ outs, _ = AscendMsprofExporter.run_cmd(cmd)
591
+ if not outs:
592
+ logger.warning('Can`t find the msprof info result')
593
+ return None
594
+ result = json.loads(outs)
595
+ if result.get('status', 1) == 1:
596
+ return None
597
+ jor_start_time = result.get('data', {}).get('collection_info', {}).get('Collection start time', None)
598
+ if jor_start_time is not None:
599
+ return float(jor_start_time.strip())
600
+ return None
601
+ except (RuntimeError, JSONDecodeError, AttributeError, TimeoutError, FileNotFoundError) as err:
602
+ logger.warning('Get the drvVersion error, use single-export mode instead. detail : %s', err)
603
+ return None
604
+
605
+ @staticmethod
606
+ def _parse_info_json(info_file):
607
+ """
608
+ Parse info log file, get the rank id and device id of the job.
609
+ Args:
610
+ input_file (str): The file path of the parse info log file.
611
+
612
+ Returns:
613
+ rank id, device id
614
+ """
615
+ with open(info_file, "r") as f:
616
+ info_dict = json.load(f)
617
+
618
+ rank_id = info_dict.get("rank_id", 0)
619
+ dev_info = info_dict.get("DeviceInfo", [])
620
+ dev_id = dev_info[0].get("id", -1)
621
+
622
+ if int(rank_id) < 0:
623
+ rank_id = 0
624
+
625
+ return str(rank_id), str(dev_id)
626
+
627
+ @classmethod
628
+ def offline_analyse(cls, path: str, pretty=False, step_list=None):
629
+ """
630
+ Analyze training performance data offline, which is invoked after performance data collection is completed.
631
+
632
+ Args:
633
+ path (str): The profiling data path which need to be analyzed offline.
634
+ There needs to be a profiler directory in this path.
635
+ pretty (bool, optional): Whether to pretty json files. Default: ``False``.
636
+ step_list (list, optional): A list of steps that need to be analyzed. Default: ``None``.
637
+ By default, all steps will be analyzed.
638
+
639
+ Examples:
640
+ >>> from mindspore import Profiler
641
+ >>> Profiler.offline_analyse("./profiling_path")
642
+ """
643
+ profiler_path = os.path.join(path, "profiler")
644
+ if not os.path.exists(profiler_path):
645
+ raise ProfilerPathErrorException(f'There must be a profiler folder in the data path: {path}.')
646
+
647
+ rank_set = set()
648
+ sub_dirs = os.listdir(os.path.realpath(profiler_path))
649
+ for sub_dir in sub_dirs:
650
+ sub_path = os.path.join(profiler_path, sub_dir)
651
+ if os.path.isdir(sub_path) and re.match(r"^PROF_\d+_\d+_[a-zA-Z0-9]+", sub_dir):
652
+ rank = cls._get_prof_rank(sub_path)
653
+ rank_set.add(rank)
654
+ if not rank_set:
655
+ return
656
+
657
+ process_list = []
658
+ for rank_id in rank_set:
659
+ profiler = cls(analyse_only=True, rank_id=rank_id)
660
+ process = Process(target=profiler.analyse,
661
+ args=(path, pretty, step_list))
662
+ process.start()
663
+ process_list.append(process)
664
+
665
+ for process in process_list:
666
+ process.join()
667
+
668
+ def op_analyse(self, op_name, device_id=None):
669
+ """
670
+ Profiler users can use this interface to obtain operator performance data.
671
+
672
+ Args:
673
+ op_name (str or list): The primitive operator name to query.
674
+ device_id (int, optional): ID of the target device. This parameter is optional during network training or
675
+ inference, and users can use device_id parameter to specify which card operator performance data to
676
+ parse. If this interface is used for offline data parsing, Default: ``0`` .
677
+
678
+ Raises:
679
+ TypeError: If the `op_name` parameter type is incorrect.
680
+ TypeError: If the `device_id` parameter type is incorrect.
681
+ RuntimeError: If MindSpore runs on Ascend, this interface cannot be used.
682
+
683
+ Supported Platforms:
684
+ ``GPU`` ``CPU``
685
+
686
+ Examples:
687
+ >>> from mindspore import Profiler
688
+ >>> from mindspore import nn
689
+ >>> from mindspore import Model
690
+ >>> # Profiler init.
691
+ >>> profiler = Profiler()
692
+ >>> # Train Model or eval Model, taking LeNet5 as an example.
693
+ >>> # Refer to https://gitee.com/mindspore/docs/blob/master/docs/mindspore/code/lenet.py
694
+ >>> net = LeNet5()
695
+ >>> optimizer = nn.Momentum(net.trainable_params(), learning_rate=0.1, momentum=0.9)
696
+ >>> loss = nn.SoftmaxCrossEntropyWithLogits(sparse=True)
697
+ >>> # Create the dataset taking MNIST as an example.
698
+ >>> # Refer to https://gitee.com/mindspore/docs/blob/master/docs/mindspore/code/mnist.py
699
+ >>> dataloader = create_dataset()
700
+ >>> model = Model(net, loss, optimizer)
701
+ >>> model.train(5, dataloader, dataset_sink_mode=False)
702
+ >>>
703
+ >>> # Profiler end
704
+ >>> profiler.analyse()
705
+ >>>
706
+ >>> profiler.op_analyse(op_name=["BiasAdd", "Conv2D"])
707
+ """
708
+ if self._device_target == 'ascend':
709
+ raise RuntimeError("The Interface 'Profiler.op_analyse()' is not supported on Ascend currently.")
710
+ if device_id and not isinstance(device_id, int):
711
+ raise TypeError(f"For 'Profiler.op_analyse()', the parameter device_id must be int, "
712
+ f"but got type {type(device_id)}")
713
+ online_device_id = int(self._dev_id)
714
+ self._dev_id = self._dev_id if device_id is None else device_id
715
+ if self._dev_id is None:
716
+ self._dev_id = 0
717
+ if not isinstance(op_name, str) and not isinstance(op_name, list):
718
+ raise TypeError(f"For 'Profiler.op_analyse()', the parameter op_name must be str or list, "
719
+ f"but got type {type(op_name)}")
720
+ if not op_name:
721
+ raise TypeError(f"For 'Profiler.op_analyse()', the parameter op_name cannot be "", '' or [].")
722
+ parser = GpuFrameWorkParser(self._output_path, self._dev_id, op_name)
723
+ op_info = parser.parse()
724
+ if self._rank_size > 1:
725
+ if online_device_id == int(self._dev_id):
726
+ return op_info
727
+ if online_device_id != int(self._dev_id):
728
+ message = f"For 'Profiler.op_analyse()', the parameter device_id is equal to {self._dev_id}, but the " \
729
+ f"current device id is {online_device_id}, so no operator performance information is queried."
730
+ return message
731
+ return op_info
732
+
733
+ def analyse(self, offline_path=None, pretty=False, step_list=None, mode="sync"):
734
+ """
735
+ Collect and analyze training performance data, support calls during and after training. The example shows above.
736
+
737
+ Args:
738
+ offline_path (Union[str, None], optional): The data path which need to be analyzed with offline mode.
739
+ Offline mode isused in abnormal exit scenario. This parameter should be set to ``None``
740
+ for online mode. Default: ``None``.
741
+ pretty (bool, optional): Whether to pretty json files. Default: ``False``.
742
+ step_list (list, optional): A list of steps that need to be analyzed. Default: ``None``.
743
+ By default, all steps will be analyzed.
744
+ mode (str, optional): Analysis mode, it must be one of ["sync", "async"]. Default: ``sync``.
745
+
746
+ - sync: analyse data in current process, it will block the current process.
747
+ - async: analyse data in subprocess, it will not the current process.Since the parsing process
748
+ will take up extra CPU resources, please enable this mode according to the actual resource situation.
749
+
750
+ """
751
+ try:
752
+ if isinstance(pretty, bool):
753
+ self._pretty_json = pretty
754
+ if mode not in [ANALYSIS_SYNC_MODE, ANALYSIS_ASYNC_MODE]:
755
+ logger.warning("For analyse, the parameter mode must be one of ['sync', 'async'], "
756
+ "it will be set to 'sync'.")
757
+ mode = ANALYSIS_SYNC_MODE
758
+ model_iteration_dict = {}
759
+ if step_list is not None and not isinstance(step_list, list):
760
+ raise ProfilerParamTypeErrorException("Parameter step_list must be a list.")
761
+ if step_list:
762
+ if not all(isinstance(step_id, int) for step_id in step_list):
763
+ raise ProfilerParamTypeErrorException("The elements of the parameter step_list must be integers.")
764
+ step_list.sort()
765
+ if step_list[-1] - step_list[0] != len(step_list) - 1:
766
+ err_msg = "The elements of the parameter step_list must be continuous integers."
767
+ raise ProfilerParamTypeErrorException(err_msg)
768
+ model_iteration_dict[DEFAULT_MODEL_ID] = step_list
769
+ if offline_path is not None and not isinstance(offline_path, str):
770
+ raise ProfilerParamTypeErrorException("For analyse, the type of parameter offline_path must be str.")
771
+ self._analyse(offline_path=offline_path, model_iteration_dict=model_iteration_dict, mode=mode)
772
+ except (ProfilerException, RuntimeError, OSError, TypeError, NameError) as err:
773
+ logger.error("Profiler analyse failed: %s", str(err))
774
+
775
+ def _analyse(self, offline_path=None, model_iteration_dict=None, mode=ANALYSIS_SYNC_MODE):
776
+ """
777
+ Collect and analyze training performance data, support calls during and after training. The example shows above.
778
+
779
+ Args:
780
+ offline_path (Union[str, None], optional): The data path which need to be analysed with offline mode.
781
+ Offline mode isused in abnormal exit scenario. This parameter should be set to ``None``
782
+ for online mode. Default: ``None``.
783
+ model_iteration_dict: Dictionary with model id as the key and iteration id as the value, Default: ``None``.
784
+ mode (str, optional): Analysis mode. Whether to analyse data in subprocess. Default: ``sync``.
785
+ By default, analyse data in current process.
786
+ """
787
+ self._model_iteration_dict = model_iteration_dict
788
+ self._init_profiler_info()
789
+ self._is_support_step_info_collect()
790
+ self._analyse_mode = mode
791
+ parallel_mode = get_auto_parallel_context("parallel_mode")
792
+ stage_num = get_auto_parallel_context("pipeline_stages")
793
+
794
+ ProfilerInfo.set_parallel_info(parallel_mode, stage_num)
795
+ if offline_path:
796
+ ProfilerInfo.set_analyse_start_time(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
797
+ self._ascend_graph_analyse(offline_path=offline_path)
798
+ ProfilerInfo.set_analyse_end_time(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
799
+ ProfilerInfo.save(self._output_path)
800
+ _offline_parse(offline_path)
801
+ return
802
+ if self._msprof_enable:
803
+ return
804
+
805
+ # Stop data collection after all operators are executed.
806
+ _pynative_executor.sync()
807
+
808
+ Profiler._has_initialized = False
809
+ self._dynamic_status = self._profiler_manager.dynamic_status()
810
+ _environment_check()
811
+
812
+ cpu_op_file = glob.glob(os.path.join(self._output_path, 'cpu_op_type_info_*'))
813
+ if self._device_target and self._device_target != DeviceTarget.CPU.value and cpu_op_file:
814
+ self._is_heterogeneous = True
815
+
816
+ ProfilerInfo.set_heterogeneous(self._is_heterogeneous)
817
+ ProfilerInfo.set_analyse_start_time(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
818
+ if self._device_target and self._device_target == DeviceTarget.CPU.value:
819
+ self._cpu_analyse()
820
+
821
+ if self._device_target and self._device_target == DeviceTarget.GPU.value:
822
+ self._gpu_analyse()
823
+
824
+ elif self._device_target and self._device_target == DeviceTarget.ASCEND.value:
825
+ self._ascend_analyse()
826
+ if self._profile_framework:
827
+ if self._device_target != DeviceTarget.CPU.value:
828
+ self._host_info_analyse()
829
+ else:
830
+ logger.warning("The parameter 'profile_framework' is not support for CPU, so there no host_info"
831
+ " directory in the output path.")
832
+ logger.info("Profiling: all the data have been analyzed.")
833
+ ProfilerInfo.set_analyse_end_time(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
834
+ ProfilerInfo.save(self._output_path)
835
+
836
+ def start(self):
837
+ """
838
+ Used for Ascend, GPU, start profiling. Profiling can be turned on based on step and epoch.
839
+
840
+ Raises:
841
+ RuntimeError: If the profiler has already started.
842
+ RuntimeError: If the `start_profile` parameter is not set or is set to ``True``.
843
+
844
+ Examples:
845
+ >>> from mindspore.train import Callback
846
+ >>> from mindspore import Profiler
847
+ >>> class StopAtStep(Callback):
848
+ ... def __init__(self, start_step, stop_step):
849
+ ... super(StopAtStep, self).__init__()
850
+ ... self.start_step = start_step
851
+ ... self.stop_step = stop_step
852
+ ... self.profiler = Profiler(start_profile=False)
853
+ ...
854
+ ... def step_begin(self, run_context):
855
+ ... cb_params = run_context.original_args()
856
+ ... step_num = cb_params.cur_step_num
857
+ ... if step_num == self.start_step:
858
+ ... self.profiler.start()
859
+ ...
860
+ ... def step_end(self, run_context):
861
+ ... cb_params = run_context.original_args()
862
+ ... step_num = cb_params.cur_step_num
863
+ ... if step_num == self.stop_step:
864
+ ... self.profiler.stop()
865
+ ...
866
+ ... def end(self, run_context):
867
+ ... self.profiler.analyse()
868
+ """
869
+ if self._msprof_enable:
870
+ return
871
+
872
+ if not self._has_started:
873
+ if not self._has_started_twice:
874
+ self._has_started = True
875
+ else:
876
+ raise RuntimeError("The profiler has already started. Do not turn on again in the open state.")
877
+
878
+ self._cpu_profiler.step_profiling_enable(True)
879
+ if self._op_time:
880
+ self._cpu_profiler.enable_op_time()
881
+ if self._profile_memory:
882
+ self._cpu_profiler.enable_profile_memory()
883
+
884
+ if self._device_target and self._device_target == DeviceTarget.GPU.value:
885
+ if self._data_process:
886
+ self._md_profiler.start()
887
+ self._gpu_profiler.data_process_enable(True)
888
+ if self._profile_framework or self._op_time:
889
+ self._gpu_profiler.step_profiling_enable(True)
890
+ if self._op_time:
891
+ self._gpu_profiler.enable_op_time()
892
+ elif self._device_target and self._device_target == DeviceTarget.ASCEND.value:
893
+ if self._data_process:
894
+ self._md_profiler.start()
895
+ self._ascend_graph_start()
896
+ ProfilerInfo.set_profiling_start_time(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
897
+ ProfilerInfo.set_system_cnt(c_expression.get_clock_syscnt())
898
+ ProfilerInfo.set_system_time(int(c_expression.get_clock_time() * 1e3)) # cast us to ns
899
+ _framework_profiler_enable_mi()
900
+
901
+ def stop(self):
902
+ """
903
+ Used for Ascend, GPU, stop profiling. Profiling can be turned off based on step and epoch.
904
+
905
+ Raises:
906
+ RuntimeError: If the profiler has not started, this function is disabled.
907
+
908
+ Examples:
909
+ >>> from mindspore.train import Callback
910
+ >>> from mindspore import Profiler
911
+ >>> class StopAtEpoch(Callback):
912
+ ... def __init__(self, start_epoch, stop_epoch):
913
+ ... super(StopAtEpoch, self).__init__()
914
+ ... self.start_epoch = start_epoch
915
+ ... self.stop_epoch = stop_epoch
916
+ ... self.profiler = Profiler(start_profile=False)
917
+ ...
918
+ ... def epoch_begin(self, run_context):
919
+ ... cb_params = run_context.original_args()
920
+ ... epoch_num = cb_params.cur_epoch_num
921
+ ... if epoch_num == self.start_epoch:
922
+ ... self.profiler.start()
923
+ ...
924
+ ... def epoch_end(self, run_context):
925
+ ... cb_params = run_context.original_args()
926
+ ... epoch_num = cb_params.cur_epoch_num
927
+ ... if epoch_num == self.stop_epoch:
928
+ ... self.profiler.stop()
929
+ ...
930
+ ... def end(self, run_context):
931
+ ... self.profiler.analyse()
932
+ """
933
+ if self._msprof_enable:
934
+ return
935
+
936
+ if self._has_started:
937
+ self._has_started = False
938
+ else:
939
+ raise RuntimeError("The profiler has not started, so can not stop. Please call the start() method "
940
+ "before calling the stop() method.")
941
+
942
+ # Stop data collection after all operators are executed.
943
+ _pynative_executor.sync()
944
+
945
+ self._cpu_profiler.stop()
946
+ if self._data_process and self._md_profiler is not None:
947
+ self._md_profiler.stop()
948
+ self._md_profiler.save(self._output_path)
949
+
950
+ if self._device_target and self._device_target == DeviceTarget.GPU.value:
951
+ self._gpu_profiler.stop()
952
+ elif self._device_target and self._device_target == DeviceTarget.ASCEND.value:
953
+ self._ascend_profiler.stop()
954
+
955
+ self._stop_time = int(time.time() * 10000000)
956
+ ProfilerInfo.set_profiling_stop_time(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
957
+ self._init_profiler_info()
958
+ ProfilerInfo.set_diff_time(self._start_time - self._monotonic_time)
959
+ ProfilerInfo.save(self._output_path)
960
+ logger.info("Profiling: stop time: %d", self._stop_time)
961
+
962
+ def _set_ascend_job_id(self, ascend_job_id):
963
+ """Set output_path for offline parsing performance data."""
964
+ if not ascend_job_id:
965
+ return
966
+ self._ascend_job_id = validate_and_normalize_path(ascend_job_id)
967
+ if not os.path.exists(self._ascend_job_id):
968
+ msg = f"Invalid ascend_job_id: {self._ascend_job_id}, Please pass the absolute path of the JOB dir"
969
+ logger.critical(msg)
970
+ raise ValueError(msg)
971
+ self._output_path, _ = os.path.split(self._ascend_job_id)
972
+
973
+ def _profiler_init(self, kwargs):
974
+ """Initialize variables when profiler is enabled by environment variables."""
975
+ options = kwargs.get("env_enable")
976
+ self._has_started = True
977
+ self._start_time = options.get("start_time")
978
+ self._output_path = options.get('file_output_path')
979
+ self._profile_memory = options.get('profile_memory')
980
+ self._parallel_strategy = options.get('parallel_strategy')
981
+ self._timeline_size_limit_byte = options.get('timeline_limit') * 1024 * 1024
982
+ self._data_process = options.get('data_process')
983
+ self._profile_communication = options.get('profile_communication')
984
+ self._op_time = options.get('op_time')
985
+ self._device_target = context.get_context("device_target").lower()
986
+ self._profile_framework = options.get('profile_framework', 'all')
987
+ self._profiler_manager = c_expression.ProfilerManager.get_instance()
988
+ self._cpu_profiler = c_expression.Profiler.get_instance("CPU")
989
+ if self._data_process:
990
+ self._md_profiler = cde.GlobalContext.profiling_manager()
991
+ if self._device_target == DeviceTarget.GPU.value:
992
+ self._gpu_profiler = c_expression.Profiler.get_instance("GPU")
993
+
994
+ if self._device_target == DeviceTarget.ASCEND.value:
995
+ self._ascend_profiler = c_expression.Profiler.get_instance("Ascend")
996
+ self._get_devid_rankid_and_devtarget()
997
+
998
+ def _init_profiler_info(self):
999
+ """Init profiler info filer."""
1000
+ mode = "graph"
1001
+ if context.get_context("mode") == context.PYNATIVE_MODE:
1002
+ mode = "pynative"
1003
+ store_id = self._dev_id if self._device_target == DeviceTarget.GPU.value else self._rank_id
1004
+ ProfilerInfo.init_info(mode, store_id)
1005
+
1006
+ def _decide_device_target(self, kwargs):
1007
+ """Complete Profiler initialization according to device_target"""
1008
+ profiler_manager = c_expression.ProfilerManager
1009
+ self._profiler_manager = profiler_manager.get_instance()
1010
+ if self._profile_framework is None:
1011
+ self._profiler_manager.set_profile_framework("NULL")
1012
+ else:
1013
+ self._profiler_manager.set_profile_framework(self._profile_framework)
1014
+ if self._device_target:
1015
+ cpu_profiler = c_expression.Profiler
1016
+ self._cpu_profiler = cpu_profiler.get_instance("CPU")
1017
+ self._cpu_profiler.init(self._output_path)
1018
+
1019
+ if self._device_target and self._device_target == DeviceTarget.CPU.value:
1020
+ self._cpu_profiler_init(kwargs)
1021
+
1022
+ if self._device_target and self._device_target == DeviceTarget.GPU.value:
1023
+ self._gpu_profiler_init(kwargs)
1024
+
1025
+ elif self._device_target and self._device_target == DeviceTarget.ASCEND.value:
1026
+ self._ascend_profiler_init(kwargs)
1027
+
1028
+ def _cpu_profiler_init(self, kwargs):
1029
+ """Cpu profiler init."""
1030
+ self.start_profile = kwargs.pop("start_profile", True)
1031
+ if not isinstance(self.start_profile, bool):
1032
+ raise TypeError(f"For '{self.__class__.__name__}', the parameter start_profile must be bool, "
1033
+ f"but got type {type(self.start_profile)}")
1034
+
1035
+ def _gpu_profiler_init(self, kwargs):
1036
+ """Gpu profiler init."""
1037
+ # Setup and start MindData Profiling
1038
+ if self._data_process:
1039
+ self._md_profiler = cde.GlobalContext.profiling_manager()
1040
+ self._md_profiler.init()
1041
+ self._parse_parameter_for_gpu(kwargs)
1042
+
1043
+ gpu_profiler = c_expression.Profiler
1044
+ self._gpu_profiler = gpu_profiler.get_instance("GPU")
1045
+ self._gpu_profiler.init(self._output_path)
1046
+ self._gpu_profiler.sync_enable(self._sync_enable)
1047
+ if GlobalComm.WORLD_COMM_GROUP == "nccl_world_group":
1048
+ self._dev_id = str(get_rank())
1049
+ os.environ['DEVICE_ID'] = self._dev_id
1050
+ self._rank_id = self._dev_id
1051
+
1052
+ def _ascend_profiler_init(self, kwargs):
1053
+ """Ascend profiler init."""
1054
+ # Setup and start MindData Profiling
1055
+ if self._data_process:
1056
+ self._md_profiler = cde.GlobalContext.profiling_manager()
1057
+ self._md_profiler.init()
1058
+ self._init_time = int(time.time() * 10000000)
1059
+ logger.info("Profiling: profiling init time: %d", self._init_time)
1060
+ self._parse_parameter_for_ascend(kwargs)
1061
+ os.environ['DEVICE_ID'] = self._dev_id
1062
+
1063
+ self._ascend_profiling_options = json.dumps(self._construct_profiling_options())
1064
+ # Characters longer than 2048 are ignored, resulting in profiling option resolution errors
1065
+ if len(self._ascend_profiling_options) > 2048:
1066
+ msg = f"For '{self.__class__.__name__}', the environment parameter length exceeds " \
1067
+ f"the limit (2048), please input valid parameters."
1068
+ logger.critical(msg)
1069
+ raise ValueError(msg)
1070
+ # use context interface to open profiling, for the new mindspore version(after 2020.5.21)
1071
+ self._ascend_profiler = c_expression.Profiler.get_instance("Ascend")
1072
+ self._ascend_profiler.init(self._output_path, int(self._dev_id), self._ascend_profiling_options)
1073
+ base_profiling_container_path = os.path.join(self._output_path, "container")
1074
+ container_path = os.path.join(base_profiling_container_path, self._dev_id)
1075
+ data_path = os.path.join(container_path, "data")
1076
+ data_path = validate_and_normalize_path(data_path)
1077
+ if not os.path.exists(data_path):
1078
+ os.makedirs(data_path, exist_ok=True)
1079
+
1080
+ def _construct_profiling_options(self):
1081
+ """
1082
+ Construct profiling options to determine which profiling data should be collected.
1083
+ """
1084
+ fp_point = os.environ.get("PROFILING_FP_START", "")
1085
+ bp_point = os.environ.get("PROFILING_BP_END", "")
1086
+
1087
+ profiling_options = {
1088
+ "output": self._output_path,
1089
+ "fp_point": fp_point,
1090
+ "bp_point": bp_point,
1091
+ "training_trace": self.ENABLE_STATUS if self._op_time else self.DISABLE_STATUS,
1092
+ "task_trace": self.ENABLE_STATUS if self._op_time else self.DISABLE_STATUS,
1093
+ "aic_metrics": AICORE_METRICS_DICT.get(self._aicore_metrics_id, "ArithmeticUtilization"),
1094
+ "aicpu": self.ENABLE_STATUS if self._data_process or self._op_time else self.DISABLE_STATUS,
1095
+ "profile_memory": self.ENABLE_STATUS if self._op_time and self._profile_memory else self.DISABLE_STATUS,
1096
+ "hccl": self.ENABLE_STATUS if self._op_time and self._profile_communication else self.DISABLE_STATUS,
1097
+ "l2_cache": self._l2_cache,
1098
+ "hbm_ddr": self._hbm_ddr,
1099
+ "pcie": self._pcie,
1100
+ "parallel_strategy": self.ENABLE_STATUS if self._parallel_strategy else self.DISABLE_STATUS,
1101
+ "op_time": self.ENABLE_STATUS if self._op_time else self.DISABLE_STATUS,
1102
+ "profile_framework": self._profile_framework,
1103
+ "profiler_level": self.profiler_level.value if self.profiler_level else self.DISABLE_STATUS,
1104
+ "host_stack": "on" if self._host_stack else "off"
1105
+ }
1106
+
1107
+ return profiling_options
1108
+
1109
+ def _parse_parameter_for_gpu(self, kwargs):
1110
+ """Parse parameter in Profiler when the device target is GPU."""
1111
+ self.start_profile = kwargs.pop("start_profile", True)
1112
+ if not isinstance(self.start_profile, bool):
1113
+ raise TypeError(f"For '{self.__class__.__name__}', the parameter start_profile must be bool, "
1114
+ f"but got type {type(self.start_profile)}")
1115
+
1116
+ self._sync_enable = kwargs.pop("sync_enable", True)
1117
+ if not isinstance(self._sync_enable, bool):
1118
+ logger.warning("The parameter sync_enable is an invalid value, it will be set to True.")
1119
+ self._sync_enable = True
1120
+
1121
+ def _parse_parameter_for_ascend(self, kwargs):
1122
+ """Parse parameter in Profiler when the device target is Ascend."""
1123
+ ascend_job_id = kwargs.pop("ascend_job_id", "")
1124
+ self._set_ascend_job_id(ascend_job_id)
1125
+ self.start_profile = kwargs.pop("start_profile", True)
1126
+ if not isinstance(self.start_profile, bool):
1127
+ raise TypeError(f"For '{self.__class__.__name__}', the parameter start_profile must be bool, "
1128
+ f"but got type {type(self.start_profile)}")
1129
+
1130
+ self._profile_communication = kwargs.pop("profile_communication", False)
1131
+ if not isinstance(self._profile_communication, bool):
1132
+ logger.warning(f"For '{self.__class__.__name__}', the parameter profile_communication must be bool, "
1133
+ f"but got type {type(self._profile_communication)}, it will be set to False.")
1134
+ self._profile_communication = False
1135
+
1136
+ if self._profile_communication:
1137
+ hccl_option = {"output": self._output_path, "task_trace": self.ENABLE_STATUS}
1138
+ os.environ['PROFILING_OPTIONS'] = json.dumps(hccl_option)
1139
+
1140
+ self._profile_memory = kwargs.pop("profile_memory", False)
1141
+ if not isinstance(self._profile_memory, bool):
1142
+ logger.warning(f"For '{self.__class__.__name__}', the parameter profile_memory must be bool, "
1143
+ f"but got type {type(self._profile_memory)}, it will be set to False.")
1144
+ self._profile_memory = False
1145
+
1146
+ self._aicore_metrics_id = kwargs.pop("aicore_metrics", 0)
1147
+ if not isinstance(self._aicore_metrics_id, int):
1148
+ logger.warning(f"For '{self.__class__.__name__}', the parameter aicore_metrics must be int, "
1149
+ f"but got type {type(self._aicore_metrics_id)}, it will be set to 0.")
1150
+ self._aicore_metrics_id = 0
1151
+
1152
+ if self._aicore_metrics_id not in AICORE_METRICS_DICT:
1153
+ logger.warning(f"For '{self.__class__.__name__}', the parameter aicore_metrics must be in "
1154
+ f"[-1, 0, 1, 2, 3, 4, 5, 6], but got {self._aicore_metrics_id}, it will be set to 0.")
1155
+ self._aicore_metrics_id = 0
1156
+
1157
+ l2_cache_enable = kwargs.pop("l2_cache", False)
1158
+ if not isinstance(l2_cache_enable, bool):
1159
+ logger.warning(f"For '{self.__class__.__name__}', the parameter l2_cache must be bool, "
1160
+ f"but got type {type(l2_cache_enable)}, it will be set to False.")
1161
+ l2_cache_enable = False
1162
+ self._l2_cache = self.ENABLE_STATUS if l2_cache_enable else self.DISABLE_STATUS
1163
+
1164
+ hbm_ddr_enable = kwargs.pop("hbm_ddr", False)
1165
+ if not isinstance(hbm_ddr_enable, bool):
1166
+ logger.warning(f"For '{self.__class__.__name__}', the parameter hbm_ddr must be bool, "
1167
+ f"but got type {type(hbm_ddr_enable)}, it will be set to False.")
1168
+ hbm_ddr_enable = False
1169
+ self._hbm_ddr = self.ENABLE_STATUS if hbm_ddr_enable else self.DISABLE_STATUS
1170
+
1171
+ pcie_enable = kwargs.pop("pcie", False)
1172
+ if not isinstance(pcie_enable, bool):
1173
+ logger.warning(f"For '{self.__class__.__name__}', the parameter pcie must be bool, "
1174
+ f"but got type {type(pcie_enable)}, it will be set to False.")
1175
+ pcie_enable = False
1176
+ self._pcie = self.ENABLE_STATUS if pcie_enable else self.DISABLE_STATUS
1177
+
1178
+ self._parallel_strategy = kwargs.pop("parallel_strategy", True)
1179
+ if not isinstance(self._parallel_strategy, bool):
1180
+ logger.warning(f"For '{self.__class__.__name__}', the parameter parallel_strategy must be bool, "
1181
+ f"but got type {type(self._parallel_strategy)}, it will be set to True.")
1182
+ self._parallel_strategy = True
1183
+
1184
+ self.profiler_level = kwargs.pop("profiler_level", None)
1185
+ if self.profiler_level and not isinstance(self.profiler_level, ProfilerLevel):
1186
+ logger.warning(f"For '{self.__class__.__name__}', the parameter profiler_level must be one of "
1187
+ f"[ProfilerLevel.Level0, ProfilerLevel.Level1, ProfilerLevel.Level2], but got type "
1188
+ f"{type(self.profiler_level)}, it will be set to ProfilerLevel.Level0.")
1189
+ self.profiler_level = ProfilerLevel.Level0
1190
+ elif self.profiler_level == ProfilerLevel.Level0:
1191
+ self._data_process = False
1192
+ self._aicore_metrics_id = -1
1193
+ logger.warning(f"For '{self.__class__.__name__}', when profiler_level set Level0, data_process will be set "
1194
+ f"to False and aicore_metrics set to -1.")
1195
+ elif self.profiler_level == ProfilerLevel.Level1:
1196
+ self._data_process = False
1197
+ logger.warning(f"For '{self.__class__.__name__}', when profiler_level set Level1, data_process will be set "
1198
+ f"to False.")
1199
+
1200
+ def _ascend_analyse(self):
1201
+ """Collect and analyse ascend performance data."""
1202
+ self._rank_size = 1
1203
+ if self._profile_communication and not GlobalComm.INITED:
1204
+ self._profile_communication = False
1205
+
1206
+ if GlobalComm.INITED:
1207
+ self._rank_size = get_group_size()
1208
+ else:
1209
+ self._rank_size = int(os.getenv('RANK_SIZE', '1'))
1210
+ ProfilerInfo.set_rank_size(self._rank_size)
1211
+
1212
+ if self._has_started:
1213
+ self.stop()
1214
+ else:
1215
+ logger.info("No need to stop profiler because profiler has been stopped.")
1216
+ self._ascend_profiler.finalize()
1217
+ # export op data before analyse
1218
+ self._ascend_graph_analyse()
1219
+
1220
+ def _minddata_analyse(self):
1221
+ """Analyse mindadata for ascend graph model."""
1222
+ if not self._data_process:
1223
+ return
1224
+ store_id = self._rank_id if self._device_target == DeviceTarget.ASCEND.value else self._dev_id
1225
+
1226
+ # parse minddata pipeline operator and queue
1227
+ try:
1228
+ MinddataPipelineParser(self._output_path, store_id, self._output_path).parse()
1229
+ except ProfilerException as err:
1230
+ logger.warning(err.message)
1231
+ finally:
1232
+ pass
1233
+
1234
+ # Analyze minddata information
1235
+ logger.info("Profiling: analyzing the minddata information.")
1236
+ try:
1237
+ MinddataProfilingAnalyzer(self._output_path, store_id,
1238
+ self._output_path, pretty=self._pretty_json).analyze()
1239
+ except ProfilerException as err:
1240
+ logger.warning(err.message)
1241
+ finally:
1242
+ pass
1243
+
1244
+ def _minddata_aicpu_analyse(self, source_path, job_id):
1245
+ """Analyse minddata aicpu after ascend."""
1246
+ if not self._data_process:
1247
+ return
1248
+ store_id = self._rank_id if self._device_target == DeviceTarget.ASCEND.value else self._dev_id
1249
+ # Parsing minddata AICPU profiling
1250
+ if self._device_target == DeviceTarget.ASCEND.value:
1251
+ logger.info("Profiling: analyzing the minddata AICPU data.")
1252
+ MinddataParser.execute(source_path, self._output_path, job_id, store_id)
1253
+
1254
+ def _ascend_fpbp_analyse(self, op_summary, steptrace):
1255
+ """
1256
+ Ascned graph model op analyse.
1257
+
1258
+ Returns:
1259
+ dict[obj]: points: the fp bp information
1260
+ """
1261
+ points = None
1262
+ try:
1263
+ dev_id = self._rank_id if self._device_target == DeviceTarget.ASCEND.value else self._dev_id
1264
+ step_trace_point_info_path = os.path.join(self._output_path, f'step_trace_point_info_{dev_id}.json')
1265
+
1266
+ step_trace_point_info_path = validate_and_normalize_path(step_trace_point_info_path)
1267
+
1268
+ fpbp_analyse = AscendFPBPGenerator(op_summary, steptrace, pretty=self._pretty_json)
1269
+ points, _ = fpbp_analyse.parse()
1270
+ fpbp_analyse.write(step_trace_point_info_path)
1271
+ except ProfilerException as err:
1272
+ logger.warning(err.message)
1273
+ finally:
1274
+ pass
1275
+ return points
1276
+
1277
+ def _ascend_op_analyse(self, op_summary, op_statistic, dynamic_status, launch_ops: List):
1278
+ """
1279
+ Ascend graph model hwts analyse.
1280
+
1281
+ Returns:
1282
+ list[obj]: The list is: framework_parser, aicpu_data_parser, optime_parser, op_task_dict
1283
+ """
1284
+ try:
1285
+ dev_id = self._rank_id if self._device_target == DeviceTarget.ASCEND.value else self._dev_id
1286
+
1287
+ op_intermediate_detail_path = os.path.join(self._output_path,
1288
+ f'aicore_intermediate_{dev_id}_detail.csv')
1289
+ op_intermediate_type_path = os.path.join(self._output_path, f'aicore_intermediate_{dev_id}_type.csv')
1290
+ aicpu_intermediate_detail_path = os.path.join(self._output_path, f'aicpu_intermediate_{dev_id}.csv')
1291
+ framework_raw_path = os.path.join(self._output_path, f'framework_raw_{dev_id}.csv')
1292
+
1293
+ op_intermediate_detail_path = validate_and_normalize_path(op_intermediate_detail_path)
1294
+ op_intermediate_type_path = validate_and_normalize_path(op_intermediate_type_path)
1295
+ aicpu_intermediate_detail_path = validate_and_normalize_path(aicpu_intermediate_detail_path)
1296
+ framework_raw_path = validate_and_normalize_path(framework_raw_path)
1297
+
1298
+ if context.get_context("mode") == context.GRAPH_MODE:
1299
+ output_timeline_data_path = os.path.join(self._output_path, f'output_timeline_data_{dev_id}.txt')
1300
+ output_timeline_data_path = validate_and_normalize_path(output_timeline_data_path)
1301
+ else:
1302
+ output_timeline_data_path = None
1303
+
1304
+ op_analyser = AscendOPGenerator(op_summary, op_statistic, dynamic_status, launch_ops)
1305
+ op_analyser.parse()
1306
+ op_analyser.write(op_intermediate_detail_path, op_intermediate_type_path,
1307
+ aicpu_intermediate_detail_path, framework_raw_path, output_timeline_data_path)
1308
+ except (ProfilerException, RuntimeError) as err:
1309
+ logger.warning(str(err))
1310
+ finally:
1311
+ pass
1312
+
1313
+ def _ascend_step_trace_analyse(self, steptrace):
1314
+ """Analyse step trace info."""
1315
+ try:
1316
+ if not self._dynamic_status:
1317
+ dev_id = self._rank_id if self._device_target == DeviceTarget.ASCEND.value else self._dev_id
1318
+ step_trace_intermediate_path = os.path.join(self._output_path,
1319
+ f'step_trace_raw_{dev_id}_detail_time.csv')
1320
+
1321
+ step_trace_intermediate_path = validate_and_normalize_path(step_trace_intermediate_path)
1322
+
1323
+ steptrace_analyser = AscendStepTraceGenerator(steptrace)
1324
+ steptrace_analyser.parse()
1325
+ steptrace_analyser.write(step_trace_intermediate_path)
1326
+ except ProfilerException as err:
1327
+ logger.warning(err.message)
1328
+ finally:
1329
+ pass
1330
+
1331
+ def _ascend_timeline_analyse(self, op_summary, steptrace, source_path, mindstudio_profiler_output) -> List:
1332
+ """Analyse timeline info."""
1333
+ try:
1334
+ logger.info("Profiling: analyzing the timeline data")
1335
+ timeline_analyser = AscendTimelineGenerator(self._output_path, source_path, mindstudio_profiler_output,
1336
+ self._rank_id, self._rank_size, context.get_context('mode'),
1337
+ self._model_iteration_dict.get(DEFAULT_MODEL_ID))
1338
+ timeline_analyser.parse_cluster_data(op_summary, steptrace)
1339
+ timeline_analyser.parse_timeline_data(pretty=self._pretty_json)
1340
+ timeline_analyser.write_timeline_display()
1341
+ timeline_analyser.write_timeline_summary()
1342
+ except (ProfilerIOException, ProfilerFileNotFoundException, RuntimeError) as err:
1343
+ logger.warning('Fail to write timeline data: %s', err)
1344
+ finally:
1345
+ pass
1346
+ return timeline_analyser.get_kernel_event_list()
1347
+
1348
+ def _ascend_dynamic_net_analyse(self, op_summary):
1349
+ """Analyse dynamic shape network info."""
1350
+ if self._profile_communication:
1351
+ logger.warning(
1352
+ "The profile_communication parameter cannot be set on the dynamic shape network.")
1353
+ if self._profile_memory:
1354
+ logger.warning("The profile_memory parameter cannot be set on the dynamic shape network.")
1355
+ logger.warning(
1356
+ "[Profiler]Dynamic Shape network does not support collecting step trace performance data currently.")
1357
+ dynamic_parser = DynamicFrameWorkParser(self._output_path, self._rank_id, pretty=self._pretty_json)
1358
+ dynamic_parser.write_dynamic_shape_data(op_summary)
1359
+
1360
+ def _ascend_flops_analyse(self, op_summary, launch_ops):
1361
+ """Get op FLOPs from op_summary, write output_op_flops_x.csv."""
1362
+ if 'vector_fops' not in op_summary.dtype.names and 'cube_fops' not in op_summary.dtype.names:
1363
+ logger.warning("[Profiler] Can not found cube fops and vector fops data in the op summary.")
1364
+ return
1365
+
1366
+ try:
1367
+ dev_id = self._rank_id if self._device_target == DeviceTarget.ASCEND.value else self._dev_id
1368
+
1369
+ flops_path = os.path.join(self._output_path, f'flops_{dev_id}.txt')
1370
+ flops_summary_path = os.path.join(self._output_path, f'flops_summary_{dev_id}.json')
1371
+
1372
+ flops_path = validate_and_normalize_path(flops_path)
1373
+ flops_summary_path = validate_and_normalize_path(flops_summary_path)
1374
+
1375
+ flops_analyser = AscendFlopsGenerator(op_summary, launch_ops, pretty=self._pretty_json)
1376
+ flops_analyser.parse()
1377
+ flops_analyser.write(flops_path, flops_summary_path)
1378
+
1379
+ except (ProfilerException, RuntimeError) as err:
1380
+ logger.warning(str(err))
1381
+ finally:
1382
+ pass
1383
+
1384
+ def _ascend_graph_memory_analyse(self, points):
1385
+ """Analyse memory usage info."""
1386
+ if not self._profile_memory:
1387
+ return
1388
+ if self._profile_memory and context.get_context("mode") == context.PYNATIVE_MODE:
1389
+ logger.warning("[Profiler]The parameter profile_memory is not supported on Ascend "
1390
+ "PyNative mode currently.")
1391
+ try:
1392
+ logger.info("Profiling: analyzing the memory usage info.")
1393
+ self._analyse_memory_usage(points)
1394
+ except (ProfilerIOException, ProfilerFileNotFoundException, ProfilerRawFileException) as err:
1395
+ logger.warning(err.message)
1396
+ finally:
1397
+ pass
1398
+
1399
+ def _ascend_ms_analyze(self, source_path):
1400
+ """Ascend ms generate"""
1401
+
1402
+ timestamp = time.strftime("%Y%m%d%H%M%S", time.localtime(time.time()))
1403
+ if self._rank_id:
1404
+ ascend_ms_path = f"rank-{self._rank_id}_{timestamp}_ascend_ms"
1405
+ else:
1406
+ ascend_ms_path = f"{socket.gethostname()}--{os.getpid()}_{timestamp}_ascend_ms"
1407
+ ascend_ms_path = os.path.join(self._output_path, ascend_ms_path)
1408
+
1409
+ dev_id = self._rank_id if self._device_target == DeviceTarget.ASCEND.value else self._dev_id
1410
+ ascend_profiler_output_path = os.path.join(ascend_ms_path, 'ASCEND_PROFILER_OUTPUT')
1411
+ os.makedirs(ascend_profiler_output_path, exist_ok=True)
1412
+
1413
+ source_profiler_info_path = os.path.join(self._output_path, f"profiler_info_{dev_id}.json")
1414
+ target_profiler_info_path = os.path.join(ascend_ms_path, f"profiler_info_{dev_id}.json")
1415
+ shutil.copy(source_profiler_info_path, target_profiler_info_path)
1416
+
1417
+ source_timeline_path = os.path.join(self._output_path, f"ascend_timeline_display_{dev_id}.json")
1418
+ target_timeline_path = os.path.join(ascend_profiler_output_path, f"trace_view.json")
1419
+ shutil.copy(source_timeline_path, target_timeline_path)
1420
+
1421
+ src_op_mem_file = os.path.join(self._output_path, f"operator_memory_{dev_id}.csv")
1422
+ if os.path.exists(src_op_mem_file):
1423
+ dst_op_mem_file = os.path.join(ascend_profiler_output_path, f"operator_memory.csv")
1424
+ shutil.copy(src_op_mem_file, dst_op_mem_file)
1425
+
1426
+ ms_output_path = os.path.abspath(
1427
+ os.path.join(source_path, os.path.pardir, 'mindstudio_profiler_output'))
1428
+ static_op_mem_path = os.path.join(ms_output_path, f"static_op_mem_*.csv")
1429
+ src_static_op_mem_path = glob.glob(static_op_mem_path)
1430
+ if src_static_op_mem_path:
1431
+ dst_static_op_mem_file = os.path.join(ascend_profiler_output_path, f"static_op_mem.csv")
1432
+ shutil.copy(src_static_op_mem_path[0], dst_static_op_mem_file)
1433
+
1434
+ self._ascend_graph_cluster_analyse(source_path, ascend_profiler_output_path)
1435
+ self._ascend_graph_communicate_analyse(source_path, ascend_profiler_output_path)
1436
+ AscendIntegrateGenerator(source_path, ascend_profiler_output_path).parse()
1437
+ AscendMemoryGenerator(self._output_path, self._rank_id, source_path, ascend_profiler_output_path).parse()
1438
+
1439
+ def _ascend_graph_cluster_analyse(self, source_path, ascend_profiler_output_path):
1440
+ """Analyse step trace time info"""
1441
+
1442
+ try:
1443
+ logger.info("Profiling: analyzing the step trace time profiler info.")
1444
+
1445
+ step_trace_time_path = os.path.join(ascend_profiler_output_path, f'step_trace_time.csv')
1446
+ step_trace_time_path = validate_and_normalize_path(step_trace_time_path)
1447
+
1448
+ cluster_analyse = AscendClusterGenerator(source_path)
1449
+ cluster_analyse.parse()
1450
+ cluster_analyse.write(step_trace_time_path)
1451
+ except (ProfilerIOException, ProfilerFileNotFoundException, ProfilerRawFileException) as err:
1452
+ logger.warning(err.message)
1453
+ finally:
1454
+ pass
1455
+
1456
+ def _ascend_graph_communicate_analyse(self, source_path, ascend_profiler_output_path):
1457
+ """Analyse communicate info"""
1458
+ if not self._profile_communication:
1459
+ return
1460
+
1461
+ try:
1462
+ logger.info("Profiling: analyzing the communicate and communicate_matrix profiler info.")
1463
+
1464
+ communication_file_path = os.path.join(ascend_profiler_output_path, f'communication.json')
1465
+ communication_file_path = validate_and_normalize_path(communication_file_path)
1466
+
1467
+ communication_matrix_file_path = os.path.join(ascend_profiler_output_path,
1468
+ f"communication_matrix.json")
1469
+ communication_matrix_file_path = validate_and_normalize_path(communication_matrix_file_path)
1470
+
1471
+ analyze_path = os.path.abspath(os.path.join(source_path, os.path.pardir, 'analyze'))
1472
+ communicate_analyser = AscendCommunicationGenerator(analyze_path)
1473
+ communicate_analyser.parse()
1474
+ communicate_analyser.write(communication_file_path, communication_matrix_file_path)
1475
+ except (ProfilerIOException, ProfilerFileNotFoundException, ProfilerRawFileException) as err:
1476
+ logger.warning(err.message)
1477
+ finally:
1478
+ pass
1479
+
1480
+ def _ascend_graph_hccl_analyse(self, mindstudio_profiler_output, steptrace):
1481
+ """Analyse hccl profiler info."""
1482
+ if not self._profile_communication:
1483
+ return
1484
+ if self._profile_communication and context.get_context("mode") == context.PYNATIVE_MODE:
1485
+ logger.warning("[Profiler]The parameter profile_communication is not supported on Ascend "
1486
+ "PyNative mode currently.")
1487
+ return
1488
+ try:
1489
+ logger.info("Profiling: analyzing the hccl profiler info.")
1490
+ dev_id = self._rank_id if self._device_target == DeviceTarget.ASCEND.value else self._dev_id
1491
+
1492
+ hccl_raw_path = os.path.join(self._output_path, f'hccl_raw_{dev_id}.csv')
1493
+ hccl_raw_path = validate_and_normalize_path(hccl_raw_path)
1494
+ hccl_analyse = AscendHCCLGenerator(mindstudio_profiler_output, steptrace)
1495
+ hccl_analyse.parse()
1496
+ hccl_analyse.write(hccl_raw_path)
1497
+
1498
+ except (ProfilerIOException, ProfilerFileNotFoundException, ProfilerRawFileException) as err:
1499
+ logger.warning(err.message)
1500
+ finally:
1501
+ pass
1502
+
1503
+ def _ascend_graph_msadvisor_analyse(self, job_id):
1504
+ """Call MSAdvisor function."""
1505
+ logger.info("MSAdvisor starts running.")
1506
+ msadvisor = Msadvisor(job_id, self._rank_id, self._output_path, pretty=self._pretty_json)
1507
+ try:
1508
+ msadvisor.analyse()
1509
+ except FileNotFoundError as err:
1510
+ logger.warning("MSAdvisor: command not found,"
1511
+ "please check if installed ascend-toolkit and set environment path correctly. %s", err)
1512
+ except OSError as err:
1513
+ logger.warning("Cannot execute binary file: Exec format error. %s", err)
1514
+ except subprocess.CalledProcessError:
1515
+ logger.warning("MSAdvisor running failed, please check MSAdvisor running log.")
1516
+ except (ValueError, ProfilerFileNotFoundException) as err:
1517
+ logger.warning("MSAdvisor running failed. %s", err)
1518
+ finally:
1519
+ pass
1520
+ if context.get_context("mode") == context.PYNATIVE_MODE:
1521
+ logger.warning("Pynative mode does not support MSAdvisor analyzer currently.")
1522
+
1523
+ def _get_kernel_op_map(self, op_summary, kernels: List[CANNEvent]) -> List:
1524
+ """Get the mapping between framework operator and device kernel."""
1525
+ if not kernels:
1526
+ return []
1527
+ kernel_map = {}
1528
+ for kernel in kernels:
1529
+ key = kernel.name if kernel.name.startswith('hcom_') else (kernel.name, str(kernel.ts))
1530
+ kernel_map[key] = kernel.parent
1531
+ launch_ops = [None] * len(op_summary)
1532
+ for index, summary in enumerate(op_summary):
1533
+ ts = str(summary['Task Start Time(us)']).strip("\t")
1534
+ name = summary['Op Name']
1535
+ key = name if name.startswith("hcom_") else (name, ts)
1536
+ launch_op = kernel_map.get(key)
1537
+ if not launch_op:
1538
+ if context.get_context("mode") == context.GRAPH_MODE or not name.startswith("aclnn"):
1539
+ logger.warning(f"Failed to get launch operator for {name}!")
1540
+ continue
1541
+ launch_ops[index] = launch_op.name
1542
+ return launch_ops
1543
+
1544
+ def _ascend_graph_analyse(self, offline_path=None):
1545
+ if offline_path or self._analyse_mode == ANALYSIS_SYNC_MODE:
1546
+ self._ascend_graph_analyse_inner(offline_path)
1547
+ else:
1548
+ MultiProcessPool().add_async_job(self._ascend_graph_analyse_inner)
1549
+
1550
+ def _ascend_graph_analyse_inner(self, offline_path=None):
1551
+ """Ascend graph mode analyse."""
1552
+ job_id = self._get_profiling_job_id(offline_path)
1553
+ if not job_id:
1554
+ return
1555
+ logger.info("Profiling: job id is %s ", job_id)
1556
+
1557
+ self._check_output_path(output_path=self._output_path)
1558
+ source_path = os.path.join(self._output_path, job_id)
1559
+ self._minddata_analyse()
1560
+ if self._op_time:
1561
+ mindstudio_profiler_output = os.path.abspath(
1562
+ os.path.join(source_path, os.path.pardir, 'mindstudio_profiler_output'))
1563
+ flag = _ascend_graph_msprof_generator(mindstudio_profiler_output, self._model_iteration_dict)
1564
+ if not flag:
1565
+ logger.warning('Current driver package not support all export mode, use single export mode, '
1566
+ 'this may lead to performance degradation. Suggest upgrading the driver package.')
1567
+ ProfilerInfo.set_export_flag(flag)
1568
+ op_summary, op_statistic, steptrace, steptrace_model \
1569
+ = _ascend_graph_msprof_analyse(mindstudio_profiler_output)
1570
+ if isinstance(op_statistic, np.ndarray) and op_statistic.shape[0] == 0 or \
1571
+ not isinstance(op_statistic, np.ndarray) and not op_statistic:
1572
+ return
1573
+ kernels = self._ascend_timeline_analyse(op_summary, steptrace, source_path, mindstudio_profiler_output)
1574
+ launch_ops = self._get_kernel_op_map(op_summary, kernels)
1575
+ self._ascend_op_analyse(op_summary, op_statistic, self._dynamic_status, launch_ops)
1576
+ graph_ids = np.unique(op_summary['Model ID']).tolist()
1577
+ points = self._ascend_fpbp_analyse(op_summary, steptrace)
1578
+ if len(graph_ids) == 1:
1579
+ self._ascend_step_trace_analyse(steptrace)
1580
+ else:
1581
+ self._ascend_step_trace_analyse(steptrace_model)
1582
+ if self._dynamic_status:
1583
+ self._ascend_dynamic_net_analyse(op_summary)
1584
+ self._ascend_flops_analyse(op_summary, launch_ops)
1585
+ self._ascend_graph_memory_analyse(points)
1586
+ self._ascend_ms_analyze(mindstudio_profiler_output)
1587
+ self._ascend_graph_hccl_analyse(mindstudio_profiler_output, steptrace)
1588
+ self._ascend_graph_msadvisor_analyse(job_id)
1589
+ self._minddata_aicpu_analyse(self._output_path, job_id)
1590
+ ProfilerInfo.set_graph_ids(graph_ids)
1591
+ try:
1592
+ ProfilerPathManager.simplify_data(self._output_path, self._data_simplification)
1593
+ except RuntimeError as err:
1594
+ logger.error('Profilier simplify data failed, %s', str(err))
1595
+
1596
+ def _ascend_graph_start(self):
1597
+ """Ascend graph mode start profiling."""
1598
+ op_range_file = os.path.join(self._framework_path, "op_range_" + str(self._rank_id))
1599
+ if os.path.exists(op_range_file):
1600
+ os.remove(op_range_file)
1601
+ logger.info("Clear old op range filer.")
1602
+ self._ascend_profiler.start()
1603
+
1604
+ def _gpu_analyse(self):
1605
+ """Collect and analyse gpu performance data."""
1606
+ self._dev_id = context.get_context("device_id")
1607
+ self._rank_size = 1
1608
+ if GlobalComm.WORLD_COMM_GROUP == "nccl_world_group":
1609
+ self._dev_id = str(get_rank())
1610
+
1611
+ if GlobalComm.INITED:
1612
+ self._rank_size = get_group_size()
1613
+ else:
1614
+ self._rank_size = int(os.getenv('RANK_SIZE', '1'))
1615
+
1616
+ ProfilerInfo.set_rank_size(self._rank_size)
1617
+
1618
+ if self._has_started:
1619
+ self.stop()
1620
+ else:
1621
+ logger.info("No need to stop profiler because profiler has been stopped.")
1622
+
1623
+ self._minddata_analyse()
1624
+
1625
+ try:
1626
+ self._analyse_step_relation_info()
1627
+ except ProfilerException as err:
1628
+ logger.warning(err.message)
1629
+ finally:
1630
+ pass
1631
+
1632
+ def _is_support_step_info_collect(self, analyse_step_trace=True):
1633
+ """Whether iteration related information needs to be parsed."""
1634
+ profiler_info = ProfilerInfo.get_profiler_info()
1635
+ graph_ids = profiler_info.get("graph_ids")
1636
+ if graph_ids and len(graph_ids) > 1:
1637
+ analyse_step_trace = False
1638
+ logger.warning(
1639
+ "[Profiler]Current model has multiple sub graphs, the segmentation of steps may be inaccurate.")
1640
+ if context.get_context("mode") == context.PYNATIVE_MODE:
1641
+ analyse_step_trace = False
1642
+ logger.warning(
1643
+ "[Profiler]Pynative mode does not support collecting step trace performance data currently.")
1644
+ if self._is_heterogeneous:
1645
+ analyse_step_trace = False
1646
+ logger.warning(
1647
+ "[Profiler]Profiler does not support collecting step trace performance data for heterogeneous "
1648
+ "scenarios currently.")
1649
+ return analyse_step_trace
1650
+
1651
+ def _analyse_step_relation_info(self):
1652
+ """Parse iteration related information."""
1653
+ if not self._op_time:
1654
+ return
1655
+ reduce_op_type = self._get_step_reduce_op_type()
1656
+ timeline_generator = self._generate_timeline(reduce_op_type)
1657
+ parser = GpuFrameWorkParser(self._output_path, self._dev_id)
1658
+ graph_ids = parser.get_graph_ids()
1659
+ ProfilerInfo.set_graph_ids(graph_ids)
1660
+ self._analyse_step_trace(
1661
+ is_training_mode_flag=timeline_generator.check_op_name('Gradients'),
1662
+ is_gpu_kernel_async_launch_flag=timeline_generator.is_gpu_kernel_async_launch()
1663
+ )
1664
+ if self._dynamic_status:
1665
+ parser.analyse_dynamic_shape_data(self._timeline_meta)
1666
+
1667
+ def _get_step_reduce_op_type(self):
1668
+ """Gets all communication operator names."""
1669
+
1670
+ step_trace_original_filename = f'step_trace_profiling_{self._dev_id}.txt'
1671
+ step_trace_file_path = os.path.join(self._output_path, step_trace_original_filename)
1672
+ step_trace_file_path = validate_and_normalize_path(step_trace_file_path)
1673
+ reduce_op_type = []
1674
+ with open(step_trace_file_path, 'r') as f_obj:
1675
+ one_step_info = f_obj.readline().strip().split()
1676
+ # The communication operator starts at index 4.
1677
+ for reduce_item in one_step_info[4:]:
1678
+ reduce_op_type.append(reduce_item.split(',')[0].split('/')[-1])
1679
+ return reduce_op_type
1680
+
1681
+ def _cpu_analyse(self):
1682
+ """Collect and analyse cpu performance data."""
1683
+ if self._has_started:
1684
+ self.stop()
1685
+ else:
1686
+ logger.info("No need to stop profiler because profiler has been stopped.")
1687
+
1688
+ if not self._op_time:
1689
+ return
1690
+ try:
1691
+ timeline_generator = CpuTimelineGenerator(self._output_path, self._rank_id, context.get_context("mode"))
1692
+ timeline_generator.init_timeline(pretty=self._pretty_json)
1693
+ timeline_generator.write_timeline(self._timeline_size_limit_byte)
1694
+ timeline_generator.write_timeline_summary()
1695
+ except (ProfilerIOException, ProfilerFileNotFoundException, RuntimeError) as err:
1696
+ logger.warning('Fail to write timeline data: %s', err)
1697
+ raise RuntimeError('Fail to write timeline data.') from err
1698
+ if context.get_context("mode") == context.PYNATIVE_MODE:
1699
+ raise RuntimeError("Currently, the CPU platform does not support Pynative mode to collect performance "
1700
+ "data.")
1701
+
1702
+ def _analyse_step_trace(self, source_path=None, framework_parser=None, is_training_mode_flag=True,
1703
+ is_gpu_kernel_async_launch_flag=False):
1704
+ """
1705
+ Analyse step trace data and save the result.
1706
+
1707
+ Args:
1708
+ source_path (str): The directory that contains the step trace original data.
1709
+ framework_parser (FrameworkParser): The framework parse instance.
1710
+ is_training_mode_flag (bool): Whether in training mode or not.
1711
+ """
1712
+ logger.info("Begin to parse step trace.")
1713
+ # construct output path
1714
+ dev_id = self._rank_id if self._device_target == DeviceTarget.ASCEND.value else self._dev_id
1715
+ step_trace_intermediate_file_path = os.path.join(
1716
+ self._output_path,
1717
+ f'step_trace_raw_{dev_id}_detail_time.csv'
1718
+ )
1719
+ point_info_file_path = os.path.join(
1720
+ self._output_path,
1721
+ f'step_trace_point_info_{dev_id}.json'
1722
+ )
1723
+ step_trace_intermediate_file_path = validate_and_normalize_path(step_trace_intermediate_file_path)
1724
+ point_info_file_path = validate_and_normalize_path(point_info_file_path)
1725
+
1726
+ if self._device_target and self._device_target == DeviceTarget.GPU.value:
1727
+ if context.get_context("mode") != context.PYNATIVE_MODE:
1728
+ input_file_path = os.path.join(self._output_path, f'step_trace_profiling_{self._dev_id}.txt')
1729
+ input_file_path = validate_and_normalize_path(input_file_path)
1730
+ parser = GpuStepTraceParser(input_dir=input_file_path,
1731
+ output_file_path=step_trace_intermediate_file_path,
1732
+ is_training_mode=is_training_mode_flag,
1733
+ is_gpu_kernel_async_launch=is_gpu_kernel_async_launch_flag)
1734
+ parser.parse_and_save()
1735
+ point_info = parser.record_point_info(point_info_file_path)
1736
+ # print parser result
1737
+ parser.show()
1738
+ logger.info("Finish saving the intermediate result: %s", step_trace_intermediate_file_path)
1739
+ logger.info("The point info is: %s", point_info)
1740
+
1741
+ return point_info, is_training_mode_flag
1742
+ return {}, is_training_mode_flag
1743
+
1744
+ # whether keep the first step
1745
+ skip_first_step_flag = framework_parser.check_op_name(INIT_OP_NAME)
1746
+ # recognize inference or training mode
1747
+ is_training_mode_flag = framework_parser.check_op_name("Gradients")
1748
+ # parser the step trace files and save the result to disk
1749
+ source_path = validate_and_normalize_path(source_path)
1750
+ parser = AscendStepTraceParser(input_dir=source_path,
1751
+ output_file_path=step_trace_intermediate_file_path,
1752
+ skip_first_step=skip_first_step_flag,
1753
+ is_training_mode=is_training_mode_flag)
1754
+ parser.set_task_id_op_name_dict(framework_parser.to_task_id_full_op_name_dict())
1755
+ parser.parse_and_save()
1756
+ point_info = parser.record_point_info(point_info_file_path)
1757
+
1758
+ # print parser result
1759
+ parser.show()
1760
+ logger.info("Finish saving the intermediate result: %s", step_trace_intermediate_file_path)
1761
+ logger.info("The point info is: %s", point_info)
1762
+
1763
+ return point_info, is_training_mode_flag
1764
+
1765
+ def _generate_timeline(self, reduce_op_type):
1766
+ """Used for gpu, generate timeline info, write to json format file."""
1767
+ try:
1768
+ timeline_generator = GpuTimelineGenerator(self._output_path, self._dev_id, self._rank_size,
1769
+ context.get_context("mode"))
1770
+ timeline_generator.init_timeline(reduce_op_type)
1771
+ self._timeline_meta = timeline_generator.write_timeline(self._timeline_size_limit_byte)
1772
+ timeline_generator.write_timeline_summary()
1773
+ return timeline_generator
1774
+ except (ProfilerIOException, ProfilerFileNotFoundException, RuntimeError) as err:
1775
+ logger.warning('Fail to write timeline data: %s', err)
1776
+ raise RuntimeError('Fail to write timeline data.') from err
1777
+
1778
+ def _analyse_memory_usage(self, points):
1779
+ """Analyse memory usage data."""
1780
+ integrator = Integrator(self._output_path, self._rank_id)
1781
+ aicore_detail_data = integrator.get_aicore_detail_data()
1782
+ memory_parser = MemoryUsageParser(self._output_path, self._rank_id, pretty=self._pretty_json)
1783
+ memory_parser.init_memory_usage_info(aicore_detail_data, points)
1784
+ memory_parser.write_memory_files()
1785
+
1786
+ def _get_profiling_job_id(self, offline_path):
1787
+ """Get profiling job id, which was generated by ada service.
1788
+
1789
+ Returns:
1790
+ str, profiling job id.
1791
+ """
1792
+
1793
+ if offline_path:
1794
+ self._output_path = os.path.join(offline_path, 'profiler')
1795
+
1796
+ job_id = ""
1797
+ job_dirs = filter(lambda item: item.startswith('JOB') or item.startswith('PROF') and os.path.isdir(
1798
+ os.path.join(self._output_path, item)), os.listdir(self._output_path))
1799
+ sorted_job_dirs = sorted(
1800
+ job_dirs, key=lambda x: os.path.getmtime(os.path.join(self._output_path, x)), reverse=True)
1801
+
1802
+ for dir_name in sorted_job_dirs:
1803
+ prof_dir = os.path.join(self._output_path, dir_name)
1804
+ device_dir = [dir for dir in os.listdir(prof_dir) \
1805
+ if dir.startswith('device') and os.path.isdir(os.path.join(prof_dir, dir))]
1806
+ job_dir = os.path.join(self._output_path, dir_name, device_dir[0])
1807
+
1808
+ if get_file_path(job_dir, "start_info") is None:
1809
+ logger.warning("Find profiling job path %s, but host_start.log not exist, "
1810
+ "profiler will ignore this job dir.", job_dir)
1811
+ continue
1812
+
1813
+ info_file_path = get_file_path(job_dir, "info.json")
1814
+ if info_file_path is None:
1815
+ logger.warning("Find profiling job path %s, but info.json not exist, "
1816
+ "profiler will ignore this job dir.", job_dir)
1817
+ continue
1818
+
1819
+ prof_rank_id, prof_device_id = self._parse_info_json(info_file_path)
1820
+ job_start_time = self._parse_job_start_time(prof_dir)
1821
+
1822
+ if offline_path:
1823
+ if self._rank_id != prof_rank_id:
1824
+ continue
1825
+ self._start_time = int(job_start_time)
1826
+ else:
1827
+ if self._dev_id != prof_device_id and self._rank_id != prof_rank_id:
1828
+ logger.debug("Find profiling find job path %s, but not current training device id. "
1829
+ "Current training rank id %s, but job path rank id: %s, "
1830
+ "profiler will ignore this job dir.", job_dir, self._rank_id, prof_rank_id)
1831
+ continue
1832
+
1833
+ if job_start_time < self._start_time:
1834
+ logger.warning("Find profiling job path %s, but start_time(%d) is earlier than this training "
1835
+ "start_time(%d), profiler will ignore this job dir.",
1836
+ job_dir, job_start_time, self._start_time)
1837
+ continue
1838
+
1839
+ job_id = os.path.join(dir_name, device_dir[0])
1840
+ break
1841
+
1842
+ if not job_id:
1843
+ msg = "Fail to get profiling job, output path is {}, " \
1844
+ "please check whether job dir or prof dir(name startswith JOB or PROF) in output path " \
1845
+ "was generated, or may be the device id from job dir dismatch the " \
1846
+ "device_id in current process.".format(self._output_path)
1847
+ logger.warning(msg)
1848
+
1849
+ return job_id
1850
+
1851
+ def _query_op_type_info(self):
1852
+ """
1853
+ Query AICORE operator type information.
1854
+
1855
+ Returns:
1856
+ list[list], the AICORE operator type and execution time information.
1857
+ """
1858
+ integrator = Integrator(self._output_path, self._rank_id)
1859
+ return integrator.get_aicore_data()
1860
+
1861
+ def _query_op_detail_info(self, op_type_order):
1862
+ """
1863
+ Query AICORE operator detail information.
1864
+
1865
+ Args:
1866
+ op_type_order(list): The name of the op type in order.
1867
+
1868
+ Returns:
1869
+ dict, the AICORE operator detail information.
1870
+ """
1871
+
1872
+ op_type_condition = {}
1873
+ if self._filt_optype_names:
1874
+ op_type_condition['not_in'] = self._filt_optype_names
1875
+
1876
+ filter_condition = {
1877
+ 'op_type': op_type_condition,
1878
+ 'is_display_detail': False,
1879
+ }
1880
+ integrator = Integrator(self._output_path, self._rank_id)
1881
+ return integrator.query_and_sort_by_op_type(filter_condition, op_type_order)
1882
+
1883
+ def _get_devid_rankid_and_devtarget(self):
1884
+ """Get device id and rank id and target of this training."""
1885
+
1886
+ device_target = ""
1887
+ dev_id = ""
1888
+ rank_id = ""
1889
+ try:
1890
+ dev_id = str(context.get_context("device_id"))
1891
+ device_target = context.get_context("device_target").lower()
1892
+ except ValueError as err:
1893
+ logger.error("Profiling: fail to get context, %s", err)
1894
+
1895
+ if not dev_id or not dev_id.isdigit():
1896
+ dev_id = str(get_local_rank()) if GlobalComm.INITED and device_target == DeviceTarget.ASCEND.value \
1897
+ else os.getenv('DEVICE_ID')
1898
+ if not dev_id or not dev_id.isdigit():
1899
+ dev_id = "0"
1900
+ logger.warning("Fail to get DEVICE_ID, use 0 instead.")
1901
+
1902
+ if device_target and device_target not in [DeviceTarget.ASCEND.value, DeviceTarget.GPU.value,
1903
+ DeviceTarget.CPU.value]:
1904
+ msg = "Profiling: unsupported backend: %s" % device_target
1905
+ raise RuntimeError(msg)
1906
+
1907
+ rank_id = str(get_rank()) if GlobalComm.INITED and device_target == DeviceTarget.ASCEND.value \
1908
+ else os.getenv("RANK_ID")
1909
+ if not rank_id or not rank_id.isdigit():
1910
+ rank_id = "0"
1911
+ logger.warning(f"For '{self.__class__.__name__}', fail to get RANK_ID from environment, "
1912
+ f"use 0 instead.")
1913
+
1914
+ self._dev_id = dev_id
1915
+ self._device_target = device_target.lower()
1916
+ if device_target == DeviceTarget.GPU.value:
1917
+ self._rank_id = dev_id
1918
+ else:
1919
+ self._rank_id = rank_id
1920
+
1921
+ def _get_output_path(self, kwargs):
1922
+ """Get output path of profiling data."""
1923
+ if os.getenv("MS_DIAGNOSTIC_DATA_PATH") and kwargs.get("output_path") is not None:
1924
+ logger.warning("Both parameter output_path and environment variable MS_DIAGNOSTIC_DATA_PATH"
1925
+ " have values set, and the profiling data saving path is the value set "
1926
+ "in parameter output_path")
1927
+ if kwargs.get("output_path") is None:
1928
+ if "output_path" in kwargs:
1929
+ kwargs.pop("output_path")
1930
+ # Environment variables are mainly set for the convenience of cloud profiler.
1931
+ output_path = os.getenv("MS_DIAGNOSTIC_DATA_PATH")
1932
+ if output_path:
1933
+ self._output_path = validate_and_normalize_path(output_path)
1934
+ else:
1935
+ output_path = "data"
1936
+ self._output_path = validate_and_normalize_path(output_path)
1937
+ else:
1938
+ output_path = kwargs.pop("output_path")
1939
+ self._output_path = validate_and_normalize_path(output_path)
1940
+
1941
+ self._output_path = os.path.join(self._output_path, "profiler")
1942
+ if not os.path.exists(self._output_path):
1943
+ os.makedirs(self._output_path, exist_ok=True)
1944
+ os.chmod(self._output_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
1945
+ else:
1946
+ logger.warning("The target dir already exists. "
1947
+ "There may be some old profiling data, and they will be rewritten in the end.")
1948
+ self._framework_path = os.path.join(self._output_path, "FRAMEWORK")
1949
+ if not os.path.exists(self._framework_path):
1950
+ os.makedirs(self._framework_path, exist_ok=True)
1951
+ os.chmod(self._framework_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
1952
+
1953
+ def _parser_kwargs(self, kwargs):
1954
+ """Parse kwargs vale."""
1955
+ self._op_time = kwargs.get("op_time", True)
1956
+
1957
+ env_run_config = json.loads(os.getenv("MS_PROFILER_RUN_CONFIG", "{}"))
1958
+ params = list(kwargs.keys())
1959
+ if not env_run_config.get("start"):
1960
+ for param in params:
1961
+ if param not in DeviceSupportParam.__getattr__(f'{self._device_target}'.upper()).value:
1962
+ logger.warning("%s is an invalid param which doesn't work.", param)
1963
+ kwargs.pop(param)
1964
+ elif not self._op_time and param not in ALWAYS_VALID_PARAM:
1965
+ logger.warning(f"When op_time is set to False, the parameter '{param}' setting is invalid.")
1966
+
1967
+ if not isinstance(self._op_time, bool):
1968
+ logger.warning(f"For '{self.__class__.__name__}', the parameter op_time must be bool, "
1969
+ f"but got type {type(self._op_time)}, it will be set to True.")
1970
+ self._op_time = True
1971
+
1972
+ self._data_process = kwargs.pop("data_process", True)
1973
+ if not isinstance(self._data_process, bool):
1974
+ logger.warning(f"For '{self.__class__.__name__}', the parameter data_process must be bool, "
1975
+ f"but got type {type(self._data_process)}, it will be set to True.")
1976
+ self._data_process = True
1977
+
1978
+ timeline_limit = kwargs.pop("timeline_limit", 500)
1979
+ if isinstance(timeline_limit, bool) or not isinstance(timeline_limit, int):
1980
+ logger.warning(f"For '{self.__class__.__name__}', the parameter timeline_limit must be int, "
1981
+ f"but got type {type(timeline_limit)}, it will be set to 500.")
1982
+ timeline_limit = 500
1983
+ if timeline_limit <= 0:
1984
+ logger.warning(
1985
+ "[Profiler]The 'timeline_limit' parameter must be greater than 0, it will be set to 500.")
1986
+ timeline_limit = 500
1987
+ self._timeline_size_limit_byte = timeline_limit * 1024 * 1024
1988
+ self._profile_framework = kwargs.pop("profile_framework", "all")
1989
+ if self._profile_framework not in ["memory", "time", "all", None]:
1990
+ logger.warning(f"For '{self.__class__.__name__}', the parameter profile_framework must be one of ['memory',"
1991
+ f" 'time', 'all', None], but got {self._profile_framework}, it will be set to 'all'.")
1992
+ self._profile_framework = "all"
1993
+ if not isinstance(self._data_simplification, bool):
1994
+ logger.warning(f"For '{self.__class__.__name__}', the parameter data_simplification must be bool, "
1995
+ f"but got type {type(self._data_simplification)}, it will be set to True.")
1996
+ self._data_simplification = True
1997
+
1998
+ if not isinstance(self._data_simplification, bool):
1999
+ logger.warning(f"For '{self.__class__.__name__}', the parameter data_simplification must be bool, "
2000
+ f"but got type {type(self._data_simplification)}, it will be set to True.")
2001
+ self._data_simplification = True
2002
+
2003
+ self._host_stack = kwargs.pop("host_stack", True)
2004
+ if not isinstance(self._host_stack, bool):
2005
+ logger.warning(f"For '{self.__class__.__name__}', the parameter host_stack must be bool, but got "
2006
+ f"type {type(self._host_stack)}, it will be set to True.")
2007
+ self._host_stack = True
2008
+
2009
+ def _host_info_analyse(self):
2010
+ """
2011
+ Read data from the csv file, and write it into timeline file, so the timeline can be show on tracing tool.
2012
+ """
2013
+ logger.info("Profiling HostInfo start.")
2014
+ host_dir = os.path.join(self._output_path, 'host_info')
2015
+ host_dir = validate_and_normalize_path(host_dir)
2016
+ if not os.path.exists(host_dir):
2017
+ logger.warning("Host info directory: %s not exist.", host_dir)
2018
+ return
2019
+ csv_file_name = 'host_info_' + str(self._rank_id) + '.csv'
2020
+ json_file_name = 'timeline_' + str(self._rank_id) + '.json'
2021
+ memory_file_name = 'host_memory_' + str(self._rank_id) + '.csv'
2022
+ dataset_file_name = 'dataset_' + str(self._rank_id) + '.csv'
2023
+ host_info_file = os.path.join(self._output_path, 'host_info', csv_file_name)
2024
+ timeline_file = os.path.join(self._output_path, 'host_info', json_file_name)
2025
+ memory_file = os.path.join(self._output_path, 'host_info', memory_file_name)
2026
+ dataset_execution_file = os.path.join(self._output_path, 'host_info', dataset_file_name)
2027
+ _parse_host_info(host_info_file, timeline_file, memory_file)
2028
+ _calculate_dataset_execution_time(host_info_file, dataset_execution_file)
2029
+ logger.info("Profile HostInfo finished.")
2030
+
2031
+
2032
+ def _offline_parse(offline_path):
2033
+ """Parse data in abnormal scenario, only support for host_info at present."""
2034
+ logger.info("Profiling HostInfo offline start.")
2035
+ host_dir = os.path.join(offline_path, 'profiler', 'host_info')
2036
+ host_dir = validate_and_normalize_path(host_dir)
2037
+ if not os.path.exists(host_dir):
2038
+ logger.warning("Host info directory: %s not exist.", host_dir)
2039
+ return
2040
+ files = os.listdir(host_dir)
2041
+ for file in files:
2042
+ if not file.startswith("host_info_") or not file.endswith(".csv"):
2043
+ continue
2044
+ rank_id = file.split('_')[-1].split('.')[0]
2045
+ if not rank_id.isdigit():
2046
+ logger.info("Cannot get rank_id from file: %s, skip it", file)
2047
+ return
2048
+ host_info_file = os.path.join(host_dir, file)
2049
+ timeline_file = os.path.join(host_dir, f'timeline_{rank_id}.json')
2050
+ memory_file = os.path.join(host_dir, f'host_memory_{rank_id}.csv')
2051
+ dataset_execution_file = os.path.join(host_dir, f'dataset_{rank_id}.csv')
2052
+ _parse_host_info(host_info_file, timeline_file, memory_file)
2053
+ _calculate_dataset_execution_time(host_info_file, dataset_execution_file)
2054
+ logger.info("Profile HostInfo offline finished.")