mindspore 1.10.0__cp37-cp37m-win_amd64.whl → 2.0.0rc1__cp37-cp37m-win_amd64.whl

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

Potentially problematic release.


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

Files changed (966) hide show
  1. mindspore/.commit_id +1 -1
  2. mindspore/ConcurrencyCheck.dll +0 -0
  3. mindspore/CppBuildInsights.dll +0 -0
  4. mindspore/CppCoreCheck.dll +0 -0
  5. mindspore/EnumIndex.dll +0 -0
  6. mindspore/EspXEngine.dll +0 -0
  7. mindspore/HResultCheck.dll +0 -0
  8. mindspore/KernelTraceControl.dll +0 -0
  9. mindspore/LocalESPC.dll +0 -0
  10. mindspore/Microsoft.Diagnostics.Tracing.EventSource.dll +0 -0
  11. mindspore/Microsoft.VisualStudio.RemoteControl.dll +0 -0
  12. mindspore/Microsoft.VisualStudio.Telemetry.dll +0 -0
  13. mindspore/Microsoft.VisualStudio.Utilities.Internal.dll +0 -0
  14. mindspore/Newtonsoft.Json.dll +0 -0
  15. mindspore/System.Runtime.CompilerServices.Unsafe.dll +0 -0
  16. mindspore/VariantClear.dll +0 -0
  17. mindspore/__init__.py +9 -4
  18. mindspore/_c_dataengine.cp37-win_amd64.pyd +0 -0
  19. mindspore/_c_expression.cp37-win_amd64.pyd +0 -0
  20. mindspore/_c_mindrecord.cp37-win_amd64.pyd +0 -0
  21. mindspore/_check_jit_forbidden_api.py +102 -0
  22. mindspore/_checkparam.py +1066 -1001
  23. mindspore/_extends/builtin_operations.py +32 -4
  24. mindspore/_extends/graph_kernel/model/graph_split.py +66 -222
  25. mindspore/_extends/parallel_compile/akg_compiler/akg_process.py +12 -9
  26. mindspore/_extends/parallel_compile/akg_compiler/build_tbe_kernel.py +119 -26
  27. mindspore/_extends/parallel_compile/akg_compiler/tbe_topi.py +50 -50
  28. mindspore/_extends/parallel_compile/akg_compiler/util.py +9 -6
  29. mindspore/_extends/parallel_compile/tbe_compiler/tbe_adapter.py +4 -25
  30. mindspore/_extends/parallel_compile/tbe_compiler/tbe_helper.py +9 -4
  31. mindspore/_extends/parallel_compile/tbe_compiler/tbe_job_manager.py +1 -27
  32. mindspore/_extends/parse/__init__.py +5 -3
  33. mindspore/_extends/parse/namespace.py +17 -2
  34. mindspore/_extends/parse/parser.py +193 -34
  35. mindspore/_extends/parse/resources.py +7 -8
  36. mindspore/_extends/parse/standard_method.py +1780 -435
  37. mindspore/_extends/parse/trope.py +3 -1
  38. mindspore/amp.py +53 -58
  39. mindspore/atlprov.dll +0 -0
  40. mindspore/boost/adasum.py +3 -2
  41. mindspore/boost/boost.py +2 -2
  42. mindspore/boost/boost_cell_wrapper.py +46 -26
  43. mindspore/boost/dim_reduce.py +6 -5
  44. mindspore/boost/grad_accumulation.py +2 -1
  45. mindspore/boost/group_loss_scale_manager.py +1 -1
  46. mindspore/c1.dll +0 -0
  47. mindspore/c1xx.dll +0 -0
  48. mindspore/c2.dll +0 -0
  49. mindspore/cfgpersist.dll +0 -0
  50. mindspore/clang_rt.asan_dbg_dynamic-x86_64.dll +0 -0
  51. mindspore/clang_rt.asan_dynamic-x86_64.dll +0 -0
  52. mindspore/common/__init__.py +11 -10
  53. mindspore/common/_decorator.py +2 -0
  54. mindspore/common/_register_for_adapter.py +55 -0
  55. mindspore/common/_stub_tensor.py +201 -0
  56. mindspore/common/_utils.py +57 -0
  57. mindspore/common/api.py +582 -297
  58. mindspore/common/dtype.py +66 -18
  59. mindspore/common/dump.py +2 -2
  60. mindspore/common/initializer.py +38 -1
  61. mindspore/common/jit_config.py +25 -13
  62. mindspore/common/mutable.py +53 -24
  63. mindspore/common/parameter.py +60 -37
  64. mindspore/common/seed.py +8 -24
  65. mindspore/common/sparse_tensor.py +927 -0
  66. mindspore/common/tensor.py +1627 -3900
  67. mindspore/communication/__init__.py +10 -5
  68. mindspore/communication/_comm_helper.py +78 -214
  69. mindspore/communication/_hccl_management.py +2 -1
  70. mindspore/communication/management.py +136 -47
  71. mindspore/config/op_info.config +501 -1008
  72. mindspore/context.py +291 -56
  73. mindspore/d3dcompiler_47.dll +0 -0
  74. mindspore/dataset/__init__.py +12 -8
  75. mindspore/dataset/audio/__init__.py +9 -9
  76. mindspore/dataset/audio/transforms.py +1090 -228
  77. mindspore/dataset/audio/utils.py +87 -39
  78. mindspore/dataset/audio/validators.py +223 -1
  79. mindspore/dataset/callback/ds_callback.py +17 -15
  80. mindspore/dataset/core/config.py +246 -17
  81. mindspore/dataset/core/py_util_helpers.py +4 -3
  82. mindspore/dataset/core/validator_helpers.py +10 -10
  83. mindspore/{parallel/nn/layers.py → dataset/debug/__init__.py} +7 -8
  84. mindspore/dataset/debug/debug_hook.py +65 -0
  85. mindspore/dataset/debug/pre_defined_hook.py +67 -0
  86. mindspore/dataset/engine/__init__.py +7 -3
  87. mindspore/dataset/engine/cache_client.py +9 -9
  88. mindspore/dataset/engine/datasets.py +648 -477
  89. mindspore/dataset/engine/datasets_audio.py +165 -167
  90. mindspore/dataset/engine/datasets_standard_format.py +93 -67
  91. mindspore/dataset/engine/datasets_text.py +492 -342
  92. mindspore/dataset/engine/datasets_user_defined.py +85 -50
  93. mindspore/dataset/engine/datasets_vision.py +1224 -699
  94. mindspore/dataset/engine/graphdata.py +134 -69
  95. mindspore/dataset/engine/iterators.py +50 -9
  96. mindspore/dataset/engine/offload.py +52 -31
  97. mindspore/dataset/engine/samplers.py +27 -24
  98. mindspore/dataset/engine/serializer_deserializer.py +14 -15
  99. mindspore/dataset/engine/validators.py +213 -52
  100. mindspore/dataset/text/__init__.py +10 -8
  101. mindspore/dataset/text/transforms.py +152 -57
  102. mindspore/dataset/text/utils.py +98 -49
  103. mindspore/dataset/text/validators.py +25 -0
  104. mindspore/dataset/transforms/__init__.py +4 -2
  105. mindspore/dataset/transforms/c_transforms.py +11 -13
  106. mindspore/dataset/transforms/py_transforms.py +2 -2
  107. mindspore/dataset/transforms/py_transforms_util.py +10 -0
  108. mindspore/dataset/transforms/transforms.py +13 -15
  109. mindspore/dataset/transforms/validators.py +7 -7
  110. mindspore/dataset/utils/__init__.py +2 -1
  111. mindspore/dataset/utils/browse_dataset.py +13 -13
  112. mindspore/dataset/utils/line_reader.py +121 -0
  113. mindspore/dataset/vision/__init__.py +8 -7
  114. mindspore/dataset/vision/c_transforms.py +125 -126
  115. mindspore/dataset/vision/py_transforms.py +37 -37
  116. mindspore/dataset/vision/py_transforms_util.py +23 -20
  117. mindspore/dataset/vision/transforms.py +316 -315
  118. mindspore/dataset/vision/utils.py +313 -17
  119. mindspore/dataset/vision/validators.py +6 -6
  120. mindspore/default_config.py +0 -1
  121. mindspore/dpcmi.dll +0 -0
  122. mindspore/{compression → experimental}/__init__.py +6 -5
  123. mindspore/experimental/map_parameter.py +275 -0
  124. mindspore/include/OWNERS +0 -1
  125. mindspore/include/api/callback/callback.h +9 -13
  126. mindspore/include/api/callback/ckpt_saver.h +2 -2
  127. mindspore/include/api/callback/loss_monitor.h +2 -2
  128. mindspore/include/api/callback/lr_scheduler.h +5 -5
  129. mindspore/include/api/callback/time_monitor.h +2 -2
  130. mindspore/include/api/callback/train_accuracy.h +4 -6
  131. mindspore/include/api/cfg.h +19 -6
  132. mindspore/include/api/context.h +70 -9
  133. mindspore/include/api/delegate.h +8 -1
  134. mindspore/include/api/dual_abi_helper.h +8 -24
  135. mindspore/include/api/metrics/accuracy.h +2 -2
  136. mindspore/include/api/metrics/metrics.h +4 -3
  137. mindspore/include/api/model.h +9 -4
  138. mindspore/include/api/model_group.h +68 -0
  139. mindspore/include/api/model_parallel_runner.h +17 -17
  140. mindspore/include/api/net.h +12 -11
  141. mindspore/include/api/serialization.h +20 -4
  142. mindspore/include/api/status.h +7 -1
  143. mindspore/include/api/types.h +25 -21
  144. mindspore/include/api/visible.h +4 -0
  145. mindspore/include/c_api/model_c.h +5 -0
  146. mindspore/include/c_api/status_c.h +1 -1
  147. mindspore/include/dataset/config.h +1 -1
  148. mindspore/include/dataset/constants.h +14 -0
  149. mindspore/include/dataset/text.h +59 -0
  150. mindspore/include/dataset/vision.h +56 -117
  151. mindspore/include/dataset/vision_lite.h +102 -0
  152. mindspore/jpeg62.dll +0 -0
  153. mindspore/log.py +28 -28
  154. mindspore/mindrecord/common/exceptions.py +2 -4
  155. mindspore/mindrecord/filereader.py +19 -1
  156. mindspore/mindrecord/filewriter.py +250 -88
  157. mindspore/mindrecord/mindpage.py +13 -13
  158. mindspore/mindrecord/shardheader.py +15 -15
  159. mindspore/mindrecord/shardreader.py +9 -0
  160. mindspore/mindrecord/shardwriter.py +29 -29
  161. mindspore/mindrecord/tools/cifar100_to_mr.py +9 -9
  162. mindspore/mindrecord/tools/cifar10_to_mr.py +9 -9
  163. mindspore/mindrecord/tools/csv_to_mr.py +4 -4
  164. mindspore/mindrecord/tools/imagenet_to_mr.py +70 -65
  165. mindspore/mindrecord/tools/mnist_to_mr.py +41 -41
  166. mindspore/mindrecord/tools/tfrecord_to_mr.py +6 -6
  167. mindspore/{libmindspore_backend.dll → mindspore_backend.dll} +0 -0
  168. mindspore/mindspore_common.dll +0 -0
  169. mindspore/mindspore_core.dll +0 -0
  170. mindspore/mindspore_glog.dll +0 -0
  171. mindspore/mindspore_shared_lib.dll +0 -0
  172. mindspore/msobj140.dll +0 -0
  173. mindspore/mspdb140.dll +0 -0
  174. mindspore/mspdbcore.dll +0 -0
  175. mindspore/mspdbst.dll +0 -0
  176. mindspore/mspft140.dll +0 -0
  177. mindspore/msvcdis140.dll +0 -0
  178. mindspore/msvcp140_1.dll +0 -0
  179. mindspore/msvcp140_2.dll +0 -0
  180. mindspore/msvcp140_atomic_wait.dll +0 -0
  181. mindspore/msvcp140_codecvt_ids.dll +0 -0
  182. mindspore/nn/__init__.py +1 -5
  183. mindspore/nn/cell.py +297 -234
  184. mindspore/nn/dynamic_lr.py +1 -1
  185. mindspore/nn/grad/cell_grad.py +17 -42
  186. mindspore/nn/layer/__init__.py +7 -4
  187. mindspore/nn/layer/activation.py +131 -88
  188. mindspore/nn/layer/basic.py +313 -613
  189. mindspore/nn/layer/channel_shuffle.py +103 -0
  190. mindspore/nn/layer/combined.py +1 -1
  191. mindspore/nn/layer/container.py +52 -6
  192. mindspore/nn/layer/conv.py +112 -43
  193. mindspore/nn/layer/dense.py +10 -9
  194. mindspore/nn/layer/embedding.py +36 -34
  195. mindspore/nn/layer/image.py +123 -27
  196. mindspore/nn/layer/math.py +108 -107
  197. mindspore/nn/layer/normalization.py +212 -366
  198. mindspore/nn/layer/padding.py +370 -42
  199. mindspore/nn/layer/pooling.py +1443 -219
  200. mindspore/nn/layer/rnn_cells.py +11 -16
  201. mindspore/nn/layer/rnns.py +38 -39
  202. mindspore/nn/layer/thor_layer.py +24 -25
  203. mindspore/nn/layer/timedistributed.py +5 -5
  204. mindspore/nn/layer/transformer.py +701 -0
  205. mindspore/nn/learning_rate_schedule.py +8 -8
  206. mindspore/nn/loss/__init__.py +9 -6
  207. mindspore/nn/loss/loss.py +678 -142
  208. mindspore/nn/metrics.py +53 -0
  209. mindspore/nn/optim/_dist_optimizer_registry.py +2 -2
  210. mindspore/nn/optim/ada_grad.py +8 -8
  211. mindspore/nn/optim/adadelta.py +2 -3
  212. mindspore/nn/optim/adafactor.py +18 -14
  213. mindspore/nn/optim/adam.py +429 -87
  214. mindspore/nn/optim/adamax.py +5 -6
  215. mindspore/nn/optim/adasum.py +10 -8
  216. mindspore/nn/optim/asgd.py +7 -7
  217. mindspore/nn/optim/ftrl.py +81 -11
  218. mindspore/nn/optim/lamb.py +7 -8
  219. mindspore/nn/optim/lars.py +4 -4
  220. mindspore/nn/optim/lazyadam.py +82 -7
  221. mindspore/nn/optim/momentum.py +8 -7
  222. mindspore/nn/optim/optimizer.py +19 -10
  223. mindspore/nn/optim/proximal_ada_grad.py +6 -5
  224. mindspore/nn/optim/rmsprop.py +3 -3
  225. mindspore/nn/optim/rprop.py +20 -16
  226. mindspore/nn/optim/sgd.py +21 -15
  227. mindspore/nn/optim/thor.py +23 -21
  228. mindspore/nn/probability/__init__.py +0 -2
  229. mindspore/nn/probability/bijector/bijector.py +7 -6
  230. mindspore/nn/probability/bijector/invert.py +4 -2
  231. mindspore/nn/probability/bijector/softplus.py +2 -2
  232. mindspore/nn/probability/bnn_layers/dense_variational.py +1 -1
  233. mindspore/nn/probability/bnn_layers/layer_distribution.py +2 -2
  234. mindspore/nn/probability/distribution/__init__.py +6 -0
  235. mindspore/nn/probability/distribution/_utils/custom_ops.py +3 -2
  236. mindspore/nn/probability/distribution/_utils/utils.py +11 -17
  237. mindspore/nn/probability/distribution/bernoulli.py +6 -6
  238. mindspore/nn/probability/distribution/beta.py +1 -1
  239. mindspore/nn/probability/distribution/categorical.py +9 -9
  240. mindspore/nn/probability/distribution/cauchy.py +8 -8
  241. mindspore/nn/probability/distribution/distribution.py +12 -6
  242. mindspore/nn/probability/distribution/exponential.py +5 -5
  243. mindspore/nn/probability/distribution/gamma.py +3 -3
  244. mindspore/nn/probability/distribution/geometric.py +6 -5
  245. mindspore/nn/probability/distribution/gumbel.py +5 -5
  246. mindspore/nn/probability/distribution/half_normal.py +133 -0
  247. mindspore/nn/probability/distribution/laplace.py +128 -0
  248. mindspore/nn/probability/distribution/log_normal.py +0 -1
  249. mindspore/nn/probability/distribution/logistic.py +4 -5
  250. mindspore/nn/probability/distribution/normal.py +11 -15
  251. mindspore/nn/probability/distribution/poisson.py +6 -2
  252. mindspore/nn/probability/distribution/student_t.py +150 -0
  253. mindspore/nn/probability/distribution/transformed_distribution.py +4 -4
  254. mindspore/nn/probability/distribution/uniform.py +5 -5
  255. mindspore/nn/reinforcement/_tensors_queue.py +3 -3
  256. mindspore/nn/reinforcement/tensor_array.py +2 -2
  257. mindspore/nn/sparse/sparse.py +8 -1
  258. mindspore/nn/wrap/cell_wrapper.py +55 -27
  259. mindspore/nn/wrap/grad_reducer.py +20 -11
  260. mindspore/nn/wrap/loss_scale.py +47 -30
  261. mindspore/numpy/array_creations.py +33 -22
  262. mindspore/numpy/array_ops.py +46 -42
  263. mindspore/numpy/logic_ops.py +6 -27
  264. mindspore/numpy/math_ops.py +26 -19
  265. mindspore/numpy/utils.py +1 -8
  266. mindspore/numpy/utils_const.py +112 -62
  267. mindspore/opencv_core452.dll +0 -0
  268. mindspore/opencv_imgcodecs452.dll +0 -0
  269. mindspore/opencv_imgproc452.dll +0 -0
  270. mindspore/ops/__init__.py +6 -3
  271. mindspore/ops/_constants.py +0 -6
  272. mindspore/ops/_grad/__init__.py +2 -1
  273. mindspore/ops/_grad/grad_array_ops.py +209 -152
  274. mindspore/ops/_grad/grad_base.py +55 -17
  275. mindspore/ops/_grad/grad_clip_ops.py +11 -3
  276. mindspore/ops/_grad/grad_comm_ops.py +58 -47
  277. mindspore/ops/_grad/grad_implementations.py +21 -61
  278. mindspore/ops/_grad/grad_inner_ops.py +48 -6
  279. mindspore/ops/_grad/grad_math_ops.py +306 -161
  280. mindspore/ops/_grad/grad_nn_ops.py +192 -181
  281. mindspore/ops/_grad/grad_other_ops.py +1 -1
  282. mindspore/ops/_grad/grad_quant_ops.py +5 -5
  283. mindspore/ops/_grad/grad_sequence_ops.py +296 -0
  284. mindspore/ops/_grad/grad_sparse.py +15 -9
  285. mindspore/ops/_grad_experimental/__init__.py +1 -0
  286. mindspore/ops/_grad_experimental/grad_array_ops.py +441 -55
  287. mindspore/ops/_grad_experimental/grad_image_ops.py +25 -7
  288. mindspore/ops/_grad_experimental/grad_inner_ops.py +3 -44
  289. mindspore/ops/_grad_experimental/grad_linalg_ops.py +16 -21
  290. mindspore/ops/_grad_experimental/grad_math_ops.py +979 -49
  291. mindspore/ops/_grad_experimental/grad_nn_ops.py +78 -8
  292. mindspore/ops/_grad_experimental/grad_scalar_ops.py +112 -0
  293. mindspore/ops/_grad_experimental/grad_sparse_ops.py +197 -13
  294. mindspore/ops/_op_impl/__init__.py +3 -3
  295. mindspore/ops/_op_impl/_custom_op/__init__.py +0 -1
  296. mindspore/ops/_op_impl/_custom_op/_basic.py +0 -1
  297. mindspore/ops/_op_impl/_custom_op/batch_matmul_impl.py +1 -1
  298. mindspore/ops/_op_impl/_custom_op/batchnorm_fold.py +4 -2
  299. mindspore/ops/_op_impl/_custom_op/batchnorm_fold2.py +2 -2
  300. mindspore/ops/_op_impl/_custom_op/batchnorm_fold2_grad.py +2 -2
  301. mindspore/ops/_op_impl/_custom_op/batchnorm_fold2_grad_reduce.py +5 -5
  302. mindspore/ops/_op_impl/_custom_op/batchnorm_fold_grad.py +3 -3
  303. mindspore/ops/_op_impl/_custom_op/cholesky_trsm_impl.py +1 -1
  304. mindspore/ops/_op_impl/_custom_op/correction_mul.py +3 -3
  305. mindspore/ops/_op_impl/_custom_op/correction_mul_grad.py +2 -2
  306. mindspore/ops/_op_impl/_custom_op/dsd_back_impl.py +4 -8
  307. mindspore/ops/_op_impl/_custom_op/dsd_impl.py +1 -1
  308. mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perchannel.py +2 -2
  309. mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perchannel_grad.py +2 -2
  310. mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perchannel_grad_reduce.py +2 -2
  311. mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perlayer.py +2 -2
  312. mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perlayer_grad.py +2 -2
  313. mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perlayer_grad_reduce.py +2 -2
  314. mindspore/ops/_op_impl/_custom_op/fake_quant_perchannel.py +2 -2
  315. mindspore/ops/_op_impl/_custom_op/fake_quant_perchannel_grad.py +2 -2
  316. mindspore/ops/_op_impl/_custom_op/fake_quant_perlayer.py +2 -2
  317. mindspore/ops/_op_impl/_custom_op/fake_quant_perlayer_grad.py +2 -2
  318. mindspore/ops/_op_impl/_custom_op/fused_abs_max1_impl.py +1 -1
  319. mindspore/ops/_op_impl/_custom_op/img2col_impl.py +1 -1
  320. mindspore/ops/_op_impl/_custom_op/matmul_cube_dense_left_impl.py +2 -2
  321. mindspore/ops/_op_impl/_custom_op/matmul_cube_dense_right_impl.py +1 -1
  322. mindspore/ops/_op_impl/_custom_op/matmul_cube_fracz_left_cast_impl.py +1 -1
  323. mindspore/ops/_op_impl/_custom_op/matmul_cube_fracz_right_mul_impl.py +1 -1
  324. mindspore/ops/_op_impl/_custom_op/matmul_cube_impl.py +2 -2
  325. mindspore/ops/_op_impl/_custom_op/matmul_dds_grad_impl.py +0 -1
  326. mindspore/ops/_op_impl/_custom_op/matmul_dds_impl.py +0 -1
  327. mindspore/ops/_op_impl/_custom_op/matrix_combine_impl.py +1 -1
  328. mindspore/ops/_op_impl/_custom_op/minmax_update_perchannel.py +2 -2
  329. mindspore/ops/_op_impl/_custom_op/minmax_update_perlayer.py +2 -2
  330. mindspore/ops/_op_impl/_custom_op/transpose02314_impl.py +1 -1
  331. mindspore/ops/_op_impl/aicpu/__init__.py +238 -3
  332. mindspore/ops/_op_impl/aicpu/abs.py +36 -0
  333. mindspore/ops/_op_impl/aicpu/adaptive_avg_pool_2d.py +34 -0
  334. mindspore/ops/_op_impl/aicpu/adaptive_avg_pool_2d_grad.py +34 -0
  335. mindspore/ops/_op_impl/aicpu/adaptive_avg_pool_3d.py +39 -0
  336. mindspore/ops/_op_impl/aicpu/adaptive_avg_pool_3d_grad.py +39 -0
  337. mindspore/ops/_op_impl/aicpu/adaptive_max_pool_2d_grad.py +37 -0
  338. mindspore/ops/_op_impl/aicpu/adaptive_max_pool_3d.py +42 -0
  339. mindspore/ops/_op_impl/aicpu/adaptive_max_pool_3d_grad.py +152 -0
  340. mindspore/ops/_op_impl/aicpu/add.py +43 -0
  341. mindspore/ops/_op_impl/aicpu/addcdiv.py +0 -32
  342. mindspore/ops/_op_impl/aicpu/addcmul.py +0 -84
  343. mindspore/ops/_op_impl/aicpu/affine_grid_grad.py +35 -0
  344. mindspore/ops/_op_impl/aicpu/arg_max.py +75 -0
  345. mindspore/ops/_op_impl/aicpu/arg_min.py +75 -0
  346. mindspore/ops/_op_impl/aicpu/argmin_with_value.py +43 -0
  347. mindspore/ops/_op_impl/aicpu/batch_matmul.py +43 -0
  348. mindspore/ops/_op_impl/aicpu/batch_norm_grad_grad.py +49 -0
  349. mindspore/ops/_op_impl/aicpu/bernoulli.py +48 -0
  350. mindspore/ops/_op_impl/aicpu/bessel_i0.py +31 -0
  351. mindspore/ops/_op_impl/aicpu/bias_add.py +44 -0
  352. mindspore/ops/_op_impl/aicpu/bias_add_grad.py +43 -0
  353. mindspore/ops/_op_impl/aicpu/bincount.py +33 -0
  354. mindspore/{nn/probability/infer/variational/__init__.py → ops/_op_impl/aicpu/cauchy.py} +17 -10
  355. mindspore/ops/_op_impl/aicpu/channel_shuffle.py +40 -0
  356. mindspore/ops/_op_impl/aicpu/cholesky.py +1 -1
  357. mindspore/ops/_op_impl/{cpu/bias_add.py → aicpu/choleskygrad.py} +9 -7
  358. mindspore/ops/_op_impl/aicpu/combined_non_max_suppression.py +42 -0
  359. mindspore/ops/_op_impl/aicpu/concat_offset.py +42 -0
  360. mindspore/ops/_op_impl/aicpu/concat_offset_v1.py +31 -0
  361. mindspore/ops/_op_impl/aicpu/conj.py +11 -0
  362. mindspore/ops/_op_impl/aicpu/crop_and_resize_grad_image.py +38 -0
  363. mindspore/ops/_op_impl/aicpu/cumulative_logsumexp.py +36 -0
  364. mindspore/ops/_op_impl/aicpu/deformable_offsets.py +38 -0
  365. mindspore/ops/_op_impl/aicpu/deformable_offsets_grad.py +2 -2
  366. mindspore/ops/_op_impl/aicpu/dense_to_sparse_set_operation.py +48 -0
  367. mindspore/ops/_op_impl/aicpu/diag.py +36 -0
  368. mindspore/ops/_op_impl/aicpu/diag_part.py +36 -0
  369. mindspore/ops/_op_impl/aicpu/diagonal.py +35 -0
  370. mindspore/ops/_op_impl/{cpu/bias_add_grad.py → aicpu/digamma.py} +9 -7
  371. mindspore/ops/_op_impl/aicpu/eig.py +35 -0
  372. mindspore/ops/_op_impl/aicpu/fft_with_size.py +41 -0
  373. mindspore/ops/_op_impl/aicpu/flatten.py +1 -0
  374. mindspore/ops/_op_impl/aicpu/fmax.py +36 -0
  375. mindspore/ops/_op_impl/aicpu/fmin.py +37 -0
  376. mindspore/ops/_op_impl/aicpu/fractional_max_pool3d_with_fixed_ksize.py +1 -1
  377. mindspore/ops/_op_impl/aicpu/fse_decode.py +43 -0
  378. mindspore/ops/_op_impl/aicpu/glu.py +33 -0
  379. mindspore/ops/_op_impl/aicpu/glu_grad.py +34 -0
  380. mindspore/ops/_op_impl/aicpu/greater.py +41 -0
  381. mindspore/ops/_op_impl/aicpu/greater_equal.py +41 -0
  382. mindspore/ops/_op_impl/aicpu/index_put.py +50 -0
  383. mindspore/ops/_op_impl/{tbe/scatter_add_ds.py → aicpu/inplace_index_add.py} +17 -21
  384. mindspore/ops/_op_impl/aicpu/instance_norm_v2.py +41 -0
  385. mindspore/ops/_op_impl/aicpu/instance_norm_v2_grad.py +44 -0
  386. mindspore/ops/_op_impl/aicpu/layer_norm_grad_grad.py +47 -0
  387. mindspore/ops/_op_impl/aicpu/less.py +41 -0
  388. mindspore/ops/_op_impl/aicpu/less_equal.py +41 -0
  389. mindspore/ops/_op_impl/aicpu/lgamma.py +32 -0
  390. mindspore/ops/_op_impl/aicpu/log_normal_reverse.py +33 -0
  391. mindspore/ops/_op_impl/aicpu/logit.py +33 -0
  392. mindspore/ops/_op_impl/aicpu/logit_grad.py +34 -0
  393. mindspore/ops/_op_impl/aicpu/masked_fill.py +42 -0
  394. mindspore/ops/_op_impl/aicpu/masked_scatter.py +39 -0
  395. mindspore/ops/_op_impl/aicpu/matmul.py +39 -0
  396. mindspore/ops/_op_impl/aicpu/matrix_logarithm.py +31 -0
  397. mindspore/ops/_op_impl/aicpu/matrix_power.py +32 -0
  398. mindspore/ops/_op_impl/aicpu/matrix_solve_ls.py +36 -0
  399. mindspore/ops/_op_impl/aicpu/matrix_triangular_solve.py +36 -0
  400. mindspore/ops/_op_impl/aicpu/mirror_pad.py +2 -0
  401. mindspore/ops/_op_impl/aicpu/mirror_pad_grad.py +0 -4
  402. mindspore/ops/_op_impl/aicpu/mul.py +3 -1
  403. mindspore/ops/_op_impl/aicpu/multinomial.py +14 -6
  404. mindspore/ops/_op_impl/aicpu/multinomial_with_replacement.py +35 -0
  405. mindspore/ops/_op_impl/aicpu/nan_to_num.py +34 -0
  406. mindspore/ops/_op_impl/aicpu/nllloss.py +38 -0
  407. mindspore/ops/_op_impl/aicpu/nllloss_grad.py +39 -0
  408. mindspore/ops/_op_impl/aicpu/ones_like.py +0 -2
  409. mindspore/ops/_op_impl/aicpu/polar.py +32 -0
  410. mindspore/ops/_op_impl/aicpu/polygamma.py +34 -0
  411. mindspore/ops/_op_impl/aicpu/qr.py +36 -0
  412. mindspore/ops/_op_impl/aicpu/quant_dtype_cast.py +40 -0
  413. mindspore/ops/_op_impl/aicpu/quantile.py +35 -0
  414. mindspore/ops/_op_impl/aicpu/ragged_tensor_to_sparse.py +73 -0
  415. mindspore/ops/_op_impl/aicpu/ragged_tensor_to_tensor.py +74 -0
  416. mindspore/ops/_op_impl/aicpu/random_shuffle.py +3 -0
  417. mindspore/ops/_op_impl/aicpu/randperm_v2.py +41 -0
  418. mindspore/ops/_op_impl/aicpu/range.py +36 -0
  419. mindspore/ops/_op_impl/aicpu/reciprocal.py +34 -0
  420. mindspore/ops/_op_impl/aicpu/reciprocal_grad.py +35 -0
  421. mindspore/ops/_op_impl/aicpu/reduce_sum.py +57 -0
  422. mindspore/ops/_op_impl/aicpu/resize_bicubic.py +2 -8
  423. mindspore/ops/_op_impl/aicpu/resize_bicubic_grad.py +1 -1
  424. mindspore/ops/_op_impl/aicpu/resize_v2.py +68 -0
  425. mindspore/ops/_op_impl/aicpu/resize_v2_grad.py +68 -0
  426. mindspore/ops/_op_impl/aicpu/scatter_elements.py +4 -0
  427. mindspore/ops/_op_impl/aicpu/scatter_nd_update.py +2 -0
  428. mindspore/ops/_op_impl/aicpu/search_sorted.py +12 -6
  429. mindspore/ops/_op_impl/aicpu/self_adjoint_eig.py +34 -0
  430. mindspore/ops/_op_impl/aicpu/sequence_add.py +34 -0
  431. mindspore/ops/_op_impl/aicpu/sequence_add_offset.py +34 -0
  432. mindspore/ops/_op_impl/aicpu/sequence_addn.py +38 -0
  433. mindspore/ops/_op_impl/aicpu/slice_grad.py +76 -0
  434. mindspore/ops/_op_impl/aicpu/smooth_l1_loss.py +35 -0
  435. mindspore/ops/_op_impl/aicpu/smooth_l1_loss_grad.py +37 -0
  436. mindspore/ops/_op_impl/aicpu/sort.py +39 -0
  437. mindspore/ops/_op_impl/aicpu/sparse_apply_adagrad_da.py +0 -24
  438. mindspore/ops/_op_impl/aicpu/sparse_cross.py +42 -0
  439. mindspore/ops/_op_impl/aicpu/sparse_fill_empty_rows.py +63 -0
  440. mindspore/ops/_op_impl/aicpu/sparse_fill_empty_rows_grad.py +45 -0
  441. mindspore/ops/_op_impl/aicpu/sparse_matrix_mat_mul.py +56 -0
  442. mindspore/ops/_op_impl/{tbe/slice_ds.py → aicpu/sparse_segment_sum.py} +16 -24
  443. mindspore/ops/_op_impl/aicpu/sparse_segment_sum_with_num_segments.py +68 -0
  444. mindspore/ops/_op_impl/aicpu/sparse_slice.py +63 -0
  445. mindspore/ops/_op_impl/aicpu/sparse_slice_grad.py +61 -0
  446. mindspore/ops/_op_impl/aicpu/squared_difference.py +2 -0
  447. mindspore/ops/_op_impl/aicpu/strided_slice_v2.py +93 -0
  448. mindspore/ops/_op_impl/aicpu/strided_slice_v2_grad.py +66 -0
  449. mindspore/ops/_op_impl/aicpu/tensor_scatter_update.py +59 -0
  450. mindspore/ops/_op_impl/{tbe/gather_v2.py → aicpu/tile.py} +24 -24
  451. mindspore/ops/_op_impl/aicpu/tridiagonal_solve.py +35 -0
  452. mindspore/ops/_op_impl/aicpu/tril_indices.py +34 -0
  453. mindspore/ops/_op_impl/aicpu/triu_indices.py +34 -0
  454. mindspore/ops/_op_impl/aicpu/uniform.py +34 -0
  455. mindspore/ops/_op_impl/aicpu/uniform_candidate_sampler.py +1 -0
  456. mindspore/ops/_op_impl/aicpu/unique_consecutive.py +10 -2
  457. mindspore/ops/_op_impl/cpu/__init__.py +1 -2
  458. mindspore/ops/_op_impl/cpu/dynamic_shape.py +5 -1
  459. mindspore/ops/_op_impl/cpu/maximum_grad.py +2 -0
  460. mindspore/{compression/common/__init__.py → ops/_op_impl/cpu/pyexecute.py} +13 -8
  461. mindspore/ops/_op_impl/cpu/reduce_sum.py +8 -0
  462. mindspore/ops/_op_impl/cpu/sparse_slice.py +62 -0
  463. mindspore/ops/_op_impl/cpu/sparse_slice_grad.py +60 -0
  464. mindspore/ops/_op_impl/cpu/tensor_shape.py +5 -1
  465. mindspore/ops/_op_impl/tbe/__init__.py +27 -608
  466. mindspore/ops/_op_impl/tbe/addcdiv_ds.py +42 -0
  467. mindspore/ops/_op_impl/tbe/addcmul_ds.py +44 -0
  468. mindspore/ops/_op_impl/tbe/assign_add_ds.py +1 -0
  469. mindspore/ops/_op_impl/tbe/atomic_addr_clean.py +1 -1
  470. mindspore/ops/_op_impl/tbe/avg_pool_3d_grad.py +1 -1
  471. mindspore/ops/_op_impl/tbe/basic_lstm_cell_c_state_grad_v2.py +0 -1
  472. mindspore/ops/_op_impl/tbe/batch_to_space.py +1 -1
  473. mindspore/ops/_op_impl/tbe/batch_to_space_nd.py +1 -1
  474. mindspore/ops/_op_impl/tbe/batch_to_space_nd_v2.py +41 -0
  475. mindspore/ops/_op_impl/tbe/bce_with_logits_loss.py +1 -0
  476. mindspore/ops/_op_impl/tbe/bias_add_grad.py +2 -0
  477. mindspore/ops/_op_impl/tbe/bn_infer_grad.py +4 -2
  478. mindspore/ops/_op_impl/tbe/bn_infer_grad_ds.py +40 -0
  479. mindspore/ops/_op_impl/tbe/bn_training_update.py +0 -1
  480. mindspore/ops/_op_impl/tbe/bn_training_update_ds.py +0 -1
  481. mindspore/ops/_op_impl/tbe/broadcast_to_ds.py +6 -4
  482. mindspore/ops/_op_impl/tbe/cast.py +0 -2
  483. mindspore/ops/_op_impl/tbe/cast_ds.py +3 -3
  484. mindspore/ops/_op_impl/tbe/ctc_loss_v2.py +0 -2
  485. mindspore/ops/_op_impl/tbe/ctc_loss_v2_grad.py +0 -2
  486. mindspore/ops/_op_impl/tbe/data_format_dim_map_ds.py +1 -0
  487. mindspore/ops/_op_impl/tbe/deformable_offsets.py +1 -0
  488. mindspore/ops/_op_impl/tbe/depthwise_conv2d.py +1 -1
  489. mindspore/ops/_op_impl/tbe/dynamic_atomic_addr_clean.py +1 -1
  490. mindspore/ops/_op_impl/tbe/gather_nd.py +1 -0
  491. mindspore/ops/_op_impl/tbe/greater.py +2 -0
  492. mindspore/ops/_op_impl/tbe/{index_add.py → inplace_index_add.py} +3 -6
  493. mindspore/ops/_op_impl/tbe/layer_norm_beta_gamma_backprop_v2.py +0 -1
  494. mindspore/ops/_op_impl/tbe/npu_clear_float_status_v2.py +35 -0
  495. mindspore/ops/_op_impl/tbe/npu_get_float_status_v2.py +35 -0
  496. mindspore/ops/_op_impl/tbe/one_hot_ds.py +0 -6
  497. mindspore/ops/_op_impl/tbe/{greater_ds.py → reduce_all_ds.py} +13 -16
  498. mindspore/ops/_op_impl/tbe/reduce_any_ds.py +39 -0
  499. mindspore/ops/_op_impl/tbe/roi_align_ds.py +44 -0
  500. mindspore/ops/_op_impl/tbe/roi_align_grad_ds.py +44 -0
  501. mindspore/ops/_op_impl/tbe/scatter_add.py +2 -0
  502. mindspore/ops/_op_impl/tbe/scatter_nd_add.py +2 -2
  503. mindspore/ops/_op_impl/tbe/slice.py +26 -15
  504. mindspore/ops/_op_impl/tbe/space_to_batch.py +1 -1
  505. mindspore/ops/_op_impl/tbe/space_to_batch_nd.py +1 -1
  506. mindspore/ops/_op_impl/tbe/strided_slice_grad_d.py +1 -0
  507. mindspore/ops/_op_impl/tbe/trans_data_ds.py +15 -5
  508. mindspore/ops/_op_impl/tbe/unsorted_segment_sum.py +1 -1
  509. mindspore/ops/_op_impl/tbe/unsorted_segment_sum_ds.py +2 -0
  510. mindspore/ops/_primitive_cache.py +3 -2
  511. mindspore/ops/_register_for_op.py +11 -0
  512. mindspore/ops/_utils/__init__.py +1 -1
  513. mindspore/ops/_utils/utils.py +20 -41
  514. mindspore/ops/_vmap/__init__.py +2 -2
  515. mindspore/ops/_vmap/vmap_array_ops.py +170 -78
  516. mindspore/ops/_vmap/vmap_base.py +24 -10
  517. mindspore/ops/_vmap/vmap_convolution_ops.py +7 -10
  518. mindspore/ops/_vmap/vmap_grad_math_ops.py +4 -4
  519. mindspore/ops/_vmap/vmap_grad_nn_ops.py +41 -9
  520. mindspore/ops/_vmap/vmap_image_ops.py +52 -0
  521. mindspore/ops/_vmap/vmap_math_ops.py +77 -6
  522. mindspore/ops/_vmap/vmap_nn_ops.py +78 -29
  523. mindspore/ops/_vmap/vmap_other_ops.py +3 -1
  524. mindspore/ops/_vmap/vmap_random_ops.py +55 -3
  525. mindspore/ops/_vmap/vmap_sparse_ops.py +1 -0
  526. mindspore/ops/bprop_mindir/AdaptiveAvgPool2D_bprop.mindir +0 -0
  527. mindspore/ops/bprop_mindir/AdaptiveMaxPool2D_bprop.mindir +0 -0
  528. mindspore/ops/bprop_mindir/ApproximateEqual_bprop.mindir +18 -19
  529. mindspore/ops/bprop_mindir/Argmax_bprop.mindir +13 -12
  530. mindspore/ops/bprop_mindir/Argmin_bprop.mindir +14 -13
  531. mindspore/ops/bprop_mindir/AssignSub_bprop.mindir +17 -18
  532. mindspore/ops/bprop_mindir/Assign_bprop.mindir +16 -16
  533. mindspore/ops/bprop_mindir/AvgPool3D_bprop.mindir +150 -0
  534. mindspore/ops/bprop_mindir/AvgPool_bprop.mindir +66 -0
  535. mindspore/ops/bprop_mindir/BCEWithLogitsLoss_bprop.mindir +0 -0
  536. mindspore/ops/bprop_mindir/BNTrainingReduce_bprop.mindir +13 -12
  537. mindspore/ops/bprop_mindir/BatchNormGrad_bprop.mindir +0 -0
  538. mindspore/ops/bprop_mindir/BatchToSpaceND_bprop.mindir +28 -0
  539. mindspore/ops/bprop_mindir/BiasAddGrad_bprop.mindir +0 -0
  540. mindspore/ops/bprop_mindir/BinaryCrossEntropy_bprop.mindir +33 -0
  541. mindspore/ops/bprop_mindir/BroadcastTo_bprop.mindir +306 -0
  542. mindspore/ops/bprop_mindir/Broadcast_bprop.mindir +12 -8
  543. mindspore/ops/bprop_mindir/CTCLoss_bprop.mindir +0 -0
  544. mindspore/ops/bprop_mindir/Concat_bprop.mindir +0 -0
  545. mindspore/ops/bprop_mindir/Conv2DBackpropFilter_bprop.mindir +240 -0
  546. mindspore/ops/bprop_mindir/Conv2DBackpropInput_bprop.mindir +247 -0
  547. mindspore/ops/bprop_mindir/Conv2DTranspose_bprop.mindir +247 -0
  548. mindspore/ops/bprop_mindir/Conv3DTranspose_bprop.mindir +315 -0
  549. mindspore/ops/bprop_mindir/Conv3D_bprop.mindir +278 -0
  550. mindspore/ops/bprop_mindir/DType_bprop.mindir +12 -12
  551. mindspore/ops/bprop_mindir/DeformableOffsets_bprop.mindir +58 -0
  552. mindspore/ops/bprop_mindir/Depend_bprop.mindir +12 -13
  553. mindspore/ops/bprop_mindir/DepthToSpace_bprop.mindir +23 -0
  554. mindspore/ops/bprop_mindir/DepthwiseConv2dNative_bprop.mindir +138 -0
  555. mindspore/ops/bprop_mindir/DiagPart_bprop.mindir +15 -0
  556. mindspore/ops/bprop_mindir/Dropout2D_bprop.mindir +0 -0
  557. mindspore/ops/bprop_mindir/Dropout3D_bprop.mindir +0 -0
  558. mindspore/ops/bprop_mindir/DropoutDoMask_bprop.mindir +22 -24
  559. mindspore/ops/bprop_mindir/DropoutGenMask_bprop.mindir +16 -14
  560. mindspore/ops/bprop_mindir/DropoutGrad_bprop.mindir +27 -0
  561. mindspore/ops/bprop_mindir/Dropout_bprop.mindir +0 -0
  562. mindspore/ops/bprop_mindir/DynamicGRUV2_bprop.mindir +0 -0
  563. mindspore/ops/bprop_mindir/DynamicRNN_bprop.mindir +0 -0
  564. mindspore/ops/bprop_mindir/DynamicShape_bprop.mindir +12 -12
  565. mindspore/ops/bprop_mindir/Elu_bprop.mindir +16 -0
  566. mindspore/ops/bprop_mindir/EmbeddingLookup_bprop.mindir +0 -0
  567. mindspore/ops/bprop_mindir/Equal_bprop.mindir +18 -19
  568. mindspore/ops/bprop_mindir/ExpandDims_bprop.mindir +58 -0
  569. mindspore/ops/bprop_mindir/FastGeLU_bprop.mindir +16 -0
  570. mindspore/ops/bprop_mindir/Flatten_bprop.mindir +54 -0
  571. mindspore/ops/bprop_mindir/FloorDiv_bprop.mindir +18 -15
  572. mindspore/ops/bprop_mindir/GatherD_bprop.mindir +26 -0
  573. mindspore/ops/bprop_mindir/GatherNd_bprop.mindir +57 -0
  574. mindspore/ops/bprop_mindir/Gather_bprop.mindir +0 -0
  575. mindspore/ops/bprop_mindir/GreaterEqual_bprop.mindir +17 -18
  576. mindspore/ops/bprop_mindir/Greater_bprop.mindir +18 -19
  577. mindspore/ops/bprop_mindir/HSigmoid_bprop.mindir +16 -0
  578. mindspore/ops/bprop_mindir/HSwish_bprop.mindir +16 -0
  579. mindspore/ops/bprop_mindir/IOU_bprop.mindir +18 -19
  580. mindspore/ops/bprop_mindir/InstanceNorm_bprop.mindir +0 -0
  581. mindspore/ops/bprop_mindir/IsFinite_bprop.mindir +13 -12
  582. mindspore/ops/bprop_mindir/IsInf_bprop.mindir +13 -10
  583. mindspore/ops/bprop_mindir/IsNan_bprop.mindir +14 -11
  584. mindspore/ops/bprop_mindir/KLDivLoss_bprop.mindir +126 -0
  585. mindspore/ops/bprop_mindir/L2Loss_bprop.mindir +15 -0
  586. mindspore/ops/bprop_mindir/L2Normalize_bprop.mindir +30 -0
  587. mindspore/ops/bprop_mindir/LRN_bprop.mindir +43 -0
  588. mindspore/ops/bprop_mindir/LayerNormGrad_bprop.mindir +0 -0
  589. mindspore/ops/bprop_mindir/LessEqual_bprop.mindir +18 -19
  590. mindspore/ops/bprop_mindir/Less_bprop.mindir +17 -18
  591. mindspore/ops/bprop_mindir/LinSpace_bprop.mindir +22 -19
  592. mindspore/ops/bprop_mindir/Load_bprop.mindir +12 -13
  593. mindspore/ops/bprop_mindir/LogSoftmax_bprop.mindir +23 -0
  594. mindspore/ops/bprop_mindir/LogicalAnd_bprop.mindir +17 -18
  595. mindspore/ops/bprop_mindir/LogicalNot_bprop.mindir +14 -13
  596. mindspore/ops/bprop_mindir/MaskedSelect_bprop.mindir +21 -0
  597. mindspore/ops/bprop_mindir/MaxPool3DGradGrad_bprop.mindir +74 -0
  598. mindspore/ops/bprop_mindir/MaxPool3DGrad_bprop.mindir +74 -0
  599. mindspore/ops/bprop_mindir/MaxPool3D_bprop.mindir +75 -0
  600. mindspore/ops/bprop_mindir/MaxPoolGradGrad_bprop.mindir +65 -0
  601. mindspore/ops/bprop_mindir/MaxPoolWithArgmax_bprop.mindir +0 -0
  602. mindspore/ops/bprop_mindir/Maximum_bprop.mindir +0 -0
  603. mindspore/ops/bprop_mindir/Minimum_bprop.mindir +0 -0
  604. mindspore/ops/bprop_mindir/MirrorPad_bprop.mindir +27 -0
  605. mindspore/ops/bprop_mindir/Mish_bprop.mindir +35 -0
  606. mindspore/ops/bprop_mindir/MulNoNan_bprop.mindir +0 -0
  607. mindspore/ops/bprop_mindir/NLLLoss_bprop.mindir +0 -0
  608. mindspore/ops/bprop_mindir/NonZero_bprop.mindir +14 -0
  609. mindspore/ops/bprop_mindir/NotEqual_bprop.mindir +18 -19
  610. mindspore/ops/bprop_mindir/OneHot_bprop.mindir +25 -23
  611. mindspore/ops/bprop_mindir/OnesLike_bprop.mindir +13 -13
  612. mindspore/ops/bprop_mindir/PReLU_bprop.mindir +0 -0
  613. mindspore/ops/bprop_mindir/Pad_bprop.mindir +0 -0
  614. mindspore/ops/bprop_mindir/Padding_bprop.mindir +0 -0
  615. mindspore/ops/bprop_mindir/RNNTLoss_bprop.mindir +29 -0
  616. mindspore/ops/bprop_mindir/ROIAlign_bprop.mindir +82 -0
  617. mindspore/ops/bprop_mindir/Range_bprop.mindir +21 -19
  618. mindspore/ops/bprop_mindir/Rank_bprop.mindir +11 -11
  619. mindspore/ops/bprop_mindir/ReLU6_bprop.mindir +16 -0
  620. mindspore/ops/bprop_mindir/ReLUV2_bprop.mindir +0 -0
  621. mindspore/ops/bprop_mindir/ReduceAll_bprop.mindir +18 -17
  622. mindspore/ops/bprop_mindir/ReduceAny_bprop.mindir +18 -17
  623. mindspore/ops/bprop_mindir/ReluGrad_bprop.mindir +19 -23
  624. mindspore/ops/bprop_mindir/Reshape_bprop.mindir +60 -0
  625. mindspore/ops/bprop_mindir/ResizeBilinear_bprop.mindir +29 -0
  626. mindspore/ops/bprop_mindir/ResizeNearestNeighbor_bprop.mindir +89 -0
  627. mindspore/ops/bprop_mindir/ReverseSequence_bprop.mindir +52 -0
  628. mindspore/ops/bprop_mindir/ReverseV2_bprop.mindir +22 -0
  629. mindspore/ops/bprop_mindir/Round_bprop.mindir +14 -13
  630. mindspore/ops/bprop_mindir/ScatterMax_bprop.mindir +0 -0
  631. mindspore/ops/bprop_mindir/ScatterMin_bprop.mindir +0 -0
  632. mindspore/ops/bprop_mindir/ScatterNdUpdate_bprop.mindir +22 -0
  633. mindspore/ops/bprop_mindir/ScatterNd_bprop.mindir +24 -0
  634. mindspore/ops/bprop_mindir/ScatterNonAliasingAdd_bprop.mindir +22 -0
  635. mindspore/ops/bprop_mindir/ScatterUpdate_bprop.mindir +0 -0
  636. mindspore/ops/bprop_mindir/SeLU_bprop.mindir +21 -0
  637. mindspore/ops/bprop_mindir/Select_bprop.mindir +30 -34
  638. mindspore/ops/bprop_mindir/Shape_bprop.mindir +12 -12
  639. mindspore/ops/bprop_mindir/SigmoidCrossEntropyWithLogits_bprop.mindir +21 -0
  640. mindspore/ops/bprop_mindir/SigmoidGrad_bprop.mindir +0 -0
  641. mindspore/ops/bprop_mindir/Sigmoid_bprop.mindir +16 -0
  642. mindspore/ops/bprop_mindir/Sign_bprop.mindir +13 -12
  643. mindspore/ops/bprop_mindir/Slice_bprop.mindir +26 -0
  644. mindspore/ops/bprop_mindir/SmoothL1Loss_bprop.mindir +36 -0
  645. mindspore/ops/bprop_mindir/SoftmaxCrossEntropyWithLogits_bprop.mindir +0 -0
  646. mindspore/ops/bprop_mindir/Softplus_bprop.mindir +16 -0
  647. mindspore/ops/bprop_mindir/Softsign_bprop.mindir +33 -0
  648. mindspore/ops/bprop_mindir/Sort_bprop.mindir +0 -0
  649. mindspore/ops/bprop_mindir/SpaceToBatchND_bprop.mindir +28 -0
  650. mindspore/ops/bprop_mindir/SpaceToDepth_bprop.mindir +23 -0
  651. mindspore/ops/bprop_mindir/SparseGatherV2_bprop.mindir +0 -0
  652. mindspore/ops/bprop_mindir/SparseSoftmaxCrossEntropyWithLogits_bprop.mindir +0 -0
  653. mindspore/ops/bprop_mindir/Split_bprop.mindir +22 -0
  654. mindspore/ops/bprop_mindir/Squeeze_bprop.mindir +54 -0
  655. mindspore/ops/bprop_mindir/StridedSliceGrad_bprop.mindir +95 -0
  656. mindspore/ops/bprop_mindir/StridedSlice_bprop.mindir +98 -0
  657. mindspore/ops/bprop_mindir/Switch_bprop.mindir +28 -32
  658. mindspore/ops/bprop_mindir/TanhGrad_bprop.mindir +0 -0
  659. mindspore/ops/bprop_mindir/Tanh_bprop.mindir +66 -0
  660. mindspore/ops/bprop_mindir/TensorScatterAdd_bprop.mindir +22 -0
  661. mindspore/ops/bprop_mindir/TensorScatterUpdate_bprop.mindir +29 -0
  662. mindspore/ops/bprop_mindir/TensorShape_bprop.mindir +14 -0
  663. mindspore/ops/bprop_mindir/Tile_bprop.mindir +0 -0
  664. mindspore/ops/bprop_mindir/TopK_bprop.mindir +0 -0
  665. mindspore/ops/bprop_mindir/TransShape_bprop.mindir +23 -0
  666. mindspore/ops/bprop_mindir/TruncateDiv_bprop.mindir +18 -15
  667. mindspore/ops/bprop_mindir/TupleGetItem_bprop.mindir +11 -13
  668. mindspore/ops/bprop_mindir/Unique_bprop.mindir +16 -0
  669. mindspore/ops/bprop_mindir/Unstack_bprop.mindir +22 -0
  670. mindspore/ops/bprop_mindir/UpsampleNearest3D_bprop.mindir +32 -0
  671. mindspore/ops/bprop_mindir/UpsampleTrilinear3D_bprop.mindir +38 -0
  672. mindspore/ops/bprop_mindir/ZerosLike_bprop.mindir +13 -12
  673. mindspore/ops/bprop_mindir/__init__.py +1 -4
  674. mindspore/ops/bprop_mindir/generate_mindir.py +32 -20
  675. mindspore/ops/composite/__init__.py +12 -13
  676. mindspore/ops/composite/base.py +261 -254
  677. mindspore/ops/composite/env_ops.py +41 -0
  678. mindspore/ops/composite/math_ops.py +197 -156
  679. mindspore/ops/composite/multitype_ops/_compile_utils.py +428 -176
  680. mindspore/ops/composite/multitype_ops/_constexpr_utils.py +188 -87
  681. mindspore/ops/composite/multitype_ops/add_impl.py +23 -1
  682. mindspore/ops/composite/multitype_ops/div_impl.py +3 -3
  683. mindspore/ops/composite/multitype_ops/equal_impl.py +1 -0
  684. mindspore/ops/composite/multitype_ops/floordiv_impl.py +1 -1
  685. mindspore/ops/composite/multitype_ops/getitem_impl.py +52 -5
  686. mindspore/ops/composite/multitype_ops/greater_equal_impl.py +31 -0
  687. mindspore/ops/composite/multitype_ops/greater_impl.py +31 -0
  688. mindspore/ops/composite/multitype_ops/in_impl.py +15 -3
  689. mindspore/ops/composite/multitype_ops/less_equal_impl.py +33 -2
  690. mindspore/ops/composite/multitype_ops/less_impl.py +33 -0
  691. mindspore/ops/composite/multitype_ops/logical_and_impl.py +2 -2
  692. mindspore/ops/composite/multitype_ops/logical_or_impl.py +2 -1
  693. mindspore/ops/composite/multitype_ops/mod_impl.py +1 -1
  694. mindspore/ops/composite/multitype_ops/mul_impl.py +21 -7
  695. mindspore/ops/composite/multitype_ops/not_in_impl.py +15 -3
  696. mindspore/ops/composite/multitype_ops/ones_like_impl.py +2 -4
  697. mindspore/ops/composite/multitype_ops/pow_impl.py +1 -0
  698. mindspore/ops/composite/multitype_ops/setitem_impl.py +62 -70
  699. mindspore/ops/composite/multitype_ops/sub_impl.py +3 -3
  700. mindspore/ops/composite/multitype_ops/zeros_like_impl.py +41 -4
  701. mindspore/ops/function/__init__.py +323 -8
  702. mindspore/ops/function/array_func.py +3511 -780
  703. mindspore/ops/function/clip_func.py +329 -0
  704. mindspore/ops/function/debug_func.py +6 -6
  705. mindspore/ops/function/grad/__init__.py +5 -1
  706. mindspore/ops/function/grad/grad_func.py +736 -65
  707. mindspore/ops/function/image_func.py +270 -0
  708. mindspore/ops/function/linalg_func.py +268 -8
  709. mindspore/ops/function/math_func.py +8032 -3164
  710. mindspore/ops/function/nn_func.py +5619 -1855
  711. mindspore/ops/function/other_func.py +115 -0
  712. mindspore/ops/function/parameter_func.py +11 -10
  713. mindspore/ops/function/random_func.py +939 -77
  714. mindspore/ops/function/sparse_func.py +249 -84
  715. mindspore/ops/function/sparse_unary_func.py +2303 -0
  716. mindspore/ops/function/spectral_func.py +146 -0
  717. mindspore/ops/function/vmap_func.py +114 -0
  718. mindspore/ops/functional.py +182 -254
  719. mindspore/ops/op_info_register.py +79 -34
  720. mindspore/ops/operations/__init__.py +210 -118
  721. mindspore/ops/operations/_csr_ops.py +7 -7
  722. mindspore/ops/operations/_embedding_cache_ops.py +25 -15
  723. mindspore/ops/operations/_grad_ops.py +447 -322
  724. mindspore/ops/operations/_inner_ops.py +547 -176
  725. mindspore/ops/operations/_map_tensor_ops.py +112 -0
  726. mindspore/ops/operations/_ms_kernel.py +29 -27
  727. mindspore/ops/operations/_ocr_ops.py +11 -11
  728. mindspore/ops/operations/_opaque_predicate_registry.py +41 -0
  729. mindspore/ops/operations/_quant_ops.py +186 -101
  730. mindspore/ops/operations/_rl_inner_ops.py +122 -61
  731. mindspore/ops/operations/_scalar_ops.py +466 -0
  732. mindspore/ops/operations/_sequence_ops.py +1047 -0
  733. mindspore/ops/operations/_tensor_array.py +10 -11
  734. mindspore/ops/operations/_thor_ops.py +4 -4
  735. mindspore/ops/operations/array_ops.py +1428 -1226
  736. mindspore/ops/operations/comm_ops.py +180 -117
  737. mindspore/ops/operations/control_ops.py +4 -2
  738. mindspore/ops/operations/custom_ops.py +185 -98
  739. mindspore/ops/operations/debug_ops.py +92 -54
  740. mindspore/ops/operations/image_ops.py +406 -211
  741. mindspore/ops/operations/inner_ops.py +42 -53
  742. mindspore/ops/operations/linalg_ops.py +32 -29
  743. mindspore/ops/operations/math_ops.py +2076 -897
  744. mindspore/ops/operations/nn_ops.py +1282 -1252
  745. mindspore/ops/operations/other_ops.py +124 -278
  746. mindspore/ops/operations/random_ops.py +345 -178
  747. mindspore/ops/operations/rl_ops.py +8 -9
  748. mindspore/ops/operations/sparse_ops.py +502 -157
  749. mindspore/ops/operations/spectral_ops.py +107 -0
  750. mindspore/ops/primitive.py +192 -15
  751. mindspore/ops/vm_impl_registry.py +23 -2
  752. mindspore/parallel/__init__.py +6 -1
  753. mindspore/parallel/_auto_parallel_context.py +199 -92
  754. mindspore/parallel/_cell_wrapper.py +4 -2
  755. mindspore/parallel/_cost_model_context.py +3 -0
  756. mindspore/parallel/_dp_allreduce_fusion.py +2 -1
  757. mindspore/parallel/_offload_context.py +185 -0
  758. mindspore/parallel/_parallel_serialization.py +167 -28
  759. mindspore/parallel/_ps_context.py +9 -5
  760. mindspore/parallel/_recovery_context.py +1 -1
  761. mindspore/parallel/_tensor.py +9 -1
  762. mindspore/{nn/transformer → parallel/_transformer}/__init__.py +6 -6
  763. mindspore/{nn/transformer → parallel/_transformer}/layers.py +59 -37
  764. mindspore/{nn/transformer → parallel/_transformer}/loss.py +4 -7
  765. mindspore/{nn/transformer → parallel/_transformer}/moe.py +160 -35
  766. mindspore/{nn/transformer → parallel/_transformer}/op_parallel_config.py +3 -3
  767. mindspore/{nn/transformer → parallel/_transformer}/transformer.py +235 -196
  768. mindspore/parallel/_utils.py +47 -7
  769. mindspore/parallel/algo_parameter_config.py +5 -1
  770. mindspore/parallel/checkpoint_transform.py +329 -0
  771. mindspore/parallel/shard.py +229 -0
  772. mindspore/perf_msvcbuildinsights.dll +0 -0
  773. mindspore/pgodb140.dll +0 -0
  774. mindspore/pgort140.dll +0 -0
  775. mindspore/profiler/__init__.py +2 -1
  776. mindspore/profiler/common/util.py +4 -3
  777. mindspore/profiler/common/validator/validate_path.py +2 -2
  778. mindspore/profiler/envprofiling.py +249 -0
  779. mindspore/profiler/parser/aicpu_data_parser.py +38 -39
  780. mindspore/profiler/parser/ascend_timeline_generator.py +497 -0
  781. mindspore/profiler/parser/base_timeline_generator.py +471 -0
  782. mindspore/profiler/parser/cpu_gpu_timeline_generator.py +684 -0
  783. mindspore/profiler/parser/framework_parser.py +42 -16
  784. mindspore/profiler/parser/hccl_parser.py +158 -158
  785. mindspore/profiler/parser/hwts_log_parser.py +7 -6
  786. mindspore/profiler/parser/integrator.py +18 -1579
  787. mindspore/profiler/parser/minddata_analyzer.py +8 -8
  788. mindspore/profiler/parser/msadvisor_analyzer.py +14 -27
  789. mindspore/profiler/parser/msadvisor_parser.py +2 -4
  790. mindspore/profiler/parser/optime_parser.py +17 -18
  791. mindspore/profiler/parser/profiler_info.py +108 -0
  792. mindspore/profiler/parser/step_trace_parser.py +1 -1
  793. mindspore/profiler/profiling.py +396 -194
  794. mindspore/rewrite/__init__.py +6 -2
  795. mindspore/rewrite/api/node.py +51 -110
  796. mindspore/rewrite/api/node_type.py +10 -6
  797. mindspore/rewrite/api/pattern_engine.py +51 -7
  798. mindspore/rewrite/api/scoped_value.py +64 -53
  799. mindspore/rewrite/api/symbol_tree.py +108 -61
  800. mindspore/rewrite/api/tree_node_helper.py +2 -3
  801. mindspore/{compression/quant/__init__.py → rewrite/ast_creator_register.py} +20 -11
  802. mindspore/rewrite/ast_helpers/__init__.py +6 -3
  803. mindspore/rewrite/ast_helpers/ast_creator.py +115 -0
  804. mindspore/rewrite/ast_helpers/ast_finder.py +99 -1
  805. mindspore/rewrite/ast_helpers/ast_modifier.py +17 -4
  806. mindspore/rewrite/ast_helpers/ast_replacer.py +1 -1
  807. mindspore/rewrite/ast_transformers/__init__.py +0 -1
  808. mindspore/rewrite/ast_transformers/flatten_recursive_stmt.py +46 -5
  809. mindspore/rewrite/ast_transformers/remove_return_out_of_if.py +6 -3
  810. mindspore/rewrite/common/__init__.py +2 -0
  811. mindspore/rewrite/common/event.py +1 -1
  812. mindspore/rewrite/common/observable.py +1 -1
  813. mindspore/rewrite/common/observer.py +1 -1
  814. mindspore/rewrite/common/rewrite_elog.py +35 -0
  815. mindspore/rewrite/namer.py +2 -2
  816. mindspore/rewrite/namespace.py +14 -4
  817. mindspore/rewrite/node.py +161 -13
  818. mindspore/rewrite/parser.py +0 -1
  819. mindspore/rewrite/parser_register.py +0 -1
  820. mindspore/rewrite/parsers/arguments_parser.py +3 -2
  821. mindspore/rewrite/parsers/assign_parser.py +267 -67
  822. mindspore/rewrite/parsers/attribute_parser.py +56 -0
  823. mindspore/rewrite/parsers/class_def_parser.py +191 -108
  824. mindspore/rewrite/parsers/constant_parser.py +101 -0
  825. mindspore/rewrite/parsers/container_parser.py +88 -0
  826. mindspore/rewrite/parsers/for_parser.py +28 -15
  827. mindspore/rewrite/parsers/function_def_parser.py +21 -5
  828. mindspore/rewrite/parsers/if_parser.py +11 -28
  829. mindspore/rewrite/parsers/module_parser.py +9 -6
  830. mindspore/rewrite/parsers/return_parser.py +3 -2
  831. mindspore/rewrite/sparsify/__init__.py +0 -0
  832. mindspore/rewrite/sparsify/sparse_transformer.py +448 -0
  833. mindspore/rewrite/sparsify/sparsify.py +109 -0
  834. mindspore/rewrite/sparsify/utils.py +173 -0
  835. mindspore/rewrite/symbol_tree.py +322 -109
  836. mindspore/rewrite/symbol_tree_builder.py +45 -8
  837. mindspore/rewrite/symbol_tree_dumper.py +0 -1
  838. mindspore/rewrite/topological_manager.py +1 -2
  839. mindspore/run_check/_check_version.py +209 -112
  840. mindspore/run_check/run_check.py +2 -1
  841. mindspore/tbbmalloc.dll +0 -0
  842. mindspore/tinyxml2.dll +0 -0
  843. mindspore/train/__init__.py +6 -4
  844. mindspore/train/_utils.py +28 -5
  845. mindspore/train/amp.py +321 -50
  846. mindspore/train/callback/__init__.py +3 -1
  847. mindspore/train/callback/_backup_and_restore.py +120 -0
  848. mindspore/train/callback/_callback.py +8 -8
  849. mindspore/train/callback/_checkpoint.py +12 -9
  850. mindspore/train/callback/_early_stop.py +13 -7
  851. mindspore/train/callback/_history.py +8 -8
  852. mindspore/train/callback/_lambda_callback.py +6 -6
  853. mindspore/train/callback/_landscape.py +36 -38
  854. mindspore/train/callback/_loss_monitor.py +12 -6
  855. mindspore/train/callback/_lr_scheduler_callback.py +2 -4
  856. mindspore/train/callback/_on_request_exit.py +212 -0
  857. mindspore/train/callback/_reduce_lr_on_plateau.py +13 -7
  858. mindspore/train/callback/_summary_collector.py +27 -19
  859. mindspore/train/callback/_time_monitor.py +13 -7
  860. mindspore/train/checkpoint_pb2.py +68 -8
  861. mindspore/train/data_sink.py +122 -33
  862. mindspore/train/dataset_helper.py +28 -87
  863. mindspore/train/loss_scale_manager.py +4 -7
  864. mindspore/{nn → train}/metrics/__init__.py +20 -20
  865. mindspore/{nn → train}/metrics/accuracy.py +12 -10
  866. mindspore/{nn → train}/metrics/auc.py +4 -4
  867. mindspore/{nn → train}/metrics/bleu_score.py +4 -4
  868. mindspore/{nn → train}/metrics/confusion_matrix.py +10 -8
  869. mindspore/{nn → train}/metrics/cosine_similarity.py +4 -4
  870. mindspore/{nn → train}/metrics/dice.py +6 -5
  871. mindspore/{nn → train}/metrics/error.py +7 -5
  872. mindspore/{nn → train}/metrics/fbeta.py +9 -7
  873. mindspore/{nn → train}/metrics/hausdorff_distance.py +8 -6
  874. mindspore/{nn → train}/metrics/loss.py +4 -3
  875. mindspore/{nn → train}/metrics/mean_surface_distance.py +6 -5
  876. mindspore/{nn → train}/metrics/metric.py +6 -5
  877. mindspore/{nn → train}/metrics/occlusion_sensitivity.py +4 -3
  878. mindspore/{nn → train}/metrics/perplexity.py +5 -4
  879. mindspore/{nn → train}/metrics/precision.py +5 -4
  880. mindspore/{nn → train}/metrics/recall.py +5 -4
  881. mindspore/{nn → train}/metrics/roc.py +7 -6
  882. mindspore/{nn → train}/metrics/root_mean_square_surface_distance.py +6 -5
  883. mindspore/{nn → train}/metrics/topk.py +7 -5
  884. mindspore/train/mind_ir_pb2.py +339 -32
  885. mindspore/train/model.py +113 -84
  886. mindspore/train/serialization.py +547 -167
  887. mindspore/train/summary/_summary_adapter.py +1 -1
  888. mindspore/train/summary/summary_record.py +43 -12
  889. mindspore/train/train_thor/convert_utils.py +7 -1
  890. mindspore/train/train_thor/dataset_helper.py +3 -3
  891. mindspore/train/train_thor/model_thor.py +0 -4
  892. mindspore/turbojpeg.dll +0 -0
  893. mindspore/vcmeta.dll +0 -0
  894. mindspore/vcruntime140.dll +0 -0
  895. mindspore/vcruntime140_1.dll +0 -0
  896. mindspore/version.py +1 -1
  897. {mindspore-1.10.0.dist-info → mindspore-2.0.0rc1.dist-info}/METADATA +4 -3
  898. {mindspore-1.10.0.dist-info → mindspore-2.0.0rc1.dist-info}/RECORD +901 -660
  899. mindspore/compression/common/constant.py +0 -124
  900. mindspore/compression/export/__init__.py +0 -19
  901. mindspore/compression/export/quant_export.py +0 -514
  902. mindspore/compression/quant/qat.py +0 -636
  903. mindspore/compression/quant/quant_utils.py +0 -462
  904. mindspore/compression/quant/quantizer.py +0 -68
  905. mindspore/libatomic-1.dll +0 -0
  906. mindspore/libgcc_s_seh-1.dll +0 -0
  907. mindspore/libgfortran-4.dll +0 -0
  908. mindspore/libgomp-1.dll +0 -0
  909. mindspore/libjpeg-62.dll +0 -0
  910. mindspore/libmindspore.dll +0 -0
  911. mindspore/libmindspore_common.dll +0 -0
  912. mindspore/libmindspore_core.dll +0 -0
  913. mindspore/libmindspore_glog.dll +0 -0
  914. mindspore/libnnacl.dll +0 -0
  915. mindspore/libopencv_core452.dll +0 -0
  916. mindspore/libopencv_imgcodecs452.dll +0 -0
  917. mindspore/libopencv_imgproc452.dll +0 -0
  918. mindspore/libquadmath-0.dll +0 -0
  919. mindspore/libsqlite3.dll +0 -0
  920. mindspore/libssp-0.dll +0 -0
  921. mindspore/libstdc++-6.dll +0 -0
  922. mindspore/libtinyxml2.dll +0 -0
  923. mindspore/libturbojpeg.dll +0 -0
  924. mindspore/libwinpthread-1.dll +0 -0
  925. mindspore/nn/layer/quant.py +0 -1868
  926. mindspore/nn/layer/rnn_utils.py +0 -90
  927. mindspore/nn/probability/dpn/__init__.py +0 -22
  928. mindspore/nn/probability/dpn/vae/__init__.py +0 -25
  929. mindspore/nn/probability/dpn/vae/cvae.py +0 -138
  930. mindspore/nn/probability/dpn/vae/vae.py +0 -122
  931. mindspore/nn/probability/infer/__init__.py +0 -22
  932. mindspore/nn/probability/infer/variational/elbo.py +0 -70
  933. mindspore/nn/probability/infer/variational/svi.py +0 -84
  934. mindspore/nn/probability/toolbox/__init__.py +0 -22
  935. mindspore/nn/probability/toolbox/anomaly_detection.py +0 -99
  936. mindspore/nn/probability/toolbox/uncertainty_evaluation.py +0 -363
  937. mindspore/nn/probability/transforms/__init__.py +0 -22
  938. mindspore/nn/probability/transforms/transform_bnn.py +0 -262
  939. mindspore/nn/probability/zhusuan/__init__.py +0 -18
  940. mindspore/nn/probability/zhusuan/framework/__init__.py +0 -18
  941. mindspore/nn/probability/zhusuan/framework/bn.py +0 -95
  942. mindspore/nn/probability/zhusuan/variational/__init__.py +0 -18
  943. mindspore/nn/probability/zhusuan/variational/elbo.py +0 -46
  944. mindspore/ops/_op_impl/tbe/bias_add_grad_ds.py +0 -52
  945. mindspore/ops/_op_impl/tbe/scatter_nd_add_ds.py +0 -43
  946. mindspore/ops/bprop_mindir/AssignAdd_bprop.mindir +0 -20
  947. mindspore/ops/bprop_mindir/Identity_bprop.mindir +0 -9
  948. mindspore/ops/bprop_mindir/LogicalOr_bprop.mindir +0 -20
  949. mindspore/ops/bprop_mindir/ReLU_bprop.mindir +0 -16
  950. mindspore/ops/bprop_mindir/UpdateState_bprop.mindir +0 -17
  951. mindspore/ops/bprop_mindir/stop_gradient_bprop.mindir +0 -12
  952. mindspore/ops/composite/array_ops.py +0 -210
  953. mindspore/ops/composite/clip_ops.py +0 -238
  954. mindspore/ops/composite/random_ops.py +0 -426
  955. mindspore/ops/composite/vmap_ops.py +0 -38
  956. mindspore/ops/operations/sponge_ops.py +0 -3531
  957. mindspore/ops/operations/sponge_update_ops.py +0 -2546
  958. mindspore/parallel/nn/__init__.py +0 -42
  959. mindspore/parallel/nn/loss.py +0 -22
  960. mindspore/parallel/nn/moe.py +0 -21
  961. mindspore/parallel/nn/op_parallel_config.py +0 -22
  962. mindspore/parallel/nn/transformer.py +0 -31
  963. mindspore/run_check/_check_deps_version.py +0 -84
  964. {mindspore-1.10.0.dist-info → mindspore-2.0.0rc1.dist-info}/WHEEL +0 -0
  965. {mindspore-1.10.0.dist-info → mindspore-2.0.0rc1.dist-info}/entry_points.txt +0 -0
  966. {mindspore-1.10.0.dist-info → mindspore-2.0.0rc1.dist-info}/top_level.txt +0 -0
@@ -19,16 +19,17 @@ from __future__ import division
19
19
 
20
20
  import math
21
21
  from functools import partial
22
-
23
22
  from mindspore import log as logger
24
23
  from mindspore._checkparam import _check_3d_int_or_tuple
25
24
  from mindspore import context
26
25
  from mindspore.ops import signature as sig
27
- from mindspore._checkparam import Validator as validator
28
- from mindspore._checkparam import Rel
26
+ from mindspore import _checkparam as validator
29
27
  from mindspore.common import dtype as mstype
30
28
  from mindspore.common._decorator import deprecated
31
- from mindspore.ops.primitive import Primitive, PrimitiveWithInfer, PrimitiveWithCheck, prim_attr_register
29
+ from mindspore.ops.primitive import Primitive
30
+ from mindspore.ops.primitive import PrimitiveWithInfer
31
+ from mindspore.ops.primitive import PrimitiveWithCheck
32
+ from mindspore.ops.primitive import prim_attr_register
32
33
 
33
34
 
34
35
  def _check_positive_int_or_tuple(arg_name, arg_value, prim_name, allow_four=False,
@@ -98,30 +99,7 @@ class CeLU(Primitive):
98
99
  r"""
99
100
  Computes CeLU (Continuously differentiable exponential linear units) of input tensors element-wise.
100
101
 
101
- .. math::
102
-
103
- \text{CeLU}(x) = \max(0,x) + \min(0, \alpha * (\exp(x/\alpha) - 1))
104
-
105
- It returns :math:`\max(0,x) + \min(0, \alpha * (\exp(x/\alpha) - 1))` element-wise.
106
-
107
- The picture about CeLU looks like this `CeLU <https://arxiv.org/abs/1704.07483>`_.
108
-
109
-
110
- Args:
111
- alpha (float): The :math:`\alpha` value for the Celu formulation. Default: 1.0
112
-
113
- Inputs:
114
- - **input_x** (Tensor) - Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
115
- additional dimensions, with dtype of float16 and float32.
116
-
117
- Outputs:
118
- Tensor, with the same type and shape as the `input_x`.
119
-
120
- Raises:
121
- TypeError: If `alpha` is not a float.
122
- ValueError: If `alpha` has the value of 0.
123
- TypeError: If `input_x` is not a Tensor.
124
- TypeError: If the dtype of 'input_x' is neither float16 nor float32.
102
+ Refer to :func:`mindspore.ops.celu` for more details.
125
103
 
126
104
  Supported Platforms:
127
105
  ``Ascend`` ``GPU`` ``CPU``
@@ -138,7 +116,7 @@ class CeLU(Primitive):
138
116
  def __init__(self, alpha=1.0):
139
117
  """Initialize CeLU"""
140
118
  validator.check_value_type("alpha", alpha, [float], self.name)
141
- validator.check_float(alpha, 0.0, Rel.NE, "alpha", self.name)
119
+ validator.check_float(alpha, 0.0, validator.NE, "alpha", self.name)
142
120
  self.alpha = alpha
143
121
  self.add_prim_attr('alpha', self.alpha)
144
122
 
@@ -169,10 +147,13 @@ class AdaptiveAvgPool3D(Primitive):
169
147
  r"""
170
148
  AdaptiveAvgPool3D operation.
171
149
 
150
+ .. warning::
151
+ This is an experimental API that is subject to change or deletion.
152
+
172
153
  Refer to :func:`mindspore.ops.adaptive_avg_pool3d` for more details.
173
154
 
174
155
  Supported Platforms:
175
- ``GPU``
156
+ ``Ascend`` ``GPU`` ``CPU``
176
157
 
177
158
  Examples:
178
159
  >>> import mindspore
@@ -199,13 +180,12 @@ class AdaptiveAvgPool3D(Primitive):
199
180
 
200
181
  @prim_attr_register
201
182
  def __init__(self, output_size):
202
- self.add_prim_attr("cust_aicpu", self.name)
203
183
  validator.check_value_type("output_size", output_size, [int, tuple], self.name)
204
184
  self.output_size = (output_size,) * 3 if isinstance(self.output_size, int) else output_size
205
185
  for i, size in enumerate(self.output_size):
206
186
  validator.check_value_type(f"output_size[{i}]", size, [int, type(None)], self.name)
207
187
  if size is not None:
208
- 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)
209
189
 
210
190
  self.output_size = tuple(-1 if val is None else val for val in self.output_size)
211
191
 
@@ -213,113 +193,78 @@ class AdaptiveAvgPool3D(Primitive):
213
193
  self.init_prim_io_names(inputs=['x'], outputs=['y'])
214
194
 
215
195
 
216
- class AdaptiveAvgPool2D(PrimitiveWithInfer):
196
+ class AdaptiveAvgPool2D(Primitive):
217
197
  r"""
218
- 2D adaptive average pooling for temporal data.
198
+ AdaptiveAvgPool2D operation.
219
199
 
220
- Refer to :func:`mindspore.ops.adaptive_avg_pool2d` for more detail.
200
+ Refer to :func:`mindspore.ops.adaptive_avg_pool2d` for more details.
221
201
 
222
202
  Supported Platforms:
223
203
  ``GPU``
224
204
 
225
205
  Examples:
226
206
  >>> # case 1: output_size=(None, 2)
227
- >>> input_x = Tensor(np.array([[[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]],
228
- ... [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]],
229
- ... [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]]]), mindspore.float32)
207
+ >>> input_x = Tensor(np.array([[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]],
208
+ ... [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]],
209
+ ... [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]]), mindspore.float32)
230
210
  >>> adaptive_avg_pool_2d = ops.AdaptiveAvgPool2D((None, 2))
231
211
  >>> output = adaptive_avg_pool_2d(input_x)
232
212
  >>> print(output)
233
- [[[[1.5 2.5]
234
- [4.5 5.5]
235
- [7.5 8.5]]
236
- [[1.5 2.5]
237
- [4.5 5.5]
238
- [7.5 8.5]]
239
- [[1.5 2.5]
240
- [4.5 5.5]
241
- [7.5 8.5]]]]
213
+ [[[1.5 2.5]
214
+ [4.5 5.5]
215
+ [7.5 8.5]]
216
+ [[1.5 2.5]
217
+ [4.5 5.5]
218
+ [7.5 8.5]]
219
+ [[1.5 2.5]
220
+ [4.5 5.5]
221
+ [7.5 8.5]]]
242
222
  >>> # case 2: output_size=2
243
223
  >>> adaptive_avg_pool_2d = ops.AdaptiveAvgPool2D(2)
244
224
  >>> output = adaptive_avg_pool_2d(input_x)
245
225
  >>> print(output)
246
- [[[[3. 4.]
247
- [6. 7.]]
248
- [[3. 4.]
249
- [6. 7.]]
250
- [[3. 4.]
251
- [6. 7.]]]]
226
+ [[[3. 4.]
227
+ [6. 7.]]
228
+ [[3. 4.]
229
+ [6. 7.]]
230
+ [[3. 4.]
231
+ [6. 7.]]]
252
232
  >>> # case 3: output_size=(1, 2)
253
233
  >>> adaptive_avg_pool_2d = ops.AdaptiveAvgPool2D((1, 2))
254
234
  >>> output = adaptive_avg_pool_2d(input_x)
255
235
  >>> print(output)
256
- [[[[4.5 5.5]]
257
- [[4.5 5.5]]
258
- [[4.5 5.5]]]]
236
+ [[[4.5 5.5]]
237
+ [[4.5 5.5]]
238
+ [[4.5 5.5]]]
259
239
  """
260
240
 
261
241
  @prim_attr_register
262
242
  def __init__(self, output_size):
263
243
  """Initialize AdaptiveAvgPool2D."""
244
+ self.init_prim_io_names(inputs=['x'], outputs=['y'])
264
245
  validator.check_value_type("output_size", output_size, [int, tuple], self.name)
265
246
  if isinstance(output_size, tuple):
266
- 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)
267
248
  self.output_size = (output_size, output_size) if isinstance(self.output_size, int) else output_size
249
+ for i, size in enumerate(self.output_size):
250
+ validator.check_value_type(f"output_size[{i}]", size, [int, type(None)], self.name)
251
+ if size is not None:
252
+ validator.check_number(f"output_size[{i}]", size, 0, validator.GE, self.name)
268
253
 
269
- def infer_shape(self, x_shape):
270
- if len(x_shape) <= len(self.output_size):
271
- raise ValueError("input_x {} dimension must be larger than output_size {} "
272
- "dimension".format(x_shape, self.output_size))
273
- validator.check_int(len(x_shape), 5, Rel.LT, 'input_x_dimensions', self.name)
274
- for input_x_dimension in x_shape:
275
- validator.check_int(input_x_dimension, 0, Rel.GT, 'input_x dimension', self.name)
276
- zipped = zip(self.output_size, x_shape[-len(self.output_size):])
277
- out_size = [i if i is not None else j for i, j in zipped]
278
- for item in out_size:
279
- validator.check_value_type("item of output_size", item, [int], self.name)
280
- self.add_prim_attr('output_size', out_size)
281
- output_shape = x_shape[:len(x_shape) - len(out_size)] + out_size
282
- return output_shape
283
-
284
- def infer_dtype(self, x_dtype):
285
- validator.check_tensor_dtype_valid("x_dtype", x_dtype, [mstype.float16, mstype.float32, mstype.float64],
286
- self.name)
287
- return x_dtype
254
+ self.output_size = tuple(-1 if val is None else val for val in self.output_size)
255
+ self.add_prim_attr('output_size', self.output_size)
288
256
 
289
257
 
290
258
  class AdaptiveMaxPool2D(Primitive):
291
259
  r"""
292
- AdaptiveMaxPool2D operation.
293
-
294
- This operator applies a 2D adaptive max pooling to an input signal composed of multiple input planes.
295
- That is, for any input size, the size of the specified output is H x W.
296
- The number of output features is equal to the number of input planes.
297
-
298
- The input and output data format can be "NCHW" and "CHW". N is the batch size, C is the number of channels,
299
- H is the feature height, and W is the feature width.
260
+ Performs 2D adaptive max pooling on a multi-plane input signal.
300
261
 
301
- For max adaptive pool2d:
302
-
303
- .. math::
304
-
305
- \begin{align}
306
- h_{start} &= floor(i * H_{in} / H_{out})\\
307
- h_{end} &= ceil((i + 1) * H_{in} / H_{out})\\
308
- w_{start} &= floor(j * W_{in} / W_{out})\\
309
- w_{end} &= ceil((j + 1) * W_{in} / W_{out})\\
310
- Output(i,j) &= {\max Input[h_{start}:h_{end}, w_{start}:w_{end}]}
311
- \end{align}
312
-
313
- Note:
314
- In Ascend, the second output `argmax` is invalid, please ignore it.
262
+ Refer to :func:`mindspore.ops.adaptive_max_pool2d` for more details.
315
263
 
316
264
  Args:
317
- output_size (Union[int, tuple]): The target output size is H x W.
318
- ouput_size can be a tuple, or a single H for H x H, and H and W can be int or None
319
- which means the output size is the same as the input.
320
-
321
- return_indices (bool): If `return_indices` is True, the indices of max value would be output.
322
- Default: False.
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.
323
268
 
324
269
  Inputs:
325
270
  - **input_x** (Tensor) - The input of AdaptiveMaxPool2D, which is a 3D or 4D tensor,
@@ -328,17 +273,6 @@ class AdaptiveMaxPool2D(Primitive):
328
273
  Outputs:
329
274
  Tensor, with the same type as the `input_x`.
330
275
 
331
- Shape of the output is `input_x_shape[:len(input_x_shape) - len(out_shape)] + out_shape`.
332
-
333
- Raises:
334
- TypeError: If `output_size` is not int or tuple.
335
- TypeError: If `input_x` is not a tensor.
336
- TypeError: If `return_indices` is not a bool.
337
- TypeError: If dtype of `input_x` is not float16, float32 or float64.
338
- ValueError: If `output_size` is a tuple and the length of `output_size` is not 2.
339
- ValueError: If the dimension of `input_x` is not NCHW or CHW.
340
- ValueError: If `output_size` is less than -1.
341
-
342
276
  Supported Platforms:
343
277
  ``Ascend`` ``GPU`` ``CPU``
344
278
 
@@ -349,7 +283,7 @@ class AdaptiveMaxPool2D(Primitive):
349
283
  ... [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]]]), mindspore.float32)
350
284
  >>> adaptive_max_pool_2d = ops.AdaptiveMaxPool2D((None, 2))
351
285
  >>> output = adaptive_max_pool_2d(input_x)
352
- >>> print(output)
286
+ >>> print(output[0])
353
287
  [[[[2. 3.]
354
288
  [5. 6.]
355
289
  [8. 9.]]
@@ -362,7 +296,7 @@ class AdaptiveMaxPool2D(Primitive):
362
296
  >>> # case 2: output_size=2
363
297
  >>> adaptive_max_pool_2d = ops.AdaptiveMaxPool2D(2)
364
298
  >>> output = adaptive_max_pool_2d(input_x)
365
- >>> print(output)
299
+ >>> print(output[0])
366
300
  [[[[5. 6.]
367
301
  [8. 9.]]
368
302
  [[5. 6.]
@@ -372,40 +306,49 @@ class AdaptiveMaxPool2D(Primitive):
372
306
  >>> # case 3: output_size=(1, 2)
373
307
  >>> adaptive_max_pool_2d = ops.AdaptiveMaxPool2D((1, 2))
374
308
  >>> output = adaptive_max_pool_2d(input_x)
375
- >>> print(output)
309
+ >>> print(output[0])
376
310
  [[[[8. 9.]]
377
311
  [[8. 9.]]
378
312
  [[8. 9.]]]]
379
313
  """
380
314
 
381
315
  @prim_attr_register
382
- def __init__(self, output_size, return_indices=False):
316
+ def __init__(self, output_size):
383
317
  """Initialize AdaptiveMaxPool2D."""
384
318
  validator.check_value_type("output_size", output_size, [int, tuple], self.name)
385
- validator.check_value_type("return_indices", return_indices, [bool], self.name)
386
319
  if isinstance(output_size, tuple):
387
- validator.check_int(len(output_size), 2, Rel.EQ,
320
+ validator.check_int(len(output_size), 2, validator.EQ,
388
321
  'length of output_size', self.name)
389
322
  self.output_size = (output_size, output_size) if isinstance(self.output_size, int) else output_size
390
323
  self.output_size = (-1 if self.output_size[0] is None else self.output_size[0],
391
324
  -1 if self.output_size[1] is None else self.output_size[1])
392
325
  for size in self.output_size:
393
- validator.check_number("output_size", size, -1, Rel.GE, None)
326
+ validator.check_number("output_size", size, -1, validator.GE, None)
394
327
  self.add_prim_attr('output_size', self.output_size)
395
- self.add_prim_attr('return_indices', return_indices)
396
328
 
397
329
 
398
330
  class AdaptiveMaxPool3D(Primitive):
399
331
  r"""
400
- 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.
401
333
 
402
- Refer to :func:`mindspore.ops.adaptive_max_pool3d` for more detail.
334
+ Refer to :func:`mindspore.ops.adaptive_max_pool3d` for more details.
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.
403
347
 
404
348
  Supported Platforms:
405
- ``GPU``
349
+ ``GPU`` ``CPU``
406
350
 
407
351
  Examples:
408
- >>> # case 1: Dynamic output size
409
352
  >>> class AdaptiveMaxPool3DNet(nn.Cell):
410
353
  ... def __init__(self):
411
354
  ... super(AdaptiveMaxPool3DNet, self).__init__()
@@ -420,23 +363,6 @@ class AdaptiveMaxPool3D(Primitive):
420
363
  [[[[33. 35.]]]]
421
364
  >>> print(output[1].asnumpy())
422
365
  [[[[33 35]]]]
423
-
424
- >>> # case 2: Constant output size
425
- >>> class ConstAdaptiveMaxPool3DNet(nn.Cell):
426
- ... def __init__(self, output_size):
427
- ... super(ConstAdaptiveMaxPool3DNet, self).__init__()
428
- ... self.output_size_ = output_size
429
- ... self.adaptive_max_pool_3d = ops.AdaptiveMaxPool3D()
430
- ... def construct(self, x_):
431
- ... return self.adaptive_max_pool_3d(x_, self.output_size_)
432
- >>> x = np.arange(0,36).reshape((1, 3, 3, 4)).astype(np.float32)
433
- >>> output_size = np.array([1, 1, 2], dtype=np.int32)
434
- >>> net = ConstAdaptiveMaxPool3DNet(Tensor(output_size))
435
- >>> output = net(Tensor(x))
436
- >>> print(output[0].asnumpy())
437
- [[[[33. 35.]]]]
438
- >>> print(output[1].asnumpy())
439
- [[[[33 35]]]]
440
366
  """
441
367
 
442
368
  @prim_attr_register
@@ -448,7 +374,7 @@ class Softmax(Primitive):
448
374
  r"""
449
375
  Applies the Softmax operation to the input tensor on the specified axis.
450
376
 
451
- Refer to :func:`mindspore.ops.softmax` for more detail.
377
+ Refer to :func:`mindspore.ops.softmax` for more details.
452
378
 
453
379
  Supported Platforms:
454
380
  ``Ascend`` ``GPU`` ``CPU``
@@ -476,7 +402,7 @@ class LogSoftmax(Primitive):
476
402
  r"""
477
403
  Log Softmax activation function.
478
404
 
479
- Refer to :func:`mindspore.ops.log_softmax` for more detail.
405
+ Refer to :func:`mindspore.ops.log_softmax` for more details.
480
406
 
481
407
  Supported Platforms:
482
408
  ``Ascend`` ``GPU`` ``CPU``
@@ -505,7 +431,7 @@ class Softplus(Primitive):
505
431
 
506
432
  .. math::
507
433
 
508
- \text{output} = \log(1 + \exp(\text{x})),
434
+ \text{output} = \log(1 + \exp(\text{x}))
509
435
 
510
436
  Inputs:
511
437
  - **input_x** (Tensor) - Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
@@ -596,7 +522,7 @@ class ReLUV3(Primitive):
596
522
  Inputs:
597
523
  - **input_x** (Tensor) - Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
598
524
  additional dimensions, data type is
599
- `number <https://www.mindspore.cn/docs/en/r1.10/api_python/mindspore.html#mindspore.dtype>`_.
525
+ `number <https://www.mindspore.cn/docs/en/r2.0/api_python/mindspore.html#mindspore.dtype>`_.
600
526
 
601
527
  Outputs:
602
528
  Tensor of shape :math:`(N, *)`, with the same type and shape as the `input_x`.
@@ -652,15 +578,13 @@ class Mish(PrimitiveWithInfer):
652
578
  >>> x = Tensor(np.array([[-1.0, 4.0, -8.0], [2.0, -5.0, 9.0]]), mindspore.float32)
653
579
  >>> mish = ops.Mish()
654
580
  >>> output = mish(x)
655
- >>> print(output)
656
- [[-0.3034014 3.9974129 -0.0026832]
657
- [ 1.9439590 -0.0033576 9.0000000]]
581
+ >>> print(output.shape)
582
+ (2, 3)
658
583
  """
659
584
 
660
585
  @prim_attr_register
661
586
  def __init__(self):
662
587
  """Initialize Mish"""
663
- super().__init__("Mish")
664
588
  self.init_prim_io_names(inputs=['x'], outputs=['output'])
665
589
 
666
590
 
@@ -708,7 +632,6 @@ class SeLU(Primitive):
708
632
  @prim_attr_register
709
633
  def __init__(self):
710
634
  """Initialize SeLU"""
711
- super().__init__("SeLU")
712
635
  self.init_prim_io_names(inputs=['input_x'], outputs=['output'])
713
636
 
714
637
 
@@ -808,14 +731,15 @@ class Elu(Primitive):
808
731
  alpha (float): The alpha value of ELU, the data type is float. Only support '1.0' currently. Default: 1.0.
809
732
 
810
733
  Inputs:
811
- - **input_x** (Tensor) - The input of ELU is a Tensor of any dimension with data type of float16 or float32.
734
+ - **input_x** (Tensor) - The input of ELU is a Tensor of any dimension with data type of
735
+ float16, float32 or float64.
812
736
 
813
737
  Outputs:
814
738
  Tensor, has the same shape and data type as `input_x`.
815
739
 
816
740
  Raises:
817
741
  TypeError: If `alpha` is not a float.
818
- TypeError: If dtype of `input_x` is neither float16 nor float32.
742
+ TypeError: If dtype of `input_x` is neither float16, float32 nor float64.
819
743
  ValueError: If `alpha` is not equal to 1.0.
820
744
 
821
745
  Supported Platforms:
@@ -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
 
@@ -842,7 +766,7 @@ class HSwish(Primitive):
842
766
  r"""
843
767
  Hard swish activation function.
844
768
 
845
- Refer to :func:`mindspore.ops.hardswish` for more detail.
769
+ Refer to :func:`mindspore.ops.hardswish` for more details.
846
770
 
847
771
  Supported Platforms:
848
772
  ``Ascend`` ``GPU`` ``CPU``
@@ -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``
@@ -928,7 +834,7 @@ class Tanh(Primitive):
928
834
  r"""
929
835
  Computes hyperbolic tangent of input element-wise.
930
836
 
931
- Refer to :func:`mindspore.ops.tanh` for more detail.
837
+ Refer to :func:`mindspore.ops.tanh` for more details.
932
838
 
933
839
  Supported Platforms:
934
840
  ``Ascend`` ``GPU`` ``CPU``
@@ -1048,12 +954,116 @@ 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
 
1056
962
 
963
+ class InstanceNormV2(Primitive):
964
+ r"""
965
+ Instance Normalization over a 4D or 5D input.
966
+
967
+ This operator applies Instance Normalization over a 4D or 5D input (a mini-batch of 2D inputs with
968
+ additional channel dimension) as described in the paper `Instance Normalization: The Missing Ingredient for
969
+ Fast Stylization <https://arxiv.org/abs/1607.08022>`_. It rescales and recenters the feature using a mini-batch
970
+ of data and the learned parameters which can be described in the following formula.
971
+
972
+ .. math::
973
+
974
+ y = \frac{x - mean}{\sqrt{variance + \epsilon}} * \gamma + \beta
975
+
976
+ where :math:`\gamma` is scale(gamma), :math:`\beta` is bias(beta), :math:`\epsilon` is epsilon.
977
+
978
+ Note:
979
+ The format of input `x` support ``NCHW`` and ``NC1HWC0`` in platform ``CPU`` and ``Ascend``.
980
+ When attr `is_training` is `False`, this module does not tracks the running mean and variance.
981
+ The output `batch_mean` and `batch_variance` would be all zero.
982
+
983
+ Args:
984
+ is_training(bool): An optional boolean value. Default: ``True``.
985
+ When set to ``True``, this module tracks the running mean and variance.
986
+ When set to ``False``, this module does not track such statistics and always uses batch
987
+ statistics in both training and eval modes.
988
+ momentum (float): The hyper parameter to compute moving average for running_mean and running_var
989
+ (e.g. :math:`new\_running\_mean = momentum * running\_mean + (1 - momentum) * current\_mean`).
990
+ Momentum value must be [0, 1]. Default: 0.1.
991
+ epsilon (float): A small value added to the denominator for numerical stability.
992
+ Epsilon value must be [0, 1). Default: 1e-5.
993
+
994
+ Inputs:
995
+ - **x** (Tensor) - The input of InstanceNormV2, Tensor of shape :math:`(N, C, H, W)`
996
+ or :math:`(N, C1, H, W, C0)`, data type: float16 or float32.
997
+ - **gamma** (Tensor) - Scale, Shape depends on the shape of input `x`, data type: float32.
998
+ If `x` shape is :math:`(N, C, H, W)`, shape of `gamma` is :math:`(N, C, 1, 1)`.
999
+ If `x` shape is :math:`(N, C1, H, W, C0)`, shape of `gamma` is :math:`(N, C1, 1, 1, C0)`.
1000
+ - **beta** (Tensor) - Bias, has the same shape and data type as `gamma`.
1001
+ - **mean** (Tensor) - Mean value, has the same shape and data type as `gamma`.
1002
+ - **variance** (Tensor) - Variance value, has the same shape and data type as `gamma`.
1003
+
1004
+ Outputs:
1005
+ Tuple of 3 Tensors, the normalized input, the mean and variance of batch input.
1006
+
1007
+ - **y** (Tensor) - The output of InstanceNormV2, same type and shape as the `x`.
1008
+ - **batch_mean** (Tensor) - The mean value of batch input, same type and shape as the input `mean`.
1009
+ - **batch_variance** (Tensor) - The variance value of batch input, same type and shape as the input `variance`.
1010
+
1011
+ Supported Platforms:
1012
+ ``Ascend`` ``CPU``
1013
+
1014
+ Raises:
1015
+ TypeError: If either item in the inputs is not Tensor.
1016
+ TypeError: If data type of `x` is neither float16 nor float32.
1017
+ TypeError: If data type of `gamma` is not a Tensor of float32.
1018
+ TypeError: If data type of `beta` is not a Tensor of float32.
1019
+ TypeError: If data type of `mean` is not a Tensor of float32.
1020
+ TypeError: If data type of `variance` is not a Tensor of float32.
1021
+ TypeError: If data type of attr `is_training` is not bool.
1022
+ TypeError: If data type of attr `momentum` is not float.
1023
+ TypeError: If data type of attr `epsilon` is not float.
1024
+ ValueError: If :math:`H * W <= 1` in input `x`.
1025
+ ValueError: If the shape of either item in the inputs is neither 4D nor 5D.
1026
+ ValueError: If `epsilon` is not in the range of [0, 1).
1027
+ ValueError: If `momentum` is not in the range of [0, 1].
1028
+
1029
+ Examples:
1030
+ >>> x = Tensor(input_data=np.random.randn(128, 48, 32, 64, 12), dtype=mindspore.float32)
1031
+ >>> gamma = Tensor(input_data=np.random.randn(128, 48, 1, 1, 12), dtype=mstype.float32)
1032
+ >>> beta = Tensor(input_data=np.random.randn(128, 48, 1, 1, 12), dtype=mstype.float32)
1033
+ >>> mean = Tensor(input_data=np.random.randn(128, 48, 1, 1, 12), dtype=mstype.float32)
1034
+ >>> var = Tensor(input_data=np.random.randn(128, 48, 1, 1, 12), dtype=mstype.float32)
1035
+ >>> ops = P.InstanceNormV2()
1036
+ >>> output = ops(x, gamma, beta, mean, var)
1037
+ >>> y_shape = output[0].shape
1038
+ >>> print(y_shape)
1039
+ (128, 48, 32, 64, 12)
1040
+ >>> batch_mean_shape = output[1].shape
1041
+ >>> print(batch_mean_shape)
1042
+ (128, 48, 1, 1, 12)
1043
+ >>> batch_var_shape = output[2].shape
1044
+ >>> print(batch_var_shape)
1045
+ (128, 48, 1, 1, 12)
1046
+ """
1047
+ __mindspore_signature__ = (
1048
+ sig.make_sig('x', dtype=sig.sig_dtype.T1),
1049
+ sig.make_sig('gamma', dtype=sig.sig_dtype.T),
1050
+ sig.make_sig('beta', dtype=sig.sig_dtype.T),
1051
+ sig.make_sig('mean', dtype=sig.sig_dtype.T),
1052
+ sig.make_sig('variance', dtype=sig.sig_dtype.T),
1053
+ )
1054
+
1055
+ @prim_attr_register
1056
+ def __init__(self, is_training=True, momentum=0.1, epsilon=1e-5):
1057
+ """Initialize InstanceNormV2."""
1058
+ self.init_prim_io_names(inputs=['x', 'gamma', 'beta', 'mean', 'variance'],
1059
+ outputs=['y', 'batch_mean', 'batch_variance'])
1060
+ validator.check_is_float(epsilon, 'epsilon', self.name)
1061
+ validator.check_is_float(momentum, '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)
1064
+ validator.check_bool(is_training, "is_training", self.name)
1065
+
1066
+
1057
1067
  class BNTrainingReduce(Primitive):
1058
1068
  """
1059
1069
  The BNTrainingReduce interface is deprecated, please use the :class:`mindspore.ops.BatchNorm` instead.
@@ -1092,8 +1102,8 @@ class BNTrainingUpdate(Primitive):
1092
1102
  validator.check_value_type("isRef", isRef, [bool], self.name)
1093
1103
  validator.check_value_type("epsilon", epsilon, [float], self.name)
1094
1104
  validator.check_value_type("factor", factor, [float], self.name)
1095
- self.epsilon = validator.check_float_range(epsilon, 0, 1, Rel.INC_RIGHT, 'epsilon', 'BNTrainingUpdate')
1096
- 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')
1097
1107
  self.format = validator.check_string(data_format, ['NCHW', 'NHWC'], 'format', self.name)
1098
1108
  if context.get_context("device_target") != "GPU" and self.format == "NHWC":
1099
1109
  raise ValueError(f"For '{self.name}', the 'NHWC' format is only supported in GPU target, "
@@ -1102,7 +1112,7 @@ class BNTrainingUpdate(Primitive):
1102
1112
  self.add_prim_attr('data_format', self.format)
1103
1113
 
1104
1114
 
1105
- class BatchNorm(Primitive):
1115
+ class BatchNorm(PrimitiveWithInfer):
1106
1116
  r"""
1107
1117
  Batch Normalization for input data and updated parameters.
1108
1118
 
@@ -1117,8 +1127,9 @@ class BatchNorm(Primitive):
1117
1127
 
1118
1128
  y = \frac{x - mean}{\sqrt{variance + \epsilon}} * \gamma + \beta
1119
1129
 
1120
- where :math:`\gamma` is scale, :math:`\beta` is bias, :math:`\epsilon` is epsilon, :math:`mean` is the mean of x,
1121
- :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`.
1122
1133
 
1123
1134
  .. warning::
1124
1135
  - If the operation is used for inference, and outputs "reserve_space_1" and "reserve_space_2" are available,
@@ -1132,8 +1143,8 @@ class BatchNorm(Primitive):
1132
1143
  momentum (float): The hyper parameter to compute moving average for running_mean and running_var
1133
1144
  (e.g. :math:`new\_running\_mean = (1 - momentum) * running\_mean + momentum * current\_mean`).
1134
1145
  Momentum value must be [0, 1]. Default: 0.1.
1135
- data_format (str): The optional value for data format, is 'NHWC' or 'NCHW'.
1136
- 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".
1137
1148
 
1138
1149
  Inputs:
1139
1150
  If `is_training` is False, inputs are Tensors.
@@ -1169,7 +1180,7 @@ class BatchNorm(Primitive):
1169
1180
  TypeError: If dtype of `input_x`, `scale` is neither float16 nor float32.
1170
1181
 
1171
1182
  Supported Platforms:
1172
- ``Ascend`` ``CPU`` ``GPU``
1183
+ ``Ascend`` ``GPU`` ``CPU``
1173
1184
 
1174
1185
  Examples:
1175
1186
  >>> input_x = Tensor(np.ones([2, 2]), mindspore.float32)
@@ -1200,8 +1211,8 @@ class BatchNorm(Primitive):
1200
1211
  else:
1201
1212
  self.add_prim_attr('side_effect_mem', True)
1202
1213
  validator.check_value_type('is_training', is_training, (bool,), self.name)
1203
- validator.check_float_range(epsilon, 0, 1, Rel.INC_RIGHT, 'epsilon', self.name)
1204
- 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)
1205
1216
  self.format = validator.check_string(data_format, ['NCHW', 'NHWC'], 'format', self.name)
1206
1217
  if context.get_context("device_target") != "GPU" and self.format == "NHWC":
1207
1218
  raise ValueError(f"For '{self.name}', the 'NHWC' format is only supported in GPU target, "
@@ -1211,12 +1222,112 @@ class BatchNorm(Primitive):
1211
1222
  self.init_prim_io_names(inputs=['x', 'scale', 'offset', 'mean', 'variance'],
1212
1223
  outputs=['y', 'batch_mean', 'batch_variance', 'reserve_space_1', 'reserve_space_2'])
1213
1224
 
1225
+ def infer_shape(self, input_x, scale, bias, mean, variance):
1226
+ input_x_channel = input_x[-1] if self.format == "NHWC" else input_x[1]
1227
+ validator.check_equal_int(len(scale), 1, "scale rank", 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)
1230
+ if not self.is_training:
1231
+ validator.check_equal_int(len(mean), 1, "mean rank", 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)
1234
+ return input_x, scale, scale, scale, scale
1235
+
1236
+ def infer_dtype(self, input_x, scale, bias, mean, variance):
1237
+ validator.check_tensor_dtype_valid("input_x", input_x, [mstype.float16, mstype.float32], self.name)
1238
+ args = {"scale": scale, "bias": bias, "mean": mean, "variance": variance}
1239
+ validator.check_tensors_dtypes_same_and_valid(args, [mstype.float16, mstype.float32], self.name)
1240
+ return input_x, mstype.float32, mstype.float32, mstype.float32, mstype.float32
1241
+
1214
1242
 
1215
1243
  class Conv2D(Primitive):
1216
1244
  r"""
1217
1245
  2D convolution layer.
1218
1246
 
1219
- Refer to :func:`mindspore.ops.conv2d` for more detail.
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'.
1220
1331
 
1221
1332
  Supported Platforms:
1222
1333
  ``Ascend`` ``GPU`` ``CPU``
@@ -1279,16 +1390,15 @@ class Conv2D(Primitive):
1279
1390
 
1280
1391
  class DataFormatVecPermute(Primitive):
1281
1392
  r"""
1282
- 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.
1283
1394
 
1284
1395
  Args:
1285
- src_format (str): An optional value for source data format. The format can be 'NHWC' and 'NCHW'.
1286
- Default: 'NHWC'.
1287
- dst_format (str): An optional value for destination data format. The format can be 'NHWC' and 'NCHW'.
1288
- 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'.
1289
1398
 
1290
1399
  Inputs:
1291
- - **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.
1292
1402
 
1293
1403
  Outputs:
1294
1404
  Tensor, has the same data type and shape as the `input_x`.
@@ -1297,7 +1407,7 @@ class DataFormatVecPermute(Primitive):
1297
1407
  TypeError: If `input_x` is not a Tensor.
1298
1408
  TypeError: If dtype of `input_x` is neither int32 nor int64.
1299
1409
  ValueError: If `src_format` or `dst_format` is not a str in ['NHWC', 'NCHW'].
1300
- 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)`.
1301
1411
 
1302
1412
  Supported Platforms:
1303
1413
  ``Ascend`` ``GPU`` ``CPU``
@@ -1384,8 +1494,8 @@ class DepthwiseConv2dNative(PrimitiveWithInfer):
1384
1494
  def infer_shape(self, x_shape, w_shape, b_shape=None):
1385
1495
  validator.check_equal_int(len(w_shape), 4, "weight rank", self.name)
1386
1496
  validator.check_equal_int(len(x_shape), 4, "x rank", self.name)
1387
- validator.check("x_shape[1]", x_shape[1], "w_shape[1]", w_shape[1], Rel.EQ, self.name)
1388
- 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)
1389
1499
 
1390
1500
  kernel_size_n, _, kernel_size_h, kernel_size_w = w_shape
1391
1501
  _, _, stride_h, stride_w = self.stride
@@ -1529,7 +1639,7 @@ class MaxPool(_Pool):
1529
1639
 
1530
1640
  Typically the input is of shape :math:`(N_{in}, C_{in}, H_{in}, W_{in})`, MaxPool outputs
1531
1641
  regional maximum in the :math:`(H_{in}, W_{in})`-dimension. Given kernel size
1532
- :math:`ks = (h_{ker}, w_{ker})` and stride :math:`s = (s_0, s_1)`, the operation is as follows.
1642
+ :math:`ks = (h_{ker}, w_{ker})` and stride :math:`s = (s_0, s_1)`, the operation is as follows:
1533
1643
 
1534
1644
  .. math::
1535
1645
  \text{output}(N_i, C_j, h, w) = \max_{m=0, \ldots, h_{ker}-1} \max_{n=0, \ldots, w_{ker}-1}
@@ -1683,55 +1793,11 @@ class MaxPoolV1(Primitive):
1683
1793
 
1684
1794
  class MaxPoolWithArgmax(Primitive):
1685
1795
  r"""
1686
- Performs max pooling on the input Tensor and returns both max values and indices.
1687
-
1688
- Typically the input is of shape :math:`(N_{in}, C_{in}, H_{in}, W_{in})`, MaxPool outputs
1689
- regional maximum in the :math:`(H_{in}, W_{in})`-dimension. Given kernel size
1690
- :math:`ks = (h_{ker}, w_{ker})` and stride :math:`s = (s_0, s_1)`, the operation is as follows.
1691
-
1692
- .. math::
1693
- \text{output}(N_i, C_j, h, w) = \max_{m=0, \ldots, h_{ker}-1} \max_{n=0, \ldots, w_{ker}-1}
1694
- \text{input}(N_i, C_j, s_0 \times h + m, s_1 \times w + n)
1695
-
1696
- Args:
1697
- kernel_size (Union[int, tuple[int]]): The size of kernel used to take the maximum value and argmax
1698
- value, is an int number that represents height and width of the kernel, or a tuple of
1699
- two int numbers that represent height and width respectively. Default: 1.
1700
- strides (Union[int, tuple[int]]): The distance of kernel moving, an int number that represents
1701
- not only the height of movement but also the width of movement, or a tuple of two int numbers that
1702
- represent height and width of movement respectively. Default: 1.
1703
- pad_mode (str): The optional value for pad mode, is "same" or "valid".
1704
- Default: "valid".
1705
-
1706
- - same: Adopts the way of completion. The height and width of the output will be the same as
1707
- the input. The total number of padding will be calculated in horizontal and vertical
1708
- directions and evenly distributed to top, bottom, left and right if possible.
1709
- Otherwise, the last extra padding will be done from the bottom and the right side.
1710
-
1711
- - valid: Adopts the way of discarding. The possible largest height and width of output
1712
- will be returned without padding. Extra pixels will be discarded.
1713
-
1714
- data_format (str) : The optional value for data format, is 'NHWC' or 'NCHW'.
1715
- Default: 'NCHW'.
1716
-
1717
- Inputs:
1718
- - **x** (Tensor) - Tensor of shape :math:`(N, C_{in}, H_{in}, W_{in})`.
1719
- Data type must be float16 or float32.
1720
-
1721
- Outputs:
1722
- Tuple of 2 Tensors, representing the maxpool result and where the max values are generated.
1723
-
1724
- - **output** (Tensor) - Maxpooling result, with shape :math:`(N, C_{out}, H_{out}, W_{out})`.
1725
- It has the same data type as `x`.
1726
- - **mask** (Tensor) - Max values' index represented by the mask. Data type is int32.
1727
-
1728
- Raises:
1729
- TypeError: If the data type of `x` is neither float16 nor float32.
1730
- TypeError: If `kernel_size` or `strides` is neither an int nor a tuple.
1731
- 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.
1732
1798
 
1733
1799
  Supported Platforms:
1734
- ``Ascend`` ``GPU`` ``CPU``
1800
+ Deprecated
1735
1801
 
1736
1802
  Examples:
1737
1803
  >>> x = Tensor(np.arange(1 * 3 * 3 * 4).reshape((1, 3, 3, 4)), mindspore.float32)
@@ -1746,6 +1812,7 @@ class MaxPoolWithArgmax(Primitive):
1746
1812
  [33. 34. 35.]]]]
1747
1813
  """
1748
1814
 
1815
+ @deprecated("2.0", "ops.MaxPoolWithArgmaxV2", False)
1749
1816
  @prim_attr_register
1750
1817
  def __init__(self, kernel_size=1, strides=1, pad_mode="valid", data_format="NCHW"):
1751
1818
  """Initialize MaxPoolWithArgmax."""
@@ -1770,13 +1837,13 @@ class MaxPoolWithArgmax(Primitive):
1770
1837
  self.add_prim_attr("strides", self.strides)
1771
1838
 
1772
1839
 
1773
- class MaxPool3D(PrimitiveWithInfer):
1840
+ class MaxPool3D(Primitive):
1774
1841
  r"""
1775
1842
  Applies a 3D max pooling over an input Tensor which can be regarded as a composition of 3D planes.
1776
1843
 
1777
1844
  Typically the input is of shape :math:`(N_{in}, C_{in}, D_{in}, H_{in}, W_{in})`, MaxPool outputs
1778
1845
  regional maximum in the :math:`(D_{in}, H_{in}, W_{in})`-dimension. Given kernel size
1779
- :math:`ks = (d_{ker}, h_{ker}, w_{ker})` and stride :math:`s = (s_0, s_1, s_2)`, the operation is as follows.
1846
+ :math:`ks = (d_{ker}, h_{ker}, w_{ker})` and stride :math:`s = (s_0, s_1, s_2)`, the operation is as follows:
1780
1847
 
1781
1848
  .. math::
1782
1849
  \text{output}(N_i, C_j, d, h, w) =
@@ -1815,7 +1882,7 @@ class MaxPool3D(PrimitiveWithInfer):
1815
1882
 
1816
1883
  Inputs:
1817
1884
  - **x** (Tensor) - Tensor of shape :math:`(N, C, D_{in}, H_{in}, W_{in})`.
1818
- Data type must be float16 or float32.
1885
+ Data type must be float16, float32 or float64.
1819
1886
 
1820
1887
  Outputs:
1821
1888
  Tensor, with shape :math:`(N, C, D_{out}, H_{out}, W_{out})`. Has the data type of `x`.
@@ -1882,56 +1949,16 @@ class MaxPool3D(PrimitiveWithInfer):
1882
1949
  validator.check_non_negative_int(item, 'pad_list item', self.name)
1883
1950
  self.add_prim_attr("pad_list", self.pad_list)
1884
1951
 
1885
- def infer_shape(self, x_shape):
1886
- validator.check_equal_int(len(x_shape), 5, "x rank", self.name)
1887
- batch, channel, input_d, input_h, input_w = x_shape
1888
- self.add_prim_attr("x_shape", x_shape)
1889
- _, _, kernel_d, kernel_h, kernel_w = self.kernel_size
1890
- _, _, stride_d, stride_h, stride_w = self.strides
1891
-
1892
- if self.pad_mode == "VALID":
1893
- out_d = math.ceil((input_d - (kernel_d - 1)) / stride_d)
1894
- out_h = math.ceil((input_h - (kernel_h - 1)) / stride_h)
1895
- out_w = math.ceil((input_w - (kernel_w - 1)) / stride_w)
1896
- elif self.pad_mode == "SAME":
1897
- out_d = math.ceil(input_d / stride_d)
1898
- out_h = math.ceil(input_h / stride_h)
1899
- out_w = math.ceil(input_w / stride_w)
1900
- else:
1901
- out_d = ((input_d + self.pad_list[0] + self.pad_list[1] -
1902
- (kernel_d - 1) - 1) / stride_d) + 1
1903
- out_h = ((input_h + self.pad_list[2] + self.pad_list[3] -
1904
- (kernel_h - 1) - 1) / stride_h) + 1
1905
- out_w = ((input_w + self.pad_list[4] + self.pad_list[5] -
1906
- (kernel_w - 1) - 1) / stride_w) + 1
1907
- if self.ceil_mode:
1908
- out_d = math.ceil(out_d)
1909
- out_h = math.ceil(out_h)
1910
- out_w = math.ceil(out_w)
1911
- else:
1912
- out_d = math.floor(out_d)
1913
- out_h = math.floor(out_h)
1914
- out_w = math.floor(out_w)
1915
- out_shape = [batch, channel, out_d, out_h, out_w]
1916
-
1917
- _check_shape('output', out_shape, self.name)
1918
- return out_shape
1919
-
1920
- def infer_dtype(self, x_dtype):
1921
- validator.check_tensor_dtype_valid("x", x_dtype, [mstype.float16, mstype.float32], self.name)
1922
- return x_dtype
1923
-
1924
1952
 
1925
1953
  class MaxUnpool2D(Primitive):
1926
1954
  r"""
1927
- Computes a partial inverse of MaxUnpool2D.
1928
-
1929
- MaxUnpool2D is not fully invertible, since the non-maximal values are lost.
1955
+ Calculates the partial inverse of MaxPool2D operation.
1930
1956
 
1931
- MaxUnpool2D takes in as input the output of MaxUnpool2D including the indices of the maximal values
1932
- and computes a partial inverse in which all non-maximal values are set to zero. Typically the input
1933
- is of shape :math:`(N, C, H_{in}, W_{in})`, the output is of shape :math:`(N, C, H_{out}, W_{out})`,
1934
- the operation is as follows.
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})` ,
1961
+ the output is of shape :math:`(N, C, H_{out}, W_{out})` , the operation is as follows:
1935
1962
 
1936
1963
  .. math::
1937
1964
  \begin{array}{ll} \\
@@ -1939,32 +1966,41 @@ class MaxUnpool2D(Primitive):
1939
1966
  W_{out} = (W{in} - 1) \times strides[1] - 2 \times pads[1] + ksize[1] \\
1940
1967
  \end{array}
1941
1968
 
1969
+ .. warning::
1970
+ This is an experimental API that is subject to change or deletion.
1971
+
1942
1972
  Args:
1943
1973
  ksize (Union[int, tuple[int]]): The size of kernel used to take the maximum value,
1944
1974
  is an int number that represents height and width of the kernel, or a tuple
1945
1975
  of two int numbers that represent height and width respectively.
1946
- strides (Union[int, tuple[int]]): The distance of kernel moving, an int number that represents
1947
- the height and width of movement are both strides, or a tuple of two int numbers that
1948
- represent height and width of movement respectively.
1949
- If strides is 0 or (0, 0), then strides equal to ksize. Default: 0.
1950
- pads (Union[int, tuple[int]]): The pad value to be filled. Default: 0. If `pads` is an integer,
1951
- the paddings of height and width are the same, equal to pads. If `pads` is a tuple of two
1952
- integers, the padding of height and width equal to pads[0] and pads[1] correspondingly.
1953
- output_shape (tuple[int]) : The target output size is an optional input. Default: ().
1954
- If output_shape == (), then the shape of output computed by kszie, strides and pads.
1955
- If output_shape != (), then output_shape must be :math:`(N, C, H, W)` or
1956
- :math:`(N, H, W, C)` and output_shape must belong to
1957
- :math:`[(N, C, H_{out} - strides[0], W_{out} - strides[1]),
1958
- (N, C, H_{out} + strides[0], W_{out} + strides[1])]`.
1959
- data_format (str) : The optional value for data format.
1976
+ strides (Union[int, tuple[int]], optional): The strides of kernel moving.
1977
+ If `strides` is 0 or (0, 0), then `strides` equal to `ksize` . Default: 0.
1978
+
1979
+ - An int number that represents the height and width of movement are both `strides` .
1980
+ - A tuple of two int numbers that represent height and width of movement respectively.
1981
+
1982
+ pads (Union[int, tuple[int]], optional): The pad value to be filled. Default: 0.
1983
+
1984
+ - If `pads` is an integer, the paddings of height and width are the same, equal to pads.
1985
+ - If `pads` is a tuple of two integers, the padding of height and width equal to pads[0]
1986
+ and pads[1] correspondingly.
1987
+
1988
+ output_shape (tuple[int], optional): The target output size is an optional input. Default: ().
1989
+
1990
+ - If :math:`output\_shape == ()` , then the shape of output computed by `kszie`, `strides` and `pads` .
1991
+ - If :math:`output\_shape != ()` , then `output_shape` must be :math:`(N, C, H, W)` or :math:`(N, H, W, C)`
1992
+ and `output_shape` must belong to :math:`[(N, C, H_{out} - strides[0], W_{out} - strides[1]),
1993
+ (N, C, H_{out} + strides[0], W_{out} + strides[1])]`.
1994
+
1995
+ data_format (str, optional): The optional value for data format.
1960
1996
  Currently support 'NCHW' and 'NHWC'. Default: 'NCHW'.
1961
1997
 
1962
1998
  Inputs:
1963
1999
  - **x** (Tensor) - The input Tensor to invert.
1964
2000
  Tensor of shape :math:`(N, C, H_{in}, W_{in})` or :math:`(N, H_{in}, W_{in}, C)`.
1965
- - **argmax** (Tensor) - Max values' index represented by the argmax.
1966
- Tensor of shape must be same with input 'x'.
1967
- Values of argmax must belong to :math:`[0, H_{in} \times W_{in} - 1]`.
2001
+ - **argmax** (Tensor) - Max values' index represented by the `argmax`.
2002
+ Tensor of shape must be same with input `x`.
2003
+ Values of `argmax` must belong to :math:`[0, H_{in} \times W_{in} - 1]`.
1968
2004
  Data type must be in int32 or int64.
1969
2005
 
1970
2006
  Outputs:
@@ -1980,10 +2016,10 @@ class MaxUnpool2D(Primitive):
1980
2016
  ValueError: If `data_format` is not a str or is neither `NCHW` nor `NHWC`.
1981
2017
  ValueError: If `output_shape` whose length is neither 0 or 4.
1982
2018
  ValueError: If `output_shape` is not close to output size
1983
- computed by attr `ksize, strides, pads`.
2019
+ computed by attr `ksize`, `strides` and `pads`.
1984
2020
 
1985
2021
  Supported Platforms:
1986
- ``Ascend`` ``CPU``
2022
+ ``Ascend`` ``GPU`` ``CPU``
1987
2023
 
1988
2024
  Examples:
1989
2025
  >>> x = Tensor(np.array([[[[0, 1], [8, 9]]]]).astype(np.float32))
@@ -2021,12 +2057,9 @@ class MaxUnpool2D(Primitive):
2021
2057
 
2022
2058
  class MaxUnpool3D(Primitive):
2023
2059
  r"""
2024
- Computes a partial inverse of MaxUnpool3D.
2060
+ Computes the inverse of :class:`mindspore.ops.MaxPool3D`.
2025
2061
 
2026
- MaxUnpool3D is not fully invertible, since the non-maximal values are lost.
2027
-
2028
- MaxUnpool3D takes in as input the output of MaxUnpool3D including the indices of the maximal
2029
- 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.
2030
2063
  Typically the input is of shape :math:`(N, C, D_{in}, H_{in}, W_{in})`, the output is of
2031
2064
  shape :math:`(N, C, D_{out}, H_{out}, W_{out})`, the operation is as follows.
2032
2065
 
@@ -2037,55 +2070,63 @@ class MaxUnpool3D(Primitive):
2037
2070
  W_{out} = (W{in} - 1) \times strides[2] - 2 \times pads[2] + ksize[2] \\
2038
2071
  \end{array}
2039
2072
 
2073
+ .. warning::
2074
+ This is an experimental API that is subject to change or deletion.
2075
+
2040
2076
  Args:
2041
2077
  ksize (Union[int, tuple[int]]): The size of kernel used to take the maximum value,
2042
2078
  is an int number that represents depth, height and width of the kernel, or a tuple
2043
2079
  of three int numbers that represent depth, height and width respectively.
2044
- strides (Union[int, tuple[int]]): The distance of kernel moving, an int number that represents
2045
- the depth, height and width of movement are both strides, or a tuple of three int numbers that
2046
- represent depth, height and width of movement respectively.
2047
- If strides is 0 or (0, 0, 0), then strides equal to ksize. Default: 0.
2048
- pads (Union[int, tuple[int]]): The pad value to be filled. Default: 0. If `pads` is an integer,
2049
- the paddings of depth, height and width are the same, equal to pads. If `pads` is a tuple of three integers,
2050
- the padding of depth, height and width equal to pads[0], pads[1] and pads[2] correspondingly.
2051
- output_shape (tuple[int]) : The target output size is an optional input. Default: ().
2052
- If output_shape == (), then the shape of output computed by kszie, strides and pads.
2053
- If output_shape != (), then output_shape must be :math:`(N, C, D, H, W)` or
2054
- :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
2055
2096
  :math:`[(N, C, D_{out} - strides[0], H_{out} - strides[1], W_{out} - strides[2]),
2056
2097
  (N, C, D_{out} + strides[0], H_{out} + strides[1], W_{out} + strides[2])]`.
2057
- 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'.
2058
2100
 
2059
2101
  Inputs:
2060
2102
  - **x** (Tensor) - The input Tensor to invert.
2061
2103
  Tensor of shape :math:`(N, C, D_{in}, H_{in}, W_{in})` or :math:`(N, D_{in}, H_{in}, W_{in}, C)`.
2062
- - **argmax** (Tensor) - Max values' index represented by the argmax.
2063
- Tensor of shape must be same with input 'x'.
2064
- Values of argmax must belong to :math:`[0, D_{in} \times H_{in} \times W_{in} - 1]`.
2065
- 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.
2066
2107
 
2067
2108
  Outputs:
2068
2109
  Tensor, with shape :math:`(N, C, D_{out}, H_{out}, W_{out})` or :math:`(N, D_{out}, H_{out}, W_{out}, C)`.
2069
2110
  Has the same data type with `x`.
2070
2111
 
2071
2112
  Raises:
2072
- TypeError: If data type of `x` or `argmax` is not supported.
2113
+ TypeError: If data type of `x` or `argmax` is Number.
2073
2114
  TypeError: If `ksize`, `strides` or `pads` is neither int nor tuple.
2074
- 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.
2075
2116
  ValueError: If numbers in `pads` is negative.
2076
2117
  ValueError: If `ksize`, `strides` or `pads` is a tuple whose length is not equal to 3.
2077
2118
  ValueError: If `data_format` is not a str or is neither `NCDHW` nor `NDHWC`.
2078
2119
  ValueError: If `output_shape` whose length is neither 0 or 5.
2079
- ValueError: If `output_shape` is not close to output size
2120
+ ValueError: If `output_shape` is not close to output size range
2080
2121
  computed by attr `ksize, strides, pads`.
2081
2122
 
2082
2123
  Supported Platforms:
2083
- ``Ascend`` ``CPU``
2124
+ ``Ascend`` ``GPU`` ``CPU``
2084
2125
 
2085
2126
  Examples:
2086
2127
  >>> x = Tensor(np.array([[[[[0, 1], [8, 9]]]]]).astype(np.float32))
2087
2128
  >>> argmax = Tensor(np.array([[[[[0, 1], [2, 3]]]]]).astype(np.int64))
2088
- >>> maxunpool3d = P.MaxUnpool3D(ksize=1, strides=1, pads=0)
2129
+ >>> maxunpool3d = ops.MaxUnpool3D(ksize=1, strides=1, pads=0)
2089
2130
  >>> output = maxunpool3d(x, argmax)
2090
2131
  >>> print(output.asnumpy())
2091
2132
  [[[[[0. 1.]
@@ -2115,11 +2156,11 @@ class MaxUnpool3D(Primitive):
2115
2156
  self.output_shape = output_shape
2116
2157
 
2117
2158
 
2118
- class AvgPool(_Pool):
2159
+ class AvgPool(Primitive):
2119
2160
  r"""
2120
2161
  Average pooling operation.
2121
2162
 
2122
- Refer to :func:`mindspore.ops.avg_pool2d` for more detail.
2163
+ Refer to :func:`mindspore.ops.avg_pool2d` for more details.
2123
2164
 
2124
2165
  Args:
2125
2166
  kernel_size (Union[int, tuple[int]]): The size of kernel used to take the average value,
@@ -2180,7 +2221,23 @@ class AvgPool(_Pool):
2180
2221
  @prim_attr_register
2181
2222
  def __init__(self, kernel_size=1, strides=1, pad_mode="valid", data_format="NCHW"):
2182
2223
  """Initialize AvgPool."""
2183
- 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)
2184
2241
 
2185
2242
 
2186
2243
  class AvgPoolV1(Primitive):
@@ -2362,6 +2419,22 @@ class MaxPool3DWithArgmax(Primitive):
2362
2419
  \max_{l=0, \ldots, d_{ker}-1} \max_{m=0, \ldots, h_{ker}-1} \max_{n=0, \ldots, w_{ker}-1}
2363
2420
  \text{input}(N_i, C_j, s_0 \times d + l, s_1 \times h + m, s_2 \times w + n)
2364
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
+
2365
2438
  Args:
2366
2439
  ksize (Union[int, tuple[int]]): The size of kernel used to take the maximum value and arg
2367
2440
  value, is an int number that represents depth, height and width of the kernel, or a tuple of
@@ -2397,7 +2470,7 @@ class MaxPool3DWithArgmax(Primitive):
2397
2470
  ValueError: If `argmax_type` is not mindspore.int64 or mindspore.int32.
2398
2471
 
2399
2472
  Supported Platforms:
2400
- ``GPU``
2473
+ ``Ascend`` ``GPU`` ``CPU``
2401
2474
 
2402
2475
  Examples:
2403
2476
  >>> x = Tensor(np.arange(2 * 1 * 2 * 2 * 2).reshape((2, 1, 2, 2, 2)), mindspore.float32)
@@ -2441,13 +2514,15 @@ class MaxPool3DWithArgmax(Primitive):
2441
2514
 
2442
2515
  class Conv2DTranspose(Conv2DBackpropInput):
2443
2516
  """
2444
- Compute a 2D transposed convolution, which is also known as a deconvolution
2445
- (although it is not an actual deconvolution).
2517
+ Calculates a 2D transposed convolution, which can be regarded as Conv2d for the gradient of the input,
2518
+ also called deconvolution, although it is not an actual deconvolution. Because it cannot restore
2519
+ the original input data completely, but it can restore the shape of the original input.
2446
2520
 
2447
2521
  Args:
2448
2522
  out_channel (int): The dimensionality of the output space.
2449
2523
  kernel_size (Union[int, tuple[int]]): The size of the convolution window.
2450
2524
  pad_mode (str): Modes to fill padding. It could be "valid", "same", or "pad". Default: "valid".
2525
+ Please refer to :class:`mindspore.nn.Conv2dTranspose` for more specifications about `pad_mode`.
2451
2526
  pad (Union[int, tuple[int]]): The pad value to be filled. Default: 0. If `pad` is an integer, the paddings of
2452
2527
  top, bottom, left and right are the same, equal to pad. If `pad` is a tuple of four integers, the
2453
2528
  padding of top, bottom, left and right equal to pad[0], pad[1], pad[2], and pad[3] correspondingly.
@@ -2457,8 +2532,8 @@ class Conv2DTranspose(Conv2DBackpropInput):
2457
2532
  dilation (Union[int, tuple[int]]): Specifies the dilation rate to be used for the dilated convolution.
2458
2533
  Default: 1.
2459
2534
  group (int): Splits input into groups. Default: 1.
2460
- data_format (str): The format of input and output data. It should be 'NHWC' or 'NCHW',\
2461
- default is 'NCHW'.
2535
+ data_format (str): The format of input and output data. It should be 'NHWC' or 'NCHW'.
2536
+ Default is 'NCHW'.
2462
2537
 
2463
2538
  Inputs:
2464
2539
  - **dout** (Tensor) - the gradients with respect to the output of the convolution.
@@ -2512,9 +2587,8 @@ class BiasAdd(Primitive):
2512
2587
 
2513
2588
  Inputs:
2514
2589
  - **input_x** (Tensor) - The input tensor. The shape can be 2-5 dimensions.
2515
- The data type should be float16 or float32.
2516
2590
  - **bias** (Tensor) - The bias tensor, with shape :math:`(C)`. C must be the same as channel dimension C of
2517
- `input_x`. The data type should be float16 or float32.
2591
+ `input_x`.
2518
2592
 
2519
2593
  Outputs:
2520
2594
  Tensor, with the same shape and data type as `input_x`.
@@ -2544,10 +2618,6 @@ class BiasAdd(Primitive):
2544
2618
  """Initialize BiasAdd."""
2545
2619
  self.init_prim_io_names(inputs=['x', 'b'], outputs=['output'])
2546
2620
  self.format = validator.check_string(data_format, ['NCHW', 'NHWC', 'NCDHW'], 'format', self.name)
2547
- if context.get_context("device_target") != "GPU" and self.format == "NHWC":
2548
- raise ValueError(f"For '{self.name}', the 'NHWC' format is only supported in GPU target, "
2549
- f"but got the 'data_format' is {self.format} and "
2550
- f"the platform is {context.get_context('device_target')}.")
2551
2621
  self.add_prim_attr('data_format', self.format)
2552
2622
 
2553
2623
 
@@ -2580,7 +2650,8 @@ class NLLLoss(Primitive):
2580
2650
 
2581
2651
  Inputs:
2582
2652
  - **logits** (Tensor) - Input logits, with shape :math:`(N, C)`. Data type only supports float32 or float16.
2583
- - **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.
2584
2655
  - **weight** (Tensor) - The rescaling weight to each class, with shape :math:`(C,)` and data type only
2585
2656
  supports float32 or float16.
2586
2657
 
@@ -2592,13 +2663,15 @@ class NLLLoss(Primitive):
2592
2663
  - **total_weight** (Tensor) - The `total_weight` is a scalar. The data type is the same with `weight's`.
2593
2664
 
2594
2665
  Raises:
2595
- 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.
2596
2668
  ValueError: If `logits` is not a one or two dimension tensor, `labels` and `weight` are not
2597
2669
  one dimension tensors.
2598
2670
  When `logits` is a two dimension tensor, the first dimension of `logits` is not equal to `labels`,
2599
2671
  and second dimension of `logits` is not equal to `weight`.
2600
2672
  When `logits` is a one dimension tensor, the dimensions of `logits`, `labels`
2601
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.
2602
2675
 
2603
2676
  Supported Platforms:
2604
2677
  ``Ascend`` ``GPU`` ``CPU``
@@ -2673,7 +2746,7 @@ class SoftmaxCrossEntropyWithLogits(Primitive):
2673
2746
  pass
2674
2747
 
2675
2748
 
2676
- class SparseSoftmaxCrossEntropyWithLogits(PrimitiveWithInfer):
2749
+ class SparseSoftmaxCrossEntropyWithLogits(Primitive):
2677
2750
  r"""
2678
2751
  Computes the softmax cross-entropy value between logits and sparse encoding labels.
2679
2752
 
@@ -2702,7 +2775,7 @@ class SparseSoftmaxCrossEntropyWithLogits(PrimitiveWithInfer):
2702
2775
  TypeError: If `is_grad` is not a bool.
2703
2776
  TypeError: If dtype of `logits` is neither float16 nor float32.
2704
2777
  TypeError: If dtype of `labels` is neither int32 nor int64.
2705
- ValueError: If logits.shape[0] != labels.shape[0].
2778
+ ValueError: If :math:`logits.shape[0] != labels.shape[0]`.
2706
2779
 
2707
2780
  Supported Platforms:
2708
2781
  ``GPU`` ``CPU``
@@ -2729,21 +2802,6 @@ class SparseSoftmaxCrossEntropyWithLogits(PrimitiveWithInfer):
2729
2802
  self.is_grad = is_grad
2730
2803
  self.add_prim_attr('sens', 1.0)
2731
2804
 
2732
- def infer_shape(self, logits_shape, labels_shape):
2733
- validator.check_non_negative_int_sequence(logits_shape, 'dims')
2734
- validator.check_non_negative_int_sequence(labels_shape, 'dims')
2735
- validator.check("logits_shape[0]", logits_shape[0], "labels_shape[0]", labels_shape[0], Rel.EQ, self.name)
2736
- loss_shape = []
2737
- if self.is_grad:
2738
- return logits_shape
2739
- return loss_shape
2740
-
2741
- def infer_dtype(self, logits_type, labels_type):
2742
- validator.check_tensor_dtype_valid("logits", logits_type, (mstype.float16, mstype.float32),
2743
- self.name)
2744
- validator.check_tensor_dtype_valid("labels", labels_type, (mstype.int32, mstype.int64), self.name)
2745
- return logits_type
2746
-
2747
2805
 
2748
2806
  class SparseSoftmaxCrossEntropyWithLogitsV2(Primitive):
2749
2807
  r"""
@@ -2813,14 +2871,19 @@ class ApplyMomentum(Primitive):
2813
2871
  gradient_scale (float): The scale of the gradient. Default: 1.0.
2814
2872
 
2815
2873
  Inputs:
2816
- - **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.
2817
2876
  - **accumulation** (Parameter) - Accumulated gradient value by moment weight,
2818
2877
  has the same data type with `variable`.
2819
- - **learning_rate** (Union[Number, Tensor]) - The learning rate value, must be a float number or
2820
- 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.
2821
2882
  - **gradient** (Tensor) - Gradient, has the same data type as `variable`.
2822
- - **momentum** (Union[Number, Tensor]) - Momentum, must be a float number or
2823
- 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.
2824
2887
 
2825
2888
  Outputs:
2826
2889
  Tensor, parameters to be updated.
@@ -2874,7 +2937,9 @@ class ApplyMomentum(Primitive):
2874
2937
 
2875
2938
  class SmoothL1Loss(Primitive):
2876
2939
  r"""
2877
- Refer to :func:`mindspore.ops.smooth_l1_loss` for more detail.
2940
+ Calculate the smooth L1 loss, and the L1 loss function has robustness.
2941
+
2942
+ Refer to :func:`mindspore.ops.smooth_l1_loss` for more details.
2878
2943
 
2879
2944
  Supported Platforms:
2880
2945
  ``Ascend`` ``GPU`` ``CPU``
@@ -2892,62 +2957,47 @@ class SmoothL1Loss(Primitive):
2892
2957
  def __init__(self, beta=1.0, reduction='none'):
2893
2958
  """Initialize SmoothL1Loss."""
2894
2959
  validator.check_value_type('beta', beta, [float], self.name)
2895
- validator.check('beta', beta, '', 0, Rel.GT, self.name)
2960
+ validator.check('beta', beta, '', 0, validator.GT, self.name)
2896
2961
  validator.check_string(
2897
2962
  reduction, ['none', 'sum', 'mean'], 'reduction', self.name)
2963
+ self.add_prim_attr('sigma', self.beta)
2898
2964
  self.init_prim_io_names(inputs=['prediction', 'target'], outputs=['output'])
2899
2965
 
2900
2966
 
2901
2967
  class MultiMarginLoss(Primitive):
2902
2968
  r"""
2903
- Creates a criterion that optimizes a multi-class classification hinge
2904
- loss (margin-based loss) between input :math:`x` (a 2D mini-batch `Tensor`) and
2905
- output :math:`y` (which is a 1D tensor of target class indices,
2906
- :math:`0 \leq y \leq \text{x.size}(1)-1`):
2907
-
2908
- For each mini-batch sample, the loss in terms of the 1D input :math:`x` and scalar
2909
- output :math:`y` is:
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.
2910
2972
 
2911
- .. math::
2912
- \text{loss}(x, y) = \frac{\sum_i \max(0, w[y] * (\text{margin} - x[y] + x[i]))^p)}{\text{x.size}(0)}
2913
-
2914
- where :math:`x \in \left\{0, \; \cdots , \; \text{x.size}(0) - 1\right\}`
2915
- and :math:`i \neq y`.
2973
+ .. warning::
2974
+ This is an experimental API that is subject to change or deletion.
2916
2975
 
2917
- Optionally, you can give non-equal weighting on the classes by passing
2918
- a 1D input `weight` tensor w into the constructor.
2976
+ Refer to :func:`mindspore.ops.multi_margin_loss` for more details.
2919
2977
 
2920
2978
  Args:
2921
- p (int): Optional. The norm degree for pairwise distance. Should be 1 or 2. Default: 1.
2922
- margin (float): Optional. A parameter to change pairwise distance. Default: 1.0.
2923
- reduction (str): Apply specific reduction method to the output: 'none', 'mean', 'sum'. Default: "mean".
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.
2924
2987
 
2925
2988
  Inputs:
2926
- - **x** (Tensor) - Input x, with shape :math:`(N, C)`. Data type only support float32, float16 or float64.
2989
+ - **inputs** (Tensor) - Input , with shape :math:`(N, C)`. Data type only support float32, float16 or float64.
2927
2990
  - **target** (Tensor) - Ground truth labels, with shape :math:`(N,)`. Data type only support int64. The
2928
2991
  value of target should be non-negative, less than C.
2929
- - **weight** (Tensor, optional) - The rescaling weight to each class with shape :math:`(C,)`. Data type only
2930
- support float32, float16 or float64. Default: None.
2992
+ - **weight** (Tensor) - The rescaling weight to each class with shape :math:`(C,)`. Data type only
2993
+ support float16, float32 or float64.
2931
2994
 
2932
2995
  Outputs:
2933
2996
  Tensor, When `reduction` is 'none', the shape is :math:`(N,)`.
2934
- Otherwise, it is a scalar. Has the same data type with `x`.
2935
-
2936
- Raises:
2937
- TypeError: If dtype of `p` or `target` is not int.
2938
- TypeError: If dtype of `margin` is not float.
2939
- TypeError: If dtype of `reduction` is not str.
2940
- TypeError: If dtype of `x` is not float16, float or float64.
2941
- TypeError: If dtype of `weight` and `x` is not the same.
2942
- ValueError: If 'p' is not 1 or 2.
2943
- ValueError: If 'reduction' is not one of {'none','sum','mean'}.
2944
- ValueError: If shape[0] of `x` is not equal to shape[0] of `target`.
2945
- ValueError: If shape[1] of `x` is not equal to shape[0] of `weight`.
2946
- ValueError: IF rank of `weight` is not 1.
2947
- ValueError: If rank of `x` is not 2 or rank of 'target' is not 1.
2997
+ Otherwise, it is a scalar. Has the same data type with `inputs`.
2948
2998
 
2949
2999
  Supported Platforms:
2950
- ``Ascend`` ``CPU``
3000
+ ``Ascend`` ``GPU`` ``CPU``
2951
3001
 
2952
3002
  Examples:
2953
3003
  >>> x = Tensor(np.ones(shape=[3, 3]), mindspore.float32)
@@ -2963,7 +3013,7 @@ class MultiMarginLoss(Primitive):
2963
3013
  def __init__(self, p=1, margin=1.0, reduction="mean"):
2964
3014
  """Initialize MultiMarginLoss"""
2965
3015
  self.p = validator.check_value_type('p', p, [int], self.name)
2966
- validator.check_int(p, {1, 2}, Rel.IN, 'p', self.name)
3016
+ validator.check_int(p, {1, 2}, validator.IN, 'p', self.name)
2967
3017
  self.margin = validator.check_value_type('margin', margin, [float], self.name)
2968
3018
  self.reduction = validator.check_string(reduction, ['none', 'sum', 'mean'], 'reduction', self.name)
2969
3019
  self.init_prim_io_names(inputs=['x', 'target', 'weight'], outputs=['y'])
@@ -3000,7 +3050,7 @@ class SoftMarginLoss(Primitive):
3000
3050
  ValueError: If `reduction` is not one of 'none', 'mean' or 'sum'.
3001
3051
 
3002
3052
  Supported Platforms:
3003
- ``Ascend``
3053
+ ``Ascend`` ``GPU``
3004
3054
 
3005
3055
  Examples:
3006
3056
  >>> loss = ops.SoftMarginLoss()
@@ -3147,10 +3197,13 @@ class RNNTLoss(PrimitiveWithInfer):
3147
3197
  validator.check_equal_int(len(labels_shape), 2, 'labels_rank', self.name)
3148
3198
  validator.check_equal_int(len(input_length_shape), 1, 'input_length_rank', self.name)
3149
3199
  validator.check_equal_int(len(label_length_shape), 1, 'label_length_rank', self.name)
3150
- validator.check('labels shape[0]', labels_shape[0], 'acts shape[0]', acts_shape[0], Rel.EQ, self.name)
3151
- validator.check('labels shape[1]', labels_shape[1], 'acts shape[2]-1', acts_shape[2] - 1, Rel.EQ, self.name)
3152
- validator.check('input_length size', input_length_shape[0], 'acts shape[0]', acts_shape[0], Rel.EQ, self.name)
3153
- 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)
3154
3207
  costs_shape = (acts_shape[0],)
3155
3208
  return costs_shape, acts_shape
3156
3209
 
@@ -3231,13 +3284,10 @@ class SGD(PrimitiveWithCheck):
3231
3284
 
3232
3285
  def check_shape(self, parameters_shape, gradient_shape, learning_rate_shape,
3233
3286
  accum_shape, momentum_shape, stat_shape):
3234
- validator.check_positive_int(len(parameters_shape), "parameters rank", self.name)
3235
- validator.check_int(len(gradient_shape), 0, Rel.GE, f'gradient rank', self.name)
3236
- validator.check_int(len(learning_rate_shape), 0, Rel.GE, f'learning rate rank', self.name)
3237
- validator.check_positive_int(len(accum_shape), "accumulation rank", self.name)
3238
- validator.check_int(len(momentum_shape), 0, Rel.GE, f'momentum rank', self.name)
3239
- validator.check_int(len(stat_shape), 0, Rel.GE, f'stat rank', self.name)
3240
- 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)
3241
3291
 
3242
3292
  def check_dtype(self, parameters_dtype, gradient_dtype, learning_rate_dtype,
3243
3293
  accum_dtype, momentum_dtype, stat_dtype):
@@ -3278,7 +3328,7 @@ class ApplyRMSProp(PrimitiveWithInfer):
3278
3328
  from being updated. Default: False.
3279
3329
 
3280
3330
  Inputs:
3281
- - **var** (Tensor) - Weights to be updated.
3331
+ - **var** (Parameter) - Weights to be updated.
3282
3332
  - **mean_square** (Tensor) - Mean square gradients, must be the same type as `var`.
3283
3333
  - **moment** (Tensor) - Delta of `var`, must be the same type as `var`.
3284
3334
  - **learning_rate** (Union[Number, Tensor]) - Learning rate. Must be a float number or
@@ -3372,7 +3422,7 @@ class ApplyCenteredRMSProp(Primitive):
3372
3422
  from being updated. Default: False.
3373
3423
 
3374
3424
  Inputs:
3375
- - **var** (Tensor) - Weights to be updated.
3425
+ - **var** (Parameter) - Weights to be updated.
3376
3426
  - **mean_gradient** (Tensor) - Mean gradients, must be the same type as `var`.
3377
3427
  - **mean_square** (Tensor) - Mean square gradients, must be the same type as `var`.
3378
3428
  - **moment** (Tensor) - Delta of `var`, must be the same type as `var`.
@@ -3449,9 +3499,9 @@ class LayerNorm(Primitive):
3449
3499
  - **input_x** (Tensor) - Tensor of shape :math:`(N, \ldots)`.
3450
3500
  The input of LayerNorm.
3451
3501
  - **gamma** (Tensor) - Tensor of shape :math:`(P_0, \ldots, P_\text{begin_params_axis})`.
3452
- The learnable parameter `gamma` as the scale on norm.
3502
+ The learnable parameter :math:`\gamma` as the scale on norm.
3453
3503
  - **beta** (Tensor) - Tensor of shape :math:`(P_0, \ldots, P_\text{begin_params_axis})`.
3454
- The learnable parameter `beta` as the scale on norm.
3504
+ The learnable parameter :math:`\beta` as the scale on norm.
3455
3505
 
3456
3506
  Outputs:
3457
3507
  tuple[Tensor], tuple of 3 tensors, the normalized input and the updated parameters.
@@ -3506,13 +3556,17 @@ class L2Normalize(Primitive):
3506
3556
  where :math:`\epsilon` is epsilon and :math:`\sum_{i}^{}\left | x_i \right | ^2` calculate the sum of squares of
3507
3557
  the input `x` along the dimension `axis`.
3508
3558
 
3559
+ Note:
3560
+ On Ascend, input data type of float64 is currently not supported.
3561
+
3509
3562
  Args:
3510
3563
  axis (Union[list(int), tuple(int), int]): Specify the axis for calculating the L2 norm. Default: 0.
3511
3564
  epsilon (float): A small value added for numerical stability. Default: 1e-4.
3512
3565
 
3513
3566
  Inputs:
3514
- - **x** (Tensor) - Input to compute the normalization. Tensor of shape :math:`(N, \ldots)`.
3515
- 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.
3516
3570
 
3517
3571
  Outputs:
3518
3572
  Tensor, with the same type and shape as the `x`.
@@ -3521,7 +3575,7 @@ class L2Normalize(Primitive):
3521
3575
  TypeError: If `axis` is not one of the following: list, tuple or int.
3522
3576
  TypeError: If `epsilon` is not a float.
3523
3577
  TypeError: If `x` is not a Tensor.
3524
- TypeError: If dtype of `x` is neither float16 nor float32.
3578
+ TypeError: If dtype of `x` is not in [float16, float32, float64].
3525
3579
  ValueError: If dimension of `x` is not greater than 0.
3526
3580
 
3527
3581
  Supported Platforms:
@@ -3583,57 +3637,14 @@ class DropoutDoMask(Primitive):
3583
3637
 
3584
3638
  class ResizeBilinear(PrimitiveWithInfer):
3585
3639
  r"""
3586
- Resizes an image to a certain size using the bilinear interpolation.
3587
-
3588
- The resizing only affects the lower two dimensions which represent the height and width. The input images
3589
- can be represented by different data types, but the data types of output images are always float32.
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.
3590
3642
 
3591
- For general resize, refer to :func:`mindspore.ops.interpolate` for more detail.
3592
-
3593
- .. warning::
3594
- This interface does not support dynamic shape and is subject to change or deletion,
3595
- use :func:`mindspore.ops.interpolate` instead.
3596
-
3597
- Args:
3598
- size (Union[tuple[int], list[int]]): A tuple or list of 2 int elements :math:`(new\_height, new\_width)`,
3599
- the new size of the images.
3600
- align_corners (bool): If true, rescale input by :math:`(new\_height - 1) / (height - 1)`,
3601
- which exactly aligns the 4 corners of images and resized images. If false,
3602
- rescale by :math:`new\_height / height`. Default: False.
3603
- half_pixel_centers (bool): Whether half pixel center. If set to True, `align_corners` should be False.
3604
- Default: False.
3605
-
3606
- Inputs:
3607
- - **x** (Tensor) - Image to be resized. Input images must be a 4-D tensor with shape
3608
- :math:`(batch, channels, height, width)`, with data type of float32 or float16.
3609
-
3610
- Outputs:
3611
- Tensor, resized image. 4-D with shape :math:`(batch, channels, new\_height, new\_width)`,
3612
- with the same data type as input `x`.
3613
-
3614
- Raises:
3615
- TypeError: If `size` is neither a tuple nor list.
3616
- TypeError: If `align_corners` is not a bool.
3617
- TypeError: If `half_pixel_centers` is not a bool.
3618
- TypeError: If `align_corners` and `half_pixel_centers` are all True.
3619
- TypeError: If `half_pixel_centers` is True and device_target not Ascend.
3620
- TypeError: If dtype of `x` is neither float16 nor float32.
3621
- TypeError: If `x` is not a Tensor.
3622
- ValueError: If length of shape of `x` is not equal to 4.
3643
+ Note:
3644
+ Dynamic shape feature is not supported for now.
3623
3645
 
3624
3646
  Supported Platforms:
3625
- ``Ascend`` ``CPU`` ``GPU``
3626
-
3627
- Examples:
3628
- >>> x = Tensor([[[[1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]]], mindspore.float32)
3629
- >>> resize_bilinear = ops.ResizeBilinear((5, 5))
3630
- >>> output = resize_bilinear(x)
3631
- >>> print(output)
3632
- [[[[1. 2. 3. 4. 5.]
3633
- [1. 2. 3. 4. 5.]
3634
- [1. 2. 3. 4. 5.]
3635
- [1. 2. 3. 4. 5.]
3636
- [1. 2. 3. 4. 5.]]]]
3647
+ ``Ascend`` ``GPU`` ``CPU``
3637
3648
  """
3638
3649
 
3639
3650
  @prim_attr_register
@@ -3649,15 +3660,11 @@ class ResizeBilinear(PrimitiveWithInfer):
3649
3660
  half_pixel_centers, [bool], self.name)
3650
3661
  if half_pixel_centers and align_corners:
3651
3662
  raise ValueError(f"If half_pixel_centers is True, align_corners must be False, but got {align_corners}")
3652
- target = context.get_context("device_target")
3653
- if half_pixel_centers and target.lower() != "ascend":
3654
- raise ValueError(f"Currently `half_pixel_centers`=True only support in Ascend device_target, "
3655
- f"but got {target}")
3656
3663
  for i, value in enumerate(size):
3657
3664
  validator.check_positive_int(value, f'{i}th value of size', self.name)
3658
3665
 
3659
3666
  def infer_shape(self, input_shape):
3660
- 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)
3661
3668
  input_shape = list(input_shape)
3662
3669
  batch, channel, _, _ = input_shape
3663
3670
  out_shape = [batch, channel]
@@ -3673,7 +3680,7 @@ class ResizeBilinear(PrimitiveWithInfer):
3673
3680
 
3674
3681
  class UpsampleTrilinear3D(Primitive):
3675
3682
  r"""
3676
- Performs upsampling with trilinear interpolation across 3dims for 5dim inputs.
3683
+ Performs upsampling with trilinear interpolation across 3dims for 5dim input Tensor.
3677
3684
 
3678
3685
  This operator scale up the volumetric input with specified `output_size` or `scales` factors,
3679
3686
  using trilinear upscaling algorithm.
@@ -3682,15 +3689,15 @@ class UpsampleTrilinear3D(Primitive):
3682
3689
  One of `scales` and `output_size` MUST be specified and it is an error if both are specified.
3683
3690
 
3684
3691
  Args:
3685
- output_size (Union[tuple[int], list[int]]): A tuple or list of 3 int
3692
+ output_size (Union[tuple[int], list[int]], optional): A tuple or list of 3 int
3686
3693
  elements :math:`(output\_depth, output\_height, output\_width)`.
3687
3694
  Defaults to None. Only one of `scales` and `output_size` can be specified.
3688
- scales (Union[tuple[float], list[float]]): A tuple or list of 3 float
3695
+ scales (Union[tuple[float], list[float]], optional): A tuple or list of 3 float
3689
3696
  elements :math:`(scale\_depth, scale\_height, scale\_width)`. Defaults to None.
3690
- align_corners (bool): An optional bool. Defaults to false.
3691
- If true, the input and output tensors are aligned by the center points of their corner pixels,
3697
+ align_corners (bool, optional): An optional bool. Defaults to false.
3698
+ If True, the input and output tensors are aligned by the center points of their corner pixels,
3692
3699
  preserving the values at the corner pixels.
3693
- If false, the input and output tensors are aligned by the corner points of their corner pixels,
3700
+ If False, the input and output tensors are aligned by the corner points of their corner pixels,
3694
3701
  and the interpolation use edge value padding for out of boundary values.
3695
3702
 
3696
3703
  Inputs:
@@ -3702,8 +3709,8 @@ class UpsampleTrilinear3D(Primitive):
3702
3709
  Tensor of shape :math:`(N, C, D_{out}, H_{out}, W_{out})`.
3703
3710
 
3704
3711
  Raises:
3705
- TypeError: When `output_size` is not none and `output_size` is not list[int] or tuple[int].
3706
- TypeError: When `scales` is not none and `scales` is not list[float] or tuple[float].
3712
+ TypeError: When `output_size` is not None and `output_size` is not list[int] or tuple[int].
3713
+ TypeError: When `scales` is not None and `scales` is not list[float] or tuple[float].
3707
3714
  TypeError: If dtype of `x` is not in [float16, float32, float64].
3708
3715
  TypeError: If type of `align_corners` is not bool.
3709
3716
  ValueError: If any value of `output_size` is negative or zero when `output_size` is not empty.
@@ -3714,22 +3721,24 @@ class UpsampleTrilinear3D(Primitive):
3714
3721
  ValueError: If size of `output_size` is not equal 3 when `output_size` is specified.
3715
3722
 
3716
3723
  Supported Platforms:
3717
- ``Ascend`` ``CPU`` ``GPU``
3724
+
3718
3725
 
3719
3726
  Examples:
3720
- >>> ops = ops.UpsampleTrilinear3D(output_size=[4, 64, 48])
3721
- >>> 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)
3722
3730
  >>> print(out.shape)
3723
3731
  (2, 3, 4, 64, 48)
3724
- ...
3725
- >>> ops = ops.UpsampleTrilinear3D(output_size=[2, 4, 4])
3732
+ >>>
3733
+ >>> net = ops.UpsampleTrilinear3D(output_size=[2, 4, 4])
3726
3734
  >>> in_x = Tensor(np.arange(1, 5, dtype=np.float32).reshape((1, 1, 1, 2, 2)))
3727
- >>> out = ops(in_x)
3735
+ >>> out = net(in_x)
3728
3736
  >>> print(out)
3729
3737
  [[[[[1. 1.25 1.75 2. ]
3730
3738
  [1.5 1.75 2.25 2.5 ]
3731
3739
  [2.5 2.75 3.25 3.5 ]
3732
3740
  [3. 3.25 3.75 4. ]]
3741
+
3733
3742
  [[1. 1.25 1.75 2. ]
3734
3743
  [1.5 1.75 2.25 2.5 ]
3735
3744
  [2.5 2.75 3.25 3.5 ]
@@ -3900,7 +3909,7 @@ class FastGeLU(Primitive):
3900
3909
  r"""
3901
3910
  Fast Gaussian Error Linear Units activation function.
3902
3911
 
3903
- Refer to :func:`mindspore.ops.fast_gelu` for more detail.
3912
+ Refer to :func:`mindspore.ops.fast_gelu` for more details.
3904
3913
 
3905
3914
  Supported Platforms:
3906
3915
  ``Ascend`` ``GPU`` ``CPU``
@@ -3970,7 +3979,7 @@ class GetNext(Primitive):
3970
3979
  """Initialize GetNext."""
3971
3980
  validator.check_value_type("types", types, [list, tuple], self.name)
3972
3981
  validator.check_value_type("shapes", shapes, [list, tuple], self.name)
3973
- 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)
3974
3983
  validator.check_value_type("output_num", output_num, [int], self.name)
3975
3984
 
3976
3985
 
@@ -3981,7 +3990,7 @@ class PReLU(PrimitiveWithInfer):
3981
3990
  Refer to :func:`mindspore.ops.prelu` for more details.
3982
3991
 
3983
3992
  Supported Platforms:
3984
- ``Ascend`` ``GPU``
3993
+ ``Ascend`` ``GPU`` ``CPU``
3985
3994
 
3986
3995
  Examples:
3987
3996
  >>> class Net(nn.Cell):
@@ -4010,11 +4019,11 @@ class PReLU(PrimitiveWithInfer):
4010
4019
  self.init_prim_io_names(inputs=['x', 'weight'], outputs=['output'])
4011
4020
 
4012
4021
 
4013
- class LSTM(PrimitiveWithInfer):
4014
- """
4022
+ class LSTM(Primitive):
4023
+ r"""
4015
4024
  Performs the Long Short-Term Memory (LSTM) on the input.
4016
4025
 
4017
- For detailed information, please refer to :class:`mindspore.nn.LSTM`.
4026
+ For detailsed information, please refer to :class:`mindspore.nn.LSTM`.
4018
4027
 
4019
4028
  Args:
4020
4029
  input_size (int): Number of features of input.
@@ -4026,20 +4035,20 @@ class LSTM(PrimitiveWithInfer):
4026
4035
  LSTM layer except the last layer. The range of dropout is [0.0, 1.0].
4027
4036
 
4028
4037
  Inputs:
4029
- - **input** (Tensor) - Tensor of shape (seq_len, batch_size, `input_size`) or
4030
- (batch_size, seq_len, `input_size`).
4031
- - **h** (tuple) - Tensor of shape (num_directions * `num_layers`, batch_size, `hidden_size`).
4032
- - **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)`.
4033
4042
  - **w** (Tensor) - A weight Tensor.
4034
4043
 
4035
4044
  Outputs:
4036
4045
  Tuple, a tuple contains (`output`, `h_n`, `c_n`, `reserve`, `state`).
4037
4046
 
4038
- - **output** (Tensor) - Tensor of shape (seq_len, batch_size, num_directions * `hidden_size`).
4039
- - **h_n** (Tensor) - Tensor of shape (num_directions * `num_layers`, batch_size, `hidden_size`).
4040
- - **c_n** (Tensor) - Tensor of shape (num_directions * `num_layers`, batch_size, `hidden_size`).
4041
- - **reserve** (Tensor) - Tensor of shape (r, 1).
4042
- - **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)`.
4043
4052
 
4044
4053
  Raises:
4045
4054
  TypeError: If `input_size`, `hidden_size` or `num_layers` is not an int.
@@ -4085,37 +4094,13 @@ class LSTM(PrimitiveWithInfer):
4085
4094
  self.has_bias = validator.check_value_type("has_bias", has_bias, (bool,), self.name)
4086
4095
  self.bidirectional = validator.check_value_type("bidirectional", bidirectional, (bool,), self.name)
4087
4096
  self.dropout = validator.check_value_type("dropout", dropout, [float], self.name)
4088
- 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)
4089
4098
 
4090
4099
  if bidirectional:
4091
4100
  self.num_directions = 2
4092
4101
  else:
4093
4102
  self.num_directions = 1
4094
4103
 
4095
- def infer_shape(self, x_shape, h_shape, c_shape, w_shape):
4096
- validator.check_equal_int(len(x_shape), 3, "x rank", self.name)
4097
- validator.check_equal_int(x_shape[2], self.input_size, "x[2]", self.name)
4098
-
4099
- # h and c should be same shape
4100
- validator.check_equal_int(len(h_shape), 3, "h rank", self.name)
4101
- validator.check("h_shape", h_shape, "c_shape", c_shape, Rel.EQ, self.name)
4102
-
4103
- validator.check_int(h_shape[0], self.num_layers * self.num_directions, Rel.EQ, "h[0]", self.name)
4104
- validator.check_equal_int(h_shape[1], x_shape[1], "h[1]", self.name)
4105
- validator.check_int(h_shape[2], self.hidden_size, Rel.EQ, "h[2]", self.name)
4106
-
4107
- y_shape = (x_shape[0], x_shape[1], self.hidden_size * self.num_directions)
4108
-
4109
- # set arbitrary shape for reserved space
4110
- reserved_shape = (1, 1)
4111
- state_shape = (1, 1)
4112
- return y_shape, h_shape, c_shape, reserved_shape, state_shape
4113
-
4114
- def infer_dtype(self, x_dtype, h_dtype, c_dtype, w_dtype):
4115
- args = {'x': x_dtype, 'h': h_dtype, 'c': c_dtype, 'w': w_dtype}
4116
- validator.check_tensors_dtypes_same_and_valid(args, (mstype.float32, mstype.float16), self.name)
4117
- return x_dtype, x_dtype, x_dtype, x_dtype, x_dtype
4118
-
4119
4104
 
4120
4105
  class SigmoidCrossEntropyWithLogits(Primitive):
4121
4106
  r"""
@@ -4134,7 +4119,7 @@ class SigmoidCrossEntropyWithLogits(Primitive):
4134
4119
  \end{array}
4135
4120
 
4136
4121
  Inputs:
4137
- - **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
4138
4123
  of additional dimensions.
4139
4124
  - **label** (Tensor) - Ground truth label. With the same shape and type as `logits`.
4140
4125
 
@@ -4174,7 +4159,7 @@ class BCEWithLogitsLoss(PrimitiveWithInfer):
4174
4159
 
4175
4160
  \begin{array}{ll} \\
4176
4161
  p_{ij} = sigmoid(X_{ij}) = \frac{1}{1 + e^{-X_{ij}}} \\
4177
- 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})]
4178
4163
  \end{array}
4179
4164
 
4180
4165
  :math:`i` indicates the :math:`i^{th}` sample, :math:`j` indicates the category. Then,
@@ -4192,8 +4177,8 @@ class BCEWithLogitsLoss(PrimitiveWithInfer):
4192
4177
  and the third method is to calculate the sum of all losses.
4193
4178
 
4194
4179
  This operator will multiply the output by the corresponding weight.
4195
- The tensor weight assigns different weights to each piece of data in the batch,
4196
- 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.
4197
4182
 
4198
4183
  In addition, it can trade off recall and precision by adding weights to positive examples.
4199
4184
  In the case of multi-label classification the loss can be described as:
@@ -4205,8 +4190,8 @@ class BCEWithLogitsLoss(PrimitiveWithInfer):
4205
4190
  \end{array}
4206
4191
 
4207
4192
  where c is the class number (c>1 for multi-label binary classification, c=1 for single-label binary classification),
4208
- 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.
4209
- :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.
4210
4195
 
4211
4196
  Args:
4212
4197
  reduction (str): Type of reduction to be applied to loss. The optional values are 'mean', 'sum', and 'none',
@@ -4259,7 +4244,7 @@ class Pad(Primitive):
4259
4244
  r"""
4260
4245
  Pads the input tensor according to the paddings.
4261
4246
 
4262
- Refer to :func:`mindspore.ops.pad` for more detail. Use :func:`mindspore.ops.pad` instead if `paddings` has
4247
+ Refer to :func:`mindspore.ops.pad` for more details. Use :func:`mindspore.ops.pad` instead if `paddings` has
4263
4248
  negative values.
4264
4249
 
4265
4250
  Args:
@@ -4269,8 +4254,8 @@ class Pad(Primitive):
4269
4254
  be extended behind the input tensor in the `D` th dimension.
4270
4255
 
4271
4256
  Inputs:
4272
- - **input_x** (Tensor) - Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
4273
- additional dimensions.
4257
+ - **input_x** (Tensor) - Tensor to be padded. It has shape :math:`(N, *)`, where :math:`*` means
4258
+ any number of additional dimensions.
4274
4259
 
4275
4260
  Outputs:
4276
4261
  Tensor, the tensor after padding.
@@ -4306,20 +4291,34 @@ class Pad(Primitive):
4306
4291
 
4307
4292
  class PadV3(Primitive):
4308
4293
  """
4309
- 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`.
4310
4295
 
4311
4296
  Args:
4312
- mode (str): An optional string, Defaults to "constant", indicates padding mode,
4313
- support "constant", "reflect", "edge", Defaults to "constant".
4314
- paddings_contiguous (bool): An optional bool value, Defaults to True.
4297
+ mode (str, optional): An optional string indicates padding mode,
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
+
4310
+ paddings_contiguous (bool, optional): An optional bool value indicates if the padding is paddings_contiguous.
4315
4311
  If true, paddings is arranged as [begin0, end0, begin1, end1, ...]
4316
4312
  If false, paddings is arranged as [begin0, begin1, ..., end1, end2, ...]
4313
+ Default:True.
4317
4314
 
4318
4315
  Inputs:
4319
- - **x** (Tensor) - Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
4320
- additional dimensions.
4321
- - **paddings** (Tensor) - Only constant value is allowed. A 1D tensor of type int32 or int64.
4322
- - **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`.
4323
4322
 
4324
4323
  Outputs:
4325
4324
  Tensor, the tensor after padding.
@@ -4328,16 +4327,19 @@ class PadV3(Primitive):
4328
4327
  TypeError: If `x` or `paddings` is not a Tensor.
4329
4328
  TypeError: If `padding_contiguous` is not a bool.
4330
4329
  ValueError: If `mode` is not a str or not in support modes.
4331
- ValueError: If `mode` is constant, the element's number of paddings not be even.
4332
- ValueError: If `mode` is constant, the element's number of paddings large than input dim * 2.
4333
- ValueError: If `mode` is edge or reflect, the element's number of paddings is not 2, 4 or 6.
4334
- ValueError: If `mode` is edge or reflect, x dims equal 3, the element's number of paddings is 2.
4335
- ValueError: If `mode` is edge or reflect, x dims equal 4, the element's number of paddings is 4.
4336
- ValueError: If `mode` is edge or reflect, x dims smaller than 3.
4337
- ValueError: If `mode` is edge, x dims bigger than 5.
4338
- ValueError: If `mode` is reflect, x dims bigger than 4.
4339
- ValueError: If `mode` is reflect, padding size bigger than the corresponding x dimension.
4340
- ValueError: After padding, output's shape number must be greater than 0.
4330
+ ValueError: If `mode` is "constant", the element's number of `paddings` not be even.
4331
+ ValueError: If `mode` is "constant", the element's number of `paddings` large than input dim * 2.
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.
4340
+ ValueError: If `mode` is "reflect", x dims bigger than 4.
4341
+ ValueError: If `mode` is "reflect", padding size bigger than the corresponding `x` dimension.
4342
+ ValueError: After padding, output's shape number is not greater than 0.
4341
4343
 
4342
4344
  Supported Platforms:
4343
4345
  ``Ascend`` ``GPU`` ``CPU``
@@ -4378,10 +4380,9 @@ class PadV3(Primitive):
4378
4380
  def __init__(self, mode='constant', paddings_contiguous=True):
4379
4381
  """Initialize PadV3"""
4380
4382
  self.init_prim_io_names(inputs=['x', 'paddings', 'constant_value'], outputs=['y'])
4381
- validator.check_string(mode, ['constant', 'reflect', 'edge'], 'mode', self.name)
4383
+ validator.check_string(mode, ['constant', 'reflect', 'edge', 'circular'], 'mode', self.name)
4382
4384
  validator.check_bool(paddings_contiguous, "paddings_contiguous", self.name)
4383
4385
  self.mode = mode
4384
- self.set_const_input_indexes([1])
4385
4386
  self.paddings_contiguous = paddings_contiguous
4386
4387
 
4387
4388
 
@@ -4397,7 +4398,7 @@ class MirrorPad(Primitive):
4397
4398
  - **input_x** (Tensor) - Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
4398
4399
  additional dimensions.
4399
4400
  - **paddings** (Tensor) - Paddings requires constant tensor. The value of `paddings` is a
4400
- 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
4401
4402
  are int type. For the input in the `D` th dimension, paddings[D, 0] indicates how many sizes
4402
4403
  to be extended ahead of the input tensor in the `D` th dimension, and paddings[D, 1]
4403
4404
  indicates how many sizes to be extended behind the input tensor in the `D` th dimension. Both
@@ -4463,7 +4464,6 @@ class MirrorPad(Primitive):
4463
4464
  self.init_prim_io_names(inputs=['x', 'paddings'], outputs=['y'])
4464
4465
  validator.check_string(mode, ['REFLECT', 'SYMMETRIC'], 'mode', self.name)
4465
4466
  self.mode = mode
4466
- self.set_const_input_indexes([1])
4467
4467
 
4468
4468
 
4469
4469
  class ComputeAccidentalHits(PrimitiveWithCheck):
@@ -4519,13 +4519,14 @@ class ComputeAccidentalHits(PrimitiveWithCheck):
4519
4519
  self.init_prim_io_names(inputs=['true_classes', 'sampled_candidates'],
4520
4520
  outputs=['indices', 'ids', 'weights'])
4521
4521
  validator.check_value_type("num_true", num_true, [int], self.name)
4522
- 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)
4523
4523
  self.num_true = num_true
4524
4524
 
4525
4525
  def check_shape(self, true_classes_shape, sampled_candidates_shape):
4526
- validator.check_int(len(true_classes_shape), 2, Rel.EQ, 'dim of true_classes', self.name)
4527
- validator.check_int(len(sampled_candidates_shape), 1, Rel.EQ, 'dim of sampled_candidates', self.name)
4528
- 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)
4529
4530
 
4530
4531
  indices_len = -1
4531
4532
  return (indices_len,), (indices_len,), (indices_len,)
@@ -4597,7 +4598,7 @@ class ROIAlign(Primitive):
4597
4598
  validator.check_value_type("spatial_scale", spatial_scale, [float], self.name)
4598
4599
  validator.check_value_type("sample_num", sample_num, [int], self.name)
4599
4600
  validator.check_value_type("roi_end_mode", roi_end_mode, [int], self.name)
4600
- 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)
4601
4602
  self.pooled_height = pooled_height
4602
4603
  self.pooled_width = pooled_width
4603
4604
  self.spatial_scale = spatial_scale
@@ -4639,22 +4640,19 @@ class Adam(Primitive):
4639
4640
  If false, update the gradients without using NAG. Default: False.
4640
4641
 
4641
4642
  Inputs:
4642
- - **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,
4643
4644
  any number of additional dimensions. The data type can be float16 or float32.
4644
- - **m** (Tensor) - The 1st moment vector in the updating formula,
4645
- the shape and data type value should be the same as `var`.
4646
- - **v** (Tensor) - the 2nd moment vector in the updating formula,
4647
- the shape and data type value should be the same as `var`. Mean square gradients with the same type as `var`.
4648
- - **beta1_power** (float) - :math:`beta_1^t(\beta_1^{t})` in the updating formula,
4649
- the data type value should be the same as `var`.
4650
- - **beta2_power** (float) - :math:`beta_2^t(\beta_2^{t})` in the updating formula,
4651
- the data type value should be the same as `var`.
4652
- - **lr** (float) - :math:`l` in the updating formula. The paper suggested value is :math:`10^{-8}`,
4653
- the data type value should be the same as `var`.
4654
- - **beta1** (float) - The exponential decay rate for the 1st moment estimations,
4655
- the data type value should be the same as `var`. The paper suggested value is :math:`0.9`.
4656
- - **beta2** (float) - The exponential decay rate for the 2nd moment estimations,
4657
- 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`.
4658
4656
  - **epsilon** (float) - Term added to the denominator to improve numerical stability.
4659
4657
  - **gradient** (Tensor) - Gradient, has the same shape and data type as `var`.
4660
4658
 
@@ -4667,7 +4665,7 @@ class Adam(Primitive):
4667
4665
 
4668
4666
  Raises:
4669
4667
  TypeError: If neither `use_locking` nor `use_nesterov` is a bool.
4670
- TypeError: If `var`, `m` or `v` is not a Tensor.
4668
+ TypeError: If `var`, `m` or `v` is not a Parameter.
4671
4669
  TypeError: If `beta1_power`, `beta2_power1`, `lr`, `beta1`, `beta2`, `epsilon` or `gradient` is not a Tensor.
4672
4670
 
4673
4671
  Supported Platforms:
@@ -4693,6 +4691,18 @@ class Adam(Primitive):
4693
4691
  [[0.9996838 0.9996838]
4694
4692
  [0.9996838 0.9996838]]
4695
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
+ )
4696
4706
 
4697
4707
  @prim_attr_register
4698
4708
  def __init__(self, use_locking=False, use_nesterov=False):
@@ -4702,7 +4712,7 @@ class Adam(Primitive):
4702
4712
  self.add_prim_attr('side_effect_mem', True)
4703
4713
 
4704
4714
 
4705
- class AdamWeightDecay(PrimitiveWithInfer):
4715
+ class AdamWeightDecay(Primitive):
4706
4716
  r"""
4707
4717
  Updates gradients by the Adaptive Moment Estimation algorithm with weight decay (AdamWeightDecay).
4708
4718
 
@@ -4744,7 +4754,7 @@ class AdamWeightDecay(PrimitiveWithInfer):
4744
4754
  it should have the the shape as `var`. The data type can be float16 or float32.
4745
4755
  - **v** (Parameter) - The 2nd moment vector in the updating formula,
4746
4756
  it should have the same shape and dtype as `m`.
4747
- - **lr** (float) - :math:`l` in the updating formula. The paper suggested value is :math:`10^{-8}`,
4757
+ - **lr** (float) - :math:`lr` in the updating formula. The paper suggested value is :math:`10^{-8}`,
4748
4758
  the data type should be float32.
4749
4759
  - **beta1** (float) - The exponential decay rate for the 1st moment estimations,
4750
4760
  the data type should be float32. The paper suggested value is :math:`0.9`
@@ -4755,6 +4765,7 @@ class AdamWeightDecay(PrimitiveWithInfer):
4755
4765
  - **decay** (float) - The weight decay value, must be a scalar tensor with float32 data type.
4756
4766
  Default: 0.0.
4757
4767
  - **gradient** (Tensor) - Gradient, has the same shape and data type as `var`.
4768
+
4758
4769
  Outputs:
4759
4770
  Tuple of 3 Tensor, the updated parameters.
4760
4771
 
@@ -4762,6 +4773,15 @@ class AdamWeightDecay(PrimitiveWithInfer):
4762
4773
  - **m** (Tensor) - The same shape and data type as `m`.
4763
4774
  - **v** (Tensor) - The same shape and data type as `v`.
4764
4775
 
4776
+ Raises:
4777
+ TypeError: If `use_locking` is not a bool.
4778
+ TypeError: If `lr`, `beta1`, `beta2`, `epsilon` or `decay` is not a float32.
4779
+ TypeError: If `var`, `m` or `v` is not a Parameter with dtype float16 or float32.
4780
+ TypeError: If `gradient` is not a Tensor.
4781
+ ValueError: - If `eps` <= 0.
4782
+ ValueError: - If `beta1`, `beta2` is not in range (0.0,1.0).
4783
+ ValueError: - If `decay` < 0.
4784
+
4765
4785
  Supported Platforms:
4766
4786
  ``Ascend`` ``GPU`` ``CPU``
4767
4787
 
@@ -4805,28 +4825,8 @@ class AdamWeightDecay(PrimitiveWithInfer):
4805
4825
  self.add_prim_attr('side_effect_mem', True)
4806
4826
  validator.check_value_type("use_locking", use_locking, [bool], self.name)
4807
4827
 
4808
- def infer_shape(self, var_shape, m_shape, v_shape, lr_shape, beta1_shape, beta2_shape,
4809
- epsilon_shape, decay_shape, grad_shape):
4810
- validator.check("var_shape", var_shape, "m_shape", m_shape, Rel.EQ, self.name)
4811
- validator.check("var_shape", var_shape, "v_shape", v_shape, Rel.EQ, self.name)
4812
- validator.check("var_shape", var_shape, "grad_shape", grad_shape, Rel.EQ, self.name)
4813
- return var_shape, m_shape, v_shape
4814
-
4815
- def infer_dtype(self, var_dtype, m_dtype, v_dtype, lr_dtype, beta1_dtype, beta2_dtype,
4816
- epsilon_dtype, decay_dtype, grad_dtype):
4817
- args = {"var": var_dtype, "grad": grad_dtype}
4818
- validator.check_tensors_dtypes_same_and_valid(args, mstype.number_type, self.name)
4819
-
4820
- args = {"m": m_dtype, "v": v_dtype}
4821
- validator.check_tensors_dtypes_same_and_valid(args, mstype.number_type, self.name)
4822
-
4823
- args = {"lr": lr_dtype, "beta1": beta1_dtype, "beta2": beta2_dtype, "epsilon": epsilon_dtype,
4824
- "decay": decay_dtype}
4825
- validator.check_scalar_or_tensor_types_same(args, [mstype.float32], self.name, True)
4826
- return var_dtype, m_dtype, v_dtype
4827
4828
 
4828
-
4829
- class AdamNoUpdateParam(PrimitiveWithInfer):
4829
+ class AdamNoUpdateParam(Primitive):
4830
4830
  r"""
4831
4831
  Updates gradients by the Adaptive Moment Estimation (Adam) algorithm. This operator do not update the parameter, but
4832
4832
  calculate the value that should be added to the parameter instead.
@@ -4921,20 +4921,6 @@ class AdamNoUpdateParam(PrimitiveWithInfer):
4921
4921
  validator.check_value_type("use_locking", use_locking, [bool], self.name)
4922
4922
  validator.check_value_type("use_nesterov", use_nesterov, [bool], self.name)
4923
4923
 
4924
- def infer_shape(self, m_shape, v_shape, beta1_power_shape, beta2_power_shape, lr_shape,
4925
- beta1_shape, beta2_shape, epsilon_shape, grad_shape):
4926
- validator.check("grad_shape", grad_shape, "m_shape", m_shape, Rel.EQ, self.name)
4927
- validator.check("grad_shape", grad_shape, "v_shape", v_shape, Rel.EQ, self.name)
4928
- return grad_shape
4929
-
4930
- def infer_dtype(self, m_dtype, v_dtype, beta1_power_dtype, beta2_power_dtype, lr_dtype,
4931
- beta1_dtype, beta2_dtype, epsilon_dtype, grad_dtype):
4932
- args = {"m": m_dtype, "v": v_dtype, "grad": grad_dtype,
4933
- "beta1_power": beta1_power_dtype, "beta2_power": beta2_power_dtype, 'lr': lr_dtype,
4934
- "beta1": beta1_dtype, "beta2": beta2_dtype, "epsilon": epsilon_dtype}
4935
- validator.check_tensors_dtypes_same_and_valid(args, [mstype.float32], self.name)
4936
- return grad_dtype
4937
-
4938
4924
 
4939
4925
  class FusedSparseAdam(Primitive):
4940
4926
  r"""
@@ -5279,7 +5265,7 @@ class FusedSparseFtrl(Primitive):
5279
5265
  self.lr = validator.check_positive_float(lr, "lr", self.name)
5280
5266
  self.l1 = validator.check_non_negative_float(l1, "l1", self.name)
5281
5267
  self.l2 = validator.check_non_negative_float(l2, "l2", self.name)
5282
- 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)
5283
5269
  self.use_locking = validator.check_value_type("use_locking", use_locking, [bool], self.name)
5284
5270
 
5285
5271
 
@@ -5393,14 +5379,14 @@ class KLDivLoss(Primitive):
5393
5379
  \operatorname{sum}(L(x, target)), & \text{if reduction} = \text{'sum'.}
5394
5380
  \end{cases}
5395
5381
 
5396
- where :math:`x` represents `logits`.
5397
- :math:`target` represents `labels`.
5382
+ where :math:`x` represents `logits`,
5383
+ :math:`target` represents `labels`, and
5398
5384
  :math:`\ell(x, target)` represents `output`.
5399
5385
 
5400
5386
  Note:
5401
- On Ascend, float64 dtype is not currently supported.
5402
- The output aligns with the mathematical definition of KL divergence
5403
- only when `reduction` is set to 'batchmean'.
5387
+ - On Ascend, float64 dtype is not currently supported.
5388
+ - The output aligns with the mathematical definition of Kullback-Leibler divergence
5389
+ only when `reduction` is set to 'batchmean'.
5404
5390
 
5405
5391
  Args:
5406
5392
  reduction (str): Specifies the reduction to be applied to the output.
@@ -5454,7 +5440,7 @@ class KLDivLoss(Primitive):
5454
5440
  elif device_target == "GPU":
5455
5441
  support_mode = ['none', 'mean', 'sum']
5456
5442
  elif device_target == "Ascend":
5457
- support_mode = ['none', 'batchmean', 'sum']
5443
+ support_mode = ['none', 'batchmean', 'sum', 'mean']
5458
5444
  else:
5459
5445
  raise ValueError(f"'{self.name}' unknown device target: '{device_target}'")
5460
5446
 
@@ -5473,7 +5459,8 @@ class BinaryCrossEntropy(Primitive):
5473
5459
  l_n = - w_n \left[ y_n \cdot \log x_n + (1 - y_n) \cdot \log (1 - x_n) \right]
5474
5460
 
5475
5461
  In which, :math:`L` indicates the loss of all batch_sizes, :math:`l` indicates the loss of one batch_size,
5476
- and n indicates one batch_size in the 1-N range. Then,
5462
+ and n indicates one batch_size in the 1-N range, :math:`w_n` indicates the
5463
+ weight of :math:`n`-th batch of binary cross entropy. Then,
5477
5464
 
5478
5465
  .. math::
5479
5466
  \ell(x, y) = \begin{cases}
@@ -5483,23 +5470,22 @@ class BinaryCrossEntropy(Primitive):
5483
5470
  \end{cases}
5484
5471
 
5485
5472
  .. warning::
5486
- - The value of "x" must range from 0 to 1.
5487
- - The value of "y" must be "0" or "1".
5473
+ - The value of :math:`x` must range from 0 to 1.
5488
5474
 
5489
5475
  Args:
5490
5476
  reduction (str): Specifies the reduction to be applied to the output.
5491
5477
  Its value must be one of 'none', 'mean' or 'sum'. Default: 'mean'.
5492
5478
 
5493
5479
  Inputs:
5494
- - **logits** (Tensor) - The input Tensor. The data type must be float16 or float32,
5480
+ - **logits** (Tensor) - The predictive value whose data type must be float16 or float32,
5495
5481
  The shape is :math:`(N, *)` where :math:`*` means, any number of additional dimensions.
5496
- - **labels** (Tensor) - The label Tensor which has the same shape and data type as `logits`.
5482
+ - **labels** (Tensor) - The target value which has the same shape and data type as `logits`.
5497
5483
  - **weight** (Tensor, optional) - A rescaling weight applied to the loss of each batch element.
5498
5484
  And it must have the same shape and data type as `logits`. Default: None.
5499
5485
 
5500
5486
  Outputs:
5501
- Tensor, has the same dtype as `logits`. if `reduction` is 'none', then it has the same shape as `logits`.
5502
- Otherwise, it is a scalar Tensor.
5487
+ Tensor or Scalar. Returns Tensor that has the same dtype and shape as `logits` if `reduction` is 'none'.
5488
+ Otherwise, returns a scalar Tensor.
5503
5489
 
5504
5490
  Raises:
5505
5491
  TypeError: If dtype of `logits`, `labels` or `weight` (if given) is neither float16 nor float32.
@@ -5594,7 +5580,7 @@ class ApplyAdaMax(Primitive):
5594
5580
  RuntimeError: If the data type of `var`, `m`, `v` and `grad` conversion of Parameter is not supported.
5595
5581
 
5596
5582
  Supported Platforms:
5597
- ``Ascend`` ``GPU``
5583
+ ``Ascend`` ``GPU`` ``CPU``
5598
5584
 
5599
5585
  Examples:
5600
5586
  >>> class Net(nn.Cell):
@@ -5773,10 +5759,10 @@ class ApplyAdagrad(Primitive):
5773
5759
  update_slots (bool): If `True`, `accum` will be updated. Default: True.
5774
5760
 
5775
5761
  Inputs:
5776
- - **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.
5777
5763
  The shape is :math:`(N, *)` where :math:`*` means, any number of additional dimensions.
5778
5764
  - **accum** (Parameter) - Accumulation to be updated. The shape and data type must be the same as `var`.
5779
- - **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.
5780
5766
  - **grad** (Tensor) - A tensor for gradient. The shape and data type must be the same as `var`.
5781
5767
 
5782
5768
  Outputs:
@@ -5786,12 +5772,12 @@ class ApplyAdagrad(Primitive):
5786
5772
  - **accum** (Tensor) - The same shape and data type as `accum`.
5787
5773
 
5788
5774
  Raises:
5789
- 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.
5790
5776
  TypeError: If `lr` is neither a Number nor a Tensor.
5791
5777
  RuntimeError: If the data type of `var`, `accum` and `grad` conversion of Parameter is not supported.
5792
5778
 
5793
5779
  Supported Platforms:
5794
- ``Ascend`` ``CPU`` ``GPU``
5780
+ ``Ascend`` ``GPU`` ``CPU``
5795
5781
 
5796
5782
  Examples:
5797
5783
  >>> class Net(nn.Cell):
@@ -5850,7 +5836,7 @@ class ApplyAdagradV2(Primitive):
5850
5836
  the relatively highest priority data type.
5851
5837
 
5852
5838
  Note:
5853
- 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`.
5854
5840
 
5855
5841
  Args:
5856
5842
  epsilon (float): A small value added for numerical stability.
@@ -5971,7 +5957,7 @@ class SparseApplyAdagradV2(Primitive):
5971
5957
  - **grad** (Tensor) - Gradients has the same data type as `var` and
5972
5958
  :math:`grad.shape[1:] = var.shape[1:]` if var.shape > 1.
5973
5959
  - **indices** (Tensor) - A vector of indices into the first dimension of `var` and `accum`.
5974
- 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]`.
5975
5961
 
5976
5962
  Outputs:
5977
5963
  Tuple of 2 tensors, the updated parameters.
@@ -5987,7 +5973,7 @@ class SparseApplyAdagradV2(Primitive):
5987
5973
  RuntimeError: If the data type of `var`, `accum` and `grad` conversion of Parameter is not supported.
5988
5974
 
5989
5975
  Supported Platforms:
5990
- ``Ascend`` ``CPU`` ``GPU``
5976
+ ``Ascend`` ``GPU`` ``CPU``
5991
5977
 
5992
5978
  Examples:
5993
5979
  >>> class Net(nn.Cell):
@@ -6123,9 +6109,10 @@ class ApplyProximalAdagrad(Primitive):
6123
6109
  self.use_locking = validator.check_value_type("use_locking", use_locking, [bool], self.name)
6124
6110
 
6125
6111
 
6126
- class SparseApplyProximalAdagrad(PrimitiveWithCheck):
6112
+ class SparseApplyProximalAdagrad(Primitive):
6127
6113
  r"""
6128
- Updates relevant entries according to the proximal adagrad algorithm. Compared with ApplyProximalAdagrad,
6114
+ Updates relevant entries according to the proximal adagrad algorithm.
6115
+ Compared with :class:`mindspore.ops.ApplyProximalAdagrad`,
6129
6116
  an additional index tensor is input.
6130
6117
 
6131
6118
  .. math::
@@ -6149,16 +6136,16 @@ class SparseApplyProximalAdagrad(PrimitiveWithCheck):
6149
6136
  The shape is :math:`(N, *)` where :math:`*` means, any number of additional dimensions.
6150
6137
  - **accum** (Parameter) - Variable tensor to be updated, has the same shape and dtype as `var`.
6151
6138
  - **lr** (Union[Number, Tensor]) - The learning rate value, must be a float number or
6152
- a scalar tensor with float16 or float32 data type.
6139
+ a scalar tensor with float16 or float32 data type. It must be positive.
6153
6140
  - **l1** (Union[Number, Tensor]) - l1 regularization strength, must be a float number or
6154
- a scalar tensor with float16 or float32 data type.
6141
+ a scalar tensor with float16 or float32 data type. It must be non-negative.
6155
6142
  - **l2** (Union[Number, Tensor]) - l2 regularization strength, must be a float number or
6156
- a scalar tensor with float16 or float32 data type.
6143
+ a scalar tensor with float16 or float32 data type. It must be non-negative.
6157
6144
  - **grad** (Tensor) - A tensor of the same type as `var` and
6158
- grad.shape[1:] = var.shape[1:] if var.shape > 1.
6145
+ :math:`grad.shape[1:] = var.shape[1:]` if var.shape > 1.
6159
6146
  - **indices** (Tensor) - A tensor of indices in the first dimension of `var` and `accum`.
6160
6147
  If there are duplicates in `indices`, the behavior is undefined. Must be one of the
6161
- following types: int32, int64 and indices.shape[0] = grad.shape[0].
6148
+ following types: int32, int64 and :math:`indices.shape[0] = grad.shape[0]`.
6162
6149
 
6163
6150
  Outputs:
6164
6151
  Tuple of 2 tensors, the updated parameters.
@@ -6170,6 +6157,7 @@ class SparseApplyProximalAdagrad(PrimitiveWithCheck):
6170
6157
  TypeError: If `use_locking` is not a bool.
6171
6158
  TypeError: If dtype of `var`, `accum`, `lr`, `l1`, `l2` or `grad` is neither float16 nor float32.
6172
6159
  TypeError: If dtype of `indices` is neither int32 nor int64.
6160
+ ValueError: If `lr` <= 0 or `l1` < 0 or `l2` < 0.
6173
6161
  RuntimeError: If the data type of `var`, `accum` and `grad` conversion of Parameter is not supported.
6174
6162
 
6175
6163
  Supported Platforms:
@@ -6220,20 +6208,6 @@ class SparseApplyProximalAdagrad(PrimitiveWithCheck):
6220
6208
  self.add_prim_attr('side_effect_mem', True)
6221
6209
  self.use_locking = validator.check_value_type("use_locking", use_locking, [bool], self.name)
6222
6210
 
6223
- def check_shape(self, var_shape, accum_shape, lr_shape, l1_shape, l2_shape,
6224
- grad_shape, indices_shape):
6225
- validator.check_int(len(indices_shape), 1, Rel.EQ, "indices rank", self.name)
6226
-
6227
- def check_dtype(self, var_dtype, accum_dtype, lr_dtype, l1_dtype, l2_dtype,
6228
- grad_dtype, indices_dtype):
6229
- args = {'var': var_dtype, 'accum': accum_dtype, 'grad': grad_dtype}
6230
- validator.check_tensors_dtypes_same_and_valid(args, [mstype.float16, mstype.float32], self.name)
6231
- validator.check_scalar_or_tensor_types_same({"lr": lr_dtype}, [mstype.float16, mstype.float32], self.name)
6232
- validator.check_scalar_or_tensor_types_same({"l1": l1_dtype}, [mstype.float16, mstype.float32], self.name)
6233
- validator.check_scalar_or_tensor_types_same({"l2": l2_dtype}, [mstype.float16, mstype.float32], self.name)
6234
- valid_dtypes = [mstype.int32, mstype.int64]
6235
- validator.check_tensor_dtype_valid('indices', indices_dtype, valid_dtypes, self.name)
6236
-
6237
6211
 
6238
6212
  class ApplyAddSign(Primitive):
6239
6213
  r"""
@@ -6496,7 +6470,7 @@ class ApplyProximalGradientDescent(Primitive):
6496
6470
  r"""
6497
6471
  Updates relevant entries according to the FOBOS(Forward Backward Splitting) algorithm.
6498
6472
  Refer to the paper `Efficient Learning using Forward-Backward Splitting
6499
- <http://papers.nips.cc//paper/3793-efficient-learning-using-forward-backward-splitting.pdf>`_ for more detail.
6473
+ <http://papers.nips.cc//paper/3793-efficient-learning-using-forward-backward-splitting.pdf>`_ for more details.
6500
6474
 
6501
6475
  .. math::
6502
6476
  \begin{array}{ll} \\
@@ -6636,6 +6610,10 @@ class ApplyFtrl(Primitive):
6636
6610
 
6637
6611
  For more details, please refer to :class:`mindspore.nn.FTRL`.
6638
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
+
6639
6617
  Args:
6640
6618
  use_locking (bool): Use locks for updating operation if true . Default: False.
6641
6619
 
@@ -6664,6 +6642,9 @@ class ApplyFtrl(Primitive):
6664
6642
  TypeError: If dtype of `var`, `grad`, `lr`, `l1`, `l2` or `lr_power` is neither float16 nor float32.
6665
6643
  TypeError: If `lr`, `l1`, `l2` or `lr_power` is neither a Number nor a Tensor.
6666
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`.
6667
6648
 
6668
6649
  Supported Platforms:
6669
6650
  ``Ascend`` ``GPU`` ``CPU``
@@ -6697,6 +6678,17 @@ class ApplyFtrl(Primitive):
6697
6678
  [ 0.00066425 0.15075898]]
6698
6679
  """
6699
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
+
6700
6692
  @prim_attr_register
6701
6693
  def __init__(self, use_locking=False):
6702
6694
  """Initialize ApplyFtrl."""
@@ -6721,17 +6713,18 @@ class SparseApplyFtrl(Primitive):
6721
6713
  l2 (float): l2 regularization strength, must be greater than or equal to zero.
6722
6714
  lr_power (float): Learning rate power controls how the learning rate decreases during training,
6723
6715
  must be less than or equal to zero. Use fixed learning rate if `lr_power` is zero.
6724
- use_locking (bool): Use locks for updating operation if true . Default: False.
6716
+ use_locking (bool, optional): Use locks for updating operation if true . Default: False.
6725
6717
 
6726
6718
  Inputs:
6727
6719
  - **var** (Parameter) - The variable to be updated. The data type must be float16 or float32.
6728
6720
  The shape is :math:`(N, *)` where :math:`*` means, any number of additional dimensions.
6729
6721
  - **accum** (Parameter) - The accumulation to be updated, must be same data type and shape as `var`.
6730
6722
  - **linear** (Parameter) - The linear coefficient to be updated, must be the same data type and shape as `var`.
6731
- - **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.
6732
6725
  - **indices** (Tensor) - A tensor of indices in the first dimension of `var` and `accum`.
6733
6726
  If there are duplicates in `indices`, the behavior is undefined.
6734
- 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]`.
6735
6728
 
6736
6729
  Outputs:
6737
6730
  - **var** (Tensor) - Tensor, has the same shape and data type as `var`.
@@ -6790,7 +6783,7 @@ class SparseApplyFtrl(Primitive):
6790
6783
  self.lr = validator.check_positive_float(lr, "lr", self.name)
6791
6784
  self.l1 = validator.check_non_negative_float(l1, "l1", self.name)
6792
6785
  self.l2 = validator.check_non_negative_float(l2, "l2", self.name)
6793
- 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)
6794
6787
  self.use_locking = validator.check_value_type("use_locking", use_locking, [bool], self.name)
6795
6788
  self.init_prim_io_names(inputs=['var', 'accum', 'linear', 'grad', 'indices'],
6796
6789
  outputs=['var', 'accum', 'linear'])
@@ -6799,74 +6792,10 @@ class SparseApplyFtrl(Primitive):
6799
6792
 
6800
6793
  class SparseApplyFtrlV2(PrimitiveWithInfer):
6801
6794
  """
6802
- Updates relevant entries according to the FTRL-proximal scheme. This class has one more attribute, named
6803
- l2_shrinkage, than class SparseApplyFtrl.
6804
-
6805
- All of inputs except `indices` comply with the implicit type conversion rules to make the data types consistent.
6806
- If they have different data types, the lower priority data type will be converted to
6807
- the relatively highest priority data type.
6808
-
6809
-
6810
- Args:
6811
- lr (float): The learning rate value, must be positive.
6812
- l1 (float): l1 regularization strength, must be greater than or equal to zero.
6813
- l2 (float): l2 regularization strength, must be greater than or equal to zero.
6814
- l2_shrinkage (float): L2 shrinkage regularization.
6815
- lr_power (float): Learning rate power controls how the learning rate decreases during training,
6816
- must be less than or equal to zero. Use fixed learning rate if `lr_power` is zero.
6817
- use_locking (bool): If `True`, the var and accumulation tensors will be protected from being updated.
6818
- Default: False.
6819
-
6820
- Inputs:
6821
- - **var** (Parameter) - The variable to be updated. The data type must be float16 or float32.
6822
- The shape is :math:`(N, *)` where :math:`*` means, any number of additional dimensions.
6823
- - **accum** (Parameter) - The accumulation to be updated, must be same data type and shape as `var`.
6824
- - **linear** (Parameter) - the linear coefficient to be updated, must be same data type and shape as `var`.
6825
- - **grad** (Tensor) - A tensor of the same type as `var` and
6826
- :math:`grad.shape[1:] = var.shape[1:]` if var.shape > 1.
6827
- - **indices** (Tensor) - A vector of indices in the first dimension of `var` and `accum`.
6828
- The type must be int32 and indices.shape[0] = grad.shape[0].
6829
-
6830
- Outputs:
6831
- Tuple of 3 Tensor, the updated parameters.
6832
-
6833
- - **var** (Tensor) - Tensor, has the same shape and data type as `var`.
6834
- - **accum** (Tensor) - Tensor, has the same shape and data type as `accum`.
6835
- - **linear** (Tensor) - Tensor, has the same shape and data type as `linear`.
6836
-
6837
- Raises:
6838
- TypeError: If `lr`, `l1`, `l2`, `lr_power` or `use_locking` is not a float.
6839
- TypeError: If `use_locking` is not a bool.
6840
- TypeError: If dtype of `var`, `accum`, `linear` or `grad` is neither float16 nor float32.
6841
- TypeError: If dtype of `indices` is not int32.
6842
- RuntimeError: If the data type of all of inputs except `indices` conversion of Parameter is not supported.
6795
+ The SparseApplyFtrlV2 interface is deprecated, please use the :class:`mindspore.ops.SparseApplyFtrl` instead.
6843
6796
 
6844
6797
  Supported Platforms:
6845
- ``Ascend``
6846
-
6847
- Examples:
6848
- >>> class SparseApplyFtrlV2Net(nn.Cell):
6849
- ... def __init__(self):
6850
- ... super(SparseApplyFtrlV2Net, self).__init__()
6851
- ... self.sparse_apply_ftrl_v2 = ops.SparseApplyFtrlV2(lr=0.01, l1=0.0, l2=0.0,
6852
- ... l2_shrinkage=0.0, lr_power=-0.5)
6853
- ... self.var = Parameter(Tensor(np.array([[0.2, 0.3]]).astype(np.float32)), name="var")
6854
- ... self.accum = Parameter(Tensor(np.array([[0.5, 0.9]]).astype(np.float32)), name="accum")
6855
- ... self.linear = Parameter(Tensor(np.array([[0.7, 0.5]]).astype(np.float32)), name="linear")
6856
- ...
6857
- ... def construct(self, grad, indices):
6858
- ... out = self.sparse_apply_ftrl_v2(self.var, self.accum, self.linear, grad, indices)
6859
- ... return out
6860
- ...
6861
- >>> net = SparseApplyFtrlV2Net()
6862
- >>> grad = Tensor(np.array([[0.8, 0.5]]).astype(np.float32))
6863
- >>> indices = Tensor(np.ones([1]), mindspore.int32)
6864
- >>> output = net(grad, indices)
6865
- >>> print(output)
6866
- (Tensor(shape=[1, 2], dtype=Float32, value=
6867
- [[ 2.00000003e-01, 3.00000012e-01]]), Tensor(shape=[1, 2], dtype=Float32, value=
6868
- [[ 5.00000000e-01, 8.99999976e-01]]), Tensor(shape=[1, 2], dtype=Float32, value=
6869
- [[ 6.99999988e-01, 5.00000000e-01]]))
6798
+ Deprecated
6870
6799
  """
6871
6800
 
6872
6801
  __mindspore_signature__ = (
@@ -6877,6 +6806,7 @@ class SparseApplyFtrlV2(PrimitiveWithInfer):
6877
6806
  sig.make_sig('indices', dtype=sig.sig_dtype.T1)
6878
6807
  )
6879
6808
 
6809
+ @deprecated("2.1", "ops.SparseApplyFtrl", False)
6880
6810
  @prim_attr_register
6881
6811
  def __init__(self, lr, l1, l2, l2_shrinkage, lr_power, use_locking=False):
6882
6812
  """Initialize SparseApplyFtrlV2."""
@@ -6887,18 +6817,18 @@ class SparseApplyFtrlV2(PrimitiveWithInfer):
6887
6817
  self.lr = validator.check_positive_float(lr, "lr", self.name)
6888
6818
  self.l1 = validator.check_non_negative_float(l1, "l1", self.name)
6889
6819
  self.l2 = validator.check_non_negative_float(l2, "l2", self.name)
6890
- 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)
6891
6821
  self.l2_shrinkage = validator.check_value_type("l2_shrinkage", l2_shrinkage, [float], self.name)
6892
6822
  self.use_locking = validator.check_value_type("use_locking", use_locking, [bool], self.name)
6893
6823
  self.add_prim_attr('side_effect_mem', True)
6894
6824
 
6895
6825
  def infer_shape(self, var_shape, accum_shape, linear_shape, grad_shape, indices_shape):
6896
- validator.check('var shape', var_shape, 'accum shape', accum_shape, Rel.EQ, self.name)
6897
- 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)
6898
6828
  if len(var_shape) > 1:
6899
- validator.check('var_shape[1:]', var_shape[1:], 'grad_shape[1:]', grad_shape[1:], Rel.EQ, self.name)
6900
- validator.check_int(len(indices_shape), 1, Rel.EQ, "indices rank", self.name)
6901
- 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)
6902
6832
  return var_shape, accum_shape, linear_shape
6903
6833
 
6904
6834
  def infer_dtype(self, var_dtype, accum_dtype, linear_dtype, grad_dtype, indices_dtype):
@@ -6912,12 +6842,20 @@ class SparseApplyFtrlV2(PrimitiveWithInfer):
6912
6842
  class Dropout(PrimitiveWithCheck):
6913
6843
  """
6914
6844
  During training, randomly zeroes some of the elements of the input tensor
6915
- with probability 1-`keep_prob` from a Bernoulli distribution.
6845
+ with probability 1-`keep_prob` from a Bernoulli distribution. It plays the
6846
+ role of reducing neuron correlation and avoid overfitting.
6916
6847
 
6917
- Refer to :func:`mindspore.ops.dropout` for more detail.
6848
+ Refer to :func:`mindspore.ops.dropout` for more details.
6918
6849
 
6919
6850
  Supported Platforms:
6920
6851
  ``Ascend`` ``GPU`` ``CPU``
6852
+
6853
+ Examples:
6854
+ >>> dropout = ops.Dropout(keep_prob=0.5)
6855
+ >>> x = Tensor(np.ones([1, 2, 3, 4, 5]), mindspore.float32)
6856
+ >>> output, mask = dropout(x)
6857
+ >>> print(output.shape, mask.shape, mask.dtype)
6858
+ (1, 2, 3, 4, 5) (16,) UInt8
6921
6859
  """
6922
6860
 
6923
6861
  @prim_attr_register
@@ -6925,10 +6863,10 @@ class Dropout(PrimitiveWithCheck):
6925
6863
  """Initialize Dropout."""
6926
6864
  self.seed0 = validator.check_value_type("Seed0", Seed0, [int], self.name)
6927
6865
  self.seed1 = validator.check_value_type("Seed1", Seed1, [int], self.name)
6928
- 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)
6929
6867
 
6930
6868
  def check_shape(self, x_shape):
6931
- 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)
6932
6870
 
6933
6871
  def check_dtype(self, x_dtype):
6934
6872
  valid_dtypes = (mstype.float16, mstype.float32, mstype.float64)
@@ -6946,7 +6884,25 @@ class Dropout2D(PrimitiveWithInfer):
6946
6884
  Note:
6947
6885
  The keep probability :math:`keep\_prob` is equal to :math:`1 - p` in :func:`mindspore.ops.dropout2d`.
6948
6886
 
6949
- Refer to :func:`mindspore.ops.dropout2d` for more detail.
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`.
6950
6906
 
6951
6907
  Supported Platforms:
6952
6908
  ``Ascend`` ``GPU`` ``CPU``
@@ -6964,7 +6920,7 @@ class Dropout2D(PrimitiveWithInfer):
6964
6920
  """Initialize Dropout2D."""
6965
6921
  super().__init__("Dropout2D")
6966
6922
  self.keep_prob = validator.check_value_type("keep_prob", keep_prob, [float], self.name)
6967
- 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)
6968
6924
 
6969
6925
 
6970
6926
  class Dropout3D(PrimitiveWithInfer):
@@ -6973,13 +6929,28 @@ class Dropout3D(PrimitiveWithInfer):
6973
6929
  with probability 1-`keep_prob` from a Bernoulli distribution(For a 5-dimensional tensor with a shape of NCDHW,
6974
6930
  the channel feature map refers to a 3-dimensional feature map with a shape of DHW).
6975
6931
 
6932
+ Note:
6933
+ The keep probability :math:`keep\_prob` is equal to :math:`1 - p` in :func:`mindspore.ops.dropout3d`.
6934
+
6976
6935
  Dropout3D can improve the independence between channel feature maps.
6977
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.
6978
6940
 
6979
- Note:
6980
- The keep probability :math:`keep\_prob` is equal to :math:`1 - p` in :func:`mindspore.ops.dropout2d`.
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.
6981
6945
 
6982
- Refer to :func:`mindspore.ops.dropout3d` for more detail.
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.
6983
6954
 
6984
6955
  Supported Platforms:
6985
6956
  ``Ascend`` ``GPU`` ``CPU``
@@ -6997,7 +6968,7 @@ class Dropout3D(PrimitiveWithInfer):
6997
6968
  """Initialize Dropout3D."""
6998
6969
  super().__init__("Dropout3D")
6999
6970
  self.keep_prob = validator.check_value_type("keep_prob", keep_prob, [float], self.name)
7000
- 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)
7001
6972
 
7002
6973
 
7003
6974
  class CTCLoss(Primitive):
@@ -7090,10 +7061,28 @@ class CTCGreedyDecoder(Primitive):
7090
7061
  r"""
7091
7062
  Performs greedy decoding on the logits given in inputs.
7092
7063
 
7093
- Refer to :func:`mindspore.ops.ctc_greedy_decoder` for more detail.
7064
+ Refer to :func:`mindspore.ops.ctc_greedy_decoder` for more details.
7094
7065
 
7095
7066
  Supported Platforms:
7096
- ``Ascend`` ``CPU``
7067
+ ``Ascend`` ``GPU`` ``CPU``
7068
+
7069
+ Examples:
7070
+ >>> inputs = Tensor(np.array([[[0.6, 0.4, 0.2], [0.8, 0.6, 0.3]],
7071
+ ... [[0.0, 0.6, 0.0], [0.5, 0.4, 0.5]]]), mindspore.float32)
7072
+ >>> sequence_length = Tensor(np.array([2, 2]), mindspore.int32)
7073
+ >>> decoded_indices, decoded_values, decoded_shape, log_probability = ops.CTCGreedyDecoder()(inputs,
7074
+ ... sequence_length)
7075
+ >>> print(decoded_indices)
7076
+ [[0 0]
7077
+ [0 1]
7078
+ [1 0]]
7079
+ >>> print(decoded_values)
7080
+ [0 1 0]
7081
+ >>> print(decoded_shape)
7082
+ [2 2]
7083
+ >>> print(log_probability)
7084
+ [[-1.2]
7085
+ [-1.3]]
7097
7086
  """
7098
7087
 
7099
7088
  @prim_attr_register
@@ -7115,23 +7104,24 @@ class BasicLSTMCell(PrimitiveWithInfer):
7115
7104
  def __init__(self, keep_prob=1.0, forget_bias=1.0, state_is_tuple=True, activation='tanh'):
7116
7105
  """Initialize BasicLSTMCell."""
7117
7106
  self.keep_prob = validator.check_value_type("keep_prob", keep_prob, [float], self.name)
7118
- 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)
7119
7108
  self.forget_bias = validator.check_value_type("forget_bias", forget_bias, [float], self.name)
7120
7109
  self.state_is_tuple = validator.check_value_type("state_is_tuple", state_is_tuple, [bool], self.name)
7121
7110
  self.activation = validator.check_string(activation, ['tanh'], "activation", self.name)
7122
7111
 
7123
7112
  def infer_shape(self, x_shape, h_shape, c_shape, w_shape, b_shape):
7124
- validator.check_int(len(x_shape), 2, Rel.EQ, "x rank", self.name)
7125
- validator.check_int(len(h_shape), 2, Rel.EQ, "h rank", self.name)
7126
- validator.check_int(len(c_shape), 2, Rel.EQ, "c rank", self.name)
7127
- validator.check_int(len(w_shape), 2, Rel.EQ, "w rank", self.name)
7128
- validator.check_int(len(b_shape), 1, Rel.EQ, "b rank", self.name)
7129
- validator.check("x_shape[0]", x_shape[0], "h_shape[0]", h_shape[0], Rel.EQ, self.name)
7130
- validator.check("c_shape[0]", c_shape[0], "h_shape[0]", h_shape[0], Rel.EQ, self.name)
7131
- validator.check("c_shape[1]", c_shape[1], "h_shape[1]", h_shape[1], Rel.EQ, self.name)
7132
- validator.check("w_shape[1]", w_shape[1], "4*h_shape[1]", 4 * h_shape[1], Rel.EQ, self.name)
7133
- validator.check("w_shape[0]", w_shape[0], "x_shape[1]+h_shape[1]", x_shape[1] + h_shape[1], Rel.EQ, self.name)
7134
- 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)
7135
7125
  ct_shape = c_shape
7136
7126
  ht_shape = c_shape
7137
7127
  it_shape = c_shape
@@ -7152,7 +7142,7 @@ class BasicLSTMCell(PrimitiveWithInfer):
7152
7142
  return c_dtype, mstype.float16, c_dtype, c_dtype, c_dtype, c_dtype, c_dtype
7153
7143
 
7154
7144
 
7155
- class DynamicRNN(PrimitiveWithInfer):
7145
+ class DynamicRNN(Primitive):
7156
7146
  r"""
7157
7147
  Applies a recurrent neural network to the input.
7158
7148
  Only long short-term memory (LSTM) is supported currently.
@@ -7167,9 +7157,9 @@ class DynamicRNN(PrimitiveWithInfer):
7167
7157
  h_{t+1} = o_{t+1} * \tanh(c_{t+1}) \\
7168
7158
  \end{array}
7169
7159
 
7170
- where :math:`h_{t+1}` is the hidden state at time `t+1`, :math:`x_{t+1}` is the input
7171
- at time `t+1`, :math:`h_{t}` is the hidden state of the layer
7172
- at time `t` or the initial hidden state at time `0`,
7160
+ :math:`h_{t+1}` is the hidden state at time `t+1`. :math:`x_{t+1}` is the input
7161
+ at time `t+1`. :math:`h_{t}` is the hidden state of the layer
7162
+ at time `t` or the initial hidden state at time `0`.
7173
7163
  :math:`\sigma` is the sigmoid function, and :math:`*` is the Hadamard product. :math:`W, b`
7174
7164
  are learnable weights between the output and the input in the formula. For instance,
7175
7165
  :math:`W_{ix}, b_{ix}` are the weight and bias used to transform from input :math:`x` to :math:`i`.
@@ -7184,8 +7174,10 @@ class DynamicRNN(PrimitiveWithInfer):
7184
7174
  keep_prob (float): A float identifying the keep prob in the operator. Default: 1.0.
7185
7175
  cell_clip (float): A float identifying the cell clip in the operator. Default: -1.0.
7186
7176
  num_proj (int): An integer identifying the number projection in the operator. Default: 0.
7187
- time_major (bool): A bool identifying the time major in the operator. Default: True.
7188
- 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.
7189
7181
  activation (str): A string identifying the type of activation function in the operator. Default: 'tanh'.
7190
7182
  Only 'tanh' is currently supported.
7191
7183
  forget_bias (float): A float identifying the forget bias in the operator. Default: 0.0.
@@ -7277,45 +7269,8 @@ class DynamicRNN(PrimitiveWithInfer):
7277
7269
  validator.check_value_type("activation", activation, [str], self.name)
7278
7270
  self.activation = validator.check_string(activation, ['tanh'], "activation", self.name)
7279
7271
 
7280
- def infer_shape(self, x_shape, w_shape, b_shape, seq_shape, h_shape, c_shape):
7281
- validator.check_int(len(x_shape), 3, Rel.EQ, "x_shape", self.name)
7282
- validator.check_int(len(w_shape), 2, Rel.EQ, "w rank", self.name)
7283
- validator.check_int(len(b_shape), 1, Rel.EQ, "b rank", self.name)
7284
- validator.check_int(len(h_shape), 3, Rel.EQ, "h_shape", self.name)
7285
- validator.check_int(len(c_shape), 3, Rel.EQ, "c_shape", self.name)
7286
- if seq_shape is not None:
7287
- raise ValueError(f"For '{self.name}', the 'seq_length' must be None.")
7288
-
7289
- num_step, batch_size, input_size = x_shape
7290
- hidden_size = w_shape[-1] // 4
7291
-
7292
- validator.check("b_shape[-1]", b_shape[-1], "w_shape[-1]", w_shape[-1], Rel.EQ, self.name)
7293
- if w_shape[-1] % 4 != 0:
7294
- raise ValueError(f"For '{self.name}', the last dimension of 'w' must be a multiple of 4, "
7295
- f"but got {w_shape[-1]}.")
7296
- validator.check("w_shape[0]", w_shape[0], "input_size + hidden_size",
7297
- input_size + hidden_size, Rel.EQ, self.name)
7298
- validator.check("b_shape[0]", b_shape[0], "w_shape[1]", w_shape[1], Rel.EQ, self.name)
7299
- validator.check_int(h_shape[0], 1, Rel.EQ, "h_shape[0]", self.name)
7300
- validator.check("h_shape[1]", h_shape[1], "batch_size", batch_size, Rel.EQ, self.name)
7301
- validator.check("h_shape[2]", h_shape[2], "hidden_size", hidden_size, Rel.EQ, self.name)
7302
- validator.check("c_shape", c_shape, "h_shape", h_shape, Rel.EQ, self.name)
7303
- self.placeholder_index = [3]
7304
- self.add_prim_attr("placeholder_index", self.placeholder_index)
7305
- self.add_prim_attr("input_size", input_size)
7306
- self.add_prim_attr("hidden_size", hidden_size)
7307
- y_shape = (num_step, batch_size, hidden_size)
7308
- return y_shape, y_shape, y_shape, y_shape, y_shape, y_shape, y_shape, y_shape
7309
-
7310
- def infer_dtype(self, x_dtype, w_dtype, b_dtype, seq_dtype, h_dtype, c_dtype):
7311
- tuple(map(partial(validator.check_tensor_dtype_valid, valid_dtypes=[mstype.float16], prim_name=self.name),
7312
- ("x", "w", "h", "c"),
7313
- (x_dtype, w_dtype, h_dtype, c_dtype)))
7314
- validator.check_tensor_dtype_valid("b", b_dtype, (mstype.float16, mstype.float32), self.name)
7315
- return b_dtype, x_dtype, b_dtype, b_dtype, b_dtype, b_dtype, b_dtype, b_dtype
7316
-
7317
-
7318
- class DynamicGRUV2(PrimitiveWithInfer):
7272
+
7273
+ class DynamicGRUV2(Primitive):
7319
7274
  r"""
7320
7275
  Applies a single-layer gated recurrent unit (GRU) to an input sequence.
7321
7276
 
@@ -7330,7 +7285,7 @@ class DynamicGRUV2(PrimitiveWithInfer):
7330
7285
 
7331
7286
  where :math:`h_{t+1}` is the hidden state at time `t+1`, :math:`x_{t+1}` is the input
7332
7287
  at time `t+1`, :math:`h_{t}` is the hidden state of the layer
7333
- at time `t` or the initial hidden state at time `0`, and :math:`r_{t+1}`,
7288
+ at time `t` or the initial hidden state at time `0`. :math:`r_{t+1}`,
7334
7289
  :math:`z_{t+1}`, :math:`n_{t+1}` are the reset, update, and new gates, respectively.
7335
7290
  :math:`W`, :math:`b` are the weight parameter and the deviation parameter respectively.
7336
7291
  :math:`\sigma` is the sigmoid function, and :math:`*` is the Hadamard product.
@@ -7445,72 +7400,20 @@ class DynamicGRUV2(PrimitiveWithInfer):
7445
7400
  self.direction = validator.check_string(direction, ['UNIDIRECTIONAL'], "direction", self.name)
7446
7401
  self.activation = validator.check_string(activation, ['tanh'], "activation", self.name)
7447
7402
  self.gate_order = validator.check_string(gate_order, ['zrh', 'rzh'], "gate_order", self.name)
7448
- self.reset_after = validator.check_value_type("reset_after", reset_after, [bool], self.name)
7449
-
7450
- def infer_shape(self, x_shape, winput_shape, whidden_shape, binput_shape, bhidden_shape, seq_shape, h_shape):
7451
- validator.check_int(len(x_shape), 3, Rel.EQ, "x shape", self.name)
7452
- validator.check_int(len(winput_shape), 2, Rel.EQ, "weight input shape rank", self.name)
7453
- validator.check_int(len(whidden_shape), 2, Rel.EQ, "weight hidden shape rank", self.name)
7454
-
7455
- num_step, batch_size, input_size = x_shape
7456
- hidden_size = winput_shape[-1] // 3
7457
- if winput_shape[-1] % 3 != 0:
7458
- raise ValueError(f"For '{self.name}', the last dimension of 'w' must be a multiple of 3, "
7459
- f"but got {winput_shape[-1]}.")
7460
-
7461
- self.placeholder_index = [3, 4, 5]
7462
- if binput_shape is not None:
7463
- validator.check_int(len(binput_shape), 1, Rel.EQ, "bias input shape rank", self.name)
7464
- validator.check("bias_input_shape", binput_shape, "3 * hidden_shape", [3 * hidden_size], Rel.EQ, self.name)
7465
- self.placeholder_index.remove(3)
7466
- if bhidden_shape is not None:
7467
- validator.check_int(len(bhidden_shape), 1, Rel.EQ, "bias hidden shape rank", self.name)
7468
- validator.check("bias_hidden_shape", bhidden_shape,
7469
- "3 * hidden_shape", [3 * hidden_size], Rel.EQ, self.name)
7470
- self.placeholder_index.remove(4)
7471
- if seq_shape is not None:
7472
- raise ValueError(f"For '{self.name}', the dimension of 'seq_length' must be None, "
7473
- f"but got {seq_shape}.")
7474
-
7475
- validator.check_int(len(h_shape), 2, Rel.EQ, "init_h shape rank", self.name)
7476
- validator.check("init_h_shape[0]", h_shape[0], "batch_size", batch_size, Rel.EQ, self.name)
7477
- validator.check("init_h_shape[1]", h_shape[1], "hidden_size", hidden_size, Rel.EQ, self.name)
7478
- validator.check("weight_input_shape[-1]", winput_shape[-1], "weight_hidden_shape[-1]",
7479
- whidden_shape[-1], Rel.EQ, self.name)
7480
- validator.check("weight_input_shape[0]", winput_shape[0], "input_size", input_size, Rel.EQ, self.name)
7481
- validator.check("weight_hidden_shape[0]", whidden_shape[0], "hidden_size", hidden_size, Rel.EQ, self.name)
7482
- if self.num_proj > 0:
7483
- y_shape = (num_step, batch_size, min(hidden_size, self.num_proj))
7484
- else:
7485
- y_shape = (num_step, batch_size, hidden_size)
7486
- out_shape = (num_step, batch_size, hidden_size)
7487
- self.add_prim_attr("placeholder_index", self.placeholder_index)
7488
- return y_shape, out_shape, out_shape, out_shape, out_shape, out_shape
7489
-
7490
- def infer_dtype(self, x_dtype, winput_dtype, whidden_dtype, binput_dtype, bhidden_dtype, seq_dtype, h_dtype):
7491
- validator.check_tensor_dtype_valid("x dtype", x_dtype, [mstype.float16], self.name)
7492
- validator.check_tensor_dtype_valid("weight input dtype", winput_dtype, [mstype.float16], self.name)
7493
- validator.check_tensor_dtype_valid("weight hidden dtype", whidden_dtype, [mstype.float16], self.name)
7494
- valid_dtypes = [mstype.float16, mstype.float32]
7495
- validator.check_tensor_dtype_valid("init_h dtype", h_dtype, valid_dtypes, self.name)
7496
- b_dtype = h_dtype
7497
- if binput_dtype is not None:
7498
- args = {'init_h': h_dtype, 'bias_input': binput_dtype}
7499
- validator.check_tensors_dtypes_same_and_valid(args, valid_dtypes, self.name)
7500
- b_dtype = binput_dtype
7501
- if bhidden_dtype is not None:
7502
- args = {'init_h': h_dtype, 'bias_hidden': bhidden_dtype}
7503
- validator.check_tensors_dtypes_same_and_valid(args, valid_dtypes, self.name)
7504
- b_dtype = bhidden_dtype
7505
-
7506
- return b_dtype, b_dtype, b_dtype, b_dtype, b_dtype, b_dtype
7403
+ self.reset_after = validator.check_value_type("reset_after", reset_after, [bool], self.name)
7404
+ self.init_prim_io_names(
7405
+ inputs=[
7406
+ "x", "weight_input", "weight_hidden", "bias_input",
7407
+ "bias_hidden", "seq_length", "init_h"
7408
+ ],
7409
+ outputs=["y", "output_h", "update", "reset", "new", "hidden_new"])
7507
7410
 
7508
7411
 
7509
7412
  class InTopK(Primitive):
7510
7413
  r"""
7511
7414
  Determines whether the targets are in the top `k` predictions.
7512
7415
 
7513
- Refer to :func:`mindspore.ops.intopk` for more detail.
7416
+ Refer to :func:`mindspore.ops.intopk` for more details.
7514
7417
 
7515
7418
  Supported Platforms:
7516
7419
  ``Ascend`` ``GPU`` ``CPU``
@@ -7531,7 +7434,7 @@ class InTopK(Primitive):
7531
7434
  validator.check_value_type("k", k, [int], self.name)
7532
7435
 
7533
7436
 
7534
- class LRN(PrimitiveWithInfer):
7437
+ class LRN(Primitive):
7535
7438
  r"""
7536
7439
  Local Response Normalization.
7537
7440
 
@@ -7540,7 +7443,7 @@ class LRN(PrimitiveWithInfer):
7540
7443
  b_{c} = a_{c}\left(k + \frac{\alpha}{n}
7541
7444
  \sum_{c'=\max(0, c-n/2)}^{\min(N-1,c+n/2)}a_{c'}^2\right)^{-\beta}
7542
7445
 
7543
- 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;
7544
7447
  where the :math:`n/2` indicates the `depth_radius`; where the :math:`k` indicates the `bias`;
7545
7448
  where the :math:`\alpha` indicates the `alpha`; where the :math:`\beta` indicates the `beta`.
7546
7449
 
@@ -7630,10 +7533,10 @@ class AvgPool3D(Primitive):
7630
7533
 
7631
7534
  - pad: Implicit paddings on both sides of the input in depth, height, width. The number of `pad` will
7632
7535
  be padded to the input Tensor borders. `pad` must be greater than or equal to 0.
7633
- pad (Union(int, tuple[int])): The pad value to be filled. Default: 0. If `pad` is an integer, the paddings of
7634
- head, tail, top, bottom, left and right are the same, equal to pad. If `pad` is a tuple of six
7635
- integers, the padding of head, tail, top, bottom, left and right equal to pad[0], pad[1], pad[2],
7636
- 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.
7637
7540
  ceil_mode (bool): If True, ceil instead of floor to compute the output shape. Default: False.
7638
7541
  count_include_pad (bool): If True, averaging calculation will include the zero-padding. Default: True.
7639
7542
  divisor_override (int): If specified, it will be used as divisor in the averaging calculation,
@@ -7661,7 +7564,7 @@ class AvgPool3D(Primitive):
7661
7564
  ValueError: If `data_format` is not 'NCDHW'.
7662
7565
 
7663
7566
  Supported Platforms:
7664
- ``Ascend`` ``CPU``
7567
+ ``Ascend`` ``GPU`` ``CPU``
7665
7568
 
7666
7569
  Examples:
7667
7570
  >>> x = Tensor(np.arange(1 * 2 * 2 * 2 * 3).reshape((1, 2, 2, 2, 3)), mindspore.float16)
@@ -7681,7 +7584,7 @@ class AvgPool3D(Primitive):
7681
7584
  self.add_prim_attr('kernel_size', self.kernel_size)
7682
7585
  self.strides = _check_3d_int_or_tuple('strides', strides, self.name, ret_five=True)
7683
7586
  self.add_prim_attr('strides', self.strides)
7684
- validator.check_value_type('pad', pad, (int, tuple), self.name)
7587
+ validator.check_value_type('pad', pad, (int, tuple, list), self.name)
7685
7588
  if isinstance(pad, int):
7686
7589
  pad = (pad,) * 6
7687
7590
  if len(pad) != 6:
@@ -7711,9 +7614,9 @@ class Conv3D(Primitive):
7711
7614
 
7712
7615
  Applies a 3D convolution over an input tensor which is typically of shape
7713
7616
  :math:`(N, C_{in}, D_{in}, H_{in}, W_{in})` and output shape
7714
- :math:`(N, C_{out}, D_{out}, H_{out}, W_{out})`. Where :math:`N` is batch size, :math:`C` is channel number,
7715
- :math:`D` is depth, :math:`H` is height, :math:`W` is width.
7716
- the formula is defined as:
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:
7717
7620
 
7718
7621
  .. math::
7719
7622
 
@@ -7721,7 +7624,21 @@ class Conv3D(Primitive):
7721
7624
  \sum_{k=0}^{C_{in}-1} ccor(\text {weight}\left(C_{\text {out}_j}, k\right),
7722
7625
  \operatorname{input}\left(N_{i}, k\right))
7723
7626
 
7724
- where :math:`k` is kernel, :math:`ccor` is the cross-correlation operator.
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>`_ .
7725
7642
 
7726
7643
  If the 'pad_mode' is set to be "valid", the output depth, height and width will be
7727
7644
  :math:`\left \lfloor{1 + \frac{D_{in} + 2 \times \text{padding} - \text{ks_d} -
@@ -7735,15 +7652,15 @@ class Conv3D(Primitive):
7735
7652
 
7736
7653
  Args:
7737
7654
  out_channel (int): The number of output channel :math:`C_{out}`.
7738
- kernel_size (Union[int, tuple[int]]): The data type is int or a tuple of 3 integers. Specifies the depth, height
7739
- and width of the 3D convolution window. Single int means the value is for the depth, height and width
7740
- of the kernel. A tuple of 3 ints means the first value is for the depth, height and the other is for the
7741
- width of the kernel.
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.
7742
7659
  mode (int): Modes for different convolutions. It is currently not used. Default: 1.
7743
- stride (Union[int, tuple[int]]): The distance of kernel moving, an int number that represents
7744
- the depth, height and width of movement are both strides, or a tuple of three int numbers that
7745
- represent depth, height and width of movement respectively. Default: 1.
7746
- pad_mode (str): Specifies padding mode. The optional values are
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
7747
7664
  "same", "valid" and "pad". Default: "valid".
7748
7665
 
7749
7666
  - same: Adopts the way of completion. The depth, height and width of the output will be equal to
@@ -7763,15 +7680,14 @@ class Conv3D(Primitive):
7763
7680
  head, tail, top, bottom, left and right are the same, equal to pad. If `pad` is a tuple of six
7764
7681
  integers, the padding of head, tail, top, bottom, left and right equal to pad[0], pad[1], pad[2],
7765
7682
  pad[3], pad[4] and pad[5] correspondingly.
7766
- dilation (Union[int, tuple[int]]): The data type is int or a tuple of 3 integers
7767
- :math:`(dilation_d, dilation_h, dilation_w)`.
7768
- Currently, dilation on depth only supports the case of 1.
7769
- Specifies the dilation rate to use for dilated convolution.
7770
- If set :math:`k > 1`, there will be :math:`k - 1` pixels skipped
7771
- for each sampling location. Its value must be greater than or equal to 1 and
7772
- bounded by the height and width of the input. Default: 1.
7773
- group (int): Splits filter into groups, `in_channels` and `out_channels` must be
7774
- divisible by the number of groups. Default: 1. Only 1 is currently supported.
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.
7775
7691
  data_format (str): The optional value for data format. Currently only support "NCDHW".
7776
7692
 
7777
7693
  Inputs:
@@ -7823,8 +7739,13 @@ class Conv3D(Primitive):
7823
7739
  self.kernel_size = _check_3d_int_or_tuple('kernel_size', kernel_size, self.name)
7824
7740
  self.stride = _check_3d_int_or_tuple('stride', stride, self.name, allow_five=False, ret_five=True)
7825
7741
  self.add_prim_attr('strides', self.stride)
7826
- self.dilation = _check_3d_int_or_tuple('dilation', dilation, self.name, allow_five=False,
7827
- ret_five=True, third_one=True)
7742
+ target = context.get_context("device_target")
7743
+ if target.lower() == "ascend":
7744
+ self.dilation = _check_3d_int_or_tuple('dilation', dilation, self.name, allow_five=False,
7745
+ ret_five=True, third_one=True)
7746
+ else:
7747
+ self.dilation = _check_3d_int_or_tuple('dilation', dilation, self.name, allow_five=False,
7748
+ ret_five=True, third_one=False)
7828
7749
  self.add_prim_attr('dilations', self.dilation)
7829
7750
  validator.check_value_type('pad', pad, (int, tuple), self.name)
7830
7751
  if isinstance(pad, int):
@@ -7850,7 +7771,13 @@ class Conv3D(Primitive):
7850
7771
  self.format = validator.check_string(data_format, ['NCDHW'], 'data_format', self.name)
7851
7772
  self.add_prim_attr('data_format', self.format)
7852
7773
  self.out_channel = validator.check_positive_int(out_channel, 'out_channel', self.name)
7853
- self.group = validator.check_equal_int(group, 1, 'group', self.name)
7774
+ validator.check_value_type("group", group, (int,), 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
+
7780
+ self.group = group
7854
7781
  self.add_prim_attr('groups', self.group)
7855
7782
  self.add_prim_attr('offset_x', 0)
7856
7783
 
@@ -8071,7 +7998,7 @@ class SparseApplyAdadelta(Primitive):
8071
7998
  def __init__(self, epsilon, use_locking=False):
8072
7999
  """Initialize SparseApplyAdadelta"""
8073
8000
  validator.check_value_type("epsilon", epsilon, [float], self.name)
8074
- validator.check_number("epsilon", epsilon, 0.0, Rel.GE, self.name)
8001
+ validator.check_number("epsilon", epsilon, 0.0, validator.GE, self.name)
8075
8002
  validator.check_value_type("use_locking", use_locking, [bool], self.name)
8076
8003
 
8077
8004
 
@@ -8082,46 +8009,54 @@ class CTCLossV2(Primitive):
8082
8009
  The CTC algorithm is proposed in `Connectionist Temporal Classification: Labeling Unsegmented Sequence Data with
8083
8010
  Recurrent Neural Networks <http://www.cs.toronto.edu/~graves/icml_2006.pdf>`_.
8084
8011
 
8012
+ .. warning::
8013
+ This is an experimental API that is subject to change or deletion.
8014
+
8085
8015
  Args:
8086
- blank (int): The blank label. Default: 0.
8087
- reduction (string): Apply specific reduction method to the output. Currently only support 'none',
8016
+ blank (int, optional): The blank label. Default: 0.
8017
+ reduction (str, optional): Apply specific reduction method to the output. Currently only support 'none',
8088
8018
  not case sensitive. Default: "none".
8089
- zero_infinity (bool): 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.
8090
8021
 
8091
8022
  Inputs:
8092
- - **log_probs** (Tensor) - A tensor of shape (T, N, C), where T is input length, N is batch size and C is number
8093
- of classes (including blank).
8094
- - **targets** (Tensor) - A tensor of shape (N, S), where S is max target length, means the target sequences.
8095
- - **input_lengths** (Union(Tuple, Tensor)) - A tuple or Tensor of shape(N). It means the lengths of the input.
8096
- - **target_lengths** (Union(Tuple, Tensor)) - A tuple or Tensor of shape(N). It means the lengths of the target.
8023
+ - **log_probs** (Tensor) - A tensor of shape :math:`(T, C, N)`, where :math:`T` is input length, :math:`N` is
8024
+ batch size and :math:`C` is number of classes (including blank).
8025
+ - **targets** (Tensor) - A tensor of shape :math:`(N, S)`, where :math:`S` is max target length,
8026
+ means the target sequences.
8027
+ - **input_lengths** (Union(Tuple, Tensor)) - A tuple or Tensor of shape :math:`(N)`.
8028
+ It means the lengths of the input.
8029
+ - **target_lengths** (Union(Tuple, Tensor)) - A tuple or Tensor of shape :math:`(N)`.
8030
+ It means the lengths of the target.
8097
8031
 
8098
8032
  Outputs:
8099
8033
  - **neg_log_likelihood** (Tensor) - A loss value which is differentiable with respect to each input node.
8100
8034
  - **log_alpha** (Tensor) - The probability of possible trace of input to target.
8101
8035
 
8102
8036
  Raises:
8103
- TypeError: If `zero_infinity` is not a bool, reduction is not string.
8037
+ TypeError: If `zero_infinity` is not a bool.
8038
+ TypeError: If `reduction` is not string.
8104
8039
  TypeError: If the dtype of `log_probs` is not float or double.
8105
8040
  TypeError: If the dtype of `targets`, `input_lengths` or `target_lengths` is not int32 or int64.
8106
- RuntimeError: If the rank of `log_probs` is not 3.
8107
- RuntimeError: If the rank of `targets` is not 2.
8108
- RuntimeError: If the shape of `input_lengths` does not match {batch_size|N}.
8109
- RuntimeError: If the shape of `target_lengths` does not match {batch_size|N}.
8110
- RuntimeError: If the types of `targets`, `input_lengths` or `target_lengths` are different.
8111
- RuntimeError: If the value of `blank` is not in range [0, num_labels|C).
8112
- RuntimeError: If any value of `input_lengths` is larger than (time_series|T).
8113
- RuntimeError: If any target_lengths[i] is not in range [0, input_length[i]].
8041
+ ValueError: If the rank of `log_probs` is not 3.
8042
+ ValueError: If the rank of `targets` is not 2.
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`.
8045
+ TypeError: If the types of `targets`, `input_lengths` or `target_lengths` are different.
8046
+ ValueError: If the value of `blank` is not in range [0, num_labels|C).
8047
+ RuntimeError: If any value of `input_lengths` is larger than (num_labels|C).
8048
+ RuntimeError: If any `target_lengths[i]` is not in range [0, `input_length[i]`].
8114
8049
 
8115
8050
  Supported Platforms:
8116
- ``Ascend`` ``CPU``
8051
+ ``Ascend`` ``GPU`` ``CPU``
8117
8052
 
8118
8053
  Examples:
8119
8054
  >>> log_probs = Tensor(np.array([[[0.3, 0.6, 0.6]],
8120
- [[0.9, 0.4, 0.2]]]).astype(np.float32))
8055
+ ... [[0.9, 0.4, 0.2]]]).astype(np.float32))
8121
8056
  >>> targets = Tensor(np.array([[0, 1]]), mstype.int32)
8122
8057
  >>> input_lengths = Tensor(np.array([2]), mstype.int32)
8123
8058
  >>> target_lengths = Tensor(np.array([1]), mstype.int32)
8124
- >>> CTCLossV2 = op.CTCLossV2(blank=0, reduction='none', zero_infinity=False)
8059
+ >>> CTCLossV2 = ops.CTCLossV2(blank=0, reduction='none', zero_infinity=False)
8125
8060
  >>> neg_log_hood, log_alpha = CTCLossV2(
8126
8061
  ... log_probs, targets, input_lengths, target_lengths)
8127
8062
  >>> print(neg_log_hood)
@@ -8132,7 +8067,7 @@ class CTCLossV2(Primitive):
8132
8067
  """
8133
8068
 
8134
8069
  @prim_attr_register
8135
- def __init__(self, blank, reduction="none", zero_infinity=False):
8070
+ def __init__(self, blank=0, reduction="none", zero_infinity=False):
8136
8071
  """Initialize CTCLossV2"""
8137
8072
  self.init_prim_io_names(inputs=["log_probs", "targets", "input_lengths", "target_lengths"],
8138
8073
  outputs=["neg_log_likelihood", "log_alpha"])
@@ -8362,17 +8297,19 @@ class Conv3DTranspose(Primitive):
8362
8297
  f"when 'pad_mode' is not \"pad\", but got 'output_padding' is "
8363
8298
  f"{output_padding} and 'pad_mode' is {pad_mode}.")
8364
8299
  self.add_prim_attr('output_padding', self.output_padding)
8365
- validator.check_int_range(self.kernel_size[0] * self.kernel_size[1] * self.kernel_size[2], 1, 343, Rel.INC_BOTH,
8366
- 'The product of height, width and depth of kernel_size belonging [1, 343]', self.name)
8367
- 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,
8368
8305
  'The product of height, width and depth of stride belonging [1, 343]', self.name)
8369
- 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,
8370
8307
  'The product of height, width and depth of stride belonging [1, 256]', self.name)
8371
- 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,
8372
8309
  'output_padding_d belonging [0, max(stride_d, dilation_d))', self.name)
8373
- 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,
8374
8311
  'output_padding_h belonging [0, max(stride_h,dilation_h))', self.name)
8375
- 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,
8376
8313
  'output_padding_w belonging [0, max(stride_w,dilation_w))', self.name)
8377
8314
 
8378
8315
 
@@ -8390,7 +8327,9 @@ class Dilation2D(Primitive):
8390
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)
8391
8328
 
8392
8329
  .. warning::
8393
- This operator is an experimental operator, which has some accuracy problems for some inputs.
8330
+ This is an experimental API that is subjected to change or deletion.
8331
+
8332
+ Note:
8394
8333
  If the input data type is float32, this operator is still executed in float16 mode.
8395
8334
 
8396
8335
  Args:
@@ -8405,7 +8344,7 @@ class Dilation2D(Primitive):
8405
8344
  each sampling location. Its value must be greater or equal to 1 and bounded by
8406
8345
  the height and width of the input `x`.
8407
8346
 
8408
- pad_mode (str): Specifies padding mode. The optional values are
8347
+ pad_mode (str, optional): Specifies padding mode. The optional values are
8409
8348
  "same", "valid". Default: "same". Both upper and lower case are supported.
8410
8349
 
8411
8350
  - same: Adopts the way of completion. The height and width of the output will be the same as
@@ -8413,10 +8352,10 @@ class Dilation2D(Primitive):
8413
8352
 
8414
8353
  - valid: Adopts the way of discarding. The possible largest height and width of output will be returned
8415
8354
  without padding. Extra pixels will be discarded.
8416
- 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".
8417
8356
 
8418
8357
  Inputs:
8419
- - **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
8420
8359
  :math:`(N, C_{in}, H_{in}, W_{in})`.
8421
8360
  - **filter** (Tensor) - A three dimension tensor with the same type as input. The shape must be
8422
8361
  :math:`(C_{in}, H_{filter}, W_{filter})`.
@@ -8426,7 +8365,7 @@ class Dilation2D(Primitive):
8426
8365
  is not necessarily the same as the input x, the type is the same as the input x.
8427
8366
 
8428
8367
  Raises:
8429
- TypeError: If type of `x` or `filter` is not the tpye in [uint8, uint16, uint32, uint64, int8, int16,
8368
+ TypeError: If type of `x` or `filter` is not the type in [uint8, uint16, uint32, uint64, int8, int16,
8430
8369
  int32, int64, float16, float32, float64].
8431
8370
  TypeError: If `stride` or `dilation` is not an int number or a tuple of two or four int numbers.
8432
8371
  ValueError: If the length of `stride` or `dilation` is neither two nor four when they are tuple.
@@ -8437,7 +8376,7 @@ class Dilation2D(Primitive):
8437
8376
  ValueError: If `data_format` is not the str of 'NCHW'.
8438
8377
 
8439
8378
  Supported Platforms:
8440
- ``Ascend`` ``GPU``
8379
+ ``GPU`` ``CPU``
8441
8380
 
8442
8381
  Examples:
8443
8382
  >>> x = Tensor(np.ones([10, 5, 32, 32]), mindspore.float16)
@@ -8502,10 +8441,10 @@ class SoftShrink(Primitive):
8502
8441
  r"""
8503
8442
  Applies the SoftShrink function element-wise.
8504
8443
 
8505
- Refer to :func:`mindspore.ops.soft_shrink` for more detail.
8444
+ Refer to :func:`mindspore.ops.softshrink` for more details.
8506
8445
 
8507
8446
  Supported Platforms:
8508
- ``Ascend`` ``CPU`` ``GPU``
8447
+ ``Ascend`` ``GPU`` ``CPU``
8509
8448
 
8510
8449
  Examples:
8511
8450
  >>> import mindspore
@@ -8523,17 +8462,17 @@ class SoftShrink(Primitive):
8523
8462
  def __init__(self, lambd=0.5):
8524
8463
  """Initialize SoftShrink"""
8525
8464
  validator.check_value_type("lambd", lambd, [float], self.name)
8526
- validator.check_number("lambd", lambd, 0, Rel.GE, self.name)
8465
+ validator.check_number("lambd", lambd, 0, validator.GE, self.name)
8527
8466
 
8528
8467
 
8529
8468
  class HShrink(Primitive):
8530
8469
  r"""
8531
8470
  Hard Shrink activation function.
8532
8471
 
8533
- Refer to :func:`mindspore.ops.hardshrink` for more detail.
8472
+ Refer to :func:`mindspore.ops.hardshrink` for more details.
8534
8473
 
8535
8474
  Supported Platforms:
8536
- ``Ascend`` ``CPU`` ``GPU``
8475
+ ``Ascend`` ``GPU`` ``CPU``
8537
8476
 
8538
8477
  Examples:
8539
8478
  >>> import mindspore as ms
@@ -8590,9 +8529,9 @@ class ApplyAdagradDA(Primitive):
8590
8529
  Inputs:
8591
8530
  - **var** (Parameter) - Variable to be updated. The data type must be float16 or float32.
8592
8531
  The shape is :math:`(N, *)` where :math:`*` means, any number of additional dimensions.
8593
- - **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
8594
8533
  shape and dtype as `var`.
8595
- - **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`.
8596
8535
  Must have the same shape and dtype as `var`.
8597
8536
  - **grad** (Tensor) - A tensor for gradient. Must have the same shape and dtype as `var`.
8598
8537
  - **lr** ([Number, Tensor]) - Scaling factor. Must be a scalar. With float32 or float16 data type.
@@ -8695,11 +8634,11 @@ class SparseApplyRMSProp(Primitive):
8695
8634
  the relatively highest priority data type.
8696
8635
 
8697
8636
  Args:
8698
- rho (float): Decay rate. The value should between 0 and 1, otherwise the behavior is undefined.
8637
+ rho (float): Decay rate. The value should be between 0 and 1, otherwise the behavior is undefined.
8699
8638
  momentum (float): Momentum. The value should be greater or equal to 0, otherwise the behavior is undefined.
8700
8639
  epsilon (float): A small value added for numerical stability. The value should be greater than 0,
8701
8640
  otherwise the behavior is undefined.
8702
- use_locking (bool): If `True`, updating of the var, ms, and mom tensors is protected by a lock;
8641
+ use_locking (bool): If `True`, updating of the var, ms, and mom tensors are protected by a lock;
8703
8642
  otherwise the behavior is undefined, but may exhibit less contention. Default: False.
8704
8643
 
8705
8644
  Inputs:
@@ -8738,7 +8677,7 @@ class SparseApplyRMSProp(Primitive):
8738
8677
  RuntimeError: If the data type of `var`, `ms`, `mom` and `grad` conversion of Parameter is not supported.
8739
8678
 
8740
8679
  Supported Platforms:
8741
- ``Ascend``
8680
+ ``Ascend`` ``GPU`` ``CPU``
8742
8681
 
8743
8682
  Examples:
8744
8683
  >>> class SparseApplyRMSPropNet(nn.Cell):
@@ -8786,9 +8725,9 @@ class SparseApplyRMSProp(Primitive):
8786
8725
  validator.check_value_type("momentum", momentum, [float], self.name)
8787
8726
  validator.check_value_type("epsilon", epsilon, [float], self.name)
8788
8727
  validator.check_value_type("use_locking", use_locking, [bool], self.name)
8789
- self.epsilon = validator.check_number("epsilon", epsilon, 0.0, Rel.GT, self.name)
8790
- self.momentum = validator.check_number("momentum", momentum, 0.0, Rel.GE, self.name)
8791
- 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)
8792
8731
 
8793
8732
 
8794
8733
  class SparseApplyCenteredRMSProp(Primitive):
@@ -8855,13 +8794,9 @@ class SparseApplyCenteredRMSProp(Primitive):
8855
8794
  ValueError: If shape of `grad` is not same as shape of `var` except first dimension.
8856
8795
 
8857
8796
  Supported Platforms:
8858
- ``Ascend`` ``CPU``
8797
+ ``Ascend`` ``GPU`` ``CPU``
8859
8798
 
8860
8799
  Examples:
8861
- >>> import numpy as np
8862
- >>> from mindspore import Tensor
8863
- >>> import mindspore.common.dtype as mstype
8864
- >>> import mindspore.ops.operations.nn_ops as nn_ops
8865
8800
  >>> var = Tensor(np.array([[0.6, 0.4], [0.1, 0.5]]).astype(np.float32))
8866
8801
  >>> mg = Tensor(np.array([[0.1, 0.3], [0.1, 0.5]]).astype(np.float32))
8867
8802
  >>> ms = Tensor(np.array([[0.2, 0.1], [0.1, 0.2]]).astype(np.float32))
@@ -8880,10 +8815,10 @@ class SparseApplyCenteredRMSProp(Primitive):
8880
8815
  """
8881
8816
 
8882
8817
  __mindspore_signature__ = (
8883
- sig.make_sig('var', dtype=sig.sig_dtype.T),
8884
- sig.make_sig('mg', dtype=sig.sig_dtype.T),
8885
- sig.make_sig('ms', dtype=sig.sig_dtype.T),
8886
- 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),
8887
8822
  sig.make_sig('lr', dtype=sig.sig_dtype.T),
8888
8823
  sig.make_sig('rho', dtype=sig.sig_dtype.T),
8889
8824
  sig.make_sig('momentum', dtype=sig.sig_dtype.T),
@@ -8998,53 +8933,15 @@ class ApplyKerasMomentum(Primitive):
8998
8933
 
8999
8934
  class MultilabelMarginLoss(Primitive):
9000
8935
  r"""
9001
- MultilabelMarginLoss operation.
9002
-
9003
- Creates a criterion that optimizes a multi-class multi-classification
9004
- hinge loss (margin-based loss) between input :math:`x` (a 2D mini-batch `Tensor`)
9005
- and output :math:`y` (which is a 2D `Tensor` of target class indices).
9006
- For each sample in the mini-batch:
9007
-
9008
- .. math::
9009
- \text{loss}(x, y) = \sum_{ij}\frac{\max(0, 1 - (x[y[j]] - x[i]))}{\text{x.size}(0)}
9010
-
9011
- where :math:`x \in \left\{0, \; \cdots , \; \text{x.size}(0) - 1\right\}`, \
9012
- :math:`y \in \left\{0, \; \cdots , \; \text{y.size}(0) - 1\right\}`, \
9013
- :math:`0 \leq y[j] \leq \text{x.size}(0)-1`, \
9014
- and :math:`i \neq y[j]` for all :math:`i` and :math:`j`.
9015
-
9016
- :math:`y` and :math:`x` must have the same size.
9017
-
9018
- The criterion only considers a contiguous block of non-negative targets that
9019
- starts at the front.
9020
-
9021
- This allows for different samples to have variable amounts of target classes.
9022
-
9023
- Args:
9024
- reduction (str): Apply specific reduction method to the output: 'none', 'mean', 'sum'. Default: "mean".
9025
-
9026
- Inputs:
9027
- - **x** (Tensor) - Predict data. Tensor of shape :math:`(C)` or :math:`(N, C)`, where :math:`N`
9028
- is the batch size and :math:`C` is the number of classes. Data type must be float16 or float32.
9029
- - **target** (Tensor) - Ground truth data, with the same shape as `x`, data type must be int32 and
9030
- label targets padded by -1.
9031
-
9032
- Outputs:
9033
- - **y** (Union[Tensor, Scalar]) - The loss of MultilabelMarginLoss. If `reduction` is "none", its shape
9034
- is :math:`(N)`. Otherwise, a scalar value will be returned.
9035
- - **is_target** (Tensor) - Output tensor for backward input, with the same shape as `target`,
9036
- data type must be int32.
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.
9037
8940
 
9038
- Raises:
9039
- TypeError: If `x` or `target` is not a Tensor.
9040
- TypeError: If dtype of `x` is neither float16 nor float32.
9041
- TypeError: If dtype of `target` is not int32.
9042
- ValueError: If length of shape of `x` is neither 1 nor 2.
9043
- ValueError: If shape of `x` is not the same as `target`.
9044
- ValueError: If `reduction` is not one of 'none', 'mean', 'sum'.
8941
+ Refer to :func:`mindspore.ops.multilabel_margin_loss` for more details.
9045
8942
 
9046
8943
  Supported Platforms:
9047
- ``Ascend``
8944
+ ``Ascend`` ``GPU``
9048
8945
 
9049
8946
  Examples:
9050
8947
  >>> loss = ops.MultilabelMarginLoss()
@@ -9117,7 +9014,7 @@ class ApplyAdamWithAmsgrad(Primitive):
9117
9014
  ValueError: If the shape of `beta1_power`, `beta2_power`, `lr` is not 0.
9118
9015
 
9119
9016
  Supported Platforms:
9120
- ``Ascend`` ``CPU`` ``GPU``
9017
+ ``Ascend`` ``GPU`` ``CPU``
9121
9018
 
9122
9019
  Examples:
9123
9020
  >>> class ApplyAdamWithAmsgradNet(nn.Cell):
@@ -9163,57 +9060,16 @@ class ApplyAdamWithAmsgrad(Primitive):
9163
9060
 
9164
9061
  class GridSampler3D(Primitive):
9165
9062
  """
9166
- Given an `input_x` and a flow-field `grid`, computes the `output` using `input_x` values and pixel locations from
9167
- `grid`. Only volumetric (5-D) `input_x` is supported.
9168
-
9169
- For `input_x` with shape :math:`(N, C, D_{in}, H_{in}, W_{in})` and `grid` with shape :math:`(N, D_{out}, H_{out},
9170
- W_{out}, 3)`, the `output` will have shape :math:`(N, C, D_{out}, H_{out}, W_{out})`.
9171
-
9172
- For each output location `output[n, :, d, h, w]`, the size-3 vector `grid[n, d, h, w]` specifies `input_x` pixel
9173
- locations x, y, z, which are used to interpolate the output value `output[n, :, d, h, w]`. And `interpolation_mode`
9174
- argument specifies "nearest" or "bilinear" interpolation method to sample the input pixels.
9175
-
9176
- `grid` specifies the sampling pixel locations normalized by the `input_x` spatial dimensions. Therefore, it should
9177
- have most values in the range of :math:`[-1, 1]`.
9178
-
9179
- If `grid` has values outside the range of :math:`[-1, 1]`, the corresponding outputs are handled as defined by
9180
- `padding_mode`. If `padding_mode` is set to be "zeros", use :math:`0` for out-of-bound grid locations. If
9181
- `padding_mode` is set to be "border", use border values for out-of-bound grid locations. If `padding_mode` is set
9182
- to be "reflection", use values at locations reflected by the border for out-of-bound grid locations. For location
9183
- far away from the border, it will keep being reflected until becoming in bound.
9184
-
9185
- Args:
9186
- interpolation_mode (str): An optional string specifying the interpolation method. The optional values are
9187
- "bilinear" or "nearest". Default: "bilinear".
9188
- padding_mode (str): An optional string specifying the pad method. The optional values are "zeros", "border" or
9189
- "reflection". Default: "zeros".
9190
- align_corners (bool): An optional bool. If set to `True`, the extrema (-1 and 1) are considered as referring to
9191
- the center points of the input’s corner pixels. If set to `False`, they are instead considered as referring
9192
- to the corner points of the input’s corner pixels, making the sampling more resolution agnostic. Default:
9193
- `False`.
9194
-
9195
- Inputs:
9196
- - **input_x** (Tensor) - A 5-D tensor with dtype of float32 or float64 and shape of :math:`(N, C, D_{in},
9197
- H_{in}, W_{in})`.
9198
- - **grid** (Tensor) - A 5-D tensor whose dtype is the same as `input_x` and whose shape is :math:`(N, D_{out},
9199
- H_{out}, W_{out}, 3)`.
9063
+ Given an input and a grid, the output is calculated using the input values
9064
+ and pixel positions in the grid. Only volume (5-D) input is supported.
9200
9065
 
9201
- Outputs:
9202
- A 5-D Tensor whose dtype is the same as `input_x` and whose shape is :math:`(N, C, D_{out}, H_{out}, W_{out})`.
9066
+ .. warning::
9067
+ This is an experimental API that is subject to change or deletion.
9203
9068
 
9204
- Raises:
9205
- TypeError: If `input_x` or `grid` is not a Tensor.
9206
- TypeError: If the dtypes of `input_x` and `grid` are inconsistent.
9207
- TypeError: If the dtype of `input_x` or `grid` is not a valid type.
9208
- TypeError: If `align_corners` is not a boolean value.
9209
- ValueError: If the rank of `input_x` or `grid` is not equal to 5.
9210
- ValueError: If the first dimension of `input_x` is not equal to that of `grid`.
9211
- ValueError: If the last dimension of `grid` is not equal to 3.
9212
- ValueError: If `interpolation_mode` is not "bilinear", "nearest" or a string value.
9213
- ValueError: If `padding_mode` is not "zeros", "border", "reflection" or a string value.
9069
+ Refer to :func:`mindspore.ops.grid_sample` for more details.
9214
9070
 
9215
9071
  Supported Platforms:
9216
- ``Ascend`` ``CPU`` ``GPU``
9072
+ ``Ascend`` ``GPU`` ``CPU``
9217
9073
 
9218
9074
  Examples:
9219
9075
  >>> gridsampler = ops.GridSampler3D(interpolation_mode='bilinear', padding_mode='zeros', align_corners=True)
@@ -9247,33 +9103,40 @@ class FractionalMaxPool(Primitive):
9247
9103
  r"""
9248
9104
  Performs fractional max pooling on the input.
9249
9105
 
9250
- Fractional max pooling is similar to regular max pooling, In regular max pooling, you downsize an
9251
- input set by taking the maximum value of smaller N x N subsections of the set (often 2x2), and try
9252
- to reduce the set by a factor of N, where N is an integer. Fractional max pooling, means that the
9253
- overall reduction ratio N does not have to be an integer.
9254
- 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.
9255
9112
 
9256
9113
  .. warning::
9257
9114
  "pooling_ratio", currently only supports row and col dimension and should be >= 1.0, the first
9258
- 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.
9259
9116
 
9260
9117
  Args:
9261
- pooling_ratio (list(float)): Decide the shape of output, is a list of floats that has length >= 4.
9262
- Pooling ratio for each dimension of value should be >=0, currently only support for row and col
9263
- dimension. The first and last elements must be 1.0 because we don't allow pooling on batch and
9264
- channels dimensions.
9265
- pseudo_random(bool): An optional bool. Defaults to False. When set to True, generates the pooling
9266
- sequence in a pseudo random fashion, otherwise, in a random fashion.
9267
- Check paper Benjamin Graham, Fractional Max-Pooling for difference between pseudo_random and
9268
- random.
9269
- overlapping(bool): An optional bool. Defaults to False. When set to True, it means when pooling,
9270
- the values at the boundary of adjacent pooling cells are used by both cells.
9271
- deterministic(bool): An optional bool. Defaults to False. When set to True, a fixed pooling region
9272
- will be used when iterating over a FractionalMaxPool node in the computation graph. Mainly
9273
- used in unit test to make FractionalMaxPool deterministic.
9274
- seed(int): An optional int. Defaults to 0. If either seed or seed2 are set to be non-zero, the
9275
- random number generator is seeded by the given seed. Otherwise, it is seeded by a random seed.
9276
- seed2(int): An optional int. Defaults to 0. An second seed to avoid seed collision.
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.
9277
9140
 
9278
9141
  Inputs:
9279
9142
  - **x** (Tensor) -The data type must be one of the following types: float32, float64, int32, int64.
@@ -9326,9 +9189,10 @@ class FractionalMaxPool(Primitive):
9326
9189
 
9327
9190
  class FractionalMaxPool3DWithFixedKsize(Primitive):
9328
9191
  r"""
9329
- This operator applies a 3D fractional max pooling over an input signal composed of several input planes.
9330
- The max-pooling operation is applied in kD x kH x kW regions by a stochastic step size determined
9331
- 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
+
9332
9196
  The number of output features is equal to the number of input planes.
9333
9197
 
9334
9198
  Refer to the paper `Fractional MaxPooling by Ben Graham <https://arxiv.org/abs/1412.6071>`_ for more details.
@@ -9337,34 +9201,27 @@ class FractionalMaxPool3DWithFixedKsize(Primitive):
9337
9201
  D the feature depth, H is the feature height, and W is the feature width.
9338
9202
 
9339
9203
  Args:
9340
- ksize (Union[float, tuple]): The target ksize is D x H x W.
9341
- ksize can be a tuple, or a single K for K x K x K.
9342
- specifying the window size (D, H, W) of the input tensor.
9343
-
9344
- output_shape (Union[int, tuple]): The target output_shape is D x H x W.
9345
- output_shape can be a tuple, or a single H for H x H x H.
9346
- specifying the size (D, H, W) of the output tensor.
9347
-
9348
- 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.
9349
9209
  Currently support 'NCDHW' and 'NHDWC'. Default: 'NCDHW'.
9350
9210
 
9351
9211
  Inputs:
9352
9212
  - **x** (Tensor) - The input of FractionalMaxPool3DWithFixedKsize, which is a 4D or 5D tensor.
9353
9213
  Tensor of data type : float16, float32, double, int32, int64.
9354
9214
  Supported shape :math:`(N, C, D_{in}, H_{in}, W_{in})` or :math:`(N, D_{in}, H_{in}, W_{in}, C)`.
9355
-
9356
9215
  - **random_samples** (Tensor) - The random step of FractionalMaxPool3DWithFixedKsize, which is a 3D tensor.
9357
9216
  Tensor of data type : float16, float32, double, and value is between (0, 1).
9358
9217
  Supported shape :math:`(N, C, 3)`
9359
9218
 
9360
9219
  Outputs:
9361
- Outputs:
9362
9220
  - **y** (Tensor) - A tensor, the output of FractionalMaxPool3DWithFixedKsize.
9363
- Has the same data type with `x`.
9364
- Tensor of shape :math:`(N, C, D_{out}, H_{out}, W_{out})` or :math:`(N, D_{out}, H_{out}, W_{out}, C)`.
9365
-
9221
+ Has the same data type with `x`.
9222
+ Tensor of shape :math:`(N, C, D_{out}, H_{out}, W_{out})` or :math:`(N, D_{out}, H_{out}, W_{out}, C)`.
9366
9223
  - **argmax** (Tensor) - A tensor, the indices along with the outputs.
9367
- Has the same shape as the `y` and int32 or int64 data type.
9224
+ Has the same shape as the `y` and int32 or int64 data type.
9368
9225
 
9369
9226
  Raises:
9370
9227
  TypeError: If `input_x` is not a 4D or 5D tensor.
@@ -9387,7 +9244,7 @@ class FractionalMaxPool3DWithFixedKsize(Primitive):
9387
9244
  >>> x = Tensor(np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])
9388
9245
  ... .reshape([1, 1, 2, 2, 4]), mstype.float32)
9389
9246
  >>> random_samples = Tensor(np.array([0.7, 0.7, 0.7]).reshape([1, 1, 3]), mstype.float32)
9390
- >>> ksize = (1.0, 1.0, 1.0)
9247
+ >>> ksize = (1, 1, 1)
9391
9248
  >>> output_shape = (1, 1, 2)
9392
9249
  >>> net = ops.FractionalMaxPool3DWithFixedKsize(ksize = ksize, output_shape = output_shape)
9393
9250
  >>> output, argmax = net(x, random_samples)
@@ -9401,15 +9258,15 @@ class FractionalMaxPool3DWithFixedKsize(Primitive):
9401
9258
  def __init__(self, ksize, output_shape, data_format="NCDHW"):
9402
9259
  """Initialize FractionalMaxPool3DWithFixedKsize."""
9403
9260
  self.init_prim_io_names(inputs=["x", "random_samples"], outputs=["y", "argmax"])
9404
- validator.check_value_type("ksize", ksize, [float, tuple], self.name)
9261
+ validator.check_value_type("ksize", ksize, [int, tuple], self.name)
9405
9262
  self.ksize = ksize
9406
- if isinstance(self.ksize, float):
9263
+ if isinstance(self.ksize, int):
9407
9264
  self.ksize = (ksize, ksize, ksize)
9408
9265
  if len(self.ksize) != 3:
9409
- raise ValueError(f"For '{self.name}', attr 'ksize' must be an positive float number or a tuple of "
9410
- 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.")
9411
9268
  for item in self.ksize:
9412
- validator.check_positive_float(item, 'ksize item', self.name)
9269
+ validator.check_positive_int(item, 'ksize item', self.name)
9413
9270
  self.output_shape = validator.check_value_type("output_shape", output_shape, [int, tuple], self.name)
9414
9271
  self.data_format = validator.check_string(data_format, ['NCDHW', 'NDHWC'], 'data_format', self.name)
9415
9272
  self.output_shape = _check_3d_int_or_tuple("output_shape", output_shape,
@@ -9422,11 +9279,10 @@ class FractionalAvgPool(Primitive):
9422
9279
  r"""
9423
9280
  Performs fractional avg pooling on the input.
9424
9281
 
9425
- Fractional avg pooling is similar to regular avg pooling, In regular avg pooling, you downsize an
9426
- input set by taking the avgrage value of smaller N x N subsections of the set (often 2x2), and try
9427
- to reduce the set by a factor of N, where N is an integer. Fractional avg pooling, means that the
9428
- overall reduction ratio N does not have to be an integer. In each pooling region, a mean operation
9429
- 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.
9430
9286
 
9431
9287
  .. warning::
9432
9288
  "pooling_ratio", currently only supports row and col dimension and should be >= 1.0, the first
@@ -9437,18 +9293,25 @@ class FractionalAvgPool(Primitive):
9437
9293
  Pooling ratio for each dimension of value should be >=0, currently only support for row and col
9438
9294
  dimension. The first and last elements must be 1.0 because we don't allow pooling on batch and
9439
9295
  channels dimensions.
9440
- pseudo_random(bool): An optional bool. Defaults to False. When set to True, generates the pooling
9441
- sequence in a pseudorandom fashion, otherwise, in a random fashion.
9442
- Check paper Benjamin Graham, Fractional Max-Pooling for difference between pseudo_random and
9443
- random.
9444
- overlapping(bool): An optional bool. Defaults to False. When set to True, it means when pooling,
9445
- the values at the boundary of adjacent pooling cells are used by both cells.
9446
- deterministic(bool): An optional bool. Defaults to False. When set to True, a fixed pooling region
9447
- will be used when iterating over a FractionalAvgPool node in the computation graph. Mainly
9448
- used in unit test to make FractionalAvgPool deterministic.
9449
- seed(int): An optional int. Defaults to 0. If either seed or seed2 are set to be non-zero, the
9450
- random number generator is seeded by the given seed. Otherwise, it is seeded by a random seed.
9451
- seed2(int): An optional int. Defaults to 0. An second seed to avoid seed collision.
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.
9452
9315
 
9453
9316
  Inputs:
9454
9317
  - **x** (Tensor) -The data type must be one of the following types: float32, float64, int32, int64.
@@ -9501,32 +9364,35 @@ class FractionalAvgPool(Primitive):
9501
9364
 
9502
9365
  class NthElement(Primitive):
9503
9366
  r"""
9504
- Finds values of the n-th order statistic for the last dimension.
9505
- If the input is a vector (rank-1), finds the entries which is the nth-smallest value in
9506
- the vector and outputs their values as scalar tensor.
9507
- For matrices (resp. higher rank input), computes the entries which is the nth-smallest value in
9508
- 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]`.
9509
9374
 
9510
9375
  Args:
9511
- reverse (bool): An optional bool. Defaults to False. When set to True, find the nth-largest value
9512
- in the vector and vice versa.
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.
9513
9378
 
9514
9379
  Inputs:
9515
- - **input** (Tensor) - A Tensor. 1-D or higher with last dimension at least n+1.
9516
- - **n** (int or Tensor) - If the n is a tensor, it should be a 0-D tensor, dtype is int32.
9517
- Valid range of n is [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`.
9518
9384
 
9519
9385
  Outputs:
9520
- Tensor, values.shape = input.shape[:-1]. The dtype is same to the input.
9386
+ - **values** (Tensor) - Its shape satisfies: `values`.shape = `input`.shape[:-1].
9387
+ The dtype is the same as `input`.
9521
9388
 
9522
9389
  Raises:
9523
- TypeError: If the type of input is out of the valid list.
9524
- TypeError: If the n is not int32 or not a Tensor.
9525
- ValueError: If n is out of [0, input.shape[-1]).
9526
-
9390
+ TypeError**: If the type of `input` is out of the valid list.
9391
+ TypeError**: If `n` is not int32 or not a Tensor.
9392
+ ValueError**: If n is out of :math:`[0, input.shape[-1])`.
9527
9393
 
9528
9394
  Supported Platforms:
9529
- ``Ascend`` ``CPU``
9395
+ ``Ascend`` ``GPU`` ``CPU``
9530
9396
 
9531
9397
  Examples:
9532
9398
  >>> input = Tensor(np.array([[1,2,3],[4,5,6]]) , mstype.int8)
@@ -9548,13 +9414,13 @@ class NthElement(Primitive):
9548
9414
 
9549
9415
  class PSROIPooling(Primitive):
9550
9416
  r"""
9551
- Position Sensitive ROI-Pooling
9417
+ Applies Position Sensitive ROI-Pooling on input Tensor.
9552
9418
 
9553
9419
  Args:
9554
9420
  spatial_scale (float): a scaling factor that maps the box coordinates to the input coordinates.
9555
9421
  For example, if your boxes are defined on the scale of a 224x224 image and
9556
9422
  your input is a 112x112 feature map (resulting from a 0.5x scaling of the original
9557
- image), youll want to set this to 0.5.
9423
+ image), you'll want to set this to 0.5.
9558
9424
  group_size (int): the size of the output (in pixels) after the pooling is performed, as (height, width).
9559
9425
  output_dim (int): the dim of the output after the pooling is performed.
9560
9426
 
@@ -9569,7 +9435,16 @@ class PSROIPooling(Primitive):
9569
9435
  0 <= x1 < x2 and 0 <= y1 < y2.
9570
9436
 
9571
9437
  Outputs:
9572
- - out (rois.shape[0] * rois.shape[2], output_dim, group_size, group_size), the result after pooling.
9438
+ - **out** (Tensor) - The result after pooling. Its shape
9439
+ is :math:`(rois.shape[0] * rois.shape[2], output\_dim, group\_size, group\_size)`.
9440
+
9441
+ Raises:
9442
+ TypeError: If `spatial_scale` is not a float.
9443
+ TypeError: If `group_size` or `output_dim` is not an int.
9444
+ TypeError: If `features` or `rois` is not a Tensor.
9445
+ TypeError: If dtype of `rois` is not float16 or float32.
9446
+ ValueError: If shape of `features` does not satisfy :math:`(C == output\_dim * group\_size * group\_size)`.
9447
+ ValueError: If `spatial_scale` is negative.
9573
9448
 
9574
9449
  Supported Platforms:
9575
9450
  ``Ascend``
@@ -9605,9 +9480,9 @@ class PSROIPooling(Primitive):
9605
9480
  ... group_size=7)
9606
9481
  >>> out = psROIPooling(features, rois)
9607
9482
  >>> print(out.shape)
9608
- (4, 3, 7, 7)
9483
+ (4, 3, 7, 7)
9609
9484
  >>> print(out.dtype)
9610
- Float32
9485
+ Float32
9611
9486
  """
9612
9487
 
9613
9488
  @prim_attr_register
@@ -9636,9 +9511,10 @@ class TripletMarginLoss(Primitive):
9636
9511
  examples` respectively). The shapes of all input tensors should be
9637
9512
  :math:`(N, D)`.
9638
9513
 
9639
- The distance swap is described in detail in the paper `Learning shallow
9640
- convolutional feature descriptors with triplet losses` by
9641
- V. Balntas, E. Riba et al.
9514
+ The distance swap is described in detail in the paper
9515
+ `Learning local feature descriptors with triplets and shallow convolutional neural
9516
+ networks <http://158.109.8.37/files/BRP2016.pdf>`_
9517
+ by V. Balntas, E. Riba et al.
9642
9518
 
9643
9519
  The loss function for each sample in the mini-batch is:
9644
9520
 
@@ -9651,17 +9527,18 @@ class TripletMarginLoss(Primitive):
9651
9527
  d(x_i, y_i) = \left\lVert {\bf x}_i - {\bf y}_i \right\rVert_p
9652
9528
 
9653
9529
  Args:
9654
- p (int): The norm degree for pairwise distance. Default: 2.
9655
- eps (float): Default: 1e-06.
9656
- swap (bool): The distance swap is described in detail in the paper
9657
- `Learning shallow convolutional feature descriptors with triplet losses` by
9658
- V. Balntas, E. Riba et al. Default: "False".
9659
- reduction (str): Apply specific reduction method to the output: 'none', 'mean', 'sum'. Default: "mean".
9530
+ p (int, optional): The norm degree for pairwise distance. Default: 2.
9531
+ eps (float, optional): Default: 1e-06.
9532
+ swap (bool, optional): The distance swap. Default: False.
9533
+ reduction (str, optional): Apply specific reduction method to the
9534
+ output: "none", "mean", "sum". Default: "mean".
9660
9535
 
9661
9536
  Inputs:
9662
9537
  - **x** (Tensor) - A sample randomly selected from the training set. Data type must be BasicType.
9663
- - **positive** (Tensor) - A sample belonging to the same category as x, with the same type and shape as `x`.
9664
- - **negative** (Tensor) - A sample belonging to the different class from x, with the same type and shape as `x`.
9538
+ - **positive** (Tensor) - A sample belonging to the same category as x,
9539
+ with the same type and shape as `x`.
9540
+ - **negative** (Tensor) - A sample belonging to the different class from x,
9541
+ with the same type and shape as `x`.
9665
9542
  - **margin** (Tensor) - Make a margin between the positive pair and the negative pair.
9666
9543
 
9667
9544
  Outputs:
@@ -9669,21 +9546,23 @@ class TripletMarginLoss(Primitive):
9669
9546
  Otherwise, a scalar value will be returned.
9670
9547
 
9671
9548
  Raises:
9672
- TypeError: If `x` or `positive` or 'negative' or 'margin' is not a Tensor.
9549
+ TypeError: If `x` or `positive` or `negative` or `margin` is not a Tensor.
9673
9550
  TypeError: If dtype of `x` or `positive` or `negative` is not BasicType.
9674
9551
  TypeError: If dtype of `x`, `positive` and `negative` is not the same.
9675
9552
  TypeError: If `margin` is not float32.
9676
9553
  TypeError: If `p` is not an int.
9677
9554
  TypeError: If `eps` is not a float.
9678
9555
  TypeError: If `swap` is not a bool.
9679
- ValueError: If dimensions of input `x`, `positive` and `negative` are less than or equal to 1 at the same time.
9680
- ValueError: If the dimension of input `x` or `positive` or `negative` is bigger than or equal to 8.
9556
+ ValueError: If dimensions of input `x`, `positive` and `negative` are
9557
+ less than or equal to 1 at the same time.
9558
+ ValueError: If the dimension of input `x` or `positive` or `negative`
9559
+ is bigger than or equal to 8.
9681
9560
  ValueError: If length of shape of `margin` is not 0.
9682
9561
  ValueError: If shape of `x`, `positive` and `negative` cannot broadcast.
9683
9562
  ValueError: If `reduction` is not one of 'none', 'mean', 'sum'.
9684
9563
 
9685
9564
  Supported Platforms:
9686
- ``Ascend`` ``CPU`` ``GPU``
9565
+ ``GPU``
9687
9566
 
9688
9567
  Examples:
9689
9568
  >>> loss = ops.TripletMarginLoss()
@@ -9710,10 +9589,10 @@ class DeformableOffsets(Primitive):
9710
9589
  r"""
9711
9590
  Computes the deformed convolution output with the expected input.
9712
9591
 
9713
- Refer to :func:`mindspore.ops.deformable_conv2d` for more detail.
9592
+ Refer to :func:`mindspore.ops.deformable_conv2d` for more details.
9714
9593
 
9715
9594
  Supported Platforms:
9716
- ``Ascend`` ``CPU`` ``GPU``
9595
+ ``Ascend`` ``GPU`` ``CPU``
9717
9596
  """
9718
9597
 
9719
9598
  @prim_attr_register
@@ -9761,26 +9640,39 @@ class DeformableOffsets(Primitive):
9761
9640
 
9762
9641
  class GridSampler2D(Primitive):
9763
9642
  """
9764
- This operation samples 2d input_x by using interpolation based on flow field grid, which is usually gennerated by
9765
- 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.
9766
9648
 
9767
9649
  Args:
9768
- 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
9769
9652
  "bilinear" or "nearest". Default: "bilinear".
9770
- padding_mode (str): An optional string specifying the pad method. The optional values are "zeros", "border" or
9771
- "reflection". Default: "zeros".
9772
- align_corners (bool): An optional bool. If "true", the centers of the corner pixels of the input and output
9773
- tensors are aligned. Defaults to "false".
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
9664
+ and output tensors are aligned. When set to False, it is not aligned. Defaults to False.
9774
9665
 
9775
9666
  Inputs:
9776
- - **input_x** (Tensor) - A 4-D tensor with dtype of float16 or float32 and shape of :math:`(N, C,
9777
- H_{in}, W_{in})`.
9778
- - **grid** (Tensor) - A 4-D tensor whose dtype is the same as `input_x` and whose shape is :math:`(N,
9779
- 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
9780
9672
  dimensions.
9781
9673
 
9782
9674
  Outputs:
9783
- 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})`.
9784
9676
 
9785
9677
  Raises:
9786
9678
  TypeError: If `input_x` or `grid` is not a Tensor.
@@ -9832,37 +9724,16 @@ class Pdist(Primitive):
9832
9724
  r"""
9833
9725
  Computes the p-norm distance between each pair of row vectors in the input.
9834
9726
 
9835
- .. math::
9836
-
9837
- y[n] = \sqrt[p]{{\mid x_{i} - x_{j} \mid}^p},
9838
-
9839
- where :math:`x_{i}, x_{j}` are two different row vectors in the input.
9840
-
9841
- Args:
9842
- p (float): p value for the p norm distance to calculate between each vector pair ∈[0,∞]. Default: 2.0.
9843
-
9844
- Inputs:
9845
- - **x** (Tensor) - Input tensor with dtype of float16 or float32 and shape of :math:`(N, M)`.
9846
-
9847
- Outputs:
9848
- Tensor, has the same dtype as `x`, whose shape is :math:`(N * (N - 1) / 2)`.
9849
-
9850
- Raises:
9851
- TypeError: If `x` is not a Tensor.
9852
- TypeError: If dtype of `x` is not float16, float32 or float64.
9853
- TypeError: If `p` is not a float.
9854
- ValueError: If `p` is a negative float.
9855
- ValueError: If dimension of `x` is not 2.
9727
+ Refer to :func:`mindspore.ops.pdist` for more details.
9856
9728
 
9857
9729
  Supported Platforms:
9858
- ``Ascend`` ``CPU`` ``GPU``
9730
+ ``GPU`` ``CPU``
9859
9731
 
9860
9732
  Examples:
9861
- >>> from mindspore import Tensor
9862
- >>> from mindspore.ops.operations.nn_ops import Pdist
9733
+ >>> from mindspore import Tensor, ops
9863
9734
  >>> import numpy as np
9864
9735
  >>> x = Tensor(np.array([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0]]).astype(np.float32))
9865
- >>> op = Pdist(p=2.0)
9736
+ >>> op = ops.Pdist(p=2.0)
9866
9737
  >>> y = op(x)
9867
9738
  >>> print(y)
9868
9739
  [1.4142135 2.828427 1.4142135]
@@ -9887,9 +9758,11 @@ class UpsampleNearest3D(Primitive):
9887
9758
  One of `output_size` or `scales` must be given, and cannot specify both.
9888
9759
 
9889
9760
  Args:
9890
- output_size (Union[tuple[int], list[int]]): A tuple or list of int specifying the output volumetric size.
9761
+ output_size (Union[tuple[int], list[int]], optional): A tuple or list of int
9762
+ specifying the output volumetric size.
9891
9763
  Default: None.
9892
- scales (Union[tuple[float], list[float]]): A tuple or list of float specifying the upsampling factors.
9764
+ scales (Union[tuple[float], list[float]], optional): A tuple or list of float
9765
+ specifying the upsampling factors.
9893
9766
  Default: None.
9894
9767
 
9895
9768
  Inputs:
@@ -9901,8 +9774,8 @@ class UpsampleNearest3D(Primitive):
9901
9774
  Tensor of shape :math:`(N, C, D_{out}, H_{out}, W_{out})`.
9902
9775
 
9903
9776
  Raises:
9904
- TypeError: When `output_size` is not none and `output_size` is not list[int] or tuple[int].
9905
- TypeError: When `scales` is not none and `scales` is not list[float] or tuple[float].
9777
+ TypeError: When `output_size` is not None and `output_size` is not list[int] or tuple[int].
9778
+ TypeError: When `scales` is not None and `scales` is not list[float] or tuple[float].
9906
9779
  TypeError: If dtype of `x` is not int [float16, float32, float64].
9907
9780
  ValueError: If any value of `output_size` is negative or zero when `output_size` is not empty.
9908
9781
  ValueError: If any value of `scales` is negative or zero when `scales` is not empty.
@@ -9912,7 +9785,7 @@ class UpsampleNearest3D(Primitive):
9912
9785
  ValueError: If size of `output_size` is not equal 3 when `output_size` is specified.
9913
9786
 
9914
9787
  Supported Platforms:
9915
- ``Ascend`` ``GPU`` ``CPU``
9788
+
9916
9789
 
9917
9790
  Examples:
9918
9791
  >>> x = Tensor(np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])
@@ -9945,10 +9818,10 @@ class UpsampleNearest3D(Primitive):
9945
9818
  scales = []
9946
9819
  validator.check_value_type('output_size', output_size, [tuple, list], self.name)
9947
9820
  for item in output_size:
9948
- 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)
9949
9822
  validator.check_value_type('scales', scales, [tuple, list], self.name)
9950
9823
  for item in scales:
9951
- validator.check_float(item, 0, Rel.GT, 'scales_item', self.name)
9824
+ validator.check_float(item, 0, validator.GT, 'scales_item', self.name)
9952
9825
  self.add_prim_attr('output_size', output_size)
9953
9826
  self.add_prim_attr('scales', scales)
9954
9827
 
@@ -9978,7 +9851,7 @@ class SparseApplyAdagradDA(Primitive):
9978
9851
  Otherwise the behavior is undefined, but may exhibit less contention. Default: False.
9979
9852
 
9980
9853
  Inputs:
9981
- - **var** (Parameter) - Variable to be updated. The data type must be float16 or float32.
9854
+ - **var** (Parameter) - Variable to be updated.
9982
9855
  The shape is :math:`(N, *)` where :math:`*` means, any number of additional dimensions.
9983
9856
  - **grad_accum** (Parameter) - The dict of mutable tensor grad_accum. Must have the same
9984
9857
  shape and dtype as `var`.
@@ -10002,8 +9875,7 @@ class SparseApplyAdagradDA(Primitive):
10002
9875
  TypeError: If `grad` is not a Tensor.
10003
9876
  TypeError: If `lr`, `l1`, `l2` or `global_step` is neither a Number nor a Tensor.
10004
9877
  TypeError: If use_locking is not a bool.
10005
- TypeError: If dtype of `var`, `grad_accum`, `grad_square_accum`, `grad_accum`,
10006
- `lr`, `l1`, `l2` is neither float16 nor float32.
9878
+ TypeError: If dtype of `var`, `grad_accum`, `grad_square_accum`, `grad_accum` is not the same.
10007
9879
  TypeError: If dtype of `grad_accum`, `grad_square_accum`, `grad_accum`
10008
9880
  is not same as `var`.
10009
9881
  TypeError: If dtype of `indices` is neither int32 nor int64.
@@ -10014,16 +9886,12 @@ class SparseApplyAdagradDA(Primitive):
10014
9886
  conversion of Parameter is not supported.
10015
9887
 
10016
9888
  Supported Platforms:
10017
- ``Ascend`` ``CPU``
9889
+ ``GPU`` ``CPU``
10018
9890
 
10019
9891
  Examples:
10020
- >>> import numpy as np
10021
- >>> from mindspore import Tensor
10022
- >>> import mindspore.common.dtype as mstype
10023
- >>> import mindspore.ops.operations.nn_ops as nn_ops
10024
- >>> var = Tensor(np.array([[1,2], [1,2]]).astype(np.float32))
10025
- >>> grad_accum = Tensor(np.array([[2,1], [3,1]]).astype(np.float32))
10026
- >>> 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)))
10027
9895
  >>> grad = Tensor(np.array([[5,1], [6,1]]).astype(np.float32))
10028
9896
  >>> indices = Tensor(np.array([0, 1], dtype=np.int32))
10029
9897
  >>> lr = Tensor(2, mstype.float32)
@@ -10039,9 +9907,9 @@ class SparseApplyAdagradDA(Primitive):
10039
9907
  """
10040
9908
 
10041
9909
  __mindspore_signature__ = (
10042
- sig.make_sig('var', dtype=sig.sig_dtype.T),
10043
- sig.make_sig('grad_accum', dtype=sig.sig_dtype.T),
10044
- 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),
10045
9913
  sig.make_sig('grad', dtype=sig.sig_dtype.T),
10046
9914
  sig.make_sig('indices', dtype=sig.sig_dtype.T1),
10047
9915
  sig.make_sig('lr', dtype=sig.sig_dtype.T),
@@ -10111,7 +9979,7 @@ class SparseApplyMomentum(Primitive):
10111
9979
  is not supported.
10112
9980
 
10113
9981
  Supported Platforms:
10114
- ``Ascend`` ``CPU``
9982
+ ``GPU`` ``CPU``
10115
9983
 
10116
9984
  Examples:
10117
9985
  >>> import mindspore.ops.operations.nn_ops as nn_ops
@@ -10195,7 +10063,7 @@ class SparseApplyProximalGradientDescent(Primitive):
10195
10063
  is not supported.
10196
10064
 
10197
10065
  Supported Platforms:
10198
- ``Ascend`` ``CPU``
10066
+ ``GPU`` ``CPU``
10199
10067
 
10200
10068
  Examples:
10201
10069
  >>> import mindspore.ops.operations.nn_ops as nn_ops
@@ -10213,7 +10081,7 @@ class SparseApplyProximalGradientDescent(Primitive):
10213
10081
  """
10214
10082
 
10215
10083
  __mindspore_signature__ = (
10216
- sig.make_sig('var', dtype=sig.sig_dtype.T),
10084
+ sig.make_sig('var', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T),
10217
10085
  sig.make_sig('alpha', dtype=sig.sig_dtype.T),
10218
10086
  sig.make_sig('l1', dtype=sig.sig_dtype.T),
10219
10087
  sig.make_sig('l2', dtype=sig.sig_dtype.T),
@@ -10231,50 +10099,51 @@ class SparseApplyProximalGradientDescent(Primitive):
10231
10099
 
10232
10100
  class NuclearNorm(Primitive):
10233
10101
  r"""
10234
- Returns the matrix nuclear norm of a given tensor.
10102
+ Returns the matrix nuclear norm of a given Tensor.
10235
10103
 
10236
10104
  Attr `dim` specifies which two dimensions of the input `x` to calculate the nuclear norm across. If `dim` is None,
10237
10105
  the nuclear norm will be calculated across all dimensions of input. Because the nuclear norm is the sum of the
10238
10106
  singular values of the matrix, the input at this time should be 2-dimensional. That is, if the input is
10239
10107
  2-dimensional, we compute the nuclear norm of the input matrix. At this point, `dim` should be None. If you set
10240
- `dim`, it also needs to be in the proper range, although it doesn't work. If the input is 3-dimensional and above,
10108
+ `dim`, it also needs to be in the proper range, otherwise it wonn't work. If the input is 3-dimensional and above,
10241
10109
  the attribute `dim` is required. It specifies which two dimensions of input to calculate the nuclear norm across.
10242
10110
 
10243
- According to the `dim` list, the input tensor is reordered by `dim`. The two dimensions pointed to by the attribute
10111
+ According to the `dim` list, the input Tensor is reordered by `dim`. The two dimensions pointed to by the attribute
10244
10112
  `dim` are placed at the end, and the order of the other dimensions is relatively unchanged. Perform the SVD of each
10245
- slice of the adjusted tensor to obtain the singular value. Sum all of the singular value of each slice/matrix to
10113
+ slice of the adjusted Tensor to obtain the singular value. Sum all of the singular value of each slice/matrix to
10246
10114
  obtain the nuclear norm.
10247
10115
 
10248
10116
  Args:
10249
- dim (Union[list(int), tuple(int)]): Specifies which two dimensions of `x` to calculate the matrix nuclear norm
10117
+ dim (Union[list(int), tuple(int)], optional): Specifies which two
10118
+ dimensions of `x` to calculate the matrix nuclear norm
10250
10119
  across. If `dim` is None, the nuclear norm will be calculated across all dimensions of `x`. The length of
10251
10120
  `dim` should be 2. The value in `dim` should be in this range:[-x_rank, x_rank). x_rank is the dimension of
10252
10121
  Tensor `x`. The value of `dim[0]` or `dim[1]` can not point to the same dimension. Default: None.
10253
- keepdim (bool): whether the output tensor have `dim` retained or not. Default: False.
10122
+ keepdim (bool, optional): Whether the output Tensor have `dim` retained or not. Default: False.
10254
10123
 
10255
10124
  Inputs:
10256
10125
  - **x** (Tensor) - Input to compute the matrix nuclear norm. The dimension of `x` should be greater than or
10257
10126
  equal to 2. Data type must be float32 or float64.
10258
10127
 
10259
10128
  Outputs:
10260
- Tensor, output tensor with dimensions in `dim` reduced to 1 will be returned if `keepdim` is `True`;
10261
- otherwise a tensor with dimensions in `dim` removed is returned. The data type is same as `x`.
10262
-
10263
- Supported Platforms:
10264
- ``Ascend`` ``CPU``
10129
+ Tensor, output Tensor with dimensions in `dim` reduced to 1 will be returned if `keepdim` is `True`;
10130
+ otherwise a Tensor with dimensions in `dim` removed is returned. The data type is same as `x`.
10265
10131
 
10266
10132
  Raises:
10267
- TypeError: If `x` is not a tensor.
10133
+ TypeError: If `x` is not a Tensor.
10268
10134
  TypeError: If dtype of `x` is neither float32 nor float64.
10269
10135
  TypeError: If dtype of `dim` is neither list(int) nor tuple(int).
10270
10136
  TypeError: If dtype of `keepdim` is not bool.
10271
10137
  ValueError: If dimension of Tensor `x` is less than 2.
10272
10138
  ValueError: If the length of `dim` is not 2 when `dim` is set.
10273
- ValueError: If the dimension of tensor `x` is not 2 when `dim` is not set.
10139
+ ValueError: If the dimension of Tensor `x` is not 2 when `dim` is not set.
10274
10140
  ValueError: If `dim[0]` or `dim[1]` point to the same dimension.
10275
10141
  ValueError: If `dim[0]` or `dim[1]` is not in this range:[-x_rank, x_rank).
10276
10142
  x_rank is the dimension of Tensor `x`.
10277
10143
 
10144
+ Supported Platforms:
10145
+ ``Ascend`` ``CPU``
10146
+
10278
10147
  Examples:
10279
10148
  >>> input_x = Tensor(np.array([[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]],
10280
10149
  ... [[7.0, 8.0, 9.0], [10.0, 11.0, 12.0]]]), ms.float32)
@@ -10308,7 +10177,7 @@ class NuclearNorm(Primitive):
10308
10177
  """Initialize NuclearNorm."""
10309
10178
  validator.check_value_type("dim", dim, [list, tuple, type(None)], self.name)
10310
10179
  if dim is not None:
10311
- 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)
10312
10181
  validator.check_is_int(dim[0], "dim[0]", self.name)
10313
10182
  validator.check_is_int(dim[1], "dim[1]", self.name)
10314
10183
  else:
@@ -10316,23 +10185,56 @@ class NuclearNorm(Primitive):
10316
10185
  validator.check_value_type("keepdim", keepdim, [bool], self.name)
10317
10186
 
10318
10187
 
10188
+ class GLU(Primitive):
10189
+ r"""
10190
+ Computes GLU (Gated Linear Unit activation function) of input tensors.
10191
+
10192
+ .. warning::
10193
+ This is an experimental API that is subject to change or deletion.
10194
+
10195
+ Refer to :func:`mindspore.ops.glu` for more details.
10196
+
10197
+ Supported Platforms:
10198
+ ``Ascend`` ``CPU``
10199
+
10200
+ Examples:
10201
+ >>> from mindspore import ops, Tensor
10202
+ >>> from mindspore import dtype as mstype
10203
+ >>> import numpy as np
10204
+ >>> axis = 0
10205
+ >>> x = Tensor(np.array([0.3220, 0.9545, 0.7879, 0.0975, 0.3698,
10206
+ ... 0.5135, 0.5740, 0.3435, 0.1895, 0.8764,
10207
+ ... 0.4980, 0.9673, 0.9879, 0.6988, 0.9022,
10208
+ ... 0.9304, 0.1558, 0.0153, 0.1559, 0.9852]).reshape([2, 2, 5]), mstype.float32)
10209
+ >>> glu = ops.GLU(axis=axis)
10210
+ >>> y = glu(x)
10211
+ >>> print(y)
10212
+ [[[0.20028052 0.6916126 0.57412136 0.06512236 0.26307625]
10213
+ [0.3682598 0.3093122 0.17306386 0.10212085 0.63814086]]]
10214
+ """
10215
+
10216
+ @prim_attr_register
10217
+ def __init__(self, axis=-1):
10218
+ """Initialize GLU"""
10219
+ validator.check_value_type("axis", axis, [int], self.name)
10220
+
10221
+
10319
10222
  class FractionalMaxPoolWithFixedKsize(Primitive):
10320
10223
  r"""
10321
10224
  Applies a 2D fractional max pooling to an input signal composed of multiple input planes.
10322
- The max-pooling operation is applied in kH × kW regions by a stochastic step size determined by
10323
- the target output size. For any input size, the size of the specified output is H x W. The number
10324
- 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.
10325
10229
 
10326
10230
  Fractional MaxPooling is described in the paper `Fractional Max-Pooling <https://arxiv.org/pdf/1412.6071>`_.
10327
10231
 
10328
10232
  Args:
10329
- ksize (Union[int, tuple[int]]): The size of kernel window used to take the maximum value.
10330
- The target ksize is H x W. ksize can be a tuple, or a single K for K x K.
10331
- specifying the window size (H, W) of the input tensor.
10332
- output_shape (Union[int, tuple[int]]): The target output size is H x W.
10333
- output_shape can be a tuple, or a single H for H x H.
10334
- specifying the size (H, W) of the output tensor.
10335
- data_format (str): The optional value for data format, is 'NCHW'.
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)`.
10237
+ data_format (str, optional): The optional value for data format, is 'NCHW'.
10336
10238
  Default: "NCHW".
10337
10239
 
10338
10240
  Inputs:
@@ -10343,21 +10245,23 @@ class FractionalMaxPoolWithFixedKsize(Primitive):
10343
10245
 
10344
10246
  Outputs:
10345
10247
  - **y** (Tensor) - Has the same type as the `input_x`.
10346
- 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})`.
10347
10249
  - **argmax** (Tensor) -A tensor whose data type must be int64. Has the same shape as the `y`.
10250
+
10348
10251
  Raises:
10349
10252
  TypeError: If data type of `input_x` is not one of the following: float16, float32, float64, int32, int64.
10350
10253
  TypeError: If data type of `random_samples` is not one of the following: float16, float32, float64.
10351
10254
  ValueError: If `ksize` is not a number and `ksize` is not a tuple of length 2.
10352
10255
  ValueError: If `output_shape` is not a number and `output_shape` is not a tuple of length 2.
10353
- ValueError: If the sum of `ksize`,`output_shape` and -1 is larger than the corresponding dimension of `input_x`.
10256
+ ValueError: If the sum of `ksize` , `output_shape` and
10257
+ -1 is larger than the corresponding dimension of `input_x`.
10354
10258
  ValueError: If the dimension of `random_samples` is not 3.
10355
10259
  ValueError: If the first dimension size of `input_x` and `random_samples` is not equal.
10356
10260
  ValueError: If the second dimension size of `input_x` and `random_samples` is not equal.
10357
10261
  ValueError: If the third dimension size of `random_samples` is not 2.
10358
10262
 
10359
10263
  Supported Platforms:
10360
- ``Ascend`` ``CPU``
10264
+ ``CPU``
10361
10265
 
10362
10266
  Examples:
10363
10267
  >>> # the ksize is an int number and the output_shape is a tuple.
@@ -10393,3 +10297,129 @@ class FractionalMaxPoolWithFixedKsize(Primitive):
10393
10297
  self.add_prim_attr("output_shape", self.output_shape)
10394
10298
  self.data_format = validator.check_string(data_format, ['NCHW'], 'data_format', self.name)
10395
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)