mindspore 2.3.0rc1__cp38-none-any.whl → 2.3.0rc2__cp38-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 (318) hide show
  1. mindspore/.commit_id +1 -1
  2. mindspore/__init__.py +1 -1
  3. mindspore/_akg/akg/utils/tbe_codegen_utils.py +13 -3
  4. mindspore/_c_dataengine.cpython-38-aarch64-linux-gnu.so +0 -0
  5. mindspore/_c_expression.cpython-38-aarch64-linux-gnu.so +0 -0
  6. mindspore/_checkparam.py +20 -0
  7. mindspore/_extends/parse/parser.py +1 -1
  8. mindspore/_extends/parse/standard_method.py +6 -5
  9. mindspore/_mindspore_offline_debug.cpython-38-aarch64-linux-gnu.so +0 -0
  10. mindspore/amp.py +5 -5
  11. mindspore/bin/cache_admin +0 -0
  12. mindspore/bin/cache_server +0 -0
  13. mindspore/boost/boost_cell_wrapper.py +1 -1
  14. mindspore/boost/group_loss_scale_manager.py +1 -1
  15. mindspore/common/__init__.py +4 -2
  16. mindspore/common/_register_for_recompute.py +48 -0
  17. mindspore/common/_stub_tensor.py +1 -0
  18. mindspore/common/api.py +56 -4
  19. mindspore/common/dtype.py +5 -3
  20. mindspore/common/dump.py +2 -2
  21. mindspore/common/hook_handle.py +51 -4
  22. mindspore/common/initializer.py +1 -1
  23. mindspore/common/jit_config.py +17 -6
  24. mindspore/common/parameter.py +7 -2
  25. mindspore/common/recompute.py +247 -0
  26. mindspore/common/sparse_tensor.py +2 -2
  27. mindspore/common/symbol.py +1 -1
  28. mindspore/common/tensor.py +74 -36
  29. mindspore/communication/__init__.py +3 -3
  30. mindspore/communication/management.py +30 -30
  31. mindspore/context.py +28 -15
  32. mindspore/dataset/__init__.py +5 -5
  33. mindspore/dataset/audio/__init__.py +2 -2
  34. mindspore/dataset/audio/transforms.py +51 -51
  35. mindspore/dataset/callback/ds_callback.py +2 -2
  36. mindspore/dataset/engine/cache_client.py +1 -1
  37. mindspore/dataset/engine/datasets.py +3 -3
  38. mindspore/dataset/engine/datasets_audio.py +14 -14
  39. mindspore/dataset/engine/datasets_standard_format.py +3 -3
  40. mindspore/dataset/engine/datasets_text.py +38 -38
  41. mindspore/dataset/engine/datasets_user_defined.py +3 -3
  42. mindspore/dataset/engine/datasets_vision.py +68 -68
  43. mindspore/dataset/text/__init__.py +3 -3
  44. mindspore/dataset/text/transforms.py +26 -26
  45. mindspore/dataset/transforms/__init__.py +1 -1
  46. mindspore/dataset/vision/__init__.py +3 -3
  47. mindspore/dataset/vision/transforms.py +92 -92
  48. mindspore/dataset/vision/utils.py +1 -1
  49. mindspore/experimental/optim/adadelta.py +2 -2
  50. mindspore/experimental/optim/adagrad.py +2 -2
  51. mindspore/experimental/optim/adam.py +2 -2
  52. mindspore/experimental/optim/adamax.py +2 -2
  53. mindspore/experimental/optim/adamw.py +2 -2
  54. mindspore/experimental/optim/asgd.py +2 -2
  55. mindspore/experimental/optim/lr_scheduler.py +24 -20
  56. mindspore/experimental/optim/nadam.py +2 -2
  57. mindspore/experimental/optim/optimizer.py +1 -1
  58. mindspore/experimental/optim/radam.py +2 -2
  59. mindspore/experimental/optim/rmsprop.py +2 -2
  60. mindspore/experimental/optim/rprop.py +2 -2
  61. mindspore/experimental/optim/sgd.py +2 -2
  62. mindspore/hal/stream.py +2 -0
  63. mindspore/include/mindapi/base/types.h +5 -0
  64. mindspore/lib/libdnnl.so.2 +0 -0
  65. mindspore/lib/libmindspore.so +0 -0
  66. mindspore/lib/libmindspore_backend.so +0 -0
  67. mindspore/lib/libmindspore_common.so +0 -0
  68. mindspore/lib/libmindspore_core.so +0 -0
  69. mindspore/lib/libmindspore_glog.so.0 +0 -0
  70. mindspore/lib/libmindspore_gpr.so.15 +0 -0
  71. mindspore/lib/libmindspore_grpc.so.15 +0 -0
  72. mindspore/lib/libmindspore_shared_lib.so +0 -0
  73. mindspore/lib/libopencv_core.so.4.5 +0 -0
  74. mindspore/lib/libopencv_imgcodecs.so.4.5 +0 -0
  75. mindspore/lib/libopencv_imgproc.so.4.5 +0 -0
  76. mindspore/lib/plugin/ascend/custom_aicpu_ops/op_impl/cpu/aicpu_kernel/impl/libcust_cpu_kernels.so +0 -0
  77. mindspore/lib/plugin/ascend/custom_aicpu_ops/op_impl/cpu/config/cust_aicpu_kernel.json +6 -6
  78. mindspore/lib/plugin/ascend/custom_aicpu_ops/op_proto/libcust_op_proto.so +0 -0
  79. mindspore/lib/plugin/ascend/libdvpp_utils.so +0 -0
  80. mindspore/lib/plugin/ascend/liblowlatency_collective.so +0 -0
  81. mindspore/lib/plugin/ascend/libmindspore_cpu_kernels.so +0 -0
  82. mindspore/lib/plugin/ascend/ms_kernels_internal/asdops/bin/DeviceBin +0 -0
  83. mindspore/lib/plugin/ascend/ms_kernels_internal/asdops/bin/PkgInspect +0 -0
  84. mindspore/lib/plugin/ascend/ms_kernels_internal/asdops/bin/op_man +0 -0
  85. mindspore/lib/plugin/ascend/ms_kernels_internal/asdops/device/ascend910b/bin/ascend910b.bin +101787 -98559
  86. mindspore/lib/plugin/ascend/ms_kernels_internal/asdops/host/libasdops_cann_host.so +0 -0
  87. mindspore/lib/plugin/ascend/ms_kernels_internal/asdops/host/libasdops_host.so +0 -0
  88. mindspore/lib/plugin/ascend/ms_kernels_internal/asdops/include/asdops/base/op_register.h +2 -2
  89. mindspore/lib/plugin/ascend/ms_kernels_internal/asdops/include/asdops/params/mix.h +8 -1
  90. mindspore/lib/plugin/ascend/ms_kernels_internal/asdops/include/asdops/params/norm.h +5 -3
  91. mindspore/lib/plugin/ascend/ms_kernels_internal/asdops/include/asdops/params/reduce.h +2 -2
  92. mindspore/lib/plugin/ascend/ms_kernels_internal/asdops/include/asdops/utils/rt/backend/backend.h +3 -3
  93. mindspore/lib/plugin/ascend/ms_kernels_internal/asdops/include/asdops/utils/rt/backend/rtbackend.h +3 -3
  94. mindspore/lib/plugin/ascend/ms_kernels_internal/asdops/include/asdops/utils/rt/base/types.h +0 -1
  95. mindspore/lib/plugin/ascend/ms_kernels_internal/asdops/include/asdops/utils/rt/module/module.h +3 -3
  96. mindspore/lib/plugin/ascend/ms_kernels_internal/asdops/include/asdops/utils/svector/svector.h +3 -2
  97. mindspore/lib/plugin/ascend/ms_kernels_internal/asdops/lib/libasdops.so +0 -0
  98. mindspore/lib/plugin/ascend/ms_kernels_internal/asdops/lib/libasdops_static.a +0 -0
  99. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/add/tiling/add_tiling.h +9 -9
  100. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/apply_rotary_pos_emb/apply_rotary_pos_emb_impl.h +2 -6
  101. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/apply_rotary_pos_emb/kernel/apply_rotary_pos_emb.h +2 -2
  102. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/apply_rotary_pos_emb/kernel/apply_rotary_pos_emb_base.h +460 -0
  103. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/apply_rotary_pos_emb/kernel/apply_rotary_pos_emb_bf16.h +217 -0
  104. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/apply_rotary_pos_emb/kernel/apply_rotary_pos_emb_fp16.h +116 -0
  105. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/apply_rotary_pos_emb/kernel/apply_rotary_pos_emb_tiling.h +16 -24
  106. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/apply_rotary_pos_emb/kernel/apply_rotary_pos_emb_value.h +27 -0
  107. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/asdop/asd_op_impl.h +0 -4
  108. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/{attention/FlashAttentionScore_impl.h → flash_attention_score/flash_attention_score_impl.h} +2 -1
  109. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/{attention/bs_attention_tiling.h → flash_attention_score/flash_attention_score_tiling.h} +15 -19
  110. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/gelu/tiling/gelu_tiling.h +7 -9
  111. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/lccl/lccl_wrapper.h +58 -0
  112. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/matmul/matmul_impl.h +19 -8
  113. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/{matmul → matmul_common}/pp_matmul_common_tiling.h +18 -8
  114. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/{matmul → matmul_common}/pp_matmul_info.h +7 -4
  115. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/{matmul → matmul_common}/tiling_data.h +44 -6
  116. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/matmul_common/tiling_utils.h +65 -0
  117. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/matmul_stridedslice/matmul_stridedslice_fusion_impl.h +10 -6
  118. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/op_param.h +4 -1
  119. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/paged_attention/kernel/paged_attention_mix_hwsync.h +41 -0
  120. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/{attention/PagedAttention_impl.h → paged_attention/paged_attention_impl.h} +1 -1
  121. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/paged_attention/paged_attention_tiling.h +63 -0
  122. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/param/add_param.h +2 -2
  123. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/{attention_param.h → param/attention_param.h} +11 -2
  124. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/param/matmul_ext_param.h +37 -0
  125. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/param/sub_param.h +45 -0
  126. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/reshape_and_cache/reshape_and_cache_tiling.h +1 -2
  127. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/rms_norm/kernel/rms_norm.h +23 -0
  128. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/rms_norm/kernel/rms_norm_base.h +175 -0
  129. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/rms_norm/kernel/rms_norm_normal.h +276 -0
  130. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/rms_norm/kernel/rms_norm_split_d.h +280 -0
  131. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/rms_norm/kernel/tiling_data.h +35 -0
  132. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/rms_norm/rms_norm_impl.h +45 -0
  133. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/sub/kernel/sub_kernel.h +20 -0
  134. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/sub/sub_impl.h +47 -0
  135. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/sub/sub_tiling.h +25 -0
  136. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/tune_repo/matmul_table.h +323 -23
  137. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/types.h +15 -4
  138. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/utils/log/log_tiling.h +8 -0
  139. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libAdd_impl.so +0 -0
  140. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libSub_impl.so +0 -0
  141. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libadd_layernorm_impl.so +0 -0
  142. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libadd_rms_norm_impl.so +0 -0
  143. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libapply_rotary_pos_emb_impl.so +0 -0
  144. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libcast_impl.so +0 -0
  145. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libgelu_impl.so +0 -0
  146. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libmatmul_impl.so +0 -0
  147. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libmatmul_stridedslice_fusion_impl.so +0 -0
  148. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libms_kernels_internal.so +0 -0
  149. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libnot_equal_impl.so +0 -0
  150. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libreshape_and_cache_impl.so +0 -0
  151. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/librms_norm_impl.so +0 -0
  152. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/flash_attention_score_bf16_bnsd_full_mix.o +0 -0
  153. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/flash_attention_score_bf16_bnsd_tri_mix.o +0 -0
  154. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/flash_attention_score_bf16_bsh_full_mix.o +0 -0
  155. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/flash_attention_score_bf16_bsh_tri_mix.o +0 -0
  156. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/flash_attention_score_fp16_bnsd_full_mix.o +0 -0
  157. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/flash_attention_score_fp16_bnsd_tri_mix.o +0 -0
  158. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/flash_attention_score_fp16_bsh_full_mix.o +0 -0
  159. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/flash_attention_score_fp16_bsh_tri_mix.o +0 -0
  160. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/paged_attention_bf16_bnsd_full_mix.o +0 -0
  161. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/paged_attention_bf16_bsh_full_mix.o +0 -0
  162. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/paged_attention_fp16_bnsd_full_mix.o +0 -0
  163. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/paged_attention_fp16_bsh_full_mix.o +0 -0
  164. mindspore/lib/plugin/ascend/ms_kernels_internal/lccl/include/lcal.h +22 -0
  165. mindspore/lib/plugin/ascend/ms_kernels_internal/lccl/include/lcal_comm.h +70 -0
  166. mindspore/lib/plugin/ascend/ms_kernels_internal/lccl/include/lcal_types.h +103 -0
  167. mindspore/lib/plugin/ascend/ms_kernels_internal/lccl/include/lccl.h +47 -0
  168. mindspore/lib/plugin/ascend/ms_kernels_internal/lccl/include/lccl_wrapper.h +58 -0
  169. mindspore/lib/plugin/ascend/ms_kernels_internal/lccl/include/lcoc.h +154 -0
  170. mindspore/lib/plugin/ascend/ms_kernels_internal/lccl/lib/liblcal.so +0 -0
  171. mindspore/lib/plugin/ascend/ms_kernels_internal/lccl/lib/liblccl_wrapper.so +0 -0
  172. mindspore/lib/plugin/libmindspore_ascend.so.2 +0 -0
  173. mindspore/log.py +2 -2
  174. mindspore/mint/__init__.py +457 -0
  175. mindspore/mint/nn/__init__.py +430 -0
  176. mindspore/mint/nn/functional.py +424 -0
  177. mindspore/mint/optim/__init__.py +24 -0
  178. mindspore/mint/optim/adamw.py +186 -0
  179. mindspore/multiprocessing/__init__.py +4 -0
  180. mindspore/nn/__init__.py +3 -0
  181. mindspore/nn/cell.py +51 -47
  182. mindspore/nn/extend/__init__.py +29 -0
  183. mindspore/nn/extend/basic.py +140 -0
  184. mindspore/nn/extend/embedding.py +143 -0
  185. mindspore/nn/extend/layer/__init__.py +27 -0
  186. mindspore/nn/extend/layer/normalization.py +107 -0
  187. mindspore/nn/extend/pooling.py +117 -0
  188. mindspore/nn/generator.py +297 -0
  189. mindspore/nn/layer/basic.py +109 -1
  190. mindspore/nn/layer/container.py +2 -2
  191. mindspore/nn/layer/conv.py +6 -6
  192. mindspore/nn/layer/embedding.py +1 -1
  193. mindspore/nn/layer/normalization.py +21 -43
  194. mindspore/nn/layer/padding.py +4 -0
  195. mindspore/nn/optim/ada_grad.py +2 -2
  196. mindspore/nn/optim/adadelta.py +1 -1
  197. mindspore/nn/optim/adafactor.py +1 -1
  198. mindspore/nn/optim/adam.py +7 -7
  199. mindspore/nn/optim/adamax.py +2 -2
  200. mindspore/nn/optim/adasum.py +2 -2
  201. mindspore/nn/optim/asgd.py +2 -2
  202. mindspore/nn/optim/ftrl.py +1 -1
  203. mindspore/nn/optim/lamb.py +3 -3
  204. mindspore/nn/optim/lars.py +1 -1
  205. mindspore/nn/optim/lazyadam.py +2 -2
  206. mindspore/nn/optim/momentum.py +2 -2
  207. mindspore/nn/optim/optimizer.py +2 -2
  208. mindspore/nn/optim/proximal_ada_grad.py +2 -2
  209. mindspore/nn/optim/rmsprop.py +2 -2
  210. mindspore/nn/optim/rprop.py +2 -2
  211. mindspore/nn/optim/sgd.py +2 -2
  212. mindspore/nn/optim/thor.py +2 -2
  213. mindspore/nn/wrap/cell_wrapper.py +9 -9
  214. mindspore/nn/wrap/grad_reducer.py +5 -5
  215. mindspore/ops/_grad_experimental/grad_comm_ops.py +4 -2
  216. mindspore/ops/_vmap/vmap_grad_nn_ops.py +41 -2
  217. mindspore/ops/_vmap/vmap_math_ops.py +27 -8
  218. mindspore/ops/_vmap/vmap_nn_ops.py +66 -8
  219. mindspore/ops/auto_generate/cpp_create_prim_instance_helper.py +73 -1
  220. mindspore/ops/auto_generate/gen_arg_dtype_cast.py +12 -3
  221. mindspore/ops/auto_generate/gen_arg_handler.py +24 -0
  222. mindspore/ops/auto_generate/gen_extend_func.py +274 -0
  223. mindspore/ops/auto_generate/gen_ops_def.py +889 -22
  224. mindspore/ops/auto_generate/gen_ops_prim.py +3541 -253
  225. mindspore/ops/auto_generate/pyboost_inner_prim.py +282 -0
  226. mindspore/ops/composite/multitype_ops/_compile_utils.py +2 -1
  227. mindspore/ops/composite/multitype_ops/_constexpr_utils.py +9 -0
  228. mindspore/ops/extend/__init__.py +9 -1
  229. mindspore/ops/extend/array_func.py +134 -27
  230. mindspore/ops/extend/math_func.py +3 -3
  231. mindspore/ops/extend/nn_func.py +363 -2
  232. mindspore/ops/function/__init__.py +19 -2
  233. mindspore/ops/function/array_func.py +463 -439
  234. mindspore/ops/function/clip_func.py +7 -18
  235. mindspore/ops/function/grad/grad_func.py +5 -5
  236. mindspore/ops/function/linalg_func.py +4 -4
  237. mindspore/ops/function/math_func.py +260 -243
  238. mindspore/ops/function/nn_func.py +825 -62
  239. mindspore/ops/function/random_func.py +73 -4
  240. mindspore/ops/function/sparse_unary_func.py +1 -1
  241. mindspore/ops/function/vmap_func.py +1 -1
  242. mindspore/ops/functional.py +2 -2
  243. mindspore/ops/op_info_register.py +1 -31
  244. mindspore/ops/operations/__init__.py +2 -3
  245. mindspore/ops/operations/_grad_ops.py +2 -107
  246. mindspore/ops/operations/_inner_ops.py +5 -5
  247. mindspore/ops/operations/_sequence_ops.py +2 -2
  248. mindspore/ops/operations/array_ops.py +11 -233
  249. mindspore/ops/operations/comm_ops.py +32 -32
  250. mindspore/ops/operations/custom_ops.py +7 -89
  251. mindspore/ops/operations/manually_defined/ops_def.py +329 -4
  252. mindspore/ops/operations/math_ops.py +13 -163
  253. mindspore/ops/operations/nn_ops.py +9 -316
  254. mindspore/ops/operations/random_ops.py +1 -1
  255. mindspore/ops/operations/sparse_ops.py +3 -3
  256. mindspore/ops/primitive.py +2 -2
  257. mindspore/ops_generate/arg_dtype_cast.py +12 -3
  258. mindspore/ops_generate/arg_handler.py +24 -0
  259. mindspore/ops_generate/gen_ops_inner_prim.py +2 -0
  260. mindspore/ops_generate/gen_pyboost_func.py +13 -6
  261. mindspore/ops_generate/pyboost_utils.py +2 -17
  262. mindspore/parallel/__init__.py +3 -2
  263. mindspore/parallel/_auto_parallel_context.py +106 -1
  264. mindspore/parallel/_parallel_serialization.py +34 -2
  265. mindspore/parallel/_utils.py +16 -0
  266. mindspore/parallel/algo_parameter_config.py +4 -4
  267. mindspore/parallel/checkpoint_transform.py +249 -77
  268. mindspore/parallel/cluster/process_entity/_api.py +1 -1
  269. mindspore/parallel/parameter_broadcast.py +1 -1
  270. mindspore/parallel/shard.py +1 -1
  271. mindspore/profiler/parser/ascend_analysis/fwk_cann_parser.py +1 -0
  272. mindspore/profiler/parser/ascend_analysis/profiler_info_parser.py +17 -5
  273. mindspore/profiler/parser/ascend_msprof_exporter.py +3 -3
  274. mindspore/profiler/parser/ascend_msprof_generator.py +10 -3
  275. mindspore/profiler/parser/ascend_op_generator.py +26 -9
  276. mindspore/profiler/parser/ascend_timeline_generator.py +7 -4
  277. mindspore/profiler/parser/profiler_info.py +11 -1
  278. mindspore/profiler/profiling.py +13 -5
  279. mindspore/rewrite/api/node.py +12 -12
  280. mindspore/rewrite/api/symbol_tree.py +11 -11
  281. mindspore/run_check/_check_version.py +1 -1
  282. mindspore/safeguard/rewrite_obfuscation.py +2 -2
  283. mindspore/train/amp.py +4 -4
  284. mindspore/train/anf_ir_pb2.py +8 -2
  285. mindspore/train/callback/_backup_and_restore.py +2 -2
  286. mindspore/train/callback/_callback.py +4 -4
  287. mindspore/train/callback/_checkpoint.py +2 -2
  288. mindspore/train/callback/_early_stop.py +2 -2
  289. mindspore/train/callback/_landscape.py +4 -4
  290. mindspore/train/callback/_loss_monitor.py +2 -2
  291. mindspore/train/callback/_on_request_exit.py +2 -2
  292. mindspore/train/callback/_reduce_lr_on_plateau.py +2 -2
  293. mindspore/train/callback/_summary_collector.py +2 -2
  294. mindspore/train/callback/_time_monitor.py +2 -2
  295. mindspore/train/dataset_helper.py +8 -3
  296. mindspore/train/loss_scale_manager.py +2 -2
  297. mindspore/train/metrics/metric.py +3 -3
  298. mindspore/train/mind_ir_pb2.py +22 -17
  299. mindspore/train/model.py +15 -15
  300. mindspore/train/serialization.py +18 -18
  301. mindspore/train/summary/summary_record.py +7 -7
  302. mindspore/train/train_thor/convert_utils.py +3 -3
  303. mindspore/version.py +1 -1
  304. {mindspore-2.3.0rc1.dist-info → mindspore-2.3.0rc2.dist-info}/METADATA +1 -1
  305. {mindspore-2.3.0rc1.dist-info → mindspore-2.3.0rc2.dist-info}/RECORD +309 -262
  306. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/matmul_stridedslice/tiling_data.h +0 -59
  307. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/FlashAttentionScore_bf16_BNSD_mix.o +0 -0
  308. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/FlashAttentionScore_bf16_BSH_mix.o +0 -0
  309. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/FlashAttentionScore_fp16_BNSD_mix.o +0 -0
  310. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/FlashAttentionScore_fp16_BSH_mix.o +0 -0
  311. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/PagedAttention_bf16_BNSD_mix.o +0 -0
  312. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/PagedAttention_bf16_BSH_mix.o +0 -0
  313. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/PagedAttention_fp16_BNSD_mix.o +0 -0
  314. mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/PagedAttention_fp16_BSH_mix.o +0 -0
  315. /mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/{attention/bs_attention_mix_hwsync.h → flash_attention_score/kernel/flash_attention_score_mix_hwsync.h} +0 -0
  316. {mindspore-2.3.0rc1.dist-info → mindspore-2.3.0rc2.dist-info}/WHEEL +0 -0
  317. {mindspore-2.3.0rc1.dist-info → mindspore-2.3.0rc2.dist-info}/entry_points.txt +0 -0
  318. {mindspore-2.3.0rc1.dist-info → mindspore-2.3.0rc2.dist-info}/top_level.txt +0 -0
@@ -1,4 +1,4 @@
1
- # Copyright 2023 Huawei Technologies Co., Ltd
1
+ # Copyright 2023-2024 Huawei Technologies Co., Ltd
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@
15
15
 
16
16
  """Defines nn operators with functional form."""
17
17
  from __future__ import absolute_import
18
- from math import pi, log
18
+ from math import pi, log, floor
19
19
 
20
20
  from mindspore import context
21
21
  from mindspore import log as logger
@@ -29,6 +29,7 @@ import mindspore.common.dtype as mstype
29
29
  from mindspore.ops.function.math_func import logsumexp
30
30
  from mindspore.ops.function.random_func import _get_seed, _set_prim_op_user_data
31
31
  from mindspore.common.tensor import Tensor
32
+ from mindspore.common.parameter import Parameter
32
33
  from mindspore._c_expression import Tensor as Tensor_
33
34
  from mindspore.ops._primitive_cache import _get_cache_prim
34
35
  from mindspore import _checkparam as validator
@@ -38,9 +39,16 @@ from mindspore.ops.operations.nn_ops import FractionalMaxPoolWithFixedKsize, Fra
38
39
  from mindspore.ops.operations.nn_ops import PadV3
39
40
  from mindspore.ops.operations.nn_ops import ChannelShuffle
40
41
  from mindspore.ops.operations.nn_ops import TripletMarginLoss
42
+ from mindspore.ops.operations.nn_ops import LayerNormExt
41
43
  from mindspore.ops.operations._sequence_ops import TupleToTensor, TensorToTuple, ListToTensor
42
44
  from mindspore.common.api import _function_forbid_reuse
43
- from mindspore.ops.auto_generate import log_softmax, prelu, celu, relu, fast_gelu, silu, elu, sigmoid, relu6
45
+ from mindspore.ops.auto_generate import log_softmax, dense, prelu, celu, relu, fast_gelu, silu, elu, sigmoid, relu6
46
+ from mindspore.ops.auto_generate.gen_ops_prim import GroupNorm
47
+ from mindspore.ops.auto_generate import (reflection_pad_1d_op, reflection_pad_2d_op, reflection_pad_3d_op,
48
+ replication_pad_1d_op, replication_pad_2d_op, replication_pad_3d_op,
49
+ constant_pad_nd_op, dropout_ext_op)
50
+ from mindspore.ops.auto_generate.gen_ops_prim import embedding_op, Convolution
51
+ from mindspore.nn.generator import default_generator
44
52
 
45
53
  abs_ = P.Abs()
46
54
  add_ = P.Add()
@@ -507,7 +515,75 @@ def avg_pool2d(input_x, kernel_size=1, stride=1, padding=0, ceil_mode=False, cou
507
515
  return input_x
508
516
 
509
517
 
510
- @constexpr
518
+ def avg_pool2d_ext(input, kernel_size, stride=None, padding=0, ceil_mode=False, count_include_pad=True,
519
+ divisor_override=None):
520
+ r"""
521
+ Applies a 2D average pooling over an input Tensor which can be regarded as a composition of 2D input planes.
522
+ Typically the input is of shape :math:`(N, C, H_{in}, W_{in})`, outputs regional average in the
523
+ :math:`(H_{in}, W_{in})`-dimension. Given kernel size :math:`(k_{H}, k_{W})` and `stride` , the operation
524
+ is as follows.
525
+
526
+ .. math::
527
+ \text{output}(N_i, C_j, h, w) = \frac{1}{k_{H} * k_{W}} \sum_{m=0}^{k_{H}-1} \sum_{n=0}^{k_{W}-1}
528
+ \text{input}(N_i, C_j, stride[0] \times h + m, stride[1] \times w + n)
529
+
530
+ Args:
531
+ input (Tensor): Tensor of shape :math:`(N, C, H_{in}, W_{in})`.
532
+ kernel_size (Union[int, tuple[int], list[int]]): The size of kernel used to take the average value.
533
+ Can be a single number or a tuple (kH, kW).
534
+ stride (Union[int, tuple[int], list[int]]): The distance of kernel moving. Can be a single number or
535
+ a tuple (sH, sW). Default value is `kernel_size` .
536
+ padding (Union(int, tuple[int], list[int])): Implicit zero padding to be added on both sides.
537
+ Can be a single number or a tuple (padH, padW). Default: 0.
538
+ ceil_mode (bool): If True, apply ceil instead of floor to compute the output shape.
539
+ Default: ``False``.
540
+ count_include_pad (bool): If True, include the zero-padding in the averaging calculation.
541
+ Default: ``True`` .
542
+ divisor_override (int): If specified, it will be used as divisor in the averaging calculation,
543
+ otherwise `kernel_size` will be used. Default: ``None``.
544
+
545
+ Returns:
546
+ Tensor, with shape :math:`(N, C, H_{out}, W_{out})`.
547
+
548
+ .. math::
549
+
550
+ H_{out} = \frac{H_{in} + 2 \times padding[0] - kernel_size[0]}{stride[0]} + 1
551
+ W_{out} = \frac{W_{in} + 2 \times padding[1] - kernel_size[1]}{stride[1]} + 1
552
+
553
+ Raises:
554
+ TypeError: If `input` is not a Tensor.
555
+ TypeError: If `kernel_size` or `stride` is neither int nor tuple.
556
+ TypeError: If `ceil_mode` or `count_include_pad` is not a bool.
557
+ TypeError: If `divisor_override` is not an int.
558
+ ValueError: If length of shape of `input` is not equal to `4` or `3`.
559
+ ValueError: If `kernel_size` or `stride` is less than 1.
560
+ ValueError: If `kernel_size` or `stride` is a tuple whose length is not equal to `2` or `1`.
561
+ ValueError: If `padding` is neither a int nor a tuple whose length is equal to `2` or `1`.
562
+ ValueError: If value of `padding` is less than `0`.
563
+
564
+ Supported Platforms:
565
+ ``Ascend``
566
+
567
+ Examples:
568
+ >>> import mindspore
569
+ >>> import numpy as np
570
+ >>> from mindspore import Tensor, mint
571
+ >>> x = Tensor(np.arange(1 * 3 * 3 * 4).reshape(1, 3, 3, 4), mindspore.float32)
572
+ >>> output = mint.avg_pool2d(x, kernel_size=2, stride=1)
573
+ >>> print(output)
574
+ [[[[ 2.5 3.5 4.5]
575
+ [ 6.5 7.5 8.5]]
576
+ [[14.5 15.5 16.5]
577
+ [18.5 19.5 20.5]]
578
+ [[26.5 27.5 28.5]
579
+ [30.5 31.5 32.5]]]]
580
+ """
581
+ if stride is None:
582
+ stride = kernel_size
583
+ return _get_cache_prim(ops.auto_generate.AvgPool2D)()(input, kernel_size, stride, padding,
584
+ ceil_mode, count_include_pad, divisor_override)
585
+
586
+
511
587
  def _check_avg_pool3d_padding(padding):
512
588
  """Check the padding value in avg_pool3d op."""
513
589
  if isinstance(padding, int):
@@ -1288,6 +1364,50 @@ def dropout(input, p=0.5, training=True, seed=None):
1288
1364
  return out
1289
1365
 
1290
1366
 
1367
+ @_function_forbid_reuse
1368
+ def dropout_ext(input, p=0.5, training=True, seed=None):
1369
+ r"""
1370
+ During training, randomly zeroes some of the elements of the input tensor
1371
+ with probability `p` from a Bernoulli distribution. It plays the role of reducing neuron correlation and
1372
+ avoid overfitting. And the return will be multiplied by :math:`\frac{1}{1-p}` during training.
1373
+ During the reasoning, this operation returns the same Tensor as the `x`.
1374
+
1375
+ Args:
1376
+ input (Tensor): The input Tensor of shape :math:`(*, N)`, with data type of float16, float32 or float64.
1377
+ p (float, optional): The dropping rate, between 0 and 1, e.g. p = 0.1,
1378
+ means dropping out 10% of input units. Default: ``0.5`` .
1379
+ training (bool): Apply dropout_ext if is True. Default: ``True``.
1380
+ seed (int, optional): Seed is used as entropy source for Random number engines generating pseudo-random numbers.
1381
+ Default: ``None`` , which will be treated as ``0`` .
1382
+
1383
+ Returns:
1384
+ - **output** (Tensor) - Zeroed tensor, with the same shape and data type as `input`.
1385
+
1386
+ Raises:
1387
+ TypeError: If `p` is not a float.
1388
+ TypeError: If dtype of `input` is not float16, float32 or float64.
1389
+ TypeError: If `input` is not a Tensor.
1390
+
1391
+ Supported Platforms:
1392
+ ``Ascend``
1393
+
1394
+ Examples:
1395
+ >>> import mindspore
1396
+ >>> from mindspore import Tensor, ops
1397
+ >>> input = Tensor(((20, 16), (50, 50)), mindspore.float32)
1398
+ >>> output = ops.dropout_ext(input, p=0.5)
1399
+ >>> print(output.shape)
1400
+ (2, 2)
1401
+ """
1402
+ check_bool_const(training, "training", "dropout_ext")
1403
+ if training is False:
1404
+ return input
1405
+ generator = default_generator()
1406
+ seed, offset = generator(1)
1407
+ out, _ = dropout_ext_op(input, p, seed, offset)
1408
+ return out
1409
+
1410
+
1291
1411
  def dropout1d(input, p=0.5, training=True):
1292
1412
  r"""
1293
1413
  During training, randomly zeroes some channels of the input tensor with probability `p`
@@ -2082,8 +2202,15 @@ def _is_dim_unknown(shape):
2082
2202
 
2083
2203
  @_primexpr
2084
2204
  def _interploate_make_tuple(rank, value):
2205
+ """
2206
+ make tuple in dynamic scenarios
2207
+ """
2085
2208
  s = tuple_to_tensor_((rank,), mstype.int32)
2086
- v = Tensor(value)
2209
+ v = None
2210
+ if isinstance(value, int):
2211
+ v = F.scalar_to_tensor(value, mstype.int64)
2212
+ else:
2213
+ v = F.scalar_to_tensor(value, mstype.float32)
2087
2214
  t = fillv2_(s, v)
2088
2215
  out = tensor_to_tuple_(t)
2089
2216
  return out
@@ -2091,6 +2218,9 @@ def _interploate_make_tuple(rank, value):
2091
2218
 
2092
2219
  @_primexpr
2093
2220
  def _interpolate_scale_factor_convert_size(shape, scale_factor):
2221
+ """
2222
+ convert scale_factor to size
2223
+ """
2094
2224
  x = tuple_to_tensor_(shape[2:], mstype.int64)
2095
2225
  y = tuple_to_tensor_(scale_factor, mstype.float32)
2096
2226
  t = x * y
@@ -2100,6 +2230,9 @@ def _interpolate_scale_factor_convert_size(shape, scale_factor):
2100
2230
 
2101
2231
 
2102
2232
  def _interpolate_size_check_with_rank(size, input_rank):
2233
+ """
2234
+ size rank check
2235
+ """
2103
2236
  if len(size) != input_rank - 2:
2104
2237
  raise ValueError(
2105
2238
  f"For 'interpolate', 'input' and 'size' must have the same spatial dimensions, "
@@ -2107,6 +2240,9 @@ def _interpolate_size_check_with_rank(size, input_rank):
2107
2240
 
2108
2241
 
2109
2242
  def _interpolate_scale_factor_check_with_rank(scale_factor, input_rank):
2243
+ """
2244
+ scale_factor rank check
2245
+ """
2110
2246
  if len(scale_factor) != input_rank - 2:
2111
2247
  raise ValueError(
2112
2248
  f"For 'interpolate', 'input' and 'scale_factor' must have the same spatial dimensions, "
@@ -2115,6 +2251,9 @@ def _interpolate_scale_factor_check_with_rank(scale_factor, input_rank):
2115
2251
 
2116
2252
 
2117
2253
  def _interpolate_mode_check(mode, supported_dict):
2254
+ """
2255
+ mode check
2256
+ """
2118
2257
  if isinstance(mode, list) or mode not in supported_dict:
2119
2258
  raise ValueError(
2120
2259
  f"For 'interpolate', 'mode' must be in '{list(supported_dict)}', but got {mode}"
@@ -2122,6 +2261,9 @@ def _interpolate_mode_check(mode, supported_dict):
2122
2261
 
2123
2262
 
2124
2263
  def _interpolate_rank_check(input_rank, mode, supported_dict):
2264
+ """
2265
+ rank check
2266
+ """
2125
2267
  if input_rank not in supported_dict.get(mode):
2126
2268
  raise ValueError(
2127
2269
  f"For 'interpolate', {mode} only support '{list(supported_dict.get(mode, {}))}'D, but got {input_rank}D"
@@ -2129,6 +2271,9 @@ def _interpolate_rank_check(input_rank, mode, supported_dict):
2129
2271
 
2130
2272
 
2131
2273
  def _interpolate_scale_factor_check(scale_factor, mode, rank, supported_dict):
2274
+ """
2275
+ scale_factor check
2276
+ """
2132
2277
  if scale_factor is not None and "scale_factor" not in supported_dict.get(
2133
2278
  mode, {}).get(rank):
2134
2279
  raise ValueError(
@@ -2137,6 +2282,9 @@ def _interpolate_scale_factor_check(scale_factor, mode, rank, supported_dict):
2137
2282
 
2138
2283
 
2139
2284
  def _interpolate_align_corners_mode_check(rank, mode, supported_dict):
2285
+ """
2286
+ align_corners check
2287
+ """
2140
2288
  if "align_corners" not in supported_dict.get(mode, {}).get(rank):
2141
2289
  raise ValueError(
2142
2290
  f"For 'interpolate', 'align_corners' option cannot currently be set with the "
@@ -2439,7 +2587,11 @@ def interpolate(input,
2439
2587
  raise ValueError(
2440
2588
  "For 'interpolate', it is incorrect to set 'recompute_scale_factor' to True"
2441
2589
  " after specifying an explicit 'size'.")
2442
- size = _interpolate_scale_factor_convert_size(shape, scale_factor)
2590
+ if F.isconstant(shape) and F.isconstant(scale_factor):
2591
+ size = tuple([floor(shape[i + 2] * scale_factor[i]) for i in
2592
+ range(min(len(shape) - 2), len(scale_factor))])
2593
+ else:
2594
+ size = _interpolate_scale_factor_convert_size(shape, scale_factor)
2443
2595
  scale_factor = None
2444
2596
  else:
2445
2597
  if dim_unknown is False:
@@ -2457,6 +2609,287 @@ def interpolate(input,
2457
2609
  return resize_func.get(mode)(input, size, align_corners, scale_factor)
2458
2610
 
2459
2611
 
2612
+ def _interploate_ext_make_tuple(input, value):
2613
+ """
2614
+ make tuple
2615
+ """
2616
+ if isinstance(value, (list, tuple)):
2617
+ return value
2618
+
2619
+ rank = F.rank(input) - 2
2620
+ out = None
2621
+ if F.isconstant(value) and F.isconstant(rank):
2622
+ out = tuple([value for _ in range(rank)])
2623
+ else:
2624
+ s = tuple_to_tensor_((rank,), mstype.int32)
2625
+ v = None
2626
+ if isinstance(value, int):
2627
+ v = F.scalar_to_tensor(value, mstype.int64)
2628
+ else:
2629
+ v = F.scalar_to_tensor(value, mstype.float32)
2630
+ t = fillv2_(s, v)
2631
+ out = tensor_to_tuple_(t)
2632
+ return out
2633
+
2634
+
2635
+ def _interpolate_ext_scale_factor_convert_size(input, scale_factor):
2636
+ """
2637
+ convert scale_factor to size
2638
+ """
2639
+ shape = F.shape(input)
2640
+ size = None
2641
+ if F.isconstant(shape) and F.isconstant(scale_factor):
2642
+ size = tuple([floor(shape[i + 2] * scale_factor[i]) for i in
2643
+ range(min(len(shape) - 2), len(scale_factor))])
2644
+ else:
2645
+ x = tuple_to_tensor_(shape[2:], mstype.int64)
2646
+ y = tuple_to_tensor_(scale_factor, mstype.float32)
2647
+ t = x * y
2648
+ t = ops.TruncateDiv()(t, Tensor(1))
2649
+ t = ops.cast(t, mstype.int64)
2650
+ size = tensor_to_tuple_(t)
2651
+ return size
2652
+
2653
+
2654
+ def interpolate_ext(input,
2655
+ size=None,
2656
+ scale_factor=None,
2657
+ mode="nearest",
2658
+ align_corners=None,
2659
+ recompute_scale_factor=None):
2660
+ r"""
2661
+ Samples the input Tensor to the given size or scale_factor by using one of the interpolate algorithms.
2662
+
2663
+ .. note::
2664
+ - In 'linear' mode, backpropagation does not support scenarios where `scale_factor` is not None
2665
+ and `align_corners` is False.
2666
+
2667
+ Args:
2668
+ input (Tensor): Tensor to be resized.
2669
+ Input tensor must be a 3-D, 4-D, or 5-D tensor with shape
2670
+ :math:`(N, C, [optional D], [optional H], W)` , with data type of float.
2671
+ size (Union[int, tuple[int], list[int]], optional): The target size.
2672
+ If size is a tuple or list, its length should be the same as the number of dimensions in input
2673
+ after removing the first two dimensions N, C.
2674
+ One and only one of size and scale_factor can be set to None. Default: ``None`` .
2675
+ scale_factor (Union[float, tuple[float], list[float]], optional): The scale factor of new size of the tensor.
2676
+ If scale_factor is a tuple or list, its length should be the same as the number of dimensions in input
2677
+ after removing the first two dimensions N, C.
2678
+ One and only one of size and scale_factor can be set to None. Default: ``None`` .
2679
+ mode (str): The sampling algorithm.
2680
+ One of 'nearest', 'linear' (3D only), 'bilinear' (4D only), 'trilinear' (5D only), 'bicubic' (4D only),
2681
+ 'area', 'nearest-exact'(matches Scikit-Image and PIL nearest neighbours interpolation algorithms and fixes
2682
+ knows issues with `nearest`, 3D and 4D). Default: ``"nearest"`` .
2683
+
2684
+ align_corners (bool): Whether to use corner alignment for coordinate mapping. Assuming a transformation is
2685
+ applied to the input Tensor along the x-axis, the specific calculation formula is as follows:
2686
+
2687
+ .. code-block::
2688
+
2689
+ ori_i = new_length != 1 ? new_i * (ori_length - 1) / (new_length - 1) : 0 # 'align_corners' = True
2690
+
2691
+ ori_i = new_length > 1 ? (new_i + 0.5) * ori_length / new_length - 0.5 : 0 # 'align_corners' = False
2692
+
2693
+ Among them, :math:`ori\_length` and :math:`new\_length` represent the length of the Tensor before and after
2694
+ transformation along the x-axis respectively; :math:`new\_i` represents the coordinate of the i-th element
2695
+ along the x-axis after transformation; :math:`ori\_i` represents
2696
+ the corresponding coordinate of the original
2697
+ data along the x-axis.
2698
+
2699
+ This is only valid for ``'linear'``, ``'bilinear'``, or ``'bicubic'`` modes. Default: ``False`` .
2700
+ recompute_scale_factor (bool, optional): Recalculate `scale_factor`.
2701
+ If True, the parameter `size` will be calculated using the value of the `scale_factor`,
2702
+ and finally scaled using the value of `size`.
2703
+ If False, the value of `size` or `scale_factor` will be used for direct interpolation. Default: ``None`` .
2704
+
2705
+ .. note::
2706
+ The 'nearest-exact' mode is the same as the nearest-neighbor interpolation algorithm used in
2707
+ scikit-image and PIL. The 'nearest' mode produces the same results as the INTER_NEAREST interpolation
2708
+ algorithm used in OpenCV.
2709
+
2710
+ Args Support List and Supported Platforms:
2711
+
2712
+ +---------------+-----------+---------------+--------------+----------------+
2713
+ | mode | input.dim | align_corners | scale_factor | device |
2714
+ +===============+===========+===============+==============+================+
2715
+ | nearest | 3 | \- | √ | Ascend,GPU,CPU |
2716
+ +---------------+-----------+---------------+--------------+----------------+
2717
+ | | 4 | \- | √ | Ascend,GPU,CPU |
2718
+ +---------------+-----------+---------------+--------------+----------------+
2719
+ | | 5 | \- | √ | Ascend,GPU,CPU |
2720
+ +---------------+-----------+---------------+--------------+----------------+
2721
+ | linear | 3 | √ | √ | Ascend,GPU,CPU |
2722
+ +---------------+-----------+---------------+--------------+----------------+
2723
+ | bilinear | 4 | √ | × | Ascend,GPU,CPU |
2724
+ +---------------+-----------+---------------+--------------+----------------+
2725
+ | bicubic | 4 | √ | × | Ascend,GPU,CPU |
2726
+ +---------------+-----------+---------------+--------------+----------------+
2727
+ | area | 3 | \- | √ | Ascend,GPU,CPU |
2728
+ +---------------+-----------+---------------+--------------+----------------+
2729
+ | | 4 | \- | √ | Ascend,GPU,CPU |
2730
+ +---------------+-----------+---------------+--------------+----------------+
2731
+ | | 5 | \- | √ | Ascend,GPU,CPU |
2732
+ +---------------+-----------+---------------+--------------+----------------+
2733
+ | nearest-exact | 3 | \- | × | Ascend,CPU |
2734
+ +---------------+-----------+---------------+--------------+----------------+
2735
+ | | 4 | \- | × | Ascend,CPU |
2736
+ +---------------+-----------+---------------+--------------+----------------+
2737
+ | trilinear | 5 | √ | √ | Ascend,GPU,CPU |
2738
+ +---------------+-----------+---------------+--------------+----------------+
2739
+
2740
+ - `-` indicates that there is no such parameter.
2741
+ - `×` indicates that this parameter is not currently supported.
2742
+ - `√` indicates that this parameter is supported.
2743
+
2744
+ Returns:
2745
+ Tensor, resized, whose dimensions and dtype are the same as `input`.
2746
+
2747
+ Raises:
2748
+ TypeError: `input` is not a Tensor.
2749
+ ValueError: Both `size` and `scale_factor` are not empty.
2750
+ ValueError: Both `size` and `scale_factor` are empty.
2751
+ ValueError: When `size` is a tuple or list, its length is not equal to `input.ndim - 2`.
2752
+ ValueError: When `scale_factor` is a tuple or list, its length is not equal to `input.ndim - 2`.
2753
+ ValueError: `mode` is not in the list of supported modes.
2754
+ ValueError: `input.ndim` is not in the list of supported dimensions for the corresponding mode.
2755
+ ValueError: `size` is not empty, `recompute_scale_factor` is not empty.
2756
+ ValueError: `scale_factor` is not in the corresponding list of supported values.
2757
+ ValueError: `align_corners` is not in the corresponding list of supported values.
2758
+
2759
+ Supported Platforms:
2760
+ ``Ascend`` ``GPU`` ``CPU``
2761
+
2762
+ Examples:
2763
+ >>> import mindspore
2764
+ >>> from mindspore import Tensor, mint
2765
+ >>> input = Tensor([[[1, 2, 3], [4, 5, 6]]], mindspore.float32)
2766
+ >>> output = mint.interpolate(input, size=(6,), mode='nearest')
2767
+ >>> print(output)
2768
+ [[[1. 1. 2. 2. 3. 3.]
2769
+ [4. 4. 5. 5. 6. 6.]]]
2770
+ """
2771
+ def run_nearest(x, size, align_corners=None, scale_factor=None):
2772
+ x_rank = F.rank(x)
2773
+ if x_rank == 3:
2774
+ x = _get_cache_prim(ops.auto_generate.UpsampleNearest1D)()(
2775
+ x, size, scale_factor)
2776
+ elif x_rank == 4:
2777
+ x = _get_cache_prim(ops.auto_generate.UpsampleNearest2D)()(
2778
+ x, size, scale_factor)
2779
+ else:
2780
+ x = _get_cache_prim(P.UpsampleNearest3D)()(x, size, scale_factor)
2781
+ return x
2782
+
2783
+ def run_linear(x, size, align_corners=None, scale_factor=None):
2784
+ out = _get_cache_prim(
2785
+ ops.auto_generate.UpsampleLinear1D)()(x, size, scale_factor, align_corners)
2786
+ return out
2787
+
2788
+ def run_bilinear(x, size, align_corners=None, scale_factor=None):
2789
+ out = _get_cache_prim(
2790
+ ops.auto_generate.UpsampleBilinear2D)()(x, size, scale_factor, align_corners)
2791
+ return out
2792
+
2793
+ def run_trilinear(x, size, align_corners=None, scale_factor=None):
2794
+ resize = _get_cache_prim(P.nn_ops.UpsampleTrilinear3D)(align_corners)
2795
+ return resize(x, size, scale_factor)
2796
+
2797
+ def run_bicubic(x, size, align_corners=None, scale_factor=None):
2798
+ resize = _get_cache_prim(P.image_ops.ResizeBicubic)(
2799
+ align_corners=align_corners, half_pixel_centers=not align_corners)
2800
+ x = resize(x, size)
2801
+ return x
2802
+
2803
+ def run_area(x, size, align_corners=None, scale_factor=None):
2804
+ x_rank = F.rank(x)
2805
+ if x_rank == 3:
2806
+ x = F.adaptive_avg_pool1d(x, size[0])
2807
+ elif x_rank == 4:
2808
+ x = F.adaptive_avg_pool2d(x, tuple(size))
2809
+ else:
2810
+ x = F.adaptive_avg_pool3d(x, tuple(size))
2811
+ return x
2812
+
2813
+ def run_nearest_exact(x, size, align_corners=None, scale_factor=None):
2814
+ x_rank = F.rank(x)
2815
+ if x_rank == 3:
2816
+ size = size[:1] + (1,)
2817
+ # For impl of nearest 3D use 4D.
2818
+ x = x.unsqueeze(-1)
2819
+ resize = _get_cache_prim(P.ResizeNearestNeighborV2)(
2820
+ align_corners=False,
2821
+ half_pixel_centers=True)
2822
+ x = resize(x, size)
2823
+ x = _get_cache_prim(P.Squeeze)(-1)(x)
2824
+ if x_rank == 4:
2825
+ resize = _get_cache_prim(P.ResizeNearestNeighborV2)(
2826
+ align_corners=False,
2827
+ half_pixel_centers=True)
2828
+ x = resize(x, size)
2829
+ return x
2830
+
2831
+
2832
+ resize_funcs = {
2833
+ "nearest": run_nearest,
2834
+ "linear": run_linear,
2835
+ "bilinear": run_bilinear,
2836
+ "bicubic": run_bicubic,
2837
+ "trilinear": run_trilinear,
2838
+ "area": run_area,
2839
+ "nearest-exact": run_nearest_exact,
2840
+ }
2841
+
2842
+ # mode check
2843
+ if mode not in resize_funcs:
2844
+ raise ValueError(
2845
+ f"For 'interpolate', 'mode' must be in '{list(resize_funcs)}', but got {mode}"
2846
+ )
2847
+ if mode in ("nearest", "area", "nearest-exact"):
2848
+ if align_corners is not None:
2849
+ raise ValueError("align_corners option can only be set with the "
2850
+ "interpolating modes: linear | bilinear | bicubic | trilinear"
2851
+ )
2852
+ else:
2853
+ if align_corners is None:
2854
+ align_corners = False
2855
+
2856
+ # check for size and scale_factor
2857
+ if size is not None and scale_factor is not None:
2858
+ raise ValueError(
2859
+ "For 'interpolate', 'size' and 'scale_factor' cannot be set simultaneously"
2860
+ )
2861
+ if size is not None:
2862
+ size = _interploate_ext_make_tuple(input, size)
2863
+ elif scale_factor is not None:
2864
+ scale_factor = _interploate_ext_make_tuple(input, scale_factor)
2865
+ else:
2866
+ raise ValueError(
2867
+ "For 'interpolate', 'size' and 'scale_factor' cannot be both empty"
2868
+ )
2869
+
2870
+ # "area" mode always requires an explicit size rather than scale factor.
2871
+ if mode == "area" and size is None:
2872
+ recompute_scale_factor = True
2873
+
2874
+ # recompute_scale_factor
2875
+ if recompute_scale_factor is not None and recompute_scale_factor:
2876
+ if size is not None:
2877
+ raise ValueError(
2878
+ "For 'interpolate', it is incorrect to set 'recompute_scale_factor' to True"
2879
+ " after specifying an explicit 'size'.")
2880
+ size = _interpolate_ext_scale_factor_convert_size(input, scale_factor)
2881
+ scale_factor = None
2882
+
2883
+ # scale_factor
2884
+ if mode in ("bilinear", "bicubic", "nearest-exact"):
2885
+ if scale_factor is not None:
2886
+ raise ValueError("scale_factor option can only be set with the "
2887
+ "interpolating modes: nearest | linear | area | trilinear"
2888
+ )
2889
+
2890
+ return resize_funcs.get(mode)(input, size, align_corners, scale_factor)
2891
+
2892
+
2460
2893
  def upsample(input, size=None, scale_factor=None, mode="nearest", align_corners=None, recompute_scale_factor=None):
2461
2894
  r"""
2462
2895
  Alias for :func:`mindspore.ops.interpolate` .
@@ -2762,6 +3195,51 @@ def softplus(input, beta=1, threshold=20): # pylint:disable=redefined-outer-name
2762
3195
  return ops.select(input * beta > threshold, input, op_output)
2763
3196
 
2764
3197
 
3198
+ def softplus_ext(input, beta=1, threshold=20): # pylint:disable=redefined-outer-name
3199
+ r"""
3200
+ Applies softplus function to `input` element-wise.
3201
+
3202
+ The softplus function is shown as follows, x is the element of `input` :
3203
+
3204
+ .. math::
3205
+
3206
+ \text{output} = \frac{1}{beta}\log(1 + \exp(\text{beta * x}))
3207
+
3208
+ When :math:`input * beta > threshold`, the implementation converts to the linear function
3209
+ to ensure numerical stability.
3210
+
3211
+ Args:
3212
+ input (Tensor) - Tensor of any dimension.
3213
+ Supported dtypes:
3214
+
3215
+ - Ascend: float16, float32, bfloat16
3216
+
3217
+ beta (number, optional) - The :math:`\beta` value in softplus function. Default: ``1`` .
3218
+ threshold (number, optional) - When :math:`input * beta > threshold`, converting softplus to a linear function.
3219
+ Default: ``20`` .
3220
+
3221
+ Returns:
3222
+ Tensor, with the same type and shape as the `input` .
3223
+
3224
+ Raises:
3225
+ TypeError: If `input` is not a Tensor.
3226
+ TypeError: If the dtype of `input` is not float16, float32, bfloat16.
3227
+
3228
+ Supported Platforms:
3229
+ ``Ascend``
3230
+
3231
+ Examples:
3232
+ >>> import mindspore
3233
+ >>> import numpy as np
3234
+ >>> from mindspore import Tensor, mint
3235
+ >>> input = Tensor(np.array([0.1, 0.2, 30, 25]), mindspore.float32)
3236
+ >>> output = mint.softplus(input)
3237
+ >>> print(output)
3238
+ [0.74439657 0.7981388 30. 25.]
3239
+ """
3240
+ return _get_cache_prim(ops.auto_generate.SoftplusExt)()(input, beta, threshold)
3241
+
3242
+
2765
3243
  def selu(input_x):
2766
3244
  r"""
2767
3245
  Activation function SeLU (Scaled exponential Linear Unit).
@@ -2855,59 +3333,6 @@ def logsigmoid(x):
2855
3333
  return ret
2856
3334
 
2857
3335
 
2858
- def dense(input, weight, bias=None):
2859
- r"""
2860
- Applies the dense connected operation to the `input`. The dense function is defined as:
2861
-
2862
- .. math::
2863
- output = input * weight^{T} + bias
2864
-
2865
- .. warning::
2866
- This is an experimental API that is subject to change or deletion.
2867
-
2868
- Args:
2869
- input (Tensor): Input Tensor of shape :math:`(*, in\_channels)`,
2870
- where :math:`*` means any number of additional dimensions.
2871
- weight (Tensor): The weight applied to the input.
2872
- The shape is :math:`(out\_channels, in\_channels)` or :math:`(in\_channels)`.
2873
- bias (Tensor, optional): Additive biases to the output.
2874
- The shape is :math:`(out\_channels)` or :math:`()`. Defaults: ``None``, the `bias` is 0.
2875
-
2876
- Returns:
2877
- Output whose shape is determined by the shape of the input and the weight.
2878
-
2879
- Raises:
2880
- TypeError: If `input` is not Tensor.
2881
- TypeError: If `weight` is not Tensor.
2882
- TypeError: If `bias` is not Tensor.
2883
-
2884
- Supported Platforms:
2885
- ``Ascend`` ``GPU`` ``CPU``
2886
-
2887
- Examples:
2888
- >>> import numpy as np
2889
- >>> import mindspore
2890
- >>> from mindspore import Tensor, ops
2891
- >>> input = Tensor([[-1., 1., 2.], [-3., -3., 1.]], mindspore.float32)
2892
- >>> weight = Tensor([[-2., -2., -2.], [0., -1., 0.]], mindspore.float32)
2893
- >>> bias = Tensor([0., 1.], mindspore.float32)
2894
- >>> output = ops.dense(input, weight, bias)
2895
- >>> print(output)
2896
- [[-4. 0.]
2897
- [10. 4.]]
2898
- """
2899
- _check_is_tensor("input", input, "dense")
2900
- _check_is_tensor("weight", weight, "dense")
2901
- _check_is_tensor("bias", bias, "dense")
2902
- weight = ops.t(weight)
2903
- input = ops.matmul(input, weight)
2904
- input_shape = input.shape
2905
- if bias is not None:
2906
- input = input + bias
2907
- _check_dense_add_bias_shape(input_shape, input.shape, bias.shape)
2908
- return input
2909
-
2910
-
2911
3336
  def _check_dense_add_bias_shape(input_shape, output_shape, bias_shape):
2912
3337
  """Check that the output has the correct shape after adding bias."""
2913
3338
  if input_shape != output_shape:
@@ -3003,7 +3428,10 @@ def bidense(input1, input2, weight, bias=None):
3003
3428
  output = output.transpose(2, 0, 1) * input2
3004
3429
  output = output.sum(2).swapaxes(0, 1)
3005
3430
  if bias is not None:
3006
- output = bias_add_(output, bias)
3431
+ if input1.dtype != bias.dtype or input2.dtype != bias.dtype:
3432
+ raise TypeError(f"For 'bidense', the dtype of 'bias', 'input1' and 'input2' must be the same,"
3433
+ f" but got {bias.dtype}, {input1.dtype} and {input2.dtype}.")
3434
+ output = bias_add_(output.astype(bias.dtype), bias)
3007
3435
  if len(input1_shape) != 2:
3008
3436
  output_shape = input1_shape[:-1] + (-1,)
3009
3437
  output = output.reshape(output_shape)
@@ -3147,7 +3575,102 @@ def pdist(input, p=2.0):
3147
3575
  return pdist_(input)
3148
3576
 
3149
3577
 
3150
- @_primexpr
3578
+ def _circular_pad(input_x, padding):
3579
+ """circular pad"""
3580
+ padding = scalar_to_tensor_(padding, const_arg=True)
3581
+ is_expand = False
3582
+ if padding.shape[0] // 2 + 1 == input_x.ndim:
3583
+ input_x = input_x.expand_dims(0)
3584
+ is_expand = True
3585
+ out = PadV3(mode="circular", paddings_contiguous=True)(input_x, padding, None)
3586
+ if is_expand:
3587
+ out = out.squeeze(0)
3588
+ return out
3589
+
3590
+
3591
+ def pad_ext(input, pad, mode='constant', value=None):
3592
+ r"""
3593
+ Pads the input tensor according to the pad.
3594
+
3595
+ Args:
3596
+ input (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of additional dimensions.
3597
+ pad (tuple[int]): Filling position of pad.
3598
+ mode (str, optional): Pad filling mode, ``'constant'`` , ``'reflect'`` , ``'replicate'`` or ``'circular'`` .
3599
+ Default: ``'constant'`` .
3600
+ value (Union[int, float, None], optional): Valid only in ``'constant'`` mode.
3601
+ Set the pad value in ``'constant'`` mode. If the value is None, 0 is used as the default pad value.
3602
+ Default: ``None`` .
3603
+
3604
+ Returns:
3605
+ Tensor, the tensor after pad.
3606
+
3607
+ Raises:
3608
+ TypeError: If `pad` is not an int of tuple.
3609
+ TypeError: If `input` is not a Tensor.
3610
+ ValueError: If length of `pad` is not even.
3611
+ ValueError: If length of `pad` is greater than 6.
3612
+ ValueError: If `mode` is not ``'constant'`` and `value` not ``None``.
3613
+
3614
+ Supported Platforms:
3615
+ ``Ascend``
3616
+
3617
+ Examples:
3618
+ >>> import mindspore as ms
3619
+ >>> from mindspore.mint.nn.functional import pad
3620
+ >>> import numpy as np
3621
+ >>> x = ms.Tensor(np.arange(1 * 2 * 2 * 2).reshape((1, 2, 2, 2)), dtype=ms.float64)
3622
+ >>> output = pad(x, [1, 0, 0, 1], mode='constant', value=6.0)
3623
+ >>> print(output)
3624
+ [[[[6. 0. 1.]
3625
+ [6. 2. 3.]
3626
+ [6. 6. 6.]]
3627
+ [[6. 4. 5.]
3628
+ [6. 6. 7.]
3629
+ [6. 6. 6.]]]]
3630
+ >>> output1 = ops.pad(x, (1, 0, 0, 1), mode='reflect')
3631
+ >>> print(output1)
3632
+ [[[[1. 0. 1.]
3633
+ [3. 2. 3.]
3634
+ [1. 0. 1.]]
3635
+ [[5. 4. 5.]
3636
+ [7. 6. 7.]
3637
+ [5. 4. 5.]]]]
3638
+ """
3639
+ if not isinstance(input, Tensor):
3640
+ raise TypeError(f"For 'pad', the type of 'input' must be Tensor, but got {type(input)}.")
3641
+ out = input
3642
+ if (isinstance(pad, tuple) and not pad):
3643
+ return out
3644
+ if mode == "constant":
3645
+ value = 0 if value is None else value
3646
+ out = constant_pad_nd_op(input, pad, value)
3647
+ elif mode == "circular":
3648
+ out = _circular_pad(input, pad)
3649
+ else:
3650
+ if len(pad) == 2:
3651
+ if mode == "reflect":
3652
+ out = reflection_pad_1d_op(input, pad)
3653
+ elif mode == "replicate":
3654
+ out = replication_pad_1d_op(input, pad)
3655
+ else:
3656
+ raise ValueError(f"Pad filling mode must be 'constant' 'circular' 'reflect' or 'replicate'.")
3657
+ elif len(pad) == 4:
3658
+ if mode == "reflect":
3659
+ out = reflection_pad_2d_op(input, pad)
3660
+ elif mode == "replicate":
3661
+ out = replication_pad_2d_op(input, pad)
3662
+ else:
3663
+ raise ValueError(f"Pad filling mode must be 'constant' 'circular' 'reflect' or 'replicate'.")
3664
+ else:
3665
+ if mode == "reflect":
3666
+ out = reflection_pad_3d_op(input, pad)
3667
+ elif mode == "replicate":
3668
+ out = replication_pad_3d_op(input, pad)
3669
+ else:
3670
+ raise ValueError(f"Pad filling mode must be 'constant' 'circular' 'reflect' or 'replicate'.")
3671
+ return out
3672
+
3673
+
3151
3674
  def _check_pad_inputs(padding):
3152
3675
  """check the input of pad"""
3153
3676
  if len(padding) % 2 != 0:
@@ -5209,6 +5732,75 @@ def conv2d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
5209
5732
  return output
5210
5733
 
5211
5734
 
5735
+ def conv_transpose2d(input, weight, bias=None, stride=1, padding=0, output_padding=0, groups=1, dilation=1):
5736
+ r"""
5737
+ Calculates a 2D transposed convolution, which can be regarded as Conv2d for the gradient of the input,
5738
+ also called deconvolution (although it is not an actual deconvolution).
5739
+
5740
+ The input is typically of shape :math:`(N, C_{in}, H_{in}, W_{in})`,
5741
+ where :math:`N` is batch size, :math:`C_{in}` is space dimension,
5742
+ :math:`H_{in}, W_{in}` are the height and width of the feature layer respectively.
5743
+
5744
+ When Conv2d and Conv2dTranspose are initialized with the same parameters, and `pad_mode` is set to 'pad',
5745
+ :math:`dilation * (kernel\_size - 1) - padding` amount of zero will be paded to the height and width
5746
+ directions of the input, they are inverses of each other in regard to the input and output shapes in this case.
5747
+ However, when `stride` > 1, Conv2d maps multiple input shapes to the same output shape. Deconvolutional network
5748
+ can refer to `Deconvolutional Networks <https://www.matthewzeiler.com/mattzeiler/deconvolutionalnetworks.pdf>`_.
5749
+
5750
+ Args:
5751
+ input (Tensor): Tensor of shape :math:`(N, C_{in}, H_{in}, W_{in})`.
5752
+ weight (Tensor): Tensor of shape
5753
+ :math:`(N, C_{in} / \text{groups}, \text{kernel_size[0]}, \text{kernel_size[1]})`, then the size of kernel
5754
+ is :math:`(\text{kernel_size[0]}, \text{kernel_size[1]})`.
5755
+ bias (Tensor, optional): Bias Tensor with shape :math:`(C_{out})`.
5756
+ When bias is ``None`` , zeros will be used. Default: ``None`` .
5757
+ stride (Union(int, tuple[int]), optional): The distance of kernel moving, an int number that represents
5758
+ the height and width of movement are both strides, or a tuple of two int numbers that
5759
+ represent height and width of movement respectively. Default: ``1`` .
5760
+ padding (Union(int, tuple[int], list[int]), optional): Implicit paddings on both sides of the input `x`.
5761
+ Can be an integer or a tuple/list with 2 integers.
5762
+ output_padding (Union[int, tuple[int]]): The number of padding on the height and width directions of the output.
5763
+ The data type is an integer or a tuple of two integers. If `output_padding` is an integer,
5764
+ then the bottom and right padding are all equal to `output_padding`. If `output_padding` is a tuple of
5765
+ 2 integers, then the bottom and right padding is equal to `output_padding[0]`, `output_padding[1]`
5766
+ respectively.
5767
+ groups (int, optional): Splits `input` into groups. Default: ``1`` .
5768
+ dilation (Union(int, tuple[int]), optional): Gaps between kernel elements.The data type is int or a tuple of
5769
+ 2 integers. Specifies the dilation rate to use for dilated convolution. If set to be :math:`k > 1`,
5770
+ there will be :math:`k - 1` pixels skipped for each sampling location. Its value must
5771
+ be greater than or equal to 1 and bounded by the height and width of the input `x`. Default: ``1`` .
5772
+
5773
+ Returns:
5774
+ Tensor, the value that applied 2D convolution. The shape is :math:`(N, C_{out}, H_{out}, W_{out})`.
5775
+ To see how different pad modes affect the output shape, please refer to
5776
+ :class:`mindspore.nn.Conv2dTranspose` for more details.
5777
+
5778
+
5779
+ Raises:
5780
+ TypeError: If `stride`, `padding` or `dilation` is neither an int nor a tuple.
5781
+ TypeError: `groups` is not an int.
5782
+ TypeError: If `bias` is not a Tensor.
5783
+ ValueError: If the shape of `bias` is not :math:`(C_{out})` .
5784
+ ValueError: If `stride` or `dilation` is less than 1.
5785
+ ValueError: If `padding` is a tuple/list whose length is not equal to 2.
5786
+
5787
+ Supported Platforms:
5788
+ ``Ascend``
5789
+
5790
+ Examples:
5791
+ >>> import mindspore
5792
+ >>> import numpy as np
5793
+ >>> from mindspore import Tensor, ops
5794
+ >>> x = Tensor(np.ones([1, 6, 32, 32]), mindspore.float32)
5795
+ >>> weight = Tensor(np.ones([6, 3, 5, 5]), mindspore.float32)
5796
+ >>> output = ops.conv_transpose2d(x, weight)
5797
+ >>> print(output.shape)
5798
+ (1, 3, 36, 36)
5799
+ """
5800
+ conv = _get_cache_prim(Convolution)(stride, padding, dilation, True, output_padding, groups)
5801
+ return conv(input, weight, bias)
5802
+
5803
+
5212
5804
  def hardsigmoid(input):
5213
5805
  r"""
5214
5806
  Hard sigmoid activation function.
@@ -5468,6 +6060,117 @@ def adaptive_avg_pool1d(input, output_size):
5468
6060
  return input
5469
6061
 
5470
6062
 
6063
+ def layer_norm(input, normalized_shape, weight=None, bias=None, eps=1e-5):
6064
+ r"""Applies the Layer Normalization to the input tensor.
6065
+
6066
+ This operator will normalize the input tensor on given axis. LayerNorm is described in the paper
6067
+ `Layer Normalization <https://arxiv.org/abs/1607.06450>`_.
6068
+
6069
+ .. math::
6070
+ y = \frac{x - mean}{\sqrt{variance + \epsilon}} * \gamma + \beta
6071
+
6072
+ where :math:`\gamma` is weight, :math:`\beta` is bias, :math:`\epsilon` is eps.
6073
+
6074
+ Args:
6075
+ input (Tensor): Tensor of shape :math:`(N, \ldots)`. The input of LayerNorm.
6076
+ normalized_shape (Union(int, tuple[int], list[int])): The normalized shape of `input` for LayerNorm.
6077
+ `normalized_shape` equal to `input_shape[begin_norm_axis:]`, where `begin_norm_axis` represents the axis
6078
+ where normalization begins.
6079
+ weight (Tensor, optional): Learnable parameter :math:`\gamma` . Tensor of shape `normalized_shape`.
6080
+ Default: ``None``, has the same data type with `input`. Initialized to ``1`` when `weight` is None.
6081
+ bias (Tensor, optional): Learnable parameter :math:`\beta` . Tensor of shape `normalized_shape`.
6082
+ Default: ``None``, has the same data type with `input`. Initialized to ``0`` when `bias` is None.
6083
+ eps (float, optional): A value added to the denominator for numerical stability(:math:`\epsilon`).
6084
+ Default: ``1e-5`` .
6085
+
6086
+ Returns:
6087
+ - **output** (Tensor) - The normalized input, has the same type and shape as the `input`.
6088
+
6089
+ Raises:
6090
+ TypeError: If `input` is not a Tensor.
6091
+ TypeError: If `normalized_shape` is not an integer, a list or a tuple.
6092
+ TypeError: If `eps` is not a float.
6093
+
6094
+ Supported Platforms:
6095
+ ``Ascend``
6096
+
6097
+ Examples:
6098
+ >>> import mindspore
6099
+ >>> import numpy as np
6100
+ >>> from mindspore import Tensor, ops
6101
+ >>> input_x = Tensor(np.array([[1, 2, 3], [1, 2, 3]]), mindspore.float32)
6102
+ >>> normalized_shape = (3,)
6103
+ >>> gamma = Tensor(np.ones(normalized_shape), mindspore.float32)
6104
+ >>> beta = Tensor(np.zeros(normalized_shape), mindspore.float32)
6105
+ >>> eps = 1e-7
6106
+ >>> output = ops.layer_norm(input_x, normalized_shape, gamma, beta, eps)
6107
+ >>> print(output)
6108
+ [[-1.2247448 0. 1.2247448]
6109
+ [-1.2247448 0. 1.2247448]]
6110
+ """
6111
+ if weight is None:
6112
+ weight = ops.ones(normalized_shape, dtype=input.dtype)
6113
+ if bias is None:
6114
+ bias = ops.zeros(normalized_shape, dtype=input.dtype)
6115
+ layer_norm_ext_op = LayerNormExt()
6116
+ return layer_norm_ext_op(input, normalized_shape, weight, bias, eps)[0]
6117
+
6118
+
6119
+ def group_norm(input, num_groups, weight=None, bias=None, eps=1e-5):
6120
+ r"""Group Normalization over a mini-batch of inputs.
6121
+
6122
+ Group Normalization is widely used in recurrent neural networks. It applies
6123
+ normalization on a mini-batch of inputs for each single training case as described
6124
+ in the paper `Group Normalization <https://arxiv.org/pdf/1803.08494.pdf>`_. Group Normalization
6125
+ divides the channels into groups and computes within each group the mean and variance for normalization,
6126
+ and it performs very stable over a wide range of batch size. :math:`\gamma` and :math:`\beta` are trainable scale
6127
+ and shift.
6128
+ It can be described using the following formula:
6129
+
6130
+ .. math::
6131
+ y = \frac{x - \mathrm{E}[x]}{\sqrt{\mathrm{Var}[x] + \epsilon}} * \gamma + \beta
6132
+
6133
+ where :math:`\gamma` is `weight`, :math:`\beta` is `bias`, :math:`\epsilon` is `eps`.
6134
+
6135
+ Args:
6136
+ input (Tensor) : The input feature with shape :math:`(N, C, *)` where :math:`*` means, any number of
6137
+ additional dimensions.
6138
+ num_groups (int): The number of groups to be divided along the channel dimension.
6139
+ weight (Tensor, optional): The shape :math:`(C,)`, Default: ``None``, has the same data type with `input`.
6140
+ bias (Tensor, optional): The shape :math:`(C,)`, Default: ``None``, has the same data type with `input`.
6141
+ eps (float, optional): A value added to the denominator for numerical stability. Default: ``1e-5`` .
6142
+
6143
+ Returns:
6144
+ Tensor, the normalized and scaled offset tensor, has the same shape and data type as the `input`.
6145
+
6146
+ Raises:
6147
+ TypeError: If `num_groups` is not an int.
6148
+ TypeError: If `eps` is not a float.
6149
+ ValueError: If `num_groups` is less than 1.
6150
+ ValueError: If `C` (the second parameter of dimensions of `input`) is not divided by `num_groups`.
6151
+
6152
+ Supported Platforms:
6153
+ ``Ascend`` ``GPU`` ``CPU``
6154
+
6155
+ Examples:
6156
+ >>> import mindspore as ms
6157
+ >>> import numpy as np
6158
+ >>> from mindspore.ops import group_norm
6159
+ >>> x = ms.Tensor(np.ones([1, 2, 4, 4], np.float32))
6160
+ >>> output = group_norm(x, 2)
6161
+ >>> print(output)
6162
+ [[[[0. 0. 0. 0.]
6163
+ [0. 0. 0. 0.]
6164
+ [0. 0. 0. 0.]
6165
+ [0. 0. 0. 0.]]
6166
+ [[0. 0. 0. 0.]
6167
+ [0. 0. 0. 0.]
6168
+ [0. 0. 0. 0.]
6169
+ [0. 0. 0. 0.]]]]
6170
+ """
6171
+ group_norm_op = GroupNorm()
6172
+ return group_norm_op(input, num_groups, weight, bias, eps)[0]
6173
+
5471
6174
  def batch_norm(input_x, running_mean, running_var, weight, bias, training=False, momentum=0.1, eps=1e-5):
5472
6175
  r"""
5473
6176
  Batch Normalization for input data and updated parameters.
@@ -7201,6 +7904,60 @@ def incre_flash_attention(query, key, value, attn_mask, actual_seq_lengths, pse_
7201
7904
  dequant_scale2, quant_scale2, quant_offset2, antiquant_scale, antiquant_offset, block_table)
7202
7905
 
7203
7906
 
7907
+ def embedding(input, weight, padding_idx=None, max_norm=None, norm_type=2.0, scale_grad_by_freq=False):
7908
+ r"""
7909
+ Retrieve the word embeddings in `weight` using indices specified in `input`.
7910
+
7911
+ .. warning::
7912
+ On Ascend, the behavior is unpredictable when the value of input is invalid.
7913
+
7914
+ Args:
7915
+ input (Tensor): The indices used to lookup in the `weight`. The data type must be mindspore.int32 or
7916
+ mindspore.int64, and the value should be in range `[0, weight.shape[0])`.
7917
+ weight (Parameter): The matrix where to lookup from. The shape must be 2D.
7918
+ padding_idx (int, optional): If the value is not None, the corresponding row of `weight` will not be updated
7919
+ in training. The value should be in range `[-weight.shape[0], weight.shape[0])` if it's not ``None``.
7920
+ Default ``None``.
7921
+ max_norm (float, optional): If not None, firstly get the p-norm result of the `weight` specified by `input`
7922
+ where p is specified by `norm_type`; if the result is larger then `max_norm`, update the `weight`
7923
+ with :math:`\frac{max\_norm}{result+1e^{-7}}` in-place. Default ``None``.
7924
+ norm_type (float, optional): Indicates the value of p in p-norm. Default ``2.0``.
7925
+ scale_grad_by_freq (bool, optional): If ``True`` the gradients will be scaled by the inverse of frequency of
7926
+ the index in `input`. Default ``False``.
7927
+
7928
+ Returns:
7929
+ Tensor, has the same data type as `weight`, the shape is :math:`(*input.shape, weight.shape[1])`.
7930
+
7931
+ Raises:
7932
+ ValueError: If `padding_idx` is out of valid range.
7933
+ ValueError: If the shape of `weight` is invalid.
7934
+ TypeError: `weight` is not a :class:`mindspore.Parameter`.
7935
+
7936
+ Supported Platforms:
7937
+ ``Ascend``
7938
+
7939
+ Examples:
7940
+ >>> import mindspore
7941
+ >>> import numpy as np
7942
+ >>> from mindspore import Tensor, Parameter, ops
7943
+ >>> input = Tensor([[1, 0, 1, 1], [0, 0, 1, 0]])
7944
+ >>> weight = Parameter(np.random.randn(3, 3).astype(np.float32))
7945
+ >>> output = ops.embedding(input, weight, max_norm=0.4)
7946
+ >>> print(output)
7947
+ [[[ 5.49015924e-02, 3.47811311e-01, -1.89771220e-01],
7948
+ [ 2.09307984e-01, -2.24846993e-02, 3.40124398e-01],
7949
+ [ 5.49015924e-02, 3.47811311e-01, -1.89771220e-01],
7950
+ [ 5.49015924e-02, 3.47811311e-01, -1.89771220e-01]],
7951
+ [[ 2.09307984e-01, -2.24846993e-02, 3.40124398e-01],
7952
+ [ 2.09307984e-01, -2.24846993e-02, 3.40124398e-01],
7953
+ [ 5.49015924e-02, 3.47811311e-01, -1.89771220e-01],
7954
+ [ 2.09307984e-01, -2.24846993e-02, 3.40124398e-01]]]
7955
+ """
7956
+ if not isinstance(weight, Parameter):
7957
+ raise TypeError(f"For Embedding, the weight must be a mindspore.Parameter, but got {type(weight)}.")
7958
+ return embedding_op(input, weight, padding_idx, max_norm, norm_type, scale_grad_by_freq)
7959
+
7960
+
7204
7961
  __all__ = [
7205
7962
  'adaptive_avg_pool1d',
7206
7963
  'adaptive_avg_pool2d',
@@ -7226,6 +7983,7 @@ __all__ = [
7226
7983
  'dropout1d',
7227
7984
  'dropout2d',
7228
7985
  'dropout3d',
7986
+ 'embedding',
7229
7987
  'fast_gelu',
7230
7988
  'fractional_max_pool2d',
7231
7989
  'fractional_max_pool3d',
@@ -7239,6 +7997,7 @@ __all__ = [
7239
7997
  'intopk',
7240
7998
  'interpolate',
7241
7999
  'upsample',
8000
+ 'layer_norm',
7242
8001
  'log_softmax',
7243
8002
  'mish',
7244
8003
  'lrn',
@@ -7256,6 +8015,7 @@ __all__ = [
7256
8015
  'softmin',
7257
8016
  'pdist',
7258
8017
  'pad',
8018
+ 'pad_ext',
7259
8019
  'prelu',
7260
8020
  'mirror_pad',
7261
8021
  'cross_entropy',
@@ -7271,6 +8031,7 @@ __all__ = [
7271
8031
  'conv3d_transpose',
7272
8032
  'conv1d',
7273
8033
  'conv2d',
8034
+ 'conv_transpose2d',
7274
8035
  'sigmoid',
7275
8036
  'logsigmoid',
7276
8037
  'relu',
@@ -7295,6 +8056,8 @@ __all__ = [
7295
8056
  'msort',
7296
8057
  'triplet_margin_loss',
7297
8058
  'channel_shuffle',
7298
- 'hardsigmoid'
8059
+ 'hardsigmoid',
8060
+ 'group_norm',
8061
+ 'dropout_ext',
7299
8062
  ]
7300
8063
  __all__.sort()