mindspore 2.2.14__cp39-cp39-win_amd64.whl → 2.3.0__cp39-cp39-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of mindspore might be problematic. Click here for more details.
- mindspore/.commit_id +1 -1
- mindspore/Microsoft.VisualStudio.Telemetry.dll +0 -0
- mindspore/Newtonsoft.Json.dll +0 -0
- mindspore/__init__.py +6 -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 +76 -18
- 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 +258 -0
- mindspore/_extends/parse/namespace.py +2 -2
- mindspore/_extends/parse/parser.py +174 -62
- mindspore/_extends/parse/resources.py +45 -14
- mindspore/_extends/parse/standard_method.py +142 -240
- mindspore/{ops/_op_impl/tbe/atomic_addr_clean.py → _extends/pijit/__init__.py} +6 -16
- mindspore/_extends/pijit/pijit_func_white_list.py +343 -0
- mindspore/_extends/remote/kernel_build_server.py +2 -0
- mindspore/_profiler.py +30 -0
- mindspore/amp.py +51 -24
- 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 +15 -4
- mindspore/common/_jit_fallback_utils.py +2 -3
- mindspore/common/_register_for_adapter.py +7 -0
- mindspore/common/_register_for_recompute.py +48 -0
- mindspore/common/_register_for_tensor.py +8 -9
- mindspore/common/_stub_tensor.py +7 -1
- mindspore/common/_utils.py +5 -17
- mindspore/common/api.py +411 -106
- mindspore/common/auto_dynamic_shape.py +27 -14
- mindspore/common/dtype.py +17 -10
- mindspore/common/dump.py +6 -8
- mindspore/common/file_system.py +48 -0
- mindspore/common/generator.py +260 -0
- mindspore/common/hook_handle.py +51 -4
- 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 +30 -11
- mindspore/common/recompute.py +262 -0
- mindspore/common/seed.py +9 -9
- mindspore/common/sparse_tensor.py +272 -24
- mindspore/common/symbol.py +122 -0
- mindspore/common/tensor.py +468 -494
- mindspore/communication/__init__.py +6 -11
- mindspore/communication/_comm_helper.py +5 -0
- mindspore/communication/comm_func.py +1140 -0
- mindspore/communication/management.py +115 -102
- mindspore/config/op_info.config +22 -54
- mindspore/context.py +346 -63
- 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/engine/cache_client.py +2 -2
- mindspore/dataset/engine/datasets.py +140 -83
- mindspore/dataset/engine/datasets_audio.py +14 -14
- mindspore/dataset/engine/datasets_standard_format.py +33 -3
- mindspore/dataset/engine/datasets_text.py +38 -38
- mindspore/dataset/engine/datasets_user_defined.py +78 -59
- mindspore/dataset/engine/datasets_vision.py +77 -73
- mindspore/dataset/engine/offload.py +5 -7
- mindspore/dataset/engine/queue.py +56 -38
- mindspore/dataset/engine/validators.py +11 -5
- mindspore/dataset/text/__init__.py +3 -3
- mindspore/dataset/text/transforms.py +408 -121
- mindspore/dataset/text/utils.py +9 -9
- mindspore/dataset/transforms/__init__.py +1 -1
- mindspore/dataset/transforms/transforms.py +261 -76
- mindspore/dataset/utils/browse_dataset.py +9 -9
- mindspore/dataset/vision/__init__.py +8 -8
- 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 +14 -2
- mindspore/dnnl.dll +0 -0
- mindspore/dpcmi.dll +0 -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 +40 -16
- 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 +15 -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/device.py +356 -0
- mindspore/hal/event.py +179 -0
- mindspore/hal/memory.py +326 -0
- mindspore/hal/stream.py +339 -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/status.h +14 -0
- mindspore/include/c_api/model_c.h +173 -0
- mindspore/include/c_api/ms/base/types.h +1 -0
- mindspore/include/c_api/types_c.h +19 -0
- mindspore/include/dataset/execute.h +1 -3
- mindspore/include/dataset/vision.h +54 -2
- mindspore/jpeg62.dll +0 -0
- mindspore/log.py +2 -2
- mindspore/mindrecord/__init__.py +5 -1
- mindspore/mindrecord/config.py +809 -0
- mindspore/mindrecord/filereader.py +25 -0
- mindspore/mindrecord/filewriter.py +76 -58
- 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_shared_lib.dll +0 -0
- mindspore/mint/__init__.py +1137 -0
- mindspore/{rewrite/ast_transformers → mint/linalg}/__init__.py +9 -4
- mindspore/mint/nn/__init__.py +512 -0
- mindspore/mint/nn/functional.py +573 -0
- mindspore/mint/optim/__init__.py +24 -0
- mindspore/mint/optim/adamw.py +185 -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 +72 -0
- mindspore/nn/__init__.py +1 -0
- mindspore/nn/cell.py +213 -257
- mindspore/nn/dynamic_lr.py +2 -2
- mindspore/nn/extend/__init__.py +29 -0
- mindspore/nn/extend/basic.py +140 -0
- mindspore/nn/extend/embedding.py +143 -0
- mindspore/{rewrite/ast_creator_register.py → nn/extend/layer/__init__.py} +9 -19
- mindspore/nn/extend/layer/normalization.py +109 -0
- mindspore/nn/extend/pooling.py +117 -0
- mindspore/nn/layer/activation.py +83 -93
- mindspore/nn/layer/basic.py +177 -82
- 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 +101 -43
- mindspore/nn/layer/embedding_service.py +531 -0
- mindspore/nn/layer/embedding_service_layer.py +393 -0
- mindspore/nn/layer/image.py +4 -7
- mindspore/nn/layer/math.py +1 -1
- mindspore/nn/layer/normalization.py +52 -66
- mindspore/nn/layer/padding.py +30 -39
- mindspore/nn/layer/pooling.py +18 -9
- 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 +52 -50
- mindspore/nn/learning_rate_schedule.py +6 -5
- mindspore/nn/loss/loss.py +62 -83
- mindspore/nn/optim/ada_grad.py +4 -2
- mindspore/nn/optim/adadelta.py +3 -1
- 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/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 +58 -13
- mindspore/nn/wrap/grad_reducer.py +148 -8
- mindspore/nn/wrap/loss_scale.py +32 -9
- mindspore/numpy/__init__.py +2 -0
- mindspore/numpy/array_creations.py +2 -0
- mindspore/numpy/array_ops.py +6 -6
- mindspore/numpy/dtypes.py +3 -3
- mindspore/numpy/fft.py +431 -0
- mindspore/numpy/math_ops.py +62 -68
- mindspore/numpy/utils.py +3 -0
- mindspore/opencv_core452.dll +0 -0
- mindspore/opencv_imgcodecs452.dll +0 -0
- mindspore/opencv_imgproc452.dll +0 -0
- mindspore/ops/__init__.py +6 -5
- mindspore/ops/_grad_experimental/grad_array_ops.py +4 -129
- mindspore/ops/_grad_experimental/grad_comm_ops.py +89 -34
- mindspore/ops/_grad_experimental/grad_math_ops.py +68 -283
- 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 +164 -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 +130 -58
- mindspore/ops/_vmap/vmap_nn_ops.py +249 -115
- 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 +231 -0
- mindspore/ops/auto_generate/gen_arg_dtype_cast.py +250 -0
- mindspore/ops/auto_generate/gen_arg_handler.py +197 -0
- mindspore/ops/auto_generate/gen_extend_func.py +980 -0
- mindspore/ops/auto_generate/gen_ops_def.py +6443 -0
- mindspore/ops/auto_generate/gen_ops_prim.py +13167 -0
- mindspore/ops/auto_generate/pyboost_inner_prim.py +429 -0
- mindspore/ops/composite/__init__.py +5 -2
- mindspore/ops/composite/base.py +121 -23
- mindspore/ops/composite/math_ops.py +10 -49
- mindspore/ops/composite/multitype_ops/_compile_utils.py +191 -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 +6 -1
- 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/extend/__init__.py +53 -0
- mindspore/ops/extend/array_func.py +218 -0
- mindspore/ops/extend/math_func.py +76 -0
- mindspore/ops/extend/nn_func.py +308 -0
- mindspore/ops/function/__init__.py +31 -11
- mindspore/ops/function/array_func.py +846 -1735
- mindspore/ops/function/clip_func.py +19 -31
- mindspore/ops/function/debug_func.py +1 -4
- mindspore/ops/function/fft_func.py +31 -0
- mindspore/ops/function/grad/grad_func.py +27 -20
- mindspore/ops/function/image_func.py +27 -21
- mindspore/ops/function/linalg_func.py +35 -68
- mindspore/ops/function/math_func.py +913 -2791
- mindspore/ops/function/nn_func.py +1439 -885
- mindspore/ops/function/other_func.py +6 -7
- mindspore/ops/function/parameter_func.py +5 -93
- mindspore/ops/function/random_func.py +254 -108
- mindspore/ops/function/reshard_func.py +102 -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 +14 -14
- mindspore/ops/functional.py +342 -343
- mindspore/ops/op_info_register.py +16 -43
- mindspore/ops/operations/__init__.py +32 -23
- mindspore/ops/operations/_grad_ops.py +21 -853
- mindspore/ops/operations/_infer_ops.py +19 -0
- mindspore/ops/operations/_inner_ops.py +107 -518
- 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 +108 -2705
- mindspore/ops/operations/comm_ops.py +801 -118
- mindspore/ops/operations/custom_ops.py +61 -120
- mindspore/ops/operations/debug_ops.py +104 -35
- 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 +61 -0
- mindspore/ops/operations/manually_defined/ops_def.py +2016 -0
- mindspore/ops/operations/math_ops.py +572 -4667
- mindspore/ops/operations/nn_ops.py +248 -2162
- mindspore/ops/operations/other_ops.py +53 -45
- mindspore/ops/operations/random_ops.py +4 -53
- mindspore/ops/operations/reshard_ops.py +53 -0
- mindspore/ops/operations/sparse_ops.py +4 -4
- mindspore/ops/primitive.py +204 -103
- mindspore/ops/silent_check.py +5 -5
- mindspore/ops_generate/__init__.py +27 -0
- mindspore/ops_generate/arg_dtype_cast.py +250 -0
- mindspore/ops_generate/arg_handler.py +197 -0
- mindspore/ops_generate/gen_aclnn_implement.py +263 -0
- mindspore/ops_generate/gen_ops.py +1084 -0
- mindspore/ops_generate/gen_ops_inner_prim.py +131 -0
- mindspore/ops_generate/gen_pyboost_func.py +968 -0
- mindspore/ops_generate/gen_utils.py +209 -0
- mindspore/ops_generate/op_proto.py +138 -0
- mindspore/ops_generate/pyboost_utils.py +354 -0
- mindspore/ops_generate/template.py +239 -0
- mindspore/parallel/__init__.py +6 -4
- mindspore/parallel/_auto_parallel_context.py +73 -3
- mindspore/parallel/_cell_wrapper.py +16 -9
- mindspore/parallel/_cost_model_context.py +1 -1
- mindspore/parallel/_dp_allreduce_fusion.py +159 -159
- mindspore/parallel/_parallel_serialization.py +29 -13
- mindspore/parallel/_ps_context.py +1 -1
- mindspore/parallel/_recovery_context.py +1 -1
- mindspore/parallel/_tensor.py +18 -11
- 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 +161 -6
- mindspore/parallel/algo_parameter_config.py +6 -8
- mindspore/parallel/checkpoint_transform.py +191 -32
- mindspore/parallel/cluster/__init__.py +15 -0
- mindspore/parallel/cluster/process_entity/__init__.py +18 -0
- mindspore/parallel/cluster/process_entity/_api.py +344 -0
- mindspore/parallel/cluster/process_entity/_utils.py +126 -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 +152 -0
- mindspore/parallel/shard.py +128 -17
- mindspore/pgodb140.dll +0 -0
- mindspore/pgort140.dll +0 -0
- mindspore/profiler/__init__.py +3 -2
- mindspore/profiler/common/process_pool.py +41 -0
- mindspore/profiler/common/singleton.py +28 -0
- mindspore/profiler/common/util.py +125 -0
- mindspore/profiler/envprofiling.py +2 -2
- mindspore/{_extends/parallel_compile/tbe_compiler → profiler/parser/ascend_analysis}/__init__.py +1 -1
- mindspore/profiler/parser/ascend_analysis/constant.py +53 -0
- mindspore/profiler/parser/ascend_analysis/file_manager.py +159 -0
- mindspore/profiler/parser/ascend_analysis/function_event.py +161 -0
- mindspore/profiler/parser/ascend_analysis/fwk_cann_parser.py +131 -0
- mindspore/profiler/parser/ascend_analysis/fwk_file_parser.py +85 -0
- mindspore/profiler/parser/ascend_analysis/msprof_timeline_parser.py +57 -0
- mindspore/profiler/parser/ascend_analysis/profiler_info_parser.py +116 -0
- mindspore/profiler/parser/ascend_analysis/tlv_decoder.py +86 -0
- mindspore/profiler/parser/ascend_analysis/trace_event_manager.py +68 -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 +147 -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 +296 -133
- mindspore/profiler/parser/base_timeline_generator.py +6 -0
- mindspore/profiler/parser/framework_parser.py +3 -2
- mindspore/profiler/parser/integrator.py +3 -1
- mindspore/profiler/parser/minddata_parser.py +72 -3
- mindspore/profiler/parser/msadvisor_analyzer.py +1 -1
- mindspore/profiler/parser/msadvisor_parser.py +1 -1
- mindspore/profiler/parser/profiler_info.py +16 -1
- mindspore/profiler/profiling.py +445 -190
- mindspore/rewrite/__init__.py +2 -13
- 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} +704 -185
- 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 +6 -14
- mindspore/run_check/run_check.py +1 -1
- mindspore/safeguard/rewrite_obfuscation.py +9 -19
- 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 +6 -5
- mindspore/train/_utils.py +178 -4
- mindspore/train/amp.py +167 -245
- 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 +143 -29
- mindspore/train/callback/_cluster_monitor.py +201 -0
- mindspore/train/callback/_early_stop.py +2 -2
- mindspore/train/callback/_flops_collector.py +238 -0
- mindspore/train/callback/_landscape.py +15 -9
- mindspore/train/callback/_loss_monitor.py +2 -2
- mindspore/train/callback/_mindio_ttp.py +443 -0
- mindspore/train/callback/_on_request_exit.py +2 -2
- mindspore/train/callback/_reduce_lr_on_plateau.py +2 -2
- mindspore/train/callback/_summary_collector.py +7 -7
- mindspore/train/callback/_time_monitor.py +3 -3
- mindspore/train/data_sink.py +6 -5
- mindspore/train/dataset_helper.py +60 -21
- 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/topk.py +2 -2
- mindspore/train/mind_ir_pb2.py +89 -15
- mindspore/train/model.py +290 -60
- mindspore/train/serialization.py +495 -220
- 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/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.3.0.dist-info}/METADATA +3 -3
- mindspore-2.3.0.dist-info/RECORD +1400 -0
- {mindspore-2.2.14.dist-info → mindspore-2.3.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/nn/layer/flash_attention.py +0 -189
- 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/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.3.0.dist-info}/WHEEL +0 -0
- {mindspore-2.2.14.dist-info → mindspore-2.3.0.dist-info}/top_level.txt +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright
|
|
1
|
+
# Copyright 2023-2024 Huawei Technologies Co., Ltd
|
|
2
2
|
#
|
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
# you may not use this file except in compliance with the License.
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
"""Defines nn operators with functional form."""
|
|
17
17
|
from __future__ import absolute_import
|
|
18
|
-
from math import pi, log
|
|
18
|
+
from math import pi, log, floor
|
|
19
19
|
|
|
20
20
|
from mindspore import context
|
|
21
21
|
from mindspore import log as logger
|
|
@@ -29,6 +29,7 @@ import mindspore.common.dtype as mstype
|
|
|
29
29
|
from mindspore.ops.function.math_func import logsumexp
|
|
30
30
|
from mindspore.ops.function.random_func import _get_seed, _set_prim_op_user_data
|
|
31
31
|
from mindspore.common.tensor import Tensor
|
|
32
|
+
from mindspore.common.parameter import Parameter
|
|
32
33
|
from mindspore._c_expression import Tensor as Tensor_
|
|
33
34
|
from mindspore.ops._primitive_cache import _get_cache_prim
|
|
34
35
|
from mindspore import _checkparam as validator
|
|
@@ -38,22 +39,62 @@ from mindspore.ops.operations.nn_ops import FractionalMaxPoolWithFixedKsize, Fra
|
|
|
38
39
|
from mindspore.ops.operations.nn_ops import PadV3
|
|
39
40
|
from mindspore.ops.operations.nn_ops import ChannelShuffle
|
|
40
41
|
from mindspore.ops.operations.nn_ops import TripletMarginLoss
|
|
41
|
-
from mindspore.ops.operations._inner_ops import SiLU
|
|
42
42
|
from mindspore.ops.operations._sequence_ops import TupleToTensor, TensorToTuple, ListToTensor
|
|
43
43
|
from mindspore.common.api import _function_forbid_reuse
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
from mindspore.ops.auto_generate import log_softmax, dense, prelu, celu, relu, fast_gelu, silu, elu, sigmoid, relu6
|
|
45
|
+
from mindspore.ops.auto_generate import group_norm_op, rms_norm, layer_norm_ext_op, batch_norm_ext_op
|
|
46
|
+
from mindspore.ops.auto_generate import (reflection_pad_1d_op, reflection_pad_2d_op, reflection_pad_3d_op, # pylint: disable=W0611
|
|
47
|
+
replication_pad_1d_op, replication_pad_2d_op, replication_pad_3d_op,
|
|
48
|
+
constant_pad_nd_op, dropout_ext_op, reverse_v2_impl)
|
|
49
|
+
from mindspore.ops.auto_generate.gen_ops_prim import embedding_op, Convolution
|
|
50
|
+
from mindspore.common.generator import default_generator
|
|
51
|
+
|
|
52
|
+
abs_ = P.Abs()
|
|
53
|
+
add_ = P.Add()
|
|
54
|
+
bias_add_ = P.BiasAdd()
|
|
55
|
+
cast_ = P.Cast()
|
|
56
|
+
div_ = P.Div()
|
|
57
|
+
dtype_ = P.DType()
|
|
58
|
+
equal_ = P.Equal()
|
|
59
|
+
erf_ = P.Erf()
|
|
60
|
+
exp_ = P.Exp()
|
|
61
|
+
expand_dims_ = P.ExpandDims()
|
|
62
|
+
fillv2_ = P.FillV2()
|
|
63
|
+
gather_ = P.Gather()
|
|
64
|
+
gather_d_ = P.GatherD()
|
|
65
|
+
gelu_ = P.GeLU()
|
|
66
|
+
greater_ = P.Greater()
|
|
48
67
|
hardswish_ = P.HSwish()
|
|
68
|
+
less_ = P.Less()
|
|
69
|
+
list_to_tensor_ = ListToTensor()
|
|
70
|
+
log_ = P.Log()
|
|
71
|
+
matmul_ = P.MatMul()
|
|
72
|
+
maximum_ = P.Maximum()
|
|
73
|
+
minimum_ = P.Minimum()
|
|
49
74
|
mish_ = NN_OPS.Mish()
|
|
50
|
-
|
|
75
|
+
mul_ = P.Mul()
|
|
76
|
+
neg_ = P.Neg()
|
|
77
|
+
ones_like_ = P.OnesLike()
|
|
78
|
+
reduce_mean_ = P.ReduceMean()
|
|
79
|
+
reduce_sum_ = P.ReduceSum()
|
|
80
|
+
reshape_ = P.Reshape()
|
|
51
81
|
scalar_to_tensor_ = P.ScalarToTensor()
|
|
52
|
-
|
|
53
|
-
|
|
82
|
+
select_ = P.Select()
|
|
83
|
+
selu_ = NN_OPS.SeLU()
|
|
84
|
+
shape_ = P.Shape()
|
|
85
|
+
sigmoid_ = P.Sigmoid()
|
|
86
|
+
sign_ = P.Sign()
|
|
87
|
+
slice_ = P.Slice()
|
|
88
|
+
softplus_ = P.Softplus()
|
|
89
|
+
softsign_ = P.Softsign()
|
|
90
|
+
sqrt_ = P.Sqrt()
|
|
91
|
+
square_ = P.Square()
|
|
92
|
+
sub_ = P.Sub()
|
|
93
|
+
tensor_shape_ = P.TensorShape()
|
|
54
94
|
tensor_to_tuple_ = TensorToTuple()
|
|
55
|
-
|
|
56
|
-
|
|
95
|
+
transpose_ = P.Transpose()
|
|
96
|
+
tuple_to_tensor_ = TupleToTensor()
|
|
97
|
+
|
|
57
98
|
check_positive_int_const = validator.check_positive_int
|
|
58
99
|
check_positive_int_sequence_const = validator.check_positive_int_sequence
|
|
59
100
|
check_positive_float_const = validator.check_positive_float
|
|
@@ -63,6 +104,7 @@ check_int_const = validator.check_is_int
|
|
|
63
104
|
check_non_negative_float_const = validator.check_non_negative_float
|
|
64
105
|
check_string_const = constexpr(validator.check_string)
|
|
65
106
|
|
|
107
|
+
generator_step_ = Tensor(1, mstype.int64)
|
|
66
108
|
|
|
67
109
|
def adaptive_avg_pool2d(input, output_size):
|
|
68
110
|
r"""
|
|
@@ -103,11 +145,11 @@ def adaptive_avg_pool2d(input, output_size):
|
|
|
103
145
|
.. math::
|
|
104
146
|
|
|
105
147
|
out\_shape = \begin{cases}
|
|
106
|
-
input\
|
|
107
|
-
output\_size[0] + input\
|
|
108
|
-
input\
|
|
109
|
-
(h, h), & \text{if
|
|
110
|
-
(h, w), & \text{if
|
|
148
|
+
input\_shape[-2] + output\_size[1], & \text{if } output\_size text{ is (None, w);}\\
|
|
149
|
+
output\_size[0] + input\_shape[-1], & \text{if } output\_size text{ is (h, None);}\\
|
|
150
|
+
input\_shape[-2:], & \text{if } output\_size text{ is (None, None);}\\
|
|
151
|
+
(h, h), & \text{if } output\_size text{ is h;}\\
|
|
152
|
+
(h, w), & \text{if } output\_size text{ is (h, w)}
|
|
111
153
|
\end{cases}
|
|
112
154
|
|
|
113
155
|
Raises:
|
|
@@ -275,7 +317,7 @@ def avg_pool1d(input_x, kernel_size=1, stride=1, padding=0, ceil_mode=False, cou
|
|
|
275
317
|
Tensor of shape :math:`(N, C_{out}, L_{out})`.
|
|
276
318
|
|
|
277
319
|
Raises:
|
|
278
|
-
TypeError: If `input_x` is not
|
|
320
|
+
TypeError: If `input_x` is not a Tensor.
|
|
279
321
|
TypeError: If `kernel_size` or `stride` is not an int.
|
|
280
322
|
TypeError: If `ceil_mode` or `count_include_pad` is not a bool.
|
|
281
323
|
ValueError: If length of shape of `input_x` is not equal to `3`.
|
|
@@ -298,9 +340,6 @@ def avg_pool1d(input_x, kernel_size=1, stride=1, padding=0, ceil_mode=False, cou
|
|
|
298
340
|
if not isinstance(input_x, (Tensor, Tensor_)):
|
|
299
341
|
raise TypeError("For avg_pool1d, the input input_x must be tensor")
|
|
300
342
|
|
|
301
|
-
if len(input_x.shape) != 3:
|
|
302
|
-
raise ValueError(f"For avg_pool1d, input must have 3 dim, but got {len(input_x.shape)}.")
|
|
303
|
-
|
|
304
343
|
_check_avgpool_1d_type_and_int(kernel_size, stride, ceil_mode, count_include_pad)
|
|
305
344
|
if isinstance(padding, int):
|
|
306
345
|
check_non_negative_int(padding, 'padding', 'avg_pool1d')
|
|
@@ -319,7 +358,6 @@ def avg_pool1d(input_x, kernel_size=1, stride=1, padding=0, ceil_mode=False, cou
|
|
|
319
358
|
raise ValueError("For avg_pool1d, stride should be int or tuple of length 1.")
|
|
320
359
|
stride = stride[0]
|
|
321
360
|
|
|
322
|
-
expand_op = _get_cache_prim(P.ExpandDims)()
|
|
323
361
|
squeeze_op = _get_cache_prim(P.Squeeze)((2, 3))
|
|
324
362
|
avg_pool_op = _get_cache_prim(P.AvgPool3D)(kernel_size=(1, 1, kernel_size),
|
|
325
363
|
strides=(1, 1, stride),
|
|
@@ -327,8 +365,8 @@ def avg_pool1d(input_x, kernel_size=1, stride=1, padding=0, ceil_mode=False, cou
|
|
|
327
365
|
pad=padding,
|
|
328
366
|
ceil_mode=ceil_mode,
|
|
329
367
|
count_include_pad=count_include_pad)
|
|
330
|
-
input_x =
|
|
331
|
-
input_x =
|
|
368
|
+
input_x = expand_dims_(input_x, 2)
|
|
369
|
+
input_x = expand_dims_(input_x, 2)
|
|
332
370
|
input_x = avg_pool_op(input_x)
|
|
333
371
|
input_x = squeeze_op(input_x)
|
|
334
372
|
return input_x
|
|
@@ -429,7 +467,7 @@ def avg_pool2d(input_x, kernel_size=1, stride=1, padding=0, ceil_mode=False, cou
|
|
|
429
467
|
Tensor, with shape :math:`(N, C_{out}, H_{out}, W_{out})`.
|
|
430
468
|
|
|
431
469
|
Raises:
|
|
432
|
-
TypeError: If `input_x` is not
|
|
470
|
+
TypeError: If `input_x` is not a Tensor.
|
|
433
471
|
TypeError: If `kernel_size` or `stride` is neither int nor tuple.
|
|
434
472
|
TypeError: If `ceil_mode` or `count_include_pad` is not a bool.
|
|
435
473
|
TypeError: If `divisor_override` is not an int.
|
|
@@ -459,15 +497,10 @@ def avg_pool2d(input_x, kernel_size=1, stride=1, padding=0, ceil_mode=False, cou
|
|
|
459
497
|
if not isinstance(input_x, (Tensor, Tensor_)):
|
|
460
498
|
raise TypeError("For avg_pool2d, the input input_x must be tensor")
|
|
461
499
|
|
|
462
|
-
if len(input_x.shape) != 4:
|
|
463
|
-
raise ValueError(f"For avg_pool2d, input must have 4 dim, but got {len(input_x.shape)}.")
|
|
464
|
-
|
|
465
500
|
kernel_size = _check_avgpool_2d_kernel_size(kernel_size)
|
|
466
501
|
stride = _check_avgpool_2d_stride(stride)
|
|
467
502
|
padding = _check_avgpool_2d_padding(padding)
|
|
468
503
|
_check_avg_pool2d_type_and_value(ceil_mode, count_include_pad, divisor_override)
|
|
469
|
-
|
|
470
|
-
expand_op = _get_cache_prim(P.ExpandDims)()
|
|
471
504
|
squeeze_op = _get_cache_prim(P.Squeeze)(2)
|
|
472
505
|
avg_pool_op = _get_cache_prim(P.AvgPool3D)(kernel_size=kernel_size,
|
|
473
506
|
strides=stride,
|
|
@@ -476,13 +509,82 @@ def avg_pool2d(input_x, kernel_size=1, stride=1, padding=0, ceil_mode=False, cou
|
|
|
476
509
|
ceil_mode=ceil_mode,
|
|
477
510
|
count_include_pad=count_include_pad,
|
|
478
511
|
divisor_override=divisor_override)
|
|
479
|
-
input_x =
|
|
512
|
+
input_x = expand_dims_(input_x, 2)
|
|
480
513
|
input_x = avg_pool_op(input_x)
|
|
481
514
|
input_x = squeeze_op(input_x)
|
|
482
515
|
return input_x
|
|
483
516
|
|
|
484
517
|
|
|
485
|
-
|
|
518
|
+
def avg_pool2d_ext(input, kernel_size, stride=None, padding=0, ceil_mode=False, count_include_pad=True,
|
|
519
|
+
divisor_override=None):
|
|
520
|
+
r"""
|
|
521
|
+
Applies a 2D average pooling over an input Tensor which can be regarded as a composition of 2D input planes.
|
|
522
|
+
Typically the input is of shape :math:`(N, C, H_{in}, W_{in})`, outputs regional average in the
|
|
523
|
+
:math:`(H_{in}, W_{in})`-dimension. Given kernel size :math:`(k_{H}, k_{W})` and `stride` , the operation
|
|
524
|
+
is as follows.
|
|
525
|
+
|
|
526
|
+
.. math::
|
|
527
|
+
\text{output}(N_i, C_j, h, w) = \frac{1}{k_{H} * k_{W}} \sum_{m=0}^{k_{H}-1} \sum_{n=0}^{k_{W}-1}
|
|
528
|
+
\text{input}(N_i, C_j, stride[0] \times h + m, stride[1] \times w + n)
|
|
529
|
+
|
|
530
|
+
Args:
|
|
531
|
+
input (Tensor): Tensor of shape :math:`(N, C, H_{in}, W_{in})`.
|
|
532
|
+
kernel_size (Union[int, tuple[int], list[int]]): The size of kernel used to take the average value.
|
|
533
|
+
Can be a single number or a tuple (kH, kW).
|
|
534
|
+
stride (Union[int, tuple[int], list[int]]): The distance of kernel moving. Can be a single number or
|
|
535
|
+
a tuple (sH, sW). Default value is `kernel_size` .
|
|
536
|
+
padding (Union(int, tuple[int], list[int])): Implicit zero padding to be added on both sides.
|
|
537
|
+
Can be a single number or a tuple (padH, padW). Default: 0.
|
|
538
|
+
ceil_mode (bool): If True, apply ceil instead of floor to compute the output shape.
|
|
539
|
+
Default: ``False``.
|
|
540
|
+
count_include_pad (bool): If True, include the zero-padding in the averaging calculation.
|
|
541
|
+
Default: ``True`` .
|
|
542
|
+
divisor_override (int): If specified, it will be used as divisor in the averaging calculation,
|
|
543
|
+
otherwise size of pooling region will be used. Default: ``None``.
|
|
544
|
+
|
|
545
|
+
Returns:
|
|
546
|
+
Tensor, with shape :math:`(N, C, H_{out}, W_{out})`.
|
|
547
|
+
|
|
548
|
+
.. math::
|
|
549
|
+
\begin{array}{ll} \\
|
|
550
|
+
H_{out} = \frac{H_{in} + 2 \times padding[0] - kernel_size[0]}{stride[0]} + 1 \\
|
|
551
|
+
W_{out} = \frac{W_{in} + 2 \times padding[1] - kernel_size[1]}{stride[1]} + 1
|
|
552
|
+
\end{array}
|
|
553
|
+
|
|
554
|
+
Raises:
|
|
555
|
+
TypeError: If `input` is not a Tensor.
|
|
556
|
+
TypeError: If `kernel_size` or `stride` is neither int nor tuple.
|
|
557
|
+
TypeError: If `ceil_mode` or `count_include_pad` is not a bool.
|
|
558
|
+
TypeError: If `divisor_override` is not an int or None.
|
|
559
|
+
ValueError: If the dimension of `input` is not equal to `4` or `3`.
|
|
560
|
+
ValueError: If `kernel_size` or `stride` is less than 1.
|
|
561
|
+
ValueError: If `kernel_size` or `stride` is a tuple whose length is not equal to `2` or `1`.
|
|
562
|
+
ValueError: If `padding` is neither a int nor a tuple whose length is equal to `2` or `1`.
|
|
563
|
+
ValueError: If value of `padding` is less than `0`.
|
|
564
|
+
|
|
565
|
+
Supported Platforms:
|
|
566
|
+
``Ascend``
|
|
567
|
+
|
|
568
|
+
Examples:
|
|
569
|
+
>>> import mindspore
|
|
570
|
+
>>> import numpy as np
|
|
571
|
+
>>> from mindspore import Tensor, ops
|
|
572
|
+
>>> x = Tensor(np.arange(1 * 3 * 3 * 4).reshape(1, 3, 3, 4), mindspore.float32)
|
|
573
|
+
>>> output = ops.function.nn_func.avg_pool2d_ext(x, kernel_size=2, stride=1)
|
|
574
|
+
>>> print(output)
|
|
575
|
+
[[[[ 2.5 3.5 4.5]
|
|
576
|
+
[ 6.5 7.5 8.5]]
|
|
577
|
+
[[14.5 15.5 16.5]
|
|
578
|
+
[18.5 19.5 20.5]]
|
|
579
|
+
[[26.5 27.5 28.5]
|
|
580
|
+
[30.5 31.5 32.5]]]]
|
|
581
|
+
"""
|
|
582
|
+
if stride is None:
|
|
583
|
+
stride = kernel_size
|
|
584
|
+
return _get_cache_prim(ops.auto_generate.AvgPool2D)()(input, kernel_size, stride, padding,
|
|
585
|
+
ceil_mode, count_include_pad, divisor_override)
|
|
586
|
+
|
|
587
|
+
|
|
486
588
|
def _check_avg_pool3d_padding(padding):
|
|
487
589
|
"""Check the padding value in avg_pool3d op."""
|
|
488
590
|
if isinstance(padding, int):
|
|
@@ -537,7 +639,7 @@ def avg_pool3d(input_x, kernel_size=1, stride=1, padding=0, ceil_mode=False, cou
|
|
|
537
639
|
Tensor, with shape :math:`(N, C, D_{out}, H_{out}, W_{out})`. Has the same data type with `input_x`.
|
|
538
640
|
|
|
539
641
|
Raises:
|
|
540
|
-
TypeError: If `input_x` is not
|
|
642
|
+
TypeError: If `input_x` is not a Tensor.
|
|
541
643
|
TypeError: If `kernel_size`, `stride` or `padding` is neither an int not a tuple.
|
|
542
644
|
TypeError: If `ceil_mode` or `count_include_pad` is not a bool.
|
|
543
645
|
TypeError: If `divisor_override` is not an int.
|
|
@@ -563,9 +665,6 @@ def avg_pool3d(input_x, kernel_size=1, stride=1, padding=0, ceil_mode=False, cou
|
|
|
563
665
|
if not isinstance(input_x, (Tensor, Tensor_)):
|
|
564
666
|
raise TypeError("For avg_pool3d, the input input_x must be tensor")
|
|
565
667
|
|
|
566
|
-
if len(input_x.shape) != 5:
|
|
567
|
-
raise ValueError(f"For avg_pool3d, input must have 5 dim, but got {len(input_x.shape)}.")
|
|
568
|
-
|
|
569
668
|
_check_avg_pool3d_padding(padding)
|
|
570
669
|
|
|
571
670
|
avg_pool_op = _get_cache_prim(P.AvgPool3D)(kernel_size=kernel_size,
|
|
@@ -638,7 +737,7 @@ def adaptive_max_pool1d(input, output_size):
|
|
|
638
737
|
_check_adaptive_max_pool1d_output_size(output_size)
|
|
639
738
|
|
|
640
739
|
x_in_shape = input.shape
|
|
641
|
-
x_dtype =
|
|
740
|
+
x_dtype = dtype_(input)
|
|
642
741
|
|
|
643
742
|
if len(x_in_shape) != 3:
|
|
644
743
|
raise ValueError(f"For adaptive_max_pool1d input must have 3 dim, but got {len(x_in_shape)}.")
|
|
@@ -657,18 +756,14 @@ def adaptive_max_pool1d(input, output_size):
|
|
|
657
756
|
raise TypeError(f"For adaptive_max_pool1d, the input dtype must be float16 or float32, "
|
|
658
757
|
f"but got {x_dtype}.")
|
|
659
758
|
|
|
660
|
-
expand_ = _get_cache_prim(P.ExpandDims)()
|
|
661
759
|
squeeze_ = _get_cache_prim(P.Squeeze)(2)
|
|
662
|
-
|
|
663
760
|
width = x_in_shape[2]
|
|
664
761
|
stride = width // output_size
|
|
665
762
|
kernel_size = width - (output_size - 1) * stride
|
|
666
763
|
stride = (1, width // output_size)
|
|
667
764
|
kernel_size = (1, kernel_size)
|
|
668
|
-
|
|
669
765
|
max_pool_ = _get_cache_prim(NN_OPS.MaxPool)(kernel_size=kernel_size, strides=stride)
|
|
670
|
-
|
|
671
|
-
input = expand_(input, 2)
|
|
766
|
+
input = expand_dims_(input, 2)
|
|
672
767
|
input = max_pool_(input)
|
|
673
768
|
input = squeeze_(input)
|
|
674
769
|
|
|
@@ -807,6 +902,8 @@ def adaptive_max_pool3d(input, output_size, return_indices=False):
|
|
|
807
902
|
>>> print(output[1].asnumpy())
|
|
808
903
|
[[[[33 35]]]]
|
|
809
904
|
"""
|
|
905
|
+
if isinstance(output_size, int):
|
|
906
|
+
output_size = (output_size, output_size, output_size)
|
|
810
907
|
adaptive_max_pool3d_ = _get_cache_prim(NN_OPS.AdaptiveMaxPool3D)()
|
|
811
908
|
output_size_ = Tensor(output_size, dtype=mstype.int32)
|
|
812
909
|
out = adaptive_max_pool3d_(input, output_size_)
|
|
@@ -814,18 +911,6 @@ def adaptive_max_pool3d(input, output_size, return_indices=False):
|
|
|
814
911
|
return output
|
|
815
912
|
|
|
816
913
|
|
|
817
|
-
def check_shape(x_shape, indices_shape, func_name):
|
|
818
|
-
"""
|
|
819
|
-
:param x_shape: the shape of x.
|
|
820
|
-
:param indices_shape: the shape of indices.
|
|
821
|
-
:param func_name: the name of function.
|
|
822
|
-
:return:
|
|
823
|
-
"""
|
|
824
|
-
if x_shape != indices_shape:
|
|
825
|
-
raise ValueError(f"For {func_name}, the x shape and indices shape must be equal, but got input "
|
|
826
|
-
f"shape {x_shape} and indices shape {indices_shape}.")
|
|
827
|
-
|
|
828
|
-
|
|
829
914
|
def max_unpool1d(x, indices, kernel_size, stride=None, padding=0, output_size=None):
|
|
830
915
|
r"""
|
|
831
916
|
Computes the inverse of `max_pool1d`.
|
|
@@ -836,7 +921,7 @@ def max_unpool1d(x, indices, kernel_size, stride=None, padding=0, output_size=No
|
|
|
836
921
|
|
|
837
922
|
.. math::
|
|
838
923
|
\begin{array}{ll} \\
|
|
839
|
-
H_{out} = (
|
|
924
|
+
H_{out} = (H_{in} - 1) \times stride[0] - 2 \times padding[0] + kernel\_size[0] \\
|
|
840
925
|
\end{array}
|
|
841
926
|
|
|
842
927
|
Args:
|
|
@@ -885,13 +970,8 @@ def max_unpool1d(x, indices, kernel_size, stride=None, padding=0, output_size=No
|
|
|
885
970
|
if stride is None:
|
|
886
971
|
stride = kernel_size
|
|
887
972
|
|
|
888
|
-
|
|
889
|
-
x_shape = shape(x)
|
|
890
|
-
indices_shape = shape(indices)
|
|
973
|
+
x_shape = shape_(x)
|
|
891
974
|
x_dim = len(x_shape)
|
|
892
|
-
check_shape(x_shape, indices_shape, "max_unpool1d")
|
|
893
|
-
if x_dim not in (2, 3):
|
|
894
|
-
raise ValueError(f"For max_unpool1d, the x shape must have 2 or 3 dims, but got {x_dim}.")
|
|
895
975
|
|
|
896
976
|
if output_size is None:
|
|
897
977
|
output_size = ()
|
|
@@ -1009,13 +1089,8 @@ def max_unpool2d(x, indices, kernel_size, stride=None, padding=0, output_size=No
|
|
|
1009
1089
|
if stride is None:
|
|
1010
1090
|
stride = kernel_size
|
|
1011
1091
|
|
|
1012
|
-
|
|
1013
|
-
x_shape = shape(x)
|
|
1014
|
-
indices_shape = shape(indices)
|
|
1092
|
+
x_shape = shape_(x)
|
|
1015
1093
|
x_dim = len(x_shape)
|
|
1016
|
-
check_shape(x_shape, indices_shape, "max_unpool2d")
|
|
1017
|
-
if x_dim not in (3, 4):
|
|
1018
|
-
raise ValueError(f"For max_unpool2d, the x shape must have 3 or 4 dims, but got {x_dim}.")
|
|
1019
1094
|
|
|
1020
1095
|
if output_size is None:
|
|
1021
1096
|
output_size = ()
|
|
@@ -1118,12 +1193,8 @@ def max_unpool3d(x, indices, kernel_size, stride=None, padding=0, output_size=No
|
|
|
1118
1193
|
if stride is None:
|
|
1119
1194
|
stride = kernel_size
|
|
1120
1195
|
|
|
1121
|
-
x_shape =
|
|
1122
|
-
indices_shape = P.Shape()(indices)
|
|
1196
|
+
x_shape = shape_(x)
|
|
1123
1197
|
x_dim = len(x_shape)
|
|
1124
|
-
check_shape(x_shape, indices_shape, "max_unpool3d")
|
|
1125
|
-
if x_dim not in (4, 5):
|
|
1126
|
-
raise ValueError(f"For max_unpool3d, the x shape must have 4 or 5 dims, but got {x_dim}.")
|
|
1127
1198
|
|
|
1128
1199
|
if output_size is None:
|
|
1129
1200
|
output_size = ()
|
|
@@ -1151,12 +1222,12 @@ def max_unpool3d(x, indices, kernel_size, stride=None, padding=0, output_size=No
|
|
|
1151
1222
|
return out
|
|
1152
1223
|
|
|
1153
1224
|
|
|
1154
|
-
def binary_cross_entropy_with_logits(
|
|
1225
|
+
def binary_cross_entropy_with_logits(input, target, weight=None, pos_weight=None, reduction='mean'):
|
|
1155
1226
|
r"""
|
|
1156
|
-
Adds sigmoid activation function to input `logits
|
|
1157
|
-
between the
|
|
1227
|
+
Adds sigmoid activation function to input `input` as logits, and uses the given logits to compute binary cross
|
|
1228
|
+
entropy between the `input` and the `target`.
|
|
1158
1229
|
|
|
1159
|
-
Sets input
|
|
1230
|
+
Sets input `input` as :math:`X`, input target as :math:`Y`, input weight as :math:`W`, output as :math:`L`. Then,
|
|
1160
1231
|
|
|
1161
1232
|
.. math::
|
|
1162
1233
|
|
|
@@ -1197,14 +1268,14 @@ def binary_cross_entropy_with_logits(logits, label, weight=None, pos_weight=None
|
|
|
1197
1268
|
:math:`P_c>1` increases the recall, :math:`P_c<1` increases the precision.
|
|
1198
1269
|
|
|
1199
1270
|
Args:
|
|
1200
|
-
|
|
1201
|
-
|
|
1271
|
+
input (Tensor): Input `input`. Data type must be float16 or float32.
|
|
1272
|
+
target (Tensor): Ground truth label, has the same shape as `input`.
|
|
1202
1273
|
Data type must be float16 or float32.
|
|
1203
1274
|
weight (Tensor, optional): A rescaling weight applied to the loss of each batch element. It can be
|
|
1204
|
-
broadcast to a tensor with shape of `
|
|
1275
|
+
broadcast to a tensor with shape of `input`. Data type must be float16 or float32.
|
|
1205
1276
|
Default: ``None``, `weight` is a Tensor whose value is ``1``.
|
|
1206
1277
|
pos_weight (Tensor, optional): A weight of positive examples. Must be a vector with length equal to the
|
|
1207
|
-
number of classes. It can be broadcast to a tensor with shape of `
|
|
1278
|
+
number of classes. It can be broadcast to a tensor with shape of `input`.
|
|
1208
1279
|
Data type must be float16 or float32. Default: ``None``, `pos_weight` is a Tensor whose value is ``1``.
|
|
1209
1280
|
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
1210
1281
|
``'sum'`` . Default: ``'mean'`` .
|
|
@@ -1214,14 +1285,14 @@ def binary_cross_entropy_with_logits(logits, label, weight=None, pos_weight=None
|
|
|
1214
1285
|
- ``'sum'``: the output elements will be summed.
|
|
1215
1286
|
|
|
1216
1287
|
Returns:
|
|
1217
|
-
Tensor or Scalar, if `reduction` is ``'none'``, it's a tensor with the same shape and type as input `
|
|
1288
|
+
Tensor or Scalar, if `reduction` is ``'none'``, it's a tensor with the same shape and type as input `input`.
|
|
1218
1289
|
Otherwise, the output is a scalar.
|
|
1219
1290
|
|
|
1220
1291
|
Raises:
|
|
1221
|
-
TypeError: If input `
|
|
1222
|
-
TypeError: If data type of input `
|
|
1292
|
+
TypeError: If input `input`, `target`, `weight`, `pos_weight` is not Tensor.
|
|
1293
|
+
TypeError: If data type of input `input`, `target`, `weight`, `pos_weight` is neither float16 nor float32.
|
|
1223
1294
|
TypeError: If data type of input `reduction` is not string.
|
|
1224
|
-
ValueError: If `weight` or `pos_weight` can not be broadcast to a tensor with shape of `
|
|
1295
|
+
ValueError: If `weight` or `pos_weight` can not be broadcast to a tensor with shape of `input`.
|
|
1225
1296
|
ValueError: If `reduction` is not one of ``'none'``, ``'mean'`` or ``'sum'``.
|
|
1226
1297
|
|
|
1227
1298
|
Supported Platforms:
|
|
@@ -1231,21 +1302,17 @@ def binary_cross_entropy_with_logits(logits, label, weight=None, pos_weight=None
|
|
|
1231
1302
|
>>> import mindspore
|
|
1232
1303
|
>>> import numpy as np
|
|
1233
1304
|
>>> from mindspore import Tensor, ops
|
|
1234
|
-
>>>
|
|
1235
|
-
>>>
|
|
1305
|
+
>>> input = Tensor(np.array([[-0.8, 1.2, 0.7], [-0.1, -0.4, 0.7]]), mindspore.float32)
|
|
1306
|
+
>>> target = Tensor(np.array([[0.3, 0.8, 1.2], [-0.6, 0.1, 2.2]]), mindspore.float32)
|
|
1236
1307
|
>>> weight = Tensor(np.array([1.0, 1.0, 1.0]), mindspore.float32)
|
|
1237
1308
|
>>> pos_weight = Tensor(np.array([1.0, 1.0, 1.0]), mindspore.float32)
|
|
1238
|
-
>>> output = ops.binary_cross_entropy_with_logits(
|
|
1309
|
+
>>> output = ops.binary_cross_entropy_with_logits(input, target, weight, pos_weight)
|
|
1239
1310
|
>>> print(output)
|
|
1240
1311
|
0.3463612
|
|
1241
1312
|
"""
|
|
1242
1313
|
|
|
1243
|
-
if weight is None:
|
|
1244
|
-
weight = ops.ones_like(logits)
|
|
1245
|
-
if pos_weight is None:
|
|
1246
|
-
pos_weight = ops.ones_like(logits)
|
|
1247
1314
|
bce_with_logits_loss_op = _get_cache_prim(NN_OPS.BCEWithLogitsLoss)(reduction)
|
|
1248
|
-
return bce_with_logits_loss_op(
|
|
1315
|
+
return bce_with_logits_loss_op(input, target, weight, pos_weight)
|
|
1249
1316
|
|
|
1250
1317
|
|
|
1251
1318
|
@_function_forbid_reuse
|
|
@@ -1294,47 +1361,45 @@ def dropout(input, p=0.5, training=True, seed=None):
|
|
|
1294
1361
|
return out
|
|
1295
1362
|
|
|
1296
1363
|
|
|
1297
|
-
|
|
1364
|
+
@_function_forbid_reuse
|
|
1365
|
+
def dropout_ext(input, p=0.5, training=True):
|
|
1298
1366
|
r"""
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
\text{CeLU}(x) = \max(0,x) + \min(0, \alpha * (\exp(x/\alpha) - 1))
|
|
1305
|
-
|
|
1306
|
-
For more details, please refer to `celu <https://arxiv.org/abs/1704.07483>`_.
|
|
1307
|
-
|
|
1308
|
-
.. warning::
|
|
1309
|
-
This is an experimental API that is subject to change or deletion.
|
|
1367
|
+
During training, randomly zeroes some of the elements of the input tensor
|
|
1368
|
+
with probability `p` from a Bernoulli distribution. It plays the role of reducing neuron correlation and
|
|
1369
|
+
avoid overfitting. And the return will be multiplied by :math:`\frac{1}{1-p}` during training.
|
|
1370
|
+
During the reasoning, this operation returns the same Tensor as the `input`.
|
|
1310
1371
|
|
|
1311
1372
|
Args:
|
|
1312
|
-
|
|
1313
|
-
|
|
1373
|
+
input (Tensor): The input Tensor of shape :math:`(*, N)`.
|
|
1374
|
+
p (float): The dropping rate of input neurons, between 0 and 1, e.g. `p` = 0.1,
|
|
1375
|
+
means dropping out 10% of input neurons. Default: ``0.5`` .
|
|
1376
|
+
training (bool): Apply dropout if it is ``True`` , if it is ``False`` , the input is returned directly,
|
|
1377
|
+
and `p` is invalid. Default: ``True``.
|
|
1314
1378
|
|
|
1315
1379
|
Returns:
|
|
1316
|
-
Tensor,
|
|
1380
|
+
- **output** (Tensor) - Zeroed tensor, with the same shape and data type as `input`.
|
|
1317
1381
|
|
|
1318
1382
|
Raises:
|
|
1319
|
-
TypeError: If `
|
|
1320
|
-
TypeError: If `
|
|
1321
|
-
TypeError: If dtype of `x` is neither float16 nor float32.
|
|
1322
|
-
ValueError: If `alpha` has the value of 0.
|
|
1383
|
+
TypeError: If `p` is not a float.
|
|
1384
|
+
TypeError: If `input` is not a Tensor.
|
|
1323
1385
|
|
|
1324
1386
|
Supported Platforms:
|
|
1325
|
-
``Ascend``
|
|
1387
|
+
``Ascend``
|
|
1326
1388
|
|
|
1327
1389
|
Examples:
|
|
1328
1390
|
>>> import mindspore
|
|
1329
|
-
>>> import numpy as np
|
|
1330
1391
|
>>> from mindspore import Tensor, ops
|
|
1331
|
-
>>>
|
|
1332
|
-
>>> output = ops.
|
|
1333
|
-
>>> print(output)
|
|
1334
|
-
|
|
1392
|
+
>>> input = Tensor(((20, 16), (50, 50)), mindspore.float32)
|
|
1393
|
+
>>> output = ops.function.nn_func.dropout_ext(input, p=0.5)
|
|
1394
|
+
>>> print(output.shape)
|
|
1395
|
+
(2, 2)
|
|
1335
1396
|
"""
|
|
1336
|
-
|
|
1337
|
-
|
|
1397
|
+
check_bool_const(training, "training", "dropout_ext")
|
|
1398
|
+
if training is False:
|
|
1399
|
+
return input
|
|
1400
|
+
seed, offset = default_generator._step(generator_step_) # pylint: disable=protected-access
|
|
1401
|
+
out, _ = dropout_ext_op(input, p, seed, offset)
|
|
1402
|
+
return out
|
|
1338
1403
|
|
|
1339
1404
|
|
|
1340
1405
|
def dropout1d(input, p=0.5, training=True):
|
|
@@ -1520,42 +1585,6 @@ def dropout3d(input, p=0.5, training=True):
|
|
|
1520
1585
|
return out
|
|
1521
1586
|
|
|
1522
1587
|
|
|
1523
|
-
def fast_gelu(x):
|
|
1524
|
-
r"""
|
|
1525
|
-
Fast Gaussian Error Linear Units activation function.
|
|
1526
|
-
|
|
1527
|
-
FastGeLU is defined as follows:
|
|
1528
|
-
|
|
1529
|
-
.. math::
|
|
1530
|
-
\text{output} = \frac {x} {1 + \exp(-1.702 * \left| x \right|)} * \exp(0.851 * (x - \left| x \right|)),
|
|
1531
|
-
|
|
1532
|
-
where :math:`x` is the element of the input.
|
|
1533
|
-
|
|
1534
|
-
Args:
|
|
1535
|
-
x (Tensor): Input to compute the FastGeLU with data type of float16 or float32.
|
|
1536
|
-
|
|
1537
|
-
Returns:
|
|
1538
|
-
Tensor, with the same type and shape as `x`.
|
|
1539
|
-
|
|
1540
|
-
Raises:
|
|
1541
|
-
TypeError: If dtype of `x` is neither float16 nor float32.
|
|
1542
|
-
|
|
1543
|
-
Supported Platforms:
|
|
1544
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
1545
|
-
|
|
1546
|
-
Examples:
|
|
1547
|
-
>>> import mindspore
|
|
1548
|
-
>>> import numpy as np
|
|
1549
|
-
>>> from mindspore import Tensor, ops
|
|
1550
|
-
>>> x = Tensor(np.array([[-1.0, 4.0, -8.0], [2.0, -5.0, 9.0]]), mindspore.float32)
|
|
1551
|
-
>>> output = ops.fast_gelu(x)
|
|
1552
|
-
>>> print(output)
|
|
1553
|
-
[[-1.5418735e-01 3.9921875e+00 -9.7473649e-06]
|
|
1554
|
-
[ 1.9375000e+00 -1.0052517e-03 8.9824219e+00]]
|
|
1555
|
-
"""
|
|
1556
|
-
return fast_gelu_(x)
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
1588
|
@_primexpr
|
|
1560
1589
|
def _check_float_range_inc_neither(arg_value, lower_limit, upper_limit, arg_name=None, prim_name=None):
|
|
1561
1590
|
"""
|
|
@@ -1574,7 +1603,7 @@ def _check_fractional_output_size_ratio(output_size, output_ratio, cls_name):
|
|
|
1574
1603
|
def fractional_max_pool2d(input, kernel_size, output_size=None, output_ratio=None, return_indices=False,
|
|
1575
1604
|
_random_samples=None):
|
|
1576
1605
|
r"""
|
|
1577
|
-
Applies the 2D FractionalMaxPool
|
|
1606
|
+
Applies the 2D FractionalMaxPool operation over `input`. The output Tensor shape can be determined by either
|
|
1578
1607
|
`output_size` or `output_ratio`, and the step size is determined by `_random_samples`. `output_size` will take
|
|
1579
1608
|
effect when `output_size` and `output_ratio` are set at the same time.
|
|
1580
1609
|
And `output_size` and `output_ratio` can not be ``None`` at the same time.
|
|
@@ -1686,7 +1715,7 @@ def fractional_max_pool2d(input, kernel_size, output_size=None, output_ratio=Non
|
|
|
1686
1715
|
def fractional_max_pool3d(input, kernel_size, output_size=None, output_ratio=None, return_indices=False,
|
|
1687
1716
|
_random_samples=None):
|
|
1688
1717
|
r"""
|
|
1689
|
-
Applies the 3D FractionalMaxPool
|
|
1718
|
+
Applies the 3D FractionalMaxPool operation over `input`. The output Tensor shape can be determined by either
|
|
1690
1719
|
`output_size` or `output_ratio`, and the step size is determined by `_random_samples`. `output_size` will take
|
|
1691
1720
|
effect when `output_size` and `output_ratio` are set at the same time.
|
|
1692
1721
|
And `output_size` and `output_ratio` can not be ``None`` at the same time.
|
|
@@ -1707,7 +1736,7 @@ def fractional_max_pool3d(input, kernel_size, output_size=None, output_ratio=Non
|
|
|
1707
1736
|
is an int number that represents depth, height and width of the kernel, or a tuple
|
|
1708
1737
|
of three int numbers that represent depth, height and width respectively.
|
|
1709
1738
|
The value must be a positive integer.
|
|
1710
|
-
output_size (Union[int, tuple[int]], optional): The
|
|
1739
|
+
output_size (Union[int, tuple[int]], optional): The shape of the target `output_size`,
|
|
1711
1740
|
is an int number that represents depth, height and width, or a tuple
|
|
1712
1741
|
of three int numbers that represent depth, height and width respectively.
|
|
1713
1742
|
The value must be a positive integer.
|
|
@@ -1813,10 +1842,10 @@ def kl_div(logits, labels, reduction='mean'):
|
|
|
1813
1842
|
|
|
1814
1843
|
.. math::
|
|
1815
1844
|
\ell(x, target) = \begin{cases}
|
|
1816
|
-
L, & \text{if reduction} = \text{'none';}\\
|
|
1817
|
-
\operatorname{mean}(L), & \text{if reduction} = \text{'mean';}\\
|
|
1818
|
-
\operatorname{
|
|
1819
|
-
\operatorname{sum}(L), & \text{if reduction} = \text{'sum'.}
|
|
1845
|
+
L(x, target), & \text{if reduction} = \text{'none';}\\
|
|
1846
|
+
\operatorname{mean}(L(x, target)), & \text{if reduction} = \text{'mean';}\\
|
|
1847
|
+
\operatorname{sum}(L(x, target)) / x.\operatorname{shape}[0], & \text{if reduction} = \text{'batchmean';}\\
|
|
1848
|
+
\operatorname{sum}(L(x, target)), & \text{if reduction} = \text{'sum'.}
|
|
1820
1849
|
\end{cases}
|
|
1821
1850
|
|
|
1822
1851
|
where :math:`x` represents `logits`.
|
|
@@ -1826,7 +1855,7 @@ def kl_div(logits, labels, reduction='mean'):
|
|
|
1826
1855
|
Note:
|
|
1827
1856
|
- Currently it does not support float64 input on `Ascend`.
|
|
1828
1857
|
- The output aligns with the mathematical definition of Kullback-Leibler divergence
|
|
1829
|
-
only when `reduction` is set to 'batchmean'
|
|
1858
|
+
only when `reduction` is set to ``'batchmean'``.
|
|
1830
1859
|
|
|
1831
1860
|
Args:
|
|
1832
1861
|
logits (Tensor): The input Tensor. The data type must be float16, float32 or float64.
|
|
@@ -1834,6 +1863,11 @@ def kl_div(logits, labels, reduction='mean'):
|
|
|
1834
1863
|
reduction (str): Specifies the reduction to be applied to the output.
|
|
1835
1864
|
Its value must be one of ``'none'`` , ``'mean'`` , ``'batchmean'`` or ``'sum'`` . Default: ``'mean'`` .
|
|
1836
1865
|
|
|
1866
|
+
- ``'none'``: no reduction will be applied.
|
|
1867
|
+
- ``'mean'``: compute and return the mean of elements in the output.
|
|
1868
|
+
- ``'sum'``: the output elements will be summed.
|
|
1869
|
+
- ``'batchmean'``: the summed output elements divided by batch size.
|
|
1870
|
+
|
|
1837
1871
|
Returns:
|
|
1838
1872
|
Tensor or Scalar, if `reduction` is ``'none'``, then output is a tensor and has the same shape as `logits`.
|
|
1839
1873
|
Otherwise, it is a scalar.
|
|
@@ -1841,7 +1875,7 @@ def kl_div(logits, labels, reduction='mean'):
|
|
|
1841
1875
|
Raises:
|
|
1842
1876
|
TypeError: If `reduction` is not a str.
|
|
1843
1877
|
TypeError: If neither `logits` nor `labels` is a Tensor.
|
|
1844
|
-
TypeError: If dtype of `logits` or `labels` is not
|
|
1878
|
+
TypeError: If dtype of `logits` or `labels` is not the supported type.
|
|
1845
1879
|
|
|
1846
1880
|
Supported Platforms:
|
|
1847
1881
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -1861,20 +1895,20 @@ def kl_div(logits, labels, reduction='mean'):
|
|
|
1861
1895
|
f"'['none', 'mean', 'batchmean', 'sum']', but got '{reduction}'.")
|
|
1862
1896
|
|
|
1863
1897
|
if reduction == 'batchmean':
|
|
1864
|
-
kl_div_sum = P.KLDivLoss(reduction='sum')(logits, labels)
|
|
1865
|
-
shape =
|
|
1898
|
+
kl_div_sum = _get_cache_prim(P.KLDivLoss)(reduction='sum')(logits, labels)
|
|
1899
|
+
shape = shape_(logits)
|
|
1866
1900
|
batch_size = shape[0]
|
|
1867
1901
|
return kl_div_sum / batch_size
|
|
1868
1902
|
|
|
1869
1903
|
if reduction == 'mean':
|
|
1870
|
-
kl_div_sum = P.KLDivLoss(reduction='sum')(logits, labels)
|
|
1871
|
-
shape =
|
|
1904
|
+
kl_div_sum = _get_cache_prim(P.KLDivLoss)(reduction='sum')(logits, labels)
|
|
1905
|
+
shape = shape_(logits)
|
|
1872
1906
|
total_size = 1
|
|
1873
1907
|
for dim in shape:
|
|
1874
1908
|
total_size = total_size * dim
|
|
1875
1909
|
return kl_div_sum / total_size
|
|
1876
1910
|
|
|
1877
|
-
return P.KLDivLoss(reduction=reduction)(logits, labels)
|
|
1911
|
+
return _get_cache_prim(P.KLDivLoss)(reduction=reduction)(logits, labels)
|
|
1878
1912
|
|
|
1879
1913
|
|
|
1880
1914
|
def hardshrink(x, lambd=0.5):
|
|
@@ -1891,9 +1925,15 @@ def hardshrink(x, lambd=0.5):
|
|
|
1891
1925
|
0, & \text{ otherwise }
|
|
1892
1926
|
\end{cases}
|
|
1893
1927
|
|
|
1928
|
+
HShrink Activation Function Graph:
|
|
1929
|
+
|
|
1930
|
+
.. image:: ../images/HShrink.png
|
|
1931
|
+
:align: center
|
|
1932
|
+
|
|
1894
1933
|
Args:
|
|
1895
1934
|
x (Tensor): The input of Hard Shrink with data type of float16 or float32.
|
|
1896
|
-
lambd (float): The threshold :math:`\lambda` defined by the Hard Shrink formula.
|
|
1935
|
+
lambd (float, optional): The threshold :math:`\lambda` defined by the Hard Shrink formula.
|
|
1936
|
+
Default: ``0.5`` .
|
|
1897
1937
|
|
|
1898
1938
|
Returns:
|
|
1899
1939
|
Tensor, has the same data type and shape as the input `x`.
|
|
@@ -1995,16 +2035,16 @@ def flip(input, dims):
|
|
|
1995
2035
|
Raises:
|
|
1996
2036
|
TypeError: If the input is not a tensor.
|
|
1997
2037
|
ValueError: If `dims` is None.
|
|
1998
|
-
ValueError: If `dims` is not a tuple of ints.
|
|
2038
|
+
ValueError: If `dims` is not a list/tuple of ints.
|
|
1999
2039
|
|
|
2000
2040
|
Supported Platforms:
|
|
2001
2041
|
``Ascend`` ``GPU`` ``CPU``
|
|
2002
2042
|
|
|
2003
2043
|
Examples:
|
|
2004
|
-
>>> import mindspore
|
|
2005
|
-
>>>
|
|
2044
|
+
>>> import mindspore
|
|
2045
|
+
>>> from mindspore import ops
|
|
2006
2046
|
>>> import numpy as np
|
|
2007
|
-
>>> input =
|
|
2047
|
+
>>> input = mindspore.Tensor(np.arange(1, 9).reshape((2, 2, 2)))
|
|
2008
2048
|
>>> output = ops.flip(input, (0, 2))
|
|
2009
2049
|
>>> print(output)
|
|
2010
2050
|
[[[6 5]
|
|
@@ -2012,7 +2052,7 @@ def flip(input, dims):
|
|
|
2012
2052
|
[[2 1]
|
|
2013
2053
|
[4 3]]]
|
|
2014
2054
|
"""
|
|
2015
|
-
res =
|
|
2055
|
+
res = reverse_v2_impl(input, dims)
|
|
2016
2056
|
return res
|
|
2017
2057
|
|
|
2018
2058
|
|
|
@@ -2034,7 +2074,7 @@ def flipud(input):
|
|
|
2034
2074
|
|
|
2035
2075
|
Examples:
|
|
2036
2076
|
>>> import mindspore as ms
|
|
2037
|
-
>>>
|
|
2077
|
+
>>> from mindspore import ops
|
|
2038
2078
|
>>> import numpy as np
|
|
2039
2079
|
>>> input = ms.Tensor(np.arange(1, 9).reshape((2, 2, 2)))
|
|
2040
2080
|
>>> output = ops.flipud(input)
|
|
@@ -2065,7 +2105,7 @@ def fliplr(input):
|
|
|
2065
2105
|
|
|
2066
2106
|
Examples:
|
|
2067
2107
|
>>> import mindspore as ms
|
|
2068
|
-
>>>
|
|
2108
|
+
>>> from mindspore import ops
|
|
2069
2109
|
>>> import numpy as np
|
|
2070
2110
|
>>> input = ms.Tensor(np.arange(1, 9).reshape((2, 2, 2)))
|
|
2071
2111
|
>>> output = ops.fliplr(input)
|
|
@@ -2094,7 +2134,7 @@ def is_floating_point(input):
|
|
|
2094
2134
|
|
|
2095
2135
|
Examples:
|
|
2096
2136
|
>>> import mindspore as ms
|
|
2097
|
-
>>>
|
|
2137
|
+
>>> from mindspore import ops
|
|
2098
2138
|
>>> from mindspore import Tensor
|
|
2099
2139
|
>>> x = ms.Tensor([1, 2, 3], ms.float32)
|
|
2100
2140
|
>>> y = ms.Tensor([1, 2, 3], ms.int64)
|
|
@@ -2105,7 +2145,7 @@ def is_floating_point(input):
|
|
|
2105
2145
|
>>> print(output2)
|
|
2106
2146
|
False
|
|
2107
2147
|
"""
|
|
2108
|
-
return input.dtype in [mstype.float32, mstype.float16, mstype.float64]
|
|
2148
|
+
return input.dtype in [mstype.float32, mstype.bfloat16, mstype.float16, mstype.float64]
|
|
2109
2149
|
|
|
2110
2150
|
|
|
2111
2151
|
def hardswish(x):
|
|
@@ -2120,6 +2160,11 @@ def hardswish(x):
|
|
|
2120
2160
|
|
|
2121
2161
|
where :math:`x_i` is an element of the input Tensor.
|
|
2122
2162
|
|
|
2163
|
+
HSwish Activation Function Graph:
|
|
2164
|
+
|
|
2165
|
+
.. image:: ../images/HSwish.png
|
|
2166
|
+
:align: center
|
|
2167
|
+
|
|
2123
2168
|
Args:
|
|
2124
2169
|
x (Tensor): The input to compute the Hard Swish.
|
|
2125
2170
|
|
|
@@ -2151,15 +2196,25 @@ def _is_dim_unknown(shape):
|
|
|
2151
2196
|
|
|
2152
2197
|
@_primexpr
|
|
2153
2198
|
def _interploate_make_tuple(rank, value):
|
|
2199
|
+
"""
|
|
2200
|
+
make tuple in dynamic scenarios
|
|
2201
|
+
"""
|
|
2154
2202
|
s = tuple_to_tensor_((rank,), mstype.int32)
|
|
2155
|
-
v =
|
|
2156
|
-
|
|
2203
|
+
v = None
|
|
2204
|
+
if isinstance(value, int):
|
|
2205
|
+
v = F.scalar_to_tensor(value, mstype.int64)
|
|
2206
|
+
else:
|
|
2207
|
+
v = F.scalar_to_tensor(value, mstype.float32)
|
|
2208
|
+
t = fillv2_(s, v)
|
|
2157
2209
|
out = tensor_to_tuple_(t)
|
|
2158
2210
|
return out
|
|
2159
2211
|
|
|
2160
2212
|
|
|
2161
2213
|
@_primexpr
|
|
2162
2214
|
def _interpolate_scale_factor_convert_size(shape, scale_factor):
|
|
2215
|
+
"""
|
|
2216
|
+
convert scale_factor to size
|
|
2217
|
+
"""
|
|
2163
2218
|
x = tuple_to_tensor_(shape[2:], mstype.int64)
|
|
2164
2219
|
y = tuple_to_tensor_(scale_factor, mstype.float32)
|
|
2165
2220
|
t = x * y
|
|
@@ -2169,6 +2224,9 @@ def _interpolate_scale_factor_convert_size(shape, scale_factor):
|
|
|
2169
2224
|
|
|
2170
2225
|
|
|
2171
2226
|
def _interpolate_size_check_with_rank(size, input_rank):
|
|
2227
|
+
"""
|
|
2228
|
+
size rank check
|
|
2229
|
+
"""
|
|
2172
2230
|
if len(size) != input_rank - 2:
|
|
2173
2231
|
raise ValueError(
|
|
2174
2232
|
f"For 'interpolate', 'input' and 'size' must have the same spatial dimensions, "
|
|
@@ -2176,6 +2234,9 @@ def _interpolate_size_check_with_rank(size, input_rank):
|
|
|
2176
2234
|
|
|
2177
2235
|
|
|
2178
2236
|
def _interpolate_scale_factor_check_with_rank(scale_factor, input_rank):
|
|
2237
|
+
"""
|
|
2238
|
+
scale_factor rank check
|
|
2239
|
+
"""
|
|
2179
2240
|
if len(scale_factor) != input_rank - 2:
|
|
2180
2241
|
raise ValueError(
|
|
2181
2242
|
f"For 'interpolate', 'input' and 'scale_factor' must have the same spatial dimensions, "
|
|
@@ -2184,6 +2245,9 @@ def _interpolate_scale_factor_check_with_rank(scale_factor, input_rank):
|
|
|
2184
2245
|
|
|
2185
2246
|
|
|
2186
2247
|
def _interpolate_mode_check(mode, supported_dict):
|
|
2248
|
+
"""
|
|
2249
|
+
mode check
|
|
2250
|
+
"""
|
|
2187
2251
|
if isinstance(mode, list) or mode not in supported_dict:
|
|
2188
2252
|
raise ValueError(
|
|
2189
2253
|
f"For 'interpolate', 'mode' must be in '{list(supported_dict)}', but got {mode}"
|
|
@@ -2191,6 +2255,9 @@ def _interpolate_mode_check(mode, supported_dict):
|
|
|
2191
2255
|
|
|
2192
2256
|
|
|
2193
2257
|
def _interpolate_rank_check(input_rank, mode, supported_dict):
|
|
2258
|
+
"""
|
|
2259
|
+
rank check
|
|
2260
|
+
"""
|
|
2194
2261
|
if input_rank not in supported_dict.get(mode):
|
|
2195
2262
|
raise ValueError(
|
|
2196
2263
|
f"For 'interpolate', {mode} only support '{list(supported_dict.get(mode, {}))}'D, but got {input_rank}D"
|
|
@@ -2198,6 +2265,9 @@ def _interpolate_rank_check(input_rank, mode, supported_dict):
|
|
|
2198
2265
|
|
|
2199
2266
|
|
|
2200
2267
|
def _interpolate_scale_factor_check(scale_factor, mode, rank, supported_dict):
|
|
2268
|
+
"""
|
|
2269
|
+
scale_factor check
|
|
2270
|
+
"""
|
|
2201
2271
|
if scale_factor is not None and "scale_factor" not in supported_dict.get(
|
|
2202
2272
|
mode, {}).get(rank):
|
|
2203
2273
|
raise ValueError(
|
|
@@ -2206,6 +2276,9 @@ def _interpolate_scale_factor_check(scale_factor, mode, rank, supported_dict):
|
|
|
2206
2276
|
|
|
2207
2277
|
|
|
2208
2278
|
def _interpolate_align_corners_mode_check(rank, mode, supported_dict):
|
|
2279
|
+
"""
|
|
2280
|
+
align_corners check
|
|
2281
|
+
"""
|
|
2209
2282
|
if "align_corners" not in supported_dict.get(mode, {}).get(rank):
|
|
2210
2283
|
raise ValueError(
|
|
2211
2284
|
f"For 'interpolate', 'align_corners' option cannot currently be set with the "
|
|
@@ -2238,17 +2311,22 @@ def interpolate(input,
|
|
|
2238
2311
|
'area', 'nearest-exact'(matches Scikit-Image and PIL nearest neighbours interpolation algorithms and fixes
|
|
2239
2312
|
knows issues with `nearest`, 3D and 4D). Default: ``"nearest"`` .
|
|
2240
2313
|
|
|
2241
|
-
align_corners (bool):
|
|
2242
|
-
|
|
2243
|
-
Default: ``None`` .
|
|
2314
|
+
align_corners (bool): Whether to use corner alignment for coordinate mapping. Assuming a transformation is
|
|
2315
|
+
applied to the input Tensor along the x-axis, the specific calculation formula is as follows:
|
|
2244
2316
|
|
|
2245
2317
|
.. code-block::
|
|
2246
2318
|
|
|
2247
|
-
|
|
2319
|
+
ori_i = new_length != 1 ? new_i * (ori_length - 1) / (new_length - 1) : 0 # 'align_corners' = True
|
|
2320
|
+
|
|
2321
|
+
ori_i = new_length > 1 ? (new_i + 0.5) * ori_length / new_length - 0.5 : 0 # 'align_corners' = False
|
|
2248
2322
|
|
|
2249
|
-
|
|
2323
|
+
Among them, :math:`ori\_length` and :math:`new\_length` represent the length of the Tensor before and after
|
|
2324
|
+
transformation along the x-axis respectively; :math:`new\_i` represents the coordinate of the i-th element
|
|
2325
|
+
along the x-axis after transformation; :math:`ori\_i` represents
|
|
2326
|
+
the corresponding coordinate of the original
|
|
2327
|
+
data along the x-axis.
|
|
2250
2328
|
|
|
2251
|
-
This is only valid for 'linear'
|
|
2329
|
+
This is only valid for ``'linear'``, ``'bilinear'``, or ``'bicubic'`` modes. Default: ``False`` .
|
|
2252
2330
|
recompute_scale_factor (bool, optional): Recalculate `scale_factor`.
|
|
2253
2331
|
If True, the parameter `size` will be calculated using the value of the `scale_factor`,
|
|
2254
2332
|
and finally scaled using the value of `size`.
|
|
@@ -2331,7 +2409,7 @@ def interpolate(input,
|
|
|
2331
2409
|
x = x.unsqueeze(-1)
|
|
2332
2410
|
x = _get_cache_prim(P.ResizeNearestNeighborV2)()(
|
|
2333
2411
|
x, size)
|
|
2334
|
-
x = P.Squeeze(-1)(x)
|
|
2412
|
+
x = _get_cache_prim(P.Squeeze)(-1)(x)
|
|
2335
2413
|
elif size is not None and x_rank == 4:
|
|
2336
2414
|
size = seq.TupleToTensor()(size[:2], mstype.int32)
|
|
2337
2415
|
x = _get_cache_prim(P.ResizeNearestNeighborV2)()(
|
|
@@ -2383,7 +2461,7 @@ def interpolate(input,
|
|
|
2383
2461
|
align_corners=False,
|
|
2384
2462
|
half_pixel_centers=True)
|
|
2385
2463
|
x = resize(x, size)
|
|
2386
|
-
x = P.Squeeze(-1)(x)
|
|
2464
|
+
x = _get_cache_prim(P.Squeeze)(-1)(x)
|
|
2387
2465
|
if x_rank == 4:
|
|
2388
2466
|
if isinstance(size, int):
|
|
2389
2467
|
size = F.scalar_to_tensor(size, mstype.int32)
|
|
@@ -2503,7 +2581,12 @@ def interpolate(input,
|
|
|
2503
2581
|
raise ValueError(
|
|
2504
2582
|
"For 'interpolate', it is incorrect to set 'recompute_scale_factor' to True"
|
|
2505
2583
|
" after specifying an explicit 'size'.")
|
|
2506
|
-
|
|
2584
|
+
if F.isconstant(shape) and F.isconstant(scale_factor):
|
|
2585
|
+
tuple_len = min(len(shape) - 2, len(scale_factor))
|
|
2586
|
+
size = tuple([floor(shape[i + 2] * scale_factor[i])
|
|
2587
|
+
for i in range(tuple_len)])
|
|
2588
|
+
else:
|
|
2589
|
+
size = _interpolate_scale_factor_convert_size(shape, scale_factor)
|
|
2507
2590
|
scale_factor = None
|
|
2508
2591
|
else:
|
|
2509
2592
|
if dim_unknown is False:
|
|
@@ -2521,54 +2604,341 @@ def interpolate(input,
|
|
|
2521
2604
|
return resize_func.get(mode)(input, size, align_corners, scale_factor)
|
|
2522
2605
|
|
|
2523
2606
|
|
|
2524
|
-
def
|
|
2525
|
-
r"""
|
|
2526
|
-
Alias for :func:`mindspore.ops.interpolate` .
|
|
2527
|
-
|
|
2528
|
-
Supported Platforms:
|
|
2529
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
2607
|
+
def _interploate_ext_make_tuple(input, value):
|
|
2530
2608
|
"""
|
|
2531
|
-
|
|
2609
|
+
make tuple
|
|
2610
|
+
"""
|
|
2611
|
+
if isinstance(value, (list, tuple)):
|
|
2612
|
+
return value
|
|
2613
|
+
|
|
2614
|
+
rank = F.rank(input) - 2
|
|
2615
|
+
out = None
|
|
2616
|
+
if F.isconstant(value) and F.isconstant(rank):
|
|
2617
|
+
out = tuple([value for _ in range(rank)])
|
|
2618
|
+
else:
|
|
2619
|
+
s = tuple_to_tensor_((rank,), mstype.int32)
|
|
2620
|
+
v = None
|
|
2621
|
+
if isinstance(value, int):
|
|
2622
|
+
v = F.scalar_to_tensor(value, mstype.int64)
|
|
2623
|
+
else:
|
|
2624
|
+
v = F.scalar_to_tensor(value, mstype.float32)
|
|
2625
|
+
t = fillv2_(s, v)
|
|
2626
|
+
out = tensor_to_tuple_(t)
|
|
2627
|
+
return out
|
|
2532
2628
|
|
|
2533
2629
|
|
|
2534
|
-
def
|
|
2630
|
+
def _interpolate_ext_scale_factor_convert_size(input, scale_factor):
|
|
2631
|
+
"""
|
|
2632
|
+
convert scale_factor to size
|
|
2633
|
+
"""
|
|
2634
|
+
shape = F.shape(input)
|
|
2635
|
+
size = None
|
|
2636
|
+
if F.isconstant(shape) and F.isconstant(scale_factor):
|
|
2637
|
+
tuple_len = min(len(shape) - 2, len(scale_factor))
|
|
2638
|
+
size = tuple([floor(shape[i + 2] * scale_factor[i])
|
|
2639
|
+
for i in range(tuple_len)])
|
|
2640
|
+
else:
|
|
2641
|
+
x = tuple_to_tensor_(shape[2:], mstype.int64)
|
|
2642
|
+
y = tuple_to_tensor_(scale_factor, mstype.float32)
|
|
2643
|
+
t = x * y
|
|
2644
|
+
t = ops.TruncateDiv()(t, Tensor(1))
|
|
2645
|
+
t = ops.cast(t, mstype.int64)
|
|
2646
|
+
size = tensor_to_tuple_(t)
|
|
2647
|
+
return size
|
|
2648
|
+
|
|
2649
|
+
|
|
2650
|
+
def interpolate_ext(input,
|
|
2651
|
+
size=None,
|
|
2652
|
+
scale_factor=None,
|
|
2653
|
+
mode="nearest",
|
|
2654
|
+
align_corners=None,
|
|
2655
|
+
recompute_scale_factor=None):
|
|
2535
2656
|
r"""
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
The function is shown as follows:
|
|
2657
|
+
Samples the input Tensor to the given size or scale_factor by using one of the interpolate algorithms.
|
|
2539
2658
|
|
|
2540
|
-
..
|
|
2541
|
-
|
|
2659
|
+
.. note::
|
|
2660
|
+
- In 'linear' mode, backpropagation does not support scenarios where `scale_factor` is not None
|
|
2661
|
+
and `align_corners` is False.
|
|
2542
2662
|
|
|
2543
2663
|
Args:
|
|
2544
|
-
|
|
2545
|
-
|
|
2664
|
+
input (Tensor): Tensor to be resized.
|
|
2665
|
+
Input tensor must be a 3-D, 4-D, or 5-D tensor with shape
|
|
2666
|
+
:math:`(N, C, [optional D], [optional H], W)` , with data type of float.
|
|
2667
|
+
size (Union[int, tuple[int], list[int]], optional): The target size.
|
|
2668
|
+
If size is a tuple or list, its length should be the same as the number of dimensions in input
|
|
2669
|
+
after removing the first two dimensions N, C.
|
|
2670
|
+
One and only one of size and scale_factor can be set to None. Default: ``None`` .
|
|
2671
|
+
scale_factor (Union[float, tuple[float], list[float]], optional): The scale factor of new size of the tensor.
|
|
2672
|
+
If scale_factor is a tuple or list, its length should be the same as the number of dimensions in input
|
|
2673
|
+
after removing the first two dimensions N, C.
|
|
2674
|
+
One and only one of size and scale_factor can be set to None. Default: ``None`` .
|
|
2675
|
+
mode (str): The sampling algorithm.
|
|
2676
|
+
One of 'nearest', 'linear' (3D only), 'bilinear' (4D only), 'trilinear' (5D only), 'bicubic' (4D only),
|
|
2677
|
+
'area', 'nearest-exact'(matches Scikit-Image and PIL nearest neighbours interpolation algorithms and fixes
|
|
2678
|
+
knows issues with `nearest`, 3D and 4D). Default: ``"nearest"`` .
|
|
2679
|
+
|
|
2680
|
+
align_corners (bool): Whether to use corner alignment for coordinate mapping. Assuming a transformation is
|
|
2681
|
+
applied to the input Tensor along the x-axis, the specific calculation formula is as follows:
|
|
2682
|
+
|
|
2683
|
+
.. code-block::
|
|
2684
|
+
|
|
2685
|
+
ori_i = new_length != 1 ? new_i * (ori_length - 1) / (new_length - 1) : 0 # 'align_corners' = True
|
|
2686
|
+
|
|
2687
|
+
ori_i = new_length > 1 ? (new_i + 0.5) * ori_length / new_length - 0.5 : 0 # 'align_corners' = False
|
|
2688
|
+
|
|
2689
|
+
Among them, :math:`ori\_length` and :math:`new\_length` represent the length of the Tensor before and after
|
|
2690
|
+
transformation along the x-axis respectively; :math:`new\_i` represents the coordinate of the i-th element
|
|
2691
|
+
along the x-axis after transformation; :math:`ori\_i` represents
|
|
2692
|
+
the corresponding coordinate of the original
|
|
2693
|
+
data along the x-axis.
|
|
2694
|
+
|
|
2695
|
+
This is only valid for ``'linear'``, ``'bilinear'``, or ``'bicubic'`` modes. Default: ``False`` .
|
|
2696
|
+
recompute_scale_factor (bool, optional): Recalculate `scale_factor`.
|
|
2697
|
+
If True, the parameter `size` will be calculated using the value of the `scale_factor`,
|
|
2698
|
+
and finally scaled using the value of `size`.
|
|
2699
|
+
If False, the value of `size` or `scale_factor` will be used for direct interpolation. Default: ``None`` .
|
|
2700
|
+
|
|
2701
|
+
.. note::
|
|
2702
|
+
The 'nearest-exact' mode is the same as the nearest-neighbor interpolation algorithm used in
|
|
2703
|
+
scikit-image and PIL. The 'nearest' mode produces the same results as the INTER_NEAREST interpolation
|
|
2704
|
+
algorithm used in OpenCV.
|
|
2705
|
+
|
|
2706
|
+
Args Support List and Supported Platforms:
|
|
2707
|
+
|
|
2708
|
+
+---------------+-----------+---------------+--------------+----------------+
|
|
2709
|
+
| mode | input.dim | align_corners | scale_factor | device |
|
|
2710
|
+
+===============+===========+===============+==============+================+
|
|
2711
|
+
| nearest | 3 | \- | √ | Ascend,GPU,CPU |
|
|
2712
|
+
+---------------+-----------+---------------+--------------+----------------+
|
|
2713
|
+
| | 4 | \- | √ | Ascend,GPU,CPU |
|
|
2714
|
+
+---------------+-----------+---------------+--------------+----------------+
|
|
2715
|
+
| | 5 | \- | √ | Ascend,GPU,CPU |
|
|
2716
|
+
+---------------+-----------+---------------+--------------+----------------+
|
|
2717
|
+
| linear | 3 | √ | √ | Ascend,GPU,CPU |
|
|
2718
|
+
+---------------+-----------+---------------+--------------+----------------+
|
|
2719
|
+
| bilinear | 4 | √ | × | Ascend,GPU,CPU |
|
|
2720
|
+
+---------------+-----------+---------------+--------------+----------------+
|
|
2721
|
+
| bicubic | 4 | √ | × | Ascend,GPU,CPU |
|
|
2722
|
+
+---------------+-----------+---------------+--------------+----------------+
|
|
2723
|
+
| area | 3 | \- | √ | Ascend,GPU,CPU |
|
|
2724
|
+
+---------------+-----------+---------------+--------------+----------------+
|
|
2725
|
+
| | 4 | \- | √ | Ascend,GPU,CPU |
|
|
2726
|
+
+---------------+-----------+---------------+--------------+----------------+
|
|
2727
|
+
| | 5 | \- | √ | Ascend,GPU,CPU |
|
|
2728
|
+
+---------------+-----------+---------------+--------------+----------------+
|
|
2729
|
+
| nearest-exact | 3 | \- | × | Ascend,CPU |
|
|
2730
|
+
+---------------+-----------+---------------+--------------+----------------+
|
|
2731
|
+
| | 4 | \- | × | Ascend,CPU |
|
|
2732
|
+
+---------------+-----------+---------------+--------------+----------------+
|
|
2733
|
+
| trilinear | 5 | √ | √ | Ascend,GPU,CPU |
|
|
2734
|
+
+---------------+-----------+---------------+--------------+----------------+
|
|
2735
|
+
|
|
2736
|
+
- `-` indicates that there is no such parameter.
|
|
2737
|
+
- `×` indicates that this parameter is not currently supported.
|
|
2738
|
+
- `√` indicates that this parameter is supported.
|
|
2546
2739
|
|
|
2547
2740
|
Returns:
|
|
2548
|
-
Tensor,
|
|
2741
|
+
Tensor, resized, whose dimensions and dtype are the same as `input`.
|
|
2549
2742
|
|
|
2550
2743
|
Raises:
|
|
2551
|
-
TypeError:
|
|
2552
|
-
|
|
2744
|
+
TypeError: `input` is not a Tensor.
|
|
2745
|
+
ValueError: Both `size` and `scale_factor` are not empty.
|
|
2746
|
+
ValueError: Both `size` and `scale_factor` are empty.
|
|
2747
|
+
ValueError: When `size` is a tuple or list, its length is not equal to `input.ndim - 2`.
|
|
2748
|
+
ValueError: When `scale_factor` is a tuple or list, its length is not equal to `input.ndim - 2`.
|
|
2749
|
+
ValueError: `mode` is not in the list of supported modes.
|
|
2750
|
+
ValueError: `input.ndim` is not in the list of supported dimensions for the corresponding mode.
|
|
2751
|
+
ValueError: `size` is not empty, `recompute_scale_factor` is not empty.
|
|
2752
|
+
ValueError: `scale_factor` is not in the corresponding list of supported values.
|
|
2753
|
+
ValueError: `align_corners` is not in the corresponding list of supported values.
|
|
2553
2754
|
|
|
2554
2755
|
Supported Platforms:
|
|
2555
2756
|
``Ascend`` ``GPU`` ``CPU``
|
|
2556
2757
|
|
|
2557
2758
|
Examples:
|
|
2558
2759
|
>>> import mindspore
|
|
2559
|
-
>>> import
|
|
2560
|
-
>>>
|
|
2561
|
-
>>>
|
|
2562
|
-
>>> output = ops.softsign(x)
|
|
2760
|
+
>>> from mindspore import Tensor, mint
|
|
2761
|
+
>>> input = Tensor([[[1, 2, 3], [4, 5, 6]]], mindspore.float32)
|
|
2762
|
+
>>> output = mint.interpolate(input, size=(6,), mode='nearest')
|
|
2563
2763
|
>>> print(output)
|
|
2564
|
-
|
|
2764
|
+
[[[1. 1. 2. 2. 3. 3.]
|
|
2765
|
+
[4. 4. 5. 5. 6. 6.]]]
|
|
2565
2766
|
"""
|
|
2566
|
-
|
|
2767
|
+
def run_nearest(x, size, align_corners=None, scale_factor=None):
|
|
2768
|
+
x_rank = F.rank(x)
|
|
2769
|
+
if x_rank == 3:
|
|
2770
|
+
x = _get_cache_prim(ops.auto_generate.UpsampleNearest1D)()(
|
|
2771
|
+
x, size, scale_factor)
|
|
2772
|
+
elif x_rank == 4:
|
|
2773
|
+
x = _get_cache_prim(ops.auto_generate.UpsampleNearest2D)()(
|
|
2774
|
+
x, size, scale_factor)
|
|
2775
|
+
else:
|
|
2776
|
+
x = _get_cache_prim(P.UpsampleNearest3D)()(x, size, scale_factor)
|
|
2777
|
+
return x
|
|
2567
2778
|
|
|
2779
|
+
def run_linear(x, size, align_corners=None, scale_factor=None):
|
|
2780
|
+
out = _get_cache_prim(
|
|
2781
|
+
ops.auto_generate.UpsampleLinear1D)()(x, size, scale_factor, align_corners)
|
|
2782
|
+
return out
|
|
2568
2783
|
|
|
2569
|
-
def
|
|
2570
|
-
|
|
2571
|
-
|
|
2784
|
+
def run_bilinear(x, size, align_corners=None, scale_factor=None):
|
|
2785
|
+
out = _get_cache_prim(
|
|
2786
|
+
ops.auto_generate.UpsampleBilinear2D)()(x, size, scale_factor, align_corners)
|
|
2787
|
+
return out
|
|
2788
|
+
|
|
2789
|
+
def run_trilinear(x, size, align_corners=None, scale_factor=None):
|
|
2790
|
+
resize = _get_cache_prim(P.nn_ops.UpsampleTrilinear3D)(align_corners)
|
|
2791
|
+
return resize(x, size, scale_factor)
|
|
2792
|
+
|
|
2793
|
+
def run_bicubic(x, size, align_corners=None, scale_factor=None):
|
|
2794
|
+
resize = _get_cache_prim(P.image_ops.ResizeBicubic)(
|
|
2795
|
+
align_corners=align_corners, half_pixel_centers=not align_corners)
|
|
2796
|
+
x = resize(x, size)
|
|
2797
|
+
return x
|
|
2798
|
+
|
|
2799
|
+
def run_area(x, size, align_corners=None, scale_factor=None):
|
|
2800
|
+
x_rank = F.rank(x)
|
|
2801
|
+
if x_rank == 3:
|
|
2802
|
+
x = F.adaptive_avg_pool1d(x, size[0])
|
|
2803
|
+
elif x_rank == 4:
|
|
2804
|
+
x = F.adaptive_avg_pool2d(x, tuple(size))
|
|
2805
|
+
else:
|
|
2806
|
+
x = F.adaptive_avg_pool3d(x, tuple(size))
|
|
2807
|
+
return x
|
|
2808
|
+
|
|
2809
|
+
def run_nearest_exact(x, size, align_corners=None, scale_factor=None):
|
|
2810
|
+
x_rank = F.rank(x)
|
|
2811
|
+
if x_rank == 3:
|
|
2812
|
+
size = size[:1] + (1,)
|
|
2813
|
+
# For impl of nearest 3D use 4D.
|
|
2814
|
+
x = x.unsqueeze(-1)
|
|
2815
|
+
resize = _get_cache_prim(P.ResizeNearestNeighborV2)(
|
|
2816
|
+
align_corners=False,
|
|
2817
|
+
half_pixel_centers=True)
|
|
2818
|
+
x = resize(x, size)
|
|
2819
|
+
x = _get_cache_prim(P.Squeeze)(-1)(x)
|
|
2820
|
+
if x_rank == 4:
|
|
2821
|
+
resize = _get_cache_prim(P.ResizeNearestNeighborV2)(
|
|
2822
|
+
align_corners=False,
|
|
2823
|
+
half_pixel_centers=True)
|
|
2824
|
+
x = resize(x, size)
|
|
2825
|
+
return x
|
|
2826
|
+
|
|
2827
|
+
|
|
2828
|
+
resize_funcs = {
|
|
2829
|
+
"nearest": run_nearest,
|
|
2830
|
+
"linear": run_linear,
|
|
2831
|
+
"bilinear": run_bilinear,
|
|
2832
|
+
"bicubic": run_bicubic,
|
|
2833
|
+
"trilinear": run_trilinear,
|
|
2834
|
+
"area": run_area,
|
|
2835
|
+
"nearest-exact": run_nearest_exact,
|
|
2836
|
+
}
|
|
2837
|
+
|
|
2838
|
+
# mode check
|
|
2839
|
+
if mode not in resize_funcs:
|
|
2840
|
+
raise ValueError(
|
|
2841
|
+
f"For 'interpolate', 'mode' must be in '{list(resize_funcs)}', but got {mode}"
|
|
2842
|
+
)
|
|
2843
|
+
if mode in ("nearest", "area", "nearest-exact"):
|
|
2844
|
+
if align_corners is not None:
|
|
2845
|
+
raise ValueError("align_corners option can only be set with the "
|
|
2846
|
+
"interpolating modes: linear | bilinear | bicubic | trilinear"
|
|
2847
|
+
)
|
|
2848
|
+
else:
|
|
2849
|
+
if align_corners is None:
|
|
2850
|
+
align_corners = False
|
|
2851
|
+
|
|
2852
|
+
# check for size and scale_factor
|
|
2853
|
+
if size is not None and scale_factor is not None:
|
|
2854
|
+
raise ValueError(
|
|
2855
|
+
"For 'interpolate', 'size' and 'scale_factor' cannot be set simultaneously"
|
|
2856
|
+
)
|
|
2857
|
+
if size is not None:
|
|
2858
|
+
size = _interploate_ext_make_tuple(input, size)
|
|
2859
|
+
elif scale_factor is not None:
|
|
2860
|
+
scale_factor = _interploate_ext_make_tuple(input, scale_factor)
|
|
2861
|
+
else:
|
|
2862
|
+
raise ValueError(
|
|
2863
|
+
"For 'interpolate', 'size' and 'scale_factor' cannot be both empty"
|
|
2864
|
+
)
|
|
2865
|
+
|
|
2866
|
+
# "area" mode always requires an explicit size rather than scale factor.
|
|
2867
|
+
if mode == "area" and size is None:
|
|
2868
|
+
recompute_scale_factor = True
|
|
2869
|
+
|
|
2870
|
+
# recompute_scale_factor
|
|
2871
|
+
if recompute_scale_factor is not None and recompute_scale_factor:
|
|
2872
|
+
if size is not None:
|
|
2873
|
+
raise ValueError(
|
|
2874
|
+
"For 'interpolate', it is incorrect to set 'recompute_scale_factor' to True"
|
|
2875
|
+
" after specifying an explicit 'size'.")
|
|
2876
|
+
size = _interpolate_ext_scale_factor_convert_size(input, scale_factor)
|
|
2877
|
+
scale_factor = None
|
|
2878
|
+
|
|
2879
|
+
# scale_factor
|
|
2880
|
+
if mode in ("bilinear", "bicubic", "nearest-exact"):
|
|
2881
|
+
if scale_factor is not None:
|
|
2882
|
+
raise ValueError("scale_factor option can only be set with the "
|
|
2883
|
+
"interpolating modes: nearest | linear | area | trilinear"
|
|
2884
|
+
)
|
|
2885
|
+
|
|
2886
|
+
return resize_funcs.get(mode)(input, size, align_corners, scale_factor)
|
|
2887
|
+
|
|
2888
|
+
|
|
2889
|
+
def upsample(input, size=None, scale_factor=None, mode="nearest", align_corners=None, recompute_scale_factor=None):
|
|
2890
|
+
r"""
|
|
2891
|
+
Alias for :func:`mindspore.ops.interpolate` .
|
|
2892
|
+
|
|
2893
|
+
Supported Platforms:
|
|
2894
|
+
``Ascend`` ``GPU`` ``CPU``
|
|
2895
|
+
"""
|
|
2896
|
+
return interpolate(input, size, scale_factor, mode, align_corners, recompute_scale_factor)
|
|
2897
|
+
|
|
2898
|
+
|
|
2899
|
+
def softsign(x):
|
|
2900
|
+
r"""
|
|
2901
|
+
SoftSign activation function.
|
|
2902
|
+
|
|
2903
|
+
The function is shown as follows:
|
|
2904
|
+
|
|
2905
|
+
.. math::
|
|
2906
|
+
\text{SoftSign}(x) = \frac{x}{1 + |x|}
|
|
2907
|
+
|
|
2908
|
+
Softsign Activation Function Graph:
|
|
2909
|
+
|
|
2910
|
+
.. image:: ../images/Softsign.png
|
|
2911
|
+
:align: center
|
|
2912
|
+
|
|
2913
|
+
Args:
|
|
2914
|
+
x (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
|
|
2915
|
+
additional dimensions, with float16 or float32 data type.
|
|
2916
|
+
|
|
2917
|
+
Returns:
|
|
2918
|
+
Tensor, with the same type and shape as the `x`.
|
|
2919
|
+
|
|
2920
|
+
Raises:
|
|
2921
|
+
TypeError: If `x` is not a Tensor.
|
|
2922
|
+
TypeError: If dtype of `x` is neither float16 nor float32.
|
|
2923
|
+
|
|
2924
|
+
Supported Platforms:
|
|
2925
|
+
``Ascend`` ``GPU`` ``CPU``
|
|
2926
|
+
|
|
2927
|
+
Examples:
|
|
2928
|
+
>>> import mindspore
|
|
2929
|
+
>>> import numpy as np
|
|
2930
|
+
>>> from mindspore import Tensor, ops
|
|
2931
|
+
>>> x = Tensor(np.array([0, -1, 2, 30, -30]), mindspore.float32)
|
|
2932
|
+
>>> output = ops.softsign(x)
|
|
2933
|
+
>>> print(output)
|
|
2934
|
+
[ 0. -0.5 0.6666667 0.9677419 -0.9677419]
|
|
2935
|
+
"""
|
|
2936
|
+
return softsign_(x)
|
|
2937
|
+
|
|
2938
|
+
|
|
2939
|
+
def soft_margin_loss(input, target, reduction='mean'):
|
|
2940
|
+
r"""
|
|
2941
|
+
Calculate the soft margin loss of input and target.
|
|
2572
2942
|
|
|
2573
2943
|
Creates a criterion that optimizes a two-class classification
|
|
2574
2944
|
logistic loss between input tensor :math:`x` and target tensor :math:`y`
|
|
@@ -2584,7 +2954,7 @@ def soft_margin_loss(input, target, reduction='mean'):
|
|
|
2584
2954
|
|
|
2585
2955
|
Args:
|
|
2586
2956
|
input (Tensor): Predict data. Data type must be float16 or float32.
|
|
2587
|
-
target (Tensor): Ground truth data, with the same type and shape as `
|
|
2957
|
+
target (Tensor): Ground truth data, with the same type and shape as `input`.
|
|
2588
2958
|
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
2589
2959
|
``'sum'`` . Default: ``'mean'`` .
|
|
2590
2960
|
|
|
@@ -2593,7 +2963,7 @@ def soft_margin_loss(input, target, reduction='mean'):
|
|
|
2593
2963
|
- ``'sum'``: the output elements will be summed.
|
|
2594
2964
|
|
|
2595
2965
|
Outputs:
|
|
2596
|
-
Tensor or Scalar. If `reduction` is ``'none'``, its shape is the same as `
|
|
2966
|
+
Tensor or Scalar. If `reduction` is ``'none'``, its shape is the same as `input`.
|
|
2597
2967
|
Otherwise, a scalar value will be returned.
|
|
2598
2968
|
|
|
2599
2969
|
Raises:
|
|
@@ -2620,34 +2990,31 @@ def soft_margin_loss(input, target, reduction='mean'):
|
|
|
2620
2990
|
return output
|
|
2621
2991
|
|
|
2622
2992
|
|
|
2623
|
-
def softmax(
|
|
2993
|
+
def softmax(input, axis=-1, *, dtype=None):
|
|
2624
2994
|
r"""
|
|
2625
2995
|
Applies the Softmax operation to the input tensor on the specified axis.
|
|
2626
|
-
Suppose a slice in the given axis :math:`
|
|
2996
|
+
Suppose a slice in the given axis :math:`axis`, then for each element :math:`input_i`,
|
|
2627
2997
|
the Softmax function is shown as follows:
|
|
2628
2998
|
|
|
2629
2999
|
.. math::
|
|
2630
|
-
\text{output}(
|
|
3000
|
+
\text{output}(input_i) = \frac{\exp(input_i)}{\sum_{j = 0}^{N-1}\exp(input_j)},
|
|
2631
3001
|
|
|
2632
3002
|
where :math:`N` is the length of the tensor.
|
|
2633
3003
|
|
|
2634
3004
|
Args:
|
|
2635
|
-
|
|
2636
|
-
x (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
|
|
3005
|
+
input (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
|
|
2637
3006
|
additional dimensions, with float16 or float32 data type.
|
|
3007
|
+
axis (int, optional): The axis to perform the Softmax operation. Default: ``-1`` .
|
|
2638
3008
|
|
|
2639
3009
|
Keyword Args:
|
|
2640
|
-
dtype (:class:`mindspore.dtype`, optional): When set, `
|
|
3010
|
+
dtype (:class:`mindspore.dtype`, optional): When set, `input` will be converted to the specified type,
|
|
2641
3011
|
`dtype`, before execution, and dtype of returned Tensor will also be `dtype`. Default: ``None`` .
|
|
2642
3012
|
|
|
2643
3013
|
Returns:
|
|
2644
|
-
Tensor, with the same type and shape as the
|
|
3014
|
+
Tensor, with the same type and shape as the `input`.
|
|
2645
3015
|
|
|
2646
3016
|
Raises:
|
|
2647
|
-
TypeError: If `axis` is not an int
|
|
2648
|
-
TypeError: If dtype of `x` is neither float16 nor float32.
|
|
2649
|
-
ValueError: If `axis` is a tuple whose length is less than 1.
|
|
2650
|
-
ValueError: If `axis` is a tuple whose elements are not all in range [-len(logits.shape), len(logits.shape))
|
|
3017
|
+
TypeError: If `axis` is not an int.
|
|
2651
3018
|
|
|
2652
3019
|
Supported Platforms:
|
|
2653
3020
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -2656,8 +3023,8 @@ def softmax(x, axis=-1, *, dtype=None):
|
|
|
2656
3023
|
>>> import mindspore
|
|
2657
3024
|
>>> import numpy as np
|
|
2658
3025
|
>>> from mindspore import Tensor, ops
|
|
2659
|
-
>>>
|
|
2660
|
-
>>> output = ops.softmax(
|
|
3026
|
+
>>> input = Tensor(np.array([1, 2, 3, 4, 5]), mindspore.float32)
|
|
3027
|
+
>>> output = ops.softmax(input)
|
|
2661
3028
|
>>> print(output)
|
|
2662
3029
|
[0.01165623 0.03168492 0.08612854 0.23412167 0.6364086 ]
|
|
2663
3030
|
"""
|
|
@@ -2666,9 +3033,57 @@ def softmax(x, axis=-1, *, dtype=None):
|
|
|
2666
3033
|
type_axis = type(axis).__name__
|
|
2667
3034
|
raise TypeError(f" the type of 'axis' must be 'int', but got '{axis}' with type '{type_axis}'.")
|
|
2668
3035
|
if dtype is not None:
|
|
2669
|
-
|
|
2670
|
-
softmax_ = _get_cache_prim(P.Softmax)(axis
|
|
2671
|
-
return softmax_(
|
|
3036
|
+
input = ops.cast(input, dtype)
|
|
3037
|
+
softmax_ = _get_cache_prim(P.Softmax)(axis)
|
|
3038
|
+
return softmax_(input)
|
|
3039
|
+
|
|
3040
|
+
|
|
3041
|
+
def softmax_ext(input, dim=None, dtype=None):
|
|
3042
|
+
r"""
|
|
3043
|
+
Applies the Softmax operation to the input tensor on the specified axis.
|
|
3044
|
+
Suppose a slice in the given axis :math:`dim`, then for each element :math:`input_i`,
|
|
3045
|
+
the Softmax function is shown as follows:
|
|
3046
|
+
|
|
3047
|
+
.. math::
|
|
3048
|
+
\text{output}(input_i) = \frac{\exp(input_i)}{\sum_{j = 0}^{N-1}\exp(input_j)},
|
|
3049
|
+
|
|
3050
|
+
where :math:`N` is the length of the tensor.
|
|
3051
|
+
|
|
3052
|
+
Args:
|
|
3053
|
+
input (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
|
|
3054
|
+
additional dimensions.
|
|
3055
|
+
dim (int, optional): The dim to perform the Softmax operation. Default: ``None`` .
|
|
3056
|
+
|
|
3057
|
+
Keyword Args:
|
|
3058
|
+
dtype (:class:`mindspore.dtype`, optional): When set, `input` will be converted to the specified type,
|
|
3059
|
+
`dtype`, before execution, and dtype of returned Tensor will also be `dtype`. Default: ``None`` .
|
|
3060
|
+
|
|
3061
|
+
Returns:
|
|
3062
|
+
Tensor, with the same type and shape as the `input`.
|
|
3063
|
+
|
|
3064
|
+
Raises:
|
|
3065
|
+
TypeError: If `dim` is not an int.
|
|
3066
|
+
|
|
3067
|
+
Supported Platforms:
|
|
3068
|
+
``Ascend`` ``GPU`` ``CPU``
|
|
3069
|
+
|
|
3070
|
+
Examples:
|
|
3071
|
+
>>> import mindspore
|
|
3072
|
+
>>> import numpy as np
|
|
3073
|
+
>>> from mindspore import Tensor, ops
|
|
3074
|
+
>>> input = Tensor(np.array([1, 2, 3, 4, 5]), mindspore.float32)
|
|
3075
|
+
>>> output = ops.function.nn_func.softmax_ext(input)
|
|
3076
|
+
>>> print(output)
|
|
3077
|
+
[0.01165623 0.03168492 0.08612854 0.23412167 0.6364086 ]
|
|
3078
|
+
"""
|
|
3079
|
+
dim = -1 if dim is None else dim
|
|
3080
|
+
if not isinstance(dim, int):
|
|
3081
|
+
type_dim = type(dim).__name__
|
|
3082
|
+
raise TypeError(f" the type of 'dim' must be 'int', but got '{dim}' with type '{type_dim}'.")
|
|
3083
|
+
if dtype is not None:
|
|
3084
|
+
input = ops.cast(input, dtype)
|
|
3085
|
+
softmax_ = _get_cache_prim(P.Softmax)(dim)
|
|
3086
|
+
return softmax_(input)
|
|
2672
3087
|
|
|
2673
3088
|
|
|
2674
3089
|
def softmin(x, axis=-1, *, dtype=None):
|
|
@@ -2692,7 +3107,7 @@ def softmin(x, axis=-1, *, dtype=None):
|
|
|
2692
3107
|
`dtype`, before execution, and dtype of returned Tensor will also be `dtype`. Default: ``None`` .
|
|
2693
3108
|
|
|
2694
3109
|
Returns:
|
|
2695
|
-
Tensor, with the same type and shape as
|
|
3110
|
+
Tensor, with the same type and shape as `x`.
|
|
2696
3111
|
|
|
2697
3112
|
Raises:
|
|
2698
3113
|
TypeError: If `axis` is not an int or a tuple.
|
|
@@ -2715,7 +3130,7 @@ def softmin(x, axis=-1, *, dtype=None):
|
|
|
2715
3130
|
|
|
2716
3131
|
if dtype is not None:
|
|
2717
3132
|
x = ops.cast(x, dtype)
|
|
2718
|
-
softmax_ = _get_cache_prim(P.Softmax)(axis
|
|
3133
|
+
softmax_ = _get_cache_prim(P.Softmax)(axis)
|
|
2719
3134
|
return softmax_(-1*x)
|
|
2720
3135
|
|
|
2721
3136
|
|
|
@@ -2731,6 +3146,11 @@ def softshrink(x, lambd=0.5):
|
|
|
2731
3146
|
0, & \text{ otherwise }
|
|
2732
3147
|
\end{cases}
|
|
2733
3148
|
|
|
3149
|
+
SoftShrink Activation Function Graph:
|
|
3150
|
+
|
|
3151
|
+
.. image:: ../images/Softshrink.png
|
|
3152
|
+
:align: center
|
|
3153
|
+
|
|
2734
3154
|
Args:
|
|
2735
3155
|
x (Tensor): The input of soft shrink with data type of float16 or float32.
|
|
2736
3156
|
lambd (float): The :math:`\lambda` must be no less than zero. Default: ``0.5`` .
|
|
@@ -2739,10 +3159,10 @@ def softshrink(x, lambd=0.5):
|
|
|
2739
3159
|
Tensor, has the same shape and data type as `x`.
|
|
2740
3160
|
|
|
2741
3161
|
Raises:
|
|
2742
|
-
TypeError: If lambd is not a float.
|
|
2743
|
-
TypeError: If
|
|
2744
|
-
TypeError: If dtype of
|
|
2745
|
-
ValueError: If lambd is less than 0.
|
|
3162
|
+
TypeError: If `lambd` is not a float.
|
|
3163
|
+
TypeError: If `x` is not a Tensor.
|
|
3164
|
+
TypeError: If dtype of `x` is neither float16 nor float32.
|
|
3165
|
+
ValueError: If `lambd` is less than 0.
|
|
2746
3166
|
|
|
2747
3167
|
Supported Platforms:
|
|
2748
3168
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -2814,45 +3234,11 @@ def softplus(input, beta=1, threshold=20): # pylint:disable=redefined-outer-name
|
|
|
2814
3234
|
>>> print(output)
|
|
2815
3235
|
[0.7443967 0.79813886 30. 25.]
|
|
2816
3236
|
"""
|
|
2817
|
-
softplus_op = _get_cache_prim(P.Softplus)()
|
|
2818
3237
|
scaling_input = beta * input
|
|
2819
|
-
op_output = (1 / beta) *
|
|
3238
|
+
op_output = (1 / beta) * softplus_(scaling_input)
|
|
2820
3239
|
return ops.select(input * beta > threshold, input, op_output)
|
|
2821
3240
|
|
|
2822
3241
|
|
|
2823
|
-
def silu(x):
|
|
2824
|
-
r"""
|
|
2825
|
-
Computes Sigmoid Linear Unit of input element-wise. The SiLU function is defined as:
|
|
2826
|
-
|
|
2827
|
-
.. math::
|
|
2828
|
-
\text{SiLU}(x) = x * \sigma(x),
|
|
2829
|
-
|
|
2830
|
-
where the Logistic Sigmoid function is defined as:
|
|
2831
|
-
|
|
2832
|
-
.. math::
|
|
2833
|
-
|
|
2834
|
-
\text{sigma}(x_i) = \frac{1}{1 + \exp(-x_i)},
|
|
2835
|
-
|
|
2836
|
-
where :math:`x_i` is an element of the x.
|
|
2837
|
-
|
|
2838
|
-
For more details, please refer to :class:`mindspore.nn.SiLU`.
|
|
2839
|
-
|
|
2840
|
-
Supported Platforms:
|
|
2841
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
2842
|
-
|
|
2843
|
-
Examples:
|
|
2844
|
-
>>> import numpy as np
|
|
2845
|
-
>>> import mindspore
|
|
2846
|
-
>>> from mindspore import Tensor, ops
|
|
2847
|
-
>>> x = Tensor(np.array([-1, 2, -3, 2, -1]), mindspore.float16)
|
|
2848
|
-
>>> output = ops.silu(x)
|
|
2849
|
-
>>> print(output)
|
|
2850
|
-
[-0.269 1.762 -0.1423 1.762 -0.269]
|
|
2851
|
-
"""
|
|
2852
|
-
silu_ = _get_cache_prim(SiLU)()
|
|
2853
|
-
return silu_(x)
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
3242
|
def selu(input_x):
|
|
2857
3243
|
r"""
|
|
2858
3244
|
Activation function SeLU (Scaled exponential Linear Unit).
|
|
@@ -2872,14 +3258,20 @@ def selu(input_x):
|
|
|
2872
3258
|
|
|
2873
3259
|
See more details in `Self-Normalizing Neural Networks <https://arxiv.org/abs/1706.02515>`_.
|
|
2874
3260
|
|
|
3261
|
+
SeLU Activation Function Graph:
|
|
3262
|
+
|
|
3263
|
+
.. image:: ../images/SeLU.png
|
|
3264
|
+
:align: center
|
|
3265
|
+
|
|
2875
3266
|
Args:
|
|
2876
|
-
input_x (Tensor): Tensor of any dimension,
|
|
3267
|
+
input_x (Tensor): Tensor of any dimension,
|
|
3268
|
+
the data type is int8, int32, float16, float32, or float64 (CPU, GPU only).
|
|
2877
3269
|
|
|
2878
3270
|
Returns:
|
|
2879
3271
|
Tensor, with the same type and shape as the `input_x`.
|
|
2880
3272
|
|
|
2881
3273
|
Raises:
|
|
2882
|
-
TypeError: If dtype of `input_x` is
|
|
3274
|
+
TypeError: If dtype of `input_x` is not int8, int32, float16, float32, or float64.
|
|
2883
3275
|
|
|
2884
3276
|
Supported Platforms:
|
|
2885
3277
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -2897,41 +3289,6 @@ def selu(input_x):
|
|
|
2897
3289
|
return selu_(input_x)
|
|
2898
3290
|
|
|
2899
3291
|
|
|
2900
|
-
def sigmoid(input):
|
|
2901
|
-
r"""
|
|
2902
|
-
Computes Sigmoid of input element-wise. The Sigmoid function is defined as:
|
|
2903
|
-
|
|
2904
|
-
.. math::
|
|
2905
|
-
|
|
2906
|
-
\text{sigmoid}(input_i) = \frac{1}{1 + \exp(-input_i)}
|
|
2907
|
-
|
|
2908
|
-
where :math:`input_i` is an element of the input.
|
|
2909
|
-
|
|
2910
|
-
Args:
|
|
2911
|
-
input (Tensor): Tensor of any dimension, the data type is float16, float32, float64, complex64 or complex128.
|
|
2912
|
-
|
|
2913
|
-
Returns:
|
|
2914
|
-
Tensor, with the same type and shape as the input.
|
|
2915
|
-
|
|
2916
|
-
Raises:
|
|
2917
|
-
TypeError: If dtype of `input` is not float16, float32, float64, complex64 or complex128.
|
|
2918
|
-
TypeError: If `input` is not a Tensor.
|
|
2919
|
-
|
|
2920
|
-
Supported Platforms:
|
|
2921
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
2922
|
-
|
|
2923
|
-
Examples:
|
|
2924
|
-
>>> import mindspore
|
|
2925
|
-
>>> import numpy as np
|
|
2926
|
-
>>> from mindspore import Tensor, ops
|
|
2927
|
-
>>> input = Tensor(np.array([1, 2, 3, 4, 5]), mindspore.float32)
|
|
2928
|
-
>>> output = ops.sigmoid(input)
|
|
2929
|
-
>>> print(output)
|
|
2930
|
-
[0.7310586 0.880797 0.95257413 0.98201376 0.9933072 ]
|
|
2931
|
-
"""
|
|
2932
|
-
return _get_cache_prim(NN_OPS.Sigmoid)()(input)
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
3292
|
def logsigmoid(x):
|
|
2936
3293
|
r"""
|
|
2937
3294
|
Applies logsigmoid activation element-wise. The input is a Tensor with any valid shape.
|
|
@@ -2943,6 +3300,11 @@ def logsigmoid(x):
|
|
|
2943
3300
|
|
|
2944
3301
|
where :math:`x_{i}` is the element of the input.
|
|
2945
3302
|
|
|
3303
|
+
LogSigmoid Activation Function Graph:
|
|
3304
|
+
|
|
3305
|
+
.. image:: ../images/LogSigmoid.png
|
|
3306
|
+
:align: center
|
|
3307
|
+
|
|
2946
3308
|
Args:
|
|
2947
3309
|
x (Tensor): The input of LogSigmoid with data type of float16 or float32.
|
|
2948
3310
|
The shape is :math:`(N,*)` where :math:`*` means, any number of additional dimensions.
|
|
@@ -2965,64 +3327,11 @@ def logsigmoid(x):
|
|
|
2965
3327
|
>>> print(output)
|
|
2966
3328
|
[-0.31326166 -0.12692806 -0.04858734]
|
|
2967
3329
|
"""
|
|
2968
|
-
output =
|
|
2969
|
-
ret =
|
|
3330
|
+
output = sigmoid_(x)
|
|
3331
|
+
ret = log_(output)
|
|
2970
3332
|
return ret
|
|
2971
3333
|
|
|
2972
3334
|
|
|
2973
|
-
def dense(input, weight, bias=None):
|
|
2974
|
-
r"""
|
|
2975
|
-
Applies the dense connected operation to the `input`. The dense function is defined as:
|
|
2976
|
-
|
|
2977
|
-
.. math::
|
|
2978
|
-
output = input * weight^{T} + bias
|
|
2979
|
-
|
|
2980
|
-
.. warning::
|
|
2981
|
-
This is an experimental API that is subject to change or deletion.
|
|
2982
|
-
|
|
2983
|
-
Args:
|
|
2984
|
-
input (Tensor): Input Tensor of shape :math:`(*, in\_channels)`,
|
|
2985
|
-
where :math:`*` means any number of additional dimensions.
|
|
2986
|
-
weight (Tensor): The weight applied to the input.
|
|
2987
|
-
The shape is :math:`(out\_channels, in\_channels)` or :math:`(in\_channels)`.
|
|
2988
|
-
bias (Tensor, optional): Additive biases to the output.
|
|
2989
|
-
The shape is :math:`(out\_channels)` or :math:`()`. Defaults: ``None``, the `bias` is 0.
|
|
2990
|
-
|
|
2991
|
-
Returns:
|
|
2992
|
-
Output whose shape is determined by the shape of the input and the weight.
|
|
2993
|
-
|
|
2994
|
-
Raises:
|
|
2995
|
-
TypeError: If `input` is not Tensor.
|
|
2996
|
-
TypeError: If `weight` is not Tensor.
|
|
2997
|
-
TypeError: If `bias` is not Tensor.
|
|
2998
|
-
|
|
2999
|
-
Supported Platforms:
|
|
3000
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
3001
|
-
|
|
3002
|
-
Examples:
|
|
3003
|
-
>>> import numpy as np
|
|
3004
|
-
>>> import mindspore
|
|
3005
|
-
>>> from mindspore import Tensor, ops
|
|
3006
|
-
>>> input = Tensor([[-1., 1., 2.], [-3., -3., 1.]], mindspore.float32)
|
|
3007
|
-
>>> weight = Tensor([[-2., -2., -2.], [0., -1., 0.]], mindspore.float32)
|
|
3008
|
-
>>> bias = Tensor([0., 1.], mindspore.float32)
|
|
3009
|
-
>>> output = ops.dense(input, weight, bias)
|
|
3010
|
-
>>> print(output)
|
|
3011
|
-
[[-4. 0.]
|
|
3012
|
-
[10. 4.]]
|
|
3013
|
-
"""
|
|
3014
|
-
_check_is_tensor("input", input, "dense")
|
|
3015
|
-
_check_is_tensor("weight", weight, "dense")
|
|
3016
|
-
_check_is_tensor("bias", bias, "dense")
|
|
3017
|
-
weight = ops.t(weight)
|
|
3018
|
-
input = ops.matmul(input, weight)
|
|
3019
|
-
input_shape = input.shape
|
|
3020
|
-
if bias is not None:
|
|
3021
|
-
input = input + bias
|
|
3022
|
-
_check_dense_add_bias_shape(input_shape, input.shape, bias.shape)
|
|
3023
|
-
return input
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
3335
|
def _check_dense_add_bias_shape(input_shape, output_shape, bias_shape):
|
|
3027
3336
|
"""Check that the output has the correct shape after adding bias."""
|
|
3028
3337
|
if input_shape != output_shape:
|
|
@@ -3113,14 +3422,15 @@ def bidense(input1, input2, weight, bias=None):
|
|
|
3113
3422
|
input1 = input1.reshape((-1, input1_shape[-1]))
|
|
3114
3423
|
input2 = input2.reshape((-1, input2_shape[-1]))
|
|
3115
3424
|
batch_size = input1.shape[0]
|
|
3116
|
-
matmul_ = P.MatMul()
|
|
3117
3425
|
output = matmul_(input1, weight.transpose(1, 2, 0).view(input1_shape[-1], -1))
|
|
3118
3426
|
output = output.view(batch_size, input2_shape[-1], weight.shape[0])
|
|
3119
3427
|
output = output.transpose(2, 0, 1) * input2
|
|
3120
3428
|
output = output.sum(2).swapaxes(0, 1)
|
|
3121
3429
|
if bias is not None:
|
|
3122
|
-
|
|
3123
|
-
|
|
3430
|
+
if input1.dtype != bias.dtype or input2.dtype != bias.dtype:
|
|
3431
|
+
raise TypeError(f"For 'bidense', the dtype of 'bias', 'input1' and 'input2' must be the same,"
|
|
3432
|
+
f" but got {bias.dtype}, {input1.dtype} and {input2.dtype}.")
|
|
3433
|
+
output = bias_add_(output.astype(bias.dtype), bias)
|
|
3124
3434
|
if len(input1_shape) != 2:
|
|
3125
3435
|
output_shape = input1_shape[:-1] + (-1,)
|
|
3126
3436
|
output = output.reshape(output_shape)
|
|
@@ -3189,7 +3499,7 @@ def deformable_conv2d(x, weight, offsets, kernel_size, strides, padding, bias=No
|
|
|
3189
3499
|
TypeError: If `strides`, `padding`, `kernel_size` or `dilations` is not a tuple with integer elements.
|
|
3190
3500
|
TypeError: If `modulated` is not a bool.
|
|
3191
3501
|
ValueError: If the tuple size of `strides`, `padding`, `kernel_size` or `dilations` is not expected.
|
|
3192
|
-
ValueError: The N or C dimensions of
|
|
3502
|
+
ValueError: The N or C dimensions of `strides` or `dilations` is not set to 1.
|
|
3193
3503
|
ValueError: If `modulated` is not set to True.
|
|
3194
3504
|
|
|
3195
3505
|
.. warning::
|
|
@@ -3214,13 +3524,10 @@ def deformable_conv2d(x, weight, offsets, kernel_size, strides, padding, bias=No
|
|
|
3214
3524
|
deformable_groups,
|
|
3215
3525
|
modulated)
|
|
3216
3526
|
fm_offset = deformable_offsets(x, offsets)
|
|
3217
|
-
|
|
3218
3527
|
weight_shape = weight.shape
|
|
3219
3528
|
out_channel = weight_shape[0]
|
|
3220
3529
|
strides_conv = (kernel_size[0], kernel_size[1])
|
|
3221
3530
|
conv = _get_cache_prim(P.Conv2D)(out_channel, kernel_size, 1, "valid", 0, strides_conv, 1, groups)
|
|
3222
|
-
bias_add_ = _get_cache_prim(P.BiasAdd)()
|
|
3223
|
-
|
|
3224
3531
|
output = conv(fm_offset, weight)
|
|
3225
3532
|
if bias is not None:
|
|
3226
3533
|
output = bias_add_(output, bias)
|
|
@@ -3231,9 +3538,7 @@ def pdist(input, p=2.0):
|
|
|
3231
3538
|
r"""
|
|
3232
3539
|
Calculates the distance between every pair of row vectors in
|
|
3233
3540
|
the input using the p-norm. If the input `input` is a 2D Tensor with shape :math:`(N, M)`,
|
|
3234
|
-
the `output` must be a 1D Tensor with shape :math:`(N * (N - 1) / 2,)`.
|
|
3235
|
-
dimension with shape :math:`(*B, N, M)`, then the `output` must be a Tensor with
|
|
3236
|
-
shape :math:`(*B, N * (N - 1) / 2)`.
|
|
3541
|
+
the `output` must be a 1D Tensor with shape :math:`(N * (N - 1) / 2,)`.
|
|
3237
3542
|
|
|
3238
3543
|
.. math::
|
|
3239
3544
|
y[n] = \sqrt[p]{{\mid x_{i} - x_{j} \mid}^p}
|
|
@@ -3241,8 +3546,7 @@ def pdist(input, p=2.0):
|
|
|
3241
3546
|
where :math:`x_{i}, x_{j}` are two different row vectors in the input.
|
|
3242
3547
|
|
|
3243
3548
|
Args:
|
|
3244
|
-
input (Tensor): Input tensor
|
|
3245
|
-
dtype: float16, float32 or float64.
|
|
3549
|
+
input (Tensor): Input tensor. dtype: float16, float32 or float64.
|
|
3246
3550
|
p (float): The order of norm distance, :math:`p∈[0, ∞)`. Default: ``2.0`` .
|
|
3247
3551
|
|
|
3248
3552
|
Returns:
|
|
@@ -3270,7 +3574,144 @@ def pdist(input, p=2.0):
|
|
|
3270
3574
|
return pdist_(input)
|
|
3271
3575
|
|
|
3272
3576
|
|
|
3273
|
-
|
|
3577
|
+
def _circular_pad(input_x, padding):
|
|
3578
|
+
"""circular pad"""
|
|
3579
|
+
if isinstance(padding, tuple):
|
|
3580
|
+
padding = tuple_to_tensor_(padding, mstype.int64)
|
|
3581
|
+
elif isinstance(padding, list):
|
|
3582
|
+
padding = list_to_tensor_(padding, mstype.int64)
|
|
3583
|
+
is_expand = False
|
|
3584
|
+
if padding.shape[0] // 2 + 1 == input_x.ndim:
|
|
3585
|
+
input_x = input_x.expand_dims(0)
|
|
3586
|
+
is_expand = True
|
|
3587
|
+
out = PadV3(mode="circular", paddings_contiguous=True)(input_x, padding, None)
|
|
3588
|
+
if is_expand:
|
|
3589
|
+
out = out.squeeze(0)
|
|
3590
|
+
return out
|
|
3591
|
+
|
|
3592
|
+
|
|
3593
|
+
def _reflection_pad(input, pad):
|
|
3594
|
+
"""reflection pad"""
|
|
3595
|
+
out = input
|
|
3596
|
+
if len(pad) == 2:
|
|
3597
|
+
out = reflection_pad_1d_op(input, pad)
|
|
3598
|
+
elif len(pad) == 4:
|
|
3599
|
+
out = reflection_pad_2d_op(input, pad)
|
|
3600
|
+
else:
|
|
3601
|
+
out = reflection_pad_3d_op(input, pad)
|
|
3602
|
+
return out
|
|
3603
|
+
|
|
3604
|
+
|
|
3605
|
+
def _replication_pad(input, pad):
|
|
3606
|
+
"""replication pad"""
|
|
3607
|
+
out = input
|
|
3608
|
+
if len(pad) == 2:
|
|
3609
|
+
out = replication_pad_1d_op(input, pad)
|
|
3610
|
+
elif len(pad) == 4:
|
|
3611
|
+
out = replication_pad_2d_op(input, pad)
|
|
3612
|
+
else:
|
|
3613
|
+
out = replication_pad_3d_op(input, pad)
|
|
3614
|
+
return out
|
|
3615
|
+
|
|
3616
|
+
|
|
3617
|
+
def pad_ext(input, pad, mode='constant', value=0.0):
|
|
3618
|
+
r"""
|
|
3619
|
+
Pads the input tensor according to the pad.
|
|
3620
|
+
|
|
3621
|
+
.. warning::
|
|
3622
|
+
`circular` mode has poor performance and is not recommended.
|
|
3623
|
+
|
|
3624
|
+
Args:
|
|
3625
|
+
input (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of additional dimensions.
|
|
3626
|
+
pad (Union[tuple[int], list[int], Tensor]): Filling position of pad.
|
|
3627
|
+
:math:`\left\lfloor\frac{\text{len(pad)}}{2}\right\rfloor` dimensions
|
|
3628
|
+
of `input` will be padded.
|
|
3629
|
+
|
|
3630
|
+
Example: to pad only the last dimension of the input tensor, then
|
|
3631
|
+
:attr:`pad` has the form
|
|
3632
|
+
:math:`(\text{padding_left}, \text{padding_right})`;
|
|
3633
|
+
|
|
3634
|
+
Example: to pad the last 2 dimensions of the input tensor, then use
|
|
3635
|
+
:math:`(\text{padding_left}, \text{padding_right}, \text{padding_top}, \text{padding_bottom})`;
|
|
3636
|
+
|
|
3637
|
+
Example: to pad the last 3 dimensions, use
|
|
3638
|
+
:math:`(\text{padding_left}, \text{padding_right}, \text{padding_top}, \text{padding_bottom},
|
|
3639
|
+
\text{padding_front}, \text{padding_back})` and so on.
|
|
3640
|
+
|
|
3641
|
+
mode (str, optional): Pad filling mode, ``'constant'`` , ``'reflect'`` , ``'replicate'`` or ``'circular'`` .
|
|
3642
|
+
Default: ``'constant'`` .
|
|
3643
|
+
|
|
3644
|
+
For ``'constant'`` mode, please refer to :class:`mindspore.nn.ConstantPad1d` as an example to understand
|
|
3645
|
+
this filling pattern and extend the padding pattern to n dimensions.
|
|
3646
|
+
|
|
3647
|
+
For ``'reflect'`` mode, please refer to :class:`mindspore.nn.ReflectionPad1d` as an example to understand
|
|
3648
|
+
this filling pattern.
|
|
3649
|
+
The reflect mode is used to pad the last three dimensions of 4D or 5D input, the last two dimensions of 3D
|
|
3650
|
+
or 4D input, or the last dimension of 2D or 3D input.
|
|
3651
|
+
|
|
3652
|
+
For ``'replicate'`` mode, please refer to :class:`mindspore.nn.ReplicationPad1d` as an example to understand
|
|
3653
|
+
this filling pattern.
|
|
3654
|
+
The replicate mode is used to pad the last three dimensions of 4D or 5D input, the last two dimensions of 3D
|
|
3655
|
+
or 4D input, or the last dimension of 2D or 3D input.
|
|
3656
|
+
|
|
3657
|
+
For ``'circular'`` mode, the pixels from one edge of the image are wrapped around to the opposite edge,
|
|
3658
|
+
such that the pixel on the right edge of the image is replaced with the pixel on the left edge,
|
|
3659
|
+
and the pixel on the bottom edge is replaced with the pixel on the top edge.
|
|
3660
|
+
The circular mode is used to pad the last three dimensions of 4D or 5D input, the last two dimensions of 3D
|
|
3661
|
+
or 4D input, or the last dimension of 2D or 3D input.
|
|
3662
|
+
|
|
3663
|
+
value (Union[int, float, None], optional): Valid only in ``'constant'`` mode.
|
|
3664
|
+
Set the padding value in ``'constant'`` mode. If the value is None, 0 is used as the default padding value.
|
|
3665
|
+
Default: ``0.0`` .
|
|
3666
|
+
|
|
3667
|
+
Returns:
|
|
3668
|
+
Tensor, the tensor after padding.
|
|
3669
|
+
|
|
3670
|
+
Raises:
|
|
3671
|
+
TypeError: If `pad` is not an int of tuple or int of list.
|
|
3672
|
+
TypeError: If `input` is not a Tensor.
|
|
3673
|
+
ValueError: If length of `pad` is not even.
|
|
3674
|
+
ValueError: If length of `pad` is greater than 6.
|
|
3675
|
+
ValueError: If `mode` is not ``'constant'`` and `value` not ``None``.
|
|
3676
|
+
|
|
3677
|
+
Supported Platforms:
|
|
3678
|
+
``Ascend``
|
|
3679
|
+
|
|
3680
|
+
Examples:
|
|
3681
|
+
>>> from mindspore import ops
|
|
3682
|
+
>>> import numpy as np
|
|
3683
|
+
>>> x = ms.Tensor(np.arange(1 * 2 * 2 * 2).reshape((1, 2, 2, 2)), dtype=ms.float64)
|
|
3684
|
+
>>> output = ops.function.nn_func.pad_ext(x, [1, 0, 0, 1], mode='constant', value=6.0)
|
|
3685
|
+
>>> print(output)
|
|
3686
|
+
[[[[6. 0. 1.]
|
|
3687
|
+
[6. 2. 3.]
|
|
3688
|
+
[6. 6. 6.]]
|
|
3689
|
+
[[6. 4. 5.]
|
|
3690
|
+
[6. 6. 7.]
|
|
3691
|
+
[6. 6. 6.]]]]
|
|
3692
|
+
"""
|
|
3693
|
+
if not isinstance(input, Tensor):
|
|
3694
|
+
raise TypeError(f"For 'pad', the type of 'input' must be Tensor, but got {type(input)}.")
|
|
3695
|
+
out = input
|
|
3696
|
+
if (isinstance(pad, tuple) and not pad):
|
|
3697
|
+
return out
|
|
3698
|
+
if mode == "constant":
|
|
3699
|
+
value = 0 if value is None else value
|
|
3700
|
+
out = constant_pad_nd_op(input, pad, value)
|
|
3701
|
+
else:
|
|
3702
|
+
if value != 0.0:
|
|
3703
|
+
raise ValueError(f"Padding mode {mode} doesn\'t take in value argument.")
|
|
3704
|
+
if mode == "circular":
|
|
3705
|
+
out = _circular_pad(input, pad)
|
|
3706
|
+
elif mode == "reflect":
|
|
3707
|
+
out = _reflection_pad(input, pad)
|
|
3708
|
+
elif mode == "replicate":
|
|
3709
|
+
out = _replication_pad(input, pad)
|
|
3710
|
+
else:
|
|
3711
|
+
raise ValueError(f"Pad filling mode must be 'constant' 'circular' 'reflect' or 'replicate'.")
|
|
3712
|
+
return out
|
|
3713
|
+
|
|
3714
|
+
|
|
3274
3715
|
def _check_pad_inputs(padding):
|
|
3275
3716
|
"""check the input of pad"""
|
|
3276
3717
|
if len(padding) % 2 != 0:
|
|
@@ -3288,8 +3729,10 @@ def pad(input_x, padding, mode='constant', value=None):
|
|
|
3288
3729
|
Pads the input tensor according to the padding.
|
|
3289
3730
|
|
|
3290
3731
|
Args:
|
|
3291
|
-
input_x (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of additional dimensions
|
|
3292
|
-
|
|
3732
|
+
input_x (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of additional dimensions
|
|
3733
|
+
which is required to be no more than 5 in Ascend.
|
|
3734
|
+
padding (Union[tuple[int], list[int], Tensor]): Filling position of pad where the negative value is not
|
|
3735
|
+
supported while running in Ascend.
|
|
3293
3736
|
:math:`\left\lfloor\frac{\text{len(padding)}}{2}\right\rfloor` dimensions
|
|
3294
3737
|
of `input_x` will be padded.
|
|
3295
3738
|
|
|
@@ -3298,56 +3741,56 @@ def pad(input_x, padding, mode='constant', value=None):
|
|
|
3298
3741
|
:math:`(\text{padding_left}, \text{padding_right})`;
|
|
3299
3742
|
|
|
3300
3743
|
Example: to pad the last 2 dimensions of the input tensor, then use
|
|
3301
|
-
:math:`(\text{padding_left}, \text{padding_right}
|
|
3302
|
-
:math:`\text{padding_top}, \text{padding_bottom})`;
|
|
3744
|
+
:math:`(\text{padding_left}, \text{padding_right}, \text{padding_top}, \text{padding_bottom})`;
|
|
3303
3745
|
|
|
3304
3746
|
Example: to pad the last 3 dimensions, use
|
|
3305
|
-
:math:`(\text{padding_left}, \text{padding_right}
|
|
3306
|
-
|
|
3307
|
-
:math:`\text{padding_front}, \text{padding_back})` and so on.
|
|
3747
|
+
:math:`(\text{padding_left}, \text{padding_right}, \text{padding_top}, \text{padding_bottom},
|
|
3748
|
+
\text{padding_front}, \text{padding_back})` and so on.
|
|
3308
3749
|
|
|
3309
|
-
mode (str, optional): Pad filling mode, ``
|
|
3750
|
+
mode (str, optional): Pad filling mode, ``'constant'`` , ``'reflect'`` , ``'replicate'`` or ``'circular'`` .
|
|
3310
3751
|
Default: ``'constant'`` .
|
|
3311
3752
|
|
|
3312
|
-
For
|
|
3753
|
+
For ``'constant'`` mode, please refer to :class:`mindspore.nn.ConstantPad1d` as an example to understand
|
|
3313
3754
|
this filling pattern and extend the padding pattern to n dimensions.
|
|
3314
3755
|
|
|
3315
|
-
For
|
|
3756
|
+
For ``'reflect'`` mode, please refer to :class:`mindspore.nn.ReflectionPad1d` as an example to understand
|
|
3316
3757
|
this filling pattern.
|
|
3317
3758
|
The reflect mode is used to pad the last two dimensions of 3D or 4D input, or the last dimension of 2D or
|
|
3318
3759
|
3D input.
|
|
3319
3760
|
|
|
3320
|
-
For
|
|
3761
|
+
For ``'replicate'`` mode, please refer to :class:`mindspore.nn.ReplicationPad1d` as an example to understand
|
|
3321
3762
|
this filling pattern.
|
|
3322
3763
|
The replicate mode is used to pad the last three dimensions of 4D or 5D input, the last two dimensions of 3D
|
|
3323
3764
|
or 4D input, or the last dimension of 2D or 3D input.
|
|
3324
3765
|
|
|
3325
|
-
For
|
|
3766
|
+
For ``'circular'`` mode, the pixels from one edge of the image are wrapped around to the opposite edge,
|
|
3326
3767
|
such that the pixel on the right edge of the image is replaced with the pixel on the left edge,
|
|
3327
3768
|
and the pixel on the bottom edge is replaced with the pixel on the top edge.
|
|
3328
3769
|
The circular mode is used to pad the last three dimensions of 4D or 5D input, the last two dimensions of 3D
|
|
3329
3770
|
or 4D input, or the last dimension of 2D or 3D input.
|
|
3330
3771
|
|
|
3331
|
-
value (Union[int, float, None], optional): Valid only in
|
|
3332
|
-
Set the padding value in
|
|
3772
|
+
value (Union[int, float, None], optional): Valid only in ``'constant'`` mode.
|
|
3773
|
+
Set the padding value in ``'constant'`` mode. If the value is None, 0 is used as the default padding value.
|
|
3333
3774
|
Default: ``None`` .
|
|
3334
3775
|
|
|
3335
3776
|
Returns:
|
|
3336
3777
|
Tensor, the tensor after padding.
|
|
3337
3778
|
|
|
3338
3779
|
Raises:
|
|
3339
|
-
TypeError: If `
|
|
3780
|
+
TypeError: If `padding` is not an int of tuple or int of list.
|
|
3340
3781
|
TypeError: If `input_x` is not a Tensor.
|
|
3341
3782
|
ValueError: If length of `padding` is not even.
|
|
3342
3783
|
ValueError: If length of `padding` is greater than 6.
|
|
3343
|
-
ValueError: If mode is not
|
|
3784
|
+
ValueError: If `mode` is not ``'constant'`` and `value` not ``None``.
|
|
3785
|
+
ValueError: If rank of `input_x` is more than 5 while running in Ascend.
|
|
3786
|
+
ValueError: If `paddings` contains negative value while running in Ascend.
|
|
3344
3787
|
|
|
3345
3788
|
Supported Platforms:
|
|
3346
3789
|
``Ascend`` ``GPU`` ``CPU``
|
|
3347
3790
|
|
|
3348
3791
|
Examples:
|
|
3349
3792
|
>>> import mindspore as ms
|
|
3350
|
-
>>>
|
|
3793
|
+
>>> from mindspore import ops
|
|
3351
3794
|
>>> import numpy as np
|
|
3352
3795
|
>>> x = ms.Tensor(np.arange(1 * 2 * 2 * 2).reshape((1, 2, 2, 2)), dtype=ms.float64)
|
|
3353
3796
|
>>> output = ops.pad(x, [1, 0, 0, 1], mode='constant', value=6.0)
|
|
@@ -3397,7 +3840,7 @@ def pad(input_x, padding, mode='constant', value=None):
|
|
|
3397
3840
|
return input_x
|
|
3398
3841
|
if not isinstance(padding, Tensor):
|
|
3399
3842
|
_check_pad_inputs(padding)
|
|
3400
|
-
padding =
|
|
3843
|
+
padding = tuple(padding)
|
|
3401
3844
|
is_expand = False
|
|
3402
3845
|
if mode == "constant":
|
|
3403
3846
|
value = 0 if value is None else value
|
|
@@ -3410,7 +3853,7 @@ def pad(input_x, padding, mode='constant', value=None):
|
|
|
3410
3853
|
raise ValueError(f"For 'pad', the padding mode '{mode}' can not set value, but got value {value}.")
|
|
3411
3854
|
if mode == "replicate":
|
|
3412
3855
|
mode = "edge"
|
|
3413
|
-
if padding
|
|
3856
|
+
if len(padding) // 2 + 1 == input_x.ndim:
|
|
3414
3857
|
input_x = input_x.expand_dims(0)
|
|
3415
3858
|
is_expand = True
|
|
3416
3859
|
out = PadV3(mode=mode, paddings_contiguous=True)(input_x, padding, value)
|
|
@@ -3419,142 +3862,6 @@ def pad(input_x, padding, mode='constant', value=None):
|
|
|
3419
3862
|
return out
|
|
3420
3863
|
|
|
3421
3864
|
|
|
3422
|
-
def relu(input):
|
|
3423
|
-
r"""
|
|
3424
|
-
Computes ReLU (Rectified Linear Unit activation function) of input tensors element-wise.
|
|
3425
|
-
|
|
3426
|
-
It returns :math:`\max(input,\ 0)` element-wise. Specially, the neurons with the negative output
|
|
3427
|
-
will be suppressed and the active neurons will stay the same.
|
|
3428
|
-
|
|
3429
|
-
.. math::
|
|
3430
|
-
|
|
3431
|
-
ReLU(input) = (input)^+ = \max(0, input)
|
|
3432
|
-
|
|
3433
|
-
Note:
|
|
3434
|
-
In general, this operator is more commonly used. The difference from `ReLuV2` is that the `ReLuV2` will
|
|
3435
|
-
output one more Mask.
|
|
3436
|
-
|
|
3437
|
-
Args:
|
|
3438
|
-
input (Tensor): Input Tensor of numeric types.
|
|
3439
|
-
|
|
3440
|
-
Returns:
|
|
3441
|
-
Tensor, has the same dtype and shape as `input_x`.
|
|
3442
|
-
|
|
3443
|
-
Raises:
|
|
3444
|
-
TypeError: If dtype of `input` is not a number.
|
|
3445
|
-
TypeError: If `input` is not a Tensor.
|
|
3446
|
-
|
|
3447
|
-
Supported Platforms:
|
|
3448
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
3449
|
-
|
|
3450
|
-
Examples:
|
|
3451
|
-
>>> import mindspore
|
|
3452
|
-
>>> import numpy as np
|
|
3453
|
-
>>> from mindspore import Tensor, ops
|
|
3454
|
-
>>> input_x = Tensor(np.array([[-1.0, 4.0, -8.0], [2.0, -5.0, 9.0]]), mindspore.float32)
|
|
3455
|
-
>>> output = ops.relu(input_x)
|
|
3456
|
-
>>> print(output)
|
|
3457
|
-
[[0. 4. 0.]
|
|
3458
|
-
[2. 0. 9.]]
|
|
3459
|
-
"""
|
|
3460
|
-
relu_ = _get_cache_prim(NN_OPS.ReLU)()
|
|
3461
|
-
return relu_(input)
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
def relu6(x):
|
|
3465
|
-
r"""
|
|
3466
|
-
Computes ReLU (Rectified Linear Unit) upper bounded by 6 of input tensors element-wise.
|
|
3467
|
-
|
|
3468
|
-
.. math::
|
|
3469
|
-
|
|
3470
|
-
\text{ReLU6}(x) = \min(\max(0,x), 6)
|
|
3471
|
-
|
|
3472
|
-
It returns :math:`\min(\max(0,x), 6)` element-wise.
|
|
3473
|
-
|
|
3474
|
-
Args:
|
|
3475
|
-
x (Tensor): Tensor of shape :math:`(N, *)`,
|
|
3476
|
-
where :math:`*` means any number of additional dimensions.
|
|
3477
|
-
Data type must be float16, float32.
|
|
3478
|
-
|
|
3479
|
-
Returns:
|
|
3480
|
-
Tensor, with the same dtype and shape as the `x`.
|
|
3481
|
-
|
|
3482
|
-
Raises:
|
|
3483
|
-
TypeError: If dtype of `x` is neither float16 nor float32.
|
|
3484
|
-
TypeError: If `x` is not a Tensor.
|
|
3485
|
-
|
|
3486
|
-
Supported Platforms:
|
|
3487
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
3488
|
-
|
|
3489
|
-
Examples:
|
|
3490
|
-
>>> import mindspore
|
|
3491
|
-
>>> import numpy as np
|
|
3492
|
-
>>> from mindspore import Tensor, ops
|
|
3493
|
-
>>> input_x = Tensor(np.array([[-1.0, 4.0, -8.0], [2.0, -5.0, 9.0]]), mindspore.float32)
|
|
3494
|
-
>>> result = ops.relu6(input_x)
|
|
3495
|
-
>>> print(result)
|
|
3496
|
-
[[0. 4. 0.]
|
|
3497
|
-
[2. 0. 6.]]
|
|
3498
|
-
"""
|
|
3499
|
-
relu6_ = _get_cache_prim(NN_OPS.ReLU6)()
|
|
3500
|
-
return relu6_(x)
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
def prelu(x, weight):
|
|
3504
|
-
r"""
|
|
3505
|
-
Parametric Rectified Linear Unit activation function.
|
|
3506
|
-
|
|
3507
|
-
PReLU is described in the paper `Delving Deep into Rectifiers: Surpassing Human-Level Performance on
|
|
3508
|
-
ImageNet Classification <https://arxiv.org/abs/1502.01852>`_. Defined as follows:
|
|
3509
|
-
|
|
3510
|
-
.. math::
|
|
3511
|
-
prelu(x_i)= \max(0, x_i) + \min(0, w * x_i),
|
|
3512
|
-
|
|
3513
|
-
where :math:`x_i` is an element of a channel of the input, `w` is the weight of the channel.
|
|
3514
|
-
|
|
3515
|
-
Note:
|
|
3516
|
-
Scalar or 1-D Tensor is not supported on Ascend.
|
|
3517
|
-
|
|
3518
|
-
Args:
|
|
3519
|
-
x (Tensor): The input Tensor of the activation function. The data type is float16 or float32.
|
|
3520
|
-
The shape is :math:`(N, *)` where :math:`*` means, any number of additional dimensions.
|
|
3521
|
-
weight (Tensor): Weight Tensor. The data type is float16 or float32.
|
|
3522
|
-
The weight can only be a Tensor, and the length is the same as the number of channels C of the `input_x`.
|
|
3523
|
-
On GPU devices, when the input is a scalar, the shape is :math:`(1,)` .
|
|
3524
|
-
|
|
3525
|
-
Returns:
|
|
3526
|
-
Tensor, with the same shape and dtype as `x`.
|
|
3527
|
-
|
|
3528
|
-
For detailed information, please refer to :class:`mindspore.nn.PReLU`.
|
|
3529
|
-
|
|
3530
|
-
Raises:
|
|
3531
|
-
TypeError: If dtype of `x` or `weight` is neither float16 nor float32.
|
|
3532
|
-
TypeError: If the `x` or the `weight` is not a Tensor.
|
|
3533
|
-
ValueError: If the `x` is a 0-D or 1-D Tensor on Ascend.
|
|
3534
|
-
ValueError: If the `weight` is not a 1-D Tensor.
|
|
3535
|
-
|
|
3536
|
-
Supported Platforms:
|
|
3537
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
3538
|
-
|
|
3539
|
-
Examples:
|
|
3540
|
-
>>> import mindspore
|
|
3541
|
-
>>> import numpy as np
|
|
3542
|
-
>>> from mindspore import Tensor, ops
|
|
3543
|
-
>>> x = Tensor(np.arange(-6, 6).reshape((2, 3, 2)), mindspore.float32)
|
|
3544
|
-
>>> weight = Tensor(np.array([0.1, 0.6, -0.3]), mindspore.float32)
|
|
3545
|
-
>>> output = ops.prelu(x, weight)
|
|
3546
|
-
>>> print(output)
|
|
3547
|
-
[[[-0.60 -0.50]
|
|
3548
|
-
[-2.40 -1.80]
|
|
3549
|
-
[ 0.60 0.30]]
|
|
3550
|
-
[[ 0.00 1.00]
|
|
3551
|
-
[ 2.00 3.00]
|
|
3552
|
-
[ 4.0 5.00]]]
|
|
3553
|
-
"""
|
|
3554
|
-
prelu_ = _get_cache_prim(NN_OPS.PReLU)()
|
|
3555
|
-
return prelu_(x, weight)
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
3865
|
def rrelu(input, lower=1.0 / 8, upper=1.0 / 3):
|
|
3559
3866
|
r"""
|
|
3560
3867
|
|
|
@@ -3583,7 +3890,7 @@ def rrelu(input, lower=1.0 / 8, upper=1.0 / 3):
|
|
|
3583
3890
|
TypeError: If `lower` is not a float or an int.
|
|
3584
3891
|
TypeError: If `upper` is not a float or an int.
|
|
3585
3892
|
TypeError: If `input` is not a Tensor.
|
|
3586
|
-
TypeError: If `input` is not a Tensor of mindspore.float16 or
|
|
3893
|
+
TypeError: If `input` is not a Tensor of mindspore.float16 or mindspore.float32.
|
|
3587
3894
|
ValueError: If `lower` is greater than upper.
|
|
3588
3895
|
|
|
3589
3896
|
Supported Platforms:
|
|
@@ -3612,13 +3919,12 @@ def rrelu(input, lower=1.0 / 8, upper=1.0 / 3):
|
|
|
3612
3919
|
_upper = Tensor(upper, mstype.float32)
|
|
3613
3920
|
_size = input.shape
|
|
3614
3921
|
if ops.is_sequence_value_unknown(_size):
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
sign_matrix = _get_cache_prim(P.Sign)()(input)
|
|
3922
|
+
_size = tensor_shape_(input)
|
|
3923
|
+
sign_matrix = sign_(input)
|
|
3618
3924
|
negative_filter = sign_matrix.clip(None, 0)
|
|
3619
3925
|
positive_filter = sign_matrix.clip(0, None)
|
|
3620
|
-
|
|
3621
|
-
mask = ops.uniform(_size, _lower, _upper).astype(
|
|
3926
|
+
input_dtype = dtype_(input)
|
|
3927
|
+
mask = ops.uniform(_size, _lower, _upper).astype(input_dtype)
|
|
3622
3928
|
negative_mask = negative_filter * mask * -1
|
|
3623
3929
|
total_mask = negative_mask + positive_filter
|
|
3624
3930
|
out = total_mask * input
|
|
@@ -3686,6 +3992,21 @@ def _innner_log_softmax(inputs, axis):
|
|
|
3686
3992
|
return inputs - logsumexp(inputs, axis, True)
|
|
3687
3993
|
|
|
3688
3994
|
|
|
3995
|
+
def _check_cross_entropy_inputs(input, target, weight, ignore_index, reduction, label_smoothing):
|
|
3996
|
+
"""
|
|
3997
|
+
Check inputs for cross_entropy().
|
|
3998
|
+
"""
|
|
3999
|
+
_check_is_tensor('input', input, "cross_entropy_loss")
|
|
4000
|
+
_check_is_tensor('target', target, "cross_entropy_loss")
|
|
4001
|
+
_check_is_tensor('weight', weight, "cross_entropy_loss")
|
|
4002
|
+
check_int_const(ignore_index, 'ignore_index', "cross_entropy_loss")
|
|
4003
|
+
check_non_negative_float_const(label_smoothing, 'label_smoothing', "cross_entropy_loss")
|
|
4004
|
+
check_string_const(reduction, ['none', 'mean', 'sum'], 'reduction', "cross_entropy_loss")
|
|
4005
|
+
if input.dtype not in [mstype.float64, mstype.float32, mstype.float16]:
|
|
4006
|
+
raise TypeError(f'For cross_entropy, the input dtype should be mstype.float64, mstype.float32 or'
|
|
4007
|
+
f'mstype.float16, but got dtype:{input.dtype}.')
|
|
4008
|
+
|
|
4009
|
+
|
|
3689
4010
|
def cross_entropy(input, target, weight=None, ignore_index=-100, reduction='mean', label_smoothing=0.0):
|
|
3690
4011
|
r"""
|
|
3691
4012
|
The cross entropy loss between input and target.
|
|
@@ -3743,7 +4064,7 @@ def cross_entropy(input, target, weight=None, ignore_index=-100, reduction='mean
|
|
|
3743
4064
|
`input` is expected to be log-probabilities, data type must be float16 or float32.
|
|
3744
4065
|
target (Tensor): For class indices, tensor of shape :math:`()`, :math:`(N)` or
|
|
3745
4066
|
:math:`(N, d_1, d_2, ..., d_K)` , data type must be int32. For probabilities, tensor of shape :math:`(C,)` ,
|
|
3746
|
-
:math:`(N, C)` or :math:`(N, C, d_1, d_2, ..., d_K)` , data type must be float16 or float32.
|
|
4067
|
+
:math:`(N, C)` or :math:`(N, C, d_1, d_2, ..., d_K)` , data type must be float16 or float32 or float64.
|
|
3747
4068
|
weight (Tensor): A rescaling weight applied to the loss of each batch element.
|
|
3748
4069
|
If not None, the shape is :math:`(C,)`, data type must be float16 or float32. Default: ``None`` .
|
|
3749
4070
|
ignore_index (int): Specifies a target value that is ignored
|
|
@@ -3776,12 +4097,7 @@ def cross_entropy(input, target, weight=None, ignore_index=-100, reduction='mean
|
|
|
3776
4097
|
>>> target = ms.Tensor(np.random.randn(3, 5), ms.float32)
|
|
3777
4098
|
>>> output = ms.ops.cross_entropy(inputs, target)
|
|
3778
4099
|
"""
|
|
3779
|
-
|
|
3780
|
-
_check_is_tensor('target', target, "cross_entropy_loss")
|
|
3781
|
-
_check_is_tensor('weight', weight, "cross_entropy_loss")
|
|
3782
|
-
check_int_const(ignore_index, 'ignore_index', "cross_entropy_loss")
|
|
3783
|
-
check_non_negative_float_const(label_smoothing, 'label_smoothing', "cross_entropy_loss")
|
|
3784
|
-
check_string_const(reduction, ['none', 'mean', 'sum'], 'reduction', "cross_entropy_loss")
|
|
4100
|
+
_check_cross_entropy_inputs(input, target, weight, ignore_index, reduction, label_smoothing)
|
|
3785
4101
|
class_dim = 0 if input.ndim == 1 else 1
|
|
3786
4102
|
if target.dtype in [mstype.float32, mstype.float16]:
|
|
3787
4103
|
return _cross_entropy(input, target, class_dim, weight, reduction, label_smoothing)
|
|
@@ -3790,8 +4106,6 @@ def cross_entropy(input, target, weight=None, ignore_index=-100, reduction='mean
|
|
|
3790
4106
|
|
|
3791
4107
|
def _cross_entropy(inputs, target, target_dim, weight=None, reduction='mean', label_smoothing=0.0):
|
|
3792
4108
|
"""cross entropy inner function"""
|
|
3793
|
-
_ones_like = _get_cache_prim(P.OnesLike)()
|
|
3794
|
-
|
|
3795
4109
|
class_dim = 0 if inputs.ndim == 1 else 1
|
|
3796
4110
|
n_classes = inputs.shape[class_dim]
|
|
3797
4111
|
inputs = _innner_log_softmax(inputs, class_dim)
|
|
@@ -3799,7 +4113,7 @@ def _cross_entropy(inputs, target, target_dim, weight=None, reduction='mean', la
|
|
|
3799
4113
|
target = target * (1 - label_smoothing) + label_smoothing / n_classes
|
|
3800
4114
|
|
|
3801
4115
|
if weight is None:
|
|
3802
|
-
weight =
|
|
4116
|
+
weight = ones_like_(inputs)
|
|
3803
4117
|
elif inputs.ndim != 1:
|
|
3804
4118
|
broadcast_shape = [1 for _ in range(inputs.ndim)]
|
|
3805
4119
|
broadcast_shape[1] = weight.shape[0]
|
|
@@ -3829,7 +4143,7 @@ def nll_loss(inputs, target, weight=None, ignore_index=-100, reduction='mean', l
|
|
|
3829
4143
|
N is the batch size, :math:`c` belonging to :math:`[0, C-1]` is class index, where :math:`C` is the number of
|
|
3830
4144
|
classes.
|
|
3831
4145
|
|
|
3832
|
-
If `reduction` is not ``None`` (default 'mean'), then
|
|
4146
|
+
If `reduction` is not ``None`` (default ``'mean'``), then
|
|
3833
4147
|
|
|
3834
4148
|
.. math::
|
|
3835
4149
|
|
|
@@ -3897,37 +4211,31 @@ def nll_loss(inputs, target, weight=None, ignore_index=-100, reduction='mean', l
|
|
|
3897
4211
|
|
|
3898
4212
|
def _nll_loss(inputs, target, target_dim=-1, weight=None, ignore_index=None, reduction='none', label_smoothing=0.0):
|
|
3899
4213
|
"""nll loss inner function"""
|
|
3900
|
-
_neg = _get_cache_prim(P.Neg)()
|
|
3901
|
-
_gather_d = _get_cache_prim(P.GatherD)()
|
|
3902
|
-
_gather = _get_cache_prim(P.Gather)()
|
|
3903
|
-
_ones_like = _get_cache_prim(P.OnesLike)()
|
|
3904
|
-
_equal = _get_cache_prim(P.Equal)()
|
|
3905
|
-
|
|
3906
4214
|
if target.ndim == inputs.ndim - 1:
|
|
3907
4215
|
target = target.expand_dims(target_dim)
|
|
3908
4216
|
if ignore_index is not None:
|
|
3909
|
-
non_pad_mask =
|
|
3910
|
-
target = target.masked_fill(non_pad_mask, 0)
|
|
4217
|
+
non_pad_mask = equal_(target, ignore_index)
|
|
4218
|
+
target = target.masked_fill(non_pad_mask, ops.cast(0, target.dtype))
|
|
3911
4219
|
else:
|
|
3912
4220
|
non_pad_mask = target
|
|
3913
4221
|
if weight is not None:
|
|
3914
|
-
loss_weights =
|
|
4222
|
+
loss_weights = gather_(weight, target, 0)
|
|
3915
4223
|
orig_shape = inputs.shape
|
|
3916
4224
|
if inputs.ndim != 2:
|
|
3917
4225
|
inputs = inputs.view(orig_shape[:2] + (-1,))
|
|
3918
4226
|
weight = weight.view(weight.shape + (1,))
|
|
3919
4227
|
weighted_inputs = inputs * weight
|
|
3920
4228
|
weighted_inputs = weighted_inputs.view(orig_shape)
|
|
3921
|
-
loss =
|
|
3922
|
-
smooth_loss =
|
|
4229
|
+
loss = neg_(gather_d_(weighted_inputs, target_dim, target))
|
|
4230
|
+
smooth_loss = neg_(weighted_inputs.sum(axis=target_dim, keepdims=True))
|
|
3923
4231
|
else:
|
|
3924
|
-
loss =
|
|
3925
|
-
smooth_loss =
|
|
3926
|
-
loss_weights =
|
|
4232
|
+
loss = neg_(gather_d_(inputs, target_dim, target))
|
|
4233
|
+
smooth_loss = neg_(inputs.sum(axis=target_dim, keepdims=True))
|
|
4234
|
+
loss_weights = ones_like_(loss)
|
|
3927
4235
|
if ignore_index is not None:
|
|
3928
|
-
loss = loss.masked_fill(non_pad_mask, 0.)
|
|
3929
|
-
loss_weights = loss_weights.masked_fill(non_pad_mask, 0.)
|
|
3930
|
-
smooth_loss = smooth_loss.masked_fill(non_pad_mask, 0.)
|
|
4236
|
+
loss = loss.masked_fill(non_pad_mask, ops.cast(0, loss.dtype))
|
|
4237
|
+
loss_weights = loss_weights.masked_fill(non_pad_mask, ops.cast(0, loss_weights.dtype))
|
|
4238
|
+
smooth_loss = smooth_loss.masked_fill(non_pad_mask, ops.cast(0, smooth_loss.dtype))
|
|
3931
4239
|
|
|
3932
4240
|
loss = loss.squeeze(target_dim)
|
|
3933
4241
|
smooth_loss = smooth_loss.squeeze(target_dim)
|
|
@@ -3949,8 +4257,9 @@ def l1_loss(input, target, reduction='mean'):
|
|
|
3949
4257
|
r"""
|
|
3950
4258
|
Calculate the mean absolute error between the `input` value and the `target` value.
|
|
3951
4259
|
|
|
3952
|
-
Assuming that the :math:`x` and :math:`y` are 1-D Tensor,
|
|
3953
|
-
|
|
4260
|
+
Assuming that the :math:`x` and :math:`y` (predicted and target value) are 1-D Tensor,
|
|
4261
|
+
length :math:`N`, `reduction` is set to ``'none'``, then calculate the loss of
|
|
4262
|
+
:math:`x` and :math:`y` without dimensionality reduction.
|
|
3954
4263
|
|
|
3955
4264
|
The formula is as follows:
|
|
3956
4265
|
|
|
@@ -3959,7 +4268,7 @@ def l1_loss(input, target, reduction='mean'):
|
|
|
3959
4268
|
|
|
3960
4269
|
where :math:`N` is the batch size.
|
|
3961
4270
|
|
|
3962
|
-
If `reduction` is ``
|
|
4271
|
+
If `reduction` is ``'mean'`` or ``'sum'`` , then:
|
|
3963
4272
|
|
|
3964
4273
|
.. math::
|
|
3965
4274
|
\ell(x, y) =
|
|
@@ -3980,13 +4289,13 @@ def l1_loss(input, target, reduction='mean'):
|
|
|
3980
4289
|
- ``'sum'``: the output elements will be summed.
|
|
3981
4290
|
|
|
3982
4291
|
Returns:
|
|
3983
|
-
Tensor or Scalar, if `reduction` is ``
|
|
4292
|
+
Tensor or Scalar, if `reduction` is ``'none'``, return a Tensor with same shape and dtype as `input`.
|
|
3984
4293
|
Otherwise, a scalar value will be returned.
|
|
3985
4294
|
|
|
3986
4295
|
Raises:
|
|
3987
4296
|
TypeError: If `input` is not a Tensor.
|
|
3988
4297
|
TypeError: If `target` is not a Tensor.
|
|
3989
|
-
ValueError: If `reduction` is not one of ``
|
|
4298
|
+
ValueError: If `reduction` is not one of ``'none'``, ``'mean'`` or ``'sum'``.
|
|
3990
4299
|
|
|
3991
4300
|
Supported Platforms:
|
|
3992
4301
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -4004,7 +4313,7 @@ def l1_loss(input, target, reduction='mean'):
|
|
|
4004
4313
|
_check_is_tensor('target', target, "l1_loss")
|
|
4005
4314
|
if reduction not in ('mean', 'sum', 'none'):
|
|
4006
4315
|
raise ValueError(f"For l1_loss, the 'reduction' must be in ['mean', 'sum', 'none'], but got {reduction}.")
|
|
4007
|
-
loss =
|
|
4316
|
+
loss = abs_(input - target)
|
|
4008
4317
|
return _get_loss(loss, reduction, "l1_loss")
|
|
4009
4318
|
|
|
4010
4319
|
|
|
@@ -4039,6 +4348,7 @@ def smooth_l1_loss(input, target, beta=1.0, reduction='none'):
|
|
|
4039
4348
|
|
|
4040
4349
|
Args:
|
|
4041
4350
|
input (Tensor): Tensor of shape :math:`(N, *)` where :math:`*` means, any number of additional dimensions.
|
|
4351
|
+
Data type is float16, float32 or float64.
|
|
4042
4352
|
target (Tensor): Ground truth data, tensor of shape :math:`(N, *)`, same shape and dtype as the `input`.
|
|
4043
4353
|
beta (float): A parameter used to control the point where the function will change between
|
|
4044
4354
|
L1 to L2 loss. The value should be greater than zero. Default: ``1.0`` .
|
|
@@ -4117,13 +4427,13 @@ def threshold(input, thr, value):
|
|
|
4117
4427
|
_check_is_tensor('input', input, "threshold")
|
|
4118
4428
|
_check_value_type("thr", thr, [float, int], "threshold")
|
|
4119
4429
|
_check_value_type("value", value, [float, int], "threshold")
|
|
4120
|
-
cond =
|
|
4430
|
+
cond = greater_(input, thr)
|
|
4121
4431
|
input_type = input.dtype
|
|
4122
4432
|
value = Tensor(value, input_type)
|
|
4123
4433
|
input_shape = input.shape
|
|
4124
|
-
shape_tensor =
|
|
4125
|
-
value =
|
|
4126
|
-
return
|
|
4434
|
+
shape_tensor = tuple_to_tensor_(input_shape, mstype.int64)
|
|
4435
|
+
value = fillv2_(shape_tensor, value)
|
|
4436
|
+
return select_(cond, input, value)
|
|
4127
4437
|
|
|
4128
4438
|
|
|
4129
4439
|
def leaky_relu(input, alpha=0.2):
|
|
@@ -4141,6 +4451,11 @@ def leaky_relu(input, alpha=0.2):
|
|
|
4141
4451
|
For more details, see `Rectifier Nonlinearities Improve Neural Network Acoustic Models
|
|
4142
4452
|
<https://ai.stanford.edu/~amaas/papers/relu_hybrid_icml2013_final.pdf>`_.
|
|
4143
4453
|
|
|
4454
|
+
LeakyReLU Activation Function Graph:
|
|
4455
|
+
|
|
4456
|
+
.. image:: ../images/LeakyReLU.png
|
|
4457
|
+
:align: center
|
|
4458
|
+
|
|
4144
4459
|
Args:
|
|
4145
4460
|
input (Tensor): The input of leaky_relu is a Tensor of any dimension.
|
|
4146
4461
|
alpha (Union[int, float]): Slope of the activation function when the element of `input` is less than 0.
|
|
@@ -4167,10 +4482,10 @@ def leaky_relu(input, alpha=0.2):
|
|
|
4167
4482
|
"""
|
|
4168
4483
|
_check_is_tensor('input', input, "leaky_relu")
|
|
4169
4484
|
_check_value_type("alpha", alpha, [float, int], "leaky_relu")
|
|
4170
|
-
select_op =
|
|
4485
|
+
select_op = maximum_
|
|
4171
4486
|
if alpha > 1:
|
|
4172
|
-
select_op =
|
|
4173
|
-
alpha =
|
|
4487
|
+
select_op = minimum_
|
|
4488
|
+
alpha = cast_(F.scalar_to_tensor(alpha), input.dtype)
|
|
4174
4489
|
return select_op(alpha * input, input)
|
|
4175
4490
|
|
|
4176
4491
|
|
|
@@ -4211,48 +4526,6 @@ def intopk(x1, x2, k):
|
|
|
4211
4526
|
_in_topk = _get_cache_prim(P.InTopK)(k)
|
|
4212
4527
|
return _in_topk(x1, x2)
|
|
4213
4528
|
|
|
4214
|
-
|
|
4215
|
-
def log_softmax(logits, axis=-1):
|
|
4216
|
-
r"""
|
|
4217
|
-
Applies the Log Softmax function to the input tensor on the specified axis.
|
|
4218
|
-
Supposes a slice in the given axis, :math:`x` for each element :math:`x_i`,
|
|
4219
|
-
the Log Softmax function is shown as follows:
|
|
4220
|
-
|
|
4221
|
-
.. math::
|
|
4222
|
-
\text{output}(x_i) = \log \left(\frac{\exp(x_i)} {\sum_{j = 0}^{N-1}\exp(x_j)}\right),
|
|
4223
|
-
|
|
4224
|
-
where :math:`N` is the length of the Tensor.
|
|
4225
|
-
|
|
4226
|
-
Args:
|
|
4227
|
-
logits (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
|
|
4228
|
-
additional dimensions, with float16 or float32 data type.
|
|
4229
|
-
axis (int): The axis to perform the Log softmax operation. Default: ``-1`` .
|
|
4230
|
-
|
|
4231
|
-
Returns:
|
|
4232
|
-
Tensor, with the same type and shape as the logits.
|
|
4233
|
-
|
|
4234
|
-
Raises:
|
|
4235
|
-
TypeError: If `axis` is not an int.
|
|
4236
|
-
TypeError: If dtype of `logits` is neither float16 nor float32.
|
|
4237
|
-
ValueError: If `axis` is not in range [-len(logits.shape), len(logits.shape)).
|
|
4238
|
-
ValueError: If dimension of `logits` is less than 1.
|
|
4239
|
-
|
|
4240
|
-
Supported Platforms:
|
|
4241
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
4242
|
-
|
|
4243
|
-
Examples:
|
|
4244
|
-
>>> import mindspore
|
|
4245
|
-
>>> import numpy as np
|
|
4246
|
-
>>> from mindspore import Tensor, ops
|
|
4247
|
-
>>> logits = Tensor(np.array([1, 2, 3, 4, 5]), mindspore.float32)
|
|
4248
|
-
>>> output = ops.log_softmax(logits)
|
|
4249
|
-
>>> print(output)
|
|
4250
|
-
[-4.4519143 -3.4519143 -2.4519143 -1.4519144 -0.4519144]
|
|
4251
|
-
"""
|
|
4252
|
-
_log_softmax = _get_cache_prim(P.LogSoftmax)(axis)
|
|
4253
|
-
return _log_softmax(logits)
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
4529
|
def lrn(x, depth_radius=5, bias=1.0, alpha=1.0, beta=0.5, norm_region="ACROSS_CHANNELS"):
|
|
4257
4530
|
r"""
|
|
4258
4531
|
Local Response Normalization.
|
|
@@ -4321,6 +4594,11 @@ def mish(x):
|
|
|
4321
4594
|
See more details in `A Self Regularized Non-Monotonic Neural Activation Function
|
|
4322
4595
|
<https://arxiv.org/abs/1908.08681>`_.
|
|
4323
4596
|
|
|
4597
|
+
Mish Activation Function Graph:
|
|
4598
|
+
|
|
4599
|
+
.. image:: ../images/Mish.png
|
|
4600
|
+
:align: center
|
|
4601
|
+
|
|
4324
4602
|
Args:
|
|
4325
4603
|
x (Tensor): The input Tensor.
|
|
4326
4604
|
Supported dtypes:
|
|
@@ -4387,21 +4665,15 @@ def _get_loss(x, reduction, cls_name, weights=1.0):
|
|
|
4387
4665
|
if reduction not in ('mean', 'sum', 'none'):
|
|
4388
4666
|
raise ValueError(f"For '{cls_name}', the 'reduction' must be in ['mean', 'sum', 'none'], "
|
|
4389
4667
|
f"but got {reduction}.")
|
|
4390
|
-
|
|
4391
|
-
reduce_mean = P.ReduceMean()
|
|
4392
|
-
reduce_sum = P.ReduceSum()
|
|
4393
|
-
mul = P.Mul()
|
|
4394
|
-
cast = P.Cast()
|
|
4395
|
-
|
|
4396
4668
|
input_dtype = x.dtype
|
|
4397
|
-
x =
|
|
4398
|
-
weights =
|
|
4399
|
-
x =
|
|
4669
|
+
x = cast_(x, mstype.float32)
|
|
4670
|
+
weights = cast_(weights, mstype.float32)
|
|
4671
|
+
x = mul_(weights, x)
|
|
4400
4672
|
if reduction == 'mean':
|
|
4401
|
-
x =
|
|
4673
|
+
x = reduce_mean_(x, _get_axis(x))
|
|
4402
4674
|
if reduction == 'sum':
|
|
4403
|
-
x =
|
|
4404
|
-
x =
|
|
4675
|
+
x = reduce_sum_(x, _get_axis(x))
|
|
4676
|
+
x = cast_(x, input_dtype)
|
|
4405
4677
|
return x
|
|
4406
4678
|
|
|
4407
4679
|
|
|
@@ -4412,20 +4684,6 @@ def check_input_dtype(param_name1, input_data1, param_name2, input_data2, cls_na
|
|
|
4412
4684
|
f'but got {param_name1} dtype:{input_data1.dtype}, {param_name2} dtype:{input_data2.dtype}.')
|
|
4413
4685
|
|
|
4414
4686
|
|
|
4415
|
-
def check_input_shape(param_name1, input_data1, param_name2, input_data2, cls_name):
|
|
4416
|
-
"""Check the shape of input1 and input2."""
|
|
4417
|
-
if input_data1.shape != input_data2.shape:
|
|
4418
|
-
raise ValueError(f'For {cls_name}, the {param_name1} shape should be equal to {param_name2} shape, '
|
|
4419
|
-
f'but got {param_name1} shape:{input_data1.shape}, {param_name2} shape:{input_data2.shape}.')
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
def _check_type_and_shape_same(param_name1, input_data1, param_name2, input_data2, cls_name):
|
|
4423
|
-
"""check input1 and input2 type and shape same"""
|
|
4424
|
-
check_input_dtype(param_name1, input_data1, param_name2, input_data2, cls_name)
|
|
4425
|
-
check_input_shape(param_name1, input_data1, param_name2, input_data2, cls_name)
|
|
4426
|
-
return 0
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
4687
|
def margin_ranking_loss(input1, input2, target, margin=0.0, reduction='mean'):
|
|
4430
4688
|
r"""
|
|
4431
4689
|
MarginRankingLoss creates a criterion that measures the loss.
|
|
@@ -4450,7 +4708,7 @@ def margin_ranking_loss(input1, input2, target, margin=0.0, reduction='mean'):
|
|
|
4450
4708
|
- ``'sum'``: the output elements will be summed.
|
|
4451
4709
|
|
|
4452
4710
|
Returns:
|
|
4453
|
-
Tensor or Scalar. if `reduction` is ``
|
|
4711
|
+
Tensor or Scalar. if `reduction` is ``'none'``, its shape is the same as `input1`.
|
|
4454
4712
|
Otherwise, a scalar value will be returned.
|
|
4455
4713
|
|
|
4456
4714
|
Raises:
|
|
@@ -4480,10 +4738,9 @@ def margin_ranking_loss(input1, input2, target, margin=0.0, reduction='mean'):
|
|
|
4480
4738
|
_check_is_tensor('input1', input1, "margin_ranking_loss")
|
|
4481
4739
|
_check_is_tensor('input2', input2, "margin_ranking_loss")
|
|
4482
4740
|
_check_is_tensor('target', target, "margin_ranking_loss")
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
x = maximum(-target * (input1 - input2) + margin, 0)
|
|
4741
|
+
check_input_dtype('input1', input1, 'input2', input2, 'margin_ranking_loss')
|
|
4742
|
+
check_input_dtype('target', target, 'input1', input1, 'margin_ranking_loss')
|
|
4743
|
+
x = maximum_(-target * (input1 - input2) + margin, 0)
|
|
4487
4744
|
return _get_loss(x, reduction, "margin_ranking_loss")
|
|
4488
4745
|
|
|
4489
4746
|
|
|
@@ -4511,7 +4768,7 @@ def cosine_embedding_loss(input1, input2, target, margin=0.0, reduction="mean"):
|
|
|
4511
4768
|
input2 (Tensor): Tensor of shape :math:`(N, *)`, same shape and dtype as `input1`.
|
|
4512
4769
|
target (Tensor): Contains value 1 or -1. Suppose the shape of `input1` is
|
|
4513
4770
|
:math:`(x_1, x_2, x_3, ..., x_R)`, then the shape of `target` must be :math:`(x_1, x_3, x_4, ..., x_R)`.
|
|
4514
|
-
margin (float, optional): Should be in [-1.0, 1.0]. Default: 0.0
|
|
4771
|
+
margin (float, optional): Should be in [-1.0, 1.0]. Default: ``0.0``.
|
|
4515
4772
|
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
4516
4773
|
``'sum'`` . Default: ``'mean'`` .
|
|
4517
4774
|
|
|
@@ -4526,7 +4783,7 @@ def cosine_embedding_loss(input1, input2, target, margin=0.0, reduction="mean"):
|
|
|
4526
4783
|
Raises:
|
|
4527
4784
|
TypeError: If `margin` is not a float.
|
|
4528
4785
|
ValueError: If `reduction` is not one of ``'none'``, ``'mean'``, ``'sum'``.
|
|
4529
|
-
ValueError: If `margin` is not in range [-1, 1].
|
|
4786
|
+
ValueError: If `margin` is not in range [-1.0, 1.0].
|
|
4530
4787
|
|
|
4531
4788
|
Supported Platforms:
|
|
4532
4789
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -4546,7 +4803,7 @@ def cosine_embedding_loss(input1, input2, target, margin=0.0, reduction="mean"):
|
|
|
4546
4803
|
_check_is_tensor('input1', input1, "ops.cosine_embedding_loss")
|
|
4547
4804
|
_check_is_tensor('input2', input2, "ops.cosine_embedding_loss")
|
|
4548
4805
|
_check_is_tensor('target', target, "ops.cosine_embedding_loss")
|
|
4549
|
-
|
|
4806
|
+
check_input_dtype('input1', input1, 'input2', input2, 'ops.cosine_embedding_loss')
|
|
4550
4807
|
_check_reduced_shape_valid(ops.shape(input1), ops.shape(target), (1,),
|
|
4551
4808
|
"ops.cosine_embedding_loss", "input1", "target")
|
|
4552
4809
|
if input1.dtype in (mstype.int32, mstype.int64):
|
|
@@ -4560,14 +4817,14 @@ def cosine_embedding_loss(input1, input2, target, margin=0.0, reduction="mean"):
|
|
|
4560
4817
|
if margin_f > 1.0 or margin_f < -1.0:
|
|
4561
4818
|
raise ValueError(f"For ops.cosine_embedding_loss, the value of 'margin' should be in [-1, 1],"
|
|
4562
4819
|
f"but got {margin_f}.")
|
|
4563
|
-
prod_sum =
|
|
4564
|
-
square1 =
|
|
4565
|
-
square2 =
|
|
4820
|
+
prod_sum = reduce_sum_(input1 * input2, (1,))
|
|
4821
|
+
square1 = reduce_sum_(ops.square(input1), (1,))
|
|
4822
|
+
square2 = reduce_sum_(ops.square(input2), (1,))
|
|
4566
4823
|
denom = ops.sqrt(square1) * ops.sqrt(square2)
|
|
4567
4824
|
cosine = prod_sum / denom
|
|
4568
4825
|
|
|
4569
4826
|
pos_value = 1.0 - cosine
|
|
4570
|
-
neg_value =
|
|
4827
|
+
neg_value = maximum_(cosine - margin_f, 0.0)
|
|
4571
4828
|
zeros = ops.zeros_like(cosine)
|
|
4572
4829
|
pos_part = ops.select(target == 1, pos_value, zeros)
|
|
4573
4830
|
neg_part = ops.select(target == -1, neg_value, zeros)
|
|
@@ -4624,7 +4881,7 @@ def max_pool3d(x, kernel_size, stride=None, padding=0, dilation=1, ceil_mode=Fal
|
|
|
4624
4881
|
W_{out} = \left\lfloor\frac{W_{in} + 2 \times \text{padding}[2] - \text{dilation}[2] \times
|
|
4625
4882
|
(\text{kernel_size}[2] - 1) - 1}{\text{stride}[2]} + 1\right\rfloor
|
|
4626
4883
|
|
|
4627
|
-
- **argmax** (Tensor) - Index corresponding to the maximum value. Data type is int64. It will be
|
|
4884
|
+
- **argmax** (Tensor) - Index corresponding to the maximum value. Data type is int64. It will be returned
|
|
4628
4885
|
only when `return_indices` is ``True`` .
|
|
4629
4886
|
|
|
4630
4887
|
Raises:
|
|
@@ -4702,9 +4959,9 @@ def grid_sample(input, grid, mode='bilinear', padding_mode='zeros', align_corner
|
|
|
4702
4959
|
|
|
4703
4960
|
padding_mode (str): An optional string specifying the pad method. The optional values are "zeros", "border" or
|
|
4704
4961
|
"reflection". Default: ``'zeros'`` .
|
|
4705
|
-
align_corners (bool):
|
|
4706
|
-
the center points of the input
|
|
4707
|
-
to the corner points of the input
|
|
4962
|
+
align_corners (bool): If set to `True`, the extrema (-1 and 1) are considered as referring to
|
|
4963
|
+
the center points of the input's corner pixels. If set to `False`, they are instead considered as referring
|
|
4964
|
+
to the corner points of the input's corner pixels, making the sampling more resolution agnostic. Default:
|
|
4708
4965
|
``False`` .
|
|
4709
4966
|
|
|
4710
4967
|
Returns:
|
|
@@ -4777,8 +5034,8 @@ def ctc_loss(log_probs, targets, input_lengths, target_lengths, blank=0, reducti
|
|
|
4777
5034
|
log_probs (Tensor): A tensor of shape :math:`(T, N, C)`, where T is input length, N is batch size and C is
|
|
4778
5035
|
number of classes (including blank).
|
|
4779
5036
|
targets (Tensor): Target sequences. A tensor of shape :math:`(N, S)`, where S is max target length.
|
|
4780
|
-
input_lengths (Union(tuple, Tensor)): Lengths of the input. A tuple or Tensor of shape(N)
|
|
4781
|
-
target_lengths (Union(tuple, Tensor)): Lengths of the target. A tuple or Tensor of shape(N)
|
|
5037
|
+
input_lengths (Union(tuple, Tensor)): Lengths of the input. A tuple or Tensor of shape :math:`(N)`.
|
|
5038
|
+
target_lengths (Union(tuple, Tensor)): Lengths of the target. A tuple or Tensor of shape :math:`(N)`.
|
|
4782
5039
|
blank (int, optional): The blank label. Default: ``0`` .
|
|
4783
5040
|
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
4784
5041
|
``'sum'`` . Default: ``'mean'`` .
|
|
@@ -4925,30 +5182,17 @@ def gaussian_nll_loss(x, target, var, full=False, eps=1e-6, reduction='mean'):
|
|
|
4925
5182
|
if not x.shape == var.shape:
|
|
4926
5183
|
if x.shape[:-1] == var.shape:
|
|
4927
5184
|
var = var.unsqueeze(dim=-1)
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
raise ValueError(f"For 'gaussian_nll_loss', 'var' must be able to correctly broadcast to 'x' and 'target'.")
|
|
4933
|
-
max_op = P.Maximum()
|
|
4934
|
-
log_op = P.Log()
|
|
4935
|
-
square_op = P.Square()
|
|
4936
|
-
maxima = max_op(var, eps)
|
|
4937
|
-
logarithm = log_op(maxima)
|
|
4938
|
-
squared_loss = square_op(x - target)
|
|
5185
|
+
|
|
5186
|
+
maxima = maximum_(var, eps)
|
|
5187
|
+
logarithm = log_(maxima)
|
|
5188
|
+
squared_loss = square_(x - target)
|
|
4939
5189
|
c = 0 if not full else 0.5 * log(2 * pi)
|
|
4940
5190
|
loss = 0.5 * (logarithm + squared_loss / maxima) + c
|
|
4941
5191
|
if reduction == 'mean':
|
|
4942
5192
|
loss = loss.mean()
|
|
4943
5193
|
elif reduction == 'sum':
|
|
4944
5194
|
loss = loss.sum()
|
|
4945
|
-
return loss
|
|
4946
|
-
|
|
4947
|
-
|
|
4948
|
-
@_primexpr
|
|
4949
|
-
def _check_hinge_embedding_loss(shape, shape2):
|
|
4950
|
-
if shape2 != shape:
|
|
4951
|
-
raise ValueError(f"For 'HingeEmbeddingLoss' the input tensor and the labels must have the same shape.")
|
|
5195
|
+
return loss
|
|
4952
5196
|
|
|
4953
5197
|
|
|
4954
5198
|
@_primexpr
|
|
@@ -4998,7 +5242,7 @@ def hinge_embedding_loss(inputs, targets, margin=1.0, reduction='mean'):
|
|
|
4998
5242
|
inputs (Tensor): Predicted values, represented as :math:`x` in the formula.
|
|
4999
5243
|
targets (Tensor): Label values, represented as :math:`y` in the formula.
|
|
5000
5244
|
Has the same shape as `inputs`, contains -1 or 1.
|
|
5001
|
-
margin (float, int): Threshold defined by Hinge Embedding Loss
|
|
5245
|
+
margin (float, int): Threshold defined by Hinge Embedding Loss `margin`.
|
|
5002
5246
|
Represented as :math:`\Delta` in the formula. Default: ``1.0`` .
|
|
5003
5247
|
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
5004
5248
|
``'sum'`` . Default: ``'mean'`` .
|
|
@@ -5008,7 +5252,7 @@ def hinge_embedding_loss(inputs, targets, margin=1.0, reduction='mean'):
|
|
|
5008
5252
|
- ``'sum'``: the output elements will be summed.
|
|
5009
5253
|
|
|
5010
5254
|
Returns:
|
|
5011
|
-
Tensor or Tensor scalar, the computed loss depending on
|
|
5255
|
+
Tensor or Tensor scalar, the computed loss depending on `reduction`.
|
|
5012
5256
|
|
|
5013
5257
|
Raises:
|
|
5014
5258
|
TypeError: If `inputs` is not a Tensor.
|
|
@@ -5023,7 +5267,7 @@ def hinge_embedding_loss(inputs, targets, margin=1.0, reduction='mean'):
|
|
|
5023
5267
|
Examples:
|
|
5024
5268
|
>>> import numpy as np
|
|
5025
5269
|
>>> import mindspore.common.dtype as mstype
|
|
5026
|
-
>>>
|
|
5270
|
+
>>> from mindspore import ops
|
|
5027
5271
|
>>> from mindspore import Tensor
|
|
5028
5272
|
>>> arr1 = np.array([0.9, -1.2, 2, 0.8, 3.9, 2, 1, 0, -1]).reshape((3, 3))
|
|
5029
5273
|
>>> arr2 = np.array([1, 1, -1, 1, -1, 1, -1, 1, 1]).reshape((3, 3))
|
|
@@ -5036,9 +5280,6 @@ def hinge_embedding_loss(inputs, targets, margin=1.0, reduction='mean'):
|
|
|
5036
5280
|
inputs_dtype = inputs.dtype
|
|
5037
5281
|
targets_dtype = targets.dtype
|
|
5038
5282
|
_check_hinge_embedding_loss_type(inputs_dtype, targets_dtype, inputs, targets, margin, reduction)
|
|
5039
|
-
_shape = inputs.shape
|
|
5040
|
-
_t_shape = targets.shape
|
|
5041
|
-
_check_hinge_embedding_loss(_shape, _t_shape)
|
|
5042
5283
|
|
|
5043
5284
|
min_val = Tensor(0, inputs_dtype)
|
|
5044
5285
|
pos_index = targets > 0
|
|
@@ -5259,21 +5500,25 @@ def conv1d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5259
5500
|
, :math:`weight` is the convolution kernel value and :math:`X` represents the input feature map.
|
|
5260
5501
|
|
|
5261
5502
|
Here are the indices' meanings:
|
|
5262
|
-
- :math:`i` corresponds to the batch number, ranging from 0 to N-1, where N is the batch size of the input.
|
|
5263
5503
|
|
|
5264
|
-
- :math:`
|
|
5504
|
+
- :math:`i` corresponds to the batch number, the range is :math:`[0, N-1]`,
|
|
5505
|
+
where :math:`N` is the batch size of the input.
|
|
5506
|
+
|
|
5507
|
+
- :math:`j` corresponds to the output channel, ranging from :math:`[0, C_{out}-1]`,
|
|
5508
|
+
where :math:`C_{out}` is the number of
|
|
5265
5509
|
output channels, which is also equal to the number of kernels.
|
|
5266
5510
|
|
|
5267
|
-
- :math:`k` corresponds to the input channel, ranging from 0
|
|
5511
|
+
- :math:`k` corresponds to the input channel, ranging from :math:`[0, C_{in}-1]`,
|
|
5512
|
+
where :math:`C_{in}` is the number of
|
|
5268
5513
|
input channels, which is also equal to the number of channels in the convolutional kernels.
|
|
5269
5514
|
|
|
5270
|
-
Therefore, in the above formula, :math:`{bias}(C_{
|
|
5271
|
-
output channel, :math:`{weight}(C_{
|
|
5515
|
+
Therefore, in the above formula, :math:`{bias}(C_{\text{out}_j})` represents the bias of the :math:`j`-th
|
|
5516
|
+
output channel, :math:`{weight}(C_{\text{out}_j}, k)` represents the slice of the :math:`j`-th convolutional
|
|
5272
5517
|
kernel in the :math:`k`-th channel, and :math:`{X}(N_i, k)` represents the slice of the :math:`k`-th input
|
|
5273
5518
|
channel in the :math:`i`-th batch of the input feature map.
|
|
5274
5519
|
|
|
5275
|
-
The shape of the convolutional kernel is given by :math:`(
|
|
5276
|
-
where :math
|
|
5520
|
+
The shape of the convolutional kernel is given by :math:`(\text{kernel_size})`,
|
|
5521
|
+
where :math:`\text{kernel_size}` is the width of the kernel.
|
|
5277
5522
|
If we consider the input and output channels as well as the `group` parameter, the complete kernel shape
|
|
5278
5523
|
will be :math:`(C_{out}, C_{in} / \text{group}, \text{kernel_size})`,
|
|
5279
5524
|
where `group` is the number of groups dividing `x`'s input channel when applying group convolution.
|
|
@@ -5284,7 +5529,7 @@ def conv1d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5284
5529
|
|
|
5285
5530
|
Note:
|
|
5286
5531
|
On Ascend platform, only group convolution in depthwise convolution scenarios is supported.
|
|
5287
|
-
That is, when `groups>1`, condition
|
|
5532
|
+
That is, when `groups>1`, condition :math:`C_{in}` = :math:`C_{out}` = `groups` must be satisfied.
|
|
5288
5533
|
|
|
5289
5534
|
Args:
|
|
5290
5535
|
input (Tensor): Input Tensor of shape :math:`(N, C_{in}, L_{in})`.
|
|
@@ -5353,13 +5598,12 @@ def conv1d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5353
5598
|
raise ValueError(f"For 'conv1d', the input must be a 3D Tensor, but got input of {input.ndim}D.")
|
|
5354
5599
|
if weight.ndim != 3:
|
|
5355
5600
|
raise ValueError(f"For 'conv1d', the weight must be a 3D Tensor, but got input of {weight.ndim}D.")
|
|
5356
|
-
|
|
5357
|
-
expanded_input = _expand(input, 2)
|
|
5601
|
+
expanded_input = expand_dims_(input, 2)
|
|
5358
5602
|
sqz = _get_cache_prim(P.Squeeze)(2)
|
|
5359
5603
|
weight_shape = weight.shape
|
|
5360
5604
|
out_channel = weight_shape[0]
|
|
5361
5605
|
kernel_size = (1, weight_shape[2])
|
|
5362
|
-
expanded_weight =
|
|
5606
|
+
expanded_weight = expand_dims_(weight, 2)
|
|
5363
5607
|
if isinstance(padding, int):
|
|
5364
5608
|
padding = (0, 0, padding, padding)
|
|
5365
5609
|
elif isinstance(padding, (tuple, list)):
|
|
@@ -5408,12 +5652,15 @@ def conv2d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5408
5652
|
, :math:`weight` is the convolution kernel value and :math:`X` represents the input feature map.
|
|
5409
5653
|
|
|
5410
5654
|
Here are the indices' meanings:
|
|
5411
|
-
- :math:`i` corresponds to the batch number, ranging from 0 to N-1, where N is the batch size of the input.
|
|
5412
5655
|
|
|
5413
|
-
- :math:`
|
|
5414
|
-
|
|
5656
|
+
- :math:`i` corresponds to the batch number, the range is :math:`[0, N-1]`,
|
|
5657
|
+
where :math:`N` is the batch size of the input.
|
|
5658
|
+
|
|
5659
|
+
- :math:`j` corresponds to the output channel, the range is :math:`[0, C_{out}-1]`,
|
|
5660
|
+
where :math:`C_{out}` is the number of output channels, which is also equal to the number of kernels.
|
|
5415
5661
|
|
|
5416
|
-
- :math:`k` corresponds to the input channel,
|
|
5662
|
+
- :math:`k` corresponds to the input channel, the range is :math:`[0, C_{in}-1]`,
|
|
5663
|
+
where :math:`C_{in}` is the number of
|
|
5417
5664
|
input channels, which is also equal to the number of channels in the convolutional kernels.
|
|
5418
5665
|
|
|
5419
5666
|
Therefore, in the above formula, :math:`{bias}(C_{out_j})` represents the bias of the :math:`j`-th
|
|
@@ -5421,8 +5668,9 @@ def conv2d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5421
5668
|
kernel in the :math:`k`-th channel, and :math:`{X}(N_i, k)` represents the slice of the :math:`k`-th input
|
|
5422
5669
|
channel in the :math:`i`-th batch of the input feature map.
|
|
5423
5670
|
|
|
5424
|
-
The shape of the convolutional kernel is given by :math:`(
|
|
5425
|
-
where :math
|
|
5671
|
+
The shape of the convolutional kernel is given by :math:`(\text{kernel_size[0]}, \text{kernel_size[1]})`,
|
|
5672
|
+
where :math:`\text{kernel_size[0]}` and :math:`\text{kernel_size[1]}` are the height and width of the kernel,
|
|
5673
|
+
respectively.
|
|
5426
5674
|
If we consider the input and output channels as well as the `group` parameter, the complete kernel shape
|
|
5427
5675
|
will be :math:`(C_{out}, C_{in} / \text{group}, \text{kernel_size[0]}, \text{kernel_size[1]})`,
|
|
5428
5676
|
where `group` is the number of groups dividing `x`'s input channel when applying group convolution.
|
|
@@ -5433,7 +5681,7 @@ def conv2d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5433
5681
|
|
|
5434
5682
|
Note:
|
|
5435
5683
|
On Ascend platform, only group convolution in depthwise convolution scenarios is supported.
|
|
5436
|
-
That is, when `groups>1`, condition
|
|
5684
|
+
That is, when `groups>1`, condition :math:`C_{in}` = :math:`C_{out}` = `groups` must be satisfied.
|
|
5437
5685
|
|
|
5438
5686
|
Args:
|
|
5439
5687
|
input (Tensor): Tensor of shape :math:`(N, C_{in}, H_{in}, W_{in})`.
|
|
@@ -5478,7 +5726,7 @@ def conv2d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5478
5726
|
TypeError: If `stride`, `padding` or `dilation` is neither an int nor a tuple.
|
|
5479
5727
|
TypeError: `groups` is not an int.
|
|
5480
5728
|
TypeError: If `bias` is not a Tensor.
|
|
5481
|
-
ValueError: If the shape of `bias` is not :math:`C_{out}` .
|
|
5729
|
+
ValueError: If the shape of `bias` is not :math:`(C_{out})` .
|
|
5482
5730
|
ValueError: If `stride` or `dilation` is less than 1.
|
|
5483
5731
|
ValueError: If `pad_mode` is not one of 'same', 'valid' or 'pad'.
|
|
5484
5732
|
ValueError: If `padding` is a tuple/list whose length is not equal to 2.
|
|
@@ -5525,6 +5773,75 @@ def conv2d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5525
5773
|
return output
|
|
5526
5774
|
|
|
5527
5775
|
|
|
5776
|
+
def conv_transpose2d(input, weight, bias=None, stride=1, padding=0, output_padding=0, groups=1, dilation=1):
|
|
5777
|
+
r"""
|
|
5778
|
+
Calculates a 2D transposed convolution, which can be regarded as Conv2d for the gradient of the input,
|
|
5779
|
+
also called deconvolution (although it is not an actual deconvolution).
|
|
5780
|
+
|
|
5781
|
+
The input is typically of shape :math:`(N, C_{in}, H_{in}, W_{in})`,
|
|
5782
|
+
where :math:`N` is batch size, :math:`C_{in}` is space dimension,
|
|
5783
|
+
:math:`H_{in}, W_{in}` are the height and width of the feature layer respectively.
|
|
5784
|
+
|
|
5785
|
+
When Conv2d and Conv2dTranspose are initialized with the same parameters, and `pad_mode` is set to 'pad',
|
|
5786
|
+
:math:`dilation * (kernel\_size - 1) - padding` amount of zero will be paded to the height and width
|
|
5787
|
+
directions of the input, they are inverses of each other in regard to the input and output shapes in this case.
|
|
5788
|
+
However, when `stride` > 1, Conv2d maps multiple input shapes to the same output shape. Deconvolutional network
|
|
5789
|
+
can refer to `Deconvolutional Networks <https://www.matthewzeiler.com/mattzeiler/deconvolutionalnetworks.pdf>`_.
|
|
5790
|
+
|
|
5791
|
+
Args:
|
|
5792
|
+
input (Tensor): Tensor of shape :math:`(N, C_{in}, H_{in}, W_{in})`.
|
|
5793
|
+
weight (Tensor): Tensor of shape
|
|
5794
|
+
:math:`(N, C_{in} / \text{groups}, \text{kernel_size[0]}, \text{kernel_size[1]})`, then the size of kernel
|
|
5795
|
+
is :math:`(\text{kernel_size[0]}, \text{kernel_size[1]})`.
|
|
5796
|
+
bias (Tensor, optional): Bias Tensor with shape :math:`(C_{out})`.
|
|
5797
|
+
When bias is ``None`` , zeros will be used. Default: ``None`` .
|
|
5798
|
+
stride (Union(int, tuple[int]), optional): The distance of kernel moving, an int number that represents
|
|
5799
|
+
the height and width of movement are both strides, or a tuple of two int numbers that
|
|
5800
|
+
represent height and width of movement respectively. Default: ``1`` .
|
|
5801
|
+
padding (Union(int, tuple[int], list[int]), optional): Implicit paddings on both sides of the input `x`.
|
|
5802
|
+
Can be an integer or a tuple/list with 2 integers.
|
|
5803
|
+
output_padding (Union[int, tuple[int]]): The number of padding on the height and width directions of the output.
|
|
5804
|
+
The data type is an integer or a tuple of two integers. If `output_padding` is an integer,
|
|
5805
|
+
then the bottom and right padding are all equal to `output_padding`. If `output_padding` is a tuple of
|
|
5806
|
+
2 integers, then the bottom and right padding is equal to `output_padding[0]`, `output_padding[1]`
|
|
5807
|
+
respectively.
|
|
5808
|
+
groups (int, optional): Splits `input` into groups. Default: ``1`` .
|
|
5809
|
+
dilation (Union(int, tuple[int]), optional): Gaps between kernel elements.The data type is int or a tuple of
|
|
5810
|
+
2 integers. Specifies the dilation rate to use for dilated convolution. If set to be :math:`k > 1`,
|
|
5811
|
+
there will be :math:`k - 1` pixels skipped for each sampling location. Its value must
|
|
5812
|
+
be greater than or equal to 1 and bounded by the height and width of the input `x`. Default: ``1`` .
|
|
5813
|
+
|
|
5814
|
+
Returns:
|
|
5815
|
+
Tensor, the value that applied 2D convolution. The shape is :math:`(N, C_{out}, H_{out}, W_{out})`.
|
|
5816
|
+
To see how different pad modes affect the output shape, please refer to
|
|
5817
|
+
:class:`mindspore.nn.Conv2dTranspose` for more details.
|
|
5818
|
+
|
|
5819
|
+
|
|
5820
|
+
Raises:
|
|
5821
|
+
TypeError: If `stride`, `padding` or `dilation` is neither an int nor a tuple.
|
|
5822
|
+
TypeError: `groups` is not an int.
|
|
5823
|
+
TypeError: If `bias` is not a Tensor.
|
|
5824
|
+
ValueError: If the shape of `bias` is not :math:`(C_{out})` .
|
|
5825
|
+
ValueError: If `stride` or `dilation` is less than 1.
|
|
5826
|
+
ValueError: If `padding` is a tuple/list whose length is not equal to 2.
|
|
5827
|
+
|
|
5828
|
+
Supported Platforms:
|
|
5829
|
+
``Ascend``
|
|
5830
|
+
|
|
5831
|
+
Examples:
|
|
5832
|
+
>>> import mindspore
|
|
5833
|
+
>>> import numpy as np
|
|
5834
|
+
>>> from mindspore import Tensor, ops
|
|
5835
|
+
>>> x = Tensor(np.ones([1, 6, 32, 32]), mindspore.float32)
|
|
5836
|
+
>>> weight = Tensor(np.ones([6, 3, 5, 5]), mindspore.float32)
|
|
5837
|
+
>>> output = ops.conv_transpose2d(x, weight)
|
|
5838
|
+
>>> print(output.shape)
|
|
5839
|
+
(1, 3, 36, 36)
|
|
5840
|
+
"""
|
|
5841
|
+
conv = _get_cache_prim(Convolution)(stride, padding, dilation, True, output_padding, groups)
|
|
5842
|
+
return conv(input, weight, bias)
|
|
5843
|
+
|
|
5844
|
+
|
|
5528
5845
|
def hardsigmoid(input):
|
|
5529
5846
|
r"""
|
|
5530
5847
|
Hard sigmoid activation function.
|
|
@@ -5539,6 +5856,11 @@ def hardsigmoid(input):
|
|
|
5539
5856
|
|
|
5540
5857
|
where :math:`x_i` is an element of the input Tensor.
|
|
5541
5858
|
|
|
5859
|
+
HSigmoid Activation Function Graph:
|
|
5860
|
+
|
|
5861
|
+
.. image:: ../images/HSigmoid.png
|
|
5862
|
+
:align: center
|
|
5863
|
+
|
|
5542
5864
|
Args:
|
|
5543
5865
|
input (Tensor): The input Tensor.
|
|
5544
5866
|
|
|
@@ -5578,10 +5900,15 @@ def hardtanh(input, min_val=-1.0, max_val=1.0):
|
|
|
5578
5900
|
|
|
5579
5901
|
Linear region range :math:`[min\_val, max\_val]` can be adjusted using `min_val` and `max_val`.
|
|
5580
5902
|
|
|
5903
|
+
Hardtanh Activation Function Graph:
|
|
5904
|
+
|
|
5905
|
+
.. image:: ../images/Hardtanh.png
|
|
5906
|
+
:align: center
|
|
5907
|
+
|
|
5581
5908
|
Args:
|
|
5582
5909
|
input (Tensor): Input Tensor.
|
|
5583
|
-
min_val (Union[int, float]): Minimum value of the linear region range. Default: ``-1.0`` .
|
|
5584
|
-
max_val (Union[int, float]): Maximum value of the linear region range. Default: ``1.0`` .
|
|
5910
|
+
min_val (Union[int, float], optional): Minimum value of the linear region range. Default: ``-1.0`` .
|
|
5911
|
+
max_val (Union[int, float], optional): Maximum value of the linear region range. Default: ``1.0`` .
|
|
5585
5912
|
|
|
5586
5913
|
Returns:
|
|
5587
5914
|
Tensor, with the same dtype and shape as `input`.
|
|
@@ -5606,18 +5933,18 @@ def hardtanh(input, min_val=-1.0, max_val=1.0):
|
|
|
5606
5933
|
_check_value_type("min_val", min_val, [int, float], "hardtanh")
|
|
5607
5934
|
_check_value_type("max_val", max_val, [int, float], "hardtanh")
|
|
5608
5935
|
input_dtype = input.dtype
|
|
5609
|
-
input =
|
|
5610
|
-
input =
|
|
5936
|
+
input = maximum_(input, min_val)
|
|
5937
|
+
input = minimum_(input, max_val)
|
|
5611
5938
|
return input.astype(input_dtype)
|
|
5612
5939
|
|
|
5613
5940
|
|
|
5614
5941
|
def huber_loss(input, target, reduction='mean', delta=1.0):
|
|
5615
5942
|
r"""
|
|
5616
5943
|
Calculates the error between the predicted value and the target value,
|
|
5617
|
-
which has the best of both the loss of
|
|
5944
|
+
which has the best of both the loss of :func:`mindspore.ops.l1_loss` and the loss of :func:`mindspore.ops.mse_loss`.
|
|
5618
5945
|
|
|
5619
5946
|
Assuming that the :math:`x` and :math:`y` are 1-D Tensor, length :math:`N`, the `reduction` parameter
|
|
5620
|
-
is set to ``
|
|
5947
|
+
is set to ``'none'`` then calculate the loss of :math:`x` and :math:`y` without dimensionality reduction.
|
|
5621
5948
|
The formula is as follows:
|
|
5622
5949
|
|
|
5623
5950
|
.. math::
|
|
@@ -5658,14 +5985,14 @@ def huber_loss(input, target, reduction='mean', delta=1.0):
|
|
|
5658
5985
|
The value must be greater than zero. Default: ``1.0`` .
|
|
5659
5986
|
|
|
5660
5987
|
Returns:
|
|
5661
|
-
Tensor or Scalar, if `reduction` is ``
|
|
5988
|
+
Tensor or Scalar, if `reduction` is ``'none'``, return a Tensor with same shape and dtype as `input`.
|
|
5662
5989
|
Otherwise, a scalar value will be returned.
|
|
5663
5990
|
|
|
5664
5991
|
Raises:
|
|
5665
5992
|
TypeError: If `input` or `target` is not a Tensor.
|
|
5666
5993
|
TypeError: If dtype of `delta` is neither float nor int.
|
|
5667
5994
|
ValueError: If `delta` is less than or equal to 0.
|
|
5668
|
-
ValueError: If `reduction` is not one of ``
|
|
5995
|
+
ValueError: If `reduction` is not one of ``'none'``, ``'mean'``, ``'sum'``.
|
|
5669
5996
|
ValueError: If `input` and `target` have different shapes and cannot be broadcasted to each other.
|
|
5670
5997
|
|
|
5671
5998
|
Supported Platforms:
|
|
@@ -5684,14 +6011,12 @@ def huber_loss(input, target, reduction='mean', delta=1.0):
|
|
|
5684
6011
|
_check_is_tensor('target', target, "huber_loss")
|
|
5685
6012
|
_check_value_type("delta", delta, [int, float], "huber_loss")
|
|
5686
6013
|
_check_number_gt_value("delta", delta, 0.0, "huber_loss")
|
|
5687
|
-
|
|
5688
|
-
|
|
5689
|
-
|
|
5690
|
-
|
|
5691
|
-
|
|
5692
|
-
|
|
5693
|
-
l2 = multi(delta, sub(z, 0.5 * delta))
|
|
5694
|
-
loss = _get_cache_prim(P.Select)()(cond, l1, l2)
|
|
6014
|
+
z = sub_(input, target)
|
|
6015
|
+
z = abs_(z)
|
|
6016
|
+
cond = less_(z, delta)
|
|
6017
|
+
l1 = mul_(0.5, square_(z))
|
|
6018
|
+
l2 = mul_(delta, sub_(z, 0.5 * delta))
|
|
6019
|
+
loss = select_(cond, l1, l2)
|
|
5695
6020
|
return _get_loss(loss, reduction, "huber_loss")
|
|
5696
6021
|
|
|
5697
6022
|
|
|
@@ -5743,7 +6068,7 @@ def adaptive_avg_pool1d(input, output_size):
|
|
|
5743
6068
|
"""
|
|
5744
6069
|
def _check(x, output_size):
|
|
5745
6070
|
x_in_shape = x.shape
|
|
5746
|
-
x_dtype =
|
|
6071
|
+
x_dtype = dtype_(x)
|
|
5747
6072
|
if not isinstance(x, (Tensor, Tensor_)):
|
|
5748
6073
|
raise TypeError("For adaptive_avg_pool1d, the input input must be tensor")
|
|
5749
6074
|
|
|
@@ -5763,24 +6088,203 @@ def adaptive_avg_pool1d(input, output_size):
|
|
|
5763
6088
|
|
|
5764
6089
|
_check(input, output_size)
|
|
5765
6090
|
x_in_shape = input.shape
|
|
5766
|
-
expand_ = _get_cache_prim(P.ExpandDims)()
|
|
5767
6091
|
squeeze_ = _get_cache_prim(P.Squeeze)(2)
|
|
5768
|
-
|
|
5769
6092
|
width = x_in_shape[2]
|
|
5770
6093
|
stride = width // output_size
|
|
5771
6094
|
kernel_size = width - (output_size - 1) * stride
|
|
5772
6095
|
stride = (1, width // output_size)
|
|
5773
6096
|
kernel_size = (1, kernel_size)
|
|
5774
|
-
|
|
5775
6097
|
avg_pool_ = _get_cache_prim(P.AvgPool)(kernel_size=kernel_size, strides=stride)
|
|
5776
|
-
|
|
5777
|
-
input = expand_(input, 2)
|
|
6098
|
+
input = expand_dims_(input, 2)
|
|
5778
6099
|
input = avg_pool_(input)
|
|
5779
6100
|
input = squeeze_(input)
|
|
5780
|
-
|
|
5781
6101
|
return input
|
|
5782
6102
|
|
|
5783
6103
|
|
|
6104
|
+
def layer_norm(input, normalized_shape, weight=None, bias=None, eps=1e-5):
|
|
6105
|
+
r"""Applies the Layer Normalization on the mini-batch input.
|
|
6106
|
+
|
|
6107
|
+
Layer normalization is widely used in recurrent neural networks. Apply normalization to the mini-batch
|
|
6108
|
+
input of a single training case. LayerNorm is described in the paper
|
|
6109
|
+
`Layer Normalization <https://arxiv.org/abs/1607.06450>`_.
|
|
6110
|
+
|
|
6111
|
+
Unlike batch normalization, layer normalization performs the exact same calculations at training and
|
|
6112
|
+
test time. Applies to all channels and pixels, even batch_size=1. The formula is as follows:
|
|
6113
|
+
|
|
6114
|
+
.. math::
|
|
6115
|
+
y = \frac{x - \mathrm{E}[x]}{\sqrt{\mathrm{Var}[x] + \epsilon}} * \gamma + \beta
|
|
6116
|
+
|
|
6117
|
+
where :math:`\gamma` is the weight value learned through training, :math:`\beta` is the bias value
|
|
6118
|
+
learned through training.
|
|
6119
|
+
|
|
6120
|
+
Args:
|
|
6121
|
+
input (Tensor): The shape of input is `(N, *)`, where `*` represents any additional dimension.
|
|
6122
|
+
normalized_shape (Union(int, tuple[int], list[int])): The normalized shape of `input` for LayerNorm.
|
|
6123
|
+
`normalized_shape` equal to `input_shape[begin_norm_axis:]`, where `begin_norm_axis` represents the axis
|
|
6124
|
+
where normalization begins.
|
|
6125
|
+
weight (Tensor, optional): Learnable parameter :math:`\gamma` . Tensor of shape `normalized_shape`.
|
|
6126
|
+
Default: ``None``, has the same data type with `input`. Initialized to ``1`` when `weight` is None.
|
|
6127
|
+
bias (Tensor, optional): Learnable parameter :math:`\beta` . Tensor of shape `normalized_shape`.
|
|
6128
|
+
Default: ``None``, has the same data type with `input`. Initialized to ``0`` when `bias` is None.
|
|
6129
|
+
eps (float, optional): A value added to the denominator for numerical stability(:math:`\epsilon`).
|
|
6130
|
+
Default: ``1e-5`` .
|
|
6131
|
+
|
|
6132
|
+
Returns:
|
|
6133
|
+
Tensor. The normalized tensor, has the same type and shape as the `input`.
|
|
6134
|
+
|
|
6135
|
+
Raises:
|
|
6136
|
+
TypeError: If `input` is not a Tensor.
|
|
6137
|
+
TypeError: If `normalized_shape` is not an integer, a list or a tuple.
|
|
6138
|
+
TypeError: If `eps` is not a float.
|
|
6139
|
+
|
|
6140
|
+
Supported Platforms:
|
|
6141
|
+
``Ascend``
|
|
6142
|
+
|
|
6143
|
+
Examples:
|
|
6144
|
+
>>> import mindspore
|
|
6145
|
+
>>> import numpy as np
|
|
6146
|
+
>>> from mindspore import Tensor, ops
|
|
6147
|
+
>>> input_x = Tensor(np.array([[1, 2, 3], [1, 2, 3]]), mindspore.float32)
|
|
6148
|
+
>>> normalized_shape = (3,)
|
|
6149
|
+
>>> gamma = Tensor(np.ones(normalized_shape), mindspore.float32)
|
|
6150
|
+
>>> beta = Tensor(np.zeros(normalized_shape), mindspore.float32)
|
|
6151
|
+
>>> eps = 1e-7
|
|
6152
|
+
>>> output = ops.layer_norm(input_x, normalized_shape, gamma, beta, eps)
|
|
6153
|
+
>>> print(output)
|
|
6154
|
+
[[-1.2247448 0. 1.2247448]
|
|
6155
|
+
[-1.2247448 0. 1.2247448]]
|
|
6156
|
+
"""
|
|
6157
|
+
if weight is None:
|
|
6158
|
+
weight = ops.ones(normalized_shape, dtype=input.dtype)
|
|
6159
|
+
if bias is None:
|
|
6160
|
+
bias = ops.zeros(normalized_shape, dtype=input.dtype)
|
|
6161
|
+
return layer_norm_ext_op(input, normalized_shape, weight, bias, eps)[0]
|
|
6162
|
+
|
|
6163
|
+
|
|
6164
|
+
def group_norm(input, num_groups, weight=None, bias=None, eps=1e-5):
|
|
6165
|
+
r"""Group Normalization over a mini-batch of inputs.
|
|
6166
|
+
|
|
6167
|
+
Group Normalization is widely used in recurrent neural networks. It applies
|
|
6168
|
+
normalization on a mini-batch of inputs for each single training case as described
|
|
6169
|
+
in the paper `Group Normalization <https://arxiv.org/pdf/1803.08494.pdf>`_. Group Normalization
|
|
6170
|
+
divides the channels into groups and computes within each group the mean and variance for normalization,
|
|
6171
|
+
and it performs very stable over a wide range of batch size. :math:`\gamma` and :math:`\beta` are trainable scale
|
|
6172
|
+
and shift.
|
|
6173
|
+
It can be described using the following formula:
|
|
6174
|
+
|
|
6175
|
+
.. math::
|
|
6176
|
+
y = \frac{x - \mathrm{E}[x]}{\sqrt{\mathrm{Var}[x] + \epsilon}} * \gamma + \beta
|
|
6177
|
+
|
|
6178
|
+
where :math:`\gamma` is `weight`, :math:`\beta` is `bias`, :math:`\epsilon` is `eps`.
|
|
6179
|
+
|
|
6180
|
+
Args:
|
|
6181
|
+
input (Tensor): The input feature with shape :math:`(N, C, *)` where :math:`*` means, any number of
|
|
6182
|
+
additional dimensions.
|
|
6183
|
+
num_groups (int): The number of groups to be divided along the channel dimension.
|
|
6184
|
+
weight (Tensor, optional): The shape :math:`(C,)`, Default: ``None``, has the same data type with `input`.
|
|
6185
|
+
bias (Tensor, optional): The shape :math:`(C,)`, Default: ``None``, has the same data type with `input`.
|
|
6186
|
+
eps (float, optional): A value added to the denominator for numerical stability. Default: ``1e-5`` .
|
|
6187
|
+
|
|
6188
|
+
Returns:
|
|
6189
|
+
Tensor, the normalized and scaled offset tensor, has the same shape and data type as the `input`.
|
|
6190
|
+
|
|
6191
|
+
Raises:
|
|
6192
|
+
TypeError: If `num_groups` is not an int.
|
|
6193
|
+
TypeError: If `eps` is not a float.
|
|
6194
|
+
ValueError: If `num_groups` is less than 1.
|
|
6195
|
+
ValueError: If `C` (the second parameter of dimensions of `input`) is not divided by `num_groups`.
|
|
6196
|
+
|
|
6197
|
+
Supported Platforms:
|
|
6198
|
+
``Ascend`` ``GPU`` ``CPU``
|
|
6199
|
+
|
|
6200
|
+
Examples:
|
|
6201
|
+
>>> import mindspore as ms
|
|
6202
|
+
>>> import numpy as np
|
|
6203
|
+
>>> from mindspore import ops
|
|
6204
|
+
>>> x = ms.Tensor(np.ones([1, 2, 4, 4], np.float32))
|
|
6205
|
+
>>> output = ops.group_norm(x, 2)
|
|
6206
|
+
>>> print(output)
|
|
6207
|
+
[[[[0. 0. 0. 0.]
|
|
6208
|
+
[0. 0. 0. 0.]
|
|
6209
|
+
[0. 0. 0. 0.]
|
|
6210
|
+
[0. 0. 0. 0.]]
|
|
6211
|
+
[[0. 0. 0. 0.]
|
|
6212
|
+
[0. 0. 0. 0.]
|
|
6213
|
+
[0. 0. 0. 0.]
|
|
6214
|
+
[0. 0. 0. 0.]]]]
|
|
6215
|
+
"""
|
|
6216
|
+
if weight is None:
|
|
6217
|
+
weight = ops.ones([input.shape[1]], dtype=input.dtype)
|
|
6218
|
+
if bias is None:
|
|
6219
|
+
bias = ops.zeros([input.shape[1]], dtype=input.dtype)
|
|
6220
|
+
return group_norm_op(input, num_groups, weight, bias, eps)[0]
|
|
6221
|
+
|
|
6222
|
+
|
|
6223
|
+
def batch_norm_ext(input, running_mean, running_var, weight=None, bias=None, training=False, momentum=0.1, eps=1e-5):
|
|
6224
|
+
r"""
|
|
6225
|
+
Batch Normalization for input data and updated parameters.
|
|
6226
|
+
|
|
6227
|
+
Batch Normalization is widely used in convolutional neural networks. This operation
|
|
6228
|
+
applies Batch Normalization over inputs to avoid internal covariate shift as described
|
|
6229
|
+
in the paper `Batch Normalization: Accelerating Deep Network Training by Reducing Internal
|
|
6230
|
+
Covariate Shift <https://arxiv.org/abs/1502.03167>`_. It rescales and recenters the
|
|
6231
|
+
features using a mini-batch of data and the learned parameters can be described
|
|
6232
|
+
in the following formula,
|
|
6233
|
+
|
|
6234
|
+
.. math::
|
|
6235
|
+
|
|
6236
|
+
y = \frac{x - mean}{\sqrt{variance + \epsilon}} * \gamma + \beta
|
|
6237
|
+
|
|
6238
|
+
where :math:`\gamma` is `weight`, :math:`\beta` is `bias`, :math:`\epsilon` is `eps`, :math:`mean` is the
|
|
6239
|
+
mean of :math:`x`, :math:`variance` is the variance of :math:`x`.
|
|
6240
|
+
|
|
6241
|
+
Args:
|
|
6242
|
+
input (Tensor): Tensor of shape :math:`(N, C, *)`, with bfloat16, float16 or float32 data type.
|
|
6243
|
+
For Atlas training products, the shape must be 2-4 dimensions currently.
|
|
6244
|
+
running_mean (Tensor): The shape :math:`(C,)`, with bfloat, float16 or float32 data type.
|
|
6245
|
+
running_var (Tensor): The shape :math:`(C,)`, with bfloat, float16 or float32 data type.
|
|
6246
|
+
weight (Tensor, optional): The shape :math:`(C,)`, with bfloat, float16 or float32 data type, Default: ``None``.
|
|
6247
|
+
Initialized to ``1`` when `weight` is None.
|
|
6248
|
+
bias (Tensor, optional): The shape :math:`(C,)`, with bfloat, float16 or float32 data type. Default: ``None``.
|
|
6249
|
+
Initialized to ``0`` when `weight` is None.
|
|
6250
|
+
training (bool, optional): If `training` is `True`, `mean` and `variance` are computed during training.
|
|
6251
|
+
If `training` is `False`, they're loaded from checkpoint during inference. Default: ``False`` .
|
|
6252
|
+
momentum (float, optional): The hyper parameter to compute moving average for `running_mean` and `running_var`
|
|
6253
|
+
(e.g. :math:`new\_running\_mean = (1 - momentum) * running\_mean + momentum * current\_mean`).
|
|
6254
|
+
Default: ``0.1`` .
|
|
6255
|
+
eps (float, optional): A small value added for numerical stability. Default: ``1e-5``.
|
|
6256
|
+
|
|
6257
|
+
Returns:
|
|
6258
|
+
Tensor, has the same type and shape as `input`. The shape is :math:`(N, C, *)`.
|
|
6259
|
+
|
|
6260
|
+
Raises:
|
|
6261
|
+
TypeError: If `training` is not a bool.
|
|
6262
|
+
TypeError: If dtype of `eps` or `momentum` is not float.
|
|
6263
|
+
TypeError: If `input`, `weight`, `bias`, `running_mean` or `running_var` is not a Tensor.
|
|
6264
|
+
|
|
6265
|
+
Supported Platforms:
|
|
6266
|
+
``Ascend``
|
|
6267
|
+
|
|
6268
|
+
Examples:
|
|
6269
|
+
>>> import mindspore
|
|
6270
|
+
>>> from mindspore import Tensor, ops
|
|
6271
|
+
>>> input_x = Tensor([[1.0, 2.0], [3.0, 4.0]], mindspore.float32)
|
|
6272
|
+
>>> running_mean = Tensor([0.5, 1.5], mindspore.float32)
|
|
6273
|
+
>>> running_var = Tensor([0.1, 0.2], mindspore.float32)
|
|
6274
|
+
>>> weight = Tensor([2.0, 2.0], mindspore.float32)
|
|
6275
|
+
>>> bias = Tensor([-1.0, -1.0], mindspore.float32)
|
|
6276
|
+
>>> output = ops.function.nn_func.batch_norm_ext(input_x, running_mean, running_var, weight, bias)
|
|
6277
|
+
>>> print(output)
|
|
6278
|
+
[[ 2.1621194 1.2360122]
|
|
6279
|
+
[14.810596 10.180061 ]]
|
|
6280
|
+
"""
|
|
6281
|
+
if weight is None:
|
|
6282
|
+
weight = ops.ones([input.shape[1]], dtype=input.dtype)
|
|
6283
|
+
if bias is None:
|
|
6284
|
+
bias = ops.zeros([input.shape[1]], dtype=input.dtype)
|
|
6285
|
+
output = batch_norm_ext_op(input, weight, bias, running_mean, running_var, training, momentum, eps)
|
|
6286
|
+
return output[0]
|
|
6287
|
+
|
|
5784
6288
|
def batch_norm(input_x, running_mean, running_var, weight, bias, training=False, momentum=0.1, eps=1e-5):
|
|
5785
6289
|
r"""
|
|
5786
6290
|
Batch Normalization for input data and updated parameters.
|
|
@@ -5800,7 +6304,8 @@ def batch_norm(input_x, running_mean, running_var, weight, bias, training=False,
|
|
|
5800
6304
|
mean of :math:`x`, :math:`variance` is the variance of :math:`x`.
|
|
5801
6305
|
|
|
5802
6306
|
.. warning::
|
|
5803
|
-
- For
|
|
6307
|
+
- For Atlas 200/300/500 inference product,
|
|
6308
|
+
the result accuracy fails to reach 1‰ due to the square root instruction.
|
|
5804
6309
|
|
|
5805
6310
|
Note:
|
|
5806
6311
|
- If `training` is `False`, `weight`, `bias`, `running_mean` and `running_var` are Tensors.
|
|
@@ -5917,6 +6422,7 @@ def binary_cross_entropy(logits, labels, weight=None, reduction='mean'):
|
|
|
5917
6422
|
Args:
|
|
5918
6423
|
logits (Tensor): The predictive value whose data type must be float16 or float32.
|
|
5919
6424
|
labels (Tensor): The target value which has the same shape and data type as `logits`.
|
|
6425
|
+
And the data type is float16 or float32.
|
|
5920
6426
|
weight (Tensor, optional): A rescaling weight applied to the loss of each batch element.
|
|
5921
6427
|
Its shape must be able to broadcast to that of `logits` and `labels`.
|
|
5922
6428
|
And it must have the same shape and data type as `logits`. Default: ``None`` . If set to ``None`` ,
|
|
@@ -5962,7 +6468,7 @@ def conv3d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5962
6468
|
r"""
|
|
5963
6469
|
Applies a 3D convolution over an input tensor. The input tensor is typically of
|
|
5964
6470
|
shape :math:`(N, C_{in}, D_{in}, H_{in}, W_{in})`, where :math:`N` is batch size, :math:`C`
|
|
5965
|
-
is channel number, :math:`D`
|
|
6471
|
+
is channel number, :math:`D, H, W` are the depth, height and width of the feature graph, respectively.
|
|
5966
6472
|
|
|
5967
6473
|
The output is calculated based on formula:
|
|
5968
6474
|
|
|
@@ -5972,26 +6478,30 @@ def conv3d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5972
6478
|
\sum_{k = 0}^{C_{in} - 1} \text{ccor}({\text{weight}(C_{\text{out}_j}, k), \text{X}(N_i, k)})
|
|
5973
6479
|
|
|
5974
6480
|
where :math:`bias` is the output channel bias, :math:`ccor` is
|
|
5975
|
-
the `cross-correlation <https://en.wikipedia.org/wiki/Cross-correlation>`_
|
|
6481
|
+
the `cross-correlation <https://en.wikipedia.org/wiki/Cross-correlation>`_
|
|
5976
6482
|
, :math:`weight` is the convolution kernel value and :math:`X` represents the input feature map.
|
|
5977
6483
|
|
|
5978
6484
|
Here are the indices' meanings:
|
|
5979
|
-
- :math:`i` corresponds to the batch number, ranging from 0 to N-1, where N is the batch size of the input.
|
|
5980
6485
|
|
|
5981
|
-
- :math:`
|
|
6486
|
+
- :math:`i` corresponds to the batch number, the range is :math:`[0, N-1]`,
|
|
6487
|
+
where :math:`N` is the batch size of the input.
|
|
6488
|
+
|
|
6489
|
+
- :math:`j` corresponds to the output channel, the range is :math:`[0, C_{out}-1]`,
|
|
6490
|
+
where :math:`C_{out}` is the number of
|
|
5982
6491
|
output channels, which is also equal to the number of kernels.
|
|
5983
6492
|
|
|
5984
|
-
- :math:`k` corresponds to the input channel,
|
|
6493
|
+
- :math:`k` corresponds to the input channel, the range is :math:`[0, C_{in}-1]`,
|
|
6494
|
+
where :math:`C_{in}` is the number of
|
|
5985
6495
|
input channels, which is also equal to the number of channels in the convolutional kernels.
|
|
5986
6496
|
|
|
5987
|
-
Therefore, in the above formula, :math:`{bias}(C_{
|
|
5988
|
-
output channel, :math:`{weight}(C_{
|
|
6497
|
+
Therefore, in the above formula, :math:`{bias}(C_{\text{out}_j})` represents the bias of the :math:`j`-th
|
|
6498
|
+
output channel, :math:`{weight}(C_{\text{out}_j}, k)` represents the slice of the :math:`j`-th convolutional
|
|
5989
6499
|
kernel in the :math:`k`-th channel, and :math:`{X}(N_i, k)` represents the slice of the :math:`k`-th input
|
|
5990
6500
|
channel in the :math:`i`-th batch of the input feature map.
|
|
5991
6501
|
|
|
5992
6502
|
The shape of the convolutional kernel is given by
|
|
5993
6503
|
:math:`(\text{kernel_size[0]}, \text{kernel_size[1]}, \text{kernel_size[2]})`
|
|
5994
|
-
where :math
|
|
6504
|
+
where :math:`\text{kernel_size[0]}` , :math:`\text{kernel_size[1]}` and :math:`\text{kernel_size[2]}` are the depth,
|
|
5995
6505
|
height and width of the kernel, respectively.
|
|
5996
6506
|
If we consider the input and output channels as well as the `group` parameter, the complete kernel shape
|
|
5997
6507
|
will be :math:`(C_{out}, C_{in} / \text{group}, \text{kernel_size[0]},
|
|
@@ -6002,8 +6512,8 @@ def conv3d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
6002
6512
|
<http://vision.stanford.edu/cs598_spring07/papers/Lecun98.pdf>`_.
|
|
6003
6513
|
|
|
6004
6514
|
Note:
|
|
6005
|
-
1. On Ascend platform,
|
|
6006
|
-
2. On Ascend dilation
|
|
6515
|
+
1. On Ascend platform, :math:`groups = 1` must be satisfied.
|
|
6516
|
+
2. On Ascend platform, :math:`dilation=1` must be satisfied.
|
|
6007
6517
|
|
|
6008
6518
|
Args:
|
|
6009
6519
|
input (Tensor): Tensor of shape :math:`(N, C_{in}, D_{in}, H_{in}, W_{in})`.
|
|
@@ -6042,8 +6552,7 @@ def conv3d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
6042
6552
|
there will be :math:`k - 1` pixels skipped for each sampling location.
|
|
6043
6553
|
The value ranges for the depth, height, and width dimensions are [1, D], [1, H], and [1, W],
|
|
6044
6554
|
respectively. Default: ``1`` .
|
|
6045
|
-
groups (int, optional):The number of groups into which the filter is divided.
|
|
6046
|
-
and `out_channels` must be divisible by `group`. Default: ``1`` .
|
|
6555
|
+
groups (int, optional):The number of groups into which the filter is divided. Default: ``1`` .
|
|
6047
6556
|
|
|
6048
6557
|
Returns:
|
|
6049
6558
|
Tensor, the value that applied 3D convolution. The shape is :math:`(N, C_{out}, D_{out}, H_{out}, W_{out})`.
|
|
@@ -6085,7 +6594,7 @@ def conv3d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
6085
6594
|
TypeError: If `out_channel` or `groups` is not an int.
|
|
6086
6595
|
TypeError: If `stride`, `padding` or `dilation` is neither an int nor a tuple.
|
|
6087
6596
|
TypeError: If `bias` is not a Tensor.
|
|
6088
|
-
ValueError: If the shape of `bias` is not :math:`C_{out}`.
|
|
6597
|
+
ValueError: If the shape of `bias` is not :math:`(C_{out})`.
|
|
6089
6598
|
ValueError: If `stride` or `dilation` is less than 1.
|
|
6090
6599
|
ValueError: If `pad_mode` is not one of 'same', 'valid' or 'pad'.
|
|
6091
6600
|
ValueError: If `padding` is a tuple or list whose length is not equal to 3.
|
|
@@ -6193,21 +6702,19 @@ def pixel_shuffle(input, upscale_factor):
|
|
|
6193
6702
|
_check_positive_int(upscale_factor, "upscale_factor")
|
|
6194
6703
|
_check_is_tensor("input", input, "pixel_shuffle")
|
|
6195
6704
|
_check_pixel_shuffle_unshuffle_input_shape(input, "pixel_shuffle")
|
|
6196
|
-
idx =
|
|
6705
|
+
idx = shape_(input)
|
|
6197
6706
|
length = input.ndim
|
|
6198
6707
|
pre = idx[:-3]
|
|
6199
6708
|
c, h, w = idx[-3:]
|
|
6200
6709
|
_check_pxiel_shuffle_valid(c, upscale_factor)
|
|
6201
6710
|
c = c // upscale_factor ** 2
|
|
6202
6711
|
input_perm = (pre + (c, upscale_factor, upscale_factor, h, w))
|
|
6203
|
-
|
|
6204
|
-
transpose = _get_cache_prim(P.Transpose)()
|
|
6205
|
-
input = reshape(input, input_perm)
|
|
6712
|
+
input = reshape_(input, input_perm)
|
|
6206
6713
|
input_perm = [i for i in range(length - 2)]
|
|
6207
6714
|
input_perm = input_perm + [length, length - 2, length + 1, length - 1]
|
|
6208
6715
|
input_perm = tuple(input_perm)
|
|
6209
|
-
input =
|
|
6210
|
-
input =
|
|
6716
|
+
input = transpose_(input, input_perm)
|
|
6717
|
+
input = reshape_(input, (pre + (c, upscale_factor * h, upscale_factor * w)))
|
|
6211
6718
|
return input
|
|
6212
6719
|
|
|
6213
6720
|
|
|
@@ -6258,7 +6765,7 @@ def pixel_unshuffle(input, downscale_factor):
|
|
|
6258
6765
|
_check_positive_int(downscale_factor, "downscale_factor")
|
|
6259
6766
|
_check_is_tensor("input", input, "pixel_unshuffle")
|
|
6260
6767
|
_check_pixel_shuffle_unshuffle_input_shape(input, "pixel_unshuffle")
|
|
6261
|
-
idx =
|
|
6768
|
+
idx = shape_(input)
|
|
6262
6769
|
length = input.ndim
|
|
6263
6770
|
pre = idx[:-3]
|
|
6264
6771
|
c, h, w = idx[-3:]
|
|
@@ -6266,14 +6773,12 @@ def pixel_unshuffle(input, downscale_factor):
|
|
|
6266
6773
|
h = h // downscale_factor
|
|
6267
6774
|
w = w // downscale_factor
|
|
6268
6775
|
input_perm = (pre + (c, h, downscale_factor, w, downscale_factor))
|
|
6269
|
-
|
|
6270
|
-
transpose = _get_cache_prim(P.Transpose)()
|
|
6271
|
-
input = reshape(input, input_perm)
|
|
6776
|
+
input = reshape_(input, input_perm)
|
|
6272
6777
|
input_perm = [i for i in range(length - 2)]
|
|
6273
6778
|
input_perm = input_perm + [length - 1, length + 1, length - 2, length]
|
|
6274
6779
|
input_perm = tuple(input_perm)
|
|
6275
|
-
input =
|
|
6276
|
-
input =
|
|
6780
|
+
input = transpose_(input, input_perm)
|
|
6781
|
+
input = reshape_(input, (pre + (c * downscale_factor * downscale_factor, h, w)))
|
|
6277
6782
|
return input
|
|
6278
6783
|
|
|
6279
6784
|
|
|
@@ -6290,7 +6795,7 @@ def glu(x, axis=-1):
|
|
|
6290
6795
|
See `Language Modeling with Gated Convluational Networks <https://arxiv.org/abs/1612.08083>`_.
|
|
6291
6796
|
|
|
6292
6797
|
Args:
|
|
6293
|
-
x (Tensor): Tensor to be
|
|
6798
|
+
x (Tensor): Tensor to be split. Its dtype is Number, and shape is :math:`(\ast_1, N, \ast_2)`
|
|
6294
6799
|
where `*` means, any number of additional dimensions.
|
|
6295
6800
|
axis (int, optional): the axis to split the input. It must be int. Default: ``-1`` , the last axis of `x`.
|
|
6296
6801
|
|
|
@@ -6312,9 +6817,6 @@ def glu(x, axis=-1):
|
|
|
6312
6817
|
[[0.05744425 0.11973753]
|
|
6313
6818
|
[0.33409387 0.41398472]]
|
|
6314
6819
|
"""
|
|
6315
|
-
if not isinstance(x, Tensor) or x.size == 0:
|
|
6316
|
-
raise TypeError("glu does not support scalars because halving size must be even")
|
|
6317
|
-
|
|
6318
6820
|
spilt = _get_cache_prim(P.Split)(axis=axis, output_num=2)
|
|
6319
6821
|
x, y = spilt(x)
|
|
6320
6822
|
y = sigmoid_(y)
|
|
@@ -6334,7 +6836,7 @@ def multi_margin_loss(input, target, p=1, margin=1, weight=None, reduction='mean
|
|
|
6334
6836
|
.. math::
|
|
6335
6837
|
\text{loss}(x, y) = \frac{\sum_i \max(0, \text{margin} - x[y] + x[i])^p}{\text{x.size}(0)}
|
|
6336
6838
|
|
|
6337
|
-
where :math:`i\in \{0,⋯,x.size(0)
|
|
6839
|
+
where :math:`i\in \{0,⋯,x.size(0)-1\}` and :math:`i \ne y`.
|
|
6338
6840
|
|
|
6339
6841
|
Args:
|
|
6340
6842
|
input (Tensor): Input , with shape :math:`(N, C)`. Data type only support float32, float16 or float64.
|
|
@@ -6353,8 +6855,8 @@ def multi_margin_loss(input, target, p=1, margin=1, weight=None, reduction='mean
|
|
|
6353
6855
|
- ``'sum'``: the output elements will be summed.
|
|
6354
6856
|
|
|
6355
6857
|
Returns:
|
|
6356
|
-
Tensor. If `reduction` is ``'none'``, returns a Tensor with the same shape as `target`.
|
|
6357
|
-
|
|
6858
|
+
- **outputs** - Tensor. If `reduction` is ``'none'``, returns a Tensor with the same shape as `target`.
|
|
6859
|
+
Otherwise, it is a scalar.
|
|
6358
6860
|
|
|
6359
6861
|
Raises:
|
|
6360
6862
|
TypeError: If dtype of `p` or `target` is not int.
|
|
@@ -6413,10 +6915,11 @@ def multilabel_margin_loss(input, target, reduction='mean'):
|
|
|
6413
6915
|
This allows for different samples to have variable amounts of target classes.
|
|
6414
6916
|
|
|
6415
6917
|
Args:
|
|
6416
|
-
input (Tensor): Predict data. Tensor of shape :math:`(C)`
|
|
6417
|
-
is the batch size and :math:`C` is the number of classes.
|
|
6418
|
-
|
|
6419
|
-
|
|
6918
|
+
input (Tensor): Predict data, :math:`x` in the formula above. Tensor of shape :math:`(C)`
|
|
6919
|
+
or :math:`(N, C)`, where :math:`N` is the batch size and :math:`C` is the number of classes.
|
|
6920
|
+
Data type must be float16 or float32.
|
|
6921
|
+
target (Tensor): Ground truth data, :math:`y` in the formula above, with the same shape as `input`,
|
|
6922
|
+
data type must be int32 and label targets padded by -1.
|
|
6420
6923
|
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
6421
6924
|
``'sum'`` . Default: ``'mean'`` .
|
|
6422
6925
|
|
|
@@ -6492,9 +6995,6 @@ def multilabel_soft_margin_loss(input, target, weight=None, reduction='mean'):
|
|
|
6492
6995
|
Tensor, the data type is the same as input, if the `reduction` is ``'none'``,
|
|
6493
6996
|
its shape is :math:`(N)` , otherwise it is zero.
|
|
6494
6997
|
|
|
6495
|
-
Raises:
|
|
6496
|
-
ValueError: If the rank of `input` or `target` is not 2.
|
|
6497
|
-
|
|
6498
6998
|
Supported Platforms:
|
|
6499
6999
|
``Ascend`` ``GPU`` ``CPU``
|
|
6500
7000
|
|
|
@@ -6509,81 +7009,22 @@ def multilabel_soft_margin_loss(input, target, weight=None, reduction='mean'):
|
|
|
6509
7009
|
cls_name = "multilabel_soft_margin_loss"
|
|
6510
7010
|
_check_is_tensor('input', input, cls_name)
|
|
6511
7011
|
_check_is_tensor('target', target, cls_name)
|
|
6512
|
-
if input.ndim != 2 or target.ndim != 2:
|
|
6513
|
-
raise ValueError(
|
|
6514
|
-
"For 'MultiLabelSoftMarginLoss', the inputs must be 2d tensor, but got dims: "
|
|
6515
|
-
f"input: {input.ndim}, target: {target.ndim} "
|
|
6516
|
-
)
|
|
6517
7012
|
|
|
6518
|
-
mul_op = _get_cache_prim(P.Mul)()
|
|
6519
|
-
exp_op = _get_cache_prim(P.Exp)()
|
|
6520
|
-
add_op = _get_cache_prim(P.Add)()
|
|
6521
|
-
log_op = _get_cache_prim(P.Log)()
|
|
6522
|
-
dyn_shape = _get_cache_prim(P.TensorShape)()
|
|
6523
7013
|
input_shape = input.shape
|
|
6524
7014
|
if ops.is_sequence_value_unknown(input_shape):
|
|
6525
|
-
input_shape =
|
|
7015
|
+
input_shape = tensor_shape_(input)
|
|
6526
7016
|
|
|
6527
|
-
pos =
|
|
6528
|
-
neg =
|
|
6529
|
-
loss =
|
|
7017
|
+
pos = log_(add_(exp_(-input), 1))
|
|
7018
|
+
neg = log_(add_(exp_(input), 1))
|
|
7019
|
+
loss = mul_(target, pos) + mul_(1 - target, neg)
|
|
6530
7020
|
if weight is not None:
|
|
6531
|
-
loss =
|
|
7021
|
+
loss = mul_(loss, weight)
|
|
6532
7022
|
class_dim = input.ndim - 1
|
|
6533
7023
|
loss = loss.sum(axis=class_dim) / input_shape[class_dim]
|
|
6534
7024
|
return _get_loss(loss, reduction, cls_name)
|
|
6535
7025
|
|
|
6536
7026
|
|
|
6537
|
-
def
|
|
6538
|
-
r"""
|
|
6539
|
-
Exponential Linear Unit activation function.
|
|
6540
|
-
|
|
6541
|
-
Applies the exponential linear unit function element-wise.
|
|
6542
|
-
The activation function is defined as:
|
|
6543
|
-
|
|
6544
|
-
.. math::
|
|
6545
|
-
|
|
6546
|
-
\text{ELU}(x)= \left\{
|
|
6547
|
-
\begin{array}{align}
|
|
6548
|
-
\alpha(e^{x} - 1) & \text{if } x \le 0\\
|
|
6549
|
-
x & \text{if } x \gt 0\\
|
|
6550
|
-
\end{array}\right.
|
|
6551
|
-
|
|
6552
|
-
Where :math:`x` is the element of input Tensor `input_x`, :math:`\alpha` is param `alpha`,
|
|
6553
|
-
it determines the smoothness of ELU.
|
|
6554
|
-
The picture about ELU looks like this `ELU <https://en.wikipedia.org/wiki/
|
|
6555
|
-
Activation_function#/media/File:Activation_elu.svg>`_ .
|
|
6556
|
-
|
|
6557
|
-
Args:
|
|
6558
|
-
input_x (Tensor): The input of ELU is a Tensor of any dimension with data type of float16 or float32.
|
|
6559
|
-
alpha (float, optional): The alpha value of ELU, the data type is float. Only support '1.0' currently.
|
|
6560
|
-
Default: ``1.0`` .
|
|
6561
|
-
|
|
6562
|
-
Returns:
|
|
6563
|
-
Tensor, has the same shape and data type as `input_x`.
|
|
6564
|
-
|
|
6565
|
-
Raises:
|
|
6566
|
-
TypeError: If `alpha` is not a float.
|
|
6567
|
-
TypeError: If dtype of `input_x` is neither float16 nor float32.
|
|
6568
|
-
ValueError: If `alpha` is not equal to 1.0.
|
|
6569
|
-
|
|
6570
|
-
Supported Platforms:
|
|
6571
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
6572
|
-
|
|
6573
|
-
Examples:
|
|
6574
|
-
>>> import mindspore
|
|
6575
|
-
>>> import numpy as np
|
|
6576
|
-
>>> from mindspore import Tensor, ops
|
|
6577
|
-
>>> x = Tensor(np.array([[-1.0, 4.0, -8.0], [2.0, -5.0, 9.0]]), mindspore.float32)
|
|
6578
|
-
>>> output = ops.elu(x)
|
|
6579
|
-
>>> print(output)
|
|
6580
|
-
[[-0.63212055 4. -0.99966455]
|
|
6581
|
-
[ 2. -0.99326205 9. ]]
|
|
6582
|
-
"""
|
|
6583
|
-
return _get_cache_prim(P.Elu)(alpha=alpha)(input_x)
|
|
6584
|
-
|
|
6585
|
-
|
|
6586
|
-
def gelu(input_x, approximate='none'):
|
|
7027
|
+
def gelu(input, approximate='none'):
|
|
6587
7028
|
r"""
|
|
6588
7029
|
Gaussian Error Linear Units activation function.
|
|
6589
7030
|
|
|
@@ -6604,18 +7045,23 @@ def gelu(input_x, approximate='none'):
|
|
|
6604
7045
|
.. math::
|
|
6605
7046
|
GELU(x_i) = 0.5 * x_i * (1 + \tanh(\sqrt(2 / \pi) * (x_i + 0.044715 * x_i^3)))
|
|
6606
7047
|
|
|
7048
|
+
GELU Activation Function Graph:
|
|
7049
|
+
|
|
7050
|
+
.. image:: ../images/GELU.png
|
|
7051
|
+
:align: center
|
|
7052
|
+
|
|
6607
7053
|
Args:
|
|
6608
|
-
|
|
7054
|
+
input (Tensor): The input of the activation function GeLU, the data type is float16, float32 or float64.
|
|
6609
7055
|
approximate (str): the gelu approximation algorithm to use. Acceptable vaslues are ``'none'`` and ``'tanh'`` .
|
|
6610
7056
|
Default: ``'none'`` .
|
|
6611
7057
|
|
|
6612
7058
|
Returns:
|
|
6613
|
-
Tensor, with the same type and shape as `
|
|
7059
|
+
Tensor, with the same type and shape as `input`.
|
|
6614
7060
|
|
|
6615
7061
|
Raises:
|
|
6616
|
-
TypeError: If `
|
|
6617
|
-
TypeError: If dtype of `
|
|
6618
|
-
ValueError: If `approximate` value is neither `none`
|
|
7062
|
+
TypeError: If `input` is not a Tensor.
|
|
7063
|
+
TypeError: If dtype of `input` is not bfloat16, float16, float32 or float64.
|
|
7064
|
+
ValueError: If `approximate` value is neither `none` nor `tanh`.
|
|
6619
7065
|
|
|
6620
7066
|
Supported Platforms:
|
|
6621
7067
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -6626,22 +7072,22 @@ def gelu(input_x, approximate='none'):
|
|
|
6626
7072
|
>>> x = Tensor([1.0, 2.0, 3.0], mindspore.float32)
|
|
6627
7073
|
>>> result = ops.gelu(x)
|
|
6628
7074
|
>>> print(result)
|
|
6629
|
-
[0.
|
|
7075
|
+
[0.8413447 1.9544997 2.9959505]
|
|
6630
7076
|
"""
|
|
6631
7077
|
if approximate not in ['none', 'tanh']:
|
|
6632
7078
|
raise ValueError("For ops.gelu, approximate value should be either 'none' or 'tanh'.")
|
|
6633
7079
|
|
|
6634
|
-
x_dtype =
|
|
6635
|
-
if x_dtype not in [mstype.float16, mstype.float32, mstype.float64]:
|
|
7080
|
+
x_dtype = dtype_(input)
|
|
7081
|
+
if x_dtype not in [mstype.float16, mstype.float32, mstype.float64, mstype.bfloat16]:
|
|
6636
7082
|
raise TypeError(f"For gelu, the input dtype must be float16, float32 or float64, "
|
|
6637
7083
|
f"but got {x_dtype}.")
|
|
6638
7084
|
if approximate == 'tanh':
|
|
6639
|
-
output =
|
|
7085
|
+
output = gelu_(input)
|
|
6640
7086
|
else:
|
|
6641
|
-
output =
|
|
6642
|
-
output =
|
|
6643
|
-
output =
|
|
6644
|
-
output =
|
|
7087
|
+
output = sqrt_(Tensor(2.0, x_dtype))
|
|
7088
|
+
output = div_(input, output)
|
|
7089
|
+
output = erf_(output) + Tensor(1.0, x_dtype)
|
|
7090
|
+
output = input * output * Tensor(0.5, x_dtype)
|
|
6645
7091
|
|
|
6646
7092
|
return output
|
|
6647
7093
|
|
|
@@ -6691,13 +7137,6 @@ def channel_shuffle(x, groups):
|
|
|
6691
7137
|
return y
|
|
6692
7138
|
|
|
6693
7139
|
|
|
6694
|
-
@_primexpr
|
|
6695
|
-
def _shape_check(in_shape, dim_list, prim_name=None):
|
|
6696
|
-
msg_prefix = f"For '{prim_name}', the" if prim_name else "The"
|
|
6697
|
-
if len(in_shape) not in dim_list:
|
|
6698
|
-
raise ValueError(f"{msg_prefix} input must has dim in {dim_list}, but got {len(in_shape)}")
|
|
6699
|
-
|
|
6700
|
-
|
|
6701
7140
|
def lp_pool1d(x, norm_type, kernel_size, stride=None, ceil_mode=False):
|
|
6702
7141
|
r"""
|
|
6703
7142
|
Applying 1D LPPooling operation on an input Tensor can be regarded as forming a 1D input plane.
|
|
@@ -6733,7 +7172,7 @@ def lp_pool1d(x, norm_type, kernel_size, stride=None, ceil_mode=False):
|
|
|
6733
7172
|
L_{out} = \left\lfloor\frac{L_{in} - \text{kernel_size}}{\text{stride}} + 1\right\rfloor
|
|
6734
7173
|
|
|
6735
7174
|
Raises:
|
|
6736
|
-
TypeError: If `x` is not
|
|
7175
|
+
TypeError: If `x` is not a Tensor.
|
|
6737
7176
|
TypeError: If `kernel_size` or `stride` is not an int.
|
|
6738
7177
|
TypeError: If `ceil_mode` is not a bool.
|
|
6739
7178
|
TypeError: If `norm_type` is neither float nor int.
|
|
@@ -6746,7 +7185,7 @@ def lp_pool1d(x, norm_type, kernel_size, stride=None, ceil_mode=False):
|
|
|
6746
7185
|
|
|
6747
7186
|
Examples:
|
|
6748
7187
|
>>> import mindspore as ms
|
|
6749
|
-
>>>
|
|
7188
|
+
>>> from mindspore import ops
|
|
6750
7189
|
>>> from mindspore import Tensor
|
|
6751
7190
|
>>> import numpy as np
|
|
6752
7191
|
>>> x = Tensor(np.arange(2 * 3 * 4).reshape((2, 3, 4)), dtype=ms.float32)
|
|
@@ -6759,7 +7198,6 @@ def lp_pool1d(x, norm_type, kernel_size, stride=None, ceil_mode=False):
|
|
|
6759
7198
|
[51. 54.]
|
|
6760
7199
|
[63. 66.]]]
|
|
6761
7200
|
"""
|
|
6762
|
-
_shape_check(x.shape, [2, 3], "lp_pool1d")
|
|
6763
7201
|
if isinstance(norm_type, (float, int)):
|
|
6764
7202
|
norm_type = float(norm_type)
|
|
6765
7203
|
else:
|
|
@@ -6818,7 +7256,7 @@ def lp_pool2d(x, norm_type, kernel_size, stride=None, ceil_mode=False):
|
|
|
6818
7256
|
W_{out} = \left\lfloor\frac{W_{in} - \text{kernel_size}[1]}{\text{stride}[1]} + 1\right\rfloor
|
|
6819
7257
|
|
|
6820
7258
|
Raises:
|
|
6821
|
-
TypeError: If `x` is not
|
|
7259
|
+
TypeError: If `x` is not a Tensor.
|
|
6822
7260
|
TypeError: If `kernel_size` or `stride` is neither int nor tuple.
|
|
6823
7261
|
TypeError: If `ceil_mode` is not a bool.
|
|
6824
7262
|
TypeError: If `norm_type` is neither float nor int.
|
|
@@ -6832,7 +7270,7 @@ def lp_pool2d(x, norm_type, kernel_size, stride=None, ceil_mode=False):
|
|
|
6832
7270
|
|
|
6833
7271
|
Examples:
|
|
6834
7272
|
>>> import mindspore as ms
|
|
6835
|
-
>>>
|
|
7273
|
+
>>> from mindspore import ops
|
|
6836
7274
|
>>> from mindspore import Tensor
|
|
6837
7275
|
>>> import numpy as np
|
|
6838
7276
|
>>> x = Tensor(np.arange(2 * 3 * 4 * 5).reshape((2, 3, 4, 5)), dtype=ms.float32)
|
|
@@ -6852,7 +7290,6 @@ def lp_pool2d(x, norm_type, kernel_size, stride=None, ceil_mode=False):
|
|
|
6852
7290
|
[ 999. 1008. 1017.]]]]
|
|
6853
7291
|
|
|
6854
7292
|
"""
|
|
6855
|
-
_shape_check(x.shape, [4], "lp_pool2d")
|
|
6856
7293
|
if isinstance(norm_type, (float, int)):
|
|
6857
7294
|
norm_type = float(norm_type)
|
|
6858
7295
|
else:
|
|
@@ -6915,13 +7352,13 @@ def mse_loss(input, target, reduction='mean'):
|
|
|
6915
7352
|
if reduction not in ['mean', 'none', 'sum']:
|
|
6916
7353
|
raise ValueError("For ops.mse_loss, `reduction` value should be either 'mean', 'none' or 'sum'.")
|
|
6917
7354
|
|
|
6918
|
-
x =
|
|
7355
|
+
x = square_(input - target)
|
|
6919
7356
|
float_type = (mstype.float16, mstype.float32, mstype.float64)
|
|
6920
7357
|
if x.dtype not in float_type:
|
|
6921
7358
|
input_dtype = mstype.float32
|
|
6922
7359
|
else:
|
|
6923
7360
|
input_dtype = x.dtype
|
|
6924
|
-
x =
|
|
7361
|
+
x = cast_(x, mstype.float32)
|
|
6925
7362
|
|
|
6926
7363
|
average_flag = True
|
|
6927
7364
|
reduce_flag = True
|
|
@@ -6931,12 +7368,12 @@ def mse_loss(input, target, reduction='mean'):
|
|
|
6931
7368
|
reduce_flag = False
|
|
6932
7369
|
|
|
6933
7370
|
if reduce_flag and average_flag:
|
|
6934
|
-
x =
|
|
7371
|
+
x = reduce_mean_(x, _get_axis(x))
|
|
6935
7372
|
|
|
6936
7373
|
if reduce_flag and not average_flag:
|
|
6937
|
-
x =
|
|
7374
|
+
x = reduce_sum_(x, _get_axis(x))
|
|
6938
7375
|
|
|
6939
|
-
return
|
|
7376
|
+
return cast_(x, input_dtype)
|
|
6940
7377
|
|
|
6941
7378
|
|
|
6942
7379
|
def msort(input):
|
|
@@ -6959,7 +7396,7 @@ def msort(input):
|
|
|
6959
7396
|
|
|
6960
7397
|
Examples:
|
|
6961
7398
|
>>> import mindspore as ms
|
|
6962
|
-
>>>
|
|
7399
|
+
>>> from mindspore import ops
|
|
6963
7400
|
>>> import numpy as np
|
|
6964
7401
|
>>> input = ms.Tensor(np.array([[8, 2, 1], [5, 9, 3], [4, 6, 7]]), ms.float16)
|
|
6965
7402
|
>>> output = ops.msort(input)
|
|
@@ -6998,7 +7435,7 @@ def triplet_margin_loss(anchor, positive, negative, margin=1.0, p=2, eps=1e-06,
|
|
|
6998
7435
|
Tensor. If `reduction` is ``"none"``, its shape is :math:`(N)`. Otherwise, a scalar value will be returned.
|
|
6999
7436
|
|
|
7000
7437
|
Raises:
|
|
7001
|
-
TypeError: If `anchor` or `positive` or
|
|
7438
|
+
TypeError: If `anchor` or `positive` or `negative` is not a Tensor.
|
|
7002
7439
|
TypeError: If dtype of `anchor`, `positive` and `negative` is not the same.
|
|
7003
7440
|
TypeError: If `margin` is not a float.
|
|
7004
7441
|
TypeError: If `p` is not an int.
|
|
@@ -7337,7 +7774,7 @@ def multi_head_attention_forward(query, key, value, embed_dim_to_check, num_head
|
|
|
7337
7774
|
|
|
7338
7775
|
if attn_mask is not None and attn_mask.dtype == mstype.bool_:
|
|
7339
7776
|
new_attn_mask = ops.zeros_like(attn_mask, dtype=q.dtype)
|
|
7340
|
-
attn_mask = new_attn_mask.masked_fill(attn_mask, float("-inf"))
|
|
7777
|
+
attn_mask = new_attn_mask.masked_fill(attn_mask, ops.cast(float("-inf"), new_attn_mask.dtype))
|
|
7341
7778
|
|
|
7342
7779
|
if attn_mask is not None:
|
|
7343
7780
|
if attn_mask.shape[0] == 1:
|
|
@@ -7446,11 +7883,10 @@ def max_pool2d(x, kernel_size, stride=None, padding=0, dilation=1, return_indice
|
|
|
7446
7883
|
return out
|
|
7447
7884
|
|
|
7448
7885
|
|
|
7449
|
-
def prompt_flash_attention(query, key, value, attn_mask, actual_seq_lengths,
|
|
7450
|
-
|
|
7451
|
-
|
|
7452
|
-
|
|
7453
|
-
num_key_value_heads=0, sparse_mode=0):
|
|
7886
|
+
def prompt_flash_attention(query, key, value, attn_mask, actual_seq_lengths, actual_seq_lengths_kv, pse_shift,
|
|
7887
|
+
deq_scale1, quant_scale1, deq_scale2, quant_scale2, quant_offset2, num_heads,
|
|
7888
|
+
scale_value=1.0, pre_tokens=2147483547, next_tokens=0, input_layout='BSH',
|
|
7889
|
+
num_key_value_heads=0, sparse_mode=0, inner_precise=1):
|
|
7454
7890
|
r"""
|
|
7455
7891
|
The interface for fully inference.
|
|
7456
7892
|
B -- Batch size
|
|
@@ -7458,7 +7894,7 @@ def prompt_flash_attention(query, key, value, attn_mask, actual_seq_lengths,
|
|
|
7458
7894
|
H -- Hidden size
|
|
7459
7895
|
|
|
7460
7896
|
Note:
|
|
7461
|
-
|
|
7897
|
+
experiment ops
|
|
7462
7898
|
|
|
7463
7899
|
.. warning::
|
|
7464
7900
|
This is an experimental API that is subject to change or deletion.
|
|
@@ -7472,8 +7908,8 @@ def prompt_flash_attention(query, key, value, attn_mask, actual_seq_lengths,
|
|
|
7472
7908
|
Input tensor of shape :math:`(B, S, H)` / `(B, N, S, D)`.
|
|
7473
7909
|
attn_mask (Tensor) - The attention mask tensor with data type of float16 or float32.
|
|
7474
7910
|
For each element, 0 indicates retention and 1 indicates discard. Input tensor of shape :math:`(B, 1, S, S)`.
|
|
7475
|
-
actual_seq_lengths (
|
|
7476
|
-
actual_seq_lengths_kv (
|
|
7911
|
+
actual_seq_lengths (Tensor): Describe actual sequence length of each input with data type of int64.
|
|
7912
|
+
actual_seq_lengths_kv (Tensor): Describe actual sequence length of each input with data type of int64.
|
|
7477
7913
|
pse_shift (Tensor) - The position encoding tensor with data type of float16 or float32.
|
|
7478
7914
|
dep_scale1 (Tensor)
|
|
7479
7915
|
quant_scale1 (Tensor)
|
|
@@ -7491,6 +7927,7 @@ def prompt_flash_attention(query, key, value, attn_mask, actual_seq_lengths,
|
|
|
7491
7927
|
num_key_value_heads (int): head numbers of key/value which are used in GQA algorithm.
|
|
7492
7928
|
The value o indicates if the key and value have the same head nums, use numHeads. Default: 0.
|
|
7493
7929
|
sparse_mode (int): Default: 0
|
|
7930
|
+
inner_precise (int): 0, float16 high precision. 1, high performance. default 1
|
|
7494
7931
|
|
|
7495
7932
|
|
|
7496
7933
|
Outputs:
|
|
@@ -7512,16 +7949,128 @@ def prompt_flash_attention(query, key, value, attn_mask, actual_seq_lengths,
|
|
|
7512
7949
|
>>> value = Tensor(np.ones((B, N, S, D), dtype=np.float16))
|
|
7513
7950
|
>>> out = ops.prompt_flash_attention(query, key, value, None, None, None, None, None, None, None, None,
|
|
7514
7951
|
None, N, input_layout='BNSD')
|
|
7515
|
-
>>> print(out
|
|
7952
|
+
>>> print(out.shape)
|
|
7516
7953
|
(1, 16, 256, 16)
|
|
7517
7954
|
"""
|
|
7518
7955
|
|
|
7519
7956
|
pfa = _get_cache_prim(NN_OPS.PromptFlashAttention)(num_heads, scale_value, pre_tokens, next_tokens, input_layout,
|
|
7520
|
-
num_key_value_heads, sparse_mode)
|
|
7957
|
+
num_key_value_heads, sparse_mode, inner_precise)
|
|
7521
7958
|
return pfa(query, key, value, attn_mask, actual_seq_lengths, actual_seq_lengths_kv, pse_shift, deq_scale1,
|
|
7522
7959
|
quant_scale1, deq_scale2, quant_scale2, quant_offset2)
|
|
7523
7960
|
|
|
7524
7961
|
|
|
7962
|
+
def incre_flash_attention(query, key, value, attn_mask, actual_seq_lengths, pse_shift, dequant_scale1, quant_scale1,
|
|
7963
|
+
dequant_scale2, quant_scale2, quant_offset2, antiquant_scale, antiquant_offset, block_table,
|
|
7964
|
+
num_heads, input_layout="BSH", scale_value=1.0, num_key_value_heads=0, block_size=0,
|
|
7965
|
+
inner_precise=1):
|
|
7966
|
+
r"""
|
|
7967
|
+
The interface for fully inference.
|
|
7968
|
+
|
|
7969
|
+
B -- Batch size
|
|
7970
|
+
|
|
7971
|
+
S -- Sequence length
|
|
7972
|
+
|
|
7973
|
+
H -- Hidden size
|
|
7974
|
+
|
|
7975
|
+
.. warning::
|
|
7976
|
+
This is an experimental API that is subject to change or deletion.
|
|
7977
|
+
If there is no input parameter and no default value, None needs to be passed.
|
|
7978
|
+
|
|
7979
|
+
Inputs:
|
|
7980
|
+
- **query** (Tensor) - The query tensor with data type of float16 or bfloat16.
|
|
7981
|
+
Input tensor of shape :math:`(B, 1, H)` / :math:`(B, N, 1, D)`.
|
|
7982
|
+
- **key** (TensorList) - The key tensor with data type of float16 or bfloat16.
|
|
7983
|
+
Input tensor of shape :math:`(B, S, H)` / :math:`(B, N, S, D)`.
|
|
7984
|
+
- **value** (TensorList) - The value tensor with data type of float16 or bfloat16.
|
|
7985
|
+
Input tensor of shape :math:`(B, S, H)` / :math:`(B, N, S, D)`.
|
|
7986
|
+
- **attn_mask** (Tensor) - The attention mask tensor with data type of float16 or bool.
|
|
7987
|
+
Input tensor of shape :math:`(B, S)` / :math:`(B, 1, S)` / :math:`(B, 1, 1, S)`.
|
|
7988
|
+
- **actual_seq_lengths** (Tensor) - Describe actual sequence length of each input with data type of int.
|
|
7989
|
+
- **pse_shift** (Tensor) - The position encoding tensor with data type of float16 or float32.
|
|
7990
|
+
- **dequant_scale1** (Tensor) - Quantitative parametor, the tensor with data type of uint64.
|
|
7991
|
+
- **quant_scale1** (Tensor) - Quantitative parametor, the tensor with data type of float.
|
|
7992
|
+
- **dequant_scale2** (Tensor) - Quantitative parametor, the tensor with data type of uint64.
|
|
7993
|
+
- **quant_scale2** (Tensor) - Quantitative parametor, the tensor with data type of float.
|
|
7994
|
+
- **quant_offset2** (Tensor) - Quantitative parametor, the tensor with data type of float.
|
|
7995
|
+
- **antiquant_scale** (Tensor) - Quantitative parametor, the tensor with data type of float.
|
|
7996
|
+
- **antiquant_offset** (Tensor) - Quantitative parametor, the tensor with data type of float.
|
|
7997
|
+
- **block_table** (Tensor) - The tensor with data type of float.
|
|
7998
|
+
- **num_heads** (int) - The number of heads.
|
|
7999
|
+
- **input_layout** (str) - the data layout of the input qkv, support `(BSH)` and `(BNSD)`. Default `BSH`.
|
|
8000
|
+
- **scale_value** (double) - The scale value indicating the scale coefficient, which is used as the scalar of
|
|
8001
|
+
Muls in the calculation. Default: 1.0.
|
|
8002
|
+
- **num_key_value_heads** (int) - head numbers of key/value which are used in GQA algorithm.
|
|
8003
|
+
The value o indicates if the key and value have the same head nums, use numHeads. Default: 0.
|
|
8004
|
+
- **block_size** (int) - Default: 0.
|
|
8005
|
+
- **inner_precise** (int) - Default: 1.
|
|
8006
|
+
|
|
8007
|
+
Outputs:
|
|
8008
|
+
- **attention_out** (Tensor) - Input tensor of shape :math:`(B, 1, H)` / :math:`(B, N, 1, D)`.
|
|
8009
|
+
|
|
8010
|
+
Supported Platforms:
|
|
8011
|
+
``Ascend``
|
|
8012
|
+
"""
|
|
8013
|
+
|
|
8014
|
+
_ifa = _get_cache_prim(NN_OPS.IncreFlashAttention)(num_heads, input_layout, scale_value, num_key_value_heads,
|
|
8015
|
+
block_size, inner_precise)
|
|
8016
|
+
return _ifa(query, key, value, attn_mask, actual_seq_lengths, pse_shift, dequant_scale1, quant_scale1,
|
|
8017
|
+
dequant_scale2, quant_scale2, quant_offset2, antiquant_scale, antiquant_offset, block_table)
|
|
8018
|
+
|
|
8019
|
+
|
|
8020
|
+
def embedding(input, weight, padding_idx=None, max_norm=None, norm_type=2.0, scale_grad_by_freq=False):
|
|
8021
|
+
r"""
|
|
8022
|
+
Retrieve the word embeddings in `weight` using indices specified in `input`.
|
|
8023
|
+
|
|
8024
|
+
.. warning::
|
|
8025
|
+
On Ascend, the behavior is unpredictable when the value of input is invalid.
|
|
8026
|
+
|
|
8027
|
+
Args:
|
|
8028
|
+
input (Tensor): The indices used to lookup in the `weight`. The data type must be mindspore.int32 or
|
|
8029
|
+
mindspore.int64, and the value should be in range `[0, weight.shape[0])`.
|
|
8030
|
+
weight (Parameter): The matrix where to lookup from. The shape must be 2D.
|
|
8031
|
+
padding_idx (int, optional): If the value is not None, the corresponding row of `weight` will not be updated
|
|
8032
|
+
in training. The value should be in range `[-weight.shape[0], weight.shape[0])` if it's not ``None``.
|
|
8033
|
+
Default ``None``.
|
|
8034
|
+
max_norm (float, optional): If not None, firstly get the p-norm result of the `weight` specified by `input`
|
|
8035
|
+
where p is specified by `norm_type`; if the result is larger then `max_norm`, update the `weight`
|
|
8036
|
+
with :math:`\frac{max\_norm}{result+1e^{-7}}` in-place. Default ``None``.
|
|
8037
|
+
norm_type (float, optional): Indicates the value of p in p-norm. Default ``2.0``.
|
|
8038
|
+
scale_grad_by_freq (bool, optional): If ``True`` the gradients will be scaled by the inverse of frequency of
|
|
8039
|
+
the index in `input`. Default ``False``.
|
|
8040
|
+
|
|
8041
|
+
Returns:
|
|
8042
|
+
Tensor, has the same data type as `weight`, the shape is :math:`(*input.shape, weight.shape[1])`.
|
|
8043
|
+
|
|
8044
|
+
Raises:
|
|
8045
|
+
ValueError: If `padding_idx` is out of valid range.
|
|
8046
|
+
ValueError: If the shape of `weight` is invalid.
|
|
8047
|
+
TypeError: `weight` is not a :class:`mindspore.Parameter`.
|
|
8048
|
+
|
|
8049
|
+
Supported Platforms:
|
|
8050
|
+
``Ascend``
|
|
8051
|
+
|
|
8052
|
+
Examples:
|
|
8053
|
+
>>> import mindspore
|
|
8054
|
+
>>> import numpy as np
|
|
8055
|
+
>>> from mindspore import Tensor, Parameter, ops
|
|
8056
|
+
>>> input = Tensor([[1, 0, 1, 1], [0, 0, 1, 0]])
|
|
8057
|
+
>>> weight = Parameter(np.random.randn(3, 3).astype(np.float32))
|
|
8058
|
+
>>> output = ops.embedding(input, weight, max_norm=0.4)
|
|
8059
|
+
>>> print(output)
|
|
8060
|
+
[[[ 5.49015924e-02, 3.47811311e-01, -1.89771220e-01],
|
|
8061
|
+
[ 2.09307984e-01, -2.24846993e-02, 3.40124398e-01],
|
|
8062
|
+
[ 5.49015924e-02, 3.47811311e-01, -1.89771220e-01],
|
|
8063
|
+
[ 5.49015924e-02, 3.47811311e-01, -1.89771220e-01]],
|
|
8064
|
+
[[ 2.09307984e-01, -2.24846993e-02, 3.40124398e-01],
|
|
8065
|
+
[ 2.09307984e-01, -2.24846993e-02, 3.40124398e-01],
|
|
8066
|
+
[ 5.49015924e-02, 3.47811311e-01, -1.89771220e-01],
|
|
8067
|
+
[ 2.09307984e-01, -2.24846993e-02, 3.40124398e-01]]]
|
|
8068
|
+
"""
|
|
8069
|
+
if not isinstance(weight, Parameter):
|
|
8070
|
+
raise TypeError(f"For Embedding, the weight must be a mindspore.Parameter, but got {type(weight)}.")
|
|
8071
|
+
return embedding_op(input, weight, padding_idx, max_norm, norm_type, scale_grad_by_freq)
|
|
8072
|
+
|
|
8073
|
+
|
|
7525
8074
|
__all__ = [
|
|
7526
8075
|
'adaptive_avg_pool1d',
|
|
7527
8076
|
'adaptive_avg_pool2d',
|
|
@@ -7547,6 +8096,7 @@ __all__ = [
|
|
|
7547
8096
|
'dropout1d',
|
|
7548
8097
|
'dropout2d',
|
|
7549
8098
|
'dropout3d',
|
|
8099
|
+
'embedding',
|
|
7550
8100
|
'fast_gelu',
|
|
7551
8101
|
'fractional_max_pool2d',
|
|
7552
8102
|
'fractional_max_pool3d',
|
|
@@ -7560,6 +8110,7 @@ __all__ = [
|
|
|
7560
8110
|
'intopk',
|
|
7561
8111
|
'interpolate',
|
|
7562
8112
|
'upsample',
|
|
8113
|
+
'layer_norm',
|
|
7563
8114
|
'log_softmax',
|
|
7564
8115
|
'mish',
|
|
7565
8116
|
'lrn',
|
|
@@ -7592,6 +8143,7 @@ __all__ = [
|
|
|
7592
8143
|
'conv3d_transpose',
|
|
7593
8144
|
'conv1d',
|
|
7594
8145
|
'conv2d',
|
|
8146
|
+
'conv_transpose2d',
|
|
7595
8147
|
'sigmoid',
|
|
7596
8148
|
'logsigmoid',
|
|
7597
8149
|
'relu',
|
|
@@ -7616,6 +8168,8 @@ __all__ = [
|
|
|
7616
8168
|
'msort',
|
|
7617
8169
|
'triplet_margin_loss',
|
|
7618
8170
|
'channel_shuffle',
|
|
7619
|
-
'hardsigmoid'
|
|
8171
|
+
'hardsigmoid',
|
|
8172
|
+
'group_norm',
|
|
8173
|
+
'rms_norm',
|
|
7620
8174
|
]
|
|
7621
8175
|
__all__.sort()
|