mindspore 2.3.0__cp39-none-any.whl → 2.3.0rc2__cp39-none-any.whl

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

Potentially problematic release.


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

Files changed (423) hide show
  1. mindspore/.commit_id +1 -1
  2. mindspore/Third_Party_Open_Source_Software_Notice +0 -1512
  3. mindspore/__init__.py +1 -2
  4. mindspore/_c_dataengine.cpython-39-aarch64-linux-gnu.so +0 -0
  5. mindspore/_c_expression.cpython-39-aarch64-linux-gnu.so +0 -0
  6. mindspore/_c_mindrecord.cpython-39-aarch64-linux-gnu.so +0 -0
  7. mindspore/_checkparam.py +25 -5
  8. mindspore/_extends/graph_kernel/model/graph_parallel.py +1 -1
  9. mindspore/_extends/parse/__init__.py +2 -2
  10. mindspore/_extends/parse/compile_config.py +0 -29
  11. mindspore/_extends/parse/namespace.py +2 -2
  12. mindspore/_extends/parse/parser.py +5 -21
  13. mindspore/_extends/parse/resources.py +7 -5
  14. mindspore/_extends/parse/standard_method.py +59 -40
  15. mindspore/_mindspore_offline_debug.cpython-39-aarch64-linux-gnu.so +0 -0
  16. mindspore/amp.py +5 -26
  17. mindspore/bin/cache_admin +0 -0
  18. mindspore/bin/cache_server +0 -0
  19. mindspore/boost/adasum.py +1 -1
  20. mindspore/boost/base.py +1 -1
  21. mindspore/boost/boost_cell_wrapper.py +1 -1
  22. mindspore/boost/grad_freeze.py +2 -2
  23. mindspore/boost/less_batch_normalization.py +6 -9
  24. mindspore/common/__init__.py +1 -8
  25. mindspore/common/_register_for_tensor.py +9 -8
  26. mindspore/common/api.py +65 -275
  27. mindspore/common/dtype.py +4 -8
  28. mindspore/common/dump.py +5 -2
  29. mindspore/common/jit_config.py +1 -1
  30. mindspore/common/lazy_inline.py +2 -14
  31. mindspore/common/parameter.py +15 -14
  32. mindspore/common/recompute.py +5 -20
  33. mindspore/common/sparse_tensor.py +6 -21
  34. mindspore/common/tensor.py +52 -100
  35. mindspore/communication/__init__.py +11 -6
  36. mindspore/communication/management.py +94 -92
  37. mindspore/context.py +18 -180
  38. mindspore/dataset/engine/datasets.py +46 -69
  39. mindspore/dataset/engine/datasets_user_defined.py +53 -72
  40. mindspore/dataset/engine/datasets_vision.py +2 -2
  41. mindspore/dataset/engine/queue.py +38 -56
  42. mindspore/dataset/engine/validators.py +5 -11
  43. mindspore/dataset/vision/__init__.py +5 -5
  44. mindspore/dataset/vision/c_transforms.py +5 -5
  45. mindspore/dataset/vision/py_transforms_util.py +1 -1
  46. mindspore/dataset/vision/transforms.py +46 -591
  47. mindspore/dataset/vision/utils.py +1 -121
  48. mindspore/dataset/vision/validators.py +3 -9
  49. mindspore/hal/__init__.py +1 -7
  50. mindspore/hal/device.py +1 -1
  51. mindspore/include/api/model.h +0 -3
  52. mindspore/include/dataset/vision.h +2 -54
  53. mindspore/include/mindapi/base/types.h +0 -1
  54. mindspore/lib/libdnnl.so.2 +0 -0
  55. mindspore/lib/libmindspore.so +0 -0
  56. mindspore/lib/libmindspore_backend.so +0 -0
  57. mindspore/lib/libmindspore_common.so +0 -0
  58. mindspore/lib/libmindspore_core.so +0 -0
  59. mindspore/lib/libmindspore_glog.so.0 +0 -0
  60. mindspore/lib/libmindspore_gpr.so.15 +0 -0
  61. mindspore/lib/libmindspore_grpc++.so.1 +0 -0
  62. mindspore/lib/libmindspore_grpc.so.15 +0 -0
  63. mindspore/lib/libmindspore_shared_lib.so +0 -0
  64. mindspore/lib/libmpi_adapter.so +0 -0
  65. mindspore/lib/libmpi_collective.so +0 -0
  66. mindspore/lib/libnnacl.so +0 -0
  67. mindspore/lib/libopencv_core.so.4.5 +0 -0
  68. mindspore/lib/libps_cache.so +0 -0
  69. mindspore/lib/plugin/ascend/custom_aicore_ops/op_impl/ai_core/tbe/config/ascend310p/aic-ascend310p-ops-info.json +0 -35
  70. mindspore/lib/plugin/ascend/custom_aicore_ops/op_impl/ai_core/tbe/custom_aicore_ops_impl/kv_cache_mgr.py +0 -2
  71. mindspore/lib/plugin/ascend/custom_aicore_ops/op_impl/vector_core/tbe/custom_aicore_ops_impl/kv_cache_mgr.py +0 -2
  72. mindspore/lib/plugin/ascend/custom_aicpu_ops/op_impl/cpu/aicpu_kernel/impl/libcust_cpu_kernels.so +0 -0
  73. mindspore/lib/plugin/ascend/custom_aicpu_ops/op_impl/cpu/config/cust_aicpu_kernel.json +0 -72
  74. mindspore/lib/plugin/ascend/custom_aicpu_ops/op_proto/libcust_op_proto.so +0 -0
  75. mindspore/lib/plugin/ascend/custom_ascendc_ops/op_api/include/{aclnn_all_finite.h → aclnn_add_custom.h} +11 -9
  76. mindspore/lib/plugin/ascend/custom_ascendc_ops/op_api/include/aclnn_decoder_kv_cache.h +1 -1
  77. mindspore/lib/plugin/ascend/custom_ascendc_ops/op_api/include/aclnn_prompt_kv_cache.h +1 -1
  78. mindspore/lib/plugin/ascend/custom_ascendc_ops/op_api/lib/libcust_opapi.so +0 -0
  79. mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/config/ascend310p/aic-ascend310p-ops-info.json +12 -184
  80. mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/config/ascend910/aic-ascend910-ops-info.json +15 -7
  81. mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/config/ascend910b/aic-ascend910b-ops-info.json +15 -7
  82. mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/custom_ascendc_ops_impl/dynamic/add_custom.cpp +81 -0
  83. mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/custom_ascendc_ops_impl/dynamic/add_custom.py +134 -0
  84. mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/custom_ascendc_ops_impl/dynamic/decoder_kv_cache.py +31 -77
  85. mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/custom_ascendc_ops_impl/dynamic/prompt_kv_cache.py +31 -77
  86. mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/op_tiling/lib/linux/aarch64/libcust_opmaster_rt2.0.so +0 -0
  87. mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/op_tiling/liboptiling.so +0 -0
  88. mindspore/lib/plugin/ascend/custom_ascendc_ops/op_proto/inc/op_proto.h +5 -4
  89. mindspore/lib/plugin/ascend/custom_ascendc_ops/op_proto/lib/linux/aarch64/libcust_opsproto_rt2.0.so +0 -0
  90. mindspore/lib/plugin/ascend/libascend_collective.so +0 -0
  91. mindspore/lib/plugin/ascend/libdvpp_utils.so +0 -0
  92. mindspore/lib/plugin/ascend/libhccl_plugin.so +0 -0
  93. mindspore/lib/plugin/ascend/liblowlatency_collective.so +0 -0
  94. mindspore/lib/plugin/ascend/libmindspore_cpu_kernels.so +0 -0
  95. mindspore/lib/plugin/ascend/ms_kernels_internal/asdops/bin/DeviceBin +0 -0
  96. mindspore/lib/plugin/ascend/ms_kernels_internal/asdops/bin/PkgInspect +0 -0
  97. mindspore/lib/plugin/ascend/ms_kernels_internal/asdops/bin/op_man +0 -0
  98. mindspore/lib/plugin/ascend/ms_kernels_internal/asdops/device/ascend910b/bin/ascend910b.bin +286 -275
  99. mindspore/lib/plugin/ascend/ms_kernels_internal/asdops/host/libasdops_cann_host.so +0 -0
  100. mindspore/lib/plugin/ascend/ms_kernels_internal/asdops/host/libasdops_host.so +0 -0
  101. mindspore/lib/plugin/ascend/ms_kernels_internal/asdops/lib/libasdops.so +0 -0
  102. mindspore/lib/plugin/ascend/ms_kernels_internal/asdops/lib/libasdops_static.a +0 -0
  103. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/add/add_impl.h +0 -1
  104. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/apply_rotary_pos_emb/apply_rotary_pos_emb_impl.h +0 -1
  105. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/asdop/asd_op_impl.h +0 -3
  106. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/backend_param.h +0 -5
  107. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/cast/cast_tiling.h +45 -1
  108. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/compare/compare_impl.h +0 -1
  109. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/flash_attention_score/flash_attention_score_impl.h +4 -8
  110. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/flash_attention_score/flash_attention_score_tiling.h +4 -11
  111. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/flash_attention_score/kernel/flash_attention_score_mix_hwsync.h +0 -18
  112. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/internal_kernel.h +0 -6
  113. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/internal_rtbackend.h +75 -1
  114. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/matmul/kernel/matmul.h +5 -5
  115. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/matmul/matmul_impl.h +3 -18
  116. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/matmul_common/pp_matmul_common_tiling.h +5 -5
  117. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/matmul_common/pp_matmul_info.h +2 -2
  118. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/matmul_common/tiling_data.h +3 -36
  119. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/matmul_stridedslice/kernel/matmul_stridedslice_fusion.h +2 -2
  120. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/matmul_stridedslice/matmul_stridedslice_fusion_impl.h +4 -22
  121. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/op_param.h +2 -16
  122. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/paged_attention/kernel/paged_attention_mix_hwsync.h +3 -1
  123. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/paged_attention/paged_attention_impl.h +4 -5
  124. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/paged_attention/paged_attention_tiling.h +4 -9
  125. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/param/attention_param.h +2 -5
  126. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/param/matmul_ext_param.h +0 -1
  127. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/param/matmul_qkv_param.h +4 -10
  128. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/param/sub_param.h +12 -0
  129. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/rms_norm/rms_norm_impl.h +0 -1
  130. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/sub/sub_impl.h +0 -1
  131. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/tune_repo/matmul_table.h +1 -1
  132. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/utils/backend.h +2 -10
  133. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/utils/elewise_utils.h +1 -5
  134. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/utils/log/log.h +0 -1
  135. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/utils/log/log_tiling.h +0 -17
  136. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/utils/math.h +7 -2
  137. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libAdd_impl.so +0 -0
  138. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libSub_impl.so +0 -0
  139. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libadd_layernorm_impl.so +0 -0
  140. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libadd_rms_norm_impl.so +0 -0
  141. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libapply_rotary_pos_emb_impl.so +0 -0
  142. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libcast_impl.so +0 -0
  143. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libgelu_impl.so +0 -0
  144. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libmatmul_impl.so +0 -0
  145. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libmatmul_stridedslice_fusion_impl.so +0 -0
  146. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libms_kernels_internal.so +0 -0
  147. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libnot_equal_impl.so +0 -0
  148. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libreshape_and_cache_impl.so +0 -0
  149. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/librms_norm_impl.so +0 -0
  150. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/flash_attention_score_bf16_bnsd_full_mix.o +0 -0
  151. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/flash_attention_score_bf16_bnsd_tri_mix.o +0 -0
  152. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/flash_attention_score_bf16_bsh_full_mix.o +0 -0
  153. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/flash_attention_score_bf16_bsh_tri_mix.o +0 -0
  154. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/flash_attention_score_fp16_bnsd_full_mix.o +0 -0
  155. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/flash_attention_score_fp16_bnsd_tri_mix.o +0 -0
  156. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/flash_attention_score_fp16_bsh_full_mix.o +0 -0
  157. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/flash_attention_score_fp16_bsh_tri_mix.o +0 -0
  158. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/paged_attention_bf16_bnsd_full_mix.o +0 -0
  159. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/paged_attention_bf16_bsh_full_mix.o +0 -0
  160. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/paged_attention_fp16_bnsd_full_mix.o +0 -0
  161. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/paged_attention_fp16_bsh_full_mix.o +0 -0
  162. mindspore/lib/plugin/ascend/ms_kernels_internal/lccl/lib/liblcal.so +0 -0
  163. mindspore/lib/plugin/ascend/ms_kernels_internal/lccl/lib/liblccl_wrapper.so +0 -0
  164. mindspore/lib/plugin/libmindspore_ascend.so.2 +0 -0
  165. mindspore/mindrecord/filewriter.py +2 -2
  166. mindspore/mint/__init__.py +40 -720
  167. mindspore/mint/nn/__init__.py +7 -89
  168. mindspore/mint/nn/functional.py +16 -165
  169. mindspore/mint/optim/adamw.py +16 -15
  170. mindspore/nn/__init__.py +2 -0
  171. mindspore/nn/cell.py +98 -97
  172. mindspore/nn/extend/basic.py +2 -2
  173. mindspore/nn/extend/embedding.py +1 -1
  174. mindspore/nn/extend/layer/normalization.py +5 -7
  175. mindspore/nn/generator.py +297 -0
  176. mindspore/nn/layer/activation.py +3 -4
  177. mindspore/nn/layer/basic.py +16 -79
  178. mindspore/nn/layer/conv.py +8 -17
  179. mindspore/nn/layer/embedding.py +4 -1
  180. mindspore/nn/layer/math.py +1 -1
  181. mindspore/nn/layer/normalization.py +1 -1
  182. mindspore/nn/layer/pooling.py +0 -5
  183. mindspore/nn/layer/rnn_cells.py +2 -2
  184. mindspore/nn/loss/loss.py +19 -19
  185. mindspore/nn/optim/adasum.py +1 -1
  186. mindspore/nn/optim/sgd.py +2 -3
  187. mindspore/nn/probability/distribution/exponential.py +1 -1
  188. mindspore/nn/probability/distribution/geometric.py +1 -1
  189. mindspore/nn/probability/distribution/logistic.py +1 -1
  190. mindspore/nn/wrap/cell_wrapper.py +1 -25
  191. mindspore/nn/wrap/loss_scale.py +1 -24
  192. mindspore/numpy/array_ops.py +1 -5
  193. mindspore/numpy/dtypes.py +3 -3
  194. mindspore/numpy/math_ops.py +8 -8
  195. mindspore/ops/__init__.py +1 -1
  196. mindspore/ops/_grad_experimental/grad_comm_ops.py +16 -75
  197. mindspore/ops/_vmap/vmap_array_ops.py +0 -27
  198. mindspore/ops/_vmap/vmap_math_ops.py +1 -29
  199. mindspore/ops/_vmap/vmap_nn_ops.py +18 -19
  200. mindspore/ops/auto_generate/cpp_create_prim_instance_helper.py +8 -34
  201. mindspore/ops/auto_generate/gen_arg_dtype_cast.py +9 -2
  202. mindspore/ops/auto_generate/gen_arg_handler.py +0 -26
  203. mindspore/ops/auto_generate/gen_extend_func.py +27 -603
  204. mindspore/ops/auto_generate/gen_ops_def.py +203 -993
  205. mindspore/ops/auto_generate/gen_ops_prim.py +402 -1946
  206. mindspore/ops/auto_generate/pyboost_inner_prim.py +20 -90
  207. mindspore/ops/composite/base.py +6 -3
  208. mindspore/ops/composite/math_ops.py +1 -1
  209. mindspore/ops/composite/multitype_ops/_compile_utils.py +17 -24
  210. mindspore/ops/composite/multitype_ops/_constexpr_utils.py +1 -1
  211. mindspore/ops/extend/__init__.py +3 -2
  212. mindspore/ops/extend/array_func.py +51 -10
  213. mindspore/ops/extend/nn_func.py +78 -2
  214. mindspore/ops/function/__init__.py +13 -8
  215. mindspore/ops/function/array_func.py +179 -455
  216. mindspore/ops/function/clip_func.py +1 -1
  217. mindspore/ops/function/grad/grad_func.py +3 -3
  218. mindspore/ops/function/math_func.py +103 -117
  219. mindspore/ops/function/nn_func.py +163 -275
  220. mindspore/ops/function/other_func.py +2 -2
  221. mindspore/ops/function/random_func.py +69 -202
  222. mindspore/ops/function/sparse_func.py +4 -4
  223. mindspore/ops/functional.py +327 -332
  224. mindspore/ops/operations/__init__.py +3 -13
  225. mindspore/ops/operations/_grad_ops.py +27 -3
  226. mindspore/ops/operations/_inner_ops.py +356 -53
  227. mindspore/ops/operations/_rl_inner_ops.py +2 -2
  228. mindspore/ops/operations/_tensor_array.py +8 -8
  229. mindspore/ops/operations/array_ops.py +65 -82
  230. mindspore/ops/operations/comm_ops.py +93 -784
  231. mindspore/ops/operations/custom_ops.py +28 -51
  232. mindspore/ops/operations/debug_ops.py +4 -4
  233. mindspore/ops/operations/inner_ops.py +2 -2
  234. mindspore/ops/operations/manually_defined/ops_def.py +4 -304
  235. mindspore/ops/operations/math_ops.py +50 -3
  236. mindspore/ops/operations/nn_ops.py +247 -14
  237. mindspore/ops/operations/other_ops.py +3 -3
  238. mindspore/ops/operations/random_ops.py +1 -1
  239. mindspore/ops/operations/sparse_ops.py +1 -1
  240. mindspore/ops/primitive.py +8 -9
  241. mindspore/ops/silent_check.py +5 -5
  242. mindspore/ops_generate/arg_dtype_cast.py +9 -2
  243. mindspore/ops_generate/arg_handler.py +0 -26
  244. mindspore/ops_generate/gen_aclnn_implement.py +4 -1
  245. mindspore/ops_generate/gen_ops.py +4 -26
  246. mindspore/ops_generate/gen_pyboost_func.py +12 -41
  247. mindspore/ops_generate/gen_utils.py +0 -21
  248. mindspore/ops_generate/pyboost_utils.py +2 -7
  249. mindspore/ops_generate/template.py +0 -1
  250. mindspore/parallel/_auto_parallel_context.py +1 -21
  251. mindspore/parallel/_tensor.py +5 -0
  252. mindspore/parallel/_transformer/transformer.py +1 -1
  253. mindspore/parallel/_utils.py +1 -15
  254. mindspore/parallel/algo_parameter_config.py +3 -1
  255. mindspore/parallel/checkpoint_transform.py +9 -12
  256. mindspore/parallel/cluster/process_entity/_api.py +29 -28
  257. mindspore/parallel/cluster/process_entity/_utils.py +3 -13
  258. mindspore/parallel/cluster/run.py +16 -13
  259. mindspore/parallel/parameter_broadcast.py +2 -2
  260. mindspore/parallel/shard.py +17 -31
  261. mindspore/profiler/__init__.py +2 -3
  262. mindspore/profiler/common/util.py +2 -107
  263. mindspore/profiler/envprofiling.py +1 -1
  264. mindspore/profiler/parser/ascend_analysis/constant.py +21 -8
  265. mindspore/profiler/parser/ascend_analysis/file_manager.py +0 -82
  266. mindspore/profiler/parser/ascend_analysis/function_event.py +28 -43
  267. mindspore/profiler/parser/ascend_analysis/fwk_cann_parser.py +27 -49
  268. mindspore/profiler/parser/ascend_analysis/fwk_file_parser.py +10 -15
  269. mindspore/profiler/parser/ascend_analysis/msprof_timeline_parser.py +20 -25
  270. mindspore/profiler/parser/ascend_analysis/profiler_info_parser.py +5 -5
  271. mindspore/profiler/parser/ascend_analysis/trace_event_manager.py +1 -10
  272. mindspore/profiler/parser/ascend_hccl_generator.py +1 -4
  273. mindspore/profiler/parser/ascend_msprof_exporter.py +22 -43
  274. mindspore/profiler/parser/ascend_timeline_generator.py +5 -7
  275. mindspore/profiler/parser/minddata_parser.py +3 -72
  276. mindspore/profiler/profiling.py +59 -176
  277. mindspore/rewrite/api/node.py +1 -1
  278. mindspore/rewrite/common/namespace.py +5 -5
  279. mindspore/rewrite/parsers/assign_parser.py +0 -2
  280. mindspore/rewrite/parsers/class_def_parser.py +4 -8
  281. mindspore/run_check/_check_version.py +1 -1
  282. mindspore/scipy/fft.py +3 -1
  283. mindspore/scipy/linalg.py +3 -2
  284. mindspore/scipy/ops.py +3 -5
  285. mindspore/scipy/optimize/__init__.py +2 -2
  286. mindspore/train/__init__.py +4 -4
  287. mindspore/train/anf_ir_pb2.py +2 -8
  288. mindspore/train/callback/__init__.py +2 -5
  289. mindspore/train/callback/_backup_and_restore.py +2 -2
  290. mindspore/train/callback/_checkpoint.py +16 -104
  291. mindspore/train/callback/_landscape.py +1 -1
  292. mindspore/train/callback/_time_monitor.py +1 -1
  293. mindspore/train/data_sink.py +4 -5
  294. mindspore/train/dataset_helper.py +20 -45
  295. mindspore/train/model.py +38 -266
  296. mindspore/train/serialization.py +105 -256
  297. mindspore/train/summary/_summary_adapter.py +1 -1
  298. mindspore/version.py +1 -1
  299. {mindspore-2.3.0.dist-info → mindspore-2.3.0rc2.dist-info}/METADATA +2 -2
  300. {mindspore-2.3.0.dist-info → mindspore-2.3.0rc2.dist-info}/RECORD +303 -420
  301. mindspore/_extends/pijit/__init__.py +0 -23
  302. mindspore/_extends/pijit/pijit_func_white_list.py +0 -343
  303. mindspore/common/file_system.py +0 -48
  304. mindspore/common/generator.py +0 -260
  305. mindspore/common/no_inline.py +0 -54
  306. mindspore/common/np_dtype.py +0 -25
  307. mindspore/communication/comm_func.py +0 -1140
  308. mindspore/hal/memory.py +0 -326
  309. mindspore/lib/libavcodec.so.59 +0 -0
  310. mindspore/lib/libavdevice.so.59 +0 -0
  311. mindspore/lib/libavfilter.so.8 +0 -0
  312. mindspore/lib/libavformat.so.59 +0 -0
  313. mindspore/lib/libavutil.so.57 +0 -0
  314. mindspore/lib/libmindspore_np_dtype.so +0 -0
  315. mindspore/lib/libswresample.so.4 +0 -0
  316. mindspore/lib/libswscale.so.6 +0 -0
  317. mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/custom_ascendc_ops_impl/dynamic/all_finite.cpp +0 -326
  318. mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/custom_ascendc_ops_impl/dynamic/all_finite.py +0 -180
  319. mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/kernel/ascend910b/all_finite/AllFinite_576ceaeef5870c451cab59af55ea46ad.json +0 -58
  320. mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/kernel/ascend910b/all_finite/AllFinite_576ceaeef5870c451cab59af55ea46ad.o +0 -0
  321. mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/kernel/ascend910b/all_finite/AllFinite_86a73ff6e28d734c96bb8d3054f7dd18.json +0 -58
  322. mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/kernel/ascend910b/all_finite/AllFinite_86a73ff6e28d734c96bb8d3054f7dd18.o +0 -0
  323. mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/kernel/ascend910b/all_finite/AllFinite_f55e0ebaad1f2f572e43677336992fa0.json +0 -58
  324. mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/kernel/ascend910b/all_finite/AllFinite_f55e0ebaad1f2f572e43677336992fa0.o +0 -0
  325. mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/kernel/config/ascend910b/all_finite.json +0 -109
  326. mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/kernel/config/ascend910b/binary_info_config.json +0 -38
  327. mindspore/lib/plugin/ascend/custom_compiler/OWNERS +0 -12
  328. mindspore/lib/plugin/ascend/custom_compiler/setup.py +0 -255
  329. mindspore/lib/plugin/ascend/custom_compiler/start.sh +0 -26
  330. mindspore/lib/plugin/ascend/custom_compiler/template.json +0 -40
  331. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/include/acme.h +0 -24
  332. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/include/acme_op.h +0 -69
  333. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/include/base_type.h +0 -133
  334. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/include/op_creator.h +0 -32
  335. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/include/op_param.h +0 -35
  336. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/include/tiling_info.h +0 -60
  337. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/src/core/kernel_register.h +0 -37
  338. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/src/core/platform/platform_configs.h +0 -89
  339. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/src/core/platform/rt_funcs.h +0 -135
  340. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/src/ops/host_src/add_op.h +0 -34
  341. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/src/ops/host_src/asd_backoff_base.h +0 -62
  342. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/src/ops/host_src/asd_elewise_op.h +0 -33
  343. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/src/ops/host_src/asd_ops.h +0 -88
  344. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/src/ops/host_src/asd_pa_op.h +0 -45
  345. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/src/ops/host_src/cast_op.h +0 -52
  346. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/src/ops/host_src/matmul_op.h +0 -95
  347. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/src/utils/asd_utils.h +0 -84
  348. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/src/utils/comm_utils.h +0 -61
  349. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/apply_rotary_pos_emb/kernel/apply_rotary_pos_emb_fp32.h +0 -224
  350. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_binary/and_impl.h +0 -29
  351. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_binary/div_impl.h +0 -29
  352. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_binary/elewise_binary_impl.h +0 -48
  353. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_binary/elewise_binary_tiling.h +0 -25
  354. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_binary/kernel/and_kernel.h +0 -46
  355. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_binary/kernel/div_kernel.h +0 -46
  356. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_binary/kernel/elewise_binary_base.h +0 -260
  357. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_binary/kernel/elewise_binary_kernel.h +0 -35
  358. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_binary/kernel/max_kernel.h +0 -66
  359. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_binary/kernel/min_kernel.h +0 -66
  360. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_binary/kernel/mul_kernel.h +0 -66
  361. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_binary/kernel/or_kernel.h +0 -46
  362. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_binary/max_impl.h +0 -29
  363. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_binary/min_impl.h +0 -29
  364. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_binary/mul_impl.h +0 -29
  365. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_binary/or_impl.h +0 -29
  366. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/abs_impl.h +0 -29
  367. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/elewise_unary_impl.h +0 -47
  368. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/elewise_unary_tiling.h +0 -24
  369. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/exp_impl.h +0 -29
  370. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/kernel/abs_kernel.h +0 -45
  371. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/kernel/elewise_unary_base.h +0 -148
  372. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/kernel/elewise_unary_kernel.h +0 -31
  373. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/kernel/exp_kernel.h +0 -45
  374. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/kernel/ln_kernel.h +0 -45
  375. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/kernel/not_kernel.h +0 -45
  376. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/kernel/reciprocal_kernel.h +0 -45
  377. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/kernel/relu_kernel.h +0 -55
  378. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/kernel/rsqrt_kernel.h +0 -45
  379. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/kernel/sqrt_kernel.h +0 -45
  380. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/ln_impl.h +0 -29
  381. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/not_impl.h +0 -29
  382. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/reciprocal_impl.h +0 -29
  383. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/relu_impl.h +0 -29
  384. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/rsqrt_impl.h +0 -29
  385. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/sqrt_impl.h +0 -29
  386. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/grouped_matmul/grouped_matmul_impl.h +0 -45
  387. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/grouped_matmul/grouped_matmul_tiling.h +0 -187
  388. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/grouped_matmul/kernel/grouped_matmul.h +0 -245
  389. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/grouped_matmul/kernel/grouped_matmul_interface.h +0 -24
  390. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/grouped_matmul/kernel/grouped_matmul_utils.h +0 -111
  391. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/grouped_matmul/tiling_data.h +0 -54
  392. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/param/compare_param.h +0 -31
  393. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/param/elewise_param.h +0 -41
  394. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/param/grouped_matmul_param.h +0 -40
  395. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/profiling_util.h +0 -364
  396. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/utils/log/log_utils.h +0 -69
  397. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/utils/register/kernel_creator.h +0 -39
  398. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/utils/register/kernel_registry.h +0 -114
  399. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/utils/utils.h +0 -98
  400. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/MatMulPostFusionMixTactic/matmul_postfusion_mix.json +0 -19
  401. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/MatMulPostFusionMixTactic/matmul_postfusion_mix.o +0 -0
  402. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/MatMulPostFusionMixTactic/matmul_postfusion_mix_mix_aic_0.o +0 -0
  403. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/MatMulPostFusionMixTactic/matmul_postfusion_mix_mix_aiv_0.o +0 -0
  404. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/MultiMatMulPostFusionMixTactic/multi_matmul_postfusion_mix.json +0 -19
  405. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/MultiMatMulPostFusionMixTactic/multi_matmul_postfusion_mix.o +0 -0
  406. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/MultiMatMulPostFusionMixTactic/multi_matmul_postfusion_mix_mix_aic_0.o +0 -0
  407. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/MultiMatMulPostFusionMixTactic/multi_matmul_postfusion_mix_mix_aiv_0.o +0 -0
  408. mindspore/mint/linalg/__init__.py +0 -22
  409. mindspore/nn/layer/embedding_service.py +0 -531
  410. mindspore/nn/layer/embedding_service_layer.py +0 -393
  411. mindspore/ops/function/reshard_func.py +0 -102
  412. mindspore/ops/operations/_infer_ops.py +0 -19
  413. mindspore/ops/operations/reshard_ops.py +0 -53
  414. mindspore/profiler/common/process_pool.py +0 -41
  415. mindspore/profiler/common/singleton.py +0 -28
  416. mindspore/profiler/parser/ascend_integrate_generator.py +0 -42
  417. mindspore/profiler/parser/ascend_memory_generator.py +0 -185
  418. mindspore/train/callback/_cluster_monitor.py +0 -201
  419. mindspore/train/callback/_flops_collector.py +0 -238
  420. mindspore/train/callback/_mindio_ttp.py +0 -443
  421. {mindspore-2.3.0.dist-info → mindspore-2.3.0rc2.dist-info}/WHEEL +0 -0
  422. {mindspore-2.3.0.dist-info → mindspore-2.3.0rc2.dist-info}/entry_points.txt +0 -0
  423. {mindspore-2.3.0.dist-info → mindspore-2.3.0rc2.dist-info}/top_level.txt +0 -0
@@ -1,1140 +0,0 @@
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
- """
17
- Defines communication operators with functional form.
18
- """
19
- from mindspore.communication import GlobalComm, get_group_rank_from_world_rank, get_group_size
20
- from mindspore.common.tensor import Tensor
21
- from mindspore._c_expression import Tensor as Tensor_
22
- from mindspore.ops import ReduceOp, cat
23
- from mindspore.ops._primitive_cache import _get_cache_prim
24
- from mindspore.ops.primitive import _primexpr
25
-
26
- __all__ = [
27
- 'all_reduce',
28
- 'all_gather_into_tensor',
29
- 'all_to_all_with_output_shape',
30
- 'all_to_all_single_with_output_shape',
31
- 'barrier',
32
- 'broadcast',
33
- 'gather_into_tensor',
34
- 'isend',
35
- 'irecv',
36
- 'reduce_scatter_tensor',
37
- 'reduce',
38
- 'scatter_tensor',
39
- 'P2POp',
40
- 'batch_isend_irecv',
41
- ]
42
-
43
- import mindspore.ops.operations as P
44
-
45
-
46
- def _check_split_sizes_sequence(tensor, sequence):
47
- if sequence == []:
48
- raise TypeError(f"sequence can not be empty list.")
49
- element0 = sequence[0]
50
- for idx in range(1, len(sequence)):
51
- if sequence[idx] != element0:
52
- raise TypeError(f"sequence containing different elements is not supported yet. "
53
- f"Elements must be the same.")
54
- if sum(sequence) != tensor.shape[0]:
55
- raise TypeError(f" The sum of sequence should equal to tensor.shape[0].")
56
-
57
-
58
- def _check_compute_split_count(tensor, output_split_sizes, input_split_sizes, group):
59
- """
60
- Check the output_split_sizes and input_split_sizes by the rules in _check_split_sizes_sequence,
61
- compute the split count and return it.
62
- """
63
- group_size = get_group_size(group)
64
- if output_split_sizes:
65
- _check_split_sizes_sequence(tensor, output_split_sizes)
66
- output_split_value = output_split_sizes[0]
67
- else:
68
- output_split_value = None
69
- if input_split_sizes:
70
- _check_split_sizes_sequence(tensor, input_split_sizes)
71
- input_split_value = input_split_sizes[0]
72
- else:
73
- input_split_value = None
74
- split_count = 0
75
- if input_split_value and output_split_value is None:
76
- split_count = tensor.shape[0] // input_split_value
77
- elif input_split_value is None and output_split_value:
78
- split_count = tensor.shape[0] // output_split_value
79
- elif input_split_value and output_split_value:
80
- if input_split_value != output_split_value:
81
- raise TypeError(f"input_split_value should equal to output_split_value.")
82
- split_count = tensor.shape[0] // input_split_value
83
- else:
84
- split_count = group_size
85
- return split_count
86
-
87
-
88
- @_primexpr
89
- def _check_all_tensors(tensor_list):
90
- """check all elements in tensor_list are type of Tensor"""
91
- if not isinstance(tensor_list, (list, tuple)):
92
- raise TypeError(f"Expected list or tuple, but got {type(tensor_list)}.")
93
- for t in tensor_list:
94
- if not isinstance(t, Tensor):
95
- raise TypeError(f"Expected tensor, but got {type(t)}")
96
-
97
-
98
- @_primexpr
99
- def _check_all_tensors_or_tuple(tensor_list):
100
- """check all elements in tensor_list are type of Tensor or tuple or list"""
101
- if not isinstance(tensor_list, (list, tuple)):
102
- raise TypeError(f"Expected list or tuple, but got {type(tensor_list)}.")
103
- for t in tensor_list:
104
- if not isinstance(t, (Tensor, tuple, list)):
105
- raise TypeError(f"Expected tensor or tuple, but got {type(t)}")
106
-
107
-
108
- @_primexpr
109
- def _check_all_tensor_same_dtype(*tensor_lists):
110
- """check all the input tensor has same dtype"""
111
- consistent_dtype = None
112
- for list_ in tensor_lists:
113
- if not isinstance(list_, (list, tuple)):
114
- list_ = [list_]
115
- for tensor_ in list_:
116
- if not isinstance(tensor_, Tensor):
117
- continue
118
-
119
- dtype = tensor_.dtype
120
- if consistent_dtype is None:
121
- consistent_dtype = dtype
122
- else:
123
- if dtype != consistent_dtype:
124
- raise TypeError("all_to_all input dtype must be the same, "
125
- f"but got {consistent_dtype} and {dtype}.")
126
-
127
-
128
- def _get_size(shape):
129
- numel = 1
130
- for s in shape:
131
- numel *= s
132
- return numel
133
-
134
-
135
- def all_reduce(tensor, op=ReduceOp.SUM, group=GlobalComm.WORLD_COMM_GROUP):
136
- """
137
- Reduce tensors across all devices in such a way that all deviceswill get the same final result,
138
- returns the tensor which is all reduced.
139
-
140
- Note:
141
- The tensors must have the same shape and format in all processes of the collection.
142
-
143
- Args:
144
- tensor (Tensor): The input tensor to be all reduced. The shape of tensor is :math:`(x_1, x_2, ..., x_R)`.
145
- op (str, optional): Specifies an operation used for element-wise reductions, like sum, prod, max, and min.
146
- On the CPU, only 'sum' is supported. Default: ``ReduceOp.SUM`` .
147
- group (str, optional): The communication group to work on. Default: ``GlobalComm.WORLD_COMM_GROUP`` , which
148
- means ``"hccl_world_group"`` in Ascend, and ``"nccl_world_group"`` in GPU.
149
-
150
- Returns:
151
- Tensor, has the same shape of the input, i.e., :math:`(x_1, x_2, ..., x_R)`.
152
- The contents depend on the specified operation.
153
-
154
- Raises:
155
- TypeError: If the type of the first input parameter is not Tensor, or any of `op` and `group` is not a str.
156
- RuntimeError: If device target is invalid, or backend is invalid, or distributed initialization fails.
157
-
158
- Supported Platforms:
159
- ``Ascend`` ``GPU`` ``CPU``
160
-
161
- Examples:
162
- .. note::
163
- Before running the following examples, you need to configure the communication environment variables.
164
-
165
- For Ascend/GPU/CPU devices, it is recommended to use the msrun startup method
166
- without any third-party or configuration file dependencies.
167
- Please see the `msrun start up
168
- <https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/msrun_launcher.html>`_
169
- for more details.
170
-
171
- This example should be run with 2 devices.
172
-
173
- >>> import numpy as np
174
- >>> from mindspore.communication import init
175
- >>> from mindspore.communication.comm_func import all_reduce
176
- >>> from mindspore import Tensor
177
- >>>
178
- >>> init()
179
- >>> input_tensor = Tensor(np.ones([2, 8]).astype(np.float32))
180
- >>> output = all_reduce(input_tensor)
181
- >>> print(output)
182
- [[2. 2. 2. 2. 2. 2. 2. 2.]
183
- [2. 2. 2. 2. 2. 2. 2. 2.]]
184
-
185
- """
186
- if not isinstance(tensor, (Tensor, Tensor_)):
187
- raise TypeError("For all_reduce, the input tensor must be tensor")
188
- all_reduce_op = _get_cache_prim(P.AllReduce)(op=op, group=group)
189
- return all_reduce_op(tensor)
190
-
191
-
192
- def all_gather_into_tensor(tensor, group=GlobalComm.WORLD_COMM_GROUP):
193
- """
194
- Gathers tensors from the specified communication group and returns the tensor which is all gathered.
195
-
196
- Note:
197
- - The tensors must have the same shape and format in all processes of the collection.
198
-
199
- Args:
200
- tensor (Tensor): The input tensor to be all gathered into tensor.
201
- The shape of tensor is :math:`(x_1, x_2, ..., x_R)`.
202
- group (str, optional): The communication group to work on. Default: ``GlobalComm.WORLD_COMM_GROUP`` , which
203
- means ``"hccl_world_group"`` in Ascend, and ``"nccl_world_group"`` in GPU.
204
-
205
- Returns:
206
- Tensor. If the number of devices in the group is N,
207
- then the shape of output is :math:`(N, x_1, x_2, ..., x_R)`.
208
-
209
- Raises:
210
- TypeError: If the type of the first input parameter is not Tensor, or `group` is not a str.
211
- ValueError: If the local rank id of the calling process in the group
212
- is larger than the group's rank size.
213
- RuntimeError: If device target is invalid, or backend is invalid, or distributed initialization fails.
214
-
215
- Supported Platforms:
216
- ``Ascend`` ``GPU``
217
-
218
- Examples:
219
- .. note::
220
- Before running the following examples, you need to configure the communication environment variables.
221
-
222
- For Ascend/GPU/CPU devices, it is recommended to use the msrun startup method
223
- without any third-party or configuration file dependencies.
224
- Please see the `msrun start up
225
- <https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/msrun_launcher.html>`_
226
- for more details.
227
-
228
- This example should be run with 2 devices.
229
-
230
- >>> import numpy as np
231
- >>> import mindspore as ms
232
- >>> from mindspore import ops
233
- >>> from mindspore.communication import init
234
- >>> from mindspore.communication.comm_func import all_gather_into_tensor
235
- >>> from mindspore import Tensor
236
- >>>
237
- >>> ms.set_context(mode=ms.GRAPH_MODE)
238
- >>> init()
239
- >>> input_tensor = Tensor(np.ones([2, 8]).astype(np.float32))
240
- >>> output = all_gather_into_tensor(input_tensor)
241
- >>> print(output)
242
- [[1. 1. 1. 1. 1. 1. 1. 1.]
243
- [1. 1. 1. 1. 1. 1. 1. 1.]
244
- [1. 1. 1. 1. 1. 1. 1. 1.]
245
- [1. 1. 1. 1. 1. 1. 1. 1.]]
246
-
247
- """
248
-
249
- if not isinstance(tensor, (Tensor, Tensor_)):
250
- raise TypeError("For all_gather_into_tensor, the input tensor must be tensor")
251
- all_gather_op = _get_cache_prim(P.AllGather)(group=group)
252
- return all_gather_op(tensor)
253
-
254
-
255
- def reduce_scatter_tensor(tensor, op=ReduceOp.SUM, group=GlobalComm.WORLD_COMM_GROUP):
256
- r"""
257
- Reduces and scatters tensors from the specified communication group and
258
- returns the tensor which is reduced and scattered.
259
-
260
- Note:
261
- The tensors must have the same shape and format in all processes of the collection.
262
-
263
- Args:
264
- tensor(Tensor): The input tensor to be reduced and scattered, suppose it has a shape :math:`(N, *)`, where `*`
265
- means any number of additional dimensions. N must be divisible by rank_size.
266
- rank_size refers to the number of cards in the communication group.
267
- op (str, optional): Specifies an operation used for element-wise reductions,
268
- like SUM and MAX. Default: ``ReduceOp.SUM`` .
269
- group (str, optional): The communication group to work on. Default: ``GlobalComm.WORLD_COMM_GROUP`` , which
270
- means ``"hccl_world_group"`` in Ascend, and ``"nccl_world_group"`` in GPU.
271
-
272
- Returns:
273
- Tensor, it has the same dtype as `input_x` with a shape of :math:`(N/rank\_size, *)`.
274
-
275
- Raises:
276
- TypeError: If the type of the first input parameter is not Tensor, or any of `op` and `group` is not a str.
277
- ValueError: If the first dimension of the input cannot be divided by the rank_size.
278
- RuntimeError: If device target is invalid, or backend is invalid, or distributed initialization fails.
279
-
280
- Supported Platforms:
281
- ``Ascend`` ``GPU``
282
-
283
- Examples:
284
- .. note::
285
- Before running the following examples, you need to configure the communication environment variables.
286
-
287
- For Ascend/GPU/CPU devices, it is recommended to use the msrun startup method
288
- without any third-party or configuration file dependencies.
289
- Please see the `msrun start up
290
- <https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/msrun_launcher.html>`_
291
- for more details.
292
-
293
- This example should be run with 2 devices.
294
-
295
- >>> import mindspore as ms
296
- >>> from mindspore import Tensor
297
- >>> from mindspore.communication import init
298
- >>> from mindspore.communication.comm_func import reduce_scatter_tensor
299
- >>> import numpy as np
300
- >>>
301
- >>> ms.set_context(mode=ms.GRAPH_MODE)
302
- >>> init()
303
- >>> input_tensor = Tensor(np.ones([8, 8]).astype(np.float32))
304
- >>> output = reduce_scatter_tensor(input_tensor)
305
- >>> print(output)
306
- [[2. 2. 2. 2. 2. 2. 2. 2.]
307
- [2. 2. 2. 2. 2. 2. 2. 2.]
308
- [2. 2. 2. 2. 2. 2. 2. 2.]
309
- [2. 2. 2. 2. 2. 2. 2. 2.]]
310
-
311
- """
312
-
313
- if not isinstance(tensor, (Tensor, Tensor_)):
314
- raise TypeError("For reduce_scatter_tensor, the input tensor must be tensor")
315
- reduce_scatter_op = _get_cache_prim(P.ReduceScatter)(op=op, group=group)
316
- return reduce_scatter_op(tensor)
317
-
318
-
319
- def reduce(tensor, dst, op=ReduceOp.SUM, group=GlobalComm.WORLD_COMM_GROUP):
320
- """
321
- Reduces tensors across the processes in the specified communication group, sends the result
322
- to the target dst(global rank), and returns the tensor which is sent to the target process.
323
-
324
- Note:
325
- Only process with destination rank receives the reduced output.
326
- Only support PyNative mode, Graph mode is not currently supported.
327
- Other processes only get a tensor with shape [1], which has no mathematical meaning.
328
-
329
- Args:
330
- tensor (Tensor): The input tensor to be reduced. The shape of tensor is :math:`(x_1, x_2, ..., x_R)`.
331
- dst (int): The target rank of the process(global rank) that receives the reduced output.
332
- op (str, optional): Specifies an operation used for element-wise reductions, like sum, prod, max, and min.
333
- On the CPU, only 'sum' is supported. Default: ``ReduceOp.SUM`` .
334
- group (str, optional): The communication group to work on. Default: ``GlobalComm.WORLD_COMM_GROUP`` , which
335
- means ``"hccl_world_group"`` in Ascend, and ``"nccl_world_group"`` in GPU.
336
-
337
- Returns:
338
- Tensor. Return the tensor in the specific rank of the process after reduction.
339
- The shape of tensor is :math:`(x_1, x_2, ..., x_R)`.
340
-
341
- Raises:
342
- TypeError: If the type of the first input parameter is not Tensor, or any of `op` and `group` is not a str.
343
- RuntimeError: If device target is invalid, or backend is invalid, or distributed initialization fails.
344
-
345
- Supported Platforms:
346
- ``Ascend``
347
-
348
- Examples:
349
- .. note::
350
- Before running the following examples, you need to configure the communication environment variables.
351
-
352
- For Ascend/GPU/CPU devices, it is recommended to use the msrun startup method
353
- without any third-party or configuration file dependencies.
354
-
355
- Please see the `msrun start up
356
- <https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/msrun_launcher.html>`_
357
- for more details.
358
-
359
- This example should be run with 4 devices.
360
-
361
- >>> from mindspore import ops
362
- >>> import mindspore.nn as nn
363
- >>> from mindspore.communication import init
364
- >>> from mindspore.communication.comm_func import reduce
365
- >>> from mindspore import Tensor
366
- >>> import numpy as np
367
- >>> # Launch 4 processes.
368
- >>> init()
369
- >>> dest_rank=1
370
- >>> input_tensor = Tensor(np.ones([2, 8]).astype(np.float32))
371
- >>> output = reduce(input_tensor)
372
- >>> print(output)
373
- Process with rank 1: [[4. 4. 4. 4. 4. 4. 4. 4.]
374
- [4. 4. 4. 4. 4. 4. 4. 4.]],
375
- Other proesses: [0.].
376
- """
377
-
378
- if not isinstance(tensor, (Tensor, Tensor_)):
379
- raise TypeError("For reduce, the input tensor must be tensor")
380
- group_rank = get_group_rank_from_world_rank(dst, group)
381
- reduce_op = _get_cache_prim(P.Reduce)(dest_rank=group_rank, op=op, group=group)
382
- return reduce_op(tensor)
383
-
384
-
385
- class P2POp:
386
- """
387
- Object for `batch_isend_irecv` input, to store information of ``"isend"`` and ``"irecv"``.
388
-
389
- Note:
390
- - Allow pass-in recv shape rather than tensor when `op` is 'irecv'.
391
- - `tensor` will not be modified in-place by final result.
392
-
393
- Args:
394
- op(Union[str, function]): Only string of ``"isend"`` and ``"irecv"`` are allow.
395
- Or function of ``comm_func.isend`` and ``comm_func.irecv`` are allow.
396
- tensor(Union[Tensor, Tuple(int)]): tensor for sending/receiving or receive tensor shape
397
- when `op` is ``"irecv"``.
398
- peer(int): remote global rank for send/receive.
399
- group (str, optional): The communication group to work on. Default: ``GlobalComm.WORLD_COMM_GROUP`` , which
400
- means ``"hccl_world_group"`` in Ascend, and ``"nccl_world_group"`` in GPU.
401
- tag(int, optional): currently not supported yet. default: ``0``.
402
-
403
- Keyword Args:
404
- recv_dtype (mindspore.dtype, optional): when `tensor` is a tuple shape, this arg will be used and has
405
- to be configured. default: ``None``
406
-
407
- Returns:
408
- P2POp Object.
409
-
410
- Raises:
411
- ValueError: when `op` is not string or function of 'isend' and 'irecv'.
412
- TypeError: when `tensor` is not type of Tensor or Tuple.
413
- NotImplementedError: when `tag` is not 0.
414
-
415
- Supported Platforms:
416
- ``Ascend``
417
-
418
- Examples:
419
- >>> import numpy as np
420
- >>> import mindspore
421
- >>> from mindspore.communication.comm_func import P2POp, isend, irecv
422
- >>> from mindspore import Tensor
423
- >>> send_tensor = Tensor(1.)
424
- >>> send_op = P2POp('isend', send_tensor, 1)
425
- >>> send_op = P2POp(isend, send_tensor, 1)
426
- >>> recv_tensor = Tensor(0.)
427
- >>> recv_op = P2POp('irecv', recv_tensor, 0)
428
- >>> recv_op = P2POp(irecv, recv_tensor, 0)
429
- >>> recv_op = P2POp('irecv', (), 0, recv_dtype=mindspore.float32)
430
- """
431
- def __init__(self, op, tensor, peer, group=None, tag=0, *, recv_dtype=None):
432
- self.op = op
433
- self.tensor = tensor
434
- self.peer = peer
435
- self.group = group
436
- self.tag = tag
437
- self.recv_dtype = recv_dtype
438
-
439
- def __new__(cls, op, tensor, peer, group=None, tag=0, recv_dtype=None):
440
- if isinstance(op, str):
441
- op_name = op
442
- else:
443
- op_name = op.__name__
444
- if op_name not in ['isend', 'irecv']:
445
- raise ValueError(f"Expected ``op`` to be of type ``isend`` or `irecv``, but got {op_name}")
446
- if not isinstance(tensor, (Tensor, tuple)):
447
- raise TypeError(f"Expected ``tensor`` to be type of tuple or Tensor, but got {type(tensor)}.")
448
- if tag != 0:
449
- raise NotImplementedError("``tag`` not support yet.")
450
- return object.__new__(cls)
451
-
452
-
453
- def batch_isend_irecv(p2p_op_list):
454
- """
455
- Batch send and recv tensors asynchronously.
456
-
457
- Note:
458
- - The 'isend' and 'irecv' of `P2POp` in `p2p_op_list` between ranks need to match each other.
459
- - `P2POp` in `p2p_op_list` can only use the same communication group.
460
- - `tag` of `P2POp` in `p2p_op_list` is not support yet.
461
- - `tensor` of `P2POp` in `p2p_op_list` will not be modified by result inplace.
462
- - Only support PyNative mode, Graph mode is not currently supported.
463
-
464
- Args:
465
- p2p_op_list(P2POp): list contains `P2POp`. `P2POp` is type of :class:`mindspore.communication.comm_func.P2POp`
466
-
467
- Returns:
468
- tuple(Tensor). Output tensors is corresponding to `p2p_op_list`.
469
- At `P2POp` with 'isend' position, output tensor is a fake tensor with scalar, which has no meaning.
470
- At `P2POp` with 'irecv' position, output tensor is a tensor received from remote device.
471
-
472
- Raises:
473
- TypeError: If `p2p_op_list` are not all type of `P2POp`.
474
-
475
- Supported Platforms:
476
- ``Ascend``
477
-
478
- Examples:
479
- .. note::
480
- Before running the following examples, you need to configure the communication environment variables.
481
-
482
- For Ascend/GPU/CPU devices, it is recommended to use the msrun startup method
483
- without any third-party or configuration file dependencies.
484
- Please see the `msrun start up
485
- <https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/msrun_launcher.html>`_
486
- for more details.
487
-
488
- This example should be run with 2 devices.
489
-
490
- >>> import numpy as np
491
- >>> import mindspore
492
- >>> from mindspore.communication import init, get_rank, get_group_size
493
- >>> from mindspore.communication.comm_func import batch_isend_irecv, P2POp
494
- >>> from mindspore import Tensor
495
- >>>
496
- >>> init()
497
- >>> this_rank = get_rank()
498
- >>> world_size = get_group_size()
499
- >>> next_rank = (this_rank + 1) % world_size
500
- >>> prev_rank = (this_rank + world_size - 1) % world_size
501
- >>>
502
- >>> send_tensor = Tensor(this_rank + 1, dtype=mindspore.float32)
503
- >>> recv_tensor = Tensor(0., dtype=mindspore.float32)
504
- >>>
505
- >>> send_op = P2POp('isend', send_tensor, next_rank)
506
- >>> recv_op = P2POp('irecv', recv_tensor, prev_rank)
507
- >>>
508
- >>> p2p_op_list = [send_op, recv_op]
509
- >>> output = batch_isend_irecv(p2p_op_list)
510
- >>> print(output)
511
- rank 0:
512
- (Tensor(shape=[], dtype=Float32, value= 0), Tensor(shape=[], dtype=Float32, value= 2))
513
- rank 1:
514
- (Tensor(shape=[], dtype=Float32, value= 0), Tensor(shape=[], dtype=Float32, value= 1))
515
- """
516
- send_tensors = []
517
- op_types = []
518
- remotes_ranks = []
519
- receive_shapes = []
520
- receive_dtypes = []
521
- tags = []
522
- group = p2p_op_list[0].group
523
- if group is None:
524
- group = GlobalComm.WORLD_COMM_GROUP
525
- type_ = None
526
- for i, p2p_op in enumerate(p2p_op_list):
527
- if not isinstance(p2p_op, P2POp):
528
- raise TypeError("must be type of P2POp")
529
- if isinstance(p2p_op.op, str):
530
- type_ = p2p_op.op
531
- else:
532
- type_ = p2p_op.op.__name__
533
- rank_ = p2p_op.peer if p2p_op.group is None else \
534
- get_group_rank_from_world_rank(p2p_op.peer, p2p_op.group)
535
- remotes_ranks.append(rank_)
536
- tags.append(p2p_op.tag)
537
- if type_ == "isend":
538
- send_tensors.append(p2p_op.tensor)
539
- elif type_ == "irecv":
540
- if isinstance(p2p_op.tensor, Tensor):
541
- receive_shapes.append(p2p_op.tensor.shape)
542
- receive_dtypes.append(p2p_op.tensor.dtype)
543
- elif isinstance(p2p_op.tensor, tuple):
544
- receive_shapes.append(p2p_op.tensor)
545
- if p2p_op.recv_dtype is None:
546
- raise ValueError(f"'recv_dtype' of {i}th P2POp in p2p_op_list is None but op_types is"
547
- "'irecv' and P2POp.tensor is a tuple type.")
548
- receive_dtypes.append(p2p_op.recv_dtype)
549
- else:
550
- raise TypeError("p2p_op.tensor must be tensor or shape")
551
- else:
552
- raise TypeError("p2p_op.op must be isend or irecv")
553
- op_types.append(type_)
554
-
555
- _op = _get_cache_prim(P.BatchISendIRecv)(op_types,
556
- remotes_ranks,
557
- receive_shapes,
558
- receive_dtypes,
559
- group)
560
- output = _op(send_tensors)
561
- return output
562
-
563
-
564
- def scatter_tensor(tensor, src=0, group=GlobalComm.WORLD_COMM_GROUP):
565
- r"""
566
- Scatter tensor evently across the processes in the specified communication group.
567
-
568
- Note:
569
- The interface behavior only support Tensor input and scatter evenly, which
570
- is different from that of `pytoch.distributed.scatter`.
571
- Only the tensor in process `src` (global rank) will do scatter.
572
- Only support PyNative mode, Graph mode is not currently supported.
573
-
574
- Args:
575
- tensor (Tensor): The input tensor to be scattered. The shape of tensor is :math:`(x_1, x_2, ..., x_R)`.
576
- src (int, optional): Specifies the rank(global rank) of the process that send the tensor.
577
- And only process `src` will send the tensor.
578
- group (str, optional): The communication group to work on.
579
- Default: "GlobalComm.WORLD_COMM_GROUP".
580
-
581
- Returns:
582
- Tensor, the shape of output is :math:`(x_1/src\_rank, x_2, ..., x_R)`. The dimension 0 of data is equal to
583
- the dimension of input tensor divided by `src`, and the other dimension keep the same.
584
-
585
- Raise:
586
- TypeError: If the type of the first input parameter is not Tensor, or any of `op` and `group` is not a str.
587
- RuntimeError: If device target is invalid, or backend is invalid, or distributed initialization fails.
588
-
589
- Supported Platforms:
590
- ``Ascend`` ``GPU``
591
-
592
- Examples:
593
- .. note::
594
- Before running the following examples, you need to configure the communication environment variables.
595
-
596
- For Ascend/GPU/CPU devices, it is recommended to use the msrun startup method
597
- without any third-party or configuration file dependencies.
598
- Please see the `msrun start up
599
- <https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/msrun_launcher.html>`_
600
- for more details.
601
-
602
- This example should be run with 2 devices.
603
-
604
- >>> import mindspore as ms
605
- >>> from mindspore.communication import init
606
- >>> from mindspore.communication.comm_func import scatter_tensor
607
- >>> import numpy as np
608
- >>> # Launch 2 processes.
609
- >>>
610
- >>> init()
611
- >>> input = ms.Tensor(np.arange(8).reshape([4, 2]).astype(np.float32))
612
- >>> out = scatter_tensor(tensor=data, src=0)
613
- >>> print(out)
614
- # rank_0
615
- [[0. 1.]
616
- [2. 3.]]
617
- # rank_1
618
- [[4. 5.]
619
- [6. 7.]]
620
- """
621
- if not isinstance(tensor, (Tensor, Tensor_)):
622
- raise TypeError("For scatter_tensor, the input tensor must be tensor")
623
- if not isinstance(src, int):
624
- raise TypeError("For scatter_tensor, the src must be int")
625
- _src = get_group_rank_from_world_rank(src, group)
626
- _op = _get_cache_prim(P.CollectiveScatter)(_src, group)
627
- return _op(tensor)
628
-
629
-
630
- def gather_into_tensor(tensor, dst=0, group=GlobalComm.WORLD_COMM_GROUP):
631
- r"""
632
- Gathers tensors from the specified communication group. The operation will gather the tensor
633
- from processes according to dimension 0.
634
-
635
- Note:
636
- Only the tensor in process `dst` (global rank) will keep the gathered tensor. The other process
637
- will keep a tensor with shape [1], which has no mathematical meaning.
638
- Only support PyNative mode, Graph mode is not currently supported.
639
-
640
- Args:
641
- tensor (Tensor): The tensor to be gathered. The shape of tensor is :math:`(x_1, x_2, ..., x_R)`.
642
- dst(int, optional): Specifies the rank(global rank) of the process that receive the tensor.
643
- And only process `dst` will receive the gathered tensor. Default: 0.
644
- group (str, optional): The communication group to work on. Default: ``GlobalComm.WORLD_COMM_GROUP``.
645
-
646
- Returns:
647
- Tensor, the shape of output is :math:`(\sum x_1, x_2, ..., x_R)`. The dimension 0 of data is equal to
648
- sum of the dimension of input tensor, and the other dimension keep the same.
649
-
650
- Raise:
651
- TypeError: If the type of the first input parameter is not Tensor, or any of `op` and `group` is not a str.
652
- RuntimeError: If device target is invalid, or backend is invalid, or distributed initialization fails.
653
-
654
- Supported Platforms:
655
- ``Ascend``
656
-
657
- Examples:
658
- .. note::
659
- Before running the following examples, you need to configure the communication environment variables.
660
-
661
- For Ascend/GPU/CPU devices, it is recommended to use the msrun startup method
662
- without any third-party or configuration file dependencies.
663
- Please see the `msrun start up
664
- <https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/msrun_launcher.html>`_
665
- for more details.
666
-
667
- This example should be run with 2 devices.
668
-
669
- >>> import numpy as np
670
- >>> import mindspore as ms
671
- >>> import mindspore.nn as nn
672
- >>> from mindspore.communication import init
673
- >>> from mindspore import Tensor
674
- >>> from mindspore.communication.comm_func import gather_into_tensor
675
- >>> # Launch 2 processes.
676
- >>>
677
- >>> init()
678
- >>> input = Tensor(np.arange(4).reshape([2, 2]).astype(np.float32))
679
- >>> output = gather_into_tensor(tensor=data, dst=0)
680
- >>> print(output)
681
- Process with rank 0: [[0. 1.],
682
- [2. 3.],
683
- [0. 1.],
684
- [2. 3.]]
685
- Process with rank 1: [0]
686
- """
687
- if not isinstance(tensor, (Tensor, Tensor_)):
688
- raise TypeError("For gather_into_tensor, the input tensor must be tensor")
689
- if not isinstance(dst, int):
690
- raise TypeError("For gather_into_tensor, the dst must be int")
691
- _dst = get_group_rank_from_world_rank(dst, group)
692
- _op = _get_cache_prim(P.CollectiveGather)(_dst, group)
693
- return _op(tensor)
694
-
695
-
696
- def broadcast(tensor, src=0, group=GlobalComm.WORLD_COMM_GROUP):
697
- """
698
- Broadcasts the tensor to the whole group.
699
-
700
- Note:
701
- The tensors must have the same shape and format in all processes of the collection.
702
- Only support PyNative mode, Graph mode is not currently supported.
703
-
704
- Args:
705
- tensor (Tensor): The tensor to be broadcasted. The shape of tensor is :math:`(x_1, x_2, ..., x_R)`.
706
- src (int, optional): Specifies the rank(global rank) of the process that broadcast the tensor.
707
- And only process `src` will broadcast the tensor.
708
- group (str, optional): The communication group to work on. Default: ``GlobalComm.WORLD_COMM_GROUP``.
709
-
710
- Returns:
711
- Tensor, tensor has the same shape as input tensor :math:`(x_1, x_2, ..., x_R)`.
712
-
713
- Raises:
714
- TypeError: If src is not an integer or group is not a string.
715
- RuntimeError: If device target is invalid, or backend is invalid, or distributed initialization fails.
716
-
717
- Supported Platforms:
718
- ``Ascend`` ``GPU``
719
-
720
- Examples:
721
- .. note::
722
- Before running the following examples, you need to configure the communication environment variables.
723
-
724
- For Ascend/GPU/CPU devices, it is recommended to use the msrun startup method
725
- without any third-party or configuration file dependencies.
726
- Please see the `msrun start up
727
- <https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/msrun_launcher.html>`_
728
- for more details.
729
-
730
- This example should be run with 2 devices.
731
-
732
- >>> import mindspore as ms
733
- >>> from mindspore import Tensor
734
- >>> from mindspore.communication import init
735
- >>> from mindspore.communication.comm_func import broadcast
736
- >>> import numpy as np
737
- >>> # Launch 2 processes.
738
- >>>
739
- >>> init()
740
- >>> data = ms.Tensor(np.arange(8).reshape([2, 4]).astype(np.float32))
741
- >>> out = broadcast(tensor=data, src=0)
742
- [[0. 1. 2. 3.]
743
- [4. 5. 6. 7.]]
744
-
745
- Tutorial Examples:
746
- - `Distributed Set Communication Primitives - Broadcast
747
- <https://www.mindspore.cn/docs/en/master/api_python/samples/ops/communicate_ops.html#broadcast>`_
748
-
749
- """
750
- if not isinstance(tensor, (Tensor, Tensor_)):
751
- raise TypeError("For broadcast, the input tensor must be tensor")
752
- if not isinstance(src, int):
753
- raise TypeError("For broadcast, the src must be int")
754
- _src = get_group_rank_from_world_rank(src, group)
755
- _op = _get_cache_prim(P.Broadcast)(_src, group)
756
- return _op((tensor,))[0]
757
-
758
-
759
- def barrier(group=GlobalComm.WORLD_COMM_GROUP):
760
- """
761
- Synchronizes all processes in the specified group. Once the process call this operation, it will be blocked until
762
- all processes call this operation. After all processes finish calling the operations, the blocked processes
763
- will be woken and continue their task.
764
-
765
- Args:
766
- group (str, optional): The communication group to work on. Default: ``GlobalComm.WORLD_COMM_GROUP``.
767
-
768
- Raises:
769
- RuntimeError: If backend is invalid, or distributed initialization fails.
770
-
771
- Supported Platforms:
772
- ``Ascend``
773
-
774
- Examples:
775
- .. note::
776
- Before running the following examples, you need to configure the communication environment variables.
777
-
778
- For Ascend/GPU/CPU devices, it is recommended to use the msrun startup method
779
- without any third-party or configuration file dependencies.
780
- Please see the `msrun start up
781
- <https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/msrun_launcher.html>`_
782
- for more details.
783
-
784
- This example should be run with 2 devices.
785
-
786
- >>> from mindspore.communication import init
787
- >>> from mindspore.communication.comm_func import barrier
788
- >>> # Launch 2 processes.
789
- >>> init()
790
- >>> barrier()
791
-
792
- Tutorial Examples:
793
- - `Distributed Set Communication Primitives - Barrier
794
- <https://www.mindspore.cn/docs/en/master/api_python/samples/ops/communicate_ops.html#barrier>`_
795
- """
796
- _op = _get_cache_prim(P.Barrier)(group)
797
- return _op()
798
-
799
-
800
- def isend(tensor, dst=0, group=GlobalComm.WORLD_COMM_GROUP, tag=0):
801
- """
802
- Send tensors to the specified dest_rank.
803
-
804
- Note:
805
- Send and Receive must be used in combination and have same tag.
806
-
807
- Args:
808
- tensor (Tensor): The shape of tensor is :math:`(x_1, x_2, ..., x_R)`.
809
- dst (int, optional): A required integer identifying the destination rank(global rank). Default: 0.
810
- group (str, optional): The communication group to work on.
811
- Default: "hccl_world_group" on Ascend, "nccl_world_group" on GPU.
812
- tag (int, optional): A required integer identifying the send/recv message tag. The message will
813
- be received by the Receive op with the same "tag". Default: 0.
814
-
815
- Raises:
816
- TypeError: `dst` is not an int or `group` is not a str。
817
- ValueError: If the rank ID of the process is greater than the rank size of the communication group.
818
-
819
- Supported Platforms:
820
- ``Ascend`` ``GPU``
821
-
822
- Examples:
823
- .. note::
824
- Before running the following examples, you need to configure the communication environment variables.
825
-
826
- For Ascend/GPU/CPU devices, it is recommended to use the msrun startup method
827
- without any third-party or configuration file dependencies.
828
- Please see the `msrun start up
829
- <https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/msrun_launcher.html>`_
830
- for more details.
831
-
832
- This example should be run with 2 devices.
833
-
834
- >>> from mindspore import ops
835
- >>> import mindspore.nn as nn
836
- >>> from mindspore.communication import init
837
- >>> from mindspore.communication.comm_func import isend
838
- >>> from mindspore import Tensor
839
- >>> import numpy as np
840
- >>>
841
- >>> init()
842
- >>> input_ = Tensor(np.ones([2, 8]).astype(np.float32))
843
- >>> isend(input_, 0)
844
- """
845
- if not isinstance(tensor, (Tensor, Tensor_)):
846
- raise TypeError("For isend, the input tensor must be tensor")
847
- _dst = get_group_rank_from_world_rank(dst, group)
848
- _op = _get_cache_prim(P.Send)(tag, _dst, group, group)
849
- _depend = _get_cache_prim(P.Depend)()
850
- return _depend(tensor, _op(tensor))
851
-
852
-
853
- def irecv(tensor, src=0, group=GlobalComm.WORLD_COMM_GROUP, tag=0):
854
- """
855
- Receive tensors from src.
856
-
857
- Note:
858
- Send and Receive must be used in combination and have same tag.
859
- The shape and dtype of input `tensor` is used to receive tensor, but the value
860
- of input `tensor` would not take effect.
861
- Only support PyNative mode, Graph mode is not currently supported.
862
-
863
- Args:
864
- tensor (Tensor): The shape of tensor is :math:`(x_1, x_2, ..., x_R)`. The shape and dtype of this
865
- tensor is used to receive tensor, but the value of input `tensor` would not take effect.
866
- src (int, optional): A required integer identifying the source rank(global rank). Default: 0.
867
- group (str, optional): The communication group to work on.
868
- Default: "hccl_world_group" on Ascend, "nccl_world_group" on GPU.
869
- tag (int, optional): A required integer identifying the send/recv message tag. The message will
870
- be received by the Send op with the same "tag". Default: 0.
871
-
872
- Returns:
873
- Tensor, the shape of output is :math:`(x_1, x_2, ..., x_R)`.
874
-
875
- Raises:
876
- TypeError: If `src` is not an int or `group` is not a str.
877
- ValueError: If the rank ID of the process is greater than the rank size of the communication group.
878
-
879
- Supported Platforms:
880
- ``Ascend`` ``GPU``
881
-
882
- Examples:
883
- .. note::
884
- Before running the following examples, you need to configure the communication environment variables.
885
-
886
- For Ascend/GPU/CPU devices, it is recommended to use the msrun startup method
887
- without any third-party or configuration file dependencies.
888
- Please see the `msrun start up
889
- <https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/msrun_launcher.html>`_
890
- for more details.
891
-
892
- This example should be run with 2 devices.
893
-
894
- >>> from mindspore import ops
895
- >>> import mindspore.nn as nn
896
- >>> from mindspore.communication import init
897
- >>> from mindspore.communication.comm_func import irecv
898
- >>> from mindspore import Tensor
899
- >>> import numpy as np
900
- >>>
901
- # Launch 2 processes.
902
- Process 0 send the following array to Process 1
903
- [[ 0. 1.]
904
- [ 2. 3.]]
905
- >>> init()
906
- >>> x = ms.Tensor(np.zeros([2, 2]))
907
- # Process 1 receive tensor from Process 0.
908
- >>> out = irecv(x, src=0)
909
- >>> print(out)
910
- [[ 0. 1.]
911
- [ 2. 3.]]
912
- """
913
- _src = get_group_rank_from_world_rank(src, group)
914
- shape = tensor.shape
915
- dtype = tensor.dtype
916
- _op = _get_cache_prim(P.Receive)(tag, _src, shape, dtype, group, group)
917
- return _op(tensor)
918
-
919
-
920
- def all_to_all_with_output_shape(output_shape_list, input_tensor_list, group=None):
921
- """
922
- scatter and gather list of tensor to/from all rank according to input/output tensor list.
923
-
924
- Note:
925
- tensor shape in `output_shape_list` and `input_tensor_list` should be match across ranks.
926
- Only support PyNative mode, Graph mode is not currently supported.
927
-
928
- Args:
929
- output_shape_list (Union[Tuple(Tensor), List(Tensor), Tuple(Tuple(int))]): List of shape
930
- that indicate the gathered tensors shape from remote ranks.
931
- input_tensor_list (Union[Tuple(Tensor), List(Tensor)]):
932
- List of tensors to scatter to the remote rank.
933
- group (str, optional): The communication group to work on.
934
- Default: None, which means "hccl_world_group" on Ascend, "nccl_world_group" on GPU.
935
-
936
- Returns:
937
- Tuple(Tensor), the tensors gathered from remote ranks.
938
-
939
- Raises:
940
- TypeError: If `input_tensor_list` is not list of tensors.
941
- TypeError: If `output_shape_list` is not list of tuple or tensors.
942
- TypeError: If tensors in `input_tensor_list` are not the same type.
943
-
944
- Supported Platforms:
945
- ``Ascend``
946
-
947
- Examples:
948
- .. note::
949
- Before running the following examples, you need to configure the communication environment variables.
950
-
951
- For Ascend/GPU/CPU devices, it is recommended to use the msrun startup method
952
- without any third-party or configuration file dependencies.
953
- Please see the `msrun start up
954
- <https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/msrun_launcher.html>`_
955
- for more details.
956
-
957
- This example should be run with 2 devices.
958
-
959
- >>> import numpy as np
960
- >>> import mindspore
961
- >>> from mindspore.communication import init, get_rank, get_group_size
962
- >>> from mindspore.communication.comm_func import all_to_all_with_output_shape
963
- >>> from mindspore import Tensor
964
- >>> from mindspore.ops import zeros
965
- >>>
966
- >>> init()
967
- >>> this_rank = get_rank()
968
- >>> if this_rank == 0:
969
- >>> send_tensor_list = [Tensor(1.), Tensor([[2, 3], [4, 5.]])]
970
- >>> recv_tensor_list = [(), (2,)]
971
- >>> if this_rank == 1:
972
- >>> send_tensor_list = [Tensor([2, 2.]), Tensor([4, 5, 6, 7.])]
973
- >>> recv_tensor_list = [(2, 2), (4,)]
974
- >>> output = all_to_all_with_output_shape(recv_tensor_list, send_tensor_list)
975
- >>> print(output)
976
- rank 0:
977
- (Tensor(shape=[], dtype=Float32, value= 1),
978
- Tensor(shape=[2], dtype=Float32, value= [2.00000000e+00, 2.00000000e+00]))
979
- rank 1:
980
- (Tensor(shape=[2, 2], dtype=Float32, value=
981
- [[2.00000000e+00, 3.00000000e+00],
982
- [4.00000000e+00, 5.00000000e+00]]),
983
- Tensor(shape=[4], dtype=Float32, value=[4.00000000e+00, 5.00000000e+00, 6.00000000e+00, 7.00000000e+00]))
984
-
985
- """
986
-
987
- _check_all_tensors(input_tensor_list)
988
- _check_all_tensors_or_tuple(output_shape_list)
989
- _check_all_tensor_same_dtype(input_tensor_list)
990
- send_numel_list = []
991
- send_flatten_tensor = []
992
- recv_numel_list = []
993
- recv_shape_list = []
994
-
995
- for tensor in input_tensor_list:
996
- send_numel_list.append(tensor.size)
997
- send_flatten_tensor.append(tensor.reshape(-1))
998
- for tensor in output_shape_list:
999
- if isinstance(tensor, Tensor):
1000
- recv_numel_list.append(tensor.size)
1001
- recv_shape_list.append(tensor.shape)
1002
- else:
1003
- _shape = tensor
1004
- recv_numel_list.append(_get_size(_shape))
1005
- recv_shape_list.append(_shape)
1006
-
1007
- _op = _get_cache_prim(P.AlltoAllV)(send_numel_list, recv_numel_list, group)
1008
- send_flatten_tensor = cat(send_flatten_tensor)
1009
- output = _op(send_flatten_tensor)
1010
- result = []
1011
- offset = 0
1012
- for numel, shape in zip(recv_numel_list, recv_shape_list):
1013
- result.append(output[offset:offset + numel].reshape(shape))
1014
- offset = offset + numel
1015
- return tuple(result)
1016
-
1017
-
1018
- def _get_all_to_all_single_numel_list(tensor, output_shape, output_split_sizes, input_split_sizes, group):
1019
- """get numel list for all_to_all_single."""
1020
- if input_split_sizes is None or not input_split_sizes:
1021
- _world_size = get_group_size(group)
1022
- if tensor.shape[0] % _world_size != 0:
1023
- raise ValueError("input shape at dim 0 must be divided by world_size, "
1024
- f"but got {tensor.shape[0]} and {_world_size}.")
1025
- _split_size = tensor.shape[0] // _world_size
1026
- input_split_sizes = (_split_size,) * _world_size
1027
- if output_split_sizes is None or not output_split_sizes:
1028
- _world_size = get_group_size(group)
1029
- shape_dim_0 = None
1030
- if isinstance(output_shape, Tensor):
1031
- shape_dim_0 = output_shape.shape[0]
1032
- else:
1033
- shape_dim_0 = output_shape[0]
1034
- if shape_dim_0 % _world_size != 0:
1035
- raise ValueError("output shape at dim 0 must be divided by world_size, "
1036
- f"but got {shape_dim_0} and {_world_size}.")
1037
- _split_size = shape_dim_0 // _world_size
1038
- output_split_sizes = (_split_size,) * _world_size
1039
-
1040
- send_size_without_first_dim = _get_size(tensor.shape[1:])
1041
- send_numel_list = [size * send_size_without_first_dim for size in input_split_sizes]
1042
-
1043
- recv_size_without_first_dim = None
1044
- recv_shape_without_first_dim = None
1045
- if isinstance(output_shape, Tensor):
1046
- recv_shape_without_first_dim = output_shape.shape[1:]
1047
- recv_size_without_first_dim = _get_size(recv_shape_without_first_dim)
1048
- else:
1049
- recv_shape_without_first_dim = output_shape[1:]
1050
- recv_size_without_first_dim = _get_size(recv_shape_without_first_dim)
1051
- recv_numel_list = [size * recv_size_without_first_dim for size in output_split_sizes]
1052
- return send_numel_list, recv_numel_list, recv_shape_without_first_dim
1053
-
1054
-
1055
- def all_to_all_single_with_output_shape(output_shape, tensor, output_split_sizes=None,
1056
- input_split_sizes=None, group=None):
1057
- """
1058
- scatter and gather input with split size to/from all rank, and return result in a single tensor.
1059
-
1060
- Note:
1061
- 'output_shape' and 'tensor' shape should be match across ranks.
1062
- Only support PyNative mode, Graph mode is not currently supported.
1063
-
1064
- Args:
1065
- output_shape (Union(Tensor, Tuple(int))): shape to indicate the shape
1066
- of tensor gathered concatenated from remote rank.
1067
- tensor (Tensor): tensor to be scattered to remote rank.
1068
- output_split_sizes (Union(Tuple(int), List(int))): output split size at dim 0. If set to None,
1069
- it means equally split by ``world_size``. Default: None.
1070
- input_split_sizes (Union(Tuple(int), List(int))): input split size at dim 0. If set to None,
1071
- it means equally split by ``world_size``. Default: None.
1072
- group (str, optional): The communication group to work on.
1073
- Default: None, which means "hccl_world_group" on Ascend, "nccl_world_group" on GPU.
1074
-
1075
- Returns:
1076
- Tensor, the tensors gathered concatenated from remote ranks.
1077
- If the numel of tensor gathered from remote is zero, it will return a Tensor will value 0,
1078
- which has no actual meanning.
1079
-
1080
- Raises:
1081
- TypeError: If `tensor` is not tensor.
1082
- TypeError: If `output_shape` is not tuple or tensors.
1083
-
1084
- Supported Platforms:
1085
- ``Ascend``
1086
-
1087
- Examples:
1088
- .. note::
1089
- Before running the following examples, you need to configure the communication environment variables.
1090
-
1091
- For Ascend/GPU/CPU devices, it is recommended to use the msrun startup method
1092
- without any third-party or configuration file dependencies.
1093
- Please see the `msrun start up
1094
- <https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/msrun_launcher.html>`_
1095
- for more details.
1096
-
1097
- This example should be run with 2 devices.
1098
-
1099
- >>> import numpy as np
1100
- >>> import mindspore
1101
- >>> from mindspore.communication import init, get_rank, get_group_size
1102
- >>> from mindspore.communication.comm_func import all_to_all_single_with_output_shape
1103
- >>> from mindspore import Tensor
1104
- >>> from mindspore.ops import zeros
1105
- >>>
1106
- >>> init()
1107
- >>> this_rank = get_rank()
1108
- >>> if this_rank == 0:
1109
- >>> output_shape = (3, 3)
1110
- >>> tensor = Tensor([[0, 1, 2.], [3, 4, 5], [6, 7, 8]])
1111
- >>> result = all_to_all_single_with_output_shape(output_shape, tensor, [2, 1], [2, 1])
1112
- >>> if this_rank == 1:
1113
- >>> output_shape = (2, 3)
1114
- >>> tensor = Tensor([[9, 10., 11], [12, 13, 14]])
1115
- >>> result = all_to_all_single_with_output_shape(output_shape, tensor)
1116
- >>> print(result)
1117
- rank 0:
1118
- [[ 0. 1. 2.]
1119
- [ 3. 4. 5.]
1120
- [ 9. 10. 11.]]
1121
- rank 1:
1122
- [[ 6. 7. 8.]
1123
- [12. 13. 14.]]
1124
-
1125
- """
1126
-
1127
- _check_all_tensors([tensor])
1128
- _check_all_tensors_or_tuple([output_shape])
1129
- if group is None:
1130
- group = GlobalComm.WORLD_COMM_GROUP
1131
-
1132
- send_numel_list, recv_numel_list, recv_shape_without_first_dim = \
1133
- _get_all_to_all_single_numel_list(tensor, output_shape, output_split_sizes, input_split_sizes, group)
1134
- _op = _get_cache_prim(P.AlltoAllV)(send_numel_list, recv_numel_list, group)
1135
- _input = tensor.reshape(-1)
1136
- result = _op(_input)
1137
- if any(recv_numel_list):
1138
- result = result.reshape((-1,) + recv_shape_without_first_dim)
1139
-
1140
- return result