mindspore 2.2.11__cp39-cp39-win_amd64.whl → 2.3.0__cp39-cp39-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 (1151) hide show
  1. mindspore/.commit_id +1 -1
  2. mindspore/__init__.py +7 -5
  3. mindspore/_c_dataengine.cp39-win_amd64.pyd +0 -0
  4. mindspore/_c_expression.cp39-win_amd64.pyd +0 -0
  5. mindspore/_c_mindrecord.cp39-win_amd64.pyd +0 -0
  6. mindspore/_checkparam.py +76 -18
  7. mindspore/_extends/builtin_operations.py +2 -1
  8. mindspore/_extends/graph_kernel/model/graph_parallel.py +16 -6
  9. mindspore/_extends/parallel_compile/akg_compiler/akg_process.py +3 -16
  10. mindspore/_extends/parallel_compile/akg_compiler/build_tbe_kernel.py +16 -4
  11. mindspore/_extends/parallel_compile/akg_compiler/compiler.py +1 -0
  12. mindspore/_extends/parallel_compile/akg_compiler/gen_custom_op_files.py +96 -0
  13. mindspore/_extends/parallel_compile/akg_compiler/tbe_topi.py +2 -1
  14. mindspore/_extends/parallel_compile/akg_compiler/util.py +5 -2
  15. mindspore/_extends/parse/__init__.py +18 -14
  16. mindspore/_extends/parse/compile_config.py +258 -0
  17. mindspore/_extends/parse/namespace.py +2 -2
  18. mindspore/_extends/parse/parser.py +174 -62
  19. mindspore/_extends/parse/resources.py +45 -14
  20. mindspore/_extends/parse/standard_method.py +142 -240
  21. mindspore/{ops/_op_impl/tbe/atomic_addr_clean.py → _extends/pijit/__init__.py} +6 -16
  22. mindspore/_extends/pijit/pijit_func_white_list.py +343 -0
  23. mindspore/_extends/remote/kernel_build_server.py +2 -0
  24. mindspore/_profiler.py +30 -0
  25. mindspore/amp.py +51 -24
  26. mindspore/avcodec-59.dll +0 -0
  27. mindspore/avdevice-59.dll +0 -0
  28. mindspore/avfilter-8.dll +0 -0
  29. mindspore/avformat-59.dll +0 -0
  30. mindspore/avutil-57.dll +0 -0
  31. mindspore/boost/adasum.py +1 -1
  32. mindspore/boost/base.py +1 -1
  33. mindspore/boost/boost_cell_wrapper.py +2 -2
  34. mindspore/boost/grad_freeze.py +2 -2
  35. mindspore/boost/group_loss_scale_manager.py +1 -1
  36. mindspore/boost/less_batch_normalization.py +9 -6
  37. mindspore/common/__init__.py +15 -4
  38. mindspore/common/_jit_fallback_utils.py +2 -3
  39. mindspore/common/_register_for_adapter.py +7 -0
  40. mindspore/common/_register_for_recompute.py +48 -0
  41. mindspore/common/_register_for_tensor.py +8 -9
  42. mindspore/common/_stub_tensor.py +7 -1
  43. mindspore/common/_utils.py +5 -17
  44. mindspore/common/api.py +411 -106
  45. mindspore/common/auto_dynamic_shape.py +27 -14
  46. mindspore/common/dtype.py +17 -10
  47. mindspore/common/dump.py +6 -8
  48. mindspore/common/file_system.py +48 -0
  49. mindspore/common/generator.py +260 -0
  50. mindspore/common/hook_handle.py +51 -4
  51. mindspore/common/initializer.py +1 -1
  52. mindspore/common/jit_config.py +34 -14
  53. mindspore/common/lazy_inline.py +72 -19
  54. mindspore/common/mindir_util.py +12 -2
  55. mindspore/common/mutable.py +79 -14
  56. mindspore/common/no_inline.py +54 -0
  57. mindspore/common/np_dtype.py +25 -0
  58. mindspore/common/parameter.py +30 -11
  59. mindspore/common/recompute.py +262 -0
  60. mindspore/common/seed.py +9 -9
  61. mindspore/common/sparse_tensor.py +272 -24
  62. mindspore/common/symbol.py +122 -0
  63. mindspore/common/tensor.py +468 -496
  64. mindspore/communication/__init__.py +6 -11
  65. mindspore/communication/_comm_helper.py +5 -0
  66. mindspore/communication/comm_func.py +1140 -0
  67. mindspore/communication/management.py +118 -102
  68. mindspore/config/op_info.config +22 -54
  69. mindspore/context.py +378 -65
  70. mindspore/dataset/__init__.py +5 -5
  71. mindspore/dataset/audio/__init__.py +6 -6
  72. mindspore/dataset/audio/transforms.py +711 -158
  73. mindspore/dataset/callback/ds_callback.py +2 -2
  74. mindspore/dataset/engine/cache_client.py +2 -2
  75. mindspore/dataset/engine/datasets.py +163 -83
  76. mindspore/dataset/engine/datasets_audio.py +14 -14
  77. mindspore/dataset/engine/datasets_standard_format.py +33 -3
  78. mindspore/dataset/engine/datasets_text.py +38 -38
  79. mindspore/dataset/engine/datasets_user_defined.py +78 -59
  80. mindspore/dataset/engine/datasets_vision.py +77 -73
  81. mindspore/dataset/engine/offload.py +5 -7
  82. mindspore/dataset/engine/queue.py +56 -38
  83. mindspore/dataset/engine/validators.py +11 -5
  84. mindspore/dataset/text/__init__.py +3 -3
  85. mindspore/dataset/text/transforms.py +408 -121
  86. mindspore/dataset/text/utils.py +9 -9
  87. mindspore/dataset/transforms/__init__.py +1 -1
  88. mindspore/dataset/transforms/transforms.py +261 -76
  89. mindspore/dataset/utils/browse_dataset.py +9 -9
  90. mindspore/dataset/vision/__init__.py +8 -8
  91. mindspore/dataset/vision/c_transforms.py +10 -10
  92. mindspore/dataset/vision/py_transforms_util.py +3 -3
  93. mindspore/dataset/vision/transforms.py +2844 -549
  94. mindspore/dataset/vision/utils.py +161 -10
  95. mindspore/dataset/vision/validators.py +14 -2
  96. mindspore/dnnl.dll +0 -0
  97. mindspore/experimental/optim/__init__.py +12 -2
  98. mindspore/experimental/optim/adadelta.py +161 -0
  99. mindspore/experimental/optim/adagrad.py +168 -0
  100. mindspore/experimental/optim/adam.py +35 -34
  101. mindspore/experimental/optim/adamax.py +170 -0
  102. mindspore/experimental/optim/adamw.py +40 -16
  103. mindspore/experimental/optim/asgd.py +153 -0
  104. mindspore/experimental/optim/lr_scheduler.py +71 -127
  105. mindspore/experimental/optim/nadam.py +157 -0
  106. mindspore/experimental/optim/optimizer.py +15 -8
  107. mindspore/experimental/optim/radam.py +194 -0
  108. mindspore/experimental/optim/rmsprop.py +154 -0
  109. mindspore/experimental/optim/rprop.py +164 -0
  110. mindspore/experimental/optim/sgd.py +28 -19
  111. mindspore/hal/__init__.py +40 -0
  112. mindspore/hal/_ascend.py +57 -0
  113. mindspore/hal/_base.py +57 -0
  114. mindspore/hal/_cpu.py +56 -0
  115. mindspore/hal/_gpu.py +57 -0
  116. mindspore/hal/device.py +356 -0
  117. mindspore/hal/event.py +179 -0
  118. mindspore/hal/memory.py +326 -0
  119. mindspore/hal/stream.py +339 -0
  120. mindspore/include/api/data_type.h +2 -2
  121. mindspore/include/api/dual_abi_helper.h +16 -3
  122. mindspore/include/api/model.h +4 -3
  123. mindspore/include/api/status.h +14 -0
  124. mindspore/include/c_api/model_c.h +173 -0
  125. mindspore/include/c_api/ms/base/types.h +1 -0
  126. mindspore/include/c_api/types_c.h +19 -0
  127. mindspore/include/dataset/execute.h +1 -3
  128. mindspore/include/dataset/vision.h +54 -2
  129. mindspore/jpeg62.dll +0 -0
  130. mindspore/log.py +2 -2
  131. mindspore/mindrecord/__init__.py +5 -1
  132. mindspore/mindrecord/config.py +809 -0
  133. mindspore/mindrecord/filereader.py +25 -0
  134. mindspore/mindrecord/filewriter.py +76 -58
  135. mindspore/mindrecord/mindpage.py +40 -6
  136. mindspore/mindrecord/shardutils.py +3 -2
  137. mindspore/mindrecord/shardwriter.py +7 -0
  138. mindspore/mindrecord/tools/cifar100_to_mr.py +53 -66
  139. mindspore/mindrecord/tools/cifar10_to_mr.py +48 -63
  140. mindspore/mindrecord/tools/csv_to_mr.py +7 -17
  141. mindspore/mindrecord/tools/imagenet_to_mr.py +3 -8
  142. mindspore/mindrecord/tools/mnist_to_mr.py +11 -21
  143. mindspore/mindrecord/tools/tfrecord_to_mr.py +2 -10
  144. mindspore/mindspore_backend.dll +0 -0
  145. mindspore/mindspore_common.dll +0 -0
  146. mindspore/mindspore_core.dll +0 -0
  147. mindspore/mindspore_glog.dll +0 -0
  148. mindspore/mindspore_np_dtype.dll +0 -0
  149. mindspore/mindspore_shared_lib.dll +0 -0
  150. mindspore/mint/__init__.py +1137 -0
  151. mindspore/{rewrite/ast_transformers → mint/linalg}/__init__.py +9 -4
  152. mindspore/mint/nn/__init__.py +512 -0
  153. mindspore/mint/nn/functional.py +573 -0
  154. mindspore/mint/optim/__init__.py +24 -0
  155. mindspore/mint/optim/adamw.py +185 -0
  156. mindspore/multiprocessing/__init__.py +72 -0
  157. mindspore/nn/__init__.py +1 -0
  158. mindspore/nn/cell.py +213 -257
  159. mindspore/nn/dynamic_lr.py +2 -2
  160. mindspore/nn/extend/__init__.py +29 -0
  161. mindspore/nn/extend/basic.py +140 -0
  162. mindspore/nn/extend/embedding.py +143 -0
  163. mindspore/{rewrite/ast_creator_register.py → nn/extend/layer/__init__.py} +9 -19
  164. mindspore/nn/extend/layer/normalization.py +109 -0
  165. mindspore/nn/extend/pooling.py +117 -0
  166. mindspore/nn/layer/activation.py +84 -94
  167. mindspore/nn/layer/basic.py +177 -82
  168. mindspore/nn/layer/channel_shuffle.py +3 -16
  169. mindspore/nn/layer/container.py +3 -3
  170. mindspore/nn/layer/conv.py +75 -66
  171. mindspore/nn/layer/embedding.py +103 -45
  172. mindspore/nn/layer/embedding_service.py +531 -0
  173. mindspore/nn/layer/embedding_service_layer.py +393 -0
  174. mindspore/nn/layer/image.py +4 -7
  175. mindspore/nn/layer/math.py +1 -1
  176. mindspore/nn/layer/normalization.py +52 -66
  177. mindspore/nn/layer/padding.py +30 -39
  178. mindspore/nn/layer/pooling.py +18 -9
  179. mindspore/nn/layer/rnn_cells.py +6 -16
  180. mindspore/nn/layer/rnns.py +6 -5
  181. mindspore/nn/layer/thor_layer.py +1 -2
  182. mindspore/nn/layer/timedistributed.py +1 -1
  183. mindspore/nn/layer/transformer.py +52 -50
  184. mindspore/nn/learning_rate_schedule.py +6 -5
  185. mindspore/nn/loss/loss.py +63 -84
  186. mindspore/nn/optim/ada_grad.py +6 -4
  187. mindspore/nn/optim/adadelta.py +3 -1
  188. mindspore/nn/optim/adafactor.py +1 -1
  189. mindspore/nn/optim/adam.py +102 -181
  190. mindspore/nn/optim/adamax.py +4 -2
  191. mindspore/nn/optim/adasum.py +3 -3
  192. mindspore/nn/optim/asgd.py +4 -2
  193. mindspore/nn/optim/ftrl.py +31 -61
  194. mindspore/nn/optim/lamb.py +5 -3
  195. mindspore/nn/optim/lars.py +2 -2
  196. mindspore/nn/optim/lazyadam.py +6 -4
  197. mindspore/nn/optim/momentum.py +13 -25
  198. mindspore/nn/optim/optimizer.py +6 -3
  199. mindspore/nn/optim/proximal_ada_grad.py +4 -2
  200. mindspore/nn/optim/rmsprop.py +9 -3
  201. mindspore/nn/optim/rprop.py +4 -2
  202. mindspore/nn/optim/sgd.py +7 -4
  203. mindspore/nn/optim/thor.py +2 -2
  204. mindspore/nn/probability/distribution/_utils/custom_ops.py +2 -2
  205. mindspore/nn/probability/distribution/beta.py +2 -2
  206. mindspore/nn/probability/distribution/categorical.py +4 -6
  207. mindspore/nn/probability/distribution/cauchy.py +2 -2
  208. mindspore/nn/probability/distribution/exponential.py +2 -2
  209. mindspore/nn/probability/distribution/geometric.py +1 -1
  210. mindspore/nn/probability/distribution/gumbel.py +2 -2
  211. mindspore/nn/probability/distribution/logistic.py +1 -1
  212. mindspore/nn/probability/distribution/poisson.py +2 -2
  213. mindspore/nn/probability/distribution/uniform.py +2 -2
  214. mindspore/nn/reinforcement/_tensors_queue.py +13 -1
  215. mindspore/nn/wrap/__init__.py +2 -1
  216. mindspore/nn/wrap/cell_wrapper.py +58 -13
  217. mindspore/nn/wrap/grad_reducer.py +148 -8
  218. mindspore/nn/wrap/loss_scale.py +32 -9
  219. mindspore/numpy/__init__.py +2 -0
  220. mindspore/numpy/array_creations.py +2 -0
  221. mindspore/numpy/array_ops.py +6 -6
  222. mindspore/numpy/dtypes.py +3 -3
  223. mindspore/numpy/fft.py +431 -0
  224. mindspore/numpy/math_ops.py +61 -67
  225. mindspore/numpy/utils.py +3 -0
  226. mindspore/opencv_core452.dll +0 -0
  227. mindspore/opencv_imgcodecs452.dll +0 -0
  228. mindspore/opencv_imgproc452.dll +0 -0
  229. mindspore/ops/__init__.py +8 -4
  230. mindspore/ops/_grad_experimental/grad_array_ops.py +4 -160
  231. mindspore/ops/_grad_experimental/grad_comm_ops.py +93 -36
  232. mindspore/ops/_grad_experimental/grad_inner_ops.py +8 -0
  233. mindspore/ops/_grad_experimental/grad_math_ops.py +92 -287
  234. mindspore/ops/_grad_experimental/grad_nn_ops.py +0 -53
  235. mindspore/ops/_grad_experimental/grad_quant_ops.py +3 -3
  236. mindspore/ops/_grad_experimental/grad_sparse.py +1 -1
  237. mindspore/ops/_grad_experimental/grad_sparse_ops.py +3 -3
  238. mindspore/ops/_op_impl/__init__.py +0 -1
  239. mindspore/ops/_op_impl/aicpu/__init__.py +1 -0
  240. mindspore/ops/_op_impl/aicpu/gamma.py +2 -0
  241. mindspore/ops/_op_impl/{cpu/concat.py → aicpu/generate_eod_mask.py} +16 -17
  242. mindspore/ops/_op_impl/aicpu/log_uniform_candidate_sampler.py +1 -3
  243. mindspore/ops/_op_impl/aicpu/poisson.py +2 -0
  244. mindspore/ops/_op_impl/cpu/__init__.py +1 -3
  245. mindspore/ops/_op_impl/cpu/adam.py +2 -2
  246. mindspore/ops/_op_impl/cpu/adam_weight_decay.py +3 -2
  247. mindspore/ops/_op_impl/cpu/maximum_grad.py +16 -14
  248. mindspore/ops/_op_impl/cpu/minimum_grad.py +8 -0
  249. mindspore/ops/_vmap/vmap_array_ops.py +164 -101
  250. mindspore/ops/_vmap/vmap_base.py +8 -1
  251. mindspore/ops/_vmap/vmap_grad_math_ops.py +95 -9
  252. mindspore/ops/_vmap/vmap_grad_nn_ops.py +143 -58
  253. mindspore/ops/_vmap/vmap_image_ops.py +70 -13
  254. mindspore/ops/_vmap/vmap_math_ops.py +130 -58
  255. mindspore/ops/_vmap/vmap_nn_ops.py +249 -115
  256. mindspore/ops/_vmap/vmap_other_ops.py +1 -1
  257. mindspore/ops/auto_generate/__init__.py +31 -0
  258. mindspore/ops/auto_generate/cpp_create_prim_instance_helper.py +231 -0
  259. mindspore/ops/auto_generate/gen_arg_dtype_cast.py +250 -0
  260. mindspore/ops/auto_generate/gen_arg_handler.py +197 -0
  261. mindspore/ops/auto_generate/gen_extend_func.py +980 -0
  262. mindspore/ops/auto_generate/gen_ops_def.py +6443 -0
  263. mindspore/ops/auto_generate/gen_ops_prim.py +13167 -0
  264. mindspore/ops/auto_generate/pyboost_inner_prim.py +429 -0
  265. mindspore/ops/composite/__init__.py +5 -2
  266. mindspore/ops/composite/base.py +121 -23
  267. mindspore/ops/composite/math_ops.py +10 -49
  268. mindspore/ops/composite/multitype_ops/_compile_utils.py +191 -618
  269. mindspore/ops/composite/multitype_ops/_constexpr_utils.py +25 -134
  270. mindspore/ops/composite/multitype_ops/add_impl.py +6 -0
  271. mindspore/ops/composite/multitype_ops/bitwise_and_impl.py +6 -0
  272. mindspore/ops/composite/multitype_ops/bitwise_or_impl.py +6 -0
  273. mindspore/ops/composite/multitype_ops/bitwise_xor_impl.py +6 -0
  274. mindspore/ops/composite/multitype_ops/div_impl.py +8 -0
  275. mindspore/ops/composite/multitype_ops/equal_impl.py +6 -0
  276. mindspore/ops/composite/multitype_ops/floordiv_impl.py +8 -0
  277. mindspore/ops/composite/multitype_ops/getitem_impl.py +6 -0
  278. mindspore/ops/composite/multitype_ops/greater_equal_impl.py +6 -0
  279. mindspore/ops/composite/multitype_ops/greater_impl.py +6 -0
  280. mindspore/ops/composite/multitype_ops/in_impl.py +8 -2
  281. mindspore/ops/composite/multitype_ops/left_shift_impl.py +6 -0
  282. mindspore/ops/composite/multitype_ops/less_equal_impl.py +6 -0
  283. mindspore/ops/composite/multitype_ops/less_impl.py +6 -0
  284. mindspore/ops/composite/multitype_ops/logic_not_impl.py +6 -0
  285. mindspore/ops/composite/multitype_ops/logical_and_impl.py +6 -0
  286. mindspore/ops/composite/multitype_ops/logical_or_impl.py +6 -0
  287. mindspore/ops/composite/multitype_ops/mod_impl.py +6 -0
  288. mindspore/ops/composite/multitype_ops/mul_impl.py +6 -0
  289. mindspore/ops/composite/multitype_ops/negative_impl.py +9 -3
  290. mindspore/ops/composite/multitype_ops/not_equal_impl.py +6 -0
  291. mindspore/ops/composite/multitype_ops/not_in_impl.py +6 -1
  292. mindspore/ops/composite/multitype_ops/ones_like_impl.py +2 -2
  293. mindspore/ops/composite/multitype_ops/pow_impl.py +6 -0
  294. mindspore/ops/composite/multitype_ops/right_shift_impl.py +6 -0
  295. mindspore/ops/composite/multitype_ops/setitem_impl.py +32 -21
  296. mindspore/ops/composite/multitype_ops/sub_impl.py +6 -0
  297. mindspore/ops/composite/multitype_ops/zeros_like_impl.py +6 -3
  298. mindspore/ops/deprecated.py +14 -3
  299. mindspore/ops/extend/__init__.py +53 -0
  300. mindspore/ops/extend/array_func.py +218 -0
  301. mindspore/ops/extend/math_func.py +76 -0
  302. mindspore/ops/extend/nn_func.py +308 -0
  303. mindspore/ops/function/__init__.py +31 -11
  304. mindspore/ops/function/array_func.py +848 -1736
  305. mindspore/ops/function/clip_func.py +19 -31
  306. mindspore/ops/function/debug_func.py +2 -5
  307. mindspore/ops/function/fft_func.py +31 -0
  308. mindspore/ops/function/grad/grad_func.py +27 -20
  309. mindspore/ops/function/image_func.py +27 -21
  310. mindspore/ops/function/linalg_func.py +30 -53
  311. mindspore/ops/function/math_func.py +916 -2791
  312. mindspore/ops/function/nn_func.py +1445 -889
  313. mindspore/ops/function/other_func.py +6 -7
  314. mindspore/ops/function/parameter_func.py +6 -92
  315. mindspore/ops/function/random_func.py +254 -108
  316. mindspore/ops/function/reshard_func.py +102 -0
  317. mindspore/ops/function/sparse_func.py +4 -4
  318. mindspore/ops/function/sparse_unary_func.py +11 -18
  319. mindspore/ops/function/spectral_func.py +1 -1
  320. mindspore/ops/function/vmap_func.py +15 -14
  321. mindspore/ops/functional.py +342 -343
  322. mindspore/ops/op_info_register.py +16 -43
  323. mindspore/ops/operations/__init__.py +32 -23
  324. mindspore/ops/operations/_embedding_cache_ops.py +1 -1
  325. mindspore/ops/operations/_grad_ops.py +21 -853
  326. mindspore/ops/operations/_infer_ops.py +19 -0
  327. mindspore/ops/operations/_inner_ops.py +155 -511
  328. mindspore/ops/operations/_quant_ops.py +4 -4
  329. mindspore/ops/operations/_rl_inner_ops.py +3 -3
  330. mindspore/ops/operations/_scalar_ops.py +5 -480
  331. mindspore/ops/operations/_sequence_ops.py +6 -36
  332. mindspore/ops/operations/_tensor_array.py +8 -8
  333. mindspore/ops/operations/array_ops.py +112 -2698
  334. mindspore/ops/operations/comm_ops.py +801 -118
  335. mindspore/ops/operations/custom_ops.py +62 -121
  336. mindspore/ops/operations/debug_ops.py +105 -36
  337. mindspore/ops/operations/image_ops.py +3 -219
  338. mindspore/ops/operations/inner_ops.py +54 -40
  339. mindspore/ops/operations/linalg_ops.py +1 -49
  340. mindspore/ops/operations/manually_defined/__init__.py +24 -0
  341. mindspore/ops/operations/manually_defined/_inner.py +61 -0
  342. mindspore/ops/operations/manually_defined/ops_def.py +2016 -0
  343. mindspore/ops/operations/math_ops.py +621 -4654
  344. mindspore/ops/operations/nn_ops.py +316 -2226
  345. mindspore/ops/operations/other_ops.py +53 -45
  346. mindspore/ops/operations/random_ops.py +4 -51
  347. mindspore/ops/operations/reshard_ops.py +53 -0
  348. mindspore/ops/operations/sparse_ops.py +8 -8
  349. mindspore/ops/primitive.py +204 -103
  350. mindspore/ops/silent_check.py +162 -0
  351. mindspore/ops_generate/__init__.py +27 -0
  352. mindspore/ops_generate/arg_dtype_cast.py +250 -0
  353. mindspore/ops_generate/arg_handler.py +197 -0
  354. mindspore/ops_generate/gen_aclnn_implement.py +263 -0
  355. mindspore/ops_generate/gen_ops.py +1084 -0
  356. mindspore/ops_generate/gen_ops_inner_prim.py +131 -0
  357. mindspore/ops_generate/gen_pyboost_func.py +968 -0
  358. mindspore/ops_generate/gen_utils.py +209 -0
  359. mindspore/ops_generate/op_proto.py +138 -0
  360. mindspore/ops_generate/pyboost_utils.py +354 -0
  361. mindspore/ops_generate/template.py +239 -0
  362. mindspore/parallel/__init__.py +7 -4
  363. mindspore/parallel/_auto_parallel_context.py +155 -6
  364. mindspore/parallel/_cell_wrapper.py +16 -9
  365. mindspore/parallel/_cost_model_context.py +1 -1
  366. mindspore/parallel/_dp_allreduce_fusion.py +159 -159
  367. mindspore/parallel/_parallel_serialization.py +62 -14
  368. mindspore/parallel/_ps_context.py +1 -1
  369. mindspore/parallel/_recovery_context.py +1 -1
  370. mindspore/parallel/_tensor.py +18 -9
  371. mindspore/parallel/_transformer/__init__.py +1 -1
  372. mindspore/parallel/_transformer/layers.py +1 -1
  373. mindspore/parallel/_transformer/loss.py +1 -1
  374. mindspore/parallel/_transformer/moe.py +1 -1
  375. mindspore/parallel/_transformer/op_parallel_config.py +1 -1
  376. mindspore/parallel/_transformer/transformer.py +10 -10
  377. mindspore/parallel/_utils.py +161 -6
  378. mindspore/parallel/algo_parameter_config.py +6 -8
  379. mindspore/parallel/checkpoint_transform.py +369 -64
  380. mindspore/parallel/cluster/__init__.py +15 -0
  381. mindspore/parallel/cluster/process_entity/__init__.py +18 -0
  382. mindspore/parallel/cluster/process_entity/_api.py +344 -0
  383. mindspore/parallel/cluster/process_entity/_utils.py +126 -0
  384. mindspore/parallel/cluster/run.py +136 -0
  385. mindspore/parallel/mpi/__init__.py +1 -1
  386. mindspore/parallel/mpi/_mpi_config.py +1 -1
  387. mindspore/parallel/parameter_broadcast.py +152 -0
  388. mindspore/parallel/shard.py +128 -17
  389. mindspore/profiler/__init__.py +3 -2
  390. mindspore/profiler/common/process_pool.py +41 -0
  391. mindspore/profiler/common/singleton.py +28 -0
  392. mindspore/profiler/common/util.py +125 -0
  393. mindspore/profiler/envprofiling.py +2 -2
  394. mindspore/{_extends/parallel_compile/tbe_compiler → profiler/parser/ascend_analysis}/__init__.py +1 -1
  395. mindspore/profiler/parser/ascend_analysis/constant.py +53 -0
  396. mindspore/profiler/parser/ascend_analysis/file_manager.py +159 -0
  397. mindspore/profiler/parser/ascend_analysis/function_event.py +161 -0
  398. mindspore/profiler/parser/ascend_analysis/fwk_cann_parser.py +131 -0
  399. mindspore/profiler/parser/ascend_analysis/fwk_file_parser.py +85 -0
  400. mindspore/profiler/parser/ascend_analysis/msprof_timeline_parser.py +57 -0
  401. mindspore/profiler/parser/ascend_analysis/profiler_info_parser.py +116 -0
  402. mindspore/profiler/parser/ascend_analysis/tlv_decoder.py +86 -0
  403. mindspore/profiler/parser/ascend_analysis/trace_event_manager.py +68 -0
  404. mindspore/profiler/parser/ascend_cluster_generator.py +116 -0
  405. mindspore/profiler/parser/ascend_communicate_generator.py +314 -0
  406. mindspore/profiler/parser/ascend_flops_generator.py +27 -5
  407. mindspore/profiler/parser/ascend_fpbp_generator.py +8 -2
  408. mindspore/profiler/parser/ascend_hccl_generator.py +31 -280
  409. mindspore/profiler/parser/ascend_integrate_generator.py +42 -0
  410. mindspore/profiler/parser/ascend_memory_generator.py +185 -0
  411. mindspore/profiler/parser/ascend_msprof_exporter.py +151 -126
  412. mindspore/profiler/parser/ascend_msprof_generator.py +75 -274
  413. mindspore/profiler/parser/ascend_op_generator.py +94 -36
  414. mindspore/profiler/parser/ascend_timeline_generator.py +297 -131
  415. mindspore/profiler/parser/base_timeline_generator.py +17 -3
  416. mindspore/profiler/parser/cpu_gpu_timeline_generator.py +2 -1
  417. mindspore/profiler/parser/framework_parser.py +11 -4
  418. mindspore/profiler/parser/integrator.py +3 -1
  419. mindspore/profiler/parser/memory_usage_parser.py +8 -2
  420. mindspore/profiler/parser/minddata_analyzer.py +8 -2
  421. mindspore/profiler/parser/minddata_parser.py +73 -4
  422. mindspore/profiler/parser/msadvisor_analyzer.py +5 -3
  423. mindspore/profiler/parser/msadvisor_parser.py +10 -4
  424. mindspore/profiler/parser/profiler_info.py +16 -1
  425. mindspore/profiler/profiling.py +522 -195
  426. mindspore/rewrite/__init__.py +2 -13
  427. mindspore/rewrite/api/node.py +123 -37
  428. mindspore/rewrite/api/pattern_engine.py +2 -3
  429. mindspore/rewrite/api/scoped_value.py +16 -15
  430. mindspore/rewrite/api/symbol_tree.py +46 -30
  431. mindspore/rewrite/ast_helpers/__init__.py +3 -6
  432. mindspore/rewrite/ast_helpers/ast_converter.py +143 -0
  433. mindspore/rewrite/ast_helpers/ast_finder.py +48 -0
  434. mindspore/rewrite/ast_helpers/ast_flattener.py +268 -0
  435. mindspore/rewrite/ast_helpers/ast_modifier.py +160 -92
  436. mindspore/rewrite/common/__init__.py +1 -2
  437. mindspore/rewrite/common/config.py +24 -0
  438. mindspore/rewrite/common/{rewrite_elog.py → error_log.py} +39 -39
  439. mindspore/rewrite/{namer.py → common/namer.py} +63 -18
  440. mindspore/rewrite/common/namespace.py +118 -0
  441. mindspore/rewrite/node/__init__.py +5 -5
  442. mindspore/rewrite/node/call_function.py +23 -7
  443. mindspore/rewrite/node/cell_container.py +7 -3
  444. mindspore/rewrite/node/control_flow.py +53 -28
  445. mindspore/rewrite/node/node.py +212 -196
  446. mindspore/rewrite/node/node_manager.py +51 -22
  447. mindspore/rewrite/node/node_topological_manager.py +3 -23
  448. mindspore/rewrite/parsers/__init__.py +12 -0
  449. mindspore/rewrite/parsers/arguments_parser.py +8 -9
  450. mindspore/rewrite/parsers/assign_parser.py +637 -413
  451. mindspore/rewrite/parsers/attribute_parser.py +3 -4
  452. mindspore/rewrite/parsers/class_def_parser.py +115 -148
  453. mindspore/rewrite/parsers/constant_parser.py +5 -5
  454. mindspore/rewrite/parsers/container_parser.py +4 -6
  455. mindspore/rewrite/parsers/expr_parser.py +55 -0
  456. mindspore/rewrite/parsers/for_parser.py +31 -98
  457. mindspore/rewrite/parsers/function_def_parser.py +13 -5
  458. mindspore/rewrite/parsers/if_parser.py +28 -10
  459. mindspore/rewrite/parsers/module_parser.py +8 -182
  460. mindspore/rewrite/parsers/parser.py +1 -5
  461. mindspore/rewrite/parsers/parser_register.py +1 -1
  462. mindspore/rewrite/parsers/return_parser.py +5 -10
  463. mindspore/rewrite/parsers/while_parser.py +59 -0
  464. mindspore/rewrite/sparsify/utils.py +1 -1
  465. mindspore/rewrite/symbol_tree/__init__.py +20 -0
  466. mindspore/rewrite/{symbol_tree.py → symbol_tree/symbol_tree.py} +704 -185
  467. mindspore/rewrite/{symbol_tree_builder.py → symbol_tree/symbol_tree_builder.py} +8 -8
  468. mindspore/rewrite/{symbol_tree_dumper.py → symbol_tree/symbol_tree_dumper.py} +4 -4
  469. mindspore/run_check/_check_version.py +6 -14
  470. mindspore/run_check/run_check.py +1 -1
  471. mindspore/safeguard/rewrite_obfuscation.py +9 -19
  472. mindspore/swresample-4.dll +0 -0
  473. mindspore/swscale-6.dll +0 -0
  474. mindspore/tinyxml2.dll +0 -0
  475. mindspore/train/__init__.py +6 -5
  476. mindspore/train/_utils.py +178 -4
  477. mindspore/train/amp.py +167 -245
  478. mindspore/train/anf_ir_pb2.py +14 -2
  479. mindspore/train/callback/__init__.py +5 -2
  480. mindspore/train/callback/_backup_and_restore.py +5 -5
  481. mindspore/train/callback/_callback.py +4 -4
  482. mindspore/train/callback/_checkpoint.py +151 -37
  483. mindspore/train/callback/_cluster_monitor.py +201 -0
  484. mindspore/train/callback/_early_stop.py +2 -2
  485. mindspore/train/callback/_flops_collector.py +238 -0
  486. mindspore/train/callback/_landscape.py +16 -11
  487. mindspore/train/callback/_loss_monitor.py +2 -2
  488. mindspore/train/callback/_mindio_ttp.py +443 -0
  489. mindspore/train/callback/_on_request_exit.py +2 -2
  490. mindspore/train/callback/_reduce_lr_on_plateau.py +2 -2
  491. mindspore/train/callback/_summary_collector.py +13 -14
  492. mindspore/train/callback/_time_monitor.py +3 -3
  493. mindspore/train/data_sink.py +6 -5
  494. mindspore/train/dataset_helper.py +66 -21
  495. mindspore/train/loss_scale_manager.py +2 -2
  496. mindspore/train/metrics/accuracy.py +7 -7
  497. mindspore/train/metrics/confusion_matrix.py +8 -6
  498. mindspore/train/metrics/cosine_similarity.py +6 -4
  499. mindspore/train/metrics/error.py +2 -2
  500. mindspore/train/metrics/metric.py +3 -3
  501. mindspore/train/metrics/perplexity.py +2 -1
  502. mindspore/train/metrics/topk.py +2 -2
  503. mindspore/train/mind_ir_pb2.py +89 -15
  504. mindspore/train/model.py +298 -56
  505. mindspore/train/serialization.py +501 -221
  506. mindspore/train/summary/_summary_adapter.py +1 -1
  507. mindspore/train/summary/_writer_pool.py +1 -1
  508. mindspore/train/summary/summary_record.py +56 -34
  509. mindspore/train/train_thor/convert_utils.py +3 -3
  510. mindspore/turbojpeg.dll +0 -0
  511. mindspore/version.py +1 -1
  512. {mindspore-2.2.11.dist-info → mindspore-2.3.0.dist-info}/METADATA +3 -3
  513. mindspore-2.3.0.dist-info/RECORD +1400 -0
  514. {mindspore-2.2.11.dist-info → mindspore-2.3.0.dist-info}/entry_points.txt +1 -0
  515. mindspore/_extends/parallel_compile/tbe_compiler/tbe_adapter.py +0 -662
  516. mindspore/_extends/parallel_compile/tbe_compiler/tbe_helper.py +0 -377
  517. mindspore/_extends/parallel_compile/tbe_compiler/tbe_job.py +0 -201
  518. mindspore/_extends/parallel_compile/tbe_compiler/tbe_job_manager.py +0 -515
  519. mindspore/gen_ops.py +0 -273
  520. mindspore/nn/layer/flash_attention.py +0 -189
  521. mindspore/ops/_op_impl/cpu/tensor_shape.py +0 -42
  522. mindspore/ops/_op_impl/tbe/__init__.py +0 -47
  523. mindspore/ops/_op_impl/tbe/abs.py +0 -38
  524. mindspore/ops/_op_impl/tbe/abs_ds.py +0 -39
  525. mindspore/ops/_op_impl/tbe/abs_grad.py +0 -43
  526. mindspore/ops/_op_impl/tbe/abs_grad_ds.py +0 -44
  527. mindspore/ops/_op_impl/tbe/accumulate_n_v2.py +0 -41
  528. mindspore/ops/_op_impl/tbe/accumulate_n_v2_ds.py +0 -42
  529. mindspore/ops/_op_impl/tbe/acos.py +0 -37
  530. mindspore/ops/_op_impl/tbe/acos_ds.py +0 -38
  531. mindspore/ops/_op_impl/tbe/acos_grad.py +0 -43
  532. mindspore/ops/_op_impl/tbe/acos_grad_ds.py +0 -44
  533. mindspore/ops/_op_impl/tbe/acosh.py +0 -37
  534. mindspore/ops/_op_impl/tbe/acosh_ds.py +0 -38
  535. mindspore/ops/_op_impl/tbe/acosh_grad.py +0 -43
  536. mindspore/ops/_op_impl/tbe/acosh_grad_ds.py +0 -44
  537. mindspore/ops/_op_impl/tbe/act_ulq_clamp_max_grad.py +0 -38
  538. mindspore/ops/_op_impl/tbe/act_ulq_clamp_min_grad.py +0 -38
  539. mindspore/ops/_op_impl/tbe/acts_ulq.py +0 -45
  540. mindspore/ops/_op_impl/tbe/acts_ulq_input_grad.py +0 -38
  541. mindspore/ops/_op_impl/tbe/adam_apply_one.py +0 -50
  542. mindspore/ops/_op_impl/tbe/adam_apply_one_assign.py +0 -53
  543. mindspore/ops/_op_impl/tbe/adam_apply_one_ds.py +0 -51
  544. mindspore/ops/_op_impl/tbe/adam_apply_one_with_decay.py +0 -54
  545. mindspore/ops/_op_impl/tbe/adam_apply_one_with_decay_assign.py +0 -54
  546. mindspore/ops/_op_impl/tbe/adam_apply_one_with_decay_ds.py +0 -55
  547. mindspore/ops/_op_impl/tbe/adaptive_max_pool2d.py +0 -37
  548. mindspore/ops/_op_impl/tbe/add.py +0 -42
  549. mindspore/ops/_op_impl/tbe/add_ds.py +0 -43
  550. mindspore/ops/_op_impl/tbe/add_n.py +0 -39
  551. mindspore/ops/_op_impl/tbe/add_n_ds.py +0 -40
  552. mindspore/ops/_op_impl/tbe/addcdiv.py +0 -41
  553. mindspore/ops/_op_impl/tbe/addcdiv_ds.py +0 -42
  554. mindspore/ops/_op_impl/tbe/addcmul.py +0 -43
  555. mindspore/ops/_op_impl/tbe/addcmul_ds.py +0 -44
  556. mindspore/ops/_op_impl/tbe/apply_ada_max.py +0 -68
  557. mindspore/ops/_op_impl/tbe/apply_ada_max_ds.py +0 -69
  558. mindspore/ops/_op_impl/tbe/apply_adadelta.py +0 -66
  559. mindspore/ops/_op_impl/tbe/apply_adadelta_ds.py +0 -67
  560. mindspore/ops/_op_impl/tbe/apply_adagrad.py +0 -55
  561. mindspore/ops/_op_impl/tbe/apply_adagrad_d_a.py +0 -67
  562. mindspore/ops/_op_impl/tbe/apply_adagrad_ds.py +0 -56
  563. mindspore/ops/_op_impl/tbe/apply_adagrad_v2.py +0 -48
  564. mindspore/ops/_op_impl/tbe/apply_adagrad_v2_ds.py +0 -49
  565. mindspore/ops/_op_impl/tbe/apply_adam.py +0 -79
  566. mindspore/ops/_op_impl/tbe/apply_adam_ds.py +0 -80
  567. mindspore/ops/_op_impl/tbe/apply_adam_with_amsgrad.py +0 -60
  568. mindspore/ops/_op_impl/tbe/apply_adam_with_amsgrad_ds.py +0 -61
  569. mindspore/ops/_op_impl/tbe/apply_add_sign.py +0 -65
  570. mindspore/ops/_op_impl/tbe/apply_add_sign_ds.py +0 -66
  571. mindspore/ops/_op_impl/tbe/apply_centered_rms_prop.py +0 -77
  572. mindspore/ops/_op_impl/tbe/apply_centered_rms_prop_ds.py +0 -78
  573. mindspore/ops/_op_impl/tbe/apply_ftrl.py +0 -67
  574. mindspore/ops/_op_impl/tbe/apply_ftrl_ds.py +0 -68
  575. mindspore/ops/_op_impl/tbe/apply_gradient_descent.py +0 -44
  576. mindspore/ops/_op_impl/tbe/apply_gradient_descent_ds.py +0 -45
  577. mindspore/ops/_op_impl/tbe/apply_keras_momentum.py +0 -49
  578. mindspore/ops/_op_impl/tbe/apply_momentum.py +0 -64
  579. mindspore/ops/_op_impl/tbe/apply_momentum_ds.py +0 -65
  580. mindspore/ops/_op_impl/tbe/apply_power_sign.py +0 -65
  581. mindspore/ops/_op_impl/tbe/apply_power_sign_ds.py +0 -66
  582. mindspore/ops/_op_impl/tbe/apply_proximal_adagrad.py +0 -57
  583. mindspore/ops/_op_impl/tbe/apply_proximal_adagrad_ds.py +0 -58
  584. mindspore/ops/_op_impl/tbe/apply_proximal_gradient_descent.py +0 -54
  585. mindspore/ops/_op_impl/tbe/apply_proximal_gradient_descent_ds.py +0 -55
  586. mindspore/ops/_op_impl/tbe/apply_rms_prop.py +0 -52
  587. mindspore/ops/_op_impl/tbe/approximate_equal.py +0 -39
  588. mindspore/ops/_op_impl/tbe/approximate_equal_ds.py +0 -40
  589. mindspore/ops/_op_impl/tbe/arg_max.py +0 -38
  590. mindspore/ops/_op_impl/tbe/arg_max_with_value.py +0 -38
  591. mindspore/ops/_op_impl/tbe/arg_max_with_value_ds.py +0 -39
  592. mindspore/ops/_op_impl/tbe/arg_min.py +0 -38
  593. mindspore/ops/_op_impl/tbe/arg_min_v2_ds.py +0 -40
  594. mindspore/ops/_op_impl/tbe/arg_min_with_value.py +0 -38
  595. mindspore/ops/_op_impl/tbe/arg_min_with_value_ds.py +0 -39
  596. mindspore/ops/_op_impl/tbe/asin.py +0 -37
  597. mindspore/ops/_op_impl/tbe/asin_ds.py +0 -38
  598. mindspore/ops/_op_impl/tbe/asin_grad.py +0 -43
  599. mindspore/ops/_op_impl/tbe/asin_grad_ds.py +0 -44
  600. mindspore/ops/_op_impl/tbe/asinh.py +0 -37
  601. mindspore/ops/_op_impl/tbe/asinh_ds.py +0 -38
  602. mindspore/ops/_op_impl/tbe/asinh_grad.py +0 -43
  603. mindspore/ops/_op_impl/tbe/asinh_grad_ds.py +0 -44
  604. mindspore/ops/_op_impl/tbe/assign.py +0 -79
  605. mindspore/ops/_op_impl/tbe/assign_add.py +0 -59
  606. mindspore/ops/_op_impl/tbe/assign_add_ds.py +0 -60
  607. mindspore/ops/_op_impl/tbe/assign_ds.py +0 -80
  608. mindspore/ops/_op_impl/tbe/assign_sub.py +0 -55
  609. mindspore/ops/_op_impl/tbe/assign_sub_ds.py +0 -56
  610. mindspore/ops/_op_impl/tbe/atan.py +0 -37
  611. mindspore/ops/_op_impl/tbe/atan2.py +0 -38
  612. mindspore/ops/_op_impl/tbe/atan2_ds.py +0 -39
  613. mindspore/ops/_op_impl/tbe/atan_ds.py +0 -38
  614. mindspore/ops/_op_impl/tbe/atan_grad.py +0 -43
  615. mindspore/ops/_op_impl/tbe/atan_grad_ds.py +0 -44
  616. mindspore/ops/_op_impl/tbe/atanh.py +0 -37
  617. mindspore/ops/_op_impl/tbe/atanh_ds.py +0 -38
  618. mindspore/ops/_op_impl/tbe/avg_pool.py +0 -43
  619. mindspore/ops/_op_impl/tbe/avg_pool_3d.py +0 -44
  620. mindspore/ops/_op_impl/tbe/avg_pool_3d_grad.py +0 -45
  621. mindspore/ops/_op_impl/tbe/avg_pool_ds.py +0 -44
  622. mindspore/ops/_op_impl/tbe/avg_pool_grad.py +0 -42
  623. mindspore/ops/_op_impl/tbe/avg_pool_grad_vm.py +0 -42
  624. mindspore/ops/_op_impl/tbe/basic_lstm_cell.py +0 -57
  625. mindspore/ops/_op_impl/tbe/basic_lstm_cell_c_state_grad.py +0 -50
  626. mindspore/ops/_op_impl/tbe/basic_lstm_cell_c_state_grad_v2.py +0 -51
  627. mindspore/ops/_op_impl/tbe/basic_lstm_cell_input_grad.py +0 -42
  628. mindspore/ops/_op_impl/tbe/basic_lstm_cell_weight_grad.py +0 -41
  629. mindspore/ops/_op_impl/tbe/batch_matmul.py +0 -42
  630. mindspore/ops/_op_impl/tbe/batch_matmul_ds.py +0 -41
  631. mindspore/ops/_op_impl/tbe/batch_matmul_v2.py +0 -47
  632. mindspore/ops/_op_impl/tbe/batch_to_space.py +0 -38
  633. mindspore/ops/_op_impl/tbe/batch_to_space_nd.py +0 -38
  634. mindspore/ops/_op_impl/tbe/batch_to_space_nd_ds.py +0 -39
  635. mindspore/ops/_op_impl/tbe/batch_to_space_nd_v2.py +0 -41
  636. mindspore/ops/_op_impl/tbe/batchnorm.py +0 -58
  637. mindspore/ops/_op_impl/tbe/batchnorm_grad.py +0 -58
  638. mindspore/ops/_op_impl/tbe/bce_with_logits_loss.py +0 -42
  639. mindspore/ops/_op_impl/tbe/bessel_i0e.py +0 -37
  640. mindspore/ops/_op_impl/tbe/bessel_i0e_ds.py +0 -38
  641. mindspore/ops/_op_impl/tbe/bessel_i1e.py +0 -37
  642. mindspore/ops/_op_impl/tbe/bessel_i1e_ds.py +0 -38
  643. mindspore/ops/_op_impl/tbe/bias_add.py +0 -38
  644. mindspore/ops/_op_impl/tbe/bias_add_ds.py +0 -39
  645. mindspore/ops/_op_impl/tbe/bias_add_grad.py +0 -53
  646. mindspore/ops/_op_impl/tbe/binary_cross_entropy.py +0 -39
  647. mindspore/ops/_op_impl/tbe/binary_cross_entropy_ds.py +0 -40
  648. mindspore/ops/_op_impl/tbe/binary_cross_entropy_grad.py +0 -44
  649. mindspore/ops/_op_impl/tbe/binary_cross_entropy_grad_ds.py +0 -45
  650. mindspore/ops/_op_impl/tbe/bitwise_and.py +0 -39
  651. mindspore/ops/_op_impl/tbe/bitwise_and_ds.py +0 -40
  652. mindspore/ops/_op_impl/tbe/bitwise_or.py +0 -39
  653. mindspore/ops/_op_impl/tbe/bitwise_or_ds.py +0 -40
  654. mindspore/ops/_op_impl/tbe/bitwise_xor.py +0 -39
  655. mindspore/ops/_op_impl/tbe/bitwise_xor_ds.py +0 -40
  656. mindspore/ops/_op_impl/tbe/bn_infer.py +0 -43
  657. mindspore/ops/_op_impl/tbe/bn_infer_ds.py +0 -45
  658. mindspore/ops/_op_impl/tbe/bn_infer_grad.py +0 -41
  659. mindspore/ops/_op_impl/tbe/bn_infer_grad_ds.py +0 -40
  660. mindspore/ops/_op_impl/tbe/bn_inference.py +0 -50
  661. mindspore/ops/_op_impl/tbe/bn_training_reduce.py +0 -38
  662. mindspore/ops/_op_impl/tbe/bn_training_reduce_ds.py +0 -39
  663. mindspore/ops/_op_impl/tbe/bn_training_reduce_grad.py +0 -46
  664. mindspore/ops/_op_impl/tbe/bn_training_reduce_grad_ds.py +0 -47
  665. mindspore/ops/_op_impl/tbe/bn_training_update.py +0 -52
  666. mindspore/ops/_op_impl/tbe/bn_training_update_ds.py +0 -53
  667. mindspore/ops/_op_impl/tbe/bn_training_update_grad.py +0 -44
  668. mindspore/ops/_op_impl/tbe/bn_training_update_grad_ds.py +0 -45
  669. mindspore/ops/_op_impl/tbe/bn_training_update_v2.py +0 -48
  670. mindspore/ops/_op_impl/tbe/bn_training_update_v3.py +0 -51
  671. mindspore/ops/_op_impl/tbe/bounding_box_decode.py +0 -41
  672. mindspore/ops/_op_impl/tbe/bounding_box_decode_ds.py +0 -42
  673. mindspore/ops/_op_impl/tbe/bounding_box_encode.py +0 -38
  674. mindspore/ops/_op_impl/tbe/broadcast_to.py +0 -40
  675. mindspore/ops/_op_impl/tbe/broadcast_to_ds.py +0 -44
  676. mindspore/ops/_op_impl/tbe/cast.py +0 -55
  677. mindspore/ops/_op_impl/tbe/cast_ds.py +0 -58
  678. mindspore/ops/_op_impl/tbe/cdist.py +0 -38
  679. mindspore/ops/_op_impl/tbe/cdist_grad.py +0 -42
  680. mindspore/ops/_op_impl/tbe/ceil.py +0 -37
  681. mindspore/ops/_op_impl/tbe/ceil_ds.py +0 -38
  682. mindspore/ops/_op_impl/tbe/celu.py +0 -39
  683. mindspore/ops/_op_impl/tbe/centralization.py +0 -39
  684. mindspore/ops/_op_impl/tbe/check_valid.py +0 -38
  685. mindspore/ops/_op_impl/tbe/check_valid_ds.py +0 -39
  686. mindspore/ops/_op_impl/tbe/clip_by_norm_no_div_sum.py +0 -41
  687. mindspore/ops/_op_impl/tbe/clip_by_norm_no_div_sum_ds.py +0 -42
  688. mindspore/ops/_op_impl/tbe/clip_by_value.py +0 -41
  689. mindspore/ops/_op_impl/tbe/clip_by_value_ds.py +0 -42
  690. mindspore/ops/_op_impl/tbe/concat.py +0 -40
  691. mindspore/ops/_op_impl/tbe/concat_ds.py +0 -38
  692. mindspore/ops/_op_impl/tbe/confusion_matrix.py +0 -63
  693. mindspore/ops/_op_impl/tbe/confusion_mul_grad.py +0 -40
  694. mindspore/ops/_op_impl/tbe/confusion_softmax_grad.py +0 -41
  695. mindspore/ops/_op_impl/tbe/confusion_transpose_d.py +0 -39
  696. mindspore/ops/_op_impl/tbe/conv2d.py +0 -47
  697. mindspore/ops/_op_impl/tbe/conv2d_backprop_filter.py +0 -42
  698. mindspore/ops/_op_impl/tbe/conv2d_backprop_filter_ds.py +0 -43
  699. mindspore/ops/_op_impl/tbe/conv2d_backprop_input.py +0 -42
  700. mindspore/ops/_op_impl/tbe/conv2d_backprop_input_ds.py +0 -44
  701. mindspore/ops/_op_impl/tbe/conv2d_ds.py +0 -47
  702. mindspore/ops/_op_impl/tbe/conv2d_transpose.py +0 -48
  703. mindspore/ops/_op_impl/tbe/conv3d.py +0 -45
  704. mindspore/ops/_op_impl/tbe/conv3d_backprop_filter.py +0 -42
  705. mindspore/ops/_op_impl/tbe/conv3d_backprop_input.py +0 -42
  706. mindspore/ops/_op_impl/tbe/conv3d_transpose.py +0 -47
  707. mindspore/ops/_op_impl/tbe/conv3d_transpose_ds.py +0 -48
  708. mindspore/ops/_op_impl/tbe/cos.py +0 -37
  709. mindspore/ops/_op_impl/tbe/cos_ds.py +0 -38
  710. mindspore/ops/_op_impl/tbe/cosh.py +0 -37
  711. mindspore/ops/_op_impl/tbe/cosh_ds.py +0 -38
  712. mindspore/ops/_op_impl/tbe/ctc_loss_v2.py +0 -42
  713. mindspore/ops/_op_impl/tbe/ctc_loss_v2_grad.py +0 -44
  714. mindspore/ops/_op_impl/tbe/cum_sum.py +0 -42
  715. mindspore/ops/_op_impl/tbe/cum_sum_ds.py +0 -44
  716. mindspore/ops/_op_impl/tbe/cummin.py +0 -41
  717. mindspore/ops/_op_impl/tbe/cumprod.py +0 -42
  718. mindspore/ops/_op_impl/tbe/data_format_dim_map.py +0 -38
  719. mindspore/ops/_op_impl/tbe/data_format_dim_map_ds.py +0 -40
  720. mindspore/ops/_op_impl/tbe/deformable_offsets.py +0 -45
  721. mindspore/ops/_op_impl/tbe/deformable_offsets_grad.py +0 -48
  722. mindspore/ops/_op_impl/tbe/depth_to_space_ds.py +0 -49
  723. mindspore/ops/_op_impl/tbe/depthwise_conv2d.py +0 -44
  724. mindspore/ops/_op_impl/tbe/depthwise_conv2d_backprop_filter.py +0 -41
  725. mindspore/ops/_op_impl/tbe/depthwise_conv2d_backprop_input.py +0 -41
  726. mindspore/ops/_op_impl/tbe/diag.py +0 -38
  727. mindspore/ops/_op_impl/tbe/diag_part.py +0 -38
  728. mindspore/ops/_op_impl/tbe/dilation.py +0 -40
  729. mindspore/ops/_op_impl/tbe/div.py +0 -41
  730. mindspore/ops/_op_impl/tbe/div_ds.py +0 -42
  731. mindspore/ops/_op_impl/tbe/div_no_nan.py +0 -41
  732. mindspore/ops/_op_impl/tbe/div_no_nan_ds.py +0 -42
  733. mindspore/ops/_op_impl/tbe/dropout_do_mask.py +0 -38
  734. mindspore/ops/_op_impl/tbe/dropout_do_mask_ds.py +0 -39
  735. mindspore/ops/_op_impl/tbe/dropout_do_mask_v3.py +0 -39
  736. mindspore/ops/_op_impl/tbe/dynamic_atomic_addr_clean.py +0 -34
  737. mindspore/ops/_op_impl/tbe/dynamic_gru_v2.py +0 -95
  738. mindspore/ops/_op_impl/tbe/dynamic_rnn.py +0 -82
  739. mindspore/ops/_op_impl/tbe/elu.py +0 -38
  740. mindspore/ops/_op_impl/tbe/elu_ds.py +0 -39
  741. mindspore/ops/_op_impl/tbe/elu_grad.py +0 -43
  742. mindspore/ops/_op_impl/tbe/elu_grad_ds.py +0 -44
  743. mindspore/ops/_op_impl/tbe/equal.py +0 -42
  744. mindspore/ops/_op_impl/tbe/equal_ds.py +0 -42
  745. mindspore/ops/_op_impl/tbe/erf.py +0 -37
  746. mindspore/ops/_op_impl/tbe/erf_ds.py +0 -38
  747. mindspore/ops/_op_impl/tbe/erfc.py +0 -37
  748. mindspore/ops/_op_impl/tbe/erfc_ds.py +0 -38
  749. mindspore/ops/_op_impl/tbe/erfinv.py +0 -36
  750. mindspore/ops/_op_impl/tbe/exp.py +0 -40
  751. mindspore/ops/_op_impl/tbe/exp_ds.py +0 -41
  752. mindspore/ops/_op_impl/tbe/expand_dims.py +0 -38
  753. mindspore/ops/_op_impl/tbe/expm1.py +0 -37
  754. mindspore/ops/_op_impl/tbe/expm1_ds.py +0 -38
  755. mindspore/ops/_op_impl/tbe/extract_image_patches.py +0 -41
  756. mindspore/ops/_op_impl/tbe/extract_volume_patches.py +0 -39
  757. mindspore/ops/_op_impl/tbe/fake_quant_with_min_max_vars.py +0 -39
  758. mindspore/ops/_op_impl/tbe/fake_quant_with_min_max_vars_gradient.py +0 -43
  759. mindspore/ops/_op_impl/tbe/fake_quant_with_min_max_vars_per_channel.py +0 -39
  760. mindspore/ops/_op_impl/tbe/fake_quant_with_min_max_vars_per_channel_gradient.py +0 -43
  761. mindspore/ops/_op_impl/tbe/fast_gelu.py +0 -37
  762. mindspore/ops/_op_impl/tbe/fast_gelu_ds.py +0 -38
  763. mindspore/ops/_op_impl/tbe/fast_gelu_grad.py +0 -41
  764. mindspore/ops/_op_impl/tbe/fast_gelu_grad_ds.py +0 -42
  765. mindspore/ops/_op_impl/tbe/fill.py +0 -56
  766. mindspore/ops/_op_impl/tbe/fill_ds.py +0 -42
  767. mindspore/ops/_op_impl/tbe/flatten.py +0 -48
  768. mindspore/ops/_op_impl/tbe/floor.py +0 -37
  769. mindspore/ops/_op_impl/tbe/floor_div.py +0 -41
  770. mindspore/ops/_op_impl/tbe/floor_div_ds.py +0 -42
  771. mindspore/ops/_op_impl/tbe/floor_ds.py +0 -38
  772. mindspore/ops/_op_impl/tbe/floor_mod.py +0 -39
  773. mindspore/ops/_op_impl/tbe/floor_mod_ds.py +0 -40
  774. mindspore/ops/_op_impl/tbe/fused_dbn_dw.py +0 -52
  775. mindspore/ops/_op_impl/tbe/fused_mul_add.py +0 -38
  776. mindspore/ops/_op_impl/tbe/fused_mul_add_n.py +0 -48
  777. mindspore/ops/_op_impl/tbe/fused_mul_add_n_l2loss.py +0 -53
  778. mindspore/ops/_op_impl/tbe/fused_mul_apply_momentum.py +0 -57
  779. mindspore/ops/_op_impl/tbe/fused_mul_apply_momentum_extern.py +0 -67
  780. mindspore/ops/_op_impl/tbe/gather_nd.py +0 -52
  781. mindspore/ops/_op_impl/tbe/gather_nd_ds.py +0 -48
  782. mindspore/ops/_op_impl/tbe/gather_v2.py +0 -56
  783. mindspore/ops/_op_impl/tbe/gather_v2_ds.py +0 -68
  784. mindspore/ops/_op_impl/tbe/gelu.py +0 -37
  785. mindspore/ops/_op_impl/tbe/gelu_ds.py +0 -38
  786. mindspore/ops/_op_impl/tbe/gelu_grad.py +0 -42
  787. mindspore/ops/_op_impl/tbe/gelu_grad_ds.py +0 -43
  788. mindspore/ops/_op_impl/tbe/ger.py +0 -43
  789. mindspore/ops/_op_impl/tbe/ger_ds.py +0 -44
  790. mindspore/ops/_op_impl/tbe/greater.py +0 -43
  791. mindspore/ops/_op_impl/tbe/greater_equal.py +0 -41
  792. mindspore/ops/_op_impl/tbe/greater_equal_ds.py +0 -42
  793. mindspore/ops/_op_impl/tbe/gru_v2_hidden_grad.py +0 -51
  794. mindspore/ops/_op_impl/tbe/gru_v2_hidden_grad_cell.py +0 -52
  795. mindspore/ops/_op_impl/tbe/hard_swish.py +0 -37
  796. mindspore/ops/_op_impl/tbe/hard_swish_ds.py +0 -38
  797. mindspore/ops/_op_impl/tbe/hard_swish_grad.py +0 -41
  798. mindspore/ops/_op_impl/tbe/hard_swish_grad_ds.py +0 -42
  799. mindspore/ops/_op_impl/tbe/histogram_fixed_width.py +0 -40
  800. mindspore/ops/_op_impl/tbe/hshrink.py +0 -33
  801. mindspore/ops/_op_impl/tbe/hshrink_grad.py +0 -37
  802. mindspore/ops/_op_impl/tbe/hsigmoid.py +0 -45
  803. mindspore/ops/_op_impl/tbe/hsigmoid_grad.py +0 -39
  804. mindspore/ops/_op_impl/tbe/ifmr.py +0 -47
  805. mindspore/ops/_op_impl/tbe/ifmr_ds.py +0 -48
  806. mindspore/ops/_op_impl/tbe/im2col.py +0 -42
  807. mindspore/ops/_op_impl/tbe/in_top_k.py +0 -37
  808. mindspore/ops/_op_impl/tbe/inplace_add.py +0 -39
  809. mindspore/ops/_op_impl/tbe/inplace_index_add.py +0 -46
  810. mindspore/ops/_op_impl/tbe/inplace_sub.py +0 -39
  811. mindspore/ops/_op_impl/tbe/inplace_update.py +0 -39
  812. mindspore/ops/_op_impl/tbe/inplace_update_ds.py +0 -40
  813. mindspore/ops/_op_impl/tbe/inv.py +0 -38
  814. mindspore/ops/_op_impl/tbe/inv_ds.py +0 -39
  815. mindspore/ops/_op_impl/tbe/inv_grad.py +0 -40
  816. mindspore/ops/_op_impl/tbe/inv_grad_ds.py +0 -41
  817. mindspore/ops/_op_impl/tbe/invert.py +0 -37
  818. mindspore/ops/_op_impl/tbe/invert_ds.py +0 -38
  819. mindspore/ops/_op_impl/tbe/iou.py +0 -38
  820. mindspore/ops/_op_impl/tbe/iou_ds.py +0 -39
  821. mindspore/ops/_op_impl/tbe/is_close.py +0 -40
  822. mindspore/ops/_op_impl/tbe/kl_div_loss.py +0 -38
  823. mindspore/ops/_op_impl/tbe/kl_div_loss_ds.py +0 -39
  824. mindspore/ops/_op_impl/tbe/kl_div_loss_grad.py +0 -40
  825. mindspore/ops/_op_impl/tbe/l2_loss.py +0 -36
  826. mindspore/ops/_op_impl/tbe/l2_loss_ds.py +0 -37
  827. mindspore/ops/_op_impl/tbe/l2_normalize.py +0 -38
  828. mindspore/ops/_op_impl/tbe/l2_normalize_grad.py +0 -40
  829. mindspore/ops/_op_impl/tbe/lamb_apply_optimizer_assign.py +0 -55
  830. mindspore/ops/_op_impl/tbe/lamb_apply_weight_assign.py +0 -42
  831. mindspore/ops/_op_impl/tbe/lamb_next_mv.py +0 -59
  832. mindspore/ops/_op_impl/tbe/lamb_next_mv_with_decay.py +0 -59
  833. mindspore/ops/_op_impl/tbe/lamb_next_right.py +0 -44
  834. mindspore/ops/_op_impl/tbe/lamb_update_with_lr.py +0 -48
  835. mindspore/ops/_op_impl/tbe/lamb_update_with_lr_v2.py +0 -44
  836. mindspore/ops/_op_impl/tbe/lars_update.py +0 -50
  837. mindspore/ops/_op_impl/tbe/lars_update_ds.py +0 -51
  838. mindspore/ops/_op_impl/tbe/layer_norm.py +0 -46
  839. mindspore/ops/_op_impl/tbe/layer_norm_beta_gamma_backprop.py +0 -44
  840. mindspore/ops/_op_impl/tbe/layer_norm_beta_gamma_backprop_ds.py +0 -45
  841. mindspore/ops/_op_impl/tbe/layer_norm_beta_gamma_backprop_v2.py +0 -40
  842. mindspore/ops/_op_impl/tbe/layer_norm_beta_gamma_backprop_v2_ds.py +0 -41
  843. mindspore/ops/_op_impl/tbe/layer_norm_ds.py +0 -47
  844. mindspore/ops/_op_impl/tbe/layer_norm_grad.py +0 -48
  845. mindspore/ops/_op_impl/tbe/layer_norm_x_backprop.py +0 -43
  846. mindspore/ops/_op_impl/tbe/layer_norm_x_backprop_ds.py +0 -44
  847. mindspore/ops/_op_impl/tbe/layer_norm_x_backprop_v2.py +0 -45
  848. mindspore/ops/_op_impl/tbe/layer_norm_x_backprop_v2_ds.py +0 -45
  849. mindspore/ops/_op_impl/tbe/lerp.py +0 -38
  850. mindspore/ops/_op_impl/tbe/less.py +0 -41
  851. mindspore/ops/_op_impl/tbe/less_ds.py +0 -42
  852. mindspore/ops/_op_impl/tbe/less_equal.py +0 -41
  853. mindspore/ops/_op_impl/tbe/less_equal_ds.py +0 -42
  854. mindspore/ops/_op_impl/tbe/log.py +0 -40
  855. mindspore/ops/_op_impl/tbe/log1p.py +0 -37
  856. mindspore/ops/_op_impl/tbe/log1p_ds.py +0 -38
  857. mindspore/ops/_op_impl/tbe/log_ds.py +0 -41
  858. mindspore/ops/_op_impl/tbe/logical_and.py +0 -37
  859. mindspore/ops/_op_impl/tbe/logical_and_ds.py +0 -38
  860. mindspore/ops/_op_impl/tbe/logical_not.py +0 -36
  861. mindspore/ops/_op_impl/tbe/logical_not_ds.py +0 -37
  862. mindspore/ops/_op_impl/tbe/logical_or.py +0 -37
  863. mindspore/ops/_op_impl/tbe/logical_or_ds.py +0 -38
  864. mindspore/ops/_op_impl/tbe/logsoftmax.py +0 -37
  865. mindspore/ops/_op_impl/tbe/logsoftmax_ds.py +0 -38
  866. mindspore/ops/_op_impl/tbe/logsoftmax_grad.py +0 -38
  867. mindspore/ops/_op_impl/tbe/logsoftmax_grad_ds.py +0 -39
  868. mindspore/ops/_op_impl/tbe/lp_norm.py +0 -40
  869. mindspore/ops/_op_impl/tbe/lp_norm_ds.py +0 -41
  870. mindspore/ops/_op_impl/tbe/lrn.py +0 -41
  871. mindspore/ops/_op_impl/tbe/lrn_grad.py +0 -42
  872. mindspore/ops/_op_impl/tbe/lstm_input_grad.py +0 -51
  873. mindspore/ops/_op_impl/tbe/masked_fill.py +0 -40
  874. mindspore/ops/_op_impl/tbe/masked_fill_ds.py +0 -41
  875. mindspore/ops/_op_impl/tbe/matmul.py +0 -53
  876. mindspore/ops/_op_impl/tbe/matmul_ds.py +0 -47
  877. mindspore/ops/_op_impl/tbe/matmul_v2.py +0 -50
  878. mindspore/ops/_op_impl/tbe/matrix_diag.py +0 -45
  879. mindspore/ops/_op_impl/tbe/matrix_diag_part.py +0 -45
  880. mindspore/ops/_op_impl/tbe/matrix_set_diag.py +0 -46
  881. mindspore/ops/_op_impl/tbe/max_pool.py +0 -39
  882. mindspore/ops/_op_impl/tbe/max_pool3d.py +0 -44
  883. mindspore/ops/_op_impl/tbe/max_pool3d_grad.py +0 -43
  884. mindspore/ops/_op_impl/tbe/max_pool3d_grad_grad.py +0 -44
  885. mindspore/ops/_op_impl/tbe/max_pool_ds.py +0 -40
  886. mindspore/ops/_op_impl/tbe/max_pool_grad.py +0 -43
  887. mindspore/ops/_op_impl/tbe/max_pool_grad_grad.py +0 -41
  888. mindspore/ops/_op_impl/tbe/max_pool_grad_grad_with_argmax.py +0 -41
  889. mindspore/ops/_op_impl/tbe/max_pool_grad_with_argmax.py +0 -42
  890. mindspore/ops/_op_impl/tbe/max_pool_with_argmax.py +0 -40
  891. mindspore/ops/_op_impl/tbe/maximum.py +0 -39
  892. mindspore/ops/_op_impl/tbe/maximum_ds.py +0 -40
  893. mindspore/ops/_op_impl/tbe/maximum_grad.py +0 -46
  894. mindspore/ops/_op_impl/tbe/maximum_grad_ds.py +0 -47
  895. mindspore/ops/_op_impl/tbe/mem_set.py +0 -38
  896. mindspore/ops/_op_impl/tbe/minimum.py +0 -40
  897. mindspore/ops/_op_impl/tbe/minimum_ds.py +0 -41
  898. mindspore/ops/_op_impl/tbe/minimum_grad.py +0 -46
  899. mindspore/ops/_op_impl/tbe/minimum_grad_ds.py +0 -47
  900. mindspore/ops/_op_impl/tbe/mish.py +0 -37
  901. mindspore/ops/_op_impl/tbe/mod.py +0 -41
  902. mindspore/ops/_op_impl/tbe/mod_ds.py +0 -42
  903. mindspore/ops/_op_impl/tbe/mul.py +0 -37
  904. mindspore/ops/_op_impl/tbe/mul_ds.py +0 -38
  905. mindspore/ops/_op_impl/tbe/mul_no_nan.py +0 -39
  906. mindspore/ops/_op_impl/tbe/mul_no_nan_ds.py +0 -40
  907. mindspore/ops/_op_impl/tbe/multilabel_margin_loss.py +0 -39
  908. mindspore/ops/_op_impl/tbe/neg.py +0 -39
  909. mindspore/ops/_op_impl/tbe/neg_ds.py +0 -40
  910. mindspore/ops/_op_impl/tbe/new_im2col.py +0 -40
  911. mindspore/ops/_op_impl/tbe/nll_loss.py +0 -41
  912. mindspore/ops/_op_impl/tbe/nll_loss_grad.py +0 -44
  913. mindspore/ops/_op_impl/tbe/nms_with_mask.py +0 -39
  914. mindspore/ops/_op_impl/tbe/not_equal.py +0 -41
  915. mindspore/ops/_op_impl/tbe/not_equal_ds.py +0 -42
  916. mindspore/ops/_op_impl/tbe/npu_alloc_float_status.py +0 -34
  917. mindspore/ops/_op_impl/tbe/npu_clear_float_status.py +0 -35
  918. mindspore/ops/_op_impl/tbe/npu_clear_float_status_v2.py +0 -35
  919. mindspore/ops/_op_impl/tbe/npu_get_float_status.py +0 -35
  920. mindspore/ops/_op_impl/tbe/npu_get_float_status_v2.py +0 -35
  921. mindspore/ops/_op_impl/tbe/one_hot.py +0 -48
  922. mindspore/ops/_op_impl/tbe/one_hot_ds.py +0 -45
  923. mindspore/ops/_op_impl/tbe/ones_like.py +0 -40
  924. mindspore/ops/_op_impl/tbe/ones_like_ds.py +0 -41
  925. mindspore/ops/_op_impl/tbe/p_s_r_o_i_pooling.py +0 -40
  926. mindspore/ops/_op_impl/tbe/p_s_r_o_i_pooling_grad.py +0 -40
  927. mindspore/ops/_op_impl/tbe/pack.py +0 -58
  928. mindspore/ops/_op_impl/tbe/pack_ds.py +0 -59
  929. mindspore/ops/_op_impl/tbe/pad_d.py +0 -40
  930. mindspore/ops/_op_impl/tbe/pad_d_ds.py +0 -41
  931. mindspore/ops/_op_impl/tbe/parallel_concat.py +0 -70
  932. mindspore/ops/_op_impl/tbe/parallel_resize_bilinear.py +0 -45
  933. mindspore/ops/_op_impl/tbe/parallel_resize_bilinear_grad.py +0 -44
  934. mindspore/ops/_op_impl/tbe/pdist.py +0 -36
  935. mindspore/ops/_op_impl/tbe/pooling.py +0 -46
  936. mindspore/ops/_op_impl/tbe/population_count.py +0 -38
  937. mindspore/ops/_op_impl/tbe/pow.py +0 -41
  938. mindspore/ops/_op_impl/tbe/pow_ds.py +0 -42
  939. mindspore/ops/_op_impl/tbe/prelu.py +0 -37
  940. mindspore/ops/_op_impl/tbe/prelu_ds.py +0 -38
  941. mindspore/ops/_op_impl/tbe/prelu_grad.py +0 -40
  942. mindspore/ops/_op_impl/tbe/range.py +0 -39
  943. mindspore/ops/_op_impl/tbe/real_div.py +0 -38
  944. mindspore/ops/_op_impl/tbe/real_div_ds.py +0 -39
  945. mindspore/ops/_op_impl/tbe/reciprocal.py +0 -36
  946. mindspore/ops/_op_impl/tbe/reciprocal_ds.py +0 -37
  947. mindspore/ops/_op_impl/tbe/reciprocal_grad.py +0 -38
  948. mindspore/ops/_op_impl/tbe/reciprocal_grad_ds.py +0 -39
  949. mindspore/ops/_op_impl/tbe/reduce_all.py +0 -38
  950. mindspore/ops/_op_impl/tbe/reduce_all_ds.py +0 -39
  951. mindspore/ops/_op_impl/tbe/reduce_any.py +0 -38
  952. mindspore/ops/_op_impl/tbe/reduce_any_ds.py +0 -39
  953. mindspore/ops/_op_impl/tbe/reduce_max.py +0 -43
  954. mindspore/ops/_op_impl/tbe/reduce_max_ds.py +0 -41
  955. mindspore/ops/_op_impl/tbe/reduce_mean.py +0 -40
  956. mindspore/ops/_op_impl/tbe/reduce_mean_ds.py +0 -42
  957. mindspore/ops/_op_impl/tbe/reduce_min.py +0 -41
  958. mindspore/ops/_op_impl/tbe/reduce_min_ds.py +0 -41
  959. mindspore/ops/_op_impl/tbe/reduce_prod.py +0 -42
  960. mindspore/ops/_op_impl/tbe/reduce_prod_ds.py +0 -41
  961. mindspore/ops/_op_impl/tbe/reduce_std.py +0 -44
  962. mindspore/ops/_op_impl/tbe/reduce_sum.py +0 -39
  963. mindspore/ops/_op_impl/tbe/reduce_sum_ds.py +0 -41
  964. mindspore/ops/_op_impl/tbe/relu.py +0 -39
  965. mindspore/ops/_op_impl/tbe/relu6.py +0 -38
  966. mindspore/ops/_op_impl/tbe/relu6_ds.py +0 -39
  967. mindspore/ops/_op_impl/tbe/relu6_grad.py +0 -43
  968. mindspore/ops/_op_impl/tbe/relu6_grad_ds.py +0 -44
  969. mindspore/ops/_op_impl/tbe/relu_ds.py +0 -40
  970. mindspore/ops/_op_impl/tbe/relu_grad.py +0 -41
  971. mindspore/ops/_op_impl/tbe/relu_grad_ds.py +0 -42
  972. mindspore/ops/_op_impl/tbe/relu_grad_v2.py +0 -40
  973. mindspore/ops/_op_impl/tbe/relu_grad_v2_ds.py +0 -41
  974. mindspore/ops/_op_impl/tbe/relu_v2.py +0 -40
  975. mindspore/ops/_op_impl/tbe/relu_v2_ds.py +0 -41
  976. mindspore/ops/_op_impl/tbe/renorm.py +0 -39
  977. mindspore/ops/_op_impl/tbe/resize_bilinear.py +0 -40
  978. mindspore/ops/_op_impl/tbe/resize_bilinear_grad.py +0 -41
  979. mindspore/ops/_op_impl/tbe/resize_bilinear_v2.py +0 -43
  980. mindspore/ops/_op_impl/tbe/resize_nearest_neighbor.py +0 -40
  981. mindspore/ops/_op_impl/tbe/resize_nearest_neighbor_ds.py +0 -40
  982. mindspore/ops/_op_impl/tbe/resize_nearest_neighbor_grad.py +0 -39
  983. mindspore/ops/_op_impl/tbe/resize_nearest_neighbor_grad_ds.py +0 -42
  984. mindspore/ops/_op_impl/tbe/reverse_v2_d.py +0 -37
  985. mindspore/ops/_op_impl/tbe/rint.py +0 -37
  986. mindspore/ops/_op_impl/tbe/rint_ds.py +0 -38
  987. mindspore/ops/_op_impl/tbe/roi_align.py +0 -43
  988. mindspore/ops/_op_impl/tbe/roi_align_ds.py +0 -44
  989. mindspore/ops/_op_impl/tbe/roi_align_grad.py +0 -43
  990. mindspore/ops/_op_impl/tbe/roi_align_grad_ds.py +0 -44
  991. mindspore/ops/_op_impl/tbe/roll.py +0 -42
  992. mindspore/ops/_op_impl/tbe/round.py +0 -38
  993. mindspore/ops/_op_impl/tbe/round_ds.py +0 -39
  994. mindspore/ops/_op_impl/tbe/rsqrt.py +0 -37
  995. mindspore/ops/_op_impl/tbe/rsqrt_ds.py +0 -38
  996. mindspore/ops/_op_impl/tbe/rsqrt_grad.py +0 -40
  997. mindspore/ops/_op_impl/tbe/rsqrt_grad_ds.py +0 -41
  998. mindspore/ops/_op_impl/tbe/scatter_add.py +0 -44
  999. mindspore/ops/_op_impl/tbe/scatter_div.py +0 -46
  1000. mindspore/ops/_op_impl/tbe/scatter_max.py +0 -45
  1001. mindspore/ops/_op_impl/tbe/scatter_min.py +0 -45
  1002. mindspore/ops/_op_impl/tbe/scatter_mul.py +0 -44
  1003. mindspore/ops/_op_impl/tbe/scatter_nd.py +0 -41
  1004. mindspore/ops/_op_impl/tbe/scatter_nd_add.py +0 -45
  1005. mindspore/ops/_op_impl/tbe/scatter_nd_d.py +0 -41
  1006. mindspore/ops/_op_impl/tbe/scatter_nd_ds.py +0 -49
  1007. mindspore/ops/_op_impl/tbe/scatter_nd_sub.py +0 -47
  1008. mindspore/ops/_op_impl/tbe/scatter_nd_sub_ds.py +0 -48
  1009. mindspore/ops/_op_impl/tbe/scatter_nd_update.py +0 -47
  1010. mindspore/ops/_op_impl/tbe/scatter_nd_update_ds.py +0 -48
  1011. mindspore/ops/_op_impl/tbe/scatter_non_aliasing_add.py +0 -39
  1012. mindspore/ops/_op_impl/tbe/scatter_non_aliasing_add_ds.py +0 -40
  1013. mindspore/ops/_op_impl/tbe/scatter_sub.py +0 -47
  1014. mindspore/ops/_op_impl/tbe/scatter_sub_ds.py +0 -48
  1015. mindspore/ops/_op_impl/tbe/scatter_update.py +0 -43
  1016. mindspore/ops/_op_impl/tbe/select.py +0 -38
  1017. mindspore/ops/_op_impl/tbe/select_ds.py +0 -39
  1018. mindspore/ops/_op_impl/tbe/selu.py +0 -39
  1019. mindspore/ops/_op_impl/tbe/selu_ds.py +0 -40
  1020. mindspore/ops/_op_impl/tbe/sgd.py +0 -62
  1021. mindspore/ops/_op_impl/tbe/sigmoid.py +0 -37
  1022. mindspore/ops/_op_impl/tbe/sigmoid_cross_entropy_with_logits.py +0 -41
  1023. mindspore/ops/_op_impl/tbe/sigmoid_cross_entropy_with_logits_ds.py +0 -42
  1024. mindspore/ops/_op_impl/tbe/sigmoid_cross_entropy_with_logits_grad.py +0 -42
  1025. mindspore/ops/_op_impl/tbe/sigmoid_cross_entropy_with_logits_grad_ds.py +0 -43
  1026. mindspore/ops/_op_impl/tbe/sigmoid_ds.py +0 -38
  1027. mindspore/ops/_op_impl/tbe/sigmoid_grad.py +0 -39
  1028. mindspore/ops/_op_impl/tbe/sigmoid_grad_ds.py +0 -40
  1029. mindspore/ops/_op_impl/tbe/sign.py +0 -38
  1030. mindspore/ops/_op_impl/tbe/sign_ds.py +0 -39
  1031. mindspore/ops/_op_impl/tbe/sin.py +0 -37
  1032. mindspore/ops/_op_impl/tbe/sin_ds.py +0 -38
  1033. mindspore/ops/_op_impl/tbe/sinh.py +0 -37
  1034. mindspore/ops/_op_impl/tbe/sinh_ds.py +0 -38
  1035. mindspore/ops/_op_impl/tbe/slice.py +0 -58
  1036. mindspore/ops/_op_impl/tbe/smooth_l1_loss.py +0 -45
  1037. mindspore/ops/_op_impl/tbe/smooth_l1_loss_ds.py +0 -46
  1038. mindspore/ops/_op_impl/tbe/smooth_l1_loss_grad.py +0 -46
  1039. mindspore/ops/_op_impl/tbe/smooth_l1_loss_grad_ds.py +0 -47
  1040. mindspore/ops/_op_impl/tbe/soft_margin_loss.py +0 -38
  1041. mindspore/ops/_op_impl/tbe/soft_margin_loss_grad.py +0 -39
  1042. mindspore/ops/_op_impl/tbe/soft_shrink.py +0 -36
  1043. mindspore/ops/_op_impl/tbe/soft_shrink_grad.py +0 -38
  1044. mindspore/ops/_op_impl/tbe/softmax.py +0 -37
  1045. mindspore/ops/_op_impl/tbe/softmax_cross_entropy_with_logits.py +0 -38
  1046. mindspore/ops/_op_impl/tbe/softmax_cross_entropy_with_logits_ds.py +0 -39
  1047. mindspore/ops/_op_impl/tbe/softmax_ds.py +0 -38
  1048. mindspore/ops/_op_impl/tbe/softmax_grad_ext.py +0 -42
  1049. mindspore/ops/_op_impl/tbe/softmax_v2_with_dropout_do_mask_v3.py +0 -39
  1050. mindspore/ops/_op_impl/tbe/softplus.py +0 -37
  1051. mindspore/ops/_op_impl/tbe/softplus_ds.py +0 -38
  1052. mindspore/ops/_op_impl/tbe/softplus_grad.py +0 -38
  1053. mindspore/ops/_op_impl/tbe/softplus_grad_ds.py +0 -38
  1054. mindspore/ops/_op_impl/tbe/softsign.py +0 -37
  1055. mindspore/ops/_op_impl/tbe/softsign_ds.py +0 -38
  1056. mindspore/ops/_op_impl/tbe/sort.py +0 -38
  1057. mindspore/ops/_op_impl/tbe/sort_ds.py +0 -39
  1058. mindspore/ops/_op_impl/tbe/space_to_batch.py +0 -38
  1059. mindspore/ops/_op_impl/tbe/space_to_batch_nd.py +0 -38
  1060. mindspore/ops/_op_impl/tbe/space_to_depth.py +0 -47
  1061. mindspore/ops/_op_impl/tbe/sparse_apply_adadelta.py +0 -56
  1062. mindspore/ops/_op_impl/tbe/sparse_apply_adagrad.py +0 -45
  1063. mindspore/ops/_op_impl/tbe/sparse_apply_adagrad_ds.py +0 -46
  1064. mindspore/ops/_op_impl/tbe/sparse_apply_adagrad_v2.py +0 -46
  1065. mindspore/ops/_op_impl/tbe/sparse_apply_adagrad_v2_ds.py +0 -47
  1066. mindspore/ops/_op_impl/tbe/sparse_apply_ftrl_d.py +0 -53
  1067. mindspore/ops/_op_impl/tbe/sparse_apply_ftrl_d_ds.py +0 -50
  1068. mindspore/ops/_op_impl/tbe/sparse_apply_ftrl_v2.py +0 -50
  1069. mindspore/ops/_op_impl/tbe/sparse_apply_proximal_adagrad.py +0 -66
  1070. mindspore/ops/_op_impl/tbe/sparse_apply_proximal_adagrad_ds.py +0 -67
  1071. mindspore/ops/_op_impl/tbe/sparse_apply_r_m_s_prop.py +0 -57
  1072. mindspore/ops/_op_impl/tbe/sparse_apply_r_m_s_prop_ds.py +0 -58
  1073. mindspore/ops/_op_impl/tbe/sparse_gather_v2.py +0 -56
  1074. mindspore/ops/_op_impl/tbe/sparse_gather_v2_ds.py +0 -58
  1075. mindspore/ops/_op_impl/tbe/split_d.py +0 -38
  1076. mindspore/ops/_op_impl/tbe/split_d_ds.py +0 -39
  1077. mindspore/ops/_op_impl/tbe/split_v.py +0 -39
  1078. mindspore/ops/_op_impl/tbe/splitv.py +0 -39
  1079. mindspore/ops/_op_impl/tbe/sqrt.py +0 -37
  1080. mindspore/ops/_op_impl/tbe/sqrt_ds.py +0 -38
  1081. mindspore/ops/_op_impl/tbe/sqrt_grad.py +0 -43
  1082. mindspore/ops/_op_impl/tbe/sqrt_grad_ds.py +0 -44
  1083. mindspore/ops/_op_impl/tbe/square.py +0 -38
  1084. mindspore/ops/_op_impl/tbe/square_ds.py +0 -39
  1085. mindspore/ops/_op_impl/tbe/square_sum_all.py +0 -40
  1086. mindspore/ops/_op_impl/tbe/square_sum_all_ds.py +0 -41
  1087. mindspore/ops/_op_impl/tbe/square_sum_v1.py +0 -38
  1088. mindspore/ops/_op_impl/tbe/square_sum_v1_ds.py +0 -39
  1089. mindspore/ops/_op_impl/tbe/square_sum_v2.py +0 -39
  1090. mindspore/ops/_op_impl/tbe/squared_difference.py +0 -39
  1091. mindspore/ops/_op_impl/tbe/squared_difference_ds.py +0 -41
  1092. mindspore/ops/_op_impl/tbe/squeeze.py +0 -37
  1093. mindspore/ops/_op_impl/tbe/strided_read.py +0 -38
  1094. mindspore/ops/_op_impl/tbe/strided_slice_d.py +0 -44
  1095. mindspore/ops/_op_impl/tbe/strided_slice_ds.py +0 -71
  1096. mindspore/ops/_op_impl/tbe/strided_slice_grad_d.py +0 -51
  1097. mindspore/ops/_op_impl/tbe/strided_slice_grad_ds.py +0 -57
  1098. mindspore/ops/_op_impl/tbe/strided_write.py +0 -38
  1099. mindspore/ops/_op_impl/tbe/sub.py +0 -39
  1100. mindspore/ops/_op_impl/tbe/sub_ds.py +0 -40
  1101. mindspore/ops/_op_impl/tbe/tan.py +0 -38
  1102. mindspore/ops/_op_impl/tbe/tan_ds.py +0 -39
  1103. mindspore/ops/_op_impl/tbe/tanh.py +0 -37
  1104. mindspore/ops/_op_impl/tbe/tanh_ds.py +0 -38
  1105. mindspore/ops/_op_impl/tbe/tanh_grad.py +0 -39
  1106. mindspore/ops/_op_impl/tbe/tanh_grad_ds.py +0 -40
  1107. mindspore/ops/_op_impl/tbe/tensor_move.py +0 -49
  1108. mindspore/ops/_op_impl/tbe/tensor_move_ds.py +0 -50
  1109. mindspore/ops/_op_impl/tbe/tensor_scatter_update.py +0 -41
  1110. mindspore/ops/_op_impl/tbe/tile.py +0 -37
  1111. mindspore/ops/_op_impl/tbe/tile_ds.py +0 -42
  1112. mindspore/ops/_op_impl/tbe/top_k.py +0 -42
  1113. mindspore/ops/_op_impl/tbe/top_k_ds.py +0 -43
  1114. mindspore/ops/_op_impl/tbe/trans_data.py +0 -167
  1115. mindspore/ops/_op_impl/tbe/trans_data_ds.py +0 -180
  1116. mindspore/ops/_op_impl/tbe/trans_data_rnn.py +0 -44
  1117. mindspore/ops/_op_impl/tbe/transpose.py +0 -60
  1118. mindspore/ops/_op_impl/tbe/transpose_d.py +0 -47
  1119. mindspore/ops/_op_impl/tbe/transpose_nod.py +0 -60
  1120. mindspore/ops/_op_impl/tbe/trunc.py +0 -39
  1121. mindspore/ops/_op_impl/tbe/truncate_div.py +0 -41
  1122. mindspore/ops/_op_impl/tbe/truncate_div_ds.py +0 -42
  1123. mindspore/ops/_op_impl/tbe/truncate_mod.py +0 -41
  1124. mindspore/ops/_op_impl/tbe/truncate_mod_ds.py +0 -42
  1125. mindspore/ops/_op_impl/tbe/unpack.py +0 -38
  1126. mindspore/ops/_op_impl/tbe/unpack_ds.py +0 -39
  1127. mindspore/ops/_op_impl/tbe/unsorted_segment_max.py +0 -49
  1128. mindspore/ops/_op_impl/tbe/unsorted_segment_max_ds.py +0 -40
  1129. mindspore/ops/_op_impl/tbe/unsorted_segment_min.py +0 -49
  1130. mindspore/ops/_op_impl/tbe/unsorted_segment_min_ds.py +0 -40
  1131. mindspore/ops/_op_impl/tbe/unsorted_segment_prod.py +0 -49
  1132. mindspore/ops/_op_impl/tbe/unsorted_segment_prod_ds.py +0 -38
  1133. mindspore/ops/_op_impl/tbe/unsorted_segment_sum.py +0 -38
  1134. mindspore/ops/_op_impl/tbe/unsorted_segment_sum_ds.py +0 -41
  1135. mindspore/ops/_op_impl/tbe/wts_arq.py +0 -40
  1136. mindspore/ops/_op_impl/tbe/xdivy.py +0 -38
  1137. mindspore/ops/_op_impl/tbe/xdivy_ds.py +0 -39
  1138. mindspore/ops/_op_impl/tbe/xlogy.py +0 -38
  1139. mindspore/ops/_op_impl/tbe/xlogy_ds.py +0 -39
  1140. mindspore/ops/_op_impl/tbe/zeros_like.py +0 -41
  1141. mindspore/ops/_op_impl/tbe/zeros_like_ds.py +0 -42
  1142. mindspore/ops/_tracefunc.py +0 -241
  1143. mindspore/ops/arg_dtype_cast.py +0 -54
  1144. mindspore/rewrite/api/tree_node_helper.py +0 -60
  1145. mindspore/rewrite/ast_helpers/ast_creator.py +0 -115
  1146. mindspore/rewrite/ast_transformers/flatten_recursive_stmt.py +0 -267
  1147. mindspore/rewrite/ast_transformers/remove_return_out_of_if.py +0 -228
  1148. mindspore/rewrite/namespace.py +0 -53
  1149. mindspore-2.2.11.dist-info/RECORD +0 -1920
  1150. {mindspore-2.2.11.dist-info → mindspore-2.3.0.dist-info}/WHEEL +0 -0
  1151. {mindspore-2.2.11.dist-info → mindspore-2.3.0.dist-info}/top_level.txt +0 -0
@@ -1,4 +1,4 @@
1
- # Copyright 2022 Huawei Technologies Co., Ltd
1
+ # Copyright 2023-2024 Huawei Technologies Co., Ltd
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@
15
15
 
16
16
  """Defines nn operators with functional form."""
17
17
  from __future__ import absolute_import
18
- from math import pi, log
18
+ from math import pi, log, floor
19
19
 
20
20
  from mindspore import context
21
21
  from mindspore import log as logger
@@ -29,6 +29,7 @@ import mindspore.common.dtype as mstype
29
29
  from mindspore.ops.function.math_func import logsumexp
30
30
  from mindspore.ops.function.random_func import _get_seed, _set_prim_op_user_data
31
31
  from mindspore.common.tensor import Tensor
32
+ from mindspore.common.parameter import Parameter
32
33
  from mindspore._c_expression import Tensor as Tensor_
33
34
  from mindspore.ops._primitive_cache import _get_cache_prim
34
35
  from mindspore import _checkparam as validator
@@ -38,22 +39,62 @@ from mindspore.ops.operations.nn_ops import FractionalMaxPoolWithFixedKsize, Fra
38
39
  from mindspore.ops.operations.nn_ops import PadV3
39
40
  from mindspore.ops.operations.nn_ops import ChannelShuffle
40
41
  from mindspore.ops.operations.nn_ops import TripletMarginLoss
41
- from mindspore.ops.operations._inner_ops import SiLU
42
42
  from mindspore.ops.operations._sequence_ops import TupleToTensor, TensorToTuple, ListToTensor
43
43
  from mindspore.common.api import _function_forbid_reuse
44
-
45
- slice_ = P.Slice()
46
- fast_gelu_ = P.FastGeLU()
47
- softsign_ = P.Softsign()
44
+ from mindspore.ops.auto_generate import log_softmax, dense, prelu, celu, relu, fast_gelu, silu, elu, sigmoid, relu6
45
+ from mindspore.ops.auto_generate import group_norm_op, rms_norm, layer_norm_ext_op, batch_norm_ext_op
46
+ from mindspore.ops.auto_generate import (reflection_pad_1d_op, reflection_pad_2d_op, reflection_pad_3d_op, # pylint: disable=W0611
47
+ replication_pad_1d_op, replication_pad_2d_op, replication_pad_3d_op,
48
+ constant_pad_nd_op, dropout_ext_op, reverse_v2_impl)
49
+ from mindspore.ops.auto_generate.gen_ops_prim import embedding_op, Convolution
50
+ from mindspore.common.generator import default_generator
51
+
52
+ abs_ = P.Abs()
53
+ add_ = P.Add()
54
+ bias_add_ = P.BiasAdd()
55
+ cast_ = P.Cast()
56
+ div_ = P.Div()
57
+ dtype_ = P.DType()
58
+ equal_ = P.Equal()
59
+ erf_ = P.Erf()
60
+ exp_ = P.Exp()
61
+ expand_dims_ = P.ExpandDims()
62
+ fillv2_ = P.FillV2()
63
+ gather_ = P.Gather()
64
+ gather_d_ = P.GatherD()
65
+ gelu_ = P.GeLU()
66
+ greater_ = P.Greater()
48
67
  hardswish_ = P.HSwish()
68
+ less_ = P.Less()
69
+ list_to_tensor_ = ListToTensor()
70
+ log_ = P.Log()
71
+ matmul_ = P.MatMul()
72
+ maximum_ = P.Maximum()
73
+ minimum_ = P.Minimum()
49
74
  mish_ = NN_OPS.Mish()
50
- selu_ = NN_OPS.SeLU()
75
+ mul_ = P.Mul()
76
+ neg_ = P.Neg()
77
+ ones_like_ = P.OnesLike()
78
+ reduce_mean_ = P.ReduceMean()
79
+ reduce_sum_ = P.ReduceSum()
80
+ reshape_ = P.Reshape()
51
81
  scalar_to_tensor_ = P.ScalarToTensor()
52
- list_to_tensor_ = ListToTensor()
53
- tuple_to_tensor_ = TupleToTensor()
82
+ select_ = P.Select()
83
+ selu_ = NN_OPS.SeLU()
84
+ shape_ = P.Shape()
85
+ sigmoid_ = P.Sigmoid()
86
+ sign_ = P.Sign()
87
+ slice_ = P.Slice()
88
+ softplus_ = P.Softplus()
89
+ softsign_ = P.Softsign()
90
+ sqrt_ = P.Sqrt()
91
+ square_ = P.Square()
92
+ sub_ = P.Sub()
93
+ tensor_shape_ = P.TensorShape()
54
94
  tensor_to_tuple_ = TensorToTuple()
55
- cast_ = P.Cast()
56
- sigmoid_ = NN_OPS.Sigmoid()
95
+ transpose_ = P.Transpose()
96
+ tuple_to_tensor_ = TupleToTensor()
97
+
57
98
  check_positive_int_const = validator.check_positive_int
58
99
  check_positive_int_sequence_const = validator.check_positive_int_sequence
59
100
  check_positive_float_const = validator.check_positive_float
@@ -63,6 +104,7 @@ check_int_const = validator.check_is_int
63
104
  check_non_negative_float_const = validator.check_non_negative_float
64
105
  check_string_const = constexpr(validator.check_string)
65
106
 
107
+ generator_step_ = Tensor(1, mstype.int64)
66
108
 
67
109
  def adaptive_avg_pool2d(input, output_size):
68
110
  r"""
@@ -103,11 +145,11 @@ def adaptive_avg_pool2d(input, output_size):
103
145
  .. math::
104
146
 
105
147
  out\_shape = \begin{cases}
106
- input\_x\_shape[-2] + output\_size[1], & \text{if output_size is (None, w);}\\
107
- output\_size[0] + input\_x\_shape[-1], & \text{if output_size is (h, None);}\\
108
- input\_x\_shape[-2:], & \text{if output_size is (None, None);}\\
109
- (h, h), & \text{if output_size is h;}\\
110
- (h, w), & \text{if output_size is (h, w)}
148
+ input\_shape[-2] + output\_size[1], & \text{if } output\_size text{ is (None, w);}\\
149
+ output\_size[0] + input\_shape[-1], & \text{if } output\_size text{ is (h, None);}\\
150
+ input\_shape[-2:], & \text{if } output\_size text{ is (None, None);}\\
151
+ (h, h), & \text{if } output\_size text{ is h;}\\
152
+ (h, w), & \text{if } output\_size text{ is (h, w)}
111
153
  \end{cases}
112
154
 
113
155
  Raises:
@@ -275,7 +317,7 @@ def avg_pool1d(input_x, kernel_size=1, stride=1, padding=0, ceil_mode=False, cou
275
317
  Tensor of shape :math:`(N, C_{out}, L_{out})`.
276
318
 
277
319
  Raises:
278
- TypeError: If `input_x` is not an Tensor.
320
+ TypeError: If `input_x` is not a Tensor.
279
321
  TypeError: If `kernel_size` or `stride` is not an int.
280
322
  TypeError: If `ceil_mode` or `count_include_pad` is not a bool.
281
323
  ValueError: If length of shape of `input_x` is not equal to `3`.
@@ -298,9 +340,6 @@ def avg_pool1d(input_x, kernel_size=1, stride=1, padding=0, ceil_mode=False, cou
298
340
  if not isinstance(input_x, (Tensor, Tensor_)):
299
341
  raise TypeError("For avg_pool1d, the input input_x must be tensor")
300
342
 
301
- if len(input_x.shape) != 3:
302
- raise ValueError(f"For avg_pool1d, input must have 3 dim, but got {len(input_x.shape)}.")
303
-
304
343
  _check_avgpool_1d_type_and_int(kernel_size, stride, ceil_mode, count_include_pad)
305
344
  if isinstance(padding, int):
306
345
  check_non_negative_int(padding, 'padding', 'avg_pool1d')
@@ -319,7 +358,6 @@ def avg_pool1d(input_x, kernel_size=1, stride=1, padding=0, ceil_mode=False, cou
319
358
  raise ValueError("For avg_pool1d, stride should be int or tuple of length 1.")
320
359
  stride = stride[0]
321
360
 
322
- expand_op = _get_cache_prim(P.ExpandDims)()
323
361
  squeeze_op = _get_cache_prim(P.Squeeze)((2, 3))
324
362
  avg_pool_op = _get_cache_prim(P.AvgPool3D)(kernel_size=(1, 1, kernel_size),
325
363
  strides=(1, 1, stride),
@@ -327,8 +365,8 @@ def avg_pool1d(input_x, kernel_size=1, stride=1, padding=0, ceil_mode=False, cou
327
365
  pad=padding,
328
366
  ceil_mode=ceil_mode,
329
367
  count_include_pad=count_include_pad)
330
- input_x = expand_op(input_x, 2)
331
- input_x = expand_op(input_x, 2)
368
+ input_x = expand_dims_(input_x, 2)
369
+ input_x = expand_dims_(input_x, 2)
332
370
  input_x = avg_pool_op(input_x)
333
371
  input_x = squeeze_op(input_x)
334
372
  return input_x
@@ -429,7 +467,7 @@ def avg_pool2d(input_x, kernel_size=1, stride=1, padding=0, ceil_mode=False, cou
429
467
  Tensor, with shape :math:`(N, C_{out}, H_{out}, W_{out})`.
430
468
 
431
469
  Raises:
432
- TypeError: If `input_x` is not an Tensor.
470
+ TypeError: If `input_x` is not a Tensor.
433
471
  TypeError: If `kernel_size` or `stride` is neither int nor tuple.
434
472
  TypeError: If `ceil_mode` or `count_include_pad` is not a bool.
435
473
  TypeError: If `divisor_override` is not an int.
@@ -459,15 +497,10 @@ def avg_pool2d(input_x, kernel_size=1, stride=1, padding=0, ceil_mode=False, cou
459
497
  if not isinstance(input_x, (Tensor, Tensor_)):
460
498
  raise TypeError("For avg_pool2d, the input input_x must be tensor")
461
499
 
462
- if len(input_x.shape) != 4:
463
- raise ValueError(f"For avg_pool2d, input must have 4 dim, but got {len(input_x.shape)}.")
464
-
465
500
  kernel_size = _check_avgpool_2d_kernel_size(kernel_size)
466
501
  stride = _check_avgpool_2d_stride(stride)
467
502
  padding = _check_avgpool_2d_padding(padding)
468
503
  _check_avg_pool2d_type_and_value(ceil_mode, count_include_pad, divisor_override)
469
-
470
- expand_op = _get_cache_prim(P.ExpandDims)()
471
504
  squeeze_op = _get_cache_prim(P.Squeeze)(2)
472
505
  avg_pool_op = _get_cache_prim(P.AvgPool3D)(kernel_size=kernel_size,
473
506
  strides=stride,
@@ -476,13 +509,82 @@ def avg_pool2d(input_x, kernel_size=1, stride=1, padding=0, ceil_mode=False, cou
476
509
  ceil_mode=ceil_mode,
477
510
  count_include_pad=count_include_pad,
478
511
  divisor_override=divisor_override)
479
- input_x = expand_op(input_x, 2)
512
+ input_x = expand_dims_(input_x, 2)
480
513
  input_x = avg_pool_op(input_x)
481
514
  input_x = squeeze_op(input_x)
482
515
  return input_x
483
516
 
484
517
 
485
- @constexpr
518
+ def avg_pool2d_ext(input, kernel_size, stride=None, padding=0, ceil_mode=False, count_include_pad=True,
519
+ divisor_override=None):
520
+ r"""
521
+ Applies a 2D average pooling over an input Tensor which can be regarded as a composition of 2D input planes.
522
+ Typically the input is of shape :math:`(N, C, H_{in}, W_{in})`, outputs regional average in the
523
+ :math:`(H_{in}, W_{in})`-dimension. Given kernel size :math:`(k_{H}, k_{W})` and `stride` , the operation
524
+ is as follows.
525
+
526
+ .. math::
527
+ \text{output}(N_i, C_j, h, w) = \frac{1}{k_{H} * k_{W}} \sum_{m=0}^{k_{H}-1} \sum_{n=0}^{k_{W}-1}
528
+ \text{input}(N_i, C_j, stride[0] \times h + m, stride[1] \times w + n)
529
+
530
+ Args:
531
+ input (Tensor): Tensor of shape :math:`(N, C, H_{in}, W_{in})`.
532
+ kernel_size (Union[int, tuple[int], list[int]]): The size of kernel used to take the average value.
533
+ Can be a single number or a tuple (kH, kW).
534
+ stride (Union[int, tuple[int], list[int]]): The distance of kernel moving. Can be a single number or
535
+ a tuple (sH, sW). Default value is `kernel_size` .
536
+ padding (Union(int, tuple[int], list[int])): Implicit zero padding to be added on both sides.
537
+ Can be a single number or a tuple (padH, padW). Default: 0.
538
+ ceil_mode (bool): If True, apply ceil instead of floor to compute the output shape.
539
+ Default: ``False``.
540
+ count_include_pad (bool): If True, include the zero-padding in the averaging calculation.
541
+ Default: ``True`` .
542
+ divisor_override (int): If specified, it will be used as divisor in the averaging calculation,
543
+ otherwise size of pooling region will be used. Default: ``None``.
544
+
545
+ Returns:
546
+ Tensor, with shape :math:`(N, C, H_{out}, W_{out})`.
547
+
548
+ .. math::
549
+ \begin{array}{ll} \\
550
+ H_{out} = \frac{H_{in} + 2 \times padding[0] - kernel_size[0]}{stride[0]} + 1 \\
551
+ W_{out} = \frac{W_{in} + 2 \times padding[1] - kernel_size[1]}{stride[1]} + 1
552
+ \end{array}
553
+
554
+ Raises:
555
+ TypeError: If `input` is not a Tensor.
556
+ TypeError: If `kernel_size` or `stride` is neither int nor tuple.
557
+ TypeError: If `ceil_mode` or `count_include_pad` is not a bool.
558
+ TypeError: If `divisor_override` is not an int or None.
559
+ ValueError: If the dimension of `input` is not equal to `4` or `3`.
560
+ ValueError: If `kernel_size` or `stride` is less than 1.
561
+ ValueError: If `kernel_size` or `stride` is a tuple whose length is not equal to `2` or `1`.
562
+ ValueError: If `padding` is neither a int nor a tuple whose length is equal to `2` or `1`.
563
+ ValueError: If value of `padding` is less than `0`.
564
+
565
+ Supported Platforms:
566
+ ``Ascend``
567
+
568
+ Examples:
569
+ >>> import mindspore
570
+ >>> import numpy as np
571
+ >>> from mindspore import Tensor, ops
572
+ >>> x = Tensor(np.arange(1 * 3 * 3 * 4).reshape(1, 3, 3, 4), mindspore.float32)
573
+ >>> output = ops.function.nn_func.avg_pool2d_ext(x, kernel_size=2, stride=1)
574
+ >>> print(output)
575
+ [[[[ 2.5 3.5 4.5]
576
+ [ 6.5 7.5 8.5]]
577
+ [[14.5 15.5 16.5]
578
+ [18.5 19.5 20.5]]
579
+ [[26.5 27.5 28.5]
580
+ [30.5 31.5 32.5]]]]
581
+ """
582
+ if stride is None:
583
+ stride = kernel_size
584
+ return _get_cache_prim(ops.auto_generate.AvgPool2D)()(input, kernel_size, stride, padding,
585
+ ceil_mode, count_include_pad, divisor_override)
586
+
587
+
486
588
  def _check_avg_pool3d_padding(padding):
487
589
  """Check the padding value in avg_pool3d op."""
488
590
  if isinstance(padding, int):
@@ -537,7 +639,7 @@ def avg_pool3d(input_x, kernel_size=1, stride=1, padding=0, ceil_mode=False, cou
537
639
  Tensor, with shape :math:`(N, C, D_{out}, H_{out}, W_{out})`. Has the same data type with `input_x`.
538
640
 
539
641
  Raises:
540
- TypeError: If `input_x` is not an Tensor.
642
+ TypeError: If `input_x` is not a Tensor.
541
643
  TypeError: If `kernel_size`, `stride` or `padding` is neither an int not a tuple.
542
644
  TypeError: If `ceil_mode` or `count_include_pad` is not a bool.
543
645
  TypeError: If `divisor_override` is not an int.
@@ -563,9 +665,6 @@ def avg_pool3d(input_x, kernel_size=1, stride=1, padding=0, ceil_mode=False, cou
563
665
  if not isinstance(input_x, (Tensor, Tensor_)):
564
666
  raise TypeError("For avg_pool3d, the input input_x must be tensor")
565
667
 
566
- if len(input_x.shape) != 5:
567
- raise ValueError(f"For avg_pool3d, input must have 5 dim, but got {len(input_x.shape)}.")
568
-
569
668
  _check_avg_pool3d_padding(padding)
570
669
 
571
670
  avg_pool_op = _get_cache_prim(P.AvgPool3D)(kernel_size=kernel_size,
@@ -638,7 +737,7 @@ def adaptive_max_pool1d(input, output_size):
638
737
  _check_adaptive_max_pool1d_output_size(output_size)
639
738
 
640
739
  x_in_shape = input.shape
641
- x_dtype = _get_cache_prim(P.DType)()(input)
740
+ x_dtype = dtype_(input)
642
741
 
643
742
  if len(x_in_shape) != 3:
644
743
  raise ValueError(f"For adaptive_max_pool1d input must have 3 dim, but got {len(x_in_shape)}.")
@@ -657,18 +756,14 @@ def adaptive_max_pool1d(input, output_size):
657
756
  raise TypeError(f"For adaptive_max_pool1d, the input dtype must be float16 or float32, "
658
757
  f"but got {x_dtype}.")
659
758
 
660
- expand_ = _get_cache_prim(P.ExpandDims)()
661
759
  squeeze_ = _get_cache_prim(P.Squeeze)(2)
662
-
663
760
  width = x_in_shape[2]
664
761
  stride = width // output_size
665
762
  kernel_size = width - (output_size - 1) * stride
666
763
  stride = (1, width // output_size)
667
764
  kernel_size = (1, kernel_size)
668
-
669
765
  max_pool_ = _get_cache_prim(NN_OPS.MaxPool)(kernel_size=kernel_size, strides=stride)
670
-
671
- input = expand_(input, 2)
766
+ input = expand_dims_(input, 2)
672
767
  input = max_pool_(input)
673
768
  input = squeeze_(input)
674
769
 
@@ -807,6 +902,8 @@ def adaptive_max_pool3d(input, output_size, return_indices=False):
807
902
  >>> print(output[1].asnumpy())
808
903
  [[[[33 35]]]]
809
904
  """
905
+ if isinstance(output_size, int):
906
+ output_size = (output_size, output_size, output_size)
810
907
  adaptive_max_pool3d_ = _get_cache_prim(NN_OPS.AdaptiveMaxPool3D)()
811
908
  output_size_ = Tensor(output_size, dtype=mstype.int32)
812
909
  out = adaptive_max_pool3d_(input, output_size_)
@@ -814,18 +911,6 @@ def adaptive_max_pool3d(input, output_size, return_indices=False):
814
911
  return output
815
912
 
816
913
 
817
- def check_shape(x_shape, indices_shape, func_name):
818
- """
819
- :param x_shape: the shape of x.
820
- :param indices_shape: the shape of indices.
821
- :param func_name: the name of function.
822
- :return:
823
- """
824
- if x_shape != indices_shape:
825
- raise ValueError(f"For {func_name}, the x shape and indices shape must be equal, but got input "
826
- f"shape {x_shape} and indices shape {indices_shape}.")
827
-
828
-
829
914
  def max_unpool1d(x, indices, kernel_size, stride=None, padding=0, output_size=None):
830
915
  r"""
831
916
  Computes the inverse of `max_pool1d`.
@@ -836,7 +921,7 @@ def max_unpool1d(x, indices, kernel_size, stride=None, padding=0, output_size=No
836
921
 
837
922
  .. math::
838
923
  \begin{array}{ll} \\
839
- H_{out} = (H{in} - 1) \times stride[0] - 2 \times padding[0] + kernel\_size[0] \\
924
+ H_{out} = (H_{in} - 1) \times stride[0] - 2 \times padding[0] + kernel\_size[0] \\
840
925
  \end{array}
841
926
 
842
927
  Args:
@@ -885,13 +970,8 @@ def max_unpool1d(x, indices, kernel_size, stride=None, padding=0, output_size=No
885
970
  if stride is None:
886
971
  stride = kernel_size
887
972
 
888
- shape = P.Shape()
889
- x_shape = shape(x)
890
- indices_shape = shape(indices)
973
+ x_shape = shape_(x)
891
974
  x_dim = len(x_shape)
892
- check_shape(x_shape, indices_shape, "max_unpool1d")
893
- if x_dim not in (2, 3):
894
- raise ValueError(f"For max_unpool1d, the x shape must have 2 or 3 dims, but got {x_dim}.")
895
975
 
896
976
  if output_size is None:
897
977
  output_size = ()
@@ -1009,13 +1089,8 @@ def max_unpool2d(x, indices, kernel_size, stride=None, padding=0, output_size=No
1009
1089
  if stride is None:
1010
1090
  stride = kernel_size
1011
1091
 
1012
- shape = P.Shape()
1013
- x_shape = shape(x)
1014
- indices_shape = shape(indices)
1092
+ x_shape = shape_(x)
1015
1093
  x_dim = len(x_shape)
1016
- check_shape(x_shape, indices_shape, "max_unpool2d")
1017
- if x_dim not in (3, 4):
1018
- raise ValueError(f"For max_unpool2d, the x shape must have 3 or 4 dims, but got {x_dim}.")
1019
1094
 
1020
1095
  if output_size is None:
1021
1096
  output_size = ()
@@ -1118,12 +1193,8 @@ def max_unpool3d(x, indices, kernel_size, stride=None, padding=0, output_size=No
1118
1193
  if stride is None:
1119
1194
  stride = kernel_size
1120
1195
 
1121
- x_shape = P.Shape()(x)
1122
- indices_shape = P.Shape()(indices)
1196
+ x_shape = shape_(x)
1123
1197
  x_dim = len(x_shape)
1124
- check_shape(x_shape, indices_shape, "max_unpool3d")
1125
- if x_dim not in (4, 5):
1126
- raise ValueError(f"For max_unpool3d, the x shape must have 4 or 5 dims, but got {x_dim}.")
1127
1198
 
1128
1199
  if output_size is None:
1129
1200
  output_size = ()
@@ -1151,12 +1222,12 @@ def max_unpool3d(x, indices, kernel_size, stride=None, padding=0, output_size=No
1151
1222
  return out
1152
1223
 
1153
1224
 
1154
- def binary_cross_entropy_with_logits(logits, label, weight=None, pos_weight=None, reduction='mean'):
1225
+ def binary_cross_entropy_with_logits(input, target, weight=None, pos_weight=None, reduction='mean'):
1155
1226
  r"""
1156
- Adds sigmoid activation function to input `logits`, and uses the given logits to compute binary cross entropy
1157
- between the logits and the label.
1227
+ Adds sigmoid activation function to input `input` as logits, and uses the given logits to compute binary cross
1228
+ entropy between the `input` and the `target`.
1158
1229
 
1159
- Sets input logits as :math:`X`, input label as :math:`Y`, input weight as :math:`W`, output as :math:`L`. Then,
1230
+ Sets input `input` as :math:`X`, input target as :math:`Y`, input weight as :math:`W`, output as :math:`L`. Then,
1160
1231
 
1161
1232
  .. math::
1162
1233
 
@@ -1197,14 +1268,14 @@ def binary_cross_entropy_with_logits(logits, label, weight=None, pos_weight=None
1197
1268
  :math:`P_c>1` increases the recall, :math:`P_c<1` increases the precision.
1198
1269
 
1199
1270
  Args:
1200
- logits (Tensor): Input logits. Data type must be float16 or float32.
1201
- label (Tensor): Ground truth label, has the same shape as `logits`.
1271
+ input (Tensor): Input `input`. Data type must be float16 or float32.
1272
+ target (Tensor): Ground truth label, has the same shape as `input`.
1202
1273
  Data type must be float16 or float32.
1203
1274
  weight (Tensor, optional): A rescaling weight applied to the loss of each batch element. It can be
1204
- broadcast to a tensor with shape of `logits`. Data type must be float16 or float32.
1275
+ broadcast to a tensor with shape of `input`. Data type must be float16 or float32.
1205
1276
  Default: ``None``, `weight` is a Tensor whose value is ``1``.
1206
1277
  pos_weight (Tensor, optional): A weight of positive examples. Must be a vector with length equal to the
1207
- number of classes. It can be broadcast to a tensor with shape of `logits`.
1278
+ number of classes. It can be broadcast to a tensor with shape of `input`.
1208
1279
  Data type must be float16 or float32. Default: ``None``, `pos_weight` is a Tensor whose value is ``1``.
1209
1280
  reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
1210
1281
  ``'sum'`` . Default: ``'mean'`` .
@@ -1214,14 +1285,14 @@ def binary_cross_entropy_with_logits(logits, label, weight=None, pos_weight=None
1214
1285
  - ``'sum'``: the output elements will be summed.
1215
1286
 
1216
1287
  Returns:
1217
- Tensor or Scalar, if `reduction` is ``'none'``, it's a tensor with the same shape and type as input `logits`.
1288
+ Tensor or Scalar, if `reduction` is ``'none'``, it's a tensor with the same shape and type as input `input`.
1218
1289
  Otherwise, the output is a scalar.
1219
1290
 
1220
1291
  Raises:
1221
- TypeError: If input `logits`, `label`, `weight`, `pos_weight` is not Tensor.
1222
- TypeError: If data type of input `logits`, `label`, `weight`, `pos_weight` is neither float16 nor float32.
1292
+ TypeError: If input `input`, `target`, `weight`, `pos_weight` is not Tensor.
1293
+ TypeError: If data type of input `input`, `target`, `weight`, `pos_weight` is neither float16 nor float32.
1223
1294
  TypeError: If data type of input `reduction` is not string.
1224
- ValueError: If `weight` or `pos_weight` can not be broadcast to a tensor with shape of `logits`.
1295
+ ValueError: If `weight` or `pos_weight` can not be broadcast to a tensor with shape of `input`.
1225
1296
  ValueError: If `reduction` is not one of ``'none'``, ``'mean'`` or ``'sum'``.
1226
1297
 
1227
1298
  Supported Platforms:
@@ -1231,21 +1302,17 @@ def binary_cross_entropy_with_logits(logits, label, weight=None, pos_weight=None
1231
1302
  >>> import mindspore
1232
1303
  >>> import numpy as np
1233
1304
  >>> from mindspore import Tensor, ops
1234
- >>> logits = Tensor(np.array([[-0.8, 1.2, 0.7], [-0.1, -0.4, 0.7]]), mindspore.float32)
1235
- >>> label = Tensor(np.array([[0.3, 0.8, 1.2], [-0.6, 0.1, 2.2]]), mindspore.float32)
1305
+ >>> input = Tensor(np.array([[-0.8, 1.2, 0.7], [-0.1, -0.4, 0.7]]), mindspore.float32)
1306
+ >>> target = Tensor(np.array([[0.3, 0.8, 1.2], [-0.6, 0.1, 2.2]]), mindspore.float32)
1236
1307
  >>> weight = Tensor(np.array([1.0, 1.0, 1.0]), mindspore.float32)
1237
1308
  >>> pos_weight = Tensor(np.array([1.0, 1.0, 1.0]), mindspore.float32)
1238
- >>> output = ops.binary_cross_entropy_with_logits(logits, label, weight, pos_weight)
1309
+ >>> output = ops.binary_cross_entropy_with_logits(input, target, weight, pos_weight)
1239
1310
  >>> print(output)
1240
1311
  0.3463612
1241
1312
  """
1242
1313
 
1243
- if weight is None:
1244
- weight = ops.ones_like(logits)
1245
- if pos_weight is None:
1246
- pos_weight = ops.ones_like(logits)
1247
1314
  bce_with_logits_loss_op = _get_cache_prim(NN_OPS.BCEWithLogitsLoss)(reduction)
1248
- return bce_with_logits_loss_op(logits, label, weight, pos_weight)
1315
+ return bce_with_logits_loss_op(input, target, weight, pos_weight)
1249
1316
 
1250
1317
 
1251
1318
  @_function_forbid_reuse
@@ -1294,47 +1361,45 @@ def dropout(input, p=0.5, training=True, seed=None):
1294
1361
  return out
1295
1362
 
1296
1363
 
1297
- def celu(x, alpha=1.0):
1364
+ @_function_forbid_reuse
1365
+ def dropout_ext(input, p=0.5, training=True):
1298
1366
  r"""
1299
- celu activation function, computes celu (Continuously differentiable exponential
1300
- linear units) of input tensors element-wise. The formula is defined as follows:
1301
-
1302
- .. math::
1303
-
1304
- \text{CeLU}(x) = \max(0,x) + \min(0, \alpha * (\exp(x/\alpha) - 1))
1305
-
1306
- For more details, please refer to `celu <https://arxiv.org/abs/1704.07483>`_.
1307
-
1308
- .. warning::
1309
- This is an experimental API that is subject to change or deletion.
1367
+ During training, randomly zeroes some of the elements of the input tensor
1368
+ with probability `p` from a Bernoulli distribution. It plays the role of reducing neuron correlation and
1369
+ avoid overfitting. And the return will be multiplied by :math:`\frac{1}{1-p}` during training.
1370
+ During the reasoning, this operation returns the same Tensor as the `input`.
1310
1371
 
1311
1372
  Args:
1312
- x (Tensor): The input of celu with data type of float16 or float32.
1313
- alpha (float, optional): The :math:`\alpha` value for the Celu formulation. Default: 1.0
1373
+ input (Tensor): The input Tensor of shape :math:`(*, N)`.
1374
+ p (float): The dropping rate of input neurons, between 0 and 1, e.g. `p` = 0.1,
1375
+ means dropping out 10% of input neurons. Default: ``0.5`` .
1376
+ training (bool): Apply dropout if it is ``True`` , if it is ``False`` , the input is returned directly,
1377
+ and `p` is invalid. Default: ``True``.
1314
1378
 
1315
1379
  Returns:
1316
- Tensor, has the same data type and shape as the input.
1380
+ - **output** (Tensor) - Zeroed tensor, with the same shape and data type as `input`.
1317
1381
 
1318
1382
  Raises:
1319
- TypeError: If `alpha` is not a float.
1320
- TypeError: If `x` is not a Tensor.
1321
- TypeError: If dtype of `x` is neither float16 nor float32.
1322
- ValueError: If `alpha` has the value of 0.
1383
+ TypeError: If `p` is not a float.
1384
+ TypeError: If `input` is not a Tensor.
1323
1385
 
1324
1386
  Supported Platforms:
1325
- ``Ascend`` ``GPU`` ``CPU``
1387
+ ``Ascend``
1326
1388
 
1327
1389
  Examples:
1328
1390
  >>> import mindspore
1329
- >>> import numpy as np
1330
1391
  >>> from mindspore import Tensor, ops
1331
- >>> x = Tensor(np.array([-2.0, -1.0, 1.0, 2.0]), mindspore.float32)
1332
- >>> output = ops.celu(x, alpha=1.0)
1333
- >>> print(output)
1334
- [-0.86466473 -0.63212055 1. 2. ]
1392
+ >>> input = Tensor(((20, 16), (50, 50)), mindspore.float32)
1393
+ >>> output = ops.function.nn_func.dropout_ext(input, p=0.5)
1394
+ >>> print(output.shape)
1395
+ (2, 2)
1335
1396
  """
1336
- celu_op = _get_cache_prim(P.CeLU)(alpha)
1337
- return celu_op(x)
1397
+ check_bool_const(training, "training", "dropout_ext")
1398
+ if training is False:
1399
+ return input
1400
+ seed, offset = default_generator._step(generator_step_) # pylint: disable=protected-access
1401
+ out, _ = dropout_ext_op(input, p, seed, offset)
1402
+ return out
1338
1403
 
1339
1404
 
1340
1405
  def dropout1d(input, p=0.5, training=True):
@@ -1520,42 +1585,6 @@ def dropout3d(input, p=0.5, training=True):
1520
1585
  return out
1521
1586
 
1522
1587
 
1523
- def fast_gelu(x):
1524
- r"""
1525
- Fast Gaussian Error Linear Units activation function.
1526
-
1527
- FastGeLU is defined as follows:
1528
-
1529
- .. math::
1530
- \text{output} = \frac {x} {1 + \exp(-1.702 * \left| x \right|)} * \exp(0.851 * (x - \left| x \right|)),
1531
-
1532
- where :math:`x` is the element of the input.
1533
-
1534
- Args:
1535
- x (Tensor): Input to compute the FastGeLU with data type of float16 or float32.
1536
-
1537
- Returns:
1538
- Tensor, with the same type and shape as `x`.
1539
-
1540
- Raises:
1541
- TypeError: If dtype of `x` is neither float16 nor float32.
1542
-
1543
- Supported Platforms:
1544
- ``Ascend`` ``GPU`` ``CPU``
1545
-
1546
- Examples:
1547
- >>> import mindspore
1548
- >>> import numpy as np
1549
- >>> from mindspore import Tensor, ops
1550
- >>> x = Tensor(np.array([[-1.0, 4.0, -8.0], [2.0, -5.0, 9.0]]), mindspore.float32)
1551
- >>> output = ops.fast_gelu(x)
1552
- >>> print(output)
1553
- [[-1.5418735e-01 3.9921875e+00 -9.7473649e-06]
1554
- [ 1.9375000e+00 -1.0052517e-03 8.9824219e+00]]
1555
- """
1556
- return fast_gelu_(x)
1557
-
1558
-
1559
1588
  @_primexpr
1560
1589
  def _check_float_range_inc_neither(arg_value, lower_limit, upper_limit, arg_name=None, prim_name=None):
1561
1590
  """
@@ -1574,7 +1603,7 @@ def _check_fractional_output_size_ratio(output_size, output_ratio, cls_name):
1574
1603
  def fractional_max_pool2d(input, kernel_size, output_size=None, output_ratio=None, return_indices=False,
1575
1604
  _random_samples=None):
1576
1605
  r"""
1577
- Applies the 2D FractionalMaxPool operatin over `input`. The output Tensor shape can be determined by either
1606
+ Applies the 2D FractionalMaxPool operation over `input`. The output Tensor shape can be determined by either
1578
1607
  `output_size` or `output_ratio`, and the step size is determined by `_random_samples`. `output_size` will take
1579
1608
  effect when `output_size` and `output_ratio` are set at the same time.
1580
1609
  And `output_size` and `output_ratio` can not be ``None`` at the same time.
@@ -1686,7 +1715,7 @@ def fractional_max_pool2d(input, kernel_size, output_size=None, output_ratio=Non
1686
1715
  def fractional_max_pool3d(input, kernel_size, output_size=None, output_ratio=None, return_indices=False,
1687
1716
  _random_samples=None):
1688
1717
  r"""
1689
- Applies the 3D FractionalMaxPool operatin over `input`. The output Tensor shape can be determined by either
1718
+ Applies the 3D FractionalMaxPool operation over `input`. The output Tensor shape can be determined by either
1690
1719
  `output_size` or `output_ratio`, and the step size is determined by `_random_samples`. `output_size` will take
1691
1720
  effect when `output_size` and `output_ratio` are set at the same time.
1692
1721
  And `output_size` and `output_ratio` can not be ``None`` at the same time.
@@ -1707,7 +1736,7 @@ def fractional_max_pool3d(input, kernel_size, output_size=None, output_ratio=Non
1707
1736
  is an int number that represents depth, height and width of the kernel, or a tuple
1708
1737
  of three int numbers that represent depth, height and width respectively.
1709
1738
  The value must be a positive integer.
1710
- output_size (Union[int, tuple[int]], optional): The Shape of the target `output_size`,
1739
+ output_size (Union[int, tuple[int]], optional): The shape of the target `output_size`,
1711
1740
  is an int number that represents depth, height and width, or a tuple
1712
1741
  of three int numbers that represent depth, height and width respectively.
1713
1742
  The value must be a positive integer.
@@ -1813,10 +1842,10 @@ def kl_div(logits, labels, reduction='mean'):
1813
1842
 
1814
1843
  .. math::
1815
1844
  \ell(x, target) = \begin{cases}
1816
- L, & \text{if reduction} = \text{'none';}\\
1817
- \operatorname{mean}(L), & \text{if reduction} = \text{'mean';}\\
1818
- \operatorname{batchmean}(L), & \text{if reduction} = \text{'batchmean';}\\
1819
- \operatorname{sum}(L), & \text{if reduction} = \text{'sum'.}
1845
+ L(x, target), & \text{if reduction} = \text{'none';}\\
1846
+ \operatorname{mean}(L(x, target)), & \text{if reduction} = \text{'mean';}\\
1847
+ \operatorname{sum}(L(x, target)) / x.\operatorname{shape}[0], & \text{if reduction} = \text{'batchmean';}\\
1848
+ \operatorname{sum}(L(x, target)), & \text{if reduction} = \text{'sum'.}
1820
1849
  \end{cases}
1821
1850
 
1822
1851
  where :math:`x` represents `logits`.
@@ -1826,7 +1855,7 @@ def kl_div(logits, labels, reduction='mean'):
1826
1855
  Note:
1827
1856
  - Currently it does not support float64 input on `Ascend`.
1828
1857
  - The output aligns with the mathematical definition of Kullback-Leibler divergence
1829
- only when `reduction` is set to 'batchmean'.
1858
+ only when `reduction` is set to ``'batchmean'``.
1830
1859
 
1831
1860
  Args:
1832
1861
  logits (Tensor): The input Tensor. The data type must be float16, float32 or float64.
@@ -1834,6 +1863,11 @@ def kl_div(logits, labels, reduction='mean'):
1834
1863
  reduction (str): Specifies the reduction to be applied to the output.
1835
1864
  Its value must be one of ``'none'`` , ``'mean'`` , ``'batchmean'`` or ``'sum'`` . Default: ``'mean'`` .
1836
1865
 
1866
+ - ``'none'``: no reduction will be applied.
1867
+ - ``'mean'``: compute and return the mean of elements in the output.
1868
+ - ``'sum'``: the output elements will be summed.
1869
+ - ``'batchmean'``: the summed output elements divided by batch size.
1870
+
1837
1871
  Returns:
1838
1872
  Tensor or Scalar, if `reduction` is ``'none'``, then output is a tensor and has the same shape as `logits`.
1839
1873
  Otherwise, it is a scalar.
@@ -1841,7 +1875,7 @@ def kl_div(logits, labels, reduction='mean'):
1841
1875
  Raises:
1842
1876
  TypeError: If `reduction` is not a str.
1843
1877
  TypeError: If neither `logits` nor `labels` is a Tensor.
1844
- TypeError: If dtype of `logits` or `labels` is not float32.
1878
+ TypeError: If dtype of `logits` or `labels` is not the supported type.
1845
1879
 
1846
1880
  Supported Platforms:
1847
1881
  ``Ascend`` ``GPU`` ``CPU``
@@ -1861,20 +1895,20 @@ def kl_div(logits, labels, reduction='mean'):
1861
1895
  f"'['none', 'mean', 'batchmean', 'sum']', but got '{reduction}'.")
1862
1896
 
1863
1897
  if reduction == 'batchmean':
1864
- kl_div_sum = P.KLDivLoss(reduction='sum')(logits, labels)
1865
- shape = P.Shape()(logits)
1898
+ kl_div_sum = _get_cache_prim(P.KLDivLoss)(reduction='sum')(logits, labels)
1899
+ shape = shape_(logits)
1866
1900
  batch_size = shape[0]
1867
1901
  return kl_div_sum / batch_size
1868
1902
 
1869
1903
  if reduction == 'mean':
1870
- kl_div_sum = P.KLDivLoss(reduction='sum')(logits, labels)
1871
- shape = P.Shape()(logits)
1904
+ kl_div_sum = _get_cache_prim(P.KLDivLoss)(reduction='sum')(logits, labels)
1905
+ shape = shape_(logits)
1872
1906
  total_size = 1
1873
1907
  for dim in shape:
1874
1908
  total_size = total_size * dim
1875
1909
  return kl_div_sum / total_size
1876
1910
 
1877
- return P.KLDivLoss(reduction=reduction)(logits, labels)
1911
+ return _get_cache_prim(P.KLDivLoss)(reduction=reduction)(logits, labels)
1878
1912
 
1879
1913
 
1880
1914
  def hardshrink(x, lambd=0.5):
@@ -1891,9 +1925,15 @@ def hardshrink(x, lambd=0.5):
1891
1925
  0, & \text{ otherwise }
1892
1926
  \end{cases}
1893
1927
 
1928
+ HShrink Activation Function Graph:
1929
+
1930
+ .. image:: ../images/HShrink.png
1931
+ :align: center
1932
+
1894
1933
  Args:
1895
1934
  x (Tensor): The input of Hard Shrink with data type of float16 or float32.
1896
- lambd (float): The threshold :math:`\lambda` defined by the Hard Shrink formula. Default: ``0.5`` .
1935
+ lambd (float, optional): The threshold :math:`\lambda` defined by the Hard Shrink formula.
1936
+ Default: ``0.5`` .
1897
1937
 
1898
1938
  Returns:
1899
1939
  Tensor, has the same data type and shape as the input `x`.
@@ -1995,16 +2035,16 @@ def flip(input, dims):
1995
2035
  Raises:
1996
2036
  TypeError: If the input is not a tensor.
1997
2037
  ValueError: If `dims` is None.
1998
- ValueError: If `dims` is not a tuple of ints.
2038
+ ValueError: If `dims` is not a list/tuple of ints.
1999
2039
 
2000
2040
  Supported Platforms:
2001
2041
  ``Ascend`` ``GPU`` ``CPU``
2002
2042
 
2003
2043
  Examples:
2004
- >>> import mindspore as ms
2005
- >>> import mindspore.ops as ops
2044
+ >>> import mindspore
2045
+ >>> from mindspore import ops
2006
2046
  >>> import numpy as np
2007
- >>> input = ms.Tensor(np.arange(1, 9).reshape((2, 2, 2)))
2047
+ >>> input = mindspore.Tensor(np.arange(1, 9).reshape((2, 2, 2)))
2008
2048
  >>> output = ops.flip(input, (0, 2))
2009
2049
  >>> print(output)
2010
2050
  [[[6 5]
@@ -2012,7 +2052,7 @@ def flip(input, dims):
2012
2052
  [[2 1]
2013
2053
  [4 3]]]
2014
2054
  """
2015
- res = _get_cache_prim(ops.ReverseV2)(axis=dims)(input)
2055
+ res = reverse_v2_impl(input, dims)
2016
2056
  return res
2017
2057
 
2018
2058
 
@@ -2034,7 +2074,7 @@ def flipud(input):
2034
2074
 
2035
2075
  Examples:
2036
2076
  >>> import mindspore as ms
2037
- >>> import mindspore.ops as ops
2077
+ >>> from mindspore import ops
2038
2078
  >>> import numpy as np
2039
2079
  >>> input = ms.Tensor(np.arange(1, 9).reshape((2, 2, 2)))
2040
2080
  >>> output = ops.flipud(input)
@@ -2065,7 +2105,7 @@ def fliplr(input):
2065
2105
 
2066
2106
  Examples:
2067
2107
  >>> import mindspore as ms
2068
- >>> import mindspore.ops as ops
2108
+ >>> from mindspore import ops
2069
2109
  >>> import numpy as np
2070
2110
  >>> input = ms.Tensor(np.arange(1, 9).reshape((2, 2, 2)))
2071
2111
  >>> output = ops.fliplr(input)
@@ -2094,7 +2134,7 @@ def is_floating_point(input):
2094
2134
 
2095
2135
  Examples:
2096
2136
  >>> import mindspore as ms
2097
- >>> import mindspore.ops as ops
2137
+ >>> from mindspore import ops
2098
2138
  >>> from mindspore import Tensor
2099
2139
  >>> x = ms.Tensor([1, 2, 3], ms.float32)
2100
2140
  >>> y = ms.Tensor([1, 2, 3], ms.int64)
@@ -2105,7 +2145,7 @@ def is_floating_point(input):
2105
2145
  >>> print(output2)
2106
2146
  False
2107
2147
  """
2108
- return input.dtype in [mstype.float32, mstype.float16, mstype.float64]
2148
+ return input.dtype in [mstype.float32, mstype.bfloat16, mstype.float16, mstype.float64]
2109
2149
 
2110
2150
 
2111
2151
  def hardswish(x):
@@ -2120,6 +2160,11 @@ def hardswish(x):
2120
2160
 
2121
2161
  where :math:`x_i` is an element of the input Tensor.
2122
2162
 
2163
+ HSwish Activation Function Graph:
2164
+
2165
+ .. image:: ../images/HSwish.png
2166
+ :align: center
2167
+
2123
2168
  Args:
2124
2169
  x (Tensor): The input to compute the Hard Swish.
2125
2170
 
@@ -2151,15 +2196,25 @@ def _is_dim_unknown(shape):
2151
2196
 
2152
2197
  @_primexpr
2153
2198
  def _interploate_make_tuple(rank, value):
2199
+ """
2200
+ make tuple in dynamic scenarios
2201
+ """
2154
2202
  s = tuple_to_tensor_((rank,), mstype.int32)
2155
- v = Tensor(value)
2156
- t = _get_cache_prim(P.FillV2)()(s, v)
2203
+ v = None
2204
+ if isinstance(value, int):
2205
+ v = F.scalar_to_tensor(value, mstype.int64)
2206
+ else:
2207
+ v = F.scalar_to_tensor(value, mstype.float32)
2208
+ t = fillv2_(s, v)
2157
2209
  out = tensor_to_tuple_(t)
2158
2210
  return out
2159
2211
 
2160
2212
 
2161
2213
  @_primexpr
2162
2214
  def _interpolate_scale_factor_convert_size(shape, scale_factor):
2215
+ """
2216
+ convert scale_factor to size
2217
+ """
2163
2218
  x = tuple_to_tensor_(shape[2:], mstype.int64)
2164
2219
  y = tuple_to_tensor_(scale_factor, mstype.float32)
2165
2220
  t = x * y
@@ -2169,6 +2224,9 @@ def _interpolate_scale_factor_convert_size(shape, scale_factor):
2169
2224
 
2170
2225
 
2171
2226
  def _interpolate_size_check_with_rank(size, input_rank):
2227
+ """
2228
+ size rank check
2229
+ """
2172
2230
  if len(size) != input_rank - 2:
2173
2231
  raise ValueError(
2174
2232
  f"For 'interpolate', 'input' and 'size' must have the same spatial dimensions, "
@@ -2176,6 +2234,9 @@ def _interpolate_size_check_with_rank(size, input_rank):
2176
2234
 
2177
2235
 
2178
2236
  def _interpolate_scale_factor_check_with_rank(scale_factor, input_rank):
2237
+ """
2238
+ scale_factor rank check
2239
+ """
2179
2240
  if len(scale_factor) != input_rank - 2:
2180
2241
  raise ValueError(
2181
2242
  f"For 'interpolate', 'input' and 'scale_factor' must have the same spatial dimensions, "
@@ -2184,6 +2245,9 @@ def _interpolate_scale_factor_check_with_rank(scale_factor, input_rank):
2184
2245
 
2185
2246
 
2186
2247
  def _interpolate_mode_check(mode, supported_dict):
2248
+ """
2249
+ mode check
2250
+ """
2187
2251
  if isinstance(mode, list) or mode not in supported_dict:
2188
2252
  raise ValueError(
2189
2253
  f"For 'interpolate', 'mode' must be in '{list(supported_dict)}', but got {mode}"
@@ -2191,6 +2255,9 @@ def _interpolate_mode_check(mode, supported_dict):
2191
2255
 
2192
2256
 
2193
2257
  def _interpolate_rank_check(input_rank, mode, supported_dict):
2258
+ """
2259
+ rank check
2260
+ """
2194
2261
  if input_rank not in supported_dict.get(mode):
2195
2262
  raise ValueError(
2196
2263
  f"For 'interpolate', {mode} only support '{list(supported_dict.get(mode, {}))}'D, but got {input_rank}D"
@@ -2198,6 +2265,9 @@ def _interpolate_rank_check(input_rank, mode, supported_dict):
2198
2265
 
2199
2266
 
2200
2267
  def _interpolate_scale_factor_check(scale_factor, mode, rank, supported_dict):
2268
+ """
2269
+ scale_factor check
2270
+ """
2201
2271
  if scale_factor is not None and "scale_factor" not in supported_dict.get(
2202
2272
  mode, {}).get(rank):
2203
2273
  raise ValueError(
@@ -2206,6 +2276,9 @@ def _interpolate_scale_factor_check(scale_factor, mode, rank, supported_dict):
2206
2276
 
2207
2277
 
2208
2278
  def _interpolate_align_corners_mode_check(rank, mode, supported_dict):
2279
+ """
2280
+ align_corners check
2281
+ """
2209
2282
  if "align_corners" not in supported_dict.get(mode, {}).get(rank):
2210
2283
  raise ValueError(
2211
2284
  f"For 'interpolate', 'align_corners' option cannot currently be set with the "
@@ -2238,17 +2311,22 @@ def interpolate(input,
2238
2311
  'area', 'nearest-exact'(matches Scikit-Image and PIL nearest neighbours interpolation algorithms and fixes
2239
2312
  knows issues with `nearest`, 3D and 4D). Default: ``"nearest"`` .
2240
2313
 
2241
- align_corners (bool): If True, rescale input by :math:`(new\_height - 1) / (height - 1)`, which exactly
2242
- aligns the corners of data and resized data. If False, rescale by :math:`new\_height / height`.
2243
- Default: ``None`` .
2314
+ align_corners (bool): Whether to use corner alignment for coordinate mapping. Assuming a transformation is
2315
+ applied to the input Tensor along the x-axis, the specific calculation formula is as follows:
2244
2316
 
2245
2317
  .. code-block::
2246
2318
 
2247
- old_i = new_length != 1 ? new_i * (old_length - 1) / (new_length - 1) : 0 # 'align_corners' = True
2319
+ ori_i = new_length != 1 ? new_i * (ori_length - 1) / (new_length - 1) : 0 # 'align_corners' = True
2320
+
2321
+ ori_i = new_length > 1 ? (new_i + 0.5) * ori_length / new_length - 0.5 : 0 # 'align_corners' = False
2248
2322
 
2249
- old_i = new_length > 1 ? (new_x + 0.5) * old_length / new_length - 0.5 : 0 # 'align_corners' = False
2323
+ Among them, :math:`ori\_length` and :math:`new\_length` represent the length of the Tensor before and after
2324
+ transformation along the x-axis respectively; :math:`new\_i` represents the coordinate of the i-th element
2325
+ along the x-axis after transformation; :math:`ori\_i` represents
2326
+ the corresponding coordinate of the original
2327
+ data along the x-axis.
2250
2328
 
2251
- This is only valid for 'linear', 'bilinear', or 'bicubic' modes. Default: ``False`` .
2329
+ This is only valid for ``'linear'``, ``'bilinear'``, or ``'bicubic'`` modes. Default: ``False`` .
2252
2330
  recompute_scale_factor (bool, optional): Recalculate `scale_factor`.
2253
2331
  If True, the parameter `size` will be calculated using the value of the `scale_factor`,
2254
2332
  and finally scaled using the value of `size`.
@@ -2331,7 +2409,7 @@ def interpolate(input,
2331
2409
  x = x.unsqueeze(-1)
2332
2410
  x = _get_cache_prim(P.ResizeNearestNeighborV2)()(
2333
2411
  x, size)
2334
- x = P.Squeeze(-1)(x)
2412
+ x = _get_cache_prim(P.Squeeze)(-1)(x)
2335
2413
  elif size is not None and x_rank == 4:
2336
2414
  size = seq.TupleToTensor()(size[:2], mstype.int32)
2337
2415
  x = _get_cache_prim(P.ResizeNearestNeighborV2)()(
@@ -2383,7 +2461,7 @@ def interpolate(input,
2383
2461
  align_corners=False,
2384
2462
  half_pixel_centers=True)
2385
2463
  x = resize(x, size)
2386
- x = P.Squeeze(-1)(x)
2464
+ x = _get_cache_prim(P.Squeeze)(-1)(x)
2387
2465
  if x_rank == 4:
2388
2466
  if isinstance(size, int):
2389
2467
  size = F.scalar_to_tensor(size, mstype.int32)
@@ -2503,7 +2581,12 @@ def interpolate(input,
2503
2581
  raise ValueError(
2504
2582
  "For 'interpolate', it is incorrect to set 'recompute_scale_factor' to True"
2505
2583
  " after specifying an explicit 'size'.")
2506
- size = _interpolate_scale_factor_convert_size(shape, scale_factor)
2584
+ if F.isconstant(shape) and F.isconstant(scale_factor):
2585
+ tuple_len = min(len(shape) - 2, len(scale_factor))
2586
+ size = tuple([floor(shape[i + 2] * scale_factor[i])
2587
+ for i in range(tuple_len)])
2588
+ else:
2589
+ size = _interpolate_scale_factor_convert_size(shape, scale_factor)
2507
2590
  scale_factor = None
2508
2591
  else:
2509
2592
  if dim_unknown is False:
@@ -2521,54 +2604,341 @@ def interpolate(input,
2521
2604
  return resize_func.get(mode)(input, size, align_corners, scale_factor)
2522
2605
 
2523
2606
 
2524
- def upsample(input, size=None, scale_factor=None, mode="nearest", align_corners=None, recompute_scale_factor=None):
2525
- r"""
2526
- Alias for :func:`mindspore.ops.interpolate` .
2527
-
2528
- Supported Platforms:
2529
- ``Ascend`` ``GPU`` ``CPU``
2607
+ def _interploate_ext_make_tuple(input, value):
2530
2608
  """
2531
- return interpolate(input, size, scale_factor, mode, align_corners, recompute_scale_factor)
2609
+ make tuple
2610
+ """
2611
+ if isinstance(value, (list, tuple)):
2612
+ return value
2613
+
2614
+ rank = F.rank(input) - 2
2615
+ out = None
2616
+ if F.isconstant(value) and F.isconstant(rank):
2617
+ out = tuple([value for _ in range(rank)])
2618
+ else:
2619
+ s = tuple_to_tensor_((rank,), mstype.int32)
2620
+ v = None
2621
+ if isinstance(value, int):
2622
+ v = F.scalar_to_tensor(value, mstype.int64)
2623
+ else:
2624
+ v = F.scalar_to_tensor(value, mstype.float32)
2625
+ t = fillv2_(s, v)
2626
+ out = tensor_to_tuple_(t)
2627
+ return out
2532
2628
 
2533
2629
 
2534
- def softsign(x):
2630
+ def _interpolate_ext_scale_factor_convert_size(input, scale_factor):
2631
+ """
2632
+ convert scale_factor to size
2633
+ """
2634
+ shape = F.shape(input)
2635
+ size = None
2636
+ if F.isconstant(shape) and F.isconstant(scale_factor):
2637
+ tuple_len = min(len(shape) - 2, len(scale_factor))
2638
+ size = tuple([floor(shape[i + 2] * scale_factor[i])
2639
+ for i in range(tuple_len)])
2640
+ else:
2641
+ x = tuple_to_tensor_(shape[2:], mstype.int64)
2642
+ y = tuple_to_tensor_(scale_factor, mstype.float32)
2643
+ t = x * y
2644
+ t = ops.TruncateDiv()(t, Tensor(1))
2645
+ t = ops.cast(t, mstype.int64)
2646
+ size = tensor_to_tuple_(t)
2647
+ return size
2648
+
2649
+
2650
+ def interpolate_ext(input,
2651
+ size=None,
2652
+ scale_factor=None,
2653
+ mode="nearest",
2654
+ align_corners=None,
2655
+ recompute_scale_factor=None):
2535
2656
  r"""
2536
- Softsign activation function.
2537
-
2538
- The function is shown as follows:
2657
+ Samples the input Tensor to the given size or scale_factor by using one of the interpolate algorithms.
2539
2658
 
2540
- .. math::
2541
- \text{SoftSign}(x) = \frac{x}{1 + |x|}
2659
+ .. note::
2660
+ - In 'linear' mode, backpropagation does not support scenarios where `scale_factor` is not None
2661
+ and `align_corners` is False.
2542
2662
 
2543
2663
  Args:
2544
- x (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
2545
- additional dimensions, with float16 or float32 data type.
2664
+ input (Tensor): Tensor to be resized.
2665
+ Input tensor must be a 3-D, 4-D, or 5-D tensor with shape
2666
+ :math:`(N, C, [optional D], [optional H], W)` , with data type of float.
2667
+ size (Union[int, tuple[int], list[int]], optional): The target size.
2668
+ If size is a tuple or list, its length should be the same as the number of dimensions in input
2669
+ after removing the first two dimensions N, C.
2670
+ One and only one of size and scale_factor can be set to None. Default: ``None`` .
2671
+ scale_factor (Union[float, tuple[float], list[float]], optional): The scale factor of new size of the tensor.
2672
+ If scale_factor is a tuple or list, its length should be the same as the number of dimensions in input
2673
+ after removing the first two dimensions N, C.
2674
+ One and only one of size and scale_factor can be set to None. Default: ``None`` .
2675
+ mode (str): The sampling algorithm.
2676
+ One of 'nearest', 'linear' (3D only), 'bilinear' (4D only), 'trilinear' (5D only), 'bicubic' (4D only),
2677
+ 'area', 'nearest-exact'(matches Scikit-Image and PIL nearest neighbours interpolation algorithms and fixes
2678
+ knows issues with `nearest`, 3D and 4D). Default: ``"nearest"`` .
2679
+
2680
+ align_corners (bool): Whether to use corner alignment for coordinate mapping. Assuming a transformation is
2681
+ applied to the input Tensor along the x-axis, the specific calculation formula is as follows:
2682
+
2683
+ .. code-block::
2684
+
2685
+ ori_i = new_length != 1 ? new_i * (ori_length - 1) / (new_length - 1) : 0 # 'align_corners' = True
2686
+
2687
+ ori_i = new_length > 1 ? (new_i + 0.5) * ori_length / new_length - 0.5 : 0 # 'align_corners' = False
2688
+
2689
+ Among them, :math:`ori\_length` and :math:`new\_length` represent the length of the Tensor before and after
2690
+ transformation along the x-axis respectively; :math:`new\_i` represents the coordinate of the i-th element
2691
+ along the x-axis after transformation; :math:`ori\_i` represents
2692
+ the corresponding coordinate of the original
2693
+ data along the x-axis.
2694
+
2695
+ This is only valid for ``'linear'``, ``'bilinear'``, or ``'bicubic'`` modes. Default: ``False`` .
2696
+ recompute_scale_factor (bool, optional): Recalculate `scale_factor`.
2697
+ If True, the parameter `size` will be calculated using the value of the `scale_factor`,
2698
+ and finally scaled using the value of `size`.
2699
+ If False, the value of `size` or `scale_factor` will be used for direct interpolation. Default: ``None`` .
2700
+
2701
+ .. note::
2702
+ The 'nearest-exact' mode is the same as the nearest-neighbor interpolation algorithm used in
2703
+ scikit-image and PIL. The 'nearest' mode produces the same results as the INTER_NEAREST interpolation
2704
+ algorithm used in OpenCV.
2705
+
2706
+ Args Support List and Supported Platforms:
2707
+
2708
+ +---------------+-----------+---------------+--------------+----------------+
2709
+ | mode | input.dim | align_corners | scale_factor | device |
2710
+ +===============+===========+===============+==============+================+
2711
+ | nearest | 3 | \- | √ | Ascend,GPU,CPU |
2712
+ +---------------+-----------+---------------+--------------+----------------+
2713
+ | | 4 | \- | √ | Ascend,GPU,CPU |
2714
+ +---------------+-----------+---------------+--------------+----------------+
2715
+ | | 5 | \- | √ | Ascend,GPU,CPU |
2716
+ +---------------+-----------+---------------+--------------+----------------+
2717
+ | linear | 3 | √ | √ | Ascend,GPU,CPU |
2718
+ +---------------+-----------+---------------+--------------+----------------+
2719
+ | bilinear | 4 | √ | × | Ascend,GPU,CPU |
2720
+ +---------------+-----------+---------------+--------------+----------------+
2721
+ | bicubic | 4 | √ | × | Ascend,GPU,CPU |
2722
+ +---------------+-----------+---------------+--------------+----------------+
2723
+ | area | 3 | \- | √ | Ascend,GPU,CPU |
2724
+ +---------------+-----------+---------------+--------------+----------------+
2725
+ | | 4 | \- | √ | Ascend,GPU,CPU |
2726
+ +---------------+-----------+---------------+--------------+----------------+
2727
+ | | 5 | \- | √ | Ascend,GPU,CPU |
2728
+ +---------------+-----------+---------------+--------------+----------------+
2729
+ | nearest-exact | 3 | \- | × | Ascend,CPU |
2730
+ +---------------+-----------+---------------+--------------+----------------+
2731
+ | | 4 | \- | × | Ascend,CPU |
2732
+ +---------------+-----------+---------------+--------------+----------------+
2733
+ | trilinear | 5 | √ | √ | Ascend,GPU,CPU |
2734
+ +---------------+-----------+---------------+--------------+----------------+
2735
+
2736
+ - `-` indicates that there is no such parameter.
2737
+ - `×` indicates that this parameter is not currently supported.
2738
+ - `√` indicates that this parameter is supported.
2546
2739
 
2547
2740
  Returns:
2548
- Tensor, with the same type and shape as the `x`.
2741
+ Tensor, resized, whose dimensions and dtype are the same as `input`.
2549
2742
 
2550
2743
  Raises:
2551
- TypeError: If `x` is not a Tensor.
2552
- TypeError: If dtype of `x` is neither float16 nor float32.
2744
+ TypeError: `input` is not a Tensor.
2745
+ ValueError: Both `size` and `scale_factor` are not empty.
2746
+ ValueError: Both `size` and `scale_factor` are empty.
2747
+ ValueError: When `size` is a tuple or list, its length is not equal to `input.ndim - 2`.
2748
+ ValueError: When `scale_factor` is a tuple or list, its length is not equal to `input.ndim - 2`.
2749
+ ValueError: `mode` is not in the list of supported modes.
2750
+ ValueError: `input.ndim` is not in the list of supported dimensions for the corresponding mode.
2751
+ ValueError: `size` is not empty, `recompute_scale_factor` is not empty.
2752
+ ValueError: `scale_factor` is not in the corresponding list of supported values.
2753
+ ValueError: `align_corners` is not in the corresponding list of supported values.
2553
2754
 
2554
2755
  Supported Platforms:
2555
2756
  ``Ascend`` ``GPU`` ``CPU``
2556
2757
 
2557
2758
  Examples:
2558
2759
  >>> import mindspore
2559
- >>> import numpy as np
2560
- >>> from mindspore import Tensor, ops
2561
- >>> x = Tensor(np.array([0, -1, 2, 30, -30]), mindspore.float32)
2562
- >>> output = ops.softsign(x)
2760
+ >>> from mindspore import Tensor, mint
2761
+ >>> input = Tensor([[[1, 2, 3], [4, 5, 6]]], mindspore.float32)
2762
+ >>> output = mint.interpolate(input, size=(6,), mode='nearest')
2563
2763
  >>> print(output)
2564
- [ 0. -0.5 0.6666667 0.9677419 -0.9677419]
2764
+ [[[1. 1. 2. 2. 3. 3.]
2765
+ [4. 4. 5. 5. 6. 6.]]]
2565
2766
  """
2566
- return softsign_(x)
2767
+ def run_nearest(x, size, align_corners=None, scale_factor=None):
2768
+ x_rank = F.rank(x)
2769
+ if x_rank == 3:
2770
+ x = _get_cache_prim(ops.auto_generate.UpsampleNearest1D)()(
2771
+ x, size, scale_factor)
2772
+ elif x_rank == 4:
2773
+ x = _get_cache_prim(ops.auto_generate.UpsampleNearest2D)()(
2774
+ x, size, scale_factor)
2775
+ else:
2776
+ x = _get_cache_prim(P.UpsampleNearest3D)()(x, size, scale_factor)
2777
+ return x
2567
2778
 
2779
+ def run_linear(x, size, align_corners=None, scale_factor=None):
2780
+ out = _get_cache_prim(
2781
+ ops.auto_generate.UpsampleLinear1D)()(x, size, scale_factor, align_corners)
2782
+ return out
2568
2783
 
2569
- def soft_margin_loss(input, target, reduction='mean'):
2570
- r"""
2571
- Calculate the soft margin loss of input and target.
2784
+ def run_bilinear(x, size, align_corners=None, scale_factor=None):
2785
+ out = _get_cache_prim(
2786
+ ops.auto_generate.UpsampleBilinear2D)()(x, size, scale_factor, align_corners)
2787
+ return out
2788
+
2789
+ def run_trilinear(x, size, align_corners=None, scale_factor=None):
2790
+ resize = _get_cache_prim(P.nn_ops.UpsampleTrilinear3D)(align_corners)
2791
+ return resize(x, size, scale_factor)
2792
+
2793
+ def run_bicubic(x, size, align_corners=None, scale_factor=None):
2794
+ resize = _get_cache_prim(P.image_ops.ResizeBicubic)(
2795
+ align_corners=align_corners, half_pixel_centers=not align_corners)
2796
+ x = resize(x, size)
2797
+ return x
2798
+
2799
+ def run_area(x, size, align_corners=None, scale_factor=None):
2800
+ x_rank = F.rank(x)
2801
+ if x_rank == 3:
2802
+ x = F.adaptive_avg_pool1d(x, size[0])
2803
+ elif x_rank == 4:
2804
+ x = F.adaptive_avg_pool2d(x, tuple(size))
2805
+ else:
2806
+ x = F.adaptive_avg_pool3d(x, tuple(size))
2807
+ return x
2808
+
2809
+ def run_nearest_exact(x, size, align_corners=None, scale_factor=None):
2810
+ x_rank = F.rank(x)
2811
+ if x_rank == 3:
2812
+ size = size[:1] + (1,)
2813
+ # For impl of nearest 3D use 4D.
2814
+ x = x.unsqueeze(-1)
2815
+ resize = _get_cache_prim(P.ResizeNearestNeighborV2)(
2816
+ align_corners=False,
2817
+ half_pixel_centers=True)
2818
+ x = resize(x, size)
2819
+ x = _get_cache_prim(P.Squeeze)(-1)(x)
2820
+ if x_rank == 4:
2821
+ resize = _get_cache_prim(P.ResizeNearestNeighborV2)(
2822
+ align_corners=False,
2823
+ half_pixel_centers=True)
2824
+ x = resize(x, size)
2825
+ return x
2826
+
2827
+
2828
+ resize_funcs = {
2829
+ "nearest": run_nearest,
2830
+ "linear": run_linear,
2831
+ "bilinear": run_bilinear,
2832
+ "bicubic": run_bicubic,
2833
+ "trilinear": run_trilinear,
2834
+ "area": run_area,
2835
+ "nearest-exact": run_nearest_exact,
2836
+ }
2837
+
2838
+ # mode check
2839
+ if mode not in resize_funcs:
2840
+ raise ValueError(
2841
+ f"For 'interpolate', 'mode' must be in '{list(resize_funcs)}', but got {mode}"
2842
+ )
2843
+ if mode in ("nearest", "area", "nearest-exact"):
2844
+ if align_corners is not None:
2845
+ raise ValueError("align_corners option can only be set with the "
2846
+ "interpolating modes: linear | bilinear | bicubic | trilinear"
2847
+ )
2848
+ else:
2849
+ if align_corners is None:
2850
+ align_corners = False
2851
+
2852
+ # check for size and scale_factor
2853
+ if size is not None and scale_factor is not None:
2854
+ raise ValueError(
2855
+ "For 'interpolate', 'size' and 'scale_factor' cannot be set simultaneously"
2856
+ )
2857
+ if size is not None:
2858
+ size = _interploate_ext_make_tuple(input, size)
2859
+ elif scale_factor is not None:
2860
+ scale_factor = _interploate_ext_make_tuple(input, scale_factor)
2861
+ else:
2862
+ raise ValueError(
2863
+ "For 'interpolate', 'size' and 'scale_factor' cannot be both empty"
2864
+ )
2865
+
2866
+ # "area" mode always requires an explicit size rather than scale factor.
2867
+ if mode == "area" and size is None:
2868
+ recompute_scale_factor = True
2869
+
2870
+ # recompute_scale_factor
2871
+ if recompute_scale_factor is not None and recompute_scale_factor:
2872
+ if size is not None:
2873
+ raise ValueError(
2874
+ "For 'interpolate', it is incorrect to set 'recompute_scale_factor' to True"
2875
+ " after specifying an explicit 'size'.")
2876
+ size = _interpolate_ext_scale_factor_convert_size(input, scale_factor)
2877
+ scale_factor = None
2878
+
2879
+ # scale_factor
2880
+ if mode in ("bilinear", "bicubic", "nearest-exact"):
2881
+ if scale_factor is not None:
2882
+ raise ValueError("scale_factor option can only be set with the "
2883
+ "interpolating modes: nearest | linear | area | trilinear"
2884
+ )
2885
+
2886
+ return resize_funcs.get(mode)(input, size, align_corners, scale_factor)
2887
+
2888
+
2889
+ def upsample(input, size=None, scale_factor=None, mode="nearest", align_corners=None, recompute_scale_factor=None):
2890
+ r"""
2891
+ Alias for :func:`mindspore.ops.interpolate` .
2892
+
2893
+ Supported Platforms:
2894
+ ``Ascend`` ``GPU`` ``CPU``
2895
+ """
2896
+ return interpolate(input, size, scale_factor, mode, align_corners, recompute_scale_factor)
2897
+
2898
+
2899
+ def softsign(x):
2900
+ r"""
2901
+ SoftSign activation function.
2902
+
2903
+ The function is shown as follows:
2904
+
2905
+ .. math::
2906
+ \text{SoftSign}(x) = \frac{x}{1 + |x|}
2907
+
2908
+ Softsign Activation Function Graph:
2909
+
2910
+ .. image:: ../images/Softsign.png
2911
+ :align: center
2912
+
2913
+ Args:
2914
+ x (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
2915
+ additional dimensions, with float16 or float32 data type.
2916
+
2917
+ Returns:
2918
+ Tensor, with the same type and shape as the `x`.
2919
+
2920
+ Raises:
2921
+ TypeError: If `x` is not a Tensor.
2922
+ TypeError: If dtype of `x` is neither float16 nor float32.
2923
+
2924
+ Supported Platforms:
2925
+ ``Ascend`` ``GPU`` ``CPU``
2926
+
2927
+ Examples:
2928
+ >>> import mindspore
2929
+ >>> import numpy as np
2930
+ >>> from mindspore import Tensor, ops
2931
+ >>> x = Tensor(np.array([0, -1, 2, 30, -30]), mindspore.float32)
2932
+ >>> output = ops.softsign(x)
2933
+ >>> print(output)
2934
+ [ 0. -0.5 0.6666667 0.9677419 -0.9677419]
2935
+ """
2936
+ return softsign_(x)
2937
+
2938
+
2939
+ def soft_margin_loss(input, target, reduction='mean'):
2940
+ r"""
2941
+ Calculate the soft margin loss of input and target.
2572
2942
 
2573
2943
  Creates a criterion that optimizes a two-class classification
2574
2944
  logistic loss between input tensor :math:`x` and target tensor :math:`y`
@@ -2584,7 +2954,7 @@ def soft_margin_loss(input, target, reduction='mean'):
2584
2954
 
2585
2955
  Args:
2586
2956
  input (Tensor): Predict data. Data type must be float16 or float32.
2587
- target (Tensor): Ground truth data, with the same type and shape as `logits`.
2957
+ target (Tensor): Ground truth data, with the same type and shape as `input`.
2588
2958
  reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
2589
2959
  ``'sum'`` . Default: ``'mean'`` .
2590
2960
 
@@ -2593,7 +2963,7 @@ def soft_margin_loss(input, target, reduction='mean'):
2593
2963
  - ``'sum'``: the output elements will be summed.
2594
2964
 
2595
2965
  Outputs:
2596
- Tensor or Scalar. If `reduction` is ``'none'``, its shape is the same as `logits`.
2966
+ Tensor or Scalar. If `reduction` is ``'none'``, its shape is the same as `input`.
2597
2967
  Otherwise, a scalar value will be returned.
2598
2968
 
2599
2969
  Raises:
@@ -2620,34 +2990,31 @@ def soft_margin_loss(input, target, reduction='mean'):
2620
2990
  return output
2621
2991
 
2622
2992
 
2623
- def softmax(x, axis=-1, *, dtype=None):
2993
+ def softmax(input, axis=-1, *, dtype=None):
2624
2994
  r"""
2625
2995
  Applies the Softmax operation to the input tensor on the specified axis.
2626
- Suppose a slice in the given axis :math:`x`, then for each element :math:`x_i`,
2996
+ Suppose a slice in the given axis :math:`axis`, then for each element :math:`input_i`,
2627
2997
  the Softmax function is shown as follows:
2628
2998
 
2629
2999
  .. math::
2630
- \text{output}(x_i) = \frac{\exp(x_i)}{\sum_{j = 0}^{N-1}\exp(x_j)},
3000
+ \text{output}(input_i) = \frac{\exp(input_i)}{\sum_{j = 0}^{N-1}\exp(input_j)},
2631
3001
 
2632
3002
  where :math:`N` is the length of the tensor.
2633
3003
 
2634
3004
  Args:
2635
- axis (Union[int, tuple[int]], optional): The axis to perform the Softmax operation. Default: ``-1`` .
2636
- x (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
3005
+ input (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
2637
3006
  additional dimensions, with float16 or float32 data type.
3007
+ axis (int, optional): The axis to perform the Softmax operation. Default: ``-1`` .
2638
3008
 
2639
3009
  Keyword Args:
2640
- dtype (:class:`mindspore.dtype`, optional): When set, `x` will be converted to the specified type,
3010
+ dtype (:class:`mindspore.dtype`, optional): When set, `input` will be converted to the specified type,
2641
3011
  `dtype`, before execution, and dtype of returned Tensor will also be `dtype`. Default: ``None`` .
2642
3012
 
2643
3013
  Returns:
2644
- Tensor, with the same type and shape as the logits.
3014
+ Tensor, with the same type and shape as the `input`.
2645
3015
 
2646
3016
  Raises:
2647
- TypeError: If `axis` is not an int or a tuple.
2648
- TypeError: If dtype of `x` is neither float16 nor float32.
2649
- ValueError: If `axis` is a tuple whose length is less than 1.
2650
- ValueError: If `axis` is a tuple whose elements are not all in range [-len(logits.shape), len(logits.shape))
3017
+ TypeError: If `axis` is not an int.
2651
3018
 
2652
3019
  Supported Platforms:
2653
3020
  ``Ascend`` ``GPU`` ``CPU``
@@ -2656,8 +3023,8 @@ def softmax(x, axis=-1, *, dtype=None):
2656
3023
  >>> import mindspore
2657
3024
  >>> import numpy as np
2658
3025
  >>> from mindspore import Tensor, ops
2659
- >>> x = Tensor(np.array([1, 2, 3, 4, 5]), mindspore.float32)
2660
- >>> output = ops.softmax(x)
3026
+ >>> input = Tensor(np.array([1, 2, 3, 4, 5]), mindspore.float32)
3027
+ >>> output = ops.softmax(input)
2661
3028
  >>> print(output)
2662
3029
  [0.01165623 0.03168492 0.08612854 0.23412167 0.6364086 ]
2663
3030
  """
@@ -2666,9 +3033,57 @@ def softmax(x, axis=-1, *, dtype=None):
2666
3033
  type_axis = type(axis).__name__
2667
3034
  raise TypeError(f" the type of 'axis' must be 'int', but got '{axis}' with type '{type_axis}'.")
2668
3035
  if dtype is not None:
2669
- x = ops.cast(x, dtype)
2670
- softmax_ = _get_cache_prim(P.Softmax)(axis=axis)
2671
- return softmax_(x)
3036
+ input = ops.cast(input, dtype)
3037
+ softmax_ = _get_cache_prim(P.Softmax)(axis)
3038
+ return softmax_(input)
3039
+
3040
+
3041
+ def softmax_ext(input, dim=None, dtype=None):
3042
+ r"""
3043
+ Applies the Softmax operation to the input tensor on the specified axis.
3044
+ Suppose a slice in the given axis :math:`dim`, then for each element :math:`input_i`,
3045
+ the Softmax function is shown as follows:
3046
+
3047
+ .. math::
3048
+ \text{output}(input_i) = \frac{\exp(input_i)}{\sum_{j = 0}^{N-1}\exp(input_j)},
3049
+
3050
+ where :math:`N` is the length of the tensor.
3051
+
3052
+ Args:
3053
+ input (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
3054
+ additional dimensions.
3055
+ dim (int, optional): The dim to perform the Softmax operation. Default: ``None`` .
3056
+
3057
+ Keyword Args:
3058
+ dtype (:class:`mindspore.dtype`, optional): When set, `input` will be converted to the specified type,
3059
+ `dtype`, before execution, and dtype of returned Tensor will also be `dtype`. Default: ``None`` .
3060
+
3061
+ Returns:
3062
+ Tensor, with the same type and shape as the `input`.
3063
+
3064
+ Raises:
3065
+ TypeError: If `dim` is not an int.
3066
+
3067
+ Supported Platforms:
3068
+ ``Ascend`` ``GPU`` ``CPU``
3069
+
3070
+ Examples:
3071
+ >>> import mindspore
3072
+ >>> import numpy as np
3073
+ >>> from mindspore import Tensor, ops
3074
+ >>> input = Tensor(np.array([1, 2, 3, 4, 5]), mindspore.float32)
3075
+ >>> output = ops.function.nn_func.softmax_ext(input)
3076
+ >>> print(output)
3077
+ [0.01165623 0.03168492 0.08612854 0.23412167 0.6364086 ]
3078
+ """
3079
+ dim = -1 if dim is None else dim
3080
+ if not isinstance(dim, int):
3081
+ type_dim = type(dim).__name__
3082
+ raise TypeError(f" the type of 'dim' must be 'int', but got '{dim}' with type '{type_dim}'.")
3083
+ if dtype is not None:
3084
+ input = ops.cast(input, dtype)
3085
+ softmax_ = _get_cache_prim(P.Softmax)(dim)
3086
+ return softmax_(input)
2672
3087
 
2673
3088
 
2674
3089
  def softmin(x, axis=-1, *, dtype=None):
@@ -2692,7 +3107,7 @@ def softmin(x, axis=-1, *, dtype=None):
2692
3107
  `dtype`, before execution, and dtype of returned Tensor will also be `dtype`. Default: ``None`` .
2693
3108
 
2694
3109
  Returns:
2695
- Tensor, with the same type and shape as the logits.
3110
+ Tensor, with the same type and shape as `x`.
2696
3111
 
2697
3112
  Raises:
2698
3113
  TypeError: If `axis` is not an int or a tuple.
@@ -2715,7 +3130,7 @@ def softmin(x, axis=-1, *, dtype=None):
2715
3130
 
2716
3131
  if dtype is not None:
2717
3132
  x = ops.cast(x, dtype)
2718
- softmax_ = _get_cache_prim(P.Softmax)(axis=axis)
3133
+ softmax_ = _get_cache_prim(P.Softmax)(axis)
2719
3134
  return softmax_(-1*x)
2720
3135
 
2721
3136
 
@@ -2731,6 +3146,11 @@ def softshrink(x, lambd=0.5):
2731
3146
  0, & \text{ otherwise }
2732
3147
  \end{cases}
2733
3148
 
3149
+ SoftShrink Activation Function Graph:
3150
+
3151
+ .. image:: ../images/Softshrink.png
3152
+ :align: center
3153
+
2734
3154
  Args:
2735
3155
  x (Tensor): The input of soft shrink with data type of float16 or float32.
2736
3156
  lambd (float): The :math:`\lambda` must be no less than zero. Default: ``0.5`` .
@@ -2739,15 +3159,16 @@ def softshrink(x, lambd=0.5):
2739
3159
  Tensor, has the same shape and data type as `x`.
2740
3160
 
2741
3161
  Raises:
2742
- TypeError: If lambd is not a float.
2743
- TypeError: If input_x is not a Tensor.
2744
- TypeError: If dtype of input_x is neither float16 nor float32.
2745
- ValueError: If lambd is less than 0.
3162
+ TypeError: If `lambd` is not a float.
3163
+ TypeError: If `x` is not a Tensor.
3164
+ TypeError: If dtype of `x` is neither float16 nor float32.
3165
+ ValueError: If `lambd` is less than 0.
2746
3166
 
2747
3167
  Supported Platforms:
2748
3168
  ``Ascend`` ``GPU`` ``CPU``
2749
3169
 
2750
3170
  Examples:
3171
+ >>> import mindspore
2751
3172
  >>> from mindspore import Tensor
2752
3173
  >>> from mindspore import ops
2753
3174
  >>> import numpy as np
@@ -2813,45 +3234,11 @@ def softplus(input, beta=1, threshold=20): # pylint:disable=redefined-outer-name
2813
3234
  >>> print(output)
2814
3235
  [0.7443967 0.79813886 30. 25.]
2815
3236
  """
2816
- softplus_op = _get_cache_prim(P.Softplus)()
2817
3237
  scaling_input = beta * input
2818
- op_output = (1 / beta) * softplus_op(scaling_input)
3238
+ op_output = (1 / beta) * softplus_(scaling_input)
2819
3239
  return ops.select(input * beta > threshold, input, op_output)
2820
3240
 
2821
3241
 
2822
- def silu(x):
2823
- r"""
2824
- Computes Sigmoid Linear Unit of input element-wise. The SiLU function is defined as:
2825
-
2826
- .. math::
2827
- \text{SiLU}(x) = x * \sigma(x),
2828
-
2829
- where the Logistic Sigmoid function is defined as:
2830
-
2831
- .. math::
2832
-
2833
- \text{sigma}(x_i) = \frac{1}{1 + \exp(-x_i)},
2834
-
2835
- where :math:`x_i` is an element of the x.
2836
-
2837
- For more details, please refer to :class:`mindspore.nn.SiLU`.
2838
-
2839
- Supported Platforms:
2840
- ``Ascend`` ``GPU`` ``CPU``
2841
-
2842
- Examples:
2843
- >>> import numpy as np
2844
- >>> import mindspore
2845
- >>> from mindspore import Tensor, ops
2846
- >>> x = Tensor(np.array([-1, 2, -3, 2, -1]), mindspore.float16)
2847
- >>> output = ops.silu(x)
2848
- >>> print(output)
2849
- [-0.269 1.762 -0.1423 1.762 -0.269]
2850
- """
2851
- silu_ = _get_cache_prim(SiLU)()
2852
- return silu_(x)
2853
-
2854
-
2855
3242
  def selu(input_x):
2856
3243
  r"""
2857
3244
  Activation function SeLU (Scaled exponential Linear Unit).
@@ -2871,14 +3258,20 @@ def selu(input_x):
2871
3258
 
2872
3259
  See more details in `Self-Normalizing Neural Networks <https://arxiv.org/abs/1706.02515>`_.
2873
3260
 
3261
+ SeLU Activation Function Graph:
3262
+
3263
+ .. image:: ../images/SeLU.png
3264
+ :align: center
3265
+
2874
3266
  Args:
2875
- input_x (Tensor): Tensor of any dimension, the data type is float16 or float32.
3267
+ input_x (Tensor): Tensor of any dimension,
3268
+ the data type is int8, int32, float16, float32, or float64 (CPU, GPU only).
2876
3269
 
2877
3270
  Returns:
2878
3271
  Tensor, with the same type and shape as the `input_x`.
2879
3272
 
2880
3273
  Raises:
2881
- TypeError: If dtype of `input_x` is neither float16 nor float32.
3274
+ TypeError: If dtype of `input_x` is not int8, int32, float16, float32, or float64.
2882
3275
 
2883
3276
  Supported Platforms:
2884
3277
  ``Ascend`` ``GPU`` ``CPU``
@@ -2896,41 +3289,6 @@ def selu(input_x):
2896
3289
  return selu_(input_x)
2897
3290
 
2898
3291
 
2899
- def sigmoid(input):
2900
- r"""
2901
- Computes Sigmoid of input element-wise. The Sigmoid function is defined as:
2902
-
2903
- .. math::
2904
-
2905
- \text{sigmoid}(input_i) = \frac{1}{1 + \exp(-input_i)}
2906
-
2907
- where :math:`input_i` is an element of the input.
2908
-
2909
- Args:
2910
- input (Tensor): Tensor of any dimension, the data type is float16, float32, float64, complex64 or complex128.
2911
-
2912
- Returns:
2913
- Tensor, with the same type and shape as the input.
2914
-
2915
- Raises:
2916
- TypeError: If dtype of `input` is not float16, float32, float64, complex64 or complex128.
2917
- TypeError: If `input` is not a Tensor.
2918
-
2919
- Supported Platforms:
2920
- ``Ascend`` ``GPU`` ``CPU``
2921
-
2922
- Examples:
2923
- >>> import mindspore
2924
- >>> import numpy as np
2925
- >>> from mindspore import Tensor, ops
2926
- >>> input = Tensor(np.array([1, 2, 3, 4, 5]), mindspore.float32)
2927
- >>> output = ops.sigmoid(input)
2928
- >>> print(output)
2929
- [0.7310586 0.880797 0.95257413 0.98201376 0.9933072 ]
2930
- """
2931
- return _get_cache_prim(NN_OPS.Sigmoid)()(input)
2932
-
2933
-
2934
3292
  def logsigmoid(x):
2935
3293
  r"""
2936
3294
  Applies logsigmoid activation element-wise. The input is a Tensor with any valid shape.
@@ -2942,6 +3300,11 @@ def logsigmoid(x):
2942
3300
 
2943
3301
  where :math:`x_{i}` is the element of the input.
2944
3302
 
3303
+ LogSigmoid Activation Function Graph:
3304
+
3305
+ .. image:: ../images/LogSigmoid.png
3306
+ :align: center
3307
+
2945
3308
  Args:
2946
3309
  x (Tensor): The input of LogSigmoid with data type of float16 or float32.
2947
3310
  The shape is :math:`(N,*)` where :math:`*` means, any number of additional dimensions.
@@ -2964,63 +3327,11 @@ def logsigmoid(x):
2964
3327
  >>> print(output)
2965
3328
  [-0.31326166 -0.12692806 -0.04858734]
2966
3329
  """
2967
- output = _get_cache_prim(P.Sigmoid)()(x)
2968
- ret = _get_cache_prim(P.Log)()(output)
3330
+ output = sigmoid_(x)
3331
+ ret = log_(output)
2969
3332
  return ret
2970
3333
 
2971
3334
 
2972
- def dense(input, weight, bias=None):
2973
- r"""
2974
- Applies the dense connected operation to the `input`. The dense function is defined as:
2975
-
2976
- .. math::
2977
- output = input * weight^{T} + bias
2978
-
2979
- .. warning::
2980
- This is an experimental API that is subject to change or deletion.
2981
-
2982
- Args:
2983
- input (Tensor): Input Tensor of shape :math:`(*, in\_channels)`,
2984
- where :math:`*` means any number of additional dimensions.
2985
- weight (Tensor): The weight applied to the input.
2986
- The shape is :math:`(out\_channels, in\_channels)` or :math:`(in\_channels)`.
2987
- bias (Tensor, optional): Additive biases to the output.
2988
- The shape is :math:`(out\_channels)` or :math:`()`. Defaults: ``None``, the `bias` is 0.
2989
-
2990
- Returns:
2991
- Output whose shape is determined by the shape of the input and the weight.
2992
-
2993
- Raises:
2994
- TypeError: If `input` is not Tensor.
2995
- TypeError: If `weight` is not Tensor.
2996
- TypeError: If `bias` is not Tensor.
2997
-
2998
- Supported Platforms:
2999
- ``Ascend`` ``GPU`` ``CPU``
3000
-
3001
- Examples:
3002
- >>> import numpy as np
3003
- >>> from mindspore import Tensor, ops
3004
- >>> input = mindspore.Tensor([[-1., 1., 2.], [-3., -3., 1.]], mindspore.float32)
3005
- >>> weight = mindspore.Tensor([[-2., -2., -2.], [0., -1., 0.]], mindspore.float32)
3006
- >>> bias = mindspore.Tensor([0., 1.], mindspore.float32)
3007
- >>> output = mindspore.ops.dense(input, weight, bias)
3008
- >>> print(output)
3009
- [[-4. 0.]
3010
- [10. 4.]]
3011
- """
3012
- _check_is_tensor("input", input, "dense")
3013
- _check_is_tensor("weight", weight, "dense")
3014
- _check_is_tensor("bias", bias, "dense")
3015
- weight = ops.t(weight)
3016
- input = ops.matmul(input, weight)
3017
- input_shape = input.shape
3018
- if bias is not None:
3019
- input = input + bias
3020
- _check_dense_add_bias_shape(input_shape, input.shape, bias.shape)
3021
- return input
3022
-
3023
-
3024
3335
  def _check_dense_add_bias_shape(input_shape, output_shape, bias_shape):
3025
3336
  """Check that the output has the correct shape after adding bias."""
3026
3337
  if input_shape != output_shape:
@@ -3111,14 +3422,15 @@ def bidense(input1, input2, weight, bias=None):
3111
3422
  input1 = input1.reshape((-1, input1_shape[-1]))
3112
3423
  input2 = input2.reshape((-1, input2_shape[-1]))
3113
3424
  batch_size = input1.shape[0]
3114
- matmul_ = P.MatMul()
3115
3425
  output = matmul_(input1, weight.transpose(1, 2, 0).view(input1_shape[-1], -1))
3116
3426
  output = output.view(batch_size, input2_shape[-1], weight.shape[0])
3117
3427
  output = output.transpose(2, 0, 1) * input2
3118
3428
  output = output.sum(2).swapaxes(0, 1)
3119
3429
  if bias is not None:
3120
- bias_add_ = P.BiasAdd()
3121
- output = bias_add_(output, bias)
3430
+ if input1.dtype != bias.dtype or input2.dtype != bias.dtype:
3431
+ raise TypeError(f"For 'bidense', the dtype of 'bias', 'input1' and 'input2' must be the same,"
3432
+ f" but got {bias.dtype}, {input1.dtype} and {input2.dtype}.")
3433
+ output = bias_add_(output.astype(bias.dtype), bias)
3122
3434
  if len(input1_shape) != 2:
3123
3435
  output_shape = input1_shape[:-1] + (-1,)
3124
3436
  output = output.reshape(output_shape)
@@ -3187,7 +3499,7 @@ def deformable_conv2d(x, weight, offsets, kernel_size, strides, padding, bias=No
3187
3499
  TypeError: If `strides`, `padding`, `kernel_size` or `dilations` is not a tuple with integer elements.
3188
3500
  TypeError: If `modulated` is not a bool.
3189
3501
  ValueError: If the tuple size of `strides`, `padding`, `kernel_size` or `dilations` is not expected.
3190
- ValueError: The N or C dimensions of 'strides' or `dilations` is not set to 1.
3502
+ ValueError: The N or C dimensions of `strides` or `dilations` is not set to 1.
3191
3503
  ValueError: If `modulated` is not set to True.
3192
3504
 
3193
3505
  .. warning::
@@ -3212,13 +3524,10 @@ def deformable_conv2d(x, weight, offsets, kernel_size, strides, padding, bias=No
3212
3524
  deformable_groups,
3213
3525
  modulated)
3214
3526
  fm_offset = deformable_offsets(x, offsets)
3215
-
3216
3527
  weight_shape = weight.shape
3217
3528
  out_channel = weight_shape[0]
3218
3529
  strides_conv = (kernel_size[0], kernel_size[1])
3219
3530
  conv = _get_cache_prim(P.Conv2D)(out_channel, kernel_size, 1, "valid", 0, strides_conv, 1, groups)
3220
- bias_add_ = _get_cache_prim(P.BiasAdd)()
3221
-
3222
3531
  output = conv(fm_offset, weight)
3223
3532
  if bias is not None:
3224
3533
  output = bias_add_(output, bias)
@@ -3229,9 +3538,7 @@ def pdist(input, p=2.0):
3229
3538
  r"""
3230
3539
  Calculates the distance between every pair of row vectors in
3231
3540
  the input using the p-norm. If the input `input` is a 2D Tensor with shape :math:`(N, M)`,
3232
- the `output` must be a 1D Tensor with shape :math:`(N * (N - 1) / 2,)`. If `input` has batch
3233
- dimension with shape :math:`(*B, N, M)`, then the `output` must be a Tensor with
3234
- shape :math:`(*B, N * (N - 1) / 2)`.
3541
+ the `output` must be a 1D Tensor with shape :math:`(N * (N - 1) / 2,)`.
3235
3542
 
3236
3543
  .. math::
3237
3544
  y[n] = \sqrt[p]{{\mid x_{i} - x_{j} \mid}^p}
@@ -3239,8 +3546,7 @@ def pdist(input, p=2.0):
3239
3546
  where :math:`x_{i}, x_{j}` are two different row vectors in the input.
3240
3547
 
3241
3548
  Args:
3242
- input (Tensor): Input tensor of shape :math:`(*B, N, M)`. :math:`*B` is batch size, one-dim or multi-dim.
3243
- dtype: float16, float32 or float64.
3549
+ input (Tensor): Input tensor. dtype: float16, float32 or float64.
3244
3550
  p (float): The order of norm distance, :math:`p∈[0, ∞)`. Default: ``2.0`` .
3245
3551
 
3246
3552
  Returns:
@@ -3268,7 +3574,144 @@ def pdist(input, p=2.0):
3268
3574
  return pdist_(input)
3269
3575
 
3270
3576
 
3271
- @_primexpr
3577
+ def _circular_pad(input_x, padding):
3578
+ """circular pad"""
3579
+ if isinstance(padding, tuple):
3580
+ padding = tuple_to_tensor_(padding, mstype.int64)
3581
+ elif isinstance(padding, list):
3582
+ padding = list_to_tensor_(padding, mstype.int64)
3583
+ is_expand = False
3584
+ if padding.shape[0] // 2 + 1 == input_x.ndim:
3585
+ input_x = input_x.expand_dims(0)
3586
+ is_expand = True
3587
+ out = PadV3(mode="circular", paddings_contiguous=True)(input_x, padding, None)
3588
+ if is_expand:
3589
+ out = out.squeeze(0)
3590
+ return out
3591
+
3592
+
3593
+ def _reflection_pad(input, pad):
3594
+ """reflection pad"""
3595
+ out = input
3596
+ if len(pad) == 2:
3597
+ out = reflection_pad_1d_op(input, pad)
3598
+ elif len(pad) == 4:
3599
+ out = reflection_pad_2d_op(input, pad)
3600
+ else:
3601
+ out = reflection_pad_3d_op(input, pad)
3602
+ return out
3603
+
3604
+
3605
+ def _replication_pad(input, pad):
3606
+ """replication pad"""
3607
+ out = input
3608
+ if len(pad) == 2:
3609
+ out = replication_pad_1d_op(input, pad)
3610
+ elif len(pad) == 4:
3611
+ out = replication_pad_2d_op(input, pad)
3612
+ else:
3613
+ out = replication_pad_3d_op(input, pad)
3614
+ return out
3615
+
3616
+
3617
+ def pad_ext(input, pad, mode='constant', value=0.0):
3618
+ r"""
3619
+ Pads the input tensor according to the pad.
3620
+
3621
+ .. warning::
3622
+ `circular` mode has poor performance and is not recommended.
3623
+
3624
+ Args:
3625
+ input (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of additional dimensions.
3626
+ pad (Union[tuple[int], list[int], Tensor]): Filling position of pad.
3627
+ :math:`\left\lfloor\frac{\text{len(pad)}}{2}\right\rfloor` dimensions
3628
+ of `input` will be padded.
3629
+
3630
+ Example: to pad only the last dimension of the input tensor, then
3631
+ :attr:`pad` has the form
3632
+ :math:`(\text{padding_left}, \text{padding_right})`;
3633
+
3634
+ Example: to pad the last 2 dimensions of the input tensor, then use
3635
+ :math:`(\text{padding_left}, \text{padding_right}, \text{padding_top}, \text{padding_bottom})`;
3636
+
3637
+ Example: to pad the last 3 dimensions, use
3638
+ :math:`(\text{padding_left}, \text{padding_right}, \text{padding_top}, \text{padding_bottom},
3639
+ \text{padding_front}, \text{padding_back})` and so on.
3640
+
3641
+ mode (str, optional): Pad filling mode, ``'constant'`` , ``'reflect'`` , ``'replicate'`` or ``'circular'`` .
3642
+ Default: ``'constant'`` .
3643
+
3644
+ For ``'constant'`` mode, please refer to :class:`mindspore.nn.ConstantPad1d` as an example to understand
3645
+ this filling pattern and extend the padding pattern to n dimensions.
3646
+
3647
+ For ``'reflect'`` mode, please refer to :class:`mindspore.nn.ReflectionPad1d` as an example to understand
3648
+ this filling pattern.
3649
+ The reflect mode is used to pad the last three dimensions of 4D or 5D input, the last two dimensions of 3D
3650
+ or 4D input, or the last dimension of 2D or 3D input.
3651
+
3652
+ For ``'replicate'`` mode, please refer to :class:`mindspore.nn.ReplicationPad1d` as an example to understand
3653
+ this filling pattern.
3654
+ The replicate mode is used to pad the last three dimensions of 4D or 5D input, the last two dimensions of 3D
3655
+ or 4D input, or the last dimension of 2D or 3D input.
3656
+
3657
+ For ``'circular'`` mode, the pixels from one edge of the image are wrapped around to the opposite edge,
3658
+ such that the pixel on the right edge of the image is replaced with the pixel on the left edge,
3659
+ and the pixel on the bottom edge is replaced with the pixel on the top edge.
3660
+ The circular mode is used to pad the last three dimensions of 4D or 5D input, the last two dimensions of 3D
3661
+ or 4D input, or the last dimension of 2D or 3D input.
3662
+
3663
+ value (Union[int, float, None], optional): Valid only in ``'constant'`` mode.
3664
+ Set the padding value in ``'constant'`` mode. If the value is None, 0 is used as the default padding value.
3665
+ Default: ``0.0`` .
3666
+
3667
+ Returns:
3668
+ Tensor, the tensor after padding.
3669
+
3670
+ Raises:
3671
+ TypeError: If `pad` is not an int of tuple or int of list.
3672
+ TypeError: If `input` is not a Tensor.
3673
+ ValueError: If length of `pad` is not even.
3674
+ ValueError: If length of `pad` is greater than 6.
3675
+ ValueError: If `mode` is not ``'constant'`` and `value` not ``None``.
3676
+
3677
+ Supported Platforms:
3678
+ ``Ascend``
3679
+
3680
+ Examples:
3681
+ >>> from mindspore import ops
3682
+ >>> import numpy as np
3683
+ >>> x = ms.Tensor(np.arange(1 * 2 * 2 * 2).reshape((1, 2, 2, 2)), dtype=ms.float64)
3684
+ >>> output = ops.function.nn_func.pad_ext(x, [1, 0, 0, 1], mode='constant', value=6.0)
3685
+ >>> print(output)
3686
+ [[[[6. 0. 1.]
3687
+ [6. 2. 3.]
3688
+ [6. 6. 6.]]
3689
+ [[6. 4. 5.]
3690
+ [6. 6. 7.]
3691
+ [6. 6. 6.]]]]
3692
+ """
3693
+ if not isinstance(input, Tensor):
3694
+ raise TypeError(f"For 'pad', the type of 'input' must be Tensor, but got {type(input)}.")
3695
+ out = input
3696
+ if (isinstance(pad, tuple) and not pad):
3697
+ return out
3698
+ if mode == "constant":
3699
+ value = 0 if value is None else value
3700
+ out = constant_pad_nd_op(input, pad, value)
3701
+ else:
3702
+ if value != 0.0:
3703
+ raise ValueError(f"Padding mode {mode} doesn\'t take in value argument.")
3704
+ if mode == "circular":
3705
+ out = _circular_pad(input, pad)
3706
+ elif mode == "reflect":
3707
+ out = _reflection_pad(input, pad)
3708
+ elif mode == "replicate":
3709
+ out = _replication_pad(input, pad)
3710
+ else:
3711
+ raise ValueError(f"Pad filling mode must be 'constant' 'circular' 'reflect' or 'replicate'.")
3712
+ return out
3713
+
3714
+
3272
3715
  def _check_pad_inputs(padding):
3273
3716
  """check the input of pad"""
3274
3717
  if len(padding) % 2 != 0:
@@ -3286,8 +3729,10 @@ def pad(input_x, padding, mode='constant', value=None):
3286
3729
  Pads the input tensor according to the padding.
3287
3730
 
3288
3731
  Args:
3289
- input_x (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of additional dimensions.
3290
- padding (Union[tuple[int], list[int], Tensor]): Filling position of pad.
3732
+ input_x (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of additional dimensions
3733
+ which is required to be no more than 5 in Ascend.
3734
+ padding (Union[tuple[int], list[int], Tensor]): Filling position of pad where the negative value is not
3735
+ supported while running in Ascend.
3291
3736
  :math:`\left\lfloor\frac{\text{len(padding)}}{2}\right\rfloor` dimensions
3292
3737
  of `input_x` will be padded.
3293
3738
 
@@ -3296,56 +3741,56 @@ def pad(input_x, padding, mode='constant', value=None):
3296
3741
  :math:`(\text{padding_left}, \text{padding_right})`;
3297
3742
 
3298
3743
  Example: to pad the last 2 dimensions of the input tensor, then use
3299
- :math:`(\text{padding_left}, \text{padding_right}`,
3300
- :math:`\text{padding_top}, \text{padding_bottom})`;
3744
+ :math:`(\text{padding_left}, \text{padding_right}, \text{padding_top}, \text{padding_bottom})`;
3301
3745
 
3302
3746
  Example: to pad the last 3 dimensions, use
3303
- :math:`(\text{padding_left}, \text{padding_right}`,
3304
- :math:`\text{padding_top}, \text{padding_bottom}`,
3305
- :math:`\text{padding_front}, \text{padding_back})` and so on.
3747
+ :math:`(\text{padding_left}, \text{padding_right}, \text{padding_top}, \text{padding_bottom},
3748
+ \text{padding_front}, \text{padding_back})` and so on.
3306
3749
 
3307
- mode (str, optional): Pad filling mode, ``"constant"`` , ``"reflect"`` , ``"replicate"`` or ``"circular"`` .
3750
+ mode (str, optional): Pad filling mode, ``'constant'`` , ``'reflect'`` , ``'replicate'`` or ``'circular'`` .
3308
3751
  Default: ``'constant'`` .
3309
3752
 
3310
- For "constant" mode, please refer to :class:`mindspore.nn.ConstantPad1d` as an example to understand
3753
+ For ``'constant'`` mode, please refer to :class:`mindspore.nn.ConstantPad1d` as an example to understand
3311
3754
  this filling pattern and extend the padding pattern to n dimensions.
3312
3755
 
3313
- For "reflect" mode, please refer to :class:`mindspore.nn.ReflectionPad1d` as an example to understand
3756
+ For ``'reflect'`` mode, please refer to :class:`mindspore.nn.ReflectionPad1d` as an example to understand
3314
3757
  this filling pattern.
3315
3758
  The reflect mode is used to pad the last two dimensions of 3D or 4D input, or the last dimension of 2D or
3316
3759
  3D input.
3317
3760
 
3318
- For "replicate" mode, please refer to :class:`mindspore.nn.ReplicationPad1d` as an example to understand
3761
+ For ``'replicate'`` mode, please refer to :class:`mindspore.nn.ReplicationPad1d` as an example to understand
3319
3762
  this filling pattern.
3320
3763
  The replicate mode is used to pad the last three dimensions of 4D or 5D input, the last two dimensions of 3D
3321
3764
  or 4D input, or the last dimension of 2D or 3D input.
3322
3765
 
3323
- For "circular" mode, the pixels from one edge of the image are wrapped around to the opposite edge,
3766
+ For ``'circular'`` mode, the pixels from one edge of the image are wrapped around to the opposite edge,
3324
3767
  such that the pixel on the right edge of the image is replaced with the pixel on the left edge,
3325
3768
  and the pixel on the bottom edge is replaced with the pixel on the top edge.
3326
3769
  The circular mode is used to pad the last three dimensions of 4D or 5D input, the last two dimensions of 3D
3327
3770
  or 4D input, or the last dimension of 2D or 3D input.
3328
3771
 
3329
- value (Union[int, float, None], optional): Valid only in "constant" mode.
3330
- Set the padding value in "constant" mode. If the value is None, 0 is used as the default padding value.
3772
+ value (Union[int, float, None], optional): Valid only in ``'constant'`` mode.
3773
+ Set the padding value in ``'constant'`` mode. If the value is None, 0 is used as the default padding value.
3331
3774
  Default: ``None`` .
3332
3775
 
3333
3776
  Returns:
3334
3777
  Tensor, the tensor after padding.
3335
3778
 
3336
3779
  Raises:
3337
- TypeError: If `paddings` is not an int of tuple or int of list.
3780
+ TypeError: If `padding` is not an int of tuple or int of list.
3338
3781
  TypeError: If `input_x` is not a Tensor.
3339
3782
  ValueError: If length of `padding` is not even.
3340
3783
  ValueError: If length of `padding` is greater than 6.
3341
- ValueError: If mode is not "constant" and value not None.
3784
+ ValueError: If `mode` is not ``'constant'`` and `value` not ``None``.
3785
+ ValueError: If rank of `input_x` is more than 5 while running in Ascend.
3786
+ ValueError: If `paddings` contains negative value while running in Ascend.
3342
3787
 
3343
3788
  Supported Platforms:
3344
3789
  ``Ascend`` ``GPU`` ``CPU``
3345
3790
 
3346
3791
  Examples:
3347
3792
  >>> import mindspore as ms
3348
- >>> import mindspore.ops as ops
3793
+ >>> from mindspore import ops
3349
3794
  >>> import numpy as np
3350
3795
  >>> x = ms.Tensor(np.arange(1 * 2 * 2 * 2).reshape((1, 2, 2, 2)), dtype=ms.float64)
3351
3796
  >>> output = ops.pad(x, [1, 0, 0, 1], mode='constant', value=6.0)
@@ -3395,7 +3840,7 @@ def pad(input_x, padding, mode='constant', value=None):
3395
3840
  return input_x
3396
3841
  if not isinstance(padding, Tensor):
3397
3842
  _check_pad_inputs(padding)
3398
- padding = Tensor(padding)
3843
+ padding = tuple(padding)
3399
3844
  is_expand = False
3400
3845
  if mode == "constant":
3401
3846
  value = 0 if value is None else value
@@ -3408,7 +3853,7 @@ def pad(input_x, padding, mode='constant', value=None):
3408
3853
  raise ValueError(f"For 'pad', the padding mode '{mode}' can not set value, but got value {value}.")
3409
3854
  if mode == "replicate":
3410
3855
  mode = "edge"
3411
- if padding.shape[0] // 2 + 1 == input_x.ndim:
3856
+ if len(padding) // 2 + 1 == input_x.ndim:
3412
3857
  input_x = input_x.expand_dims(0)
3413
3858
  is_expand = True
3414
3859
  out = PadV3(mode=mode, paddings_contiguous=True)(input_x, padding, value)
@@ -3417,142 +3862,6 @@ def pad(input_x, padding, mode='constant', value=None):
3417
3862
  return out
3418
3863
 
3419
3864
 
3420
- def relu(input):
3421
- r"""
3422
- Computes ReLU (Rectified Linear Unit activation function) of input tensors element-wise.
3423
-
3424
- It returns :math:`\max(input,\ 0)` element-wise. Specially, the neurons with the negative output
3425
- will be suppressed and the active neurons will stay the same.
3426
-
3427
- .. math::
3428
-
3429
- ReLU(input) = (input)^+ = \max(0, input)
3430
-
3431
- Note:
3432
- In general, this operator is more commonly used. The difference from `ReLuV2` is that the `ReLuV2` will
3433
- output one more Mask.
3434
-
3435
- Args:
3436
- input (Tensor): Input Tensor of numeric types.
3437
-
3438
- Returns:
3439
- Tensor, has the same dtype and shape as `input_x`.
3440
-
3441
- Raises:
3442
- TypeError: If dtype of `input` is not a number.
3443
- TypeError: If `input` is not a Tensor.
3444
-
3445
- Supported Platforms:
3446
- ``Ascend`` ``GPU`` ``CPU``
3447
-
3448
- Examples:
3449
- >>> import mindspore
3450
- >>> import numpy as np
3451
- >>> from mindspore import Tensor, ops
3452
- >>> input_x = Tensor(np.array([[-1.0, 4.0, -8.0], [2.0, -5.0, 9.0]]), mindspore.float32)
3453
- >>> output = ops.relu(input_x)
3454
- >>> print(output)
3455
- [[0. 4. 0.]
3456
- [2. 0. 9.]]
3457
- """
3458
- relu_ = _get_cache_prim(NN_OPS.ReLU)()
3459
- return relu_(input)
3460
-
3461
-
3462
- def relu6(x):
3463
- r"""
3464
- Computes ReLU (Rectified Linear Unit) upper bounded by 6 of input tensors element-wise.
3465
-
3466
- .. math::
3467
-
3468
- \text{ReLU6}(x) = \min(\max(0,x), 6)
3469
-
3470
- It returns :math:`\min(\max(0,x), 6)` element-wise.
3471
-
3472
- Args:
3473
- x (Tensor): Tensor of shape :math:`(N, *)`,
3474
- where :math:`*` means any number of additional dimensions.
3475
- Data type must be float16, float32.
3476
-
3477
- Returns:
3478
- Tensor, with the same dtype and shape as the `x`.
3479
-
3480
- Raises:
3481
- TypeError: If dtype of `x` is neither float16 nor float32.
3482
- TypeError: If `x` is not a Tensor.
3483
-
3484
- Supported Platforms:
3485
- ``Ascend`` ``GPU`` ``CPU``
3486
-
3487
- Examples:
3488
- >>> import mindspore
3489
- >>> import numpy as np
3490
- >>> from mindspore import Tensor, ops
3491
- >>> input_x = Tensor(np.array([[-1.0, 4.0, -8.0], [2.0, -5.0, 9.0]]), mindspore.float32)
3492
- >>> result = ops.relu6(input_x)
3493
- >>> print(result)
3494
- [[0. 4. 0.]
3495
- [2. 0. 6.]]
3496
- """
3497
- relu6_ = _get_cache_prim(NN_OPS.ReLU6)()
3498
- return relu6_(x)
3499
-
3500
-
3501
- def prelu(x, weight):
3502
- r"""
3503
- Parametric Rectified Linear Unit activation function.
3504
-
3505
- PReLU is described in the paper `Delving Deep into Rectifiers: Surpassing Human-Level Performance on
3506
- ImageNet Classification <https://arxiv.org/abs/1502.01852>`_. Defined as follows:
3507
-
3508
- .. math::
3509
- prelu(x_i)= \max(0, x_i) + \min(0, w * x_i),
3510
-
3511
- where :math:`x_i` is an element of a channel of the input, `w` is the weight of the channel.
3512
-
3513
- Note:
3514
- Scalar or 1-D Tensor is not supported on Ascend.
3515
-
3516
- Args:
3517
- x (Tensor): The input Tensor of the activation function. The data type is float16 or float32.
3518
- The shape is :math:`(N, *)` where :math:`*` means, any number of additional dimensions.
3519
- weight (Tensor): Weight Tensor. The data type is float16 or float32.
3520
- The weight can only be a Tensor, and the length is the same as the number of channels C of the `input_x`.
3521
- On GPU devices, when the input is a scalar, the shape is :math:`(1,)` .
3522
-
3523
- Returns:
3524
- Tensor, with the same shape and dtype as `x`.
3525
-
3526
- For detailed information, please refer to :class:`mindspore.nn.PReLU`.
3527
-
3528
- Raises:
3529
- TypeError: If dtype of `x` or `weight` is neither float16 nor float32.
3530
- TypeError: If the `x` or the `weight` is not a Tensor.
3531
- ValueError: If the `x` is a 0-D or 1-D Tensor on Ascend.
3532
- ValueError: If the `weight` is not a 1-D Tensor.
3533
-
3534
- Supported Platforms:
3535
- ``Ascend`` ``GPU`` ``CPU``
3536
-
3537
- Examples:
3538
- >>> import mindspore
3539
- >>> import numpy as np
3540
- >>> from mindspore import Tensor, ops
3541
- >>> x = Tensor(np.arange(-6, 6).reshape((2, 3, 2)), mindspore.float32)
3542
- >>> weight = Tensor(np.array([0.1, 0.6, -0.3]), mindspore.float32)
3543
- >>> output = ops.prelu(x, weight)
3544
- >>> print(output)
3545
- [[[-0.60 -0.50]
3546
- [-2.40 -1.80]
3547
- [ 0.60 0.30]]
3548
- [[ 0.00 1.00]
3549
- [ 2.00 3.00]
3550
- [ 4.0 5.00]]]
3551
- """
3552
- prelu_ = _get_cache_prim(NN_OPS.PReLU)()
3553
- return prelu_(x, weight)
3554
-
3555
-
3556
3865
  def rrelu(input, lower=1.0 / 8, upper=1.0 / 3):
3557
3866
  r"""
3558
3867
 
@@ -3581,7 +3890,7 @@ def rrelu(input, lower=1.0 / 8, upper=1.0 / 3):
3581
3890
  TypeError: If `lower` is not a float or an int.
3582
3891
  TypeError: If `upper` is not a float or an int.
3583
3892
  TypeError: If `input` is not a Tensor.
3584
- TypeError: If `input` is not a Tensor of mindspore.float16 or mindpore.float32.
3893
+ TypeError: If `input` is not a Tensor of mindspore.float16 or mindspore.float32.
3585
3894
  ValueError: If `lower` is greater than upper.
3586
3895
 
3587
3896
  Supported Platforms:
@@ -3610,13 +3919,12 @@ def rrelu(input, lower=1.0 / 8, upper=1.0 / 3):
3610
3919
  _upper = Tensor(upper, mstype.float32)
3611
3920
  _size = input.shape
3612
3921
  if ops.is_sequence_value_unknown(_size):
3613
- dyn_shape = _get_cache_prim(P.TensorShape)()
3614
- _size = dyn_shape(input)
3615
- sign_matrix = _get_cache_prim(P.Sign)()(input)
3922
+ _size = tensor_shape_(input)
3923
+ sign_matrix = sign_(input)
3616
3924
  negative_filter = sign_matrix.clip(None, 0)
3617
3925
  positive_filter = sign_matrix.clip(0, None)
3618
- _dtype = _get_cache_prim(P.DType)()(input)
3619
- mask = ops.uniform(_size, _lower, _upper).astype(_dtype)
3926
+ input_dtype = dtype_(input)
3927
+ mask = ops.uniform(_size, _lower, _upper).astype(input_dtype)
3620
3928
  negative_mask = negative_filter * mask * -1
3621
3929
  total_mask = negative_mask + positive_filter
3622
3930
  out = total_mask * input
@@ -3684,6 +3992,21 @@ def _innner_log_softmax(inputs, axis):
3684
3992
  return inputs - logsumexp(inputs, axis, True)
3685
3993
 
3686
3994
 
3995
+ def _check_cross_entropy_inputs(input, target, weight, ignore_index, reduction, label_smoothing):
3996
+ """
3997
+ Check inputs for cross_entropy().
3998
+ """
3999
+ _check_is_tensor('input', input, "cross_entropy_loss")
4000
+ _check_is_tensor('target', target, "cross_entropy_loss")
4001
+ _check_is_tensor('weight', weight, "cross_entropy_loss")
4002
+ check_int_const(ignore_index, 'ignore_index', "cross_entropy_loss")
4003
+ check_non_negative_float_const(label_smoothing, 'label_smoothing', "cross_entropy_loss")
4004
+ check_string_const(reduction, ['none', 'mean', 'sum'], 'reduction', "cross_entropy_loss")
4005
+ if input.dtype not in [mstype.float64, mstype.float32, mstype.float16]:
4006
+ raise TypeError(f'For cross_entropy, the input dtype should be mstype.float64, mstype.float32 or'
4007
+ f'mstype.float16, but got dtype:{input.dtype}.')
4008
+
4009
+
3687
4010
  def cross_entropy(input, target, weight=None, ignore_index=-100, reduction='mean', label_smoothing=0.0):
3688
4011
  r"""
3689
4012
  The cross entropy loss between input and target.
@@ -3741,7 +4064,7 @@ def cross_entropy(input, target, weight=None, ignore_index=-100, reduction='mean
3741
4064
  `input` is expected to be log-probabilities, data type must be float16 or float32.
3742
4065
  target (Tensor): For class indices, tensor of shape :math:`()`, :math:`(N)` or
3743
4066
  :math:`(N, d_1, d_2, ..., d_K)` , data type must be int32. For probabilities, tensor of shape :math:`(C,)` ,
3744
- :math:`(N, C)` or :math:`(N, C, d_1, d_2, ..., d_K)` , data type must be float16 or float32.
4067
+ :math:`(N, C)` or :math:`(N, C, d_1, d_2, ..., d_K)` , data type must be float16 or float32 or float64.
3745
4068
  weight (Tensor): A rescaling weight applied to the loss of each batch element.
3746
4069
  If not None, the shape is :math:`(C,)`, data type must be float16 or float32. Default: ``None`` .
3747
4070
  ignore_index (int): Specifies a target value that is ignored
@@ -3774,12 +4097,7 @@ def cross_entropy(input, target, weight=None, ignore_index=-100, reduction='mean
3774
4097
  >>> target = ms.Tensor(np.random.randn(3, 5), ms.float32)
3775
4098
  >>> output = ms.ops.cross_entropy(inputs, target)
3776
4099
  """
3777
- _check_is_tensor('input', input, "cross_entropy_loss")
3778
- _check_is_tensor('target', target, "cross_entropy_loss")
3779
- _check_is_tensor('weight', weight, "cross_entropy_loss")
3780
- check_int_const(ignore_index, 'ignore_index', "cross_entropy_loss")
3781
- check_non_negative_float_const(label_smoothing, 'label_smoothing', "cross_entropy_loss")
3782
- check_string_const(reduction, ['none', 'mean', 'sum'], 'reduction', "cross_entropy_loss")
4100
+ _check_cross_entropy_inputs(input, target, weight, ignore_index, reduction, label_smoothing)
3783
4101
  class_dim = 0 if input.ndim == 1 else 1
3784
4102
  if target.dtype in [mstype.float32, mstype.float16]:
3785
4103
  return _cross_entropy(input, target, class_dim, weight, reduction, label_smoothing)
@@ -3788,8 +4106,6 @@ def cross_entropy(input, target, weight=None, ignore_index=-100, reduction='mean
3788
4106
 
3789
4107
  def _cross_entropy(inputs, target, target_dim, weight=None, reduction='mean', label_smoothing=0.0):
3790
4108
  """cross entropy inner function"""
3791
- _ones_like = _get_cache_prim(P.OnesLike)()
3792
-
3793
4109
  class_dim = 0 if inputs.ndim == 1 else 1
3794
4110
  n_classes = inputs.shape[class_dim]
3795
4111
  inputs = _innner_log_softmax(inputs, class_dim)
@@ -3797,7 +4113,7 @@ def _cross_entropy(inputs, target, target_dim, weight=None, reduction='mean', la
3797
4113
  target = target * (1 - label_smoothing) + label_smoothing / n_classes
3798
4114
 
3799
4115
  if weight is None:
3800
- weight = _ones_like(inputs)
4116
+ weight = ones_like_(inputs)
3801
4117
  elif inputs.ndim != 1:
3802
4118
  broadcast_shape = [1 for _ in range(inputs.ndim)]
3803
4119
  broadcast_shape[1] = weight.shape[0]
@@ -3827,7 +4143,7 @@ def nll_loss(inputs, target, weight=None, ignore_index=-100, reduction='mean', l
3827
4143
  N is the batch size, :math:`c` belonging to :math:`[0, C-1]` is class index, where :math:`C` is the number of
3828
4144
  classes.
3829
4145
 
3830
- If `reduction` is not ``None`` (default 'mean'), then
4146
+ If `reduction` is not ``None`` (default ``'mean'``), then
3831
4147
 
3832
4148
  .. math::
3833
4149
 
@@ -3895,37 +4211,31 @@ def nll_loss(inputs, target, weight=None, ignore_index=-100, reduction='mean', l
3895
4211
 
3896
4212
  def _nll_loss(inputs, target, target_dim=-1, weight=None, ignore_index=None, reduction='none', label_smoothing=0.0):
3897
4213
  """nll loss inner function"""
3898
- _neg = _get_cache_prim(P.Neg)()
3899
- _gather_d = _get_cache_prim(P.GatherD)()
3900
- _gather = _get_cache_prim(P.Gather)()
3901
- _ones_like = _get_cache_prim(P.OnesLike)()
3902
- _equal = _get_cache_prim(P.Equal)()
3903
-
3904
4214
  if target.ndim == inputs.ndim - 1:
3905
4215
  target = target.expand_dims(target_dim)
3906
4216
  if ignore_index is not None:
3907
- non_pad_mask = _equal(target, ignore_index)
3908
- target = target.masked_fill(non_pad_mask, 0)
4217
+ non_pad_mask = equal_(target, ignore_index)
4218
+ target = target.masked_fill(non_pad_mask, ops.cast(0, target.dtype))
3909
4219
  else:
3910
4220
  non_pad_mask = target
3911
4221
  if weight is not None:
3912
- loss_weights = _gather(weight, target, 0)
4222
+ loss_weights = gather_(weight, target, 0)
3913
4223
  orig_shape = inputs.shape
3914
4224
  if inputs.ndim != 2:
3915
4225
  inputs = inputs.view(orig_shape[:2] + (-1,))
3916
4226
  weight = weight.view(weight.shape + (1,))
3917
4227
  weighted_inputs = inputs * weight
3918
4228
  weighted_inputs = weighted_inputs.view(orig_shape)
3919
- loss = _neg(_gather_d(weighted_inputs, target_dim, target))
3920
- smooth_loss = _neg(weighted_inputs.sum(axis=target_dim, keepdims=True))
4229
+ loss = neg_(gather_d_(weighted_inputs, target_dim, target))
4230
+ smooth_loss = neg_(weighted_inputs.sum(axis=target_dim, keepdims=True))
3921
4231
  else:
3922
- loss = _neg(_gather_d(inputs, target_dim, target))
3923
- smooth_loss = _neg(inputs.sum(axis=target_dim, keepdims=True))
3924
- loss_weights = _ones_like(loss)
4232
+ loss = neg_(gather_d_(inputs, target_dim, target))
4233
+ smooth_loss = neg_(inputs.sum(axis=target_dim, keepdims=True))
4234
+ loss_weights = ones_like_(loss)
3925
4235
  if ignore_index is not None:
3926
- loss = loss.masked_fill(non_pad_mask, 0.)
3927
- loss_weights = loss_weights.masked_fill(non_pad_mask, 0.)
3928
- smooth_loss = smooth_loss.masked_fill(non_pad_mask, 0.)
4236
+ loss = loss.masked_fill(non_pad_mask, ops.cast(0, loss.dtype))
4237
+ loss_weights = loss_weights.masked_fill(non_pad_mask, ops.cast(0, loss_weights.dtype))
4238
+ smooth_loss = smooth_loss.masked_fill(non_pad_mask, ops.cast(0, smooth_loss.dtype))
3929
4239
 
3930
4240
  loss = loss.squeeze(target_dim)
3931
4241
  smooth_loss = smooth_loss.squeeze(target_dim)
@@ -3947,8 +4257,9 @@ def l1_loss(input, target, reduction='mean'):
3947
4257
  r"""
3948
4258
  Calculate the mean absolute error between the `input` value and the `target` value.
3949
4259
 
3950
- Assuming that the :math:`x` and :math:`y` are 1-D Tensor, length :math:`N`, `reduction` is set to ``"none"``,
3951
- then calculate the loss of :math:`x` and :math:`y` without dimensionality reduction.
4260
+ Assuming that the :math:`x` and :math:`y` (predicted and target value) are 1-D Tensor,
4261
+ length :math:`N`, `reduction` is set to ``'none'``, then calculate the loss of
4262
+ :math:`x` and :math:`y` without dimensionality reduction.
3952
4263
 
3953
4264
  The formula is as follows:
3954
4265
 
@@ -3957,7 +4268,7 @@ def l1_loss(input, target, reduction='mean'):
3957
4268
 
3958
4269
  where :math:`N` is the batch size.
3959
4270
 
3960
- If `reduction` is ``"mean"`` or ``"sum"`` , then:
4271
+ If `reduction` is ``'mean'`` or ``'sum'`` , then:
3961
4272
 
3962
4273
  .. math::
3963
4274
  \ell(x, y) =
@@ -3978,13 +4289,13 @@ def l1_loss(input, target, reduction='mean'):
3978
4289
  - ``'sum'``: the output elements will be summed.
3979
4290
 
3980
4291
  Returns:
3981
- Tensor or Scalar, if `reduction` is ``"none"``, return a Tensor with same shape and dtype as `input`.
4292
+ Tensor or Scalar, if `reduction` is ``'none'``, return a Tensor with same shape and dtype as `input`.
3982
4293
  Otherwise, a scalar value will be returned.
3983
4294
 
3984
4295
  Raises:
3985
4296
  TypeError: If `input` is not a Tensor.
3986
4297
  TypeError: If `target` is not a Tensor.
3987
- ValueError: If `reduction` is not one of ``"none"``, ``"mean"`` or ``"sum"``.
4298
+ ValueError: If `reduction` is not one of ``'none'``, ``'mean'`` or ``'sum'``.
3988
4299
 
3989
4300
  Supported Platforms:
3990
4301
  ``Ascend`` ``GPU`` ``CPU``
@@ -3992,8 +4303,8 @@ def l1_loss(input, target, reduction='mean'):
3992
4303
  Examples:
3993
4304
  >>> from mindspore import Tensor, ops
3994
4305
  >>> from mindspore import dtype as mstype
3995
- >>> x = ms.Tensor([[1, 2, 3], [4, 5, 6]], mstype.float32)
3996
- >>> target = ms.Tensor([[6, 5, 4], [3, 2, 1]], mstype.float32)
4306
+ >>> x = Tensor([[1, 2, 3], [4, 5, 6]], mstype.float32)
4307
+ >>> target = Tensor([[6, 5, 4], [3, 2, 1]], mstype.float32)
3997
4308
  >>> output = ops.l1_loss(x, target, reduction="mean")
3998
4309
  >>> print(output)
3999
4310
  3.0
@@ -4002,7 +4313,7 @@ def l1_loss(input, target, reduction='mean'):
4002
4313
  _check_is_tensor('target', target, "l1_loss")
4003
4314
  if reduction not in ('mean', 'sum', 'none'):
4004
4315
  raise ValueError(f"For l1_loss, the 'reduction' must be in ['mean', 'sum', 'none'], but got {reduction}.")
4005
- loss = _get_cache_prim(P.Abs)()(input - target)
4316
+ loss = abs_(input - target)
4006
4317
  return _get_loss(loss, reduction, "l1_loss")
4007
4318
 
4008
4319
 
@@ -4037,6 +4348,7 @@ def smooth_l1_loss(input, target, beta=1.0, reduction='none'):
4037
4348
 
4038
4349
  Args:
4039
4350
  input (Tensor): Tensor of shape :math:`(N, *)` where :math:`*` means, any number of additional dimensions.
4351
+ Data type is float16, float32 or float64.
4040
4352
  target (Tensor): Ground truth data, tensor of shape :math:`(N, *)`, same shape and dtype as the `input`.
4041
4353
  beta (float): A parameter used to control the point where the function will change between
4042
4354
  L1 to L2 loss. The value should be greater than zero. Default: ``1.0`` .
@@ -4115,13 +4427,13 @@ def threshold(input, thr, value):
4115
4427
  _check_is_tensor('input', input, "threshold")
4116
4428
  _check_value_type("thr", thr, [float, int], "threshold")
4117
4429
  _check_value_type("value", value, [float, int], "threshold")
4118
- cond = _get_cache_prim(P.Greater)()(input, thr)
4430
+ cond = greater_(input, thr)
4119
4431
  input_type = input.dtype
4120
4432
  value = Tensor(value, input_type)
4121
4433
  input_shape = input.shape
4122
- shape_tensor = _get_cache_prim(TupleToTensor)()(input_shape, mstype.int64)
4123
- value = _get_cache_prim(P.FillV2)()(shape_tensor, value)
4124
- return _get_cache_prim(P.Select)()(cond, input, value)
4434
+ shape_tensor = tuple_to_tensor_(input_shape, mstype.int64)
4435
+ value = fillv2_(shape_tensor, value)
4436
+ return select_(cond, input, value)
4125
4437
 
4126
4438
 
4127
4439
  def leaky_relu(input, alpha=0.2):
@@ -4139,6 +4451,11 @@ def leaky_relu(input, alpha=0.2):
4139
4451
  For more details, see `Rectifier Nonlinearities Improve Neural Network Acoustic Models
4140
4452
  <https://ai.stanford.edu/~amaas/papers/relu_hybrid_icml2013_final.pdf>`_.
4141
4453
 
4454
+ LeakyReLU Activation Function Graph:
4455
+
4456
+ .. image:: ../images/LeakyReLU.png
4457
+ :align: center
4458
+
4142
4459
  Args:
4143
4460
  input (Tensor): The input of leaky_relu is a Tensor of any dimension.
4144
4461
  alpha (Union[int, float]): Slope of the activation function when the element of `input` is less than 0.
@@ -4165,10 +4482,10 @@ def leaky_relu(input, alpha=0.2):
4165
4482
  """
4166
4483
  _check_is_tensor('input', input, "leaky_relu")
4167
4484
  _check_value_type("alpha", alpha, [float, int], "leaky_relu")
4168
- select_op = _get_cache_prim(P.Maximum)()
4485
+ select_op = maximum_
4169
4486
  if alpha > 1:
4170
- select_op = _get_cache_prim(P.Minimum)()
4171
- alpha = _get_cache_prim(P.Cast)()(F.scalar_to_tensor(alpha), input.dtype)
4487
+ select_op = minimum_
4488
+ alpha = cast_(F.scalar_to_tensor(alpha), input.dtype)
4172
4489
  return select_op(alpha * input, input)
4173
4490
 
4174
4491
 
@@ -4209,48 +4526,6 @@ def intopk(x1, x2, k):
4209
4526
  _in_topk = _get_cache_prim(P.InTopK)(k)
4210
4527
  return _in_topk(x1, x2)
4211
4528
 
4212
-
4213
- def log_softmax(logits, axis=-1):
4214
- r"""
4215
- Applies the Log Softmax function to the input tensor on the specified axis.
4216
- Supposes a slice in the given axis, :math:`x` for each element :math:`x_i`,
4217
- the Log Softmax function is shown as follows:
4218
-
4219
- .. math::
4220
- \text{output}(x_i) = \log \left(\frac{\exp(x_i)} {\sum_{j = 0}^{N-1}\exp(x_j)}\right),
4221
-
4222
- where :math:`N` is the length of the Tensor.
4223
-
4224
- Args:
4225
- logits (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
4226
- additional dimensions, with float16 or float32 data type.
4227
- axis (int): The axis to perform the Log softmax operation. Default: ``-1`` .
4228
-
4229
- Returns:
4230
- Tensor, with the same type and shape as the logits.
4231
-
4232
- Raises:
4233
- TypeError: If `axis` is not an int.
4234
- TypeError: If dtype of `logits` is neither float16 nor float32.
4235
- ValueError: If `axis` is not in range [-len(logits.shape), len(logits.shape)).
4236
- ValueError: If dimension of `logits` is less than 1.
4237
-
4238
- Supported Platforms:
4239
- ``Ascend`` ``GPU`` ``CPU``
4240
-
4241
- Examples:
4242
- >>> import mindspore
4243
- >>> import numpy as np
4244
- >>> from mindspore import Tensor, ops
4245
- >>> logits = Tensor(np.array([1, 2, 3, 4, 5]), mindspore.float32)
4246
- >>> output = ops.log_softmax(logits)
4247
- >>> print(output)
4248
- [-4.4519143 -3.4519143 -2.4519143 -1.4519144 -0.4519144]
4249
- """
4250
- _log_softmax = _get_cache_prim(P.LogSoftmax)(axis)
4251
- return _log_softmax(logits)
4252
-
4253
-
4254
4529
  def lrn(x, depth_radius=5, bias=1.0, alpha=1.0, beta=0.5, norm_region="ACROSS_CHANNELS"):
4255
4530
  r"""
4256
4531
  Local Response Normalization.
@@ -4319,6 +4594,11 @@ def mish(x):
4319
4594
  See more details in `A Self Regularized Non-Monotonic Neural Activation Function
4320
4595
  <https://arxiv.org/abs/1908.08681>`_.
4321
4596
 
4597
+ Mish Activation Function Graph:
4598
+
4599
+ .. image:: ../images/Mish.png
4600
+ :align: center
4601
+
4322
4602
  Args:
4323
4603
  x (Tensor): The input Tensor.
4324
4604
  Supported dtypes:
@@ -4385,21 +4665,15 @@ def _get_loss(x, reduction, cls_name, weights=1.0):
4385
4665
  if reduction not in ('mean', 'sum', 'none'):
4386
4666
  raise ValueError(f"For '{cls_name}', the 'reduction' must be in ['mean', 'sum', 'none'], "
4387
4667
  f"but got {reduction}.")
4388
-
4389
- reduce_mean = P.ReduceMean()
4390
- reduce_sum = P.ReduceSum()
4391
- mul = P.Mul()
4392
- cast = P.Cast()
4393
-
4394
4668
  input_dtype = x.dtype
4395
- x = cast(x, mstype.float32)
4396
- weights = cast(weights, mstype.float32)
4397
- x = mul(weights, x)
4669
+ x = cast_(x, mstype.float32)
4670
+ weights = cast_(weights, mstype.float32)
4671
+ x = mul_(weights, x)
4398
4672
  if reduction == 'mean':
4399
- x = reduce_mean(x, _get_axis(x))
4673
+ x = reduce_mean_(x, _get_axis(x))
4400
4674
  if reduction == 'sum':
4401
- x = reduce_sum(x, _get_axis(x))
4402
- x = cast(x, input_dtype)
4675
+ x = reduce_sum_(x, _get_axis(x))
4676
+ x = cast_(x, input_dtype)
4403
4677
  return x
4404
4678
 
4405
4679
 
@@ -4410,20 +4684,6 @@ def check_input_dtype(param_name1, input_data1, param_name2, input_data2, cls_na
4410
4684
  f'but got {param_name1} dtype:{input_data1.dtype}, {param_name2} dtype:{input_data2.dtype}.')
4411
4685
 
4412
4686
 
4413
- def check_input_shape(param_name1, input_data1, param_name2, input_data2, cls_name):
4414
- """Check the shape of input1 and input2."""
4415
- if input_data1.shape != input_data2.shape:
4416
- raise ValueError(f'For {cls_name}, the {param_name1} shape should be equal to {param_name2} shape, '
4417
- f'but got {param_name1} shape:{input_data1.shape}, {param_name2} shape:{input_data2.shape}.')
4418
-
4419
-
4420
- def _check_type_and_shape_same(param_name1, input_data1, param_name2, input_data2, cls_name):
4421
- """check input1 and input2 type and shape same"""
4422
- check_input_dtype(param_name1, input_data1, param_name2, input_data2, cls_name)
4423
- check_input_shape(param_name1, input_data1, param_name2, input_data2, cls_name)
4424
- return 0
4425
-
4426
-
4427
4687
  def margin_ranking_loss(input1, input2, target, margin=0.0, reduction='mean'):
4428
4688
  r"""
4429
4689
  MarginRankingLoss creates a criterion that measures the loss.
@@ -4448,7 +4708,7 @@ def margin_ranking_loss(input1, input2, target, margin=0.0, reduction='mean'):
4448
4708
  - ``'sum'``: the output elements will be summed.
4449
4709
 
4450
4710
  Returns:
4451
- Tensor or Scalar. if `reduction` is ``"none"``, its shape is the same as `labels`.
4711
+ Tensor or Scalar. if `reduction` is ``'none'``, its shape is the same as `input1`.
4452
4712
  Otherwise, a scalar value will be returned.
4453
4713
 
4454
4714
  Raises:
@@ -4478,10 +4738,9 @@ def margin_ranking_loss(input1, input2, target, margin=0.0, reduction='mean'):
4478
4738
  _check_is_tensor('input1', input1, "margin_ranking_loss")
4479
4739
  _check_is_tensor('input2', input2, "margin_ranking_loss")
4480
4740
  _check_is_tensor('target', target, "margin_ranking_loss")
4481
- maximum = P.Maximum()
4482
- _check_type_and_shape_same('input1', input1, 'input2', input2, 'margin_ranking_loss')
4483
- _check_type_and_shape_same('target', target, 'input1', input1, 'margin_ranking_loss')
4484
- x = maximum(-target * (input1 - input2) + margin, 0)
4741
+ check_input_dtype('input1', input1, 'input2', input2, 'margin_ranking_loss')
4742
+ check_input_dtype('target', target, 'input1', input1, 'margin_ranking_loss')
4743
+ x = maximum_(-target * (input1 - input2) + margin, 0)
4485
4744
  return _get_loss(x, reduction, "margin_ranking_loss")
4486
4745
 
4487
4746
 
@@ -4509,7 +4768,7 @@ def cosine_embedding_loss(input1, input2, target, margin=0.0, reduction="mean"):
4509
4768
  input2 (Tensor): Tensor of shape :math:`(N, *)`, same shape and dtype as `input1`.
4510
4769
  target (Tensor): Contains value 1 or -1. Suppose the shape of `input1` is
4511
4770
  :math:`(x_1, x_2, x_3, ..., x_R)`, then the shape of `target` must be :math:`(x_1, x_3, x_4, ..., x_R)`.
4512
- margin (float, optional): Should be in [-1.0, 1.0]. Default: 0.0.
4771
+ margin (float, optional): Should be in [-1.0, 1.0]. Default: ``0.0``.
4513
4772
  reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
4514
4773
  ``'sum'`` . Default: ``'mean'`` .
4515
4774
 
@@ -4524,7 +4783,7 @@ def cosine_embedding_loss(input1, input2, target, margin=0.0, reduction="mean"):
4524
4783
  Raises:
4525
4784
  TypeError: If `margin` is not a float.
4526
4785
  ValueError: If `reduction` is not one of ``'none'``, ``'mean'``, ``'sum'``.
4527
- ValueError: If `margin` is not in range [-1, 1].
4786
+ ValueError: If `margin` is not in range [-1.0, 1.0].
4528
4787
 
4529
4788
  Supported Platforms:
4530
4789
  ``Ascend`` ``GPU`` ``CPU``
@@ -4544,7 +4803,7 @@ def cosine_embedding_loss(input1, input2, target, margin=0.0, reduction="mean"):
4544
4803
  _check_is_tensor('input1', input1, "ops.cosine_embedding_loss")
4545
4804
  _check_is_tensor('input2', input2, "ops.cosine_embedding_loss")
4546
4805
  _check_is_tensor('target', target, "ops.cosine_embedding_loss")
4547
- _check_type_and_shape_same('input1', input1, 'input2', input2, 'ops.cosine_embedding_loss')
4806
+ check_input_dtype('input1', input1, 'input2', input2, 'ops.cosine_embedding_loss')
4548
4807
  _check_reduced_shape_valid(ops.shape(input1), ops.shape(target), (1,),
4549
4808
  "ops.cosine_embedding_loss", "input1", "target")
4550
4809
  if input1.dtype in (mstype.int32, mstype.int64):
@@ -4558,14 +4817,14 @@ def cosine_embedding_loss(input1, input2, target, margin=0.0, reduction="mean"):
4558
4817
  if margin_f > 1.0 or margin_f < -1.0:
4559
4818
  raise ValueError(f"For ops.cosine_embedding_loss, the value of 'margin' should be in [-1, 1],"
4560
4819
  f"but got {margin_f}.")
4561
- prod_sum = _get_cache_prim(P.ReduceSum)()(input1 * input2, (1,))
4562
- square1 = _get_cache_prim(P.ReduceSum)()(ops.square(input1), (1,))
4563
- square2 = _get_cache_prim(P.ReduceSum)()(ops.square(input2), (1,))
4820
+ prod_sum = reduce_sum_(input1 * input2, (1,))
4821
+ square1 = reduce_sum_(ops.square(input1), (1,))
4822
+ square2 = reduce_sum_(ops.square(input2), (1,))
4564
4823
  denom = ops.sqrt(square1) * ops.sqrt(square2)
4565
4824
  cosine = prod_sum / denom
4566
4825
 
4567
4826
  pos_value = 1.0 - cosine
4568
- neg_value = _get_cache_prim(P.Maximum)()(cosine - margin_f, 0.0)
4827
+ neg_value = maximum_(cosine - margin_f, 0.0)
4569
4828
  zeros = ops.zeros_like(cosine)
4570
4829
  pos_part = ops.select(target == 1, pos_value, zeros)
4571
4830
  neg_part = ops.select(target == -1, neg_value, zeros)
@@ -4622,7 +4881,7 @@ def max_pool3d(x, kernel_size, stride=None, padding=0, dilation=1, ceil_mode=Fal
4622
4881
  W_{out} = \left\lfloor\frac{W_{in} + 2 \times \text{padding}[2] - \text{dilation}[2] \times
4623
4882
  (\text{kernel_size}[2] - 1) - 1}{\text{stride}[2]} + 1\right\rfloor
4624
4883
 
4625
- - **argmax** (Tensor) - Index corresponding to the maximum value. Data type is int64. It will be return
4884
+ - **argmax** (Tensor) - Index corresponding to the maximum value. Data type is int64. It will be returned
4626
4885
  only when `return_indices` is ``True`` .
4627
4886
 
4628
4887
  Raises:
@@ -4700,9 +4959,9 @@ def grid_sample(input, grid, mode='bilinear', padding_mode='zeros', align_corner
4700
4959
 
4701
4960
  padding_mode (str): An optional string specifying the pad method. The optional values are "zeros", "border" or
4702
4961
  "reflection". Default: ``'zeros'`` .
4703
- align_corners (bool): An optional bool. If set to `True`, the extrema (-1 and 1) are considered as referring to
4704
- the center points of the inputs corner pixels. If set to `False`, they are instead considered as referring
4705
- to the corner points of the inputs corner pixels, making the sampling more resolution agnostic. Default:
4962
+ align_corners (bool): If set to `True`, the extrema (-1 and 1) are considered as referring to
4963
+ the center points of the input's corner pixels. If set to `False`, they are instead considered as referring
4964
+ to the corner points of the input's corner pixels, making the sampling more resolution agnostic. Default:
4706
4965
  ``False`` .
4707
4966
 
4708
4967
  Returns:
@@ -4775,8 +5034,8 @@ def ctc_loss(log_probs, targets, input_lengths, target_lengths, blank=0, reducti
4775
5034
  log_probs (Tensor): A tensor of shape :math:`(T, N, C)`, where T is input length, N is batch size and C is
4776
5035
  number of classes (including blank).
4777
5036
  targets (Tensor): Target sequences. A tensor of shape :math:`(N, S)`, where S is max target length.
4778
- input_lengths (Union(tuple, Tensor)): Lengths of the input. A tuple or Tensor of shape(N).
4779
- target_lengths (Union(tuple, Tensor)): Lengths of the target. A tuple or Tensor of shape(N).
5037
+ input_lengths (Union(tuple, Tensor)): Lengths of the input. A tuple or Tensor of shape :math:`(N)`.
5038
+ target_lengths (Union(tuple, Tensor)): Lengths of the target. A tuple or Tensor of shape :math:`(N)`.
4780
5039
  blank (int, optional): The blank label. Default: ``0`` .
4781
5040
  reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
4782
5041
  ``'sum'`` . Default: ``'mean'`` .
@@ -4923,30 +5182,17 @@ def gaussian_nll_loss(x, target, var, full=False, eps=1e-6, reduction='mean'):
4923
5182
  if not x.shape == var.shape:
4924
5183
  if x.shape[:-1] == var.shape:
4925
5184
  var = var.unsqueeze(dim=-1)
4926
- # Heterosclerotic case
4927
- elif x.shape[:-1] == var.shape[:-1] and var.shape[-1] == 1:
4928
- pass
4929
- else:
4930
- raise ValueError(f"For 'gaussian_nll_loss', 'var' must be able to correctly broadcast to 'x' and 'target'.")
4931
- max_op = P.Maximum()
4932
- log_op = P.Log()
4933
- square_op = P.Square()
4934
- maxima = max_op(var, eps)
4935
- logarithm = log_op(maxima)
4936
- squared_loss = square_op(x - target)
5185
+
5186
+ maxima = maximum_(var, eps)
5187
+ logarithm = log_(maxima)
5188
+ squared_loss = square_(x - target)
4937
5189
  c = 0 if not full else 0.5 * log(2 * pi)
4938
5190
  loss = 0.5 * (logarithm + squared_loss / maxima) + c
4939
5191
  if reduction == 'mean':
4940
5192
  loss = loss.mean()
4941
5193
  elif reduction == 'sum':
4942
5194
  loss = loss.sum()
4943
- return loss
4944
-
4945
-
4946
- @_primexpr
4947
- def _check_hinge_embedding_loss(shape, shape2):
4948
- if shape2 != shape:
4949
- raise ValueError(f"For 'HingeEmbeddingLoss' the input tensor and the labels must have the same shape.")
5195
+ return loss
4950
5196
 
4951
5197
 
4952
5198
  @_primexpr
@@ -4996,7 +5242,7 @@ def hinge_embedding_loss(inputs, targets, margin=1.0, reduction='mean'):
4996
5242
  inputs (Tensor): Predicted values, represented as :math:`x` in the formula.
4997
5243
  targets (Tensor): Label values, represented as :math:`y` in the formula.
4998
5244
  Has the same shape as `inputs`, contains -1 or 1.
4999
- margin (float, int): Threshold defined by Hinge Embedding Loss :math:`margin`.
5245
+ margin (float, int): Threshold defined by Hinge Embedding Loss `margin`.
5000
5246
  Represented as :math:`\Delta` in the formula. Default: ``1.0`` .
5001
5247
  reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
5002
5248
  ``'sum'`` . Default: ``'mean'`` .
@@ -5006,7 +5252,7 @@ def hinge_embedding_loss(inputs, targets, margin=1.0, reduction='mean'):
5006
5252
  - ``'sum'``: the output elements will be summed.
5007
5253
 
5008
5254
  Returns:
5009
- Tensor or Tensor scalar, the computed loss depending on :math:`reduction`.
5255
+ Tensor or Tensor scalar, the computed loss depending on `reduction`.
5010
5256
 
5011
5257
  Raises:
5012
5258
  TypeError: If `inputs` is not a Tensor.
@@ -5021,7 +5267,7 @@ def hinge_embedding_loss(inputs, targets, margin=1.0, reduction='mean'):
5021
5267
  Examples:
5022
5268
  >>> import numpy as np
5023
5269
  >>> import mindspore.common.dtype as mstype
5024
- >>> import mindspore.ops as ops
5270
+ >>> from mindspore import ops
5025
5271
  >>> from mindspore import Tensor
5026
5272
  >>> arr1 = np.array([0.9, -1.2, 2, 0.8, 3.9, 2, 1, 0, -1]).reshape((3, 3))
5027
5273
  >>> arr2 = np.array([1, 1, -1, 1, -1, 1, -1, 1, 1]).reshape((3, 3))
@@ -5034,9 +5280,6 @@ def hinge_embedding_loss(inputs, targets, margin=1.0, reduction='mean'):
5034
5280
  inputs_dtype = inputs.dtype
5035
5281
  targets_dtype = targets.dtype
5036
5282
  _check_hinge_embedding_loss_type(inputs_dtype, targets_dtype, inputs, targets, margin, reduction)
5037
- _shape = inputs.shape
5038
- _t_shape = targets.shape
5039
- _check_hinge_embedding_loss(_shape, _t_shape)
5040
5283
 
5041
5284
  min_val = Tensor(0, inputs_dtype)
5042
5285
  pos_index = targets > 0
@@ -5257,21 +5500,25 @@ def conv1d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
5257
5500
  , :math:`weight` is the convolution kernel value and :math:`X` represents the input feature map.
5258
5501
 
5259
5502
  Here are the indices' meanings:
5260
- - :math:`i` corresponds to the batch number, ranging from 0 to N-1, where N is the batch size of the input.
5261
5503
 
5262
- - :math:`j` corresponds to the output channel, ranging from 0 to C_{out}-1, where C_{out} is the number of
5504
+ - :math:`i` corresponds to the batch number, the range is :math:`[0, N-1]`,
5505
+ where :math:`N` is the batch size of the input.
5506
+
5507
+ - :math:`j` corresponds to the output channel, ranging from :math:`[0, C_{out}-1]`,
5508
+ where :math:`C_{out}` is the number of
5263
5509
  output channels, which is also equal to the number of kernels.
5264
5510
 
5265
- - :math:`k` corresponds to the input channel, ranging from 0 to C_{in}-1, where C_{in} is the number of
5511
+ - :math:`k` corresponds to the input channel, ranging from :math:`[0, C_{in}-1]`,
5512
+ where :math:`C_{in}` is the number of
5266
5513
  input channels, which is also equal to the number of channels in the convolutional kernels.
5267
5514
 
5268
- Therefore, in the above formula, :math:`{bias}(C_{out_j})` represents the bias of the :math:`j`-th
5269
- output channel, :math:`{weight}(C_{out_j}, k)` represents the slice of the :math:`j`-th convolutional
5515
+ Therefore, in the above formula, :math:`{bias}(C_{\text{out}_j})` represents the bias of the :math:`j`-th
5516
+ output channel, :math:`{weight}(C_{\text{out}_j}, k)` represents the slice of the :math:`j`-th convolutional
5270
5517
  kernel in the :math:`k`-th channel, and :math:`{X}(N_i, k)` represents the slice of the :math:`k`-th input
5271
5518
  channel in the :math:`i`-th batch of the input feature map.
5272
5519
 
5273
- The shape of the convolutional kernel is given by :math:`(kernel\_size)`,
5274
- where :math:`kernel\_size` is the width of the kernel.
5520
+ The shape of the convolutional kernel is given by :math:`(\text{kernel_size})`,
5521
+ where :math:`\text{kernel_size}` is the width of the kernel.
5275
5522
  If we consider the input and output channels as well as the `group` parameter, the complete kernel shape
5276
5523
  will be :math:`(C_{out}, C_{in} / \text{group}, \text{kernel_size})`,
5277
5524
  where `group` is the number of groups dividing `x`'s input channel when applying group convolution.
@@ -5282,7 +5529,7 @@ def conv1d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
5282
5529
 
5283
5530
  Note:
5284
5531
  On Ascend platform, only group convolution in depthwise convolution scenarios is supported.
5285
- That is, when `groups>1`, condition `C_{in}` = `C_{out}` = `groups` must be satisfied.
5532
+ That is, when `groups>1`, condition :math:`C_{in}` = :math:`C_{out}` = `groups` must be satisfied.
5286
5533
 
5287
5534
  Args:
5288
5535
  input (Tensor): Input Tensor of shape :math:`(N, C_{in}, L_{in})`.
@@ -5342,7 +5589,7 @@ def conv1d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
5342
5589
  >>> from mindspore import Tensor, ops
5343
5590
  >>> x = Tensor(np.arange(64).reshape((4, 4, 4)), mindspore.float32)
5344
5591
  >>> weight = Tensor(np.arange(8).reshape((2, 2, 2)), mindspore.float32)
5345
- >>> bias = Tensor([-0.12345, 2.7683], ms.float32)
5592
+ >>> bias = Tensor([-0.12345, 2.7683], mindspore.float32)
5346
5593
  >>> output = ops.conv1d(x, weight, pad_mode='pad', padding=(1,), bias=bias, groups=2)
5347
5594
  >>> print(output.shape)
5348
5595
  (4, 2, 5)
@@ -5351,13 +5598,12 @@ def conv1d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
5351
5598
  raise ValueError(f"For 'conv1d', the input must be a 3D Tensor, but got input of {input.ndim}D.")
5352
5599
  if weight.ndim != 3:
5353
5600
  raise ValueError(f"For 'conv1d', the weight must be a 3D Tensor, but got input of {weight.ndim}D.")
5354
- _expand = _get_cache_prim(P.ExpandDims)()
5355
- expanded_input = _expand(input, 2)
5601
+ expanded_input = expand_dims_(input, 2)
5356
5602
  sqz = _get_cache_prim(P.Squeeze)(2)
5357
5603
  weight_shape = weight.shape
5358
5604
  out_channel = weight_shape[0]
5359
5605
  kernel_size = (1, weight_shape[2])
5360
- expanded_weight = _expand(weight, 2)
5606
+ expanded_weight = expand_dims_(weight, 2)
5361
5607
  if isinstance(padding, int):
5362
5608
  padding = (0, 0, padding, padding)
5363
5609
  elif isinstance(padding, (tuple, list)):
@@ -5406,12 +5652,15 @@ def conv2d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
5406
5652
  , :math:`weight` is the convolution kernel value and :math:`X` represents the input feature map.
5407
5653
 
5408
5654
  Here are the indices' meanings:
5409
- - :math:`i` corresponds to the batch number, ranging from 0 to N-1, where N is the batch size of the input.
5410
5655
 
5411
- - :math:`j` corresponds to the output channel, ranging from 0 to C_{out}-1, where C_{out} is the number of
5412
- output channels, which is also equal to the number of kernels.
5656
+ - :math:`i` corresponds to the batch number, the range is :math:`[0, N-1]`,
5657
+ where :math:`N` is the batch size of the input.
5658
+
5659
+ - :math:`j` corresponds to the output channel, the range is :math:`[0, C_{out}-1]`,
5660
+ where :math:`C_{out}` is the number of output channels, which is also equal to the number of kernels.
5413
5661
 
5414
- - :math:`k` corresponds to the input channel, ranging from 0 to C_{in}-1, where C_{in} is the number of
5662
+ - :math:`k` corresponds to the input channel, the range is :math:`[0, C_{in}-1]`,
5663
+ where :math:`C_{in}` is the number of
5415
5664
  input channels, which is also equal to the number of channels in the convolutional kernels.
5416
5665
 
5417
5666
  Therefore, in the above formula, :math:`{bias}(C_{out_j})` represents the bias of the :math:`j`-th
@@ -5419,8 +5668,9 @@ def conv2d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
5419
5668
  kernel in the :math:`k`-th channel, and :math:`{X}(N_i, k)` represents the slice of the :math:`k`-th input
5420
5669
  channel in the :math:`i`-th batch of the input feature map.
5421
5670
 
5422
- The shape of the convolutional kernel is given by :math:`(kernel\_size[0], kernel\_size[1])`,
5423
- where :math:`kernel\_size[0]` and :math:`kernel\_size[1]` are the height and width of the kernel, respectively.
5671
+ The shape of the convolutional kernel is given by :math:`(\text{kernel_size[0]}, \text{kernel_size[1]})`,
5672
+ where :math:`\text{kernel_size[0]}` and :math:`\text{kernel_size[1]}` are the height and width of the kernel,
5673
+ respectively.
5424
5674
  If we consider the input and output channels as well as the `group` parameter, the complete kernel shape
5425
5675
  will be :math:`(C_{out}, C_{in} / \text{group}, \text{kernel_size[0]}, \text{kernel_size[1]})`,
5426
5676
  where `group` is the number of groups dividing `x`'s input channel when applying group convolution.
@@ -5431,7 +5681,7 @@ def conv2d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
5431
5681
 
5432
5682
  Note:
5433
5683
  On Ascend platform, only group convolution in depthwise convolution scenarios is supported.
5434
- That is, when `groups>1`, condition `C_{in}` = `C_{out}` = `groups` must be satisfied.
5684
+ That is, when `groups>1`, condition :math:`C_{in}` = :math:`C_{out}` = `groups` must be satisfied.
5435
5685
 
5436
5686
  Args:
5437
5687
  input (Tensor): Tensor of shape :math:`(N, C_{in}, H_{in}, W_{in})`.
@@ -5476,7 +5726,7 @@ def conv2d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
5476
5726
  TypeError: If `stride`, `padding` or `dilation` is neither an int nor a tuple.
5477
5727
  TypeError: `groups` is not an int.
5478
5728
  TypeError: If `bias` is not a Tensor.
5479
- ValueError: If the shape of `bias` is not :math:`C_{out}` .
5729
+ ValueError: If the shape of `bias` is not :math:`(C_{out})` .
5480
5730
  ValueError: If `stride` or `dilation` is less than 1.
5481
5731
  ValueError: If `pad_mode` is not one of 'same', 'valid' or 'pad'.
5482
5732
  ValueError: If `padding` is a tuple/list whose length is not equal to 2.
@@ -5523,6 +5773,75 @@ def conv2d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
5523
5773
  return output
5524
5774
 
5525
5775
 
5776
+ def conv_transpose2d(input, weight, bias=None, stride=1, padding=0, output_padding=0, groups=1, dilation=1):
5777
+ r"""
5778
+ Calculates a 2D transposed convolution, which can be regarded as Conv2d for the gradient of the input,
5779
+ also called deconvolution (although it is not an actual deconvolution).
5780
+
5781
+ The input is typically of shape :math:`(N, C_{in}, H_{in}, W_{in})`,
5782
+ where :math:`N` is batch size, :math:`C_{in}` is space dimension,
5783
+ :math:`H_{in}, W_{in}` are the height and width of the feature layer respectively.
5784
+
5785
+ When Conv2d and Conv2dTranspose are initialized with the same parameters, and `pad_mode` is set to 'pad',
5786
+ :math:`dilation * (kernel\_size - 1) - padding` amount of zero will be paded to the height and width
5787
+ directions of the input, they are inverses of each other in regard to the input and output shapes in this case.
5788
+ However, when `stride` > 1, Conv2d maps multiple input shapes to the same output shape. Deconvolutional network
5789
+ can refer to `Deconvolutional Networks <https://www.matthewzeiler.com/mattzeiler/deconvolutionalnetworks.pdf>`_.
5790
+
5791
+ Args:
5792
+ input (Tensor): Tensor of shape :math:`(N, C_{in}, H_{in}, W_{in})`.
5793
+ weight (Tensor): Tensor of shape
5794
+ :math:`(N, C_{in} / \text{groups}, \text{kernel_size[0]}, \text{kernel_size[1]})`, then the size of kernel
5795
+ is :math:`(\text{kernel_size[0]}, \text{kernel_size[1]})`.
5796
+ bias (Tensor, optional): Bias Tensor with shape :math:`(C_{out})`.
5797
+ When bias is ``None`` , zeros will be used. Default: ``None`` .
5798
+ stride (Union(int, tuple[int]), optional): The distance of kernel moving, an int number that represents
5799
+ the height and width of movement are both strides, or a tuple of two int numbers that
5800
+ represent height and width of movement respectively. Default: ``1`` .
5801
+ padding (Union(int, tuple[int], list[int]), optional): Implicit paddings on both sides of the input `x`.
5802
+ Can be an integer or a tuple/list with 2 integers.
5803
+ output_padding (Union[int, tuple[int]]): The number of padding on the height and width directions of the output.
5804
+ The data type is an integer or a tuple of two integers. If `output_padding` is an integer,
5805
+ then the bottom and right padding are all equal to `output_padding`. If `output_padding` is a tuple of
5806
+ 2 integers, then the bottom and right padding is equal to `output_padding[0]`, `output_padding[1]`
5807
+ respectively.
5808
+ groups (int, optional): Splits `input` into groups. Default: ``1`` .
5809
+ dilation (Union(int, tuple[int]), optional): Gaps between kernel elements.The data type is int or a tuple of
5810
+ 2 integers. Specifies the dilation rate to use for dilated convolution. If set to be :math:`k > 1`,
5811
+ there will be :math:`k - 1` pixels skipped for each sampling location. Its value must
5812
+ be greater than or equal to 1 and bounded by the height and width of the input `x`. Default: ``1`` .
5813
+
5814
+ Returns:
5815
+ Tensor, the value that applied 2D convolution. The shape is :math:`(N, C_{out}, H_{out}, W_{out})`.
5816
+ To see how different pad modes affect the output shape, please refer to
5817
+ :class:`mindspore.nn.Conv2dTranspose` for more details.
5818
+
5819
+
5820
+ Raises:
5821
+ TypeError: If `stride`, `padding` or `dilation` is neither an int nor a tuple.
5822
+ TypeError: `groups` is not an int.
5823
+ TypeError: If `bias` is not a Tensor.
5824
+ ValueError: If the shape of `bias` is not :math:`(C_{out})` .
5825
+ ValueError: If `stride` or `dilation` is less than 1.
5826
+ ValueError: If `padding` is a tuple/list whose length is not equal to 2.
5827
+
5828
+ Supported Platforms:
5829
+ ``Ascend``
5830
+
5831
+ Examples:
5832
+ >>> import mindspore
5833
+ >>> import numpy as np
5834
+ >>> from mindspore import Tensor, ops
5835
+ >>> x = Tensor(np.ones([1, 6, 32, 32]), mindspore.float32)
5836
+ >>> weight = Tensor(np.ones([6, 3, 5, 5]), mindspore.float32)
5837
+ >>> output = ops.conv_transpose2d(x, weight)
5838
+ >>> print(output.shape)
5839
+ (1, 3, 36, 36)
5840
+ """
5841
+ conv = _get_cache_prim(Convolution)(stride, padding, dilation, True, output_padding, groups)
5842
+ return conv(input, weight, bias)
5843
+
5844
+
5526
5845
  def hardsigmoid(input):
5527
5846
  r"""
5528
5847
  Hard sigmoid activation function.
@@ -5537,6 +5856,11 @@ def hardsigmoid(input):
5537
5856
 
5538
5857
  where :math:`x_i` is an element of the input Tensor.
5539
5858
 
5859
+ HSigmoid Activation Function Graph:
5860
+
5861
+ .. image:: ../images/HSigmoid.png
5862
+ :align: center
5863
+
5540
5864
  Args:
5541
5865
  input (Tensor): The input Tensor.
5542
5866
 
@@ -5576,10 +5900,15 @@ def hardtanh(input, min_val=-1.0, max_val=1.0):
5576
5900
 
5577
5901
  Linear region range :math:`[min\_val, max\_val]` can be adjusted using `min_val` and `max_val`.
5578
5902
 
5903
+ Hardtanh Activation Function Graph:
5904
+
5905
+ .. image:: ../images/Hardtanh.png
5906
+ :align: center
5907
+
5579
5908
  Args:
5580
5909
  input (Tensor): Input Tensor.
5581
- min_val (Union[int, float]): Minimum value of the linear region range. Default: ``-1.0`` .
5582
- max_val (Union[int, float]): Maximum value of the linear region range. Default: ``1.0`` .
5910
+ min_val (Union[int, float], optional): Minimum value of the linear region range. Default: ``-1.0`` .
5911
+ max_val (Union[int, float], optional): Maximum value of the linear region range. Default: ``1.0`` .
5583
5912
 
5584
5913
  Returns:
5585
5914
  Tensor, with the same dtype and shape as `input`.
@@ -5604,18 +5933,18 @@ def hardtanh(input, min_val=-1.0, max_val=1.0):
5604
5933
  _check_value_type("min_val", min_val, [int, float], "hardtanh")
5605
5934
  _check_value_type("max_val", max_val, [int, float], "hardtanh")
5606
5935
  input_dtype = input.dtype
5607
- input = _get_cache_prim(P.Maximum)()(input, min_val)
5608
- input = _get_cache_prim(P.Minimum)()(input, max_val)
5936
+ input = maximum_(input, min_val)
5937
+ input = minimum_(input, max_val)
5609
5938
  return input.astype(input_dtype)
5610
5939
 
5611
5940
 
5612
5941
  def huber_loss(input, target, reduction='mean', delta=1.0):
5613
5942
  r"""
5614
5943
  Calculates the error between the predicted value and the target value,
5615
- which has the best of both the loss of l1 and the loss of mse.
5944
+ which has the best of both the loss of :func:`mindspore.ops.l1_loss` and the loss of :func:`mindspore.ops.mse_loss`.
5616
5945
 
5617
5946
  Assuming that the :math:`x` and :math:`y` are 1-D Tensor, length :math:`N`, the `reduction` parameter
5618
- is set to ``"none"`` then calculate the loss of :math:`x` and :math:`y` without dimensionality reduction.
5947
+ is set to ``'none'`` then calculate the loss of :math:`x` and :math:`y` without dimensionality reduction.
5619
5948
  The formula is as follows:
5620
5949
 
5621
5950
  .. math::
@@ -5656,14 +5985,14 @@ def huber_loss(input, target, reduction='mean', delta=1.0):
5656
5985
  The value must be greater than zero. Default: ``1.0`` .
5657
5986
 
5658
5987
  Returns:
5659
- Tensor or Scalar, if `reduction` is ``"none"``, return a Tensor with same shape and dtype as `input`.
5988
+ Tensor or Scalar, if `reduction` is ``'none'``, return a Tensor with same shape and dtype as `input`.
5660
5989
  Otherwise, a scalar value will be returned.
5661
5990
 
5662
5991
  Raises:
5663
5992
  TypeError: If `input` or `target` is not a Tensor.
5664
5993
  TypeError: If dtype of `delta` is neither float nor int.
5665
5994
  ValueError: If `delta` is less than or equal to 0.
5666
- ValueError: If `reduction` is not one of ``"none"``, ``"mean"``, ``"sum"``.
5995
+ ValueError: If `reduction` is not one of ``'none'``, ``'mean'``, ``'sum'``.
5667
5996
  ValueError: If `input` and `target` have different shapes and cannot be broadcasted to each other.
5668
5997
 
5669
5998
  Supported Platforms:
@@ -5682,14 +6011,12 @@ def huber_loss(input, target, reduction='mean', delta=1.0):
5682
6011
  _check_is_tensor('target', target, "huber_loss")
5683
6012
  _check_value_type("delta", delta, [int, float], "huber_loss")
5684
6013
  _check_number_gt_value("delta", delta, 0.0, "huber_loss")
5685
- sub = _get_cache_prim(P.Sub)()
5686
- multi = _get_cache_prim(P.Mul)()
5687
- z = sub(input, target)
5688
- z = _get_cache_prim(P.Abs)()(z)
5689
- cond = _get_cache_prim(P.Less)()(z, delta)
5690
- l1 = multi(0.5, _get_cache_prim(P.Square)()(z))
5691
- l2 = multi(delta, sub(z, 0.5 * delta))
5692
- loss = _get_cache_prim(P.Select)()(cond, l1, l2)
6014
+ z = sub_(input, target)
6015
+ z = abs_(z)
6016
+ cond = less_(z, delta)
6017
+ l1 = mul_(0.5, square_(z))
6018
+ l2 = mul_(delta, sub_(z, 0.5 * delta))
6019
+ loss = select_(cond, l1, l2)
5693
6020
  return _get_loss(loss, reduction, "huber_loss")
5694
6021
 
5695
6022
 
@@ -5741,7 +6068,7 @@ def adaptive_avg_pool1d(input, output_size):
5741
6068
  """
5742
6069
  def _check(x, output_size):
5743
6070
  x_in_shape = x.shape
5744
- x_dtype = _get_cache_prim(P.DType)()(x)
6071
+ x_dtype = dtype_(x)
5745
6072
  if not isinstance(x, (Tensor, Tensor_)):
5746
6073
  raise TypeError("For adaptive_avg_pool1d, the input input must be tensor")
5747
6074
 
@@ -5761,24 +6088,203 @@ def adaptive_avg_pool1d(input, output_size):
5761
6088
 
5762
6089
  _check(input, output_size)
5763
6090
  x_in_shape = input.shape
5764
- expand_ = _get_cache_prim(P.ExpandDims)()
5765
6091
  squeeze_ = _get_cache_prim(P.Squeeze)(2)
5766
-
5767
6092
  width = x_in_shape[2]
5768
6093
  stride = width // output_size
5769
6094
  kernel_size = width - (output_size - 1) * stride
5770
6095
  stride = (1, width // output_size)
5771
6096
  kernel_size = (1, kernel_size)
5772
-
5773
6097
  avg_pool_ = _get_cache_prim(P.AvgPool)(kernel_size=kernel_size, strides=stride)
5774
-
5775
- input = expand_(input, 2)
6098
+ input = expand_dims_(input, 2)
5776
6099
  input = avg_pool_(input)
5777
6100
  input = squeeze_(input)
5778
-
5779
6101
  return input
5780
6102
 
5781
6103
 
6104
+ def layer_norm(input, normalized_shape, weight=None, bias=None, eps=1e-5):
6105
+ r"""Applies the Layer Normalization on the mini-batch input.
6106
+
6107
+ Layer normalization is widely used in recurrent neural networks. Apply normalization to the mini-batch
6108
+ input of a single training case. LayerNorm is described in the paper
6109
+ `Layer Normalization <https://arxiv.org/abs/1607.06450>`_.
6110
+
6111
+ Unlike batch normalization, layer normalization performs the exact same calculations at training and
6112
+ test time. Applies to all channels and pixels, even batch_size=1. The formula is as follows:
6113
+
6114
+ .. math::
6115
+ y = \frac{x - \mathrm{E}[x]}{\sqrt{\mathrm{Var}[x] + \epsilon}} * \gamma + \beta
6116
+
6117
+ where :math:`\gamma` is the weight value learned through training, :math:`\beta` is the bias value
6118
+ learned through training.
6119
+
6120
+ Args:
6121
+ input (Tensor): The shape of input is `(N, *)`, where `*` represents any additional dimension.
6122
+ normalized_shape (Union(int, tuple[int], list[int])): The normalized shape of `input` for LayerNorm.
6123
+ `normalized_shape` equal to `input_shape[begin_norm_axis:]`, where `begin_norm_axis` represents the axis
6124
+ where normalization begins.
6125
+ weight (Tensor, optional): Learnable parameter :math:`\gamma` . Tensor of shape `normalized_shape`.
6126
+ Default: ``None``, has the same data type with `input`. Initialized to ``1`` when `weight` is None.
6127
+ bias (Tensor, optional): Learnable parameter :math:`\beta` . Tensor of shape `normalized_shape`.
6128
+ Default: ``None``, has the same data type with `input`. Initialized to ``0`` when `bias` is None.
6129
+ eps (float, optional): A value added to the denominator for numerical stability(:math:`\epsilon`).
6130
+ Default: ``1e-5`` .
6131
+
6132
+ Returns:
6133
+ Tensor. The normalized tensor, has the same type and shape as the `input`.
6134
+
6135
+ Raises:
6136
+ TypeError: If `input` is not a Tensor.
6137
+ TypeError: If `normalized_shape` is not an integer, a list or a tuple.
6138
+ TypeError: If `eps` is not a float.
6139
+
6140
+ Supported Platforms:
6141
+ ``Ascend``
6142
+
6143
+ Examples:
6144
+ >>> import mindspore
6145
+ >>> import numpy as np
6146
+ >>> from mindspore import Tensor, ops
6147
+ >>> input_x = Tensor(np.array([[1, 2, 3], [1, 2, 3]]), mindspore.float32)
6148
+ >>> normalized_shape = (3,)
6149
+ >>> gamma = Tensor(np.ones(normalized_shape), mindspore.float32)
6150
+ >>> beta = Tensor(np.zeros(normalized_shape), mindspore.float32)
6151
+ >>> eps = 1e-7
6152
+ >>> output = ops.layer_norm(input_x, normalized_shape, gamma, beta, eps)
6153
+ >>> print(output)
6154
+ [[-1.2247448 0. 1.2247448]
6155
+ [-1.2247448 0. 1.2247448]]
6156
+ """
6157
+ if weight is None:
6158
+ weight = ops.ones(normalized_shape, dtype=input.dtype)
6159
+ if bias is None:
6160
+ bias = ops.zeros(normalized_shape, dtype=input.dtype)
6161
+ return layer_norm_ext_op(input, normalized_shape, weight, bias, eps)[0]
6162
+
6163
+
6164
+ def group_norm(input, num_groups, weight=None, bias=None, eps=1e-5):
6165
+ r"""Group Normalization over a mini-batch of inputs.
6166
+
6167
+ Group Normalization is widely used in recurrent neural networks. It applies
6168
+ normalization on a mini-batch of inputs for each single training case as described
6169
+ in the paper `Group Normalization <https://arxiv.org/pdf/1803.08494.pdf>`_. Group Normalization
6170
+ divides the channels into groups and computes within each group the mean and variance for normalization,
6171
+ and it performs very stable over a wide range of batch size. :math:`\gamma` and :math:`\beta` are trainable scale
6172
+ and shift.
6173
+ It can be described using the following formula:
6174
+
6175
+ .. math::
6176
+ y = \frac{x - \mathrm{E}[x]}{\sqrt{\mathrm{Var}[x] + \epsilon}} * \gamma + \beta
6177
+
6178
+ where :math:`\gamma` is `weight`, :math:`\beta` is `bias`, :math:`\epsilon` is `eps`.
6179
+
6180
+ Args:
6181
+ input (Tensor): The input feature with shape :math:`(N, C, *)` where :math:`*` means, any number of
6182
+ additional dimensions.
6183
+ num_groups (int): The number of groups to be divided along the channel dimension.
6184
+ weight (Tensor, optional): The shape :math:`(C,)`, Default: ``None``, has the same data type with `input`.
6185
+ bias (Tensor, optional): The shape :math:`(C,)`, Default: ``None``, has the same data type with `input`.
6186
+ eps (float, optional): A value added to the denominator for numerical stability. Default: ``1e-5`` .
6187
+
6188
+ Returns:
6189
+ Tensor, the normalized and scaled offset tensor, has the same shape and data type as the `input`.
6190
+
6191
+ Raises:
6192
+ TypeError: If `num_groups` is not an int.
6193
+ TypeError: If `eps` is not a float.
6194
+ ValueError: If `num_groups` is less than 1.
6195
+ ValueError: If `C` (the second parameter of dimensions of `input`) is not divided by `num_groups`.
6196
+
6197
+ Supported Platforms:
6198
+ ``Ascend`` ``GPU`` ``CPU``
6199
+
6200
+ Examples:
6201
+ >>> import mindspore as ms
6202
+ >>> import numpy as np
6203
+ >>> from mindspore import ops
6204
+ >>> x = ms.Tensor(np.ones([1, 2, 4, 4], np.float32))
6205
+ >>> output = ops.group_norm(x, 2)
6206
+ >>> print(output)
6207
+ [[[[0. 0. 0. 0.]
6208
+ [0. 0. 0. 0.]
6209
+ [0. 0. 0. 0.]
6210
+ [0. 0. 0. 0.]]
6211
+ [[0. 0. 0. 0.]
6212
+ [0. 0. 0. 0.]
6213
+ [0. 0. 0. 0.]
6214
+ [0. 0. 0. 0.]]]]
6215
+ """
6216
+ if weight is None:
6217
+ weight = ops.ones([input.shape[1]], dtype=input.dtype)
6218
+ if bias is None:
6219
+ bias = ops.zeros([input.shape[1]], dtype=input.dtype)
6220
+ return group_norm_op(input, num_groups, weight, bias, eps)[0]
6221
+
6222
+
6223
+ def batch_norm_ext(input, running_mean, running_var, weight=None, bias=None, training=False, momentum=0.1, eps=1e-5):
6224
+ r"""
6225
+ Batch Normalization for input data and updated parameters.
6226
+
6227
+ Batch Normalization is widely used in convolutional neural networks. This operation
6228
+ applies Batch Normalization over inputs to avoid internal covariate shift as described
6229
+ in the paper `Batch Normalization: Accelerating Deep Network Training by Reducing Internal
6230
+ Covariate Shift <https://arxiv.org/abs/1502.03167>`_. It rescales and recenters the
6231
+ features using a mini-batch of data and the learned parameters can be described
6232
+ in the following formula,
6233
+
6234
+ .. math::
6235
+
6236
+ y = \frac{x - mean}{\sqrt{variance + \epsilon}} * \gamma + \beta
6237
+
6238
+ where :math:`\gamma` is `weight`, :math:`\beta` is `bias`, :math:`\epsilon` is `eps`, :math:`mean` is the
6239
+ mean of :math:`x`, :math:`variance` is the variance of :math:`x`.
6240
+
6241
+ Args:
6242
+ input (Tensor): Tensor of shape :math:`(N, C, *)`, with bfloat16, float16 or float32 data type.
6243
+ For Atlas training products, the shape must be 2-4 dimensions currently.
6244
+ running_mean (Tensor): The shape :math:`(C,)`, with bfloat, float16 or float32 data type.
6245
+ running_var (Tensor): The shape :math:`(C,)`, with bfloat, float16 or float32 data type.
6246
+ weight (Tensor, optional): The shape :math:`(C,)`, with bfloat, float16 or float32 data type, Default: ``None``.
6247
+ Initialized to ``1`` when `weight` is None.
6248
+ bias (Tensor, optional): The shape :math:`(C,)`, with bfloat, float16 or float32 data type. Default: ``None``.
6249
+ Initialized to ``0`` when `weight` is None.
6250
+ training (bool, optional): If `training` is `True`, `mean` and `variance` are computed during training.
6251
+ If `training` is `False`, they're loaded from checkpoint during inference. Default: ``False`` .
6252
+ momentum (float, optional): The hyper parameter to compute moving average for `running_mean` and `running_var`
6253
+ (e.g. :math:`new\_running\_mean = (1 - momentum) * running\_mean + momentum * current\_mean`).
6254
+ Default: ``0.1`` .
6255
+ eps (float, optional): A small value added for numerical stability. Default: ``1e-5``.
6256
+
6257
+ Returns:
6258
+ Tensor, has the same type and shape as `input`. The shape is :math:`(N, C, *)`.
6259
+
6260
+ Raises:
6261
+ TypeError: If `training` is not a bool.
6262
+ TypeError: If dtype of `eps` or `momentum` is not float.
6263
+ TypeError: If `input`, `weight`, `bias`, `running_mean` or `running_var` is not a Tensor.
6264
+
6265
+ Supported Platforms:
6266
+ ``Ascend``
6267
+
6268
+ Examples:
6269
+ >>> import mindspore
6270
+ >>> from mindspore import Tensor, ops
6271
+ >>> input_x = Tensor([[1.0, 2.0], [3.0, 4.0]], mindspore.float32)
6272
+ >>> running_mean = Tensor([0.5, 1.5], mindspore.float32)
6273
+ >>> running_var = Tensor([0.1, 0.2], mindspore.float32)
6274
+ >>> weight = Tensor([2.0, 2.0], mindspore.float32)
6275
+ >>> bias = Tensor([-1.0, -1.0], mindspore.float32)
6276
+ >>> output = ops.function.nn_func.batch_norm_ext(input_x, running_mean, running_var, weight, bias)
6277
+ >>> print(output)
6278
+ [[ 2.1621194 1.2360122]
6279
+ [14.810596 10.180061 ]]
6280
+ """
6281
+ if weight is None:
6282
+ weight = ops.ones([input.shape[1]], dtype=input.dtype)
6283
+ if bias is None:
6284
+ bias = ops.zeros([input.shape[1]], dtype=input.dtype)
6285
+ output = batch_norm_ext_op(input, weight, bias, running_mean, running_var, training, momentum, eps)
6286
+ return output[0]
6287
+
5782
6288
  def batch_norm(input_x, running_mean, running_var, weight, bias, training=False, momentum=0.1, eps=1e-5):
5783
6289
  r"""
5784
6290
  Batch Normalization for input data and updated parameters.
@@ -5798,7 +6304,8 @@ def batch_norm(input_x, running_mean, running_var, weight, bias, training=False,
5798
6304
  mean of :math:`x`, :math:`variance` is the variance of :math:`x`.
5799
6305
 
5800
6306
  .. warning::
5801
- - For Ascend 310, the result accuracy fails to reach 1‰ due to the square root instruction.
6307
+ - For Atlas 200/300/500 inference product,
6308
+ the result accuracy fails to reach 1‰ due to the square root instruction.
5802
6309
 
5803
6310
  Note:
5804
6311
  - If `training` is `False`, `weight`, `bias`, `running_mean` and `running_var` are Tensors.
@@ -5915,6 +6422,7 @@ def binary_cross_entropy(logits, labels, weight=None, reduction='mean'):
5915
6422
  Args:
5916
6423
  logits (Tensor): The predictive value whose data type must be float16 or float32.
5917
6424
  labels (Tensor): The target value which has the same shape and data type as `logits`.
6425
+ And the data type is float16 or float32.
5918
6426
  weight (Tensor, optional): A rescaling weight applied to the loss of each batch element.
5919
6427
  Its shape must be able to broadcast to that of `logits` and `labels`.
5920
6428
  And it must have the same shape and data type as `logits`. Default: ``None`` . If set to ``None`` ,
@@ -5960,7 +6468,7 @@ def conv3d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
5960
6468
  r"""
5961
6469
  Applies a 3D convolution over an input tensor. The input tensor is typically of
5962
6470
  shape :math:`(N, C_{in}, D_{in}, H_{in}, W_{in})`, where :math:`N` is batch size, :math:`C`
5963
- is channel number, :math:`D` is feature depth, :math:`H` is feature height, :math:`W` is feature width.
6471
+ is channel number, :math:`D, H, W` are the depth, height and width of the feature graph, respectively.
5964
6472
 
5965
6473
  The output is calculated based on formula:
5966
6474
 
@@ -5970,26 +6478,30 @@ def conv3d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
5970
6478
  \sum_{k = 0}^{C_{in} - 1} \text{ccor}({\text{weight}(C_{\text{out}_j}, k), \text{X}(N_i, k)})
5971
6479
 
5972
6480
  where :math:`bias` is the output channel bias, :math:`ccor` is
5973
- the `cross-correlation <https://en.wikipedia.org/wiki/Cross-correlation>`_,
6481
+ the `cross-correlation <https://en.wikipedia.org/wiki/Cross-correlation>`_
5974
6482
  , :math:`weight` is the convolution kernel value and :math:`X` represents the input feature map.
5975
6483
 
5976
6484
  Here are the indices' meanings:
5977
- - :math:`i` corresponds to the batch number, ranging from 0 to N-1, where N is the batch size of the input.
5978
6485
 
5979
- - :math:`j` corresponds to the output channel, ranging from 0 to C_{out}-1, where C_{out} is the number of
6486
+ - :math:`i` corresponds to the batch number, the range is :math:`[0, N-1]`,
6487
+ where :math:`N` is the batch size of the input.
6488
+
6489
+ - :math:`j` corresponds to the output channel, the range is :math:`[0, C_{out}-1]`,
6490
+ where :math:`C_{out}` is the number of
5980
6491
  output channels, which is also equal to the number of kernels.
5981
6492
 
5982
- - :math:`k` corresponds to the input channel, ranging from 0 to C_{in}-1, where C_{in} is the number of
6493
+ - :math:`k` corresponds to the input channel, the range is :math:`[0, C_{in}-1]`,
6494
+ where :math:`C_{in}` is the number of
5983
6495
  input channels, which is also equal to the number of channels in the convolutional kernels.
5984
6496
 
5985
- Therefore, in the above formula, :math:`{bias}(C_{out_j})` represents the bias of the :math:`j`-th
5986
- output channel, :math:`{weight}(C_{out_j}, k)` represents the slice of the :math:`j`-th convolutional
6497
+ Therefore, in the above formula, :math:`{bias}(C_{\text{out}_j})` represents the bias of the :math:`j`-th
6498
+ output channel, :math:`{weight}(C_{\text{out}_j}, k)` represents the slice of the :math:`j`-th convolutional
5987
6499
  kernel in the :math:`k`-th channel, and :math:`{X}(N_i, k)` represents the slice of the :math:`k`-th input
5988
6500
  channel in the :math:`i`-th batch of the input feature map.
5989
6501
 
5990
6502
  The shape of the convolutional kernel is given by
5991
6503
  :math:`(\text{kernel_size[0]}, \text{kernel_size[1]}, \text{kernel_size[2]})`
5992
- where :math:`kernel\_size[0]` , :math:`kernel\_size[1]` and :math:`kernel\_size[2]` are the depth,
6504
+ where :math:`\text{kernel_size[0]}` , :math:`\text{kernel_size[1]}` and :math:`\text{kernel_size[2]}` are the depth,
5993
6505
  height and width of the kernel, respectively.
5994
6506
  If we consider the input and output channels as well as the `group` parameter, the complete kernel shape
5995
6507
  will be :math:`(C_{out}, C_{in} / \text{group}, \text{kernel_size[0]},
@@ -6000,8 +6512,8 @@ def conv3d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
6000
6512
  <http://vision.stanford.edu/cs598_spring07/papers/Lecun98.pdf>`_.
6001
6513
 
6002
6514
  Note:
6003
- 1. On Ascend platform, `groups = 1` must be satisfied.
6004
- 2. On Ascend dilation on depth only supports the case of 1.
6515
+ 1. On Ascend platform, :math:`groups = 1` must be satisfied.
6516
+ 2. On Ascend platform, :math:`dilation=1` must be satisfied.
6005
6517
 
6006
6518
  Args:
6007
6519
  input (Tensor): Tensor of shape :math:`(N, C_{in}, D_{in}, H_{in}, W_{in})`.
@@ -6040,8 +6552,7 @@ def conv3d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
6040
6552
  there will be :math:`k - 1` pixels skipped for each sampling location.
6041
6553
  The value ranges for the depth, height, and width dimensions are [1, D], [1, H], and [1, W],
6042
6554
  respectively. Default: ``1`` .
6043
- groups (int, optional):The number of groups into which the filter is divided. `in_channels`
6044
- and `out_channels` must be divisible by `group`. Default: ``1`` .
6555
+ groups (int, optional):The number of groups into which the filter is divided. Default: ``1`` .
6045
6556
 
6046
6557
  Returns:
6047
6558
  Tensor, the value that applied 3D convolution. The shape is :math:`(N, C_{out}, D_{out}, H_{out}, W_{out})`.
@@ -6083,7 +6594,7 @@ def conv3d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
6083
6594
  TypeError: If `out_channel` or `groups` is not an int.
6084
6595
  TypeError: If `stride`, `padding` or `dilation` is neither an int nor a tuple.
6085
6596
  TypeError: If `bias` is not a Tensor.
6086
- ValueError: If the shape of `bias` is not :math:`C_{out}`.
6597
+ ValueError: If the shape of `bias` is not :math:`(C_{out})`.
6087
6598
  ValueError: If `stride` or `dilation` is less than 1.
6088
6599
  ValueError: If `pad_mode` is not one of 'same', 'valid' or 'pad'.
6089
6600
  ValueError: If `padding` is a tuple or list whose length is not equal to 3.
@@ -6191,21 +6702,19 @@ def pixel_shuffle(input, upscale_factor):
6191
6702
  _check_positive_int(upscale_factor, "upscale_factor")
6192
6703
  _check_is_tensor("input", input, "pixel_shuffle")
6193
6704
  _check_pixel_shuffle_unshuffle_input_shape(input, "pixel_shuffle")
6194
- idx = P.Shape()(input)
6705
+ idx = shape_(input)
6195
6706
  length = input.ndim
6196
6707
  pre = idx[:-3]
6197
6708
  c, h, w = idx[-3:]
6198
6709
  _check_pxiel_shuffle_valid(c, upscale_factor)
6199
6710
  c = c // upscale_factor ** 2
6200
6711
  input_perm = (pre + (c, upscale_factor, upscale_factor, h, w))
6201
- reshape = _get_cache_prim(P.Reshape)()
6202
- transpose = _get_cache_prim(P.Transpose)()
6203
- input = reshape(input, input_perm)
6712
+ input = reshape_(input, input_perm)
6204
6713
  input_perm = [i for i in range(length - 2)]
6205
6714
  input_perm = input_perm + [length, length - 2, length + 1, length - 1]
6206
6715
  input_perm = tuple(input_perm)
6207
- input = transpose(input, input_perm)
6208
- input = reshape(input, (pre + (c, upscale_factor * h, upscale_factor * w)))
6716
+ input = transpose_(input, input_perm)
6717
+ input = reshape_(input, (pre + (c, upscale_factor * h, upscale_factor * w)))
6209
6718
  return input
6210
6719
 
6211
6720
 
@@ -6256,7 +6765,7 @@ def pixel_unshuffle(input, downscale_factor):
6256
6765
  _check_positive_int(downscale_factor, "downscale_factor")
6257
6766
  _check_is_tensor("input", input, "pixel_unshuffle")
6258
6767
  _check_pixel_shuffle_unshuffle_input_shape(input, "pixel_unshuffle")
6259
- idx = P.Shape()(input)
6768
+ idx = shape_(input)
6260
6769
  length = input.ndim
6261
6770
  pre = idx[:-3]
6262
6771
  c, h, w = idx[-3:]
@@ -6264,14 +6773,12 @@ def pixel_unshuffle(input, downscale_factor):
6264
6773
  h = h // downscale_factor
6265
6774
  w = w // downscale_factor
6266
6775
  input_perm = (pre + (c, h, downscale_factor, w, downscale_factor))
6267
- reshape = _get_cache_prim(P.Reshape)()
6268
- transpose = _get_cache_prim(P.Transpose)()
6269
- input = reshape(input, input_perm)
6776
+ input = reshape_(input, input_perm)
6270
6777
  input_perm = [i for i in range(length - 2)]
6271
6778
  input_perm = input_perm + [length - 1, length + 1, length - 2, length]
6272
6779
  input_perm = tuple(input_perm)
6273
- input = transpose(input, input_perm)
6274
- input = reshape(input, (pre + (c * downscale_factor * downscale_factor, h, w)))
6780
+ input = transpose_(input, input_perm)
6781
+ input = reshape_(input, (pre + (c * downscale_factor * downscale_factor, h, w)))
6275
6782
  return input
6276
6783
 
6277
6784
 
@@ -6288,7 +6795,7 @@ def glu(x, axis=-1):
6288
6795
  See `Language Modeling with Gated Convluational Networks <https://arxiv.org/abs/1612.08083>`_.
6289
6796
 
6290
6797
  Args:
6291
- x (Tensor): Tensor to be splited. Its dtype is Number, and shape is :math:`(\ast_1, N, \ast_2)`
6798
+ x (Tensor): Tensor to be split. Its dtype is Number, and shape is :math:`(\ast_1, N, \ast_2)`
6292
6799
  where `*` means, any number of additional dimensions.
6293
6800
  axis (int, optional): the axis to split the input. It must be int. Default: ``-1`` , the last axis of `x`.
6294
6801
 
@@ -6310,9 +6817,6 @@ def glu(x, axis=-1):
6310
6817
  [[0.05744425 0.11973753]
6311
6818
  [0.33409387 0.41398472]]
6312
6819
  """
6313
- if not isinstance(x, Tensor) or x.size == 0:
6314
- raise TypeError("glu does not support scalars because halving size must be even")
6315
-
6316
6820
  spilt = _get_cache_prim(P.Split)(axis=axis, output_num=2)
6317
6821
  x, y = spilt(x)
6318
6822
  y = sigmoid_(y)
@@ -6332,7 +6836,7 @@ def multi_margin_loss(input, target, p=1, margin=1, weight=None, reduction='mean
6332
6836
  .. math::
6333
6837
  \text{loss}(x, y) = \frac{\sum_i \max(0, \text{margin} - x[y] + x[i])^p}{\text{x.size}(0)}
6334
6838
 
6335
- where :math:`i\in \{0,⋯,x.size(0)1\}` and :math:`i \ne y`.
6839
+ where :math:`i\in \{0,⋯,x.size(0)-1\}` and :math:`i \ne y`.
6336
6840
 
6337
6841
  Args:
6338
6842
  input (Tensor): Input , with shape :math:`(N, C)`. Data type only support float32, float16 or float64.
@@ -6351,8 +6855,8 @@ def multi_margin_loss(input, target, p=1, margin=1, weight=None, reduction='mean
6351
6855
  - ``'sum'``: the output elements will be summed.
6352
6856
 
6353
6857
  Returns:
6354
- Tensor. If `reduction` is ``'none'``, returns a Tensor with the same shape as `target`.
6355
- Otherwise, it is a scalar.
6858
+ - **outputs** - Tensor. If `reduction` is ``'none'``, returns a Tensor with the same shape as `target`.
6859
+ Otherwise, it is a scalar.
6356
6860
 
6357
6861
  Raises:
6358
6862
  TypeError: If dtype of `p` or `target` is not int.
@@ -6411,10 +6915,11 @@ def multilabel_margin_loss(input, target, reduction='mean'):
6411
6915
  This allows for different samples to have variable amounts of target classes.
6412
6916
 
6413
6917
  Args:
6414
- input (Tensor): Predict data. Tensor of shape :math:`(C)` or :math:`(N, C)`, where :math:`N`
6415
- is the batch size and :math:`C` is the number of classes. Data type must be float16 or float32.
6416
- target (Tensor): Ground truth data, with the same shape as `input`, data type must be int32 and
6417
- label targets padded by -1.
6918
+ input (Tensor): Predict data, :math:`x` in the formula above. Tensor of shape :math:`(C)`
6919
+ or :math:`(N, C)`, where :math:`N` is the batch size and :math:`C` is the number of classes.
6920
+ Data type must be float16 or float32.
6921
+ target (Tensor): Ground truth data, :math:`y` in the formula above, with the same shape as `input`,
6922
+ data type must be int32 and label targets padded by -1.
6418
6923
  reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
6419
6924
  ``'sum'`` . Default: ``'mean'`` .
6420
6925
 
@@ -6490,9 +6995,6 @@ def multilabel_soft_margin_loss(input, target, weight=None, reduction='mean'):
6490
6995
  Tensor, the data type is the same as input, if the `reduction` is ``'none'``,
6491
6996
  its shape is :math:`(N)` , otherwise it is zero.
6492
6997
 
6493
- Raises:
6494
- ValueError: If the rank of `input` or `target` is not 2.
6495
-
6496
6998
  Supported Platforms:
6497
6999
  ``Ascend`` ``GPU`` ``CPU``
6498
7000
 
@@ -6507,81 +7009,22 @@ def multilabel_soft_margin_loss(input, target, weight=None, reduction='mean'):
6507
7009
  cls_name = "multilabel_soft_margin_loss"
6508
7010
  _check_is_tensor('input', input, cls_name)
6509
7011
  _check_is_tensor('target', target, cls_name)
6510
- if input.ndim != 2 or target.ndim != 2:
6511
- raise ValueError(
6512
- "For 'MultiLabelSoftMarginLoss', the inputs must be 2d tensor, but got dims: "
6513
- f"input: {input.ndim}, target: {target.ndim} "
6514
- )
6515
7012
 
6516
- mul_op = _get_cache_prim(P.Mul)()
6517
- exp_op = _get_cache_prim(P.Exp)()
6518
- add_op = _get_cache_prim(P.Add)()
6519
- log_op = _get_cache_prim(P.Log)()
6520
- dyn_shape = _get_cache_prim(P.TensorShape)()
6521
7013
  input_shape = input.shape
6522
7014
  if ops.is_sequence_value_unknown(input_shape):
6523
- input_shape = dyn_shape(input)
7015
+ input_shape = tensor_shape_(input)
6524
7016
 
6525
- pos = log_op(add_op(exp_op(-input), 1))
6526
- neg = log_op(add_op(exp_op(input), 1))
6527
- loss = mul_op(target, pos) + mul_op(1 - target, neg)
7017
+ pos = log_(add_(exp_(-input), 1))
7018
+ neg = log_(add_(exp_(input), 1))
7019
+ loss = mul_(target, pos) + mul_(1 - target, neg)
6528
7020
  if weight is not None:
6529
- loss = mul_op(loss, weight)
7021
+ loss = mul_(loss, weight)
6530
7022
  class_dim = input.ndim - 1
6531
7023
  loss = loss.sum(axis=class_dim) / input_shape[class_dim]
6532
7024
  return _get_loss(loss, reduction, cls_name)
6533
7025
 
6534
7026
 
6535
- def elu(input_x, alpha=1.0):
6536
- r"""
6537
- Exponential Linear Unit activation function.
6538
-
6539
- Applies the exponential linear unit function element-wise.
6540
- The activation function is defined as:
6541
-
6542
- .. math::
6543
-
6544
- \text{ELU}(x)= \left\{
6545
- \begin{array}{align}
6546
- \alpha(e^{x} - 1) & \text{if } x \le 0\\
6547
- x & \text{if } x \gt 0\\
6548
- \end{array}\right.
6549
-
6550
- Where :math:`x` is the element of input Tensor `input_x`, :math:`\alpha` is param `alpha`,
6551
- it determines the smoothness of ELU.
6552
- The picture about ELU looks like this `ELU <https://en.wikipedia.org/wiki/
6553
- Activation_function#/media/File:Activation_elu.svg>`_ .
6554
-
6555
- Args:
6556
- input_x (Tensor): The input of ELU is a Tensor of any dimension with data type of float16 or float32.
6557
- alpha (float, optional): The alpha value of ELU, the data type is float. Only support '1.0' currently.
6558
- Default: ``1.0`` .
6559
-
6560
- Returns:
6561
- Tensor, has the same shape and data type as `input_x`.
6562
-
6563
- Raises:
6564
- TypeError: If `alpha` is not a float.
6565
- TypeError: If dtype of `input_x` is neither float16 nor float32.
6566
- ValueError: If `alpha` is not equal to 1.0.
6567
-
6568
- Supported Platforms:
6569
- ``Ascend`` ``GPU`` ``CPU``
6570
-
6571
- Examples:
6572
- >>> import mindspore
6573
- >>> import numpy as np
6574
- >>> from mindspore import Tensor, ops
6575
- >>> x = Tensor(np.array([[-1.0, 4.0, -8.0], [2.0, -5.0, 9.0]]), mindspore.float32)
6576
- >>> output = ops.elu(x)
6577
- >>> print(output)
6578
- [[-0.63212055 4. -0.99966455]
6579
- [ 2. -0.99326205 9. ]]
6580
- """
6581
- return _get_cache_prim(P.Elu)(alpha=alpha)(input_x)
6582
-
6583
-
6584
- def gelu(input_x, approximate='none'):
7027
+ def gelu(input, approximate='none'):
6585
7028
  r"""
6586
7029
  Gaussian Error Linear Units activation function.
6587
7030
 
@@ -6602,18 +7045,23 @@ def gelu(input_x, approximate='none'):
6602
7045
  .. math::
6603
7046
  GELU(x_i) = 0.5 * x_i * (1 + \tanh(\sqrt(2 / \pi) * (x_i + 0.044715 * x_i^3)))
6604
7047
 
7048
+ GELU Activation Function Graph:
7049
+
7050
+ .. image:: ../images/GELU.png
7051
+ :align: center
7052
+
6605
7053
  Args:
6606
- input_x (Tensor): The input of the activation function GeLU, the data type is float16, float32 or float64.
7054
+ input (Tensor): The input of the activation function GeLU, the data type is float16, float32 or float64.
6607
7055
  approximate (str): the gelu approximation algorithm to use. Acceptable vaslues are ``'none'`` and ``'tanh'`` .
6608
7056
  Default: ``'none'`` .
6609
7057
 
6610
7058
  Returns:
6611
- Tensor, with the same type and shape as `input_x`.
7059
+ Tensor, with the same type and shape as `input`.
6612
7060
 
6613
7061
  Raises:
6614
- TypeError: If `input_x` is not a Tensor.
6615
- TypeError: If dtype of `input_x` is not float16, float32 or float64.
6616
- ValueError: If `approximate` value is neither `none` or `tanh`.
7062
+ TypeError: If `input` is not a Tensor.
7063
+ TypeError: If dtype of `input` is not bfloat16, float16, float32 or float64.
7064
+ ValueError: If `approximate` value is neither `none` nor `tanh`.
6617
7065
 
6618
7066
  Supported Platforms:
6619
7067
  ``Ascend`` ``GPU`` ``CPU``
@@ -6624,22 +7072,22 @@ def gelu(input_x, approximate='none'):
6624
7072
  >>> x = Tensor([1.0, 2.0, 3.0], mindspore.float32)
6625
7073
  >>> result = ops.gelu(x)
6626
7074
  >>> print(result)
6627
- [0.841192 1.9545976 2.9963627]
7075
+ [0.8413447 1.9544997 2.9959505]
6628
7076
  """
6629
7077
  if approximate not in ['none', 'tanh']:
6630
7078
  raise ValueError("For ops.gelu, approximate value should be either 'none' or 'tanh'.")
6631
7079
 
6632
- x_dtype = _get_cache_prim(P.DType)()(input_x)
6633
- if x_dtype not in [mstype.float16, mstype.float32, mstype.float64]:
7080
+ x_dtype = dtype_(input)
7081
+ if x_dtype not in [mstype.float16, mstype.float32, mstype.float64, mstype.bfloat16]:
6634
7082
  raise TypeError(f"For gelu, the input dtype must be float16, float32 or float64, "
6635
7083
  f"but got {x_dtype}.")
6636
7084
  if approximate == 'tanh':
6637
- output = _get_cache_prim(P.GeLU)()(input_x)
7085
+ output = gelu_(input)
6638
7086
  else:
6639
- output = _get_cache_prim(P.Sqrt)()(Tensor(2.0, x_dtype))
6640
- output = _get_cache_prim(P.Div)()(input_x, output)
6641
- output = _get_cache_prim(P.Erf)()(output) + Tensor(1.0, x_dtype)
6642
- output = input_x * output * Tensor(0.5, x_dtype)
7087
+ output = sqrt_(Tensor(2.0, x_dtype))
7088
+ output = div_(input, output)
7089
+ output = erf_(output) + Tensor(1.0, x_dtype)
7090
+ output = input * output * Tensor(0.5, x_dtype)
6643
7091
 
6644
7092
  return output
6645
7093
 
@@ -6689,13 +7137,6 @@ def channel_shuffle(x, groups):
6689
7137
  return y
6690
7138
 
6691
7139
 
6692
- @_primexpr
6693
- def _shape_check(in_shape, dim_list, prim_name=None):
6694
- msg_prefix = f"For '{prim_name}', the" if prim_name else "The"
6695
- if len(in_shape) not in dim_list:
6696
- raise ValueError(f"{msg_prefix} input must has dim in {dim_list}, but got {len(in_shape)}")
6697
-
6698
-
6699
7140
  def lp_pool1d(x, norm_type, kernel_size, stride=None, ceil_mode=False):
6700
7141
  r"""
6701
7142
  Applying 1D LPPooling operation on an input Tensor can be regarded as forming a 1D input plane.
@@ -6731,7 +7172,7 @@ def lp_pool1d(x, norm_type, kernel_size, stride=None, ceil_mode=False):
6731
7172
  L_{out} = \left\lfloor\frac{L_{in} - \text{kernel_size}}{\text{stride}} + 1\right\rfloor
6732
7173
 
6733
7174
  Raises:
6734
- TypeError: If `x` is not an Tensor.
7175
+ TypeError: If `x` is not a Tensor.
6735
7176
  TypeError: If `kernel_size` or `stride` is not an int.
6736
7177
  TypeError: If `ceil_mode` is not a bool.
6737
7178
  TypeError: If `norm_type` is neither float nor int.
@@ -6744,7 +7185,7 @@ def lp_pool1d(x, norm_type, kernel_size, stride=None, ceil_mode=False):
6744
7185
 
6745
7186
  Examples:
6746
7187
  >>> import mindspore as ms
6747
- >>> import mindspore.ops as ops
7188
+ >>> from mindspore import ops
6748
7189
  >>> from mindspore import Tensor
6749
7190
  >>> import numpy as np
6750
7191
  >>> x = Tensor(np.arange(2 * 3 * 4).reshape((2, 3, 4)), dtype=ms.float32)
@@ -6757,7 +7198,6 @@ def lp_pool1d(x, norm_type, kernel_size, stride=None, ceil_mode=False):
6757
7198
  [51. 54.]
6758
7199
  [63. 66.]]]
6759
7200
  """
6760
- _shape_check(x.shape, [2, 3], "lp_pool1d")
6761
7201
  if isinstance(norm_type, (float, int)):
6762
7202
  norm_type = float(norm_type)
6763
7203
  else:
@@ -6816,7 +7256,7 @@ def lp_pool2d(x, norm_type, kernel_size, stride=None, ceil_mode=False):
6816
7256
  W_{out} = \left\lfloor\frac{W_{in} - \text{kernel_size}[1]}{\text{stride}[1]} + 1\right\rfloor
6817
7257
 
6818
7258
  Raises:
6819
- TypeError: If `x` is not an Tensor.
7259
+ TypeError: If `x` is not a Tensor.
6820
7260
  TypeError: If `kernel_size` or `stride` is neither int nor tuple.
6821
7261
  TypeError: If `ceil_mode` is not a bool.
6822
7262
  TypeError: If `norm_type` is neither float nor int.
@@ -6830,7 +7270,7 @@ def lp_pool2d(x, norm_type, kernel_size, stride=None, ceil_mode=False):
6830
7270
 
6831
7271
  Examples:
6832
7272
  >>> import mindspore as ms
6833
- >>> import mindspore.ops as ops
7273
+ >>> from mindspore import ops
6834
7274
  >>> from mindspore import Tensor
6835
7275
  >>> import numpy as np
6836
7276
  >>> x = Tensor(np.arange(2 * 3 * 4 * 5).reshape((2, 3, 4, 5)), dtype=ms.float32)
@@ -6850,7 +7290,6 @@ def lp_pool2d(x, norm_type, kernel_size, stride=None, ceil_mode=False):
6850
7290
  [ 999. 1008. 1017.]]]]
6851
7291
 
6852
7292
  """
6853
- _shape_check(x.shape, [4], "lp_pool2d")
6854
7293
  if isinstance(norm_type, (float, int)):
6855
7294
  norm_type = float(norm_type)
6856
7295
  else:
@@ -6913,13 +7352,13 @@ def mse_loss(input, target, reduction='mean'):
6913
7352
  if reduction not in ['mean', 'none', 'sum']:
6914
7353
  raise ValueError("For ops.mse_loss, `reduction` value should be either 'mean', 'none' or 'sum'.")
6915
7354
 
6916
- x = _get_cache_prim(P.Square)()(input - target)
7355
+ x = square_(input - target)
6917
7356
  float_type = (mstype.float16, mstype.float32, mstype.float64)
6918
7357
  if x.dtype not in float_type:
6919
7358
  input_dtype = mstype.float32
6920
7359
  else:
6921
7360
  input_dtype = x.dtype
6922
- x = _get_cache_prim(P.Cast)()(x, mstype.float32)
7361
+ x = cast_(x, mstype.float32)
6923
7362
 
6924
7363
  average_flag = True
6925
7364
  reduce_flag = True
@@ -6929,12 +7368,12 @@ def mse_loss(input, target, reduction='mean'):
6929
7368
  reduce_flag = False
6930
7369
 
6931
7370
  if reduce_flag and average_flag:
6932
- x = _get_cache_prim(P.ReduceMean)()(x, _get_axis(x))
7371
+ x = reduce_mean_(x, _get_axis(x))
6933
7372
 
6934
7373
  if reduce_flag and not average_flag:
6935
- x = _get_cache_prim(P.ReduceSum)()(x, _get_axis(x))
7374
+ x = reduce_sum_(x, _get_axis(x))
6936
7375
 
6937
- return _get_cache_prim(P.Cast)()(x, input_dtype)
7376
+ return cast_(x, input_dtype)
6938
7377
 
6939
7378
 
6940
7379
  def msort(input):
@@ -6957,7 +7396,7 @@ def msort(input):
6957
7396
 
6958
7397
  Examples:
6959
7398
  >>> import mindspore as ms
6960
- >>> import mindspore.ops as ops
7399
+ >>> from mindspore import ops
6961
7400
  >>> import numpy as np
6962
7401
  >>> input = ms.Tensor(np.array([[8, 2, 1], [5, 9, 3], [4, 6, 7]]), ms.float16)
6963
7402
  >>> output = ops.msort(input)
@@ -6996,7 +7435,7 @@ def triplet_margin_loss(anchor, positive, negative, margin=1.0, p=2, eps=1e-06,
6996
7435
  Tensor. If `reduction` is ``"none"``, its shape is :math:`(N)`. Otherwise, a scalar value will be returned.
6997
7436
 
6998
7437
  Raises:
6999
- TypeError: If `anchor` or `positive` or 'negative' is not a Tensor.
7438
+ TypeError: If `anchor` or `positive` or `negative` is not a Tensor.
7000
7439
  TypeError: If dtype of `anchor`, `positive` and `negative` is not the same.
7001
7440
  TypeError: If `margin` is not a float.
7002
7441
  TypeError: If `p` is not an int.
@@ -7335,7 +7774,7 @@ def multi_head_attention_forward(query, key, value, embed_dim_to_check, num_head
7335
7774
 
7336
7775
  if attn_mask is not None and attn_mask.dtype == mstype.bool_:
7337
7776
  new_attn_mask = ops.zeros_like(attn_mask, dtype=q.dtype)
7338
- attn_mask = new_attn_mask.masked_fill(attn_mask, float("-inf"))
7777
+ attn_mask = new_attn_mask.masked_fill(attn_mask, ops.cast(float("-inf"), new_attn_mask.dtype))
7339
7778
 
7340
7779
  if attn_mask is not None:
7341
7780
  if attn_mask.shape[0] == 1:
@@ -7444,11 +7883,10 @@ def max_pool2d(x, kernel_size, stride=None, padding=0, dilation=1, return_indice
7444
7883
  return out
7445
7884
 
7446
7885
 
7447
- def prompt_flash_attention(query, key, value, padding_mask, attn_mask, actual_seq_lengths,
7448
- actual_seq_lengths_kv, deq_scale1, quant_scale1,
7449
- deq_scale2, quant_scale2, quant_offset2, num_heads, scale_value=1.0, pre_tokens=2147483547,
7450
- next_tokens=0, input_layout='BSH',
7451
- num_key_value_heads=0, sparse_mode=0):
7886
+ def prompt_flash_attention(query, key, value, attn_mask, actual_seq_lengths, actual_seq_lengths_kv, pse_shift,
7887
+ deq_scale1, quant_scale1, deq_scale2, quant_scale2, quant_offset2, num_heads,
7888
+ scale_value=1.0, pre_tokens=2147483547, next_tokens=0, input_layout='BSH',
7889
+ num_key_value_heads=0, sparse_mode=0, inner_precise=1):
7452
7890
  r"""
7453
7891
  The interface for fully inference.
7454
7892
  B -- Batch size
@@ -7456,7 +7894,7 @@ def prompt_flash_attention(query, key, value, padding_mask, attn_mask, actual_se
7456
7894
  H -- Hidden size
7457
7895
 
7458
7896
  Note:
7459
- is only supported on ascend910B
7897
+ experiment ops
7460
7898
 
7461
7899
  .. warning::
7462
7900
  This is an experimental API that is subject to change or deletion.
@@ -7468,11 +7906,11 @@ def prompt_flash_attention(query, key, value, padding_mask, attn_mask, actual_se
7468
7906
  Input tensor of shape :math:`(B, S, H)` / `(B, N, S, D)`.
7469
7907
  value (Tensor) - The value tensor with data type of float16 or float32.
7470
7908
  Input tensor of shape :math:`(B, S, H)` / `(B, N, S, D)`.
7471
- padding_mask (Tensor) - The padding mask tensor with data type of float16 or float32
7472
7909
  attn_mask (Tensor) - The attention mask tensor with data type of float16 or float32.
7473
7910
  For each element, 0 indicates retention and 1 indicates discard. Input tensor of shape :math:`(B, 1, S, S)`.
7474
- actual_seq_lengths (list[int]): Describe actual sequence length of each input with data type of int.
7475
- actual_seq_lengths_kv (list[int]): Describe actual sequence length of each input with data type of int.
7911
+ actual_seq_lengths (Tensor): Describe actual sequence length of each input with data type of int64.
7912
+ actual_seq_lengths_kv (Tensor): Describe actual sequence length of each input with data type of int64.
7913
+ pse_shift (Tensor) - The position encoding tensor with data type of float16 or float32.
7476
7914
  dep_scale1 (Tensor)
7477
7915
  quant_scale1 (Tensor)
7478
7916
  deq_scale2 (Tensor)
@@ -7489,6 +7927,7 @@ def prompt_flash_attention(query, key, value, padding_mask, attn_mask, actual_se
7489
7927
  num_key_value_heads (int): head numbers of key/value which are used in GQA algorithm.
7490
7928
  The value o indicates if the key and value have the same head nums, use numHeads. Default: 0.
7491
7929
  sparse_mode (int): Default: 0
7930
+ inner_precise (int): 0, float16 high precision. 1, high performance. default 1
7492
7931
 
7493
7932
 
7494
7933
  Outputs:
@@ -7510,16 +7949,128 @@ def prompt_flash_attention(query, key, value, padding_mask, attn_mask, actual_se
7510
7949
  >>> value = Tensor(np.ones((B, N, S, D), dtype=np.float16))
7511
7950
  >>> out = ops.prompt_flash_attention(query, key, value, None, None, None, None, None, None, None, None,
7512
7951
  None, N, input_layout='BNSD')
7513
- >>> print(out[0].shape)
7952
+ >>> print(out.shape)
7514
7953
  (1, 16, 256, 16)
7515
7954
  """
7516
7955
 
7517
7956
  pfa = _get_cache_prim(NN_OPS.PromptFlashAttention)(num_heads, scale_value, pre_tokens, next_tokens, input_layout,
7518
- num_key_value_heads, sparse_mode)
7519
- return pfa(query, key, value, padding_mask, attn_mask, actual_seq_lengths, actual_seq_lengths_kv, deq_scale1,
7957
+ num_key_value_heads, sparse_mode, inner_precise)
7958
+ return pfa(query, key, value, attn_mask, actual_seq_lengths, actual_seq_lengths_kv, pse_shift, deq_scale1,
7520
7959
  quant_scale1, deq_scale2, quant_scale2, quant_offset2)
7521
7960
 
7522
7961
 
7962
+ def incre_flash_attention(query, key, value, attn_mask, actual_seq_lengths, pse_shift, dequant_scale1, quant_scale1,
7963
+ dequant_scale2, quant_scale2, quant_offset2, antiquant_scale, antiquant_offset, block_table,
7964
+ num_heads, input_layout="BSH", scale_value=1.0, num_key_value_heads=0, block_size=0,
7965
+ inner_precise=1):
7966
+ r"""
7967
+ The interface for fully inference.
7968
+
7969
+ B -- Batch size
7970
+
7971
+ S -- Sequence length
7972
+
7973
+ H -- Hidden size
7974
+
7975
+ .. warning::
7976
+ This is an experimental API that is subject to change or deletion.
7977
+ If there is no input parameter and no default value, None needs to be passed.
7978
+
7979
+ Inputs:
7980
+ - **query** (Tensor) - The query tensor with data type of float16 or bfloat16.
7981
+ Input tensor of shape :math:`(B, 1, H)` / :math:`(B, N, 1, D)`.
7982
+ - **key** (TensorList) - The key tensor with data type of float16 or bfloat16.
7983
+ Input tensor of shape :math:`(B, S, H)` / :math:`(B, N, S, D)`.
7984
+ - **value** (TensorList) - The value tensor with data type of float16 or bfloat16.
7985
+ Input tensor of shape :math:`(B, S, H)` / :math:`(B, N, S, D)`.
7986
+ - **attn_mask** (Tensor) - The attention mask tensor with data type of float16 or bool.
7987
+ Input tensor of shape :math:`(B, S)` / :math:`(B, 1, S)` / :math:`(B, 1, 1, S)`.
7988
+ - **actual_seq_lengths** (Tensor) - Describe actual sequence length of each input with data type of int.
7989
+ - **pse_shift** (Tensor) - The position encoding tensor with data type of float16 or float32.
7990
+ - **dequant_scale1** (Tensor) - Quantitative parametor, the tensor with data type of uint64.
7991
+ - **quant_scale1** (Tensor) - Quantitative parametor, the tensor with data type of float.
7992
+ - **dequant_scale2** (Tensor) - Quantitative parametor, the tensor with data type of uint64.
7993
+ - **quant_scale2** (Tensor) - Quantitative parametor, the tensor with data type of float.
7994
+ - **quant_offset2** (Tensor) - Quantitative parametor, the tensor with data type of float.
7995
+ - **antiquant_scale** (Tensor) - Quantitative parametor, the tensor with data type of float.
7996
+ - **antiquant_offset** (Tensor) - Quantitative parametor, the tensor with data type of float.
7997
+ - **block_table** (Tensor) - The tensor with data type of float.
7998
+ - **num_heads** (int) - The number of heads.
7999
+ - **input_layout** (str) - the data layout of the input qkv, support `(BSH)` and `(BNSD)`. Default `BSH`.
8000
+ - **scale_value** (double) - The scale value indicating the scale coefficient, which is used as the scalar of
8001
+ Muls in the calculation. Default: 1.0.
8002
+ - **num_key_value_heads** (int) - head numbers of key/value which are used in GQA algorithm.
8003
+ The value o indicates if the key and value have the same head nums, use numHeads. Default: 0.
8004
+ - **block_size** (int) - Default: 0.
8005
+ - **inner_precise** (int) - Default: 1.
8006
+
8007
+ Outputs:
8008
+ - **attention_out** (Tensor) - Input tensor of shape :math:`(B, 1, H)` / :math:`(B, N, 1, D)`.
8009
+
8010
+ Supported Platforms:
8011
+ ``Ascend``
8012
+ """
8013
+
8014
+ _ifa = _get_cache_prim(NN_OPS.IncreFlashAttention)(num_heads, input_layout, scale_value, num_key_value_heads,
8015
+ block_size, inner_precise)
8016
+ return _ifa(query, key, value, attn_mask, actual_seq_lengths, pse_shift, dequant_scale1, quant_scale1,
8017
+ dequant_scale2, quant_scale2, quant_offset2, antiquant_scale, antiquant_offset, block_table)
8018
+
8019
+
8020
+ def embedding(input, weight, padding_idx=None, max_norm=None, norm_type=2.0, scale_grad_by_freq=False):
8021
+ r"""
8022
+ Retrieve the word embeddings in `weight` using indices specified in `input`.
8023
+
8024
+ .. warning::
8025
+ On Ascend, the behavior is unpredictable when the value of input is invalid.
8026
+
8027
+ Args:
8028
+ input (Tensor): The indices used to lookup in the `weight`. The data type must be mindspore.int32 or
8029
+ mindspore.int64, and the value should be in range `[0, weight.shape[0])`.
8030
+ weight (Parameter): The matrix where to lookup from. The shape must be 2D.
8031
+ padding_idx (int, optional): If the value is not None, the corresponding row of `weight` will not be updated
8032
+ in training. The value should be in range `[-weight.shape[0], weight.shape[0])` if it's not ``None``.
8033
+ Default ``None``.
8034
+ max_norm (float, optional): If not None, firstly get the p-norm result of the `weight` specified by `input`
8035
+ where p is specified by `norm_type`; if the result is larger then `max_norm`, update the `weight`
8036
+ with :math:`\frac{max\_norm}{result+1e^{-7}}` in-place. Default ``None``.
8037
+ norm_type (float, optional): Indicates the value of p in p-norm. Default ``2.0``.
8038
+ scale_grad_by_freq (bool, optional): If ``True`` the gradients will be scaled by the inverse of frequency of
8039
+ the index in `input`. Default ``False``.
8040
+
8041
+ Returns:
8042
+ Tensor, has the same data type as `weight`, the shape is :math:`(*input.shape, weight.shape[1])`.
8043
+
8044
+ Raises:
8045
+ ValueError: If `padding_idx` is out of valid range.
8046
+ ValueError: If the shape of `weight` is invalid.
8047
+ TypeError: `weight` is not a :class:`mindspore.Parameter`.
8048
+
8049
+ Supported Platforms:
8050
+ ``Ascend``
8051
+
8052
+ Examples:
8053
+ >>> import mindspore
8054
+ >>> import numpy as np
8055
+ >>> from mindspore import Tensor, Parameter, ops
8056
+ >>> input = Tensor([[1, 0, 1, 1], [0, 0, 1, 0]])
8057
+ >>> weight = Parameter(np.random.randn(3, 3).astype(np.float32))
8058
+ >>> output = ops.embedding(input, weight, max_norm=0.4)
8059
+ >>> print(output)
8060
+ [[[ 5.49015924e-02, 3.47811311e-01, -1.89771220e-01],
8061
+ [ 2.09307984e-01, -2.24846993e-02, 3.40124398e-01],
8062
+ [ 5.49015924e-02, 3.47811311e-01, -1.89771220e-01],
8063
+ [ 5.49015924e-02, 3.47811311e-01, -1.89771220e-01]],
8064
+ [[ 2.09307984e-01, -2.24846993e-02, 3.40124398e-01],
8065
+ [ 2.09307984e-01, -2.24846993e-02, 3.40124398e-01],
8066
+ [ 5.49015924e-02, 3.47811311e-01, -1.89771220e-01],
8067
+ [ 2.09307984e-01, -2.24846993e-02, 3.40124398e-01]]]
8068
+ """
8069
+ if not isinstance(weight, Parameter):
8070
+ raise TypeError(f"For Embedding, the weight must be a mindspore.Parameter, but got {type(weight)}.")
8071
+ return embedding_op(input, weight, padding_idx, max_norm, norm_type, scale_grad_by_freq)
8072
+
8073
+
7523
8074
  __all__ = [
7524
8075
  'adaptive_avg_pool1d',
7525
8076
  'adaptive_avg_pool2d',
@@ -7545,6 +8096,7 @@ __all__ = [
7545
8096
  'dropout1d',
7546
8097
  'dropout2d',
7547
8098
  'dropout3d',
8099
+ 'embedding',
7548
8100
  'fast_gelu',
7549
8101
  'fractional_max_pool2d',
7550
8102
  'fractional_max_pool3d',
@@ -7558,6 +8110,7 @@ __all__ = [
7558
8110
  'intopk',
7559
8111
  'interpolate',
7560
8112
  'upsample',
8113
+ 'layer_norm',
7561
8114
  'log_softmax',
7562
8115
  'mish',
7563
8116
  'lrn',
@@ -7590,6 +8143,7 @@ __all__ = [
7590
8143
  'conv3d_transpose',
7591
8144
  'conv1d',
7592
8145
  'conv2d',
8146
+ 'conv_transpose2d',
7593
8147
  'sigmoid',
7594
8148
  'logsigmoid',
7595
8149
  'relu',
@@ -7614,6 +8168,8 @@ __all__ = [
7614
8168
  'msort',
7615
8169
  'triplet_margin_loss',
7616
8170
  'channel_shuffle',
7617
- 'hardsigmoid'
8171
+ 'hardsigmoid',
8172
+ 'group_norm',
8173
+ 'rms_norm',
7618
8174
  ]
7619
8175
  __all__.sort()