mindspore 2.4.10__cp311-cp311-win_amd64.whl → 2.5.0__cp311-cp311-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


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

Files changed (366) hide show
  1. mindspore/.commit_id +1 -1
  2. mindspore/__init__.py +8 -3
  3. mindspore/_c_dataengine.cp311-win_amd64.pyd +0 -0
  4. mindspore/_c_expression.cp311-win_amd64.pyd +0 -0
  5. mindspore/_c_mindrecord.cp311-win_amd64.pyd +0 -0
  6. mindspore/_checkparam.py +0 -5
  7. mindspore/_extends/parallel_compile/akg_compiler/gen_custom_op_files.py +1 -1
  8. mindspore/_extends/parse/compile_config.py +64 -0
  9. mindspore/_extends/parse/deprecated/__init__.py +0 -0
  10. mindspore/_extends/parse/deprecated/deprecated_tensor_method.py +375 -0
  11. mindspore/_extends/parse/parser.py +23 -5
  12. mindspore/_extends/parse/standard_method.py +123 -27
  13. mindspore/_extends/pijit/pijit_func_white_list.py +1 -1
  14. mindspore/amp.py +7 -1
  15. mindspore/avcodec-59.dll +0 -0
  16. mindspore/avdevice-59.dll +0 -0
  17. mindspore/avfilter-8.dll +0 -0
  18. mindspore/avformat-59.dll +0 -0
  19. mindspore/avutil-57.dll +0 -0
  20. mindspore/boost/boost_cell_wrapper.py +136 -41
  21. mindspore/common/__init__.py +3 -1
  22. mindspore/common/_register_for_tensor.py +0 -1
  23. mindspore/common/_stub_tensor.py +25 -4
  24. mindspore/common/_tensor_cpp_method.py +17 -0
  25. mindspore/common/_tensor_docs.py +6132 -0
  26. mindspore/common/api.py +98 -21
  27. mindspore/common/dtype.py +34 -34
  28. mindspore/common/dump.py +2 -1
  29. mindspore/common/file_system.py +8 -3
  30. mindspore/common/generator.py +2 -0
  31. mindspore/common/hook_handle.py +3 -1
  32. mindspore/common/initializer.py +3 -4
  33. mindspore/common/lazy_inline.py +8 -2
  34. mindspore/common/mindir_util.py +10 -2
  35. mindspore/common/parameter.py +31 -15
  36. mindspore/common/tensor.py +713 -1337
  37. mindspore/communication/__init__.py +1 -1
  38. mindspore/communication/_comm_helper.py +5 -0
  39. mindspore/communication/comm_func.py +215 -173
  40. mindspore/communication/management.py +23 -20
  41. mindspore/context.py +285 -191
  42. mindspore/dataset/__init__.py +23 -19
  43. mindspore/dataset/callback/ds_callback.py +2 -1
  44. mindspore/dataset/core/config.py +84 -3
  45. mindspore/dataset/engine/cache_admin.py +3 -3
  46. mindspore/dataset/engine/cache_client.py +5 -4
  47. mindspore/dataset/engine/datasets.py +192 -149
  48. mindspore/dataset/engine/datasets_audio.py +14 -0
  49. mindspore/dataset/engine/datasets_standard_format.py +11 -11
  50. mindspore/dataset/engine/datasets_text.py +38 -1
  51. mindspore/dataset/engine/datasets_user_defined.py +100 -66
  52. mindspore/dataset/engine/datasets_vision.py +81 -8
  53. mindspore/dataset/engine/iterators.py +281 -63
  54. mindspore/dataset/engine/obs/util.py +8 -0
  55. mindspore/dataset/engine/queue.py +40 -0
  56. mindspore/dataset/engine/samplers.py +26 -2
  57. mindspore/dataset/engine/serializer_deserializer.py +1 -1
  58. mindspore/dataset/engine/validators.py +43 -11
  59. mindspore/dataset/transforms/py_transforms_util.py +17 -0
  60. mindspore/dataset/transforms/transforms.py +29 -12
  61. mindspore/dataset/vision/validators.py +1 -2
  62. mindspore/device_context/__init__.py +21 -0
  63. mindspore/device_context/ascend/__init__.py +25 -0
  64. mindspore/device_context/ascend/device.py +72 -0
  65. mindspore/device_context/ascend/op_debug.py +94 -0
  66. mindspore/device_context/ascend/op_precision.py +193 -0
  67. mindspore/device_context/ascend/op_tuning.py +127 -0
  68. mindspore/device_context/cpu/__init__.py +25 -0
  69. mindspore/device_context/cpu/device.py +62 -0
  70. mindspore/device_context/cpu/op_tuning.py +43 -0
  71. mindspore/device_context/gpu/__init__.py +21 -0
  72. mindspore/device_context/gpu/device.py +70 -0
  73. mindspore/device_context/gpu/op_precision.py +67 -0
  74. mindspore/device_context/gpu/op_tuning.py +175 -0
  75. mindspore/device_manager.py +134 -0
  76. mindspore/dnnl.dll +0 -0
  77. mindspore/experimental/llm_boost/__init__.py +1 -0
  78. mindspore/experimental/llm_boost/ascend_native/__init__.py +22 -0
  79. mindspore/experimental/llm_boost/ascend_native/llama_boost_ascend_native.py +211 -0
  80. mindspore/experimental/llm_boost/ascend_native/llm_boost.py +52 -0
  81. mindspore/experimental/llm_boost/atb/boost_base.py +2 -3
  82. mindspore/experimental/llm_boost/atb/llama_boost.py +6 -1
  83. mindspore/experimental/llm_boost/register.py +1 -0
  84. mindspore/experimental/optim/adadelta.py +26 -22
  85. mindspore/experimental/optim/adam.py +3 -0
  86. mindspore/experimental/optim/lr_scheduler.py +33 -24
  87. mindspore/experimental/optim/radam.py +33 -30
  88. mindspore/hal/device.py +28 -0
  89. mindspore/hal/event.py +17 -0
  90. mindspore/hal/memory.py +94 -3
  91. mindspore/hal/stream.py +91 -6
  92. mindspore/include/api/context.h +0 -1
  93. mindspore/jpeg62.dll +0 -0
  94. mindspore/log.py +12 -0
  95. mindspore/mindrecord/__init__.py +1 -1
  96. mindspore/mindrecord/config.py +17 -316
  97. mindspore/mindrecord/filereader.py +1 -9
  98. mindspore/mindrecord/filewriter.py +5 -15
  99. mindspore/mindrecord/mindpage.py +1 -9
  100. mindspore/mindspore_backend.dll +0 -0
  101. mindspore/mindspore_common.dll +0 -0
  102. mindspore/mindspore_core.dll +0 -0
  103. mindspore/mindspore_glog.dll +0 -0
  104. mindspore/mindspore_ops.dll +0 -0
  105. mindspore/mint/__init__.py +824 -218
  106. mindspore/mint/distributed/__init__.py +66 -4
  107. mindspore/mint/distributed/distributed.py +2594 -44
  108. mindspore/mint/linalg/__init__.py +6 -0
  109. mindspore/mint/nn/__init__.py +473 -14
  110. mindspore/mint/nn/functional.py +486 -11
  111. mindspore/mint/nn/layer/__init__.py +17 -4
  112. mindspore/mint/nn/layer/_functions.py +330 -0
  113. mindspore/mint/nn/layer/activation.py +169 -1
  114. mindspore/mint/nn/layer/basic.py +123 -0
  115. mindspore/mint/nn/layer/conv.py +727 -0
  116. mindspore/mint/nn/layer/normalization.py +215 -19
  117. mindspore/mint/nn/layer/padding.py +797 -0
  118. mindspore/mint/nn/layer/pooling.py +170 -0
  119. mindspore/mint/optim/__init__.py +2 -1
  120. mindspore/mint/optim/adam.py +223 -0
  121. mindspore/mint/optim/adamw.py +26 -19
  122. mindspore/mint/special/__init__.py +2 -1
  123. mindspore/multiprocessing/__init__.py +5 -0
  124. mindspore/nn/cell.py +126 -19
  125. mindspore/nn/dynamic_lr.py +2 -1
  126. mindspore/nn/layer/activation.py +6 -6
  127. mindspore/nn/layer/basic.py +35 -25
  128. mindspore/nn/layer/channel_shuffle.py +3 -3
  129. mindspore/nn/layer/embedding.py +3 -3
  130. mindspore/nn/layer/normalization.py +8 -7
  131. mindspore/nn/layer/padding.py +4 -3
  132. mindspore/nn/layer/pooling.py +47 -13
  133. mindspore/nn/layer/rnn_cells.py +1 -1
  134. mindspore/nn/layer/rnns.py +2 -1
  135. mindspore/nn/layer/timedistributed.py +5 -5
  136. mindspore/nn/layer/transformer.py +48 -26
  137. mindspore/nn/learning_rate_schedule.py +5 -3
  138. mindspore/nn/loss/loss.py +31 -36
  139. mindspore/nn/optim/ada_grad.py +1 -0
  140. mindspore/nn/optim/adadelta.py +2 -2
  141. mindspore/nn/optim/adam.py +1 -1
  142. mindspore/nn/optim/lars.py +1 -4
  143. mindspore/nn/optim/optimizer.py +1 -1
  144. mindspore/nn/optim/rprop.py +2 -2
  145. mindspore/nn/optim/thor.py +2 -1
  146. mindspore/nn/utils/init.py +13 -11
  147. mindspore/nn/wrap/cell_wrapper.py +4 -6
  148. mindspore/nn/wrap/loss_scale.py +3 -4
  149. mindspore/numpy/array_creations.py +60 -62
  150. mindspore/numpy/array_ops.py +148 -143
  151. mindspore/numpy/logic_ops.py +41 -42
  152. mindspore/numpy/math_ops.py +361 -359
  153. mindspore/numpy/utils.py +16 -16
  154. mindspore/numpy/utils_const.py +4 -4
  155. mindspore/opencv_core452.dll +0 -0
  156. mindspore/opencv_imgcodecs452.dll +0 -0
  157. mindspore/opencv_imgproc452.dll +0 -0
  158. mindspore/ops/__init__.py +2 -1
  159. mindspore/ops/_grad_experimental/grad_comm_ops.py +94 -13
  160. mindspore/ops/_grad_experimental/grad_debug_ops.py +6 -1
  161. mindspore/ops/_grad_experimental/grad_inner_ops.py +9 -0
  162. mindspore/ops/_grad_experimental/grad_math_ops.py +2 -1
  163. mindspore/ops/_op_impl/cpu/__init__.py +1 -0
  164. mindspore/ops/_op_impl/cpu/raise_op.py +28 -0
  165. mindspore/ops/_vmap/vmap_array_ops.py +20 -19
  166. mindspore/ops/_vmap/vmap_base.py +0 -2
  167. mindspore/ops/_vmap/vmap_grad_nn_ops.py +19 -13
  168. mindspore/ops/_vmap/vmap_math_ops.py +11 -9
  169. mindspore/ops/_vmap/vmap_nn_ops.py +20 -34
  170. mindspore/ops/auto_generate/cpp_create_prim_instance_helper.py +149 -12
  171. mindspore/ops/auto_generate/gen_arg_handler.py +0 -61
  172. mindspore/ops/auto_generate/gen_extend_func.py +554 -60
  173. mindspore/ops/auto_generate/gen_ops_def.py +1621 -115
  174. mindspore/ops/auto_generate/gen_ops_prim.py +8024 -3409
  175. mindspore/ops/auto_generate/pyboost_inner_prim.py +183 -79
  176. mindspore/ops/composite/base.py +1 -1
  177. mindspore/ops/composite/multitype_ops/_compile_utils.py +229 -30
  178. mindspore/ops/composite/multitype_ops/pow_impl.py +0 -29
  179. mindspore/ops/function/__init__.py +12 -0
  180. mindspore/ops/function/array_func.py +561 -159
  181. mindspore/ops/function/clip_func.py +64 -0
  182. mindspore/ops/function/debug_func.py +28 -20
  183. mindspore/ops/function/image_func.py +1 -1
  184. mindspore/ops/function/linalg_func.py +5 -4
  185. mindspore/ops/function/math_func.py +1659 -290
  186. mindspore/ops/function/nn_func.py +988 -317
  187. mindspore/ops/function/parameter_func.py +3 -56
  188. mindspore/ops/function/random_func.py +243 -33
  189. mindspore/ops/function/sparse_unary_func.py +1 -1
  190. mindspore/ops/functional.py +18 -5
  191. mindspore/ops/functional_overload.py +897 -0
  192. mindspore/ops/operations/__init__.py +3 -2
  193. mindspore/ops/operations/_embedding_cache_ops.py +4 -4
  194. mindspore/ops/operations/_grad_ops.py +2 -34
  195. mindspore/ops/operations/_infer_ops.py +2 -1
  196. mindspore/ops/operations/_inner_ops.py +38 -8
  197. mindspore/ops/operations/array_ops.py +45 -303
  198. mindspore/ops/operations/comm_ops.py +19 -16
  199. mindspore/ops/operations/custom_ops.py +11 -55
  200. mindspore/ops/operations/debug_ops.py +42 -47
  201. mindspore/ops/operations/inner_ops.py +6 -4
  202. mindspore/ops/operations/linalg_ops.py +3 -2
  203. mindspore/ops/operations/manually_defined/ops_def.py +185 -104
  204. mindspore/ops/operations/math_ops.py +11 -216
  205. mindspore/ops/operations/nn_ops.py +146 -308
  206. mindspore/ops/primitive.py +23 -21
  207. mindspore/ops/tensor_method.py +1669 -0
  208. mindspore/ops_generate/aclnn_kernel_register_auto_cc_generator.py +110 -0
  209. mindspore/ops_generate/add_tensor_docs_generator.py +54 -0
  210. mindspore/ops_generate/arg_handler.py +0 -61
  211. mindspore/ops_generate/auto_grad_impl_cc_generator.py +135 -0
  212. mindspore/ops_generate/auto_grad_reg_cc_generator.py +93 -0
  213. mindspore/ops_generate/base_generator.py +11 -0
  214. mindspore/ops_generate/cpp_create_prim_instance_helper_generator.py +108 -0
  215. mindspore/ops_generate/functional_map_cpp_generator.py +491 -0
  216. mindspore/ops_generate/functional_overload_py_generator.py +110 -0
  217. mindspore/ops_generate/functions_cc_generator.py +233 -0
  218. mindspore/ops_generate/gen_aclnn_implement.py +110 -114
  219. mindspore/ops_generate/gen_constants.py +157 -3
  220. mindspore/ops_generate/gen_ops.py +245 -990
  221. mindspore/ops_generate/gen_pyboost_func.py +97 -998
  222. mindspore/ops_generate/gen_utils.py +119 -33
  223. mindspore/ops_generate/lite_ops_cpp_generator.py +155 -0
  224. mindspore/ops_generate/op_api_proto.py +206 -0
  225. mindspore/ops_generate/op_def_py_generator.py +131 -0
  226. mindspore/ops_generate/op_prim_py_generator.py +480 -0
  227. mindspore/ops_generate/op_proto.py +373 -108
  228. mindspore/ops_generate/op_template_parser.py +436 -0
  229. mindspore/ops_generate/ops_def_cc_generator.py +288 -0
  230. mindspore/ops_generate/ops_def_h_generator.py +74 -0
  231. mindspore/ops_generate/ops_name_h_generator.py +68 -0
  232. mindspore/ops_generate/ops_primitive_h_generator.py +81 -0
  233. mindspore/ops_generate/pyboost_functions_cpp_generator.py +370 -0
  234. mindspore/ops_generate/pyboost_functions_h_generator.py +68 -0
  235. mindspore/ops_generate/pyboost_functions_py_generator.py +148 -0
  236. mindspore/ops_generate/pyboost_grad_function_cpp_generator.py +154 -0
  237. mindspore/ops_generate/pyboost_inner_prim_generator.py +131 -0
  238. mindspore/ops_generate/pyboost_native_grad_functions_generator.py +268 -0
  239. mindspore/ops_generate/pyboost_op_cpp_code_generator.py +851 -0
  240. mindspore/ops_generate/pyboost_overload_functions_cpp_generator.py +344 -0
  241. mindspore/ops_generate/pyboost_utils.py +92 -33
  242. mindspore/ops_generate/template.py +294 -44
  243. mindspore/ops_generate/tensor_func_reg_cpp_generator.py +422 -0
  244. mindspore/parallel/__init__.py +3 -3
  245. mindspore/parallel/_auto_parallel_context.py +24 -33
  246. mindspore/parallel/_parallel_serialization.py +13 -2
  247. mindspore/parallel/_utils.py +4 -1
  248. mindspore/parallel/algo_parameter_config.py +1 -1
  249. mindspore/parallel/checkpoint_transform.py +44 -0
  250. mindspore/parallel/cluster/process_entity/_api.py +131 -37
  251. mindspore/parallel/cluster/process_entity/_utils.py +41 -6
  252. mindspore/parallel/cluster/run.py +20 -3
  253. mindspore/parallel/parameter_broadcast.py +1 -1
  254. mindspore/parallel/shard.py +3 -0
  255. mindspore/parallel/transform_safetensors.py +119 -253
  256. mindspore/profiler/__init__.py +17 -4
  257. mindspore/profiler/analysis/__init__.py +0 -0
  258. mindspore/profiler/analysis/parser/__init__.py +0 -0
  259. mindspore/profiler/analysis/parser/ascend_cann_parser.py +166 -0
  260. mindspore/profiler/analysis/parser/base_parser.py +158 -0
  261. mindspore/profiler/analysis/parser/framework_cann_relation_parser.py +45 -0
  262. mindspore/profiler/analysis/parser/ms_framework_parser.py +142 -0
  263. mindspore/profiler/analysis/parser/ms_minddata_parser.py +145 -0
  264. mindspore/profiler/analysis/parser/timeline_assembly_factory/__init__.py +0 -0
  265. mindspore/profiler/analysis/parser/timeline_assembly_factory/ascend_timeline_assembler.py +261 -0
  266. mindspore/profiler/analysis/parser/timeline_assembly_factory/base_timeline_assembler.py +40 -0
  267. mindspore/profiler/analysis/parser/timeline_assembly_factory/trace_view_container.py +84 -0
  268. mindspore/profiler/analysis/parser/timeline_creator/__init__.py +0 -0
  269. mindspore/profiler/analysis/parser/timeline_creator/base_timeline_creator.py +44 -0
  270. mindspore/profiler/analysis/parser/timeline_creator/cpu_op_timeline_creator.py +90 -0
  271. mindspore/profiler/analysis/parser/timeline_creator/fwk_timeline_creator.py +76 -0
  272. mindspore/profiler/analysis/parser/timeline_creator/msprof_timeline_creator.py +103 -0
  273. mindspore/profiler/analysis/parser/timeline_creator/scope_layer_timeline_creator.py +134 -0
  274. mindspore/profiler/analysis/parser/timeline_event/__init__.py +0 -0
  275. mindspore/profiler/analysis/parser/timeline_event/base_event.py +233 -0
  276. mindspore/profiler/analysis/parser/timeline_event/cpu_op_event.py +47 -0
  277. mindspore/profiler/analysis/parser/timeline_event/flow_event.py +36 -0
  278. mindspore/profiler/analysis/parser/timeline_event/fwk_event.py +260 -0
  279. mindspore/profiler/analysis/parser/timeline_event/msprof_event.py +73 -0
  280. mindspore/profiler/analysis/parser/timeline_event/scope_layer_event.py +53 -0
  281. mindspore/profiler/analysis/parser/timeline_event/timeline_event_pool.py +146 -0
  282. mindspore/profiler/analysis/task_manager.py +131 -0
  283. mindspore/profiler/analysis/time_converter.py +84 -0
  284. mindspore/profiler/analysis/viewer/__init__.py +0 -0
  285. mindspore/profiler/analysis/viewer/ascend_communication_viewer.py +333 -0
  286. mindspore/profiler/analysis/viewer/ascend_integrate_viewer.py +87 -0
  287. mindspore/profiler/analysis/viewer/ascend_kernel_details_viewer.py +252 -0
  288. mindspore/profiler/analysis/viewer/ascend_memory_viewer.py +313 -0
  289. mindspore/profiler/analysis/viewer/ascend_op_memory_viewer.py +322 -0
  290. mindspore/profiler/analysis/viewer/ascend_step_trace_time_viewer.py +265 -0
  291. mindspore/profiler/analysis/viewer/ascend_timeline_viewer.py +58 -0
  292. mindspore/profiler/analysis/viewer/base_viewer.py +26 -0
  293. mindspore/profiler/analysis/viewer/ms_dataset_viewer.py +97 -0
  294. mindspore/profiler/analysis/viewer/ms_minddata_viewer.py +581 -0
  295. mindspore/profiler/analysis/work_flow.py +73 -0
  296. mindspore/profiler/common/ascend_msprof_exporter.py +138 -0
  297. mindspore/profiler/common/command_executor.py +90 -0
  298. mindspore/profiler/common/constant.py +174 -3
  299. mindspore/profiler/common/file_manager.py +208 -0
  300. mindspore/profiler/common/log.py +130 -0
  301. mindspore/profiler/common/msprof_cmd_tool.py +202 -0
  302. mindspore/profiler/common/path_manager.py +371 -0
  303. mindspore/profiler/common/process_bar.py +168 -0
  304. mindspore/profiler/common/process_pool.py +9 -3
  305. mindspore/profiler/common/profiler_context.py +476 -0
  306. mindspore/profiler/common/profiler_info.py +304 -0
  307. mindspore/profiler/common/profiler_output_path.py +284 -0
  308. mindspore/profiler/common/profiler_parameters.py +210 -0
  309. mindspore/profiler/common/profiler_path_manager.py +120 -0
  310. mindspore/profiler/common/record_function.py +76 -0
  311. mindspore/profiler/common/tlv_decoder.py +76 -0
  312. mindspore/profiler/common/util.py +75 -2
  313. mindspore/profiler/dynamic_profiler.py +270 -37
  314. mindspore/profiler/envprofiler.py +138 -0
  315. mindspore/profiler/mstx.py +199 -0
  316. mindspore/profiler/platform/__init__.py +21 -0
  317. mindspore/profiler/platform/base_profiler.py +40 -0
  318. mindspore/profiler/platform/cpu_profiler.py +124 -0
  319. mindspore/profiler/platform/gpu_profiler.py +74 -0
  320. mindspore/profiler/platform/npu_profiler.py +309 -0
  321. mindspore/profiler/profiler.py +580 -93
  322. mindspore/profiler/profiler_action_controller.py +187 -0
  323. mindspore/profiler/profiler_interface.py +114 -0
  324. mindspore/profiler/schedule.py +208 -0
  325. mindspore/rewrite/api/symbol_tree.py +1 -2
  326. mindspore/run_check/_check_version.py +2 -6
  327. mindspore/runtime/__init__.py +37 -0
  328. mindspore/runtime/device.py +27 -0
  329. mindspore/runtime/event.py +209 -0
  330. mindspore/runtime/executor.py +148 -0
  331. mindspore/runtime/memory.py +392 -0
  332. mindspore/runtime/stream.py +460 -0
  333. mindspore/runtime/thread_bind_core.py +401 -0
  334. mindspore/swresample-4.dll +0 -0
  335. mindspore/swscale-6.dll +0 -0
  336. mindspore/tinyxml2.dll +0 -0
  337. mindspore/train/__init__.py +2 -2
  338. mindspore/train/_utils.py +53 -18
  339. mindspore/train/amp.py +8 -4
  340. mindspore/train/callback/_checkpoint.py +32 -18
  341. mindspore/train/callback/_early_stop.py +1 -1
  342. mindspore/train/callback/_flops_collector.py +105 -69
  343. mindspore/train/callback/_history.py +1 -1
  344. mindspore/train/callback/_summary_collector.py +44 -6
  345. mindspore/train/callback/_tft_register.py +31 -10
  346. mindspore/train/dataset_helper.py +11 -11
  347. mindspore/train/metrics/precision.py +4 -5
  348. mindspore/train/mind_ir_pb2.py +167 -46
  349. mindspore/train/model.py +13 -15
  350. mindspore/train/serialization.py +462 -76
  351. mindspore/train/summary/summary_record.py +1 -2
  352. mindspore/train/train_thor/model_thor.py +1 -1
  353. mindspore/turbojpeg.dll +0 -0
  354. mindspore/utils/__init__.py +4 -2
  355. mindspore/utils/dryrun.py +138 -0
  356. mindspore/utils/runtime_execution_order_check.py +550 -0
  357. mindspore/version.py +1 -1
  358. {mindspore-2.4.10.dist-info → mindspore-2.5.0.dist-info}/METADATA +2 -3
  359. {mindspore-2.4.10.dist-info → mindspore-2.5.0.dist-info}/RECORD +362 -238
  360. {mindspore-2.4.10.dist-info → mindspore-2.5.0.dist-info}/entry_points.txt +1 -1
  361. mindspore/common/_tensor_overload.py +0 -139
  362. mindspore/mindspore_np_dtype.dll +0 -0
  363. mindspore/profiler/envprofiling.py +0 -254
  364. mindspore/profiler/profiling.py +0 -1926
  365. {mindspore-2.4.10.dist-info → mindspore-2.5.0.dist-info}/WHEEL +0 -0
  366. {mindspore-2.4.10.dist-info → mindspore-2.5.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,422 @@
1
+ # Copyright 2024 Huawei Technologies Co., Ltd
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # ============================================================================
15
+ """
16
+ This module defines the PyboostInnerPrimGenerator class, which is responsible for generating Python primitive
17
+ wrappers for Pyboost operations. The generator constructs Python function definitions based on operator prototypes,
18
+ generates necessary import statements, and writes the generated content into Python source files.
19
+
20
+ The primary functionality is to take operator prototypes, extract relevant fields, and create Python function wrappers
21
+ that can be used to call the Pyboost primitive implementations.
22
+ """
23
+
24
+ import os
25
+
26
+ import template
27
+ from template import Template
28
+ import gen_constants as K
29
+ import pyboost_utils
30
+ import op_api_proto
31
+ from gen_utils import save_file
32
+ from base_generator import BaseGenerator
33
+ from op_proto import OpProto
34
+ from op_template_parser import OpTemplateParser
35
+
36
+
37
+ class TensorFuncRegCppGenerator(BaseGenerator):
38
+ """
39
+ Generates C++ tensor function registration code for different backends (Ascend, CPU, GPU).
40
+
41
+ This class is responsible for generating header and implementation files required to register
42
+ tensor functions, including device-specific dispatchers and function definitions.
43
+ """
44
+
45
+ def __init__(self):
46
+ self.TENSOR_FUNC_CC_REG = template.TENSOR_FUNC_CC_REG
47
+ self.TENSOR_FUNC_CALL_BODY = template.TENSOR_FUNC_CALL_BODY
48
+ self.TENSOR_FUNC_OVERLOAD_CALL_BODY = template.TENSOR_FUNC_OVERLOAD_CALL_BODY
49
+ self.TENSOR_API_HEADER = template.TENSOR_API_HEADER
50
+ self.TENSOR_API_SOURCE = template.TENSOR_API_SOURCE
51
+ self.TENSOR_FUNC_UTILS = template.TENSOR_FUNC_UTILS
52
+ self.TENSOR_FUNC_UT_BODY = template.TENSOR_FUNC_UT_BODY
53
+ self.TENSOR_FUNC_UT_OVERLOAD_BODY = template.TENSOR_FUNC_UT_OVERLOAD_BODY
54
+ self.TENSOR_CPP_METHOD = template.TENSOR_CPP_METHOD
55
+
56
+ self.func_def_reg = Template("tensor_class->def(\"${func_name}\", TensorMethod${cpp_func_name});\n")
57
+ self.single_case_template = Template(
58
+ 'case ${case_id}:\n'
59
+ ' ${device_dispatcher}\n'
60
+ ' break;\n'
61
+ )
62
+ self.single_case_in_ut_template = Template(
63
+ 'case ${case_id}:\n'
64
+ ' ${device_dispatcher}\n'
65
+ )
66
+ self.device_dispatcher_template = Template(
67
+ 'if (backend == kAscendDevice || backend == kDavinciDevice) {\n'
68
+ ' ${ascend_dispatcher}\n'
69
+ '} else if (backend == kCPUDevice) {\n'
70
+ ' ${cpu_dispatcher}\n'
71
+ '} else if (backend == kGPUDevice) {\n'
72
+ ' ${gpu_dispatcher}\n'
73
+ '} else {\n'
74
+ ' MS_LOG(ERROR) << "Device target is not supported!";\n'
75
+ ' return py::none();\n'
76
+ '}'
77
+ )
78
+ self.pyboost_return_template = Template(
79
+ '${arg_handler_processor}\n'
80
+ 'MS_LOG(INFO) << "Call Tensor${class_name}";\n'
81
+ 'return ToPython(TensorPyboostMethodRegister::'
82
+ 'GetOp(tensor::TensorPyboostMethod::k${class_name}Reg)(arg_list));\n'
83
+ )
84
+ self.callback_python_template = Template(
85
+ 'MS_LOG(INFO) << "Callback python method: ${py_method}";\n'
86
+ 'py::function fn = python_adapter::GetPyFn(\"mindspore.ops.tensor_method\", \"${py_method}\");\n'
87
+ 'py::object res = fn(self, *py_args, **py_kwargs);\n'
88
+ 'return res;\n'
89
+ )
90
+ self.callback_python_in_ut_template = Template(
91
+ 'MS_LOG(INFO) << "Callback python method in UT: ${py_method}";\n'
92
+ 'fn = python_adapter::GetPyFn(\"mindspore.ops.tensor_method\", \"${py_method}\");\n'
93
+ 'res = fn(self, *py_args, **py_kwargs);\n'
94
+ 'break;\n'
95
+ )
96
+ self.header_func_header_template = Template(
97
+ "py::object TensorMethod${cpp_func_name}"
98
+ "(const py::object &self, const py::args &py_args, const py::kwargs &py_kwargs);\n"
99
+ )
100
+
101
+ def generate(self, work_path, op_protos, func_protos_data, alias_func_mapping):
102
+ """
103
+ Generates C++ header and source files for tensor function registrations.
104
+
105
+ Args:
106
+ work_path (str): The directory where the generated files will be saved.
107
+ op_protos (list): A list of tensor op prototypes.
108
+ func_protos_data (dict): Dictionary mapping function names to lists of TensorFuncProto objects.
109
+ alias_func_mapping (dict): A dictionary mapping function name to its alias function names.
110
+ """
111
+
112
+ all_op_func_data, single_op_func_data, overload_op_func_data = op_api_proto.categorize_func_data(
113
+ func_protos_data)
114
+
115
+ tensor_method_list = self._get_op_enum_name_list(op_protos)
116
+ func_call_body_list = []
117
+ self._create_single_op_source_files(single_op_func_data, func_call_body_list)
118
+ self._create_overload_op_source_files(overload_op_func_data, func_call_body_list)
119
+ merge_func_call_body = pyboost_utils.merge_strings_by_chunk_size(func_call_body_list)
120
+
121
+ for i, func_body_chunk_str in enumerate(merge_func_call_body):
122
+ tensor_api_source = self.TENSOR_API_SOURCE.replace(tenosr_func_call_body=func_body_chunk_str)
123
+ save_file(os.path.join(work_path, K.TENSOR_API_PATH), f"tensor_api_{i}.cc",
124
+ tensor_api_source)
125
+
126
+ func_def_body_list, tensor_cpp_methods_list, tensor_api_declaration_list = self._get_sorted_func_def_body(
127
+ all_op_func_data, alias_func_mapping)
128
+ tensor_api_header = self.TENSOR_API_HEADER.replace(tensor_api_declaration_list=tensor_api_declaration_list)
129
+ save_file(os.path.join(work_path, K.TENSOR_API_PATH), f"tensor_api.h",
130
+ tensor_api_header)
131
+ self._generate_func_name_for_stub_tensor(work_path, tensor_cpp_methods_list)
132
+ func_cc_reg = self.TENSOR_FUNC_CC_REG.replace(func_def_body=func_def_body_list)
133
+ tensor_methods = self.TENSOR_FUNC_UTILS.replace(tensor_methods=tensor_method_list)
134
+
135
+ save_file(os.path.join(work_path, K.TENSOR_FUNC_REGISTER_PATH), "tensor_func_utils.h", tensor_methods)
136
+ save_file(os.path.join(work_path, K.TENSOR_FUNC_REGISTER_PATH), "tensor_func_reg.cc", func_cc_reg)
137
+
138
+ def _get_op_enum_name_list(self, op_protos):
139
+ """
140
+ Extracts operation class names and returns them as a formatted list.
141
+
142
+ Args:
143
+ op_protos (list): A list of operation prototype objects, where each object has an `op_class`
144
+ with a `name` attribute.
145
+
146
+ Returns:
147
+ str: A list of formatted strings, where each string is of the form 'k<name>,\n', where <name>
148
+ is the class name from the `op_class` attribute.
149
+
150
+ """
151
+ tensor_method_list = ""
152
+ for op_proto in op_protos:
153
+ if op_proto.op_dispatch is None or not op_proto.op_dispatch.enable:
154
+ continue
155
+ class_name = op_proto.op_class.name
156
+ tensor_method_list += f"k{class_name}Reg,\n"
157
+ return tensor_method_list
158
+
159
+ def _generate_func_name_for_stub_tensor(self, work_path, tensor_cpp_methods_list):
160
+ """
161
+ Generates a Python file containing tensor C++ function methods list and saves it to the specified path.
162
+
163
+ This function takes a list of C++ tensor methods, formats them into a Python script as a string,
164
+ and writes this script to a file named `_tensor_cpp_method.py` under the provided working path.
165
+
166
+ Args:
167
+ work_path (str): The base directory where the generated file will be saved.
168
+ tensor_cpp_methods_list (list): A list of tensor C++ method definitions to be included in the Python file.
169
+ """
170
+ tensor_cpp_methods_str = self.TENSOR_CPP_METHOD.replace(
171
+ tensor_cpp_methods_list_str=str(tensor_cpp_methods_list))
172
+ save_file(os.path.join(work_path, K.ADD_TENSOR_DOCS_PY_PATH), "_tensor_cpp_method.py", tensor_cpp_methods_str)
173
+
174
+ def _get_sorted_func_def_body(self, all_op_func_data, alias_func_mapping):
175
+ """
176
+ Generate sorted function definitions and headers for operations.
177
+
178
+ This function processes a dictionary of operation function data and an alias mapping,
179
+ producing two lists: one containing function definition bodies and another containing
180
+ function header definitions.
181
+
182
+ Args:
183
+ all_op_func_data (dict): A dictionary where keys are function API names (str), and
184
+ values are lists of function prototypes.
185
+ alias_func_mapping (dict): A mapping of function names to a list of their alias names.
186
+
187
+ Returns:
188
+ tuple: A tuple containing two lists:
189
+ - func_def_body_list (list of str): A list of formatted function definition strings.
190
+ - tensor_cpp_methods_list (list of str): A list of formatted function header strings.
191
+ """
192
+ func_def_body_list = []
193
+ tensor_cpp_methods_list = []
194
+ tensor_api_declaration_list = ""
195
+ for func_api_name, func_protos in all_op_func_data.items():
196
+ cpp_func_name = pyboost_utils.format_func_api_name(func_api_name)
197
+ if len(func_protos) == 1:
198
+ func_proto = func_protos[0]
199
+ func_name = func_proto.func_name
200
+ func_def_body_list.append(self.func_def_reg.replace(func_name=func_name, cpp_func_name=cpp_func_name))
201
+ tensor_cpp_methods_list.append(func_name)
202
+ tensor_api_declaration_list += self.header_func_header_template.replace(cpp_func_name=cpp_func_name)
203
+ if func_name in alias_func_mapping:
204
+ for alias_func_name in alias_func_mapping[func_name]:
205
+ func_def_body_list.append(
206
+ self.func_def_reg.replace(func_name=alias_func_name, cpp_func_name=cpp_func_name))
207
+ tensor_cpp_methods_list.append(alias_func_name)
208
+ elif len(func_protos) > 1:
209
+ func_def_body_list.append(
210
+ self.func_def_reg.replace(func_name=func_api_name, cpp_func_name=cpp_func_name))
211
+ tensor_cpp_methods_list.append(func_api_name)
212
+ tensor_api_declaration_list += self.header_func_header_template.replace(cpp_func_name=cpp_func_name)
213
+ if func_api_name in alias_func_mapping:
214
+ for alias_func_name in alias_func_mapping[func_api_name]:
215
+ func_def_body_list.append(self.func_def_reg.replace(func_name=alias_func_name,
216
+ cpp_func_name=cpp_func_name))
217
+ tensor_cpp_methods_list.append(alias_func_name)
218
+ return func_def_body_list, tensor_cpp_methods_list, tensor_api_declaration_list
219
+
220
+ def _create_single_op_source_files(self, single_op_func_data, func_call_body_list):
221
+ """
222
+ Generates the list of call body strings for single operation functions.
223
+
224
+ Args:
225
+ single_op_func_data (dict): Dictionary of tensor function prototypes with only one definition.
226
+
227
+ Returns:
228
+ list: Updated str list for generating C++ function call bodies.
229
+ """
230
+ for func_api_name, func_proto in single_op_func_data.items():
231
+ func_name = func_proto.func_name
232
+ cpp_func_name = pyboost_utils.format_func_api_name(func_api_name)
233
+ device_dispatcher_str = self._get_device_dispatchers_str(func_proto)
234
+ signature_str = self._generate_single_signature_str(
235
+ func_proto.op_proto, func_proto.kw_only_args, func_proto.varargs
236
+ )
237
+ op_args = func_proto.op_proto.op_args
238
+ max_size = len(op_args)
239
+ self_index = self._get_input_tensor_index(func_proto)
240
+ ut_body = self.TENSOR_FUNC_UT_BODY.replace(py_method=func_proto.py_method)
241
+ tensor_func_single_call_body = self.TENSOR_FUNC_CALL_BODY.replace(cpp_func_name=cpp_func_name,
242
+ func_name=func_name,
243
+ device_dispatcher=device_dispatcher_str,
244
+ signatures=signature_str,
245
+ max_args=max_size,
246
+ self_index=self_index,
247
+ ut_body=ut_body)
248
+ func_call_body_list.append(tensor_func_single_call_body)
249
+
250
+ def _create_overload_op_source_files(self, overload_op_func_data, func_call_body_list):
251
+ """
252
+ Generates the list of call body strings for overloaded operation functions.
253
+
254
+ Args:
255
+ overload_op_func_data (dict): Dictionary of tensor function prototypes with overloaded definitions.
256
+
257
+ Returns:
258
+ list: Updated str list for generating C++ function call bodies.
259
+ """
260
+ for func_api_name, func_protos in overload_op_func_data.items():
261
+ tensor_func_overload_call_body = self._get_overload_func_call_str(func_api_name, func_protos)
262
+ func_call_body_list.append(tensor_func_overload_call_body)
263
+
264
+ def _get_overload_func_call_str(self, func_api_name, func_protos):
265
+ """
266
+ Generates C++ call body string for overloaded tensor functions.
267
+
268
+ Args:
269
+ func_api_name (str): Name of the function API.
270
+ func_protos (list): List of TensorFuncProto objects representing the function prototypes.
271
+
272
+ Returns:
273
+ str: Generated call body string for the overloaded functions.
274
+ """
275
+ signatures_str = self._generate_func_signatures_list_str(func_protos)
276
+ dispatch_cases = self._get_dispatch_cases(func_protos)
277
+ ut_dispatch_cases = self._get_ut_dispatch_cases(func_protos)
278
+ ut_overload_body = self.TENSOR_FUNC_UT_OVERLOAD_BODY.replace(ut_dispatch_cases=ut_dispatch_cases)
279
+
280
+ max_size = 0
281
+ self_index = 0
282
+ for tensor_proto in func_protos:
283
+ op_proto = tensor_proto.op_proto
284
+ op_args = op_proto.op_args
285
+ max_size = max(len(op_args), max_size)
286
+ self_index = self._get_input_tensor_index(tensor_proto)
287
+ cpp_func_name = pyboost_utils.format_func_api_name(func_api_name)
288
+ overload_func_call_str = self.TENSOR_FUNC_OVERLOAD_CALL_BODY.replace(cpp_func_name=cpp_func_name,
289
+ func_name=func_api_name,
290
+ signatures=signatures_str,
291
+ dispatch_cases=dispatch_cases,
292
+ max_args=max_size,
293
+ self_index=self_index,
294
+ ut_overload_body=ut_overload_body)
295
+ return overload_func_call_str
296
+
297
+ def _generate_func_signatures_list_str(self, func_protos) -> str:
298
+ """
299
+ Generates function signatures as a string from the given prototypes.
300
+
301
+ Args:
302
+ func_protos (list): List of TensorFuncProto objects representing the function prototypes.
303
+
304
+ Returns:
305
+ str: Generated function signatures string.
306
+ """
307
+ sig_str = ''
308
+ first_sig = True
309
+ for tensor_proto in func_protos:
310
+ op_proto = tensor_proto.op_proto
311
+ if not first_sig:
312
+ sig_str += ',\n'
313
+ first_sig = False
314
+ sig_str += self._generate_single_signature_str(op_proto, tensor_proto.kw_only_args, tensor_proto.varargs)
315
+ return sig_str
316
+
317
+ def _generate_single_signature_str(self, op_proto: OpProto, kw_only_args, varargs) -> str:
318
+ op_parser = OpTemplateParser(op_proto)
319
+ return op_parser.generate_signature_str(kw_only_args, varargs, is_tensor_api=True)
320
+
321
+ def _get_input_tensor_index(self, func_proto):
322
+ """
323
+ Get index of input.
324
+
325
+ Args:
326
+ func_proto (TensorFuncProto): Function prototype to generate dispatch strings for.
327
+
328
+ Returns:
329
+ int: Index of input.
330
+ """
331
+ op_name = func_proto.op_proto.op_class.name
332
+ op_args = func_proto.op_proto.op_args
333
+ if op_name in K.INPUT_NAME_MAP:
334
+ self_index = [i for i in range(len(op_args)) if op_args[i].arg_name == K.INPUT_NAME_MAP[op_name]]
335
+ else:
336
+ self_index = [i for i in range(len(op_args)) if op_args[i].arg_name in K.INPUT_ARGS_NAME]
337
+ if len(self_index) != 1:
338
+ raise ValueError(
339
+ f'There must be only one field named \'input\'. But got {len(self_index)} in {op_name}')
340
+ return self_index
341
+
342
+ def _get_dispatch_cases(self, func_protos):
343
+ """
344
+ Generates C++ switch-case statements for dispatching tensor function calls.
345
+
346
+ Args:
347
+ func_protos (list): List of TensorFuncProto objects representing the function prototypes.
348
+
349
+ Returns:
350
+ str: Generated switch-case dispatch statements.
351
+ """
352
+ dispatch_cases_str = ''
353
+ for idx, func_proto in enumerate(func_protos):
354
+ device_dispatcher_str = self._get_device_dispatchers_str(func_proto)
355
+ dispatch_cases_str += self.single_case_template.replace(case_id=idx,
356
+ device_dispatcher=device_dispatcher_str)
357
+ dispatch_cases_str += 'default:\n'
358
+ dispatch_cases_str += ' return py::none();'
359
+ return dispatch_cases_str
360
+
361
+ def _get_ut_dispatch_cases(self, func_protos):
362
+ """
363
+ Generates C++ switch-case statements for dispatching tensor function calls.
364
+
365
+ Args:
366
+ func_protos (list): List of TensorFuncProto objects representing the function prototypes.
367
+
368
+ Returns:
369
+ str: Generated switch-case dispatch statements.
370
+ """
371
+ dispatch_cases_str = ''
372
+ for idx, func_proto in enumerate(func_protos):
373
+ device_dispatcher_str = self.callback_python_in_ut_template.replace(py_method=func_proto.py_method)
374
+ dispatch_cases_str += self.single_case_in_ut_template.replace(case_id=idx,
375
+ device_dispatcher=device_dispatcher_str)
376
+ dispatch_cases_str += 'default:\n'
377
+ dispatch_cases_str += ' res = py::none();'
378
+ return dispatch_cases_str
379
+
380
+ def _get_device_dispatchers_str(self, func_proto):
381
+ """
382
+ Generates device-specific dispatch strings for the given function prototype.
383
+
384
+ Args:
385
+ func_proto (TensorFuncProto): Function prototype to generate dispatch strings for.
386
+
387
+ Returns:
388
+ str: Generated device-specific dispatch string.
389
+ """
390
+ ascend_dispatcher_str = self._get_single_device_dispatcher_str(func_proto, 'ascend')
391
+ cpu_dispatcher_str = self._get_single_device_dispatcher_str(func_proto, 'cpu')
392
+ gpu_dispatcher_str = self._get_single_device_dispatcher_str(func_proto, 'gpu')
393
+ device_dispatcher_str = self.device_dispatcher_template.replace(ascend_dispatcher=ascend_dispatcher_str,
394
+ cpu_dispatcher=cpu_dispatcher_str,
395
+ gpu_dispatcher=gpu_dispatcher_str)
396
+ return device_dispatcher_str
397
+
398
+ def _get_single_device_dispatcher_str(self, func_proto, device):
399
+ """
400
+ Generates the dispatch string for a specific device.
401
+
402
+ Args:
403
+ func_proto (TensorFuncProto): Function prototype to generate the dispatcher for.
404
+ device (str): Device type ('ascend', 'cpu', 'gpu').
405
+
406
+ Returns:
407
+ str: Generated device dispatcher string.
408
+ """
409
+ func_proto_device = getattr(func_proto, device)
410
+ if func_proto_device == 'pyboost':
411
+ arg_handler_processor_str = self._get_arg_handler_processor(func_proto.func_name, func_proto.op_proto)
412
+ return self.pyboost_return_template.replace(arg_handler_processor=arg_handler_processor_str,
413
+ class_name=func_proto.op_proto.op_class.name)
414
+
415
+ if func_proto_device == 'py_method':
416
+ return self.callback_python_template.replace(py_method=func_proto.py_method)
417
+
418
+ raise TypeError("Only support pyboost or python_method.")
419
+
420
+ def _get_arg_handler_processor(self, func_name, op_proto):
421
+ op_parser = OpTemplateParser(op_proto)
422
+ return op_parser.get_arg_handler_processor(func_name, op_proto, is_tensor_api=True)
@@ -19,12 +19,12 @@ from mindspore.parallel.algo_parameter_config import get_algo_parameters, reset_
19
19
  set_algo_parameters
20
20
  from mindspore.parallel.checkpoint_transform import rank_list_for_transform, transform_checkpoint_by_rank, \
21
21
  transform_checkpoints, merge_pipeline_strategys, sync_pipeline_shared_parameters, \
22
- load_segmented_checkpoints
22
+ load_segmented_checkpoints, set_op_strategy_config
23
23
  from mindspore.parallel.parameter_broadcast import parameter_broadcast
24
24
  from mindspore.parallel.shard import shard, Layout
25
- from mindspore.parallel.transform_safetensors import safetensors_to_ckpt, ckpt_to_safetensors, unified_safetensors
25
+ from mindspore.parallel.transform_safetensors import unified_safetensors
26
26
 
27
27
  __all__ = ["set_algo_parameters", "reset_algo_parameters", "get_algo_parameters", "rank_list_for_transform",
28
28
  "transform_checkpoint_by_rank", "transform_checkpoints", "merge_pipeline_strategys", "shard",
29
29
  "sync_pipeline_shared_parameters", "Layout", "parameter_broadcast", "load_segmented_checkpoints",
30
- "safetensors_to_ckpt", "ckpt_to_safetensors", "unified_safetensors"]
30
+ "unified_safetensors", "set_op_strategy_config"]
@@ -187,6 +187,25 @@ class _AutoParallelContext:
187
187
  self.check_context_handle()
188
188
  return self._context_handle.get_dump_local_norm()
189
189
 
190
+ def set_dump_local_norm_path(self, dump_local_norm_path):
191
+ """
192
+ Set dump local norm path for auto parallel.
193
+
194
+ Args:
195
+ dump_local_norm_path (str): User need to specify the path to save dump files
196
+ if he want to dump local norm. Default: ''
197
+
198
+ Raises:
199
+ KeyError: When the value of dump_local_norm_path is not a str value.
200
+ """
201
+ self.check_context_handle()
202
+ self._context_handle.set_dump_local_norm_path(dump_local_norm_path)
203
+
204
+ def get_dump_local_norm_path(self):
205
+ """Get dump local norm path."""
206
+ self.check_context_handle()
207
+ return self._context_handle.get_dump_local_norm_path()
208
+
190
209
  def set_dump_device_local_norm(self, dump_device_local_norm):
191
210
  """
192
211
  Set dump device local norm for auto parallel.
@@ -195,7 +214,7 @@ class _AutoParallelContext:
195
214
  dump_device_local_norm (bool): User need to specify if he want to dump device local norm. Default: False
196
215
 
197
216
  Raises:
198
- ValueError: If the dump_device_local_norm in not a bool value.
217
+ ValueError: If the dump_device_local_norm is not a bool value.
199
218
  """
200
219
  self.check_context_handle()
201
220
  self._context_handle.set_dump_device_local_norm(dump_device_local_norm)
@@ -1089,13 +1108,6 @@ class _AutoParallelContext:
1089
1108
  self.check_context_handle()
1090
1109
  return self._context_handle.get_optimizer_weight_shard_size()
1091
1110
 
1092
- def set_ops_strategy_json_config(self, type, path, mode):
1093
- """
1094
- Set configuration of saving ops strategy in file .json.
1095
- """
1096
- self.check_context_handle()
1097
- self._context_handle.set_ops_strategy_json_config(type, path, mode)
1098
-
1099
1111
  def set_optimizer_weight_shard_aggregated_save(self, optimizer_weight_shard_aggregated_save):
1100
1112
  """
1101
1113
  Set optimizer_weight_shard_aggregated_save.
@@ -1233,31 +1245,6 @@ class _AutoParallelContext:
1233
1245
  self.set_enable_all_gather_fusion(openstate)
1234
1246
  self.set_enable_reduce_scatter_fusion(openstate)
1235
1247
 
1236
-
1237
- def _set_ops_strategy_json_config(type="SAVE", path="", mode="all"):
1238
- """
1239
- Set strategy json configuration.
1240
-
1241
- Args:
1242
- type (str): The parameter for choosing save or load .json file.
1243
- path (str): Path to save or load parallel strategy json.
1244
- mode (str): The parameter for choosing save all or important operators.
1245
-
1246
- Raises:
1247
- KeyError: When type is not 'SAVE' or 'LOAD'.
1248
- KeyError: When mode is not 'all' or 'principal'.
1249
- """
1250
- dir_path = os.path.dirname(path)
1251
- if dir_path and not os.path.exists(dir_path):
1252
- os.makedirs(dir_path, mode=0o700, exist_ok=True)
1253
- check_type = ["SAVE", "LOAD"]
1254
- check_mode = ["all", "principal"]
1255
- if type in check_type and mode in check_mode:
1256
- auto_parallel_context().set_ops_strategy_json_config(type, path, mode)
1257
- else:
1258
- raise KeyError("Type must be 'SAVE' or 'LOAD' and mode must be 'all' or 'principal'")
1259
-
1260
-
1261
1248
  _AUTO_PARALLEL_CONTEXT = None
1262
1249
 
1263
1250
 
@@ -1307,6 +1294,7 @@ _set_auto_parallel_context_func_map = {
1307
1294
  "strategy_ckpt_config": auto_parallel_context().set_strategy_ckpt_config,
1308
1295
  "comm_fusion": auto_parallel_context().set_comm_fusion,
1309
1296
  "dump_local_norm": auto_parallel_context().set_dump_local_norm,
1297
+ "dump_local_norm_path": auto_parallel_context().set_dump_local_norm_path,
1310
1298
  "dump_device_local_norm": auto_parallel_context().set_dump_device_local_norm}
1311
1299
 
1312
1300
  _get_auto_parallel_context_func_map = {
@@ -1341,6 +1329,7 @@ _get_auto_parallel_context_func_map = {
1341
1329
  "strategy_ckpt_config": auto_parallel_context().get_strategy_ckpt_config,
1342
1330
  "full_batch_is_set": auto_parallel_context().get_full_batch_is_set,
1343
1331
  "dump_local_norm": auto_parallel_context().get_dump_local_norm,
1332
+ "dump_local_norm_path": auto_parallel_context().get_dump_local_norm_path,
1344
1333
  "dump_device_local_norm": auto_parallel_context().get_dump_device_local_norm}
1345
1334
 
1346
1335
 
@@ -1452,6 +1441,8 @@ def _set_auto_parallel_context(**kwargs):
1452
1441
  - reducescatter: If communication fusion type is `reducescatter`. The `mode` contains: `auto`
1453
1442
  and `size`. Config is same as `allgather`.
1454
1443
 
1444
+
1445
+
1455
1446
  Raises:
1456
1447
  ValueError: If input key is not attribute in auto parallel context.
1457
1448
  """
@@ -115,11 +115,15 @@ def _check_strategy_file(strategy_filename):
115
115
  f"be empty. Please check whether the 'strategy_filename' is correct.")
116
116
 
117
117
 
118
- def _load_protobuf_strategy(strategy_filename):
118
+ def _load_protobuf_strategy(strategy_filename, strategy_set=None):
119
119
  """load strategy from protobuf file"""
120
120
  parallel_strategy_map = ms.train.node_strategy_pb2.ParallelStrategyMap()
121
121
  with open(strategy_filename, 'rb') as f:
122
122
  pb_content = f.read()
123
+ if strategy_set is not None:
124
+ if pb_content in strategy_set:
125
+ return {}
126
+ strategy_set.add(pb_content)
123
127
  try:
124
128
  parallel_strategy_map.ParseFromString(pb_content)
125
129
  except BaseException as e:
@@ -188,8 +192,11 @@ def _merge_protobuf_strategy(src_strategy_files, dst_strategy_file):
188
192
  """merge protobuf strategy"""
189
193
  dst_parallel_strategy_map = ms.train.node_strategy_pb2.ParallelStrategyMap()
190
194
  merged_stage = []
195
+ strategy_set = set()
191
196
  for src_strategy_file in src_strategy_files:
192
- src_parallel_strategy_map = _load_protobuf_strategy(src_strategy_file)
197
+ src_parallel_strategy_map = _load_protobuf_strategy(src_strategy_file, strategy_set=strategy_set)
198
+ if not src_parallel_strategy_map:
199
+ continue
193
200
  strategy_items = src_parallel_strategy_map.parallel_strategy_item
194
201
  layout_items = src_parallel_strategy_map.parallel_layout_item
195
202
  if not strategy_items or not layout_items:
@@ -339,6 +346,9 @@ def _get_device_num_from_strategy(strategy_file=None):
339
346
  src_strategy = strategy_file
340
347
  strategy_list = _convert_to_list(src_strategy)
341
348
  device_mat = list(strategy_list.values())[0][0]
349
+ if not device_mat:
350
+ raise ValueError("The parallel strategy file only contains pipeline-parallelism, which is not supported for "
351
+ "parallel strategy conversion now.")
342
352
  return np.prod(device_mat)
343
353
 
344
354
 
@@ -559,3 +569,4 @@ def _get_param_list_when_first_dim_sharded(device_arrangement, first_dim_sharded
559
569
  start = rank - offset
560
570
  param_total_list = list(range(start, start + range_size))
561
571
  return param_total_list
572
+
@@ -30,7 +30,7 @@ from mindspore.common.seed import get_seed
30
30
  from mindspore._c_expression import GraphExecutor_
31
31
  from mindspore.parallel._tensor import _load_tensor_by_layout, _load_tensor_shape_by_layout
32
32
 
33
- SUPPORTED_TUPLE_IN_TUPLE_STRATEGY = ["GroupedMatmul", "FusedInferAttentionScore", "Custom"]
33
+ SUPPORTED_TUPLE_IN_TUPLE_STRATEGY = ["GroupedMatmul", "FusedInferAttentionScore", "Custom", "Index"]
34
34
 
35
35
 
36
36
  def _get_parallel_mode():
@@ -135,6 +135,9 @@ def _slice_parameter(parameter, phase, layout):
135
135
  rank = get_rank()
136
136
  new_tensor_shape = _load_tensor_shape_by_layout(parameter, layout, rank)
137
137
  parameter.shape = new_tensor_shape
138
+ if hasattr(parameter.init_mode, "shape") and parameter.init_mode.shape != parameter.shape:
139
+ parameter.init_mode.shape = new_tensor_shape
140
+ parameter.sliced = True
138
141
  else:
139
142
  graph_executor = GraphExecutor_.get_instance()
140
143
  new_param = parameter.init_data(layout, set_sliced=True)
@@ -370,7 +370,7 @@ def get_algo_parameters(attr_key):
370
370
  Examples:
371
371
  >>> import mindspore as ms
372
372
  >>> ms.get_algo_parameters("fully_use_devices")
373
- True
373
+ False
374
374
  """
375
375
  if attr_key not in get_algo_parameters_config_func_map:
376
376
  raise ValueError("Get context keyword %s is not recognized!" % attr_key)
@@ -28,6 +28,7 @@ from mindspore.parallel._parallel_serialization import _rank_list_for_transform_
28
28
  _extract_layout_map, _extract_src_dst_layout_map, _parameter_not_in_local_stage, _extract_pipeline_stage_num, \
29
29
  _merge_protobuf_strategy, _merge_json_strategy, _extract_src_dst_layout_map_by_src
30
30
  from mindspore.parallel.transform_safetensors import _transform_safetensors, _collect_safetensor_files
31
+ from mindspore._c_expression import AutoParallelContext
31
32
 
32
33
  __all__ = ["merge_pipeline_strategys", "rank_list_for_transform", "transform_checkpoint_by_rank",
33
34
  "transform_checkpoints", "sync_pipeline_shared_parameters", "load_segmented_checkpoints"]
@@ -648,3 +649,46 @@ def load_segmented_checkpoints(ckpt_file_dir, net=None, strict_load=False, filte
648
649
  parameter_dict.update(ms.load_checkpoint(checkpoint_file, net, strict_load, filter_prefix, dec_key,
649
650
  dec_mode, specify_prefix, choice_func))
650
651
  return parameter_dict
652
+
653
+
654
+ def set_op_strategy_config(mode="SAVE", path=""):
655
+ """
656
+ Set strategy json configuration when using sharding propagation.
657
+
658
+ .. warning::
659
+ This is an experimental interface, may be changed or canceled in the future;
660
+ This interface currently doesn't support saving or loading strategies using layout.
661
+
662
+ Note:
663
+ - It only works when `parallel_mode=ParallelMode.AUTO_PARALLEL` and `search_mode='sharding_propagation'`.
664
+ - It only supports saving and reloading with the same configuration for the same network. If the network
665
+ or training hyperparameters are modified after using the `SAVE` mode to save the strategies of operator
666
+ to the setting json file, which may lead to the failure of using the `LOAD` mode to load operator
667
+ strategies from json.
668
+ - When performing distributed training, users can first save the strategy using dryrun on a single device
669
+ and then load strategy to perform distributed training.
670
+
671
+ Args:
672
+ mode (str): The parameter for choosing save or load .json file. Default value: ``"SAVE"`` .
673
+ path (str): Path to save or load parallel strategy json, must be an absolute path. Default value: ``""`` .
674
+
675
+ Raises:
676
+ KeyError: When type is not ``"SAVE"`` or ``"LOAD"`` .
677
+ KeyError: When path does not end in ``".json"`` .
678
+ KeyError: When path is not an absolute path.
679
+ """
680
+ if not os.path.isabs(path):
681
+ raise KeyError("File path must be an absolute path")
682
+ _, file_type = os.path.splitext(path)
683
+ if file_type != ".json":
684
+ raise KeyError("File type must be .json")
685
+ dir_path = os.path.dirname(path)
686
+ if dir_path and not os.path.exists(dir_path):
687
+ os.makedirs(dir_path, mode=0o700, exist_ok=True)
688
+ check_mode_type = ["SAVE", "LOAD"]
689
+ if mode in check_mode_type:
690
+ if AutoParallelContext.get_instance() is None:
691
+ raise ValueError("Get AutoParallelContext instance failed!!!")
692
+ AutoParallelContext.get_instance().set_ops_strategy_json_config(mode, path, "all")
693
+ else:
694
+ raise KeyError("Type must be 'SAVE' or 'LOAD'")