mindspore 2.2.14__cp39-cp39-win_amd64.whl → 2.4.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.
- mindspore/.commit_id +1 -1
- mindspore/Microsoft.VisualStudio.Telemetry.dll +0 -0
- mindspore/Newtonsoft.Json.dll +0 -0
- mindspore/__init__.py +8 -5
- mindspore/_c_dataengine.cp39-win_amd64.pyd +0 -0
- mindspore/_c_expression.cp39-win_amd64.pyd +0 -0
- mindspore/_c_mindrecord.cp39-win_amd64.pyd +0 -0
- mindspore/_checkparam.py +124 -25
- mindspore/_extends/builtin_operations.py +2 -1
- mindspore/_extends/graph_kernel/model/graph_parallel.py +16 -6
- mindspore/_extends/parallel_compile/akg_compiler/akg_process.py +3 -16
- mindspore/_extends/parallel_compile/akg_compiler/build_tbe_kernel.py +16 -4
- mindspore/_extends/parallel_compile/akg_compiler/compiler.py +1 -0
- mindspore/_extends/parallel_compile/akg_compiler/gen_custom_op_files.py +96 -0
- mindspore/_extends/parallel_compile/akg_compiler/tbe_topi.py +2 -1
- mindspore/_extends/parallel_compile/akg_compiler/util.py +5 -2
- mindspore/_extends/parse/__init__.py +18 -14
- mindspore/_extends/parse/compile_config.py +299 -0
- mindspore/_extends/parse/namespace.py +2 -2
- mindspore/_extends/parse/parser.py +182 -68
- mindspore/_extends/parse/resources.py +45 -14
- mindspore/_extends/parse/standard_method.py +192 -252
- mindspore/{ops/_op_impl/tbe/atomic_addr_clean.py → _extends/pijit/__init__.py} +6 -16
- mindspore/_extends/pijit/pijit_func_white_list.py +669 -0
- mindspore/_extends/remote/kernel_build_server.py +2 -0
- mindspore/_profiler.py +30 -0
- mindspore/amp.py +67 -26
- mindspore/atlprov.dll +0 -0
- mindspore/avcodec-59.dll +0 -0
- mindspore/avdevice-59.dll +0 -0
- mindspore/avfilter-8.dll +0 -0
- mindspore/avformat-59.dll +0 -0
- mindspore/avutil-57.dll +0 -0
- mindspore/boost/adasum.py +1 -1
- mindspore/boost/base.py +1 -1
- mindspore/boost/boost_cell_wrapper.py +2 -2
- mindspore/boost/grad_freeze.py +2 -2
- mindspore/boost/group_loss_scale_manager.py +1 -1
- mindspore/boost/less_batch_normalization.py +9 -6
- mindspore/c1.dll +0 -0
- mindspore/c1xx.dll +0 -0
- mindspore/c2.dll +0 -0
- mindspore/common/__init__.py +20 -7
- mindspore/common/_jit_fallback_utils.py +2 -3
- mindspore/common/_pijit_context.py +190 -0
- mindspore/common/_register_for_adapter.py +7 -0
- mindspore/common/_register_for_recompute.py +48 -0
- mindspore/common/_register_for_tensor.py +10 -10
- mindspore/common/_stub_tensor.py +7 -1
- mindspore/common/_tensor_overload.py +139 -0
- mindspore/common/_utils.py +5 -17
- mindspore/common/api.py +449 -129
- mindspore/common/auto_dynamic_shape.py +27 -14
- mindspore/common/dtype.py +17 -10
- mindspore/common/dump.py +8 -11
- mindspore/common/file_system.py +48 -0
- mindspore/common/generator.py +254 -0
- mindspore/common/hook_handle.py +65 -30
- mindspore/common/initializer.py +1 -1
- mindspore/common/jit_config.py +34 -14
- mindspore/common/lazy_inline.py +72 -19
- mindspore/common/mindir_util.py +12 -2
- mindspore/common/mutable.py +79 -14
- mindspore/common/no_inline.py +54 -0
- mindspore/common/np_dtype.py +25 -0
- mindspore/common/parameter.py +73 -21
- mindspore/common/recompute.py +292 -0
- mindspore/common/seed.py +9 -9
- mindspore/common/sparse_tensor.py +276 -24
- mindspore/common/symbol.py +122 -0
- mindspore/common/tensor.py +668 -514
- mindspore/communication/__init__.py +6 -11
- mindspore/communication/_comm_helper.py +43 -3
- mindspore/communication/comm_func.py +1395 -0
- mindspore/communication/management.py +117 -104
- mindspore/config/op_info.config +22 -54
- mindspore/context.py +455 -71
- mindspore/dataset/__init__.py +5 -5
- mindspore/dataset/audio/__init__.py +6 -6
- mindspore/dataset/audio/transforms.py +711 -158
- mindspore/dataset/callback/ds_callback.py +2 -2
- mindspore/dataset/core/config.py +7 -0
- mindspore/dataset/core/validator_helpers.py +7 -0
- mindspore/dataset/engine/cache_client.py +2 -2
- mindspore/dataset/engine/datasets.py +201 -116
- mindspore/dataset/engine/datasets_audio.py +14 -14
- mindspore/dataset/engine/datasets_standard_format.py +83 -3
- mindspore/dataset/engine/datasets_text.py +39 -39
- mindspore/dataset/engine/datasets_user_defined.py +230 -141
- mindspore/dataset/engine/datasets_vision.py +78 -74
- mindspore/dataset/engine/iterators.py +29 -0
- mindspore/dataset/engine/obs/util.py +7 -0
- mindspore/dataset/engine/offload.py +5 -7
- mindspore/dataset/engine/queue.py +138 -66
- mindspore/dataset/engine/serializer_deserializer.py +2 -2
- mindspore/dataset/engine/validators.py +41 -15
- mindspore/dataset/text/__init__.py +2 -5
- mindspore/dataset/text/transforms.py +408 -121
- mindspore/dataset/text/utils.py +9 -9
- mindspore/dataset/transforms/__init__.py +0 -3
- mindspore/dataset/transforms/transforms.py +261 -76
- mindspore/dataset/utils/browse_dataset.py +9 -9
- mindspore/dataset/utils/line_reader.py +2 -0
- mindspore/dataset/vision/__init__.py +7 -10
- mindspore/dataset/vision/c_transforms.py +10 -10
- mindspore/dataset/vision/py_transforms_util.py +1 -1
- mindspore/dataset/vision/transforms.py +2844 -549
- mindspore/dataset/vision/utils.py +161 -10
- mindspore/dataset/vision/validators.py +16 -3
- mindspore/dnnl.dll +0 -0
- mindspore/dpcmi.dll +0 -0
- mindspore/{rewrite/ast_creator_register.py → experimental/es/__init__.py} +5 -20
- mindspore/experimental/es/embedding_service.py +883 -0
- mindspore/experimental/es/embedding_service_layer.py +581 -0
- mindspore/experimental/llm_boost/__init__.py +21 -0
- mindspore/experimental/llm_boost/atb/__init__.py +23 -0
- mindspore/experimental/llm_boost/atb/boost_base.py +211 -0
- mindspore/experimental/llm_boost/atb/llama_boost.py +115 -0
- mindspore/experimental/llm_boost/atb/qwen_boost.py +101 -0
- mindspore/experimental/llm_boost/register.py +129 -0
- mindspore/experimental/llm_boost/utils.py +31 -0
- mindspore/experimental/optim/__init__.py +12 -2
- mindspore/experimental/optim/adadelta.py +161 -0
- mindspore/experimental/optim/adagrad.py +168 -0
- mindspore/experimental/optim/adam.py +35 -34
- mindspore/experimental/optim/adamax.py +170 -0
- mindspore/experimental/optim/adamw.py +124 -15
- mindspore/experimental/optim/asgd.py +153 -0
- mindspore/experimental/optim/lr_scheduler.py +66 -121
- mindspore/experimental/optim/nadam.py +157 -0
- mindspore/experimental/optim/optimizer.py +18 -8
- mindspore/experimental/optim/radam.py +194 -0
- mindspore/experimental/optim/rmsprop.py +154 -0
- mindspore/experimental/optim/rprop.py +164 -0
- mindspore/experimental/optim/sgd.py +28 -19
- mindspore/hal/__init__.py +40 -0
- mindspore/hal/_ascend.py +57 -0
- mindspore/hal/_base.py +57 -0
- mindspore/hal/_cpu.py +56 -0
- mindspore/hal/_gpu.py +57 -0
- mindspore/hal/contiguous_tensors_handle.py +175 -0
- mindspore/hal/device.py +356 -0
- mindspore/hal/event.py +179 -0
- mindspore/hal/memory.py +326 -0
- mindspore/hal/stream.py +357 -0
- mindspore/include/api/data_type.h +2 -2
- mindspore/include/api/dual_abi_helper.h +16 -3
- mindspore/include/api/model.h +4 -3
- mindspore/include/api/model_group.h +13 -1
- mindspore/include/api/status.h +14 -0
- mindspore/include/api/types.h +10 -10
- mindspore/include/c_api/model_c.h +173 -0
- mindspore/include/c_api/types_c.h +19 -0
- mindspore/include/dataset/config.h +2 -2
- mindspore/include/dataset/constants.h +2 -2
- mindspore/include/dataset/execute.h +3 -5
- mindspore/include/dataset/vision.h +58 -2
- mindspore/jpeg62.dll +0 -0
- mindspore/log.py +3 -3
- mindspore/mindrecord/__init__.py +5 -1
- mindspore/mindrecord/config.py +809 -0
- mindspore/mindrecord/filereader.py +25 -0
- mindspore/mindrecord/filewriter.py +138 -103
- mindspore/mindrecord/mindpage.py +40 -6
- mindspore/mindrecord/shardutils.py +3 -2
- mindspore/mindrecord/shardwriter.py +7 -0
- mindspore/mindrecord/tools/cifar100_to_mr.py +8 -13
- mindspore/mindrecord/tools/cifar10_to_mr.py +9 -15
- mindspore/mindrecord/tools/csv_to_mr.py +4 -9
- mindspore/mindrecord/tools/imagenet_to_mr.py +3 -8
- mindspore/mindrecord/tools/mnist_to_mr.py +7 -12
- mindspore/mindrecord/tools/tfrecord_to_mr.py +1 -6
- mindspore/mindspore_backend.dll +0 -0
- mindspore/mindspore_common.dll +0 -0
- mindspore/mindspore_core.dll +0 -0
- mindspore/mindspore_glog.dll +0 -0
- mindspore/mindspore_np_dtype.dll +0 -0
- mindspore/mindspore_ops.dll +0 -0
- mindspore/mint/__init__.py +1586 -0
- mindspore/mint/distributed/__init__.py +31 -0
- mindspore/mint/distributed/distributed.py +254 -0
- mindspore/{rewrite/ast_transformers → mint/linalg}/__init__.py +9 -4
- mindspore/mint/nn/__init__.py +757 -0
- mindspore/mint/nn/functional.py +679 -0
- mindspore/mint/nn/layer/__init__.py +39 -0
- mindspore/mint/nn/layer/activation.py +133 -0
- mindspore/mint/nn/layer/normalization.py +477 -0
- mindspore/mint/nn/layer/pooling.py +110 -0
- mindspore/mint/optim/__init__.py +24 -0
- mindspore/mint/optim/adamw.py +206 -0
- mindspore/mint/special/__init__.py +63 -0
- mindspore/msobj140.dll +0 -0
- mindspore/mspdb140.dll +0 -0
- mindspore/mspdbcore.dll +0 -0
- mindspore/mspdbst.dll +0 -0
- mindspore/mspft140.dll +0 -0
- mindspore/msvcdis140.dll +0 -0
- mindspore/msvcp140_1.dll +0 -0
- mindspore/msvcp140_2.dll +0 -0
- mindspore/msvcp140_atomic_wait.dll +0 -0
- mindspore/msvcp140_codecvt_ids.dll +0 -0
- mindspore/multiprocessing/__init__.py +73 -0
- mindspore/nn/cell.py +461 -323
- mindspore/nn/dynamic_lr.py +2 -2
- mindspore/nn/layer/activation.py +292 -135
- mindspore/nn/layer/basic.py +288 -83
- mindspore/nn/layer/channel_shuffle.py +3 -16
- mindspore/nn/layer/container.py +3 -3
- mindspore/nn/layer/conv.py +75 -66
- mindspore/nn/layer/embedding.py +221 -45
- mindspore/nn/layer/image.py +4 -7
- mindspore/nn/layer/math.py +1 -1
- mindspore/nn/layer/normalization.py +150 -68
- mindspore/nn/layer/padding.py +64 -87
- mindspore/nn/layer/pooling.py +175 -12
- mindspore/nn/layer/rnn_cells.py +6 -16
- mindspore/nn/layer/rnns.py +6 -5
- mindspore/nn/layer/thor_layer.py +1 -2
- mindspore/nn/layer/timedistributed.py +1 -1
- mindspore/nn/layer/transformer.py +55 -53
- mindspore/nn/learning_rate_schedule.py +6 -5
- mindspore/nn/loss/__init__.py +2 -2
- mindspore/nn/loss/loss.py +145 -88
- mindspore/nn/optim/__init__.py +2 -1
- mindspore/nn/optim/ada_grad.py +4 -2
- mindspore/nn/optim/adadelta.py +4 -2
- mindspore/nn/optim/adafactor.py +1 -1
- mindspore/nn/optim/adam.py +102 -181
- mindspore/nn/optim/adamax.py +4 -2
- mindspore/nn/optim/adasum.py +3 -3
- mindspore/nn/optim/asgd.py +4 -2
- mindspore/nn/optim/ftrl.py +31 -61
- mindspore/nn/optim/lamb.py +5 -3
- mindspore/nn/optim/lars.py +2 -2
- mindspore/nn/optim/lazyadam.py +6 -4
- mindspore/nn/optim/momentum.py +13 -25
- mindspore/nn/optim/optimizer.py +6 -3
- mindspore/nn/optim/proximal_ada_grad.py +4 -2
- mindspore/nn/optim/rmsprop.py +9 -3
- mindspore/nn/optim/rprop.py +4 -2
- mindspore/nn/optim/sgd.py +5 -3
- mindspore/nn/optim/tft_wrapper.py +127 -0
- mindspore/nn/optim/thor.py +2 -2
- mindspore/nn/probability/distribution/_utils/custom_ops.py +2 -2
- mindspore/nn/probability/distribution/beta.py +2 -2
- mindspore/nn/probability/distribution/categorical.py +4 -6
- mindspore/nn/probability/distribution/cauchy.py +2 -2
- mindspore/nn/probability/distribution/exponential.py +2 -2
- mindspore/nn/probability/distribution/geometric.py +1 -1
- mindspore/nn/probability/distribution/gumbel.py +2 -2
- mindspore/nn/probability/distribution/logistic.py +1 -1
- mindspore/nn/probability/distribution/poisson.py +2 -2
- mindspore/nn/probability/distribution/uniform.py +2 -2
- mindspore/nn/reinforcement/_tensors_queue.py +13 -1
- mindspore/nn/wrap/__init__.py +2 -1
- mindspore/nn/wrap/cell_wrapper.py +46 -12
- mindspore/nn/wrap/grad_reducer.py +148 -8
- mindspore/nn/wrap/loss_scale.py +44 -7
- mindspore/numpy/__init__.py +2 -0
- mindspore/numpy/array_creations.py +67 -68
- mindspore/numpy/array_ops.py +70 -66
- mindspore/numpy/dtypes.py +3 -3
- mindspore/numpy/fft.py +966 -0
- mindspore/numpy/logic_ops.py +11 -10
- mindspore/numpy/math_ops.py +147 -152
- mindspore/numpy/utils.py +3 -0
- mindspore/numpy/utils_const.py +4 -4
- mindspore/opencv_core452.dll +0 -0
- mindspore/opencv_imgcodecs452.dll +0 -0
- mindspore/opencv_imgproc452.dll +0 -0
- mindspore/ops/__init__.py +9 -6
- mindspore/ops/_grad_experimental/grad_array_ops.py +4 -129
- mindspore/ops/_grad_experimental/grad_comm_ops.py +135 -36
- mindspore/ops/_grad_experimental/grad_math_ops.py +61 -298
- mindspore/ops/_grad_experimental/grad_nn_ops.py +0 -53
- mindspore/ops/_grad_experimental/grad_quant_ops.py +3 -3
- mindspore/ops/_grad_experimental/grad_sparse.py +1 -1
- mindspore/ops/_grad_experimental/grad_sparse_ops.py +3 -3
- mindspore/ops/_op_impl/__init__.py +0 -1
- mindspore/ops/_op_impl/aicpu/gamma.py +2 -0
- mindspore/ops/_op_impl/aicpu/generate_eod_mask.py +1 -1
- mindspore/ops/_op_impl/aicpu/log_uniform_candidate_sampler.py +1 -3
- mindspore/ops/_op_impl/aicpu/poisson.py +2 -0
- mindspore/ops/_op_impl/cpu/__init__.py +1 -3
- mindspore/ops/_op_impl/cpu/adam.py +2 -2
- mindspore/ops/_op_impl/cpu/adam_weight_decay.py +3 -2
- mindspore/ops/_op_impl/cpu/maximum_grad.py +16 -14
- mindspore/ops/_op_impl/cpu/minimum_grad.py +8 -0
- mindspore/ops/_vmap/vmap_array_ops.py +162 -101
- mindspore/ops/_vmap/vmap_base.py +8 -1
- mindspore/ops/_vmap/vmap_grad_math_ops.py +95 -9
- mindspore/ops/_vmap/vmap_grad_nn_ops.py +143 -58
- mindspore/ops/_vmap/vmap_image_ops.py +70 -13
- mindspore/ops/_vmap/vmap_math_ops.py +147 -59
- mindspore/ops/_vmap/vmap_nn_ops.py +292 -117
- mindspore/ops/_vmap/vmap_other_ops.py +1 -1
- mindspore/ops/auto_generate/__init__.py +31 -0
- mindspore/ops/auto_generate/cpp_create_prim_instance_helper.py +309 -0
- mindspore/ops/auto_generate/gen_arg_dtype_cast.py +252 -0
- mindspore/ops/auto_generate/gen_arg_handler.py +197 -0
- mindspore/ops/auto_generate/gen_extend_func.py +1701 -0
- mindspore/ops/auto_generate/gen_ops_def.py +8482 -0
- mindspore/ops/auto_generate/gen_ops_prim.py +16704 -0
- mindspore/ops/auto_generate/pyboost_inner_prim.py +549 -0
- mindspore/ops/composite/__init__.py +5 -2
- mindspore/ops/composite/base.py +201 -66
- mindspore/ops/composite/math_ops.py +10 -49
- mindspore/ops/composite/multitype_ops/_compile_utils.py +192 -618
- mindspore/ops/composite/multitype_ops/_constexpr_utils.py +25 -134
- mindspore/ops/composite/multitype_ops/add_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/bitwise_and_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/bitwise_or_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/bitwise_xor_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/div_impl.py +8 -0
- mindspore/ops/composite/multitype_ops/equal_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/floordiv_impl.py +8 -0
- mindspore/ops/composite/multitype_ops/getitem_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/greater_equal_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/greater_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/in_impl.py +8 -2
- mindspore/ops/composite/multitype_ops/left_shift_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/less_equal_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/less_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/logic_not_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/logical_and_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/logical_or_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/mod_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/mul_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/negative_impl.py +9 -3
- mindspore/ops/composite/multitype_ops/not_equal_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/not_in_impl.py +8 -3
- mindspore/ops/composite/multitype_ops/ones_like_impl.py +2 -2
- mindspore/ops/composite/multitype_ops/pow_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/right_shift_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/setitem_impl.py +32 -21
- mindspore/ops/composite/multitype_ops/sub_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/zeros_like_impl.py +6 -3
- mindspore/ops/deprecated.py +14 -3
- mindspore/ops/function/__init__.py +53 -11
- mindspore/ops/function/array_func.py +1269 -1821
- mindspore/ops/function/clip_func.py +19 -31
- mindspore/ops/function/debug_func.py +114 -5
- mindspore/ops/function/fft_func.py +44 -0
- mindspore/ops/function/grad/grad_func.py +30 -22
- mindspore/ops/function/image_func.py +27 -21
- mindspore/ops/function/linalg_func.py +35 -68
- mindspore/ops/function/math_func.py +1170 -2697
- mindspore/ops/function/nn_func.py +2116 -1128
- mindspore/ops/function/other_func.py +8 -8
- mindspore/ops/function/parameter_func.py +5 -93
- mindspore/ops/function/random_func.py +435 -113
- mindspore/ops/function/reshard_func.py +104 -0
- mindspore/ops/function/sparse_func.py +4 -4
- mindspore/ops/function/sparse_unary_func.py +9 -16
- mindspore/ops/function/spectral_func.py +1 -1
- mindspore/ops/function/vmap_func.py +16 -15
- mindspore/ops/functional.py +355 -346
- mindspore/ops/op_info_register.py +18 -45
- mindspore/ops/operations/__init__.py +38 -24
- mindspore/ops/operations/_grad_ops.py +21 -927
- mindspore/ops/operations/_infer_ops.py +19 -0
- mindspore/ops/operations/_inner_ops.py +173 -607
- mindspore/ops/operations/_rl_inner_ops.py +2 -2
- mindspore/ops/operations/_scalar_ops.py +5 -480
- mindspore/ops/operations/_sequence_ops.py +6 -36
- mindspore/ops/operations/_tensor_array.py +8 -8
- mindspore/ops/operations/array_ops.py +106 -2837
- mindspore/ops/operations/comm_ops.py +799 -127
- mindspore/ops/operations/custom_ops.py +124 -119
- mindspore/ops/operations/debug_ops.py +142 -41
- mindspore/ops/operations/image_ops.py +1 -217
- mindspore/ops/operations/inner_ops.py +5 -40
- mindspore/ops/operations/linalg_ops.py +1 -49
- mindspore/ops/operations/manually_defined/__init__.py +24 -0
- mindspore/ops/operations/manually_defined/_inner.py +73 -0
- mindspore/ops/operations/manually_defined/ops_def.py +2271 -0
- mindspore/ops/operations/math_ops.py +666 -4972
- mindspore/ops/operations/nn_ops.py +205 -2213
- mindspore/ops/operations/other_ops.py +60 -49
- mindspore/ops/operations/random_ops.py +50 -54
- mindspore/ops/operations/reshard_ops.py +53 -0
- mindspore/ops/operations/sparse_ops.py +4 -4
- mindspore/ops/primitive.py +216 -103
- mindspore/ops_generate/__init__.py +27 -0
- mindspore/ops_generate/arg_dtype_cast.py +252 -0
- mindspore/ops_generate/arg_handler.py +197 -0
- mindspore/ops_generate/gen_aclnn_implement.py +263 -0
- mindspore/ops_generate/gen_constants.py +36 -0
- mindspore/ops_generate/gen_ops.py +1099 -0
- mindspore/ops_generate/gen_ops_inner_prim.py +131 -0
- mindspore/ops_generate/gen_pyboost_func.py +1052 -0
- mindspore/ops_generate/gen_utils.py +209 -0
- mindspore/ops_generate/op_proto.py +145 -0
- mindspore/ops_generate/pyboost_utils.py +367 -0
- mindspore/ops_generate/template.py +261 -0
- mindspore/parallel/__init__.py +8 -4
- mindspore/parallel/_auto_parallel_context.py +100 -10
- mindspore/parallel/_cell_wrapper.py +99 -9
- mindspore/parallel/_cost_model_context.py +1 -1
- mindspore/parallel/_dp_allreduce_fusion.py +159 -159
- mindspore/parallel/_parallel_serialization.py +67 -23
- mindspore/parallel/_ps_context.py +1 -1
- mindspore/parallel/_recovery_context.py +1 -1
- mindspore/parallel/_tensor.py +99 -22
- mindspore/parallel/_transformer/__init__.py +1 -1
- mindspore/parallel/_transformer/layers.py +1 -1
- mindspore/parallel/_transformer/loss.py +1 -1
- mindspore/parallel/_transformer/moe.py +1 -1
- mindspore/parallel/_transformer/op_parallel_config.py +1 -1
- mindspore/parallel/_transformer/transformer.py +2 -2
- mindspore/parallel/_utils.py +173 -6
- mindspore/parallel/algo_parameter_config.py +8 -10
- mindspore/parallel/checkpoint_transform.py +204 -38
- mindspore/parallel/cluster/__init__.py +15 -0
- mindspore/parallel/cluster/process_entity/__init__.py +18 -0
- mindspore/parallel/cluster/process_entity/_api.py +352 -0
- mindspore/parallel/cluster/process_entity/_utils.py +101 -0
- mindspore/parallel/cluster/run.py +136 -0
- mindspore/parallel/mpi/__init__.py +1 -1
- mindspore/parallel/mpi/_mpi_config.py +1 -1
- mindspore/parallel/parameter_broadcast.py +151 -0
- mindspore/parallel/shard.py +279 -37
- mindspore/parallel/transform_safetensors.py +993 -0
- mindspore/pgodb140.dll +0 -0
- mindspore/pgort140.dll +0 -0
- mindspore/profiler/__init__.py +4 -2
- mindspore/profiler/common/constant.py +29 -0
- mindspore/profiler/common/process_pool.py +41 -0
- mindspore/profiler/common/registry.py +47 -0
- mindspore/profiler/common/singleton.py +28 -0
- mindspore/profiler/common/util.py +153 -0
- mindspore/profiler/dynamic_profiler.py +694 -0
- mindspore/profiler/envprofiling.py +18 -20
- mindspore/{_extends/parallel_compile/tbe_compiler → profiler/parser/ascend_analysis}/__init__.py +1 -1
- mindspore/profiler/parser/ascend_analysis/constant.py +71 -0
- mindspore/profiler/parser/ascend_analysis/file_manager.py +180 -0
- mindspore/profiler/parser/ascend_analysis/function_event.py +185 -0
- mindspore/profiler/parser/ascend_analysis/fwk_cann_parser.py +136 -0
- mindspore/profiler/parser/ascend_analysis/fwk_file_parser.py +131 -0
- mindspore/profiler/parser/ascend_analysis/msprof_timeline_parser.py +104 -0
- mindspore/profiler/parser/ascend_analysis/path_manager.py +313 -0
- mindspore/profiler/parser/ascend_analysis/profiler_info_parser.py +123 -0
- mindspore/profiler/parser/ascend_analysis/tlv_decoder.py +86 -0
- mindspore/profiler/parser/ascend_analysis/trace_event_manager.py +75 -0
- mindspore/profiler/parser/ascend_cluster_generator.py +14 -9
- mindspore/profiler/parser/ascend_communicate_generator.py +0 -1
- mindspore/profiler/parser/ascend_flops_generator.py +20 -4
- mindspore/profiler/parser/ascend_hccl_generator.py +29 -278
- mindspore/profiler/parser/ascend_integrate_generator.py +42 -0
- mindspore/profiler/parser/ascend_memory_generator.py +185 -0
- mindspore/profiler/parser/ascend_msprof_exporter.py +148 -146
- mindspore/profiler/parser/ascend_msprof_generator.py +73 -283
- mindspore/profiler/parser/ascend_op_generator.py +92 -42
- mindspore/profiler/parser/ascend_timeline_generator.py +298 -133
- mindspore/profiler/parser/base_timeline_generator.py +25 -25
- mindspore/profiler/parser/cpu_gpu_timeline_generator.py +25 -12
- mindspore/profiler/parser/framework_parser.py +4 -393
- mindspore/profiler/parser/gpu_analysis/__init__.py +14 -0
- mindspore/profiler/parser/gpu_analysis/function_event.py +44 -0
- mindspore/profiler/parser/gpu_analysis/fwk_file_parser.py +89 -0
- mindspore/profiler/parser/gpu_analysis/profiler_info_parser.py +72 -0
- mindspore/profiler/parser/integrator.py +3 -1
- mindspore/profiler/parser/memory_usage_parser.py +0 -154
- mindspore/profiler/parser/minddata_parser.py +72 -3
- mindspore/profiler/parser/profiler_info.py +94 -7
- mindspore/profiler/profiler.py +153 -0
- mindspore/profiler/profiling.py +631 -508
- mindspore/rewrite/__init__.py +2 -14
- mindspore/rewrite/api/node.py +122 -36
- mindspore/rewrite/api/pattern_engine.py +2 -3
- mindspore/rewrite/api/scoped_value.py +16 -15
- mindspore/rewrite/api/symbol_tree.py +45 -29
- mindspore/rewrite/ast_helpers/__init__.py +3 -6
- mindspore/rewrite/ast_helpers/ast_converter.py +143 -0
- mindspore/rewrite/ast_helpers/ast_finder.py +48 -0
- mindspore/rewrite/ast_helpers/ast_flattener.py +268 -0
- mindspore/rewrite/ast_helpers/ast_modifier.py +160 -92
- mindspore/rewrite/common/__init__.py +1 -2
- mindspore/rewrite/common/config.py +24 -0
- mindspore/rewrite/common/{rewrite_elog.py → error_log.py} +39 -39
- mindspore/rewrite/{namer.py → common/namer.py} +63 -18
- mindspore/rewrite/common/namespace.py +118 -0
- mindspore/rewrite/node/__init__.py +5 -5
- mindspore/rewrite/node/call_function.py +23 -7
- mindspore/rewrite/node/cell_container.py +7 -3
- mindspore/rewrite/node/control_flow.py +53 -28
- mindspore/rewrite/node/node.py +212 -196
- mindspore/rewrite/node/node_manager.py +51 -22
- mindspore/rewrite/node/node_topological_manager.py +3 -23
- mindspore/rewrite/parsers/__init__.py +12 -0
- mindspore/rewrite/parsers/arguments_parser.py +8 -9
- mindspore/rewrite/parsers/assign_parser.py +637 -413
- mindspore/rewrite/parsers/attribute_parser.py +3 -4
- mindspore/rewrite/parsers/class_def_parser.py +115 -148
- mindspore/rewrite/parsers/constant_parser.py +5 -5
- mindspore/rewrite/parsers/container_parser.py +4 -6
- mindspore/rewrite/parsers/expr_parser.py +55 -0
- mindspore/rewrite/parsers/for_parser.py +31 -98
- mindspore/rewrite/parsers/function_def_parser.py +13 -5
- mindspore/rewrite/parsers/if_parser.py +28 -10
- mindspore/rewrite/parsers/module_parser.py +8 -182
- mindspore/rewrite/parsers/parser.py +1 -5
- mindspore/rewrite/parsers/parser_register.py +1 -1
- mindspore/rewrite/parsers/return_parser.py +5 -10
- mindspore/rewrite/parsers/while_parser.py +59 -0
- mindspore/rewrite/sparsify/utils.py +1 -1
- mindspore/rewrite/symbol_tree/__init__.py +20 -0
- mindspore/rewrite/{symbol_tree.py → symbol_tree/symbol_tree.py} +705 -186
- mindspore/rewrite/{symbol_tree_builder.py → symbol_tree/symbol_tree_builder.py} +8 -8
- mindspore/rewrite/{symbol_tree_dumper.py → symbol_tree/symbol_tree_dumper.py} +4 -4
- mindspore/run_check/_check_version.py +40 -115
- mindspore/run_check/run_check.py +1 -1
- mindspore/safeguard/rewrite_obfuscation.py +597 -263
- mindspore/swresample-4.dll +0 -0
- mindspore/swscale-6.dll +0 -0
- mindspore/tbbmalloc.dll +0 -0
- mindspore/tinyxml2.dll +0 -0
- mindspore/train/__init__.py +7 -5
- mindspore/train/_utils.py +204 -4
- mindspore/train/amp.py +335 -295
- mindspore/train/anf_ir_pb2.py +14 -2
- mindspore/train/callback/__init__.py +5 -2
- mindspore/train/callback/_backup_and_restore.py +5 -5
- mindspore/train/callback/_callback.py +4 -4
- mindspore/train/callback/_checkpoint.py +220 -43
- mindspore/train/callback/_cluster_monitor.py +201 -0
- mindspore/train/callback/_early_stop.py +2 -2
- mindspore/train/callback/_flops_collector.py +239 -0
- mindspore/train/callback/_landscape.py +15 -9
- mindspore/train/callback/_loss_monitor.py +5 -5
- mindspore/train/callback/_on_request_exit.py +136 -33
- mindspore/train/callback/_reduce_lr_on_plateau.py +2 -2
- mindspore/train/callback/_summary_collector.py +12 -12
- mindspore/train/callback/_tft_register.py +352 -0
- mindspore/train/callback/_time_monitor.py +3 -3
- mindspore/train/data_sink.py +6 -5
- mindspore/train/dataset_helper.py +66 -23
- mindspore/train/loss_scale_manager.py +2 -2
- mindspore/train/metrics/accuracy.py +7 -7
- mindspore/train/metrics/confusion_matrix.py +8 -6
- mindspore/train/metrics/cosine_similarity.py +6 -4
- mindspore/train/metrics/error.py +2 -2
- mindspore/train/metrics/metric.py +3 -3
- mindspore/train/metrics/perplexity.py +2 -1
- mindspore/train/metrics/roc.py +4 -4
- mindspore/train/metrics/topk.py +2 -2
- mindspore/train/mind_ir_pb2.py +116 -37
- mindspore/train/model.py +382 -76
- mindspore/train/serialization.py +787 -288
- mindspore/train/summary/_summary_adapter.py +1 -1
- mindspore/train/summary/summary_record.py +51 -28
- mindspore/train/train_thor/convert_utils.py +3 -3
- mindspore/turbojpeg.dll +0 -0
- mindspore/utils/__init__.py +21 -0
- mindspore/utils/utils.py +60 -0
- mindspore/vcmeta.dll +0 -0
- mindspore/vcruntime140.dll +0 -0
- mindspore/vcruntime140_1.dll +0 -0
- mindspore/version.py +1 -1
- {mindspore-2.2.14.dist-info → mindspore-2.4.0.dist-info}/METADATA +8 -4
- mindspore-2.4.0.dist-info/RECORD +1406 -0
- {mindspore-2.2.14.dist-info → mindspore-2.4.0.dist-info}/entry_points.txt +1 -0
- mindspore/_extends/parallel_compile/tbe_compiler/tbe_adapter.py +0 -662
- mindspore/_extends/parallel_compile/tbe_compiler/tbe_helper.py +0 -377
- mindspore/_extends/parallel_compile/tbe_compiler/tbe_job.py +0 -201
- mindspore/_extends/parallel_compile/tbe_compiler/tbe_job_manager.py +0 -515
- mindspore/gen_ops.py +0 -273
- mindspore/include/c_api/ms/abstract.h +0 -67
- mindspore/include/c_api/ms/attribute.h +0 -197
- mindspore/include/c_api/ms/base/handle_types.h +0 -43
- mindspore/include/c_api/ms/base/macros.h +0 -32
- mindspore/include/c_api/ms/base/status.h +0 -33
- mindspore/include/c_api/ms/base/types.h +0 -282
- mindspore/include/c_api/ms/context.h +0 -102
- mindspore/include/c_api/ms/graph.h +0 -160
- mindspore/include/c_api/ms/node.h +0 -606
- mindspore/include/c_api/ms/tensor.h +0 -161
- mindspore/include/c_api/ms/value.h +0 -84
- mindspore/mindspore_shared_lib.dll +0 -0
- mindspore/nn/layer/flash_attention.py +0 -189
- mindspore/ops/_op_impl/aicpu/strided_slice_v2.py +0 -93
- mindspore/ops/_op_impl/aicpu/strided_slice_v2_grad.py +0 -66
- mindspore/ops/_op_impl/cpu/concat.py +0 -39
- mindspore/ops/_op_impl/cpu/tensor_shape.py +0 -42
- mindspore/ops/_op_impl/tbe/__init__.py +0 -47
- mindspore/ops/_op_impl/tbe/abs.py +0 -38
- mindspore/ops/_op_impl/tbe/abs_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/abs_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/abs_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/accumulate_n_v2.py +0 -41
- mindspore/ops/_op_impl/tbe/accumulate_n_v2_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/acos.py +0 -37
- mindspore/ops/_op_impl/tbe/acos_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/acos_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/acos_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/acosh.py +0 -37
- mindspore/ops/_op_impl/tbe/acosh_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/acosh_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/acosh_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/act_ulq_clamp_max_grad.py +0 -38
- mindspore/ops/_op_impl/tbe/act_ulq_clamp_min_grad.py +0 -38
- mindspore/ops/_op_impl/tbe/acts_ulq.py +0 -45
- mindspore/ops/_op_impl/tbe/acts_ulq_input_grad.py +0 -38
- mindspore/ops/_op_impl/tbe/adam_apply_one.py +0 -50
- mindspore/ops/_op_impl/tbe/adam_apply_one_assign.py +0 -53
- mindspore/ops/_op_impl/tbe/adam_apply_one_ds.py +0 -51
- mindspore/ops/_op_impl/tbe/adam_apply_one_with_decay.py +0 -54
- mindspore/ops/_op_impl/tbe/adam_apply_one_with_decay_assign.py +0 -54
- mindspore/ops/_op_impl/tbe/adam_apply_one_with_decay_ds.py +0 -55
- mindspore/ops/_op_impl/tbe/adaptive_max_pool2d.py +0 -37
- mindspore/ops/_op_impl/tbe/add.py +0 -42
- mindspore/ops/_op_impl/tbe/add_ds.py +0 -43
- mindspore/ops/_op_impl/tbe/add_n.py +0 -39
- mindspore/ops/_op_impl/tbe/add_n_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/addcdiv.py +0 -41
- mindspore/ops/_op_impl/tbe/addcdiv_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/addcmul.py +0 -43
- mindspore/ops/_op_impl/tbe/addcmul_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/apply_ada_max.py +0 -68
- mindspore/ops/_op_impl/tbe/apply_ada_max_ds.py +0 -69
- mindspore/ops/_op_impl/tbe/apply_adadelta.py +0 -66
- mindspore/ops/_op_impl/tbe/apply_adadelta_ds.py +0 -67
- mindspore/ops/_op_impl/tbe/apply_adagrad.py +0 -55
- mindspore/ops/_op_impl/tbe/apply_adagrad_d_a.py +0 -67
- mindspore/ops/_op_impl/tbe/apply_adagrad_ds.py +0 -56
- mindspore/ops/_op_impl/tbe/apply_adagrad_v2.py +0 -48
- mindspore/ops/_op_impl/tbe/apply_adagrad_v2_ds.py +0 -49
- mindspore/ops/_op_impl/tbe/apply_adam.py +0 -79
- mindspore/ops/_op_impl/tbe/apply_adam_ds.py +0 -80
- mindspore/ops/_op_impl/tbe/apply_adam_with_amsgrad.py +0 -60
- mindspore/ops/_op_impl/tbe/apply_adam_with_amsgrad_ds.py +0 -61
- mindspore/ops/_op_impl/tbe/apply_add_sign.py +0 -65
- mindspore/ops/_op_impl/tbe/apply_add_sign_ds.py +0 -66
- mindspore/ops/_op_impl/tbe/apply_centered_rms_prop.py +0 -77
- mindspore/ops/_op_impl/tbe/apply_centered_rms_prop_ds.py +0 -78
- mindspore/ops/_op_impl/tbe/apply_ftrl.py +0 -67
- mindspore/ops/_op_impl/tbe/apply_ftrl_ds.py +0 -68
- mindspore/ops/_op_impl/tbe/apply_gradient_descent.py +0 -44
- mindspore/ops/_op_impl/tbe/apply_gradient_descent_ds.py +0 -45
- mindspore/ops/_op_impl/tbe/apply_keras_momentum.py +0 -49
- mindspore/ops/_op_impl/tbe/apply_momentum.py +0 -64
- mindspore/ops/_op_impl/tbe/apply_momentum_ds.py +0 -65
- mindspore/ops/_op_impl/tbe/apply_power_sign.py +0 -65
- mindspore/ops/_op_impl/tbe/apply_power_sign_ds.py +0 -66
- mindspore/ops/_op_impl/tbe/apply_proximal_adagrad.py +0 -57
- mindspore/ops/_op_impl/tbe/apply_proximal_adagrad_ds.py +0 -58
- mindspore/ops/_op_impl/tbe/apply_proximal_gradient_descent.py +0 -54
- mindspore/ops/_op_impl/tbe/apply_proximal_gradient_descent_ds.py +0 -55
- mindspore/ops/_op_impl/tbe/apply_rms_prop.py +0 -52
- mindspore/ops/_op_impl/tbe/approximate_equal.py +0 -39
- mindspore/ops/_op_impl/tbe/approximate_equal_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/arg_max.py +0 -38
- mindspore/ops/_op_impl/tbe/arg_max_with_value.py +0 -38
- mindspore/ops/_op_impl/tbe/arg_max_with_value_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/arg_min.py +0 -38
- mindspore/ops/_op_impl/tbe/arg_min_v2_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/arg_min_with_value.py +0 -38
- mindspore/ops/_op_impl/tbe/arg_min_with_value_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/asin.py +0 -37
- mindspore/ops/_op_impl/tbe/asin_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/asin_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/asin_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/asinh.py +0 -37
- mindspore/ops/_op_impl/tbe/asinh_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/asinh_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/asinh_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/assign.py +0 -79
- mindspore/ops/_op_impl/tbe/assign_add.py +0 -59
- mindspore/ops/_op_impl/tbe/assign_add_ds.py +0 -60
- mindspore/ops/_op_impl/tbe/assign_ds.py +0 -80
- mindspore/ops/_op_impl/tbe/assign_sub.py +0 -55
- mindspore/ops/_op_impl/tbe/assign_sub_ds.py +0 -56
- mindspore/ops/_op_impl/tbe/atan.py +0 -37
- mindspore/ops/_op_impl/tbe/atan2.py +0 -38
- mindspore/ops/_op_impl/tbe/atan2_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/atan_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/atan_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/atan_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/atanh.py +0 -37
- mindspore/ops/_op_impl/tbe/atanh_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/avg_pool.py +0 -43
- mindspore/ops/_op_impl/tbe/avg_pool_3d.py +0 -44
- mindspore/ops/_op_impl/tbe/avg_pool_3d_grad.py +0 -45
- mindspore/ops/_op_impl/tbe/avg_pool_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/avg_pool_grad.py +0 -42
- mindspore/ops/_op_impl/tbe/avg_pool_grad_vm.py +0 -42
- mindspore/ops/_op_impl/tbe/basic_lstm_cell.py +0 -57
- mindspore/ops/_op_impl/tbe/basic_lstm_cell_c_state_grad.py +0 -50
- mindspore/ops/_op_impl/tbe/basic_lstm_cell_c_state_grad_v2.py +0 -51
- mindspore/ops/_op_impl/tbe/basic_lstm_cell_input_grad.py +0 -42
- mindspore/ops/_op_impl/tbe/basic_lstm_cell_weight_grad.py +0 -41
- mindspore/ops/_op_impl/tbe/batch_matmul.py +0 -42
- mindspore/ops/_op_impl/tbe/batch_matmul_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/batch_matmul_v2.py +0 -47
- mindspore/ops/_op_impl/tbe/batch_to_space.py +0 -38
- mindspore/ops/_op_impl/tbe/batch_to_space_nd.py +0 -38
- mindspore/ops/_op_impl/tbe/batch_to_space_nd_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/batch_to_space_nd_v2.py +0 -41
- mindspore/ops/_op_impl/tbe/batchnorm.py +0 -58
- mindspore/ops/_op_impl/tbe/batchnorm_grad.py +0 -58
- mindspore/ops/_op_impl/tbe/bce_with_logits_loss.py +0 -42
- mindspore/ops/_op_impl/tbe/bessel_i0e.py +0 -37
- mindspore/ops/_op_impl/tbe/bessel_i0e_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/bessel_i1e.py +0 -37
- mindspore/ops/_op_impl/tbe/bessel_i1e_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/bias_add.py +0 -38
- mindspore/ops/_op_impl/tbe/bias_add_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/bias_add_grad.py +0 -53
- mindspore/ops/_op_impl/tbe/binary_cross_entropy.py +0 -39
- mindspore/ops/_op_impl/tbe/binary_cross_entropy_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/binary_cross_entropy_grad.py +0 -44
- mindspore/ops/_op_impl/tbe/binary_cross_entropy_grad_ds.py +0 -45
- mindspore/ops/_op_impl/tbe/bitwise_and.py +0 -39
- mindspore/ops/_op_impl/tbe/bitwise_and_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/bitwise_or.py +0 -39
- mindspore/ops/_op_impl/tbe/bitwise_or_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/bitwise_xor.py +0 -39
- mindspore/ops/_op_impl/tbe/bitwise_xor_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/bn_infer.py +0 -43
- mindspore/ops/_op_impl/tbe/bn_infer_ds.py +0 -45
- mindspore/ops/_op_impl/tbe/bn_infer_grad.py +0 -41
- mindspore/ops/_op_impl/tbe/bn_infer_grad_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/bn_inference.py +0 -50
- mindspore/ops/_op_impl/tbe/bn_training_reduce.py +0 -38
- mindspore/ops/_op_impl/tbe/bn_training_reduce_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/bn_training_reduce_grad.py +0 -46
- mindspore/ops/_op_impl/tbe/bn_training_reduce_grad_ds.py +0 -47
- mindspore/ops/_op_impl/tbe/bn_training_update.py +0 -52
- mindspore/ops/_op_impl/tbe/bn_training_update_ds.py +0 -53
- mindspore/ops/_op_impl/tbe/bn_training_update_grad.py +0 -44
- mindspore/ops/_op_impl/tbe/bn_training_update_grad_ds.py +0 -45
- mindspore/ops/_op_impl/tbe/bn_training_update_v2.py +0 -48
- mindspore/ops/_op_impl/tbe/bn_training_update_v3.py +0 -51
- mindspore/ops/_op_impl/tbe/bounding_box_decode.py +0 -41
- mindspore/ops/_op_impl/tbe/bounding_box_decode_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/bounding_box_encode.py +0 -38
- mindspore/ops/_op_impl/tbe/broadcast_to.py +0 -40
- mindspore/ops/_op_impl/tbe/broadcast_to_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/cast.py +0 -55
- mindspore/ops/_op_impl/tbe/cast_ds.py +0 -58
- mindspore/ops/_op_impl/tbe/cdist.py +0 -38
- mindspore/ops/_op_impl/tbe/cdist_grad.py +0 -42
- mindspore/ops/_op_impl/tbe/ceil.py +0 -37
- mindspore/ops/_op_impl/tbe/ceil_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/celu.py +0 -39
- mindspore/ops/_op_impl/tbe/centralization.py +0 -39
- mindspore/ops/_op_impl/tbe/check_valid.py +0 -38
- mindspore/ops/_op_impl/tbe/check_valid_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/clip_by_norm_no_div_sum.py +0 -41
- mindspore/ops/_op_impl/tbe/clip_by_norm_no_div_sum_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/clip_by_value.py +0 -41
- mindspore/ops/_op_impl/tbe/clip_by_value_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/concat.py +0 -40
- mindspore/ops/_op_impl/tbe/concat_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/confusion_matrix.py +0 -63
- mindspore/ops/_op_impl/tbe/confusion_mul_grad.py +0 -40
- mindspore/ops/_op_impl/tbe/confusion_softmax_grad.py +0 -41
- mindspore/ops/_op_impl/tbe/confusion_transpose_d.py +0 -39
- mindspore/ops/_op_impl/tbe/conv2d.py +0 -47
- mindspore/ops/_op_impl/tbe/conv2d_backprop_filter.py +0 -42
- mindspore/ops/_op_impl/tbe/conv2d_backprop_filter_ds.py +0 -43
- mindspore/ops/_op_impl/tbe/conv2d_backprop_input.py +0 -42
- mindspore/ops/_op_impl/tbe/conv2d_backprop_input_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/conv2d_ds.py +0 -47
- mindspore/ops/_op_impl/tbe/conv2d_transpose.py +0 -48
- mindspore/ops/_op_impl/tbe/conv3d.py +0 -45
- mindspore/ops/_op_impl/tbe/conv3d_backprop_filter.py +0 -42
- mindspore/ops/_op_impl/tbe/conv3d_backprop_input.py +0 -42
- mindspore/ops/_op_impl/tbe/conv3d_transpose.py +0 -47
- mindspore/ops/_op_impl/tbe/conv3d_transpose_ds.py +0 -48
- mindspore/ops/_op_impl/tbe/cos.py +0 -37
- mindspore/ops/_op_impl/tbe/cos_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/cosh.py +0 -37
- mindspore/ops/_op_impl/tbe/cosh_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/ctc_loss_v2.py +0 -42
- mindspore/ops/_op_impl/tbe/ctc_loss_v2_grad.py +0 -44
- mindspore/ops/_op_impl/tbe/cum_sum.py +0 -42
- mindspore/ops/_op_impl/tbe/cum_sum_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/cummin.py +0 -41
- mindspore/ops/_op_impl/tbe/cumprod.py +0 -42
- mindspore/ops/_op_impl/tbe/data_format_dim_map.py +0 -38
- mindspore/ops/_op_impl/tbe/data_format_dim_map_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/deformable_offsets.py +0 -45
- mindspore/ops/_op_impl/tbe/deformable_offsets_grad.py +0 -48
- mindspore/ops/_op_impl/tbe/depth_to_space_ds.py +0 -49
- mindspore/ops/_op_impl/tbe/depthwise_conv2d.py +0 -44
- mindspore/ops/_op_impl/tbe/depthwise_conv2d_backprop_filter.py +0 -41
- mindspore/ops/_op_impl/tbe/depthwise_conv2d_backprop_input.py +0 -41
- mindspore/ops/_op_impl/tbe/diag.py +0 -38
- mindspore/ops/_op_impl/tbe/diag_part.py +0 -38
- mindspore/ops/_op_impl/tbe/dilation.py +0 -40
- mindspore/ops/_op_impl/tbe/div.py +0 -41
- mindspore/ops/_op_impl/tbe/div_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/div_no_nan.py +0 -41
- mindspore/ops/_op_impl/tbe/div_no_nan_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/dropout_do_mask.py +0 -38
- mindspore/ops/_op_impl/tbe/dropout_do_mask_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/dropout_do_mask_v3.py +0 -39
- mindspore/ops/_op_impl/tbe/dynamic_atomic_addr_clean.py +0 -34
- mindspore/ops/_op_impl/tbe/dynamic_gru_v2.py +0 -95
- mindspore/ops/_op_impl/tbe/dynamic_rnn.py +0 -82
- mindspore/ops/_op_impl/tbe/elu.py +0 -38
- mindspore/ops/_op_impl/tbe/elu_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/elu_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/elu_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/equal.py +0 -42
- mindspore/ops/_op_impl/tbe/equal_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/erf.py +0 -37
- mindspore/ops/_op_impl/tbe/erf_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/erfc.py +0 -37
- mindspore/ops/_op_impl/tbe/erfc_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/erfinv.py +0 -36
- mindspore/ops/_op_impl/tbe/exp.py +0 -40
- mindspore/ops/_op_impl/tbe/exp_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/expand_dims.py +0 -38
- mindspore/ops/_op_impl/tbe/expm1.py +0 -37
- mindspore/ops/_op_impl/tbe/expm1_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/extract_image_patches.py +0 -41
- mindspore/ops/_op_impl/tbe/extract_volume_patches.py +0 -39
- mindspore/ops/_op_impl/tbe/fake_quant_with_min_max_vars.py +0 -39
- mindspore/ops/_op_impl/tbe/fake_quant_with_min_max_vars_gradient.py +0 -43
- mindspore/ops/_op_impl/tbe/fake_quant_with_min_max_vars_per_channel.py +0 -39
- mindspore/ops/_op_impl/tbe/fake_quant_with_min_max_vars_per_channel_gradient.py +0 -43
- mindspore/ops/_op_impl/tbe/fast_gelu.py +0 -37
- mindspore/ops/_op_impl/tbe/fast_gelu_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/fast_gelu_grad.py +0 -41
- mindspore/ops/_op_impl/tbe/fast_gelu_grad_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/fill.py +0 -56
- mindspore/ops/_op_impl/tbe/fill_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/flatten.py +0 -48
- mindspore/ops/_op_impl/tbe/floor.py +0 -37
- mindspore/ops/_op_impl/tbe/floor_div.py +0 -41
- mindspore/ops/_op_impl/tbe/floor_div_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/floor_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/floor_mod.py +0 -39
- mindspore/ops/_op_impl/tbe/floor_mod_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/fused_dbn_dw.py +0 -52
- mindspore/ops/_op_impl/tbe/fused_mul_add.py +0 -38
- mindspore/ops/_op_impl/tbe/fused_mul_add_n.py +0 -48
- mindspore/ops/_op_impl/tbe/fused_mul_add_n_l2loss.py +0 -53
- mindspore/ops/_op_impl/tbe/fused_mul_apply_momentum.py +0 -57
- mindspore/ops/_op_impl/tbe/fused_mul_apply_momentum_extern.py +0 -67
- mindspore/ops/_op_impl/tbe/gather_nd.py +0 -52
- mindspore/ops/_op_impl/tbe/gather_nd_ds.py +0 -48
- mindspore/ops/_op_impl/tbe/gather_v2.py +0 -56
- mindspore/ops/_op_impl/tbe/gather_v2_ds.py +0 -68
- mindspore/ops/_op_impl/tbe/gelu.py +0 -37
- mindspore/ops/_op_impl/tbe/gelu_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/gelu_grad.py +0 -42
- mindspore/ops/_op_impl/tbe/gelu_grad_ds.py +0 -43
- mindspore/ops/_op_impl/tbe/ger.py +0 -43
- mindspore/ops/_op_impl/tbe/ger_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/greater.py +0 -43
- mindspore/ops/_op_impl/tbe/greater_equal.py +0 -41
- mindspore/ops/_op_impl/tbe/greater_equal_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/gru_v2_hidden_grad.py +0 -51
- mindspore/ops/_op_impl/tbe/gru_v2_hidden_grad_cell.py +0 -52
- mindspore/ops/_op_impl/tbe/hard_swish.py +0 -37
- mindspore/ops/_op_impl/tbe/hard_swish_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/hard_swish_grad.py +0 -41
- mindspore/ops/_op_impl/tbe/hard_swish_grad_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/histogram_fixed_width.py +0 -40
- mindspore/ops/_op_impl/tbe/hshrink.py +0 -33
- mindspore/ops/_op_impl/tbe/hshrink_grad.py +0 -37
- mindspore/ops/_op_impl/tbe/hsigmoid.py +0 -45
- mindspore/ops/_op_impl/tbe/hsigmoid_grad.py +0 -39
- mindspore/ops/_op_impl/tbe/ifmr.py +0 -47
- mindspore/ops/_op_impl/tbe/ifmr_ds.py +0 -48
- mindspore/ops/_op_impl/tbe/im2col.py +0 -42
- mindspore/ops/_op_impl/tbe/in_top_k.py +0 -37
- mindspore/ops/_op_impl/tbe/inplace_add.py +0 -39
- mindspore/ops/_op_impl/tbe/inplace_index_add.py +0 -46
- mindspore/ops/_op_impl/tbe/inplace_sub.py +0 -39
- mindspore/ops/_op_impl/tbe/inplace_update.py +0 -39
- mindspore/ops/_op_impl/tbe/inplace_update_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/inv.py +0 -38
- mindspore/ops/_op_impl/tbe/inv_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/inv_grad.py +0 -40
- mindspore/ops/_op_impl/tbe/inv_grad_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/invert.py +0 -37
- mindspore/ops/_op_impl/tbe/invert_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/iou.py +0 -38
- mindspore/ops/_op_impl/tbe/iou_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/is_close.py +0 -40
- mindspore/ops/_op_impl/tbe/kl_div_loss.py +0 -38
- mindspore/ops/_op_impl/tbe/kl_div_loss_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/kl_div_loss_grad.py +0 -40
- mindspore/ops/_op_impl/tbe/l2_loss.py +0 -36
- mindspore/ops/_op_impl/tbe/l2_loss_ds.py +0 -37
- mindspore/ops/_op_impl/tbe/l2_normalize.py +0 -38
- mindspore/ops/_op_impl/tbe/l2_normalize_grad.py +0 -40
- mindspore/ops/_op_impl/tbe/lamb_apply_optimizer_assign.py +0 -55
- mindspore/ops/_op_impl/tbe/lamb_apply_weight_assign.py +0 -42
- mindspore/ops/_op_impl/tbe/lamb_next_mv.py +0 -59
- mindspore/ops/_op_impl/tbe/lamb_next_mv_with_decay.py +0 -59
- mindspore/ops/_op_impl/tbe/lamb_next_right.py +0 -44
- mindspore/ops/_op_impl/tbe/lamb_update_with_lr.py +0 -48
- mindspore/ops/_op_impl/tbe/lamb_update_with_lr_v2.py +0 -44
- mindspore/ops/_op_impl/tbe/lars_update.py +0 -50
- mindspore/ops/_op_impl/tbe/lars_update_ds.py +0 -51
- mindspore/ops/_op_impl/tbe/layer_norm.py +0 -46
- mindspore/ops/_op_impl/tbe/layer_norm_beta_gamma_backprop.py +0 -44
- mindspore/ops/_op_impl/tbe/layer_norm_beta_gamma_backprop_ds.py +0 -45
- mindspore/ops/_op_impl/tbe/layer_norm_beta_gamma_backprop_v2.py +0 -40
- mindspore/ops/_op_impl/tbe/layer_norm_beta_gamma_backprop_v2_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/layer_norm_ds.py +0 -47
- mindspore/ops/_op_impl/tbe/layer_norm_grad.py +0 -48
- mindspore/ops/_op_impl/tbe/layer_norm_x_backprop.py +0 -43
- mindspore/ops/_op_impl/tbe/layer_norm_x_backprop_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/layer_norm_x_backprop_v2.py +0 -45
- mindspore/ops/_op_impl/tbe/layer_norm_x_backprop_v2_ds.py +0 -45
- mindspore/ops/_op_impl/tbe/lerp.py +0 -38
- mindspore/ops/_op_impl/tbe/less.py +0 -41
- mindspore/ops/_op_impl/tbe/less_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/less_equal.py +0 -41
- mindspore/ops/_op_impl/tbe/less_equal_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/log.py +0 -40
- mindspore/ops/_op_impl/tbe/log1p.py +0 -37
- mindspore/ops/_op_impl/tbe/log1p_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/log_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/logical_and.py +0 -37
- mindspore/ops/_op_impl/tbe/logical_and_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/logical_not.py +0 -36
- mindspore/ops/_op_impl/tbe/logical_not_ds.py +0 -37
- mindspore/ops/_op_impl/tbe/logical_or.py +0 -37
- mindspore/ops/_op_impl/tbe/logical_or_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/logsoftmax.py +0 -37
- mindspore/ops/_op_impl/tbe/logsoftmax_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/logsoftmax_grad.py +0 -38
- mindspore/ops/_op_impl/tbe/logsoftmax_grad_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/lp_norm.py +0 -40
- mindspore/ops/_op_impl/tbe/lp_norm_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/lrn.py +0 -41
- mindspore/ops/_op_impl/tbe/lrn_grad.py +0 -42
- mindspore/ops/_op_impl/tbe/lstm_input_grad.py +0 -51
- mindspore/ops/_op_impl/tbe/masked_fill.py +0 -40
- mindspore/ops/_op_impl/tbe/masked_fill_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/matmul.py +0 -53
- mindspore/ops/_op_impl/tbe/matmul_ds.py +0 -47
- mindspore/ops/_op_impl/tbe/matmul_v2.py +0 -50
- mindspore/ops/_op_impl/tbe/matrix_diag.py +0 -45
- mindspore/ops/_op_impl/tbe/matrix_diag_part.py +0 -45
- mindspore/ops/_op_impl/tbe/matrix_set_diag.py +0 -46
- mindspore/ops/_op_impl/tbe/max_pool.py +0 -39
- mindspore/ops/_op_impl/tbe/max_pool3d.py +0 -44
- mindspore/ops/_op_impl/tbe/max_pool3d_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/max_pool3d_grad_grad.py +0 -44
- mindspore/ops/_op_impl/tbe/max_pool_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/max_pool_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/max_pool_grad_grad.py +0 -41
- mindspore/ops/_op_impl/tbe/max_pool_grad_grad_with_argmax.py +0 -41
- mindspore/ops/_op_impl/tbe/max_pool_grad_with_argmax.py +0 -42
- mindspore/ops/_op_impl/tbe/max_pool_with_argmax.py +0 -40
- mindspore/ops/_op_impl/tbe/maximum.py +0 -39
- mindspore/ops/_op_impl/tbe/maximum_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/maximum_grad.py +0 -46
- mindspore/ops/_op_impl/tbe/maximum_grad_ds.py +0 -47
- mindspore/ops/_op_impl/tbe/mem_set.py +0 -38
- mindspore/ops/_op_impl/tbe/minimum.py +0 -40
- mindspore/ops/_op_impl/tbe/minimum_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/minimum_grad.py +0 -46
- mindspore/ops/_op_impl/tbe/minimum_grad_ds.py +0 -47
- mindspore/ops/_op_impl/tbe/mish.py +0 -37
- mindspore/ops/_op_impl/tbe/mod.py +0 -41
- mindspore/ops/_op_impl/tbe/mod_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/mul.py +0 -37
- mindspore/ops/_op_impl/tbe/mul_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/mul_no_nan.py +0 -39
- mindspore/ops/_op_impl/tbe/mul_no_nan_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/multilabel_margin_loss.py +0 -39
- mindspore/ops/_op_impl/tbe/neg.py +0 -39
- mindspore/ops/_op_impl/tbe/neg_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/new_im2col.py +0 -40
- mindspore/ops/_op_impl/tbe/nll_loss.py +0 -41
- mindspore/ops/_op_impl/tbe/nll_loss_grad.py +0 -44
- mindspore/ops/_op_impl/tbe/nms_with_mask.py +0 -39
- mindspore/ops/_op_impl/tbe/not_equal.py +0 -41
- mindspore/ops/_op_impl/tbe/not_equal_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/npu_alloc_float_status.py +0 -34
- mindspore/ops/_op_impl/tbe/npu_clear_float_status.py +0 -35
- mindspore/ops/_op_impl/tbe/npu_clear_float_status_v2.py +0 -35
- mindspore/ops/_op_impl/tbe/npu_get_float_status.py +0 -35
- mindspore/ops/_op_impl/tbe/npu_get_float_status_v2.py +0 -35
- mindspore/ops/_op_impl/tbe/one_hot.py +0 -48
- mindspore/ops/_op_impl/tbe/one_hot_ds.py +0 -45
- mindspore/ops/_op_impl/tbe/ones_like.py +0 -40
- mindspore/ops/_op_impl/tbe/ones_like_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/p_s_r_o_i_pooling.py +0 -40
- mindspore/ops/_op_impl/tbe/p_s_r_o_i_pooling_grad.py +0 -40
- mindspore/ops/_op_impl/tbe/pack.py +0 -58
- mindspore/ops/_op_impl/tbe/pack_ds.py +0 -59
- mindspore/ops/_op_impl/tbe/pad_d.py +0 -40
- mindspore/ops/_op_impl/tbe/pad_d_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/parallel_concat.py +0 -70
- mindspore/ops/_op_impl/tbe/parallel_resize_bilinear.py +0 -45
- mindspore/ops/_op_impl/tbe/parallel_resize_bilinear_grad.py +0 -44
- mindspore/ops/_op_impl/tbe/pdist.py +0 -36
- mindspore/ops/_op_impl/tbe/pooling.py +0 -46
- mindspore/ops/_op_impl/tbe/population_count.py +0 -38
- mindspore/ops/_op_impl/tbe/pow.py +0 -41
- mindspore/ops/_op_impl/tbe/pow_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/prelu.py +0 -37
- mindspore/ops/_op_impl/tbe/prelu_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/prelu_grad.py +0 -40
- mindspore/ops/_op_impl/tbe/range.py +0 -39
- mindspore/ops/_op_impl/tbe/real_div.py +0 -38
- mindspore/ops/_op_impl/tbe/real_div_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/reciprocal.py +0 -36
- mindspore/ops/_op_impl/tbe/reciprocal_ds.py +0 -37
- mindspore/ops/_op_impl/tbe/reciprocal_grad.py +0 -38
- mindspore/ops/_op_impl/tbe/reciprocal_grad_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/reduce_all.py +0 -38
- mindspore/ops/_op_impl/tbe/reduce_all_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/reduce_any.py +0 -38
- mindspore/ops/_op_impl/tbe/reduce_any_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/reduce_max.py +0 -43
- mindspore/ops/_op_impl/tbe/reduce_max_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/reduce_mean.py +0 -40
- mindspore/ops/_op_impl/tbe/reduce_mean_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/reduce_min.py +0 -41
- mindspore/ops/_op_impl/tbe/reduce_min_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/reduce_prod.py +0 -42
- mindspore/ops/_op_impl/tbe/reduce_prod_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/reduce_std.py +0 -44
- mindspore/ops/_op_impl/tbe/reduce_sum.py +0 -39
- mindspore/ops/_op_impl/tbe/reduce_sum_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/relu.py +0 -39
- mindspore/ops/_op_impl/tbe/relu6.py +0 -38
- mindspore/ops/_op_impl/tbe/relu6_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/relu6_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/relu6_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/relu_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/relu_grad.py +0 -41
- mindspore/ops/_op_impl/tbe/relu_grad_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/relu_grad_v2.py +0 -40
- mindspore/ops/_op_impl/tbe/relu_grad_v2_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/relu_v2.py +0 -40
- mindspore/ops/_op_impl/tbe/relu_v2_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/renorm.py +0 -39
- mindspore/ops/_op_impl/tbe/resize_bilinear.py +0 -40
- mindspore/ops/_op_impl/tbe/resize_bilinear_grad.py +0 -41
- mindspore/ops/_op_impl/tbe/resize_bilinear_v2.py +0 -43
- mindspore/ops/_op_impl/tbe/resize_nearest_neighbor.py +0 -40
- mindspore/ops/_op_impl/tbe/resize_nearest_neighbor_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/resize_nearest_neighbor_grad.py +0 -39
- mindspore/ops/_op_impl/tbe/resize_nearest_neighbor_grad_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/reverse_v2_d.py +0 -37
- mindspore/ops/_op_impl/tbe/rint.py +0 -37
- mindspore/ops/_op_impl/tbe/rint_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/roi_align.py +0 -43
- mindspore/ops/_op_impl/tbe/roi_align_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/roi_align_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/roi_align_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/roll.py +0 -42
- mindspore/ops/_op_impl/tbe/round.py +0 -38
- mindspore/ops/_op_impl/tbe/round_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/rsqrt.py +0 -37
- mindspore/ops/_op_impl/tbe/rsqrt_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/rsqrt_grad.py +0 -40
- mindspore/ops/_op_impl/tbe/rsqrt_grad_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/scatter_add.py +0 -44
- mindspore/ops/_op_impl/tbe/scatter_div.py +0 -46
- mindspore/ops/_op_impl/tbe/scatter_max.py +0 -45
- mindspore/ops/_op_impl/tbe/scatter_min.py +0 -45
- mindspore/ops/_op_impl/tbe/scatter_mul.py +0 -44
- mindspore/ops/_op_impl/tbe/scatter_nd.py +0 -41
- mindspore/ops/_op_impl/tbe/scatter_nd_add.py +0 -45
- mindspore/ops/_op_impl/tbe/scatter_nd_d.py +0 -41
- mindspore/ops/_op_impl/tbe/scatter_nd_ds.py +0 -49
- mindspore/ops/_op_impl/tbe/scatter_nd_sub.py +0 -47
- mindspore/ops/_op_impl/tbe/scatter_nd_sub_ds.py +0 -48
- mindspore/ops/_op_impl/tbe/scatter_nd_update.py +0 -47
- mindspore/ops/_op_impl/tbe/scatter_nd_update_ds.py +0 -48
- mindspore/ops/_op_impl/tbe/scatter_non_aliasing_add.py +0 -39
- mindspore/ops/_op_impl/tbe/scatter_non_aliasing_add_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/scatter_sub.py +0 -47
- mindspore/ops/_op_impl/tbe/scatter_sub_ds.py +0 -48
- mindspore/ops/_op_impl/tbe/scatter_update.py +0 -43
- mindspore/ops/_op_impl/tbe/select.py +0 -38
- mindspore/ops/_op_impl/tbe/select_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/selu.py +0 -39
- mindspore/ops/_op_impl/tbe/selu_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/sgd.py +0 -62
- mindspore/ops/_op_impl/tbe/sigmoid.py +0 -37
- mindspore/ops/_op_impl/tbe/sigmoid_cross_entropy_with_logits.py +0 -41
- mindspore/ops/_op_impl/tbe/sigmoid_cross_entropy_with_logits_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/sigmoid_cross_entropy_with_logits_grad.py +0 -42
- mindspore/ops/_op_impl/tbe/sigmoid_cross_entropy_with_logits_grad_ds.py +0 -43
- mindspore/ops/_op_impl/tbe/sigmoid_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/sigmoid_grad.py +0 -39
- mindspore/ops/_op_impl/tbe/sigmoid_grad_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/sign.py +0 -38
- mindspore/ops/_op_impl/tbe/sign_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/sin.py +0 -37
- mindspore/ops/_op_impl/tbe/sin_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/sinh.py +0 -37
- mindspore/ops/_op_impl/tbe/sinh_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/slice.py +0 -58
- mindspore/ops/_op_impl/tbe/smooth_l1_loss.py +0 -45
- mindspore/ops/_op_impl/tbe/smooth_l1_loss_ds.py +0 -46
- mindspore/ops/_op_impl/tbe/smooth_l1_loss_grad.py +0 -46
- mindspore/ops/_op_impl/tbe/smooth_l1_loss_grad_ds.py +0 -47
- mindspore/ops/_op_impl/tbe/soft_margin_loss.py +0 -38
- mindspore/ops/_op_impl/tbe/soft_margin_loss_grad.py +0 -39
- mindspore/ops/_op_impl/tbe/soft_shrink.py +0 -36
- mindspore/ops/_op_impl/tbe/soft_shrink_grad.py +0 -38
- mindspore/ops/_op_impl/tbe/softmax.py +0 -37
- mindspore/ops/_op_impl/tbe/softmax_cross_entropy_with_logits.py +0 -38
- mindspore/ops/_op_impl/tbe/softmax_cross_entropy_with_logits_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/softmax_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/softmax_grad_ext.py +0 -42
- mindspore/ops/_op_impl/tbe/softmax_v2_with_dropout_do_mask_v3.py +0 -39
- mindspore/ops/_op_impl/tbe/softplus.py +0 -37
- mindspore/ops/_op_impl/tbe/softplus_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/softplus_grad.py +0 -38
- mindspore/ops/_op_impl/tbe/softplus_grad_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/softsign.py +0 -37
- mindspore/ops/_op_impl/tbe/softsign_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/sort.py +0 -38
- mindspore/ops/_op_impl/tbe/sort_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/space_to_batch.py +0 -38
- mindspore/ops/_op_impl/tbe/space_to_batch_nd.py +0 -38
- mindspore/ops/_op_impl/tbe/space_to_depth.py +0 -47
- mindspore/ops/_op_impl/tbe/sparse_apply_adadelta.py +0 -56
- mindspore/ops/_op_impl/tbe/sparse_apply_adagrad.py +0 -45
- mindspore/ops/_op_impl/tbe/sparse_apply_adagrad_ds.py +0 -46
- mindspore/ops/_op_impl/tbe/sparse_apply_adagrad_v2.py +0 -46
- mindspore/ops/_op_impl/tbe/sparse_apply_adagrad_v2_ds.py +0 -47
- mindspore/ops/_op_impl/tbe/sparse_apply_ftrl_d.py +0 -53
- mindspore/ops/_op_impl/tbe/sparse_apply_ftrl_d_ds.py +0 -50
- mindspore/ops/_op_impl/tbe/sparse_apply_ftrl_v2.py +0 -50
- mindspore/ops/_op_impl/tbe/sparse_apply_proximal_adagrad.py +0 -66
- mindspore/ops/_op_impl/tbe/sparse_apply_proximal_adagrad_ds.py +0 -67
- mindspore/ops/_op_impl/tbe/sparse_apply_r_m_s_prop.py +0 -57
- mindspore/ops/_op_impl/tbe/sparse_apply_r_m_s_prop_ds.py +0 -58
- mindspore/ops/_op_impl/tbe/sparse_gather_v2.py +0 -56
- mindspore/ops/_op_impl/tbe/sparse_gather_v2_ds.py +0 -58
- mindspore/ops/_op_impl/tbe/split_d.py +0 -38
- mindspore/ops/_op_impl/tbe/split_d_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/split_v.py +0 -39
- mindspore/ops/_op_impl/tbe/splitv.py +0 -39
- mindspore/ops/_op_impl/tbe/sqrt.py +0 -37
- mindspore/ops/_op_impl/tbe/sqrt_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/sqrt_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/sqrt_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/square.py +0 -38
- mindspore/ops/_op_impl/tbe/square_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/square_sum_all.py +0 -40
- mindspore/ops/_op_impl/tbe/square_sum_all_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/square_sum_v1.py +0 -38
- mindspore/ops/_op_impl/tbe/square_sum_v1_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/square_sum_v2.py +0 -39
- mindspore/ops/_op_impl/tbe/squared_difference.py +0 -39
- mindspore/ops/_op_impl/tbe/squared_difference_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/squeeze.py +0 -37
- mindspore/ops/_op_impl/tbe/strided_read.py +0 -38
- mindspore/ops/_op_impl/tbe/strided_slice_d.py +0 -44
- mindspore/ops/_op_impl/tbe/strided_slice_ds.py +0 -71
- mindspore/ops/_op_impl/tbe/strided_slice_grad_d.py +0 -51
- mindspore/ops/_op_impl/tbe/strided_slice_grad_ds.py +0 -57
- mindspore/ops/_op_impl/tbe/strided_write.py +0 -38
- mindspore/ops/_op_impl/tbe/sub.py +0 -39
- mindspore/ops/_op_impl/tbe/sub_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/tan.py +0 -38
- mindspore/ops/_op_impl/tbe/tan_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/tanh.py +0 -37
- mindspore/ops/_op_impl/tbe/tanh_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/tanh_grad.py +0 -39
- mindspore/ops/_op_impl/tbe/tanh_grad_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/tensor_move.py +0 -49
- mindspore/ops/_op_impl/tbe/tensor_move_ds.py +0 -50
- mindspore/ops/_op_impl/tbe/tensor_scatter_update.py +0 -41
- mindspore/ops/_op_impl/tbe/tile.py +0 -37
- mindspore/ops/_op_impl/tbe/tile_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/top_k.py +0 -42
- mindspore/ops/_op_impl/tbe/top_k_ds.py +0 -43
- mindspore/ops/_op_impl/tbe/trans_data.py +0 -167
- mindspore/ops/_op_impl/tbe/trans_data_ds.py +0 -180
- mindspore/ops/_op_impl/tbe/trans_data_rnn.py +0 -44
- mindspore/ops/_op_impl/tbe/transpose.py +0 -60
- mindspore/ops/_op_impl/tbe/transpose_d.py +0 -47
- mindspore/ops/_op_impl/tbe/transpose_nod.py +0 -60
- mindspore/ops/_op_impl/tbe/trunc.py +0 -39
- mindspore/ops/_op_impl/tbe/truncate_div.py +0 -41
- mindspore/ops/_op_impl/tbe/truncate_div_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/truncate_mod.py +0 -41
- mindspore/ops/_op_impl/tbe/truncate_mod_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/unpack.py +0 -38
- mindspore/ops/_op_impl/tbe/unpack_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/unsorted_segment_max.py +0 -49
- mindspore/ops/_op_impl/tbe/unsorted_segment_max_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/unsorted_segment_min.py +0 -49
- mindspore/ops/_op_impl/tbe/unsorted_segment_min_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/unsorted_segment_prod.py +0 -49
- mindspore/ops/_op_impl/tbe/unsorted_segment_prod_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/unsorted_segment_sum.py +0 -38
- mindspore/ops/_op_impl/tbe/unsorted_segment_sum_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/wts_arq.py +0 -40
- mindspore/ops/_op_impl/tbe/xdivy.py +0 -38
- mindspore/ops/_op_impl/tbe/xdivy_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/xlogy.py +0 -38
- mindspore/ops/_op_impl/tbe/xlogy_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/zeros_like.py +0 -41
- mindspore/ops/_op_impl/tbe/zeros_like_ds.py +0 -42
- mindspore/ops/_tracefunc.py +0 -241
- mindspore/ops/arg_dtype_cast.py +0 -54
- mindspore/ops/silent_check.py +0 -162
- mindspore/profiler/parser/msadvisor_analyzer.py +0 -82
- mindspore/profiler/parser/msadvisor_parser.py +0 -240
- mindspore/rewrite/api/tree_node_helper.py +0 -60
- mindspore/rewrite/ast_helpers/ast_creator.py +0 -115
- mindspore/rewrite/ast_transformers/flatten_recursive_stmt.py +0 -267
- mindspore/rewrite/ast_transformers/remove_return_out_of_if.py +0 -228
- mindspore/rewrite/namespace.py +0 -53
- mindspore-2.2.14.dist-info/RECORD +0 -1924
- {mindspore-2.2.14.dist-info → mindspore-2.4.0.dist-info}/WHEEL +0 -0
- {mindspore-2.2.14.dist-info → mindspore-2.4.0.dist-info}/top_level.txt +0 -0
|
@@ -30,6 +30,17 @@ 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 mindspore.run_check._check_version import AscendEnvChecker
|
|
34
|
+
from ..auto_generate import (CeLU, Flatten, LogSoftmax, LogSoftmaxExt, ReLU, ReLU6, Dense, Tanh,
|
|
35
|
+
Elu, Sigmoid, Softmax, SoftplusExt, HSwish, HSigmoid, AvgPool, BiasAdd,
|
|
36
|
+
NLLLoss, OneHot, GeLU, FastGeLU, PReLU, RmsNorm, IncreFlashAttention, MSELossExt,
|
|
37
|
+
GridSampler3D, GridSampler2D, LayerNorm, LayerNormExt, HShrink, AdamWeightDecay, Dropout,
|
|
38
|
+
ApplyRotaryPosEmb, PagedAttention, PagedAttentionMask, ReshapeAndCache,
|
|
39
|
+
FlashAttentionScore, Embedding, UpsampleNearest1D, UpsampleNearest2D,
|
|
40
|
+
UpsampleNearest3D, UpsampleTrilinear3D,
|
|
41
|
+
UpsampleBilinear2D, UpsampleLinear1D,
|
|
42
|
+
BinaryCrossEntropy, BCEWithLogitsLoss, SoftShrink)
|
|
43
|
+
from .manually_defined import BatchNorm
|
|
33
44
|
|
|
34
45
|
|
|
35
46
|
def _check_positive_int_or_tuple(arg_name, arg_value, prim_name, allow_four=False,
|
|
@@ -95,83 +106,6 @@ def _update_attr_by_format(arg_value, arg_format):
|
|
|
95
106
|
return ret
|
|
96
107
|
|
|
97
108
|
|
|
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
109
|
class AdaptiveAvgPool3D(Primitive):
|
|
176
110
|
r"""
|
|
177
111
|
AdaptiveAvgPool3D operation.
|
|
@@ -427,86 +361,6 @@ class AdaptiveMaxPool3D(Primitive):
|
|
|
427
361
|
self.init_prim_io_names(inputs=['x', 'output_size'], outputs=['y', 'argmax'])
|
|
428
362
|
|
|
429
363
|
|
|
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
364
|
class Softplus(Primitive):
|
|
511
365
|
r"""
|
|
512
366
|
Softplus activation function.
|
|
@@ -586,39 +440,6 @@ class Softsign(Primitive):
|
|
|
586
440
|
self.init_prim_io_names(inputs=['x'], outputs=['output'])
|
|
587
441
|
|
|
588
442
|
|
|
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
443
|
class ReLUV3(Primitive):
|
|
623
444
|
r"""
|
|
624
445
|
Computes ReLUV3 (Rectified Linear Unit activation function) of input tensors element-wise.
|
|
@@ -633,7 +454,7 @@ class ReLUV3(Primitive):
|
|
|
633
454
|
Inputs:
|
|
634
455
|
- **input_x** (Tensor) - Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
|
|
635
456
|
additional dimensions, data type is
|
|
636
|
-
`number <https://www.mindspore.cn/docs/en/
|
|
457
|
+
`number <https://www.mindspore.cn/docs/en/master/api_python/mindspore/mindspore.dtype.html>`_.
|
|
637
458
|
|
|
638
459
|
Outputs:
|
|
639
460
|
Tensor of shape :math:`(N, *)`, with the same type and shape as the `input_x`.
|
|
@@ -749,275 +570,6 @@ class SeLU(Primitive):
|
|
|
749
570
|
self.init_prim_io_names(inputs=['input_x'], outputs=['output'])
|
|
750
571
|
|
|
751
572
|
|
|
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
|
-
|
|
1020
|
-
|
|
1021
573
|
class FusedBatchNorm(Primitive):
|
|
1022
574
|
r"""
|
|
1023
575
|
The FusedBatchNorm interface is deprecated, please use the BatchNorm interface.
|
|
@@ -1229,137 +781,6 @@ class InstanceNormV2(Primitive):
|
|
|
1229
781
|
validator.check_bool(is_training, "is_training", self.name)
|
|
1230
782
|
|
|
1231
783
|
|
|
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
784
|
class Conv2D(Primitive):
|
|
1364
785
|
r"""
|
|
1365
786
|
2D convolution layer.
|
|
@@ -1379,21 +800,26 @@ class Conv2D(Primitive):
|
|
|
1379
800
|
, :math:`weight` is the convolution kernel value and :math:`X` represents the input feature map.
|
|
1380
801
|
|
|
1381
802
|
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
803
|
|
|
1384
|
-
- :math:`
|
|
804
|
+
- :math:`i` corresponds to the batch number, the range is :math:`[0, N-1]`,
|
|
805
|
+
where :math:`N` is the batch size of the input.
|
|
806
|
+
|
|
807
|
+
- :math:`j` corresponds to the output channel, the range is :math:`[0, C_{out}-1]`,
|
|
808
|
+
where :math:`C_{out}` is the number of
|
|
1385
809
|
output channels, which is also equal to the number of kernels.
|
|
1386
810
|
|
|
1387
|
-
- :math:`k` corresponds to the input channel,
|
|
811
|
+
- :math:`k` corresponds to the input channel, the range is :math:`[0, C_{in}-1]`,
|
|
812
|
+
where :math:`C_{in}` is the number of
|
|
1388
813
|
input channels, which is also equal to the number of channels in the convolutional kernels.
|
|
1389
814
|
|
|
1390
|
-
Therefore, in the above formula, :math:`{bias}(C_{
|
|
1391
|
-
output channel, :math:`{weight}(C_{
|
|
815
|
+
Therefore, in the above formula, :math:`{bias}(C_{\text{out}_j})` represents the bias of the :math:`j`-th
|
|
816
|
+
output channel, :math:`{weight}(C_{\text{out}_j}, k)` represents the slice of the :math:`j`-th convolutional
|
|
1392
817
|
kernel in the :math:`k`-th channel, and :math:`{X}(N_i, k)` represents the slice of the :math:`k`-th input
|
|
1393
818
|
channel in the :math:`i`-th batch of the input feature map.
|
|
1394
819
|
|
|
1395
|
-
The shape of the convolutional kernel is given by :math:`(
|
|
1396
|
-
where :math
|
|
820
|
+
The shape of the convolutional kernel is given by :math:`(\text{kernel_size[0]},\text{kernel_size[1]})`,
|
|
821
|
+
where :math:`\text{kernel_size[0]}`
|
|
822
|
+
and :math:`\text{kernel_size[1]}` are the height and width of the kernel, respectively.
|
|
1397
823
|
If we consider the input and output channels as well as the `group` parameter, the complete kernel shape
|
|
1398
824
|
will be :math:`(C_{out}, C_{in} / \text{group}, \text{kernel_size[0]}, \text{kernel_size[1]})`,
|
|
1399
825
|
where `group` is the number of groups dividing `x`'s input channel when applying group convolution.
|
|
@@ -1450,7 +876,7 @@ class Conv2D(Primitive):
|
|
|
1450
876
|
group (int, optional): Specifies the number of groups dividing `x`'s input channel when applying
|
|
1451
877
|
group convolution. Default: ``1`` .
|
|
1452
878
|
data_format (str, optional): The optional value for data format, is ``'NHWC'`` or ``'NCHW'`` .
|
|
1453
|
-
Default: ``"NCHW"
|
|
879
|
+
Default: ``"NCHW"``. (NHWC is only supported in GPU now.)
|
|
1454
880
|
|
|
1455
881
|
Inputs:
|
|
1456
882
|
- **x** (Tensor) - Input tensor of shape :math:`(N, C_{in}, H_{in}, W_{in})` or
|
|
@@ -1844,13 +1270,13 @@ class MaxPool(_Pool):
|
|
|
1844
1270
|
not only the height of movement but also the width of movement, or a tuple of two int numbers that
|
|
1845
1271
|
represent height and width of movement respectively. Default: ``1`` .
|
|
1846
1272
|
pad_mode (str, optional): Specifies the padding mode with a padding value of 0. It can be set to:
|
|
1847
|
-
``
|
|
1273
|
+
``'same'`` or ``'valid'`` . Default: ``'valid'`` .
|
|
1848
1274
|
|
|
1849
|
-
- ``
|
|
1275
|
+
- ``'same'``: Pad the input around its edges so that the shape of input and output
|
|
1850
1276
|
are the same when `stride` is set to ``1``.
|
|
1851
1277
|
The amount of padding to is calculated by the operator internally, If the amount is even, it is
|
|
1852
1278
|
uniformly distributed around the input, if it is odd, the excess amount goes to the right/bottom side.
|
|
1853
|
-
- ``
|
|
1279
|
+
- ``'valid'``: No padding is applied to the input, and the output returns the maximum
|
|
1854
1280
|
possible height and width. Extra pixels that could not complete a full stride will
|
|
1855
1281
|
be discarded.
|
|
1856
1282
|
|
|
@@ -1869,8 +1295,8 @@ class MaxPool(_Pool):
|
|
|
1869
1295
|
|
|
1870
1296
|
Raises:
|
|
1871
1297
|
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'
|
|
1298
|
+
ValueError: If `pad_mode` is neither ``'valid'`` nor ``'same'`` with not case sensitive.
|
|
1299
|
+
ValueError: If `data_format` is neither ``'NCHW'`` nor ``'NHWC'``.
|
|
1874
1300
|
ValueError: If `kernel_size` or `strides` is less than 1.
|
|
1875
1301
|
ValueError: If length of shape of `input` is not equal to 4.
|
|
1876
1302
|
|
|
@@ -2033,10 +1459,10 @@ class MaxPool3D(Primitive):
|
|
|
2033
1459
|
pad[3], pad[4] and pad[5] correspondingly.
|
|
2034
1460
|
ceil_mode (Union[bool, None]): Whether to use ceil instead of floor to calculate output shape.
|
|
2035
1461
|
Only effective in "pad" mode.
|
|
2036
|
-
When
|
|
1462
|
+
When `pad_mode` is ``"pad"`` and "ceil_mode" is ``None`` , `ceil_mode` will be set as ``False``.
|
|
2037
1463
|
Default: ``None`` .
|
|
2038
|
-
data_format (str) : The optional value for data format. Currently only support ``
|
|
2039
|
-
Default: ``
|
|
1464
|
+
data_format (str) : The optional value for data format. Currently only support ``"NCDHW"`` .
|
|
1465
|
+
Default: ``"NCDHW"`` .
|
|
2040
1466
|
|
|
2041
1467
|
Inputs:
|
|
2042
1468
|
- **x** (Tensor) - Tensor of shape :math:`(N, C, D_{in}, H_{in}, W_{in})`.
|
|
@@ -2049,10 +1475,10 @@ class MaxPool3D(Primitive):
|
|
|
2049
1475
|
TypeError: If `kernel_size` or `strides` is neither an int nor a tuple.
|
|
2050
1476
|
TypeError: If `pad_mode` or `data_format` is not a string.
|
|
2051
1477
|
ValueError: If numbers in `kernel_size` or `strides` are not positive.
|
|
2052
|
-
ValueError: If `pad_mode` is not one of
|
|
2053
|
-
ValueError: If `pad_mode` is
|
|
1478
|
+
ValueError: If `pad_mode` is not one of ``"SAME"``, ``"VALID"`` or ``"PAD"``.
|
|
1479
|
+
ValueError: If `pad_mode` is ``"SAME"`` or ``"VALID"``, `ceil_mode` is not ``None``.
|
|
2054
1480
|
ValueError: If `kernel_size` or `strides` is a tuple whose length is not equal to 3.
|
|
2055
|
-
ValueError: If `data_format` is not
|
|
1481
|
+
ValueError: If `data_format` is not ``"NCDHW"``.
|
|
2056
1482
|
|
|
2057
1483
|
Supported Platforms:
|
|
2058
1484
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -2278,7 +1704,7 @@ class MaxUnpool3D(Primitive):
|
|
|
2278
1704
|
ValueError: If numbers in `strides` or `ksize` is negative.
|
|
2279
1705
|
ValueError: If numbers in `pads` is negative.
|
|
2280
1706
|
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
|
|
1707
|
+
ValueError: If `data_format` is not a str or is neither ``'NCDHW'`` nor ``'NDHWC'``.
|
|
2282
1708
|
ValueError: If `output_shape` whose length is neither 0 or 5.
|
|
2283
1709
|
ValueError: If `output_shape` is not close to output size range
|
|
2284
1710
|
computed by attr `ksize, strides, pads`.
|
|
@@ -2305,112 +1731,20 @@ class MaxUnpool3D(Primitive):
|
|
|
2305
1731
|
self.ksize = _check_3d_int_or_tuple('ksize', ksize, self.name, ret_five=True)
|
|
2306
1732
|
if strides in (0, (0, 0, 0)):
|
|
2307
1733
|
strides = ksize
|
|
2308
|
-
self.strides = _check_3d_int_or_tuple('strides', strides, self.name, ret_five=True)
|
|
2309
|
-
self.pads = _check_3d_int_or_tuple('pads', pads, self.name, ret_five=True, greater_zero=False)
|
|
2310
|
-
self.data_format = validator.check_string(data_format, ['NCDHW', 'NDHWC'], 'data_format', self.name)
|
|
2311
|
-
if data_format == "NDHWC":
|
|
2312
|
-
self.ksize = (self.ksize[0], self.ksize[2], self.ksize[3], self.ksize[4], self.ksize[1])
|
|
2313
|
-
self.strides = (self.strides[0], self.strides[2], self.strides[3], self.strides[4], self.strides[1])
|
|
2314
|
-
self.pads = (self.pads[0], self.pads[2], self.pads[3], self.pads[4], self.pads[1])
|
|
2315
|
-
|
|
2316
|
-
self.add_prim_attr('ksize', self.ksize)
|
|
2317
|
-
self.add_prim_attr('strides', self.strides)
|
|
2318
|
-
self.add_prim_attr('pads', self.pads)
|
|
2319
|
-
|
|
2320
|
-
validator.check_value_type("output_shape", output_shape, [tuple], self.name)
|
|
2321
|
-
self.output_shape = output_shape
|
|
2322
|
-
|
|
2323
|
-
|
|
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)
|
|
1734
|
+
self.strides = _check_3d_int_or_tuple('strides', strides, self.name, ret_five=True)
|
|
1735
|
+
self.pads = _check_3d_int_or_tuple('pads', pads, self.name, ret_five=True, greater_zero=False)
|
|
1736
|
+
self.data_format = validator.check_string(data_format, ['NCDHW', 'NDHWC'], 'data_format', self.name)
|
|
1737
|
+
if data_format == "NDHWC":
|
|
1738
|
+
self.ksize = (self.ksize[0], self.ksize[2], self.ksize[3], self.ksize[4], self.ksize[1])
|
|
1739
|
+
self.strides = (self.strides[0], self.strides[2], self.strides[3], self.strides[4], self.strides[1])
|
|
1740
|
+
self.pads = (self.pads[0], self.pads[2], self.pads[3], self.pads[4], self.pads[1])
|
|
1741
|
+
|
|
1742
|
+
self.add_prim_attr('ksize', self.ksize)
|
|
1743
|
+
self.add_prim_attr('strides', self.strides)
|
|
1744
|
+
self.add_prim_attr('pads', self.pads)
|
|
1745
|
+
|
|
1746
|
+
validator.check_value_type("output_shape", output_shape, [tuple], self.name)
|
|
1747
|
+
self.output_shape = output_shape
|
|
2414
1748
|
|
|
2415
1749
|
|
|
2416
1750
|
class AvgPoolV1(Primitive):
|
|
@@ -2641,7 +1975,7 @@ class MaxPool3DWithArgmax(Primitive):
|
|
|
2641
1975
|
TypeError: If `ksize` , `strides` , `pads` or `dilation` is not int or tuple.
|
|
2642
1976
|
ValueError: If `ksize` or `strides` is less than 1.
|
|
2643
1977
|
ValueError: If `pads` is less than 0.
|
|
2644
|
-
ValueError: If `data_format` is not 'NCDHW'
|
|
1978
|
+
ValueError: If `data_format` is not ``'NCDHW'``.
|
|
2645
1979
|
ValueError: If `argmax_type` is not mindspore.int64 or mindspore.int32.
|
|
2646
1980
|
|
|
2647
1981
|
Supported Platforms:
|
|
@@ -2743,10 +2077,10 @@ class Conv2DTranspose(Conv2DBackpropInput):
|
|
|
2743
2077
|
TypeError: If `kernel_size`, `stride`, `pad` or `dilation` is neither an int nor a tuple.
|
|
2744
2078
|
TypeError: If `out_channel` or `group` is not an int.
|
|
2745
2079
|
ValueError: If `kernel_size`, `stride` or `dilation` is less than 1.
|
|
2746
|
-
ValueError: If `pad_mode` is not one of 'same'
|
|
2080
|
+
ValueError: If `pad_mode` is not one of ``'same'``, ``'valid'`` or ``'pad'``.
|
|
2747
2081
|
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'
|
|
2082
|
+
ValueError: If `pad_mode` it not equal to ``'pad'`` and `pad` is not equal to (0, 0, 0, 0).
|
|
2083
|
+
ValueError: If `data_format` is neither ``'NCHW'`` nor ``'NHWC'``.
|
|
2750
2084
|
|
|
2751
2085
|
Supported Platforms:
|
|
2752
2086
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -2772,146 +2106,6 @@ class Conv2DTranspose(Conv2DBackpropInput):
|
|
|
2772
2106
|
pad_list, mode, stride, dilation, group, data_format)
|
|
2773
2107
|
|
|
2774
2108
|
|
|
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
2109
|
class SoftmaxCrossEntropyWithLogits(Primitive):
|
|
2916
2110
|
r"""
|
|
2917
2111
|
Gets the softmax cross-entropy value between logits and labels with one-hot encoding.
|
|
@@ -3232,7 +2426,7 @@ class MultiMarginLoss(Primitive):
|
|
|
3232
2426
|
or float64.
|
|
3233
2427
|
- **target** (Tensor) - Ground truth labels, with shape :math:`(N,)`. Data type only support int64. The
|
|
3234
2428
|
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
|
|
2429
|
+
- **weight** (Tensor, optional) - The rescaling weight to each class with shape :math:`(C,)`. Data type only
|
|
3236
2430
|
support float16, float32 or float64.
|
|
3237
2431
|
|
|
3238
2432
|
Outputs:
|
|
@@ -3254,6 +2448,11 @@ class MultiMarginLoss(Primitive):
|
|
|
3254
2448
|
>>> print(output)
|
|
3255
2449
|
0.6666667
|
|
3256
2450
|
"""
|
|
2451
|
+
__mindspore_signature__ = (
|
|
2452
|
+
sig.make_sig('x'),
|
|
2453
|
+
sig.make_sig('target'),
|
|
2454
|
+
sig.make_sig('weight', default=None)
|
|
2455
|
+
)
|
|
3257
2456
|
|
|
3258
2457
|
@prim_attr_register
|
|
3259
2458
|
def __init__(self, p=1, margin=1.0, reduction="mean"):
|
|
@@ -3264,6 +2463,9 @@ class MultiMarginLoss(Primitive):
|
|
|
3264
2463
|
self.reduction = validator.check_string(reduction, ['none', 'sum', 'mean'], 'reduction', self.name)
|
|
3265
2464
|
self.init_prim_io_names(inputs=['x', 'target', 'weight'], outputs=['y'])
|
|
3266
2465
|
|
|
2466
|
+
def __call__(self, x, target, weight=None):
|
|
2467
|
+
return super().__call__(x, target, weight)
|
|
2468
|
+
|
|
3267
2469
|
|
|
3268
2470
|
class SoftMarginLoss(Primitive):
|
|
3269
2471
|
r"""
|
|
@@ -3412,7 +2614,9 @@ class RNNTLoss(PrimitiveWithInfer):
|
|
|
3412
2614
|
blank_label (int): blank label. Default: ``0`` .
|
|
3413
2615
|
|
|
3414
2616
|
Inputs:
|
|
3415
|
-
- **acts** (Tensor) - Tensor of shape :math:`(B, T, U, V)
|
|
2617
|
+
- **acts** (Tensor) - Tensor of shape :math:`(B, T, U, V)`, where :math:`B` is batch,
|
|
2618
|
+
:math:`T` is sequence length, :math:`U` is label length and :math:`V` is output dim.
|
|
2619
|
+
Data type must be float16 or float32.
|
|
3416
2620
|
- **labels** (Tensor) - Tensor of shape :math:`(B, U-1)`. Data type is int32.
|
|
3417
2621
|
- **input_lengths** (Tensor) - Tensor of shape :math:`(B,)`. Data type is int32.
|
|
3418
2622
|
- **label_lengths** (Tensor) - Tensor of shape :math:`(B,)`. Data type is int32.
|
|
@@ -3744,79 +2948,6 @@ class ApplyCenteredRMSProp(Primitive):
|
|
|
3744
2948
|
self.add_prim_attr('side_effect_mem', True)
|
|
3745
2949
|
|
|
3746
2950
|
|
|
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
2951
|
class L2Normalize(Primitive):
|
|
3821
2952
|
r"""
|
|
3822
2953
|
L2 Normalization Operator.
|
|
@@ -3833,8 +2964,9 @@ class L2Normalize(Primitive):
|
|
|
3833
2964
|
On Ascend, input data type of float64 is currently not supported.
|
|
3834
2965
|
|
|
3835
2966
|
Args:
|
|
3836
|
-
axis (Union[list(int), tuple(int), int]): Specify the axis for calculating the L2 norm.
|
|
3837
|
-
|
|
2967
|
+
axis (Union[list(int), tuple(int), int], optional): Specify the axis for calculating the L2 norm.
|
|
2968
|
+
Default: ``0`` .
|
|
2969
|
+
epsilon (float, optional): A small value added for numerical stability. Default: ``1e-4`` .
|
|
3838
2970
|
|
|
3839
2971
|
Inputs:
|
|
3840
2972
|
- **x** (Tensor) - Input to compute the normalization. Tensor of shape :math:`(N, *)`,
|
|
@@ -3867,276 +2999,16 @@ class L2Normalize(Primitive):
|
|
|
3867
2999
|
|
|
3868
3000
|
@prim_attr_register
|
|
3869
3001
|
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'])
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
class FastGeLU(Primitive):
|
|
4110
|
-
r"""
|
|
4111
|
-
Fast Gaussian Error Linear Units activation function.
|
|
4112
|
-
|
|
4113
|
-
Refer to :func:`mindspore.ops.fast_gelu` for more details.
|
|
4114
|
-
|
|
4115
|
-
Inputs:
|
|
4116
|
-
- **x** (Tensor) - Input to compute the FastGeLU with data type of float16 or float32.
|
|
4117
|
-
|
|
4118
|
-
Outputs:
|
|
4119
|
-
Tensor, with the same type and shape as `x`.
|
|
4120
|
-
|
|
4121
|
-
Supported Platforms:
|
|
4122
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
4123
|
-
|
|
4124
|
-
Examples:
|
|
4125
|
-
>>> import mindspore
|
|
4126
|
-
>>> import numpy as np
|
|
4127
|
-
>>> 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]]
|
|
4134
|
-
"""
|
|
4135
|
-
|
|
4136
|
-
@prim_attr_register
|
|
4137
|
-
def __init__(self):
|
|
4138
|
-
"""Initialize FastGeLU."""
|
|
4139
|
-
self.init_prim_io_names(inputs=['x'], outputs=['output'])
|
|
3002
|
+
"""Initialize L2Normalize."""
|
|
3003
|
+
axis = [axis] if isinstance(axis, int) else axis
|
|
3004
|
+
validator.check_value_type('axis', axis, [list, tuple], self.name)
|
|
3005
|
+
validator.check_value_type('epsilon', epsilon, [int, float], self.name)
|
|
3006
|
+
self.add_prim_attr('axis', axis)
|
|
3007
|
+
self.init_attrs['axis'] = axis
|
|
3008
|
+
if len(axis) != 1:
|
|
3009
|
+
raise TypeError(f"For '{self.name}', the length of 'axis' must be 1, but got {len(axis)}, "
|
|
3010
|
+
f"later will support multiple axis!")
|
|
3011
|
+
self.axis = axis
|
|
4140
3012
|
|
|
4141
3013
|
|
|
4142
3014
|
class GetNext(Primitive):
|
|
@@ -4193,55 +3065,6 @@ class GetNext(Primitive):
|
|
|
4193
3065
|
validator.check_value_type("output_num", output_num, [int], self.name)
|
|
4194
3066
|
|
|
4195
3067
|
|
|
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
3068
|
class LSTM(Primitive):
|
|
4246
3069
|
r"""
|
|
4247
3070
|
Performs the Long Short-Term Memory (LSTM) on the input.
|
|
@@ -4251,9 +3074,9 @@ class LSTM(Primitive):
|
|
|
4251
3074
|
Args:
|
|
4252
3075
|
input_size (int): Number of features of input.
|
|
4253
3076
|
hidden_size (int): Number of features of hidden layer.
|
|
4254
|
-
num_layers (int): Number of layers of stacked LSTM.
|
|
4255
|
-
has_bias (bool): Whether the cell has bias `b_ih` and `b_hh
|
|
4256
|
-
bidirectional (bool): Specifies whether it is a bidirectional LSTM.
|
|
3077
|
+
num_layers (int): Number of layers of stacked LSTM, , which is only support `1` on CPU.
|
|
3078
|
+
has_bias (bool): Whether the cell has bias `b_ih` and `b_hh` , which is only support `False` on CPU.
|
|
3079
|
+
bidirectional (bool): Specifies whether it is a bidirectional LSTM, , which is only support `False` on CPU.
|
|
4257
3080
|
dropout (float): If not 0, append `Dropout` layer on the outputs of each
|
|
4258
3081
|
LSTM layer except the last layer. The range of dropout is [0.0, 1.0].
|
|
4259
3082
|
proj_size (int): If `proj_size` > 0, a projection of the corresponding size will be used,
|
|
@@ -4383,105 +3206,6 @@ class SigmoidCrossEntropyWithLogits(Primitive):
|
|
|
4383
3206
|
self.init_prim_io_names(inputs=['predict', 'target'], outputs=['loss'])
|
|
4384
3207
|
|
|
4385
3208
|
|
|
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
3209
|
class Pad(Primitive):
|
|
4486
3210
|
r"""
|
|
4487
3211
|
Pads the input tensor according to the paddings.
|
|
@@ -4729,18 +3453,18 @@ class ComputeAccidentalHits(Primitive):
|
|
|
4729
3453
|
num_true (int): The number of target classes per training example. Default: ``1`` .
|
|
4730
3454
|
|
|
4731
3455
|
Inputs:
|
|
4732
|
-
- **true_classes** (Tensor) - The target classes. With data type of
|
|
3456
|
+
- **true_classes** (Tensor) - The target classes. With data type of int64
|
|
4733
3457
|
and shape :math:`(batch\_size, num\_true)`.
|
|
4734
3458
|
- **sampled_candidates** (Tensor) - The Candidate sampling results of operators, types of training samples,
|
|
4735
|
-
with data type of
|
|
3459
|
+
with data type of int64 and shape :math:`(num\_sampled, )`.
|
|
4736
3460
|
|
|
4737
3461
|
Outputs:
|
|
4738
3462
|
Tuple of 3 Tensors.
|
|
4739
3463
|
|
|
4740
3464
|
- **indices** (Tensor) - A Tensor with shape :math:`(num\_accidental\_hits, )`,
|
|
4741
|
-
with
|
|
3465
|
+
with data type of int32.
|
|
4742
3466
|
- **ids** (Tensor) - A Tensor with shape :math:`(num\_accidental\_hits, )`,
|
|
4743
|
-
with
|
|
3467
|
+
with data type of int64.
|
|
4744
3468
|
- **weights** (Tensor) - A Tensor with shape :math:`(num\_accidental\_hits, )`, with the type float32.
|
|
4745
3469
|
|
|
4746
3470
|
Raises:
|
|
@@ -4795,8 +3519,9 @@ class ROIAlign(Primitive):
|
|
|
4795
3519
|
|
|
4796
3520
|
|
|
4797
3521
|
Inputs:
|
|
4798
|
-
- **features** (Tensor) - The input features, whose shape must be :math:`(N, C, H, W)
|
|
4799
|
-
|
|
3522
|
+
- **features** (Tensor) - The input features, whose shape must be :math:`(N, C, H, W)`, with data type of
|
|
3523
|
+
float16 or float32.
|
|
3524
|
+
- **rois** (Tensor) - The shape is :math:`(rois\_n, 5)`, with data type of float16 or float32.
|
|
4800
3525
|
`rois_n` represents the number of RoI. The size of the second dimension must be `5` and the `5` colunms
|
|
4801
3526
|
are :math:`(image\_index, top\_left\_x, top\_left\_y, bottom\_right\_x, bottom\_right\_y)`.
|
|
4802
3527
|
`image_index` represents the index of image. `top_left_x` and `top_left_y` represent the `x, y`
|
|
@@ -4958,120 +3683,6 @@ class Adam(Primitive):
|
|
|
4958
3683
|
self.add_prim_attr('side_effect_mem', True)
|
|
4959
3684
|
|
|
4960
3685
|
|
|
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
3686
|
class AdamNoUpdateParam(Primitive):
|
|
5076
3687
|
r"""
|
|
5077
3688
|
Updates gradients by the Adaptive Moment Estimation (Adam) algorithm. This operator do not update the parameter, but
|
|
@@ -5164,6 +3775,7 @@ class AdamNoUpdateParam(Primitive):
|
|
|
5164
3775
|
@prim_attr_register
|
|
5165
3776
|
def __init__(self, use_locking=False, use_nesterov=False):
|
|
5166
3777
|
"""Initialize AdamNoUpdateParam."""
|
|
3778
|
+
self.add_prim_attr('side_effect_mem', True)
|
|
5167
3779
|
validator.check_value_type("use_locking", use_locking, [bool], self.name)
|
|
5168
3780
|
validator.check_value_type("use_nesterov", use_nesterov, [bool], self.name)
|
|
5169
3781
|
|
|
@@ -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
|
-
-
|
|
5642
|
-
-
|
|
5643
|
-
-
|
|
5644
|
-
|
|
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.
|
|
@@ -5697,86 +4313,6 @@ class KLDivLoss(Primitive):
|
|
|
5697
4313
|
self.reduction = validator.check_string(reduction, support_mode, 'reduction', self.name)
|
|
5698
4314
|
|
|
5699
4315
|
|
|
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
|
|
5772
|
-
"""
|
|
5773
|
-
|
|
5774
|
-
@prim_attr_register
|
|
5775
|
-
def __init__(self, reduction='mean'):
|
|
5776
|
-
"""Initialize BinaryCrossEntropy."""
|
|
5777
|
-
self.reduction = validator.check_string(reduction, ['none', 'mean', 'sum'], 'reduction', self.name)
|
|
5778
|
-
|
|
5779
|
-
|
|
5780
4316
|
class ApplyAdaMax(Primitive):
|
|
5781
4317
|
r"""
|
|
5782
4318
|
Updates relevant entries according to the adamax scheme.
|
|
@@ -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
|
-
|
|
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.
|
|
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
|
-
|
|
6512
|
-
- **
|
|
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
|
|
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.
|
|
6833
|
-
|
|
6834
|
-
|
|
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__()
|
|
@@ -7112,86 +5651,23 @@ class SparseApplyFtrlV2(PrimitiveWithInfer):
|
|
|
7112
5651
|
self.lr_power = validator.check_number("lr_power", lr_power, 0, validator.LE, self.name)
|
|
7113
5652
|
self.l2_shrinkage = validator.check_value_type("l2_shrinkage", l2_shrinkage, [float], self.name)
|
|
7114
5653
|
self.use_locking = validator.check_value_type("use_locking", use_locking, [bool], self.name)
|
|
7115
|
-
self.add_prim_attr('side_effect_mem', True)
|
|
7116
|
-
|
|
7117
|
-
def infer_shape(self, var_shape, accum_shape, linear_shape, grad_shape, indices_shape):
|
|
7118
|
-
validator.check('var shape', var_shape, 'accum shape', accum_shape, validator.EQ, self.name)
|
|
7119
|
-
validator.check('var shape', var_shape, 'linear shape', linear_shape, validator.EQ, self.name)
|
|
7120
|
-
if len(var_shape) > 1:
|
|
7121
|
-
validator.check('var_shape[1:]', var_shape[1:], 'grad_shape[1:]', grad_shape[1:], validator.EQ, self.name)
|
|
7122
|
-
validator.check_int(len(indices_shape), 1, validator.EQ, "indices rank", self.name)
|
|
7123
|
-
validator.check('grad_shape[0]', grad_shape[0], 'indices_shape[0]', indices_shape[0], validator.EQ, self.name)
|
|
7124
|
-
return var_shape, accum_shape, linear_shape
|
|
7125
|
-
|
|
7126
|
-
def infer_dtype(self, var_dtype, accum_dtype, linear_dtype, grad_dtype, indices_dtype):
|
|
7127
|
-
args = {"var_dtype": var_dtype, "accum_dtype": accum_dtype,
|
|
7128
|
-
"linear_dtype": linear_dtype, "grad_dtype": grad_dtype}
|
|
7129
|
-
validator.check_tensors_dtypes_same_and_valid(args, [mstype.float16, mstype.float32], self.name)
|
|
7130
|
-
validator.check_tensor_dtype_valid("indicese", indices_dtype, [mstype.int32], self.name)
|
|
7131
|
-
return var_dtype, accum_dtype, linear_dtype
|
|
7132
|
-
|
|
7133
|
-
|
|
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)
|
|
5654
|
+
self.add_prim_attr('side_effect_mem', True)
|
|
7188
5655
|
|
|
7189
|
-
def
|
|
7190
|
-
validator.
|
|
5656
|
+
def infer_shape(self, var_shape, accum_shape, linear_shape, grad_shape, indices_shape):
|
|
5657
|
+
validator.check('var shape', var_shape, 'accum shape', accum_shape, validator.EQ, self.name)
|
|
5658
|
+
validator.check('var shape', var_shape, 'linear shape', linear_shape, validator.EQ, self.name)
|
|
5659
|
+
if len(var_shape) > 1:
|
|
5660
|
+
validator.check('var_shape[1:]', var_shape[1:], 'grad_shape[1:]', grad_shape[1:], validator.EQ, self.name)
|
|
5661
|
+
validator.check_int(len(indices_shape), 1, validator.EQ, "indices rank", self.name)
|
|
5662
|
+
validator.check('grad_shape[0]', grad_shape[0], 'indices_shape[0]', indices_shape[0], validator.EQ, self.name)
|
|
5663
|
+
return var_shape, accum_shape, linear_shape
|
|
7191
5664
|
|
|
7192
|
-
def
|
|
7193
|
-
|
|
7194
|
-
|
|
5665
|
+
def infer_dtype(self, var_dtype, accum_dtype, linear_dtype, grad_dtype, indices_dtype):
|
|
5666
|
+
args = {"var_dtype": var_dtype, "accum_dtype": accum_dtype,
|
|
5667
|
+
"linear_dtype": linear_dtype, "grad_dtype": grad_dtype}
|
|
5668
|
+
validator.check_tensors_dtypes_same_and_valid(args, [mstype.float16, mstype.float32], self.name)
|
|
5669
|
+
validator.check_tensor_dtype_valid("indicese", indices_dtype, [mstype.int32], self.name)
|
|
5670
|
+
return var_dtype, accum_dtype, linear_dtype
|
|
7195
5671
|
|
|
7196
5672
|
|
|
7197
5673
|
class Dropout2D(PrimitiveWithInfer):
|
|
@@ -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
|
|
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.
|
|
@@ -7898,6 +6376,9 @@ class AvgPool3D(Primitive):
|
|
|
7898
6376
|
\frac{1}{d_{ker} * h_{ker} * w_{ker}} \sum_{l=0}^{d_{ker}-1} \sum_{m=0}^{h_{ker}-1} \sum_{n=0}^{w_{ker}-1}
|
|
7899
6377
|
\text{input}(N_i, C_j, s_0 \times d + l, s_1 \times h + m, s_2 \times w + n)
|
|
7900
6378
|
|
|
6379
|
+
Note:
|
|
6380
|
+
This interface currently does not support Atlas A2 training series products.
|
|
6381
|
+
|
|
7901
6382
|
Args:
|
|
7902
6383
|
kernel_size (Union[int, tuple[int]]): The size of kernel used to take the average value,
|
|
7903
6384
|
is an int number that represents depth, height and width are both kernel_size, or a tuple
|
|
@@ -8007,8 +6488,9 @@ class Conv3D(Primitive):
|
|
|
8007
6488
|
|
|
8008
6489
|
Applies a 3D convolution over an input tensor which is typically of shape
|
|
8009
6490
|
:math:`(N, C_{in}, D_{in}, H_{in}, W_{in})`,
|
|
8010
|
-
where :math:`N` is batch size, :math:`C` is channel number,
|
|
8011
|
-
:math:`H
|
|
6491
|
+
where :math:`N` is batch size, :math:`C` is channel number,
|
|
6492
|
+
:math:`D, H, W`
|
|
6493
|
+
are the depth, height and width of the feature map, respectively.
|
|
8012
6494
|
|
|
8013
6495
|
The output is calculated based on formula:
|
|
8014
6496
|
|
|
@@ -8019,25 +6501,30 @@ class Conv3D(Primitive):
|
|
|
8019
6501
|
|
|
8020
6502
|
where :math:`bias` is the output channel bias, :math:`ccor` is
|
|
8021
6503
|
the `cross-correlation <https://en.wikipedia.org/wiki/Cross-correlation>`_,
|
|
8022
|
-
|
|
6504
|
+
:math:`weight` is the convolution kernel value and :math:`X` represents the input feature map.
|
|
8023
6505
|
|
|
8024
6506
|
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
6507
|
|
|
8027
|
-
- :math:`
|
|
6508
|
+
- :math:`i` corresponds to the batch number, the range is :math:`[0, N-1]`,
|
|
6509
|
+
where :math:`N` is the batch size of the input.
|
|
6510
|
+
|
|
6511
|
+
- :math:`j` corresponds to the output channel, the range is :math:`[0, C_{out}-1]`,
|
|
6512
|
+
where :math:`C_{out}` is the number of
|
|
8028
6513
|
output channels, which is also equal to the number of kernels.
|
|
8029
6514
|
|
|
8030
|
-
- :math:`k` corresponds to the input channel,
|
|
6515
|
+
- :math:`k` corresponds to the input channel, the range is :math:`[0, C_{in}-1]`,
|
|
6516
|
+
where :math:`C_{in}` is the number of
|
|
8031
6517
|
input channels, which is also equal to the number of channels in the convolutional kernels.
|
|
8032
6518
|
|
|
8033
|
-
Therefore, in the above formula, :math:`{bias}(C_{
|
|
8034
|
-
output channel, :math:`{weight}(C_{
|
|
6519
|
+
Therefore, in the above formula, :math:`{bias}(C_{\text{out}_j})` represents the bias of the :math:`j`-th
|
|
6520
|
+
output channel, :math:`{weight}(C_{\text{out}_j}, k)`represents the slice of the :math:`j`-th convolutional
|
|
8035
6521
|
kernel in the :math:`k`-th channel, and :math:`{X}(N_i, k)` represents the slice of the :math:`k`-th input
|
|
8036
6522
|
channel in the :math:`i`-th batch of the input feature map.
|
|
8037
6523
|
|
|
8038
6524
|
The shape of the convolutional kernel is given by
|
|
8039
6525
|
:math:`(\text{kernel_size[0]}, \text{kernel_size[1]}, \text{kernel_size[2]})`
|
|
8040
|
-
where :math
|
|
6526
|
+
where :math:`\text{kernel_size[0]}` ,
|
|
6527
|
+
:math:`\text{kernel_size[1]}` and :math:`\text{kernel_size[2]}` are the depth,
|
|
8041
6528
|
height and width of the kernel, respectively.
|
|
8042
6529
|
If we consider the input and output channels as well as the `group` parameter, the complete kernel shape
|
|
8043
6530
|
will be :math:`(C_{out}, C_{in} / \text{group}, \text{kernel_size[0]},
|
|
@@ -8048,8 +6535,8 @@ class Conv3D(Primitive):
|
|
|
8048
6535
|
<http://vision.stanford.edu/cs598_spring07/papers/Lecun98.pdf>`_.
|
|
8049
6536
|
|
|
8050
6537
|
Note:
|
|
8051
|
-
1. On Ascend platform,
|
|
8052
|
-
2. On Ascend
|
|
6538
|
+
1. On Ascend platform, :math:`groups=1` must be satisfied.
|
|
6539
|
+
2. On Ascend :math:`dilation` on depth only supports the case of 1.
|
|
8053
6540
|
|
|
8054
6541
|
Args:
|
|
8055
6542
|
out_channel (int): Specifies output channel :math:`C_{out}`.
|
|
@@ -8607,7 +7094,7 @@ class CTCLossV2Grad(Primitive):
|
|
|
8607
7094
|
zero_infinity (bool): Whether to set infinite loss and correlation gradient to zero. Default: ``False`` .
|
|
8608
7095
|
|
|
8609
7096
|
Inputs:
|
|
8610
|
-
- **grad_out** (
|
|
7097
|
+
- **grad_out** (Tensor) - Gradient renewal codfficient, A tensor for shape (N), where N is batch size.
|
|
8611
7098
|
- **log_probs** (Tensor) - A tensor of shape (T, N, C), where T is input length, N is batch size and C is number
|
|
8612
7099
|
of classes (including blank).
|
|
8613
7100
|
- **targets** (Tensor) - A tensor of shape (N, S), where S is max target length, means the target sequences.
|
|
@@ -8671,7 +7158,7 @@ class Conv3DTranspose(Primitive):
|
|
|
8671
7158
|
\times (\text{kernel_size}[2] - 1) + \text{output_padding}[2] + 1
|
|
8672
7159
|
|
|
8673
7160
|
Note:
|
|
8674
|
-
In Ascend,
|
|
7161
|
+
In Ascend, only support :math:`group=1`.
|
|
8675
7162
|
|
|
8676
7163
|
Args:
|
|
8677
7164
|
in_channel (int): The channel of the input x.
|
|
@@ -8739,7 +7226,7 @@ class Conv3DTranspose(Primitive):
|
|
|
8739
7226
|
ValueError: If `pad` is a tuple whose length is not equal to 6.
|
|
8740
7227
|
ValueError: If `pad_mode` is not equal to 'pad' and `pad` is not equal to (0, 0, 0, 0, 0, 0).
|
|
8741
7228
|
ValueError: If `data_format` is not 'NCDHW'.
|
|
8742
|
-
TypeError: If data type of dout and weight is
|
|
7229
|
+
TypeError: If data type of dout and weight is neither float16 nor float32.
|
|
8743
7230
|
ValueError: If bias is not none. The rank of dout and weight is not 5.
|
|
8744
7231
|
|
|
8745
7232
|
Supported Platforms:
|
|
@@ -8977,83 +7464,6 @@ class Dilation2D(Primitive):
|
|
|
8977
7464
|
self.add_prim_attr('dilation', self.dilation)
|
|
8978
7465
|
|
|
8979
7466
|
|
|
8980
|
-
class SoftShrink(Primitive):
|
|
8981
|
-
r"""
|
|
8982
|
-
Applies the SoftShrink function element-wise.
|
|
8983
|
-
|
|
8984
|
-
Refer to :func:`mindspore.ops.softshrink` for more details.
|
|
8985
|
-
|
|
8986
|
-
Args:
|
|
8987
|
-
lambd(float, optional): The :math:`\lambda` must be no less than zero. Default: ``0.5`` .
|
|
8988
|
-
|
|
8989
|
-
Inputs:
|
|
8990
|
-
- **input_x** (Tensor) - The input of soft shrink with data type of float16 or float32.
|
|
8991
|
-
|
|
8992
|
-
Outputs:
|
|
8993
|
-
Tensor, has the same shape and data type as `input_x`.
|
|
8994
|
-
|
|
8995
|
-
Supported Platforms:
|
|
8996
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
8997
|
-
|
|
8998
|
-
Examples:
|
|
8999
|
-
>>> import mindspore
|
|
9000
|
-
>>> import numpy as np
|
|
9001
|
-
>>> from mindspore import Tensor, ops
|
|
9002
|
-
>>> input_x = Tensor(np.array([[ 0.5297, 0.7871, 1.1754], [ 0.7836, 0.6218, -1.1542]]), mindspore.float16)
|
|
9003
|
-
>>> softshrink = ops.SoftShrink()
|
|
9004
|
-
>>> output = softshrink(input_x)
|
|
9005
|
-
>>> print(output)
|
|
9006
|
-
[[ 0.02979 0.287 0.676 ]
|
|
9007
|
-
[ 0.2837 0.1216 -0.6543 ]]
|
|
9008
|
-
"""
|
|
9009
|
-
|
|
9010
|
-
@prim_attr_register
|
|
9011
|
-
def __init__(self, lambd=0.5):
|
|
9012
|
-
"""Initialize SoftShrink"""
|
|
9013
|
-
validator.check_value_type("lambd", lambd, [float], self.name)
|
|
9014
|
-
validator.check_number("lambd", lambd, 0, validator.GE, self.name)
|
|
9015
|
-
|
|
9016
|
-
|
|
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
7467
|
class ApplyAdagradDA(Primitive):
|
|
9058
7468
|
r"""
|
|
9059
7469
|
Update `var` according to the proximal adagrad scheme.
|
|
@@ -9098,11 +7508,9 @@ class ApplyAdagradDA(Primitive):
|
|
|
9098
7508
|
- **global_step** ([Number, Tensor]) - Training step number. Must be a scalar. With int32 or int64 data type.
|
|
9099
7509
|
|
|
9100
7510
|
Outputs:
|
|
9101
|
-
Tuple of
|
|
7511
|
+
Tuple of 1 Tensors, the updated parameters.
|
|
9102
7512
|
|
|
9103
7513
|
- **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
7514
|
|
|
9107
7515
|
Raises:
|
|
9108
7516
|
TypeError: If `var`, `gradient_accumulator` or `gradient_squared_accumulator` is not a Parameter.
|
|
@@ -9153,11 +7561,7 @@ class ApplyAdagradDA(Primitive):
|
|
|
9153
7561
|
>>> print(output)
|
|
9154
7562
|
(Tensor(shape=[2, 2], dtype=Float32, value=
|
|
9155
7563
|
[[-7.39064650e-04, -1.36888528e-03],
|
|
9156
|
-
[-5.96988888e-04, -1.42478070e-03]])
|
|
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]]))
|
|
7564
|
+
[-5.96988888e-04, -1.42478070e-03]]))
|
|
9161
7565
|
"""
|
|
9162
7566
|
|
|
9163
7567
|
__mindspore_signature__ = (
|
|
@@ -9669,6 +8073,14 @@ class ApplyAdamWithAmsgradV2(Primitive):
|
|
|
9669
8073
|
var:=var-lr_t*m_t/(\sqrt{\hat v_t}+\epsilon) \\
|
|
9670
8074
|
\end{array}
|
|
9671
8075
|
|
|
8076
|
+
:math:`t` represents updating step while :math:`m` represents the 1st moment vector,
|
|
8077
|
+
:math:`v` represents the 2nd moment vector, :math:`\hat v_t` represents `vhat`,
|
|
8078
|
+
:math:`lr` represents learning rate,
|
|
8079
|
+
:math:`g` represents `grad`, :math:`\beta_1, \beta_2` represent `beta1` and `beta2`,
|
|
8080
|
+
:math:`\beta_1^{t}` represents `beta1_power`, :math:`\beta_2^{t}` represents `beta2_power`,
|
|
8081
|
+
:math:`var` represents the variable to be updated,
|
|
8082
|
+
:math:`\epsilon` represents `epsilon`.
|
|
8083
|
+
|
|
9672
8084
|
All of the inputs are consistent with implicit type conversion rules,
|
|
9673
8085
|
which ensure that the data types are the same. If they have different data types, the lower precision data type
|
|
9674
8086
|
will be converted to the data type with relatively higher precision.
|
|
@@ -9717,7 +8129,7 @@ class ApplyAdamWithAmsgradV2(Primitive):
|
|
|
9717
8129
|
``Ascend`` ``GPU`` ``CPU``
|
|
9718
8130
|
|
|
9719
8131
|
Examples:
|
|
9720
|
-
>>>
|
|
8132
|
+
>>> from mindspore import ops
|
|
9721
8133
|
>>> import mindspore.nn as nn
|
|
9722
8134
|
>>> from mindspore import Tensor, Parameter
|
|
9723
8135
|
>>> import numpy as np
|
|
@@ -9770,83 +8182,6 @@ class ApplyAdamWithAmsgradV2(Primitive):
|
|
|
9770
8182
|
self.add_prim_attr("side_effect_mem", True)
|
|
9771
8183
|
|
|
9772
8184
|
|
|
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
8185
|
class FractionalMaxPool(Primitive):
|
|
9851
8186
|
r"""
|
|
9852
8187
|
Performs fractional max pooling on the input.
|
|
@@ -10399,104 +8734,21 @@ class DeformableOffsets(Primitive):
|
|
|
10399
8734
|
self.add_prim_attr('modulated', self.modulated)
|
|
10400
8735
|
|
|
10401
8736
|
|
|
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
8737
|
class Pdist(Primitive):
|
|
10489
8738
|
r"""
|
|
10490
8739
|
Computes the p-norm distance between each pair of row vectors in the input.
|
|
10491
8740
|
|
|
10492
8741
|
Refer to :func:`mindspore.ops.pdist` for more details.
|
|
10493
8742
|
|
|
8743
|
+
Note:
|
|
8744
|
+
The pdist operator involves exponentiation, the inf/nan calculation result may be generated
|
|
8745
|
+
when the float16 input is used. The float32 input is recommended.
|
|
8746
|
+
|
|
10494
8747
|
Args:
|
|
10495
8748
|
p (float, optional): The order of norm distance, :math:`p∈[0, ∞)`. Default: ``2.0`` .
|
|
10496
8749
|
|
|
10497
8750
|
Inputs:
|
|
10498
|
-
- **x** (Tensor) - Input tensor
|
|
10499
|
-
one-dim or multi-dim. Supported dtypes: float16, float32 or float64.
|
|
8751
|
+
- **x** (Tensor) - Input tensor. Supported dtypes: float16, float32 or float64.
|
|
10500
8752
|
|
|
10501
8753
|
Outputs:
|
|
10502
8754
|
Tensor, has the same dtype as `x`.
|
|
@@ -10523,71 +8775,6 @@ class Pdist(Primitive):
|
|
|
10523
8775
|
self.init_prim_io_names(inputs=['x'], outputs=['y'])
|
|
10524
8776
|
|
|
10525
8777
|
|
|
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
8778
|
class SparseApplyAdagradDA(Primitive):
|
|
10592
8779
|
r"""
|
|
10593
8780
|
Update `var` according to the proximal adagrad scheme.
|
|
@@ -11230,54 +9417,6 @@ class MaxPoolWithArgmaxV2(Primitive):
|
|
|
11230
9417
|
self.add_prim_attr("ceil_mode", self.ceil_mode)
|
|
11231
9418
|
|
|
11232
9419
|
|
|
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
9420
|
class WKV(Primitive):
|
|
11282
9421
|
r"""
|
|
11283
9422
|
The WKV computation is similar to AFT(Zhai et al., 2021), but W is now a channel-wise vector multiplied
|
|
@@ -11338,7 +9477,8 @@ class PromptFlashAttention(Primitive):
|
|
|
11338
9477
|
S -- Sequence length
|
|
11339
9478
|
H -- Hidden size
|
|
11340
9479
|
|
|
11341
|
-
|
|
9480
|
+
Note:
|
|
9481
|
+
experiment ops
|
|
11342
9482
|
|
|
11343
9483
|
.. warning::
|
|
11344
9484
|
This is an experimental API that is subject to change or deletion.
|
|
@@ -11355,6 +9495,7 @@ class PromptFlashAttention(Primitive):
|
|
|
11355
9495
|
num_key_value_heads (int): head numbers of key/value which are used in GQA algorithm.
|
|
11356
9496
|
The value o indicates if the key and value have the same head nums, use numHeads. Default: 0.
|
|
11357
9497
|
sparse_mode (int): Default: 0
|
|
9498
|
+
inner_precise (int): 0, float16 high precision. 1, high performance. default 1
|
|
11358
9499
|
|
|
11359
9500
|
Inputs:
|
|
11360
9501
|
- **query** (Tensor) - The query tensor with data type of float16 or float32.
|
|
@@ -11365,8 +9506,8 @@ class PromptFlashAttention(Primitive):
|
|
|
11365
9506
|
Input tensor of shape :math:`(B, S, H)` / `(B, N, S, D)`.
|
|
11366
9507
|
- **attn_mask** (Tensor) - The attention mask tensor with data type of float16 or float32.
|
|
11367
9508
|
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
|
|
11369
|
-
- **actual_seq_lengths_kv** (Tensor): Describe actual sequence length of each input with data type of
|
|
9509
|
+
- **actual_seq_lengths** (Tensor): Describe actual sequence length of each input with data type of int64.
|
|
9510
|
+
- **actual_seq_lengths_kv** (Tensor): Describe actual sequence length of each input with data type of int64.
|
|
11370
9511
|
- **pse_shift** (Tensor) - The position encoding tensor with data type of float16 or float32.
|
|
11371
9512
|
- **dep_scale1** (Tensor)
|
|
11372
9513
|
- **quant_scale1** (Tensor)
|
|
@@ -11374,11 +9515,10 @@ class PromptFlashAttention(Primitive):
|
|
|
11374
9515
|
- **quant_scale2** (Tensor)
|
|
11375
9516
|
- **quant_offset2** (Tensor)
|
|
11376
9517
|
|
|
11377
|
-
|
|
11378
9518
|
Outputs:
|
|
11379
9519
|
- **attention_out** (Tensor) - Input tensor of shape :math:`(B, S, H)` / `(B, N, S, D)`.
|
|
11380
9520
|
|
|
11381
|
-
|
|
9521
|
+
Supported Platforms:
|
|
11382
9522
|
``Ascend``
|
|
11383
9523
|
|
|
11384
9524
|
Examples:
|
|
@@ -11392,15 +9532,16 @@ class PromptFlashAttention(Primitive):
|
|
|
11392
9532
|
>>> query = Tensor(np.ones((B, N, S, D), dtype=np.float16))
|
|
11393
9533
|
>>> key = Tensor(np.ones((B, N, S, D), dtype=np.float16))
|
|
11394
9534
|
>>> value = Tensor(np.ones((B, N, S, D), dtype=np.float16))
|
|
9535
|
+
>>> attn_mask = Tensor(np.ones((B, 1, S, S), dtype=np.float16))
|
|
11395
9536
|
>>> pfa = P.PromptFlashAttention(N, input_layout='BNSD')
|
|
11396
|
-
>>> out = pfa(query, key, value,
|
|
11397
|
-
>>> print(out
|
|
9537
|
+
>>> out = pfa(query, key, value, attn_mask, None, None, None, None, None, None, None, None)
|
|
9538
|
+
>>> print(out.shape)
|
|
11398
9539
|
(1, 16, 256, 16)
|
|
11399
9540
|
"""
|
|
11400
9541
|
|
|
11401
9542
|
@prim_attr_register
|
|
11402
|
-
def __init__(self, num_heads, scale_value=1.0, pre_tokens=
|
|
11403
|
-
num_key_value_heads=0, sparse_mode=0):
|
|
9543
|
+
def __init__(self, num_heads, scale_value=1.0, pre_tokens=214748647, next_tokens=0, input_layout='BSH',
|
|
9544
|
+
num_key_value_heads=0, sparse_mode=0, inner_precise=1):
|
|
11404
9545
|
"""Initialize PromptFlashAttention."""
|
|
11405
9546
|
validator.check_value_type('num_heads', num_heads, [int], self.name)
|
|
11406
9547
|
validator.check_value_type('scale_value', scale_value, [float], self.name)
|
|
@@ -11409,175 +9550,26 @@ class PromptFlashAttention(Primitive):
|
|
|
11409
9550
|
validator.check_value_type('input_layout', input_layout, [str], self.name)
|
|
11410
9551
|
validator.check_value_type('num_key_value_heads', num_key_value_heads, [int], self.name)
|
|
11411
9552
|
validator.check_value_type('sparse_mode', sparse_mode, [int], self.name)
|
|
9553
|
+
validator.check_value_type('inner_precise', inner_precise, [int], self.name)
|
|
11412
9554
|
self.init_prim_io_names(inputs=["query", "key", "value", "attn_mask", "actual_seq_lengths",
|
|
11413
9555
|
"actual_seq_lengths_kv", "pse_shift", "deq_scale1", "quant_scale1",
|
|
11414
9556
|
"deq_scale2", "quant_scale2", "quant_offset2"],
|
|
11415
9557
|
outputs=["attention_out"])
|
|
11416
9558
|
|
|
11417
9559
|
|
|
11418
|
-
class
|
|
11419
|
-
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'])
|
|
11493
|
-
|
|
11494
|
-
|
|
11495
|
-
class RmsNorm(Primitive):
|
|
11496
|
-
r"""
|
|
11497
|
-
The RmsNorm operator is a normalization operation, and its formula is:
|
|
11498
|
-
|
|
11499
|
-
.. math::
|
|
11500
|
-
y=\frac{x_i}{\sqrt{\frac{1}{n}}\sum_{i=1}^{n}{ x_i^2}+\varepsilon }\gamma_i
|
|
11501
|
-
|
|
11502
|
-
.. warning::
|
|
11503
|
-
This is an experimental API that is subject to change or deletion.
|
|
11504
|
-
|
|
11505
|
-
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.
|
|
11511
|
-
|
|
11512
|
-
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"
|
|
11520
|
-
|
|
11521
|
-
Supported Platforms:
|
|
11522
|
-
``Ascend``
|
|
11523
|
-
"""
|
|
11524
|
-
|
|
11525
|
-
@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'])
|
|
11562
|
-
|
|
11563
|
-
|
|
11564
|
-
class ReshapeAndCache(Primitive):
|
|
9560
|
+
class AllFinite(Primitive):
|
|
11565
9561
|
r"""
|
|
11566
|
-
|
|
11567
|
-
This is an experimental API that is subject to change or deletion.
|
|
9562
|
+
Check all gradients is finite.
|
|
11568
9563
|
"""
|
|
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
9564
|
|
|
11577
9565
|
@prim_attr_register
|
|
11578
9566
|
def __init__(self):
|
|
11579
|
-
"""Initialize
|
|
11580
|
-
self.init_prim_io_names(
|
|
11581
|
-
|
|
11582
|
-
|
|
11583
|
-
|
|
9567
|
+
"""Initialize"""
|
|
9568
|
+
self.init_prim_io_names(inputs=['gradients'],
|
|
9569
|
+
outputs=["is_finite"])
|
|
9570
|
+
if context.get_context("device_target") == "Ascend":
|
|
9571
|
+
checker = AscendEnvChecker(None)
|
|
9572
|
+
if not checker.check_custom_version():
|
|
9573
|
+
raise RuntimeError(
|
|
9574
|
+
"The version of Ascend AI software package installed "
|
|
9575
|
+
"in the current environment does not support AllFinite.")
|