mindspore 2.3.0__cp310-cp310-win_amd64.whl → 2.4.0__cp310-cp310-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 (308) 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 +3 -1
  5. mindspore/_c_dataengine.cp310-win_amd64.pyd +0 -0
  6. mindspore/_c_expression.cp310-win_amd64.pyd +0 -0
  7. mindspore/_c_mindrecord.cp310-win_amd64.pyd +0 -0
  8. mindspore/_checkparam.py +50 -9
  9. mindspore/_extends/parse/compile_config.py +41 -0
  10. mindspore/_extends/parse/parser.py +9 -7
  11. mindspore/_extends/parse/standard_method.py +52 -14
  12. mindspore/_extends/pijit/pijit_func_white_list.py +350 -24
  13. mindspore/amp.py +24 -10
  14. mindspore/atlprov.dll +0 -0
  15. mindspore/avcodec-59.dll +0 -0
  16. mindspore/avdevice-59.dll +0 -0
  17. mindspore/avfilter-8.dll +0 -0
  18. mindspore/avformat-59.dll +0 -0
  19. mindspore/avutil-57.dll +0 -0
  20. mindspore/c1.dll +0 -0
  21. mindspore/c1xx.dll +0 -0
  22. mindspore/c2.dll +0 -0
  23. mindspore/common/__init__.py +6 -4
  24. mindspore/common/_pijit_context.py +190 -0
  25. mindspore/common/_register_for_tensor.py +2 -1
  26. mindspore/common/_tensor_overload.py +139 -0
  27. mindspore/common/api.py +102 -87
  28. mindspore/common/dump.py +5 -6
  29. mindspore/common/generator.py +1 -7
  30. mindspore/common/hook_handle.py +14 -26
  31. mindspore/common/mindir_util.py +2 -2
  32. mindspore/common/parameter.py +46 -13
  33. mindspore/common/recompute.py +39 -9
  34. mindspore/common/sparse_tensor.py +7 -3
  35. mindspore/common/tensor.py +209 -29
  36. mindspore/communication/__init__.py +1 -1
  37. mindspore/communication/_comm_helper.py +38 -3
  38. mindspore/communication/comm_func.py +310 -55
  39. mindspore/communication/management.py +14 -14
  40. mindspore/context.py +123 -22
  41. mindspore/dataset/__init__.py +1 -1
  42. mindspore/dataset/audio/__init__.py +1 -1
  43. mindspore/dataset/core/config.py +7 -0
  44. mindspore/dataset/core/validator_helpers.py +7 -0
  45. mindspore/dataset/engine/cache_client.py +1 -1
  46. mindspore/dataset/engine/datasets.py +72 -44
  47. mindspore/dataset/engine/datasets_audio.py +7 -7
  48. mindspore/dataset/engine/datasets_standard_format.py +53 -3
  49. mindspore/dataset/engine/datasets_text.py +20 -20
  50. mindspore/dataset/engine/datasets_user_defined.py +174 -104
  51. mindspore/dataset/engine/datasets_vision.py +33 -33
  52. mindspore/dataset/engine/iterators.py +29 -0
  53. mindspore/dataset/engine/obs/util.py +7 -0
  54. mindspore/dataset/engine/queue.py +114 -60
  55. mindspore/dataset/engine/serializer_deserializer.py +2 -2
  56. mindspore/dataset/engine/validators.py +34 -14
  57. mindspore/dataset/text/__init__.py +1 -4
  58. mindspore/dataset/transforms/__init__.py +0 -3
  59. mindspore/dataset/utils/line_reader.py +2 -0
  60. mindspore/dataset/vision/__init__.py +1 -4
  61. mindspore/dataset/vision/utils.py +1 -1
  62. mindspore/dataset/vision/validators.py +2 -1
  63. mindspore/dnnl.dll +0 -0
  64. mindspore/dpcmi.dll +0 -0
  65. mindspore/{nn/extend → experimental/es}/__init__.py +4 -11
  66. mindspore/experimental/es/embedding_service.py +883 -0
  67. mindspore/{nn/layer → experimental/es}/embedding_service_layer.py +218 -30
  68. mindspore/experimental/llm_boost/__init__.py +21 -0
  69. mindspore/{nn/extend/layer → experimental/llm_boost/atb}/__init__.py +4 -8
  70. mindspore/experimental/llm_boost/atb/boost_base.py +211 -0
  71. mindspore/experimental/llm_boost/atb/llama_boost.py +115 -0
  72. mindspore/experimental/llm_boost/atb/qwen_boost.py +101 -0
  73. mindspore/experimental/llm_boost/register.py +129 -0
  74. mindspore/experimental/llm_boost/utils.py +31 -0
  75. mindspore/experimental/optim/adamw.py +85 -0
  76. mindspore/experimental/optim/optimizer.py +3 -0
  77. mindspore/hal/__init__.py +3 -3
  78. mindspore/hal/contiguous_tensors_handle.py +175 -0
  79. mindspore/hal/stream.py +18 -0
  80. mindspore/include/api/model_group.h +13 -1
  81. mindspore/include/api/types.h +10 -10
  82. mindspore/include/dataset/config.h +2 -2
  83. mindspore/include/dataset/constants.h +2 -2
  84. mindspore/include/dataset/execute.h +2 -2
  85. mindspore/include/dataset/vision.h +4 -0
  86. mindspore/jpeg62.dll +0 -0
  87. mindspore/log.py +1 -1
  88. mindspore/mindrecord/filewriter.py +68 -51
  89. mindspore/mindspore_backend.dll +0 -0
  90. mindspore/mindspore_common.dll +0 -0
  91. mindspore/mindspore_core.dll +0 -0
  92. mindspore/mindspore_glog.dll +0 -0
  93. mindspore/mindspore_np_dtype.dll +0 -0
  94. mindspore/mindspore_ops.dll +0 -0
  95. mindspore/mint/__init__.py +495 -46
  96. mindspore/mint/distributed/__init__.py +31 -0
  97. mindspore/mint/distributed/distributed.py +254 -0
  98. mindspore/mint/nn/__init__.py +266 -21
  99. mindspore/mint/nn/functional.py +125 -19
  100. mindspore/mint/nn/layer/__init__.py +39 -0
  101. mindspore/mint/nn/layer/activation.py +133 -0
  102. mindspore/mint/nn/layer/normalization.py +477 -0
  103. mindspore/mint/nn/layer/pooling.py +110 -0
  104. mindspore/mint/optim/adamw.py +28 -7
  105. mindspore/mint/special/__init__.py +63 -0
  106. mindspore/msobj140.dll +0 -0
  107. mindspore/mspdb140.dll +0 -0
  108. mindspore/mspdbcore.dll +0 -0
  109. mindspore/mspdbst.dll +0 -0
  110. mindspore/mspft140.dll +0 -0
  111. mindspore/msvcdis140.dll +0 -0
  112. mindspore/msvcp140_1.dll +0 -0
  113. mindspore/msvcp140_2.dll +0 -0
  114. mindspore/msvcp140_atomic_wait.dll +0 -0
  115. mindspore/msvcp140_codecvt_ids.dll +0 -0
  116. mindspore/multiprocessing/__init__.py +2 -1
  117. mindspore/nn/__init__.py +0 -1
  118. mindspore/nn/cell.py +275 -93
  119. mindspore/nn/layer/activation.py +211 -44
  120. mindspore/nn/layer/basic.py +113 -3
  121. mindspore/nn/layer/embedding.py +120 -2
  122. mindspore/nn/layer/normalization.py +101 -5
  123. mindspore/nn/layer/padding.py +34 -48
  124. mindspore/nn/layer/pooling.py +161 -7
  125. mindspore/nn/layer/transformer.py +3 -3
  126. mindspore/nn/loss/__init__.py +2 -2
  127. mindspore/nn/loss/loss.py +84 -6
  128. mindspore/nn/optim/__init__.py +2 -1
  129. mindspore/nn/optim/adadelta.py +1 -1
  130. mindspore/nn/optim/adam.py +1 -1
  131. mindspore/nn/optim/lamb.py +1 -1
  132. mindspore/nn/optim/tft_wrapper.py +127 -0
  133. mindspore/nn/wrap/cell_wrapper.py +12 -23
  134. mindspore/nn/wrap/grad_reducer.py +5 -5
  135. mindspore/nn/wrap/loss_scale.py +17 -3
  136. mindspore/numpy/__init__.py +1 -1
  137. mindspore/numpy/array_creations.py +65 -68
  138. mindspore/numpy/array_ops.py +64 -60
  139. mindspore/numpy/fft.py +610 -75
  140. mindspore/numpy/logic_ops.py +11 -10
  141. mindspore/numpy/math_ops.py +85 -84
  142. mindspore/numpy/utils_const.py +4 -4
  143. mindspore/opencv_core452.dll +0 -0
  144. mindspore/opencv_imgcodecs452.dll +0 -0
  145. mindspore/opencv_imgproc452.dll +0 -0
  146. mindspore/ops/__init__.py +6 -4
  147. mindspore/ops/_grad_experimental/grad_comm_ops.py +47 -3
  148. mindspore/ops/_grad_experimental/grad_math_ops.py +0 -22
  149. mindspore/ops/_vmap/vmap_array_ops.py +2 -4
  150. mindspore/ops/_vmap/vmap_math_ops.py +17 -1
  151. mindspore/ops/_vmap/vmap_nn_ops.py +43 -2
  152. mindspore/ops/auto_generate/cpp_create_prim_instance_helper.py +85 -7
  153. mindspore/ops/auto_generate/gen_arg_dtype_cast.py +2 -0
  154. mindspore/ops/auto_generate/gen_extend_func.py +734 -13
  155. mindspore/ops/auto_generate/gen_ops_def.py +2420 -381
  156. mindspore/ops/auto_generate/gen_ops_prim.py +5196 -1659
  157. mindspore/ops/auto_generate/pyboost_inner_prim.py +176 -56
  158. mindspore/ops/composite/base.py +85 -48
  159. mindspore/ops/composite/multitype_ops/_compile_utils.py +1 -0
  160. mindspore/ops/composite/multitype_ops/not_in_impl.py +2 -2
  161. mindspore/ops/function/__init__.py +22 -0
  162. mindspore/ops/function/array_func.py +490 -153
  163. mindspore/ops/function/debug_func.py +113 -1
  164. mindspore/ops/function/fft_func.py +15 -2
  165. mindspore/ops/function/grad/grad_func.py +3 -2
  166. mindspore/ops/function/math_func.py +558 -207
  167. mindspore/ops/function/nn_func.py +817 -383
  168. mindspore/ops/function/other_func.py +3 -2
  169. mindspore/ops/function/random_func.py +184 -8
  170. mindspore/ops/function/reshard_func.py +13 -11
  171. mindspore/ops/function/sparse_unary_func.py +1 -1
  172. mindspore/ops/function/vmap_func.py +3 -2
  173. mindspore/ops/functional.py +24 -14
  174. mindspore/ops/op_info_register.py +3 -3
  175. mindspore/ops/operations/__init__.py +6 -1
  176. mindspore/ops/operations/_grad_ops.py +2 -76
  177. mindspore/ops/operations/_infer_ops.py +1 -1
  178. mindspore/ops/operations/_inner_ops.py +71 -94
  179. mindspore/ops/operations/array_ops.py +12 -146
  180. mindspore/ops/operations/comm_ops.py +42 -53
  181. mindspore/ops/operations/custom_ops.py +83 -19
  182. mindspore/ops/operations/debug_ops.py +42 -10
  183. mindspore/ops/operations/manually_defined/_inner.py +12 -0
  184. mindspore/ops/operations/manually_defined/ops_def.py +265 -10
  185. mindspore/ops/operations/math_ops.py +12 -223
  186. mindspore/ops/operations/nn_ops.py +20 -114
  187. mindspore/ops/operations/other_ops.py +7 -4
  188. mindspore/ops/operations/random_ops.py +46 -1
  189. mindspore/ops/primitive.py +18 -6
  190. mindspore/ops_generate/arg_dtype_cast.py +2 -0
  191. mindspore/ops_generate/gen_aclnn_implement.py +11 -11
  192. mindspore/ops_generate/gen_constants.py +36 -0
  193. mindspore/ops_generate/gen_ops.py +67 -52
  194. mindspore/ops_generate/gen_ops_inner_prim.py +1 -1
  195. mindspore/ops_generate/gen_pyboost_func.py +131 -47
  196. mindspore/ops_generate/op_proto.py +10 -3
  197. mindspore/ops_generate/pyboost_utils.py +14 -1
  198. mindspore/ops_generate/template.py +43 -21
  199. mindspore/parallel/__init__.py +3 -1
  200. mindspore/parallel/_auto_parallel_context.py +28 -8
  201. mindspore/parallel/_cell_wrapper.py +83 -0
  202. mindspore/parallel/_parallel_serialization.py +47 -19
  203. mindspore/parallel/_tensor.py +81 -11
  204. mindspore/parallel/_utils.py +13 -1
  205. mindspore/parallel/algo_parameter_config.py +5 -5
  206. mindspore/parallel/checkpoint_transform.py +46 -39
  207. mindspore/parallel/cluster/process_entity/__init__.py +1 -1
  208. mindspore/parallel/cluster/process_entity/_api.py +31 -23
  209. mindspore/parallel/cluster/process_entity/_utils.py +2 -27
  210. mindspore/parallel/parameter_broadcast.py +3 -4
  211. mindspore/parallel/shard.py +162 -31
  212. mindspore/parallel/transform_safetensors.py +993 -0
  213. mindspore/pgodb140.dll +0 -0
  214. mindspore/pgort140.dll +0 -0
  215. mindspore/profiler/__init__.py +2 -1
  216. mindspore/profiler/common/constant.py +29 -0
  217. mindspore/profiler/common/registry.py +47 -0
  218. mindspore/profiler/common/util.py +28 -0
  219. mindspore/profiler/dynamic_profiler.py +694 -0
  220. mindspore/profiler/envprofiling.py +17 -19
  221. mindspore/profiler/parser/ascend_analysis/constant.py +18 -0
  222. mindspore/profiler/parser/ascend_analysis/file_manager.py +25 -4
  223. mindspore/profiler/parser/ascend_analysis/function_event.py +43 -19
  224. mindspore/profiler/parser/ascend_analysis/fwk_cann_parser.py +31 -26
  225. mindspore/profiler/parser/ascend_analysis/fwk_file_parser.py +56 -10
  226. mindspore/profiler/parser/ascend_analysis/msprof_timeline_parser.py +55 -8
  227. mindspore/profiler/parser/ascend_analysis/path_manager.py +313 -0
  228. mindspore/profiler/parser/ascend_analysis/profiler_info_parser.py +27 -20
  229. mindspore/profiler/parser/ascend_analysis/trace_event_manager.py +9 -2
  230. mindspore/profiler/parser/ascend_msprof_exporter.py +5 -4
  231. mindspore/profiler/parser/ascend_timeline_generator.py +27 -25
  232. mindspore/profiler/parser/base_timeline_generator.py +19 -25
  233. mindspore/profiler/parser/cpu_gpu_timeline_generator.py +25 -12
  234. mindspore/profiler/parser/framework_parser.py +1 -391
  235. mindspore/profiler/parser/gpu_analysis/__init__.py +14 -0
  236. mindspore/profiler/parser/gpu_analysis/function_event.py +44 -0
  237. mindspore/profiler/parser/gpu_analysis/fwk_file_parser.py +89 -0
  238. mindspore/profiler/parser/gpu_analysis/profiler_info_parser.py +72 -0
  239. mindspore/profiler/parser/memory_usage_parser.py +0 -154
  240. mindspore/profiler/parser/profiler_info.py +78 -6
  241. mindspore/profiler/profiler.py +153 -0
  242. mindspore/profiler/profiling.py +280 -412
  243. mindspore/rewrite/__init__.py +1 -2
  244. mindspore/rewrite/common/namespace.py +4 -4
  245. mindspore/rewrite/symbol_tree/symbol_tree.py +3 -3
  246. mindspore/run_check/_check_version.py +36 -103
  247. mindspore/safeguard/rewrite_obfuscation.py +591 -247
  248. mindspore/swresample-4.dll +0 -0
  249. mindspore/swscale-6.dll +0 -0
  250. mindspore/tbbmalloc.dll +0 -0
  251. mindspore/tinyxml2.dll +0 -0
  252. mindspore/train/__init__.py +4 -3
  253. mindspore/train/_utils.py +28 -2
  254. mindspore/train/amp.py +171 -53
  255. mindspore/train/callback/__init__.py +2 -2
  256. mindspore/train/callback/_callback.py +4 -4
  257. mindspore/train/callback/_checkpoint.py +85 -22
  258. mindspore/train/callback/_cluster_monitor.py +1 -1
  259. mindspore/train/callback/_flops_collector.py +1 -0
  260. mindspore/train/callback/_loss_monitor.py +3 -3
  261. mindspore/train/callback/_on_request_exit.py +134 -31
  262. mindspore/train/callback/_summary_collector.py +5 -5
  263. mindspore/train/callback/_tft_register.py +352 -0
  264. mindspore/train/dataset_helper.py +7 -3
  265. mindspore/train/metrics/metric.py +3 -3
  266. mindspore/train/metrics/roc.py +4 -4
  267. mindspore/train/mind_ir_pb2.py +44 -39
  268. mindspore/train/model.py +134 -58
  269. mindspore/train/serialization.py +336 -112
  270. mindspore/turbojpeg.dll +0 -0
  271. mindspore/utils/__init__.py +21 -0
  272. mindspore/utils/utils.py +60 -0
  273. mindspore/vcmeta.dll +0 -0
  274. mindspore/vcruntime140.dll +0 -0
  275. mindspore/vcruntime140_1.dll +0 -0
  276. mindspore/version.py +1 -1
  277. {mindspore-2.3.0.dist-info → mindspore-2.4.0.dist-info}/METADATA +6 -2
  278. {mindspore-2.3.0.dist-info → mindspore-2.4.0.dist-info}/RECORD +281 -275
  279. mindspore/include/c_api/ms/abstract.h +0 -67
  280. mindspore/include/c_api/ms/attribute.h +0 -197
  281. mindspore/include/c_api/ms/base/handle_types.h +0 -43
  282. mindspore/include/c_api/ms/base/macros.h +0 -32
  283. mindspore/include/c_api/ms/base/status.h +0 -33
  284. mindspore/include/c_api/ms/base/types.h +0 -283
  285. mindspore/include/c_api/ms/context.h +0 -102
  286. mindspore/include/c_api/ms/graph.h +0 -160
  287. mindspore/include/c_api/ms/node.h +0 -606
  288. mindspore/include/c_api/ms/tensor.h +0 -161
  289. mindspore/include/c_api/ms/value.h +0 -84
  290. mindspore/mindspore_shared_lib.dll +0 -0
  291. mindspore/nn/extend/basic.py +0 -140
  292. mindspore/nn/extend/embedding.py +0 -143
  293. mindspore/nn/extend/layer/normalization.py +0 -109
  294. mindspore/nn/extend/pooling.py +0 -117
  295. mindspore/nn/layer/embedding_service.py +0 -531
  296. mindspore/ops/_op_impl/aicpu/strided_slice_v2.py +0 -93
  297. mindspore/ops/_op_impl/aicpu/strided_slice_v2_grad.py +0 -66
  298. mindspore/ops/extend/__init__.py +0 -53
  299. mindspore/ops/extend/array_func.py +0 -218
  300. mindspore/ops/extend/math_func.py +0 -76
  301. mindspore/ops/extend/nn_func.py +0 -308
  302. mindspore/ops/silent_check.py +0 -162
  303. mindspore/profiler/parser/msadvisor_analyzer.py +0 -82
  304. mindspore/profiler/parser/msadvisor_parser.py +0 -240
  305. mindspore/train/callback/_mindio_ttp.py +0 -443
  306. {mindspore-2.3.0.dist-info → mindspore-2.4.0.dist-info}/WHEEL +0 -0
  307. {mindspore-2.3.0.dist-info → mindspore-2.4.0.dist-info}/entry_points.txt +0 -0
  308. {mindspore-2.3.0.dist-info → mindspore-2.4.0.dist-info}/top_level.txt +0 -0
@@ -33,6 +33,7 @@ __all__ = ['Softmin',
33
33
  'Softmax',
34
34
  'Softmax2d',
35
35
  'LogSoftmax',
36
+ 'LogSoftmaxExt',
36
37
  'ReLU',
37
38
  'ReLU6',
38
39
  'RReLU',
@@ -46,6 +47,7 @@ __all__ = ['Softmin',
46
47
  'Sigmoid',
47
48
  'Softsign',
48
49
  'PReLU',
50
+ 'PReLUExt',
49
51
  'get_activation',
50
52
  'LeakyReLU',
51
53
  'HSigmoid',
@@ -279,6 +281,35 @@ class Softmax(Cell):
279
281
  return self.softmax(input)
280
282
 
281
283
 
284
+ class SoftmaxExt(Cell):
285
+ r"""
286
+ Applies the Softmax function to an n-dimensional input Tensor.
287
+
288
+ For details, please refer to :func:`mindspore.mint.nn.functional.softmax`.
289
+
290
+ Supported Platforms:
291
+ ``Ascend``
292
+
293
+ Examples:
294
+ >>> import mindspore
295
+ >>> from mindspore import Tensor, nn
296
+ >>> import numpy as np
297
+ >>> input = Tensor(np.array([-1, -2, 0, 2, 1]), mindspore.float16)
298
+ >>> softmax = nn.SoftmaxExt()
299
+ >>> output = softmax(input)
300
+ >>> print(output)
301
+ [0.03168 0.01166 0.0861 0.636 0.2341 ]
302
+ """
303
+
304
+ def __init__(self, dim=None):
305
+ """Initialize Softmax."""
306
+ super(SoftmaxExt, self).__init__()
307
+ self.dim = dim
308
+
309
+ def construct(self, input):
310
+ return ops.function.nn_func.softmax_ext(input, self.dim)
311
+
312
+
282
313
  class LogSoftmax(Cell):
283
314
  r"""
284
315
  Applies the LogSoftmax function to n-dimensional input tensor element-wise.
@@ -329,6 +360,51 @@ class LogSoftmax(Cell):
329
360
  return self.log_softmax(x)
330
361
 
331
362
 
363
+ class LogSoftmaxExt(Cell):
364
+ r"""
365
+ Applies the Log Softmax function to the input tensor on the specified axis.
366
+ Supposes a slice in the given axis, :math:`x` for each element :math:`x_i`,
367
+ the Log Softmax function is shown as follows:
368
+
369
+ .. math::
370
+ \text{output}(x_i) = \log \left(\frac{\exp(x_i)} {\sum_{j = 0}^{N-1}\exp(x_j)}\right),
371
+
372
+ where :math:`N` is the length of the Tensor.
373
+
374
+ Args:
375
+ dim (int, optional): The axis to perform the Log softmax operation. Default: ``None`` .
376
+
377
+ Returns:
378
+ Tensor, with the same shape as the input.
379
+
380
+ Raises:
381
+ ValueError: If `dim` is not in range [-len(input.shape), len(input.shape)).
382
+
383
+ Supported Platforms:
384
+ ``Ascend``
385
+
386
+ Examples:
387
+ >>> import mindspore
388
+ >>> from mindspore import Tensor, nn
389
+ >>> import numpy as np
390
+ >>> x = Tensor(np.array([[-1.0, 4.0, -8.0], [2.0, -5.0, 9.0]]), mindspore.float32)
391
+ >>> log_softmax = nn.LogSoftmaxExt(dim=-1)
392
+ >>> output = log_softmax(x)
393
+ >>> print(output)
394
+ [[-5.00672150e+00 -6.72150636e-03 -1.20067215e+01]
395
+ [-7.00091219e+00 -1.40009127e+01 -9.12250078e-04]]
396
+ """
397
+
398
+ def __init__(self, dim=None):
399
+ """Initialize LogSoftmaxExt."""
400
+ super(LogSoftmaxExt, self).__init__()
401
+ self.log_softmax = P.LogSoftmaxExt()
402
+ self.dim = dim
403
+
404
+ def construct(self, x):
405
+ return self.log_softmax(x, dim=self.dim)
406
+
407
+
332
408
  class ELU(Cell):
333
409
  r"""
334
410
  Applies the exponential linear unit function element-wise.
@@ -434,8 +510,8 @@ class ReLU(Cell):
434
510
  super(ReLU, self).__init__()
435
511
  self.relu = P.ReLU()
436
512
 
437
- def construct(self, x):
438
- return self.relu(x)
513
+ def construct(self, input):
514
+ return self.relu(input)
439
515
 
440
516
 
441
517
  class ReLU6(Cell):
@@ -898,6 +974,13 @@ class GELU(Cell):
898
974
  Outputs:
899
975
  Tensor, with the same type and shape as the `x`.
900
976
 
977
+ Note:
978
+ when calculating the input gradient of GELU with an input value of infinity, there are differences
979
+ in the output of the backward between ``Ascend`` and ``GPU``.
980
+ when x is -inf, the computation result of ``Ascend`` is 0, and the computation result of ``GPU`` is Nan.
981
+ when x is inf, the computation result of ``Ascend`` is dy, and the computation result of ``GPU`` is Nan.
982
+ In mathematical terms, the result of Ascend has higher precision.
983
+
901
984
  Raises:
902
985
  TypeError: If dtype of `x` is not one of float16, float32, or float64.
903
986
 
@@ -1164,14 +1247,85 @@ class PReLU(Cell):
1164
1247
  return self.prelu(x, F.cast(self.w, x.dtype))
1165
1248
 
1166
1249
 
1250
+ class PReLUExt(Cell):
1251
+ r"""
1252
+ Applies PReLU activation function element-wise.
1253
+
1254
+ PReLU is defined as:
1255
+
1256
+ .. math::
1257
+
1258
+ PReLU(x_i)= \max(0, x_i) + w * \min(0, x_i),
1259
+
1260
+ where :math:`x_i` is an element of an channel of the input.
1261
+
1262
+ Here :math:`w` is a learnable parameter with a default initial value 0.25.
1263
+ Parameter :math:`w` has dimensionality of the argument channel. If called without argument
1264
+ channel, a single parameter :math:`w` will be shared across all channels.
1265
+
1266
+ PReLU Activation Function Graph:
1267
+
1268
+ .. image:: ../images/PReLU2.png
1269
+ :align: center
1270
+
1271
+ .. note::
1272
+ Channel dim is the 2nd dim of input. When input has dims < 2, then there is
1273
+ no channel dim and the number of channels = 1.
1274
+
1275
+ Args:
1276
+ num_parameters (int): number of `w` to learn. Although it takes an int as input,
1277
+ there is only two legitimate values: 1, or the number of channels at Tensor `input`. Default: ``1`` .
1278
+ init (float): the initial value of `w`. Default: ``0.25`` .
1279
+ dtype (mindspore.dtype, optional): the type of `w`. Default: ``None`` . Supported data type
1280
+ is {float16, float32, bfloat16}.
1281
+
1282
+ Inputs:
1283
+ - **input** (Tensor) - The input of PReLU.
1284
+
1285
+ Outputs:
1286
+ Tensor, with the same dtype and shape as the `input`.
1287
+
1288
+ Supported Platforms:
1289
+ ``Ascend``
1290
+
1291
+ Examples:
1292
+ >>> import mindspore
1293
+ >>> from mindspore import Tensor, nn
1294
+ >>> import numpy as np
1295
+ >>> x = Tensor(np.array([[[[0.1, 0.6], [0.9, 0.9]]]]), mindspore.float32)
1296
+ >>> prelu = nn.PReLUExt()
1297
+ >>> output = prelu(x)
1298
+ >>> print(output)
1299
+ [[[[0.1 0.6]
1300
+ [0.9 0.9]]]]
1301
+
1302
+ """
1303
+
1304
+ def __init__(self, num_parameters=1, init=0.25, dtype=None):
1305
+ """Initialize PReLUExt."""
1306
+ super(PReLUExt, self).__init__()
1307
+ tmp = np.empty((num_parameters,), dtype=np.float32)
1308
+ tmp.fill(init)
1309
+ w = Tensor(tmp, dtype=dtype)
1310
+ self.weight = Parameter(w, name='weight')
1311
+
1312
+ def construct(self, input):
1313
+ return ops.prelu(input, self.weight)
1314
+
1315
+
1167
1316
  class HSwish(Cell):
1168
1317
  r"""
1169
- Applies hswish-type activation element-wise.
1318
+ Applies Hard Swish activation function element-wise.
1170
1319
 
1171
1320
  Hard swish is defined as:
1172
1321
 
1173
1322
  .. math::
1174
- \text{hswish}(x_{i}) = x_{i} * \frac{ReLU6(x_{i} + 3)}{6},
1323
+ \text{Hardswish}(input) =
1324
+ \begin{cases}
1325
+ 0, & \text{ if } input \leq -3, \\
1326
+ input, & \text{ if } input \geq +3, \\
1327
+ input*(input + 3)/6, & \text{ otherwise }
1328
+ \end{cases}
1175
1329
 
1176
1330
  HSwish Activation Function Graph:
1177
1331
 
@@ -1179,14 +1333,14 @@ class HSwish(Cell):
1179
1333
  :align: center
1180
1334
 
1181
1335
  Inputs:
1182
- - **x** (Tensor) - The input of HSwish, data type must be float16 or float32.
1183
- The shape is :math:`(N,*)` where :math:`*` means, any number of additional dimensions.
1336
+ - **input** (Tensor) - The input of HSwish.
1184
1337
 
1185
1338
  Outputs:
1186
- Tensor, with the same type and shape as the `x`.
1339
+ Tensor, with the same type and shape as the `input`.
1187
1340
 
1188
1341
  Raises:
1189
- TypeError: If dtype of `x` is neither float16 nor float32.
1342
+ TypeError: If `input` is not a tensor.
1343
+ TypeError: If `input` is neither int nor float.
1190
1344
 
1191
1345
  Supported Platforms:
1192
1346
  ``Ascend`` ``GPU`` ``CPU``
@@ -1195,9 +1349,9 @@ class HSwish(Cell):
1195
1349
  >>> import mindspore
1196
1350
  >>> from mindspore import Tensor, nn
1197
1351
  >>> import numpy as np
1198
- >>> x = Tensor(np.array([-1, -2, 0, 2, 1]), mindspore.float16)
1352
+ >>> input = Tensor(np.array([-1, -2, 0, 2, 1]), mindspore.float16)
1199
1353
  >>> hswish = nn.HSwish()
1200
- >>> result = hswish(x)
1354
+ >>> result = hswish(input)
1201
1355
  >>> print(result)
1202
1356
  [-0.3333 -0.3333 0. 1.667 0.6665]
1203
1357
  """
@@ -1207,18 +1361,23 @@ class HSwish(Cell):
1207
1361
  super(HSwish, self).__init__()
1208
1362
  self.hswish = P.HSwish()
1209
1363
 
1210
- def construct(self, x):
1211
- return self.hswish(x)
1364
+ def construct(self, input):
1365
+ return self.hswish(input)
1212
1366
 
1213
1367
 
1214
1368
  class HSigmoid(Cell):
1215
1369
  r"""
1216
- Applies Hard sigmoid activation function element-wise.
1370
+ Applies Hard Sigmoid activation function element-wise.
1217
1371
 
1218
- Hard sigmoid is defined as:
1372
+ Hard Sigmoid is defined as:
1219
1373
 
1220
1374
  .. math::
1221
- \text{hsigmoid}(x_{i}) = \max(0, \min(1, \frac{x_{i} + 3}{6})),
1375
+ \text{Hardsigmoid}(input) =
1376
+ \begin{cases}
1377
+ 0, & \text{ if } input \leq -3, \\
1378
+ 1, & \text{ if } input \geq +3, \\
1379
+ input/6 + 1/2, & \text{ otherwise }
1380
+ \end{cases}
1222
1381
 
1223
1382
  HSigmoid Activation Function Graph:
1224
1383
 
@@ -1226,13 +1385,14 @@ class HSigmoid(Cell):
1226
1385
  :align: center
1227
1386
 
1228
1387
  Inputs:
1229
- - **input_x** (Tensor) - The input of HSigmoid. Tensor of any dimension.
1388
+ - **input** (Tensor) - The input of HSigmoid.
1230
1389
 
1231
1390
  Outputs:
1232
- Tensor, with the same type and shape as the `input_x`.
1391
+ Tensor, with the same type and shape as the `input`.
1233
1392
 
1234
1393
  Raises:
1235
- TypeError: If `input_x` is not a Tensor.
1394
+ TypeError: If `input` is not a Tensor.
1395
+ TypeError: If `input` is neither int nor float.
1236
1396
 
1237
1397
  Supported Platforms:
1238
1398
  ``Ascend`` ``GPU`` ``CPU``
@@ -1241,9 +1401,9 @@ class HSigmoid(Cell):
1241
1401
  >>> import mindspore
1242
1402
  >>> from mindspore import Tensor, nn
1243
1403
  >>> import numpy as np
1244
- >>> x = Tensor(np.array([-1, -2, 0, 2, 1]), mindspore.float16)
1404
+ >>> input = Tensor(np.array([-1, -2, 0, 2, 1]), mindspore.float16)
1245
1405
  >>> hsigmoid = nn.HSigmoid()
1246
- >>> result = hsigmoid(x)
1406
+ >>> result = hsigmoid(input)
1247
1407
  >>> print(result)
1248
1408
  [0.3333 0.1666 0.5 0.8335 0.6665]
1249
1409
  """
@@ -1253,8 +1413,8 @@ class HSigmoid(Cell):
1253
1413
  super(HSigmoid, self).__init__()
1254
1414
  self.hsigmoid = P.HSigmoid()
1255
1415
 
1256
- def construct(self, input_x):
1257
- return self.hsigmoid(input_x)
1416
+ def construct(self, input):
1417
+ return self.hsigmoid(input)
1258
1418
 
1259
1419
 
1260
1420
  class LogSigmoid(Cell):
@@ -1370,21 +1530,22 @@ class SoftShrink(Cell):
1370
1530
  :align: center
1371
1531
 
1372
1532
  Args:
1373
- lambd (float): the :math:`\lambda` must be no less than zero for the SoftShrink formulation.
1374
- Default: ``0.5`` .
1533
+ lambd (number, optional): The threshold :math:`\lambda` defined by the Soft Shrink formula.
1534
+ It should be greater than or equal to 0, default: ``0.5`` .
1375
1535
 
1376
1536
  Inputs:
1377
- - **input_x** (Tensor) - The input of SoftShrink with data type of float16 or float32.
1378
- Any number of additional dimensions.
1537
+ - **input** (Tensor) - The input of Soft Shrink. Supported dtypes:
1538
+
1539
+ - Ascend: float16, float32, bfloat16.
1540
+ - CPU/GPU: float16, float32.
1379
1541
 
1380
1542
  Outputs:
1381
- Tensor, has the same shape and data type as `input_x`.
1543
+ Tensor, the same shape and data type as the input.
1382
1544
 
1383
1545
  Raises:
1384
- TypeError: If lambd is not a float.
1385
- TypeError: If input_x is not a Tensor.
1386
- TypeError: If dtype of input_x is neither float16 nor float32.
1387
- ValueError: If lambd is less than 0.
1546
+ TypeError: If `lambd` is not a float, int or bool.
1547
+ TypeError: If `input` is not a tensor.
1548
+ TypeError: If dtype of `input` is not float16, float32 or bfloat16.
1388
1549
 
1389
1550
  Supported Platforms:
1390
1551
  ``Ascend`` ``GPU`` ``CPU``
@@ -1393,9 +1554,9 @@ class SoftShrink(Cell):
1393
1554
  >>> import mindspore
1394
1555
  >>> from mindspore import Tensor, nn
1395
1556
  >>> import numpy as np
1396
- >>> input_x = Tensor(np.array([[ 0.5297, 0.7871, 1.1754], [ 0.7836, 0.6218, -1.1542]]), mindspore.float16)
1557
+ >>> input = Tensor(np.array([[ 0.5297, 0.7871, 1.1754], [ 0.7836, 0.6218, -1.1542]]), mindspore.float16)
1397
1558
  >>> softshrink = nn.SoftShrink()
1398
- >>> output = softshrink(input_x)
1559
+ >>> output = softshrink(input)
1399
1560
  >>> print(output)
1400
1561
  [[ 0.02979 0.287 0.676 ]
1401
1562
  [ 0.2837 0.1216 -0.6543 ]]
@@ -1405,8 +1566,8 @@ class SoftShrink(Cell):
1405
1566
  super(SoftShrink, self).__init__()
1406
1567
  self.softshrink = P.SoftShrink(lambd)
1407
1568
 
1408
- def construct(self, input_x):
1409
- output = self.softshrink(input_x)
1569
+ def construct(self, input):
1570
+ output = self.softshrink(input)
1410
1571
  return output
1411
1572
 
1412
1573
 
@@ -1430,17 +1591,21 @@ class HShrink(Cell):
1430
1591
  :align: center
1431
1592
 
1432
1593
  Args:
1433
- lambd (float): The threshold :math:`\lambda` defined by the Hard Shrink formula. Default: ``0.5`` .
1594
+ lambd (number, optional): The threshold :math:`\lambda` defined by the Hard Shrink formula. Default: ``0.5`` .
1434
1595
 
1435
1596
  Inputs:
1436
- - **input_x** (Tensor) - The input of Hard Shrink with data type of float16 or float32.
1597
+ - **input** (Tensor) - The input of Hard Shrink. Supported dtypes:
1598
+
1599
+ - Ascend: float16, float32, bfloat16.
1600
+ - CPU/GPU: float16, float32.
1437
1601
 
1438
1602
  Outputs:
1439
1603
  Tensor, the same shape and data type as the input.
1440
1604
 
1441
1605
  Raises:
1442
- TypeError: If `lambd` is not a float.
1443
- TypeError: If dtype of `input_x` is neither float16 nor float32.
1606
+ TypeError: If `lambd` is not a float, int or bool.
1607
+ TypeError: If `input` is not a tensor.
1608
+ TypeError: If dtype of `input` is not float16, float32 or bfloat16.
1444
1609
 
1445
1610
  Supported Platforms:
1446
1611
  ``Ascend`` ``GPU`` ``CPU``
@@ -1449,20 +1614,20 @@ class HShrink(Cell):
1449
1614
  >>> import mindspore
1450
1615
  >>> from mindspore import Tensor, nn
1451
1616
  >>> import numpy as np
1452
- >>> input_x = Tensor(np.array([[ 0.5, 1, 2.0], [0.0533,0.0776,-2.1233]]), mindspore.float32)
1617
+ >>> input = Tensor(np.array([[0.5, 1, 2.0], [0.0533, 0.0776, -2.1233]]), mindspore.float32)
1453
1618
  >>> hshrink = nn.HShrink()
1454
- >>> output = hshrink(input_x)
1619
+ >>> output = hshrink(input)
1455
1620
  >>> print(output)
1456
1621
  [[ 0. 1. 2. ]
1457
- [ 0. 0. -2.1233]]
1622
+ [ 0. 0. -2.1233]]
1458
1623
  """
1459
1624
 
1460
1625
  def __init__(self, lambd=0.5):
1461
1626
  super(HShrink, self).__init__()
1462
1627
  self.hshrink = P.HShrink(lambd)
1463
1628
 
1464
- def construct(self, input_x):
1465
- return self.hshrink(input_x)
1629
+ def construct(self, input):
1630
+ return self.hshrink(input)
1466
1631
 
1467
1632
 
1468
1633
  class Threshold(Cell):
@@ -1602,6 +1767,7 @@ _activation = {
1602
1767
  'softmax': Softmax,
1603
1768
  'softmax2d': Softmax2d,
1604
1769
  'logsoftmax': LogSoftmax,
1770
+ 'logsoftmaxExt': LogSoftmaxExt,
1605
1771
  'relu': ReLU,
1606
1772
  'relu6': ReLU6,
1607
1773
  'rrelu': RReLU,
@@ -1615,6 +1781,7 @@ _activation = {
1615
1781
  'sigmoid': Sigmoid,
1616
1782
  'softsign': Softsign,
1617
1783
  'prelu': PReLU,
1784
+ 'preluExt': PReLUExt,
1618
1785
  'leakyrelu': LeakyReLU,
1619
1786
  'hswish': HSwish,
1620
1787
  'hsigmoid': HSigmoid,
@@ -40,7 +40,7 @@ from mindspore.common._decorator import deprecated
40
40
  from mindspore.ops.auto_generate import dropout_ext_op, fold_ext
41
41
  from mindspore.common.generator import default_generator
42
42
 
43
- __all__ = ['Dropout', 'Flatten', 'Dense', 'ClipByNorm', 'Norm', 'OneHot', 'Pad', 'Unfold', 'Tril', 'Triu',
43
+ __all__ = ['Dropout', 'Flatten', 'Dense', 'Linear', 'ClipByNorm', 'Norm', 'OneHot', 'Pad', 'Unfold', 'Tril', 'Triu',
44
44
  'MatrixDiag', 'MatrixDiagPart', 'MatrixSetDiag', 'L1Regularizer', 'Dropout1d',
45
45
  'Dropout2d', 'Dropout3d', 'Upsample', 'Roll', 'Identity', 'Unflatten', 'DropoutExt']
46
46
 
@@ -510,8 +510,8 @@ class UpsampleExt(Cell):
510
510
  self.align_corners = align_corners
511
511
  self.recompute_scale_factor = recompute_scale_factor
512
512
 
513
- def construct(self, x):
514
- out = interpolate_ext(x, self.size, self.scale_factor, self.mode,
513
+ def construct(self, input):
514
+ out = interpolate_ext(input, self.size, self.scale_factor, self.mode,
515
515
  self.align_corners, self.recompute_scale_factor)
516
516
  return out
517
517
 
@@ -743,6 +743,116 @@ class Dense(Cell):
743
743
  return s
744
744
 
745
745
 
746
+ class Linear(Cell):
747
+ r"""
748
+ The linear connected layer.
749
+
750
+ Applies linear connected layer for the input. This layer implements the operation as:
751
+
752
+ .. math::
753
+ \text{outputs} = X * kernel + bias
754
+
755
+ where :math:`X` is the input tensors, :math:`\text{kernel}` is a weight matrix with the same
756
+ data type as the :math:`X` created by the layer, and :math:`\text{bias}` is a bias vector
757
+ with the same data type as the :math:`X` created by the layer (only if has_bias is True).
758
+
759
+ Args:
760
+ in_features (int): The number of features in the input space.
761
+ out_features (int): The number of features in the output space.
762
+ bias (bool): Specifies whether the layer uses a bias vector :math:`\text{bias}`. Default: ``True``.
763
+ weight_init (Union[Tensor, str, Initializer, numbers.Number]): The trainable weight_init parameter. The dtype
764
+ is same as `x`. The values of str refer to the function `initializer`. Default: ``None`` ,
765
+ weight will be initialized using HeUniform.
766
+ bias_init (Union[Tensor, str, Initializer, numbers.Number]): The trainable bias_init parameter. The dtype is
767
+ same as `x`. The values of str refer to the function `initializer`. Default: ``None`` ,
768
+ bias will be initialized using Uniform.
769
+ dtype (:class:`mindspore.dtype`): Data type of Parameter. Default: ``None`` .
770
+
771
+ Inputs:
772
+ - **x** (Tensor) - Tensor of shape :math:`(*, in\_features)`. The `in_features` in `Args` should be equal
773
+ to :math:`in\_features` in `Inputs`.
774
+
775
+ Outputs:
776
+ Tensor of shape :math:`(*, out\_features)`.
777
+
778
+ Raises:
779
+ TypeError: If `in_features` or `out_features` is not an int.
780
+ TypeError: If `bias` is not a bool.
781
+ ValueError: If length of shape of `weight_init` is not equal to 2 or shape[0] of `weight_init`
782
+ is not equal to `out_features` or shape[1] of `weight_init` is not equal to `in_features`.
783
+ ValueError: If length of shape of `bias_init` is not equal to 1
784
+ or shape[0] of `bias_init` is not equal to `out_features`.
785
+
786
+ Supported Platforms:
787
+ ``Ascend`` ``GPU`` ``CPU``
788
+
789
+ Examples:
790
+ >>> import mindspore
791
+ >>> from mindspore import Tensor
792
+ >>> from mindspore import nn
793
+ >>> import numpy as np
794
+ >>> x = Tensor(np.array([[180, 234, 154], [244, 48, 247]]), mindspore.float32)
795
+ >>> net = nn.mint.nn.Linear(3, 4)
796
+ >>> output = net(x)
797
+ >>> print(output.shape)
798
+ (2, 4)
799
+ """
800
+
801
+ @cell_attr_register(attrs=['has_bias'])
802
+ def __init__(self,
803
+ in_features,
804
+ out_features,
805
+ bias=True,
806
+ weight_init=None,
807
+ bias_init=None,
808
+ dtype=None):
809
+ """Initialize Linear."""
810
+ super(Linear, self).__init__()
811
+ self.in_features = Validator.check_positive_int(
812
+ in_features, "in_features", self.cls_name)
813
+ self.out_features = Validator.check_positive_int(
814
+ out_features, "out_features", self.cls_name)
815
+ self.has_bias = Validator.check_bool(
816
+ bias, "has_bias", self.cls_name)
817
+ self.dense = P.Dense()
818
+ if dtype is None:
819
+ dtype = mstype.float32
820
+ if isinstance(weight_init, Tensor):
821
+ if weight_init.ndim != 2 or weight_init.shape[0] != out_features or \
822
+ weight_init.shape[1] != in_features:
823
+ raise ValueError(f"For '{self.cls_name}', weight init shape error. The ndim of 'weight_init' must "
824
+ f"be equal to 2, and the first dim must be equal to 'out_features', and the "
825
+ f"second dim must be equal to 'in_features'. But got 'weight_init': {weight_init}, "
826
+ f"'out_features': {out_features}, 'in_features': {in_features}.")
827
+ if weight_init is None:
828
+ weight_init = HeUniform(math.sqrt(5))
829
+ self.weight = Parameter(initializer(
830
+ weight_init, [out_features, in_features], dtype=dtype), name="weight")
831
+
832
+ self.bias = None
833
+ if self.has_bias:
834
+ if isinstance(bias_init, Tensor):
835
+ if bias_init.ndim != 1 or bias_init.shape[0] != out_features:
836
+ raise ValueError(f"For '{self.cls_name}', bias init shape error. The ndim of 'bias_init' must "
837
+ f"be equal to 1, and the first dim must be equal to 'out_features'. But got "
838
+ f"'bias_init': {bias_init}, 'out_features': {out_features}.")
839
+ if bias_init is None:
840
+ bound = 1 / math.sqrt(in_features)
841
+ bias_init = Uniform(scale=bound)
842
+ self.bias = Parameter(initializer(
843
+ bias_init, [out_features], dtype=dtype), name="bias")
844
+
845
+ def construct(self, x):
846
+ x = self.dense(x, self.weight, self.bias)
847
+ return x
848
+
849
+ def extend_repr(self):
850
+ s = f'input_features={self.in_features}, output_features={self.out_features}'
851
+ if self.has_bias:
852
+ s += f', has_bias={self.has_bias}'
853
+ return s
854
+
855
+
746
856
  @constexpr
747
857
  def _is_equal_one(x):
748
858
  if x is None: