mindspore 2.0.0a0__cp37-none-any.whl → 2.0.0rc1__cp37-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 (693) hide show
  1. mindspore/.commit_id +1 -1
  2. mindspore/Third_Party_Open_Source_Software_Notice +9064 -0
  3. mindspore/__init__.py +4 -2
  4. mindspore/_akg/akg/composite/build_module.py +11 -0
  5. mindspore/_akg/akg/config/repository_cuda.json +11 -0
  6. mindspore/_akg/akg/tvm/contrib/nvcc.py +4 -3
  7. mindspore/_c_dataengine.cpython-37m-aarch64-linux-gnu.so +0 -0
  8. mindspore/_c_expression.cpython-37m-aarch64-linux-gnu.so +0 -0
  9. mindspore/_c_mindrecord.cpython-37m-aarch64-linux-gnu.so +0 -0
  10. mindspore/_check_jit_forbidden_api.py +102 -0
  11. mindspore/_checkparam.py +1066 -1001
  12. mindspore/_extends/parallel_compile/akg_compiler/akg_process.py +4 -3
  13. mindspore/_extends/parallel_compile/akg_compiler/tbe_topi.py +50 -48
  14. mindspore/_extends/parallel_compile/akg_compiler/util.py +9 -4
  15. mindspore/_extends/parallel_compile/tbe_compiler/tbe_adapter.py +4 -4
  16. mindspore/_extends/parallel_compile/tbe_compiler/tbe_helper.py +9 -4
  17. mindspore/_extends/parse/__init__.py +5 -3
  18. mindspore/_extends/parse/namespace.py +16 -1
  19. mindspore/_extends/parse/parser.py +107 -22
  20. mindspore/_extends/parse/resources.py +0 -7
  21. mindspore/_extends/parse/standard_method.py +885 -413
  22. mindspore/_mindspore_offline_debug.cpython-37m-aarch64-linux-gnu.so +0 -0
  23. mindspore/amp.py +52 -57
  24. mindspore/bin/cache_admin +0 -0
  25. mindspore/bin/cache_server +0 -0
  26. mindspore/boost/boost.py +2 -2
  27. mindspore/boost/boost_cell_wrapper.py +38 -20
  28. mindspore/boost/dim_reduce.py +3 -3
  29. mindspore/boost/group_loss_scale_manager.py +1 -1
  30. mindspore/common/__init__.py +4 -6
  31. mindspore/common/_decorator.py +2 -0
  32. mindspore/common/_register_for_adapter.py +55 -0
  33. mindspore/common/_stub_tensor.py +201 -0
  34. mindspore/common/_utils.py +41 -7
  35. mindspore/common/api.py +215 -141
  36. mindspore/common/dtype.py +8 -1
  37. mindspore/common/dump.py +2 -2
  38. mindspore/common/initializer.py +4 -2
  39. mindspore/common/jit_config.py +17 -13
  40. mindspore/common/mutable.py +33 -13
  41. mindspore/common/parameter.py +23 -21
  42. mindspore/common/seed.py +8 -24
  43. mindspore/common/sparse_tensor.py +62 -41
  44. mindspore/common/tensor.py +852 -1154
  45. mindspore/communication/__init__.py +2 -2
  46. mindspore/communication/_comm_helper.py +11 -4
  47. mindspore/communication/management.py +22 -21
  48. mindspore/config/op_info.config +501 -1008
  49. mindspore/config/super_bar_config.json +512 -0
  50. mindspore/context.py +201 -23
  51. mindspore/dataset/__init__.py +6 -6
  52. mindspore/dataset/audio/__init__.py +7 -7
  53. mindspore/dataset/audio/transforms.py +670 -30
  54. mindspore/dataset/audio/utils.py +47 -4
  55. mindspore/dataset/audio/validators.py +223 -1
  56. mindspore/dataset/callback/ds_callback.py +2 -2
  57. mindspore/dataset/core/config.py +210 -14
  58. mindspore/dataset/core/validator_helpers.py +2 -2
  59. mindspore/{parallel/nn/layers.py → dataset/debug/__init__.py} +7 -8
  60. mindspore/dataset/debug/debug_hook.py +65 -0
  61. mindspore/dataset/debug/pre_defined_hook.py +67 -0
  62. mindspore/dataset/engine/__init__.py +7 -3
  63. mindspore/dataset/engine/cache_client.py +1 -1
  64. mindspore/dataset/engine/datasets.py +322 -66
  65. mindspore/dataset/engine/datasets_audio.py +80 -76
  66. mindspore/dataset/engine/datasets_standard_format.py +51 -38
  67. mindspore/dataset/engine/datasets_text.py +232 -118
  68. mindspore/dataset/engine/datasets_user_defined.py +41 -17
  69. mindspore/dataset/engine/datasets_vision.py +746 -225
  70. mindspore/dataset/engine/graphdata.py +75 -10
  71. mindspore/dataset/engine/iterators.py +45 -5
  72. mindspore/dataset/engine/offload.py +48 -28
  73. mindspore/dataset/engine/validators.py +117 -8
  74. mindspore/dataset/text/__init__.py +6 -5
  75. mindspore/dataset/text/transforms.py +86 -3
  76. mindspore/dataset/text/utils.py +6 -4
  77. mindspore/dataset/text/validators.py +25 -0
  78. mindspore/dataset/transforms/__init__.py +3 -2
  79. mindspore/dataset/transforms/c_transforms.py +1 -1
  80. mindspore/dataset/transforms/transforms.py +2 -2
  81. mindspore/dataset/utils/__init__.py +2 -1
  82. mindspore/dataset/utils/line_reader.py +121 -0
  83. mindspore/dataset/vision/__init__.py +2 -3
  84. mindspore/dataset/vision/c_transforms.py +9 -9
  85. mindspore/dataset/vision/py_transforms.py +5 -5
  86. mindspore/dataset/vision/py_transforms_util.py +2 -0
  87. mindspore/dataset/vision/transforms.py +160 -161
  88. mindspore/dataset/vision/utils.py +3 -3
  89. mindspore/experimental/map_parameter.py +38 -26
  90. mindspore/include/OWNERS +0 -1
  91. mindspore/include/api/callback/callback.h +9 -13
  92. mindspore/include/api/callback/ckpt_saver.h +2 -2
  93. mindspore/include/api/callback/loss_monitor.h +2 -2
  94. mindspore/include/api/callback/lr_scheduler.h +5 -5
  95. mindspore/include/api/callback/time_monitor.h +2 -2
  96. mindspore/include/api/callback/train_accuracy.h +4 -6
  97. mindspore/include/api/cfg.h +19 -6
  98. mindspore/include/api/context.h +44 -9
  99. mindspore/include/api/delegate.h +1 -1
  100. mindspore/include/api/metrics/accuracy.h +2 -2
  101. mindspore/include/api/metrics/metrics.h +4 -3
  102. mindspore/include/api/model.h +9 -4
  103. mindspore/include/api/model_parallel_runner.h +2 -2
  104. mindspore/include/api/net.h +12 -11
  105. mindspore/include/api/serialization.h +19 -3
  106. mindspore/include/api/types.h +3 -3
  107. mindspore/include/dataset/constants.h +7 -0
  108. mindspore/include/dataset/text.h +59 -0
  109. mindspore/include/mindapi/base/type_id.h +1 -0
  110. mindspore/lib/libdnnl.so.2 +0 -0
  111. mindspore/lib/libicudata.so.69 +0 -0
  112. mindspore/lib/libicui18n.so.69 +0 -0
  113. mindspore/lib/libicuuc.so.69 +0 -0
  114. mindspore/lib/libmindspore.so +0 -0
  115. mindspore/lib/libmindspore_backend.so +0 -0
  116. mindspore/lib/libmindspore_common.so +0 -0
  117. mindspore/lib/libmindspore_core.so +0 -0
  118. mindspore/lib/libmindspore_glog.so.0 +0 -0
  119. mindspore/lib/libmindspore_gpr.so.15 +0 -0
  120. mindspore/lib/libmindspore_grpc++.so.1 +0 -0
  121. mindspore/lib/libmindspore_grpc.so.15 +0 -0
  122. mindspore/lib/libmindspore_shared_lib.so +0 -0
  123. mindspore/lib/libmpi_adapter.so +0 -0
  124. mindspore/lib/libmpi_collective.so +0 -0
  125. mindspore/lib/libnnacl.so +0 -0
  126. mindspore/lib/libopencv_core.so.4.5 +0 -0
  127. mindspore/lib/libopencv_imgcodecs.so.4.5 +0 -0
  128. mindspore/lib/libopencv_imgproc.so.4.5 +0 -0
  129. mindspore/lib/libps_cache.so +0 -0
  130. mindspore/lib/plugin/ascend/libakg.so +0 -0
  131. mindspore/lib/plugin/ascend/libascend_collective.so +0 -0
  132. mindspore/lib/plugin/ascend/libdvpp_utils.so +0 -0
  133. mindspore/lib/plugin/ascend/libhccl_plugin.so +0 -0
  134. mindspore/lib/plugin/ascend/libmindspore_aicpu_kernels.so +0 -0
  135. mindspore/lib/plugin/ascend/libmindspore_cpu_kernels.so +0 -0
  136. mindspore/lib/plugin/cpu/libakg.so +0 -0
  137. mindspore/lib/plugin/libmindspore_ascend.so.1 +0 -0
  138. mindspore/lib/plugin/{libmindspore_ascend.so → libmindspore_ascend.so.2} +0 -0
  139. mindspore/log.py +1 -1
  140. mindspore/mindrecord/filereader.py +18 -0
  141. mindspore/mindrecord/filewriter.py +197 -34
  142. mindspore/mindrecord/shardreader.py +9 -0
  143. mindspore/mindrecord/shardwriter.py +1 -1
  144. mindspore/mindrecord/tools/cifar100_to_mr.py +3 -3
  145. mindspore/mindrecord/tools/cifar10_to_mr.py +3 -3
  146. mindspore/mindrecord/tools/csv_to_mr.py +3 -3
  147. mindspore/mindrecord/tools/imagenet_to_mr.py +16 -11
  148. mindspore/mindrecord/tools/mnist_to_mr.py +2 -2
  149. mindspore/mindrecord/tools/tfrecord_to_mr.py +6 -6
  150. mindspore/nn/__init__.py +0 -4
  151. mindspore/nn/cell.py +204 -132
  152. mindspore/nn/dynamic_lr.py +1 -1
  153. mindspore/nn/grad/cell_grad.py +7 -6
  154. mindspore/nn/layer/__init__.py +5 -4
  155. mindspore/nn/layer/activation.py +40 -89
  156. mindspore/nn/layer/basic.py +255 -624
  157. mindspore/nn/layer/channel_shuffle.py +7 -6
  158. mindspore/nn/layer/combined.py +1 -1
  159. mindspore/nn/layer/container.py +41 -4
  160. mindspore/nn/layer/conv.py +64 -28
  161. mindspore/nn/layer/dense.py +9 -8
  162. mindspore/nn/layer/embedding.py +27 -25
  163. mindspore/nn/layer/image.py +53 -46
  164. mindspore/nn/layer/math.py +97 -105
  165. mindspore/nn/layer/normalization.py +117 -86
  166. mindspore/nn/layer/padding.py +185 -95
  167. mindspore/nn/layer/pooling.py +817 -414
  168. mindspore/nn/layer/rnn_cells.py +10 -15
  169. mindspore/nn/layer/rnns.py +37 -38
  170. mindspore/nn/layer/thor_layer.py +11 -12
  171. mindspore/nn/layer/timedistributed.py +5 -5
  172. mindspore/nn/layer/transformer.py +701 -0
  173. mindspore/nn/learning_rate_schedule.py +8 -8
  174. mindspore/nn/loss/__init__.py +5 -4
  175. mindspore/nn/loss/loss.py +334 -199
  176. mindspore/nn/optim/ada_grad.py +6 -6
  177. mindspore/nn/optim/adadelta.py +2 -3
  178. mindspore/nn/optim/adafactor.py +4 -5
  179. mindspore/nn/optim/adam.py +126 -62
  180. mindspore/nn/optim/adamax.py +3 -4
  181. mindspore/nn/optim/adasum.py +6 -6
  182. mindspore/nn/optim/asgd.py +2 -2
  183. mindspore/nn/optim/ftrl.py +67 -38
  184. mindspore/nn/optim/lamb.py +4 -5
  185. mindspore/nn/optim/lars.py +2 -2
  186. mindspore/nn/optim/lazyadam.py +43 -4
  187. mindspore/nn/optim/momentum.py +6 -5
  188. mindspore/nn/optim/optimizer.py +3 -1
  189. mindspore/nn/optim/proximal_ada_grad.py +2 -2
  190. mindspore/nn/optim/rmsprop.py +1 -1
  191. mindspore/nn/optim/rprop.py +8 -9
  192. mindspore/nn/optim/sgd.py +19 -13
  193. mindspore/nn/optim/thor.py +10 -15
  194. mindspore/nn/probability/__init__.py +0 -2
  195. mindspore/nn/probability/bijector/bijector.py +4 -4
  196. mindspore/nn/probability/bijector/invert.py +1 -1
  197. mindspore/nn/probability/bijector/softplus.py +2 -2
  198. mindspore/nn/probability/bnn_layers/dense_variational.py +1 -1
  199. mindspore/nn/probability/bnn_layers/layer_distribution.py +2 -2
  200. mindspore/nn/probability/distribution/_utils/utils.py +9 -15
  201. mindspore/nn/probability/distribution/bernoulli.py +3 -3
  202. mindspore/nn/probability/distribution/beta.py +1 -1
  203. mindspore/nn/probability/distribution/categorical.py +5 -7
  204. mindspore/nn/probability/distribution/cauchy.py +3 -3
  205. mindspore/nn/probability/distribution/distribution.py +2 -2
  206. mindspore/nn/probability/distribution/exponential.py +2 -2
  207. mindspore/nn/probability/distribution/gamma.py +3 -3
  208. mindspore/nn/probability/distribution/geometric.py +1 -1
  209. mindspore/nn/probability/distribution/gumbel.py +3 -3
  210. mindspore/nn/probability/distribution/half_normal.py +15 -11
  211. mindspore/nn/probability/distribution/laplace.py +16 -13
  212. mindspore/nn/probability/distribution/logistic.py +2 -2
  213. mindspore/nn/probability/distribution/normal.py +1 -1
  214. mindspore/nn/probability/distribution/poisson.py +1 -1
  215. mindspore/nn/probability/distribution/student_t.py +20 -15
  216. mindspore/nn/probability/distribution/transformed_distribution.py +4 -4
  217. mindspore/nn/probability/distribution/uniform.py +2 -2
  218. mindspore/nn/reinforcement/_tensors_queue.py +3 -3
  219. mindspore/nn/reinforcement/tensor_array.py +2 -2
  220. mindspore/nn/sparse/sparse.py +2 -2
  221. mindspore/nn/wrap/cell_wrapper.py +27 -10
  222. mindspore/nn/wrap/grad_reducer.py +2 -2
  223. mindspore/nn/wrap/loss_scale.py +40 -24
  224. mindspore/numpy/array_creations.py +33 -22
  225. mindspore/numpy/array_ops.py +35 -30
  226. mindspore/numpy/logic_ops.py +6 -27
  227. mindspore/numpy/math_ops.py +22 -19
  228. mindspore/numpy/utils.py +1 -1
  229. mindspore/numpy/utils_const.py +108 -58
  230. mindspore/ops/_constants.py +0 -6
  231. mindspore/ops/_grad/__init__.py +2 -1
  232. mindspore/ops/_grad/grad_array_ops.py +86 -117
  233. mindspore/ops/_grad/grad_base.py +23 -1
  234. mindspore/ops/_grad/grad_clip_ops.py +2 -3
  235. mindspore/ops/_grad/grad_comm_ops.py +34 -24
  236. mindspore/ops/_grad/grad_implementations.py +9 -45
  237. mindspore/ops/_grad/grad_inner_ops.py +47 -4
  238. mindspore/ops/_grad/grad_math_ops.py +142 -117
  239. mindspore/ops/_grad/grad_nn_ops.py +71 -165
  240. mindspore/ops/_grad/grad_sequence_ops.py +296 -0
  241. mindspore/ops/_grad/grad_sparse.py +7 -6
  242. mindspore/ops/_grad_experimental/__init__.py +1 -0
  243. mindspore/ops/_grad_experimental/grad_array_ops.py +150 -15
  244. mindspore/ops/_grad_experimental/grad_image_ops.py +16 -7
  245. mindspore/ops/_grad_experimental/grad_inner_ops.py +1 -22
  246. mindspore/ops/_grad_experimental/grad_linalg_ops.py +4 -11
  247. mindspore/ops/_grad_experimental/grad_math_ops.py +210 -89
  248. mindspore/ops/_grad_experimental/grad_nn_ops.py +26 -22
  249. mindspore/ops/_grad_experimental/grad_scalar_ops.py +112 -0
  250. mindspore/ops/_grad_experimental/grad_sparse_ops.py +49 -8
  251. mindspore/ops/_op_impl/_custom_op/batch_matmul_impl.py +1 -1
  252. mindspore/ops/_op_impl/_custom_op/batchnorm_fold.py +2 -2
  253. mindspore/ops/_op_impl/_custom_op/batchnorm_fold2.py +2 -2
  254. mindspore/ops/_op_impl/_custom_op/batchnorm_fold2_grad.py +2 -2
  255. mindspore/ops/_op_impl/_custom_op/batchnorm_fold2_grad_reduce.py +4 -4
  256. mindspore/ops/_op_impl/_custom_op/batchnorm_fold_grad.py +3 -3
  257. mindspore/ops/_op_impl/_custom_op/cholesky_trsm_impl.py +1 -1
  258. mindspore/ops/_op_impl/_custom_op/correction_mul.py +2 -2
  259. mindspore/ops/_op_impl/_custom_op/correction_mul_grad.py +2 -2
  260. mindspore/ops/_op_impl/_custom_op/dsd_back_impl.py +1 -5
  261. mindspore/ops/_op_impl/_custom_op/dsd_impl.py +1 -1
  262. mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perchannel.py +2 -2
  263. mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perchannel_grad.py +2 -2
  264. mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perchannel_grad_reduce.py +2 -2
  265. mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perlayer.py +2 -2
  266. mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perlayer_grad.py +2 -2
  267. mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perlayer_grad_reduce.py +2 -2
  268. mindspore/ops/_op_impl/_custom_op/fake_quant_perchannel.py +2 -2
  269. mindspore/ops/_op_impl/_custom_op/fake_quant_perchannel_grad.py +2 -2
  270. mindspore/ops/_op_impl/_custom_op/fake_quant_perlayer.py +2 -2
  271. mindspore/ops/_op_impl/_custom_op/fake_quant_perlayer_grad.py +2 -2
  272. mindspore/ops/_op_impl/_custom_op/fused_abs_max1_impl.py +1 -1
  273. mindspore/ops/_op_impl/_custom_op/img2col_impl.py +1 -1
  274. mindspore/ops/_op_impl/_custom_op/matmul_cube_dense_left_impl.py +2 -2
  275. mindspore/ops/_op_impl/_custom_op/matmul_cube_dense_right_impl.py +1 -1
  276. mindspore/ops/_op_impl/_custom_op/matmul_cube_fracz_left_cast_impl.py +1 -1
  277. mindspore/ops/_op_impl/_custom_op/matmul_cube_fracz_right_mul_impl.py +1 -1
  278. mindspore/ops/_op_impl/_custom_op/matmul_cube_impl.py +2 -2
  279. mindspore/ops/_op_impl/_custom_op/matmul_dds_impl.py +0 -4
  280. mindspore/ops/_op_impl/_custom_op/matrix_combine_impl.py +1 -1
  281. mindspore/ops/_op_impl/_custom_op/minmax_update_perchannel.py +2 -2
  282. mindspore/ops/_op_impl/_custom_op/minmax_update_perlayer.py +2 -2
  283. mindspore/ops/_op_impl/_custom_op/transpose02314_impl.py +1 -1
  284. mindspore/ops/_op_impl/aicpu/__init__.py +236 -4
  285. mindspore/ops/_op_impl/aicpu/abs.py +36 -0
  286. mindspore/ops/_op_impl/aicpu/{adaptive_avg_pool_2d_v1.py → adaptive_avg_pool_2d.py} +6 -5
  287. mindspore/ops/_op_impl/aicpu/adaptive_avg_pool_2d_grad.py +34 -0
  288. mindspore/ops/_op_impl/aicpu/add.py +43 -0
  289. mindspore/ops/_op_impl/aicpu/addcdiv.py +0 -32
  290. mindspore/ops/_op_impl/aicpu/addcmul.py +0 -84
  291. mindspore/ops/_op_impl/aicpu/affine_grid_grad.py +35 -0
  292. mindspore/ops/_op_impl/aicpu/batch_matmul.py +43 -43
  293. mindspore/ops/_op_impl/aicpu/bernoulli.py +48 -0
  294. mindspore/{compression/common/__init__.py → ops/_op_impl/aicpu/bessel_i0.py} +15 -8
  295. mindspore/ops/_op_impl/aicpu/channel_shuffle.py +40 -0
  296. mindspore/ops/_op_impl/aicpu/conj.py +11 -0
  297. mindspore/ops/_op_impl/aicpu/cumulative_logsumexp.py +0 -3
  298. mindspore/ops/_op_impl/aicpu/deformable_offsets.py +38 -0
  299. mindspore/ops/_op_impl/aicpu/deformable_offsets_grad.py +43 -0
  300. mindspore/ops/_op_impl/aicpu/{adaptive_avg_pool_2d_grad_v1.py → digamma.py} +7 -9
  301. mindspore/ops/_op_impl/aicpu/flatten.py +1 -0
  302. mindspore/ops/_op_impl/aicpu/fmax.py +36 -0
  303. mindspore/ops/_op_impl/aicpu/fmin.py +37 -0
  304. mindspore/ops/_op_impl/aicpu/fractional_max_pool3d_with_fixed_ksize.py +1 -1
  305. mindspore/ops/_op_impl/aicpu/fse_decode.py +43 -0
  306. mindspore/ops/_op_impl/aicpu/greater.py +41 -0
  307. mindspore/ops/_op_impl/aicpu/greater_equal.py +41 -0
  308. mindspore/ops/_op_impl/aicpu/index_put.py +50 -0
  309. mindspore/ops/_op_impl/aicpu/less.py +41 -0
  310. mindspore/{nn/probability/infer/variational/__init__.py → ops/_op_impl/aicpu/lgamma.py} +16 -10
  311. mindspore/ops/_op_impl/aicpu/mirror_pad.py +0 -4
  312. mindspore/ops/_op_impl/aicpu/mirror_pad_grad.py +0 -4
  313. mindspore/ops/_op_impl/aicpu/mul.py +3 -1
  314. mindspore/ops/_op_impl/aicpu/multinomial.py +14 -6
  315. mindspore/ops/_op_impl/aicpu/nllloss.py +38 -0
  316. mindspore/ops/_op_impl/aicpu/nllloss_grad.py +39 -0
  317. mindspore/ops/_op_impl/aicpu/ones_like.py +0 -2
  318. mindspore/ops/_op_impl/aicpu/polar.py +32 -0
  319. mindspore/ops/_op_impl/aicpu/polygamma.py +34 -0
  320. mindspore/ops/_op_impl/aicpu/quant_dtype_cast.py +40 -0
  321. mindspore/ops/_op_impl/aicpu/quantile.py +35 -0
  322. mindspore/ops/_op_impl/aicpu/ragged_tensor_to_sparse.py +73 -0
  323. mindspore/ops/_op_impl/aicpu/randperm_v2.py +41 -0
  324. mindspore/ops/_op_impl/aicpu/resize_bicubic.py +2 -8
  325. mindspore/ops/_op_impl/aicpu/resize_bicubic_grad.py +1 -1
  326. mindspore/ops/_op_impl/aicpu/resize_v2.py +68 -0
  327. mindspore/ops/_op_impl/aicpu/resize_v2_grad.py +68 -0
  328. mindspore/ops/_op_impl/aicpu/scatter_elements.py +4 -0
  329. mindspore/ops/_op_impl/aicpu/scatter_nd_update.py +2 -0
  330. mindspore/ops/_op_impl/aicpu/sequence_add.py +34 -0
  331. mindspore/ops/_op_impl/aicpu/sequence_add_offset.py +34 -0
  332. mindspore/ops/_op_impl/aicpu/sequence_addn.py +38 -0
  333. mindspore/ops/_op_impl/aicpu/smooth_l1_loss.py +35 -0
  334. mindspore/ops/_op_impl/aicpu/smooth_l1_loss_grad.py +37 -0
  335. mindspore/ops/_op_impl/aicpu/sparse_apply_adagrad_da.py +0 -24
  336. mindspore/ops/_op_impl/aicpu/sparse_cross.py +42 -0
  337. mindspore/ops/_op_impl/aicpu/sparse_slice.py +4 -0
  338. mindspore/ops/_op_impl/aicpu/sparse_slice_grad.py +6 -0
  339. mindspore/ops/_op_impl/aicpu/tensor_scatter_update.py +59 -0
  340. mindspore/ops/_op_impl/aicpu/trans_data.py +1 -0
  341. mindspore/ops/_op_impl/aicpu/tril_indices.py +34 -0
  342. mindspore/ops/_op_impl/aicpu/uniform.py +34 -0
  343. mindspore/ops/_op_impl/aicpu/uniform_candidate_sampler.py +1 -0
  344. mindspore/ops/_op_impl/aicpu/unique_consecutive.py +10 -2
  345. mindspore/ops/_op_impl/cpu/dynamic_shape.py +5 -1
  346. mindspore/ops/_op_impl/cpu/sparse_slice.py +4 -0
  347. mindspore/ops/_op_impl/cpu/sparse_slice_grad.py +6 -0
  348. mindspore/ops/_op_impl/cpu/tensor_shape.py +5 -1
  349. mindspore/ops/_op_impl/tbe/__init__.py +27 -611
  350. mindspore/ops/_op_impl/tbe/assign_add_ds.py +1 -0
  351. mindspore/ops/_op_impl/tbe/atomic_addr_clean.py +1 -1
  352. mindspore/ops/_op_impl/tbe/avg_pool_3d_grad.py +1 -1
  353. mindspore/ops/_op_impl/tbe/batch_matmul_ds.py +1 -0
  354. mindspore/ops/_op_impl/tbe/batch_to_space.py +1 -1
  355. mindspore/ops/_op_impl/tbe/batch_to_space_nd.py +1 -1
  356. mindspore/ops/_op_impl/tbe/bn_infer_grad.py +4 -2
  357. mindspore/ops/_op_impl/tbe/bn_training_update.py +0 -1
  358. mindspore/ops/_op_impl/tbe/bn_training_update_ds.py +0 -1
  359. mindspore/ops/_op_impl/tbe/broadcast_to_ds.py +6 -4
  360. mindspore/ops/_op_impl/tbe/cast.py +0 -2
  361. mindspore/ops/_op_impl/tbe/cast_ds.py +3 -3
  362. mindspore/ops/_op_impl/tbe/data_format_dim_map_ds.py +1 -0
  363. mindspore/ops/_op_impl/tbe/depthwise_conv2d.py +2 -2
  364. mindspore/ops/_op_impl/tbe/dynamic_atomic_addr_clean.py +1 -1
  365. mindspore/ops/_op_impl/tbe/gather_nd.py +1 -0
  366. mindspore/ops/_op_impl/tbe/{index_add.py → inplace_index_add.py} +3 -6
  367. mindspore/ops/_op_impl/tbe/matmul_ds.py +2 -0
  368. mindspore/ops/_op_impl/tbe/npu_clear_float_status_v2.py +35 -0
  369. mindspore/ops/_op_impl/tbe/npu_get_float_status_v2.py +35 -0
  370. mindspore/ops/_op_impl/tbe/scatter_mul.py +2 -0
  371. mindspore/ops/_op_impl/tbe/scatter_nd_add.py +0 -2
  372. mindspore/ops/_op_impl/tbe/space_to_batch.py +1 -1
  373. mindspore/ops/_op_impl/tbe/space_to_batch_nd.py +1 -1
  374. mindspore/ops/_op_impl/tbe/trans_data_ds.py +15 -5
  375. mindspore/ops/_register_for_op.py +1 -0
  376. mindspore/ops/_utils/__init__.py +1 -2
  377. mindspore/ops/_utils/utils.py +19 -40
  378. mindspore/ops/_vmap/vmap_array_ops.py +116 -38
  379. mindspore/ops/_vmap/vmap_base.py +16 -9
  380. mindspore/ops/_vmap/vmap_convolution_ops.py +7 -10
  381. mindspore/ops/_vmap/vmap_grad_math_ops.py +4 -4
  382. mindspore/ops/_vmap/vmap_grad_nn_ops.py +7 -5
  383. mindspore/ops/_vmap/vmap_image_ops.py +12 -5
  384. mindspore/ops/_vmap/vmap_math_ops.py +46 -5
  385. mindspore/ops/_vmap/vmap_nn_ops.py +15 -21
  386. mindspore/ops/_vmap/vmap_random_ops.py +1 -1
  387. mindspore/ops/bprop_mindir/AdaptiveAvgPool2D_bprop.mindir +0 -0
  388. mindspore/ops/bprop_mindir/AdaptiveMaxPool2D_bprop.mindir +0 -0
  389. mindspore/ops/bprop_mindir/AvgPool3D_bprop.mindir +150 -0
  390. mindspore/ops/bprop_mindir/AvgPool_bprop.mindir +66 -0
  391. mindspore/ops/bprop_mindir/BCEWithLogitsLoss_bprop.mindir +0 -0
  392. mindspore/ops/bprop_mindir/BatchNormGrad_bprop.mindir +0 -0
  393. mindspore/ops/bprop_mindir/BiasAddGrad_bprop.mindir +0 -0
  394. mindspore/ops/bprop_mindir/BinaryCrossEntropy_bprop.mindir +33 -0
  395. mindspore/ops/bprop_mindir/BroadcastTo_bprop.mindir +220 -106
  396. mindspore/ops/bprop_mindir/CTCLoss_bprop.mindir +0 -0
  397. mindspore/ops/bprop_mindir/Conv2DBackpropFilter_bprop.mindir +240 -0
  398. mindspore/ops/bprop_mindir/Conv2DBackpropInput_bprop.mindir +247 -0
  399. mindspore/ops/bprop_mindir/Conv2DTranspose_bprop.mindir +247 -0
  400. mindspore/ops/bprop_mindir/Conv3DTranspose_bprop.mindir +315 -0
  401. mindspore/ops/bprop_mindir/Conv3D_bprop.mindir +278 -0
  402. mindspore/ops/bprop_mindir/DeformableOffsets_bprop.mindir +58 -0
  403. mindspore/ops/bprop_mindir/DepthwiseConv2dNative_bprop.mindir +138 -0
  404. mindspore/ops/bprop_mindir/Dropout2D_bprop.mindir +0 -0
  405. mindspore/ops/bprop_mindir/Dropout3D_bprop.mindir +0 -0
  406. mindspore/ops/bprop_mindir/DropoutDoMask_bprop.mindir +22 -23
  407. mindspore/ops/bprop_mindir/DropoutGenMask_bprop.mindir +16 -17
  408. mindspore/ops/bprop_mindir/DropoutGrad_bprop.mindir +27 -0
  409. mindspore/ops/bprop_mindir/Dropout_bprop.mindir +0 -0
  410. mindspore/ops/bprop_mindir/DynamicGRUV2_bprop.mindir +0 -0
  411. mindspore/ops/bprop_mindir/DynamicRNN_bprop.mindir +0 -0
  412. mindspore/ops/bprop_mindir/Elu_bprop.mindir +16 -0
  413. mindspore/ops/bprop_mindir/EmbeddingLookup_bprop.mindir +0 -0
  414. mindspore/ops/bprop_mindir/ExpandDims_bprop.mindir +39 -41
  415. mindspore/ops/bprop_mindir/FastGeLU_bprop.mindir +16 -0
  416. mindspore/ops/bprop_mindir/Flatten_bprop.mindir +41 -43
  417. mindspore/ops/bprop_mindir/GatherNd_bprop.mindir +51 -57
  418. mindspore/ops/bprop_mindir/Gather_bprop.mindir +0 -0
  419. mindspore/ops/bprop_mindir/HSigmoid_bprop.mindir +16 -0
  420. mindspore/ops/bprop_mindir/HSwish_bprop.mindir +16 -0
  421. mindspore/ops/bprop_mindir/InstanceNorm_bprop.mindir +0 -0
  422. mindspore/ops/bprop_mindir/KLDivLoss_bprop.mindir +126 -0
  423. mindspore/ops/bprop_mindir/L2Loss_bprop.mindir +15 -0
  424. mindspore/ops/bprop_mindir/L2Normalize_bprop.mindir +30 -0
  425. mindspore/ops/bprop_mindir/LRN_bprop.mindir +43 -0
  426. mindspore/ops/bprop_mindir/LayerNormGrad_bprop.mindir +0 -0
  427. mindspore/ops/bprop_mindir/LogSoftmax_bprop.mindir +23 -0
  428. mindspore/ops/bprop_mindir/MaxPool3DGradGrad_bprop.mindir +74 -0
  429. mindspore/ops/bprop_mindir/MaxPool3DGrad_bprop.mindir +74 -0
  430. mindspore/ops/bprop_mindir/MaxPool3D_bprop.mindir +75 -0
  431. mindspore/ops/bprop_mindir/MaxPoolGradGrad_bprop.mindir +65 -0
  432. mindspore/ops/bprop_mindir/MaxPoolWithArgmax_bprop.mindir +0 -0
  433. mindspore/ops/bprop_mindir/MirrorPad_bprop.mindir +27 -0
  434. mindspore/ops/bprop_mindir/Mish_bprop.mindir +35 -0
  435. mindspore/ops/bprop_mindir/MulNoNan_bprop.mindir +0 -0
  436. mindspore/ops/bprop_mindir/NLLLoss_bprop.mindir +0 -0
  437. mindspore/ops/bprop_mindir/OneHot_bprop.mindir +24 -25
  438. mindspore/ops/bprop_mindir/PReLU_bprop.mindir +0 -0
  439. mindspore/ops/bprop_mindir/Pad_bprop.mindir +0 -0
  440. mindspore/ops/bprop_mindir/Padding_bprop.mindir +0 -0
  441. mindspore/ops/bprop_mindir/RNNTLoss_bprop.mindir +29 -0
  442. mindspore/ops/bprop_mindir/ROIAlign_bprop.mindir +82 -0
  443. mindspore/ops/bprop_mindir/ReLU6_bprop.mindir +16 -0
  444. mindspore/ops/bprop_mindir/ReLUV2_bprop.mindir +0 -0
  445. mindspore/ops/bprop_mindir/ReluGrad_bprop.mindir +18 -19
  446. mindspore/ops/bprop_mindir/Reshape_bprop.mindir +53 -53
  447. mindspore/ops/bprop_mindir/ResizeBilinear_bprop.mindir +29 -0
  448. mindspore/ops/bprop_mindir/ResizeNearestNeighbor_bprop.mindir +77 -85
  449. mindspore/ops/bprop_mindir/SeLU_bprop.mindir +21 -0
  450. mindspore/ops/bprop_mindir/SigmoidCrossEntropyWithLogits_bprop.mindir +21 -0
  451. mindspore/ops/bprop_mindir/SigmoidGrad_bprop.mindir +0 -0
  452. mindspore/ops/bprop_mindir/Sigmoid_bprop.mindir +16 -0
  453. mindspore/ops/bprop_mindir/SmoothL1Loss_bprop.mindir +36 -0
  454. mindspore/ops/bprop_mindir/SoftmaxCrossEntropyWithLogits_bprop.mindir +0 -0
  455. mindspore/ops/bprop_mindir/Softplus_bprop.mindir +16 -0
  456. mindspore/ops/bprop_mindir/Softsign_bprop.mindir +33 -0
  457. mindspore/ops/bprop_mindir/SparseSoftmaxCrossEntropyWithLogits_bprop.mindir +0 -0
  458. mindspore/ops/bprop_mindir/Squeeze_bprop.mindir +37 -39
  459. mindspore/ops/bprop_mindir/StridedSlice_bprop.mindir +70 -72
  460. mindspore/ops/bprop_mindir/TanhGrad_bprop.mindir +0 -0
  461. mindspore/ops/bprop_mindir/Tanh_bprop.mindir +66 -0
  462. mindspore/ops/bprop_mindir/Tile_bprop.mindir +0 -0
  463. mindspore/ops/bprop_mindir/TopK_bprop.mindir +0 -0
  464. mindspore/ops/bprop_mindir/TupleGetItem_bprop.mindir +17 -17
  465. mindspore/ops/bprop_mindir/UpsampleNearest3D_bprop.mindir +32 -0
  466. mindspore/ops/bprop_mindir/UpsampleTrilinear3D_bprop.mindir +38 -0
  467. mindspore/ops/bprop_mindir/generate_mindir.py +2 -0
  468. mindspore/ops/composite/__init__.py +7 -8
  469. mindspore/ops/composite/base.py +101 -47
  470. mindspore/ops/composite/math_ops.py +188 -158
  471. mindspore/ops/composite/multitype_ops/_compile_utils.py +415 -170
  472. mindspore/ops/composite/multitype_ops/_constexpr_utils.py +142 -87
  473. mindspore/ops/composite/multitype_ops/add_impl.py +6 -1
  474. mindspore/ops/composite/multitype_ops/div_impl.py +2 -3
  475. mindspore/ops/composite/multitype_ops/getitem_impl.py +31 -3
  476. mindspore/ops/composite/multitype_ops/greater_equal_impl.py +31 -0
  477. mindspore/ops/composite/multitype_ops/greater_impl.py +31 -0
  478. mindspore/ops/composite/multitype_ops/in_impl.py +9 -0
  479. mindspore/ops/composite/multitype_ops/less_equal_impl.py +31 -0
  480. mindspore/ops/composite/multitype_ops/less_impl.py +31 -0
  481. mindspore/ops/composite/multitype_ops/mul_impl.py +21 -5
  482. mindspore/ops/composite/multitype_ops/not_in_impl.py +9 -0
  483. mindspore/ops/composite/multitype_ops/ones_like_impl.py +2 -4
  484. mindspore/ops/composite/multitype_ops/setitem_impl.py +21 -3
  485. mindspore/ops/composite/multitype_ops/sub_impl.py +1 -1
  486. mindspore/ops/composite/multitype_ops/zeros_like_impl.py +35 -4
  487. mindspore/ops/function/__init__.py +152 -8
  488. mindspore/ops/function/array_func.py +2555 -674
  489. mindspore/ops/function/clip_func.py +209 -13
  490. mindspore/ops/function/debug_func.py +2 -2
  491. mindspore/ops/function/grad/__init__.py +2 -1
  492. mindspore/ops/function/grad/grad_func.py +147 -62
  493. mindspore/ops/function/image_func.py +54 -38
  494. mindspore/ops/function/linalg_func.py +167 -16
  495. mindspore/ops/function/math_func.py +4849 -1492
  496. mindspore/ops/function/nn_func.py +2573 -988
  497. mindspore/ops/function/other_func.py +115 -0
  498. mindspore/ops/function/parameter_func.py +3 -3
  499. mindspore/ops/function/random_func.py +790 -73
  500. mindspore/ops/function/sparse_func.py +98 -78
  501. mindspore/ops/function/sparse_unary_func.py +54 -53
  502. mindspore/ops/function/spectral_func.py +27 -24
  503. mindspore/ops/function/vmap_func.py +22 -2
  504. mindspore/ops/functional.py +97 -37
  505. mindspore/ops/op_info_register.py +70 -28
  506. mindspore/ops/operations/__init__.py +47 -14
  507. mindspore/ops/operations/_csr_ops.py +7 -7
  508. mindspore/ops/operations/_embedding_cache_ops.py +5 -5
  509. mindspore/ops/operations/_grad_ops.py +276 -187
  510. mindspore/ops/operations/_inner_ops.py +319 -113
  511. mindspore/ops/operations/_ms_kernel.py +10 -8
  512. mindspore/ops/operations/_ocr_ops.py +9 -9
  513. mindspore/ops/operations/_opaque_predicate_registry.py +4 -0
  514. mindspore/ops/operations/_quant_ops.py +137 -102
  515. mindspore/ops/operations/_rl_inner_ops.py +121 -60
  516. mindspore/ops/operations/_scalar_ops.py +466 -0
  517. mindspore/ops/operations/_sequence_ops.py +1004 -2
  518. mindspore/ops/operations/_tensor_array.py +10 -11
  519. mindspore/ops/operations/_thor_ops.py +1 -1
  520. mindspore/ops/operations/array_ops.py +801 -466
  521. mindspore/ops/operations/comm_ops.py +51 -49
  522. mindspore/ops/operations/control_ops.py +2 -2
  523. mindspore/ops/operations/custom_ops.py +123 -44
  524. mindspore/ops/operations/debug_ops.py +24 -24
  525. mindspore/ops/operations/image_ops.py +240 -153
  526. mindspore/ops/operations/inner_ops.py +34 -50
  527. mindspore/ops/operations/linalg_ops.py +31 -9
  528. mindspore/ops/operations/math_ops.py +988 -757
  529. mindspore/ops/operations/nn_ops.py +965 -819
  530. mindspore/ops/operations/other_ops.py +51 -40
  531. mindspore/ops/operations/random_ops.py +204 -122
  532. mindspore/ops/operations/rl_ops.py +8 -9
  533. mindspore/ops/operations/sparse_ops.py +254 -93
  534. mindspore/ops/operations/spectral_ops.py +35 -3
  535. mindspore/ops/primitive.py +111 -9
  536. mindspore/parallel/_auto_parallel_context.py +189 -83
  537. mindspore/parallel/_offload_context.py +185 -0
  538. mindspore/parallel/_parallel_serialization.py +99 -7
  539. mindspore/parallel/_ps_context.py +9 -5
  540. mindspore/parallel/_recovery_context.py +1 -1
  541. mindspore/parallel/_tensor.py +7 -1
  542. mindspore/{nn/transformer → parallel/_transformer}/__init__.py +6 -6
  543. mindspore/{nn/transformer → parallel/_transformer}/layers.py +6 -37
  544. mindspore/{nn/transformer → parallel/_transformer}/loss.py +4 -7
  545. mindspore/{nn/transformer → parallel/_transformer}/moe.py +20 -16
  546. mindspore/{nn/transformer → parallel/_transformer}/op_parallel_config.py +3 -3
  547. mindspore/{nn/transformer → parallel/_transformer}/transformer.py +48 -111
  548. mindspore/parallel/_utils.py +1 -2
  549. mindspore/parallel/algo_parameter_config.py +1 -1
  550. mindspore/parallel/checkpoint_transform.py +37 -34
  551. mindspore/parallel/shard.py +17 -18
  552. mindspore/profiler/common/validator/validate_path.py +2 -2
  553. mindspore/profiler/envprofiling.py +69 -47
  554. mindspore/profiler/parser/ascend_timeline_generator.py +49 -42
  555. mindspore/profiler/parser/base_timeline_generator.py +49 -56
  556. mindspore/profiler/parser/cpu_gpu_timeline_generator.py +98 -78
  557. mindspore/profiler/parser/hwts_log_parser.py +1 -1
  558. mindspore/profiler/parser/integrator.py +15 -14
  559. mindspore/profiler/parser/minddata_analyzer.py +2 -2
  560. mindspore/profiler/parser/msadvisor_analyzer.py +12 -25
  561. mindspore/profiler/parser/msadvisor_parser.py +2 -4
  562. mindspore/profiler/parser/optime_parser.py +17 -18
  563. mindspore/profiler/parser/profiler_info.py +2 -1
  564. mindspore/profiler/profiling.py +218 -186
  565. mindspore/rewrite/__init__.py +3 -1
  566. mindspore/rewrite/api/node.py +1 -114
  567. mindspore/rewrite/api/node_type.py +3 -0
  568. mindspore/rewrite/api/pattern_engine.py +31 -1
  569. mindspore/rewrite/api/scoped_value.py +4 -4
  570. mindspore/rewrite/api/symbol_tree.py +3 -78
  571. mindspore/rewrite/api/tree_node_helper.py +1 -1
  572. mindspore/rewrite/ast_creator_register.py +1 -0
  573. mindspore/rewrite/ast_helpers/__init__.py +2 -2
  574. mindspore/rewrite/ast_helpers/ast_creator.py +1 -2
  575. mindspore/rewrite/ast_helpers/ast_finder.py +65 -0
  576. mindspore/rewrite/ast_helpers/ast_modifier.py +11 -3
  577. mindspore/rewrite/ast_transformers/flatten_recursive_stmt.py +18 -2
  578. mindspore/rewrite/namespace.py +0 -2
  579. mindspore/rewrite/node.py +157 -11
  580. mindspore/rewrite/parsers/assign_parser.py +231 -53
  581. mindspore/rewrite/parsers/class_def_parser.py +187 -109
  582. mindspore/rewrite/parsers/for_parser.py +24 -14
  583. mindspore/rewrite/parsers/function_def_parser.py +21 -4
  584. mindspore/rewrite/parsers/if_parser.py +6 -2
  585. mindspore/rewrite/sparsify/__init__.py +0 -0
  586. mindspore/rewrite/sparsify/sparse_transformer.py +448 -0
  587. mindspore/rewrite/sparsify/sparsify.py +109 -0
  588. mindspore/rewrite/sparsify/utils.py +173 -0
  589. mindspore/rewrite/symbol_tree.py +256 -133
  590. mindspore/rewrite/symbol_tree_builder.py +38 -1
  591. mindspore/run_check/_check_version.py +69 -63
  592. mindspore/run_check/run_check.py +2 -1
  593. mindspore/scipy/linalg.py +10 -114
  594. mindspore/scipy/ops.py +2 -2
  595. mindspore/scipy/ops_wrapper.py +1 -1
  596. mindspore/scipy/optimize/_bfgs.py +1 -1
  597. mindspore/scipy/optimize/_lagrange.py +200 -0
  598. mindspore/scipy/optimize/line_search.py +3 -2
  599. mindspore/scipy/optimize/minimize.py +41 -2
  600. mindspore/scipy/sparse/__init__.py +2 -2
  601. mindspore/scipy/sparse/linalg.py +4 -464
  602. mindspore/scipy/utils.py +1 -1
  603. mindspore/scipy/utils_const.py +7 -1
  604. mindspore/train/__init__.py +1 -1
  605. mindspore/train/_utils.py +28 -5
  606. mindspore/train/amp.py +273 -102
  607. mindspore/train/callback/_backup_and_restore.py +5 -5
  608. mindspore/train/callback/_callback.py +2 -2
  609. mindspore/train/callback/_checkpoint.py +3 -3
  610. mindspore/train/callback/_early_stop.py +3 -3
  611. mindspore/train/callback/_lambda_callback.py +2 -2
  612. mindspore/train/callback/_landscape.py +29 -31
  613. mindspore/train/callback/_loss_monitor.py +3 -3
  614. mindspore/train/callback/_on_request_exit.py +3 -3
  615. mindspore/train/callback/_reduce_lr_on_plateau.py +4 -4
  616. mindspore/train/callback/_summary_collector.py +23 -16
  617. mindspore/train/callback/_time_monitor.py +3 -3
  618. mindspore/train/checkpoint_pb2.py +68 -8
  619. mindspore/train/data_sink.py +15 -3
  620. mindspore/train/dataset_helper.py +10 -15
  621. mindspore/train/loss_scale_manager.py +8 -11
  622. mindspore/train/metrics/__init__.py +1 -1
  623. mindspore/train/metrics/bleu_score.py +1 -1
  624. mindspore/train/metrics/confusion_matrix.py +1 -1
  625. mindspore/train/metrics/cosine_similarity.py +1 -1
  626. mindspore/train/metrics/dice.py +2 -2
  627. mindspore/train/metrics/fbeta.py +1 -1
  628. mindspore/train/metrics/hausdorff_distance.py +4 -3
  629. mindspore/train/metrics/mean_surface_distance.py +2 -2
  630. mindspore/train/metrics/occlusion_sensitivity.py +1 -1
  631. mindspore/train/metrics/perplexity.py +1 -1
  632. mindspore/train/metrics/precision.py +1 -1
  633. mindspore/train/metrics/recall.py +1 -1
  634. mindspore/train/metrics/roc.py +2 -2
  635. mindspore/train/metrics/root_mean_square_surface_distance.py +2 -2
  636. mindspore/train/mind_ir_pb2.py +116 -37
  637. mindspore/train/model.py +45 -28
  638. mindspore/train/serialization.py +295 -188
  639. mindspore/train/summary/_summary_adapter.py +1 -1
  640. mindspore/train/summary/summary_record.py +43 -13
  641. mindspore/train/train_thor/convert_utils.py +2 -2
  642. mindspore/train/train_thor/dataset_helper.py +3 -3
  643. mindspore/version.py +1 -1
  644. {mindspore-2.0.0a0.dist-info → mindspore-2.0.0rc1.dist-info}/METADATA +3 -2
  645. {mindspore-2.0.0a0.dist-info → mindspore-2.0.0rc1.dist-info}/RECORD +648 -574
  646. mindspore/compression/__init__.py +0 -19
  647. mindspore/compression/common/constant.py +0 -124
  648. mindspore/compression/export/__init__.py +0 -19
  649. mindspore/compression/export/quant_export.py +0 -515
  650. mindspore/compression/quant/__init__.py +0 -28
  651. mindspore/compression/quant/qat.py +0 -634
  652. mindspore/compression/quant/quant_utils.py +0 -462
  653. mindspore/compression/quant/quantizer.py +0 -68
  654. mindspore/nn/layer/quant.py +0 -1868
  655. mindspore/nn/layer/rnn_utils.py +0 -90
  656. mindspore/nn/probability/dpn/__init__.py +0 -22
  657. mindspore/nn/probability/dpn/vae/__init__.py +0 -25
  658. mindspore/nn/probability/dpn/vae/cvae.py +0 -140
  659. mindspore/nn/probability/dpn/vae/vae.py +0 -124
  660. mindspore/nn/probability/infer/__init__.py +0 -22
  661. mindspore/nn/probability/infer/variational/elbo.py +0 -70
  662. mindspore/nn/probability/infer/variational/svi.py +0 -84
  663. mindspore/nn/probability/toolbox/__init__.py +0 -22
  664. mindspore/nn/probability/toolbox/anomaly_detection.py +0 -99
  665. mindspore/nn/probability/toolbox/uncertainty_evaluation.py +0 -364
  666. mindspore/nn/probability/transforms/__init__.py +0 -22
  667. mindspore/nn/probability/transforms/transform_bnn.py +0 -262
  668. mindspore/nn/probability/zhusuan/__init__.py +0 -18
  669. mindspore/nn/probability/zhusuan/framework/__init__.py +0 -18
  670. mindspore/nn/probability/zhusuan/framework/bn.py +0 -95
  671. mindspore/nn/probability/zhusuan/variational/__init__.py +0 -18
  672. mindspore/nn/probability/zhusuan/variational/elbo.py +0 -46
  673. mindspore/ops/_op_impl/aicpu/parallel_concat.py +0 -42
  674. mindspore/ops/_op_impl/tbe/gather_v2.py +0 -56
  675. mindspore/ops/bprop_mindir/AssignAdd_bprop.mindir +0 -19
  676. mindspore/ops/bprop_mindir/Cast_bprop.mindir +0 -19
  677. mindspore/ops/bprop_mindir/LogicalOr_bprop.mindir +0 -19
  678. mindspore/ops/bprop_mindir/MatMul_bprop.mindir +0 -0
  679. mindspore/ops/bprop_mindir/ReLU_bprop.mindir +0 -17
  680. mindspore/ops/bprop_mindir/Transpose_bprop.mindir +0 -0
  681. mindspore/ops/bprop_mindir/UpdateState_bprop.mindir +0 -15
  682. mindspore/ops/composite/array_ops.py +0 -241
  683. mindspore/ops/composite/clip_ops.py +0 -134
  684. mindspore/ops/composite/random_ops.py +0 -426
  685. mindspore/ops/composite/vmap_ops.py +0 -38
  686. mindspore/parallel/nn/__init__.py +0 -42
  687. mindspore/parallel/nn/loss.py +0 -22
  688. mindspore/parallel/nn/moe.py +0 -21
  689. mindspore/parallel/nn/op_parallel_config.py +0 -22
  690. mindspore/parallel/nn/transformer.py +0 -31
  691. {mindspore-2.0.0a0.dist-info → mindspore-2.0.0rc1.dist-info}/WHEEL +0 -0
  692. {mindspore-2.0.0a0.dist-info → mindspore-2.0.0rc1.dist-info}/entry_points.txt +0 -0
  693. {mindspore-2.0.0a0.dist-info → mindspore-2.0.0rc1.dist-info}/top_level.txt +0 -0
@@ -23,8 +23,7 @@ from mindspore import log as logger
23
23
  from mindspore._checkparam import _check_3d_int_or_tuple
24
24
  from mindspore import context
25
25
  from mindspore.ops import signature as sig
26
- from mindspore._checkparam import Validator as validator
27
- from mindspore._checkparam import Rel
26
+ from mindspore import _checkparam as validator
28
27
  from mindspore.common import dtype as mstype
29
28
  from mindspore.common._decorator import deprecated
30
29
  from mindspore.ops.primitive import Primitive
@@ -117,7 +116,7 @@ class CeLU(Primitive):
117
116
  def __init__(self, alpha=1.0):
118
117
  """Initialize CeLU"""
119
118
  validator.check_value_type("alpha", alpha, [float], self.name)
120
- validator.check_float(alpha, 0.0, Rel.NE, "alpha", self.name)
119
+ validator.check_float(alpha, 0.0, validator.NE, "alpha", self.name)
121
120
  self.alpha = alpha
122
121
  self.add_prim_attr('alpha', self.alpha)
123
122
 
@@ -148,10 +147,13 @@ class AdaptiveAvgPool3D(Primitive):
148
147
  r"""
149
148
  AdaptiveAvgPool3D operation.
150
149
 
150
+ .. warning::
151
+ This is an experimental API that is subject to change or deletion.
152
+
151
153
  Refer to :func:`mindspore.ops.adaptive_avg_pool3d` for more details.
152
154
 
153
155
  Supported Platforms:
154
- ``GPU`` ``CPU``
156
+ ``Ascend`` ``GPU`` ``CPU``
155
157
 
156
158
  Examples:
157
159
  >>> import mindspore
@@ -183,7 +185,7 @@ class AdaptiveAvgPool3D(Primitive):
183
185
  for i, size in enumerate(self.output_size):
184
186
  validator.check_value_type(f"output_size[{i}]", size, [int, type(None)], self.name)
185
187
  if size is not None:
186
- validator.check_number(f"output_size[{i}]", size, 0, Rel.GE, self.name)
188
+ validator.check_number(f"output_size[{i}]", size, 0, validator.GE, self.name)
187
189
 
188
190
  self.output_size = tuple(-1 if val is None else val for val in self.output_size)
189
191
 
@@ -191,67 +193,21 @@ class AdaptiveAvgPool3D(Primitive):
191
193
  self.init_prim_io_names(inputs=['x'], outputs=['y'])
192
194
 
193
195
 
194
- class AdaptiveAvgPool2DV1(Primitive):
196
+ class AdaptiveAvgPool2D(Primitive):
195
197
  r"""
196
- AdaptiveAvgPool2DV1 operation.
197
-
198
- This operator applies a 2D adaptive average pooling to an input signal composed of multiple input planes.
199
- That is, for any input size, the size of the specified output is H x W.
200
- The number of output features is equal to the number of input planes.
198
+ AdaptiveAvgPool2D operation.
201
199
 
202
- The input and output data format can be "NCHW" and "CHW". N is the batch size, C is the number of channels,
203
- H is the feature height, and W is the feature width.
204
-
205
- For AdaptiveAvgPool2DV1:
206
-
207
- .. math::
208
- \begin{align}
209
- h_{start} &= floor(i * H_{in} / H_{out})\\
210
- h_{end} &= ceil((i + 1) * H_{in} / H_{out})\\
211
- w_{start} &= floor(j * W_{in} / W_{out})\\
212
- w_{end} &= ceil((j + 1) * W_{in} / W_{out})\\
213
- Output(i,j) &= \frac{\sum Input[h_{start}:h_{end}, w_{start}:w_{end}]}{(h_{end}- h_{start})
214
- * (w_{end}- w_{start})}
215
- \end{align}
216
-
217
- Args:
218
- - output_size (Union[int, tuple]): The target output size is H x W.
219
- ouput_size can be a tuple, or a single H for H x H, and H and W can be int or None
220
- which means the output size is the same as the input.
221
-
222
- Inputs:
223
- - **input_x** (Tensor) - The input of AdaptiveAvgPool2DV1, which is a 3D or 4D tensor,
224
- with float16 or float32 data type.
225
-
226
- Outputs:
227
- Tensor, with the same type as the `input_x`.
228
-
229
- Shape of the output is `input_x_shape[:len(input_x_shape) - len(out_shape)] + out_shape`.
230
-
231
- .. math::
232
- out\_shape = \begin{cases}
233
- input\_x\_shape[-2] + output\_size[1], & \text{if output_size is (None, w);}\\
234
- output\_size[0] + input\_x\_shape[-1], & \text{if output_size is (h, None);}\\
235
- input\_x\_shape[-2:], & \text{if output_size is (None, None);}\\
236
- (h, h), & \text{if output_size is h;}\\
237
- (h, w), & \text{if output_size is (h, w)}
238
- \end{cases}
239
-
240
- Raises:
241
- TypeError: If `input_x` is not a tensor.
242
- TypeError: If dtype of `input_x` is not float16 nor float32.
243
- ValueError: If `output_size` is a tuple and the length of `output_size` is not 2.
244
- ValueError: If the dimension of `input_x` is less than or equal to the dimension of `output_size`.
200
+ Refer to :func:`mindspore.ops.adaptive_avg_pool2d` for more details.
245
201
 
246
202
  Supported Platforms:
247
- ``Ascend`` ``CPU``
203
+ ``GPU``
248
204
 
249
205
  Examples:
250
206
  >>> # case 1: output_size=(None, 2)
251
207
  >>> input_x = Tensor(np.array([[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]],
252
208
  ... [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]],
253
209
  ... [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]]), mindspore.float32)
254
- >>> adaptive_avg_pool_2d = ops.AdaptiveAvgPool2DV1((None, 2))
210
+ >>> adaptive_avg_pool_2d = ops.AdaptiveAvgPool2D((None, 2))
255
211
  >>> output = adaptive_avg_pool_2d(input_x)
256
212
  >>> print(output)
257
213
  [[[1.5 2.5]
@@ -264,7 +220,7 @@ class AdaptiveAvgPool2DV1(Primitive):
264
220
  [4.5 5.5]
265
221
  [7.5 8.5]]]
266
222
  >>> # case 2: output_size=2
267
- >>> adaptive_avg_pool_2d = ops.AdaptiveAvgPool2DV1(2)
223
+ >>> adaptive_avg_pool_2d = ops.AdaptiveAvgPool2D(2)
268
224
  >>> output = adaptive_avg_pool_2d(input_x)
269
225
  >>> print(output)
270
226
  [[[3. 4.]
@@ -274,7 +230,7 @@ class AdaptiveAvgPool2DV1(Primitive):
274
230
  [[3. 4.]
275
231
  [6. 7.]]]
276
232
  >>> # case 3: output_size=(1, 2)
277
- >>> adaptive_avg_pool_2d = ops.AdaptiveAvgPool2DV1((1, 2))
233
+ >>> adaptive_avg_pool_2d = ops.AdaptiveAvgPool2D((1, 2))
278
234
  >>> output = adaptive_avg_pool_2d(input_x)
279
235
  >>> print(output)
280
236
  [[[4.5 5.5]]
@@ -284,77 +240,38 @@ class AdaptiveAvgPool2DV1(Primitive):
284
240
 
285
241
  @prim_attr_register
286
242
  def __init__(self, output_size):
287
- """Initialize AdaptiveAvgPool2DV1."""
243
+ """Initialize AdaptiveAvgPool2D."""
288
244
  self.init_prim_io_names(inputs=['x'], outputs=['y'])
289
245
  validator.check_value_type("output_size", output_size, [int, tuple], self.name)
290
246
  if isinstance(output_size, tuple):
291
- validator.check_int(len(output_size), 2, Rel.EQ, 'length of output_size', self.name)
247
+ validator.check_int(len(output_size), 2, validator.EQ, 'length of output_size', self.name)
292
248
  self.output_size = (output_size, output_size) if isinstance(self.output_size, int) else output_size
293
249
  for i, size in enumerate(self.output_size):
294
250
  validator.check_value_type(f"output_size[{i}]", size, [int, type(None)], self.name)
295
251
  if size is not None:
296
- validator.check_number(f"output_size[{i}]", size, 0, Rel.GE, self.name)
252
+ validator.check_number(f"output_size[{i}]", size, 0, validator.GE, self.name)
297
253
 
298
254
  self.output_size = tuple(-1 if val is None else val for val in self.output_size)
299
255
  self.add_prim_attr('output_size', self.output_size)
300
256
 
301
257
 
302
- class AdaptiveAvgPool2D(AdaptiveAvgPool2DV1):
258
+ class AdaptiveMaxPool2D(Primitive):
303
259
  r"""
304
- 2D adaptive average pooling for temporal data.
260
+ Performs 2D adaptive max pooling on a multi-plane input signal.
305
261
 
306
- Refer to :func:`mindspore.ops.adaptive_avg_pool2d` for more details.
307
-
308
- Supported Platforms:
309
- ``GPU``
310
-
311
- Examples:
312
- >>> # case 1: output_size=(None, 2)
313
- >>> input_x = Tensor(np.array([[[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]],
314
- ... [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]],
315
- ... [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]]]), mindspore.float32)
316
- >>> adaptive_avg_pool_2d = ops.AdaptiveAvgPool2D((None, 2))
317
- >>> output = adaptive_avg_pool_2d(input_x)
318
- >>> print(output)
319
- [[[[1.5 2.5]
320
- [4.5 5.5]
321
- [7.5 8.5]]
322
- [[1.5 2.5]
323
- [4.5 5.5]
324
- [7.5 8.5]]
325
- [[1.5 2.5]
326
- [4.5 5.5]
327
- [7.5 8.5]]]]
328
- >>> # case 2: output_size=2
329
- >>> adaptive_avg_pool_2d = ops.AdaptiveAvgPool2D(2)
330
- >>> output = adaptive_avg_pool_2d(input_x)
331
- >>> print(output)
332
- [[[[3. 4.]
333
- [6. 7.]]
334
- [[3. 4.]
335
- [6. 7.]]
336
- [[3. 4.]
337
- [6. 7.]]]]
338
- >>> # case 3: output_size=(1, 2)
339
- >>> adaptive_avg_pool_2d = ops.AdaptiveAvgPool2D((1, 2))
340
- >>> output = adaptive_avg_pool_2d(input_x)
341
- >>> print(output)
342
- [[[[4.5 5.5]]
343
- [[4.5 5.5]]
344
- [[4.5 5.5]]]]
345
- """
346
-
347
- @prim_attr_register
348
- def __init__(self, output_size):
349
- """Initialize AdaptiveAvgPool2D."""
350
- super(AdaptiveAvgPool2D, self).__init__(output_size)
262
+ Refer to :func:`mindspore.ops.adaptive_max_pool2d` for more details.
351
263
 
264
+ Args:
265
+ output_size (Union[int, tuple]): The target output size. `ouput_size` can be a tuple :math:`(H, W)`,
266
+ or an int H for :math:`(H, H)`. :math:`H` and :math:`W` can be int or None.
267
+ If it is None, it means the output size is the same as the input size.
352
268
 
353
- class AdaptiveMaxPool2D(Primitive):
354
- r"""
355
- Applies a 2D adaptive max pooling over an input signal composed of several input planes.
269
+ Inputs:
270
+ - **input_x** (Tensor) - The input of AdaptiveMaxPool2D, which is a 3D or 4D tensor,
271
+ with float16, float32 or float64 data type.
356
272
 
357
- Refer to :func:`mindspore.ops.adaptive_max_pool2d` for more details.
273
+ Outputs:
274
+ Tensor, with the same type as the `input_x`.
358
275
 
359
276
  Supported Platforms:
360
277
  ``Ascend`` ``GPU`` ``CPU``
@@ -366,7 +283,7 @@ class AdaptiveMaxPool2D(Primitive):
366
283
  ... [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]]]), mindspore.float32)
367
284
  >>> adaptive_max_pool_2d = ops.AdaptiveMaxPool2D((None, 2))
368
285
  >>> output = adaptive_max_pool_2d(input_x)
369
- >>> print(output)
286
+ >>> print(output[0])
370
287
  [[[[2. 3.]
371
288
  [5. 6.]
372
289
  [8. 9.]]
@@ -379,7 +296,7 @@ class AdaptiveMaxPool2D(Primitive):
379
296
  >>> # case 2: output_size=2
380
297
  >>> adaptive_max_pool_2d = ops.AdaptiveMaxPool2D(2)
381
298
  >>> output = adaptive_max_pool_2d(input_x)
382
- >>> print(output)
299
+ >>> print(output[0])
383
300
  [[[[5. 6.]
384
301
  [8. 9.]]
385
302
  [[5. 6.]
@@ -389,35 +306,45 @@ class AdaptiveMaxPool2D(Primitive):
389
306
  >>> # case 3: output_size=(1, 2)
390
307
  >>> adaptive_max_pool_2d = ops.AdaptiveMaxPool2D((1, 2))
391
308
  >>> output = adaptive_max_pool_2d(input_x)
392
- >>> print(output)
309
+ >>> print(output[0])
393
310
  [[[[8. 9.]]
394
311
  [[8. 9.]]
395
312
  [[8. 9.]]]]
396
313
  """
397
314
 
398
315
  @prim_attr_register
399
- def __init__(self, output_size, return_indices=False):
316
+ def __init__(self, output_size):
400
317
  """Initialize AdaptiveMaxPool2D."""
401
318
  validator.check_value_type("output_size", output_size, [int, tuple], self.name)
402
- validator.check_value_type("return_indices", return_indices, [bool], self.name)
403
319
  if isinstance(output_size, tuple):
404
- validator.check_int(len(output_size), 2, Rel.EQ,
320
+ validator.check_int(len(output_size), 2, validator.EQ,
405
321
  'length of output_size', self.name)
406
322
  self.output_size = (output_size, output_size) if isinstance(self.output_size, int) else output_size
407
323
  self.output_size = (-1 if self.output_size[0] is None else self.output_size[0],
408
324
  -1 if self.output_size[1] is None else self.output_size[1])
409
325
  for size in self.output_size:
410
- validator.check_number("output_size", size, -1, Rel.GE, None)
326
+ validator.check_number("output_size", size, -1, validator.GE, None)
411
327
  self.add_prim_attr('output_size', self.output_size)
412
- self.add_prim_attr('return_indices', return_indices)
413
328
 
414
329
 
415
330
  class AdaptiveMaxPool3D(Primitive):
416
331
  r"""
417
- Applies a 3D adaptive max pooling over an input signal composed of several input planes.
332
+ Performs 3D adaptive max pooling on a multi-plane input signal.
418
333
 
419
334
  Refer to :func:`mindspore.ops.adaptive_max_pool3d` for more details.
420
335
 
336
+ Inputs:
337
+ - **x** (Tensor) - Tensor, with shape :math:`(C, D, H, W)` or :math:`(N, C, D, H, W)`.
338
+ - **output_size** (Union[int, tuple]) - The specified output size, which is an integer that represents depth,
339
+ height and width, or a tuple of three int numbers that represent depth, height and width respectively.
340
+ The value must be a positive integer. If it is None, the output size and input size of the corresponding
341
+ dimension are the same.
342
+
343
+ Outputs:
344
+ - **y** (Tensor) - Tensor, with the same number of dims and data type as the `input`.
345
+ - **argmax** (Tensor) - Tensor, the indices of max value, which has the same shape as the
346
+ `y` and it's data type is int32.
347
+
421
348
  Supported Platforms:
422
349
  ``GPU`` ``CPU``
423
350
 
@@ -504,7 +431,7 @@ class Softplus(Primitive):
504
431
 
505
432
  .. math::
506
433
 
507
- \text{output} = \log(1 + \exp(\text{x})),
434
+ \text{output} = \log(1 + \exp(\text{x}))
508
435
 
509
436
  Inputs:
510
437
  - **input_x** (Tensor) - Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
@@ -595,7 +522,7 @@ class ReLUV3(Primitive):
595
522
  Inputs:
596
523
  - **input_x** (Tensor) - Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
597
524
  additional dimensions, data type is
598
- `number <https://www.mindspore.cn/docs/en/r2.0.0-alpha/api_python/mindspore.html#mindspore.dtype>`_.
525
+ `number <https://www.mindspore.cn/docs/en/r2.0/api_python/mindspore.html#mindspore.dtype>`_.
599
526
 
600
527
  Outputs:
601
528
  Tensor of shape :math:`(N, *)`, with the same type and shape as the `input_x`.
@@ -651,15 +578,13 @@ class Mish(PrimitiveWithInfer):
651
578
  >>> x = Tensor(np.array([[-1.0, 4.0, -8.0], [2.0, -5.0, 9.0]]), mindspore.float32)
652
579
  >>> mish = ops.Mish()
653
580
  >>> output = mish(x)
654
- >>> print(output)
655
- [[-0.3034014 3.9974129 -0.0026832]
656
- [ 1.9439590 -0.0033576 9.0000000]]
581
+ >>> print(output.shape)
582
+ (2, 3)
657
583
  """
658
584
 
659
585
  @prim_attr_register
660
586
  def __init__(self):
661
587
  """Initialize Mish"""
662
- super().__init__("Mish")
663
588
  self.init_prim_io_names(inputs=['x'], outputs=['output'])
664
589
 
665
590
 
@@ -707,7 +632,6 @@ class SeLU(Primitive):
707
632
  @prim_attr_register
708
633
  def __init__(self):
709
634
  """Initialize SeLU"""
710
- super().__init__("SeLU")
711
635
  self.init_prim_io_names(inputs=['input_x'], outputs=['output'])
712
636
 
713
637
 
@@ -834,7 +758,7 @@ class Elu(Primitive):
834
758
  def __init__(self, alpha=1.0):
835
759
  """Initialize Elu"""
836
760
  validator.check_value_type("alpha", alpha, [float], self.name)
837
- validator.check_number("alpha", alpha, 1.0, Rel.EQ, self.name)
761
+ validator.check_number("alpha", alpha, 1.0, validator.EQ, self.name)
838
762
  self.init_prim_io_names(inputs=['x'], outputs=['output', 'mask'])
839
763
 
840
764
 
@@ -887,25 +811,7 @@ class HSigmoid(Primitive):
887
811
  r"""
888
812
  Hard sigmoid activation function.
889
813
 
890
- Applies hard sigmoid activation element-wise. The input is a Tensor with any valid shape.
891
-
892
- Hard sigmoid is defined as:
893
-
894
- .. math::
895
-
896
- \text{hsigmoid}(x_{i}) = max(0, min(1, \frac{x_{i} + 3}{6})),
897
-
898
- where :math:`x_i` is an element of the input Tensor.
899
-
900
- Inputs:
901
- - **input_x** (Tensor) - Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
902
- additional dimensions.
903
-
904
- Outputs:
905
- Tensor, with the same type and shape as the `input_x`.
906
-
907
- Raises:
908
- TypeError: If `input_x` is not a Tensor.
814
+ Refer to :func:`mindspore.ops.hardsigmoid` for more details.
909
815
 
910
816
  Supported Platforms:
911
817
  ``Ascend`` ``GPU`` ``CPU``
@@ -1048,8 +954,8 @@ class InstanceNorm(PrimitiveWithInfer):
1048
954
  """Initialize InstanceNorm."""
1049
955
  self.init_prim_io_names(inputs=['x', 'gamma', 'beta', 'mean', 'variance'],
1050
956
  outputs=['y', 'save_mean', 'save_variance'])
1051
- self.epsilon = validator.check_float_range(epsilon, 0, 1, Rel.INC_RIGHT, 'epsilon', self.name)
1052
- self.momentum = validator.check_float_range(momentum, 0, 1, Rel.INC_BOTH, 'momentum', self.name)
957
+ self.epsilon = validator.check_float_range(epsilon, 0, 1, validator.INC_RIGHT, 'epsilon', self.name)
958
+ self.momentum = validator.check_float_range(momentum, 0, 1, validator.INC_BOTH, 'momentum', self.name)
1053
959
  self._update_parameter = True
1054
960
  self.add_prim_attr('side_effect_mem', True)
1055
961
 
@@ -1153,8 +1059,8 @@ class InstanceNormV2(Primitive):
1153
1059
  outputs=['y', 'batch_mean', 'batch_variance'])
1154
1060
  validator.check_is_float(epsilon, 'epsilon', self.name)
1155
1061
  validator.check_is_float(momentum, 'momentum', self.name)
1156
- validator.check_float_range(epsilon, 0, 1, Rel.INC_RIGHT, 'epsilon', self.name)
1157
- validator.check_float_range(momentum, 0, 1, Rel.INC_BOTH, 'momentum', self.name)
1062
+ validator.check_float_range(epsilon, 0, 1, validator.INC_RIGHT, 'epsilon', self.name)
1063
+ validator.check_float_range(momentum, 0, 1, validator.INC_BOTH, 'momentum', self.name)
1158
1064
  validator.check_bool(is_training, "is_training", self.name)
1159
1065
 
1160
1066
 
@@ -1196,8 +1102,8 @@ class BNTrainingUpdate(Primitive):
1196
1102
  validator.check_value_type("isRef", isRef, [bool], self.name)
1197
1103
  validator.check_value_type("epsilon", epsilon, [float], self.name)
1198
1104
  validator.check_value_type("factor", factor, [float], self.name)
1199
- self.epsilon = validator.check_float_range(epsilon, 0, 1, Rel.INC_RIGHT, 'epsilon', 'BNTrainingUpdate')
1200
- self.factor = validator.check_float_range(factor, 0, 1, Rel.INC_BOTH, 'factor', 'BNTrainingUpdate')
1105
+ self.epsilon = validator.check_float_range(epsilon, 0, 1, validator.INC_RIGHT, 'epsilon', 'BNTrainingUpdate')
1106
+ self.factor = validator.check_float_range(factor, 0, 1, validator.INC_BOTH, 'factor', 'BNTrainingUpdate')
1201
1107
  self.format = validator.check_string(data_format, ['NCHW', 'NHWC'], 'format', self.name)
1202
1108
  if context.get_context("device_target") != "GPU" and self.format == "NHWC":
1203
1109
  raise ValueError(f"For '{self.name}', the 'NHWC' format is only supported in GPU target, "
@@ -1221,8 +1127,9 @@ class BatchNorm(PrimitiveWithInfer):
1221
1127
 
1222
1128
  y = \frac{x - mean}{\sqrt{variance + \epsilon}} * \gamma + \beta
1223
1129
 
1224
- where :math:`\gamma` is scale, :math:`\beta` is bias, :math:`\epsilon` is epsilon, :math:`mean` is the mean of x,
1225
- :math:`variance` is the variance of x.
1130
+ where :math:`\gamma` is scale, :math:`\beta` is bias, :math:`\epsilon` is epsilon,
1131
+ :math:`mean` is the mean of :math:`x`,
1132
+ :math:`variance` is the variance of :math:`x`.
1226
1133
 
1227
1134
  .. warning::
1228
1135
  - If the operation is used for inference, and outputs "reserve_space_1" and "reserve_space_2" are available,
@@ -1236,8 +1143,8 @@ class BatchNorm(PrimitiveWithInfer):
1236
1143
  momentum (float): The hyper parameter to compute moving average for running_mean and running_var
1237
1144
  (e.g. :math:`new\_running\_mean = (1 - momentum) * running\_mean + momentum * current\_mean`).
1238
1145
  Momentum value must be [0, 1]. Default: 0.1.
1239
- data_format (str): The optional value for data format, is 'NHWC' or 'NCHW'.
1240
- Default: "NCHW".
1146
+ data_format (str): The optional value for data format, is 'NHWC' or 'NCHW', and the 'NHWC' format
1147
+ is only supported in GPU target. Default: "NCHW".
1241
1148
 
1242
1149
  Inputs:
1243
1150
  If `is_training` is False, inputs are Tensors.
@@ -1273,7 +1180,7 @@ class BatchNorm(PrimitiveWithInfer):
1273
1180
  TypeError: If dtype of `input_x`, `scale` is neither float16 nor float32.
1274
1181
 
1275
1182
  Supported Platforms:
1276
- ``Ascend`` ``CPU`` ``GPU``
1183
+ ``Ascend`` ``GPU`` ``CPU``
1277
1184
 
1278
1185
  Examples:
1279
1186
  >>> input_x = Tensor(np.ones([2, 2]), mindspore.float32)
@@ -1304,8 +1211,8 @@ class BatchNorm(PrimitiveWithInfer):
1304
1211
  else:
1305
1212
  self.add_prim_attr('side_effect_mem', True)
1306
1213
  validator.check_value_type('is_training', is_training, (bool,), self.name)
1307
- validator.check_float_range(epsilon, 0, 1, Rel.INC_RIGHT, 'epsilon', self.name)
1308
- validator.check_float_range(momentum, 0, 1, Rel.INC_BOTH, 'momentum', self.name)
1214
+ validator.check_float_range(epsilon, 0, 1, validator.INC_RIGHT, 'epsilon', self.name)
1215
+ validator.check_float_range(momentum, 0, 1, validator.INC_BOTH, 'momentum', self.name)
1309
1216
  self.format = validator.check_string(data_format, ['NCHW', 'NHWC'], 'format', self.name)
1310
1217
  if context.get_context("device_target") != "GPU" and self.format == "NHWC":
1311
1218
  raise ValueError(f"For '{self.name}', the 'NHWC' format is only supported in GPU target, "
@@ -1318,12 +1225,12 @@ class BatchNorm(PrimitiveWithInfer):
1318
1225
  def infer_shape(self, input_x, scale, bias, mean, variance):
1319
1226
  input_x_channel = input_x[-1] if self.format == "NHWC" else input_x[1]
1320
1227
  validator.check_equal_int(len(scale), 1, "scale rank", self.name)
1321
- validator.check("scale shape", scale, "bias shape", bias, Rel.EQ, self.name)
1322
- validator.check("scale shape[0]", scale[0], "input_x channel", input_x_channel, Rel.EQ, self.name)
1228
+ validator.check("scale shape", scale, "bias shape", bias, validator.EQ, self.name)
1229
+ validator.check("scale shape[0]", scale[0], "input_x channel", input_x_channel, validator.EQ, self.name)
1323
1230
  if not self.is_training:
1324
1231
  validator.check_equal_int(len(mean), 1, "mean rank", self.name)
1325
- validator.check("mean shape", mean, "variance shape", variance, Rel.EQ, self.name)
1326
- validator.check("mean shape", mean, "scale shape", scale, Rel.EQ, self.name)
1232
+ validator.check("mean shape", mean, "variance shape", variance, validator.EQ, self.name)
1233
+ validator.check("mean shape", mean, "scale shape", scale, validator.EQ, self.name)
1327
1234
  return input_x, scale, scale, scale, scale
1328
1235
 
1329
1236
  def infer_dtype(self, input_x, scale, bias, mean, variance):
@@ -1337,7 +1244,90 @@ class Conv2D(Primitive):
1337
1244
  r"""
1338
1245
  2D convolution layer.
1339
1246
 
1340
- Refer to :func:`mindspore.ops.conv2d` for more details.
1247
+ Applies a 2D convolution over an input tensor which is typically of shape :math:`(N, C_{in}, H_{in}, W_{in})`,
1248
+ where :math:`N` is batch size, :math:`C` is channel number, :math:`H` is height, :math:`W` is width, :math:`X_i` is
1249
+ the :math:`i^{th}` input value and :math:`b_i` indicates the deviation value of the :math:`i^{th}` input value.
1250
+ For each batch of shape :math:`(C_{in}, H_{in}, W_{in})`, the formula is defined as:
1251
+
1252
+ .. math::
1253
+
1254
+ out_j = \sum_{i=0}^{C_{in} - 1} ccor(W_{ij}, X_i) + b_j,
1255
+
1256
+ where :math:`ccor` is the cross correlation operator, :math:`C_{in}` is the input channel number, :math:`j` ranges
1257
+ from :math:`0` to :math:`C_{out} - 1`, :math:`W_{ij}` corresponds to the :math:`i`-th channel of the :math:`j`-th
1258
+ filter and :math:`out_{j}` corresponds to the :math:`j`-th channel of the output. :math:`W_{ij}` is a slice
1259
+ of kernel and it has shape :math:`(\text{kernel_size[0]}, \text{kernel_size[1]})`,
1260
+ where :math:`\text{kernel_size[0]}` and :math:`\text{kernel_size[1]}` are the height and width of the
1261
+ convolution kernel. The full kernel has shape
1262
+ :math:`(C_{out}, C_{in} / \text{group}, \text{kernel_size[0]}, \text{kernel_size[1]})`,
1263
+ where group is the group number to split the input in the channel dimension.
1264
+
1265
+ If the 'pad_mode' is set to be "pad", the output height and width will be
1266
+ :math:`\left \lfloor{1 + \frac{H_{in} + \text{padding[0]} + \text{padding[1]} - \text{kernel_size[0]} -
1267
+ (\text{kernel_size[0]} - 1) \times (\text{dilation[0]} - 1) }{\text{stride[0]}}} \right \rfloor` and
1268
+ :math:`\left \lfloor{1 + \frac{W_{in} + \text{padding[2]} + \text{padding[3]} - \text{kernel_size[1]} -
1269
+ (\text{kernel_size[1]} - 1) \times (\text{dilation[1]} - 1) }{\text{stride[1]}}} \right \rfloor` respectively.
1270
+ Where :math:`dilation` is Spacing between kernel elements, :math:`stride` is The step length of each step,
1271
+ :math:`padding` is zero-padding added to both sides of the input.
1272
+
1273
+ The first introduction can be found in paper `Gradient Based Learning Applied to Document Recognition
1274
+ <http://vision.stanford.edu/cs598_spring07/papers/Lecun98.pdf>`_.
1275
+
1276
+ Note:
1277
+ On Ascend platform, :math:`group = 1` must be satisfied.
1278
+
1279
+ Args:
1280
+ out_channel (int): The number of output channel :math:`C_{out}`.
1281
+ kernel_size (Union[int, tuple[int]]): The data type is int or a tuple of 2 integers. Specifies the height
1282
+ and width of the 2D convolution window. Single int means the value is for both the height and the width of
1283
+ the kernel. A tuple of 2 ints means the first value is for the height and the other is for the
1284
+ width of the kernel.
1285
+ mode (int): Modes for different convolutions. The value is currently not used. Default: 1.
1286
+ pad_mode (str): Specifies padding mode. The optional values are
1287
+ "same", "valid" and "pad". Default: "valid".
1288
+
1289
+ - same: Adopts the way of completion. The height and width of the output will be equal to
1290
+ the input `x` divided by stride. The padding will be evenly calculated in top and bottom,
1291
+ left and right possiblily.
1292
+ Otherwise, the last extra padding will be calculated from the bottom and the right side.
1293
+ If this mode is set, `pad` must be 0.
1294
+
1295
+ - valid: Adopts the way of discarding. The possible largest height and width of output will be returned
1296
+ without padding. Extra pixels will be discarded. If this mode is set, `pad` must be 0.
1297
+
1298
+ - pad: Implicit paddings on both sides of the input `x`. The number of `pad` will be padded to the input
1299
+ Tensor borders. `pad` must be greater than or equal to 0.
1300
+ pad (Union(int, tuple[int])): Implicit paddings on both sides of the input `x`. If `pad` is one integer,
1301
+ the paddings of top, bottom, left and right are the same, equal to pad. If `pad` is a tuple
1302
+ with four integers, the paddings of top, bottom, left and right will be equal to pad[0],
1303
+ pad[1], pad[2], and pad[3] accordingly. Default: 0.
1304
+ stride (Union(int, tuple[int])): The distance of kernel moving, an int number that represents
1305
+ the height and width of movement are both strides, or a tuple of two int numbers that
1306
+ represent height and width of movement respectively. Default: 1.
1307
+ dilation (Union(int, tuple[int])): The data type is int or a tuple of 2 integers. Specifies the dilation rate
1308
+ to use for dilated convolution. If set to be :math:`k > 1`, there will
1309
+ be :math:`k - 1` pixels skipped for each sampling location. Its value must
1310
+ be greater than or equal to 1 and bounded by the height and width of the
1311
+ input `x`. Default: 1.
1312
+ group (int): Splits input into groups. Default: 1.
1313
+ data_format (str): The optional value for data format, is 'NHWC' or 'NCHW'. Default: "NCHW".
1314
+
1315
+ Inputs:
1316
+ - **x** (Tensor) - Tensor of shape :math:`(N, C_{in}, H_{in}, W_{in})`.
1317
+ - **weight** (Tensor) - Set size of kernel is :math:`(\text{kernel_size[0]}, \text{kernel_size[1]})`,
1318
+ then the shape is :math:`(C_{out}, C_{in}, \text{kernel_size[0]}, \text{kernel_size[1]})`.
1319
+
1320
+ Outputs:
1321
+ Tensor, the value that applied 2D convolution. The shape is :math:`(N, C_{out}, H_{out}, W_{out})`.
1322
+
1323
+ Raises:
1324
+ TypeError: If `kernel_size`, `stride`, `pad` or `dilation` is neither an int nor a tuple.
1325
+ TypeError: If `out_channel` or `group` is not an int.
1326
+ ValueError: If `kernel_size`, `stride` or `dilation` is less than 1.
1327
+ ValueError: If `pad_mode` is not one of 'same', 'valid' or 'pad'.
1328
+ ValueError: If `pad` is a tuple whose length is not equal to 4.
1329
+ ValueError: If `pad_mode` it not equal to 'pad' and `pad` is not equal to (0, 0, 0, 0).
1330
+ ValueError: If `data_format` is neither 'NCHW' nor 'NHWC'.
1341
1331
 
1342
1332
  Supported Platforms:
1343
1333
  ``Ascend`` ``GPU`` ``CPU``
@@ -1400,16 +1390,15 @@ class Conv2D(Primitive):
1400
1390
 
1401
1391
  class DataFormatVecPermute(Primitive):
1402
1392
  r"""
1403
- Permute input tensor from src_format to dst_format.
1393
+ Converts the input tensor from the `src_format` to the `dst_format` by permuting its dimensions.
1404
1394
 
1405
1395
  Args:
1406
- src_format (str, optional): An optional value for source data format. The format can be 'NHWC' and 'NCHW'.
1407
- Default: 'NHWC'.
1408
- dst_format (str, optional): An optional value for destination data format. The format can be 'NHWC' and 'NCHW'.
1409
- Default: 'NCHW'.
1396
+ src_format (str, optional): the source data format, which can be 'NHWC' and 'NCHW'. Default: 'NHWC'.
1397
+ dst_format (str, optional): the target data format, which can be 'NHWC' and 'NCHW'. Default: 'NCHW'.
1410
1398
 
1411
1399
  Inputs:
1412
- - **input_x** (Tensor) - A Tensor of shape (4, ) or (4, 2) in source data format. Only supports int32 and int64.
1400
+ - **input_x** (Tensor) - A Tensor of shape :math:`(4, )` or :math:`(4, 2)` in source data format.
1401
+ Supports int32 and int64 datatype.
1413
1402
 
1414
1403
  Outputs:
1415
1404
  Tensor, has the same data type and shape as the `input_x`.
@@ -1418,10 +1407,10 @@ class DataFormatVecPermute(Primitive):
1418
1407
  TypeError: If `input_x` is not a Tensor.
1419
1408
  TypeError: If dtype of `input_x` is neither int32 nor int64.
1420
1409
  ValueError: If `src_format` or `dst_format` is not a str in ['NHWC', 'NCHW'].
1421
- ValueError: If input_x shape is not (4, ) or (4, 2).
1410
+ ValueError: If `input_x` shape is not :math:`(4, )` or :math:`(4, 2)`.
1422
1411
 
1423
1412
  Supported Platforms:
1424
- ``GPU`` ``CPU``
1413
+ ``Ascend`` ``GPU`` ``CPU``
1425
1414
 
1426
1415
  Examples:
1427
1416
  >>> class Net(nn.Cell):
@@ -1505,8 +1494,8 @@ class DepthwiseConv2dNative(PrimitiveWithInfer):
1505
1494
  def infer_shape(self, x_shape, w_shape, b_shape=None):
1506
1495
  validator.check_equal_int(len(w_shape), 4, "weight rank", self.name)
1507
1496
  validator.check_equal_int(len(x_shape), 4, "x rank", self.name)
1508
- validator.check("x_shape[1]", x_shape[1], "w_shape[1]", w_shape[1], Rel.EQ, self.name)
1509
- validator.check('kernel_size', self.kernel_size, 'w_shape[2:4]', tuple(w_shape[2:4]), Rel.EQ, self.name)
1497
+ validator.check("x_shape[1]", x_shape[1], "w_shape[1]", w_shape[1], validator.EQ, self.name)
1498
+ validator.check('kernel_size', self.kernel_size, 'w_shape[2:4]', tuple(w_shape[2:4]), validator.EQ, self.name)
1510
1499
 
1511
1500
  kernel_size_n, _, kernel_size_h, kernel_size_w = w_shape
1512
1501
  _, _, stride_h, stride_w = self.stride
@@ -1804,55 +1793,11 @@ class MaxPoolV1(Primitive):
1804
1793
 
1805
1794
  class MaxPoolWithArgmax(Primitive):
1806
1795
  r"""
1807
- Performs max pooling on the input Tensor and returns both max values and indices.
1808
-
1809
- Typically the input is of shape :math:`(N_{in}, C_{in}, H_{in}, W_{in})`, MaxPool outputs
1810
- regional maximum in the :math:`(H_{in}, W_{in})`-dimension. Given kernel size
1811
- :math:`ks = (h_{ker}, w_{ker})` and stride :math:`s = (s_0, s_1)`, the operation is as follows:
1812
-
1813
- .. math::
1814
- \text{output}(N_i, C_j, h, w) = \max_{m=0, \ldots, h_{ker}-1} \max_{n=0, \ldots, w_{ker}-1}
1815
- \text{input}(N_i, C_j, s_0 \times h + m, s_1 \times w + n)
1816
-
1817
- Args:
1818
- kernel_size (Union[int, tuple[int]]): The size of kernel used to take the maximum value and argmax
1819
- value, is an int number that represents height and width of the kernel, or a tuple of
1820
- two int numbers that represent height and width respectively. Default: 1.
1821
- strides (Union[int, tuple[int]]): The distance of kernel moving, an int number that represents
1822
- not only the height of movement but also the width of movement, or a tuple of two int numbers that
1823
- represent height and width of movement respectively. Default: 1.
1824
- pad_mode (str): The optional value for pad mode, is "same" or "valid".
1825
- Default: "valid".
1826
-
1827
- - same: Adopts the way of completion. The height and width of the output will be the same as
1828
- the input. The total number of padding will be calculated in horizontal and vertical
1829
- directions and evenly distributed to top, bottom, left and right if possible.
1830
- Otherwise, the last extra padding will be done from the bottom and the right side.
1831
-
1832
- - valid: Adopts the way of discarding. The possible largest height and width of output
1833
- will be returned without padding. Extra pixels will be discarded.
1834
-
1835
- data_format (str) : The optional value for data format, is 'NHWC' or 'NCHW'.
1836
- Default: 'NCHW'.
1837
-
1838
- Inputs:
1839
- - **x** (Tensor) - Tensor of shape :math:`(N, C_{in}, H_{in}, W_{in})`.
1840
- Data type must be float16 or float32.
1841
-
1842
- Outputs:
1843
- Tuple of 2 Tensors, representing the maxpool result and where the max values are generated.
1844
-
1845
- - **output** (Tensor) - Maxpooling result, with shape :math:`(N, C_{out}, H_{out}, W_{out})`.
1846
- It has the same data type as `x`.
1847
- - **mask** (Tensor) - Max values' index represented by the mask. Data type is int32.
1848
-
1849
- Raises:
1850
- TypeError: If the data type of `x` is neither float16 nor float32.
1851
- TypeError: If `kernel_size` or `strides` is neither an int nor a tuple.
1852
- TypeError: If `x` is not a Tensor.
1796
+ `ops.MaxPoolWithArgmax` is deprecated from version 2.0 and will be removed in a future version,
1797
+ use `ops.MaxPoolWithArgmaxV2` instead.
1853
1798
 
1854
1799
  Supported Platforms:
1855
- ``Ascend`` ``GPU`` ``CPU``
1800
+ Deprecated
1856
1801
 
1857
1802
  Examples:
1858
1803
  >>> x = Tensor(np.arange(1 * 3 * 3 * 4).reshape((1, 3, 3, 4)), mindspore.float32)
@@ -1867,6 +1812,7 @@ class MaxPoolWithArgmax(Primitive):
1867
1812
  [33. 34. 35.]]]]
1868
1813
  """
1869
1814
 
1815
+ @deprecated("2.0", "ops.MaxPoolWithArgmaxV2", False)
1870
1816
  @prim_attr_register
1871
1817
  def __init__(self, kernel_size=1, strides=1, pad_mode="valid", data_format="NCHW"):
1872
1818
  """Initialize MaxPoolWithArgmax."""
@@ -1891,7 +1837,7 @@ class MaxPoolWithArgmax(Primitive):
1891
1837
  self.add_prim_attr("strides", self.strides)
1892
1838
 
1893
1839
 
1894
- class MaxPool3D(PrimitiveWithInfer):
1840
+ class MaxPool3D(Primitive):
1895
1841
  r"""
1896
1842
  Applies a 3D max pooling over an input Tensor which can be regarded as a composition of 3D planes.
1897
1843
 
@@ -1936,7 +1882,7 @@ class MaxPool3D(PrimitiveWithInfer):
1936
1882
 
1937
1883
  Inputs:
1938
1884
  - **x** (Tensor) - Tensor of shape :math:`(N, C, D_{in}, H_{in}, W_{in})`.
1939
- Data type must be float16 or float32.
1885
+ Data type must be float16, float32 or float64.
1940
1886
 
1941
1887
  Outputs:
1942
1888
  Tensor, with shape :math:`(N, C, D_{out}, H_{out}, W_{out})`. Has the data type of `x`.
@@ -2003,55 +1949,15 @@ class MaxPool3D(PrimitiveWithInfer):
2003
1949
  validator.check_non_negative_int(item, 'pad_list item', self.name)
2004
1950
  self.add_prim_attr("pad_list", self.pad_list)
2005
1951
 
2006
- def infer_shape(self, x_shape):
2007
- validator.check_equal_int(len(x_shape), 5, "x rank", self.name)
2008
- batch, channel, input_d, input_h, input_w = x_shape
2009
- self.add_prim_attr("x_shape", x_shape)
2010
- _, _, kernel_d, kernel_h, kernel_w = self.kernel_size
2011
- _, _, stride_d, stride_h, stride_w = self.strides
2012
-
2013
- if self.pad_mode == "VALID":
2014
- out_d = math.ceil((input_d - (kernel_d - 1)) / stride_d)
2015
- out_h = math.ceil((input_h - (kernel_h - 1)) / stride_h)
2016
- out_w = math.ceil((input_w - (kernel_w - 1)) / stride_w)
2017
- elif self.pad_mode == "SAME":
2018
- out_d = math.ceil(input_d / stride_d)
2019
- out_h = math.ceil(input_h / stride_h)
2020
- out_w = math.ceil(input_w / stride_w)
2021
- else:
2022
- out_d = ((input_d + self.pad_list[0] + self.pad_list[1] -
2023
- (kernel_d - 1) - 1) / stride_d) + 1
2024
- out_h = ((input_h + self.pad_list[2] + self.pad_list[3] -
2025
- (kernel_h - 1) - 1) / stride_h) + 1
2026
- out_w = ((input_w + self.pad_list[4] + self.pad_list[5] -
2027
- (kernel_w - 1) - 1) / stride_w) + 1
2028
- if self.ceil_mode:
2029
- out_d = math.ceil(out_d)
2030
- out_h = math.ceil(out_h)
2031
- out_w = math.ceil(out_w)
2032
- else:
2033
- out_d = math.floor(out_d)
2034
- out_h = math.floor(out_h)
2035
- out_w = math.floor(out_w)
2036
- out_shape = [batch, channel, out_d, out_h, out_w]
2037
-
2038
- _check_shape('output', out_shape, self.name)
2039
- return out_shape
2040
-
2041
- def infer_dtype(self, x_dtype):
2042
- validator.check_tensor_dtype_valid("x", x_dtype, [mstype.float16, mstype.float32], self.name)
2043
- return x_dtype
2044
-
2045
1952
 
2046
1953
  class MaxUnpool2D(Primitive):
2047
1954
  r"""
2048
- Computes a partial inverse of MaxPool2D.
2049
-
2050
- MaxPool2D is not fully invertible, since the non-maximal values are lost.
1955
+ Calculates the partial inverse of MaxPool2D operation.
2051
1956
 
2052
- MaxUnpool2D takes in as input the output of MaxPool2D including the indices of
2053
- the maximal values and computes a partial inverse in which all non-maximal values
2054
- are set to zero. Typically the input is of shape :math:`(N, C, H_{in}, W_{in})` ,
1957
+ Since MaxPool2D loses non-maximal values, it is not fully invertible.
1958
+ Therefore, MaxUnpool2D takes the output of MaxPool2D, including the indices of
1959
+ the maximal values, and computes a partial inverse where all non-maximal values are set to zero.
1960
+ Typically the input is of shape :math:`(N, C, H_{in}, W_{in})` ,
2055
1961
  the output is of shape :math:`(N, C, H_{out}, W_{out})` , the operation is as follows:
2056
1962
 
2057
1963
  .. math::
@@ -2060,6 +1966,9 @@ class MaxUnpool2D(Primitive):
2060
1966
  W_{out} = (W{in} - 1) \times strides[1] - 2 \times pads[1] + ksize[1] \\
2061
1967
  \end{array}
2062
1968
 
1969
+ .. warning::
1970
+ This is an experimental API that is subject to change or deletion.
1971
+
2063
1972
  Args:
2064
1973
  ksize (Union[int, tuple[int]]): The size of kernel used to take the maximum value,
2065
1974
  is an int number that represents height and width of the kernel, or a tuple
@@ -2090,7 +1999,7 @@ class MaxUnpool2D(Primitive):
2090
1999
  - **x** (Tensor) - The input Tensor to invert.
2091
2000
  Tensor of shape :math:`(N, C, H_{in}, W_{in})` or :math:`(N, H_{in}, W_{in}, C)`.
2092
2001
  - **argmax** (Tensor) - Max values' index represented by the `argmax`.
2093
- Tensor of shape must be same with input 'x'.
2002
+ Tensor of shape must be same with input `x`.
2094
2003
  Values of `argmax` must belong to :math:`[0, H_{in} \times W_{in} - 1]`.
2095
2004
  Data type must be in int32 or int64.
2096
2005
 
@@ -2110,7 +2019,7 @@ class MaxUnpool2D(Primitive):
2110
2019
  computed by attr `ksize`, `strides` and `pads`.
2111
2020
 
2112
2021
  Supported Platforms:
2113
- ``GPU`` ``CPU``
2022
+ ``Ascend`` ``GPU`` ``CPU``
2114
2023
 
2115
2024
  Examples:
2116
2025
  >>> x = Tensor(np.array([[[[0, 1], [8, 9]]]]).astype(np.float32))
@@ -2148,12 +2057,9 @@ class MaxUnpool2D(Primitive):
2148
2057
 
2149
2058
  class MaxUnpool3D(Primitive):
2150
2059
  r"""
2151
- Computes a partial inverse of MaxUnpool3D.
2152
-
2153
- MaxUnpool3D is not fully invertible, since the non-maximal values are lost.
2060
+ Computes the inverse of :class:`mindspore.ops.MaxPool3D`.
2154
2061
 
2155
- MaxUnpool3D takes in as input the output of MaxUnpool3D including the indices of the maximal
2156
- values and computes a partial inverse in which all non-maximal values are set to zero.
2062
+ MaxUnpool3D keeps the maximal value and set all position of non-maximal values to zero.
2157
2063
  Typically the input is of shape :math:`(N, C, D_{in}, H_{in}, W_{in})`, the output is of
2158
2064
  shape :math:`(N, C, D_{out}, H_{out}, W_{out})`, the operation is as follows.
2159
2065
 
@@ -2164,55 +2070,63 @@ class MaxUnpool3D(Primitive):
2164
2070
  W_{out} = (W{in} - 1) \times strides[2] - 2 \times pads[2] + ksize[2] \\
2165
2071
  \end{array}
2166
2072
 
2073
+ .. warning::
2074
+ This is an experimental API that is subject to change or deletion.
2075
+
2167
2076
  Args:
2168
2077
  ksize (Union[int, tuple[int]]): The size of kernel used to take the maximum value,
2169
2078
  is an int number that represents depth, height and width of the kernel, or a tuple
2170
2079
  of three int numbers that represent depth, height and width respectively.
2171
- strides (Union[int, tuple[int]]): The distance of kernel moving, an int number that represents
2172
- the depth, height and width of movement are both strides, or a tuple of three int numbers that
2173
- represent depth, height and width of movement respectively.
2174
- If strides is 0 or (0, 0, 0), then strides equal to ksize. Default: 0.
2175
- pads (Union[int, tuple[int]]): The pad value to be filled. Default: 0. If `pads` is an integer,
2176
- the paddings of depth, height and width are the same, equal to pads. If `pads` is a tuple of three integers,
2177
- the padding of depth, height and width equal to pads[0], pads[1] and pads[2] correspondingly.
2178
- output_shape (tuple[int]) : The target output size is an optional input. Default: ().
2179
- If output_shape == (), then the shape of output computed by kszie, strides and pads.
2180
- If output_shape != (), then output_shape must be :math:`(N, C, D, H, W)` or
2181
- :math:`(N, D, H, W, C)` and output_shape must belong to
2080
+ strides (Union[int, tuple[int]], optional): The distance of kernel moving. Default: 0.
2081
+
2082
+ - If it is an int number, the depth, height and width of movement are all equal to `strides`.
2083
+ - If it is a tuple of three int numbers, they represent depth, height and width of movement respectively.
2084
+ - If strides is 0 or (0, 0, 0), then `strides` equal to `ksize`.
2085
+
2086
+ pads (Union[int, tuple[int]], optional): The pad value to be filled. Default: 0.
2087
+
2088
+ - If `pads` is an integer, the paddings of depth, height and width are the same, equal to pads.
2089
+ - If `pads` is a tuple of three integers, the padding of depth, height and width equal to pads[0],
2090
+ pads[1] and pads[2] correspondingly.
2091
+
2092
+ output_shape (tuple[int], optional) : The target output size. Default: ().
2093
+ If :math:`output\_shape == ()`, then the shape of output computed by kszie, strides and pads shown above.
2094
+ If :math:`output\_shape != ()`, then output_shape format must be :math:`(N, C, D, H, W)` or
2095
+ :math:`(N, D, H, W, C)` and output_shape must be in range
2182
2096
  :math:`[(N, C, D_{out} - strides[0], H_{out} - strides[1], W_{out} - strides[2]),
2183
2097
  (N, C, D_{out} + strides[0], H_{out} + strides[1], W_{out} + strides[2])]`.
2184
- data_format (str) : The optional value for data format. Currently support 'NCDHW' and 'NDHWC'. Default: 'NCDHW'.
2098
+ data_format (str, optional) : The optional value for data format. Currently
2099
+ support 'NCDHW' and 'NDHWC'. Default: 'NCDHW'.
2185
2100
 
2186
2101
  Inputs:
2187
2102
  - **x** (Tensor) - The input Tensor to invert.
2188
2103
  Tensor of shape :math:`(N, C, D_{in}, H_{in}, W_{in})` or :math:`(N, D_{in}, H_{in}, W_{in}, C)`.
2189
- - **argmax** (Tensor) - Max values' index represented by the argmax.
2190
- Tensor of shape must be same with input 'x'.
2191
- Values of argmax must belong to :math:`[0, D_{in} \times H_{in} \times W_{in} - 1]`.
2192
- Data type must be in int32 or int64.
2104
+ - **argmax** (Tensor) - Max values' index. Tensor that has the same shape as `x`.
2105
+ Values of `argmax` must be in range :math:`[0, D_{in} \times H_{in} \times W_{in} - 1]`.
2106
+ Data type must be int32 or int64.
2193
2107
 
2194
2108
  Outputs:
2195
2109
  Tensor, with shape :math:`(N, C, D_{out}, H_{out}, W_{out})` or :math:`(N, D_{out}, H_{out}, W_{out}, C)`.
2196
2110
  Has the same data type with `x`.
2197
2111
 
2198
2112
  Raises:
2199
- TypeError: If data type of `x` or `argmax` is not supported.
2113
+ TypeError: If data type of `x` or `argmax` is Number.
2200
2114
  TypeError: If `ksize`, `strides` or `pads` is neither int nor tuple.
2201
- ValueError: If numbers in `strides` (also support 0 and (0, 0, 0)) or `ksize` is not positive.
2115
+ ValueError: If numbers in `strides` or `ksize` is negative.
2202
2116
  ValueError: If numbers in `pads` is negative.
2203
2117
  ValueError: If `ksize`, `strides` or `pads` is a tuple whose length is not equal to 3.
2204
2118
  ValueError: If `data_format` is not a str or is neither `NCDHW` nor `NDHWC`.
2205
2119
  ValueError: If `output_shape` whose length is neither 0 or 5.
2206
- ValueError: If `output_shape` is not close to output size
2120
+ ValueError: If `output_shape` is not close to output size range
2207
2121
  computed by attr `ksize, strides, pads`.
2208
2122
 
2209
2123
  Supported Platforms:
2210
- ``GPU`` ``CPU``
2124
+ ``Ascend`` ``GPU`` ``CPU``
2211
2125
 
2212
2126
  Examples:
2213
2127
  >>> x = Tensor(np.array([[[[[0, 1], [8, 9]]]]]).astype(np.float32))
2214
2128
  >>> argmax = Tensor(np.array([[[[[0, 1], [2, 3]]]]]).astype(np.int64))
2215
- >>> maxunpool3d = P.MaxUnpool3D(ksize=1, strides=1, pads=0)
2129
+ >>> maxunpool3d = ops.MaxUnpool3D(ksize=1, strides=1, pads=0)
2216
2130
  >>> output = maxunpool3d(x, argmax)
2217
2131
  >>> print(output.asnumpy())
2218
2132
  [[[[[0. 1.]
@@ -2242,7 +2156,7 @@ class MaxUnpool3D(Primitive):
2242
2156
  self.output_shape = output_shape
2243
2157
 
2244
2158
 
2245
- class AvgPool(_Pool):
2159
+ class AvgPool(Primitive):
2246
2160
  r"""
2247
2161
  Average pooling operation.
2248
2162
 
@@ -2307,7 +2221,23 @@ class AvgPool(_Pool):
2307
2221
  @prim_attr_register
2308
2222
  def __init__(self, kernel_size=1, strides=1, pad_mode="valid", data_format="NCHW"):
2309
2223
  """Initialize AvgPool."""
2310
- super(AvgPool, self).__init__(kernel_size, strides, pad_mode, data_format)
2224
+ self.init_prim_io_names(inputs=['x'], outputs=['output'])
2225
+ validator.check_value_type('kernel_size', kernel_size, [int, tuple], self.name)
2226
+ validator.check_value_type('strides', strides, [int, tuple], self.name)
2227
+ validator.check_value_type('pad_mode', pad_mode, [str], self.name)
2228
+ self.pad_mode = validator.check_string(pad_mode.upper(), ['VALID', 'SAME'], 'pad_mode', self.name)
2229
+ self.add_prim_attr("pad_mode", self.pad_mode)
2230
+ self.format = validator.check_string(data_format, ['NCHW', 'NHWC'], 'format', self.name)
2231
+ if context.get_context("device_target") != "GPU" and self.format == "NHWC":
2232
+ raise ValueError(f"For '{self.name}', the 'NHWC' format is only supported in GPU target, "
2233
+ f"but got the 'data_format' is {self.format} and "
2234
+ f"the platform is {context.get_context('device_target')}.")
2235
+ self.add_prim_attr('data_format', self.format)
2236
+ self.kernel_size = _check_positive_int_or_tuple(
2237
+ "kernel_size", kernel_size, self.name, allow_four=False, ret_four=True)
2238
+ self.add_prim_attr("kernel_size", self.kernel_size)
2239
+ self.strides = _check_positive_int_or_tuple("strides", strides, self.name, allow_four=False, ret_four=True)
2240
+ self.add_prim_attr("strides", self.strides)
2311
2241
 
2312
2242
 
2313
2243
  class AvgPoolV1(Primitive):
@@ -2489,6 +2419,22 @@ class MaxPool3DWithArgmax(Primitive):
2489
2419
  \max_{l=0, \ldots, d_{ker}-1} \max_{m=0, \ldots, h_{ker}-1} \max_{n=0, \ldots, w_{ker}-1}
2490
2420
  \text{input}(N_i, C_j, s_0 \times d + l, s_1 \times h + m, s_2 \times w + n)
2491
2421
 
2422
+ The output is a Tensor with shape :math:`(N_{out}, C_{out}, D_{out}, H_{out}, W_{out})` and its depth, height and
2423
+ width are:
2424
+
2425
+ .. math::
2426
+ \begin{array}{ll} \\
2427
+ D_{out} = \frac{D_{in} + 2 \times \text{pads}[0] - \text{dilation}[0] \times (\text{ksize}[0] - 1) - 1}
2428
+ {\text{stride}[0]} + 1 \\
2429
+ H_{out} = \frac{H_{in} + 2 \times \text{pads}[1] - \text{dilation}[1] \times (\text{ksize}[1] - 1) - 1}
2430
+ {\text{stride}[1]} + 1 \\
2431
+ W_{out} = \frac{W_{in} + 2 \times \text{pads}[2] - \text{dilation}[2] \times (\text{ksize}[2] - 1) - 1}
2432
+ {\text{stride}[2]} + 1 \\
2433
+ \end{array}
2434
+
2435
+ .. warning::
2436
+ This is an experimental API that is subject to change or deletion.
2437
+
2492
2438
  Args:
2493
2439
  ksize (Union[int, tuple[int]]): The size of kernel used to take the maximum value and arg
2494
2440
  value, is an int number that represents depth, height and width of the kernel, or a tuple of
@@ -2524,7 +2470,7 @@ class MaxPool3DWithArgmax(Primitive):
2524
2470
  ValueError: If `argmax_type` is not mindspore.int64 or mindspore.int32.
2525
2471
 
2526
2472
  Supported Platforms:
2527
- ``GPU``
2473
+ ``Ascend`` ``GPU`` ``CPU``
2528
2474
 
2529
2475
  Examples:
2530
2476
  >>> x = Tensor(np.arange(2 * 1 * 2 * 2 * 2).reshape((2, 1, 2, 2, 2)), mindspore.float32)
@@ -2586,8 +2532,8 @@ class Conv2DTranspose(Conv2DBackpropInput):
2586
2532
  dilation (Union[int, tuple[int]]): Specifies the dilation rate to be used for the dilated convolution.
2587
2533
  Default: 1.
2588
2534
  group (int): Splits input into groups. Default: 1.
2589
- data_format (str): The format of input and output data. It should be 'NHWC' or 'NCHW',\
2590
- default is 'NCHW'.
2535
+ data_format (str): The format of input and output data. It should be 'NHWC' or 'NCHW'.
2536
+ Default is 'NCHW'.
2591
2537
 
2592
2538
  Inputs:
2593
2539
  - **dout** (Tensor) - the gradients with respect to the output of the convolution.
@@ -2704,7 +2650,8 @@ class NLLLoss(Primitive):
2704
2650
 
2705
2651
  Inputs:
2706
2652
  - **logits** (Tensor) - Input logits, with shape :math:`(N, C)`. Data type only supports float32 or float16.
2707
- - **labels** (Tensor) - Ground truth labels, with shape :math:`(N,)`. Data type only supports int32.
2653
+ - **labels** (Tensor) - Ground truth labels, with shape :math:`(N,)`, where each value belong to
2654
+ :math:`[0, C-1]`. Data type only supports int32 or int64.
2708
2655
  - **weight** (Tensor) - The rescaling weight to each class, with shape :math:`(C,)` and data type only
2709
2656
  supports float32 or float16.
2710
2657
 
@@ -2716,13 +2663,15 @@ class NLLLoss(Primitive):
2716
2663
  - **total_weight** (Tensor) - The `total_weight` is a scalar. The data type is the same with `weight's`.
2717
2664
 
2718
2665
  Raises:
2719
- TypeError: If dtype of `logits` or `weight` is neither float16 nor float32, `labels` is not int32.
2666
+ TypeError: If dtype of `logits` or `weight` is neither float16 nor float32.
2667
+ TypeError: If dtype of `labels` is neither int32 nor int64.
2720
2668
  ValueError: If `logits` is not a one or two dimension tensor, `labels` and `weight` are not
2721
2669
  one dimension tensors.
2722
2670
  When `logits` is a two dimension tensor, the first dimension of `logits` is not equal to `labels`,
2723
2671
  and second dimension of `logits` is not equal to `weight`.
2724
2672
  When `logits` is a one dimension tensor, the dimensions of `logits`, `labels`
2725
2673
  and `weight` should be equal to each other.
2674
+ ValueError: If the value of `labels` exceed :math:`[0, C-1]`, where :math:`C` is the number of classes.
2726
2675
 
2727
2676
  Supported Platforms:
2728
2677
  ``Ascend`` ``GPU`` ``CPU``
@@ -2826,7 +2775,7 @@ class SparseSoftmaxCrossEntropyWithLogits(Primitive):
2826
2775
  TypeError: If `is_grad` is not a bool.
2827
2776
  TypeError: If dtype of `logits` is neither float16 nor float32.
2828
2777
  TypeError: If dtype of `labels` is neither int32 nor int64.
2829
- ValueError: If logits.shape[0] != labels.shape[0].
2778
+ ValueError: If :math:`logits.shape[0] != labels.shape[0]`.
2830
2779
 
2831
2780
  Supported Platforms:
2832
2781
  ``GPU`` ``CPU``
@@ -2922,14 +2871,19 @@ class ApplyMomentum(Primitive):
2922
2871
  gradient_scale (float): The scale of the gradient. Default: 1.0.
2923
2872
 
2924
2873
  Inputs:
2925
- - **variable** (Parameter) - Weights to be updated. Data type must be float.
2874
+ - **variable** (Parameter) - Weights to be updated. Data type must be float64, int64, float, float16,
2875
+ int16, int32, int8, uint16, uint32, uint64, uint8, complex64, complex128.
2926
2876
  - **accumulation** (Parameter) - Accumulated gradient value by moment weight,
2927
2877
  has the same data type with `variable`.
2928
- - **learning_rate** (Union[Number, Tensor]) - The learning rate value, must be a float number or
2929
- a scalar tensor with float data type.
2878
+ - **learning_rate** (Union[Number, Tensor]) - The learning rate value, must be a float64, int64, float,
2879
+ float16, int16, int32, int8, uint16, uint32, uint64, uint8, complex64, complex128 number or
2880
+ a scalar tensor with float64, int64, float, float16, int16, int32, int8, uint16, uint32, uint64, uint8,
2881
+ complex64, complex128 data type.
2930
2882
  - **gradient** (Tensor) - Gradient, has the same data type as `variable`.
2931
- - **momentum** (Union[Number, Tensor]) - Momentum, must be a float number or
2932
- a scalar tensor with float data type.
2883
+ - **momentum** (Union[Number, Tensor]) - Momentum, must be a float64, int64, float, float16, int16, int32,
2884
+ int8, uint16, uint32, uint64, uint8, complex64, complex128 number or
2885
+ a scalar tensor with float64, int64, float, float16, int16, int32, int8, uint16, uint32, uint64, uint8,
2886
+ complex64, complex128 data type.
2933
2887
 
2934
2888
  Outputs:
2935
2889
  Tensor, parameters to be updated.
@@ -3003,21 +2957,47 @@ class SmoothL1Loss(Primitive):
3003
2957
  def __init__(self, beta=1.0, reduction='none'):
3004
2958
  """Initialize SmoothL1Loss."""
3005
2959
  validator.check_value_type('beta', beta, [float], self.name)
3006
- validator.check('beta', beta, '', 0, Rel.GT, self.name)
2960
+ validator.check('beta', beta, '', 0, validator.GT, self.name)
3007
2961
  validator.check_string(
3008
2962
  reduction, ['none', 'sum', 'mean'], 'reduction', self.name)
2963
+ self.add_prim_attr('sigma', self.beta)
3009
2964
  self.init_prim_io_names(inputs=['prediction', 'target'], outputs=['output'])
3010
2965
 
3011
2966
 
3012
2967
  class MultiMarginLoss(Primitive):
3013
2968
  r"""
3014
- Creates a criterion that optimizes a multi-class classification hinge loss (margin-based loss)
3015
- between input and output.
2969
+ Creates a loss function that minimizes the hinge loss
2970
+ for multi-class classification tasks.
2971
+ The loss is calculated by comparing the input and output of the function.
2972
+
2973
+ .. warning::
2974
+ This is an experimental API that is subject to change or deletion.
3016
2975
 
3017
2976
  Refer to :func:`mindspore.ops.multi_margin_loss` for more details.
3018
2977
 
2978
+ Args:
2979
+ p (int, optional): The norm degree for pairwise distance. Should be 1 or 2. Default: 1.
2980
+ margin (int, optional): A parameter to change pairwise distance. Default: 1.0.
2981
+ reduction (str, optional): Apply specific reduction method to the output: 'none', 'mean',
2982
+ 'sum'. Default: 'mean'.
2983
+
2984
+ - 'none': no reduction will be applied.
2985
+ - 'mean': the sum of the output will be divided by the number of elements in the output.
2986
+ - 'sum': the output will be summed.
2987
+
2988
+ Inputs:
2989
+ - **inputs** (Tensor) - Input , with shape :math:`(N, C)`. Data type only support float32, float16 or float64.
2990
+ - **target** (Tensor) - Ground truth labels, with shape :math:`(N,)`. Data type only support int64. The
2991
+ value of target should be non-negative, less than C.
2992
+ - **weight** (Tensor) - The rescaling weight to each class with shape :math:`(C,)`. Data type only
2993
+ support float16, float32 or float64.
2994
+
2995
+ Outputs:
2996
+ Tensor, When `reduction` is 'none', the shape is :math:`(N,)`.
2997
+ Otherwise, it is a scalar. Has the same data type with `inputs`.
2998
+
3019
2999
  Supported Platforms:
3020
- ``CPU``
3000
+ ``Ascend`` ``GPU`` ``CPU``
3021
3001
 
3022
3002
  Examples:
3023
3003
  >>> x = Tensor(np.ones(shape=[3, 3]), mindspore.float32)
@@ -3033,7 +3013,7 @@ class MultiMarginLoss(Primitive):
3033
3013
  def __init__(self, p=1, margin=1.0, reduction="mean"):
3034
3014
  """Initialize MultiMarginLoss"""
3035
3015
  self.p = validator.check_value_type('p', p, [int], self.name)
3036
- validator.check_int(p, {1, 2}, Rel.IN, 'p', self.name)
3016
+ validator.check_int(p, {1, 2}, validator.IN, 'p', self.name)
3037
3017
  self.margin = validator.check_value_type('margin', margin, [float], self.name)
3038
3018
  self.reduction = validator.check_string(reduction, ['none', 'sum', 'mean'], 'reduction', self.name)
3039
3019
  self.init_prim_io_names(inputs=['x', 'target', 'weight'], outputs=['y'])
@@ -3217,10 +3197,13 @@ class RNNTLoss(PrimitiveWithInfer):
3217
3197
  validator.check_equal_int(len(labels_shape), 2, 'labels_rank', self.name)
3218
3198
  validator.check_equal_int(len(input_length_shape), 1, 'input_length_rank', self.name)
3219
3199
  validator.check_equal_int(len(label_length_shape), 1, 'label_length_rank', self.name)
3220
- validator.check('labels shape[0]', labels_shape[0], 'acts shape[0]', acts_shape[0], Rel.EQ, self.name)
3221
- validator.check('labels shape[1]', labels_shape[1], 'acts shape[2]-1', acts_shape[2] - 1, Rel.EQ, self.name)
3222
- validator.check('input_length size', input_length_shape[0], 'acts shape[0]', acts_shape[0], Rel.EQ, self.name)
3223
- validator.check('label_length size', label_length_shape[0], 'acts shape[0]', acts_shape[0], Rel.EQ, self.name)
3200
+ validator.check('labels shape[0]', labels_shape[0], 'acts shape[0]', acts_shape[0], validator.EQ, self.name)
3201
+ validator.check('labels shape[1]', labels_shape[1], 'acts shape[2]-1',
3202
+ acts_shape[2] - 1, validator.EQ, self.name)
3203
+ validator.check('input_length size', input_length_shape[0], 'acts shape[0]',
3204
+ acts_shape[0], validator.EQ, self.name)
3205
+ validator.check('label_length size', label_length_shape[0], 'acts shape[0]',
3206
+ acts_shape[0], validator.EQ, self.name)
3224
3207
  costs_shape = (acts_shape[0],)
3225
3208
  return costs_shape, acts_shape
3226
3209
 
@@ -3301,13 +3284,10 @@ class SGD(PrimitiveWithCheck):
3301
3284
 
3302
3285
  def check_shape(self, parameters_shape, gradient_shape, learning_rate_shape,
3303
3286
  accum_shape, momentum_shape, stat_shape):
3304
- validator.check_positive_int(len(parameters_shape), "parameters rank", self.name)
3305
- validator.check_int(len(gradient_shape), 0, Rel.GE, f'gradient rank', self.name)
3306
- validator.check_int(len(learning_rate_shape), 0, Rel.GE, f'learning rate rank', self.name)
3307
- validator.check_positive_int(len(accum_shape), "accumulation rank", self.name)
3308
- validator.check_int(len(momentum_shape), 0, Rel.GE, f'momentum rank', self.name)
3309
- validator.check_int(len(stat_shape), 0, Rel.GE, f'stat rank', self.name)
3310
- validator.check("gradient shape", gradient_shape, "stat shape", stat_shape, Rel.EQ, self.name)
3287
+ validator.check_int(len(gradient_shape), 0, validator.GE, f'gradient rank', self.name)
3288
+ validator.check_int(len(learning_rate_shape), 0, validator.GE, f'learning rate rank', self.name)
3289
+ validator.check_int(len(momentum_shape), 0, validator.GE, f'momentum rank', self.name)
3290
+ validator.check_int(len(stat_shape), 0, validator.GE, f'stat rank', self.name)
3311
3291
 
3312
3292
  def check_dtype(self, parameters_dtype, gradient_dtype, learning_rate_dtype,
3313
3293
  accum_dtype, momentum_dtype, stat_dtype):
@@ -3348,7 +3328,7 @@ class ApplyRMSProp(PrimitiveWithInfer):
3348
3328
  from being updated. Default: False.
3349
3329
 
3350
3330
  Inputs:
3351
- - **var** (Tensor) - Weights to be updated.
3331
+ - **var** (Parameter) - Weights to be updated.
3352
3332
  - **mean_square** (Tensor) - Mean square gradients, must be the same type as `var`.
3353
3333
  - **moment** (Tensor) - Delta of `var`, must be the same type as `var`.
3354
3334
  - **learning_rate** (Union[Number, Tensor]) - Learning rate. Must be a float number or
@@ -3442,7 +3422,7 @@ class ApplyCenteredRMSProp(Primitive):
3442
3422
  from being updated. Default: False.
3443
3423
 
3444
3424
  Inputs:
3445
- - **var** (Tensor) - Weights to be updated.
3425
+ - **var** (Parameter) - Weights to be updated.
3446
3426
  - **mean_gradient** (Tensor) - Mean gradients, must be the same type as `var`.
3447
3427
  - **mean_square** (Tensor) - Mean square gradients, must be the same type as `var`.
3448
3428
  - **moment** (Tensor) - Delta of `var`, must be the same type as `var`.
@@ -3519,9 +3499,9 @@ class LayerNorm(Primitive):
3519
3499
  - **input_x** (Tensor) - Tensor of shape :math:`(N, \ldots)`.
3520
3500
  The input of LayerNorm.
3521
3501
  - **gamma** (Tensor) - Tensor of shape :math:`(P_0, \ldots, P_\text{begin_params_axis})`.
3522
- The learnable parameter `gamma` as the scale on norm.
3502
+ The learnable parameter :math:`\gamma` as the scale on norm.
3523
3503
  - **beta** (Tensor) - Tensor of shape :math:`(P_0, \ldots, P_\text{begin_params_axis})`.
3524
- The learnable parameter `beta` as the scale on norm.
3504
+ The learnable parameter :math:`\beta` as the scale on norm.
3525
3505
 
3526
3506
  Outputs:
3527
3507
  tuple[Tensor], tuple of 3 tensors, the normalized input and the updated parameters.
@@ -3576,13 +3556,17 @@ class L2Normalize(Primitive):
3576
3556
  where :math:`\epsilon` is epsilon and :math:`\sum_{i}^{}\left | x_i \right | ^2` calculate the sum of squares of
3577
3557
  the input `x` along the dimension `axis`.
3578
3558
 
3559
+ Note:
3560
+ On Ascend, input data type of float64 is currently not supported.
3561
+
3579
3562
  Args:
3580
3563
  axis (Union[list(int), tuple(int), int]): Specify the axis for calculating the L2 norm. Default: 0.
3581
3564
  epsilon (float): A small value added for numerical stability. Default: 1e-4.
3582
3565
 
3583
3566
  Inputs:
3584
- - **x** (Tensor) - Input to compute the normalization. Tensor of shape :math:`(N, \ldots)`.
3585
- Data type must be float16 or float32.
3567
+ - **x** (Tensor) - Input to compute the normalization. Tensor of shape :math:`(N, *)`,
3568
+ where :math:`*` means any number of additional dimensions.
3569
+ Data type must be float16, float32 or float64.
3586
3570
 
3587
3571
  Outputs:
3588
3572
  Tensor, with the same type and shape as the `x`.
@@ -3591,7 +3575,7 @@ class L2Normalize(Primitive):
3591
3575
  TypeError: If `axis` is not one of the following: list, tuple or int.
3592
3576
  TypeError: If `epsilon` is not a float.
3593
3577
  TypeError: If `x` is not a Tensor.
3594
- TypeError: If dtype of `x` is neither float16 nor float32.
3578
+ TypeError: If dtype of `x` is not in [float16, float32, float64].
3595
3579
  ValueError: If dimension of `x` is not greater than 0.
3596
3580
 
3597
3581
  Supported Platforms:
@@ -3653,57 +3637,14 @@ class DropoutDoMask(Primitive):
3653
3637
 
3654
3638
  class ResizeBilinear(PrimitiveWithInfer):
3655
3639
  r"""
3656
- Resizes an image to a certain size using the bilinear interpolation.
3657
-
3658
- The resizing only affects the lower two dimensions which represent the height and width. The input images
3659
- can be represented by different data types, but the data types of output images are always float32.
3660
-
3661
- For general resize, refer to :func:`mindspore.ops.interpolate` for more details.
3662
-
3663
- .. warning::
3664
- This interface does not support dynamic shape and is subject to change or deletion,
3665
- use :func:`mindspore.ops.interpolate` instead.
3666
-
3667
- Args:
3668
- size (Union[tuple[int], list[int]]): A tuple or list of 2 int elements :math:`(new\_height, new\_width)`,
3669
- the new size of the images.
3670
- align_corners (bool): If true, rescale input by :math:`(new\_height - 1) / (height - 1)`,
3671
- which exactly aligns the 4 corners of images and resized images. If false,
3672
- rescale by :math:`new\_height / height`. Default: False.
3673
- half_pixel_centers (bool): Whether half pixel center. If set to True, `align_corners` should be False.
3674
- Default: False.
3640
+ This API is deprecated, please use the :class:`mindspore.ops.ResizeBilinearV2` instead.
3641
+ For general resizing with other interpolation methods, refer to :func:`mindspore.ops.interpolate` for more details.
3675
3642
 
3676
- Inputs:
3677
- - **x** (Tensor) - Image to be resized. Input images must be a 4-D tensor with shape
3678
- :math:`(batch, channels, height, width)`, with data type of float32 or float16.
3679
-
3680
- Outputs:
3681
- Tensor, resized image. 4-D with shape :math:`(batch, channels, new\_height, new\_width)`,
3682
- with the same data type as input `x`.
3683
-
3684
- Raises:
3685
- TypeError: If `size` is neither a tuple nor list.
3686
- TypeError: If `align_corners` is not a bool.
3687
- TypeError: If `half_pixel_centers` is not a bool.
3688
- TypeError: If `align_corners` and `half_pixel_centers` are all True.
3689
- TypeError: If `half_pixel_centers` is True and device_target not Ascend.
3690
- TypeError: If dtype of `x` is neither float16 nor float32.
3691
- TypeError: If `x` is not a Tensor.
3692
- ValueError: If length of shape of `x` is not equal to 4.
3643
+ Note:
3644
+ Dynamic shape feature is not supported for now.
3693
3645
 
3694
3646
  Supported Platforms:
3695
- ``Ascend`` ``CPU`` ``GPU``
3696
-
3697
- Examples:
3698
- >>> x = Tensor([[[[1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]]], mindspore.float32)
3699
- >>> resize_bilinear = ops.ResizeBilinear((5, 5))
3700
- >>> output = resize_bilinear(x)
3701
- >>> print(output)
3702
- [[[[1. 2. 3. 4. 5.]
3703
- [1. 2. 3. 4. 5.]
3704
- [1. 2. 3. 4. 5.]
3705
- [1. 2. 3. 4. 5.]
3706
- [1. 2. 3. 4. 5.]]]]
3647
+ ``Ascend`` ``GPU`` ``CPU``
3707
3648
  """
3708
3649
 
3709
3650
  @prim_attr_register
@@ -3723,7 +3664,7 @@ class ResizeBilinear(PrimitiveWithInfer):
3723
3664
  validator.check_positive_int(value, f'{i}th value of size', self.name)
3724
3665
 
3725
3666
  def infer_shape(self, input_shape):
3726
- validator.check("dimension of input", len(input_shape), "", 4, Rel.EQ, self.name)
3667
+ validator.check("dimension of input", len(input_shape), "", 4, validator.EQ, self.name)
3727
3668
  input_shape = list(input_shape)
3728
3669
  batch, channel, _, _ = input_shape
3729
3670
  out_shape = [batch, channel]
@@ -3780,22 +3721,24 @@ class UpsampleTrilinear3D(Primitive):
3780
3721
  ValueError: If size of `output_size` is not equal 3 when `output_size` is specified.
3781
3722
 
3782
3723
  Supported Platforms:
3783
- ``GPU`` ``CPU``
3724
+
3784
3725
 
3785
3726
  Examples:
3786
- >>> ops = ops.UpsampleTrilinear3D(output_size=[4, 64, 48])
3787
- >>> out = ops(Tensor(input_data=np.random.randn(2, 3, 4, 512, 256)))
3727
+ >>> net = ops.UpsampleTrilinear3D(output_size=[4, 64, 48])
3728
+ >>> in_x = Tensor(input_data=np.random.randn(2, 3, 4, 512, 256))
3729
+ >>> out = net(in_x)
3788
3730
  >>> print(out.shape)
3789
3731
  (2, 3, 4, 64, 48)
3790
- ...
3791
- >>> ops = ops.UpsampleTrilinear3D(output_size=[2, 4, 4])
3732
+ >>>
3733
+ >>> net = ops.UpsampleTrilinear3D(output_size=[2, 4, 4])
3792
3734
  >>> in_x = Tensor(np.arange(1, 5, dtype=np.float32).reshape((1, 1, 1, 2, 2)))
3793
- >>> out = ops(in_x)
3735
+ >>> out = net(in_x)
3794
3736
  >>> print(out)
3795
3737
  [[[[[1. 1.25 1.75 2. ]
3796
3738
  [1.5 1.75 2.25 2.5 ]
3797
3739
  [2.5 2.75 3.25 3.5 ]
3798
3740
  [3. 3.25 3.75 4. ]]
3741
+
3799
3742
  [[1. 1.25 1.75 2. ]
3800
3743
  [1.5 1.75 2.25 2.5 ]
3801
3744
  [2.5 2.75 3.25 3.5 ]
@@ -4036,7 +3979,7 @@ class GetNext(Primitive):
4036
3979
  """Initialize GetNext."""
4037
3980
  validator.check_value_type("types", types, [list, tuple], self.name)
4038
3981
  validator.check_value_type("shapes", shapes, [list, tuple], self.name)
4039
- validator.check("types length", len(types), "shapes length", len(shapes), Rel.EQ, self.name)
3982
+ validator.check("types length", len(types), "shapes length", len(shapes), validator.EQ, self.name)
4040
3983
  validator.check_value_type("output_num", output_num, [int], self.name)
4041
3984
 
4042
3985
 
@@ -4076,8 +4019,8 @@ class PReLU(PrimitiveWithInfer):
4076
4019
  self.init_prim_io_names(inputs=['x', 'weight'], outputs=['output'])
4077
4020
 
4078
4021
 
4079
- class LSTM(PrimitiveWithInfer):
4080
- """
4022
+ class LSTM(Primitive):
4023
+ r"""
4081
4024
  Performs the Long Short-Term Memory (LSTM) on the input.
4082
4025
 
4083
4026
  For detailsed information, please refer to :class:`mindspore.nn.LSTM`.
@@ -4092,20 +4035,20 @@ class LSTM(PrimitiveWithInfer):
4092
4035
  LSTM layer except the last layer. The range of dropout is [0.0, 1.0].
4093
4036
 
4094
4037
  Inputs:
4095
- - **input** (Tensor) - Tensor of shape (seq_len, batch_size, `input_size`) or
4096
- (batch_size, seq_len, `input_size`).
4097
- - **h** (tuple) - Tensor of shape (num_directions * `num_layers`, batch_size, `hidden_size`).
4098
- - **c** (tuple) - Tensor of shape (num_directions * `num_layers`, batch_size, `hidden_size`).
4038
+ - **input** (Tensor) - Tensor of shape :math:`(seq\_len, batch\_size, input\_size)` or
4039
+ :math:`(batch\_size, seq\_len, input\_size)`.
4040
+ - **h** (Tensor) - Tensor of shape :math:`(num\_directions * num\_layers, batch\_size, hidden\_size)`.
4041
+ - **c** (Tensor) - Tensor of shape :math:`(num\_directions * num\_layers, batch\_size, hidden\_size)`.
4099
4042
  - **w** (Tensor) - A weight Tensor.
4100
4043
 
4101
4044
  Outputs:
4102
4045
  Tuple, a tuple contains (`output`, `h_n`, `c_n`, `reserve`, `state`).
4103
4046
 
4104
- - **output** (Tensor) - Tensor of shape (seq_len, batch_size, num_directions * `hidden_size`).
4105
- - **h_n** (Tensor) - Tensor of shape (num_directions * `num_layers`, batch_size, `hidden_size`).
4106
- - **c_n** (Tensor) - Tensor of shape (num_directions * `num_layers`, batch_size, `hidden_size`).
4107
- - **reserve** (Tensor) - Tensor of shape (r, 1).
4108
- - **state** (Tensor) - Random number generator state and its shape is (s, 1).
4047
+ - **output** (Tensor) - Tensor of shape :math:`(seq\_len, batch\_size, num\_directions * hidden\_size)`.
4048
+ - **h_n** (Tensor) - Tensor of shape :math:`(num\_directions * num\_layers, batch\_size, hidden\_size)`.
4049
+ - **c_n** (Tensor) - Tensor of shape :math:`(num\_directions * num\_layers, batch\_size, hidden\_size)`.
4050
+ - **reserve** (Tensor) - Tensor of shape :math:`(r, 1)`.
4051
+ - **state** (Tensor) - Random number generator state and its shape is :math:`(s, 1)`.
4109
4052
 
4110
4053
  Raises:
4111
4054
  TypeError: If `input_size`, `hidden_size` or `num_layers` is not an int.
@@ -4151,37 +4094,13 @@ class LSTM(PrimitiveWithInfer):
4151
4094
  self.has_bias = validator.check_value_type("has_bias", has_bias, (bool,), self.name)
4152
4095
  self.bidirectional = validator.check_value_type("bidirectional", bidirectional, (bool,), self.name)
4153
4096
  self.dropout = validator.check_value_type("dropout", dropout, [float], self.name)
4154
- self.dropout = validator.check_float_range(dropout, 0, 1, Rel.INC_BOTH, 'dropout', self.name)
4097
+ self.dropout = validator.check_float_range(dropout, 0, 1, validator.INC_BOTH, 'dropout', self.name)
4155
4098
 
4156
4099
  if bidirectional:
4157
4100
  self.num_directions = 2
4158
4101
  else:
4159
4102
  self.num_directions = 1
4160
4103
 
4161
- def infer_shape(self, x_shape, h_shape, c_shape, w_shape):
4162
- validator.check_equal_int(len(x_shape), 3, "x rank", self.name)
4163
- validator.check_equal_int(x_shape[2], self.input_size, "x[2]", self.name)
4164
-
4165
- # h and c should be same shape
4166
- validator.check_equal_int(len(h_shape), 3, "h rank", self.name)
4167
- validator.check("h_shape", h_shape, "c_shape", c_shape, Rel.EQ, self.name)
4168
-
4169
- validator.check_int(h_shape[0], self.num_layers * self.num_directions, Rel.EQ, "h[0]", self.name)
4170
- validator.check_equal_int(h_shape[1], x_shape[1], "h[1]", self.name)
4171
- validator.check_int(h_shape[2], self.hidden_size, Rel.EQ, "h[2]", self.name)
4172
-
4173
- y_shape = (x_shape[0], x_shape[1], self.hidden_size * self.num_directions)
4174
-
4175
- # set arbitrary shape for reserved space
4176
- reserved_shape = (1, 1)
4177
- state_shape = (1, 1)
4178
- return y_shape, h_shape, c_shape, reserved_shape, state_shape
4179
-
4180
- def infer_dtype(self, x_dtype, h_dtype, c_dtype, w_dtype):
4181
- args = {'x': x_dtype, 'h': h_dtype, 'c': c_dtype, 'w': w_dtype}
4182
- validator.check_tensors_dtypes_same_and_valid(args, (mstype.float32, mstype.float16), self.name)
4183
- return x_dtype, x_dtype, x_dtype, x_dtype, x_dtype
4184
-
4185
4104
 
4186
4105
  class SigmoidCrossEntropyWithLogits(Primitive):
4187
4106
  r"""
@@ -4200,7 +4119,7 @@ class SigmoidCrossEntropyWithLogits(Primitive):
4200
4119
  \end{array}
4201
4120
 
4202
4121
  Inputs:
4203
- - **logits** (Tensor) - Input logits. Tensor of shape :math:`(N, *)` where :math:`*` means, any number
4122
+ - **logits** (Tensor) - Input logits. Tensor of shape :math:`(N, *)` where :math:`*` means any number
4204
4123
  of additional dimensions.
4205
4124
  - **label** (Tensor) - Ground truth label. With the same shape and type as `logits`.
4206
4125
 
@@ -4240,7 +4159,7 @@ class BCEWithLogitsLoss(PrimitiveWithInfer):
4240
4159
 
4241
4160
  \begin{array}{ll} \\
4242
4161
  p_{ij} = sigmoid(X_{ij}) = \frac{1}{1 + e^{-X_{ij}}} \\
4243
- L_{ij} = -[Y_{ij} * log(p_{ij}) + (1 - Y_{ij})log(1 - p_{ij})]
4162
+ L_{ij} = -[Y_{ij}log(p_{ij}) + (1 - Y_{ij})log(1 - p_{ij})]
4244
4163
  \end{array}
4245
4164
 
4246
4165
  :math:`i` indicates the :math:`i^{th}` sample, :math:`j` indicates the category. Then,
@@ -4258,8 +4177,8 @@ class BCEWithLogitsLoss(PrimitiveWithInfer):
4258
4177
  and the third method is to calculate the sum of all losses.
4259
4178
 
4260
4179
  This operator will multiply the output by the corresponding weight.
4261
- The tensor weight assigns different weights to each piece of data in the batch,
4262
- and the tensor pos_weight adds corresponding weights to the positive examples of each category.
4180
+ The tensor `weight` assigns different weights to each piece of data in the batch,
4181
+ and the tensor `pos_weight` adds corresponding weights to the positive examples of each category.
4263
4182
 
4264
4183
  In addition, it can trade off recall and precision by adding weights to positive examples.
4265
4184
  In the case of multi-label classification the loss can be described as:
@@ -4271,8 +4190,8 @@ class BCEWithLogitsLoss(PrimitiveWithInfer):
4271
4190
  \end{array}
4272
4191
 
4273
4192
  where c is the class number (c>1 for multi-label binary classification, c=1 for single-label binary classification),
4274
- n is the number of the sample in the batch and :math:`p_c` is the weight of the positive answer for the class c.
4275
- :math:`p_c>1` increases the recall, :math:`p_c<1` increases the precision.
4193
+ n is the number of the sample in the batch and :math:`P_c` is the weight of the positive answer for the class c.
4194
+ :math:`P_c>1` increases the recall, :math:`P_c<1` increases the precision.
4276
4195
 
4277
4196
  Args:
4278
4197
  reduction (str): Type of reduction to be applied to loss. The optional values are 'mean', 'sum', and 'none',
@@ -4335,8 +4254,8 @@ class Pad(Primitive):
4335
4254
  be extended behind the input tensor in the `D` th dimension.
4336
4255
 
4337
4256
  Inputs:
4338
- - **input_x** (Tensor) - Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
4339
- additional dimensions.
4257
+ - **input_x** (Tensor) - Tensor to be padded. It has shape :math:`(N, *)`, where :math:`*` means
4258
+ any number of additional dimensions.
4340
4259
 
4341
4260
  Outputs:
4342
4261
  Tensor, the tensor after padding.
@@ -4372,21 +4291,34 @@ class Pad(Primitive):
4372
4291
 
4373
4292
  class PadV3(Primitive):
4374
4293
  """
4375
- Pads the input tensor according to the paddings, `mode` and `paddings_contiguous`.
4294
+ Pads the input Tensor according to the `paddings`, `mode` and `paddings_contiguous`.
4376
4295
 
4377
4296
  Args:
4378
4297
  mode (str, optional): An optional string indicates padding mode,
4379
- support "constant", "reflect", "edge". Default: "constant".
4298
+ support "constant", "reflect", "edge", "circular". Default: "constant".
4299
+ The effects of various padding modes are as follows:
4300
+
4301
+ - "constant": Pads the input Tensor with value specified by `constant_value`.
4302
+ - "reflect": Pads the input Tensor by reflecting the values of the pixels at the
4303
+ boundary of the Tensor.
4304
+ - "edge": Pads the input Tensor with the values of the pixels on the border of the Tensor.
4305
+ - "circular": Circular padding mode. In this mode, the pixels from one edge of the image
4306
+ are wrapped around to the opposite edge, such that the pixel on the right edge of the
4307
+ image is replaced with the pixel on the left edge, and the pixel on the bottom edge
4308
+ is replaced with the pixel on the top edge.
4309
+
4380
4310
  paddings_contiguous (bool, optional): An optional bool value indicates if the padding is paddings_contiguous.
4381
4311
  If true, paddings is arranged as [begin0, end0, begin1, end1, ...]
4382
4312
  If false, paddings is arranged as [begin0, begin1, ..., end1, end2, ...]
4383
4313
  Default:True.
4384
4314
 
4385
4315
  Inputs:
4386
- - **x** (Tensor) - Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
4387
- additional dimensions.
4388
- - **paddings** (Tensor) - Only constant value is allowed. A 1D tensor of type int32 or int64.
4389
- - **constant_value** (Tensor, optional) - A tensor with the same type as `x`, padding value in 'constant' mode.
4316
+ - **x** (Tensor) - Tensor to be padded. It has shape :math:`(N, *)`, where :math:`*` means
4317
+ any number of additional dimensions.
4318
+ - **paddings** (Tensor) - Specifies the number of zeros to be padded before and after each
4319
+ dimension of the input Tensor `x`. It's a 1D Tensor of type int32 or int64.
4320
+ - **constant_value** (Tensor, optional) - Padding value to use in 'constant' mode,
4321
+ if not specified, 0 is used instead. It has the same type as `x`.
4390
4322
 
4391
4323
  Outputs:
4392
4324
  Tensor, the tensor after padding.
@@ -4397,19 +4329,20 @@ class PadV3(Primitive):
4397
4329
  ValueError: If `mode` is not a str or not in support modes.
4398
4330
  ValueError: If `mode` is "constant", the element's number of `paddings` not be even.
4399
4331
  ValueError: If `mode` is "constant", the element's number of `paddings` large than input dim * 2.
4400
- ValueError: If `mode` is "edge" or "reflect", the element's number of `paddings` is not 2, 4 or 6.
4401
- ValueError: If `mode` is "edge" or "reflect", `x` dims equals 3,
4402
- the element's number of `paddings` is 2.
4403
- ValueError: If `mode` is "edge" or "reflect", `x` dims equals 4,
4404
- the element's number of `paddings` is 4.
4405
- ValueError: If `mode` is "edge" or "reflect", `x` dims smaller than 3.
4406
- ValueError: If `mode` is "edge", x dims bigger than 5.
4332
+ ValueError: If `mode` is "edge" "reflect" or "circular", the element's number of `paddings` is not 2, 4 or 6.
4333
+ ValueError: If `mode` is "edge" "reflect" or "circular", `x` dims equals 3,
4334
+ the element's number of `paddings` is not 2.
4335
+ ValueError: If `mode` is "edge" "reflect" or "circular", `x` dims equals 4,
4336
+ the element's number of `paddings` is not 4.
4337
+ ValueError: If `mode` is "circular", `x` dims equals 5, the element's number of `paddings` is not 6.
4338
+ ValueError: If `mode` is "edge", "reflect" or "circular", `x` dims smaller than 3.
4339
+ ValueError: If `mode` is "edge" or "circular", x dims bigger than 5.
4407
4340
  ValueError: If `mode` is "reflect", x dims bigger than 4.
4408
4341
  ValueError: If `mode` is "reflect", padding size bigger than the corresponding `x` dimension.
4409
4342
  ValueError: After padding, output's shape number is not greater than 0.
4410
4343
 
4411
4344
  Supported Platforms:
4412
- ``GPU`` ``CPU``
4345
+ ``Ascend`` ``GPU`` ``CPU``
4413
4346
 
4414
4347
  Examples:
4415
4348
  >>> # case1: mode="reflect", paddings_contiguous=True
@@ -4447,7 +4380,7 @@ class PadV3(Primitive):
4447
4380
  def __init__(self, mode='constant', paddings_contiguous=True):
4448
4381
  """Initialize PadV3"""
4449
4382
  self.init_prim_io_names(inputs=['x', 'paddings', 'constant_value'], outputs=['y'])
4450
- validator.check_string(mode, ['constant', 'reflect', 'edge'], 'mode', self.name)
4383
+ validator.check_string(mode, ['constant', 'reflect', 'edge', 'circular'], 'mode', self.name)
4451
4384
  validator.check_bool(paddings_contiguous, "paddings_contiguous", self.name)
4452
4385
  self.mode = mode
4453
4386
  self.paddings_contiguous = paddings_contiguous
@@ -4465,7 +4398,7 @@ class MirrorPad(Primitive):
4465
4398
  - **input_x** (Tensor) - Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
4466
4399
  additional dimensions.
4467
4400
  - **paddings** (Tensor) - Paddings requires constant tensor. The value of `paddings` is a
4468
- matrix(list), and its shape is (N, 2). N is the rank of input data. All elements of paddings
4401
+ matrix(list), and its shape is :math:`(N, 2)`. N is the rank of input data. All elements of paddings
4469
4402
  are int type. For the input in the `D` th dimension, paddings[D, 0] indicates how many sizes
4470
4403
  to be extended ahead of the input tensor in the `D` th dimension, and paddings[D, 1]
4471
4404
  indicates how many sizes to be extended behind the input tensor in the `D` th dimension. Both
@@ -4492,7 +4425,7 @@ class MirrorPad(Primitive):
4492
4425
  ValueError: If paddings.size is not equal to 2 * rank of input_x.
4493
4426
 
4494
4427
  Supported Platforms:
4495
- ``GPU`` ``CPU``
4428
+ ``Ascend`` ``GPU`` ``CPU``
4496
4429
 
4497
4430
  Examples:
4498
4431
  >>> from mindspore import Tensor, nn, ops
@@ -4531,7 +4464,6 @@ class MirrorPad(Primitive):
4531
4464
  self.init_prim_io_names(inputs=['x', 'paddings'], outputs=['y'])
4532
4465
  validator.check_string(mode, ['REFLECT', 'SYMMETRIC'], 'mode', self.name)
4533
4466
  self.mode = mode
4534
- self.set_const_input_indexes([1])
4535
4467
 
4536
4468
 
4537
4469
  class ComputeAccidentalHits(PrimitiveWithCheck):
@@ -4587,13 +4519,14 @@ class ComputeAccidentalHits(PrimitiveWithCheck):
4587
4519
  self.init_prim_io_names(inputs=['true_classes', 'sampled_candidates'],
4588
4520
  outputs=['indices', 'ids', 'weights'])
4589
4521
  validator.check_value_type("num_true", num_true, [int], self.name)
4590
- validator.check_number("num_true", num_true, 1, Rel.GE, self.name)
4522
+ validator.check_number("num_true", num_true, 1, validator.GE, self.name)
4591
4523
  self.num_true = num_true
4592
4524
 
4593
4525
  def check_shape(self, true_classes_shape, sampled_candidates_shape):
4594
- validator.check_int(len(true_classes_shape), 2, Rel.EQ, 'dim of true_classes', self.name)
4595
- validator.check_int(len(sampled_candidates_shape), 1, Rel.EQ, 'dim of sampled_candidates', self.name)
4596
- validator.check("true_classes shape[1]", true_classes_shape[1], "num_true", self.num_true, Rel.EQ, self.name)
4526
+ validator.check_int(len(true_classes_shape), 2, validator.EQ, 'dim of true_classes', self.name)
4527
+ validator.check_int(len(sampled_candidates_shape), 1, validator.EQ, 'dim of sampled_candidates', self.name)
4528
+ validator.check("true_classes shape[1]", true_classes_shape[1], "num_true",
4529
+ self.num_true, validator.EQ, self.name)
4597
4530
 
4598
4531
  indices_len = -1
4599
4532
  return (indices_len,), (indices_len,), (indices_len,)
@@ -4665,7 +4598,7 @@ class ROIAlign(Primitive):
4665
4598
  validator.check_value_type("spatial_scale", spatial_scale, [float], self.name)
4666
4599
  validator.check_value_type("sample_num", sample_num, [int], self.name)
4667
4600
  validator.check_value_type("roi_end_mode", roi_end_mode, [int], self.name)
4668
- validator.check_int_range(roi_end_mode, 0, 1, Rel.INC_BOTH, "roi_end_mode", self.name)
4601
+ validator.check_int_range(roi_end_mode, 0, 1, validator.INC_BOTH, "roi_end_mode", self.name)
4669
4602
  self.pooled_height = pooled_height
4670
4603
  self.pooled_width = pooled_width
4671
4604
  self.spatial_scale = spatial_scale
@@ -4707,22 +4640,19 @@ class Adam(Primitive):
4707
4640
  If false, update the gradients without using NAG. Default: False.
4708
4641
 
4709
4642
  Inputs:
4710
- - **var** (Tensor) - Weights to be updated. The shape is :math:`(N, *)` where :math:`*` means,
4643
+ - **var** (Parameter) - Weights to be updated. The shape is :math:`(N, *)` where :math:`*` means,
4711
4644
  any number of additional dimensions. The data type can be float16 or float32.
4712
- - **m** (Tensor) - The 1st moment vector in the updating formula,
4713
- the shape and data type value should be the same as `var`.
4714
- - **v** (Tensor) - the 2nd moment vector in the updating formula,
4715
- the shape and data type value should be the same as `var`. Mean square gradients with the same type as `var`.
4716
- - **beta1_power** (float) - :math:`beta_1^t(\beta_1^{t})` in the updating formula,
4717
- the data type value should be the same as `var`.
4718
- - **beta2_power** (float) - :math:`beta_2^t(\beta_2^{t})` in the updating formula,
4719
- the data type value should be the same as `var`.
4720
- - **lr** (float) - :math:`l` in the updating formula. The paper suggested value is :math:`10^{-8}`,
4721
- the data type value should be the same as `var`.
4722
- - **beta1** (float) - The exponential decay rate for the 1st moment estimations,
4723
- the data type value should be the same as `var`. The paper suggested value is :math:`0.9`.
4724
- - **beta2** (float) - The exponential decay rate for the 2nd moment estimations,
4725
- the data type value should be the same as `var`. The paper suggested value is :math:`0.999`.
4645
+ - **m** (Parameter) - The 1st moment vector in the updating formula,
4646
+ the shape should be the same as `var`.
4647
+ - **v** (Parameter) - the 2nd moment vector in the updating formula,
4648
+ the shape should be the same as `var`.
4649
+ - **beta1_power** (float) - :math:`beta_1^t(\beta_1^{t})` in the updating formula.
4650
+ - **beta2_power** (float) - :math:`beta_2^t(\beta_2^{t})` in the updating formula.
4651
+ - **lr** (float) - :math:`l` in the updating formula. The paper suggested value is :math:`10^{-8}`.
4652
+ - **beta1** (float) - The exponential decay rate for the 1st moment estimations.
4653
+ The paper suggested value is :math:`0.9`.
4654
+ - **beta2** (float) - The exponential decay rate for the 2nd moment estimations.
4655
+ The paper suggested value is :math:`0.999`.
4726
4656
  - **epsilon** (float) - Term added to the denominator to improve numerical stability.
4727
4657
  - **gradient** (Tensor) - Gradient, has the same shape and data type as `var`.
4728
4658
 
@@ -4735,7 +4665,7 @@ class Adam(Primitive):
4735
4665
 
4736
4666
  Raises:
4737
4667
  TypeError: If neither `use_locking` nor `use_nesterov` is a bool.
4738
- TypeError: If `var`, `m` or `v` is not a Tensor.
4668
+ TypeError: If `var`, `m` or `v` is not a Parameter.
4739
4669
  TypeError: If `beta1_power`, `beta2_power1`, `lr`, `beta1`, `beta2`, `epsilon` or `gradient` is not a Tensor.
4740
4670
 
4741
4671
  Supported Platforms:
@@ -4761,6 +4691,18 @@ class Adam(Primitive):
4761
4691
  [[0.9996838 0.9996838]
4762
4692
  [0.9996838 0.9996838]]
4763
4693
  """
4694
+ __mindspore_signature__ = (
4695
+ sig.make_sig('var', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T),
4696
+ sig.make_sig('m', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T1),
4697
+ sig.make_sig('v', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T2),
4698
+ sig.make_sig('beta1_power', dtype=sig.sig_dtype.T3),
4699
+ sig.make_sig('beta2_power', dtype=sig.sig_dtype.T4),
4700
+ sig.make_sig('lr', dtype=sig.sig_dtype.T5),
4701
+ sig.make_sig('beta1', dtype=sig.sig_dtype.T6),
4702
+ sig.make_sig('beta2', dtype=sig.sig_dtype.T7),
4703
+ sig.make_sig('epsilon', dtype=sig.sig_dtype.T8),
4704
+ sig.make_sig('gradient', dtype=sig.sig_dtype.T)
4705
+ )
4764
4706
 
4765
4707
  @prim_attr_register
4766
4708
  def __init__(self, use_locking=False, use_nesterov=False):
@@ -5323,7 +5265,7 @@ class FusedSparseFtrl(Primitive):
5323
5265
  self.lr = validator.check_positive_float(lr, "lr", self.name)
5324
5266
  self.l1 = validator.check_non_negative_float(l1, "l1", self.name)
5325
5267
  self.l2 = validator.check_non_negative_float(l2, "l2", self.name)
5326
- self.lr_power = validator.check_number("lr_power", lr_power, 0, Rel.LE, self.name)
5268
+ self.lr_power = validator.check_number("lr_power", lr_power, 0, validator.LE, self.name)
5327
5269
  self.use_locking = validator.check_value_type("use_locking", use_locking, [bool], self.name)
5328
5270
 
5329
5271
 
@@ -5498,7 +5440,7 @@ class KLDivLoss(Primitive):
5498
5440
  elif device_target == "GPU":
5499
5441
  support_mode = ['none', 'mean', 'sum']
5500
5442
  elif device_target == "Ascend":
5501
- support_mode = ['none', 'batchmean', 'sum']
5443
+ support_mode = ['none', 'batchmean', 'sum', 'mean']
5502
5444
  else:
5503
5445
  raise ValueError(f"'{self.name}' unknown device target: '{device_target}'")
5504
5446
 
@@ -5518,7 +5460,7 @@ class BinaryCrossEntropy(Primitive):
5518
5460
 
5519
5461
  In which, :math:`L` indicates the loss of all batch_sizes, :math:`l` indicates the loss of one batch_size,
5520
5462
  and n indicates one batch_size in the 1-N range, :math:`w_n` indicates the
5521
- weight of nth batch of binary cross entropy. Then,
5463
+ weight of :math:`n`-th batch of binary cross entropy. Then,
5522
5464
 
5523
5465
  .. math::
5524
5466
  \ell(x, y) = \begin{cases}
@@ -5528,8 +5470,7 @@ class BinaryCrossEntropy(Primitive):
5528
5470
  \end{cases}
5529
5471
 
5530
5472
  .. warning::
5531
- - The value of "x" must range from 0 to 1.
5532
- - The value of "y" must be "0" or "1".
5473
+ - The value of :math:`x` must range from 0 to 1.
5533
5474
 
5534
5475
  Args:
5535
5476
  reduction (str): Specifies the reduction to be applied to the output.
@@ -5741,7 +5682,7 @@ class ApplyAdadelta(Primitive):
5741
5682
  is not supported.
5742
5683
 
5743
5684
  Supported Platforms:
5744
- ``Ascend`` ``CPU`` ``GPU``
5685
+ ``Ascend`` ``GPU`` ``CPU``
5745
5686
 
5746
5687
  Examples:
5747
5688
  >>> import numpy as np
@@ -5818,10 +5759,10 @@ class ApplyAdagrad(Primitive):
5818
5759
  update_slots (bool): If `True`, `accum` will be updated. Default: True.
5819
5760
 
5820
5761
  Inputs:
5821
- - **var** (Parameter) - Variable to be updated. With float32 or float16 data type.
5762
+ - **var** (Parameter) - Variable to be updated. With float or complex data type.
5822
5763
  The shape is :math:`(N, *)` where :math:`*` means, any number of additional dimensions.
5823
5764
  - **accum** (Parameter) - Accumulation to be updated. The shape and data type must be the same as `var`.
5824
- - **lr** (Union[Number, Tensor]) - The learning rate value, must be a scalar. With float32 or float16 data type.
5765
+ - **lr** (Union[Number, Tensor]) - The learning rate value, must be a scalar. With float or complex data type.
5825
5766
  - **grad** (Tensor) - A tensor for gradient. The shape and data type must be the same as `var`.
5826
5767
 
5827
5768
  Outputs:
@@ -5831,12 +5772,12 @@ class ApplyAdagrad(Primitive):
5831
5772
  - **accum** (Tensor) - The same shape and data type as `accum`.
5832
5773
 
5833
5774
  Raises:
5834
- TypeError: If dtype of `var`, `accum`, `lr` or `grad` is neither float16 nor float32.
5775
+ TypeError: If dtype of `var`, `accum`, `lr` or `grad` is neither float nor complex.
5835
5776
  TypeError: If `lr` is neither a Number nor a Tensor.
5836
5777
  RuntimeError: If the data type of `var`, `accum` and `grad` conversion of Parameter is not supported.
5837
5778
 
5838
5779
  Supported Platforms:
5839
- ``Ascend`` ``CPU`` ``GPU``
5780
+ ``Ascend`` ``GPU`` ``CPU``
5840
5781
 
5841
5782
  Examples:
5842
5783
  >>> class Net(nn.Cell):
@@ -5895,7 +5836,7 @@ class ApplyAdagradV2(Primitive):
5895
5836
  the relatively highest priority data type.
5896
5837
 
5897
5838
  Note:
5898
- The difference is that `ApplyAdagradV2` has one more small constant value than `ApplyAdagrad`.
5839
+ The difference is that `ApplyAdagradV2` has one more small constant value :math:`\epsilon` than `ApplyAdagrad`.
5899
5840
 
5900
5841
  Args:
5901
5842
  epsilon (float): A small value added for numerical stability.
@@ -6016,7 +5957,7 @@ class SparseApplyAdagradV2(Primitive):
6016
5957
  - **grad** (Tensor) - Gradients has the same data type as `var` and
6017
5958
  :math:`grad.shape[1:] = var.shape[1:]` if var.shape > 1.
6018
5959
  - **indices** (Tensor) - A vector of indices into the first dimension of `var` and `accum`.
6019
- The type must be int32 and indices.shape[0] = grad.shape[0].
5960
+ The type must be int32 and :math:`indices.shape[0] = grad.shape[0]`.
6020
5961
 
6021
5962
  Outputs:
6022
5963
  Tuple of 2 tensors, the updated parameters.
@@ -6032,7 +5973,7 @@ class SparseApplyAdagradV2(Primitive):
6032
5973
  RuntimeError: If the data type of `var`, `accum` and `grad` conversion of Parameter is not supported.
6033
5974
 
6034
5975
  Supported Platforms:
6035
- ``Ascend`` ``CPU`` ``GPU``
5976
+ ``Ascend`` ``GPU`` ``CPU``
6036
5977
 
6037
5978
  Examples:
6038
5979
  >>> class Net(nn.Cell):
@@ -6201,10 +6142,10 @@ class SparseApplyProximalAdagrad(Primitive):
6201
6142
  - **l2** (Union[Number, Tensor]) - l2 regularization strength, must be a float number or
6202
6143
  a scalar tensor with float16 or float32 data type. It must be non-negative.
6203
6144
  - **grad** (Tensor) - A tensor of the same type as `var` and
6204
- grad.shape[1:] = var.shape[1:] if var.shape > 1.
6145
+ :math:`grad.shape[1:] = var.shape[1:]` if var.shape > 1.
6205
6146
  - **indices** (Tensor) - A tensor of indices in the first dimension of `var` and `accum`.
6206
6147
  If there are duplicates in `indices`, the behavior is undefined. Must be one of the
6207
- following types: int32, int64 and indices.shape[0] = grad.shape[0].
6148
+ following types: int32, int64 and :math:`indices.shape[0] = grad.shape[0]`.
6208
6149
 
6209
6150
  Outputs:
6210
6151
  Tuple of 2 tensors, the updated parameters.
@@ -6220,7 +6161,7 @@ class SparseApplyProximalAdagrad(Primitive):
6220
6161
  RuntimeError: If the data type of `var`, `accum` and `grad` conversion of Parameter is not supported.
6221
6162
 
6222
6163
  Supported Platforms:
6223
- ``Ascend`` ``GPU`` ``CPU``
6164
+ ``Ascend`` ``GPU``
6224
6165
 
6225
6166
  Examples:
6226
6167
  >>> class Net(nn.Cell):
@@ -6669,6 +6610,10 @@ class ApplyFtrl(Primitive):
6669
6610
 
6670
6611
  For more details, please refer to :class:`mindspore.nn.FTRL`.
6671
6612
 
6613
+ Note:
6614
+ Currently, only positive numbers are supported on the Ascend platform,
6615
+ and the calculation results for other scenarios are not defined.
6616
+
6672
6617
  Args:
6673
6618
  use_locking (bool): Use locks for updating operation if true . Default: False.
6674
6619
 
@@ -6697,6 +6642,9 @@ class ApplyFtrl(Primitive):
6697
6642
  TypeError: If dtype of `var`, `grad`, `lr`, `l1`, `l2` or `lr_power` is neither float16 nor float32.
6698
6643
  TypeError: If `lr`, `l1`, `l2` or `lr_power` is neither a Number nor a Tensor.
6699
6644
  TypeError: If `grad` is not a Tensor.
6645
+ RuntimeError: If the parameter types of `var`, `accum` and `linear` are inconsistent.
6646
+ RuntimeError: If the parameter types of `grad`, `lr`, `l1`, `l2`, `lr_power` are inconsistent with `var`
6647
+ and the precision is greater than `var`.
6700
6648
 
6701
6649
  Supported Platforms:
6702
6650
  ``Ascend`` ``GPU`` ``CPU``
@@ -6730,6 +6678,17 @@ class ApplyFtrl(Primitive):
6730
6678
  [ 0.00066425 0.15075898]]
6731
6679
  """
6732
6680
 
6681
+ __mindspore_signature__ = (
6682
+ sig.make_sig('var', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T),
6683
+ sig.make_sig('accum', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T),
6684
+ sig.make_sig('linear', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T),
6685
+ sig.make_sig('grad', dtype=sig.sig_dtype.T),
6686
+ sig.make_sig('lr', dtype=sig.sig_dtype.T),
6687
+ sig.make_sig('l1', dtype=sig.sig_dtype.T),
6688
+ sig.make_sig('l2', dtype=sig.sig_dtype.T),
6689
+ sig.make_sig('lr_power', dtype=sig.sig_dtype.T)
6690
+ )
6691
+
6733
6692
  @prim_attr_register
6734
6693
  def __init__(self, use_locking=False):
6735
6694
  """Initialize ApplyFtrl."""
@@ -6761,10 +6720,11 @@ class SparseApplyFtrl(Primitive):
6761
6720
  The shape is :math:`(N, *)` where :math:`*` means, any number of additional dimensions.
6762
6721
  - **accum** (Parameter) - The accumulation to be updated, must be same data type and shape as `var`.
6763
6722
  - **linear** (Parameter) - The linear coefficient to be updated, must be the same data type and shape as `var`.
6764
- - **grad** (Tensor) - A tensor of the same type as `var` and grad.shape[1:] = var.shape[1:] if var.shape > 1.
6723
+ - **grad** (Tensor) - A tensor of the same type as `var` and :math:`grad.shape[1:] = var.shape[1:]`
6724
+ if var.shape > 1.
6765
6725
  - **indices** (Tensor) - A tensor of indices in the first dimension of `var` and `accum`.
6766
6726
  If there are duplicates in `indices`, the behavior is undefined.
6767
- The type must be int32 or int64 and indices.shape[0] = grad.shape[0].
6727
+ The type must be int32 or int64 and :math:`indices.shape[0] = grad.shape[0]`.
6768
6728
 
6769
6729
  Outputs:
6770
6730
  - **var** (Tensor) - Tensor, has the same shape and data type as `var`.
@@ -6823,83 +6783,19 @@ class SparseApplyFtrl(Primitive):
6823
6783
  self.lr = validator.check_positive_float(lr, "lr", self.name)
6824
6784
  self.l1 = validator.check_non_negative_float(l1, "l1", self.name)
6825
6785
  self.l2 = validator.check_non_negative_float(l2, "l2", self.name)
6826
- self.lr_power = validator.check_number("lr_power", lr_power, 0, Rel.LE, self.name)
6786
+ self.lr_power = validator.check_number("lr_power", lr_power, 0, validator.LE, self.name)
6827
6787
  self.use_locking = validator.check_value_type("use_locking", use_locking, [bool], self.name)
6828
6788
  self.init_prim_io_names(inputs=['var', 'accum', 'linear', 'grad', 'indices'],
6829
- outputs=['var', 'accum', 'linear'])
6830
- self.add_prim_attr('side_effect_mem', True)
6831
-
6832
-
6833
- class SparseApplyFtrlV2(PrimitiveWithInfer):
6834
- """
6835
- Updates relevant entries according to the FTRL-proximal scheme. This class has one more attribute, named
6836
- l2_shrinkage, than class SparseApplyFtrl.
6837
-
6838
- All of inputs except `indices` comply with the implicit type conversion rules to make the data types consistent.
6839
- If they have different data types, the lower priority data type will be converted to
6840
- the relatively highest priority data type.
6841
-
6842
-
6843
- Args:
6844
- lr (float): The learning rate value, must be positive.
6845
- l1 (float): l1 regularization strength, must be greater than or equal to zero.
6846
- l2 (float): l2 regularization strength, must be greater than or equal to zero.
6847
- l2_shrinkage (float): L2 shrinkage regularization.
6848
- lr_power (float): Learning rate power controls how the learning rate decreases during training,
6849
- must be less than or equal to zero. Use fixed learning rate if `lr_power` is zero.
6850
- use_locking (bool, optional): If `True`, the var and accumulation tensors will be protected from being updated.
6851
- Default: False.
6852
-
6853
- Inputs:
6854
- - **var** (Parameter) - The variable to be updated. The data type must be float16 or float32.
6855
- The shape is :math:`(N, *)` where :math:`*` means, any number of additional dimensions.
6856
- - **accum** (Parameter) - The accumulation to be updated, must be same data type and shape as `var`.
6857
- - **linear** (Parameter) - the linear coefficient to be updated, must be same data type and shape as `var`.
6858
- - **grad** (Tensor) - A tensor of the same type as `var` and
6859
- :math:`grad.shape[1:] = var.shape[1:]` if var.shape > 1.
6860
- - **indices** (Tensor) - A vector of indices in the first dimension of `var` and `accum`.
6861
- The type must be int32 and indices.shape[0] = grad.shape[0].
6862
-
6863
- Outputs:
6864
- Tuple of 3 Tensor, the updated parameters.
6789
+ outputs=['var', 'accum', 'linear'])
6790
+ self.add_prim_attr('side_effect_mem', True)
6865
6791
 
6866
- - **var** (Tensor) - Tensor, has the same shape and data type as `var`.
6867
- - **accum** (Tensor) - Tensor, has the same shape and data type as `accum`.
6868
- - **linear** (Tensor) - Tensor, has the same shape and data type as `linear`.
6869
6792
 
6870
- Raises:
6871
- TypeError: If `lr`, `l1`, `l2`, `lr_power` or `use_locking` is not a float.
6872
- TypeError: If `use_locking` is not a bool.
6873
- TypeError: If dtype of `var`, `accum`, `linear` or `grad` is neither float16 nor float32.
6874
- TypeError: If dtype of `indices` is not int32.
6875
- RuntimeError: If the data type of all of inputs except `indices` conversion of Parameter is not supported.
6793
+ class SparseApplyFtrlV2(PrimitiveWithInfer):
6794
+ """
6795
+ The SparseApplyFtrlV2 interface is deprecated, please use the :class:`mindspore.ops.SparseApplyFtrl` instead.
6876
6796
 
6877
6797
  Supported Platforms:
6878
- ``Ascend``
6879
-
6880
- Examples:
6881
- >>> class SparseApplyFtrlV2Net(nn.Cell):
6882
- ... def __init__(self):
6883
- ... super(SparseApplyFtrlV2Net, self).__init__()
6884
- ... self.sparse_apply_ftrl_v2 = ops.SparseApplyFtrlV2(lr=0.01, l1=0.0, l2=0.0,
6885
- ... l2_shrinkage=0.0, lr_power=-0.5)
6886
- ... self.var = Parameter(Tensor(np.array([[0.2, 0.3]]).astype(np.float32)), name="var")
6887
- ... self.accum = Parameter(Tensor(np.array([[0.5, 0.9]]).astype(np.float32)), name="accum")
6888
- ... self.linear = Parameter(Tensor(np.array([[0.7, 0.5]]).astype(np.float32)), name="linear")
6889
- ...
6890
- ... def construct(self, grad, indices):
6891
- ... out = self.sparse_apply_ftrl_v2(self.var, self.accum, self.linear, grad, indices)
6892
- ... return out
6893
- ...
6894
- >>> net = SparseApplyFtrlV2Net()
6895
- >>> grad = Tensor(np.array([[0.8, 0.5]]).astype(np.float32))
6896
- >>> indices = Tensor(np.ones([1]), mindspore.int32)
6897
- >>> output = net(grad, indices)
6898
- >>> print(output)
6899
- (Tensor(shape=[1, 2], dtype=Float32, value=
6900
- [[ 2.00000003e-01, 3.00000012e-01]]), Tensor(shape=[1, 2], dtype=Float32, value=
6901
- [[ 5.00000000e-01, 8.99999976e-01]]), Tensor(shape=[1, 2], dtype=Float32, value=
6902
- [[ 6.99999988e-01, 5.00000000e-01]]))
6798
+ Deprecated
6903
6799
  """
6904
6800
 
6905
6801
  __mindspore_signature__ = (
@@ -6910,6 +6806,7 @@ class SparseApplyFtrlV2(PrimitiveWithInfer):
6910
6806
  sig.make_sig('indices', dtype=sig.sig_dtype.T1)
6911
6807
  )
6912
6808
 
6809
+ @deprecated("2.1", "ops.SparseApplyFtrl", False)
6913
6810
  @prim_attr_register
6914
6811
  def __init__(self, lr, l1, l2, l2_shrinkage, lr_power, use_locking=False):
6915
6812
  """Initialize SparseApplyFtrlV2."""
@@ -6920,18 +6817,18 @@ class SparseApplyFtrlV2(PrimitiveWithInfer):
6920
6817
  self.lr = validator.check_positive_float(lr, "lr", self.name)
6921
6818
  self.l1 = validator.check_non_negative_float(l1, "l1", self.name)
6922
6819
  self.l2 = validator.check_non_negative_float(l2, "l2", self.name)
6923
- self.lr_power = validator.check_number("lr_power", lr_power, 0, Rel.LE, self.name)
6820
+ self.lr_power = validator.check_number("lr_power", lr_power, 0, validator.LE, self.name)
6924
6821
  self.l2_shrinkage = validator.check_value_type("l2_shrinkage", l2_shrinkage, [float], self.name)
6925
6822
  self.use_locking = validator.check_value_type("use_locking", use_locking, [bool], self.name)
6926
6823
  self.add_prim_attr('side_effect_mem', True)
6927
6824
 
6928
6825
  def infer_shape(self, var_shape, accum_shape, linear_shape, grad_shape, indices_shape):
6929
- validator.check('var shape', var_shape, 'accum shape', accum_shape, Rel.EQ, self.name)
6930
- validator.check('var shape', var_shape, 'linear shape', linear_shape, Rel.EQ, self.name)
6826
+ validator.check('var shape', var_shape, 'accum shape', accum_shape, validator.EQ, self.name)
6827
+ validator.check('var shape', var_shape, 'linear shape', linear_shape, validator.EQ, self.name)
6931
6828
  if len(var_shape) > 1:
6932
- validator.check('var_shape[1:]', var_shape[1:], 'grad_shape[1:]', grad_shape[1:], Rel.EQ, self.name)
6933
- validator.check_int(len(indices_shape), 1, Rel.EQ, "indices rank", self.name)
6934
- validator.check('grad_shape[0]', grad_shape[0], 'indices_shape[0]', indices_shape[0], Rel.EQ, self.name)
6829
+ validator.check('var_shape[1:]', var_shape[1:], 'grad_shape[1:]', grad_shape[1:], validator.EQ, self.name)
6830
+ validator.check_int(len(indices_shape), 1, validator.EQ, "indices rank", self.name)
6831
+ validator.check('grad_shape[0]', grad_shape[0], 'indices_shape[0]', indices_shape[0], validator.EQ, self.name)
6935
6832
  return var_shape, accum_shape, linear_shape
6936
6833
 
6937
6834
  def infer_dtype(self, var_dtype, accum_dtype, linear_dtype, grad_dtype, indices_dtype):
@@ -6954,11 +6851,11 @@ class Dropout(PrimitiveWithCheck):
6954
6851
  ``Ascend`` ``GPU`` ``CPU``
6955
6852
 
6956
6853
  Examples:
6957
- >>> dropout = ops.Dropout3D(keep_prob=0.5)
6854
+ >>> dropout = ops.Dropout(keep_prob=0.5)
6958
6855
  >>> x = Tensor(np.ones([1, 2, 3, 4, 5]), mindspore.float32)
6959
6856
  >>> output, mask = dropout(x)
6960
- >>> print(output.shape)
6961
- (1, 2, 3, 4, 5)
6857
+ >>> print(output.shape, mask.shape, mask.dtype)
6858
+ (1, 2, 3, 4, 5) (16,) UInt8
6962
6859
  """
6963
6860
 
6964
6861
  @prim_attr_register
@@ -6966,10 +6863,10 @@ class Dropout(PrimitiveWithCheck):
6966
6863
  """Initialize Dropout."""
6967
6864
  self.seed0 = validator.check_value_type("Seed0", Seed0, [int], self.name)
6968
6865
  self.seed1 = validator.check_value_type("Seed1", Seed1, [int], self.name)
6969
- self.keep_prob = validator.check_float_range(keep_prob, 0, 1, Rel.INC_RIGHT, "keep_prob", self.name)
6866
+ self.keep_prob = validator.check_float_range(keep_prob, 0, 1, validator.INC_RIGHT, "keep_prob", self.name)
6970
6867
 
6971
6868
  def check_shape(self, x_shape):
6972
- validator.check_int(len(x_shape), 1, Rel.GE, "x_shape", self.name)
6869
+ validator.check_int(len(x_shape), 1, validator.GE, "x_shape", self.name)
6973
6870
 
6974
6871
  def check_dtype(self, x_dtype):
6975
6872
  valid_dtypes = (mstype.float16, mstype.float32, mstype.float64)
@@ -6987,7 +6884,25 @@ class Dropout2D(PrimitiveWithInfer):
6987
6884
  Note:
6988
6885
  The keep probability :math:`keep\_prob` is equal to :math:`1 - p` in :func:`mindspore.ops.dropout2d`.
6989
6886
 
6990
- Refer to :func:`mindspore.ops.dropout2d` for more details.
6887
+ Args:
6888
+ keep_prob (float, optional): The keep probability of a channel, between 0 and 1, e.g. `keep_prob` = 0.8,
6889
+ means dropping out 20% of channels. Default: 0.5.
6890
+
6891
+ Inputs:
6892
+ - **x** (Tensor) - A 4-D tensor with shape :math:`(N, C, H, W)`, where N is the batch size, C is the number
6893
+ of channels, H is the feature height, and W is the feature width. The data type should be int8, int16, int32,
6894
+ int64, float16 or float32.
6895
+
6896
+ Outputs:
6897
+ - **output** (Tensor) - With the same shape and data type as `x`.
6898
+ - **mask** (Tensor) - With the same shape as `x` and the data type is bool.
6899
+
6900
+ Raises:
6901
+ TypeError: If `x` is not a Tensor.
6902
+ TypeError: If dtype of `x` is not int8, int16, int32, int64, float16, float32 or float64.
6903
+ TypeError: If the data type of `keep_prob` is not float.
6904
+ ValueError: If `keep_prob` is out of the range `[0.0, 1.0]`.
6905
+ ValueError: If `x` shape is not `4D`.
6991
6906
 
6992
6907
  Supported Platforms:
6993
6908
  ``Ascend`` ``GPU`` ``CPU``
@@ -7005,7 +6920,7 @@ class Dropout2D(PrimitiveWithInfer):
7005
6920
  """Initialize Dropout2D."""
7006
6921
  super().__init__("Dropout2D")
7007
6922
  self.keep_prob = validator.check_value_type("keep_prob", keep_prob, [float], self.name)
7008
- self.keep_prob = validator.check_float_range(keep_prob, 0.0, 1.0, Rel.INC_BOTH, "keep_prob", self.name)
6923
+ self.keep_prob = validator.check_float_range(keep_prob, 0.0, 1.0, validator.INC_BOTH, "keep_prob", self.name)
7009
6924
 
7010
6925
 
7011
6926
  class Dropout3D(PrimitiveWithInfer):
@@ -7014,12 +6929,28 @@ class Dropout3D(PrimitiveWithInfer):
7014
6929
  with probability 1-`keep_prob` from a Bernoulli distribution(For a 5-dimensional tensor with a shape of NCDHW,
7015
6930
  the channel feature map refers to a 3-dimensional feature map with a shape of DHW).
7016
6931
 
7017
- Dropout3D can improve the independence between channel feature maps.
7018
-
7019
6932
  Note:
7020
6933
  The keep probability :math:`keep\_prob` is equal to :math:`1 - p` in :func:`mindspore.ops.dropout3d`.
7021
6934
 
7022
- Refer to :func:`mindspore.ops.dropout3d` for more details.
6935
+ Dropout3D can improve the independence between channel feature maps.
6936
+
6937
+ Args:
6938
+ keep_prob (float): The keep probability of a channel, between 0 and 1, e.g. `keep_prob` = 0.8,
6939
+ means dropping out 20% of channels. Default: 0.5.
6940
+
6941
+ Inputs:
6942
+ - **x** (Tensor) - A 5-D tensor with shape :math:`(N, C, D, H, W)`, where N is the batch size, C is the number
6943
+ of channels, D is the feature depth, H is the feature height, and W is the feature width.
6944
+ The data type should be int8, int16, int32, int64, float16 or float32.
6945
+
6946
+ Outputs:
6947
+ - **output** (Tensor) - With the same shape and data type as `x`.
6948
+ - **mask** (Tensor) - With the same shape as `x` and the data type is bool.
6949
+
6950
+ Raises:
6951
+ TypeError: If the data type of `keep_prob` is not float.
6952
+ ValueError: If `keep_prob` is out of the range [0.0, 1.0];
6953
+ or if the dim of input is not 5-D.
7023
6954
 
7024
6955
  Supported Platforms:
7025
6956
  ``Ascend`` ``GPU`` ``CPU``
@@ -7037,7 +6968,7 @@ class Dropout3D(PrimitiveWithInfer):
7037
6968
  """Initialize Dropout3D."""
7038
6969
  super().__init__("Dropout3D")
7039
6970
  self.keep_prob = validator.check_value_type("keep_prob", keep_prob, [float], self.name)
7040
- self.keep_prob = validator.check_float_range(keep_prob, 0.0, 1.0, Rel.INC_BOTH, "keep_prob", self.name)
6971
+ self.keep_prob = validator.check_float_range(keep_prob, 0.0, 1.0, validator.INC_BOTH, "keep_prob", self.name)
7041
6972
 
7042
6973
 
7043
6974
  class CTCLoss(Primitive):
@@ -7133,7 +7064,7 @@ class CTCGreedyDecoder(Primitive):
7133
7064
  Refer to :func:`mindspore.ops.ctc_greedy_decoder` for more details.
7134
7065
 
7135
7066
  Supported Platforms:
7136
- ``Ascend`` ``CPU``
7067
+ ``Ascend`` ``GPU`` ``CPU``
7137
7068
 
7138
7069
  Examples:
7139
7070
  >>> inputs = Tensor(np.array([[[0.6, 0.4, 0.2], [0.8, 0.6, 0.3]],
@@ -7173,23 +7104,24 @@ class BasicLSTMCell(PrimitiveWithInfer):
7173
7104
  def __init__(self, keep_prob=1.0, forget_bias=1.0, state_is_tuple=True, activation='tanh'):
7174
7105
  """Initialize BasicLSTMCell."""
7175
7106
  self.keep_prob = validator.check_value_type("keep_prob", keep_prob, [float], self.name)
7176
- self.keep_prob = validator.check_float_range(keep_prob, 0.0, 1.0, Rel.INC_BOTH, "keep_prob", self.name)
7107
+ self.keep_prob = validator.check_float_range(keep_prob, 0.0, 1.0, validator.INC_BOTH, "keep_prob", self.name)
7177
7108
  self.forget_bias = validator.check_value_type("forget_bias", forget_bias, [float], self.name)
7178
7109
  self.state_is_tuple = validator.check_value_type("state_is_tuple", state_is_tuple, [bool], self.name)
7179
7110
  self.activation = validator.check_string(activation, ['tanh'], "activation", self.name)
7180
7111
 
7181
7112
  def infer_shape(self, x_shape, h_shape, c_shape, w_shape, b_shape):
7182
- validator.check_int(len(x_shape), 2, Rel.EQ, "x rank", self.name)
7183
- validator.check_int(len(h_shape), 2, Rel.EQ, "h rank", self.name)
7184
- validator.check_int(len(c_shape), 2, Rel.EQ, "c rank", self.name)
7185
- validator.check_int(len(w_shape), 2, Rel.EQ, "w rank", self.name)
7186
- validator.check_int(len(b_shape), 1, Rel.EQ, "b rank", self.name)
7187
- validator.check("x_shape[0]", x_shape[0], "h_shape[0]", h_shape[0], Rel.EQ, self.name)
7188
- validator.check("c_shape[0]", c_shape[0], "h_shape[0]", h_shape[0], Rel.EQ, self.name)
7189
- validator.check("c_shape[1]", c_shape[1], "h_shape[1]", h_shape[1], Rel.EQ, self.name)
7190
- validator.check("w_shape[1]", w_shape[1], "4*h_shape[1]", 4 * h_shape[1], Rel.EQ, self.name)
7191
- validator.check("w_shape[0]", w_shape[0], "x_shape[1]+h_shape[1]", x_shape[1] + h_shape[1], Rel.EQ, self.name)
7192
- validator.check("b_shape[0]", b_shape[0], "4*h_shape[1]", 4 * h_shape[1], Rel.EQ, self.name)
7113
+ validator.check_int(len(x_shape), 2, validator.EQ, "x rank", self.name)
7114
+ validator.check_int(len(h_shape), 2, validator.EQ, "h rank", self.name)
7115
+ validator.check_int(len(c_shape), 2, validator.EQ, "c rank", self.name)
7116
+ validator.check_int(len(w_shape), 2, validator.EQ, "w rank", self.name)
7117
+ validator.check_int(len(b_shape), 1, validator.EQ, "b rank", self.name)
7118
+ validator.check("x_shape[0]", x_shape[0], "h_shape[0]", h_shape[0], validator.EQ, self.name)
7119
+ validator.check("c_shape[0]", c_shape[0], "h_shape[0]", h_shape[0], validator.EQ, self.name)
7120
+ validator.check("c_shape[1]", c_shape[1], "h_shape[1]", h_shape[1], validator.EQ, self.name)
7121
+ validator.check("w_shape[1]", w_shape[1], "4*h_shape[1]", 4 * h_shape[1], validator.EQ, self.name)
7122
+ validator.check("w_shape[0]", w_shape[0], "x_shape[1]+h_shape[1]", x_shape[1] + h_shape[1],
7123
+ validator.EQ, self.name)
7124
+ validator.check("b_shape[0]", b_shape[0], "4*h_shape[1]", 4 * h_shape[1], validator.EQ, self.name)
7193
7125
  ct_shape = c_shape
7194
7126
  ht_shape = c_shape
7195
7127
  it_shape = c_shape
@@ -7242,8 +7174,10 @@ class DynamicRNN(Primitive):
7242
7174
  keep_prob (float): A float identifying the keep prob in the operator. Default: 1.0.
7243
7175
  cell_clip (float): A float identifying the cell clip in the operator. Default: -1.0.
7244
7176
  num_proj (int): An integer identifying the number projection in the operator. Default: 0.
7245
- time_major (bool): A bool identifying the time major in the operator. Default: True.
7246
- Only `True` is currently supported.
7177
+ time_major (bool): A bool specify the data format of `x`. If it is set to True, the format is
7178
+ :math:`(num\_step, batch\_size, input\_size)`, if it is set to False, the format is
7179
+ :math:`(batch\_size, num\_step, input\_size)`.
7180
+ Default: True. Only supports True at present.
7247
7181
  activation (str): A string identifying the type of activation function in the operator. Default: 'tanh'.
7248
7182
  Only 'tanh' is currently supported.
7249
7183
  forget_bias (float): A float identifying the forget bias in the operator. Default: 0.0.
@@ -7500,7 +7434,7 @@ class InTopK(Primitive):
7500
7434
  validator.check_value_type("k", k, [int], self.name)
7501
7435
 
7502
7436
 
7503
- class LRN(PrimitiveWithInfer):
7437
+ class LRN(Primitive):
7504
7438
  r"""
7505
7439
  Local Response Normalization.
7506
7440
 
@@ -7509,7 +7443,7 @@ class LRN(PrimitiveWithInfer):
7509
7443
  b_{c} = a_{c}\left(k + \frac{\alpha}{n}
7510
7444
  \sum_{c'=\max(0, c-n/2)}^{\min(N-1,c+n/2)}a_{c'}^2\right)^{-\beta}
7511
7445
 
7512
- where the :math:`a_{c}` indicates the specific value of the pixel corresponding to c in feature map;
7446
+ where the :math:`a_{c}` indicates the specific value of the pixel corresponding to :math:`c` in feature map;
7513
7447
  where the :math:`n/2` indicates the `depth_radius`; where the :math:`k` indicates the `bias`;
7514
7448
  where the :math:`\alpha` indicates the `alpha`; where the :math:`\beta` indicates the `beta`.
7515
7449
 
@@ -7599,10 +7533,10 @@ class AvgPool3D(Primitive):
7599
7533
 
7600
7534
  - pad: Implicit paddings on both sides of the input in depth, height, width. The number of `pad` will
7601
7535
  be padded to the input Tensor borders. `pad` must be greater than or equal to 0.
7602
- pad (Union(int, tuple[int])): The pad value to be filled. Default: 0. If `pad` is an integer, the paddings of
7603
- head, tail, top, bottom, left and right are the same, equal to pad. If `pad` is a tuple of six
7604
- integers, the padding of head, tail, top, bottom, left and right equal to pad[0], pad[1], pad[2],
7605
- pad[3], pad[4] and pad[5] correspondingly.
7536
+ pad (Union(int, tuple[int], list[int])): The pad value to be filled. Default: 0. If `pad` is an integer,
7537
+ the paddings of head, tail, top, bottom, left and right are the same, equal to pad.
7538
+ If `pad` is a tuple of six integers, the padding of head, tail, top, bottom, left and right equal to
7539
+ pad[0], pad[1], pad[2], pad[3], pad[4] and pad[5] correspondingly.
7606
7540
  ceil_mode (bool): If True, ceil instead of floor to compute the output shape. Default: False.
7607
7541
  count_include_pad (bool): If True, averaging calculation will include the zero-padding. Default: True.
7608
7542
  divisor_override (int): If specified, it will be used as divisor in the averaging calculation,
@@ -7650,7 +7584,7 @@ class AvgPool3D(Primitive):
7650
7584
  self.add_prim_attr('kernel_size', self.kernel_size)
7651
7585
  self.strides = _check_3d_int_or_tuple('strides', strides, self.name, ret_five=True)
7652
7586
  self.add_prim_attr('strides', self.strides)
7653
- validator.check_value_type('pad', pad, (int, tuple), self.name)
7587
+ validator.check_value_type('pad', pad, (int, tuple, list), self.name)
7654
7588
  if isinstance(pad, int):
7655
7589
  pad = (pad,) * 6
7656
7590
  if len(pad) != 6:
@@ -7678,7 +7612,104 @@ class Conv3D(Primitive):
7678
7612
  r"""
7679
7613
  3D convolution layer.
7680
7614
 
7681
- Refer to :func:`mindspore.ops.conv3d` for more details.
7615
+ Applies a 3D convolution over an input tensor which is typically of shape
7616
+ :math:`(N, C_{in}, D_{in}, H_{in}, W_{in})` and output shape
7617
+ :math:`(N, C_{out}, D_{out}, H_{out}, W_{out})`, where :math:`N` is batch size, :math:`C` is channel number,
7618
+ :math:`D` is depth, :math:`H, W` is feature height and width respectively.
7619
+ the output value of a layer is calculated as:
7620
+
7621
+ .. math::
7622
+
7623
+ \operatorname{out}\left(N_{i}, C_{\text {out}_j}\right)=\operatorname{bias}\left(C_{\text {out}_j}\right)+
7624
+ \sum_{k=0}^{C_{in}-1} ccor(\text {weight}\left(C_{\text {out}_j}, k\right),
7625
+ \operatorname{input}\left(N_{i}, k\right))
7626
+
7627
+ where :math:`k` is kernel,
7628
+ :math:`ccor` is the `cross-correlation <https://en.wikipedia.org/wiki/Cross-correlation>`_ ,
7629
+ :math:`C_{in}` is the channel number of the input, :math:`out_{j}` corresponds to the jth channel of
7630
+ the output and :math:`j` is in the range of :math:`[0, C_{out}-1]`. :math:`\text{weight}(C_{\text{out}_j}, k)`
7631
+ is a convolution kernel slice with shape
7632
+ :math:`(\text{kernel_size[0]}, \text{kernel_size[1]}, \text{kernel_size[2]})`,
7633
+ where :math:`\text{kernel_size[0]}`, :math:`\text{kernel_size[1]}` and :math:`\text{kernel_size[2]}` are
7634
+ the depth, height and width of the convolution kernel respectively. :math:`\text{bias}` is the bias parameter
7635
+ and :math:`\text{X}` is the input tensor.
7636
+ The shape of full convolution kernel is
7637
+ :math:`(C_{out}, C_{in} / \text{groups}, \text{kernel_size[0]}, \text{kernel_size[1]}, \text{kernel_size[2]})`,
7638
+ where `groups` is the number of groups to split `input` in the channel dimension.
7639
+
7640
+ For more details, please refer to the paper `Gradient Based Learning Applied to Document
7641
+ Recognition <http://vision.stanford.edu/cs598_spring07/papers/Lecun98.pdf>`_ .
7642
+
7643
+ If the 'pad_mode' is set to be "valid", the output depth, height and width will be
7644
+ :math:`\left \lfloor{1 + \frac{D_{in} + 2 \times \text{padding} - \text{ks_d} -
7645
+ (\text{ks_d} - 1) \times (\text{dilation} - 1) }{\text{stride}}} \right \rfloor` and
7646
+ :math:`\left \lfloor{1 + \frac{H_{in} + 2 \times \text{padding} - \text{ks_h} -
7647
+ (\text{ks_h} - 1) \times (\text{dilation} - 1) }{\text{stride}}} \right \rfloor` and
7648
+ :math:`\left \lfloor{1 + \frac{W_{in} + 2 \times \text{padding} - \text{ks_w} -
7649
+ (\text{ks_w} - 1) \times (\text{dilation} - 1) }{\text{stride}}} \right \rfloor` respectively. Where
7650
+ :math:`dilation` is Spacing between kernel elements, :math:`stride` is The step length of each step,
7651
+ :math:`padding` is zero-padding added to both sides of the input.
7652
+
7653
+ Args:
7654
+ out_channel (int): The number of output channel :math:`C_{out}`.
7655
+ kernel_size (Union[int, tuple[int]]): Specifies the depth, height
7656
+ and width of the 3D convolution window. It can be a single int or a tuple of 3 integers.
7657
+ Single int means the value is for the depth, height and width
7658
+ of the kernel. A tuple of 3 ints corresponds to the depth, height and width of the kernel respectively.
7659
+ mode (int): Modes for different convolutions. It is currently not used. Default: 1.
7660
+ stride (Union[int, tuple[int]], optional): The distance of kernel moving, it can be an int number
7661
+ that represents the depth, height and width of movement or a tuple of three int numbers that
7662
+ represent depth, height and width movement respectively. Default: 1.
7663
+ pad_mode (str, optional): Specifies padding mode. The optional values are
7664
+ "same", "valid" and "pad". Default: "valid".
7665
+
7666
+ - same: Adopts the way of completion. The depth, height and width of the output will be equal to
7667
+ the input `x` divided by stride. The padding will be evenly calculated in head and tail, top and bottom,
7668
+ left and right directions possiblily.
7669
+ Otherwise, the last extra padding will be calculated from the tail, bottom and the right side.
7670
+ If this mode is set, `pad` must be 0.
7671
+
7672
+ - valid: Adopts the way of discarding. The possible largest depth, height and width of output
7673
+ will be returned without padding. Extra pixels will be discarded. If this mode is set, `pad`
7674
+ must be 0.
7675
+
7676
+ - pad: Implicit paddings on both sides of the input in depth, height and width. The number of `pad` will
7677
+ be padded to the input Tensor borders. `pad` must be greater than or equal to 0.
7678
+
7679
+ pad (Union(int, tuple[int])): The pad value to be filled. Default: 0. If `pad` is an integer, the paddings of
7680
+ head, tail, top, bottom, left and right are the same, equal to pad. If `pad` is a tuple of six
7681
+ integers, the padding of head, tail, top, bottom, left and right equal to pad[0], pad[1], pad[2],
7682
+ pad[3], pad[4] and pad[5] correspondingly.
7683
+ dilation (Union[int, tuple[int]], optional): The data type is int or a tuple of 3 integers
7684
+ :math:`(dilation_d, dilation_h, dilation_w)`. Currently, dilation on depth only supports the case of 1
7685
+ on Ascend backend. Specifies the dilation rate to use for dilated convolution. If set :math:`k > 1`,
7686
+ there will be :math:`k - 1` pixels skipped for each sampling location.
7687
+ The value ranges for the depth, height, and width dimensions are [1, D], [1, H], and [1, W],
7688
+ respectively. Default: 1.
7689
+ group (int, optional):The number of groups into which the filter is divided. `in_channels`
7690
+ and `out_channels` must be divisible by `group`. Default: 1.
7691
+ data_format (str): The optional value for data format. Currently only support "NCDHW".
7692
+
7693
+ Inputs:
7694
+ - **x** (Tensor) - Tensor of shape :math:`(N, C_{in}, D_{in}, H_{in}, W_{in})`.
7695
+ Currently input data type only support float16 and float32.
7696
+ - **weight** (Tensor) - Set size of kernel is :math:`(k_d, K_h, K_w)`, then the shape is
7697
+ :math:`(C_{out}, C_{in}/groups, k_d, K_h, K_w)`.
7698
+ Currently weight data type only support float16 and float32.
7699
+ - **bias** (Tensor) - Tensor of shape :math:`C_{in}`. Currently, only support none.
7700
+
7701
+ Outputs:
7702
+ Tensor, the value that applied 3D convolution. The shape is :math:`(N, C_{out}, D_{out}, H_{out}, W_{out})`.
7703
+
7704
+ Raises:
7705
+ TypeError: If `out_channel` or `group` is not an int.
7706
+ TypeError: If `kernel_size`, `stride`, `pad` or `dilation` is neither an int nor a tuple.
7707
+ ValueError: If `out_channel`, `kernel_size`, `stride` or `dilation` is less than 1.
7708
+ ValueError: If `pad` is less than 0.
7709
+ ValueError: If `pad_mode` is not one of 'same', 'valid' or 'pad'.
7710
+ ValueError: If `pad` is a tuple whose length is not equal to 6.
7711
+ ValueError: If `pad_mode` is not equal to 'pad' and `pad` is not equal to (0, 0, 0, 0, 0, 0).
7712
+ ValueError: If `data_format` is not 'NCDHW'.
7682
7713
 
7683
7714
  Supported Platforms:
7684
7715
  ``Ascend`` ``GPU`` ``CPU``
@@ -7741,7 +7772,11 @@ class Conv3D(Primitive):
7741
7772
  self.add_prim_attr('data_format', self.format)
7742
7773
  self.out_channel = validator.check_positive_int(out_channel, 'out_channel', self.name)
7743
7774
  validator.check_value_type("group", group, (int,), self.name)
7744
- validator.check_int_range(group, 1, out_channel, Rel.INC_BOTH, "group", self.name)
7775
+ validator.check_int_range(group, 1, out_channel, validator.INC_BOTH, "group", self.name)
7776
+ device_target = context.get_context("device_target")
7777
+ if device_target == "Ascend" and group != 1:
7778
+ raise ValueError("On Ascend platform, group = 1 must be satisfied.")
7779
+
7745
7780
  self.group = group
7746
7781
  self.add_prim_attr('groups', self.group)
7747
7782
  self.add_prim_attr('offset_x', 0)
@@ -7963,7 +7998,7 @@ class SparseApplyAdadelta(Primitive):
7963
7998
  def __init__(self, epsilon, use_locking=False):
7964
7999
  """Initialize SparseApplyAdadelta"""
7965
8000
  validator.check_value_type("epsilon", epsilon, [float], self.name)
7966
- validator.check_number("epsilon", epsilon, 0.0, Rel.GE, self.name)
8001
+ validator.check_number("epsilon", epsilon, 0.0, validator.GE, self.name)
7967
8002
  validator.check_value_type("use_locking", use_locking, [bool], self.name)
7968
8003
 
7969
8004
 
@@ -7974,11 +8009,15 @@ class CTCLossV2(Primitive):
7974
8009
  The CTC algorithm is proposed in `Connectionist Temporal Classification: Labeling Unsegmented Sequence Data with
7975
8010
  Recurrent Neural Networks <http://www.cs.toronto.edu/~graves/icml_2006.pdf>`_.
7976
8011
 
8012
+ .. warning::
8013
+ This is an experimental API that is subject to change or deletion.
8014
+
7977
8015
  Args:
7978
8016
  blank (int, optional): The blank label. Default: 0.
7979
8017
  reduction (str, optional): Apply specific reduction method to the output. Currently only support 'none',
7980
8018
  not case sensitive. Default: "none".
7981
- zero_infinity (bool, optional): Whether to set infinite loss and correlation gradient to zero. Default: False.
8019
+ zero_infinity (bool, optional): If loss is infinite, this parameter determines whether to set that loss
8020
+ and its correlated gradient to zero. Default: False.
7982
8021
 
7983
8022
  Inputs:
7984
8023
  - **log_probs** (Tensor) - A tensor of shape :math:`(T, C, N)`, where :math:`T` is input length, :math:`N` is
@@ -8001,19 +8040,19 @@ class CTCLossV2(Primitive):
8001
8040
  TypeError: If the dtype of `targets`, `input_lengths` or `target_lengths` is not int32 or int64.
8002
8041
  ValueError: If the rank of `log_probs` is not 3.
8003
8042
  ValueError: If the rank of `targets` is not 2.
8004
- ValueError: If the shape of `input_lengths` does not match {batch_size|N}.
8005
- ValueError: If the shape of `target_lengths` does not match {batch_size|N}.
8043
+ ValueError: If the shape of `input_lengths` does not match batch_size :math:`N`.
8044
+ ValueError: If the shape of `target_lengths` does not match batch_size :math:`N`.
8006
8045
  TypeError: If the types of `targets`, `input_lengths` or `target_lengths` are different.
8007
8046
  ValueError: If the value of `blank` is not in range [0, num_labels|C).
8008
8047
  RuntimeError: If any value of `input_lengths` is larger than (num_labels|C).
8009
- RuntimeError: If any `target_lengths[i]` is not in range [0, `input_length[i]` ].
8048
+ RuntimeError: If any `target_lengths[i]` is not in range [0, `input_length[i]`].
8010
8049
 
8011
8050
  Supported Platforms:
8012
8051
  ``Ascend`` ``GPU`` ``CPU``
8013
8052
 
8014
8053
  Examples:
8015
8054
  >>> log_probs = Tensor(np.array([[[0.3, 0.6, 0.6]],
8016
- [[0.9, 0.4, 0.2]]]).astype(np.float32))
8055
+ ... [[0.9, 0.4, 0.2]]]).astype(np.float32))
8017
8056
  >>> targets = Tensor(np.array([[0, 1]]), mstype.int32)
8018
8057
  >>> input_lengths = Tensor(np.array([2]), mstype.int32)
8019
8058
  >>> target_lengths = Tensor(np.array([1]), mstype.int32)
@@ -8258,17 +8297,19 @@ class Conv3DTranspose(Primitive):
8258
8297
  f"when 'pad_mode' is not \"pad\", but got 'output_padding' is "
8259
8298
  f"{output_padding} and 'pad_mode' is {pad_mode}.")
8260
8299
  self.add_prim_attr('output_padding', self.output_padding)
8261
- validator.check_int_range(self.kernel_size[0] * self.kernel_size[1] * self.kernel_size[2], 1, 343, Rel.INC_BOTH,
8262
- 'The product of height, width and depth of kernel_size belonging [1, 343]', self.name)
8263
- validator.check_int_range(self.stride[0] * self.stride[1] * self.stride[2], 1, 343, Rel.INC_BOTH,
8300
+ validator.check_int_range(self.kernel_size[0] * self.kernel_size[1] * self.kernel_size[2],
8301
+ 1, 343, validator.INC_BOTH,
8302
+ 'The product of height, width and depth of kernel_size belonging [1, 343]',
8303
+ self.name)
8304
+ validator.check_int_range(self.stride[0] * self.stride[1] * self.stride[2], 1, 343, validator.INC_BOTH,
8264
8305
  'The product of height, width and depth of stride belonging [1, 343]', self.name)
8265
- validator.check_int_range(self.stride[1] * self.stride[2], 1, 256, Rel.INC_BOTH,
8306
+ validator.check_int_range(self.stride[1] * self.stride[2], 1, 256, validator.INC_BOTH,
8266
8307
  'The product of height, width and depth of stride belonging [1, 256]', self.name)
8267
- validator.check_int_range(self.output_padding[2], 0, max(self.dilation[2], self.stride[2]), Rel.INC_LEFT,
8308
+ validator.check_int_range(self.output_padding[2], 0, max(self.dilation[2], self.stride[2]), validator.INC_LEFT,
8268
8309
  'output_padding_d belonging [0, max(stride_d, dilation_d))', self.name)
8269
- validator.check_int_range(self.output_padding[3], 0, max(self.dilation[3], self.stride[3]), Rel.INC_LEFT,
8310
+ validator.check_int_range(self.output_padding[3], 0, max(self.dilation[3], self.stride[3]), validator.INC_LEFT,
8270
8311
  'output_padding_h belonging [0, max(stride_h,dilation_h))', self.name)
8271
- validator.check_int_range(self.output_padding[4], 0, max(self.dilation[4], self.stride[4]), Rel.INC_LEFT,
8312
+ validator.check_int_range(self.output_padding[4], 0, max(self.dilation[4], self.stride[4]), validator.INC_LEFT,
8272
8313
  'output_padding_w belonging [0, max(stride_w,dilation_w))', self.name)
8273
8314
 
8274
8315
 
@@ -8286,7 +8327,9 @@ class Dilation2D(Primitive):
8286
8327
  \text{input}(N_i, C_j, s_0 \times h + d_0 \times m, s_1 \times w + d_1 \times n) + \text{filter}(C_j, m, n)
8287
8328
 
8288
8329
  .. warning::
8289
- This operator is an experimental operator.
8330
+ This is an experimental API that is subjected to change or deletion.
8331
+
8332
+ Note:
8290
8333
  If the input data type is float32, this operator is still executed in float16 mode.
8291
8334
 
8292
8335
  Args:
@@ -8301,7 +8344,7 @@ class Dilation2D(Primitive):
8301
8344
  each sampling location. Its value must be greater or equal to 1 and bounded by
8302
8345
  the height and width of the input `x`.
8303
8346
 
8304
- pad_mode (str): Specifies padding mode. The optional values are
8347
+ pad_mode (str, optional): Specifies padding mode. The optional values are
8305
8348
  "same", "valid". Default: "same". Both upper and lower case are supported.
8306
8349
 
8307
8350
  - same: Adopts the way of completion. The height and width of the output will be the same as
@@ -8309,10 +8352,10 @@ class Dilation2D(Primitive):
8309
8352
 
8310
8353
  - valid: Adopts the way of discarding. The possible largest height and width of output will be returned
8311
8354
  without padding. Extra pixels will be discarded.
8312
- data_format (str): The value for data format, only 'NCHW' is supported at present. Default: "NCHW".
8355
+ data_format (str, optional): The value for data format, only 'NCHW' is supported at present. Default: "NCHW".
8313
8356
 
8314
8357
  Inputs:
8315
- - **x** (Tensor) - Input data. A four dimension tensor with float16 or float32 data type. The shape must be
8358
+ - **x** (Tensor) - Input data. A 4-D Tensor, its shape must be
8316
8359
  :math:`(N, C_{in}, H_{in}, W_{in})`.
8317
8360
  - **filter** (Tensor) - A three dimension tensor with the same type as input. The shape must be
8318
8361
  :math:`(C_{in}, H_{filter}, W_{filter})`.
@@ -8398,10 +8441,10 @@ class SoftShrink(Primitive):
8398
8441
  r"""
8399
8442
  Applies the SoftShrink function element-wise.
8400
8443
 
8401
- Refer to :func:`mindspore.ops.soft_shrink` for more details.
8444
+ Refer to :func:`mindspore.ops.softshrink` for more details.
8402
8445
 
8403
8446
  Supported Platforms:
8404
- ``Ascend`` ``CPU`` ``GPU``
8447
+ ``Ascend`` ``GPU`` ``CPU``
8405
8448
 
8406
8449
  Examples:
8407
8450
  >>> import mindspore
@@ -8419,7 +8462,7 @@ class SoftShrink(Primitive):
8419
8462
  def __init__(self, lambd=0.5):
8420
8463
  """Initialize SoftShrink"""
8421
8464
  validator.check_value_type("lambd", lambd, [float], self.name)
8422
- validator.check_number("lambd", lambd, 0, Rel.GE, self.name)
8465
+ validator.check_number("lambd", lambd, 0, validator.GE, self.name)
8423
8466
 
8424
8467
 
8425
8468
  class HShrink(Primitive):
@@ -8429,7 +8472,7 @@ class HShrink(Primitive):
8429
8472
  Refer to :func:`mindspore.ops.hardshrink` for more details.
8430
8473
 
8431
8474
  Supported Platforms:
8432
- ``Ascend`` ``CPU`` ``GPU``
8475
+ ``Ascend`` ``GPU`` ``CPU``
8433
8476
 
8434
8477
  Examples:
8435
8478
  >>> import mindspore as ms
@@ -8486,9 +8529,9 @@ class ApplyAdagradDA(Primitive):
8486
8529
  Inputs:
8487
8530
  - **var** (Parameter) - Variable to be updated. The data type must be float16 or float32.
8488
8531
  The shape is :math:`(N, *)` where :math:`*` means, any number of additional dimensions.
8489
- - **gradient_accumulator** (Parameter) - The dict of mutable tensor gradient_accumulator. Must have the same
8532
+ - **gradient_accumulator** (Parameter) - The dict of mutable tensor :math:`grad\_accum`. Must have the same
8490
8533
  shape and dtype as `var`.
8491
- - **gradient_squared_accumulator** (Parameter) - The dict of mutable tensor gradient_squared_accumulator.
8534
+ - **gradient_squared_accumulator** (Parameter) - The dict of mutable tensor :math:`grad\_squared\_accum`.
8492
8535
  Must have the same shape and dtype as `var`.
8493
8536
  - **grad** (Tensor) - A tensor for gradient. Must have the same shape and dtype as `var`.
8494
8537
  - **lr** ([Number, Tensor]) - Scaling factor. Must be a scalar. With float32 or float16 data type.
@@ -8634,7 +8677,7 @@ class SparseApplyRMSProp(Primitive):
8634
8677
  RuntimeError: If the data type of `var`, `ms`, `mom` and `grad` conversion of Parameter is not supported.
8635
8678
 
8636
8679
  Supported Platforms:
8637
- ``Ascend`` ``CPU`` ``GPU``
8680
+ ``Ascend`` ``GPU`` ``CPU``
8638
8681
 
8639
8682
  Examples:
8640
8683
  >>> class SparseApplyRMSPropNet(nn.Cell):
@@ -8682,9 +8725,9 @@ class SparseApplyRMSProp(Primitive):
8682
8725
  validator.check_value_type("momentum", momentum, [float], self.name)
8683
8726
  validator.check_value_type("epsilon", epsilon, [float], self.name)
8684
8727
  validator.check_value_type("use_locking", use_locking, [bool], self.name)
8685
- self.epsilon = validator.check_number("epsilon", epsilon, 0.0, Rel.GT, self.name)
8686
- self.momentum = validator.check_number("momentum", momentum, 0.0, Rel.GE, self.name)
8687
- self.rho = validator.check_float_range(rho, 0.0, 1.0, Rel.INC_BOTH, "rho", self.name)
8728
+ self.epsilon = validator.check_number("epsilon", epsilon, 0.0, validator.GT, self.name)
8729
+ self.momentum = validator.check_number("momentum", momentum, 0.0, validator.GE, self.name)
8730
+ self.rho = validator.check_float_range(rho, 0.0, 1.0, validator.INC_BOTH, "rho", self.name)
8688
8731
 
8689
8732
 
8690
8733
  class SparseApplyCenteredRMSProp(Primitive):
@@ -8751,13 +8794,9 @@ class SparseApplyCenteredRMSProp(Primitive):
8751
8794
  ValueError: If shape of `grad` is not same as shape of `var` except first dimension.
8752
8795
 
8753
8796
  Supported Platforms:
8754
- ``GPU`` ``CPU``
8797
+ ``Ascend`` ``GPU`` ``CPU``
8755
8798
 
8756
8799
  Examples:
8757
- >>> import numpy as np
8758
- >>> from mindspore import Tensor
8759
- >>> import mindspore.common.dtype as mstype
8760
- >>> import mindspore.ops.operations.nn_ops as nn_ops
8761
8800
  >>> var = Tensor(np.array([[0.6, 0.4], [0.1, 0.5]]).astype(np.float32))
8762
8801
  >>> mg = Tensor(np.array([[0.1, 0.3], [0.1, 0.5]]).astype(np.float32))
8763
8802
  >>> ms = Tensor(np.array([[0.2, 0.1], [0.1, 0.2]]).astype(np.float32))
@@ -8776,10 +8815,10 @@ class SparseApplyCenteredRMSProp(Primitive):
8776
8815
  """
8777
8816
 
8778
8817
  __mindspore_signature__ = (
8779
- sig.make_sig('var', dtype=sig.sig_dtype.T),
8780
- sig.make_sig('mg', dtype=sig.sig_dtype.T),
8781
- sig.make_sig('ms', dtype=sig.sig_dtype.T),
8782
- sig.make_sig('mom', dtype=sig.sig_dtype.T),
8818
+ sig.make_sig('var', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T),
8819
+ sig.make_sig('mg', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T),
8820
+ sig.make_sig('ms', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T),
8821
+ sig.make_sig('mom', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T),
8783
8822
  sig.make_sig('lr', dtype=sig.sig_dtype.T),
8784
8823
  sig.make_sig('rho', dtype=sig.sig_dtype.T),
8785
8824
  sig.make_sig('momentum', dtype=sig.sig_dtype.T),
@@ -8894,13 +8933,12 @@ class ApplyKerasMomentum(Primitive):
8894
8933
 
8895
8934
  class MultilabelMarginLoss(Primitive):
8896
8935
  r"""
8897
- MultilabelMarginLoss operation.
8936
+ Creates a loss criterion that minimizes the hinge loss for multi-class
8937
+ classification tasks.
8938
+ It takes a 2D mini-batch Tensor :math:`x` as input and a 2D
8939
+ Tensor :math:`y` containing target class indices as output.
8898
8940
 
8899
- Creates a criterion that optimizes a multi-class multi-classification
8900
- hinge loss (margin-based loss) between input :math:`x` (a 2D mini-batch `Tensor`)
8901
- and output :math:`y` (which is a 2D `Tensor` of target class indices).
8902
-
8903
- Refer to :func:`mindspore.ops.multi_label_margin_loss` for more details.
8941
+ Refer to :func:`mindspore.ops.multilabel_margin_loss` for more details.
8904
8942
 
8905
8943
  Supported Platforms:
8906
8944
  ``Ascend`` ``GPU``
@@ -8976,7 +9014,7 @@ class ApplyAdamWithAmsgrad(Primitive):
8976
9014
  ValueError: If the shape of `beta1_power`, `beta2_power`, `lr` is not 0.
8977
9015
 
8978
9016
  Supported Platforms:
8979
- ``Ascend`` ``CPU`` ``GPU``
9017
+ ``Ascend`` ``GPU`` ``CPU``
8980
9018
 
8981
9019
  Examples:
8982
9020
  >>> class ApplyAdamWithAmsgradNet(nn.Cell):
@@ -9025,6 +9063,9 @@ class GridSampler3D(Primitive):
9025
9063
  Given an input and a grid, the output is calculated using the input values
9026
9064
  and pixel positions in the grid. Only volume (5-D) input is supported.
9027
9065
 
9066
+ .. warning::
9067
+ This is an experimental API that is subject to change or deletion.
9068
+
9028
9069
  Refer to :func:`mindspore.ops.grid_sample` for more details.
9029
9070
 
9030
9071
  Supported Platforms:
@@ -9062,35 +9103,40 @@ class FractionalMaxPool(Primitive):
9062
9103
  r"""
9063
9104
  Performs fractional max pooling on the input.
9064
9105
 
9065
- Fractional max pooling is similar to regular max pooling, In regular max pooling, you downsize an
9066
- input set by taking the maximum value of smaller N x N subsections of the set (often 2x2), and try
9067
- to reduce the set by a factor of N, where N is an integer. Fractional max pooling, means that the
9068
- overall reduction ratio N does not have to be an integer.
9069
- The sizes of the pooling regions are generated randomly but are fairly uniform.
9106
+ Fractional max pooling is similar to regular max pooling, but with the added flexibility of
9107
+ allowing the overall reduction ratio `N` to be a non-integer value. In regular max pooling,
9108
+ an input set is reduced in size by taking the maximum value of `N x N` (usually 2x2)
9109
+ subsections of the set, with the goal of reducing the set by a factor of `N`, where `N` is an integer.
9110
+
9111
+ In contrast, fractional max pooling uses randomly generated pool sizes that are fairly uniform in size.
9070
9112
 
9071
9113
  .. warning::
9072
9114
  "pooling_ratio", currently only supports row and col dimension and should be >= 1.0, the first
9073
- and last elements must be 1.0 because we don't allow pooling on batch and channels dimensions.
9115
+ and last elements must be 1.0 because pooling on batch and channels dimensions is not allowed.
9074
9116
 
9075
9117
  Args:
9076
- pooling_ratio (list(float)): Decide the shape of output, is a list of floats that has length >= 4.
9077
- Pooling ratio for each dimension of value should be >=0, currently only support for row and col
9078
- dimension. The first and last elements must be 1.0 because we don't allow pooling on batch and
9079
- channels dimensions.
9080
- pseudo_random(bool, optional): When set to True, generates the pooling
9081
- sequence in a pseudo random fashion, otherwise, in a random fashion.
9082
- Check paper Benjamin Graham, Fractional Max-Pooling for difference between pseudo_random and
9083
- random. Defaults to False.
9084
- overlapping(bool, optional): When set to True, it means when pooling,
9085
- the values at the boundary of adjacent pooling cells are used by both cells.
9086
- When set to False, the values are not reused. Defaults to False.
9087
- deterministic(bool, optional): When set to True, a fixed pooling region
9088
- will be used when iterating over a FractionalMaxPool node in the computation graph. Mainly
9089
- used in unit test to make FractionalMaxPool deterministic. When set to False,
9090
- fixed pool regions will not be used. Defaults to False.
9091
- seed(int, optional): If either seed or seed2 are set to be non-zero, the random number generator is
9092
- seeded by the given seed. Otherwise, it is seeded by a random seed. Defaults to 0.
9093
- seed2(int, optional): An second seed to avoid seed collision. Defaults to 0.
9118
+ pooling_ratio (list(float)): Decide the shape of output, is a list of float numbers has length >= 4.
9119
+ Pooling ratio for each dimension of value should not be less than 0, currently only support
9120
+ for row and col dimension.
9121
+ pseudo_random(bool, optional): Generate the pooling sequence either randomly or pseudo-randomly.
9122
+ If the pseudo_random parameter is set to True, the sequence will be generated in a
9123
+ pseudo-random fashion, otherwise it will be generated randomly.
9124
+ Refer to `Fractional Max-Pooling <https://arxiv.org/pdf/1412.6071>`_
9125
+ by Benjamin Graham to understand the distinction between the two.
9126
+ Default: False.
9127
+ overlapping(bool, optional): When set to True, the values at the boundary of adjacent pooling cells
9128
+ will be shared by both cells during pooling process. When set to False, the values are not reused.
9129
+ Default: False.
9130
+ deterministic(bool, optional): If deterministic is set to True, a fixed pooling region will be used
9131
+ in the computation graph, ensuring that the FractionalMaxPool is deterministic.
9132
+ This is often used in unit tests. When set to False, fixed pool regions will not be used.
9133
+ Default: False.
9134
+ seed(int, optional): If either seed or seed2 are set to a non-zero value, the random number
9135
+ generator will be seeded using the specified seed. If neither seed nor seed2 are set,
9136
+ the generator will be seeded by a random seed.
9137
+ Default: 0.
9138
+ seed2(int, optional): The second seed to avoid seed collision.
9139
+ Default: 0.
9094
9140
 
9095
9141
  Inputs:
9096
9142
  - **x** (Tensor) -The data type must be one of the following types: float32, float64, int32, int64.
@@ -9112,7 +9158,7 @@ class FractionalMaxPool(Primitive):
9112
9158
  ValueError: If the first and last element of `pooling_ratio` is not equal to 1.0.
9113
9159
 
9114
9160
  Supported Platforms:
9115
- ``GPU`` ``CPU``
9161
+ ``Ascend`` ``GPU`` ``CPU``
9116
9162
 
9117
9163
  Examples:
9118
9164
  >>> x = np.array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]).reshape([1,4,4,1]).astype(np.int64)
@@ -9143,9 +9189,10 @@ class FractionalMaxPool(Primitive):
9143
9189
 
9144
9190
  class FractionalMaxPool3DWithFixedKsize(Primitive):
9145
9191
  r"""
9146
- This operator applies a 3D fractional max pooling over an input signal composed of several input planes.
9147
- The max-pooling operation is applied in kD x kH x kW regions by a stochastic step size determined
9148
- by the target output size.
9192
+ Applies a 3D fractional max pooling to an input signal composed of multiple input planes.
9193
+ The max-pooling operation is applied in :math:`(kD, kH, kW)` regions by a stochastic step size determined by
9194
+ the target output size `output_shape`.
9195
+
9149
9196
  The number of output features is equal to the number of input planes.
9150
9197
 
9151
9198
  Refer to the paper `Fractional MaxPooling by Ben Graham <https://arxiv.org/abs/1412.6071>`_ for more details.
@@ -9154,13 +9201,11 @@ class FractionalMaxPool3DWithFixedKsize(Primitive):
9154
9201
  D the feature depth, H is the feature height, and W is the feature width.
9155
9202
 
9156
9203
  Args:
9157
- ksize (Union[float, tuple]): The target ksize is D x H x W.
9158
- ksize can be a tuple, or a single K for K x K x K.
9159
- specifying the window size (D, H, W) of the input tensor.
9160
- output_shape (Union[int, tuple]): The target output_shape is D x H x W.
9161
- output_shape can be a tuple, or a single H for H x H x H.
9162
- specifying the size (D, H, W) of the output tensor.
9163
- data_format (str) : The optional value for data format.
9204
+ ksize (Union[float, tuple]): Size of the pooling window. `ksize` can be a tuple of three values specify a
9205
+ shape :math:`(k_D, k_H, k_W)`, or a single int `K` for :math:`(K, K, K)`.
9206
+ output_shape (Union[int, tuple]): The target output shape. `output_shape` can be a tuple of three values
9207
+ specify a shape :math:`(D_{out}, H_{out}, W_{out})`, or a single float `S` for :math:`(S, S, S)`.
9208
+ data_format (str, optional): The optional value for data format.
9164
9209
  Currently support 'NCDHW' and 'NHDWC'. Default: 'NCDHW'.
9165
9210
 
9166
9211
  Inputs:
@@ -9193,13 +9238,13 @@ class FractionalMaxPool3DWithFixedKsize(Primitive):
9193
9238
  ValueError: If the third dimension size of `random_samples` is not 3.
9194
9239
 
9195
9240
  Supported Platforms:
9196
- ``GPU`` ``CPU``
9241
+ ``Ascend`` ``GPU`` ``CPU``
9197
9242
 
9198
9243
  Examples:
9199
9244
  >>> x = Tensor(np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])
9200
9245
  ... .reshape([1, 1, 2, 2, 4]), mstype.float32)
9201
9246
  >>> random_samples = Tensor(np.array([0.7, 0.7, 0.7]).reshape([1, 1, 3]), mstype.float32)
9202
- >>> ksize = (1.0, 1.0, 1.0)
9247
+ >>> ksize = (1, 1, 1)
9203
9248
  >>> output_shape = (1, 1, 2)
9204
9249
  >>> net = ops.FractionalMaxPool3DWithFixedKsize(ksize = ksize, output_shape = output_shape)
9205
9250
  >>> output, argmax = net(x, random_samples)
@@ -9213,15 +9258,15 @@ class FractionalMaxPool3DWithFixedKsize(Primitive):
9213
9258
  def __init__(self, ksize, output_shape, data_format="NCDHW"):
9214
9259
  """Initialize FractionalMaxPool3DWithFixedKsize."""
9215
9260
  self.init_prim_io_names(inputs=["x", "random_samples"], outputs=["y", "argmax"])
9216
- validator.check_value_type("ksize", ksize, [float, tuple], self.name)
9261
+ validator.check_value_type("ksize", ksize, [int, tuple], self.name)
9217
9262
  self.ksize = ksize
9218
- if isinstance(self.ksize, float):
9263
+ if isinstance(self.ksize, int):
9219
9264
  self.ksize = (ksize, ksize, ksize)
9220
9265
  if len(self.ksize) != 3:
9221
- raise ValueError(f"For '{self.name}', attr 'ksize' must be an positive float number or a tuple of "
9222
- f"three float numbers, but got {len(self.ksize)} numbers.")
9266
+ raise ValueError(f"For '{self.name}', attr 'ksize' must be an positive int number or a tuple of "
9267
+ f"three int numbers, but got {len(self.ksize)} numbers.")
9223
9268
  for item in self.ksize:
9224
- validator.check_positive_float(item, 'ksize item', self.name)
9269
+ validator.check_positive_int(item, 'ksize item', self.name)
9225
9270
  self.output_shape = validator.check_value_type("output_shape", output_shape, [int, tuple], self.name)
9226
9271
  self.data_format = validator.check_string(data_format, ['NCDHW', 'NDHWC'], 'data_format', self.name)
9227
9272
  self.output_shape = _check_3d_int_or_tuple("output_shape", output_shape,
@@ -9234,11 +9279,10 @@ class FractionalAvgPool(Primitive):
9234
9279
  r"""
9235
9280
  Performs fractional avg pooling on the input.
9236
9281
 
9237
- Fractional avg pooling is similar to regular avg pooling, In regular avg pooling, you downsize an
9238
- input set by taking the avgrage value of smaller N x N subsections of the set (often 2x2), and try
9239
- to reduce the set by a factor of N, where N is an integer. Fractional avg pooling, means that the
9240
- overall reduction ratio N does not have to be an integer. In each pooling region, a mean operation
9241
- is performed.
9282
+ Fractional avg pooling is similar to regular avg pooling, but with the added flexibility of
9283
+ allowing the overall reduction ratio `N` to be a non-integer value. In regular avg pooling,
9284
+ an input set is reduced in size by taking the average value of `N x N` (usually 2x2)
9285
+ subsections of the set, with the goal of reducing the set by a factor of `N`, where `N` is an integer.
9242
9286
 
9243
9287
  .. warning::
9244
9288
  "pooling_ratio", currently only supports row and col dimension and should be >= 1.0, the first
@@ -9249,20 +9293,25 @@ class FractionalAvgPool(Primitive):
9249
9293
  Pooling ratio for each dimension of value should be >=0, currently only support for row and col
9250
9294
  dimension. The first and last elements must be 1.0 because we don't allow pooling on batch and
9251
9295
  channels dimensions.
9252
- pseudo_random(bool, optional): When set to True, generates the pooling
9253
- sequence in a pseudorandom fashion, otherwise, in a random fashion.
9254
- Check paper Benjamin Graham, Fractional Max-Pooling for difference between pseudo_random and
9255
- random. Defaults to False.
9256
- overlapping(bool, optional): When set to True, it means when pooling,
9257
- the values at the boundary of adjacent pooling cells are used by both cells.
9258
- When set to False, the values are not reused. Defaults to False.
9259
- deterministic(bool, optional): When set to True, a fixed pooling region
9260
- will be used when iterating over a FractionalAvgPool node in the computation graph. Mainly
9261
- used in unit test to make FractionalAvgPool deterministic. When set to False,
9262
- fixed pool regions will not be used. Defaults to False.
9263
- seed(int, optional): If either seed or seed2 are set to be non-zero, the random number generator
9264
- is seeded by the given seed. Otherwise, it is seeded by a random seed. Defaults to 0.
9265
- seed2(int, optional): An second seed to avoid seed collision. Defaults to 0.
9296
+ pseudo_random(bool, optional): Generate the pooling sequence either randomly or pseudo-randomly.
9297
+ If the pseudo_random parameter is set to True, the sequence will be generated in a
9298
+ pseudo-random fashion, otherwise it will be generated randomly.
9299
+ Refer to `Fractional Max-Pooling <https://arxiv.org/pdf/1412.6071>`_
9300
+ by Benjamin Graham to understand the distinction between the two.
9301
+ Default: False.
9302
+ overlapping(bool, optional): When set to True, the values at the boundary of adjacent pooling cells
9303
+ will be shared by both cells during pooling process. When set to False, the values are not reused.
9304
+ Default: False.
9305
+ deterministic(bool, optional): If deterministic is set to True, a fixed pooling region will be used
9306
+ in the computation graph, ensuring that the FractionalAvgPool is deterministic.
9307
+ This is often used in unit tests. When set to False, fixed pool regions will not be used.
9308
+ Default: False.
9309
+ seed(int, optional): If either seed or seed2 are set to a non-zero value, the random number
9310
+ generator will be seeded using the specified seed. If neither seed nor seed2 are set,
9311
+ the generator will be seeded by a random seed.
9312
+ Default: 0.
9313
+ seed2(int, optional): The second seed to avoid seed collision.
9314
+ Default: 0.
9266
9315
 
9267
9316
  Inputs:
9268
9317
  - **x** (Tensor) -The data type must be one of the following types: float32, float64, int32, int64.
@@ -9284,7 +9333,7 @@ class FractionalAvgPool(Primitive):
9284
9333
  ValueError: If the first and last element of `pooling_ratio` is not equal to 1.0.
9285
9334
 
9286
9335
  Supported Platforms:
9287
- ``GPU`` ``CPU``
9336
+ ``Ascend`` ``GPU`` ``CPU``
9288
9337
 
9289
9338
  Examples:
9290
9339
  >>> x = np.array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]).reshape([1,4,4,1]).astype(np.int64)
@@ -9315,20 +9364,23 @@ class FractionalAvgPool(Primitive):
9315
9364
 
9316
9365
  class NthElement(Primitive):
9317
9366
  r"""
9318
- Finds values of the n-th order statistic for the last dimension.
9319
- If the input is a vector (rank-1), finds the entries which is the nth-smallest value in
9320
- the vector and outputs their values as scalar tensor.
9321
- For matrices (resp. higher rank input), computes the entries which is the nth-smallest value in
9322
- each row (resp. vector along the last dimension). Thus, values.shape = input.shape[:-1].
9367
+ Computes the n-th smallest values for the last dimension of the input Tensor.
9368
+
9369
+ - When `input` is a 1-D Tensor (i.e. Vector), it finds the nth-smallest value in the vector
9370
+ and outputs its value as a scalar Tensor.
9371
+ - When `input` is matrices or has higher rank, it finds the nth-smallest value
9372
+ in each row (or vector along the last dimension) and outputs
9373
+ these values in a Tensor with shape of `values.shape = input.shape[:-1]`.
9323
9374
 
9324
9375
  Args:
9325
- reverse (bool, optional): An optional bool. When set to True, find the nth-largest value
9326
- in the vector and vice versa. Default: False.
9376
+ reverse (bool, optional): An optional bool. If set to True, it find the :math:`n`-th largest value
9377
+ in the vector instead of the nth-smallest. Default: False.
9327
9378
 
9328
9379
  Inputs:
9329
- - **input** (Tensor) - A Tensor. 1-D or higher with last dimension at least :math:`n+1`.
9330
- - **n** (Union[int, Tensor]) - If the n is a tensor, it should be a 0-D tensor, dtype is int32.
9331
- Valid range of n is :math:`[0, input.shape[-1])`.
9380
+ - **input** (Tensor) - Input Tensor with 1-D or higher dimension.
9381
+ - **n** (Union[int, Tensor]) - If the `n` is a Tensor, it should be a 0-D Tensor, dtype is int32.
9382
+ Valid range of `n` is :math:`[0, input.shape[-1])` where :math:`input.shape[-1]` is
9383
+ last dimension size of `input`.
9332
9384
 
9333
9385
  Outputs:
9334
9386
  - **values** (Tensor) - Its shape satisfies: `values`.shape = `input`.shape[:-1].
@@ -9340,7 +9392,7 @@ class NthElement(Primitive):
9340
9392
  ValueError**: If n is out of :math:`[0, input.shape[-1])`.
9341
9393
 
9342
9394
  Supported Platforms:
9343
- ``GPU`` ``CPU``
9395
+ ``Ascend`` ``GPU`` ``CPU``
9344
9396
 
9345
9397
  Examples:
9346
9398
  >>> input = Tensor(np.array([[1,2,3],[4,5,6]]) , mstype.int8)
@@ -9368,7 +9420,7 @@ class PSROIPooling(Primitive):
9368
9420
  spatial_scale (float): a scaling factor that maps the box coordinates to the input coordinates.
9369
9421
  For example, if your boxes are defined on the scale of a 224x224 image and
9370
9422
  your input is a 112x112 feature map (resulting from a 0.5x scaling of the original
9371
- image), youll want to set this to 0.5.
9423
+ image), you'll want to set this to 0.5.
9372
9424
  group_size (int): the size of the output (in pixels) after the pooling is performed, as (height, width).
9373
9425
  output_dim (int): the dim of the output after the pooling is performed.
9374
9426
 
@@ -9428,9 +9480,9 @@ class PSROIPooling(Primitive):
9428
9480
  ... group_size=7)
9429
9481
  >>> out = psROIPooling(features, rois)
9430
9482
  >>> print(out.shape)
9431
- (4, 3, 7, 7)
9483
+ (4, 3, 7, 7)
9432
9484
  >>> print(out.dtype)
9433
- Float32
9485
+ Float32
9434
9486
  """
9435
9487
 
9436
9488
  @prim_attr_register
@@ -9477,11 +9529,9 @@ class TripletMarginLoss(Primitive):
9477
9529
  Args:
9478
9530
  p (int, optional): The norm degree for pairwise distance. Default: 2.
9479
9531
  eps (float, optional): Default: 1e-06.
9480
- swap (bool, optional): The distance swap is described in detail in the paper
9481
- `Learning local feature descriptors with triplets and shallow convolutional neural networks`
9482
- by V. Balntas, E. Riba et al. Default: "False".
9532
+ swap (bool, optional): The distance swap. Default: False.
9483
9533
  reduction (str, optional): Apply specific reduction method to the
9484
- output: 'none', 'mean', 'sum'. Default: "mean".
9534
+ output: "none", "mean", "sum". Default: "mean".
9485
9535
 
9486
9536
  Inputs:
9487
9537
  - **x** (Tensor) - A sample randomly selected from the training set. Data type must be BasicType.
@@ -9512,7 +9562,7 @@ class TripletMarginLoss(Primitive):
9512
9562
  ValueError: If `reduction` is not one of 'none', 'mean', 'sum'.
9513
9563
 
9514
9564
  Supported Platforms:
9515
- ``GPU`` ``CPU``
9565
+ ``GPU``
9516
9566
 
9517
9567
  Examples:
9518
9568
  >>> loss = ops.TripletMarginLoss()
@@ -9542,7 +9592,7 @@ class DeformableOffsets(Primitive):
9542
9592
  Refer to :func:`mindspore.ops.deformable_conv2d` for more details.
9543
9593
 
9544
9594
  Supported Platforms:
9545
- ``Ascend`` ``CPU`` ``GPU``
9595
+ ``Ascend`` ``GPU`` ``CPU``
9546
9596
  """
9547
9597
 
9548
9598
  @prim_attr_register
@@ -9590,26 +9640,39 @@ class DeformableOffsets(Primitive):
9590
9640
 
9591
9641
  class GridSampler2D(Primitive):
9592
9642
  """
9593
- This operation samples 2d input_x by using interpolation based on flow field grid, which is usually gennerated by
9594
- :func:`mindspore.ops.affine_grid`.
9643
+ This operation samples 2d `input_x` by using interpolation based on flow field grid,
9644
+ which is usually gennerated by :func:`mindspore.ops.affine_grid`.
9645
+
9646
+ .. warning::
9647
+ This is an experimental API that is subject to change or deletion.
9595
9648
 
9596
9649
  Args:
9597
- interpolation_mode (str): An optional string specifying the interpolation method. The optional values are
9650
+ interpolation_mode (str, optional): An optional string specifying the interpolation method.
9651
+ The optional values are
9598
9652
  "bilinear" or "nearest". Default: "bilinear".
9599
- padding_mode (str): An optional string specifying the pad method. The optional values are "zeros", "border" or
9600
- "reflection". Default: "zeros".
9601
- align_corners (bool): An optional bool. When set to True, the centers of the corner pixels of the input
9653
+ padding_mode (str, optional): An optional string specifying the pad method.
9654
+ The optional values are "zeros", "border" or "reflection". Default: "zeros".
9655
+ When the sampling grid is outside input's bounds, effects of various padding modes are as follows:
9656
+
9657
+ - "zeros": Pads the input tensor with zeros.
9658
+ - "border": Pads the input tensor with the values of the pixels on the border of the tensor.
9659
+ - "reflection": Pads the input tensor by reflecting the values of the pixels at the
9660
+ boundary of the tensor.
9661
+
9662
+ align_corners (bool, optional): An optional bool. When set to True,
9663
+ the centers of the corner pixels of the input
9602
9664
  and output tensors are aligned. When set to False, it is not aligned. Defaults to False.
9603
9665
 
9604
9666
  Inputs:
9605
- - **input_x** (Tensor) - A 4-D tensor with dtype of float16 or float32 and shape of :math:`(N, C,
9606
- H_{in}, W_{in})`.
9607
- - **grid** (Tensor) - A 4-D tensor whose dtype is the same as `input_x` and whose shape is :math:`(N,
9608
- H_{out}, W_{out}, 2)`. Used to specify the sampling pixel locations normalized by the input spatial
9667
+ - **input_x** (Tensor) - A 4-D tensor with dtype of float16 or float32 and shape of
9668
+ :math:`(N, C, H_{in}, W_{in})`.
9669
+ - **grid** (Tensor) - A 4-D tensor whose dtype is the same as `input_x` and whose shape is
9670
+ :math:`(N, H_{out}, W_{out}, 2)`.
9671
+ Used to specify the sampling pixel locations normalized by the input spatial
9609
9672
  dimensions.
9610
9673
 
9611
9674
  Outputs:
9612
- A 4-D Tensor whose dtype is the same as `input_x` and whose shape is :math:`(N, C, H_{out}, W_{out})`.
9675
+ A 4-D Tensor whose dtype is the same as `input_x` and whose shape is :math:`(N, C, H_{out}, W_{out})`.
9613
9676
 
9614
9677
  Raises:
9615
9678
  TypeError: If `input_x` or `grid` is not a Tensor.
@@ -9661,37 +9724,16 @@ class Pdist(Primitive):
9661
9724
  r"""
9662
9725
  Computes the p-norm distance between each pair of row vectors in the input.
9663
9726
 
9664
- .. math::
9665
-
9666
- y[n] = \sqrt[p]{{\mid x_{i} - x_{j} \mid}^p},
9667
-
9668
- where :math:`x_{i}, x_{j}` are two different row vectors in the input.
9669
-
9670
- Args:
9671
- p (float): p value for the p norm distance to calculate between each vector pair ∈[0,∞]. Default: 2.0.
9672
-
9673
- Inputs:
9674
- - **x** (Tensor) - Input tensor with dtype of float16 or float32 and shape of :math:`(N, M)`.
9675
-
9676
- Outputs:
9677
- Tensor, has the same dtype as `x`, whose shape is :math:`(N * (N - 1) / 2)`.
9678
-
9679
- Raises:
9680
- TypeError: If `x` is not a Tensor.
9681
- TypeError: If dtype of `x` is not float16, float32 or float64.
9682
- TypeError: If `p` is not a float.
9683
- ValueError: If `p` is a negative float.
9684
- ValueError: If dimension of `x` is not 2.
9727
+ Refer to :func:`mindspore.ops.pdist` for more details.
9685
9728
 
9686
9729
  Supported Platforms:
9687
- ``Ascend`` ``CPU`` ``GPU``
9730
+ ``GPU`` ``CPU``
9688
9731
 
9689
9732
  Examples:
9690
- >>> from mindspore import Tensor
9691
- >>> from mindspore.ops.operations.nn_ops import Pdist
9733
+ >>> from mindspore import Tensor, ops
9692
9734
  >>> import numpy as np
9693
9735
  >>> x = Tensor(np.array([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0]]).astype(np.float32))
9694
- >>> op = Pdist(p=2.0)
9736
+ >>> op = ops.Pdist(p=2.0)
9695
9737
  >>> y = op(x)
9696
9738
  >>> print(y)
9697
9739
  [1.4142135 2.828427 1.4142135]
@@ -9743,7 +9785,7 @@ class UpsampleNearest3D(Primitive):
9743
9785
  ValueError: If size of `output_size` is not equal 3 when `output_size` is specified.
9744
9786
 
9745
9787
  Supported Platforms:
9746
- ``GPU`` ``CPU``
9788
+
9747
9789
 
9748
9790
  Examples:
9749
9791
  >>> x = Tensor(np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])
@@ -9776,10 +9818,10 @@ class UpsampleNearest3D(Primitive):
9776
9818
  scales = []
9777
9819
  validator.check_value_type('output_size', output_size, [tuple, list], self.name)
9778
9820
  for item in output_size:
9779
- validator.check_int(item, 0, Rel.GT, 'output_size_item', self.name)
9821
+ validator.check_int(item, 0, validator.GT, 'output_size_item', self.name)
9780
9822
  validator.check_value_type('scales', scales, [tuple, list], self.name)
9781
9823
  for item in scales:
9782
- validator.check_float(item, 0, Rel.GT, 'scales_item', self.name)
9824
+ validator.check_float(item, 0, validator.GT, 'scales_item', self.name)
9783
9825
  self.add_prim_attr('output_size', output_size)
9784
9826
  self.add_prim_attr('scales', scales)
9785
9827
 
@@ -9844,16 +9886,12 @@ class SparseApplyAdagradDA(Primitive):
9844
9886
  conversion of Parameter is not supported.
9845
9887
 
9846
9888
  Supported Platforms:
9847
- ``CPU``
9889
+ ``GPU`` ``CPU``
9848
9890
 
9849
9891
  Examples:
9850
- >>> import numpy as np
9851
- >>> from mindspore import Tensor
9852
- >>> import mindspore.common.dtype as mstype
9853
- >>> import mindspore.ops.operations.nn_ops as nn_ops
9854
- >>> var = Tensor(np.array([[1,2], [1,2]]).astype(np.float32))
9855
- >>> grad_accum = Tensor(np.array([[2,1], [3,1]]).astype(np.float32))
9856
- >>> grad_square_accum = Tensor(np.array([[4,1], [5,1]]).astype(np.float32))
9892
+ >>> var = Parameter(Tensor(np.array([[1,2], [1,2]]).astype(np.float32)))
9893
+ >>> grad_accum = Parameter(Tensor(np.array([[2,1], [3,1]]).astype(np.float32)))
9894
+ >>> grad_square_accum = Parameter(Tensor(np.array([[4,1], [5,1]]).astype(np.float32)))
9857
9895
  >>> grad = Tensor(np.array([[5,1], [6,1]]).astype(np.float32))
9858
9896
  >>> indices = Tensor(np.array([0, 1], dtype=np.int32))
9859
9897
  >>> lr = Tensor(2, mstype.float32)
@@ -9869,9 +9907,9 @@ class SparseApplyAdagradDA(Primitive):
9869
9907
  """
9870
9908
 
9871
9909
  __mindspore_signature__ = (
9872
- sig.make_sig('var', dtype=sig.sig_dtype.T),
9873
- sig.make_sig('grad_accum', dtype=sig.sig_dtype.T),
9874
- sig.make_sig('grad_square_accum', dtype=sig.sig_dtype.T),
9910
+ sig.make_sig('var', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T),
9911
+ sig.make_sig('grad_accum', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T),
9912
+ sig.make_sig('grad_square_accum', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T),
9875
9913
  sig.make_sig('grad', dtype=sig.sig_dtype.T),
9876
9914
  sig.make_sig('indices', dtype=sig.sig_dtype.T1),
9877
9915
  sig.make_sig('lr', dtype=sig.sig_dtype.T),
@@ -9941,7 +9979,7 @@ class SparseApplyMomentum(Primitive):
9941
9979
  is not supported.
9942
9980
 
9943
9981
  Supported Platforms:
9944
- ``CPU``
9982
+ ``GPU`` ``CPU``
9945
9983
 
9946
9984
  Examples:
9947
9985
  >>> import mindspore.ops.operations.nn_ops as nn_ops
@@ -10025,7 +10063,7 @@ class SparseApplyProximalGradientDescent(Primitive):
10025
10063
  is not supported.
10026
10064
 
10027
10065
  Supported Platforms:
10028
- ``CPU``
10066
+ ``GPU`` ``CPU``
10029
10067
 
10030
10068
  Examples:
10031
10069
  >>> import mindspore.ops.operations.nn_ops as nn_ops
@@ -10043,7 +10081,7 @@ class SparseApplyProximalGradientDescent(Primitive):
10043
10081
  """
10044
10082
 
10045
10083
  __mindspore_signature__ = (
10046
- sig.make_sig('var', dtype=sig.sig_dtype.T),
10084
+ sig.make_sig('var', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T),
10047
10085
  sig.make_sig('alpha', dtype=sig.sig_dtype.T),
10048
10086
  sig.make_sig('l1', dtype=sig.sig_dtype.T),
10049
10087
  sig.make_sig('l2', dtype=sig.sig_dtype.T),
@@ -10104,7 +10142,7 @@ class NuclearNorm(Primitive):
10104
10142
  x_rank is the dimension of Tensor `x`.
10105
10143
 
10106
10144
  Supported Platforms:
10107
- ``CPU``
10145
+ ``Ascend`` ``CPU``
10108
10146
 
10109
10147
  Examples:
10110
10148
  >>> input_x = Tensor(np.array([[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]],
@@ -10139,7 +10177,7 @@ class NuclearNorm(Primitive):
10139
10177
  """Initialize NuclearNorm."""
10140
10178
  validator.check_value_type("dim", dim, [list, tuple, type(None)], self.name)
10141
10179
  if dim is not None:
10142
- validator.check_int(len(dim), 2, Rel.EQ, 'length of dim_size', self.name)
10180
+ validator.check_int(len(dim), 2, validator.EQ, 'length of dim_size', self.name)
10143
10181
  validator.check_is_int(dim[0], "dim[0]", self.name)
10144
10182
  validator.check_is_int(dim[1], "dim[1]", self.name)
10145
10183
  else:
@@ -10148,44 +10186,27 @@ class NuclearNorm(Primitive):
10148
10186
 
10149
10187
 
10150
10188
  class GLU(Primitive):
10151
- r"""The gated linear unit.
10152
-
10153
- .. math ::
10154
- \begin{array}{ll} \\
10155
- \text{GLU}(a, b) = a \otimes \sigma(b)
10156
- \end{array}
10157
- where `input` is split in half along `dim` to form `a` and `b`,
10158
- σ is the sigmoid function and ⊗ is the element-wise product between matrices.
10159
-
10160
- Args:
10161
- axis (int): Dimension on which to split the input.
10162
- The value of `axis` must be in the range [-rank(`x`), rank(`x`)). Default: -1.
10163
-
10164
- Inputs:
10165
- - **x** (Tensor) - Input tensor. `x.shape[axis]` must be even.
10189
+ r"""
10190
+ Computes GLU (Gated Linear Unit activation function) of input tensors.
10166
10191
 
10167
- Outputs:
10168
- - **y** (Tensor) - The output of Glu, has the same data type with `x`.
10169
- With the same shape as `x`, except for the dimension of `axis`, y.shape[axis] = x.shape[axis] / 2.
10192
+ .. warning::
10193
+ This is an experimental API that is subject to change or deletion.
10170
10194
 
10171
- Raises:
10172
- TypeError: If data type of `x` is not one of the following: float16, float32, float64.
10173
- TypeError: If data type of `axis` is not int.
10174
- ValueError: If `axis` is not in the range [-rank(`x`), rank(`x`)).
10175
- ValueError: If the dimension of the `x` is not equal or greater than 1.
10176
- ValueError: If `x.shape[axis]` is not even.
10195
+ Refer to :func:`mindspore.ops.glu` for more details.
10177
10196
 
10178
10197
  Supported Platforms:
10179
10198
  ``Ascend`` ``CPU``
10180
10199
 
10181
10200
  Examples:
10182
- >>> from mindspore.ops.operations import nn_ops
10201
+ >>> from mindspore import ops, Tensor
10202
+ >>> from mindspore import dtype as mstype
10203
+ >>> import numpy as np
10183
10204
  >>> axis = 0
10184
10205
  >>> x = Tensor(np.array([0.3220, 0.9545, 0.7879, 0.0975, 0.3698,
10185
10206
  ... 0.5135, 0.5740, 0.3435, 0.1895, 0.8764,
10186
10207
  ... 0.4980, 0.9673, 0.9879, 0.6988, 0.9022,
10187
10208
  ... 0.9304, 0.1558, 0.0153, 0.1559, 0.9852]).reshape([2, 2, 5]), mstype.float32)
10188
- >>> glu = nn_ops.GLU(axis=axis)
10209
+ >>> glu = ops.GLU(axis=axis)
10189
10210
  >>> y = glu(x)
10190
10211
  >>> print(y)
10191
10212
  [[[0.20028052 0.6916126 0.57412136 0.06512236 0.26307625]
@@ -10201,19 +10222,18 @@ class GLU(Primitive):
10201
10222
  class FractionalMaxPoolWithFixedKsize(Primitive):
10202
10223
  r"""
10203
10224
  Applies a 2D fractional max pooling to an input signal composed of multiple input planes.
10204
- The max-pooling operation is applied in kH x kW regions by a stochastic step size determined by
10205
- the target output size. For any input size, the size of the specified output is H x W. The number
10206
- of output features is equal to the number of input planes.
10225
+ The max-pooling operation is applied in :math:`(kH, kW)` regions by a stochastic step size determined by
10226
+ the target output size `output_shape`.
10227
+
10228
+ The number of output features is equal to the number of input planes.
10207
10229
 
10208
10230
  Fractional MaxPooling is described in the paper `Fractional Max-Pooling <https://arxiv.org/pdf/1412.6071>`_.
10209
10231
 
10210
10232
  Args:
10211
- ksize (Union[int, tuple[int]]): The size of kernel window used to take the maximum value.
10212
- The target ksize is H x W. ksize can be a tuple, or a single K for K x K.
10213
- specifying the window size (H, W) of the input tensor.
10214
- output_shape (Union[int, tuple[int]]): The target output size is H x W.
10215
- output_shape can be a tuple, or a single H for H x H.
10216
- specifying the size (H, W) of the output tensor.
10233
+ ksize (Union[int, tuple[int]]): Size of the pooling window. `ksize` can be a tuple of two values
10234
+ specify a shape :math:`(k_H, k_W)`, or a single int `K` for :math:`(K, K)`.
10235
+ output_shape (Union[int, tuple[int]]): The target output shape. `output_shape` can be a
10236
+ tuple of two values specify a shape :math:`(H_{out}, W_{out})`, or a single float `S` for :math:`(S, S)`.
10217
10237
  data_format (str, optional): The optional value for data format, is 'NCHW'.
10218
10238
  Default: "NCHW".
10219
10239
 
@@ -10225,7 +10245,7 @@ class FractionalMaxPoolWithFixedKsize(Primitive):
10225
10245
 
10226
10246
  Outputs:
10227
10247
  - **y** (Tensor) - Has the same type as the `input_x`.
10228
- Has the shape :math:`(N, C, output\underline{~}shape{H}, output\underline{~}shape{W})`.
10248
+ Has the shape :math:`(N, C, H_{out}, W_{out})`.
10229
10249
  - **argmax** (Tensor) -A tensor whose data type must be int64. Has the same shape as the `y`.
10230
10250
 
10231
10251
  Raises:
@@ -10277,3 +10297,129 @@ class FractionalMaxPoolWithFixedKsize(Primitive):
10277
10297
  self.add_prim_attr("output_shape", self.output_shape)
10278
10298
  self.data_format = validator.check_string(data_format, ['NCHW'], 'data_format', self.name)
10279
10299
  self.init_prim_io_names(inputs=['input_x', 'random_samples'], outputs=['y', 'argmax'])
10300
+
10301
+
10302
+ class ChannelShuffle(Primitive):
10303
+ r"""
10304
+ Divide the channels in a tensor of shape (*, C, H, W) into g groups and
10305
+ rearrange them as (*, C/g, g, H*W), while keeping the original tensor shapes.
10306
+
10307
+ .. warning::
10308
+ This is an experimental API that is subject to change or deletion.
10309
+
10310
+ Refer to :func:`mindspore.ops.channel_shuffle` for more detail.
10311
+
10312
+ Supported Platforms:
10313
+ ``Ascend`` ``CPU``
10314
+
10315
+ Examples:
10316
+ >>> group = 2
10317
+ >>> x = Tensor(np.arange(1 * 4 * 2 * 2).reshape(1, 4, 2, 2).astype(np.int16))
10318
+ >>> channel_shuffle_func = ops.ChannelShuffle(group)
10319
+ >>> y = channel_shuffle_func(x)
10320
+ >>> print(y)
10321
+ [[[[ 0 1]
10322
+ [ 2 3]]
10323
+ [[ 8 9]
10324
+ [10 11]]
10325
+ [[ 4 5]
10326
+ [ 6 7]]
10327
+ [[12 13]
10328
+ [14 15]]]]
10329
+ """
10330
+
10331
+ @prim_attr_register
10332
+ def __init__(self, group):
10333
+ """Initialize ChannelShuffle"""
10334
+ if not isinstance(group, int):
10335
+ raise ValueError(f"For '{self.name}', attr 'group' must be an positive int number")
10336
+ self.init_prim_io_names(inputs=['x'], outputs=['y'])
10337
+
10338
+
10339
+ class MaxPoolWithArgmaxV2(Primitive):
10340
+ r"""
10341
+ Performs max pooling on the input Tensor and returns both max values and indices.
10342
+
10343
+ Typically the input is of shape :math:`(N_{in}, C_{in}, H_{in}, W_{in})`, MaxPool outputs
10344
+ regional maximum in the :math:`(H_{in}, W_{in})`-dimension. Given kernel size
10345
+ :math:`ks = (h_{ker}, w_{ker})` and stride :math:`s = (s_0, s_1)`, the operation is as follows:
10346
+
10347
+ .. math::
10348
+ \text{output}(N_i, C_j, h, w) = \max_{m=0, \ldots, h_{ker}-1} \max_{n=0, \ldots, w_{ker}-1}
10349
+ \text{input}(N_i, C_j, s_0 \times h + m, s_1 \times w + n)
10350
+
10351
+ Args:
10352
+ kernel_size (Union[int, tuple[int]]): The size of kernel used to take the maximum value and argmax
10353
+ value, is an int number that represents height and width of the kernel, or a tuple of
10354
+ two int numbers that represent height and width respectively.
10355
+ strides (Union[int, tuple[int]]): The distance of kernel moving, an int number that represents
10356
+ not only the height of movement but also the width of movement, or a tuple of two int numbers that
10357
+ represent height and width of movement respectively. Default: None, meaning that `strides = kernel_size`.
10358
+ pads (Union[int, tuple[int]]): An int number that represents the depth, height and width of movement are both
10359
+ strides, or a tuple of three int numbers that represent depth, height and width of movement respectively.
10360
+ dilation (Union[int, tuple[int]]): Default: '(1, 1)'.
10361
+ ceil_mode (bool): Whether to use ceil instead of floor to calculate output shape. Default: False.
10362
+ argmax_type (mindspore.dtype) : The dtype for argmax. Default: mstype.int64.
10363
+
10364
+ Inputs:
10365
+ - **x** (Tensor) - Tensor of shape :math:`(N_{in}, C_{in}, H_{in}, W_{in})` with data type of int8,
10366
+ int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32 or float64.
10367
+
10368
+ Outputs:
10369
+ Tuple of 2 Tensors, representing the maxpool result and where the max values are generated.
10370
+
10371
+ - **output** (Tensor) - Maxpooling result, with shape :math:`(N_{out}, C_{out}, H_{out}, W_{out})`.
10372
+ It has the same data type as `x`.
10373
+ - **argmax** (Tensor) - Index corresponding to the maximum value. Data type is int32 or int64.
10374
+
10375
+ Raises:
10376
+ TypeError: If `x` is not a Tensor.
10377
+ ValueError: If length of shape of `x` is not equal to 4.
10378
+ TypeError: If `kernel_size` , `strides` , `pads` or `dilation` is not int or tuple.
10379
+ ValueError: If `kernel_size`, `strides` or `dilation` is less than 1.
10380
+ ValueError: If `pads` is less than 0.
10381
+ ValueError: If `argmax_type` is not mindspore.int64 or mindspore.int32.
10382
+ TypeError: If `ceil_mode` is not bool.
10383
+
10384
+ Supported Platforms:
10385
+ ``Ascend`` ``GPU`` ``CPU``
10386
+
10387
+ Examples:
10388
+ >>> x = Tensor(np.arange(20 * 16 * 50 * 32).reshape((20, 16, 50, 32)), mindspore.float32)
10389
+ >>> maxpool_arg_v2_op = ops.MaxPoolWithArgmaxV2(kernel_size=(3, 2), strides=(2, 1))
10390
+ >>> output_tensor, argmax = maxpool_arg_v2_op(x)
10391
+ >>> print(output_tensor.shape)
10392
+ (20, 16, 24, 31)
10393
+ >>> pirnt(argmax.shape)
10394
+ (20, 16, 24, 31)
10395
+ """
10396
+
10397
+ @prim_attr_register
10398
+ def __init__(self, kernel_size, strides=None, pads=0, dilation=(1, 1,), ceil_mode=False, argmax_type=mstype.int64):
10399
+ """Initialize MaxPoolWithArgmaxV2."""
10400
+ self.init_prim_io_names(inputs=["x"], outputs=["output", "argmax"])
10401
+ validator.check_value_type("ceil_mode", ceil_mode, bool, self.name)
10402
+ self.ceil_mode = ceil_mode
10403
+ validator.check_value_type("argmax_type", argmax_type, [mstype.Type], self.name)
10404
+ argmax_type_valid_values = (mstype.int32, mstype.int64)
10405
+ validator.check_type_name("argmax_type", argmax_type, argmax_type_valid_values, self.name)
10406
+ if argmax_type == mstype.int32:
10407
+ self.add_prim_attr("argmax_type", 3)
10408
+ elif argmax_type == mstype.int64:
10409
+ self.add_prim_attr("argmax_type", 4)
10410
+ else:
10411
+ raise ValueError(
10412
+ f"For '{self.name}', the 'argmax_type' must be mstype.int32 or mstype.int64, but got {argmax_type}.")
10413
+ self.kernel_size = _check_positive_int_or_tuple("kernel_size", kernel_size, self.name, ret_four=True,
10414
+ allow_four=True)
10415
+ if strides is None:
10416
+ strides = kernel_size
10417
+ self.strides = _check_positive_int_or_tuple("strides", strides, self.name, ret_four=True, allow_four=True)
10418
+ self.pads = _check_positive_int_or_tuple("pads", pads, self.name, ret_four=True, allow_four=True,
10419
+ strict_positive=False)
10420
+ self.dilation = _check_positive_int_or_tuple("dilation", dilation, self.name, ret_four=True, allow_four=True)
10421
+ self.add_prim_attr("kernel_size", self.kernel_size)
10422
+ self.add_prim_attr("strides", self.strides)
10423
+ self.add_prim_attr("pads", self.pads)
10424
+ self.add_prim_attr("dilation", self.dilation)
10425
+ self.add_prim_attr("ceil_mode", self.ceil_mode)