mindspore 2.2.14__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 (1166) hide show
  1. mindspore/.commit_id +1 -1
  2. mindspore/Microsoft.VisualStudio.Telemetry.dll +0 -0
  3. mindspore/Newtonsoft.Json.dll +0 -0
  4. mindspore/__init__.py +6 -5
  5. mindspore/_c_dataengine.cp39-win_amd64.pyd +0 -0
  6. mindspore/_c_expression.cp39-win_amd64.pyd +0 -0
  7. mindspore/_c_mindrecord.cp39-win_amd64.pyd +0 -0
  8. mindspore/_checkparam.py +76 -18
  9. mindspore/_extends/builtin_operations.py +2 -1
  10. mindspore/_extends/graph_kernel/model/graph_parallel.py +16 -6
  11. mindspore/_extends/parallel_compile/akg_compiler/akg_process.py +3 -16
  12. mindspore/_extends/parallel_compile/akg_compiler/build_tbe_kernel.py +16 -4
  13. mindspore/_extends/parallel_compile/akg_compiler/compiler.py +1 -0
  14. mindspore/_extends/parallel_compile/akg_compiler/gen_custom_op_files.py +96 -0
  15. mindspore/_extends/parallel_compile/akg_compiler/tbe_topi.py +2 -1
  16. mindspore/_extends/parallel_compile/akg_compiler/util.py +5 -2
  17. mindspore/_extends/parse/__init__.py +18 -14
  18. mindspore/_extends/parse/compile_config.py +258 -0
  19. mindspore/_extends/parse/namespace.py +2 -2
  20. mindspore/_extends/parse/parser.py +174 -62
  21. mindspore/_extends/parse/resources.py +45 -14
  22. mindspore/_extends/parse/standard_method.py +142 -240
  23. mindspore/{ops/_op_impl/tbe/atomic_addr_clean.py → _extends/pijit/__init__.py} +6 -16
  24. mindspore/_extends/pijit/pijit_func_white_list.py +343 -0
  25. mindspore/_extends/remote/kernel_build_server.py +2 -0
  26. mindspore/_profiler.py +30 -0
  27. mindspore/amp.py +51 -24
  28. mindspore/atlprov.dll +0 -0
  29. mindspore/avcodec-59.dll +0 -0
  30. mindspore/avdevice-59.dll +0 -0
  31. mindspore/avfilter-8.dll +0 -0
  32. mindspore/avformat-59.dll +0 -0
  33. mindspore/avutil-57.dll +0 -0
  34. mindspore/boost/adasum.py +1 -1
  35. mindspore/boost/base.py +1 -1
  36. mindspore/boost/boost_cell_wrapper.py +2 -2
  37. mindspore/boost/grad_freeze.py +2 -2
  38. mindspore/boost/group_loss_scale_manager.py +1 -1
  39. mindspore/boost/less_batch_normalization.py +9 -6
  40. mindspore/c1.dll +0 -0
  41. mindspore/c1xx.dll +0 -0
  42. mindspore/c2.dll +0 -0
  43. mindspore/common/__init__.py +15 -4
  44. mindspore/common/_jit_fallback_utils.py +2 -3
  45. mindspore/common/_register_for_adapter.py +7 -0
  46. mindspore/common/_register_for_recompute.py +48 -0
  47. mindspore/common/_register_for_tensor.py +8 -9
  48. mindspore/common/_stub_tensor.py +7 -1
  49. mindspore/common/_utils.py +5 -17
  50. mindspore/common/api.py +411 -106
  51. mindspore/common/auto_dynamic_shape.py +27 -14
  52. mindspore/common/dtype.py +17 -10
  53. mindspore/common/dump.py +6 -8
  54. mindspore/common/file_system.py +48 -0
  55. mindspore/common/generator.py +260 -0
  56. mindspore/common/hook_handle.py +51 -4
  57. mindspore/common/initializer.py +1 -1
  58. mindspore/common/jit_config.py +34 -14
  59. mindspore/common/lazy_inline.py +72 -19
  60. mindspore/common/mindir_util.py +12 -2
  61. mindspore/common/mutable.py +79 -14
  62. mindspore/common/no_inline.py +54 -0
  63. mindspore/common/np_dtype.py +25 -0
  64. mindspore/common/parameter.py +30 -11
  65. mindspore/common/recompute.py +262 -0
  66. mindspore/common/seed.py +9 -9
  67. mindspore/common/sparse_tensor.py +272 -24
  68. mindspore/common/symbol.py +122 -0
  69. mindspore/common/tensor.py +468 -494
  70. mindspore/communication/__init__.py +6 -11
  71. mindspore/communication/_comm_helper.py +5 -0
  72. mindspore/communication/comm_func.py +1140 -0
  73. mindspore/communication/management.py +115 -102
  74. mindspore/config/op_info.config +22 -54
  75. mindspore/context.py +346 -63
  76. mindspore/dataset/__init__.py +5 -5
  77. mindspore/dataset/audio/__init__.py +6 -6
  78. mindspore/dataset/audio/transforms.py +711 -158
  79. mindspore/dataset/callback/ds_callback.py +2 -2
  80. mindspore/dataset/engine/cache_client.py +2 -2
  81. mindspore/dataset/engine/datasets.py +140 -83
  82. mindspore/dataset/engine/datasets_audio.py +14 -14
  83. mindspore/dataset/engine/datasets_standard_format.py +33 -3
  84. mindspore/dataset/engine/datasets_text.py +38 -38
  85. mindspore/dataset/engine/datasets_user_defined.py +78 -59
  86. mindspore/dataset/engine/datasets_vision.py +77 -73
  87. mindspore/dataset/engine/offload.py +5 -7
  88. mindspore/dataset/engine/queue.py +56 -38
  89. mindspore/dataset/engine/validators.py +11 -5
  90. mindspore/dataset/text/__init__.py +3 -3
  91. mindspore/dataset/text/transforms.py +408 -121
  92. mindspore/dataset/text/utils.py +9 -9
  93. mindspore/dataset/transforms/__init__.py +1 -1
  94. mindspore/dataset/transforms/transforms.py +261 -76
  95. mindspore/dataset/utils/browse_dataset.py +9 -9
  96. mindspore/dataset/vision/__init__.py +8 -8
  97. mindspore/dataset/vision/c_transforms.py +10 -10
  98. mindspore/dataset/vision/py_transforms_util.py +1 -1
  99. mindspore/dataset/vision/transforms.py +2844 -549
  100. mindspore/dataset/vision/utils.py +161 -10
  101. mindspore/dataset/vision/validators.py +14 -2
  102. mindspore/dnnl.dll +0 -0
  103. mindspore/dpcmi.dll +0 -0
  104. mindspore/experimental/optim/__init__.py +12 -2
  105. mindspore/experimental/optim/adadelta.py +161 -0
  106. mindspore/experimental/optim/adagrad.py +168 -0
  107. mindspore/experimental/optim/adam.py +35 -34
  108. mindspore/experimental/optim/adamax.py +170 -0
  109. mindspore/experimental/optim/adamw.py +40 -16
  110. mindspore/experimental/optim/asgd.py +153 -0
  111. mindspore/experimental/optim/lr_scheduler.py +66 -121
  112. mindspore/experimental/optim/nadam.py +157 -0
  113. mindspore/experimental/optim/optimizer.py +15 -8
  114. mindspore/experimental/optim/radam.py +194 -0
  115. mindspore/experimental/optim/rmsprop.py +154 -0
  116. mindspore/experimental/optim/rprop.py +164 -0
  117. mindspore/experimental/optim/sgd.py +28 -19
  118. mindspore/hal/__init__.py +40 -0
  119. mindspore/hal/_ascend.py +57 -0
  120. mindspore/hal/_base.py +57 -0
  121. mindspore/hal/_cpu.py +56 -0
  122. mindspore/hal/_gpu.py +57 -0
  123. mindspore/hal/device.py +356 -0
  124. mindspore/hal/event.py +179 -0
  125. mindspore/hal/memory.py +326 -0
  126. mindspore/hal/stream.py +339 -0
  127. mindspore/include/api/data_type.h +2 -2
  128. mindspore/include/api/dual_abi_helper.h +16 -3
  129. mindspore/include/api/model.h +4 -3
  130. mindspore/include/api/status.h +14 -0
  131. mindspore/include/c_api/model_c.h +173 -0
  132. mindspore/include/c_api/ms/base/types.h +1 -0
  133. mindspore/include/c_api/types_c.h +19 -0
  134. mindspore/include/dataset/execute.h +1 -3
  135. mindspore/include/dataset/vision.h +54 -2
  136. mindspore/jpeg62.dll +0 -0
  137. mindspore/log.py +2 -2
  138. mindspore/mindrecord/__init__.py +5 -1
  139. mindspore/mindrecord/config.py +809 -0
  140. mindspore/mindrecord/filereader.py +25 -0
  141. mindspore/mindrecord/filewriter.py +76 -58
  142. mindspore/mindrecord/mindpage.py +40 -6
  143. mindspore/mindrecord/shardutils.py +3 -2
  144. mindspore/mindrecord/shardwriter.py +7 -0
  145. mindspore/mindrecord/tools/cifar100_to_mr.py +8 -13
  146. mindspore/mindrecord/tools/cifar10_to_mr.py +9 -15
  147. mindspore/mindrecord/tools/csv_to_mr.py +4 -9
  148. mindspore/mindrecord/tools/imagenet_to_mr.py +3 -8
  149. mindspore/mindrecord/tools/mnist_to_mr.py +7 -12
  150. mindspore/mindrecord/tools/tfrecord_to_mr.py +1 -6
  151. mindspore/mindspore_backend.dll +0 -0
  152. mindspore/mindspore_common.dll +0 -0
  153. mindspore/mindspore_core.dll +0 -0
  154. mindspore/mindspore_glog.dll +0 -0
  155. mindspore/mindspore_np_dtype.dll +0 -0
  156. mindspore/mindspore_shared_lib.dll +0 -0
  157. mindspore/mint/__init__.py +1137 -0
  158. mindspore/{rewrite/ast_transformers → mint/linalg}/__init__.py +9 -4
  159. mindspore/mint/nn/__init__.py +512 -0
  160. mindspore/mint/nn/functional.py +573 -0
  161. mindspore/mint/optim/__init__.py +24 -0
  162. mindspore/mint/optim/adamw.py +185 -0
  163. mindspore/msobj140.dll +0 -0
  164. mindspore/mspdb140.dll +0 -0
  165. mindspore/mspdbcore.dll +0 -0
  166. mindspore/mspdbst.dll +0 -0
  167. mindspore/mspft140.dll +0 -0
  168. mindspore/msvcdis140.dll +0 -0
  169. mindspore/msvcp140_1.dll +0 -0
  170. mindspore/msvcp140_2.dll +0 -0
  171. mindspore/msvcp140_atomic_wait.dll +0 -0
  172. mindspore/msvcp140_codecvt_ids.dll +0 -0
  173. mindspore/multiprocessing/__init__.py +72 -0
  174. mindspore/nn/__init__.py +1 -0
  175. mindspore/nn/cell.py +213 -257
  176. mindspore/nn/dynamic_lr.py +2 -2
  177. mindspore/nn/extend/__init__.py +29 -0
  178. mindspore/nn/extend/basic.py +140 -0
  179. mindspore/nn/extend/embedding.py +143 -0
  180. mindspore/{rewrite/ast_creator_register.py → nn/extend/layer/__init__.py} +9 -19
  181. mindspore/nn/extend/layer/normalization.py +109 -0
  182. mindspore/nn/extend/pooling.py +117 -0
  183. mindspore/nn/layer/activation.py +83 -93
  184. mindspore/nn/layer/basic.py +177 -82
  185. mindspore/nn/layer/channel_shuffle.py +3 -16
  186. mindspore/nn/layer/container.py +3 -3
  187. mindspore/nn/layer/conv.py +75 -66
  188. mindspore/nn/layer/embedding.py +101 -43
  189. mindspore/nn/layer/embedding_service.py +531 -0
  190. mindspore/nn/layer/embedding_service_layer.py +393 -0
  191. mindspore/nn/layer/image.py +4 -7
  192. mindspore/nn/layer/math.py +1 -1
  193. mindspore/nn/layer/normalization.py +52 -66
  194. mindspore/nn/layer/padding.py +30 -39
  195. mindspore/nn/layer/pooling.py +18 -9
  196. mindspore/nn/layer/rnn_cells.py +6 -16
  197. mindspore/nn/layer/rnns.py +6 -5
  198. mindspore/nn/layer/thor_layer.py +1 -2
  199. mindspore/nn/layer/timedistributed.py +1 -1
  200. mindspore/nn/layer/transformer.py +52 -50
  201. mindspore/nn/learning_rate_schedule.py +6 -5
  202. mindspore/nn/loss/loss.py +62 -83
  203. mindspore/nn/optim/ada_grad.py +4 -2
  204. mindspore/nn/optim/adadelta.py +3 -1
  205. mindspore/nn/optim/adafactor.py +1 -1
  206. mindspore/nn/optim/adam.py +102 -181
  207. mindspore/nn/optim/adamax.py +4 -2
  208. mindspore/nn/optim/adasum.py +3 -3
  209. mindspore/nn/optim/asgd.py +4 -2
  210. mindspore/nn/optim/ftrl.py +31 -61
  211. mindspore/nn/optim/lamb.py +5 -3
  212. mindspore/nn/optim/lars.py +2 -2
  213. mindspore/nn/optim/lazyadam.py +6 -4
  214. mindspore/nn/optim/momentum.py +13 -25
  215. mindspore/nn/optim/optimizer.py +6 -3
  216. mindspore/nn/optim/proximal_ada_grad.py +4 -2
  217. mindspore/nn/optim/rmsprop.py +9 -3
  218. mindspore/nn/optim/rprop.py +4 -2
  219. mindspore/nn/optim/sgd.py +5 -3
  220. mindspore/nn/optim/thor.py +2 -2
  221. mindspore/nn/probability/distribution/_utils/custom_ops.py +2 -2
  222. mindspore/nn/probability/distribution/beta.py +2 -2
  223. mindspore/nn/probability/distribution/categorical.py +4 -6
  224. mindspore/nn/probability/distribution/cauchy.py +2 -2
  225. mindspore/nn/probability/distribution/exponential.py +2 -2
  226. mindspore/nn/probability/distribution/geometric.py +1 -1
  227. mindspore/nn/probability/distribution/gumbel.py +2 -2
  228. mindspore/nn/probability/distribution/logistic.py +1 -1
  229. mindspore/nn/probability/distribution/poisson.py +2 -2
  230. mindspore/nn/probability/distribution/uniform.py +2 -2
  231. mindspore/nn/reinforcement/_tensors_queue.py +13 -1
  232. mindspore/nn/wrap/__init__.py +2 -1
  233. mindspore/nn/wrap/cell_wrapper.py +58 -13
  234. mindspore/nn/wrap/grad_reducer.py +148 -8
  235. mindspore/nn/wrap/loss_scale.py +32 -9
  236. mindspore/numpy/__init__.py +2 -0
  237. mindspore/numpy/array_creations.py +2 -0
  238. mindspore/numpy/array_ops.py +6 -6
  239. mindspore/numpy/dtypes.py +3 -3
  240. mindspore/numpy/fft.py +431 -0
  241. mindspore/numpy/math_ops.py +62 -68
  242. mindspore/numpy/utils.py +3 -0
  243. mindspore/opencv_core452.dll +0 -0
  244. mindspore/opencv_imgcodecs452.dll +0 -0
  245. mindspore/opencv_imgproc452.dll +0 -0
  246. mindspore/ops/__init__.py +6 -5
  247. mindspore/ops/_grad_experimental/grad_array_ops.py +4 -129
  248. mindspore/ops/_grad_experimental/grad_comm_ops.py +89 -34
  249. mindspore/ops/_grad_experimental/grad_math_ops.py +68 -283
  250. mindspore/ops/_grad_experimental/grad_nn_ops.py +0 -53
  251. mindspore/ops/_grad_experimental/grad_quant_ops.py +3 -3
  252. mindspore/ops/_grad_experimental/grad_sparse.py +1 -1
  253. mindspore/ops/_grad_experimental/grad_sparse_ops.py +3 -3
  254. mindspore/ops/_op_impl/__init__.py +0 -1
  255. mindspore/ops/_op_impl/aicpu/gamma.py +2 -0
  256. mindspore/ops/_op_impl/aicpu/generate_eod_mask.py +1 -1
  257. mindspore/ops/_op_impl/aicpu/log_uniform_candidate_sampler.py +1 -3
  258. mindspore/ops/_op_impl/aicpu/poisson.py +2 -0
  259. mindspore/ops/_op_impl/cpu/__init__.py +1 -3
  260. mindspore/ops/_op_impl/cpu/adam.py +2 -2
  261. mindspore/ops/_op_impl/cpu/adam_weight_decay.py +3 -2
  262. mindspore/ops/_op_impl/cpu/maximum_grad.py +16 -14
  263. mindspore/ops/_op_impl/cpu/minimum_grad.py +8 -0
  264. mindspore/ops/_vmap/vmap_array_ops.py +164 -101
  265. mindspore/ops/_vmap/vmap_base.py +8 -1
  266. mindspore/ops/_vmap/vmap_grad_math_ops.py +95 -9
  267. mindspore/ops/_vmap/vmap_grad_nn_ops.py +143 -58
  268. mindspore/ops/_vmap/vmap_image_ops.py +70 -13
  269. mindspore/ops/_vmap/vmap_math_ops.py +130 -58
  270. mindspore/ops/_vmap/vmap_nn_ops.py +249 -115
  271. mindspore/ops/_vmap/vmap_other_ops.py +1 -1
  272. mindspore/ops/auto_generate/__init__.py +31 -0
  273. mindspore/ops/auto_generate/cpp_create_prim_instance_helper.py +231 -0
  274. mindspore/ops/auto_generate/gen_arg_dtype_cast.py +250 -0
  275. mindspore/ops/auto_generate/gen_arg_handler.py +197 -0
  276. mindspore/ops/auto_generate/gen_extend_func.py +980 -0
  277. mindspore/ops/auto_generate/gen_ops_def.py +6443 -0
  278. mindspore/ops/auto_generate/gen_ops_prim.py +13167 -0
  279. mindspore/ops/auto_generate/pyboost_inner_prim.py +429 -0
  280. mindspore/ops/composite/__init__.py +5 -2
  281. mindspore/ops/composite/base.py +121 -23
  282. mindspore/ops/composite/math_ops.py +10 -49
  283. mindspore/ops/composite/multitype_ops/_compile_utils.py +191 -618
  284. mindspore/ops/composite/multitype_ops/_constexpr_utils.py +25 -134
  285. mindspore/ops/composite/multitype_ops/add_impl.py +6 -0
  286. mindspore/ops/composite/multitype_ops/bitwise_and_impl.py +6 -0
  287. mindspore/ops/composite/multitype_ops/bitwise_or_impl.py +6 -0
  288. mindspore/ops/composite/multitype_ops/bitwise_xor_impl.py +6 -0
  289. mindspore/ops/composite/multitype_ops/div_impl.py +8 -0
  290. mindspore/ops/composite/multitype_ops/equal_impl.py +6 -0
  291. mindspore/ops/composite/multitype_ops/floordiv_impl.py +8 -0
  292. mindspore/ops/composite/multitype_ops/getitem_impl.py +6 -0
  293. mindspore/ops/composite/multitype_ops/greater_equal_impl.py +6 -0
  294. mindspore/ops/composite/multitype_ops/greater_impl.py +6 -0
  295. mindspore/ops/composite/multitype_ops/in_impl.py +8 -2
  296. mindspore/ops/composite/multitype_ops/left_shift_impl.py +6 -0
  297. mindspore/ops/composite/multitype_ops/less_equal_impl.py +6 -0
  298. mindspore/ops/composite/multitype_ops/less_impl.py +6 -0
  299. mindspore/ops/composite/multitype_ops/logic_not_impl.py +6 -0
  300. mindspore/ops/composite/multitype_ops/logical_and_impl.py +6 -0
  301. mindspore/ops/composite/multitype_ops/logical_or_impl.py +6 -0
  302. mindspore/ops/composite/multitype_ops/mod_impl.py +6 -0
  303. mindspore/ops/composite/multitype_ops/mul_impl.py +6 -0
  304. mindspore/ops/composite/multitype_ops/negative_impl.py +9 -3
  305. mindspore/ops/composite/multitype_ops/not_equal_impl.py +6 -0
  306. mindspore/ops/composite/multitype_ops/not_in_impl.py +6 -1
  307. mindspore/ops/composite/multitype_ops/ones_like_impl.py +2 -2
  308. mindspore/ops/composite/multitype_ops/pow_impl.py +6 -0
  309. mindspore/ops/composite/multitype_ops/right_shift_impl.py +6 -0
  310. mindspore/ops/composite/multitype_ops/setitem_impl.py +32 -21
  311. mindspore/ops/composite/multitype_ops/sub_impl.py +6 -0
  312. mindspore/ops/composite/multitype_ops/zeros_like_impl.py +6 -3
  313. mindspore/ops/deprecated.py +14 -3
  314. mindspore/ops/extend/__init__.py +53 -0
  315. mindspore/ops/extend/array_func.py +218 -0
  316. mindspore/ops/extend/math_func.py +76 -0
  317. mindspore/ops/extend/nn_func.py +308 -0
  318. mindspore/ops/function/__init__.py +31 -11
  319. mindspore/ops/function/array_func.py +846 -1735
  320. mindspore/ops/function/clip_func.py +19 -31
  321. mindspore/ops/function/debug_func.py +1 -4
  322. mindspore/ops/function/fft_func.py +31 -0
  323. mindspore/ops/function/grad/grad_func.py +27 -20
  324. mindspore/ops/function/image_func.py +27 -21
  325. mindspore/ops/function/linalg_func.py +35 -68
  326. mindspore/ops/function/math_func.py +913 -2791
  327. mindspore/ops/function/nn_func.py +1439 -885
  328. mindspore/ops/function/other_func.py +6 -7
  329. mindspore/ops/function/parameter_func.py +5 -93
  330. mindspore/ops/function/random_func.py +254 -108
  331. mindspore/ops/function/reshard_func.py +102 -0
  332. mindspore/ops/function/sparse_func.py +4 -4
  333. mindspore/ops/function/sparse_unary_func.py +9 -16
  334. mindspore/ops/function/spectral_func.py +1 -1
  335. mindspore/ops/function/vmap_func.py +14 -14
  336. mindspore/ops/functional.py +342 -343
  337. mindspore/ops/op_info_register.py +16 -43
  338. mindspore/ops/operations/__init__.py +32 -23
  339. mindspore/ops/operations/_grad_ops.py +21 -853
  340. mindspore/ops/operations/_infer_ops.py +19 -0
  341. mindspore/ops/operations/_inner_ops.py +107 -518
  342. mindspore/ops/operations/_rl_inner_ops.py +2 -2
  343. mindspore/ops/operations/_scalar_ops.py +5 -480
  344. mindspore/ops/operations/_sequence_ops.py +6 -36
  345. mindspore/ops/operations/_tensor_array.py +8 -8
  346. mindspore/ops/operations/array_ops.py +108 -2705
  347. mindspore/ops/operations/comm_ops.py +801 -118
  348. mindspore/ops/operations/custom_ops.py +61 -120
  349. mindspore/ops/operations/debug_ops.py +104 -35
  350. mindspore/ops/operations/image_ops.py +1 -217
  351. mindspore/ops/operations/inner_ops.py +5 -40
  352. mindspore/ops/operations/linalg_ops.py +1 -49
  353. mindspore/ops/operations/manually_defined/__init__.py +24 -0
  354. mindspore/ops/operations/manually_defined/_inner.py +61 -0
  355. mindspore/ops/operations/manually_defined/ops_def.py +2016 -0
  356. mindspore/ops/operations/math_ops.py +572 -4667
  357. mindspore/ops/operations/nn_ops.py +248 -2162
  358. mindspore/ops/operations/other_ops.py +53 -45
  359. mindspore/ops/operations/random_ops.py +4 -53
  360. mindspore/ops/operations/reshard_ops.py +53 -0
  361. mindspore/ops/operations/sparse_ops.py +4 -4
  362. mindspore/ops/primitive.py +204 -103
  363. mindspore/ops/silent_check.py +5 -5
  364. mindspore/ops_generate/__init__.py +27 -0
  365. mindspore/ops_generate/arg_dtype_cast.py +250 -0
  366. mindspore/ops_generate/arg_handler.py +197 -0
  367. mindspore/ops_generate/gen_aclnn_implement.py +263 -0
  368. mindspore/ops_generate/gen_ops.py +1084 -0
  369. mindspore/ops_generate/gen_ops_inner_prim.py +131 -0
  370. mindspore/ops_generate/gen_pyboost_func.py +968 -0
  371. mindspore/ops_generate/gen_utils.py +209 -0
  372. mindspore/ops_generate/op_proto.py +138 -0
  373. mindspore/ops_generate/pyboost_utils.py +354 -0
  374. mindspore/ops_generate/template.py +239 -0
  375. mindspore/parallel/__init__.py +6 -4
  376. mindspore/parallel/_auto_parallel_context.py +73 -3
  377. mindspore/parallel/_cell_wrapper.py +16 -9
  378. mindspore/parallel/_cost_model_context.py +1 -1
  379. mindspore/parallel/_dp_allreduce_fusion.py +159 -159
  380. mindspore/parallel/_parallel_serialization.py +29 -13
  381. mindspore/parallel/_ps_context.py +1 -1
  382. mindspore/parallel/_recovery_context.py +1 -1
  383. mindspore/parallel/_tensor.py +18 -11
  384. mindspore/parallel/_transformer/__init__.py +1 -1
  385. mindspore/parallel/_transformer/layers.py +1 -1
  386. mindspore/parallel/_transformer/loss.py +1 -1
  387. mindspore/parallel/_transformer/moe.py +1 -1
  388. mindspore/parallel/_transformer/op_parallel_config.py +1 -1
  389. mindspore/parallel/_transformer/transformer.py +2 -2
  390. mindspore/parallel/_utils.py +161 -6
  391. mindspore/parallel/algo_parameter_config.py +6 -8
  392. mindspore/parallel/checkpoint_transform.py +191 -32
  393. mindspore/parallel/cluster/__init__.py +15 -0
  394. mindspore/parallel/cluster/process_entity/__init__.py +18 -0
  395. mindspore/parallel/cluster/process_entity/_api.py +344 -0
  396. mindspore/parallel/cluster/process_entity/_utils.py +126 -0
  397. mindspore/parallel/cluster/run.py +136 -0
  398. mindspore/parallel/mpi/__init__.py +1 -1
  399. mindspore/parallel/mpi/_mpi_config.py +1 -1
  400. mindspore/parallel/parameter_broadcast.py +152 -0
  401. mindspore/parallel/shard.py +128 -17
  402. mindspore/pgodb140.dll +0 -0
  403. mindspore/pgort140.dll +0 -0
  404. mindspore/profiler/__init__.py +3 -2
  405. mindspore/profiler/common/process_pool.py +41 -0
  406. mindspore/profiler/common/singleton.py +28 -0
  407. mindspore/profiler/common/util.py +125 -0
  408. mindspore/profiler/envprofiling.py +2 -2
  409. mindspore/{_extends/parallel_compile/tbe_compiler → profiler/parser/ascend_analysis}/__init__.py +1 -1
  410. mindspore/profiler/parser/ascend_analysis/constant.py +53 -0
  411. mindspore/profiler/parser/ascend_analysis/file_manager.py +159 -0
  412. mindspore/profiler/parser/ascend_analysis/function_event.py +161 -0
  413. mindspore/profiler/parser/ascend_analysis/fwk_cann_parser.py +131 -0
  414. mindspore/profiler/parser/ascend_analysis/fwk_file_parser.py +85 -0
  415. mindspore/profiler/parser/ascend_analysis/msprof_timeline_parser.py +57 -0
  416. mindspore/profiler/parser/ascend_analysis/profiler_info_parser.py +116 -0
  417. mindspore/profiler/parser/ascend_analysis/tlv_decoder.py +86 -0
  418. mindspore/profiler/parser/ascend_analysis/trace_event_manager.py +68 -0
  419. mindspore/profiler/parser/ascend_cluster_generator.py +14 -9
  420. mindspore/profiler/parser/ascend_communicate_generator.py +0 -1
  421. mindspore/profiler/parser/ascend_flops_generator.py +20 -4
  422. mindspore/profiler/parser/ascend_hccl_generator.py +29 -278
  423. mindspore/profiler/parser/ascend_integrate_generator.py +42 -0
  424. mindspore/profiler/parser/ascend_memory_generator.py +185 -0
  425. mindspore/profiler/parser/ascend_msprof_exporter.py +147 -146
  426. mindspore/profiler/parser/ascend_msprof_generator.py +73 -283
  427. mindspore/profiler/parser/ascend_op_generator.py +92 -42
  428. mindspore/profiler/parser/ascend_timeline_generator.py +296 -133
  429. mindspore/profiler/parser/base_timeline_generator.py +6 -0
  430. mindspore/profiler/parser/framework_parser.py +3 -2
  431. mindspore/profiler/parser/integrator.py +3 -1
  432. mindspore/profiler/parser/minddata_parser.py +72 -3
  433. mindspore/profiler/parser/msadvisor_analyzer.py +1 -1
  434. mindspore/profiler/parser/msadvisor_parser.py +1 -1
  435. mindspore/profiler/parser/profiler_info.py +16 -1
  436. mindspore/profiler/profiling.py +445 -190
  437. mindspore/rewrite/__init__.py +2 -13
  438. mindspore/rewrite/api/node.py +122 -36
  439. mindspore/rewrite/api/pattern_engine.py +2 -3
  440. mindspore/rewrite/api/scoped_value.py +16 -15
  441. mindspore/rewrite/api/symbol_tree.py +45 -29
  442. mindspore/rewrite/ast_helpers/__init__.py +3 -6
  443. mindspore/rewrite/ast_helpers/ast_converter.py +143 -0
  444. mindspore/rewrite/ast_helpers/ast_finder.py +48 -0
  445. mindspore/rewrite/ast_helpers/ast_flattener.py +268 -0
  446. mindspore/rewrite/ast_helpers/ast_modifier.py +160 -92
  447. mindspore/rewrite/common/__init__.py +1 -2
  448. mindspore/rewrite/common/config.py +24 -0
  449. mindspore/rewrite/common/{rewrite_elog.py → error_log.py} +39 -39
  450. mindspore/rewrite/{namer.py → common/namer.py} +63 -18
  451. mindspore/rewrite/common/namespace.py +118 -0
  452. mindspore/rewrite/node/__init__.py +5 -5
  453. mindspore/rewrite/node/call_function.py +23 -7
  454. mindspore/rewrite/node/cell_container.py +7 -3
  455. mindspore/rewrite/node/control_flow.py +53 -28
  456. mindspore/rewrite/node/node.py +212 -196
  457. mindspore/rewrite/node/node_manager.py +51 -22
  458. mindspore/rewrite/node/node_topological_manager.py +3 -23
  459. mindspore/rewrite/parsers/__init__.py +12 -0
  460. mindspore/rewrite/parsers/arguments_parser.py +8 -9
  461. mindspore/rewrite/parsers/assign_parser.py +637 -413
  462. mindspore/rewrite/parsers/attribute_parser.py +3 -4
  463. mindspore/rewrite/parsers/class_def_parser.py +115 -148
  464. mindspore/rewrite/parsers/constant_parser.py +5 -5
  465. mindspore/rewrite/parsers/container_parser.py +4 -6
  466. mindspore/rewrite/parsers/expr_parser.py +55 -0
  467. mindspore/rewrite/parsers/for_parser.py +31 -98
  468. mindspore/rewrite/parsers/function_def_parser.py +13 -5
  469. mindspore/rewrite/parsers/if_parser.py +28 -10
  470. mindspore/rewrite/parsers/module_parser.py +8 -182
  471. mindspore/rewrite/parsers/parser.py +1 -5
  472. mindspore/rewrite/parsers/parser_register.py +1 -1
  473. mindspore/rewrite/parsers/return_parser.py +5 -10
  474. mindspore/rewrite/parsers/while_parser.py +59 -0
  475. mindspore/rewrite/sparsify/utils.py +1 -1
  476. mindspore/rewrite/symbol_tree/__init__.py +20 -0
  477. mindspore/rewrite/{symbol_tree.py → symbol_tree/symbol_tree.py} +704 -185
  478. mindspore/rewrite/{symbol_tree_builder.py → symbol_tree/symbol_tree_builder.py} +8 -8
  479. mindspore/rewrite/{symbol_tree_dumper.py → symbol_tree/symbol_tree_dumper.py} +4 -4
  480. mindspore/run_check/_check_version.py +6 -14
  481. mindspore/run_check/run_check.py +1 -1
  482. mindspore/safeguard/rewrite_obfuscation.py +9 -19
  483. mindspore/swresample-4.dll +0 -0
  484. mindspore/swscale-6.dll +0 -0
  485. mindspore/tbbmalloc.dll +0 -0
  486. mindspore/tinyxml2.dll +0 -0
  487. mindspore/train/__init__.py +6 -5
  488. mindspore/train/_utils.py +178 -4
  489. mindspore/train/amp.py +167 -245
  490. mindspore/train/anf_ir_pb2.py +14 -2
  491. mindspore/train/callback/__init__.py +5 -2
  492. mindspore/train/callback/_backup_and_restore.py +5 -5
  493. mindspore/train/callback/_callback.py +4 -4
  494. mindspore/train/callback/_checkpoint.py +143 -29
  495. mindspore/train/callback/_cluster_monitor.py +201 -0
  496. mindspore/train/callback/_early_stop.py +2 -2
  497. mindspore/train/callback/_flops_collector.py +238 -0
  498. mindspore/train/callback/_landscape.py +15 -9
  499. mindspore/train/callback/_loss_monitor.py +2 -2
  500. mindspore/train/callback/_mindio_ttp.py +443 -0
  501. mindspore/train/callback/_on_request_exit.py +2 -2
  502. mindspore/train/callback/_reduce_lr_on_plateau.py +2 -2
  503. mindspore/train/callback/_summary_collector.py +7 -7
  504. mindspore/train/callback/_time_monitor.py +3 -3
  505. mindspore/train/data_sink.py +6 -5
  506. mindspore/train/dataset_helper.py +60 -21
  507. mindspore/train/loss_scale_manager.py +2 -2
  508. mindspore/train/metrics/accuracy.py +7 -7
  509. mindspore/train/metrics/confusion_matrix.py +8 -6
  510. mindspore/train/metrics/cosine_similarity.py +6 -4
  511. mindspore/train/metrics/error.py +2 -2
  512. mindspore/train/metrics/metric.py +3 -3
  513. mindspore/train/metrics/perplexity.py +2 -1
  514. mindspore/train/metrics/topk.py +2 -2
  515. mindspore/train/mind_ir_pb2.py +89 -15
  516. mindspore/train/model.py +290 -60
  517. mindspore/train/serialization.py +495 -220
  518. mindspore/train/summary/_summary_adapter.py +1 -1
  519. mindspore/train/summary/summary_record.py +51 -28
  520. mindspore/train/train_thor/convert_utils.py +3 -3
  521. mindspore/turbojpeg.dll +0 -0
  522. mindspore/vcmeta.dll +0 -0
  523. mindspore/vcruntime140.dll +0 -0
  524. mindspore/vcruntime140_1.dll +0 -0
  525. mindspore/version.py +1 -1
  526. {mindspore-2.2.14.dist-info → mindspore-2.3.0.dist-info}/METADATA +3 -3
  527. mindspore-2.3.0.dist-info/RECORD +1400 -0
  528. {mindspore-2.2.14.dist-info → mindspore-2.3.0.dist-info}/entry_points.txt +1 -0
  529. mindspore/_extends/parallel_compile/tbe_compiler/tbe_adapter.py +0 -662
  530. mindspore/_extends/parallel_compile/tbe_compiler/tbe_helper.py +0 -377
  531. mindspore/_extends/parallel_compile/tbe_compiler/tbe_job.py +0 -201
  532. mindspore/_extends/parallel_compile/tbe_compiler/tbe_job_manager.py +0 -515
  533. mindspore/gen_ops.py +0 -273
  534. mindspore/nn/layer/flash_attention.py +0 -189
  535. mindspore/ops/_op_impl/cpu/concat.py +0 -39
  536. mindspore/ops/_op_impl/cpu/tensor_shape.py +0 -42
  537. mindspore/ops/_op_impl/tbe/__init__.py +0 -47
  538. mindspore/ops/_op_impl/tbe/abs.py +0 -38
  539. mindspore/ops/_op_impl/tbe/abs_ds.py +0 -39
  540. mindspore/ops/_op_impl/tbe/abs_grad.py +0 -43
  541. mindspore/ops/_op_impl/tbe/abs_grad_ds.py +0 -44
  542. mindspore/ops/_op_impl/tbe/accumulate_n_v2.py +0 -41
  543. mindspore/ops/_op_impl/tbe/accumulate_n_v2_ds.py +0 -42
  544. mindspore/ops/_op_impl/tbe/acos.py +0 -37
  545. mindspore/ops/_op_impl/tbe/acos_ds.py +0 -38
  546. mindspore/ops/_op_impl/tbe/acos_grad.py +0 -43
  547. mindspore/ops/_op_impl/tbe/acos_grad_ds.py +0 -44
  548. mindspore/ops/_op_impl/tbe/acosh.py +0 -37
  549. mindspore/ops/_op_impl/tbe/acosh_ds.py +0 -38
  550. mindspore/ops/_op_impl/tbe/acosh_grad.py +0 -43
  551. mindspore/ops/_op_impl/tbe/acosh_grad_ds.py +0 -44
  552. mindspore/ops/_op_impl/tbe/act_ulq_clamp_max_grad.py +0 -38
  553. mindspore/ops/_op_impl/tbe/act_ulq_clamp_min_grad.py +0 -38
  554. mindspore/ops/_op_impl/tbe/acts_ulq.py +0 -45
  555. mindspore/ops/_op_impl/tbe/acts_ulq_input_grad.py +0 -38
  556. mindspore/ops/_op_impl/tbe/adam_apply_one.py +0 -50
  557. mindspore/ops/_op_impl/tbe/adam_apply_one_assign.py +0 -53
  558. mindspore/ops/_op_impl/tbe/adam_apply_one_ds.py +0 -51
  559. mindspore/ops/_op_impl/tbe/adam_apply_one_with_decay.py +0 -54
  560. mindspore/ops/_op_impl/tbe/adam_apply_one_with_decay_assign.py +0 -54
  561. mindspore/ops/_op_impl/tbe/adam_apply_one_with_decay_ds.py +0 -55
  562. mindspore/ops/_op_impl/tbe/adaptive_max_pool2d.py +0 -37
  563. mindspore/ops/_op_impl/tbe/add.py +0 -42
  564. mindspore/ops/_op_impl/tbe/add_ds.py +0 -43
  565. mindspore/ops/_op_impl/tbe/add_n.py +0 -39
  566. mindspore/ops/_op_impl/tbe/add_n_ds.py +0 -40
  567. mindspore/ops/_op_impl/tbe/addcdiv.py +0 -41
  568. mindspore/ops/_op_impl/tbe/addcdiv_ds.py +0 -42
  569. mindspore/ops/_op_impl/tbe/addcmul.py +0 -43
  570. mindspore/ops/_op_impl/tbe/addcmul_ds.py +0 -44
  571. mindspore/ops/_op_impl/tbe/apply_ada_max.py +0 -68
  572. mindspore/ops/_op_impl/tbe/apply_ada_max_ds.py +0 -69
  573. mindspore/ops/_op_impl/tbe/apply_adadelta.py +0 -66
  574. mindspore/ops/_op_impl/tbe/apply_adadelta_ds.py +0 -67
  575. mindspore/ops/_op_impl/tbe/apply_adagrad.py +0 -55
  576. mindspore/ops/_op_impl/tbe/apply_adagrad_d_a.py +0 -67
  577. mindspore/ops/_op_impl/tbe/apply_adagrad_ds.py +0 -56
  578. mindspore/ops/_op_impl/tbe/apply_adagrad_v2.py +0 -48
  579. mindspore/ops/_op_impl/tbe/apply_adagrad_v2_ds.py +0 -49
  580. mindspore/ops/_op_impl/tbe/apply_adam.py +0 -79
  581. mindspore/ops/_op_impl/tbe/apply_adam_ds.py +0 -80
  582. mindspore/ops/_op_impl/tbe/apply_adam_with_amsgrad.py +0 -60
  583. mindspore/ops/_op_impl/tbe/apply_adam_with_amsgrad_ds.py +0 -61
  584. mindspore/ops/_op_impl/tbe/apply_add_sign.py +0 -65
  585. mindspore/ops/_op_impl/tbe/apply_add_sign_ds.py +0 -66
  586. mindspore/ops/_op_impl/tbe/apply_centered_rms_prop.py +0 -77
  587. mindspore/ops/_op_impl/tbe/apply_centered_rms_prop_ds.py +0 -78
  588. mindspore/ops/_op_impl/tbe/apply_ftrl.py +0 -67
  589. mindspore/ops/_op_impl/tbe/apply_ftrl_ds.py +0 -68
  590. mindspore/ops/_op_impl/tbe/apply_gradient_descent.py +0 -44
  591. mindspore/ops/_op_impl/tbe/apply_gradient_descent_ds.py +0 -45
  592. mindspore/ops/_op_impl/tbe/apply_keras_momentum.py +0 -49
  593. mindspore/ops/_op_impl/tbe/apply_momentum.py +0 -64
  594. mindspore/ops/_op_impl/tbe/apply_momentum_ds.py +0 -65
  595. mindspore/ops/_op_impl/tbe/apply_power_sign.py +0 -65
  596. mindspore/ops/_op_impl/tbe/apply_power_sign_ds.py +0 -66
  597. mindspore/ops/_op_impl/tbe/apply_proximal_adagrad.py +0 -57
  598. mindspore/ops/_op_impl/tbe/apply_proximal_adagrad_ds.py +0 -58
  599. mindspore/ops/_op_impl/tbe/apply_proximal_gradient_descent.py +0 -54
  600. mindspore/ops/_op_impl/tbe/apply_proximal_gradient_descent_ds.py +0 -55
  601. mindspore/ops/_op_impl/tbe/apply_rms_prop.py +0 -52
  602. mindspore/ops/_op_impl/tbe/approximate_equal.py +0 -39
  603. mindspore/ops/_op_impl/tbe/approximate_equal_ds.py +0 -40
  604. mindspore/ops/_op_impl/tbe/arg_max.py +0 -38
  605. mindspore/ops/_op_impl/tbe/arg_max_with_value.py +0 -38
  606. mindspore/ops/_op_impl/tbe/arg_max_with_value_ds.py +0 -39
  607. mindspore/ops/_op_impl/tbe/arg_min.py +0 -38
  608. mindspore/ops/_op_impl/tbe/arg_min_v2_ds.py +0 -40
  609. mindspore/ops/_op_impl/tbe/arg_min_with_value.py +0 -38
  610. mindspore/ops/_op_impl/tbe/arg_min_with_value_ds.py +0 -39
  611. mindspore/ops/_op_impl/tbe/asin.py +0 -37
  612. mindspore/ops/_op_impl/tbe/asin_ds.py +0 -38
  613. mindspore/ops/_op_impl/tbe/asin_grad.py +0 -43
  614. mindspore/ops/_op_impl/tbe/asin_grad_ds.py +0 -44
  615. mindspore/ops/_op_impl/tbe/asinh.py +0 -37
  616. mindspore/ops/_op_impl/tbe/asinh_ds.py +0 -38
  617. mindspore/ops/_op_impl/tbe/asinh_grad.py +0 -43
  618. mindspore/ops/_op_impl/tbe/asinh_grad_ds.py +0 -44
  619. mindspore/ops/_op_impl/tbe/assign.py +0 -79
  620. mindspore/ops/_op_impl/tbe/assign_add.py +0 -59
  621. mindspore/ops/_op_impl/tbe/assign_add_ds.py +0 -60
  622. mindspore/ops/_op_impl/tbe/assign_ds.py +0 -80
  623. mindspore/ops/_op_impl/tbe/assign_sub.py +0 -55
  624. mindspore/ops/_op_impl/tbe/assign_sub_ds.py +0 -56
  625. mindspore/ops/_op_impl/tbe/atan.py +0 -37
  626. mindspore/ops/_op_impl/tbe/atan2.py +0 -38
  627. mindspore/ops/_op_impl/tbe/atan2_ds.py +0 -39
  628. mindspore/ops/_op_impl/tbe/atan_ds.py +0 -38
  629. mindspore/ops/_op_impl/tbe/atan_grad.py +0 -43
  630. mindspore/ops/_op_impl/tbe/atan_grad_ds.py +0 -44
  631. mindspore/ops/_op_impl/tbe/atanh.py +0 -37
  632. mindspore/ops/_op_impl/tbe/atanh_ds.py +0 -38
  633. mindspore/ops/_op_impl/tbe/avg_pool.py +0 -43
  634. mindspore/ops/_op_impl/tbe/avg_pool_3d.py +0 -44
  635. mindspore/ops/_op_impl/tbe/avg_pool_3d_grad.py +0 -45
  636. mindspore/ops/_op_impl/tbe/avg_pool_ds.py +0 -44
  637. mindspore/ops/_op_impl/tbe/avg_pool_grad.py +0 -42
  638. mindspore/ops/_op_impl/tbe/avg_pool_grad_vm.py +0 -42
  639. mindspore/ops/_op_impl/tbe/basic_lstm_cell.py +0 -57
  640. mindspore/ops/_op_impl/tbe/basic_lstm_cell_c_state_grad.py +0 -50
  641. mindspore/ops/_op_impl/tbe/basic_lstm_cell_c_state_grad_v2.py +0 -51
  642. mindspore/ops/_op_impl/tbe/basic_lstm_cell_input_grad.py +0 -42
  643. mindspore/ops/_op_impl/tbe/basic_lstm_cell_weight_grad.py +0 -41
  644. mindspore/ops/_op_impl/tbe/batch_matmul.py +0 -42
  645. mindspore/ops/_op_impl/tbe/batch_matmul_ds.py +0 -41
  646. mindspore/ops/_op_impl/tbe/batch_matmul_v2.py +0 -47
  647. mindspore/ops/_op_impl/tbe/batch_to_space.py +0 -38
  648. mindspore/ops/_op_impl/tbe/batch_to_space_nd.py +0 -38
  649. mindspore/ops/_op_impl/tbe/batch_to_space_nd_ds.py +0 -39
  650. mindspore/ops/_op_impl/tbe/batch_to_space_nd_v2.py +0 -41
  651. mindspore/ops/_op_impl/tbe/batchnorm.py +0 -58
  652. mindspore/ops/_op_impl/tbe/batchnorm_grad.py +0 -58
  653. mindspore/ops/_op_impl/tbe/bce_with_logits_loss.py +0 -42
  654. mindspore/ops/_op_impl/tbe/bessel_i0e.py +0 -37
  655. mindspore/ops/_op_impl/tbe/bessel_i0e_ds.py +0 -38
  656. mindspore/ops/_op_impl/tbe/bessel_i1e.py +0 -37
  657. mindspore/ops/_op_impl/tbe/bessel_i1e_ds.py +0 -38
  658. mindspore/ops/_op_impl/tbe/bias_add.py +0 -38
  659. mindspore/ops/_op_impl/tbe/bias_add_ds.py +0 -39
  660. mindspore/ops/_op_impl/tbe/bias_add_grad.py +0 -53
  661. mindspore/ops/_op_impl/tbe/binary_cross_entropy.py +0 -39
  662. mindspore/ops/_op_impl/tbe/binary_cross_entropy_ds.py +0 -40
  663. mindspore/ops/_op_impl/tbe/binary_cross_entropy_grad.py +0 -44
  664. mindspore/ops/_op_impl/tbe/binary_cross_entropy_grad_ds.py +0 -45
  665. mindspore/ops/_op_impl/tbe/bitwise_and.py +0 -39
  666. mindspore/ops/_op_impl/tbe/bitwise_and_ds.py +0 -40
  667. mindspore/ops/_op_impl/tbe/bitwise_or.py +0 -39
  668. mindspore/ops/_op_impl/tbe/bitwise_or_ds.py +0 -40
  669. mindspore/ops/_op_impl/tbe/bitwise_xor.py +0 -39
  670. mindspore/ops/_op_impl/tbe/bitwise_xor_ds.py +0 -40
  671. mindspore/ops/_op_impl/tbe/bn_infer.py +0 -43
  672. mindspore/ops/_op_impl/tbe/bn_infer_ds.py +0 -45
  673. mindspore/ops/_op_impl/tbe/bn_infer_grad.py +0 -41
  674. mindspore/ops/_op_impl/tbe/bn_infer_grad_ds.py +0 -40
  675. mindspore/ops/_op_impl/tbe/bn_inference.py +0 -50
  676. mindspore/ops/_op_impl/tbe/bn_training_reduce.py +0 -38
  677. mindspore/ops/_op_impl/tbe/bn_training_reduce_ds.py +0 -39
  678. mindspore/ops/_op_impl/tbe/bn_training_reduce_grad.py +0 -46
  679. mindspore/ops/_op_impl/tbe/bn_training_reduce_grad_ds.py +0 -47
  680. mindspore/ops/_op_impl/tbe/bn_training_update.py +0 -52
  681. mindspore/ops/_op_impl/tbe/bn_training_update_ds.py +0 -53
  682. mindspore/ops/_op_impl/tbe/bn_training_update_grad.py +0 -44
  683. mindspore/ops/_op_impl/tbe/bn_training_update_grad_ds.py +0 -45
  684. mindspore/ops/_op_impl/tbe/bn_training_update_v2.py +0 -48
  685. mindspore/ops/_op_impl/tbe/bn_training_update_v3.py +0 -51
  686. mindspore/ops/_op_impl/tbe/bounding_box_decode.py +0 -41
  687. mindspore/ops/_op_impl/tbe/bounding_box_decode_ds.py +0 -42
  688. mindspore/ops/_op_impl/tbe/bounding_box_encode.py +0 -38
  689. mindspore/ops/_op_impl/tbe/broadcast_to.py +0 -40
  690. mindspore/ops/_op_impl/tbe/broadcast_to_ds.py +0 -44
  691. mindspore/ops/_op_impl/tbe/cast.py +0 -55
  692. mindspore/ops/_op_impl/tbe/cast_ds.py +0 -58
  693. mindspore/ops/_op_impl/tbe/cdist.py +0 -38
  694. mindspore/ops/_op_impl/tbe/cdist_grad.py +0 -42
  695. mindspore/ops/_op_impl/tbe/ceil.py +0 -37
  696. mindspore/ops/_op_impl/tbe/ceil_ds.py +0 -38
  697. mindspore/ops/_op_impl/tbe/celu.py +0 -39
  698. mindspore/ops/_op_impl/tbe/centralization.py +0 -39
  699. mindspore/ops/_op_impl/tbe/check_valid.py +0 -38
  700. mindspore/ops/_op_impl/tbe/check_valid_ds.py +0 -39
  701. mindspore/ops/_op_impl/tbe/clip_by_norm_no_div_sum.py +0 -41
  702. mindspore/ops/_op_impl/tbe/clip_by_norm_no_div_sum_ds.py +0 -42
  703. mindspore/ops/_op_impl/tbe/clip_by_value.py +0 -41
  704. mindspore/ops/_op_impl/tbe/clip_by_value_ds.py +0 -42
  705. mindspore/ops/_op_impl/tbe/concat.py +0 -40
  706. mindspore/ops/_op_impl/tbe/concat_ds.py +0 -38
  707. mindspore/ops/_op_impl/tbe/confusion_matrix.py +0 -63
  708. mindspore/ops/_op_impl/tbe/confusion_mul_grad.py +0 -40
  709. mindspore/ops/_op_impl/tbe/confusion_softmax_grad.py +0 -41
  710. mindspore/ops/_op_impl/tbe/confusion_transpose_d.py +0 -39
  711. mindspore/ops/_op_impl/tbe/conv2d.py +0 -47
  712. mindspore/ops/_op_impl/tbe/conv2d_backprop_filter.py +0 -42
  713. mindspore/ops/_op_impl/tbe/conv2d_backprop_filter_ds.py +0 -43
  714. mindspore/ops/_op_impl/tbe/conv2d_backprop_input.py +0 -42
  715. mindspore/ops/_op_impl/tbe/conv2d_backprop_input_ds.py +0 -44
  716. mindspore/ops/_op_impl/tbe/conv2d_ds.py +0 -47
  717. mindspore/ops/_op_impl/tbe/conv2d_transpose.py +0 -48
  718. mindspore/ops/_op_impl/tbe/conv3d.py +0 -45
  719. mindspore/ops/_op_impl/tbe/conv3d_backprop_filter.py +0 -42
  720. mindspore/ops/_op_impl/tbe/conv3d_backprop_input.py +0 -42
  721. mindspore/ops/_op_impl/tbe/conv3d_transpose.py +0 -47
  722. mindspore/ops/_op_impl/tbe/conv3d_transpose_ds.py +0 -48
  723. mindspore/ops/_op_impl/tbe/cos.py +0 -37
  724. mindspore/ops/_op_impl/tbe/cos_ds.py +0 -38
  725. mindspore/ops/_op_impl/tbe/cosh.py +0 -37
  726. mindspore/ops/_op_impl/tbe/cosh_ds.py +0 -38
  727. mindspore/ops/_op_impl/tbe/ctc_loss_v2.py +0 -42
  728. mindspore/ops/_op_impl/tbe/ctc_loss_v2_grad.py +0 -44
  729. mindspore/ops/_op_impl/tbe/cum_sum.py +0 -42
  730. mindspore/ops/_op_impl/tbe/cum_sum_ds.py +0 -44
  731. mindspore/ops/_op_impl/tbe/cummin.py +0 -41
  732. mindspore/ops/_op_impl/tbe/cumprod.py +0 -42
  733. mindspore/ops/_op_impl/tbe/data_format_dim_map.py +0 -38
  734. mindspore/ops/_op_impl/tbe/data_format_dim_map_ds.py +0 -40
  735. mindspore/ops/_op_impl/tbe/deformable_offsets.py +0 -45
  736. mindspore/ops/_op_impl/tbe/deformable_offsets_grad.py +0 -48
  737. mindspore/ops/_op_impl/tbe/depth_to_space_ds.py +0 -49
  738. mindspore/ops/_op_impl/tbe/depthwise_conv2d.py +0 -44
  739. mindspore/ops/_op_impl/tbe/depthwise_conv2d_backprop_filter.py +0 -41
  740. mindspore/ops/_op_impl/tbe/depthwise_conv2d_backprop_input.py +0 -41
  741. mindspore/ops/_op_impl/tbe/diag.py +0 -38
  742. mindspore/ops/_op_impl/tbe/diag_part.py +0 -38
  743. mindspore/ops/_op_impl/tbe/dilation.py +0 -40
  744. mindspore/ops/_op_impl/tbe/div.py +0 -41
  745. mindspore/ops/_op_impl/tbe/div_ds.py +0 -42
  746. mindspore/ops/_op_impl/tbe/div_no_nan.py +0 -41
  747. mindspore/ops/_op_impl/tbe/div_no_nan_ds.py +0 -42
  748. mindspore/ops/_op_impl/tbe/dropout_do_mask.py +0 -38
  749. mindspore/ops/_op_impl/tbe/dropout_do_mask_ds.py +0 -39
  750. mindspore/ops/_op_impl/tbe/dropout_do_mask_v3.py +0 -39
  751. mindspore/ops/_op_impl/tbe/dynamic_atomic_addr_clean.py +0 -34
  752. mindspore/ops/_op_impl/tbe/dynamic_gru_v2.py +0 -95
  753. mindspore/ops/_op_impl/tbe/dynamic_rnn.py +0 -82
  754. mindspore/ops/_op_impl/tbe/elu.py +0 -38
  755. mindspore/ops/_op_impl/tbe/elu_ds.py +0 -39
  756. mindspore/ops/_op_impl/tbe/elu_grad.py +0 -43
  757. mindspore/ops/_op_impl/tbe/elu_grad_ds.py +0 -44
  758. mindspore/ops/_op_impl/tbe/equal.py +0 -42
  759. mindspore/ops/_op_impl/tbe/equal_ds.py +0 -42
  760. mindspore/ops/_op_impl/tbe/erf.py +0 -37
  761. mindspore/ops/_op_impl/tbe/erf_ds.py +0 -38
  762. mindspore/ops/_op_impl/tbe/erfc.py +0 -37
  763. mindspore/ops/_op_impl/tbe/erfc_ds.py +0 -38
  764. mindspore/ops/_op_impl/tbe/erfinv.py +0 -36
  765. mindspore/ops/_op_impl/tbe/exp.py +0 -40
  766. mindspore/ops/_op_impl/tbe/exp_ds.py +0 -41
  767. mindspore/ops/_op_impl/tbe/expand_dims.py +0 -38
  768. mindspore/ops/_op_impl/tbe/expm1.py +0 -37
  769. mindspore/ops/_op_impl/tbe/expm1_ds.py +0 -38
  770. mindspore/ops/_op_impl/tbe/extract_image_patches.py +0 -41
  771. mindspore/ops/_op_impl/tbe/extract_volume_patches.py +0 -39
  772. mindspore/ops/_op_impl/tbe/fake_quant_with_min_max_vars.py +0 -39
  773. mindspore/ops/_op_impl/tbe/fake_quant_with_min_max_vars_gradient.py +0 -43
  774. mindspore/ops/_op_impl/tbe/fake_quant_with_min_max_vars_per_channel.py +0 -39
  775. mindspore/ops/_op_impl/tbe/fake_quant_with_min_max_vars_per_channel_gradient.py +0 -43
  776. mindspore/ops/_op_impl/tbe/fast_gelu.py +0 -37
  777. mindspore/ops/_op_impl/tbe/fast_gelu_ds.py +0 -38
  778. mindspore/ops/_op_impl/tbe/fast_gelu_grad.py +0 -41
  779. mindspore/ops/_op_impl/tbe/fast_gelu_grad_ds.py +0 -42
  780. mindspore/ops/_op_impl/tbe/fill.py +0 -56
  781. mindspore/ops/_op_impl/tbe/fill_ds.py +0 -42
  782. mindspore/ops/_op_impl/tbe/flatten.py +0 -48
  783. mindspore/ops/_op_impl/tbe/floor.py +0 -37
  784. mindspore/ops/_op_impl/tbe/floor_div.py +0 -41
  785. mindspore/ops/_op_impl/tbe/floor_div_ds.py +0 -42
  786. mindspore/ops/_op_impl/tbe/floor_ds.py +0 -38
  787. mindspore/ops/_op_impl/tbe/floor_mod.py +0 -39
  788. mindspore/ops/_op_impl/tbe/floor_mod_ds.py +0 -40
  789. mindspore/ops/_op_impl/tbe/fused_dbn_dw.py +0 -52
  790. mindspore/ops/_op_impl/tbe/fused_mul_add.py +0 -38
  791. mindspore/ops/_op_impl/tbe/fused_mul_add_n.py +0 -48
  792. mindspore/ops/_op_impl/tbe/fused_mul_add_n_l2loss.py +0 -53
  793. mindspore/ops/_op_impl/tbe/fused_mul_apply_momentum.py +0 -57
  794. mindspore/ops/_op_impl/tbe/fused_mul_apply_momentum_extern.py +0 -67
  795. mindspore/ops/_op_impl/tbe/gather_nd.py +0 -52
  796. mindspore/ops/_op_impl/tbe/gather_nd_ds.py +0 -48
  797. mindspore/ops/_op_impl/tbe/gather_v2.py +0 -56
  798. mindspore/ops/_op_impl/tbe/gather_v2_ds.py +0 -68
  799. mindspore/ops/_op_impl/tbe/gelu.py +0 -37
  800. mindspore/ops/_op_impl/tbe/gelu_ds.py +0 -38
  801. mindspore/ops/_op_impl/tbe/gelu_grad.py +0 -42
  802. mindspore/ops/_op_impl/tbe/gelu_grad_ds.py +0 -43
  803. mindspore/ops/_op_impl/tbe/ger.py +0 -43
  804. mindspore/ops/_op_impl/tbe/ger_ds.py +0 -44
  805. mindspore/ops/_op_impl/tbe/greater.py +0 -43
  806. mindspore/ops/_op_impl/tbe/greater_equal.py +0 -41
  807. mindspore/ops/_op_impl/tbe/greater_equal_ds.py +0 -42
  808. mindspore/ops/_op_impl/tbe/gru_v2_hidden_grad.py +0 -51
  809. mindspore/ops/_op_impl/tbe/gru_v2_hidden_grad_cell.py +0 -52
  810. mindspore/ops/_op_impl/tbe/hard_swish.py +0 -37
  811. mindspore/ops/_op_impl/tbe/hard_swish_ds.py +0 -38
  812. mindspore/ops/_op_impl/tbe/hard_swish_grad.py +0 -41
  813. mindspore/ops/_op_impl/tbe/hard_swish_grad_ds.py +0 -42
  814. mindspore/ops/_op_impl/tbe/histogram_fixed_width.py +0 -40
  815. mindspore/ops/_op_impl/tbe/hshrink.py +0 -33
  816. mindspore/ops/_op_impl/tbe/hshrink_grad.py +0 -37
  817. mindspore/ops/_op_impl/tbe/hsigmoid.py +0 -45
  818. mindspore/ops/_op_impl/tbe/hsigmoid_grad.py +0 -39
  819. mindspore/ops/_op_impl/tbe/ifmr.py +0 -47
  820. mindspore/ops/_op_impl/tbe/ifmr_ds.py +0 -48
  821. mindspore/ops/_op_impl/tbe/im2col.py +0 -42
  822. mindspore/ops/_op_impl/tbe/in_top_k.py +0 -37
  823. mindspore/ops/_op_impl/tbe/inplace_add.py +0 -39
  824. mindspore/ops/_op_impl/tbe/inplace_index_add.py +0 -46
  825. mindspore/ops/_op_impl/tbe/inplace_sub.py +0 -39
  826. mindspore/ops/_op_impl/tbe/inplace_update.py +0 -39
  827. mindspore/ops/_op_impl/tbe/inplace_update_ds.py +0 -40
  828. mindspore/ops/_op_impl/tbe/inv.py +0 -38
  829. mindspore/ops/_op_impl/tbe/inv_ds.py +0 -39
  830. mindspore/ops/_op_impl/tbe/inv_grad.py +0 -40
  831. mindspore/ops/_op_impl/tbe/inv_grad_ds.py +0 -41
  832. mindspore/ops/_op_impl/tbe/invert.py +0 -37
  833. mindspore/ops/_op_impl/tbe/invert_ds.py +0 -38
  834. mindspore/ops/_op_impl/tbe/iou.py +0 -38
  835. mindspore/ops/_op_impl/tbe/iou_ds.py +0 -39
  836. mindspore/ops/_op_impl/tbe/is_close.py +0 -40
  837. mindspore/ops/_op_impl/tbe/kl_div_loss.py +0 -38
  838. mindspore/ops/_op_impl/tbe/kl_div_loss_ds.py +0 -39
  839. mindspore/ops/_op_impl/tbe/kl_div_loss_grad.py +0 -40
  840. mindspore/ops/_op_impl/tbe/l2_loss.py +0 -36
  841. mindspore/ops/_op_impl/tbe/l2_loss_ds.py +0 -37
  842. mindspore/ops/_op_impl/tbe/l2_normalize.py +0 -38
  843. mindspore/ops/_op_impl/tbe/l2_normalize_grad.py +0 -40
  844. mindspore/ops/_op_impl/tbe/lamb_apply_optimizer_assign.py +0 -55
  845. mindspore/ops/_op_impl/tbe/lamb_apply_weight_assign.py +0 -42
  846. mindspore/ops/_op_impl/tbe/lamb_next_mv.py +0 -59
  847. mindspore/ops/_op_impl/tbe/lamb_next_mv_with_decay.py +0 -59
  848. mindspore/ops/_op_impl/tbe/lamb_next_right.py +0 -44
  849. mindspore/ops/_op_impl/tbe/lamb_update_with_lr.py +0 -48
  850. mindspore/ops/_op_impl/tbe/lamb_update_with_lr_v2.py +0 -44
  851. mindspore/ops/_op_impl/tbe/lars_update.py +0 -50
  852. mindspore/ops/_op_impl/tbe/lars_update_ds.py +0 -51
  853. mindspore/ops/_op_impl/tbe/layer_norm.py +0 -46
  854. mindspore/ops/_op_impl/tbe/layer_norm_beta_gamma_backprop.py +0 -44
  855. mindspore/ops/_op_impl/tbe/layer_norm_beta_gamma_backprop_ds.py +0 -45
  856. mindspore/ops/_op_impl/tbe/layer_norm_beta_gamma_backprop_v2.py +0 -40
  857. mindspore/ops/_op_impl/tbe/layer_norm_beta_gamma_backprop_v2_ds.py +0 -41
  858. mindspore/ops/_op_impl/tbe/layer_norm_ds.py +0 -47
  859. mindspore/ops/_op_impl/tbe/layer_norm_grad.py +0 -48
  860. mindspore/ops/_op_impl/tbe/layer_norm_x_backprop.py +0 -43
  861. mindspore/ops/_op_impl/tbe/layer_norm_x_backprop_ds.py +0 -44
  862. mindspore/ops/_op_impl/tbe/layer_norm_x_backprop_v2.py +0 -45
  863. mindspore/ops/_op_impl/tbe/layer_norm_x_backprop_v2_ds.py +0 -45
  864. mindspore/ops/_op_impl/tbe/lerp.py +0 -38
  865. mindspore/ops/_op_impl/tbe/less.py +0 -41
  866. mindspore/ops/_op_impl/tbe/less_ds.py +0 -42
  867. mindspore/ops/_op_impl/tbe/less_equal.py +0 -41
  868. mindspore/ops/_op_impl/tbe/less_equal_ds.py +0 -42
  869. mindspore/ops/_op_impl/tbe/log.py +0 -40
  870. mindspore/ops/_op_impl/tbe/log1p.py +0 -37
  871. mindspore/ops/_op_impl/tbe/log1p_ds.py +0 -38
  872. mindspore/ops/_op_impl/tbe/log_ds.py +0 -41
  873. mindspore/ops/_op_impl/tbe/logical_and.py +0 -37
  874. mindspore/ops/_op_impl/tbe/logical_and_ds.py +0 -38
  875. mindspore/ops/_op_impl/tbe/logical_not.py +0 -36
  876. mindspore/ops/_op_impl/tbe/logical_not_ds.py +0 -37
  877. mindspore/ops/_op_impl/tbe/logical_or.py +0 -37
  878. mindspore/ops/_op_impl/tbe/logical_or_ds.py +0 -38
  879. mindspore/ops/_op_impl/tbe/logsoftmax.py +0 -37
  880. mindspore/ops/_op_impl/tbe/logsoftmax_ds.py +0 -38
  881. mindspore/ops/_op_impl/tbe/logsoftmax_grad.py +0 -38
  882. mindspore/ops/_op_impl/tbe/logsoftmax_grad_ds.py +0 -39
  883. mindspore/ops/_op_impl/tbe/lp_norm.py +0 -40
  884. mindspore/ops/_op_impl/tbe/lp_norm_ds.py +0 -41
  885. mindspore/ops/_op_impl/tbe/lrn.py +0 -41
  886. mindspore/ops/_op_impl/tbe/lrn_grad.py +0 -42
  887. mindspore/ops/_op_impl/tbe/lstm_input_grad.py +0 -51
  888. mindspore/ops/_op_impl/tbe/masked_fill.py +0 -40
  889. mindspore/ops/_op_impl/tbe/masked_fill_ds.py +0 -41
  890. mindspore/ops/_op_impl/tbe/matmul.py +0 -53
  891. mindspore/ops/_op_impl/tbe/matmul_ds.py +0 -47
  892. mindspore/ops/_op_impl/tbe/matmul_v2.py +0 -50
  893. mindspore/ops/_op_impl/tbe/matrix_diag.py +0 -45
  894. mindspore/ops/_op_impl/tbe/matrix_diag_part.py +0 -45
  895. mindspore/ops/_op_impl/tbe/matrix_set_diag.py +0 -46
  896. mindspore/ops/_op_impl/tbe/max_pool.py +0 -39
  897. mindspore/ops/_op_impl/tbe/max_pool3d.py +0 -44
  898. mindspore/ops/_op_impl/tbe/max_pool3d_grad.py +0 -43
  899. mindspore/ops/_op_impl/tbe/max_pool3d_grad_grad.py +0 -44
  900. mindspore/ops/_op_impl/tbe/max_pool_ds.py +0 -40
  901. mindspore/ops/_op_impl/tbe/max_pool_grad.py +0 -43
  902. mindspore/ops/_op_impl/tbe/max_pool_grad_grad.py +0 -41
  903. mindspore/ops/_op_impl/tbe/max_pool_grad_grad_with_argmax.py +0 -41
  904. mindspore/ops/_op_impl/tbe/max_pool_grad_with_argmax.py +0 -42
  905. mindspore/ops/_op_impl/tbe/max_pool_with_argmax.py +0 -40
  906. mindspore/ops/_op_impl/tbe/maximum.py +0 -39
  907. mindspore/ops/_op_impl/tbe/maximum_ds.py +0 -40
  908. mindspore/ops/_op_impl/tbe/maximum_grad.py +0 -46
  909. mindspore/ops/_op_impl/tbe/maximum_grad_ds.py +0 -47
  910. mindspore/ops/_op_impl/tbe/mem_set.py +0 -38
  911. mindspore/ops/_op_impl/tbe/minimum.py +0 -40
  912. mindspore/ops/_op_impl/tbe/minimum_ds.py +0 -41
  913. mindspore/ops/_op_impl/tbe/minimum_grad.py +0 -46
  914. mindspore/ops/_op_impl/tbe/minimum_grad_ds.py +0 -47
  915. mindspore/ops/_op_impl/tbe/mish.py +0 -37
  916. mindspore/ops/_op_impl/tbe/mod.py +0 -41
  917. mindspore/ops/_op_impl/tbe/mod_ds.py +0 -42
  918. mindspore/ops/_op_impl/tbe/mul.py +0 -37
  919. mindspore/ops/_op_impl/tbe/mul_ds.py +0 -38
  920. mindspore/ops/_op_impl/tbe/mul_no_nan.py +0 -39
  921. mindspore/ops/_op_impl/tbe/mul_no_nan_ds.py +0 -40
  922. mindspore/ops/_op_impl/tbe/multilabel_margin_loss.py +0 -39
  923. mindspore/ops/_op_impl/tbe/neg.py +0 -39
  924. mindspore/ops/_op_impl/tbe/neg_ds.py +0 -40
  925. mindspore/ops/_op_impl/tbe/new_im2col.py +0 -40
  926. mindspore/ops/_op_impl/tbe/nll_loss.py +0 -41
  927. mindspore/ops/_op_impl/tbe/nll_loss_grad.py +0 -44
  928. mindspore/ops/_op_impl/tbe/nms_with_mask.py +0 -39
  929. mindspore/ops/_op_impl/tbe/not_equal.py +0 -41
  930. mindspore/ops/_op_impl/tbe/not_equal_ds.py +0 -42
  931. mindspore/ops/_op_impl/tbe/npu_alloc_float_status.py +0 -34
  932. mindspore/ops/_op_impl/tbe/npu_clear_float_status.py +0 -35
  933. mindspore/ops/_op_impl/tbe/npu_clear_float_status_v2.py +0 -35
  934. mindspore/ops/_op_impl/tbe/npu_get_float_status.py +0 -35
  935. mindspore/ops/_op_impl/tbe/npu_get_float_status_v2.py +0 -35
  936. mindspore/ops/_op_impl/tbe/one_hot.py +0 -48
  937. mindspore/ops/_op_impl/tbe/one_hot_ds.py +0 -45
  938. mindspore/ops/_op_impl/tbe/ones_like.py +0 -40
  939. mindspore/ops/_op_impl/tbe/ones_like_ds.py +0 -41
  940. mindspore/ops/_op_impl/tbe/p_s_r_o_i_pooling.py +0 -40
  941. mindspore/ops/_op_impl/tbe/p_s_r_o_i_pooling_grad.py +0 -40
  942. mindspore/ops/_op_impl/tbe/pack.py +0 -58
  943. mindspore/ops/_op_impl/tbe/pack_ds.py +0 -59
  944. mindspore/ops/_op_impl/tbe/pad_d.py +0 -40
  945. mindspore/ops/_op_impl/tbe/pad_d_ds.py +0 -41
  946. mindspore/ops/_op_impl/tbe/parallel_concat.py +0 -70
  947. mindspore/ops/_op_impl/tbe/parallel_resize_bilinear.py +0 -45
  948. mindspore/ops/_op_impl/tbe/parallel_resize_bilinear_grad.py +0 -44
  949. mindspore/ops/_op_impl/tbe/pdist.py +0 -36
  950. mindspore/ops/_op_impl/tbe/pooling.py +0 -46
  951. mindspore/ops/_op_impl/tbe/population_count.py +0 -38
  952. mindspore/ops/_op_impl/tbe/pow.py +0 -41
  953. mindspore/ops/_op_impl/tbe/pow_ds.py +0 -42
  954. mindspore/ops/_op_impl/tbe/prelu.py +0 -37
  955. mindspore/ops/_op_impl/tbe/prelu_ds.py +0 -38
  956. mindspore/ops/_op_impl/tbe/prelu_grad.py +0 -40
  957. mindspore/ops/_op_impl/tbe/range.py +0 -39
  958. mindspore/ops/_op_impl/tbe/real_div.py +0 -38
  959. mindspore/ops/_op_impl/tbe/real_div_ds.py +0 -39
  960. mindspore/ops/_op_impl/tbe/reciprocal.py +0 -36
  961. mindspore/ops/_op_impl/tbe/reciprocal_ds.py +0 -37
  962. mindspore/ops/_op_impl/tbe/reciprocal_grad.py +0 -38
  963. mindspore/ops/_op_impl/tbe/reciprocal_grad_ds.py +0 -39
  964. mindspore/ops/_op_impl/tbe/reduce_all.py +0 -38
  965. mindspore/ops/_op_impl/tbe/reduce_all_ds.py +0 -39
  966. mindspore/ops/_op_impl/tbe/reduce_any.py +0 -38
  967. mindspore/ops/_op_impl/tbe/reduce_any_ds.py +0 -39
  968. mindspore/ops/_op_impl/tbe/reduce_max.py +0 -43
  969. mindspore/ops/_op_impl/tbe/reduce_max_ds.py +0 -41
  970. mindspore/ops/_op_impl/tbe/reduce_mean.py +0 -40
  971. mindspore/ops/_op_impl/tbe/reduce_mean_ds.py +0 -42
  972. mindspore/ops/_op_impl/tbe/reduce_min.py +0 -41
  973. mindspore/ops/_op_impl/tbe/reduce_min_ds.py +0 -41
  974. mindspore/ops/_op_impl/tbe/reduce_prod.py +0 -42
  975. mindspore/ops/_op_impl/tbe/reduce_prod_ds.py +0 -41
  976. mindspore/ops/_op_impl/tbe/reduce_std.py +0 -44
  977. mindspore/ops/_op_impl/tbe/reduce_sum.py +0 -39
  978. mindspore/ops/_op_impl/tbe/reduce_sum_ds.py +0 -41
  979. mindspore/ops/_op_impl/tbe/relu.py +0 -39
  980. mindspore/ops/_op_impl/tbe/relu6.py +0 -38
  981. mindspore/ops/_op_impl/tbe/relu6_ds.py +0 -39
  982. mindspore/ops/_op_impl/tbe/relu6_grad.py +0 -43
  983. mindspore/ops/_op_impl/tbe/relu6_grad_ds.py +0 -44
  984. mindspore/ops/_op_impl/tbe/relu_ds.py +0 -40
  985. mindspore/ops/_op_impl/tbe/relu_grad.py +0 -41
  986. mindspore/ops/_op_impl/tbe/relu_grad_ds.py +0 -42
  987. mindspore/ops/_op_impl/tbe/relu_grad_v2.py +0 -40
  988. mindspore/ops/_op_impl/tbe/relu_grad_v2_ds.py +0 -41
  989. mindspore/ops/_op_impl/tbe/relu_v2.py +0 -40
  990. mindspore/ops/_op_impl/tbe/relu_v2_ds.py +0 -41
  991. mindspore/ops/_op_impl/tbe/renorm.py +0 -39
  992. mindspore/ops/_op_impl/tbe/resize_bilinear.py +0 -40
  993. mindspore/ops/_op_impl/tbe/resize_bilinear_grad.py +0 -41
  994. mindspore/ops/_op_impl/tbe/resize_bilinear_v2.py +0 -43
  995. mindspore/ops/_op_impl/tbe/resize_nearest_neighbor.py +0 -40
  996. mindspore/ops/_op_impl/tbe/resize_nearest_neighbor_ds.py +0 -40
  997. mindspore/ops/_op_impl/tbe/resize_nearest_neighbor_grad.py +0 -39
  998. mindspore/ops/_op_impl/tbe/resize_nearest_neighbor_grad_ds.py +0 -42
  999. mindspore/ops/_op_impl/tbe/reverse_v2_d.py +0 -37
  1000. mindspore/ops/_op_impl/tbe/rint.py +0 -37
  1001. mindspore/ops/_op_impl/tbe/rint_ds.py +0 -38
  1002. mindspore/ops/_op_impl/tbe/roi_align.py +0 -43
  1003. mindspore/ops/_op_impl/tbe/roi_align_ds.py +0 -44
  1004. mindspore/ops/_op_impl/tbe/roi_align_grad.py +0 -43
  1005. mindspore/ops/_op_impl/tbe/roi_align_grad_ds.py +0 -44
  1006. mindspore/ops/_op_impl/tbe/roll.py +0 -42
  1007. mindspore/ops/_op_impl/tbe/round.py +0 -38
  1008. mindspore/ops/_op_impl/tbe/round_ds.py +0 -39
  1009. mindspore/ops/_op_impl/tbe/rsqrt.py +0 -37
  1010. mindspore/ops/_op_impl/tbe/rsqrt_ds.py +0 -38
  1011. mindspore/ops/_op_impl/tbe/rsqrt_grad.py +0 -40
  1012. mindspore/ops/_op_impl/tbe/rsqrt_grad_ds.py +0 -41
  1013. mindspore/ops/_op_impl/tbe/scatter_add.py +0 -44
  1014. mindspore/ops/_op_impl/tbe/scatter_div.py +0 -46
  1015. mindspore/ops/_op_impl/tbe/scatter_max.py +0 -45
  1016. mindspore/ops/_op_impl/tbe/scatter_min.py +0 -45
  1017. mindspore/ops/_op_impl/tbe/scatter_mul.py +0 -44
  1018. mindspore/ops/_op_impl/tbe/scatter_nd.py +0 -41
  1019. mindspore/ops/_op_impl/tbe/scatter_nd_add.py +0 -45
  1020. mindspore/ops/_op_impl/tbe/scatter_nd_d.py +0 -41
  1021. mindspore/ops/_op_impl/tbe/scatter_nd_ds.py +0 -49
  1022. mindspore/ops/_op_impl/tbe/scatter_nd_sub.py +0 -47
  1023. mindspore/ops/_op_impl/tbe/scatter_nd_sub_ds.py +0 -48
  1024. mindspore/ops/_op_impl/tbe/scatter_nd_update.py +0 -47
  1025. mindspore/ops/_op_impl/tbe/scatter_nd_update_ds.py +0 -48
  1026. mindspore/ops/_op_impl/tbe/scatter_non_aliasing_add.py +0 -39
  1027. mindspore/ops/_op_impl/tbe/scatter_non_aliasing_add_ds.py +0 -40
  1028. mindspore/ops/_op_impl/tbe/scatter_sub.py +0 -47
  1029. mindspore/ops/_op_impl/tbe/scatter_sub_ds.py +0 -48
  1030. mindspore/ops/_op_impl/tbe/scatter_update.py +0 -43
  1031. mindspore/ops/_op_impl/tbe/select.py +0 -38
  1032. mindspore/ops/_op_impl/tbe/select_ds.py +0 -39
  1033. mindspore/ops/_op_impl/tbe/selu.py +0 -39
  1034. mindspore/ops/_op_impl/tbe/selu_ds.py +0 -40
  1035. mindspore/ops/_op_impl/tbe/sgd.py +0 -62
  1036. mindspore/ops/_op_impl/tbe/sigmoid.py +0 -37
  1037. mindspore/ops/_op_impl/tbe/sigmoid_cross_entropy_with_logits.py +0 -41
  1038. mindspore/ops/_op_impl/tbe/sigmoid_cross_entropy_with_logits_ds.py +0 -42
  1039. mindspore/ops/_op_impl/tbe/sigmoid_cross_entropy_with_logits_grad.py +0 -42
  1040. mindspore/ops/_op_impl/tbe/sigmoid_cross_entropy_with_logits_grad_ds.py +0 -43
  1041. mindspore/ops/_op_impl/tbe/sigmoid_ds.py +0 -38
  1042. mindspore/ops/_op_impl/tbe/sigmoid_grad.py +0 -39
  1043. mindspore/ops/_op_impl/tbe/sigmoid_grad_ds.py +0 -40
  1044. mindspore/ops/_op_impl/tbe/sign.py +0 -38
  1045. mindspore/ops/_op_impl/tbe/sign_ds.py +0 -39
  1046. mindspore/ops/_op_impl/tbe/sin.py +0 -37
  1047. mindspore/ops/_op_impl/tbe/sin_ds.py +0 -38
  1048. mindspore/ops/_op_impl/tbe/sinh.py +0 -37
  1049. mindspore/ops/_op_impl/tbe/sinh_ds.py +0 -38
  1050. mindspore/ops/_op_impl/tbe/slice.py +0 -58
  1051. mindspore/ops/_op_impl/tbe/smooth_l1_loss.py +0 -45
  1052. mindspore/ops/_op_impl/tbe/smooth_l1_loss_ds.py +0 -46
  1053. mindspore/ops/_op_impl/tbe/smooth_l1_loss_grad.py +0 -46
  1054. mindspore/ops/_op_impl/tbe/smooth_l1_loss_grad_ds.py +0 -47
  1055. mindspore/ops/_op_impl/tbe/soft_margin_loss.py +0 -38
  1056. mindspore/ops/_op_impl/tbe/soft_margin_loss_grad.py +0 -39
  1057. mindspore/ops/_op_impl/tbe/soft_shrink.py +0 -36
  1058. mindspore/ops/_op_impl/tbe/soft_shrink_grad.py +0 -38
  1059. mindspore/ops/_op_impl/tbe/softmax.py +0 -37
  1060. mindspore/ops/_op_impl/tbe/softmax_cross_entropy_with_logits.py +0 -38
  1061. mindspore/ops/_op_impl/tbe/softmax_cross_entropy_with_logits_ds.py +0 -39
  1062. mindspore/ops/_op_impl/tbe/softmax_ds.py +0 -38
  1063. mindspore/ops/_op_impl/tbe/softmax_grad_ext.py +0 -42
  1064. mindspore/ops/_op_impl/tbe/softmax_v2_with_dropout_do_mask_v3.py +0 -39
  1065. mindspore/ops/_op_impl/tbe/softplus.py +0 -37
  1066. mindspore/ops/_op_impl/tbe/softplus_ds.py +0 -38
  1067. mindspore/ops/_op_impl/tbe/softplus_grad.py +0 -38
  1068. mindspore/ops/_op_impl/tbe/softplus_grad_ds.py +0 -38
  1069. mindspore/ops/_op_impl/tbe/softsign.py +0 -37
  1070. mindspore/ops/_op_impl/tbe/softsign_ds.py +0 -38
  1071. mindspore/ops/_op_impl/tbe/sort.py +0 -38
  1072. mindspore/ops/_op_impl/tbe/sort_ds.py +0 -39
  1073. mindspore/ops/_op_impl/tbe/space_to_batch.py +0 -38
  1074. mindspore/ops/_op_impl/tbe/space_to_batch_nd.py +0 -38
  1075. mindspore/ops/_op_impl/tbe/space_to_depth.py +0 -47
  1076. mindspore/ops/_op_impl/tbe/sparse_apply_adadelta.py +0 -56
  1077. mindspore/ops/_op_impl/tbe/sparse_apply_adagrad.py +0 -45
  1078. mindspore/ops/_op_impl/tbe/sparse_apply_adagrad_ds.py +0 -46
  1079. mindspore/ops/_op_impl/tbe/sparse_apply_adagrad_v2.py +0 -46
  1080. mindspore/ops/_op_impl/tbe/sparse_apply_adagrad_v2_ds.py +0 -47
  1081. mindspore/ops/_op_impl/tbe/sparse_apply_ftrl_d.py +0 -53
  1082. mindspore/ops/_op_impl/tbe/sparse_apply_ftrl_d_ds.py +0 -50
  1083. mindspore/ops/_op_impl/tbe/sparse_apply_ftrl_v2.py +0 -50
  1084. mindspore/ops/_op_impl/tbe/sparse_apply_proximal_adagrad.py +0 -66
  1085. mindspore/ops/_op_impl/tbe/sparse_apply_proximal_adagrad_ds.py +0 -67
  1086. mindspore/ops/_op_impl/tbe/sparse_apply_r_m_s_prop.py +0 -57
  1087. mindspore/ops/_op_impl/tbe/sparse_apply_r_m_s_prop_ds.py +0 -58
  1088. mindspore/ops/_op_impl/tbe/sparse_gather_v2.py +0 -56
  1089. mindspore/ops/_op_impl/tbe/sparse_gather_v2_ds.py +0 -58
  1090. mindspore/ops/_op_impl/tbe/split_d.py +0 -38
  1091. mindspore/ops/_op_impl/tbe/split_d_ds.py +0 -39
  1092. mindspore/ops/_op_impl/tbe/split_v.py +0 -39
  1093. mindspore/ops/_op_impl/tbe/splitv.py +0 -39
  1094. mindspore/ops/_op_impl/tbe/sqrt.py +0 -37
  1095. mindspore/ops/_op_impl/tbe/sqrt_ds.py +0 -38
  1096. mindspore/ops/_op_impl/tbe/sqrt_grad.py +0 -43
  1097. mindspore/ops/_op_impl/tbe/sqrt_grad_ds.py +0 -44
  1098. mindspore/ops/_op_impl/tbe/square.py +0 -38
  1099. mindspore/ops/_op_impl/tbe/square_ds.py +0 -39
  1100. mindspore/ops/_op_impl/tbe/square_sum_all.py +0 -40
  1101. mindspore/ops/_op_impl/tbe/square_sum_all_ds.py +0 -41
  1102. mindspore/ops/_op_impl/tbe/square_sum_v1.py +0 -38
  1103. mindspore/ops/_op_impl/tbe/square_sum_v1_ds.py +0 -39
  1104. mindspore/ops/_op_impl/tbe/square_sum_v2.py +0 -39
  1105. mindspore/ops/_op_impl/tbe/squared_difference.py +0 -39
  1106. mindspore/ops/_op_impl/tbe/squared_difference_ds.py +0 -41
  1107. mindspore/ops/_op_impl/tbe/squeeze.py +0 -37
  1108. mindspore/ops/_op_impl/tbe/strided_read.py +0 -38
  1109. mindspore/ops/_op_impl/tbe/strided_slice_d.py +0 -44
  1110. mindspore/ops/_op_impl/tbe/strided_slice_ds.py +0 -71
  1111. mindspore/ops/_op_impl/tbe/strided_slice_grad_d.py +0 -51
  1112. mindspore/ops/_op_impl/tbe/strided_slice_grad_ds.py +0 -57
  1113. mindspore/ops/_op_impl/tbe/strided_write.py +0 -38
  1114. mindspore/ops/_op_impl/tbe/sub.py +0 -39
  1115. mindspore/ops/_op_impl/tbe/sub_ds.py +0 -40
  1116. mindspore/ops/_op_impl/tbe/tan.py +0 -38
  1117. mindspore/ops/_op_impl/tbe/tan_ds.py +0 -39
  1118. mindspore/ops/_op_impl/tbe/tanh.py +0 -37
  1119. mindspore/ops/_op_impl/tbe/tanh_ds.py +0 -38
  1120. mindspore/ops/_op_impl/tbe/tanh_grad.py +0 -39
  1121. mindspore/ops/_op_impl/tbe/tanh_grad_ds.py +0 -40
  1122. mindspore/ops/_op_impl/tbe/tensor_move.py +0 -49
  1123. mindspore/ops/_op_impl/tbe/tensor_move_ds.py +0 -50
  1124. mindspore/ops/_op_impl/tbe/tensor_scatter_update.py +0 -41
  1125. mindspore/ops/_op_impl/tbe/tile.py +0 -37
  1126. mindspore/ops/_op_impl/tbe/tile_ds.py +0 -42
  1127. mindspore/ops/_op_impl/tbe/top_k.py +0 -42
  1128. mindspore/ops/_op_impl/tbe/top_k_ds.py +0 -43
  1129. mindspore/ops/_op_impl/tbe/trans_data.py +0 -167
  1130. mindspore/ops/_op_impl/tbe/trans_data_ds.py +0 -180
  1131. mindspore/ops/_op_impl/tbe/trans_data_rnn.py +0 -44
  1132. mindspore/ops/_op_impl/tbe/transpose.py +0 -60
  1133. mindspore/ops/_op_impl/tbe/transpose_d.py +0 -47
  1134. mindspore/ops/_op_impl/tbe/transpose_nod.py +0 -60
  1135. mindspore/ops/_op_impl/tbe/trunc.py +0 -39
  1136. mindspore/ops/_op_impl/tbe/truncate_div.py +0 -41
  1137. mindspore/ops/_op_impl/tbe/truncate_div_ds.py +0 -42
  1138. mindspore/ops/_op_impl/tbe/truncate_mod.py +0 -41
  1139. mindspore/ops/_op_impl/tbe/truncate_mod_ds.py +0 -42
  1140. mindspore/ops/_op_impl/tbe/unpack.py +0 -38
  1141. mindspore/ops/_op_impl/tbe/unpack_ds.py +0 -39
  1142. mindspore/ops/_op_impl/tbe/unsorted_segment_max.py +0 -49
  1143. mindspore/ops/_op_impl/tbe/unsorted_segment_max_ds.py +0 -40
  1144. mindspore/ops/_op_impl/tbe/unsorted_segment_min.py +0 -49
  1145. mindspore/ops/_op_impl/tbe/unsorted_segment_min_ds.py +0 -40
  1146. mindspore/ops/_op_impl/tbe/unsorted_segment_prod.py +0 -49
  1147. mindspore/ops/_op_impl/tbe/unsorted_segment_prod_ds.py +0 -38
  1148. mindspore/ops/_op_impl/tbe/unsorted_segment_sum.py +0 -38
  1149. mindspore/ops/_op_impl/tbe/unsorted_segment_sum_ds.py +0 -41
  1150. mindspore/ops/_op_impl/tbe/wts_arq.py +0 -40
  1151. mindspore/ops/_op_impl/tbe/xdivy.py +0 -38
  1152. mindspore/ops/_op_impl/tbe/xdivy_ds.py +0 -39
  1153. mindspore/ops/_op_impl/tbe/xlogy.py +0 -38
  1154. mindspore/ops/_op_impl/tbe/xlogy_ds.py +0 -39
  1155. mindspore/ops/_op_impl/tbe/zeros_like.py +0 -41
  1156. mindspore/ops/_op_impl/tbe/zeros_like_ds.py +0 -42
  1157. mindspore/ops/_tracefunc.py +0 -241
  1158. mindspore/ops/arg_dtype_cast.py +0 -54
  1159. mindspore/rewrite/api/tree_node_helper.py +0 -60
  1160. mindspore/rewrite/ast_helpers/ast_creator.py +0 -115
  1161. mindspore/rewrite/ast_transformers/flatten_recursive_stmt.py +0 -267
  1162. mindspore/rewrite/ast_transformers/remove_return_out_of_if.py +0 -228
  1163. mindspore/rewrite/namespace.py +0 -53
  1164. mindspore-2.2.14.dist-info/RECORD +0 -1924
  1165. {mindspore-2.2.14.dist-info → mindspore-2.3.0.dist-info}/WHEEL +0 -0
  1166. {mindspore-2.2.14.dist-info → mindspore-2.3.0.dist-info}/top_level.txt +0 -0
@@ -30,6 +30,16 @@ from mindspore.ops.primitive import Primitive
30
30
  from mindspore.ops.primitive import PrimitiveWithInfer
31
31
  from mindspore.ops.primitive import PrimitiveWithCheck
32
32
  from mindspore.ops.primitive import prim_attr_register
33
+ from ..auto_generate import (CeLU, Flatten, LogSoftmax, ReLU, ReLU6, Dense, Tanh,
34
+ Elu, Sigmoid, Softmax, SoftplusExt, HSwish, HSigmoid, AvgPool, BiasAdd,
35
+ NLLLoss, OneHot, GeLU, FastGeLU, PReLU, RmsNorm,
36
+ GridSampler3D, GridSampler2D, LayerNorm, LayerNormExt, HShrink, AdamWeightDecay, Dropout,
37
+ ApplyRotaryPosEmb, PagedAttention, PagedAttentionMask, ReshapeAndCache,
38
+ FlashAttentionScore, Embedding, UpsampleNearest1D, UpsampleNearest2D,
39
+ UpsampleNearest3D, UpsampleTrilinear3D,
40
+ UpsampleBilinear2D, UpsampleLinear1D,
41
+ BinaryCrossEntropy, BCEWithLogitsLoss)
42
+ from .manually_defined import BatchNorm
33
43
 
34
44
 
35
45
  def _check_positive_int_or_tuple(arg_name, arg_value, prim_name, allow_four=False,
@@ -95,83 +105,6 @@ def _update_attr_by_format(arg_value, arg_format):
95
105
  return ret
96
106
 
97
107
 
98
- class CeLU(Primitive):
99
- r"""
100
- Computes CeLU (Continuously differentiable exponential linear units) of input tensors element-wise.
101
-
102
- Refer to :func:`mindspore.ops.celu` for more details.
103
-
104
- .. warning::
105
- This is an experimental API that is subject to change or deletion.
106
-
107
- Args:
108
- alpha (float, optional): The :math:`\alpha` value for the Celu formulation. Default: ``1.0`` .
109
-
110
- Inputs:
111
- - **input_x** (Tensor) - The input tensor with a dtype of float16 or float32.
112
-
113
- Outputs:
114
- Tensor, with the same type and shape as the `input_x`.
115
-
116
- Supported Platforms:
117
- ``Ascend`` ``GPU`` ``CPU``
118
-
119
- Examples:
120
- >>> import mindspore
121
- >>> import numpy as np
122
- >>> from mindspore import Tensor, ops
123
- >>> input_x = Tensor(np.array([-2.0, -1.0, 1.0, 2.0]), mindspore.float32)
124
- >>> celu = ops.CeLU(alpha=1.0)
125
- >>> output = celu(input_x)
126
- >>> print(output)
127
- [-0.86466473 -0.63212055 1. 2. ]
128
- >>> input_x = Tensor(2.1, mindspore.float32)
129
- >>> output = celu(input_x)
130
- >>> print(output)
131
- 2.1
132
- """
133
-
134
- @prim_attr_register
135
- def __init__(self, alpha=1.0):
136
- """Initialize CeLU"""
137
- validator.check_value_type("alpha", alpha, [float], self.name)
138
- validator.check_float(alpha, 0.0, validator.NE, "alpha", self.name)
139
- self.alpha = alpha
140
- self.add_prim_attr('alpha', self.alpha)
141
-
142
-
143
- class Flatten(Primitive):
144
- r"""
145
- Flattens a tensor without changing its batch size on the 0-th axis.
146
-
147
- Refer to :func:`mindspore.ops.flatten` for more details.
148
-
149
- Inputs:
150
- - **input_x** (Tensor) - Tensor of shape :math:`(N, \ldots)` to be flattened, where :math:`N` is batch size.
151
-
152
- Outputs:
153
- Tensor, the shape of the output tensor is :math:`(N, X)`, where :math:`X` is
154
- the product of the remaining dimension.
155
-
156
- Supported Platforms:
157
- ``Ascend`` ``GPU`` ``CPU``
158
-
159
- Examples:
160
- >>> import mindspore
161
- >>> import numpy as np
162
- >>> from mindspore import Tensor, ops
163
- >>> input_x = Tensor(np.ones(shape=[1, 2, 3, 4]), mindspore.float32)
164
- >>> flatten = ops.Flatten()
165
- >>> output = flatten(input_x)
166
- >>> print(output.shape)
167
- (1, 24)
168
- """
169
-
170
- @prim_attr_register
171
- def __init__(self):
172
- pass
173
-
174
-
175
108
  class AdaptiveAvgPool3D(Primitive):
176
109
  r"""
177
110
  AdaptiveAvgPool3D operation.
@@ -427,86 +360,6 @@ class AdaptiveMaxPool3D(Primitive):
427
360
  self.init_prim_io_names(inputs=['x', 'output_size'], outputs=['y', 'argmax'])
428
361
 
429
362
 
430
- class Softmax(Primitive):
431
- r"""
432
- Applies the Softmax operation to the input tensor on the specified axis.
433
-
434
- Refer to :func:`mindspore.ops.softmax` for more details.
435
-
436
- Args:
437
- axis (Union[int, tuple]): The axis to perform the Softmax operation. Default: ``-1`` .
438
-
439
- Inputs:
440
- - **logits** (Tensor) - Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
441
- additional dimensions. Supported dtypes:
442
-
443
- - Ascend: float16, float32.
444
- - GPU/CPU: float16, float32, float64.
445
-
446
- Outputs:
447
- Tensor, with the same type and shape as the logits.
448
-
449
- Supported Platforms:
450
- ``Ascend`` ``GPU`` ``CPU``
451
-
452
- Examples:
453
- >>> import mindspore
454
- >>> import numpy as np
455
- >>> from mindspore import Tensor, ops
456
- >>> logits = Tensor(np.array([1, 2, 3, 4, 5]), mindspore.float32)
457
- >>> softmax = ops.Softmax()
458
- >>> output = softmax(logits)
459
- >>> print(output)
460
- [0.01165623 0.03168492 0.08612854 0.23412167 0.6364086 ]
461
- """
462
-
463
- @prim_attr_register
464
- def __init__(self, axis=-1):
465
- """Initialize Softmax."""
466
- self.init_prim_io_names(inputs=['x'], outputs=['output'])
467
- validator.check_value_type("axis", axis, [int, tuple], self.name)
468
- if isinstance(axis, int):
469
- self.add_prim_attr('axis', (axis,))
470
- for item in self.axis:
471
- validator.check_value_type("item of axis", item, [int], self.name)
472
-
473
-
474
- class LogSoftmax(Primitive):
475
- r"""
476
- Log Softmax activation function.
477
-
478
- Refer to :func:`mindspore.ops.log_softmax` for more details.
479
-
480
- Args:
481
- axis (int, optional): The axis to perform the Log softmax operation. Default: ``-1`` .
482
-
483
- Inputs:
484
- - **logits** (Tensor) - Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
485
- additional dimensions, with float16 or float32 data type.
486
-
487
- Outputs:
488
- Tensor, with the same type and shape as the `logits`.
489
-
490
- Supported Platforms:
491
- ``Ascend`` ``GPU`` ``CPU``
492
-
493
- Examples:
494
- >>> import mindspore
495
- >>> import numpy as np
496
- >>> from mindspore import Tensor, ops
497
- >>> logits = Tensor(np.array([1, 2, 3, 4, 5]), mindspore.float32)
498
- >>> log_softmax = ops.LogSoftmax()
499
- >>> output = log_softmax(logits)
500
- >>> print(output)
501
- [-4.4519143 -3.4519143 -2.4519143 -1.4519144 -0.4519144]
502
- """
503
-
504
- @prim_attr_register
505
- def __init__(self, axis=-1):
506
- """Initialize LogSoftmax."""
507
- validator.check_value_type("axis", axis, [int], self.name)
508
-
509
-
510
363
  class Softplus(Primitive):
511
364
  r"""
512
365
  Softplus activation function.
@@ -586,39 +439,6 @@ class Softsign(Primitive):
586
439
  self.init_prim_io_names(inputs=['x'], outputs=['output'])
587
440
 
588
441
 
589
- class ReLU(Primitive):
590
- r"""
591
- Computes ReLU (Rectified Linear Unit activation function) of input tensors element-wise.
592
-
593
- Refer to :func:`mindspore.ops.relu` for more details.
594
-
595
- Inputs:
596
- - **input_x** (Tensor) - Input Tensor of numeric types.
597
-
598
- Outputs:
599
- Tensor, has the same dtype and shape as `input_x`.
600
-
601
- Supported Platforms:
602
- ``Ascend`` ``GPU`` ``CPU``
603
-
604
- Examples:
605
- >>> import mindspore
606
- >>> import numpy as np
607
- >>> from mindspore import Tensor, ops
608
- >>> input_x = Tensor(np.array([[-1.0, 4.0, -8.0], [2.0, -5.0, 9.0]]), mindspore.float32)
609
- >>> relu = ops.ReLU()
610
- >>> output = relu(input_x)
611
- >>> print(output)
612
- [[0. 4. 0.]
613
- [2. 0. 9.]]
614
- """
615
-
616
- @prim_attr_register
617
- def __init__(self):
618
- """Initialize ReLU"""
619
- self.init_prim_io_names(inputs=['x'], outputs=['output'])
620
-
621
-
622
442
  class ReLUV3(Primitive):
623
443
  r"""
624
444
  Computes ReLUV3 (Rectified Linear Unit activation function) of input tensors element-wise.
@@ -633,7 +453,7 @@ class ReLUV3(Primitive):
633
453
  Inputs:
634
454
  - **input_x** (Tensor) - Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
635
455
  additional dimensions, data type is
636
- `number <https://www.mindspore.cn/docs/en/r2.2/api_python/mindspore.html#mindspore.dtype>`_.
456
+ `number <https://www.mindspore.cn/docs/en/master/api_python/mindspore.html#mindspore.dtype>`_.
637
457
 
638
458
  Outputs:
639
459
  Tensor of shape :math:`(N, *)`, with the same type and shape as the `input_x`.
@@ -749,273 +569,6 @@ class SeLU(Primitive):
749
569
  self.init_prim_io_names(inputs=['input_x'], outputs=['output'])
750
570
 
751
571
 
752
- class ReLU6(PrimitiveWithCheck):
753
- r"""
754
- Computes ReLU (Rectified Linear Unit) upper bounded by 6 of input tensors element-wise.
755
-
756
- Refer to :func:`mindspore.ops.relu6` for more details.
757
-
758
- Inputs:
759
- - **input_x** (Tensor) - Tensor of shape :math:`(N, *)`,
760
- where :math:`*` means any number of additional dimensions.
761
- Data type must be float16, float32.
762
-
763
- Outputs:
764
- Tensor, with the same type and shape as the `input_x`.
765
-
766
- Supported Platforms:
767
- ``Ascend`` ``GPU`` ``CPU``
768
-
769
- Examples:
770
- >>> import mindspore
771
- >>> import numpy as np
772
- >>> from mindspore import Tensor, ops
773
- >>> input_x = Tensor(np.array([[-1.0, 4.0, -8.0], [2.0, -5.0, 9.0]]), mindspore.float32)
774
- >>> relu6 = ops.ReLU6()
775
- >>> result = relu6(input_x)
776
- >>> print(result)
777
- [[0. 4. 0.]
778
- [2. 0. 6.]]
779
- """
780
-
781
- @prim_attr_register
782
- def __init__(self):
783
- """Initialize ReLU6"""
784
- self.init_prim_io_names(inputs=['x'], outputs=['output'])
785
-
786
- def check_shape(self, input_x):
787
- pass
788
-
789
- def check_dtype(self, input_x):
790
- validator.check_tensor_dtype_valid('input_x', input_x, (mstype.float16, mstype.float32), self.name)
791
-
792
-
793
- class ReLUV2(Primitive):
794
- r"""
795
- The ReLUV2 interface is deprecated, please use the :class:`mindspore.ops.ReLU` instead.
796
-
797
- Rectified Linear Unit activation function.
798
-
799
- It returns element-wise :math:`\max(0, x)`, specially, the neurons with the negative output
800
- will be suppressed and the active neurons will stay the same.
801
-
802
- .. math::
803
-
804
- \text{ReLU}(x) = (x)^+ = \max(0, x)
805
-
806
- Inputs:
807
- - **input_x** (Tensor) - The input tensor must be a 4-D tensor.
808
-
809
- Outputs:
810
- - **output** (Tensor) - Has the same type and shape as the `input_x`.
811
- - **mask** (Tensor) - A tensor, but it is meaningless.
812
-
813
- Raises:
814
- TypeError: If `input_x` is not a Tensor.
815
- ValueError: If shape of `input_x` is not 4-D.
816
-
817
- Supported Platforms:
818
- deprecated
819
-
820
- Examples:
821
- >>> input_x = Tensor(np.array([[[[1, -2], [-3, 4]], [[-5, 6], [7, -8]]]]), mindspore.float32)
822
- >>> relu_v2 = ops.ReLUV2()
823
- >>> output, _= relu_v2(input_x)
824
- >>> print(output)
825
- [[[[1. 0.]
826
- [0. 4.]]
827
- [[0. 6.]
828
- [7. 0.]]]]
829
- """
830
-
831
- @prim_attr_register
832
- def __init__(self):
833
- """Initialize ReLUV2"""
834
- self.init_prim_io_names(inputs=['x'], outputs=['output', 'mask'])
835
-
836
-
837
- class Elu(Primitive):
838
- r"""
839
- Exponential Linear Uint activation function.
840
-
841
- Applies the exponential linear unit function element-wise.
842
- The activation function is defined as:
843
-
844
- .. math::
845
-
846
- \text{ELU}(x)= \left\{
847
- \begin{array}{align}
848
- \alpha(e^{x} - 1) & \text{if } x \le 0\\
849
- x & \text{if } x \gt 0\\
850
- \end{array}\right.
851
-
852
- The picture about ELU looks like this `ELU <https://en.wikipedia.org/wiki/
853
- Activation_function#/media/File:Activation_elu.svg>`_ .
854
-
855
- Args:
856
- alpha (float): The alpha value of ELU, the data type is float. Only support '1.0' currently. Default: ``1.0`` .
857
-
858
- Inputs:
859
- - **input_x** (Tensor) - The input of ELU is a Tensor of any dimension with data type of
860
- float16, float32 or float64.
861
-
862
- Outputs:
863
- Tensor, has the same shape and data type as `input_x`.
864
-
865
- Raises:
866
- TypeError: If `alpha` is not a float.
867
- TypeError: If dtype of `input_x` is neither float16, float32 nor float64.
868
- ValueError: If `alpha` is not equal to 1.0.
869
-
870
- Supported Platforms:
871
- ``Ascend`` ``GPU`` ``CPU``
872
-
873
- Examples:
874
- >>> import mindspore
875
- >>> import numpy as np
876
- >>> from mindspore import Tensor, ops
877
- >>> input_x = Tensor(np.array([[-1.0, 4.0, -8.0], [2.0, -5.0, 9.0]]), mindspore.float32)
878
- >>> elu = ops.Elu()
879
- >>> output = elu(input_x)
880
- >>> print(output)
881
- [[-0.63212055 4. -0.99966455]
882
- [ 2. -0.99326205 9. ]]
883
- """
884
-
885
- @prim_attr_register
886
- def __init__(self, alpha=1.0):
887
- """Initialize Elu"""
888
- validator.check_value_type("alpha", alpha, [float], self.name)
889
- validator.check_number("alpha", alpha, 1.0, validator.EQ, self.name)
890
- self.init_prim_io_names(inputs=['x'], outputs=['output', 'mask'])
891
-
892
-
893
- class HSwish(Primitive):
894
- r"""
895
- Hard swish activation function.
896
-
897
- Refer to :func:`mindspore.ops.hardswish` for more details.
898
-
899
- Inputs:
900
- - **input_x** (Tensor) - The input Tensor.
901
-
902
- Outputs:
903
- Tensor, with the same type and shape as the `input_x`.
904
-
905
- Supported Platforms:
906
- ``Ascend`` ``GPU`` ``CPU``
907
-
908
- Examples:
909
- >>> import mindspore
910
- >>> import numpy as np
911
- >>> from mindspore import Tensor, ops
912
- >>> hswish = ops.HSwish()
913
- >>> input_x = Tensor(np.array([-1, -2, 0, 2, 1]), mindspore.float16)
914
- >>> result = hswish(input_x)
915
- >>> print(result)
916
- [-0.3333 -0.3333 0 1.666 0.6665]
917
- """
918
-
919
- @prim_attr_register
920
- def __init__(self):
921
- """Initialize HSwish."""
922
- self.init_prim_io_names(inputs=['x'], outputs=['output'])
923
-
924
-
925
- class Sigmoid(Primitive):
926
- r"""
927
- Sigmoid activation function.
928
-
929
- Refer to :func:`mindspore.ops.sigmoid` for more details.
930
-
931
- Inputs:
932
- - **input_x** (Tensor) - Tensor of any dimension.
933
-
934
- Outputs:
935
- Tensor, with the same type and shape as the input_x.
936
-
937
- Supported Platforms:
938
- ``Ascend`` ``GPU`` ``CPU``
939
-
940
- Examples:
941
- >>> import mindspore
942
- >>> import numpy as np
943
- >>> from mindspore import Tensor, ops
944
- >>> input_x = Tensor(np.array([1, 2, 3, 4, 5]), mindspore.float32)
945
- >>> sigmoid = ops.Sigmoid()
946
- >>> output = sigmoid(input_x)
947
- >>> print(output)
948
- [0.7310586 0.880797 0.95257413 0.98201376 0.9933072 ]
949
- """
950
-
951
- @prim_attr_register
952
- def __init__(self):
953
- """Initialize Sigmoid."""
954
- self.init_prim_io_names(inputs=['x'], outputs=['output'])
955
-
956
-
957
- class HSigmoid(Primitive):
958
- r"""
959
- Hard sigmoid activation function.
960
-
961
- Refer to :func:`mindspore.ops.hardsigmoid` for more details.
962
-
963
- Inputs:
964
- - **input_x** (Tensor) - The input Tensor.
965
-
966
- Outputs:
967
- Tensor, with the same type and shape as the `input_x`.
968
-
969
- Supported Platforms:
970
- ``Ascend`` ``GPU`` ``CPU``
971
-
972
- Examples:
973
- >>> import mindspore
974
- >>> import numpy as np
975
- >>> from mindspore import Tensor, ops
976
- >>> hsigmoid = ops.HSigmoid()
977
- >>> input_x = Tensor(np.array([-1, -2, 0, 2, 1]), mindspore.float16)
978
- >>> result = hsigmoid(input_x)
979
- >>> print(result)
980
- [0.3333 0.1666 0.5 0.8335 0.6665]
981
- """
982
-
983
- @prim_attr_register
984
- def __init__(self):
985
- """Initialize HSigmoid."""
986
- self.init_prim_io_names(inputs=['input_x'], outputs=['output'])
987
-
988
-
989
- class Tanh(Primitive):
990
- r"""
991
- Computes hyperbolic tangent of input element-wise.
992
-
993
- Refer to :func:`mindspore.ops.tanh` for more details.
994
-
995
- Inputs:
996
- - **input_x** (Tensor) - Input Tensor of any dimension.
997
-
998
- Outputs:
999
- Tensor, with the same type and shape as the `input_x`.
1000
-
1001
- Supported Platforms:
1002
- ``Ascend`` ``GPU`` ``CPU``
1003
-
1004
- Examples:
1005
- >>> import mindspore
1006
- >>> import numpy as np
1007
- >>> from mindspore import Tensor, ops
1008
- >>> input_x = Tensor(np.array([1, 2, 3, 4, 5]), mindspore.float32)
1009
- >>> tanh = ops.Tanh()
1010
- >>> output = tanh(input_x)
1011
- >>> print(output)
1012
- [0.7615941 0.9640276 0.9950547 0.9993293 0.9999092]
1013
- """
1014
-
1015
- @prim_attr_register
1016
- def __init__(self):
1017
- """Initialize Tanh"""
1018
- self.init_prim_io_names(inputs=['x'], outputs=['y'])
1019
572
 
1020
573
 
1021
574
  class FusedBatchNorm(Primitive):
@@ -1229,137 +782,6 @@ class InstanceNormV2(Primitive):
1229
782
  validator.check_bool(is_training, "is_training", self.name)
1230
783
 
1231
784
 
1232
- class BatchNorm(PrimitiveWithInfer):
1233
- r"""
1234
- Batch Normalization for input data and updated parameters.
1235
-
1236
- Batch Normalization is widely used in convolutional neural networks. This operation
1237
- applies Batch Normalization over inputs to avoid internal covariate shift as described
1238
- in the paper `Batch Normalization: Accelerating Deep Network Training by Reducing Internal
1239
- Covariate Shift <https://arxiv.org/abs/1502.03167>`_. It rescales and recenters the
1240
- features using a mini-batch of data and the learned parameters can be described
1241
- in the following formula,
1242
-
1243
- .. math::
1244
-
1245
- y = \frac{x - mean}{\sqrt{variance + \epsilon}} * \gamma + \beta
1246
-
1247
- where :math:`\gamma` is scale, :math:`\beta` is bias, :math:`\epsilon` is epsilon,
1248
- :math:`mean` is the mean of :math:`x`,
1249
- :math:`variance` is the variance of :math:`x`.
1250
-
1251
- .. warning::
1252
- - If the operation is used for inference, and outputs "reserve_space_1" and "reserve_space_2" are available,
1253
- then "reserve_space_1" has the same value as "mean" and "reserve_space_2" has the same value as "variance".
1254
- - For Ascend 310, the result accuracy fails to reach 1‰ due to the square root instruction.
1255
-
1256
- Args:
1257
- is_training (bool): If `is_training` is ``True`` , `mean` and `variance` are computed during training.
1258
- If `is_training` is ``False`` , they're loaded from checkpoint during inference. Default: ``False`` .
1259
- epsilon (float): A small value added for numerical stability. Default: ``1e-5``, value must be (0, 1] .
1260
- momentum (float): The hyper parameter to compute moving average for running_mean and running_var
1261
- (e.g. :math:`new\_running\_mean = (1 - momentum) * running\_mean + momentum * current\_mean`).
1262
- Momentum value must be [0, 1]. Default: ``0.1`` .
1263
- data_format (str): The optional value for data format, is ``'NHWC'`` or ``'NCHW'``, and the ``'NHWC'`` format
1264
- is only supported in GPU target. Default: ``"NCHW"`` .
1265
-
1266
- Inputs:
1267
- If `is_training` is ``False`` , inputs are Tensors.
1268
-
1269
- - **input_x** (Tensor) - Tensor of shape :math:`(N, C)`, with float16 or float32 data type.
1270
- - **scale** (Tensor) - Tensor of shape :math:`(C,)`, with float16 or float32 data type.
1271
- - **bias** (Tensor) - Tensor of shape :math:`(C,)`, has the same data type with `scale`.
1272
- - **mean** (Tensor) - Tensor of shape :math:`(C,)`, has the same data type with `scale`.
1273
- - **variance** (Tensor) - Tensor of shape :math:`(C,)`, has the same data type with `scale`.
1274
-
1275
- If `is_training` is ``True`` , `scale`, `bias`, `mean` and `variance` are Parameters.
1276
-
1277
- - **input_x** (Tensor) - Tensor of shape :math:`(N, C)`, with float16 or float32 data type.
1278
- - **scale** (Parameter) - Parameter of shape :math:`(C,)`, with float16 or float32 data type.
1279
- - **bias** (Parameter) - Parameter of shape :math:`(C,)`, has the same data type with `scale`.
1280
- - **mean** (Parameter) - Parameter of shape :math:`(C,)`, has the same data type with `scale`.
1281
- - **variance** (Parameter) - Parameter of shape :math:`(C,)`, has the same data type with `scale`.
1282
-
1283
- Outputs:
1284
- Tuple of 5 Tensors, the normalized inputs and the updated parameters.
1285
-
1286
- - **output_x** (Tensor) - The same type and shape as the input_x. The shape is :math:`(N, C)`.
1287
- - **batch_mean** (Tensor) - Tensor of shape :math:`(C,)`.
1288
- - **batch_variance** (Tensor) - Tensor of shape :math:`(C,)`.
1289
- - **reserve_space_1** (Tensor) - Tensor of shape :math:`(C,)`.
1290
- - **reserve_space_2** (Tensor) - Tensor of shape :math:`(C,)`.
1291
-
1292
- Raises:
1293
- TypeError: If `is_training` is not a bool.
1294
- TypeError: If dtype of `epsilon` or `momentum` is not float.
1295
- TypeError: If `data_format` is not a str.
1296
- TypeError: If `input_x`, `scale`, `bias`, `mean` or `variance` is not a Tensor.
1297
- TypeError: If dtype of `input_x`, `scale` is neither float16 nor float32.
1298
-
1299
- Supported Platforms:
1300
- ``Ascend`` ``GPU`` ``CPU``
1301
-
1302
- Examples:
1303
- >>> import mindspore
1304
- >>> import numpy as np
1305
- >>> from mindspore import Tensor, ops
1306
- >>> input_x = Tensor(np.ones([2, 2]), mindspore.float32)
1307
- >>> scale = Tensor(np.ones([2]), mindspore.float32)
1308
- >>> bias = Tensor(np.ones([2]), mindspore.float32)
1309
- >>> mean = Tensor(np.ones([2]), mindspore.float32)
1310
- >>> variance = Tensor(np.ones([2]), mindspore.float32)
1311
- >>> batch_norm = ops.BatchNorm()
1312
- >>> output = batch_norm(input_x, scale, bias, mean, variance)
1313
- >>> print(output[0])
1314
- [[1. 1.]
1315
- [1. 1.]]
1316
- """
1317
-
1318
- __mindspore_signature__ = (
1319
- sig.make_sig('input_x', dtype=sig.sig_dtype.T1),
1320
- sig.make_sig('scale', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T2),
1321
- sig.make_sig('bias', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T2),
1322
- sig.make_sig('mean', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T3),
1323
- sig.make_sig('variance', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T3)
1324
- )
1325
-
1326
- @prim_attr_register
1327
- def __init__(self, is_training=False, epsilon=1e-5, momentum=0.1, data_format="NCHW"):
1328
- """Initialize BatchNorm."""
1329
- if is_training is False:
1330
- self.set_signatures(tuple())
1331
- else:
1332
- self.add_prim_attr('side_effect_mem', True)
1333
- validator.check_value_type('is_training', is_training, (bool,), self.name)
1334
- validator.check_float_range(epsilon, 0, 1, validator.INC_RIGHT, 'epsilon', self.name)
1335
- validator.check_float_range(momentum, 0, 1, validator.INC_BOTH, 'momentum', self.name)
1336
- self.format = validator.check_string(data_format, ['NCHW', 'NHWC'], 'format', self.name)
1337
- if context.get_context("device_target") != "GPU" and self.format == "NHWC":
1338
- raise ValueError(f"For '{self.name}', the 'NHWC' format is only supported in GPU target, "
1339
- f"but got the 'data_format' is {self.format} and "
1340
- f"the platform is {context.get_context('device_target')}.")
1341
- self.add_prim_attr('data_format', self.format)
1342
- self.init_prim_io_names(inputs=['x', 'scale', 'offset', 'mean', 'variance'],
1343
- outputs=['y', 'batch_mean', 'batch_variance', 'reserve_space_1', 'reserve_space_2'])
1344
-
1345
- def infer_shape(self, input_x, scale, bias, mean, variance):
1346
- input_x_channel = input_x[-1] if self.format == "NHWC" else input_x[1]
1347
- validator.check_equal_int(len(scale), 1, "scale rank", self.name)
1348
- validator.check("scale shape", scale, "bias shape", bias, validator.EQ, self.name)
1349
- validator.check("scale shape[0]", scale[0], "input_x channel", input_x_channel, validator.EQ, self.name)
1350
- if not self.is_training:
1351
- validator.check_equal_int(len(mean), 1, "mean rank", self.name)
1352
- validator.check("mean shape", mean, "variance shape", variance, validator.EQ, self.name)
1353
- validator.check("mean shape", mean, "scale shape", scale, validator.EQ, self.name)
1354
- return input_x, scale, scale, scale, scale
1355
-
1356
- def infer_dtype(self, input_x, scale, bias, mean, variance):
1357
- validator.check_tensor_dtype_valid("input_x", input_x, [mstype.float16, mstype.float32], self.name)
1358
- args = {"scale": scale, "bias": bias, "mean": mean, "variance": variance}
1359
- validator.check_tensors_dtypes_same_and_valid(args, [mstype.float16, mstype.float32], self.name)
1360
- return input_x, mstype.float32, mstype.float32, mstype.float32, mstype.float32
1361
-
1362
-
1363
785
  class Conv2D(Primitive):
1364
786
  r"""
1365
787
  2D convolution layer.
@@ -1379,21 +801,26 @@ class Conv2D(Primitive):
1379
801
  , :math:`weight` is the convolution kernel value and :math:`X` represents the input feature map.
1380
802
 
1381
803
  Here are the indices' meanings:
1382
- - :math:`i` corresponds to the batch number, ranging from 0 to N-1, where N is the batch size of the input.
1383
804
 
1384
- - :math:`j` corresponds to the output channel, ranging from 0 to C_{out}-1, where C_{out} is the number of
805
+ - :math:`i` corresponds to the batch number, the range is :math:`[0, N-1]`,
806
+ where :math:`N` is the batch size of the input.
807
+
808
+ - :math:`j` corresponds to the output channel, the range is :math:`[0, C_{out}-1]`,
809
+ where :math:`C_{out}` is the number of
1385
810
  output channels, which is also equal to the number of kernels.
1386
811
 
1387
- - :math:`k` corresponds to the input channel, ranging from 0 to C_{in}-1, where C_{in} is the number of
812
+ - :math:`k` corresponds to the input channel, the range is :math:`[0, C_{in}-1]`,
813
+ where :math:`C_{in}` is the number of
1388
814
  input channels, which is also equal to the number of channels in the convolutional kernels.
1389
815
 
1390
- Therefore, in the above formula, :math:`{bias}(C_{out_j})` represents the bias of the :math:`j`-th
1391
- output channel, :math:`{weight}(C_{out_j}, k)` represents the slice of the :math:`j`-th convolutional
816
+ Therefore, in the above formula, :math:`{bias}(C_{\text{out}_j})` represents the bias of the :math:`j`-th
817
+ output channel, :math:`{weight}(C_{\text{out}_j}, k)` represents the slice of the :math:`j`-th convolutional
1392
818
  kernel in the :math:`k`-th channel, and :math:`{X}(N_i, k)` represents the slice of the :math:`k`-th input
1393
819
  channel in the :math:`i`-th batch of the input feature map.
1394
820
 
1395
- The shape of the convolutional kernel is given by :math:`(kernel\_size[0], kernel\_size[1])`,
1396
- where :math:`kernel\_size[0]` and :math:`kernel\_size[1]` are the height and width of the kernel, respectively.
821
+ The shape of the convolutional kernel is given by :math:`(\text{kernel_size[0]},\text{kernel_size[1]})`,
822
+ where :math:`\text{kernel_size[0]}`
823
+ and :math:`\text{kernel_size[1]}` are the height and width of the kernel, respectively.
1397
824
  If we consider the input and output channels as well as the `group` parameter, the complete kernel shape
1398
825
  will be :math:`(C_{out}, C_{in} / \text{group}, \text{kernel_size[0]}, \text{kernel_size[1]})`,
1399
826
  where `group` is the number of groups dividing `x`'s input channel when applying group convolution.
@@ -1450,7 +877,7 @@ class Conv2D(Primitive):
1450
877
  group (int, optional): Specifies the number of groups dividing `x`'s input channel when applying
1451
878
  group convolution. Default: ``1`` .
1452
879
  data_format (str, optional): The optional value for data format, is ``'NHWC'`` or ``'NCHW'`` .
1453
- Default: ``"NCHW"`` .
880
+ Default: ``"NCHW"``. (NHWC is only supported in GPU now.)
1454
881
 
1455
882
  Inputs:
1456
883
  - **x** (Tensor) - Input tensor of shape :math:`(N, C_{in}, H_{in}, W_{in})` or
@@ -1844,13 +1271,13 @@ class MaxPool(_Pool):
1844
1271
  not only the height of movement but also the width of movement, or a tuple of two int numbers that
1845
1272
  represent height and width of movement respectively. Default: ``1`` .
1846
1273
  pad_mode (str, optional): Specifies the padding mode with a padding value of 0. It can be set to:
1847
- ``"same"`` or ``"valid"`` . Default: ``"valid"`` .
1274
+ ``'same'`` or ``'valid'`` . Default: ``'valid'`` .
1848
1275
 
1849
- - ``"same"``: Pad the input around its edges so that the shape of input and output
1276
+ - ``'same'``: Pad the input around its edges so that the shape of input and output
1850
1277
  are the same when `stride` is set to ``1``.
1851
1278
  The amount of padding to is calculated by the operator internally, If the amount is even, it is
1852
1279
  uniformly distributed around the input, if it is odd, the excess amount goes to the right/bottom side.
1853
- - ``"valid"``: No padding is applied to the input, and the output returns the maximum
1280
+ - ``'valid'``: No padding is applied to the input, and the output returns the maximum
1854
1281
  possible height and width. Extra pixels that could not complete a full stride will
1855
1282
  be discarded.
1856
1283
 
@@ -1869,8 +1296,8 @@ class MaxPool(_Pool):
1869
1296
 
1870
1297
  Raises:
1871
1298
  TypeError: If `kernel_size` or `strides` is neither int nor tuple.
1872
- ValueError: If `pad_mode` is neither 'valid' nor 'same' with not case sensitive.
1873
- ValueError: If `data_format` is neither 'NCHW' nor 'NHWC'.
1299
+ ValueError: If `pad_mode` is neither ``'valid'`` nor ``'same'`` with not case sensitive.
1300
+ ValueError: If `data_format` is neither ``'NCHW'`` nor ``'NHWC'``.
1874
1301
  ValueError: If `kernel_size` or `strides` is less than 1.
1875
1302
  ValueError: If length of shape of `input` is not equal to 4.
1876
1303
 
@@ -2033,10 +1460,10 @@ class MaxPool3D(Primitive):
2033
1460
  pad[3], pad[4] and pad[5] correspondingly.
2034
1461
  ceil_mode (Union[bool, None]): Whether to use ceil instead of floor to calculate output shape.
2035
1462
  Only effective in "pad" mode.
2036
- When "pad_mode" is ``"pad"`` and "ceil_mode" is ``"None"`` , "ceil_mode" will be set as ``"False"``.
1463
+ When `pad_mode` is ``"pad"`` and "ceil_mode" is ``None`` , `ceil_mode` will be set as ``False``.
2037
1464
  Default: ``None`` .
2038
- data_format (str) : The optional value for data format. Currently only support ``'NCDHW'`` .
2039
- Default: ``'NCDHW'`` .
1465
+ data_format (str) : The optional value for data format. Currently only support ``"NCDHW"`` .
1466
+ Default: ``"NCDHW"`` .
2040
1467
 
2041
1468
  Inputs:
2042
1469
  - **x** (Tensor) - Tensor of shape :math:`(N, C, D_{in}, H_{in}, W_{in})`.
@@ -2049,10 +1476,10 @@ class MaxPool3D(Primitive):
2049
1476
  TypeError: If `kernel_size` or `strides` is neither an int nor a tuple.
2050
1477
  TypeError: If `pad_mode` or `data_format` is not a string.
2051
1478
  ValueError: If numbers in `kernel_size` or `strides` are not positive.
2052
- ValueError: If `pad_mode` is not one of 'SAME', 'VALID' or 'PAD'.
2053
- ValueError: If `pad_mode` is 'SAME' or 'VALID', 'ceil_mode' is not None.
1479
+ ValueError: If `pad_mode` is not one of ``"SAME"``, ``"VALID"`` or ``"PAD"``.
1480
+ ValueError: If `pad_mode` is ``"SAME"`` or ``"VALID"``, `ceil_mode` is not ``None``.
2054
1481
  ValueError: If `kernel_size` or `strides` is a tuple whose length is not equal to 3.
2055
- ValueError: If `data_format` is not 'NCDHW'.
1482
+ ValueError: If `data_format` is not ``"NCDHW"``.
2056
1483
 
2057
1484
  Supported Platforms:
2058
1485
  ``Ascend`` ``GPU`` ``CPU``
@@ -2278,7 +1705,7 @@ class MaxUnpool3D(Primitive):
2278
1705
  ValueError: If numbers in `strides` or `ksize` is negative.
2279
1706
  ValueError: If numbers in `pads` is negative.
2280
1707
  ValueError: If `ksize`, `strides` or `pads` is a tuple whose length is not equal to 3.
2281
- ValueError: If `data_format` is not a str or is neither `NCDHW` nor `NDHWC`.
1708
+ ValueError: If `data_format` is not a str or is neither ``'NCDHW'`` nor ``'NDHWC'``.
2282
1709
  ValueError: If `output_shape` whose length is neither 0 or 5.
2283
1710
  ValueError: If `output_shape` is not close to output size range
2284
1711
  computed by attr `ksize, strides, pads`.
@@ -2321,98 +1748,6 @@ class MaxUnpool3D(Primitive):
2321
1748
  self.output_shape = output_shape
2322
1749
 
2323
1750
 
2324
- class AvgPool(Primitive):
2325
- r"""
2326
- Average pooling operation.
2327
-
2328
- Refer to :func:`mindspore.ops.avg_pool2d` for more details.
2329
-
2330
- Args:
2331
- kernel_size (Union[int, tuple[int]]): The size of kernel used to take the average value,
2332
- is an int number that represents height and width of the kernel, or a tuple
2333
- of two int numbers that represent height and width respectively. Default: ``1`` .
2334
- strides (Union[int, tuple[int]]): The distance of kernel moving, an int number that represents
2335
- the height and width of movement are both strides, or a tuple of two int numbers that
2336
- represent height and width of movement respectively. Default: ``1`` .
2337
- pad_mode (str, optional): Specifies the padding mode with a padding value of 0. It can be set to:
2338
- ``"same"`` or ``"valid"`` . Default: ``"valid"`` .
2339
-
2340
- - ``"same"``: Pad the input around its edges so that the shape of input and output
2341
- are the same when `stride` is set to ``1``.
2342
- The amount of padding to is calculated by the operator internally, If the amount is even, it is
2343
- uniformly distributed around the input, if it is odd, the excess amount goes to the right/bottom side.
2344
- - ``"valid"``: No padding is applied to the input, and the output returns the maximum
2345
- possible height and width. Extra pixels that could not complete a full stride will
2346
- be discarded.
2347
-
2348
- data_format (str, optional): The format of input and output data. It should be ``'NHWC'`` or ``'NCHW'`` .
2349
- Default: ``'NCHW'`` .
2350
-
2351
- Inputs:
2352
- - **x** (Tensor) - Tensor of shape :math:`(N, C_{in}, H_{in}, W_{in})`.
2353
- Supported dtypes: float16, float32, float64.
2354
-
2355
- Outputs:
2356
- Tensor, with shape :math:`(N, C_{out}, H_{out}, W_{out})`.
2357
-
2358
- Raises:
2359
- TypeError: If `kernel_size` or `strides` is neither int nor tuple.
2360
- TypeError: If dtype of `x` is not float16, float32 or float64.
2361
- ValueError: If `kernel_size` or `strides` is less than 1.
2362
- ValueError: If `pad_mode` is neither 'valid' nor 'same' with not case sensitive.
2363
- ValueError: If `data_format` is neither 'NCHW' nor 'NHWC'.
2364
- ValueError: If length of shape of `x` is not equal to 4.
2365
-
2366
- Supported Platforms:
2367
- ``Ascend`` ``GPU`` ``CPU``
2368
-
2369
- Examples:
2370
- >>> import mindspore
2371
- >>> import numpy as np
2372
- >>> from mindspore import Tensor, ops, nn
2373
- >>> class Net(nn.Cell):
2374
- ... def __init__(self):
2375
- ... super(Net, self).__init__()
2376
- ... self.avgpool_op = ops.AvgPool(pad_mode="VALID", kernel_size=2, strides=1)
2377
- ...
2378
- ... def construct(self, x):
2379
- ... result = self.avgpool_op(x)
2380
- ... return result
2381
- ...
2382
- >>> x = Tensor(np.arange(1 * 3 * 3 * 4).reshape(1, 3, 3, 4), mindspore.float32)
2383
- >>> net = Net()
2384
- >>> output = net(x)
2385
- >>> print(output)
2386
- [[[[ 2.5 3.5 4.5]
2387
- [ 6.5 7.5 8.5]]
2388
- [[14.5 15.5 16.5]
2389
- [18.5 19.5 20.5]]
2390
- [[26.5 27.5 28.5]
2391
- [30.5 31.5 32.5]]]]
2392
- """
2393
-
2394
- @prim_attr_register
2395
- def __init__(self, kernel_size=1, strides=1, pad_mode="valid", data_format="NCHW"):
2396
- """Initialize AvgPool."""
2397
- self.init_prim_io_names(inputs=['x'], outputs=['output'])
2398
- validator.check_value_type('kernel_size', kernel_size, [int, tuple], self.name)
2399
- validator.check_value_type('strides', strides, [int, tuple], self.name)
2400
- validator.check_value_type('pad_mode', pad_mode, [str], self.name)
2401
- self.pad_mode = validator.check_string(pad_mode.upper(), ['VALID', 'SAME'], 'pad_mode', self.name)
2402
- self.add_prim_attr("pad_mode", self.pad_mode)
2403
- self.format = validator.check_string(data_format, ['NCHW', 'NHWC'], 'format', self.name)
2404
- if context.get_context("device_target") != "GPU" and self.format == "NHWC":
2405
- raise ValueError(f"For '{self.name}', the 'NHWC' format is only supported in GPU target, "
2406
- f"but got the 'data_format' is {self.format} and "
2407
- f"the platform is {context.get_context('device_target')}.")
2408
- self.add_prim_attr('data_format', self.format)
2409
- self.kernel_size = _check_positive_int_or_tuple(
2410
- "kernel_size", kernel_size, self.name, allow_four=False, ret_four=True)
2411
- self.add_prim_attr("kernel_size", self.kernel_size)
2412
- self.strides = _check_positive_int_or_tuple("strides", strides, self.name, allow_four=False, ret_four=True)
2413
- self.add_prim_attr("strides", self.strides)
2414
-
2415
-
2416
1751
  class AvgPoolV1(Primitive):
2417
1752
  r"""
2418
1753
  Average-pooling operation.
@@ -2641,7 +1976,7 @@ class MaxPool3DWithArgmax(Primitive):
2641
1976
  TypeError: If `ksize` , `strides` , `pads` or `dilation` is not int or tuple.
2642
1977
  ValueError: If `ksize` or `strides` is less than 1.
2643
1978
  ValueError: If `pads` is less than 0.
2644
- ValueError: If `data_format` is not 'NCDHW'.
1979
+ ValueError: If `data_format` is not ``'NCDHW'``.
2645
1980
  ValueError: If `argmax_type` is not mindspore.int64 or mindspore.int32.
2646
1981
 
2647
1982
  Supported Platforms:
@@ -2743,10 +2078,10 @@ class Conv2DTranspose(Conv2DBackpropInput):
2743
2078
  TypeError: If `kernel_size`, `stride`, `pad` or `dilation` is neither an int nor a tuple.
2744
2079
  TypeError: If `out_channel` or `group` is not an int.
2745
2080
  ValueError: If `kernel_size`, `stride` or `dilation` is less than 1.
2746
- ValueError: If `pad_mode` is not one of 'same', 'valid' or 'pad'.
2081
+ ValueError: If `pad_mode` is not one of ``'same'``, ``'valid'`` or ``'pad'``.
2747
2082
  ValueError: If `padding` is a tuple whose length is not equal to 4.
2748
- ValueError: If `pad_mode` it not equal to 'pad' and `pad` is not equal to (0, 0, 0, 0).
2749
- ValueError: If `data_format` is neither 'NCHW' nor 'NHWC'.
2083
+ ValueError: If `pad_mode` it not equal to ``'pad'`` and `pad` is not equal to (0, 0, 0, 0).
2084
+ ValueError: If `data_format` is neither ``'NCHW'`` nor ``'NHWC'``.
2750
2085
 
2751
2086
  Supported Platforms:
2752
2087
  ``Ascend`` ``GPU`` ``CPU``
@@ -2772,146 +2107,6 @@ class Conv2DTranspose(Conv2DBackpropInput):
2772
2107
  pad_list, mode, stride, dilation, group, data_format)
2773
2108
 
2774
2109
 
2775
- class BiasAdd(Primitive):
2776
- r"""
2777
- Returns the sum of the input Tensor and the bias Tensor. Before adding, the bias Tensor will be broadcasted to be
2778
- consistent with the shape of the input Tensor.
2779
-
2780
- Args:
2781
- data_format (str, optional): The format of input and output data.
2782
- It should be ``"NHWC"`` , ``"NCHW"`` or ``"NCDHW"`` .
2783
- Default is ``"NCHW"`` .
2784
-
2785
- Inputs:
2786
- - **input_x** (Tensor) - The input tensor. The shape can be 2-5 dimensions. Supported dtypes:
2787
-
2788
- - Ascend/CPU: all Number type.
2789
- - GPU: float16, float32, int8.
2790
-
2791
- - **bias** (Tensor) - The bias tensor, with shape :math:`(C)`. C must be the same as channel dimension C of
2792
- `input_x`. It has the same type as `input_x`.
2793
-
2794
- Outputs:
2795
- Tensor, with the same shape and data type as `input_x`.
2796
-
2797
- Raises:
2798
- TypeError: If `data_format` is not a str.
2799
- ValueError: If value of `data_format` is not in the range of ['NHWC','NCHW','NCDHW'].
2800
- TypeError: If `input_x` or `bias` is not a Tensor.
2801
- TypeError: If dtype of `input_x` and `bias` is inconsistent.
2802
- TypeError: If dimension of `input_x` is not in the range [2, 5].
2803
-
2804
- Supported Platforms:
2805
- ``Ascend`` ``GPU`` ``CPU``
2806
-
2807
- Examples:
2808
- >>> import mindspore
2809
- >>> import numpy as np
2810
- >>> from mindspore import Tensor, ops
2811
- >>> input_x = Tensor(np.arange(6).reshape((2, 3)), mindspore.float32)
2812
- >>> bias = Tensor(np.random.random(3).reshape((3,)), mindspore.float32)
2813
- >>> bias_add = ops.BiasAdd()
2814
- >>> output = bias_add(input_x, bias)
2815
- >>> print(output.shape)
2816
- (2, 3)
2817
- """
2818
-
2819
- @prim_attr_register
2820
- def __init__(self, data_format="NCHW"):
2821
- """Initialize BiasAdd."""
2822
- self.init_prim_io_names(inputs=['x', 'b'], outputs=['output'])
2823
- self.format = validator.check_string(data_format, ['NCHW', 'NHWC', 'NCDHW'], 'format', self.name)
2824
- self.add_prim_attr('data_format', self.format)
2825
-
2826
-
2827
- class NLLLoss(Primitive):
2828
- r"""
2829
- Gets the negative log likelihood loss between logits and labels.
2830
-
2831
- The nll loss with :math:`reduction = none` can be described as:
2832
-
2833
- .. math::
2834
-
2835
- \ell(x, t)=L=\left\{l_{1}, \ldots, l_{N}\right\}^{\top},
2836
- \quad l_{n}=-w_{t_{n}} x_{n, t_{n}},
2837
- \quad w_{c}=\text { weight }[c] \cdot 1
2838
-
2839
- where :math:`x` is the logits, :math:`t` is the labels, :math:`w` is the weight,
2840
- N is the batch size, :math:`c` belonging to [0, C-1] is class index, where :math:`C` is the number of classes.
2841
-
2842
- If :math:`reduction \neq none` (default ``'mean'`` ), then
2843
-
2844
- .. math::
2845
-
2846
- \ell(x, t)=\left\{\begin{array}{ll}
2847
- \sum_{n=1}^{N} \frac{1}{\sum_{n=1}^{N} w_{t n}} l_{n}, & \text { if reduction }=\text { 'mean'; } \\
2848
- \sum_{n=1}^{N} l_{n}, & \text { if reduction }=\text { 'sum' }
2849
- \end{array}\right.
2850
-
2851
- Args:
2852
- reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
2853
- ``'sum'`` . Default: ``'mean'`` .
2854
-
2855
- - ``'none'``: no reduction will be applied.
2856
- - ``'mean'``: compute and return the weighted mean of elements in the output.
2857
- - ``'sum'``: the output elements will be summed.
2858
-
2859
- ignore_index (int): Specifies a target value that is ignored
2860
- and does not contribute to the input gradient. Default: ``-100`` .
2861
-
2862
- Inputs:
2863
- - **logits** (Tensor) - Input logits, with shape :math:`(N, C)`. Data type only supports float32 or float16.
2864
- - **labels** (Tensor) - Ground truth labels, with shape :math:`(N,)`, where each value belong to
2865
- :math:`[0, C-1]`. Data type only supports int32 or int64.
2866
- - **weight** (Tensor) - The rescaling weight to each class, with shape :math:`(C,)` and data type only
2867
- supports float32 or float16.
2868
-
2869
- Outputs:
2870
- Tuple of 2 tensors composed with `loss` and `total_weight`.
2871
-
2872
- - **loss** (Tensor) - When `reduction` is ``'none'`` and `logits` is a 2D tensor,
2873
- the `loss` shape is :math:`(N,)`. Otherwise, the `loss` is a scalar.
2874
- The data type is the same with `input's`.
2875
- - **total_weight** (Tensor) - The `total_weight` is a scalar. The data type is the same with `weight's`.
2876
-
2877
- Raises:
2878
- TypeError: If dtype of `logits` or `weight` is neither float16 nor float32.
2879
- TypeError: If dtype of `labels` is neither int32 nor int64.
2880
- ValueError: If `logits` is not a one or two dimension tensor, `labels` and `weight` are not
2881
- one dimension tensors.
2882
- When `logits` is a two dimension tensor, the first dimension of `logits` is not equal to `labels`,
2883
- and second dimension of `logits` is not equal to `weight`.
2884
- When `logits` is a one dimension tensor, the dimensions of `logits`, `labels`
2885
- and `weight` should be equal to each other.
2886
- ValueError: If the value of `labels` exceed :math:`[0, C-1]`, where :math:`C` is the number of classes.
2887
-
2888
- Supported Platforms:
2889
- ``Ascend`` ``GPU`` ``CPU``
2890
-
2891
- Examples:
2892
- >>> import numpy as np
2893
- >>> from mindspore import Tensor, ops
2894
- >>> logits = Tensor(np.array([[0.5488135, 0.71518934],
2895
- ... [0.60276335, 0.5448832],
2896
- ... [0.4236548, 0.6458941]]).astype(np.float32))
2897
- >>> labels = Tensor(np.array([0, 0, 0]).astype(np.int32))
2898
- >>> weight = Tensor(np.array([0.3834415, 0.79172504]).astype(np.float32))
2899
- >>> nll_loss = ops.NLLLoss(reduction="mean")
2900
- >>> loss, weight = nll_loss(logits, labels, weight)
2901
- >>> print(loss)
2902
- -0.52507716
2903
- >>> print(weight)
2904
- 1.1503246
2905
- """
2906
-
2907
- @prim_attr_register
2908
- def __init__(self, reduction="mean", ignore_index=-100):
2909
- """Initialize NLLLoss"""
2910
- self.init_prim_io_names(inputs=['x', 'target', "weight"], outputs=['loss', 'total_weight'])
2911
- self.reduction = validator.check_string(reduction, ['none', 'sum', 'mean'], 'reduction', self.name)
2912
- validator.check_value_type('ignore_index', ignore_index, [int], self.name)
2913
-
2914
-
2915
2110
  class SoftmaxCrossEntropyWithLogits(Primitive):
2916
2111
  r"""
2917
2112
  Gets the softmax cross-entropy value between logits and labels with one-hot encoding.
@@ -3232,7 +2427,7 @@ class MultiMarginLoss(Primitive):
3232
2427
  or float64.
3233
2428
  - **target** (Tensor) - Ground truth labels, with shape :math:`(N,)`. Data type only support int64. The
3234
2429
  value of target should be non-negative, less than C.
3235
- - **weight** (Tensor) - The rescaling weight to each class with shape :math:`(C,)`. Data type only
2430
+ - **weight** (Tensor, optional) - The rescaling weight to each class with shape :math:`(C,)`. Data type only
3236
2431
  support float16, float32 or float64.
3237
2432
 
3238
2433
  Outputs:
@@ -3254,6 +2449,11 @@ class MultiMarginLoss(Primitive):
3254
2449
  >>> print(output)
3255
2450
  0.6666667
3256
2451
  """
2452
+ __mindspore_signature__ = (
2453
+ sig.make_sig('x'),
2454
+ sig.make_sig('target'),
2455
+ sig.make_sig('weight', default=None)
2456
+ )
3257
2457
 
3258
2458
  @prim_attr_register
3259
2459
  def __init__(self, p=1, margin=1.0, reduction="mean"):
@@ -3264,6 +2464,9 @@ class MultiMarginLoss(Primitive):
3264
2464
  self.reduction = validator.check_string(reduction, ['none', 'sum', 'mean'], 'reduction', self.name)
3265
2465
  self.init_prim_io_names(inputs=['x', 'target', 'weight'], outputs=['y'])
3266
2466
 
2467
+ def __call__(self, x, target, weight=None):
2468
+ return super().__call__(x, target, weight)
2469
+
3267
2470
 
3268
2471
  class SoftMarginLoss(Primitive):
3269
2472
  r"""
@@ -3412,7 +2615,9 @@ class RNNTLoss(PrimitiveWithInfer):
3412
2615
  blank_label (int): blank label. Default: ``0`` .
3413
2616
 
3414
2617
  Inputs:
3415
- - **acts** (Tensor) - Tensor of shape :math:`(B, T, U, V)`. Data type must be float16 or float32.
2618
+ - **acts** (Tensor) - Tensor of shape :math:`(B, T, U, V)`, where :math:`B` is batch,
2619
+ :math:`T` is sequence length, :math:`U` is label length and :math:`V` is output dim.
2620
+ Data type must be float16 or float32.
3416
2621
  - **labels** (Tensor) - Tensor of shape :math:`(B, U-1)`. Data type is int32.
3417
2622
  - **input_lengths** (Tensor) - Tensor of shape :math:`(B,)`. Data type is int32.
3418
2623
  - **label_lengths** (Tensor) - Tensor of shape :math:`(B,)`. Data type is int32.
@@ -3744,379 +2949,40 @@ class ApplyCenteredRMSProp(Primitive):
3744
2949
  self.add_prim_attr('side_effect_mem', True)
3745
2950
 
3746
2951
 
3747
- class LayerNorm(Primitive):
3748
- r"""
3749
- Applies the Layer Normalization to the input tensor.
3750
-
3751
- This operator will normalize the input tensor on given axis. LayerNorm is described in the paper
3752
- `Layer Normalization <https://arxiv.org/abs/1607.06450>`_.
3753
-
3754
- .. math::
3755
- y = \frac{x - mean}{\sqrt{variance + \epsilon}} * \gamma + \beta
3756
-
3757
- where :math:`\gamma` is scale, :math:`\beta` is bias, :math:`\epsilon` is epsilon.
3758
-
3759
- Args:
3760
- begin_norm_axis (int): The begin axis of the `input_x` to apply LayerNorm,
3761
- the value must be in [-1, rank(input_x)). Default: ``1`` .
3762
- begin_params_axis (int): The begin axis of the parameter input (`gamma`, `beta`) to
3763
- apply LayerNorm, the value must be in [-1, rank(input_x)). Default: ``1`` .
3764
- epsilon (float): A value added to the denominator for numerical stability(:math:`\epsilon`). Default: ``1e-7`` .
3765
-
3766
- Inputs:
3767
- - **input_x** (Tensor) - Tensor of shape :math:`(N, \ldots)`.
3768
- The input of LayerNorm. Supported dtypes: float16, float32, float64.
3769
- - **gamma** (Tensor) - Tensor of shape :math:`(P_\text{begin_params_axis}, \ldots, P_\text{rank(input_x)-1})`.
3770
- The learnable parameter :math:`\gamma` as the scale on norm. Supported dtypes: float16, float32, float64.
3771
- - **beta** (Tensor) - Tensor of shape :math:`(P_\text{begin_params_axis}, \ldots, P_\text{rank(input_x)-1})`.
3772
- The learnable parameter :math:`\beta` as the scale on norm. Supported dtypes: float16, float32, float64.
3773
-
3774
- Outputs:
3775
- tuple[Tensor], tuple of 3 tensors, the normalized input and the updated parameters.
3776
-
3777
- - **output_x** (Tensor) - The normalized input, has the same type and shape as the `input_x`.
3778
- - **mean** (Tensor) - The first `begin_norm_axis` dimensions of `mean` shape is the same as `input_x`,
3779
- and the remaining dimensions are 1. Suppose the shape of the `input_x` is :math:`(x_1, x_2, \ldots, x_R)`,
3780
- the shape of the `mean` is :math:`(x_1, \ldots, x_{begin\_params\_axis}, 1, \ldots, 1)`
3781
- (when `begin_params_axis=0`, the shape of `mean` is :math:`(1, \ldots, 1)` ).
3782
- - **variance** (Tensor) - Shape is the same as `mean` .
3783
-
3784
- Raises:
3785
- TypeError: If `begin_norm_axis` or `begin_params_axis` is not an int.
3786
- TypeError: If `epsilon` is not a float.
3787
- TypeError: If `input_x`, `gamma` or `beta` is not a Tensor.
3788
-
3789
- Supported Platforms:
3790
- ``Ascend`` ``GPU`` ``CPU``
3791
-
3792
- Examples:
3793
- >>> import mindspore
3794
- >>> import numpy as np
3795
- >>> from mindspore import Tensor, ops
3796
- >>> input_x = Tensor(np.array([[1, 2, 3], [1, 2, 3]]), mindspore.float32)
3797
- >>> gamma = Tensor(np.ones([3]), mindspore.float32)
3798
- >>> beta = Tensor(np.ones([3]), mindspore.float32)
3799
- >>> layer_norm = ops.LayerNorm()
3800
- >>> output, mean, variance = layer_norm(input_x, gamma, beta)
3801
- >>> print(output)
3802
- [[-0.2247448 1. 2.2247448]
3803
- [-0.2247448 1. 2.2247448]]
3804
- >>> print(mean)
3805
- [[2.]
3806
- [2.]]
3807
- >>> print(variance)
3808
- [[0.6666667]
3809
- [0.6666667]]
3810
- """
3811
-
3812
- @prim_attr_register
3813
- def __init__(self, begin_norm_axis=1, begin_params_axis=1, epsilon=1e-7):
3814
- """Initialize LayerNorm."""
3815
- validator.check_value_type('begin_norm_axis', begin_norm_axis, [int], self.name)
3816
- validator.check_value_type('begin_params_axis', begin_params_axis, [int], self.name)
3817
- validator.check_value_type('epsilon', epsilon, [float], self.name)
3818
-
3819
-
3820
2952
  class L2Normalize(Primitive):
3821
2953
  r"""
3822
2954
  L2 Normalization Operator.
3823
2955
 
3824
- This operator will normalize the input using the given axis. The function is shown as follows:
3825
-
3826
- .. math::
3827
- \displaylines{{\text{output} = \frac{x}{\sqrt{\text{max}( \sum_{i}^{}\left | x_i \right | ^2, \epsilon)}}}}
3828
-
3829
- where :math:`\epsilon` is epsilon and :math:`\sum_{i}^{}\left | x_i \right | ^2` calculate the sum of squares of
3830
- the input `x` along the dimension `axis`.
3831
-
3832
- Note:
3833
- On Ascend, input data type of float64 is currently not supported.
3834
-
3835
- Args:
3836
- axis (Union[list(int), tuple(int), int]): Specify the axis for calculating the L2 norm. Default: ``0`` .
3837
- epsilon (float): A small value added for numerical stability. Default: ``1e-4`` .
3838
-
3839
- Inputs:
3840
- - **x** (Tensor) - Input to compute the normalization. Tensor of shape :math:`(N, *)`,
3841
- where :math:`*` means any number of additional dimensions.
3842
- Data type must be float16, float32 or float64.
3843
-
3844
- Outputs:
3845
- Tensor, with the same type and shape as the `x`.
3846
-
3847
- Raises:
3848
- TypeError: If `axis` is not one of the following: list, tuple or int.
3849
- TypeError: If `epsilon` is not a float.
3850
- TypeError: If `x` is not a Tensor.
3851
- TypeError: If dtype of `x` is not in [float16, float32, float64].
3852
- ValueError: If dimension of `x` is not greater than 0.
3853
-
3854
- Supported Platforms:
3855
- ``Ascend`` ``GPU`` ``CPU``
3856
-
3857
- Examples:
3858
- >>> import mindspore
3859
- >>> import numpy as np
3860
- >>> from mindspore import Tensor, ops
3861
- >>> l2_normalize = ops.L2Normalize()
3862
- >>> x = Tensor(np.random.randint(-256, 256, (2, 3, 4)), mindspore.float32)
3863
- >>> output = l2_normalize(x)
3864
- >>> print(output.shape)
3865
- (2, 3, 4)
3866
- """
3867
-
3868
- @prim_attr_register
3869
- def __init__(self, axis=0, epsilon=1e-4):
3870
- """Initialize L2Normalize."""
3871
- axis = [axis] if isinstance(axis, int) else axis
3872
- validator.check_value_type('axis', axis, [list, tuple], self.name)
3873
- validator.check_value_type('epsilon', epsilon, [int, float], self.name)
3874
- self.add_prim_attr('axis', axis)
3875
- self.init_attrs['axis'] = axis
3876
- if len(axis) != 1:
3877
- raise TypeError(f"For '{self.name}', the length of 'axis' must be 1, but got {len(axis)}, "
3878
- f"later will support multiple axis!")
3879
- self.axis = axis
3880
-
3881
-
3882
- class ResizeBilinear(PrimitiveWithInfer):
3883
- r"""
3884
- This API is deprecated, please use the :class:`mindspore.ops.ResizeBilinearV2` instead.
3885
- For general resizing with other interpolation methods, refer to :func:`mindspore.ops.interpolate` for more details.
3886
-
3887
- Note:
3888
- Dynamic shape feature is not supported for now.
3889
-
3890
- Supported Platforms:
3891
- Deprecated
3892
- """
3893
-
3894
- @prim_attr_register
3895
- def __init__(self, size, align_corners=False, half_pixel_centers=False):
3896
- """Initialize ResizeBilinear."""
3897
- validator.check_value_type("size", size, [tuple, list], self.name)
3898
- validator.check_equal_int(len(size), 2, "size len", self.name)
3899
- for item in size:
3900
- validator.check_positive_int(item, 'size item', self.name)
3901
- validator.check_value_type("size item", item, int, self.name)
3902
- self.align_corners = validator.check_value_type("align_corners", align_corners, [bool], self.name)
3903
- self.half_pixel_centers = validator.check_value_type("half_pixel_centers",
3904
- half_pixel_centers, [bool], self.name)
3905
- if half_pixel_centers and align_corners:
3906
- raise ValueError(f"If half_pixel_centers is True, align_corners must be False, but got {align_corners}")
3907
- for i, value in enumerate(size):
3908
- validator.check_positive_int(value, f'{i}th value of size', self.name)
3909
-
3910
- def infer_shape(self, input_shape):
3911
- validator.check("dimension of input", len(input_shape), "", 4, validator.EQ, self.name)
3912
- input_shape = list(input_shape)
3913
- batch, channel, _, _ = input_shape
3914
- out_shape = [batch, channel]
3915
- for i in self.size:
3916
- out_shape.append(int(i))
3917
- return out_shape
3918
-
3919
- def infer_dtype(self, input_dtype):
3920
- validator.check_tensor_dtype_valid('input_dtype', input_dtype, [mstype.float16, mstype.float32],
3921
- self.name)
3922
- return input_dtype
3923
-
3924
-
3925
- class UpsampleTrilinear3D(Primitive):
3926
- r"""
3927
- Performs upsampling with trilinear interpolation across 3dims for 5dim input Tensor.
3928
-
3929
- This operator scale up the volumetric input with specified `output_size` or `scales` factors,
3930
- using trilinear upscaling algorithm.
3931
-
3932
- Note:
3933
- One of `scales` and `output_size` must be specified. And it is an error if both are specified.
3934
-
3935
- Args:
3936
- align_corners (bool, optional): An optional bool. Default: ``False``.
3937
- If ``True``, the input and output tensors are aligned by the center points of their corner pixels,
3938
- preserving the values at the corner pixels.
3939
- If ``False`` , the input and output tensors are aligned by the corner points of their corner pixels,
3940
- and the interpolation use edge value padding for out of boundary values.
3941
-
3942
- Inputs:
3943
- - **x** (Tensor) - 5D tensor of shape :math:`(N, C, D_{in}, H_{in}, W_{in})`. Supporting types:
3944
- [float16, float32, float64].
3945
- - **output_size** (Union[tuple[int], list[int]]): A tuple or list of 3 int elements
3946
- :math:`(output\_depth, output\_height, output\_width)`. Default: ``None``.
3947
- - **scales** (Union[tuple[float], list[float]]): A tuple or list of 3 float
3948
- elements :math:`(scale\_depth, scale\_height, scale\_width)`. Default: ``None``.
3949
-
3950
- Outputs:
3951
- - **y** (Tensor) - Upsampled output with the same data type as `x`, whose shape is
3952
- :math:`(N, C, D_{out}, H_{out}, W_{out})`.
3953
-
3954
- Raises:
3955
- TypeError: When `output_size` is not ``None`` and `output_size` is not list[int] or tuple[int].
3956
- TypeError: When `scales` is not ``None`` and `scales` is not list[float] or tuple[float].
3957
- TypeError: If dtype of `x` is not in [float16, float32, float64].
3958
- TypeError: If type of `align_corners` is not bool.
3959
- ValueError: If any value of `output_size` is negative or zero when `output_size` is not ``None``.
3960
- ValueError: If any value of `scales` is negative or zero when `scales` is not ``None``.
3961
- ValueError: If shape of `x` is not 5D.
3962
- ValueError: If none of `scales` and `output_size` is specified or both specified.
3963
- ValueError: If size of `scales` is not equal 3 when `scales` is specified.
3964
- ValueError: If size of `output_size` is not equal 3 when `output_size` is specified.
3965
-
3966
- Supported Platforms:
3967
- ``Ascend`` ``GPU`` ``CPU``
3968
-
3969
- Examples:
3970
- >>> import numpy as np
3971
- >>> from mindspore import Tensor, ops
3972
- >>> net = ops.UpsampleTrilinear3D()
3973
- >>> in_x = Tensor(input_data=np.random.randn(2, 3, 4, 512, 256))
3974
- >>> output_size=[4, 64, 48]
3975
- >>> out = net(in_x, output_size, None)
3976
- >>> print(out.shape)
3977
- (2, 3, 4, 64, 48)
3978
- >>>
3979
- >>> net = ops.UpsampleTrilinear3D()
3980
- >>> in_x = Tensor(np.arange(1, 5, dtype=np.float32).reshape((1, 1, 1, 2, 2)))
3981
- >>> output_size=[2, 4, 4]
3982
- >>> out = net(in_x, output_size, None)
3983
- >>> print(out)
3984
- [[[[[1. 1.25 1.75 2. ]
3985
- [1.5 1.75 2.25 2.5 ]
3986
- [2.5 2.75 3.25 3.5 ]
3987
- [3. 3.25 3.75 4. ]]
3988
- [[1. 1.25 1.75 2. ]
3989
- [1.5 1.75 2.25 2.5 ]
3990
- [2.5 2.75 3.25 3.5 ]
3991
- [3. 3.25 3.75 4. ]]]]]
3992
- """
3993
-
3994
- @prim_attr_register
3995
- def __init__(self, align_corners=False):
3996
- """Initialize UpsampleTrilinear3D."""
3997
- self.init_prim_io_names(inputs=['x', 'output_size', 'scales'], outputs=['y'])
3998
- self.align_corners = align_corners
3999
- validator.check_bool(self.align_corners, "align_corners", self.name)
4000
- self.add_prim_attr('align_corners', self.align_corners)
4001
-
4002
-
4003
- class OneHot(Primitive):
4004
- r"""
4005
- Computes a one-hot tensor.
4006
-
4007
- The locations represented by indices in `indices` take value `on_value`, while all
4008
- other locations take value `off_value`.
4009
-
4010
- Note:
4011
- If the input indices is rank `N`, the output will have rank `N+1`. The new axis is created at dimension `axis`.
4012
- On Ascend, if `on_value` is Int64 dtype, `indices` must be Int64 dtype.
4013
-
4014
- Args:
4015
- axis (int): Position to insert the value. e.g. If shape of `indices` is :math:`(N, C)`, and `axis` is -1,
4016
- the output shape will be :math:`(N, C, D)`, If `axis` is 0, the output shape will be :math:`(D, N, C)`.
4017
- Default: ``-1`` .
4018
-
4019
- Inputs:
4020
- - **indices** (Tensor) - A tensor of indices. Tensor of shape :math:`(X_0, \ldots, X_n)`.
4021
- Data type must be int32 or int64.
4022
- - **depth** (int) - A scalar defining the depth of the one-hot dimension.
4023
- - **on_value** (Tensor) - A value to fill in output when `indices[j] = i`. Data type must be int32, int64,
4024
- float16 or float32.
4025
- - **off_value** (Tensor) - A value to fill in output when `indices[j] != i`.
4026
- It has the same data type as `on_value`.
4027
-
4028
- Outputs:
4029
- Tensor, one-hot tensor. Tensor of shape :math:`(X_0, \ldots, X_{axis}, \text{depth} ,X_{axis+1}, \ldots, X_n)`,
4030
- and it has the same data type as `on_value`.
4031
-
4032
- Raises:
4033
- TypeError: If `axis` or `depth` is not an int.
4034
- TypeError: If dtype of `indices` is not int32 or int64.
4035
- TypeError: If `indices`, `on_value` or `off_value` is not a Tensor.
4036
- ValueError: If `axis` is not in range [-1, len(indices_shape)].
4037
- ValueError: If `depth` is less than 0.
4038
-
4039
- Supported Platforms:
4040
- ``Ascend`` ``GPU`` ``CPU``
4041
-
4042
- Examples:
4043
- >>> import mindspore
4044
- >>> import numpy as np
4045
- >>> from mindspore import Tensor, ops
4046
- >>> indices = Tensor(np.array([0, 1, 2]), mindspore.int32)
4047
- >>> depth, on_value, off_value = 3, Tensor(1.0, mindspore.float32), Tensor(0.0, mindspore.float32)
4048
- >>> onehot = ops.OneHot()
4049
- >>> output = onehot(indices, depth, on_value, off_value)
4050
- >>> print(output)
4051
- [[1. 0. 0.]
4052
- [0. 1. 0.]
4053
- [0. 0. 1.]]
4054
- """
4055
-
4056
- @prim_attr_register
4057
- def __init__(self, axis=-1):
4058
- """Initialize OneHot."""
4059
- self.init_prim_io_names(inputs=['indices', 'depth', 'on_value', 'off_value'], outputs=['output'])
4060
- validator.check_value_type("axis", axis, [int], self.name)
4061
-
4062
-
4063
- class GeLU(Primitive):
4064
- r"""
4065
- Gaussian Error Linear Units activation function.
4066
-
4067
- GeLU is described in the paper `Gaussian Error Linear Units (GELUs) <https://arxiv.org/abs/1606.08415>`_.
4068
- And also please refer to `BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding
4069
- <https://arxiv.org/abs/1810.04805>`_.
4070
-
4071
- GeLU is defined as follows:
4072
-
4073
- .. math::
4074
- GELU(x_i) = x_i*P(X < x_i)
4075
-
4076
- where :math:`P` is the cumulative distribution function of the standard Gaussian distribution,
4077
- :math:`x_i` is the input element.
4078
-
4079
- Inputs:
4080
- - **x** (Tensor) - The input of the activation function GeLU, the data type is float16, float32 or float64.
4081
-
4082
- Outputs:
4083
- Tensor, with the same type and shape as `x`.
4084
-
4085
- Raises:
4086
- TypeError: If `x` is not a Tensor.
4087
- TypeError: If dtype of `x` is not float16, float32 or float64.
4088
-
4089
- Supported Platforms:
4090
- ``Ascend`` ``GPU`` ``CPU``
4091
-
4092
- Examples:
4093
- >>> import mindspore
4094
- >>> import numpy as np
4095
- >>> from mindspore import Tensor, ops
4096
- >>> x = Tensor(np.array([1.0, 2.0, 3.0]), mindspore.float32)
4097
- >>> gelu = ops.GeLU()
4098
- >>> result = gelu(x)
4099
- >>> print(result)
4100
- [0.841192 1.9545976 2.9963627]
4101
- """
4102
-
4103
- @prim_attr_register
4104
- def __init__(self):
4105
- """Initialize GeLU"""
4106
- self.init_prim_io_names(inputs=['x'], outputs=['output'])
2956
+ This operator will normalize the input using the given axis. The function is shown as follows:
4107
2957
 
2958
+ .. math::
2959
+ \displaylines{{\text{output} = \frac{x}{\sqrt{\text{max}( \sum_{i}^{}\left | x_i \right | ^2, \epsilon)}}}}
4108
2960
 
4109
- class FastGeLU(Primitive):
4110
- r"""
4111
- Fast Gaussian Error Linear Units activation function.
2961
+ where :math:`\epsilon` is epsilon and :math:`\sum_{i}^{}\left | x_i \right | ^2` calculate the sum of squares of
2962
+ the input `x` along the dimension `axis`.
2963
+
2964
+ Note:
2965
+ On Ascend, input data type of float64 is currently not supported.
4112
2966
 
4113
- Refer to :func:`mindspore.ops.fast_gelu` for more details.
2967
+ Args:
2968
+ axis (Union[list(int), tuple(int), int], optional): Specify the axis for calculating the L2 norm.
2969
+ Default: ``0`` .
2970
+ epsilon (float, optional): A small value added for numerical stability. Default: ``1e-4`` .
4114
2971
 
4115
2972
  Inputs:
4116
- - **x** (Tensor) - Input to compute the FastGeLU with data type of float16 or float32.
2973
+ - **x** (Tensor) - Input to compute the normalization. Tensor of shape :math:`(N, *)`,
2974
+ where :math:`*` means any number of additional dimensions.
2975
+ Data type must be float16, float32 or float64.
4117
2976
 
4118
2977
  Outputs:
4119
- Tensor, with the same type and shape as `x`.
2978
+ Tensor, with the same type and shape as the `x`.
2979
+
2980
+ Raises:
2981
+ TypeError: If `axis` is not one of the following: list, tuple or int.
2982
+ TypeError: If `epsilon` is not a float.
2983
+ TypeError: If `x` is not a Tensor.
2984
+ TypeError: If dtype of `x` is not in [float16, float32, float64].
2985
+ ValueError: If dimension of `x` is not greater than 0.
4120
2986
 
4121
2987
  Supported Platforms:
4122
2988
  ``Ascend`` ``GPU`` ``CPU``
@@ -4125,18 +2991,25 @@ class FastGeLU(Primitive):
4125
2991
  >>> import mindspore
4126
2992
  >>> import numpy as np
4127
2993
  >>> from mindspore import Tensor, ops
4128
- >>> x = Tensor(np.array([[-1.0, 4.0, -8.0], [2.0, -5.0, 9.0]]), mindspore.float32)
4129
- >>> fast_gelu = ops.FastGeLU()
4130
- >>> output = fast_gelu(x)
4131
- >>> print(output)
4132
- [[-1.5418735e-01 3.9921875e+00 -9.7473649e-06]
4133
- [ 1.9375000e+00 -1.0052517e-03 8.9824219e+00]]
2994
+ >>> l2_normalize = ops.L2Normalize()
2995
+ >>> x = Tensor(np.random.randint(-256, 256, (2, 3, 4)), mindspore.float32)
2996
+ >>> output = l2_normalize(x)
2997
+ >>> print(output.shape)
2998
+ (2, 3, 4)
4134
2999
  """
4135
3000
 
4136
3001
  @prim_attr_register
4137
- def __init__(self):
4138
- """Initialize FastGeLU."""
4139
- self.init_prim_io_names(inputs=['x'], outputs=['output'])
3002
+ def __init__(self, axis=0, epsilon=1e-4):
3003
+ """Initialize L2Normalize."""
3004
+ axis = [axis] if isinstance(axis, int) else axis
3005
+ validator.check_value_type('axis', axis, [list, tuple], self.name)
3006
+ validator.check_value_type('epsilon', epsilon, [int, float], self.name)
3007
+ self.add_prim_attr('axis', axis)
3008
+ self.init_attrs['axis'] = axis
3009
+ if len(axis) != 1:
3010
+ raise TypeError(f"For '{self.name}', the length of 'axis' must be 1, but got {len(axis)}, "
3011
+ f"later will support multiple axis!")
3012
+ self.axis = axis
4140
3013
 
4141
3014
 
4142
3015
  class GetNext(Primitive):
@@ -4193,55 +3066,6 @@ class GetNext(Primitive):
4193
3066
  validator.check_value_type("output_num", output_num, [int], self.name)
4194
3067
 
4195
3068
 
4196
- class PReLU(PrimitiveWithInfer):
4197
- r"""
4198
- Parametric Rectified Linear Unit activation function.
4199
-
4200
- Refer to :func:`mindspore.ops.prelu` for more details.
4201
-
4202
- Inputs:
4203
- - **x** (Tensor) - The input Tensor of the activation function. The data type is float16 or float32.
4204
- The shape is :math:`(N, C, *)` where :math:`*` means, any number of additional dimensions.
4205
- - **weight** (Tensor) - Weight Tensor. The data type is float16 or float32.
4206
- The weight can only be a vector, and the length is the same as the number of channels C of the `input_x`.
4207
- On GPU devices, when the input is a scalar, the shape is 1.
4208
-
4209
- Outputs:
4210
- Tensor, with the same type as `x`.
4211
-
4212
- Supported Platforms:
4213
- ``Ascend`` ``GPU`` ``CPU``
4214
-
4215
- Examples:
4216
- >>> import mindspore
4217
- >>> import numpy as np
4218
- >>> from mindspore import Tensor, nn, ops
4219
- >>> class Net(nn.Cell):
4220
- ... def __init__(self):
4221
- ... super(Net, self).__init__()
4222
- ... self.prelu = ops.PReLU()
4223
- ... def construct(self, x, weight):
4224
- ... result = self.prelu(x, weight)
4225
- ... return result
4226
- ...
4227
- >>> x = Tensor(np.arange(-6, 6).reshape((2, 3, 2)), mindspore.float32)
4228
- >>> weight = Tensor(np.array([0.1, 0.6, -0.3]), mindspore.float32)
4229
- >>> net = Net()
4230
- >>> output = net(x, weight)
4231
- >>> print(output)
4232
- [[[-0.60 -0.50]
4233
- [-2.40 -1.80]
4234
- [ 0.60 0.30]]
4235
- [[ 0.00 1.00]
4236
- [ 2.00 3.00]
4237
- [ 4.0 5.00]]]
4238
- """
4239
-
4240
- @prim_attr_register
4241
- def __init__(self):
4242
- self.init_prim_io_names(inputs=['x', 'weight'], outputs=['output'])
4243
-
4244
-
4245
3069
  class LSTM(Primitive):
4246
3070
  r"""
4247
3071
  Performs the Long Short-Term Memory (LSTM) on the input.
@@ -4383,105 +3207,6 @@ class SigmoidCrossEntropyWithLogits(Primitive):
4383
3207
  self.init_prim_io_names(inputs=['predict', 'target'], outputs=['loss'])
4384
3208
 
4385
3209
 
4386
- class BCEWithLogitsLoss(PrimitiveWithInfer):
4387
- r"""
4388
- Adds sigmoid activation function to input `logits`, and uses the given logits to compute binary cross entropy
4389
- between the logits and the label.
4390
-
4391
- Sets input logits as :math:`X`, input label as :math:`Y`, input weight as :math:`W`, output as :math:`L`. Then,
4392
-
4393
- .. math::
4394
-
4395
- \begin{array}{ll} \\
4396
- p_{ij} = sigmoid(X_{ij}) = \frac{1}{1 + e^{-X_{ij}}} \\
4397
- L_{ij} = -[Y_{ij}log(p_{ij}) + (1 - Y_{ij})log(1 - p_{ij})]
4398
- \end{array}
4399
-
4400
- :math:`i` indicates the :math:`i^{th}` sample, :math:`j` indicates the category. Then,
4401
-
4402
- .. math::
4403
- \ell(x, y) = \begin{cases}
4404
- L, & \text{if reduction} = \text{'none';}\\
4405
- \operatorname{mean}(L), & \text{if reduction} = \text{'mean';}\\
4406
- \operatorname{sum}(L), & \text{if reduction} = \text{'sum'.}
4407
- \end{cases}
4408
-
4409
- :math:`\ell` indicates the method of calculating the loss. There are three methods:
4410
- the first method is to provide the loss value directly,
4411
- the second method is to calculate the average value of all losses,
4412
- and the third method is to calculate the sum of all losses.
4413
-
4414
- This operator will multiply the output by the corresponding weight.
4415
- The tensor `weight` assigns different weights to each piece of data in the batch,
4416
- and the tensor `pos_weight` adds corresponding weights to the positive examples of each category.
4417
-
4418
- In addition, it can trade off recall and precision by adding weights to positive examples.
4419
- In the case of multi-label classification the loss can be described as:
4420
-
4421
- .. math::
4422
- \begin{array}{ll} \\
4423
- p_{ij,c} = sigmoid(X_{ij,c}) = \frac{1}{1 + e^{-X_{ij,c}}} \\
4424
- L_{ij,c} = -[P_{c}Y_{ij,c} * log(p_{ij,c}) + (1 - Y_{ij,c})log(1 - p_{ij,c})]
4425
- \end{array}
4426
-
4427
- where c is the class number (c>1 for multi-label binary classification, c=1 for single-label binary classification),
4428
- n is the number of the sample in the batch and :math:`P_c` is the weight of the positive answer for the class c.
4429
- :math:`P_c>1` increases the recall, :math:`P_c<1` increases the precision.
4430
-
4431
- Args:
4432
- reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
4433
- ``'sum'`` . Default: ``'mean'`` .
4434
-
4435
- - ``'none'``: no reduction will be applied.
4436
- - ``'mean'``: compute and return the weighted mean of elements in the output.
4437
- - ``'sum'``: the output elements will be summed.
4438
-
4439
- Inputs:
4440
- - **logits** (Tensor) - Input logits. Data type must be float16 or float32.
4441
- Tensor of shape :math:`(N, *)` where :math:`*` means, any number of additional dimensions.
4442
- - **label** (Tensor) - Ground truth label, has the same shape as `logits`.
4443
- Data type must be float16 or float32.
4444
- - **weight** (Tensor) - A rescaling weight applied to the loss of each batch element. It can be
4445
- broadcast to a tensor with shape of `logits`. Data type must be float16 or float32.
4446
- - **pos_weight** (Tensor) - A weight of positive examples. Must be a vector with length equal to the
4447
- number of classes. It can be broadcast to a tensor with shape of `logits`.
4448
- Data type must be float16 or float32.
4449
-
4450
- Outputs:
4451
- Tensor or Scalar, if `reduction` is ``'none'``, it's a tensor with the same shape and type as input `logits`.
4452
- Otherwise, the output is a scalar.
4453
-
4454
- Raises:
4455
- TypeError: If any input is not Tensor.
4456
- TypeError: If data type of any input is neither float16 nor float32.
4457
- TypeError: If data type of `reduction` is not string.
4458
- ValueError: If `weight` or `pos_weight` can not be broadcast to a tensor with shape of `logits`.
4459
- ValueError: If `reduction` is not one of ``'none'``, ``'mean'`` or ``'sum'``.
4460
-
4461
- Supported Platforms:
4462
- ``Ascend`` ``GPU`` ``CPU``
4463
-
4464
- Examples:
4465
- >>> import mindspore
4466
- >>> import numpy as np
4467
- >>> from mindspore import Tensor, ops
4468
- >>> logits = Tensor(np.array([[-0.8, 1.2, 0.7], [-0.1, -0.4, 0.7]]), mindspore.float32)
4469
- >>> label = Tensor(np.array([[0.3, 0.8, 1.2], [-0.6, 0.1, 2.2]]), mindspore.float32)
4470
- >>> weight = Tensor(np.array([1.0, 1.0, 1.0]), mindspore.float32)
4471
- >>> pos_weight = Tensor(np.array([1.0, 1.0, 1.0]), mindspore.float32)
4472
- >>> loss = ops.BCEWithLogitsLoss()
4473
- >>> output = loss(logits, label, weight, pos_weight)
4474
- >>> print(output)
4475
- 0.3463612
4476
- """
4477
-
4478
- @prim_attr_register
4479
- def __init__(self, reduction='mean'):
4480
- """Initialize BCEWithLogitsLoss"""
4481
- super().__init__("BCEWithLogitsLoss")
4482
- self.reduction = validator.check_string(reduction, ['none', 'sum', 'mean'], 'reduction', self.name)
4483
-
4484
-
4485
3210
  class Pad(Primitive):
4486
3211
  r"""
4487
3212
  Pads the input tensor according to the paddings.
@@ -4729,18 +3454,18 @@ class ComputeAccidentalHits(Primitive):
4729
3454
  num_true (int): The number of target classes per training example. Default: ``1`` .
4730
3455
 
4731
3456
  Inputs:
4732
- - **true_classes** (Tensor) - The target classes. With data type of int32 or int64
3457
+ - **true_classes** (Tensor) - The target classes. With data type of int64
4733
3458
  and shape :math:`(batch\_size, num\_true)`.
4734
3459
  - **sampled_candidates** (Tensor) - The Candidate sampling results of operators, types of training samples,
4735
- with data type of int32 or int64 and shape :math:`(num\_sampled, )`.
3460
+ with data type of int64 and shape :math:`(num\_sampled, )`.
4736
3461
 
4737
3462
  Outputs:
4738
3463
  Tuple of 3 Tensors.
4739
3464
 
4740
3465
  - **indices** (Tensor) - A Tensor with shape :math:`(num\_accidental\_hits, )`,
4741
- with the same type as `true_classes`.
3466
+ with data type of int32.
4742
3467
  - **ids** (Tensor) - A Tensor with shape :math:`(num\_accidental\_hits, )`,
4743
- with the same type as `true_classes`.
3468
+ with data type of int64.
4744
3469
  - **weights** (Tensor) - A Tensor with shape :math:`(num\_accidental\_hits, )`, with the type float32.
4745
3470
 
4746
3471
  Raises:
@@ -4795,8 +3520,9 @@ class ROIAlign(Primitive):
4795
3520
 
4796
3521
 
4797
3522
  Inputs:
4798
- - **features** (Tensor) - The input features, whose shape must be :math:`(N, C, H, W)`.
4799
- - **rois** (Tensor) - The shape is :math:`(rois\_n, 5)`. With data type of float16 or float32.
3523
+ - **features** (Tensor) - The input features, whose shape must be :math:`(N, C, H, W)`, with data type of
3524
+ float16 or float32.
3525
+ - **rois** (Tensor) - The shape is :math:`(rois\_n, 5)`, with data type of float16 or float32.
4800
3526
  `rois_n` represents the number of RoI. The size of the second dimension must be `5` and the `5` colunms
4801
3527
  are :math:`(image\_index, top\_left\_x, top\_left\_y, bottom\_right\_x, bottom\_right\_y)`.
4802
3528
  `image_index` represents the index of image. `top_left_x` and `top_left_y` represent the `x, y`
@@ -4958,120 +3684,6 @@ class Adam(Primitive):
4958
3684
  self.add_prim_attr('side_effect_mem', True)
4959
3685
 
4960
3686
 
4961
- class AdamWeightDecay(Primitive):
4962
- r"""
4963
- Updates gradients by the Adaptive Moment Estimation algorithm with weight decay (AdamWeightDecay).
4964
-
4965
- The Adam algorithm is proposed in `Adam: A Method for Stochastic Optimization <https://arxiv.org/abs/1412.6980>`_.
4966
- The AdamWeightDecay variant was proposed in `Decoupled Weight Decay Regularization
4967
- <https://arxiv.org/abs/1711.05101>`_.
4968
-
4969
- The updating formulas are as follows,
4970
-
4971
- .. math::
4972
- \begin{array}{ll} \\
4973
- m = \beta_1 * m + (1 - \beta_1) * g \\
4974
- v = \beta_2 * v + (1 - \beta_2) * g * g \\
4975
- update = \frac{m}{\sqrt{v} + \epsilon} \\
4976
- update =
4977
- \begin{cases}
4978
- update + weight\_decay * w
4979
- & \text{ if } weight\_decay > 0 \\
4980
- update
4981
- & \text{ otherwise }
4982
- \end{cases} \\
4983
- w = w - lr * update
4984
- \end{array}
4985
-
4986
- :math:`m` represents the 1st moment vector, :math:`v` represents the 2nd moment vector, :math:`g` represents
4987
- `gradient`, :math:`\beta_1, \beta_2` represent `beta1` and `beta2`,
4988
- :math:`lr` represents `learning_rate`, :math:`w` represents `var`, :math:`decay` represents `weight_decay`,
4989
- :math:`\epsilon` represents `epsilon`.
4990
-
4991
- Args:
4992
- use_locking (bool): Whether to enable a lock to protect variable tensors from being updated.
4993
- If ``True`` , updates of the var, m, and v tensors will be protected by a lock.
4994
- If ``False`` , the result is unpredictable. Default: ``False`` .
4995
-
4996
- Inputs:
4997
- - **var** (Parameter) - Weights to be updated. The shape is :math:`(N, *)` where :math:`*` means,
4998
- any number of additional dimensions. The data type can be float16 or float32.
4999
- - **m** (Parameter) - The 1st moment vector in the updating formula,
5000
- it should have the the shape as `var`. The data type can be float16 or float32.
5001
- - **v** (Parameter) - The 2nd moment vector in the updating formula,
5002
- it should have the same shape as `m`.
5003
- - **lr** (float) - :math:`lr` in the updating formula. The paper suggested value is :math:`10^{-8}`,
5004
- the data type should be float32.
5005
- - **beta1** (float) - The exponential decay rate for the 1st moment estimations,
5006
- the data type should be float32. The paper suggested value is :math:`0.9`
5007
- - **beta2** (float) - The exponential decay rate for the 2nd moment estimations,
5008
- the data type should be float32. The paper suggested value is :math:`0.999`
5009
- - **epsilon** (float) - Term added to the denominator to improve numerical stability,
5010
- the data type should be float32.
5011
- - **decay** (float) - The weight decay value, must be a scalar tensor with float32 data type.
5012
- Default: ``0.0`` .
5013
- - **gradient** (Tensor) - Gradient, has the same shape as `var`.
5014
-
5015
- Outputs:
5016
- Tuple of 3 Tensor, the updated parameters.
5017
-
5018
- - **var** (Tensor) - The same shape and data type as `var`.
5019
- - **m** (Tensor) - The same shape and data type as `m`.
5020
- - **v** (Tensor) - The same shape and data type as `v`.
5021
-
5022
- Raises:
5023
- TypeError: If `use_locking` is not a bool.
5024
- TypeError: If `lr`, `beta1`, `beta2`, `epsilon` or `decay` is not a float32.
5025
- TypeError: If `var`, `m` or `v` is not a Parameter with dtype float16 or float32.
5026
- TypeError: If `gradient` is not a Tensor.
5027
- ValueError: If `eps` <= 0.
5028
- ValueError: If `beta1`, `beta2` is not in range (0.0,1.0).
5029
- ValueError: If `decay` < 0.
5030
-
5031
- Supported Platforms:
5032
- ``Ascend`` ``GPU`` ``CPU``
5033
-
5034
- Examples:
5035
- >>> import numpy as np
5036
- >>> import mindspore.nn as nn
5037
- >>> from mindspore import Tensor, Parameter, ops
5038
- >>> class Net(nn.Cell):
5039
- ... def __init__(self):
5040
- ... super(Net, self).__init__()
5041
- ... self.adam_weight_decay = ops.AdamWeightDecay()
5042
- ... self.var = Parameter(Tensor(np.ones([2, 2]).astype(np.float32)), name="var")
5043
- ... self.m = Parameter(Tensor(np.ones([2, 2]).astype(np.float32)), name="m")
5044
- ... self.v = Parameter(Tensor(np.ones([2, 2]).astype(np.float32)), name="v")
5045
- ... def construct(self, lr, beta1, beta2, epsilon, decay, grad):
5046
- ... out = self.adam_weight_decay(self.var, self.m, self.v, lr, beta1, beta2,
5047
- ... epsilon, decay, grad)
5048
- ... return out
5049
- >>> net = Net()
5050
- >>> gradient = Tensor(np.ones([2, 2]).astype(np.float32))
5051
- >>> output = net(0.001, 0.9, 0.999, 1e-8, 0.0, gradient)
5052
- >>> print(net.var.asnumpy())
5053
- [[0.999 0.999]
5054
- [0.999 0.999]]
5055
- """
5056
- __mindspore_signature__ = (
5057
- sig.make_sig('var', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T),
5058
- sig.make_sig('m', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T2),
5059
- sig.make_sig('v', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T2),
5060
- sig.make_sig('lr', dtype=sig.sig_dtype.T1),
5061
- sig.make_sig('beta1', dtype=sig.sig_dtype.T1),
5062
- sig.make_sig('beta2', dtype=sig.sig_dtype.T1),
5063
- sig.make_sig('epsilon', dtype=sig.sig_dtype.T1),
5064
- sig.make_sig('decay', dtype=sig.sig_dtype.T1),
5065
- sig.make_sig('gradient', dtype=sig.sig_dtype.T)
5066
- )
5067
-
5068
- @prim_attr_register
5069
- def __init__(self, use_locking=False):
5070
- """Initialize AdamWeightDecay."""
5071
- self.add_prim_attr('side_effect_mem', True)
5072
- validator.check_value_type("use_locking", use_locking, [bool], self.name)
5073
-
5074
-
5075
3687
  class AdamNoUpdateParam(Primitive):
5076
3688
  r"""
5077
3689
  Updates gradients by the Adaptive Moment Estimation (Adam) algorithm. This operator do not update the parameter, but
@@ -5632,16 +4244,20 @@ class KLDivLoss(Primitive):
5632
4244
  Note:
5633
4245
  - On Ascend, float64 dtype is not currently supported.
5634
4246
  - The output aligns with the mathematical definition of Kullback-Leibler divergence
5635
- only when `reduction` is set to 'batchmean'.
4247
+ only when `reduction` is set to ``'batchmean'``.
4248
+ - On Ascend, the value of `reduction` must be one of ``'batchmean'``, ``'none'`` or ``'sum'``.
4249
+ - On GPU, the value of `reduction` must be one of ``'mean'``, ``'none'`` or ``'sum'``.
4250
+ - On CPU, the value of `reduction` must be one of ``'mean'``, ``'batchmean'``, ``'none'``
4251
+ or ``'sum'``.
5636
4252
 
5637
4253
  Args:
5638
4254
  reduction (str): Specifies the reduction to be applied to the output.
5639
4255
  Default: ``'mean'`` .
5640
4256
 
5641
- - On Ascend, the value of `reduction` must be one of ``'batchmean'``, ``'none'`` or ``'sum'``.
5642
- - On GPU, the value of `reduction` must be one of ``'mean'``, ``'none'`` or ``'sum'``.
5643
- - On CPU, the value of `reduction` must be one of ``'mean'``, ``'batchmean'``, ``'none'``
5644
- or ``'sum'``.
4257
+ - ``'none'``: no reduction will be applied.
4258
+ - ``'mean'``: compute and return the mean of elements in the output.
4259
+ - ``'sum'``: the output elements will be summed.
4260
+ - ``'batchmean'``: average loss is taken over the batch, similar to the mean mode.
5645
4261
 
5646
4262
  Inputs:
5647
4263
  - **logits** (Tensor) - The input Tensor. The data type must be float16, float32 or float64.
@@ -5678,103 +4294,23 @@ class KLDivLoss(Primitive):
5678
4294
  >>> labels = Tensor(np.array([0., 1., 0.]), mindspore.float32)
5679
4295
  >>> output = net(logits, labels)
5680
4296
  >>> print(output)
5681
- -0.7
5682
- """
5683
-
5684
- @prim_attr_register
5685
- def __init__(self, reduction='mean'):
5686
- """Initialize KLDivLoss."""
5687
- device_target = context.get_context("device_target")
5688
- if device_target == "CPU":
5689
- support_mode = ['none', 'mean', 'batchmean', 'sum']
5690
- elif device_target == "GPU":
5691
- support_mode = ['none', 'mean', 'sum']
5692
- elif device_target == "Ascend":
5693
- support_mode = ['none', 'batchmean', 'sum', 'mean']
5694
- else:
5695
- raise ValueError(f"'{self.name}' unknown device target: '{device_target}'")
5696
-
5697
- self.reduction = validator.check_string(reduction, support_mode, 'reduction', self.name)
5698
-
5699
-
5700
- class BinaryCrossEntropy(Primitive):
5701
- r"""
5702
- Computes the binary cross entropy between the logits and the labels.
5703
-
5704
- Sets logits as :math:`x`, labels as :math:`y`, output as :math:`\ell(x, y)`.
5705
- Let,
5706
-
5707
- .. math::
5708
- L = \{l_1,\dots,l_N\}^\top, \quad
5709
- l_n = - w_n \left[ y_n \cdot \log x_n + (1 - y_n) \cdot \log (1 - x_n) \right]
5710
-
5711
- In which, :math:`L` indicates the loss of all batch_sizes, :math:`l` indicates the loss of one batch_size,
5712
- and n indicates one batch_size in the 1-N range, :math:`w_n` indicates the
5713
- weight of :math:`n`-th batch of binary cross entropy. Then,
5714
-
5715
- .. math::
5716
- \ell(x, y) = \begin{cases}
5717
- L, & \text{if reduction} = \text{'none';}\\
5718
- \operatorname{mean}(L), & \text{if reduction} = \text{'mean';}\\
5719
- \operatorname{sum}(L), & \text{if reduction} = \text{'sum'.}
5720
- \end{cases}
5721
-
5722
- .. warning::
5723
- - The value of :math:`x` must range from 0 to 1.
5724
-
5725
- Args:
5726
- reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
5727
- ``'sum'`` . Default: ``'mean'`` .
5728
-
5729
- - ``'none'``: no reduction will be applied.
5730
- - ``'mean'``: compute and return the weighted mean of elements in the output.
5731
- - ``'sum'``: the output elements will be summed.
5732
-
5733
- Inputs:
5734
- - **logits** (Tensor) - The predictive value whose data type must be float16 or float32,
5735
- The shape is :math:`(N, *)` where :math:`*` means, any number of additional dimensions.
5736
- - **labels** (Tensor) - The target value which has the same shape and data type as `logits`.
5737
- - **weight** (Tensor, optional) - A rescaling weight applied to the loss of each batch element.
5738
- And it must have the same shape and data type as `logits`. Default: ``None`` .
5739
-
5740
- Outputs:
5741
- Tensor or Scalar. Returns Tensor that has the same dtype and shape as `logits` if `reduction` is 'none'.
5742
- Otherwise, returns a scalar Tensor.
5743
-
5744
- Raises:
5745
- TypeError: If dtype of `logits`, `labels` or `weight` (if given) is neither float16 nor float32.
5746
- ValueError: If `reduction` is not one of ``'none'``, ``'mean'`` or ``'sum'``.
5747
- ValueError: If shape of `labels` is not the same as `logits` or `weight` (if given).
5748
- TypeError: If `logits`, `labels` or `weight` is not a Tensor.
5749
-
5750
- Supported Platforms:
5751
- ``Ascend`` ``GPU`` ``CPU``
5752
-
5753
- Examples:
5754
- >>> import mindspore
5755
- >>> import numpy as np
5756
- >>> from mindspore import Tensor, nn, ops
5757
- >>> class Net(nn.Cell):
5758
- ... def __init__(self):
5759
- ... super(Net, self).__init__()
5760
- ... self.binary_cross_entropy = ops.BinaryCrossEntropy()
5761
- ... def construct(self, logits, labels, weight):
5762
- ... result = self.binary_cross_entropy(logits, labels, weight)
5763
- ... return result
5764
- ...
5765
- >>> net = Net()
5766
- >>> logits = Tensor(np.array([0.2, 0.7, 0.1]), mindspore.float32)
5767
- >>> labels = Tensor(np.array([0., 1., 0.]), mindspore.float32)
5768
- >>> weight = Tensor(np.array([1, 2, 2]), mindspore.float32)
5769
- >>> output = net(logits, labels, weight)
5770
- >>> print(output)
5771
- 0.38240486
4297
+ -0.7
5772
4298
  """
5773
4299
 
5774
4300
  @prim_attr_register
5775
4301
  def __init__(self, reduction='mean'):
5776
- """Initialize BinaryCrossEntropy."""
5777
- self.reduction = validator.check_string(reduction, ['none', 'mean', 'sum'], 'reduction', self.name)
4302
+ """Initialize KLDivLoss."""
4303
+ device_target = context.get_context("device_target")
4304
+ if device_target == "CPU":
4305
+ support_mode = ['none', 'mean', 'batchmean', 'sum']
4306
+ elif device_target == "GPU":
4307
+ support_mode = ['none', 'mean', 'sum']
4308
+ elif device_target == "Ascend":
4309
+ support_mode = ['none', 'batchmean', 'sum', 'mean']
4310
+ else:
4311
+ raise ValueError(f"'{self.name}' unknown device target: '{device_target}'")
4312
+
4313
+ self.reduction = validator.check_string(reduction, support_mode, 'reduction', self.name)
5778
4314
 
5779
4315
 
5780
4316
  class ApplyAdaMax(Primitive):
@@ -6497,22 +5033,21 @@ class ApplyAddSign(Primitive):
6497
5033
  is the last moment of :math:`m_{t+1}`, :math:`lr` represents scaling factor `lr`, :math:`g` represents `grad`,
6498
5034
  :math:`\alpha` represents `alpha`, :math:`\beta` represents `beta`.
6499
5035
 
6500
- Inputs of `var`, `accum` and `grad` comply with the implicit type conversion rules
5036
+ The data type of all inputs must be float16 or float32 on Ascend and float16, float32 or float64 on CPU and GPU.
5037
+
5038
+ Inputs of `var`, `accum` and `grad` , `sign_decay` and `beta` comply with the implicit type conversion rules
6501
5039
  to make the data types consistent.
6502
5040
  If they have different data types, the lower priority data type will be converted to
6503
5041
  the relatively highest priority data type.
6504
- The data type of inputs must be float16 or float32 on Ascend and float16, float32 or float64 on CPU and GPU.
6505
5042
 
6506
5043
  Inputs:
6507
- - **var** (Parameter) - Variable tensor to be updated. With float16, float32 or float64 data type.
5044
+ - **var** (Parameter) - Variable tensor to be updated.
6508
5045
  The shape is :math:`(N, *)` where :math:`*` means, any number of additional dimensions.
6509
5046
  - **m** (Parameter) - Variable tensor to be updated, has the same data type as `var`.
6510
5047
  - **lr** (Union[Number, Tensor]) - The learning rate value, must be a scalar.
6511
- With float16, float32 or float64 data type.
6512
- - **alpha** (Union[Number, Tensor]) - Must be a scalar. With float16, float32 or float64 data type.
6513
- - **sign_decay** (Union[Number, Tensor]) - Must be a scalar. With float16, float32 or float64 data type.
5048
+ - **alpha** (Union[Number, Tensor]) - Must be a scalar.
5049
+ - **sign_decay** (Union[Number, Tensor]) - Must be a scalar.
6514
5050
  - **beta** (Union[Number, Tensor]) - The exponential decay rate, must be a scalar.
6515
- With float16, float32 or float64 data type.
6516
5051
  - **grad** (Tensor) - A tensor of the same shape as `var`, for the gradient.
6517
5052
 
6518
5053
  Outputs:
@@ -6522,7 +5057,8 @@ class ApplyAddSign(Primitive):
6522
5057
  - **m** (Tensor) - The same shape and data type as `m`.
6523
5058
 
6524
5059
  Raises:
6525
- TypeError: If dtype of `var`, `lr`, `alpha`, `sign_decay` or `beta` is not float16, float32 or float64.
5060
+ TypeError: If dtype of `var`, `lr` and `alpha` is not float16, float32 or float64.
5061
+ TypeError: If dtype of `sign_decay` and `beta` are both not float16, float32 or float64.
6526
5062
  TypeError: If `lr`, `alpha` or `sign_decay` is neither a Number nor a Tensor.
6527
5063
  TypeError: If `grad` is not a Tensor.
6528
5064
  TypeError: If the data type of `var`, `accum` and `grad` conversion of Parameter is not supported.
@@ -6829,9 +5365,12 @@ class LARSUpdate(PrimitiveWithInfer):
6829
5365
  For more details, please refer to :class:`mindspore.nn.LARS`.
6830
5366
 
6831
5367
  Args:
6832
- epsilon (float): Term added to the denominator to improve numerical stability. Default: ``1e-05`` .
6833
- hyperpara (float): Trust coefficient for calculating the local learning rate. Default: ``0.001`` .
6834
- use_clip (bool): Whether to use clip operation for calculating the local learning rate. Default: ``False`` .
5368
+ epsilon (float, optional): Term added to the denominator to improve numerical stability.
5369
+ Default: ``1e-05`` .
5370
+ hyperpara (float, optional): Trust coefficient for calculating the local learning rate.
5371
+ Default: ``0.001`` .
5372
+ use_clip (bool, optional): Whether to use clip operation for calculating the local learning rate.
5373
+ Default: ``False`` .
6835
5374
 
6836
5375
  Inputs:
6837
5376
  - **weight** (Tensor) - A tensor, representing the weight.
@@ -7033,7 +5572,7 @@ class SparseApplyFtrl(Primitive):
7033
5572
  Examples:
7034
5573
  >>> import mindspore
7035
5574
  >>> import numpy as np
7036
- >>> from mindspore import Tensor, nn, Parameter
5575
+ >>> from mindspore import Tensor, nn, Parameter, ops
7037
5576
  >>> class SparseApplyFtrlNet(nn.Cell):
7038
5577
  ... def __init__(self):
7039
5578
  ... super(SparseApplyFtrlNet, self).__init__()
@@ -7131,69 +5670,6 @@ class SparseApplyFtrlV2(PrimitiveWithInfer):
7131
5670
  return var_dtype, accum_dtype, linear_dtype
7132
5671
 
7133
5672
 
7134
- class Dropout(PrimitiveWithCheck):
7135
- r"""
7136
- During training, randomly zeroes some of the elements of the input tensor
7137
- with probability :math:`1 - keep\_prob` from a Bernoulli distribution. It plays the
7138
- role of reducing neuron correlation and avoid overfitting.
7139
-
7140
- Refer to :func:`mindspore.ops.dropout` for more details.
7141
-
7142
- Args:
7143
- keep_prob (float, optional): The keep rate, between 0 and 1, e.g. keep_prob = 0.9,
7144
- means dropping out 10% of input units. Default: ``0.5`` .
7145
- Seed0 (int, optional): Seed0 value for random generating. Default: ``0`` .
7146
- Seed1 (int, optional): Seed1 value for random generating. Default: ``0`` .
7147
-
7148
- Inputs:
7149
- - **x** (Tensor) - The input Tensor of shape :math:`(*, N)`, with data type of float16, float32 or float64.
7150
-
7151
- Outputs:
7152
- - **output** (Tensor) - With the same shape and data type as `x`.
7153
- - **mask** (Tensor) - The mask applied to `x`.
7154
-
7155
- - On GPU and CPU, `mask` has the same shape and data type as `x`.
7156
- - On Ascend, to achieve a better performance, it is denoted as a 1-D Tensor
7157
- with Uint8 data type. It has shape :math:`(byte\_counts, )` where :math:`byte\_counts` is the
7158
- number of bytes needed to mask the input `x`, :math:`byte\_counts` is calculated using the
7159
- following formula:
7160
-
7161
- .. math::
7162
-
7163
- byte\_counts = \text{ceil}(\text{cumprod}(x.shape) / 128) * 16
7164
-
7165
- If shape of `x` is :math:`(2, 3, 4, 5, 6)`, the shape of `mask` will be :math:`(96, )`.
7166
-
7167
- Supported Platforms:
7168
- ``Ascend`` ``GPU`` ``CPU``
7169
-
7170
- Examples:
7171
- >>> import mindspore
7172
- >>> import numpy as np
7173
- >>> from mindspore import Tensor, ops
7174
- >>> dropout = ops.Dropout(keep_prob=0.5)
7175
- >>> x = Tensor(np.ones([1, 2, 3, 4, 5]), mindspore.float32)
7176
- >>> output, mask = dropout(x)
7177
- >>> print(output.shape, mask.shape, mask.dtype)
7178
- (1, 2, 3, 4, 5) (16,) UInt8
7179
- """
7180
-
7181
- @prim_attr_register
7182
- def __init__(self, keep_prob=0.5, Seed0=0, Seed1=0):
7183
- """Initialize Dropout."""
7184
- self.seed0 = validator.check_value_type("Seed0", Seed0, [int], self.name)
7185
- self.seed1 = validator.check_value_type("Seed1", Seed1, [int], self.name)
7186
- self.keep_prob = validator.check_float_range(keep_prob, 0, 1, validator.INC_RIGHT, "keep_prob", self.name)
7187
- self.add_prim_attr("side_effect_hidden", True)
7188
-
7189
- def check_shape(self, x_shape):
7190
- validator.check_int(len(x_shape), 1, validator.GE, "x_shape", self.name)
7191
-
7192
- def check_dtype(self, x_dtype):
7193
- valid_dtypes = (mstype.float16, mstype.float32, mstype.float64)
7194
- validator.check_tensor_dtype_valid("x", x_dtype, valid_dtypes, self.name)
7195
-
7196
-
7197
5673
  class Dropout2D(PrimitiveWithInfer):
7198
5674
  r"""
7199
5675
  During training, randomly zeroes some channels of the input tensor with probability :math:`1-keep\_prob`
@@ -7545,7 +6021,7 @@ class DynamicRNN(Primitive):
7545
6021
  - **w** (Tensor) - Weight. Tensor of shape :math:`(input\_size + hidden\_size, 4 * hidden\_size)`.
7546
6022
  The data type must be float16.
7547
6023
  - **b** (Tensor) - Bias. Tensor of shape :math:`(4 * hidden\_size)`.
7548
- The data type must be float16 or float32.
6024
+ The data type must be float16.
7549
6025
  - **seq_length** (Tensor) - The length of each batch. Tensor of shape :math:`(batch\_size, )`.
7550
6026
  Only `None` is currently supported.
7551
6027
  - **init_h** (Tensor) - Hidden state of initial time. Tensor of shape :math:`(1, batch\_size, hidden\_size)`.
@@ -7614,11 +6090,13 @@ class DynamicRNN(Primitive):
7614
6090
  self.forget_bias = validator.check_value_type("forget_bias", forget_bias, [float], self.name)
7615
6091
  self.cell_depth = validator.check_value_type("cell_depth", cell_depth, [int], self.name)
7616
6092
  self.keep_prob = validator.check_value_type("keep_prob", keep_prob, [float], self.name)
6093
+ validator.check_number_range(keep_prob, 0.0, 1.0, validator.INC_BOTH, float, "keep_prob")
7617
6094
  self.cell_clip = validator.check_value_type("cell_clip", cell_clip, [float], self.name)
7618
6095
  self.num_proj = validator.check_non_negative_int(num_proj, "num_proj", self.name)
7619
6096
  self.forget_bias = validator.check_value_type("forget_bias", forget_bias, [float], self.name)
7620
6097
  self.use_peephole = validator.check_value_type("use_peephole", use_peephole, [bool], self.name)
7621
6098
  self.time_major = validator.check_value_type("time_major", time_major, [bool], self.name)
6099
+ validator.check("time_major", time_major, "the supported value", True, validator.EQ, self.name)
7622
6100
  self.is_training = validator.check_value_type("is_training", is_training, [bool], self.name)
7623
6101
  validator.check_value_type("cell_type", cell_type, [str], self.name)
7624
6102
  self.cell_type = validator.check_string(cell_type, ['LSTM'], "cell_type", self.name)
@@ -7649,21 +6127,21 @@ class DynamicGRUV2(Primitive):
7649
6127
  :math:`\sigma` is the sigmoid function, and :math:`*` is the Hadamard product.
7650
6128
 
7651
6129
  Args:
7652
- direction (str): A string identifying the direction in the operator. Default: ``'UNIDIRECTIONAL'`` .
6130
+ direction (str, optional): A string identifying the direction in the operator. Default: ``'UNIDIRECTIONAL'`` .
7653
6131
  Only ``'UNIDIRECTIONAL'`` is currently supported.
7654
- cell_depth (int): An integer identifying the cell depth in the operator. Default: ``1`` .
7655
- keep_prob (float): A float identifying the keep prob in the operator. Default: ``1.0`` .
7656
- cell_clip (float): A float identifying the cell clip in the operator. Default: ``-1.0`` .
7657
- num_proj (int): An integer identifying the number projection in the operator. Default: ``0`` .
7658
- time_major (bool): A bool identifying the time major in the operator. Default: ``True`` .
7659
- activation (str) : A string identifying the type of activation function in the operator.
6132
+ cell_depth (int, optional): An integer identifying the cell depth in the operator. Default: ``1`` .
6133
+ keep_prob (float, optional): A float identifying the keep prob in the operator. Default: ``1.0`` .
6134
+ cell_clip (float, optional): A float identifying the cell clip in the operator. Default: ``-1.0`` .
6135
+ num_proj (int, optional): An integer identifying the number projection in the operator. Default: ``0`` .
6136
+ time_major (bool, optional): A bool identifying the time major in the operator. Default: ``True`` .
6137
+ activation (str, optional) : A string identifying the type of activation function in the operator.
7660
6138
  Default: ``'tanh'`` . Only ``'tanh'`` is currently supported.
7661
- gate_order (str): A string identifying the gate order in weight and bias. Default: ``'rzh'`` .
6139
+ gate_order (str, optional): A string identifying the gate order in weight and bias. Default: ``'rzh'`` .
7662
6140
  ``'zrh'`` is another option. Here, ``'rzh'`` means the gate order is: reset gate, update gate, hidden gate.
7663
6141
  ``'zrh'`` means the gate order is: update gate, reset gate, hidden gate.
7664
- reset_after (bool): A bool identifying whether to apply reset gate after matrix multiplication.
6142
+ reset_after (bool, optional): A bool identifying whether to apply reset gate after matrix multiplication.
7665
6143
  Default: ``True`` .
7666
- is_training (bool): A bool identifying is training in the operator. Default: ``True`` .
6144
+ is_training (bool, optional): A bool identifying is training in the operator. Default: ``True`` .
7667
6145
 
7668
6146
  Inputs:
7669
6147
  - **x** (Tensor) - Current words.
@@ -8007,8 +6485,9 @@ class Conv3D(Primitive):
8007
6485
 
8008
6486
  Applies a 3D convolution over an input tensor which is typically of shape
8009
6487
  :math:`(N, C_{in}, D_{in}, H_{in}, W_{in})`,
8010
- where :math:`N` is batch size, :math:`C` is channel number, :math:`D` is feature depth,
8011
- :math:`H` is feature height, :math:`W` is feature width.
6488
+ where :math:`N` is batch size, :math:`C` is channel number,
6489
+ :math:`D, H, W`
6490
+ are the depth, height and width of the feature map, respectively.
8012
6491
 
8013
6492
  The output is calculated based on formula:
8014
6493
 
@@ -8019,25 +6498,30 @@ class Conv3D(Primitive):
8019
6498
 
8020
6499
  where :math:`bias` is the output channel bias, :math:`ccor` is
8021
6500
  the `cross-correlation <https://en.wikipedia.org/wiki/Cross-correlation>`_,
8022
- , :math:`weight` is the convolution kernel value and :math:`X` represents the input feature map.
6501
+ :math:`weight` is the convolution kernel value and :math:`X` represents the input feature map.
8023
6502
 
8024
6503
  Here are the indices' meanings:
8025
- - :math:`i` corresponds to the batch number, ranging from 0 to N-1, where N is the batch size of the input.
8026
6504
 
8027
- - :math:`j` corresponds to the output channel, ranging from 0 to C_{out}-1, where C_{out} is the number of
6505
+ - :math:`i` corresponds to the batch number, the range is :math:`[0, N-1]`,
6506
+ where :math:`N` is the batch size of the input.
6507
+
6508
+ - :math:`j` corresponds to the output channel, the range is :math:`[0, C_{out}-1]`,
6509
+ where :math:`C_{out}` is the number of
8028
6510
  output channels, which is also equal to the number of kernels.
8029
6511
 
8030
- - :math:`k` corresponds to the input channel, ranging from 0 to C_{in}-1, where C_{in} is the number of
6512
+ - :math:`k` corresponds to the input channel, the range is :math:`[0, C_{in}-1]`,
6513
+ where :math:`C_{in}` is the number of
8031
6514
  input channels, which is also equal to the number of channels in the convolutional kernels.
8032
6515
 
8033
- Therefore, in the above formula, :math:`{bias}(C_{out_j})` represents the bias of the :math:`j`-th
8034
- output channel, :math:`{weight}(C_{out_j}, k)` represents the slice of the :math:`j`-th convolutional
6516
+ Therefore, in the above formula, :math:`{bias}(C_{\text{out}_j})` represents the bias of the :math:`j`-th
6517
+ output channel, :math:`{weight}(C_{\text{out}_j}, k)`represents the slice of the :math:`j`-th convolutional
8035
6518
  kernel in the :math:`k`-th channel, and :math:`{X}(N_i, k)` represents the slice of the :math:`k`-th input
8036
6519
  channel in the :math:`i`-th batch of the input feature map.
8037
6520
 
8038
6521
  The shape of the convolutional kernel is given by
8039
6522
  :math:`(\text{kernel_size[0]}, \text{kernel_size[1]}, \text{kernel_size[2]})`
8040
- where :math:`kernel\_size[0]` , :math:`kernel\_size[1]` and :math:`kernel\_size[2]` are the depth,
6523
+ where :math:`\text{kernel_size[0]}` ,
6524
+ :math:`\text{kernel_size[1]}` and :math:`\text{kernel_size[2]}` are the depth,
8041
6525
  height and width of the kernel, respectively.
8042
6526
  If we consider the input and output channels as well as the `group` parameter, the complete kernel shape
8043
6527
  will be :math:`(C_{out}, C_{in} / \text{group}, \text{kernel_size[0]},
@@ -8048,8 +6532,8 @@ class Conv3D(Primitive):
8048
6532
  <http://vision.stanford.edu/cs598_spring07/papers/Lecun98.pdf>`_.
8049
6533
 
8050
6534
  Note:
8051
- 1. On Ascend platform, `groups = 1` must be satisfied.
8052
- 2. On Ascend `dilation` on depth only supports the case of 1.
6535
+ 1. On Ascend platform, :math:`groups=1` must be satisfied.
6536
+ 2. On Ascend :math:`dilation` on depth only supports the case of 1.
8053
6537
 
8054
6538
  Args:
8055
6539
  out_channel (int): Specifies output channel :math:`C_{out}`.
@@ -8671,7 +7155,7 @@ class Conv3DTranspose(Primitive):
8671
7155
  \times (\text{kernel_size}[2] - 1) + \text{output_padding}[2] + 1
8672
7156
 
8673
7157
  Note:
8674
- In Ascend, `group` must be equal to 1.
7158
+ In Ascend, only support :math:`group=1`.
8675
7159
 
8676
7160
  Args:
8677
7161
  in_channel (int): The channel of the input x.
@@ -8739,7 +7223,7 @@ class Conv3DTranspose(Primitive):
8739
7223
  ValueError: If `pad` is a tuple whose length is not equal to 6.
8740
7224
  ValueError: If `pad_mode` is not equal to 'pad' and `pad` is not equal to (0, 0, 0, 0, 0, 0).
8741
7225
  ValueError: If `data_format` is not 'NCDHW'.
8742
- TypeError: If data type of dout and weight is not float16.
7226
+ TypeError: If data type of dout and weight is neither float16 nor float32.
8743
7227
  ValueError: If bias is not none. The rank of dout and weight is not 5.
8744
7228
 
8745
7229
  Supported Platforms:
@@ -9014,46 +7498,6 @@ class SoftShrink(Primitive):
9014
7498
  validator.check_number("lambd", lambd, 0, validator.GE, self.name)
9015
7499
 
9016
7500
 
9017
- class HShrink(Primitive):
9018
- r"""
9019
- Hard Shrink activation function.
9020
-
9021
- Refer to :func:`mindspore.ops.hardshrink` for more details.
9022
-
9023
- Args:
9024
- lambd (float, optional): The threshold :math:`\lambda` defined by the Hard Shrink formula. Default: ``0.5`` .
9025
-
9026
- Inputs:
9027
- - **input_x** (Tensor) - The input of Hard Shrink with data type of float16 or float32.
9028
-
9029
- Outputs:
9030
- Tensor, the same shape and data type as the input.
9031
-
9032
- Supported Platforms:
9033
- ``Ascend`` ``GPU`` ``CPU``
9034
-
9035
- Examples:
9036
- >>> import mindspore as ms
9037
- >>> import mindspore.ops as ops
9038
- >>> from mindspore import Tensor, nn
9039
- >>> import numpy as np
9040
- >>> input_x = Tensor(np.array([[0.5, 1, 2.0], [0.0533, 0.0776, -2.1233]]), ms.float32)
9041
- >>> hshrink = ops.HShrink()
9042
- >>> output = hshrink(input_x)
9043
- >>> print(output)
9044
- [[ 0. 1. 2. ]
9045
- [ 0. 0. -2.1233]]
9046
- """
9047
-
9048
- @prim_attr_register
9049
- def __init__(self, lambd=0.5):
9050
- """Initialize HShrink"""
9051
- validator.check_value_type('lambd', lambd, [float], self.name)
9052
- if lambd < 0.0:
9053
- lambd = 0.0
9054
- self.add_prim_attr('lambd', lambd)
9055
-
9056
-
9057
7501
  class ApplyAdagradDA(Primitive):
9058
7502
  r"""
9059
7503
  Update `var` according to the proximal adagrad scheme.
@@ -9098,11 +7542,9 @@ class ApplyAdagradDA(Primitive):
9098
7542
  - **global_step** ([Number, Tensor]) - Training step number. Must be a scalar. With int32 or int64 data type.
9099
7543
 
9100
7544
  Outputs:
9101
- Tuple of 3 Tensors, the updated parameters.
7545
+ Tuple of 1 Tensors, the updated parameters.
9102
7546
 
9103
7547
  - **var** (Tensor) - The same shape and data type as `var`.
9104
- - **gradient_accumulator** (Tensor) - The same shape and data type as `gradient_accumulator`.
9105
- - **gradient_squared_accumulator** (Tensor) - The same shape and data type as `gradient_squared_accumulator`.
9106
7548
 
9107
7549
  Raises:
9108
7550
  TypeError: If `var`, `gradient_accumulator` or `gradient_squared_accumulator` is not a Parameter.
@@ -9153,11 +7595,7 @@ class ApplyAdagradDA(Primitive):
9153
7595
  >>> print(output)
9154
7596
  (Tensor(shape=[2, 2], dtype=Float32, value=
9155
7597
  [[-7.39064650e-04, -1.36888528e-03],
9156
- [-5.96988888e-04, -1.42478070e-03]]), Tensor(shape=[2, 2], dtype=Float32, value=
9157
- [[ 4.00000006e-01, 7.00000048e-01],
9158
- [ 2.00000003e-01, 6.99999988e-01]]), Tensor(shape=[2, 2], dtype=Float32, value=
9159
- [[ 2.90000021e-01, 2.60000020e-01],
9160
- [ 1.09999999e-01, 2.40000010e-01]]))
7598
+ [-5.96988888e-04, -1.42478070e-03]]))
9161
7599
  """
9162
7600
 
9163
7601
  __mindspore_signature__ = (
@@ -9669,6 +8107,14 @@ class ApplyAdamWithAmsgradV2(Primitive):
9669
8107
  var:=var-lr_t*m_t/(\sqrt{\hat v_t}+\epsilon) \\
9670
8108
  \end{array}
9671
8109
 
8110
+ :math:`t` represents updating step while :math:`m` represents the 1st moment vector,
8111
+ :math:`v` represents the 2nd moment vector, :math:`\hat v_t` represents `vhat`,
8112
+ :math:`lr` represents learning rate,
8113
+ :math:`g` represents `grad`, :math:`\beta_1, \beta_2` represent `beta1` and `beta2`,
8114
+ :math:`\beta_1^{t}` represents `beta1_power`, :math:`\beta_2^{t}` represents `beta2_power`,
8115
+ :math:`var` represents the variable to be updated,
8116
+ :math:`\epsilon` represents `epsilon`.
8117
+
9672
8118
  All of the inputs are consistent with implicit type conversion rules,
9673
8119
  which ensure that the data types are the same. If they have different data types, the lower precision data type
9674
8120
  will be converted to the data type with relatively higher precision.
@@ -9717,7 +8163,7 @@ class ApplyAdamWithAmsgradV2(Primitive):
9717
8163
  ``Ascend`` ``GPU`` ``CPU``
9718
8164
 
9719
8165
  Examples:
9720
- >>> import mindspore.ops as ops
8166
+ >>> from mindspore import ops
9721
8167
  >>> import mindspore.nn as nn
9722
8168
  >>> from mindspore import Tensor, Parameter
9723
8169
  >>> import numpy as np
@@ -9770,83 +8216,6 @@ class ApplyAdamWithAmsgradV2(Primitive):
9770
8216
  self.add_prim_attr("side_effect_mem", True)
9771
8217
 
9772
8218
 
9773
- class GridSampler3D(Primitive):
9774
- """
9775
- Given an input and a grid, the output is calculated using the input values
9776
- and pixel positions in the grid. Only volume (5-D) input is supported.
9777
-
9778
- .. warning::
9779
- This is an experimental API that is subject to change or deletion.
9780
-
9781
- Refer to :func:`mindspore.ops.grid_sample` for more details.
9782
-
9783
- Args:
9784
- interpolation_mode (str, optional): An optional string specifying the interpolation method.
9785
- The optional values are ``"bilinear"`` or ``"nearest"`` . Default: ``"bilinear"`` .
9786
-
9787
- - ``"nearest"``: Nearest neighbor interpolation. Each output pixel is assigned the value of the
9788
- nearest input pixel. This method is simple and fast but can result in blocky or pixelated outputs.
9789
- - ``"bilinear"``: Bilinear interpolation. Each output pixel is a weighted average of the four nearest input
9790
- pixels, computed using bilinear interpolation. This method produces smoother results compared
9791
- to nearest neighbor interpolation.
9792
-
9793
- padding_mode (str, optional): An optional string specifying the pad method.
9794
- The optional values are ``"zeros"`` , ``"border"`` or ``"reflection"`` . Default: ``"zeros"`` .
9795
- When the sampling grid is outside input's bounds, effects of various padding modes are as follows:
9796
-
9797
- - ``"zeros"``: Pads the input tensor with zeros.
9798
- - ``"border"``: Pads the input tensor with the values of the pixels on the border of the tensor.
9799
- - ``"reflection"``: Pads the input tensor by reflecting the values of the pixels at the
9800
- boundary of the tensor.
9801
-
9802
- align_corners (bool, optional): An optional bool specifying alignment method. If set to ``True`` ,
9803
- the extrema (-1 and 1) are considered as referring to
9804
- the center points of the input’s corner pixels. If set to ``False`` , they are instead considered as
9805
- referring to the corner points of the input’s corner pixels, making the sampling more resolution agnostic.
9806
- Default: ``False`` .
9807
-
9808
- Inputs:
9809
- - **input_x** (Tensor) - A 5-D tensor with dtype of float16, float32 or float64
9810
- and shape of :math:`(N, C, D_{in}, H_{in}, W_{in})`.
9811
- - **grid** (Tensor) - A 5-D tensor whose dtype is the same as `input_x` and whose shape is :math:`(N, D_{out},
9812
- H_{out}, W_{out}, 3)`.
9813
-
9814
- Outputs:
9815
- A 5-D Tensor whose dtype is the same as `input_x` and whose shape is :math:`(N, C, D_{out}, H_{out}, W_{out})`.
9816
-
9817
- Supported Platforms:
9818
- ``Ascend`` ``GPU`` ``CPU``
9819
-
9820
- Examples:
9821
- >>> import numpy as np
9822
- >>> from mindspore import Tensor, ops
9823
- >>> gridsampler = ops.GridSampler3D(interpolation_mode='bilinear', padding_mode='zeros', align_corners=True)
9824
- >>> input_x = Tensor(np.arange(32).reshape((2, 2, 2, 2, 2)).astype(np.float32))
9825
- >>> grid = Tensor(np.arange(-0.2, 1, 0.1).reshape((2, 2, 1, 1, 3)).astype(np.float32))
9826
- >>> output = gridsampler(input_x, grid)
9827
- >>> print(output)
9828
- [[[[[ 3.3 ]]
9829
- [[ 4.35 ]]]
9830
- [[[11.300001]]
9831
- [[12.349999]]]]
9832
- [[[[21.4 ]]
9833
- [[22.449999]]]
9834
- [[[29.4 ]]
9835
- [[30.449999]]]]]
9836
- """
9837
-
9838
- @prim_attr_register
9839
- def __init__(self, interpolation_mode='bilinear', padding_mode='zeros', align_corners=False):
9840
- """Initialize GridSampler3D."""
9841
- validator.check_string(interpolation_mode, ['bilinear', 'nearest'], 'interpolation_mode', self.name)
9842
- validator.check_string(padding_mode, ['zeros', 'border', 'reflection'], 'padding_mode', self.name)
9843
- validator.check_bool(align_corners, 'align_corners', self.name)
9844
- self.init_prim_io_names(inputs=['input_x', 'grid'], outputs=['output'])
9845
- self.add_prim_attr('interpolation_mode', interpolation_mode)
9846
- self.add_prim_attr('padding_mode', padding_mode)
9847
- self.add_prim_attr('align_corners', align_corners)
9848
-
9849
-
9850
8219
  class FractionalMaxPool(Primitive):
9851
8220
  r"""
9852
8221
  Performs fractional max pooling on the input.
@@ -10399,104 +8768,21 @@ class DeformableOffsets(Primitive):
10399
8768
  self.add_prim_attr('modulated', self.modulated)
10400
8769
 
10401
8770
 
10402
- class GridSampler2D(Primitive):
10403
- """
10404
- This operation samples 2d `input_x` by using interpolation based on flow field grid,
10405
- which is usually gennerated by :func:`mindspore.ops.affine_grid`.
10406
-
10407
- .. warning::
10408
- This is an experimental API that is subject to change or deletion.
10409
-
10410
- Refer to :func:`mindspore.ops.grid_sample` for more details.
10411
-
10412
- Args:
10413
- interpolation_mode (str, optional): An optional string specifying the interpolation method.
10414
- The optional values are
10415
- ``"bilinear"`` or ``"nearest"`` . Default: ``"bilinear"`` .
10416
-
10417
- - ``"nearest"``: Nearest neighbor interpolation. Each output pixel is assigned the value of the
10418
- nearest input pixel. This method is simple and fast but can result in blocky or pixelated outputs.
10419
- - ``"bilinear"``: Bilinear interpolation. Each output pixel is a weighted average of the four nearest input
10420
- pixels, computed using bilinear interpolation. This method produces smoother results compared
10421
- to nearest neighbor interpolation.
10422
-
10423
- padding_mode (str, optional): An optional string specifying the pad method.
10424
- The optional values are ``"zeros"`` , ``"border"`` or ``"reflection"`` . Default: ``"zeros"`` .
10425
- When the sampling grid is outside input's bounds, effects of various padding modes are as follows:
10426
-
10427
- - ``"zeros"``: Pads the input tensor with zeros.
10428
- - ``"border"``: Pads the input tensor with the values of the pixels on the border of the tensor.
10429
- - ``"reflection"``: Pads the input tensor by reflecting the values of the pixels at the
10430
- boundary of the tensor.
10431
-
10432
- align_corners (bool, optional): An optional bool. When set to ``True`` ,
10433
- the centers of the corner pixels of the input
10434
- and output tensors are aligned. When set to ``False`` , it is not aligned. Default: ``False`` .
10435
-
10436
- Inputs:
10437
- - **input_x** (Tensor) - A 4-D tensor with shape
10438
- :math:`(N, C, H_{in}, W_{in})`. Supported dtypes:
10439
-
10440
- - Ascend: float16, float32.
10441
- - GPU/CPU: float16, float32, float64.
10442
-
10443
- - **grid** (Tensor) - A 4-D tensor whose dtype is the same as `input_x` and whose shape is
10444
- :math:`(N, H_{out}, W_{out}, 2)`.
10445
- Used to specify the sampling pixel locations normalized by the input spatial
10446
- dimensions.
10447
-
10448
- Outputs:
10449
- A 4-D Tensor whose dtype is the same as `input_x` and whose shape is :math:`(N, C, H_{out}, W_{out})`.
10450
-
10451
- Supported Platforms:
10452
- ``Ascend`` ``GPU`` ``CPU``
10453
-
10454
- Examples:
10455
- >>> import numpy as np
10456
- >>> from mindspore import Tensor, ops
10457
- >>> gridsampler = ops.GridSampler2D(interpolation_mode='bilinear', padding_mode='zeros', align_corners=True)
10458
- >>> input_x = Tensor(np.arange(16).reshape((2, 2, 2, 2)).astype(np.float32))
10459
- >>> grid = Tensor(np.arange(-9, 9, 0.5).reshape((2, 3, 3, 2)).astype(np.float32))
10460
- >>> output = gridsampler(input_x, grid)
10461
- >>> print(output)
10462
- [[[[ 0. 0. 0. ]
10463
- [ 0. 0. 0. ]
10464
- [ 0. 0. 0.5 ]]
10465
- [[ 0. 0. 0. ]
10466
- [ 0. 0. 0. ]
10467
- [ 0. 1.5 4.5 ]]]
10468
- [[[10. 8.25 1.375]
10469
- [ 0. 0. 0. ]
10470
- [ 0. 0. 0. ]]
10471
- [[14. 11.25 1.875]
10472
- [ 0. 0. 0. ]
10473
- [ 0. 0. 0. ]]]]
10474
- """
10475
-
10476
- @prim_attr_register
10477
- def __init__(self, interpolation_mode='bilinear', padding_mode='zeros', align_corners=False):
10478
- """Initialize GridSampler2D."""
10479
- validator.check_string(interpolation_mode, ['bilinear', 'nearest'], 'interpolation_mode', self.name)
10480
- validator.check_string(padding_mode, ['zeros', 'border', 'reflection'], 'padding_mode', self.name)
10481
- validator.check_bool(align_corners, 'align_corners', self.name)
10482
- self.init_prim_io_names(inputs=['input', 'grid'], outputs=['output'])
10483
- self.add_prim_attr('interpolation_mode', interpolation_mode)
10484
- self.add_prim_attr('padding_mode', padding_mode)
10485
- self.add_prim_attr('align_corners', align_corners)
10486
-
10487
-
10488
8771
  class Pdist(Primitive):
10489
8772
  r"""
10490
8773
  Computes the p-norm distance between each pair of row vectors in the input.
10491
8774
 
10492
8775
  Refer to :func:`mindspore.ops.pdist` for more details.
10493
8776
 
8777
+ Note:
8778
+ The pdist operator involves exponentiation, the inf/nan calculation result may be generated
8779
+ when the float16 input is used. The float32 input is recommended.
8780
+
10494
8781
  Args:
10495
8782
  p (float, optional): The order of norm distance, :math:`p∈[0, ∞)`. Default: ``2.0`` .
10496
8783
 
10497
8784
  Inputs:
10498
- - **x** (Tensor) - Input tensor of shape :math:`(*B, N, M)`. :math:`*B` is batch size,
10499
- one-dim or multi-dim. Supported dtypes: float16, float32 or float64.
8785
+ - **x** (Tensor) - Input tensor. Supported dtypes: float16, float32 or float64.
10500
8786
 
10501
8787
  Outputs:
10502
8788
  Tensor, has the same dtype as `x`.
@@ -10523,71 +8809,6 @@ class Pdist(Primitive):
10523
8809
  self.init_prim_io_names(inputs=['x'], outputs=['y'])
10524
8810
 
10525
8811
 
10526
- class UpsampleNearest3D(Primitive):
10527
- r"""
10528
- Performs nearest neighbor upsampling operation.
10529
-
10530
- This operator scale up the volumetric input with specified `output_size` or `scales` factors, using nearest
10531
- neighbor algorithm.
10532
-
10533
- One of `output_size` or `scales` must be given, and can not specified both at the same time.
10534
-
10535
- Inputs:
10536
- - **x** (Tensor) - 5D tensor of shape :math:`(N, C, D_{in}, H_{in}, W_{in})`.
10537
- Supporting types: [float16, float32, float64].
10538
- - **output_size** (Union[tuple[int], list[int]]): A tuple or list of int specifying the output volumetric size.
10539
- Default: ``None``.
10540
- - **scales** (Union[tuple[float], list[float]]): A tuple or list of float specifying the upsampling factors.
10541
- Default: ``None``.
10542
-
10543
- Outputs:
10544
- - **y** (Tensor) - Upsampled output with the same type as `x` , whose shape is
10545
- :math:`(N, C, D_{out}, H_{out}, W_{out})`.
10546
-
10547
- Raises:
10548
- TypeError: When `output_size` is not ``None`` and `output_size` is not list[int] or tuple[int].
10549
- TypeError: When `scales` is not ``None`` and `scales` is not list[float] or tuple[float].
10550
- TypeError: If dtype of `x` is not int [uint8, float16, float32, float64].
10551
- ValueError: If any value of `output_size` is negative or zero when `output_size` is not ``None``.
10552
- ValueError: If any value of `scales` is negative or zero when `scales` is not ``None``.
10553
- ValueError: If shape of `x` is not 5D.
10554
- ValueError: If none of `scales` and `output_size` is specified or both specified.
10555
- ValueError: If size of `scales` is not equal 3 when `scales` is specified.
10556
- ValueError: If size of `output_size` is not equal 3 when `output_size` is specified.
10557
-
10558
- Supported Platforms:
10559
- ``Ascend`` ``GPU`` ``CPU``
10560
-
10561
- Examples:
10562
- >>> import numpy as np
10563
- >>> from mindspore import Tensor, ops
10564
- >>> from mindspore import dtype as mstype
10565
- >>> x = Tensor(np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])
10566
- ... .reshape([1, 1, 2, 2, 4]), mstype.float32)
10567
- >>> output_size = [3, 4, 5]
10568
- >>> net = ops.UpsampleNearest3D()
10569
- >>> output = net(x, output_size, None)
10570
- >>> print(output)
10571
- [[[[[ 1. 1. 2. 3. 4.]
10572
- [ 1. 1. 2. 3. 4.]
10573
- [ 5. 5. 6. 7. 8.]
10574
- [ 5. 5. 6. 7. 8.]]
10575
- [[ 1. 1. 2. 3. 4.]
10576
- [ 1. 1. 2. 3. 4.]
10577
- [ 5. 5. 6. 7. 8.]
10578
- [ 5. 5. 6. 7. 8.]]
10579
- [[ 9. 9. 10. 11. 12.]
10580
- [ 9. 9. 10. 11. 12.]
10581
- [13. 13. 14. 15. 16.]
10582
- [13. 13. 14. 15. 16.]]]]]
10583
- """
10584
-
10585
- @prim_attr_register
10586
- def __init__(self):
10587
- """Initialize UpsampleNearest3D."""
10588
- self.init_prim_io_names(inputs=['x', 'output_size', 'scales'], outputs=['y'])
10589
-
10590
-
10591
8812
  class SparseApplyAdagradDA(Primitive):
10592
8813
  r"""
10593
8814
  Update `var` according to the proximal adagrad scheme.
@@ -11230,54 +9451,6 @@ class MaxPoolWithArgmaxV2(Primitive):
11230
9451
  self.add_prim_attr("ceil_mode", self.ceil_mode)
11231
9452
 
11232
9453
 
11233
- class Dense(Primitive):
11234
- r"""
11235
- The dense connected fusion operator.
11236
-
11237
- Applies dense connected operator for the input. The implement of the operation is as:
11238
-
11239
- .. math::
11240
- output = x @ w ^ T + b,
11241
-
11242
- where :math:`x` is the input tensor, :math:`w` is a weight matrix with the same data type as the :math:`x` ,
11243
- and :math:`b` is a bias vector with the same data type as the :math:`x` (only if `b` is not ``None``).
11244
-
11245
- Inputs:
11246
- - **x** (Tensor) - The shape must meet the following requirement: :math:`len(x.shape)>0`.
11247
- - **w** (Tensor) - The shape must meet the following requirements:
11248
- If :math:`len(x.shape)>1`, :math:`len(w.shape)=2`. If :math:`len(x.shape)=1`, :math:`len(w.shape)=1`.
11249
- :math:`w.shape[-1]=x.shape[-1]`.
11250
- - **b** (Union[Tensor, None]) - If `b` is not ``None``, the shape must meet the following requirements:
11251
- If :math:`len(x.shape)>1`, :math:`len(b.shape)=0` or :math:`len(b.shape)=1` .
11252
- If :math:`len(b.shape)=1`, :math:`b.shape[0]=w.shape[0]`.
11253
- If :math:`len(x.shape)=1`, :math:`len(b.shape)=0`.
11254
-
11255
- Outputs:
11256
- If :math:`len(x.shape)>1`, Tensor of shape :math:`(*x.shape[:-1], w.shape[0])`.
11257
- If :math:`len(x.shape)=1`, Tensor of shape :math:`()`.
11258
-
11259
- Supported Platforms:
11260
- ``Ascend`` ``GPU`` ``CPU``
11261
-
11262
- Examples:
11263
- >>> import numpy as np
11264
- >>> from mindspore import Tensor, ops
11265
- >>> x = Tensor(np.random.random((4, 5, 6, 7)).astype(np.float32))
11266
- >>> weight = Tensor(np.random.random((6, 7)).astype(np.float32))
11267
- >>> bias = Tensor(np.random.random((6,)).astype(np.float32))
11268
- >>> dense = ops.Dense()
11269
- >>> output = dense(x, weight, bias)
11270
- >>> print(output.shape)
11271
- (4, 5, 6, 6)
11272
- """
11273
-
11274
- @prim_attr_register
11275
- def __init__(self):
11276
- """Initialize Dense."""
11277
- self.init_prim_io_names(inputs=['x', 'w', 'b'], outputs=["output"])
11278
- self.add_prim_attr("has_bias", True)
11279
-
11280
-
11281
9454
  class WKV(Primitive):
11282
9455
  r"""
11283
9456
  The WKV computation is similar to AFT(Zhai et al., 2021), but W is now a channel-wise vector multiplied
@@ -11338,7 +9511,8 @@ class PromptFlashAttention(Primitive):
11338
9511
  S -- Sequence length
11339
9512
  H -- Hidden size
11340
9513
 
11341
- Refer to :func:mindspore.ops.prompt_flash_attention for more detail.
9514
+ Note:
9515
+ experiment ops
11342
9516
 
11343
9517
  .. warning::
11344
9518
  This is an experimental API that is subject to change or deletion.
@@ -11355,6 +9529,7 @@ class PromptFlashAttention(Primitive):
11355
9529
  num_key_value_heads (int): head numbers of key/value which are used in GQA algorithm.
11356
9530
  The value o indicates if the key and value have the same head nums, use numHeads. Default: 0.
11357
9531
  sparse_mode (int): Default: 0
9532
+ inner_precise (int): 0, float16 high precision. 1, high performance. default 1
11358
9533
 
11359
9534
  Inputs:
11360
9535
  - **query** (Tensor) - The query tensor with data type of float16 or float32.
@@ -11365,8 +9540,8 @@ class PromptFlashAttention(Primitive):
11365
9540
  Input tensor of shape :math:`(B, S, H)` / `(B, N, S, D)`.
11366
9541
  - **attn_mask** (Tensor) - The attention mask tensor with data type of float16 or float32.
11367
9542
  For each element, 0 indicates retention and 1 indicates discard. Input tensor of shape :math:`(B, 1, S, S)`.
11368
- - **actual_seq_lengths** (Tensor): Describe actual sequence length of each input with data type of int.
11369
- - **actual_seq_lengths_kv** (Tensor): Describe actual sequence length of each input with data type of int.
9543
+ - **actual_seq_lengths** (Tensor): Describe actual sequence length of each input with data type of int64.
9544
+ - **actual_seq_lengths_kv** (Tensor): Describe actual sequence length of each input with data type of int64.
11370
9545
  - **pse_shift** (Tensor) - The position encoding tensor with data type of float16 or float32.
11371
9546
  - **dep_scale1** (Tensor)
11372
9547
  - **quant_scale1** (Tensor)
@@ -11374,11 +9549,10 @@ class PromptFlashAttention(Primitive):
11374
9549
  - **quant_scale2** (Tensor)
11375
9550
  - **quant_offset2** (Tensor)
11376
9551
 
11377
-
11378
9552
  Outputs:
11379
9553
  - **attention_out** (Tensor) - Input tensor of shape :math:`(B, S, H)` / `(B, N, S, D)`.
11380
9554
 
11381
- Supported Platforms:
9555
+ Supported Platforms:
11382
9556
  ``Ascend``
11383
9557
 
11384
9558
  Examples:
@@ -11392,15 +9566,16 @@ class PromptFlashAttention(Primitive):
11392
9566
  >>> query = Tensor(np.ones((B, N, S, D), dtype=np.float16))
11393
9567
  >>> key = Tensor(np.ones((B, N, S, D), dtype=np.float16))
11394
9568
  >>> value = Tensor(np.ones((B, N, S, D), dtype=np.float16))
9569
+ >>> attn_mask = Tensor(np.ones((B, 1, S, S), dtype=np.float16))
11395
9570
  >>> pfa = P.PromptFlashAttention(N, input_layout='BNSD')
11396
- >>> out = pfa(query, key, value, None, None, None, None, None, None, None, None, None)
11397
- >>> print(out[0].shape)
9571
+ >>> out = pfa(query, key, value, attn_mask, None, None, None, None, None, None, None, None)
9572
+ >>> print(out.shape)
11398
9573
  (1, 16, 256, 16)
11399
9574
  """
11400
9575
 
11401
9576
  @prim_attr_register
11402
- def __init__(self, num_heads, scale_value=1.0, pre_tokens=2147483547, next_tokens=0, input_layout='BSH',
11403
- num_key_value_heads=0, sparse_mode=0):
9577
+ def __init__(self, num_heads, scale_value=1.0, pre_tokens=214748647, next_tokens=0, input_layout='BSH',
9578
+ num_key_value_heads=0, sparse_mode=0, inner_precise=1):
11404
9579
  """Initialize PromptFlashAttention."""
11405
9580
  validator.check_value_type('num_heads', num_heads, [int], self.name)
11406
9581
  validator.check_value_type('scale_value', scale_value, [float], self.name)
@@ -11409,175 +9584,86 @@ class PromptFlashAttention(Primitive):
11409
9584
  validator.check_value_type('input_layout', input_layout, [str], self.name)
11410
9585
  validator.check_value_type('num_key_value_heads', num_key_value_heads, [int], self.name)
11411
9586
  validator.check_value_type('sparse_mode', sparse_mode, [int], self.name)
9587
+ validator.check_value_type('inner_precise', inner_precise, [int], self.name)
11412
9588
  self.init_prim_io_names(inputs=["query", "key", "value", "attn_mask", "actual_seq_lengths",
11413
9589
  "actual_seq_lengths_kv", "pse_shift", "deq_scale1", "quant_scale1",
11414
9590
  "deq_scale2", "quant_scale2", "quant_offset2"],
11415
9591
  outputs=["attention_out"])
11416
9592
 
11417
9593
 
11418
- class FlashAttentionScore(Primitive):
9594
+ class IncreFlashAttention(Primitive):
11419
9595
  r"""
11420
- FlashAttentionScore.
11421
- .. warning::
11422
- This is an experimental API that is subject to change or deletion.
11423
- B -- Batch size
11424
- S1 -- Sequence length of query
11425
- S2 -- Sequence length of key and value
11426
- N1 -- Num heads of query
11427
- N2 -- Num heads of key and value, and N2 must be a factor of N1
11428
- D -- head size
11429
- H1 -- Hidden size of query, which equals to N1 * D
11430
- H2 -- Hidden size of key and value, which equals to N2 * D
11431
- Args:
11432
- head_num (int): The head num of query.
11433
- keep_prob (float): The keep probability of dropout. Default: 1.0.
11434
- scale_value (float): The scale value. Default: 1.0.
11435
- pre_tokens (int): Previous tokens. Default: 65536.
11436
- next_tokens (int): Next tokens. Default: 65536.
11437
- inner_precise (int): Specify the execution mode, where 0 indicates high precision mode and 1 indicates high
11438
- performance mode. Only support 0 currently. Default: 0.
11439
- input_layout (str, optional): Specifies the layout of `query`, the value must be one of ["BSH", "BNSD"].
11440
- Default: "BSH".
11441
- sparse_mode (int): Default 0.
11442
-
11443
- Inputs:
11444
- - **query** (Tensor[float16, float32, bfloat16]) - The query tensor.
11445
- Input tensor of shape :math:`(B, S1, H1)` or `(B, N1, S1, D)`.
11446
- - **key** (Tensor[float16, float32, bfloat16]) - The key tensor.
11447
- Input tensor of shape :math:`(B, S2, H2)` or `(B, N2, S2, D)`.
11448
- - **value** (Tensor[float16, float32, bfloat16]) - The value tensor.
11449
- Input tensor of shape :math:`(B, S2, H2)` or `(B, N2, S2, D)`.
11450
- - **real_shift** (Tensor[float16, float32, bfloat16], None) - The position embedding code.
11451
- Input tensor of shape :math: `(B, N1, S1, S2)` or `(B, N1, 1, S2)`.
11452
- - **drop_mask** (Tensor[uint8], None) - The dropout mask tensor.
11453
- Input tensor of shape :math:`(B, N1, S1, S2 // 8) or None`.
11454
- - **padding_mask** (None) - The padding mask of float16 or float32, not implemented yet.
11455
- - **attn_mask** (Tensor[uint8], None) - The attention mask tensor.
11456
- For each element, 0 indicates retention and 1 indicates discard.
11457
- Input tensor of shape :math:`(B, N1, S1, S2)`, `(B, 1, S1, S2)` or `(S1, S2)`.
11458
- - **prefix** (Tensor[int64], None) - Not implemented yet.
11459
- Input tensor of shape :math:`(B,)`.
11460
-
11461
- Outputs:
11462
- - **softmax_max** (Tensor[float32]) - (B, N1, S1, 8)
11463
- - **softmax_sum** (Tensor[float32]) - (B, N1, S1, 8)
11464
- - **softmax_out** (Tensor[float32]) - Useless output, ignore it. Output tensor of shape : `()`
11465
- - **attention_out** (Tensor[float16, float32, bfloat16]) - The output of attention, its shape, and data type
11466
- are the same as the query.
11467
-
11468
- Supported Platforms:
11469
- ``Ascend``
11470
- """
11471
-
11472
- @prim_attr_register
11473
- def __init__(self, head_num, keep_prob=1.0, scale_value=1.0, pre_tokens=65536, next_tokens=65536, inner_precise=0,
11474
- input_layout="BSH", sparse_mode=0):
11475
- """Initialize FlashAttentionScore"""
11476
- validator.check_value_type('head_num', head_num, [int], self.name)
11477
- validator.check_value_type('keep_prob', keep_prob, [int, float], self.name)
11478
- validator.check_float(keep_prob, 0.0, validator.GE, "keep_prob", self.name)
11479
- validator.check_float(keep_prob, 1.0, validator.LE, "keep_prob", self.name)
11480
- validator.check_value_type('scale_value', scale_value, [float], self.name)
11481
- validator.check_value_type('pre_tokens', pre_tokens, [int], self.name)
11482
- validator.check_value_type('next_tokens', next_tokens, [int], self.name)
11483
- validator.check_value_type('inner_precise', inner_precise, [int], self.name)
11484
- validator.check_value_type('sparse_mode', sparse_mode, [int], self.name)
11485
- if inner_precise not in [0]:
11486
- raise ValueError(f"Attribute 'inner_precise' must be 0, but got {inner_precise}")
11487
- validator.check_value_type('input_layout', input_layout, [str], self.name)
11488
- if input_layout not in ["BSH", "BNSD"]:
11489
- raise ValueError(f"Attribute 'input_layout' must be either 'BSH' or 'BNSD', but got {input_layout}")
11490
- self.init_prim_io_names(
11491
- inputs=['query', 'key', 'value', 'real_shift', 'drop_mask', 'padding_mask', 'attn_mask', 'prefix'],
11492
- outputs=['softmax_max', 'softmax_sum', 'softmax_out', 'attention_out'])
9596
+ The interface for fully inference.
11493
9597
 
9598
+ B -- Batch size
11494
9599
 
11495
- class RmsNorm(Primitive):
11496
- r"""
11497
- The RmsNorm operator is a normalization operation, and its formula is:
9600
+ S -- Sequence length
11498
9601
 
11499
- .. math::
11500
- y=\frac{x_i}{\sqrt{\frac{1}{n}}\sum_{i=1}^{n}{ x_i^2}+\varepsilon }\gamma_i
9602
+ H -- Hidden size
11501
9603
 
11502
9604
  .. warning::
11503
9605
  This is an experimental API that is subject to change or deletion.
9606
+ If there is no input parameter and no default value, None needs to be passed.
11504
9607
 
11505
9608
  Args:
11506
- epsilon (float): prevent division by 0, default value is `1e-6`
11507
-
11508
- Inputs:
11509
- - **input_x** (Tensor) - Input data of RmsNorm, support data type: float16, float32, bfloat16.
11510
- - **gamma** (Tensor) - Support data type: float16, float32, bfloat16.
9609
+ - **num_heads** (int) - The number of heads.
9610
+ - **input_layout** (str) - the data layout of the input qkv, support `(BSH)` and `(BNSD)`. Default `BSH`.
9611
+ - **scale_value** (double) - The scale value indicating the scale coefficient, which is used as the scalar of
9612
+ Muls in the calculation. Default: 1.0.
9613
+ - **num_key_value_heads** (int) - head numbers of key/value which are used in GQA algorithm.
9614
+ The value o indicates if the key and value have the same head nums, use numHeads. Default: 0.
9615
+ - **block_size** (int) - Default: 0.
9616
+ - **inner_precise** (int) - Default: 1.
9617
+
9618
+ Inputs:
9619
+ - **query** (Tensor) - The query tensor with data type of float16 or bfloat16.
9620
+ Input tensor of shape :math:`(B, 1, H)` / :math:`(B, N, 1, D)`.
9621
+ - **key** (TensorList) - The key tensor with data type of float16 or bfloat16.
9622
+ Input tensor of shape :math:`(B, S, H)` / :math:`(B, N, S, D)`.
9623
+ - **value** (TensorList) - The value tensor with data type of float16 or bfloat16.
9624
+ Input tensor of shape :math:`(B, S, H)` / :math:`(B, N, S, D)`.
9625
+ - **attn_mask** (Tensor) - The attention mask tensor with data type of float16 or bool.
9626
+ Input tensor of shape :math:`(B, S)` / :math:`(B, 1, S)` / :math:`(B, 1, 1, S)`.
9627
+ - **actual_seq_lengths** (Tensor) - Describe actual sequence length of each input with data type of int.
9628
+ - **pse_shift** (Tensor) - The position encoding tensor with data type of float16 or float32.
9629
+ - **dequant_scale1** (Tensor) - Quantitative parametor, the tensor with data type of uint64.
9630
+ - **quant_scale1** (Tensor) - Quantitative parametor, the tensor with data type of float.
9631
+ - **dequant_scale2** (Tensor) - Quantitative parametor, the tensor with data type of uint64.
9632
+ - **quant_scale2** (Tensor) - Quantitative parametor, the tensor with data type of float.
9633
+ - **quant_offset2** (Tensor) - Quantitative parametor, the tensor with data type of float.
9634
+ - **antiquant_scale** (Tensor) - Quantitative parametor, the tensor with data type of float.
9635
+ - **antiquant_offset** (Tensor) - Quantitative parametor, the tensor with data type of float.
9636
+ - **block_table** (Tensor) - The tensor with data type of float.
11511
9637
 
11512
9638
  Outputs:
11513
- - **y** (Tensor) - Has the same type and shape with `input_x`.
11514
- - **rstd** (Tensor) - Has the same type with `input_x`, used by gradient calculation.
11515
-
11516
- Raises:
11517
- TypeError: If data type of `input_x` is not one of the following: float16, float32, bfloat16.
11518
- TypeError: If data type of `gamma` is not one of the following: float16, float32, bfloat16.
11519
- TypeError: If data type of "input_x" is not the same with the data type of "gamma"
9639
+ - **attention_out** (Tensor) - Input tensor of shape :math:`(B, 1, H)` / :math:`(B, N, 1, D)`.
11520
9640
 
11521
9641
  Supported Platforms:
11522
9642
  ``Ascend``
11523
9643
  """
11524
9644
 
11525
9645
  @prim_attr_register
11526
- def __init__(self, epsilon=1e-6):
11527
- """Initialize Dense."""
11528
- validator.check_value_type("epsilon", epsilon, [float], self.name)
11529
- self.init_prim_io_names(inputs=['x', 'gamma'], outputs=["y", "rstd"])
11530
-
11531
-
11532
- class PagedAttention(Primitive):
11533
- r"""
11534
- .. warning::
11535
- This is an experimental API that is subject to change or deletion.
11536
- """
11537
- @prim_attr_register
11538
- def __init__(self, head_num, scale_value=1.0, kv_head_num=0):
11539
- """Initialize PagedAttention"""
11540
- validator.check_value_type('head_num', head_num, [int], self.name)
11541
- validator.check_value_type('scale_value', scale_value, [float], self.name) # scale after qkbmm
11542
- validator.check_value_type('kv_head_num', kv_head_num, [int], self.name) # for MQA
11543
- self.init_prim_io_names(
11544
- inputs=['query', 'key_cache', 'value_cache', 'block_tables', 'context_lens'],
11545
- outputs=['attention_out'])
11546
-
11547
-
11548
- class PagedAttentionMask(Primitive):
11549
- r"""
11550
- .. warning::
11551
- This is an experimental API that is subject to change or deletion.
11552
- """
11553
- @prim_attr_register
11554
- def __init__(self, head_num, scale_value=1.0, kv_head_num=0):
11555
- """Initialize PagedAttentionMask"""
11556
- validator.check_value_type('head_num', head_num, [int], self.name)
11557
- validator.check_value_type('scale_value', scale_value, [float], self.name) # scale after qkbmm
11558
- validator.check_value_type('kv_head_num', kv_head_num, [int], self.name) # for MQA
11559
- self.init_prim_io_names(
11560
- inputs=['query', 'key_cache', 'value_cache', 'block_tables', 'context_lens', 'alibi_mask'],
11561
- outputs=['attention_out'])
9646
+ def __init__(self, num_heads, input_layout="BSH", scale_value=1.0, num_key_value_heads=0, block_size=0,
9647
+ inner_precise=1):
9648
+ """Initialize IncreFlashAttention."""
9649
+ validator.check_value_type('num_heads', num_heads, [int], self.name)
9650
+ validator.check_value_type('input_layout', input_layout, [str], self.name)
9651
+ validator.check_value_type('scale_value', scale_value, [float], self.name)
9652
+ validator.check_value_type('num_key_value_heads', num_key_value_heads, [int], self.name)
9653
+ validator.check_value_type('block_size', block_size, [int], self.name)
9654
+ validator.check_value_type('inner_precise', inner_precise, [int], self.name)
9655
+ self.init_prim_io_names(inputs=["query", "key", "value", "attn_mask", "actual_seq_lengths", "pse_shift",
9656
+ "dequant_scale1", "quant_scale1", "dequant_scale2", "quant_scale2",
9657
+ "quant_offset2", "antiquant_scale", "antiquant_offset", "block_table"],
9658
+ outputs=["attention_out"])
11562
9659
 
11563
9660
 
11564
- class ReshapeAndCache(Primitive):
9661
+ class AllFinite(Primitive):
11565
9662
  r"""
11566
- .. warning::
11567
- This is an experimental API that is subject to change or deletion.
9663
+ Check all gradients is finite.
11568
9664
  """
11569
- __mindspore_signature__ = (
11570
- sig.make_sig('key', dtype=sig.sig_dtype.T),
11571
- sig.make_sig('value', dtype=sig.sig_dtype.T),
11572
- sig.make_sig('key_cache', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T),
11573
- sig.make_sig('value_cache', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T),
11574
- sig.make_sig('slot_mapping', dtype=sig.sig_dtype.T1),
11575
- )
11576
-
11577
9665
  @prim_attr_register
11578
9666
  def __init__(self):
11579
- """Initialize ReshapeAndCache"""
11580
- self.init_prim_io_names(
11581
- inputs=['key', 'value', 'key_cache', 'value_cache', 'slot_mapping'],
11582
- outputs=['key_out'])
11583
- self.add_prim_attr('side_effect_mem', True)
9667
+ """Initialize"""
9668
+ self.init_prim_io_names(inputs=['gradients'],
9669
+ outputs=["is_finite"])