mindspore 2.2.14__cp37-cp37m-manylinux1_x86_64.whl → 2.3.0rc2__cp37-cp37m-manylinux1_x86_64.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.
- mindspore/.commit_id +1 -1
- mindspore/__init__.py +4 -4
- mindspore/_akg/akg/composite/build_module.py +155 -11
- mindspore/_akg/akg/config/repository.json +38 -0
- mindspore/_akg/akg/ms/info_version_adapt.py +29 -0
- mindspore/_akg/akg/tvm/contrib/nvcc.py +4 -1
- mindspore/_akg/akg/utils/ascend_profilier/path_manager.py +2 -1
- mindspore/_akg/akg/utils/composite_op_helper.py +4 -2
- mindspore/_akg/akg/utils/dump_ascend_meta.py +2 -2
- mindspore/_akg/akg/utils/gen_random.py +14 -8
- mindspore/_akg/akg/utils/op_dsl.py +11 -0
- mindspore/_akg/akg/utils/tbe_codegen_utils.py +18 -8
- mindspore/_c_dataengine.cpython-37m-x86_64-linux-gnu.so +0 -0
- mindspore/_c_expression.cpython-37m-x86_64-linux-gnu.so +0 -0
- mindspore/_c_mindrecord.cpython-37m-x86_64-linux-gnu.so +0 -0
- mindspore/_checkparam.py +78 -0
- 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 +229 -0
- mindspore/_extends/parse/parser.py +155 -59
- mindspore/_extends/parse/resources.py +40 -7
- mindspore/_extends/parse/standard_method.py +127 -206
- mindspore/_extends/remote/kernel_build_server.py +2 -0
- mindspore/_mindspore_offline_debug.cpython-37m-x86_64-linux-gnu.so +0 -0
- mindspore/{ops/_op_impl/tbe/atomic_addr_clean.py → _profiler.py} +13 -16
- mindspore/amp.py +24 -18
- mindspore/bin/cache_admin +0 -0
- mindspore/bin/cache_server +0 -0
- mindspore/boost/boost_cell_wrapper.py +1 -1
- mindspore/boost/group_loss_scale_manager.py +1 -1
- mindspore/common/__init__.py +7 -3
- 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/_stub_tensor.py +7 -1
- mindspore/common/_utils.py +5 -17
- mindspore/common/api.py +145 -50
- mindspore/common/auto_dynamic_shape.py +27 -14
- mindspore/common/dtype.py +9 -6
- mindspore/common/dump.py +5 -4
- mindspore/common/hook_handle.py +51 -4
- mindspore/common/initializer.py +1 -1
- mindspore/common/jit_config.py +33 -13
- mindspore/common/lazy_inline.py +58 -17
- mindspore/common/mindir_util.py +12 -2
- mindspore/common/mutable.py +79 -14
- mindspore/common/parameter.py +24 -4
- mindspore/common/recompute.py +247 -0
- mindspore/common/seed.py +9 -9
- mindspore/common/sparse_tensor.py +251 -18
- mindspore/common/symbol.py +122 -0
- mindspore/common/tensor.py +391 -465
- mindspore/communication/__init__.py +3 -3
- mindspore/communication/_comm_helper.py +5 -0
- mindspore/communication/management.py +53 -38
- mindspore/config/op_info.config +22 -54
- mindspore/context.py +176 -55
- 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 +72 -38
- 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 +7 -7
- mindspore/dataset/engine/datasets_vision.py +75 -71
- mindspore/dataset/engine/offload.py +5 -7
- 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 +3 -3
- mindspore/dataset/vision/c_transforms.py +5 -5
- mindspore/dataset/vision/transforms.py +2264 -514
- mindspore/dataset/vision/utils.py +40 -9
- mindspore/dataset/vision/validators.py +7 -1
- 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 +34 -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/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 +1 -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/mindapi/base/format.h +125 -23
- mindspore/include/mindapi/base/types.h +12 -0
- mindspore/lib/libdnnl.so.2 +0 -0
- mindspore/lib/libmindspore.so +0 -0
- mindspore/lib/libmindspore_backend.so +0 -0
- mindspore/lib/libmindspore_common.so +0 -0
- mindspore/lib/libmindspore_core.so +0 -0
- mindspore/lib/libmindspore_glog.so.0 +0 -0
- mindspore/lib/libmindspore_gpr.so.15 +0 -0
- mindspore/lib/libmindspore_grpc++.so.1 +0 -0
- mindspore/lib/libmindspore_grpc.so.15 +0 -0
- mindspore/lib/libmindspore_shared_lib.so +0 -0
- mindspore/lib/libmpi_adapter.so +0 -0
- mindspore/lib/libmpi_collective.so +0 -0
- mindspore/lib/libnnacl.so +0 -0
- mindspore/lib/libopencv_core.so.4.5 +0 -0
- mindspore/lib/libopencv_imgcodecs.so.4.5 +0 -0
- mindspore/lib/libopencv_imgproc.so.4.5 +0 -0
- mindspore/lib/libps_cache.so +0 -0
- mindspore/lib/plugin/ascend/custom_aicore_ops/op_impl/ai_core/tbe/config/ascend910/aic-ascend910-ops-info.json +2044 -154
- mindspore/lib/plugin/ascend/custom_aicore_ops/op_impl/ai_core/tbe/config/ascend910b/aic-ascend910b-ops-info.json +2044 -33
- mindspore/lib/plugin/ascend/custom_aicore_ops/op_impl/ai_core/tbe/custom_aicore_ops_impl/build_tbe_kernel.py +529 -0
- mindspore/lib/plugin/ascend/custom_aicore_ops/op_impl/ai_core/tbe/custom_aicore_ops_impl/compiler.py +56 -0
- mindspore/lib/plugin/ascend/custom_aicore_ops/op_impl/ai_core/tbe/custom_aicore_ops_impl/custom.py +1109 -0
- mindspore/lib/plugin/ascend/custom_aicore_ops/op_impl/ai_core/tbe/custom_aicore_ops_impl/get_file_path.py +36 -0
- mindspore/lib/plugin/ascend/custom_aicore_ops/op_impl/ai_core/tbe/custom_aicore_ops_impl/kv_cache_mgr.py +0 -2
- mindspore/lib/plugin/ascend/custom_aicore_ops/op_impl/ai_core/tbe/custom_aicore_ops_impl/tbe_topi.py +556 -0
- mindspore/lib/plugin/ascend/custom_aicore_ops/op_impl/vector_core/tbe/custom_aicore_ops_impl/kv_cache_mgr.py +0 -2
- mindspore/lib/plugin/ascend/custom_aicpu_ops/op_impl/cpu/aicpu_kernel/impl/libcust_cpu_kernels.so +0 -0
- mindspore/lib/plugin/ascend/custom_aicpu_ops/op_impl/cpu/config/cust_aicpu_kernel.json +6318 -1760
- mindspore/lib/plugin/ascend/custom_aicpu_ops/op_proto/libcust_op_proto.so +0 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_api/include/aclnn_add_custom.h +49 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_api/include/aclnn_decoder_kv_cache.h +59 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_api/include/aclnn_prompt_kv_cache.h +59 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_api/lib/libcust_opapi.so +0 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/config/ascend310p/aic-ascend310p-ops-info.json +52 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/config/ascend910/aic-ascend910-ops-info.json +232 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/config/ascend910b/aic-ascend910b-ops-info.json +232 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/custom_ascendc_ops_impl/dynamic/add_custom.cpp +81 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/custom_ascendc_ops_impl/dynamic/add_custom.py +134 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/custom_ascendc_ops_impl/dynamic/decoder_kv_cache.cpp +192 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/custom_ascendc_ops_impl/dynamic/decoder_kv_cache.py +134 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/custom_ascendc_ops_impl/dynamic/prompt_kv_cache.cpp +274 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/custom_ascendc_ops_impl/dynamic/prompt_kv_cache.py +134 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/op_tiling/lib/linux/x86_64/libcust_opmaster_rt2.0.so +0 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/op_tiling/liboptiling.so +0 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_proto/inc/op_proto.h +39 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_proto/lib/linux/x86_64/libcust_opsproto_rt2.0.so +0 -0
- mindspore/lib/plugin/ascend/libakg.so +0 -0
- mindspore/lib/plugin/ascend/libascend_collective.so +0 -0
- mindspore/lib/plugin/ascend/libdvpp_utils.so +0 -0
- mindspore/lib/plugin/ascend/libhccl_plugin.so +0 -0
- mindspore/lib/plugin/ascend/libmindspore_cpu_kernels.so +0 -0
- mindspore/lib/plugin/cpu/libakg.so +0 -0
- mindspore/lib/plugin/gpu/libcuda_ops.so.10 +0 -0
- mindspore/lib/plugin/gpu/libcuda_ops.so.11 +0 -0
- mindspore/lib/plugin/gpu10.1/libakg.so +0 -0
- mindspore/lib/plugin/gpu10.1/libnccl.so.2 +0 -0
- mindspore/lib/plugin/gpu10.1/libnvidia_collective.so +0 -0
- mindspore/lib/plugin/gpu11.1/libakg.so +0 -0
- mindspore/lib/plugin/gpu11.1/libnccl.so.2 +0 -0
- mindspore/lib/plugin/gpu11.1/libnvidia_collective.so +0 -0
- mindspore/lib/plugin/gpu11.6/libakg.so +0 -0
- mindspore/lib/plugin/gpu11.6/libnccl.so.2 +0 -0
- mindspore/lib/plugin/gpu11.6/libnvidia_collective.so +0 -0
- mindspore/lib/plugin/{libmindspore_ascend.so.1 → libmindspore_ascend.so.2} +0 -0
- mindspore/lib/plugin/libmindspore_gpu.so.10.1 +0 -0
- mindspore/lib/plugin/libmindspore_gpu.so.11.1 +0 -0
- mindspore/lib/plugin/libmindspore_gpu.so.11.6 +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 +74 -56
- 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/mint/__init__.py +457 -0
- mindspore/mint/nn/__init__.py +430 -0
- mindspore/mint/nn/functional.py +424 -0
- mindspore/mint/optim/__init__.py +24 -0
- mindspore/mint/optim/adamw.py +186 -0
- mindspore/multiprocessing/__init__.py +72 -0
- mindspore/nn/__init__.py +3 -0
- mindspore/nn/cell.py +131 -174
- 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 +107 -0
- mindspore/nn/extend/pooling.py +117 -0
- mindspore/nn/generator.py +297 -0
- mindspore/nn/layer/activation.py +79 -90
- mindspore/nn/layer/basic.py +113 -81
- mindspore/nn/layer/channel_shuffle.py +3 -16
- mindspore/nn/layer/container.py +3 -3
- mindspore/nn/layer/conv.py +71 -71
- mindspore/nn/layer/embedding.py +105 -44
- mindspore/nn/layer/image.py +4 -7
- mindspore/nn/layer/normalization.py +52 -66
- mindspore/nn/layer/padding.py +30 -39
- mindspore/nn/layer/pooling.py +13 -9
- mindspore/nn/layer/rnn_cells.py +5 -15
- 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 +43 -64
- 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 +2 -2
- 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 +6 -5
- 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 +1 -1
- mindspore/nn/probability/distribution/gumbel.py +2 -2
- 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 +33 -12
- mindspore/nn/wrap/grad_reducer.py +148 -8
- mindspore/nn/wrap/loss_scale.py +7 -7
- mindspore/numpy/__init__.py +2 -0
- mindspore/numpy/array_creations.py +2 -0
- mindspore/numpy/array_ops.py +1 -5
- mindspore/numpy/fft.py +431 -0
- mindspore/numpy/math_ops.py +54 -60
- mindspore/numpy/utils.py +3 -0
- mindspore/ops/__init__.py +5 -4
- mindspore/ops/_grad_experimental/grad_array_ops.py +4 -129
- mindspore/ops/_grad_experimental/grad_comm_ops.py +14 -18
- 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 +137 -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 +101 -57
- mindspore/ops/_vmap/vmap_nn_ops.py +230 -97
- 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 +205 -0
- mindspore/ops/auto_generate/gen_arg_dtype_cast.py +257 -0
- mindspore/ops/auto_generate/gen_arg_handler.py +171 -0
- mindspore/ops/auto_generate/gen_extend_func.py +404 -0
- mindspore/ops/auto_generate/gen_ops_def.py +5653 -0
- mindspore/ops/auto_generate/gen_ops_prim.py +11623 -0
- mindspore/ops/auto_generate/pyboost_inner_prim.py +359 -0
- mindspore/ops/composite/__init__.py +5 -2
- mindspore/ops/composite/base.py +118 -17
- mindspore/ops/composite/math_ops.py +9 -48
- mindspore/ops/composite/multitype_ops/_compile_utils.py +168 -602
- mindspore/ops/composite/multitype_ops/_constexpr_utils.py +24 -133
- 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 +54 -0
- mindspore/ops/extend/array_func.py +259 -0
- mindspore/ops/extend/math_func.py +76 -0
- mindspore/ops/extend/nn_func.py +384 -0
- mindspore/ops/function/__init__.py +37 -12
- mindspore/ops/function/array_func.py +702 -1867
- 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 +24 -17
- mindspore/ops/function/image_func.py +27 -21
- mindspore/ops/function/linalg_func.py +35 -68
- mindspore/ops/function/math_func.py +639 -2531
- mindspore/ops/function/nn_func.py +1274 -832
- mindspore/ops/function/other_func.py +4 -5
- mindspore/ops/function/parameter_func.py +5 -93
- mindspore/ops/function/random_func.py +84 -71
- 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 +57 -63
- mindspore/ops/op_info_register.py +16 -43
- mindspore/ops/operations/__init__.py +19 -20
- mindspore/ops/operations/_grad_ops.py +20 -828
- mindspore/ops/operations/_inner_ops.py +180 -288
- mindspore/ops/operations/_scalar_ops.py +5 -480
- mindspore/ops/operations/_sequence_ops.py +6 -36
- mindspore/ops/operations/array_ops.py +83 -2697
- mindspore/ops/operations/comm_ops.py +38 -46
- mindspore/ops/operations/custom_ops.py +14 -96
- mindspore/ops/operations/debug_ops.py +100 -31
- mindspore/ops/operations/image_ops.py +1 -217
- mindspore/ops/operations/inner_ops.py +3 -38
- mindspore/ops/operations/linalg_ops.py +1 -49
- mindspore/{rewrite/ast_transformers → ops/operations/manually_defined}/__init__.py +11 -4
- mindspore/ops/operations/manually_defined/_inner.py +61 -0
- mindspore/ops/operations/manually_defined/ops_def.py +1716 -0
- mindspore/ops/operations/math_ops.py +581 -4629
- mindspore/ops/operations/nn_ops.py +260 -1941
- mindspore/ops/operations/other_ops.py +50 -42
- mindspore/ops/operations/random_ops.py +3 -52
- mindspore/ops/operations/sparse_ops.py +3 -3
- mindspore/ops/primitive.py +196 -96
- mindspore/ops_generate/__init__.py +27 -0
- mindspore/ops_generate/arg_dtype_cast.py +257 -0
- mindspore/ops_generate/arg_handler.py +171 -0
- mindspore/ops_generate/gen_aclnn_implement.py +266 -0
- mindspore/ops_generate/gen_ops.py +1062 -0
- mindspore/ops_generate/gen_ops_inner_prim.py +131 -0
- mindspore/ops_generate/gen_pyboost_func.py +939 -0
- mindspore/ops_generate/gen_utils.py +188 -0
- mindspore/ops_generate/op_proto.py +138 -0
- mindspore/ops_generate/pyboost_utils.py +349 -0
- mindspore/ops_generate/template.py +238 -0
- mindspore/parallel/__init__.py +6 -4
- mindspore/parallel/_auto_parallel_context.py +52 -2
- 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 +19 -7
- 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 +1 -1
- mindspore/parallel/_utils.py +147 -6
- mindspore/parallel/algo_parameter_config.py +6 -6
- mindspore/parallel/checkpoint_transform.py +180 -24
- mindspore/parallel/cluster/__init__.py +15 -0
- mindspore/parallel/cluster/process_entity/__init__.py +18 -0
- mindspore/parallel/cluster/process_entity/_api.py +345 -0
- mindspore/parallel/cluster/process_entity/_utils.py +116 -0
- mindspore/parallel/cluster/run.py +139 -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 +99 -2
- mindspore/profiler/common/util.py +20 -0
- mindspore/profiler/envprofiling.py +1 -1
- mindspore/{_extends/parallel_compile/tbe_compiler → profiler/parser/ascend_analysis}/__init__.py +1 -1
- mindspore/profiler/parser/ascend_analysis/constant.py +66 -0
- mindspore/profiler/parser/ascend_analysis/file_manager.py +77 -0
- mindspore/profiler/parser/ascend_analysis/function_event.py +146 -0
- mindspore/profiler/parser/ascend_analysis/fwk_cann_parser.py +109 -0
- mindspore/profiler/parser/ascend_analysis/fwk_file_parser.py +80 -0
- mindspore/profiler/parser/ascend_analysis/msprof_timeline_parser.py +52 -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 +59 -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 +25 -277
- mindspore/profiler/parser/ascend_msprof_exporter.py +112 -132
- 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 +294 -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/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 +305 -167
- mindspore/rewrite/__init__.py +2 -13
- mindspore/rewrite/api/node.py +121 -35
- 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 +635 -413
- mindspore/rewrite/parsers/attribute_parser.py +3 -4
- mindspore/rewrite/parsers/class_def_parser.py +107 -144
- 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/scipy/__init__.py +2 -1
- mindspore/scipy/fft.py +133 -0
- mindspore/scipy/linalg.py +140 -55
- mindspore/scipy/ops.py +15 -71
- mindspore/scipy/ops_grad.py +5 -34
- mindspore/scipy/optimize/line_search.py +2 -2
- mindspore/scipy/optimize/minimize.py +1 -1
- mindspore/train/__init__.py +3 -2
- mindspore/train/_utils.py +178 -4
- mindspore/train/amp.py +167 -245
- mindspore/train/anf_ir_pb2.py +8 -2
- mindspore/train/callback/_backup_and_restore.py +4 -4
- mindspore/train/callback/_callback.py +4 -4
- mindspore/train/callback/_checkpoint.py +39 -13
- mindspore/train/callback/_early_stop.py +2 -2
- mindspore/train/callback/_landscape.py +14 -8
- mindspore/train/callback/_loss_monitor.py +2 -2
- 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 +2 -2
- mindspore/train/data_sink.py +1 -1
- mindspore/train/dataset_helper.py +18 -4
- 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 +24 -22
- mindspore/train/serialization.py +257 -133
- mindspore/train/summary/summary_record.py +51 -28
- mindspore/train/train_thor/convert_utils.py +3 -3
- mindspore/version.py +1 -1
- {mindspore-2.2.14.dist-info → mindspore-2.3.0rc2.dist-info}/METADATA +2 -2
- {mindspore-2.2.14.dist-info → mindspore-2.3.0rc2.dist-info}/RECORD +534 -1066
- {mindspore-2.2.14.dist-info → mindspore-2.3.0rc2.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/config/super_bar_config.json +0 -544
- mindspore/gen_ops.py +0 -273
- mindspore/lib/plugin/ascend/custom_aicpu_ops/op_impl/cpu/aicpu_kernel/impl/libcust_aicpu_kernels.so +0 -0
- mindspore/lib/plugin/ascend/libmindspore_aicpu_kernels.so +0 -0
- 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 → mindspore-2.3.0rc2.dist-info}/WHEEL +0 -0
- {mindspore-2.2.14.dist-info → mindspore-2.3.0rc2.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,63 @@ 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.
|
|
42
|
+
from mindspore.ops.operations.nn_ops import LayerNormExt
|
|
42
43
|
from mindspore.ops.operations._sequence_ops import TupleToTensor, TensorToTuple, ListToTensor
|
|
43
44
|
from mindspore.common.api import _function_forbid_reuse
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
from mindspore.ops.auto_generate import log_softmax, dense, prelu, celu, relu, fast_gelu, silu, elu, sigmoid, relu6
|
|
46
|
+
from mindspore.ops.auto_generate.gen_ops_prim import GroupNorm
|
|
47
|
+
from mindspore.ops.auto_generate import (reflection_pad_1d_op, reflection_pad_2d_op, reflection_pad_3d_op,
|
|
48
|
+
replication_pad_1d_op, replication_pad_2d_op, replication_pad_3d_op,
|
|
49
|
+
constant_pad_nd_op, dropout_ext_op)
|
|
50
|
+
from mindspore.ops.auto_generate.gen_ops_prim import embedding_op, Convolution
|
|
51
|
+
from mindspore.nn.generator import default_generator
|
|
52
|
+
|
|
53
|
+
abs_ = P.Abs()
|
|
54
|
+
add_ = P.Add()
|
|
55
|
+
bias_add_ = P.BiasAdd()
|
|
56
|
+
cast_ = P.Cast()
|
|
57
|
+
div_ = P.Div()
|
|
58
|
+
dtype_ = P.DType()
|
|
59
|
+
equal_ = P.Equal()
|
|
60
|
+
erf_ = P.Erf()
|
|
61
|
+
exp_ = P.Exp()
|
|
62
|
+
expand_dims_ = P.ExpandDims()
|
|
63
|
+
fillv2_ = P.FillV2()
|
|
64
|
+
gather_ = P.Gather()
|
|
65
|
+
gather_d_ = P.GatherD()
|
|
66
|
+
gelu_ = P.GeLU()
|
|
67
|
+
greater_ = P.Greater()
|
|
48
68
|
hardswish_ = P.HSwish()
|
|
69
|
+
less_ = P.Less()
|
|
70
|
+
list_to_tensor_ = ListToTensor()
|
|
71
|
+
log_ = P.Log()
|
|
72
|
+
matmul_ = P.MatMul()
|
|
73
|
+
maximum_ = P.Maximum()
|
|
74
|
+
minimum_ = P.Minimum()
|
|
49
75
|
mish_ = NN_OPS.Mish()
|
|
50
|
-
|
|
76
|
+
mul_ = P.Mul()
|
|
77
|
+
neg_ = P.Neg()
|
|
78
|
+
ones_like_ = P.OnesLike()
|
|
79
|
+
reduce_mean_ = P.ReduceMean()
|
|
80
|
+
reduce_sum_ = P.ReduceSum()
|
|
81
|
+
reshape_ = P.Reshape()
|
|
51
82
|
scalar_to_tensor_ = P.ScalarToTensor()
|
|
52
|
-
|
|
53
|
-
|
|
83
|
+
select_ = P.Select()
|
|
84
|
+
selu_ = NN_OPS.SeLU()
|
|
85
|
+
shape_ = P.Shape()
|
|
86
|
+
sigmoid_ = P.Sigmoid()
|
|
87
|
+
sign_ = P.Sign()
|
|
88
|
+
slice_ = P.Slice()
|
|
89
|
+
softplus_ = P.Softplus()
|
|
90
|
+
softsign_ = P.Softsign()
|
|
91
|
+
sqrt_ = P.Sqrt()
|
|
92
|
+
square_ = P.Square()
|
|
93
|
+
sub_ = P.Sub()
|
|
94
|
+
tensor_shape_ = P.TensorShape()
|
|
54
95
|
tensor_to_tuple_ = TensorToTuple()
|
|
55
|
-
|
|
56
|
-
|
|
96
|
+
transpose_ = P.Transpose()
|
|
97
|
+
tuple_to_tensor_ = TupleToTensor()
|
|
98
|
+
|
|
57
99
|
check_positive_int_const = validator.check_positive_int
|
|
58
100
|
check_positive_int_sequence_const = validator.check_positive_int_sequence
|
|
59
101
|
check_positive_float_const = validator.check_positive_float
|
|
@@ -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,81 @@ 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 `kernel_size` will be used. Default: ``None``.
|
|
544
|
+
|
|
545
|
+
Returns:
|
|
546
|
+
Tensor, with shape :math:`(N, C, H_{out}, W_{out})`.
|
|
547
|
+
|
|
548
|
+
.. math::
|
|
549
|
+
|
|
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
|
+
|
|
553
|
+
Raises:
|
|
554
|
+
TypeError: If `input` is not a Tensor.
|
|
555
|
+
TypeError: If `kernel_size` or `stride` is neither int nor tuple.
|
|
556
|
+
TypeError: If `ceil_mode` or `count_include_pad` is not a bool.
|
|
557
|
+
TypeError: If `divisor_override` is not an int.
|
|
558
|
+
ValueError: If length of shape of `input` is not equal to `4` or `3`.
|
|
559
|
+
ValueError: If `kernel_size` or `stride` is less than 1.
|
|
560
|
+
ValueError: If `kernel_size` or `stride` is a tuple whose length is not equal to `2` or `1`.
|
|
561
|
+
ValueError: If `padding` is neither a int nor a tuple whose length is equal to `2` or `1`.
|
|
562
|
+
ValueError: If value of `padding` is less than `0`.
|
|
563
|
+
|
|
564
|
+
Supported Platforms:
|
|
565
|
+
``Ascend``
|
|
566
|
+
|
|
567
|
+
Examples:
|
|
568
|
+
>>> import mindspore
|
|
569
|
+
>>> import numpy as np
|
|
570
|
+
>>> from mindspore import Tensor, mint
|
|
571
|
+
>>> x = Tensor(np.arange(1 * 3 * 3 * 4).reshape(1, 3, 3, 4), mindspore.float32)
|
|
572
|
+
>>> output = mint.avg_pool2d(x, kernel_size=2, stride=1)
|
|
573
|
+
>>> print(output)
|
|
574
|
+
[[[[ 2.5 3.5 4.5]
|
|
575
|
+
[ 6.5 7.5 8.5]]
|
|
576
|
+
[[14.5 15.5 16.5]
|
|
577
|
+
[18.5 19.5 20.5]]
|
|
578
|
+
[[26.5 27.5 28.5]
|
|
579
|
+
[30.5 31.5 32.5]]]]
|
|
580
|
+
"""
|
|
581
|
+
if stride is None:
|
|
582
|
+
stride = kernel_size
|
|
583
|
+
return _get_cache_prim(ops.auto_generate.AvgPool2D)()(input, kernel_size, stride, padding,
|
|
584
|
+
ceil_mode, count_include_pad, divisor_override)
|
|
585
|
+
|
|
586
|
+
|
|
486
587
|
def _check_avg_pool3d_padding(padding):
|
|
487
588
|
"""Check the padding value in avg_pool3d op."""
|
|
488
589
|
if isinstance(padding, int):
|
|
@@ -537,7 +638,7 @@ def avg_pool3d(input_x, kernel_size=1, stride=1, padding=0, ceil_mode=False, cou
|
|
|
537
638
|
Tensor, with shape :math:`(N, C, D_{out}, H_{out}, W_{out})`. Has the same data type with `input_x`.
|
|
538
639
|
|
|
539
640
|
Raises:
|
|
540
|
-
TypeError: If `input_x` is not
|
|
641
|
+
TypeError: If `input_x` is not a Tensor.
|
|
541
642
|
TypeError: If `kernel_size`, `stride` or `padding` is neither an int not a tuple.
|
|
542
643
|
TypeError: If `ceil_mode` or `count_include_pad` is not a bool.
|
|
543
644
|
TypeError: If `divisor_override` is not an int.
|
|
@@ -563,9 +664,6 @@ def avg_pool3d(input_x, kernel_size=1, stride=1, padding=0, ceil_mode=False, cou
|
|
|
563
664
|
if not isinstance(input_x, (Tensor, Tensor_)):
|
|
564
665
|
raise TypeError("For avg_pool3d, the input input_x must be tensor")
|
|
565
666
|
|
|
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
667
|
_check_avg_pool3d_padding(padding)
|
|
570
668
|
|
|
571
669
|
avg_pool_op = _get_cache_prim(P.AvgPool3D)(kernel_size=kernel_size,
|
|
@@ -638,7 +736,7 @@ def adaptive_max_pool1d(input, output_size):
|
|
|
638
736
|
_check_adaptive_max_pool1d_output_size(output_size)
|
|
639
737
|
|
|
640
738
|
x_in_shape = input.shape
|
|
641
|
-
x_dtype =
|
|
739
|
+
x_dtype = dtype_(input)
|
|
642
740
|
|
|
643
741
|
if len(x_in_shape) != 3:
|
|
644
742
|
raise ValueError(f"For adaptive_max_pool1d input must have 3 dim, but got {len(x_in_shape)}.")
|
|
@@ -657,18 +755,14 @@ def adaptive_max_pool1d(input, output_size):
|
|
|
657
755
|
raise TypeError(f"For adaptive_max_pool1d, the input dtype must be float16 or float32, "
|
|
658
756
|
f"but got {x_dtype}.")
|
|
659
757
|
|
|
660
|
-
expand_ = _get_cache_prim(P.ExpandDims)()
|
|
661
758
|
squeeze_ = _get_cache_prim(P.Squeeze)(2)
|
|
662
|
-
|
|
663
759
|
width = x_in_shape[2]
|
|
664
760
|
stride = width // output_size
|
|
665
761
|
kernel_size = width - (output_size - 1) * stride
|
|
666
762
|
stride = (1, width // output_size)
|
|
667
763
|
kernel_size = (1, kernel_size)
|
|
668
|
-
|
|
669
764
|
max_pool_ = _get_cache_prim(NN_OPS.MaxPool)(kernel_size=kernel_size, strides=stride)
|
|
670
|
-
|
|
671
|
-
input = expand_(input, 2)
|
|
765
|
+
input = expand_dims_(input, 2)
|
|
672
766
|
input = max_pool_(input)
|
|
673
767
|
input = squeeze_(input)
|
|
674
768
|
|
|
@@ -807,6 +901,8 @@ def adaptive_max_pool3d(input, output_size, return_indices=False):
|
|
|
807
901
|
>>> print(output[1].asnumpy())
|
|
808
902
|
[[[[33 35]]]]
|
|
809
903
|
"""
|
|
904
|
+
if isinstance(output_size, int):
|
|
905
|
+
output_size = (output_size, output_size, output_size)
|
|
810
906
|
adaptive_max_pool3d_ = _get_cache_prim(NN_OPS.AdaptiveMaxPool3D)()
|
|
811
907
|
output_size_ = Tensor(output_size, dtype=mstype.int32)
|
|
812
908
|
out = adaptive_max_pool3d_(input, output_size_)
|
|
@@ -814,18 +910,6 @@ def adaptive_max_pool3d(input, output_size, return_indices=False):
|
|
|
814
910
|
return output
|
|
815
911
|
|
|
816
912
|
|
|
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
913
|
def max_unpool1d(x, indices, kernel_size, stride=None, padding=0, output_size=None):
|
|
830
914
|
r"""
|
|
831
915
|
Computes the inverse of `max_pool1d`.
|
|
@@ -836,7 +920,7 @@ def max_unpool1d(x, indices, kernel_size, stride=None, padding=0, output_size=No
|
|
|
836
920
|
|
|
837
921
|
.. math::
|
|
838
922
|
\begin{array}{ll} \\
|
|
839
|
-
H_{out} = (
|
|
923
|
+
H_{out} = (H_{in} - 1) \times stride[0] - 2 \times padding[0] + kernel\_size[0] \\
|
|
840
924
|
\end{array}
|
|
841
925
|
|
|
842
926
|
Args:
|
|
@@ -885,13 +969,8 @@ def max_unpool1d(x, indices, kernel_size, stride=None, padding=0, output_size=No
|
|
|
885
969
|
if stride is None:
|
|
886
970
|
stride = kernel_size
|
|
887
971
|
|
|
888
|
-
|
|
889
|
-
x_shape = shape(x)
|
|
890
|
-
indices_shape = shape(indices)
|
|
972
|
+
x_shape = shape_(x)
|
|
891
973
|
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
974
|
|
|
896
975
|
if output_size is None:
|
|
897
976
|
output_size = ()
|
|
@@ -1009,13 +1088,8 @@ def max_unpool2d(x, indices, kernel_size, stride=None, padding=0, output_size=No
|
|
|
1009
1088
|
if stride is None:
|
|
1010
1089
|
stride = kernel_size
|
|
1011
1090
|
|
|
1012
|
-
|
|
1013
|
-
x_shape = shape(x)
|
|
1014
|
-
indices_shape = shape(indices)
|
|
1091
|
+
x_shape = shape_(x)
|
|
1015
1092
|
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
1093
|
|
|
1020
1094
|
if output_size is None:
|
|
1021
1095
|
output_size = ()
|
|
@@ -1118,12 +1192,8 @@ def max_unpool3d(x, indices, kernel_size, stride=None, padding=0, output_size=No
|
|
|
1118
1192
|
if stride is None:
|
|
1119
1193
|
stride = kernel_size
|
|
1120
1194
|
|
|
1121
|
-
x_shape =
|
|
1122
|
-
indices_shape = P.Shape()(indices)
|
|
1195
|
+
x_shape = shape_(x)
|
|
1123
1196
|
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
1197
|
|
|
1128
1198
|
if output_size is None:
|
|
1129
1199
|
output_size = ()
|
|
@@ -1294,47 +1364,48 @@ def dropout(input, p=0.5, training=True, seed=None):
|
|
|
1294
1364
|
return out
|
|
1295
1365
|
|
|
1296
1366
|
|
|
1297
|
-
|
|
1367
|
+
@_function_forbid_reuse
|
|
1368
|
+
def dropout_ext(input, p=0.5, training=True, seed=None):
|
|
1298
1369
|
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.
|
|
1370
|
+
During training, randomly zeroes some of the elements of the input tensor
|
|
1371
|
+
with probability `p` from a Bernoulli distribution. It plays the role of reducing neuron correlation and
|
|
1372
|
+
avoid overfitting. And the return will be multiplied by :math:`\frac{1}{1-p}` during training.
|
|
1373
|
+
During the reasoning, this operation returns the same Tensor as the `x`.
|
|
1310
1374
|
|
|
1311
1375
|
Args:
|
|
1312
|
-
|
|
1313
|
-
|
|
1376
|
+
input (Tensor): The input Tensor of shape :math:`(*, N)`, with data type of float16, float32 or float64.
|
|
1377
|
+
p (float, optional): The dropping rate, between 0 and 1, e.g. p = 0.1,
|
|
1378
|
+
means dropping out 10% of input units. Default: ``0.5`` .
|
|
1379
|
+
training (bool): Apply dropout_ext if is True. Default: ``True``.
|
|
1380
|
+
seed (int, optional): Seed is used as entropy source for Random number engines generating pseudo-random numbers.
|
|
1381
|
+
Default: ``None`` , which will be treated as ``0`` .
|
|
1314
1382
|
|
|
1315
1383
|
Returns:
|
|
1316
|
-
Tensor,
|
|
1384
|
+
- **output** (Tensor) - Zeroed tensor, with the same shape and data type as `input`.
|
|
1317
1385
|
|
|
1318
1386
|
Raises:
|
|
1319
|
-
TypeError: If `
|
|
1320
|
-
TypeError: If `
|
|
1321
|
-
TypeError: If
|
|
1322
|
-
ValueError: If `alpha` has the value of 0.
|
|
1387
|
+
TypeError: If `p` is not a float.
|
|
1388
|
+
TypeError: If dtype of `input` is not float16, float32 or float64.
|
|
1389
|
+
TypeError: If `input` is not a Tensor.
|
|
1323
1390
|
|
|
1324
1391
|
Supported Platforms:
|
|
1325
|
-
``Ascend``
|
|
1392
|
+
``Ascend``
|
|
1326
1393
|
|
|
1327
1394
|
Examples:
|
|
1328
1395
|
>>> import mindspore
|
|
1329
|
-
>>> import numpy as np
|
|
1330
1396
|
>>> from mindspore import Tensor, ops
|
|
1331
|
-
>>>
|
|
1332
|
-
>>> output = ops.
|
|
1333
|
-
>>> print(output)
|
|
1334
|
-
|
|
1397
|
+
>>> input = Tensor(((20, 16), (50, 50)), mindspore.float32)
|
|
1398
|
+
>>> output = ops.dropout_ext(input, p=0.5)
|
|
1399
|
+
>>> print(output.shape)
|
|
1400
|
+
(2, 2)
|
|
1335
1401
|
"""
|
|
1336
|
-
|
|
1337
|
-
|
|
1402
|
+
check_bool_const(training, "training", "dropout_ext")
|
|
1403
|
+
if training is False:
|
|
1404
|
+
return input
|
|
1405
|
+
generator = default_generator()
|
|
1406
|
+
seed, offset = generator(1)
|
|
1407
|
+
out, _ = dropout_ext_op(input, p, seed, offset)
|
|
1408
|
+
return out
|
|
1338
1409
|
|
|
1339
1410
|
|
|
1340
1411
|
def dropout1d(input, p=0.5, training=True):
|
|
@@ -1520,42 +1591,6 @@ def dropout3d(input, p=0.5, training=True):
|
|
|
1520
1591
|
return out
|
|
1521
1592
|
|
|
1522
1593
|
|
|
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
1594
|
@_primexpr
|
|
1560
1595
|
def _check_float_range_inc_neither(arg_value, lower_limit, upper_limit, arg_name=None, prim_name=None):
|
|
1561
1596
|
"""
|
|
@@ -1574,7 +1609,7 @@ def _check_fractional_output_size_ratio(output_size, output_ratio, cls_name):
|
|
|
1574
1609
|
def fractional_max_pool2d(input, kernel_size, output_size=None, output_ratio=None, return_indices=False,
|
|
1575
1610
|
_random_samples=None):
|
|
1576
1611
|
r"""
|
|
1577
|
-
Applies the 2D FractionalMaxPool
|
|
1612
|
+
Applies the 2D FractionalMaxPool operation over `input`. The output Tensor shape can be determined by either
|
|
1578
1613
|
`output_size` or `output_ratio`, and the step size is determined by `_random_samples`. `output_size` will take
|
|
1579
1614
|
effect when `output_size` and `output_ratio` are set at the same time.
|
|
1580
1615
|
And `output_size` and `output_ratio` can not be ``None`` at the same time.
|
|
@@ -1686,7 +1721,7 @@ def fractional_max_pool2d(input, kernel_size, output_size=None, output_ratio=Non
|
|
|
1686
1721
|
def fractional_max_pool3d(input, kernel_size, output_size=None, output_ratio=None, return_indices=False,
|
|
1687
1722
|
_random_samples=None):
|
|
1688
1723
|
r"""
|
|
1689
|
-
Applies the 3D FractionalMaxPool
|
|
1724
|
+
Applies the 3D FractionalMaxPool operation over `input`. The output Tensor shape can be determined by either
|
|
1690
1725
|
`output_size` or `output_ratio`, and the step size is determined by `_random_samples`. `output_size` will take
|
|
1691
1726
|
effect when `output_size` and `output_ratio` are set at the same time.
|
|
1692
1727
|
And `output_size` and `output_ratio` can not be ``None`` at the same time.
|
|
@@ -1707,7 +1742,7 @@ def fractional_max_pool3d(input, kernel_size, output_size=None, output_ratio=Non
|
|
|
1707
1742
|
is an int number that represents depth, height and width of the kernel, or a tuple
|
|
1708
1743
|
of three int numbers that represent depth, height and width respectively.
|
|
1709
1744
|
The value must be a positive integer.
|
|
1710
|
-
output_size (Union[int, tuple[int]], optional): The
|
|
1745
|
+
output_size (Union[int, tuple[int]], optional): The shape of the target `output_size`,
|
|
1711
1746
|
is an int number that represents depth, height and width, or a tuple
|
|
1712
1747
|
of three int numbers that represent depth, height and width respectively.
|
|
1713
1748
|
The value must be a positive integer.
|
|
@@ -1813,10 +1848,10 @@ def kl_div(logits, labels, reduction='mean'):
|
|
|
1813
1848
|
|
|
1814
1849
|
.. math::
|
|
1815
1850
|
\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'.}
|
|
1851
|
+
L(x, target), & \text{if reduction} = \text{'none';}\\
|
|
1852
|
+
\operatorname{mean}(L(x, target)), & \text{if reduction} = \text{'mean';}\\
|
|
1853
|
+
\operatorname{sum}(L(x, target)) / x.\operatorname{shape}[0], & \text{if reduction} = \text{'batchmean';}\\
|
|
1854
|
+
\operatorname{sum}(L(x, target)), & \text{if reduction} = \text{'sum'.}
|
|
1820
1855
|
\end{cases}
|
|
1821
1856
|
|
|
1822
1857
|
where :math:`x` represents `logits`.
|
|
@@ -1826,7 +1861,7 @@ def kl_div(logits, labels, reduction='mean'):
|
|
|
1826
1861
|
Note:
|
|
1827
1862
|
- Currently it does not support float64 input on `Ascend`.
|
|
1828
1863
|
- The output aligns with the mathematical definition of Kullback-Leibler divergence
|
|
1829
|
-
only when `reduction` is set to 'batchmean'
|
|
1864
|
+
only when `reduction` is set to ``'batchmean'``.
|
|
1830
1865
|
|
|
1831
1866
|
Args:
|
|
1832
1867
|
logits (Tensor): The input Tensor. The data type must be float16, float32 or float64.
|
|
@@ -1834,6 +1869,11 @@ def kl_div(logits, labels, reduction='mean'):
|
|
|
1834
1869
|
reduction (str): Specifies the reduction to be applied to the output.
|
|
1835
1870
|
Its value must be one of ``'none'`` , ``'mean'`` , ``'batchmean'`` or ``'sum'`` . Default: ``'mean'`` .
|
|
1836
1871
|
|
|
1872
|
+
- ``'none'``: no reduction will be applied.
|
|
1873
|
+
- ``'mean'``: compute and return the mean of elements in the output.
|
|
1874
|
+
- ``'sum'``: the output elements will be summed.
|
|
1875
|
+
- ``'batchmean'``: the summed output elements divided by batch size.
|
|
1876
|
+
|
|
1837
1877
|
Returns:
|
|
1838
1878
|
Tensor or Scalar, if `reduction` is ``'none'``, then output is a tensor and has the same shape as `logits`.
|
|
1839
1879
|
Otherwise, it is a scalar.
|
|
@@ -1841,7 +1881,7 @@ def kl_div(logits, labels, reduction='mean'):
|
|
|
1841
1881
|
Raises:
|
|
1842
1882
|
TypeError: If `reduction` is not a str.
|
|
1843
1883
|
TypeError: If neither `logits` nor `labels` is a Tensor.
|
|
1844
|
-
TypeError: If dtype of `logits` or `labels` is not
|
|
1884
|
+
TypeError: If dtype of `logits` or `labels` is not the supported type.
|
|
1845
1885
|
|
|
1846
1886
|
Supported Platforms:
|
|
1847
1887
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -1861,20 +1901,20 @@ def kl_div(logits, labels, reduction='mean'):
|
|
|
1861
1901
|
f"'['none', 'mean', 'batchmean', 'sum']', but got '{reduction}'.")
|
|
1862
1902
|
|
|
1863
1903
|
if reduction == 'batchmean':
|
|
1864
|
-
kl_div_sum = P.KLDivLoss(reduction='sum')(logits, labels)
|
|
1865
|
-
shape =
|
|
1904
|
+
kl_div_sum = _get_cache_prim(P.KLDivLoss)(reduction='sum')(logits, labels)
|
|
1905
|
+
shape = shape_(logits)
|
|
1866
1906
|
batch_size = shape[0]
|
|
1867
1907
|
return kl_div_sum / batch_size
|
|
1868
1908
|
|
|
1869
1909
|
if reduction == 'mean':
|
|
1870
|
-
kl_div_sum = P.KLDivLoss(reduction='sum')(logits, labels)
|
|
1871
|
-
shape =
|
|
1910
|
+
kl_div_sum = _get_cache_prim(P.KLDivLoss)(reduction='sum')(logits, labels)
|
|
1911
|
+
shape = shape_(logits)
|
|
1872
1912
|
total_size = 1
|
|
1873
1913
|
for dim in shape:
|
|
1874
1914
|
total_size = total_size * dim
|
|
1875
1915
|
return kl_div_sum / total_size
|
|
1876
1916
|
|
|
1877
|
-
return P.KLDivLoss(reduction=reduction)(logits, labels)
|
|
1917
|
+
return _get_cache_prim(P.KLDivLoss)(reduction=reduction)(logits, labels)
|
|
1878
1918
|
|
|
1879
1919
|
|
|
1880
1920
|
def hardshrink(x, lambd=0.5):
|
|
@@ -1891,9 +1931,15 @@ def hardshrink(x, lambd=0.5):
|
|
|
1891
1931
|
0, & \text{ otherwise }
|
|
1892
1932
|
\end{cases}
|
|
1893
1933
|
|
|
1934
|
+
HShrink Activation Function Graph:
|
|
1935
|
+
|
|
1936
|
+
.. image:: ../images/HShrink.png
|
|
1937
|
+
:align: center
|
|
1938
|
+
|
|
1894
1939
|
Args:
|
|
1895
1940
|
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.
|
|
1941
|
+
lambd (float, optional): The threshold :math:`\lambda` defined by the Hard Shrink formula.
|
|
1942
|
+
Default: ``0.5`` .
|
|
1897
1943
|
|
|
1898
1944
|
Returns:
|
|
1899
1945
|
Tensor, has the same data type and shape as the input `x`.
|
|
@@ -1995,7 +2041,7 @@ def flip(input, dims):
|
|
|
1995
2041
|
Raises:
|
|
1996
2042
|
TypeError: If the input is not a tensor.
|
|
1997
2043
|
ValueError: If `dims` is None.
|
|
1998
|
-
ValueError: If `dims` is not a tuple of ints.
|
|
2044
|
+
ValueError: If `dims` is not a list/tuple of ints.
|
|
1999
2045
|
|
|
2000
2046
|
Supported Platforms:
|
|
2001
2047
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -2105,7 +2151,7 @@ def is_floating_point(input):
|
|
|
2105
2151
|
>>> print(output2)
|
|
2106
2152
|
False
|
|
2107
2153
|
"""
|
|
2108
|
-
return input.dtype in [mstype.float32, mstype.float16, mstype.float64]
|
|
2154
|
+
return input.dtype in [mstype.float32, mstype.bfloat16, mstype.float16, mstype.float64]
|
|
2109
2155
|
|
|
2110
2156
|
|
|
2111
2157
|
def hardswish(x):
|
|
@@ -2120,6 +2166,11 @@ def hardswish(x):
|
|
|
2120
2166
|
|
|
2121
2167
|
where :math:`x_i` is an element of the input Tensor.
|
|
2122
2168
|
|
|
2169
|
+
HSwish Activation Function Graph:
|
|
2170
|
+
|
|
2171
|
+
.. image:: ../images/HSwish.png
|
|
2172
|
+
:align: center
|
|
2173
|
+
|
|
2123
2174
|
Args:
|
|
2124
2175
|
x (Tensor): The input to compute the Hard Swish.
|
|
2125
2176
|
|
|
@@ -2151,15 +2202,25 @@ def _is_dim_unknown(shape):
|
|
|
2151
2202
|
|
|
2152
2203
|
@_primexpr
|
|
2153
2204
|
def _interploate_make_tuple(rank, value):
|
|
2205
|
+
"""
|
|
2206
|
+
make tuple in dynamic scenarios
|
|
2207
|
+
"""
|
|
2154
2208
|
s = tuple_to_tensor_((rank,), mstype.int32)
|
|
2155
|
-
v =
|
|
2156
|
-
|
|
2209
|
+
v = None
|
|
2210
|
+
if isinstance(value, int):
|
|
2211
|
+
v = F.scalar_to_tensor(value, mstype.int64)
|
|
2212
|
+
else:
|
|
2213
|
+
v = F.scalar_to_tensor(value, mstype.float32)
|
|
2214
|
+
t = fillv2_(s, v)
|
|
2157
2215
|
out = tensor_to_tuple_(t)
|
|
2158
2216
|
return out
|
|
2159
2217
|
|
|
2160
2218
|
|
|
2161
2219
|
@_primexpr
|
|
2162
2220
|
def _interpolate_scale_factor_convert_size(shape, scale_factor):
|
|
2221
|
+
"""
|
|
2222
|
+
convert scale_factor to size
|
|
2223
|
+
"""
|
|
2163
2224
|
x = tuple_to_tensor_(shape[2:], mstype.int64)
|
|
2164
2225
|
y = tuple_to_tensor_(scale_factor, mstype.float32)
|
|
2165
2226
|
t = x * y
|
|
@@ -2169,6 +2230,9 @@ def _interpolate_scale_factor_convert_size(shape, scale_factor):
|
|
|
2169
2230
|
|
|
2170
2231
|
|
|
2171
2232
|
def _interpolate_size_check_with_rank(size, input_rank):
|
|
2233
|
+
"""
|
|
2234
|
+
size rank check
|
|
2235
|
+
"""
|
|
2172
2236
|
if len(size) != input_rank - 2:
|
|
2173
2237
|
raise ValueError(
|
|
2174
2238
|
f"For 'interpolate', 'input' and 'size' must have the same spatial dimensions, "
|
|
@@ -2176,6 +2240,9 @@ def _interpolate_size_check_with_rank(size, input_rank):
|
|
|
2176
2240
|
|
|
2177
2241
|
|
|
2178
2242
|
def _interpolate_scale_factor_check_with_rank(scale_factor, input_rank):
|
|
2243
|
+
"""
|
|
2244
|
+
scale_factor rank check
|
|
2245
|
+
"""
|
|
2179
2246
|
if len(scale_factor) != input_rank - 2:
|
|
2180
2247
|
raise ValueError(
|
|
2181
2248
|
f"For 'interpolate', 'input' and 'scale_factor' must have the same spatial dimensions, "
|
|
@@ -2184,6 +2251,9 @@ def _interpolate_scale_factor_check_with_rank(scale_factor, input_rank):
|
|
|
2184
2251
|
|
|
2185
2252
|
|
|
2186
2253
|
def _interpolate_mode_check(mode, supported_dict):
|
|
2254
|
+
"""
|
|
2255
|
+
mode check
|
|
2256
|
+
"""
|
|
2187
2257
|
if isinstance(mode, list) or mode not in supported_dict:
|
|
2188
2258
|
raise ValueError(
|
|
2189
2259
|
f"For 'interpolate', 'mode' must be in '{list(supported_dict)}', but got {mode}"
|
|
@@ -2191,6 +2261,9 @@ def _interpolate_mode_check(mode, supported_dict):
|
|
|
2191
2261
|
|
|
2192
2262
|
|
|
2193
2263
|
def _interpolate_rank_check(input_rank, mode, supported_dict):
|
|
2264
|
+
"""
|
|
2265
|
+
rank check
|
|
2266
|
+
"""
|
|
2194
2267
|
if input_rank not in supported_dict.get(mode):
|
|
2195
2268
|
raise ValueError(
|
|
2196
2269
|
f"For 'interpolate', {mode} only support '{list(supported_dict.get(mode, {}))}'D, but got {input_rank}D"
|
|
@@ -2198,6 +2271,9 @@ def _interpolate_rank_check(input_rank, mode, supported_dict):
|
|
|
2198
2271
|
|
|
2199
2272
|
|
|
2200
2273
|
def _interpolate_scale_factor_check(scale_factor, mode, rank, supported_dict):
|
|
2274
|
+
"""
|
|
2275
|
+
scale_factor check
|
|
2276
|
+
"""
|
|
2201
2277
|
if scale_factor is not None and "scale_factor" not in supported_dict.get(
|
|
2202
2278
|
mode, {}).get(rank):
|
|
2203
2279
|
raise ValueError(
|
|
@@ -2206,6 +2282,9 @@ def _interpolate_scale_factor_check(scale_factor, mode, rank, supported_dict):
|
|
|
2206
2282
|
|
|
2207
2283
|
|
|
2208
2284
|
def _interpolate_align_corners_mode_check(rank, mode, supported_dict):
|
|
2285
|
+
"""
|
|
2286
|
+
align_corners check
|
|
2287
|
+
"""
|
|
2209
2288
|
if "align_corners" not in supported_dict.get(mode, {}).get(rank):
|
|
2210
2289
|
raise ValueError(
|
|
2211
2290
|
f"For 'interpolate', 'align_corners' option cannot currently be set with the "
|
|
@@ -2238,17 +2317,22 @@ def interpolate(input,
|
|
|
2238
2317
|
'area', 'nearest-exact'(matches Scikit-Image and PIL nearest neighbours interpolation algorithms and fixes
|
|
2239
2318
|
knows issues with `nearest`, 3D and 4D). Default: ``"nearest"`` .
|
|
2240
2319
|
|
|
2241
|
-
align_corners (bool):
|
|
2242
|
-
|
|
2243
|
-
Default: ``None`` .
|
|
2320
|
+
align_corners (bool): Whether to use corner alignment for coordinate mapping. Assuming a transformation is
|
|
2321
|
+
applied to the input Tensor along the x-axis, the specific calculation formula is as follows:
|
|
2244
2322
|
|
|
2245
2323
|
.. code-block::
|
|
2246
2324
|
|
|
2247
|
-
|
|
2325
|
+
ori_i = new_length != 1 ? new_i * (ori_length - 1) / (new_length - 1) : 0 # 'align_corners' = True
|
|
2248
2326
|
|
|
2249
|
-
|
|
2327
|
+
ori_i = new_length > 1 ? (new_i + 0.5) * ori_length / new_length - 0.5 : 0 # 'align_corners' = False
|
|
2250
2328
|
|
|
2251
|
-
|
|
2329
|
+
Among them, :math:`ori\_length` and :math:`new\_length` represent the length of the Tensor before and after
|
|
2330
|
+
transformation along the x-axis respectively; :math:`new\_i` represents the coordinate of the i-th element
|
|
2331
|
+
along the x-axis after transformation; :math:`ori\_i` represents
|
|
2332
|
+
the corresponding coordinate of the original
|
|
2333
|
+
data along the x-axis.
|
|
2334
|
+
|
|
2335
|
+
This is only valid for ``'linear'``, ``'bilinear'``, or ``'bicubic'`` modes. Default: ``False`` .
|
|
2252
2336
|
recompute_scale_factor (bool, optional): Recalculate `scale_factor`.
|
|
2253
2337
|
If True, the parameter `size` will be calculated using the value of the `scale_factor`,
|
|
2254
2338
|
and finally scaled using the value of `size`.
|
|
@@ -2331,7 +2415,7 @@ def interpolate(input,
|
|
|
2331
2415
|
x = x.unsqueeze(-1)
|
|
2332
2416
|
x = _get_cache_prim(P.ResizeNearestNeighborV2)()(
|
|
2333
2417
|
x, size)
|
|
2334
|
-
x = P.Squeeze(-1)(x)
|
|
2418
|
+
x = _get_cache_prim(P.Squeeze)(-1)(x)
|
|
2335
2419
|
elif size is not None and x_rank == 4:
|
|
2336
2420
|
size = seq.TupleToTensor()(size[:2], mstype.int32)
|
|
2337
2421
|
x = _get_cache_prim(P.ResizeNearestNeighborV2)()(
|
|
@@ -2383,7 +2467,7 @@ def interpolate(input,
|
|
|
2383
2467
|
align_corners=False,
|
|
2384
2468
|
half_pixel_centers=True)
|
|
2385
2469
|
x = resize(x, size)
|
|
2386
|
-
x = P.Squeeze(-1)(x)
|
|
2470
|
+
x = _get_cache_prim(P.Squeeze)(-1)(x)
|
|
2387
2471
|
if x_rank == 4:
|
|
2388
2472
|
if isinstance(size, int):
|
|
2389
2473
|
size = F.scalar_to_tensor(size, mstype.int32)
|
|
@@ -2503,7 +2587,11 @@ def interpolate(input,
|
|
|
2503
2587
|
raise ValueError(
|
|
2504
2588
|
"For 'interpolate', it is incorrect to set 'recompute_scale_factor' to True"
|
|
2505
2589
|
" after specifying an explicit 'size'.")
|
|
2506
|
-
|
|
2590
|
+
if F.isconstant(shape) and F.isconstant(scale_factor):
|
|
2591
|
+
size = tuple([floor(shape[i + 2] * scale_factor[i]) for i in
|
|
2592
|
+
range(min(len(shape) - 2), len(scale_factor))])
|
|
2593
|
+
else:
|
|
2594
|
+
size = _interpolate_scale_factor_convert_size(shape, scale_factor)
|
|
2507
2595
|
scale_factor = None
|
|
2508
2596
|
else:
|
|
2509
2597
|
if dim_unknown is False:
|
|
@@ -2521,52 +2609,338 @@ def interpolate(input,
|
|
|
2521
2609
|
return resize_func.get(mode)(input, size, align_corners, scale_factor)
|
|
2522
2610
|
|
|
2523
2611
|
|
|
2524
|
-
def
|
|
2525
|
-
r"""
|
|
2526
|
-
Alias for :func:`mindspore.ops.interpolate` .
|
|
2527
|
-
|
|
2528
|
-
Supported Platforms:
|
|
2529
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
2612
|
+
def _interploate_ext_make_tuple(input, value):
|
|
2530
2613
|
"""
|
|
2531
|
-
|
|
2614
|
+
make tuple
|
|
2615
|
+
"""
|
|
2616
|
+
if isinstance(value, (list, tuple)):
|
|
2617
|
+
return value
|
|
2532
2618
|
|
|
2619
|
+
rank = F.rank(input) - 2
|
|
2620
|
+
out = None
|
|
2621
|
+
if F.isconstant(value) and F.isconstant(rank):
|
|
2622
|
+
out = tuple([value for _ in range(rank)])
|
|
2623
|
+
else:
|
|
2624
|
+
s = tuple_to_tensor_((rank,), mstype.int32)
|
|
2625
|
+
v = None
|
|
2626
|
+
if isinstance(value, int):
|
|
2627
|
+
v = F.scalar_to_tensor(value, mstype.int64)
|
|
2628
|
+
else:
|
|
2629
|
+
v = F.scalar_to_tensor(value, mstype.float32)
|
|
2630
|
+
t = fillv2_(s, v)
|
|
2631
|
+
out = tensor_to_tuple_(t)
|
|
2632
|
+
return out
|
|
2533
2633
|
|
|
2534
|
-
def softsign(x):
|
|
2535
|
-
r"""
|
|
2536
|
-
Softsign activation function.
|
|
2537
2634
|
|
|
2538
|
-
|
|
2635
|
+
def _interpolate_ext_scale_factor_convert_size(input, scale_factor):
|
|
2636
|
+
"""
|
|
2637
|
+
convert scale_factor to size
|
|
2638
|
+
"""
|
|
2639
|
+
shape = F.shape(input)
|
|
2640
|
+
size = None
|
|
2641
|
+
if F.isconstant(shape) and F.isconstant(scale_factor):
|
|
2642
|
+
size = tuple([floor(shape[i + 2] * scale_factor[i]) for i in
|
|
2643
|
+
range(min(len(shape) - 2), len(scale_factor))])
|
|
2644
|
+
else:
|
|
2645
|
+
x = tuple_to_tensor_(shape[2:], mstype.int64)
|
|
2646
|
+
y = tuple_to_tensor_(scale_factor, mstype.float32)
|
|
2647
|
+
t = x * y
|
|
2648
|
+
t = ops.TruncateDiv()(t, Tensor(1))
|
|
2649
|
+
t = ops.cast(t, mstype.int64)
|
|
2650
|
+
size = tensor_to_tuple_(t)
|
|
2651
|
+
return size
|
|
2652
|
+
|
|
2653
|
+
|
|
2654
|
+
def interpolate_ext(input,
|
|
2655
|
+
size=None,
|
|
2656
|
+
scale_factor=None,
|
|
2657
|
+
mode="nearest",
|
|
2658
|
+
align_corners=None,
|
|
2659
|
+
recompute_scale_factor=None):
|
|
2660
|
+
r"""
|
|
2661
|
+
Samples the input Tensor to the given size or scale_factor by using one of the interpolate algorithms.
|
|
2539
2662
|
|
|
2540
|
-
..
|
|
2541
|
-
|
|
2663
|
+
.. note::
|
|
2664
|
+
- In 'linear' mode, backpropagation does not support scenarios where `scale_factor` is not None
|
|
2665
|
+
and `align_corners` is False.
|
|
2542
2666
|
|
|
2543
2667
|
Args:
|
|
2544
|
-
|
|
2545
|
-
|
|
2668
|
+
input (Tensor): Tensor to be resized.
|
|
2669
|
+
Input tensor must be a 3-D, 4-D, or 5-D tensor with shape
|
|
2670
|
+
:math:`(N, C, [optional D], [optional H], W)` , with data type of float.
|
|
2671
|
+
size (Union[int, tuple[int], list[int]], optional): The target size.
|
|
2672
|
+
If size 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
|
+
scale_factor (Union[float, tuple[float], list[float]], optional): The scale factor of new size of the tensor.
|
|
2676
|
+
If scale_factor is a tuple or list, its length should be the same as the number of dimensions in input
|
|
2677
|
+
after removing the first two dimensions N, C.
|
|
2678
|
+
One and only one of size and scale_factor can be set to None. Default: ``None`` .
|
|
2679
|
+
mode (str): The sampling algorithm.
|
|
2680
|
+
One of 'nearest', 'linear' (3D only), 'bilinear' (4D only), 'trilinear' (5D only), 'bicubic' (4D only),
|
|
2681
|
+
'area', 'nearest-exact'(matches Scikit-Image and PIL nearest neighbours interpolation algorithms and fixes
|
|
2682
|
+
knows issues with `nearest`, 3D and 4D). Default: ``"nearest"`` .
|
|
2683
|
+
|
|
2684
|
+
align_corners (bool): Whether to use corner alignment for coordinate mapping. Assuming a transformation is
|
|
2685
|
+
applied to the input Tensor along the x-axis, the specific calculation formula is as follows:
|
|
2686
|
+
|
|
2687
|
+
.. code-block::
|
|
2688
|
+
|
|
2689
|
+
ori_i = new_length != 1 ? new_i * (ori_length - 1) / (new_length - 1) : 0 # 'align_corners' = True
|
|
2690
|
+
|
|
2691
|
+
ori_i = new_length > 1 ? (new_i + 0.5) * ori_length / new_length - 0.5 : 0 # 'align_corners' = False
|
|
2692
|
+
|
|
2693
|
+
Among them, :math:`ori\_length` and :math:`new\_length` represent the length of the Tensor before and after
|
|
2694
|
+
transformation along the x-axis respectively; :math:`new\_i` represents the coordinate of the i-th element
|
|
2695
|
+
along the x-axis after transformation; :math:`ori\_i` represents
|
|
2696
|
+
the corresponding coordinate of the original
|
|
2697
|
+
data along the x-axis.
|
|
2698
|
+
|
|
2699
|
+
This is only valid for ``'linear'``, ``'bilinear'``, or ``'bicubic'`` modes. Default: ``False`` .
|
|
2700
|
+
recompute_scale_factor (bool, optional): Recalculate `scale_factor`.
|
|
2701
|
+
If True, the parameter `size` will be calculated using the value of the `scale_factor`,
|
|
2702
|
+
and finally scaled using the value of `size`.
|
|
2703
|
+
If False, the value of `size` or `scale_factor` will be used for direct interpolation. Default: ``None`` .
|
|
2704
|
+
|
|
2705
|
+
.. note::
|
|
2706
|
+
The 'nearest-exact' mode is the same as the nearest-neighbor interpolation algorithm used in
|
|
2707
|
+
scikit-image and PIL. The 'nearest' mode produces the same results as the INTER_NEAREST interpolation
|
|
2708
|
+
algorithm used in OpenCV.
|
|
2709
|
+
|
|
2710
|
+
Args Support List and Supported Platforms:
|
|
2711
|
+
|
|
2712
|
+
+---------------+-----------+---------------+--------------+----------------+
|
|
2713
|
+
| mode | input.dim | align_corners | scale_factor | device |
|
|
2714
|
+
+===============+===========+===============+==============+================+
|
|
2715
|
+
| nearest | 3 | \- | √ | Ascend,GPU,CPU |
|
|
2716
|
+
+---------------+-----------+---------------+--------------+----------------+
|
|
2717
|
+
| | 4 | \- | √ | Ascend,GPU,CPU |
|
|
2718
|
+
+---------------+-----------+---------------+--------------+----------------+
|
|
2719
|
+
| | 5 | \- | √ | Ascend,GPU,CPU |
|
|
2720
|
+
+---------------+-----------+---------------+--------------+----------------+
|
|
2721
|
+
| linear | 3 | √ | √ | Ascend,GPU,CPU |
|
|
2722
|
+
+---------------+-----------+---------------+--------------+----------------+
|
|
2723
|
+
| bilinear | 4 | √ | × | Ascend,GPU,CPU |
|
|
2724
|
+
+---------------+-----------+---------------+--------------+----------------+
|
|
2725
|
+
| bicubic | 4 | √ | × | Ascend,GPU,CPU |
|
|
2726
|
+
+---------------+-----------+---------------+--------------+----------------+
|
|
2727
|
+
| area | 3 | \- | √ | Ascend,GPU,CPU |
|
|
2728
|
+
+---------------+-----------+---------------+--------------+----------------+
|
|
2729
|
+
| | 4 | \- | √ | Ascend,GPU,CPU |
|
|
2730
|
+
+---------------+-----------+---------------+--------------+----------------+
|
|
2731
|
+
| | 5 | \- | √ | Ascend,GPU,CPU |
|
|
2732
|
+
+---------------+-----------+---------------+--------------+----------------+
|
|
2733
|
+
| nearest-exact | 3 | \- | × | Ascend,CPU |
|
|
2734
|
+
+---------------+-----------+---------------+--------------+----------------+
|
|
2735
|
+
| | 4 | \- | × | Ascend,CPU |
|
|
2736
|
+
+---------------+-----------+---------------+--------------+----------------+
|
|
2737
|
+
| trilinear | 5 | √ | √ | Ascend,GPU,CPU |
|
|
2738
|
+
+---------------+-----------+---------------+--------------+----------------+
|
|
2739
|
+
|
|
2740
|
+
- `-` indicates that there is no such parameter.
|
|
2741
|
+
- `×` indicates that this parameter is not currently supported.
|
|
2742
|
+
- `√` indicates that this parameter is supported.
|
|
2546
2743
|
|
|
2547
2744
|
Returns:
|
|
2548
|
-
Tensor,
|
|
2745
|
+
Tensor, resized, whose dimensions and dtype are the same as `input`.
|
|
2549
2746
|
|
|
2550
2747
|
Raises:
|
|
2551
|
-
TypeError:
|
|
2552
|
-
|
|
2748
|
+
TypeError: `input` is not a Tensor.
|
|
2749
|
+
ValueError: Both `size` and `scale_factor` are not empty.
|
|
2750
|
+
ValueError: Both `size` and `scale_factor` are empty.
|
|
2751
|
+
ValueError: When `size` is a tuple or list, its length is not equal to `input.ndim - 2`.
|
|
2752
|
+
ValueError: When `scale_factor` is a tuple or list, its length is not equal to `input.ndim - 2`.
|
|
2753
|
+
ValueError: `mode` is not in the list of supported modes.
|
|
2754
|
+
ValueError: `input.ndim` is not in the list of supported dimensions for the corresponding mode.
|
|
2755
|
+
ValueError: `size` is not empty, `recompute_scale_factor` is not empty.
|
|
2756
|
+
ValueError: `scale_factor` is not in the corresponding list of supported values.
|
|
2757
|
+
ValueError: `align_corners` is not in the corresponding list of supported values.
|
|
2553
2758
|
|
|
2554
2759
|
Supported Platforms:
|
|
2555
2760
|
``Ascend`` ``GPU`` ``CPU``
|
|
2556
2761
|
|
|
2557
2762
|
Examples:
|
|
2558
2763
|
>>> import mindspore
|
|
2559
|
-
>>> import
|
|
2560
|
-
>>>
|
|
2561
|
-
>>>
|
|
2562
|
-
>>> output = ops.softsign(x)
|
|
2764
|
+
>>> from mindspore import Tensor, mint
|
|
2765
|
+
>>> input = Tensor([[[1, 2, 3], [4, 5, 6]]], mindspore.float32)
|
|
2766
|
+
>>> output = mint.interpolate(input, size=(6,), mode='nearest')
|
|
2563
2767
|
>>> print(output)
|
|
2564
|
-
|
|
2768
|
+
[[[1. 1. 2. 2. 3. 3.]
|
|
2769
|
+
[4. 4. 5. 5. 6. 6.]]]
|
|
2565
2770
|
"""
|
|
2566
|
-
|
|
2771
|
+
def run_nearest(x, size, align_corners=None, scale_factor=None):
|
|
2772
|
+
x_rank = F.rank(x)
|
|
2773
|
+
if x_rank == 3:
|
|
2774
|
+
x = _get_cache_prim(ops.auto_generate.UpsampleNearest1D)()(
|
|
2775
|
+
x, size, scale_factor)
|
|
2776
|
+
elif x_rank == 4:
|
|
2777
|
+
x = _get_cache_prim(ops.auto_generate.UpsampleNearest2D)()(
|
|
2778
|
+
x, size, scale_factor)
|
|
2779
|
+
else:
|
|
2780
|
+
x = _get_cache_prim(P.UpsampleNearest3D)()(x, size, scale_factor)
|
|
2781
|
+
return x
|
|
2567
2782
|
|
|
2783
|
+
def run_linear(x, size, align_corners=None, scale_factor=None):
|
|
2784
|
+
out = _get_cache_prim(
|
|
2785
|
+
ops.auto_generate.UpsampleLinear1D)()(x, size, scale_factor, align_corners)
|
|
2786
|
+
return out
|
|
2568
2787
|
|
|
2569
|
-
def
|
|
2788
|
+
def run_bilinear(x, size, align_corners=None, scale_factor=None):
|
|
2789
|
+
out = _get_cache_prim(
|
|
2790
|
+
ops.auto_generate.UpsampleBilinear2D)()(x, size, scale_factor, align_corners)
|
|
2791
|
+
return out
|
|
2792
|
+
|
|
2793
|
+
def run_trilinear(x, size, align_corners=None, scale_factor=None):
|
|
2794
|
+
resize = _get_cache_prim(P.nn_ops.UpsampleTrilinear3D)(align_corners)
|
|
2795
|
+
return resize(x, size, scale_factor)
|
|
2796
|
+
|
|
2797
|
+
def run_bicubic(x, size, align_corners=None, scale_factor=None):
|
|
2798
|
+
resize = _get_cache_prim(P.image_ops.ResizeBicubic)(
|
|
2799
|
+
align_corners=align_corners, half_pixel_centers=not align_corners)
|
|
2800
|
+
x = resize(x, size)
|
|
2801
|
+
return x
|
|
2802
|
+
|
|
2803
|
+
def run_area(x, size, align_corners=None, scale_factor=None):
|
|
2804
|
+
x_rank = F.rank(x)
|
|
2805
|
+
if x_rank == 3:
|
|
2806
|
+
x = F.adaptive_avg_pool1d(x, size[0])
|
|
2807
|
+
elif x_rank == 4:
|
|
2808
|
+
x = F.adaptive_avg_pool2d(x, tuple(size))
|
|
2809
|
+
else:
|
|
2810
|
+
x = F.adaptive_avg_pool3d(x, tuple(size))
|
|
2811
|
+
return x
|
|
2812
|
+
|
|
2813
|
+
def run_nearest_exact(x, size, align_corners=None, scale_factor=None):
|
|
2814
|
+
x_rank = F.rank(x)
|
|
2815
|
+
if x_rank == 3:
|
|
2816
|
+
size = size[:1] + (1,)
|
|
2817
|
+
# For impl of nearest 3D use 4D.
|
|
2818
|
+
x = x.unsqueeze(-1)
|
|
2819
|
+
resize = _get_cache_prim(P.ResizeNearestNeighborV2)(
|
|
2820
|
+
align_corners=False,
|
|
2821
|
+
half_pixel_centers=True)
|
|
2822
|
+
x = resize(x, size)
|
|
2823
|
+
x = _get_cache_prim(P.Squeeze)(-1)(x)
|
|
2824
|
+
if x_rank == 4:
|
|
2825
|
+
resize = _get_cache_prim(P.ResizeNearestNeighborV2)(
|
|
2826
|
+
align_corners=False,
|
|
2827
|
+
half_pixel_centers=True)
|
|
2828
|
+
x = resize(x, size)
|
|
2829
|
+
return x
|
|
2830
|
+
|
|
2831
|
+
|
|
2832
|
+
resize_funcs = {
|
|
2833
|
+
"nearest": run_nearest,
|
|
2834
|
+
"linear": run_linear,
|
|
2835
|
+
"bilinear": run_bilinear,
|
|
2836
|
+
"bicubic": run_bicubic,
|
|
2837
|
+
"trilinear": run_trilinear,
|
|
2838
|
+
"area": run_area,
|
|
2839
|
+
"nearest-exact": run_nearest_exact,
|
|
2840
|
+
}
|
|
2841
|
+
|
|
2842
|
+
# mode check
|
|
2843
|
+
if mode not in resize_funcs:
|
|
2844
|
+
raise ValueError(
|
|
2845
|
+
f"For 'interpolate', 'mode' must be in '{list(resize_funcs)}', but got {mode}"
|
|
2846
|
+
)
|
|
2847
|
+
if mode in ("nearest", "area", "nearest-exact"):
|
|
2848
|
+
if align_corners is not None:
|
|
2849
|
+
raise ValueError("align_corners option can only be set with the "
|
|
2850
|
+
"interpolating modes: linear | bilinear | bicubic | trilinear"
|
|
2851
|
+
)
|
|
2852
|
+
else:
|
|
2853
|
+
if align_corners is None:
|
|
2854
|
+
align_corners = False
|
|
2855
|
+
|
|
2856
|
+
# check for size and scale_factor
|
|
2857
|
+
if size is not None and scale_factor is not None:
|
|
2858
|
+
raise ValueError(
|
|
2859
|
+
"For 'interpolate', 'size' and 'scale_factor' cannot be set simultaneously"
|
|
2860
|
+
)
|
|
2861
|
+
if size is not None:
|
|
2862
|
+
size = _interploate_ext_make_tuple(input, size)
|
|
2863
|
+
elif scale_factor is not None:
|
|
2864
|
+
scale_factor = _interploate_ext_make_tuple(input, scale_factor)
|
|
2865
|
+
else:
|
|
2866
|
+
raise ValueError(
|
|
2867
|
+
"For 'interpolate', 'size' and 'scale_factor' cannot be both empty"
|
|
2868
|
+
)
|
|
2869
|
+
|
|
2870
|
+
# "area" mode always requires an explicit size rather than scale factor.
|
|
2871
|
+
if mode == "area" and size is None:
|
|
2872
|
+
recompute_scale_factor = True
|
|
2873
|
+
|
|
2874
|
+
# recompute_scale_factor
|
|
2875
|
+
if recompute_scale_factor is not None and recompute_scale_factor:
|
|
2876
|
+
if size is not None:
|
|
2877
|
+
raise ValueError(
|
|
2878
|
+
"For 'interpolate', it is incorrect to set 'recompute_scale_factor' to True"
|
|
2879
|
+
" after specifying an explicit 'size'.")
|
|
2880
|
+
size = _interpolate_ext_scale_factor_convert_size(input, scale_factor)
|
|
2881
|
+
scale_factor = None
|
|
2882
|
+
|
|
2883
|
+
# scale_factor
|
|
2884
|
+
if mode in ("bilinear", "bicubic", "nearest-exact"):
|
|
2885
|
+
if scale_factor is not None:
|
|
2886
|
+
raise ValueError("scale_factor option can only be set with the "
|
|
2887
|
+
"interpolating modes: nearest | linear | area | trilinear"
|
|
2888
|
+
)
|
|
2889
|
+
|
|
2890
|
+
return resize_funcs.get(mode)(input, size, align_corners, scale_factor)
|
|
2891
|
+
|
|
2892
|
+
|
|
2893
|
+
def upsample(input, size=None, scale_factor=None, mode="nearest", align_corners=None, recompute_scale_factor=None):
|
|
2894
|
+
r"""
|
|
2895
|
+
Alias for :func:`mindspore.ops.interpolate` .
|
|
2896
|
+
|
|
2897
|
+
Supported Platforms:
|
|
2898
|
+
``Ascend`` ``GPU`` ``CPU``
|
|
2899
|
+
"""
|
|
2900
|
+
return interpolate(input, size, scale_factor, mode, align_corners, recompute_scale_factor)
|
|
2901
|
+
|
|
2902
|
+
|
|
2903
|
+
def softsign(x):
|
|
2904
|
+
r"""
|
|
2905
|
+
SoftSign activation function.
|
|
2906
|
+
|
|
2907
|
+
The function is shown as follows:
|
|
2908
|
+
|
|
2909
|
+
.. math::
|
|
2910
|
+
\text{SoftSign}(x) = \frac{x}{1 + |x|}
|
|
2911
|
+
|
|
2912
|
+
Softsign Activation Function Graph:
|
|
2913
|
+
|
|
2914
|
+
.. image:: ../images/Softsign.png
|
|
2915
|
+
:align: center
|
|
2916
|
+
|
|
2917
|
+
Args:
|
|
2918
|
+
x (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
|
|
2919
|
+
additional dimensions, with float16 or float32 data type.
|
|
2920
|
+
|
|
2921
|
+
Returns:
|
|
2922
|
+
Tensor, with the same type and shape as the `x`.
|
|
2923
|
+
|
|
2924
|
+
Raises:
|
|
2925
|
+
TypeError: If `x` is not a Tensor.
|
|
2926
|
+
TypeError: If dtype of `x` is neither float16 nor float32.
|
|
2927
|
+
|
|
2928
|
+
Supported Platforms:
|
|
2929
|
+
``Ascend`` ``GPU`` ``CPU``
|
|
2930
|
+
|
|
2931
|
+
Examples:
|
|
2932
|
+
>>> import mindspore
|
|
2933
|
+
>>> import numpy as np
|
|
2934
|
+
>>> from mindspore import Tensor, ops
|
|
2935
|
+
>>> x = Tensor(np.array([0, -1, 2, 30, -30]), mindspore.float32)
|
|
2936
|
+
>>> output = ops.softsign(x)
|
|
2937
|
+
>>> print(output)
|
|
2938
|
+
[ 0. -0.5 0.6666667 0.9677419 -0.9677419]
|
|
2939
|
+
"""
|
|
2940
|
+
return softsign_(x)
|
|
2941
|
+
|
|
2942
|
+
|
|
2943
|
+
def soft_margin_loss(input, target, reduction='mean'):
|
|
2570
2944
|
r"""
|
|
2571
2945
|
Calculate the soft margin loss of input and target.
|
|
2572
2946
|
|
|
@@ -2584,7 +2958,7 @@ def soft_margin_loss(input, target, reduction='mean'):
|
|
|
2584
2958
|
|
|
2585
2959
|
Args:
|
|
2586
2960
|
input (Tensor): Predict data. Data type must be float16 or float32.
|
|
2587
|
-
target (Tensor): Ground truth data, with the same type and shape as `
|
|
2961
|
+
target (Tensor): Ground truth data, with the same type and shape as `input`.
|
|
2588
2962
|
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
2589
2963
|
``'sum'`` . Default: ``'mean'`` .
|
|
2590
2964
|
|
|
@@ -2593,7 +2967,7 @@ def soft_margin_loss(input, target, reduction='mean'):
|
|
|
2593
2967
|
- ``'sum'``: the output elements will be summed.
|
|
2594
2968
|
|
|
2595
2969
|
Outputs:
|
|
2596
|
-
Tensor or Scalar. If `reduction` is ``'none'``, its shape is the same as `
|
|
2970
|
+
Tensor or Scalar. If `reduction` is ``'none'``, its shape is the same as `input`.
|
|
2597
2971
|
Otherwise, a scalar value will be returned.
|
|
2598
2972
|
|
|
2599
2973
|
Raises:
|
|
@@ -2620,34 +2994,31 @@ def soft_margin_loss(input, target, reduction='mean'):
|
|
|
2620
2994
|
return output
|
|
2621
2995
|
|
|
2622
2996
|
|
|
2623
|
-
def softmax(
|
|
2997
|
+
def softmax(input, axis=-1, *, dtype=None):
|
|
2624
2998
|
r"""
|
|
2625
2999
|
Applies the Softmax operation to the input tensor on the specified axis.
|
|
2626
|
-
Suppose a slice in the given axis :math:`
|
|
3000
|
+
Suppose a slice in the given axis :math:`axis`, then for each element :math:`input_i`,
|
|
2627
3001
|
the Softmax function is shown as follows:
|
|
2628
3002
|
|
|
2629
3003
|
.. math::
|
|
2630
|
-
\text{output}(
|
|
3004
|
+
\text{output}(input_i) = \frac{\exp(input_i)}{\sum_{j = 0}^{N-1}\exp(input_j)},
|
|
2631
3005
|
|
|
2632
3006
|
where :math:`N` is the length of the tensor.
|
|
2633
3007
|
|
|
2634
3008
|
Args:
|
|
2635
|
-
|
|
2636
|
-
x (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
|
|
3009
|
+
input (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
|
|
2637
3010
|
additional dimensions, with float16 or float32 data type.
|
|
3011
|
+
axis (int, optional): The axis to perform the Softmax operation. Default: ``-1`` .
|
|
2638
3012
|
|
|
2639
3013
|
Keyword Args:
|
|
2640
|
-
dtype (:class:`mindspore.dtype`, optional): When set, `
|
|
3014
|
+
dtype (:class:`mindspore.dtype`, optional): When set, `input` will be converted to the specified type,
|
|
2641
3015
|
`dtype`, before execution, and dtype of returned Tensor will also be `dtype`. Default: ``None`` .
|
|
2642
3016
|
|
|
2643
3017
|
Returns:
|
|
2644
|
-
Tensor, with the same type and shape as the
|
|
3018
|
+
Tensor, with the same type and shape as the `input`.
|
|
2645
3019
|
|
|
2646
3020
|
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))
|
|
3021
|
+
TypeError: If `axis` is not an int.
|
|
2651
3022
|
|
|
2652
3023
|
Supported Platforms:
|
|
2653
3024
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -2656,8 +3027,8 @@ def softmax(x, axis=-1, *, dtype=None):
|
|
|
2656
3027
|
>>> import mindspore
|
|
2657
3028
|
>>> import numpy as np
|
|
2658
3029
|
>>> from mindspore import Tensor, ops
|
|
2659
|
-
>>>
|
|
2660
|
-
>>> output = ops.softmax(
|
|
3030
|
+
>>> input = Tensor(np.array([1, 2, 3, 4, 5]), mindspore.float32)
|
|
3031
|
+
>>> output = ops.softmax(input)
|
|
2661
3032
|
>>> print(output)
|
|
2662
3033
|
[0.01165623 0.03168492 0.08612854 0.23412167 0.6364086 ]
|
|
2663
3034
|
"""
|
|
@@ -2666,9 +3037,9 @@ def softmax(x, axis=-1, *, dtype=None):
|
|
|
2666
3037
|
type_axis = type(axis).__name__
|
|
2667
3038
|
raise TypeError(f" the type of 'axis' must be 'int', but got '{axis}' with type '{type_axis}'.")
|
|
2668
3039
|
if dtype is not None:
|
|
2669
|
-
|
|
2670
|
-
softmax_ = _get_cache_prim(P.Softmax)(axis
|
|
2671
|
-
return softmax_(
|
|
3040
|
+
input = ops.cast(input, dtype)
|
|
3041
|
+
softmax_ = _get_cache_prim(P.Softmax)(axis)
|
|
3042
|
+
return softmax_(input)
|
|
2672
3043
|
|
|
2673
3044
|
|
|
2674
3045
|
def softmin(x, axis=-1, *, dtype=None):
|
|
@@ -2692,7 +3063,7 @@ def softmin(x, axis=-1, *, dtype=None):
|
|
|
2692
3063
|
`dtype`, before execution, and dtype of returned Tensor will also be `dtype`. Default: ``None`` .
|
|
2693
3064
|
|
|
2694
3065
|
Returns:
|
|
2695
|
-
Tensor, with the same type and shape as
|
|
3066
|
+
Tensor, with the same type and shape as `x`.
|
|
2696
3067
|
|
|
2697
3068
|
Raises:
|
|
2698
3069
|
TypeError: If `axis` is not an int or a tuple.
|
|
@@ -2715,7 +3086,7 @@ def softmin(x, axis=-1, *, dtype=None):
|
|
|
2715
3086
|
|
|
2716
3087
|
if dtype is not None:
|
|
2717
3088
|
x = ops.cast(x, dtype)
|
|
2718
|
-
softmax_ = _get_cache_prim(P.Softmax)(axis
|
|
3089
|
+
softmax_ = _get_cache_prim(P.Softmax)(axis)
|
|
2719
3090
|
return softmax_(-1*x)
|
|
2720
3091
|
|
|
2721
3092
|
|
|
@@ -2731,6 +3102,11 @@ def softshrink(x, lambd=0.5):
|
|
|
2731
3102
|
0, & \text{ otherwise }
|
|
2732
3103
|
\end{cases}
|
|
2733
3104
|
|
|
3105
|
+
SoftShrink Activation Function Graph:
|
|
3106
|
+
|
|
3107
|
+
.. image:: ../images/Softshrink.png
|
|
3108
|
+
:align: center
|
|
3109
|
+
|
|
2734
3110
|
Args:
|
|
2735
3111
|
x (Tensor): The input of soft shrink with data type of float16 or float32.
|
|
2736
3112
|
lambd (float): The :math:`\lambda` must be no less than zero. Default: ``0.5`` .
|
|
@@ -2739,10 +3115,10 @@ def softshrink(x, lambd=0.5):
|
|
|
2739
3115
|
Tensor, has the same shape and data type as `x`.
|
|
2740
3116
|
|
|
2741
3117
|
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.
|
|
3118
|
+
TypeError: If `lambd` is not a float.
|
|
3119
|
+
TypeError: If `x` is not a Tensor.
|
|
3120
|
+
TypeError: If dtype of `x` is neither float16 nor float32.
|
|
3121
|
+
ValueError: If `lambd` is less than 0.
|
|
2746
3122
|
|
|
2747
3123
|
Supported Platforms:
|
|
2748
3124
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -2814,43 +3190,54 @@ def softplus(input, beta=1, threshold=20): # pylint:disable=redefined-outer-name
|
|
|
2814
3190
|
>>> print(output)
|
|
2815
3191
|
[0.7443967 0.79813886 30. 25.]
|
|
2816
3192
|
"""
|
|
2817
|
-
softplus_op = _get_cache_prim(P.Softplus)()
|
|
2818
3193
|
scaling_input = beta * input
|
|
2819
|
-
op_output = (1 / beta) *
|
|
3194
|
+
op_output = (1 / beta) * softplus_(scaling_input)
|
|
2820
3195
|
return ops.select(input * beta > threshold, input, op_output)
|
|
2821
3196
|
|
|
2822
3197
|
|
|
2823
|
-
def
|
|
3198
|
+
def softplus_ext(input, beta=1, threshold=20): # pylint:disable=redefined-outer-name
|
|
2824
3199
|
r"""
|
|
2825
|
-
|
|
3200
|
+
Applies softplus function to `input` element-wise.
|
|
3201
|
+
|
|
3202
|
+
The softplus function is shown as follows, x is the element of `input` :
|
|
2826
3203
|
|
|
2827
3204
|
.. math::
|
|
2828
|
-
\text{SiLU}(x) = x * \sigma(x),
|
|
2829
3205
|
|
|
2830
|
-
|
|
3206
|
+
\text{output} = \frac{1}{beta}\log(1 + \exp(\text{beta * x}))
|
|
2831
3207
|
|
|
2832
|
-
|
|
3208
|
+
When :math:`input * beta > threshold`, the implementation converts to the linear function
|
|
3209
|
+
to ensure numerical stability.
|
|
3210
|
+
|
|
3211
|
+
Args:
|
|
3212
|
+
input (Tensor) - Tensor of any dimension.
|
|
3213
|
+
Supported dtypes:
|
|
2833
3214
|
|
|
2834
|
-
|
|
3215
|
+
- Ascend: float16, float32, bfloat16
|
|
2835
3216
|
|
|
2836
|
-
|
|
3217
|
+
beta (number, optional) - The :math:`\beta` value in softplus function. Default: ``1`` .
|
|
3218
|
+
threshold (number, optional) - When :math:`input * beta > threshold`, converting softplus to a linear function.
|
|
3219
|
+
Default: ``20`` .
|
|
2837
3220
|
|
|
2838
|
-
|
|
3221
|
+
Returns:
|
|
3222
|
+
Tensor, with the same type and shape as the `input` .
|
|
3223
|
+
|
|
3224
|
+
Raises:
|
|
3225
|
+
TypeError: If `input` is not a Tensor.
|
|
3226
|
+
TypeError: If the dtype of `input` is not float16, float32, bfloat16.
|
|
2839
3227
|
|
|
2840
3228
|
Supported Platforms:
|
|
2841
|
-
``Ascend``
|
|
3229
|
+
``Ascend``
|
|
2842
3230
|
|
|
2843
3231
|
Examples:
|
|
2844
|
-
>>> import numpy as np
|
|
2845
3232
|
>>> import mindspore
|
|
2846
|
-
>>>
|
|
2847
|
-
>>>
|
|
2848
|
-
>>>
|
|
3233
|
+
>>> import numpy as np
|
|
3234
|
+
>>> from mindspore import Tensor, mint
|
|
3235
|
+
>>> input = Tensor(np.array([0.1, 0.2, 30, 25]), mindspore.float32)
|
|
3236
|
+
>>> output = mint.softplus(input)
|
|
2849
3237
|
>>> print(output)
|
|
2850
|
-
[
|
|
3238
|
+
[0.74439657 0.7981388 30. 25.]
|
|
2851
3239
|
"""
|
|
2852
|
-
|
|
2853
|
-
return silu_(x)
|
|
3240
|
+
return _get_cache_prim(ops.auto_generate.SoftplusExt)()(input, beta, threshold)
|
|
2854
3241
|
|
|
2855
3242
|
|
|
2856
3243
|
def selu(input_x):
|
|
@@ -2872,14 +3259,20 @@ def selu(input_x):
|
|
|
2872
3259
|
|
|
2873
3260
|
See more details in `Self-Normalizing Neural Networks <https://arxiv.org/abs/1706.02515>`_.
|
|
2874
3261
|
|
|
3262
|
+
SeLU Activation Function Graph:
|
|
3263
|
+
|
|
3264
|
+
.. image:: ../images/SeLU.png
|
|
3265
|
+
:align: center
|
|
3266
|
+
|
|
2875
3267
|
Args:
|
|
2876
|
-
input_x (Tensor): Tensor of any dimension,
|
|
3268
|
+
input_x (Tensor): Tensor of any dimension,
|
|
3269
|
+
the data type is int8, int32, float16, float32, or float64 (CPU, GPU only).
|
|
2877
3270
|
|
|
2878
3271
|
Returns:
|
|
2879
3272
|
Tensor, with the same type and shape as the `input_x`.
|
|
2880
3273
|
|
|
2881
3274
|
Raises:
|
|
2882
|
-
TypeError: If dtype of `input_x` is
|
|
3275
|
+
TypeError: If dtype of `input_x` is not int8, int32, float16, float32, or float64.
|
|
2883
3276
|
|
|
2884
3277
|
Supported Platforms:
|
|
2885
3278
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -2897,41 +3290,6 @@ def selu(input_x):
|
|
|
2897
3290
|
return selu_(input_x)
|
|
2898
3291
|
|
|
2899
3292
|
|
|
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
3293
|
def logsigmoid(x):
|
|
2936
3294
|
r"""
|
|
2937
3295
|
Applies logsigmoid activation element-wise. The input is a Tensor with any valid shape.
|
|
@@ -2943,6 +3301,11 @@ def logsigmoid(x):
|
|
|
2943
3301
|
|
|
2944
3302
|
where :math:`x_{i}` is the element of the input.
|
|
2945
3303
|
|
|
3304
|
+
LogSigmoid Activation Function Graph:
|
|
3305
|
+
|
|
3306
|
+
.. image:: ../images/LogSigmoid.png
|
|
3307
|
+
:align: center
|
|
3308
|
+
|
|
2946
3309
|
Args:
|
|
2947
3310
|
x (Tensor): The input of LogSigmoid with data type of float16 or float32.
|
|
2948
3311
|
The shape is :math:`(N,*)` where :math:`*` means, any number of additional dimensions.
|
|
@@ -2965,64 +3328,11 @@ def logsigmoid(x):
|
|
|
2965
3328
|
>>> print(output)
|
|
2966
3329
|
[-0.31326166 -0.12692806 -0.04858734]
|
|
2967
3330
|
"""
|
|
2968
|
-
output =
|
|
2969
|
-
ret =
|
|
3331
|
+
output = sigmoid_(x)
|
|
3332
|
+
ret = log_(output)
|
|
2970
3333
|
return ret
|
|
2971
3334
|
|
|
2972
3335
|
|
|
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
3336
|
def _check_dense_add_bias_shape(input_shape, output_shape, bias_shape):
|
|
3027
3337
|
"""Check that the output has the correct shape after adding bias."""
|
|
3028
3338
|
if input_shape != output_shape:
|
|
@@ -3113,14 +3423,15 @@ def bidense(input1, input2, weight, bias=None):
|
|
|
3113
3423
|
input1 = input1.reshape((-1, input1_shape[-1]))
|
|
3114
3424
|
input2 = input2.reshape((-1, input2_shape[-1]))
|
|
3115
3425
|
batch_size = input1.shape[0]
|
|
3116
|
-
matmul_ = P.MatMul()
|
|
3117
3426
|
output = matmul_(input1, weight.transpose(1, 2, 0).view(input1_shape[-1], -1))
|
|
3118
3427
|
output = output.view(batch_size, input2_shape[-1], weight.shape[0])
|
|
3119
3428
|
output = output.transpose(2, 0, 1) * input2
|
|
3120
3429
|
output = output.sum(2).swapaxes(0, 1)
|
|
3121
3430
|
if bias is not None:
|
|
3122
|
-
|
|
3123
|
-
|
|
3431
|
+
if input1.dtype != bias.dtype or input2.dtype != bias.dtype:
|
|
3432
|
+
raise TypeError(f"For 'bidense', the dtype of 'bias', 'input1' and 'input2' must be the same,"
|
|
3433
|
+
f" but got {bias.dtype}, {input1.dtype} and {input2.dtype}.")
|
|
3434
|
+
output = bias_add_(output.astype(bias.dtype), bias)
|
|
3124
3435
|
if len(input1_shape) != 2:
|
|
3125
3436
|
output_shape = input1_shape[:-1] + (-1,)
|
|
3126
3437
|
output = output.reshape(output_shape)
|
|
@@ -3189,7 +3500,7 @@ def deformable_conv2d(x, weight, offsets, kernel_size, strides, padding, bias=No
|
|
|
3189
3500
|
TypeError: If `strides`, `padding`, `kernel_size` or `dilations` is not a tuple with integer elements.
|
|
3190
3501
|
TypeError: If `modulated` is not a bool.
|
|
3191
3502
|
ValueError: If the tuple size of `strides`, `padding`, `kernel_size` or `dilations` is not expected.
|
|
3192
|
-
ValueError: The N or C dimensions of
|
|
3503
|
+
ValueError: The N or C dimensions of `strides` or `dilations` is not set to 1.
|
|
3193
3504
|
ValueError: If `modulated` is not set to True.
|
|
3194
3505
|
|
|
3195
3506
|
.. warning::
|
|
@@ -3214,13 +3525,10 @@ def deformable_conv2d(x, weight, offsets, kernel_size, strides, padding, bias=No
|
|
|
3214
3525
|
deformable_groups,
|
|
3215
3526
|
modulated)
|
|
3216
3527
|
fm_offset = deformable_offsets(x, offsets)
|
|
3217
|
-
|
|
3218
3528
|
weight_shape = weight.shape
|
|
3219
3529
|
out_channel = weight_shape[0]
|
|
3220
3530
|
strides_conv = (kernel_size[0], kernel_size[1])
|
|
3221
3531
|
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
3532
|
output = conv(fm_offset, weight)
|
|
3225
3533
|
if bias is not None:
|
|
3226
3534
|
output = bias_add_(output, bias)
|
|
@@ -3231,9 +3539,7 @@ def pdist(input, p=2.0):
|
|
|
3231
3539
|
r"""
|
|
3232
3540
|
Calculates the distance between every pair of row vectors in
|
|
3233
3541
|
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)`.
|
|
3542
|
+
the `output` must be a 1D Tensor with shape :math:`(N * (N - 1) / 2,)`.
|
|
3237
3543
|
|
|
3238
3544
|
.. math::
|
|
3239
3545
|
y[n] = \sqrt[p]{{\mid x_{i} - x_{j} \mid}^p}
|
|
@@ -3241,8 +3547,7 @@ def pdist(input, p=2.0):
|
|
|
3241
3547
|
where :math:`x_{i}, x_{j}` are two different row vectors in the input.
|
|
3242
3548
|
|
|
3243
3549
|
Args:
|
|
3244
|
-
input (Tensor): Input tensor
|
|
3245
|
-
dtype: float16, float32 or float64.
|
|
3550
|
+
input (Tensor): Input tensor. dtype: float16, float32 or float64.
|
|
3246
3551
|
p (float): The order of norm distance, :math:`p∈[0, ∞)`. Default: ``2.0`` .
|
|
3247
3552
|
|
|
3248
3553
|
Returns:
|
|
@@ -3270,7 +3575,102 @@ def pdist(input, p=2.0):
|
|
|
3270
3575
|
return pdist_(input)
|
|
3271
3576
|
|
|
3272
3577
|
|
|
3273
|
-
|
|
3578
|
+
def _circular_pad(input_x, padding):
|
|
3579
|
+
"""circular pad"""
|
|
3580
|
+
padding = scalar_to_tensor_(padding, const_arg=True)
|
|
3581
|
+
is_expand = False
|
|
3582
|
+
if padding.shape[0] // 2 + 1 == input_x.ndim:
|
|
3583
|
+
input_x = input_x.expand_dims(0)
|
|
3584
|
+
is_expand = True
|
|
3585
|
+
out = PadV3(mode="circular", paddings_contiguous=True)(input_x, padding, None)
|
|
3586
|
+
if is_expand:
|
|
3587
|
+
out = out.squeeze(0)
|
|
3588
|
+
return out
|
|
3589
|
+
|
|
3590
|
+
|
|
3591
|
+
def pad_ext(input, pad, mode='constant', value=None):
|
|
3592
|
+
r"""
|
|
3593
|
+
Pads the input tensor according to the pad.
|
|
3594
|
+
|
|
3595
|
+
Args:
|
|
3596
|
+
input (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of additional dimensions.
|
|
3597
|
+
pad (tuple[int]): Filling position of pad.
|
|
3598
|
+
mode (str, optional): Pad filling mode, ``'constant'`` , ``'reflect'`` , ``'replicate'`` or ``'circular'`` .
|
|
3599
|
+
Default: ``'constant'`` .
|
|
3600
|
+
value (Union[int, float, None], optional): Valid only in ``'constant'`` mode.
|
|
3601
|
+
Set the pad value in ``'constant'`` mode. If the value is None, 0 is used as the default pad value.
|
|
3602
|
+
Default: ``None`` .
|
|
3603
|
+
|
|
3604
|
+
Returns:
|
|
3605
|
+
Tensor, the tensor after pad.
|
|
3606
|
+
|
|
3607
|
+
Raises:
|
|
3608
|
+
TypeError: If `pad` is not an int of tuple.
|
|
3609
|
+
TypeError: If `input` is not a Tensor.
|
|
3610
|
+
ValueError: If length of `pad` is not even.
|
|
3611
|
+
ValueError: If length of `pad` is greater than 6.
|
|
3612
|
+
ValueError: If `mode` is not ``'constant'`` and `value` not ``None``.
|
|
3613
|
+
|
|
3614
|
+
Supported Platforms:
|
|
3615
|
+
``Ascend``
|
|
3616
|
+
|
|
3617
|
+
Examples:
|
|
3618
|
+
>>> import mindspore as ms
|
|
3619
|
+
>>> from mindspore.mint.nn.functional import pad
|
|
3620
|
+
>>> import numpy as np
|
|
3621
|
+
>>> x = ms.Tensor(np.arange(1 * 2 * 2 * 2).reshape((1, 2, 2, 2)), dtype=ms.float64)
|
|
3622
|
+
>>> output = pad(x, [1, 0, 0, 1], mode='constant', value=6.0)
|
|
3623
|
+
>>> print(output)
|
|
3624
|
+
[[[[6. 0. 1.]
|
|
3625
|
+
[6. 2. 3.]
|
|
3626
|
+
[6. 6. 6.]]
|
|
3627
|
+
[[6. 4. 5.]
|
|
3628
|
+
[6. 6. 7.]
|
|
3629
|
+
[6. 6. 6.]]]]
|
|
3630
|
+
>>> output1 = ops.pad(x, (1, 0, 0, 1), mode='reflect')
|
|
3631
|
+
>>> print(output1)
|
|
3632
|
+
[[[[1. 0. 1.]
|
|
3633
|
+
[3. 2. 3.]
|
|
3634
|
+
[1. 0. 1.]]
|
|
3635
|
+
[[5. 4. 5.]
|
|
3636
|
+
[7. 6. 7.]
|
|
3637
|
+
[5. 4. 5.]]]]
|
|
3638
|
+
"""
|
|
3639
|
+
if not isinstance(input, Tensor):
|
|
3640
|
+
raise TypeError(f"For 'pad', the type of 'input' must be Tensor, but got {type(input)}.")
|
|
3641
|
+
out = input
|
|
3642
|
+
if (isinstance(pad, tuple) and not pad):
|
|
3643
|
+
return out
|
|
3644
|
+
if mode == "constant":
|
|
3645
|
+
value = 0 if value is None else value
|
|
3646
|
+
out = constant_pad_nd_op(input, pad, value)
|
|
3647
|
+
elif mode == "circular":
|
|
3648
|
+
out = _circular_pad(input, pad)
|
|
3649
|
+
else:
|
|
3650
|
+
if len(pad) == 2:
|
|
3651
|
+
if mode == "reflect":
|
|
3652
|
+
out = reflection_pad_1d_op(input, pad)
|
|
3653
|
+
elif mode == "replicate":
|
|
3654
|
+
out = replication_pad_1d_op(input, pad)
|
|
3655
|
+
else:
|
|
3656
|
+
raise ValueError(f"Pad filling mode must be 'constant' 'circular' 'reflect' or 'replicate'.")
|
|
3657
|
+
elif len(pad) == 4:
|
|
3658
|
+
if mode == "reflect":
|
|
3659
|
+
out = reflection_pad_2d_op(input, pad)
|
|
3660
|
+
elif mode == "replicate":
|
|
3661
|
+
out = replication_pad_2d_op(input, pad)
|
|
3662
|
+
else:
|
|
3663
|
+
raise ValueError(f"Pad filling mode must be 'constant' 'circular' 'reflect' or 'replicate'.")
|
|
3664
|
+
else:
|
|
3665
|
+
if mode == "reflect":
|
|
3666
|
+
out = reflection_pad_3d_op(input, pad)
|
|
3667
|
+
elif mode == "replicate":
|
|
3668
|
+
out = replication_pad_3d_op(input, pad)
|
|
3669
|
+
else:
|
|
3670
|
+
raise ValueError(f"Pad filling mode must be 'constant' 'circular' 'reflect' or 'replicate'.")
|
|
3671
|
+
return out
|
|
3672
|
+
|
|
3673
|
+
|
|
3274
3674
|
def _check_pad_inputs(padding):
|
|
3275
3675
|
"""check the input of pad"""
|
|
3276
3676
|
if len(padding) % 2 != 0:
|
|
@@ -3288,8 +3688,10 @@ def pad(input_x, padding, mode='constant', value=None):
|
|
|
3288
3688
|
Pads the input tensor according to the padding.
|
|
3289
3689
|
|
|
3290
3690
|
Args:
|
|
3291
|
-
input_x (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of additional dimensions
|
|
3292
|
-
|
|
3691
|
+
input_x (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of additional dimensions
|
|
3692
|
+
which is required to be no more than 5 in Ascend.
|
|
3693
|
+
padding (Union[tuple[int], list[int], Tensor]): Filling position of pad where the negative value is not
|
|
3694
|
+
supported while running in Ascend.
|
|
3293
3695
|
:math:`\left\lfloor\frac{\text{len(padding)}}{2}\right\rfloor` dimensions
|
|
3294
3696
|
of `input_x` will be padded.
|
|
3295
3697
|
|
|
@@ -3298,49 +3700,49 @@ def pad(input_x, padding, mode='constant', value=None):
|
|
|
3298
3700
|
:math:`(\text{padding_left}, \text{padding_right})`;
|
|
3299
3701
|
|
|
3300
3702
|
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})`;
|
|
3703
|
+
:math:`(\text{padding_left}, \text{padding_right}, \text{padding_top}, \text{padding_bottom})`;
|
|
3303
3704
|
|
|
3304
3705
|
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.
|
|
3706
|
+
:math:`(\text{padding_left}, \text{padding_right}, \text{padding_top}, \text{padding_bottom},
|
|
3707
|
+
\text{padding_front}, \text{padding_back})` and so on.
|
|
3308
3708
|
|
|
3309
|
-
mode (str, optional): Pad filling mode, ``
|
|
3709
|
+
mode (str, optional): Pad filling mode, ``'constant'`` , ``'reflect'`` , ``'replicate'`` or ``'circular'`` .
|
|
3310
3710
|
Default: ``'constant'`` .
|
|
3311
3711
|
|
|
3312
|
-
For
|
|
3712
|
+
For ``'constant'`` mode, please refer to :class:`mindspore.nn.ConstantPad1d` as an example to understand
|
|
3313
3713
|
this filling pattern and extend the padding pattern to n dimensions.
|
|
3314
3714
|
|
|
3315
|
-
For
|
|
3715
|
+
For ``'reflect'`` mode, please refer to :class:`mindspore.nn.ReflectionPad1d` as an example to understand
|
|
3316
3716
|
this filling pattern.
|
|
3317
3717
|
The reflect mode is used to pad the last two dimensions of 3D or 4D input, or the last dimension of 2D or
|
|
3318
3718
|
3D input.
|
|
3319
3719
|
|
|
3320
|
-
For
|
|
3720
|
+
For ``'replicate'`` mode, please refer to :class:`mindspore.nn.ReplicationPad1d` as an example to understand
|
|
3321
3721
|
this filling pattern.
|
|
3322
3722
|
The replicate mode is used to pad the last three dimensions of 4D or 5D input, the last two dimensions of 3D
|
|
3323
3723
|
or 4D input, or the last dimension of 2D or 3D input.
|
|
3324
3724
|
|
|
3325
|
-
For
|
|
3725
|
+
For ``'circular'`` mode, the pixels from one edge of the image are wrapped around to the opposite edge,
|
|
3326
3726
|
such that the pixel on the right edge of the image is replaced with the pixel on the left edge,
|
|
3327
3727
|
and the pixel on the bottom edge is replaced with the pixel on the top edge.
|
|
3328
3728
|
The circular mode is used to pad the last three dimensions of 4D or 5D input, the last two dimensions of 3D
|
|
3329
3729
|
or 4D input, or the last dimension of 2D or 3D input.
|
|
3330
3730
|
|
|
3331
|
-
value (Union[int, float, None], optional): Valid only in
|
|
3332
|
-
Set the padding value in
|
|
3731
|
+
value (Union[int, float, None], optional): Valid only in ``'constant'`` mode.
|
|
3732
|
+
Set the padding value in ``'constant'`` mode. If the value is None, 0 is used as the default padding value.
|
|
3333
3733
|
Default: ``None`` .
|
|
3334
3734
|
|
|
3335
3735
|
Returns:
|
|
3336
3736
|
Tensor, the tensor after padding.
|
|
3337
3737
|
|
|
3338
3738
|
Raises:
|
|
3339
|
-
TypeError: If `
|
|
3739
|
+
TypeError: If `padding` is not an int of tuple or int of list.
|
|
3340
3740
|
TypeError: If `input_x` is not a Tensor.
|
|
3341
3741
|
ValueError: If length of `padding` is not even.
|
|
3342
3742
|
ValueError: If length of `padding` is greater than 6.
|
|
3343
|
-
ValueError: If mode is not
|
|
3743
|
+
ValueError: If `mode` is not ``'constant'`` and `value` not ``None``.
|
|
3744
|
+
ValueError: If rank of `input_x` is more than 5 while running in Ascend.
|
|
3745
|
+
ValueError: If `paddings` contains negative value while running in Ascend.
|
|
3344
3746
|
|
|
3345
3747
|
Supported Platforms:
|
|
3346
3748
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -3397,7 +3799,7 @@ def pad(input_x, padding, mode='constant', value=None):
|
|
|
3397
3799
|
return input_x
|
|
3398
3800
|
if not isinstance(padding, Tensor):
|
|
3399
3801
|
_check_pad_inputs(padding)
|
|
3400
|
-
padding =
|
|
3802
|
+
padding = tuple(padding)
|
|
3401
3803
|
is_expand = False
|
|
3402
3804
|
if mode == "constant":
|
|
3403
3805
|
value = 0 if value is None else value
|
|
@@ -3410,7 +3812,7 @@ def pad(input_x, padding, mode='constant', value=None):
|
|
|
3410
3812
|
raise ValueError(f"For 'pad', the padding mode '{mode}' can not set value, but got value {value}.")
|
|
3411
3813
|
if mode == "replicate":
|
|
3412
3814
|
mode = "edge"
|
|
3413
|
-
if padding
|
|
3815
|
+
if len(padding) // 2 + 1 == input_x.ndim:
|
|
3414
3816
|
input_x = input_x.expand_dims(0)
|
|
3415
3817
|
is_expand = True
|
|
3416
3818
|
out = PadV3(mode=mode, paddings_contiguous=True)(input_x, padding, value)
|
|
@@ -3419,142 +3821,6 @@ def pad(input_x, padding, mode='constant', value=None):
|
|
|
3419
3821
|
return out
|
|
3420
3822
|
|
|
3421
3823
|
|
|
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
3824
|
def rrelu(input, lower=1.0 / 8, upper=1.0 / 3):
|
|
3559
3825
|
r"""
|
|
3560
3826
|
|
|
@@ -3583,7 +3849,7 @@ def rrelu(input, lower=1.0 / 8, upper=1.0 / 3):
|
|
|
3583
3849
|
TypeError: If `lower` is not a float or an int.
|
|
3584
3850
|
TypeError: If `upper` is not a float or an int.
|
|
3585
3851
|
TypeError: If `input` is not a Tensor.
|
|
3586
|
-
TypeError: If `input` is not a Tensor of mindspore.float16 or
|
|
3852
|
+
TypeError: If `input` is not a Tensor of mindspore.float16 or mindspore.float32.
|
|
3587
3853
|
ValueError: If `lower` is greater than upper.
|
|
3588
3854
|
|
|
3589
3855
|
Supported Platforms:
|
|
@@ -3612,13 +3878,12 @@ def rrelu(input, lower=1.0 / 8, upper=1.0 / 3):
|
|
|
3612
3878
|
_upper = Tensor(upper, mstype.float32)
|
|
3613
3879
|
_size = input.shape
|
|
3614
3880
|
if ops.is_sequence_value_unknown(_size):
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
sign_matrix = _get_cache_prim(P.Sign)()(input)
|
|
3881
|
+
_size = tensor_shape_(input)
|
|
3882
|
+
sign_matrix = sign_(input)
|
|
3618
3883
|
negative_filter = sign_matrix.clip(None, 0)
|
|
3619
3884
|
positive_filter = sign_matrix.clip(0, None)
|
|
3620
|
-
|
|
3621
|
-
mask = ops.uniform(_size, _lower, _upper).astype(
|
|
3885
|
+
input_dtype = dtype_(input)
|
|
3886
|
+
mask = ops.uniform(_size, _lower, _upper).astype(input_dtype)
|
|
3622
3887
|
negative_mask = negative_filter * mask * -1
|
|
3623
3888
|
total_mask = negative_mask + positive_filter
|
|
3624
3889
|
out = total_mask * input
|
|
@@ -3686,6 +3951,21 @@ def _innner_log_softmax(inputs, axis):
|
|
|
3686
3951
|
return inputs - logsumexp(inputs, axis, True)
|
|
3687
3952
|
|
|
3688
3953
|
|
|
3954
|
+
def _check_cross_entropy_inputs(input, target, weight, ignore_index, reduction, label_smoothing):
|
|
3955
|
+
"""
|
|
3956
|
+
Check inputs for cross_entropy().
|
|
3957
|
+
"""
|
|
3958
|
+
_check_is_tensor('input', input, "cross_entropy_loss")
|
|
3959
|
+
_check_is_tensor('target', target, "cross_entropy_loss")
|
|
3960
|
+
_check_is_tensor('weight', weight, "cross_entropy_loss")
|
|
3961
|
+
check_int_const(ignore_index, 'ignore_index', "cross_entropy_loss")
|
|
3962
|
+
check_non_negative_float_const(label_smoothing, 'label_smoothing', "cross_entropy_loss")
|
|
3963
|
+
check_string_const(reduction, ['none', 'mean', 'sum'], 'reduction', "cross_entropy_loss")
|
|
3964
|
+
if input.dtype not in [mstype.float64, mstype.float32, mstype.float16]:
|
|
3965
|
+
raise TypeError(f'For cross_entropy, the input dtype should be mstype.float64, mstype.float32 or'
|
|
3966
|
+
f'mstype.float16, but got dtype:{input.dtype}.')
|
|
3967
|
+
|
|
3968
|
+
|
|
3689
3969
|
def cross_entropy(input, target, weight=None, ignore_index=-100, reduction='mean', label_smoothing=0.0):
|
|
3690
3970
|
r"""
|
|
3691
3971
|
The cross entropy loss between input and target.
|
|
@@ -3743,7 +4023,7 @@ def cross_entropy(input, target, weight=None, ignore_index=-100, reduction='mean
|
|
|
3743
4023
|
`input` is expected to be log-probabilities, data type must be float16 or float32.
|
|
3744
4024
|
target (Tensor): For class indices, tensor of shape :math:`()`, :math:`(N)` or
|
|
3745
4025
|
: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.
|
|
4026
|
+
:math:`(N, C)` or :math:`(N, C, d_1, d_2, ..., d_K)` , data type must be float16 or float32 or float64.
|
|
3747
4027
|
weight (Tensor): A rescaling weight applied to the loss of each batch element.
|
|
3748
4028
|
If not None, the shape is :math:`(C,)`, data type must be float16 or float32. Default: ``None`` .
|
|
3749
4029
|
ignore_index (int): Specifies a target value that is ignored
|
|
@@ -3776,12 +4056,7 @@ def cross_entropy(input, target, weight=None, ignore_index=-100, reduction='mean
|
|
|
3776
4056
|
>>> target = ms.Tensor(np.random.randn(3, 5), ms.float32)
|
|
3777
4057
|
>>> output = ms.ops.cross_entropy(inputs, target)
|
|
3778
4058
|
"""
|
|
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")
|
|
4059
|
+
_check_cross_entropy_inputs(input, target, weight, ignore_index, reduction, label_smoothing)
|
|
3785
4060
|
class_dim = 0 if input.ndim == 1 else 1
|
|
3786
4061
|
if target.dtype in [mstype.float32, mstype.float16]:
|
|
3787
4062
|
return _cross_entropy(input, target, class_dim, weight, reduction, label_smoothing)
|
|
@@ -3790,8 +4065,6 @@ def cross_entropy(input, target, weight=None, ignore_index=-100, reduction='mean
|
|
|
3790
4065
|
|
|
3791
4066
|
def _cross_entropy(inputs, target, target_dim, weight=None, reduction='mean', label_smoothing=0.0):
|
|
3792
4067
|
"""cross entropy inner function"""
|
|
3793
|
-
_ones_like = _get_cache_prim(P.OnesLike)()
|
|
3794
|
-
|
|
3795
4068
|
class_dim = 0 if inputs.ndim == 1 else 1
|
|
3796
4069
|
n_classes = inputs.shape[class_dim]
|
|
3797
4070
|
inputs = _innner_log_softmax(inputs, class_dim)
|
|
@@ -3799,7 +4072,7 @@ def _cross_entropy(inputs, target, target_dim, weight=None, reduction='mean', la
|
|
|
3799
4072
|
target = target * (1 - label_smoothing) + label_smoothing / n_classes
|
|
3800
4073
|
|
|
3801
4074
|
if weight is None:
|
|
3802
|
-
weight =
|
|
4075
|
+
weight = ones_like_(inputs)
|
|
3803
4076
|
elif inputs.ndim != 1:
|
|
3804
4077
|
broadcast_shape = [1 for _ in range(inputs.ndim)]
|
|
3805
4078
|
broadcast_shape[1] = weight.shape[0]
|
|
@@ -3829,7 +4102,7 @@ def nll_loss(inputs, target, weight=None, ignore_index=-100, reduction='mean', l
|
|
|
3829
4102
|
N is the batch size, :math:`c` belonging to :math:`[0, C-1]` is class index, where :math:`C` is the number of
|
|
3830
4103
|
classes.
|
|
3831
4104
|
|
|
3832
|
-
If `reduction` is not ``None`` (default 'mean'), then
|
|
4105
|
+
If `reduction` is not ``None`` (default ``'mean'``), then
|
|
3833
4106
|
|
|
3834
4107
|
.. math::
|
|
3835
4108
|
|
|
@@ -3897,37 +4170,31 @@ def nll_loss(inputs, target, weight=None, ignore_index=-100, reduction='mean', l
|
|
|
3897
4170
|
|
|
3898
4171
|
def _nll_loss(inputs, target, target_dim=-1, weight=None, ignore_index=None, reduction='none', label_smoothing=0.0):
|
|
3899
4172
|
"""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
4173
|
if target.ndim == inputs.ndim - 1:
|
|
3907
4174
|
target = target.expand_dims(target_dim)
|
|
3908
4175
|
if ignore_index is not None:
|
|
3909
|
-
non_pad_mask =
|
|
3910
|
-
target = target.masked_fill(non_pad_mask, 0)
|
|
4176
|
+
non_pad_mask = equal_(target, ignore_index)
|
|
4177
|
+
target = target.masked_fill(non_pad_mask, ops.cast(0, target.dtype))
|
|
3911
4178
|
else:
|
|
3912
4179
|
non_pad_mask = target
|
|
3913
4180
|
if weight is not None:
|
|
3914
|
-
loss_weights =
|
|
4181
|
+
loss_weights = gather_(weight, target, 0)
|
|
3915
4182
|
orig_shape = inputs.shape
|
|
3916
4183
|
if inputs.ndim != 2:
|
|
3917
4184
|
inputs = inputs.view(orig_shape[:2] + (-1,))
|
|
3918
4185
|
weight = weight.view(weight.shape + (1,))
|
|
3919
4186
|
weighted_inputs = inputs * weight
|
|
3920
4187
|
weighted_inputs = weighted_inputs.view(orig_shape)
|
|
3921
|
-
loss =
|
|
3922
|
-
smooth_loss =
|
|
4188
|
+
loss = neg_(gather_d_(weighted_inputs, target_dim, target))
|
|
4189
|
+
smooth_loss = neg_(weighted_inputs.sum(axis=target_dim, keepdims=True))
|
|
3923
4190
|
else:
|
|
3924
|
-
loss =
|
|
3925
|
-
smooth_loss =
|
|
3926
|
-
loss_weights =
|
|
4191
|
+
loss = neg_(gather_d_(inputs, target_dim, target))
|
|
4192
|
+
smooth_loss = neg_(inputs.sum(axis=target_dim, keepdims=True))
|
|
4193
|
+
loss_weights = ones_like_(loss)
|
|
3927
4194
|
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.)
|
|
4195
|
+
loss = loss.masked_fill(non_pad_mask, ops.cast(0, loss.dtype))
|
|
4196
|
+
loss_weights = loss_weights.masked_fill(non_pad_mask, ops.cast(0, loss_weights.dtype))
|
|
4197
|
+
smooth_loss = smooth_loss.masked_fill(non_pad_mask, ops.cast(0, smooth_loss.dtype))
|
|
3931
4198
|
|
|
3932
4199
|
loss = loss.squeeze(target_dim)
|
|
3933
4200
|
smooth_loss = smooth_loss.squeeze(target_dim)
|
|
@@ -3949,8 +4216,9 @@ def l1_loss(input, target, reduction='mean'):
|
|
|
3949
4216
|
r"""
|
|
3950
4217
|
Calculate the mean absolute error between the `input` value and the `target` value.
|
|
3951
4218
|
|
|
3952
|
-
Assuming that the :math:`x` and :math:`y` are 1-D Tensor,
|
|
3953
|
-
|
|
4219
|
+
Assuming that the :math:`x` and :math:`y` (predicted and target value) are 1-D Tensor,
|
|
4220
|
+
length :math:`N`, `reduction` is set to ``'none'``, then calculate the loss of
|
|
4221
|
+
:math:`x` and :math:`y` without dimensionality reduction.
|
|
3954
4222
|
|
|
3955
4223
|
The formula is as follows:
|
|
3956
4224
|
|
|
@@ -3959,7 +4227,7 @@ def l1_loss(input, target, reduction='mean'):
|
|
|
3959
4227
|
|
|
3960
4228
|
where :math:`N` is the batch size.
|
|
3961
4229
|
|
|
3962
|
-
If `reduction` is ``
|
|
4230
|
+
If `reduction` is ``'mean'`` or ``'sum'`` , then:
|
|
3963
4231
|
|
|
3964
4232
|
.. math::
|
|
3965
4233
|
\ell(x, y) =
|
|
@@ -3980,13 +4248,13 @@ def l1_loss(input, target, reduction='mean'):
|
|
|
3980
4248
|
- ``'sum'``: the output elements will be summed.
|
|
3981
4249
|
|
|
3982
4250
|
Returns:
|
|
3983
|
-
Tensor or Scalar, if `reduction` is ``
|
|
4251
|
+
Tensor or Scalar, if `reduction` is ``'none'``, return a Tensor with same shape and dtype as `input`.
|
|
3984
4252
|
Otherwise, a scalar value will be returned.
|
|
3985
4253
|
|
|
3986
4254
|
Raises:
|
|
3987
4255
|
TypeError: If `input` is not a Tensor.
|
|
3988
4256
|
TypeError: If `target` is not a Tensor.
|
|
3989
|
-
ValueError: If `reduction` is not one of ``
|
|
4257
|
+
ValueError: If `reduction` is not one of ``'none'``, ``'mean'`` or ``'sum'``.
|
|
3990
4258
|
|
|
3991
4259
|
Supported Platforms:
|
|
3992
4260
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -4004,7 +4272,7 @@ def l1_loss(input, target, reduction='mean'):
|
|
|
4004
4272
|
_check_is_tensor('target', target, "l1_loss")
|
|
4005
4273
|
if reduction not in ('mean', 'sum', 'none'):
|
|
4006
4274
|
raise ValueError(f"For l1_loss, the 'reduction' must be in ['mean', 'sum', 'none'], but got {reduction}.")
|
|
4007
|
-
loss =
|
|
4275
|
+
loss = abs_(input - target)
|
|
4008
4276
|
return _get_loss(loss, reduction, "l1_loss")
|
|
4009
4277
|
|
|
4010
4278
|
|
|
@@ -4039,6 +4307,7 @@ def smooth_l1_loss(input, target, beta=1.0, reduction='none'):
|
|
|
4039
4307
|
|
|
4040
4308
|
Args:
|
|
4041
4309
|
input (Tensor): Tensor of shape :math:`(N, *)` where :math:`*` means, any number of additional dimensions.
|
|
4310
|
+
Data type is float16, float32 or float64.
|
|
4042
4311
|
target (Tensor): Ground truth data, tensor of shape :math:`(N, *)`, same shape and dtype as the `input`.
|
|
4043
4312
|
beta (float): A parameter used to control the point where the function will change between
|
|
4044
4313
|
L1 to L2 loss. The value should be greater than zero. Default: ``1.0`` .
|
|
@@ -4117,13 +4386,13 @@ def threshold(input, thr, value):
|
|
|
4117
4386
|
_check_is_tensor('input', input, "threshold")
|
|
4118
4387
|
_check_value_type("thr", thr, [float, int], "threshold")
|
|
4119
4388
|
_check_value_type("value", value, [float, int], "threshold")
|
|
4120
|
-
cond =
|
|
4389
|
+
cond = greater_(input, thr)
|
|
4121
4390
|
input_type = input.dtype
|
|
4122
4391
|
value = Tensor(value, input_type)
|
|
4123
4392
|
input_shape = input.shape
|
|
4124
|
-
shape_tensor =
|
|
4125
|
-
value =
|
|
4126
|
-
return
|
|
4393
|
+
shape_tensor = tuple_to_tensor_(input_shape, mstype.int64)
|
|
4394
|
+
value = fillv2_(shape_tensor, value)
|
|
4395
|
+
return select_(cond, input, value)
|
|
4127
4396
|
|
|
4128
4397
|
|
|
4129
4398
|
def leaky_relu(input, alpha=0.2):
|
|
@@ -4141,6 +4410,11 @@ def leaky_relu(input, alpha=0.2):
|
|
|
4141
4410
|
For more details, see `Rectifier Nonlinearities Improve Neural Network Acoustic Models
|
|
4142
4411
|
<https://ai.stanford.edu/~amaas/papers/relu_hybrid_icml2013_final.pdf>`_.
|
|
4143
4412
|
|
|
4413
|
+
LeakyReLU Activation Function Graph:
|
|
4414
|
+
|
|
4415
|
+
.. image:: ../images/LeakyReLU.png
|
|
4416
|
+
:align: center
|
|
4417
|
+
|
|
4144
4418
|
Args:
|
|
4145
4419
|
input (Tensor): The input of leaky_relu is a Tensor of any dimension.
|
|
4146
4420
|
alpha (Union[int, float]): Slope of the activation function when the element of `input` is less than 0.
|
|
@@ -4167,10 +4441,10 @@ def leaky_relu(input, alpha=0.2):
|
|
|
4167
4441
|
"""
|
|
4168
4442
|
_check_is_tensor('input', input, "leaky_relu")
|
|
4169
4443
|
_check_value_type("alpha", alpha, [float, int], "leaky_relu")
|
|
4170
|
-
select_op =
|
|
4444
|
+
select_op = maximum_
|
|
4171
4445
|
if alpha > 1:
|
|
4172
|
-
select_op =
|
|
4173
|
-
alpha =
|
|
4446
|
+
select_op = minimum_
|
|
4447
|
+
alpha = cast_(F.scalar_to_tensor(alpha), input.dtype)
|
|
4174
4448
|
return select_op(alpha * input, input)
|
|
4175
4449
|
|
|
4176
4450
|
|
|
@@ -4211,48 +4485,6 @@ def intopk(x1, x2, k):
|
|
|
4211
4485
|
_in_topk = _get_cache_prim(P.InTopK)(k)
|
|
4212
4486
|
return _in_topk(x1, x2)
|
|
4213
4487
|
|
|
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
4488
|
def lrn(x, depth_radius=5, bias=1.0, alpha=1.0, beta=0.5, norm_region="ACROSS_CHANNELS"):
|
|
4257
4489
|
r"""
|
|
4258
4490
|
Local Response Normalization.
|
|
@@ -4321,6 +4553,11 @@ def mish(x):
|
|
|
4321
4553
|
See more details in `A Self Regularized Non-Monotonic Neural Activation Function
|
|
4322
4554
|
<https://arxiv.org/abs/1908.08681>`_.
|
|
4323
4555
|
|
|
4556
|
+
Mish Activation Function Graph:
|
|
4557
|
+
|
|
4558
|
+
.. image:: ../images/Mish.png
|
|
4559
|
+
:align: center
|
|
4560
|
+
|
|
4324
4561
|
Args:
|
|
4325
4562
|
x (Tensor): The input Tensor.
|
|
4326
4563
|
Supported dtypes:
|
|
@@ -4387,21 +4624,15 @@ def _get_loss(x, reduction, cls_name, weights=1.0):
|
|
|
4387
4624
|
if reduction not in ('mean', 'sum', 'none'):
|
|
4388
4625
|
raise ValueError(f"For '{cls_name}', the 'reduction' must be in ['mean', 'sum', 'none'], "
|
|
4389
4626
|
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
4627
|
input_dtype = x.dtype
|
|
4397
|
-
x =
|
|
4398
|
-
weights =
|
|
4399
|
-
x =
|
|
4628
|
+
x = cast_(x, mstype.float32)
|
|
4629
|
+
weights = cast_(weights, mstype.float32)
|
|
4630
|
+
x = mul_(weights, x)
|
|
4400
4631
|
if reduction == 'mean':
|
|
4401
|
-
x =
|
|
4632
|
+
x = reduce_mean_(x, _get_axis(x))
|
|
4402
4633
|
if reduction == 'sum':
|
|
4403
|
-
x =
|
|
4404
|
-
x =
|
|
4634
|
+
x = reduce_sum_(x, _get_axis(x))
|
|
4635
|
+
x = cast_(x, input_dtype)
|
|
4405
4636
|
return x
|
|
4406
4637
|
|
|
4407
4638
|
|
|
@@ -4412,20 +4643,6 @@ def check_input_dtype(param_name1, input_data1, param_name2, input_data2, cls_na
|
|
|
4412
4643
|
f'but got {param_name1} dtype:{input_data1.dtype}, {param_name2} dtype:{input_data2.dtype}.')
|
|
4413
4644
|
|
|
4414
4645
|
|
|
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
4646
|
def margin_ranking_loss(input1, input2, target, margin=0.0, reduction='mean'):
|
|
4430
4647
|
r"""
|
|
4431
4648
|
MarginRankingLoss creates a criterion that measures the loss.
|
|
@@ -4450,7 +4667,7 @@ def margin_ranking_loss(input1, input2, target, margin=0.0, reduction='mean'):
|
|
|
4450
4667
|
- ``'sum'``: the output elements will be summed.
|
|
4451
4668
|
|
|
4452
4669
|
Returns:
|
|
4453
|
-
Tensor or Scalar. if `reduction` is ``
|
|
4670
|
+
Tensor or Scalar. if `reduction` is ``'none'``, its shape is the same as `input1`.
|
|
4454
4671
|
Otherwise, a scalar value will be returned.
|
|
4455
4672
|
|
|
4456
4673
|
Raises:
|
|
@@ -4480,10 +4697,9 @@ def margin_ranking_loss(input1, input2, target, margin=0.0, reduction='mean'):
|
|
|
4480
4697
|
_check_is_tensor('input1', input1, "margin_ranking_loss")
|
|
4481
4698
|
_check_is_tensor('input2', input2, "margin_ranking_loss")
|
|
4482
4699
|
_check_is_tensor('target', target, "margin_ranking_loss")
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
x = maximum(-target * (input1 - input2) + margin, 0)
|
|
4700
|
+
check_input_dtype('input1', input1, 'input2', input2, 'margin_ranking_loss')
|
|
4701
|
+
check_input_dtype('target', target, 'input1', input1, 'margin_ranking_loss')
|
|
4702
|
+
x = maximum_(-target * (input1 - input2) + margin, 0)
|
|
4487
4703
|
return _get_loss(x, reduction, "margin_ranking_loss")
|
|
4488
4704
|
|
|
4489
4705
|
|
|
@@ -4511,7 +4727,7 @@ def cosine_embedding_loss(input1, input2, target, margin=0.0, reduction="mean"):
|
|
|
4511
4727
|
input2 (Tensor): Tensor of shape :math:`(N, *)`, same shape and dtype as `input1`.
|
|
4512
4728
|
target (Tensor): Contains value 1 or -1. Suppose the shape of `input1` is
|
|
4513
4729
|
: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
|
|
4730
|
+
margin (float, optional): Should be in [-1.0, 1.0]. Default: ``0.0``.
|
|
4515
4731
|
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
4516
4732
|
``'sum'`` . Default: ``'mean'`` .
|
|
4517
4733
|
|
|
@@ -4526,7 +4742,7 @@ def cosine_embedding_loss(input1, input2, target, margin=0.0, reduction="mean"):
|
|
|
4526
4742
|
Raises:
|
|
4527
4743
|
TypeError: If `margin` is not a float.
|
|
4528
4744
|
ValueError: If `reduction` is not one of ``'none'``, ``'mean'``, ``'sum'``.
|
|
4529
|
-
ValueError: If `margin` is not in range [-1, 1].
|
|
4745
|
+
ValueError: If `margin` is not in range [-1.0, 1.0].
|
|
4530
4746
|
|
|
4531
4747
|
Supported Platforms:
|
|
4532
4748
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -4546,7 +4762,7 @@ def cosine_embedding_loss(input1, input2, target, margin=0.0, reduction="mean"):
|
|
|
4546
4762
|
_check_is_tensor('input1', input1, "ops.cosine_embedding_loss")
|
|
4547
4763
|
_check_is_tensor('input2', input2, "ops.cosine_embedding_loss")
|
|
4548
4764
|
_check_is_tensor('target', target, "ops.cosine_embedding_loss")
|
|
4549
|
-
|
|
4765
|
+
check_input_dtype('input1', input1, 'input2', input2, 'ops.cosine_embedding_loss')
|
|
4550
4766
|
_check_reduced_shape_valid(ops.shape(input1), ops.shape(target), (1,),
|
|
4551
4767
|
"ops.cosine_embedding_loss", "input1", "target")
|
|
4552
4768
|
if input1.dtype in (mstype.int32, mstype.int64):
|
|
@@ -4560,14 +4776,14 @@ def cosine_embedding_loss(input1, input2, target, margin=0.0, reduction="mean"):
|
|
|
4560
4776
|
if margin_f > 1.0 or margin_f < -1.0:
|
|
4561
4777
|
raise ValueError(f"For ops.cosine_embedding_loss, the value of 'margin' should be in [-1, 1],"
|
|
4562
4778
|
f"but got {margin_f}.")
|
|
4563
|
-
prod_sum =
|
|
4564
|
-
square1 =
|
|
4565
|
-
square2 =
|
|
4779
|
+
prod_sum = reduce_sum_(input1 * input2, (1,))
|
|
4780
|
+
square1 = reduce_sum_(ops.square(input1), (1,))
|
|
4781
|
+
square2 = reduce_sum_(ops.square(input2), (1,))
|
|
4566
4782
|
denom = ops.sqrt(square1) * ops.sqrt(square2)
|
|
4567
4783
|
cosine = prod_sum / denom
|
|
4568
4784
|
|
|
4569
4785
|
pos_value = 1.0 - cosine
|
|
4570
|
-
neg_value =
|
|
4786
|
+
neg_value = maximum_(cosine - margin_f, 0.0)
|
|
4571
4787
|
zeros = ops.zeros_like(cosine)
|
|
4572
4788
|
pos_part = ops.select(target == 1, pos_value, zeros)
|
|
4573
4789
|
neg_part = ops.select(target == -1, neg_value, zeros)
|
|
@@ -4624,7 +4840,7 @@ def max_pool3d(x, kernel_size, stride=None, padding=0, dilation=1, ceil_mode=Fal
|
|
|
4624
4840
|
W_{out} = \left\lfloor\frac{W_{in} + 2 \times \text{padding}[2] - \text{dilation}[2] \times
|
|
4625
4841
|
(\text{kernel_size}[2] - 1) - 1}{\text{stride}[2]} + 1\right\rfloor
|
|
4626
4842
|
|
|
4627
|
-
- **argmax** (Tensor) - Index corresponding to the maximum value. Data type is int64. It will be
|
|
4843
|
+
- **argmax** (Tensor) - Index corresponding to the maximum value. Data type is int64. It will be returned
|
|
4628
4844
|
only when `return_indices` is ``True`` .
|
|
4629
4845
|
|
|
4630
4846
|
Raises:
|
|
@@ -4702,9 +4918,9 @@ def grid_sample(input, grid, mode='bilinear', padding_mode='zeros', align_corner
|
|
|
4702
4918
|
|
|
4703
4919
|
padding_mode (str): An optional string specifying the pad method. The optional values are "zeros", "border" or
|
|
4704
4920
|
"reflection". Default: ``'zeros'`` .
|
|
4705
|
-
align_corners (bool):
|
|
4706
|
-
the center points of the input
|
|
4707
|
-
to the corner points of the input
|
|
4921
|
+
align_corners (bool): If set to `True`, the extrema (-1 and 1) are considered as referring to
|
|
4922
|
+
the center points of the input's corner pixels. If set to `False`, they are instead considered as referring
|
|
4923
|
+
to the corner points of the input's corner pixels, making the sampling more resolution agnostic. Default:
|
|
4708
4924
|
``False`` .
|
|
4709
4925
|
|
|
4710
4926
|
Returns:
|
|
@@ -4777,8 +4993,8 @@ def ctc_loss(log_probs, targets, input_lengths, target_lengths, blank=0, reducti
|
|
|
4777
4993
|
log_probs (Tensor): A tensor of shape :math:`(T, N, C)`, where T is input length, N is batch size and C is
|
|
4778
4994
|
number of classes (including blank).
|
|
4779
4995
|
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)
|
|
4996
|
+
input_lengths (Union(tuple, Tensor)): Lengths of the input. A tuple or Tensor of shape :math:`(N)`.
|
|
4997
|
+
target_lengths (Union(tuple, Tensor)): Lengths of the target. A tuple or Tensor of shape :math:`(N)`.
|
|
4782
4998
|
blank (int, optional): The blank label. Default: ``0`` .
|
|
4783
4999
|
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
4784
5000
|
``'sum'`` . Default: ``'mean'`` .
|
|
@@ -4925,17 +5141,10 @@ def gaussian_nll_loss(x, target, var, full=False, eps=1e-6, reduction='mean'):
|
|
|
4925
5141
|
if not x.shape == var.shape:
|
|
4926
5142
|
if x.shape[:-1] == var.shape:
|
|
4927
5143
|
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)
|
|
5144
|
+
|
|
5145
|
+
maxima = maximum_(var, eps)
|
|
5146
|
+
logarithm = log_(maxima)
|
|
5147
|
+
squared_loss = square_(x - target)
|
|
4939
5148
|
c = 0 if not full else 0.5 * log(2 * pi)
|
|
4940
5149
|
loss = 0.5 * (logarithm + squared_loss / maxima) + c
|
|
4941
5150
|
if reduction == 'mean':
|
|
@@ -4945,12 +5154,6 @@ def gaussian_nll_loss(x, target, var, full=False, eps=1e-6, reduction='mean'):
|
|
|
4945
5154
|
return loss
|
|
4946
5155
|
|
|
4947
5156
|
|
|
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.")
|
|
4952
|
-
|
|
4953
|
-
|
|
4954
5157
|
@_primexpr
|
|
4955
5158
|
def _check_hinge_embedding_loss_type(inputs_dtype, targets_dtype, inputs, targets, margin, reduction):
|
|
4956
5159
|
"""Check hinge embedding loss type."""
|
|
@@ -4998,7 +5201,7 @@ def hinge_embedding_loss(inputs, targets, margin=1.0, reduction='mean'):
|
|
|
4998
5201
|
inputs (Tensor): Predicted values, represented as :math:`x` in the formula.
|
|
4999
5202
|
targets (Tensor): Label values, represented as :math:`y` in the formula.
|
|
5000
5203
|
Has the same shape as `inputs`, contains -1 or 1.
|
|
5001
|
-
margin (float, int): Threshold defined by Hinge Embedding Loss
|
|
5204
|
+
margin (float, int): Threshold defined by Hinge Embedding Loss `margin`.
|
|
5002
5205
|
Represented as :math:`\Delta` in the formula. Default: ``1.0`` .
|
|
5003
5206
|
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
5004
5207
|
``'sum'`` . Default: ``'mean'`` .
|
|
@@ -5008,7 +5211,7 @@ def hinge_embedding_loss(inputs, targets, margin=1.0, reduction='mean'):
|
|
|
5008
5211
|
- ``'sum'``: the output elements will be summed.
|
|
5009
5212
|
|
|
5010
5213
|
Returns:
|
|
5011
|
-
Tensor or Tensor scalar, the computed loss depending on
|
|
5214
|
+
Tensor or Tensor scalar, the computed loss depending on `reduction`.
|
|
5012
5215
|
|
|
5013
5216
|
Raises:
|
|
5014
5217
|
TypeError: If `inputs` is not a Tensor.
|
|
@@ -5036,9 +5239,6 @@ def hinge_embedding_loss(inputs, targets, margin=1.0, reduction='mean'):
|
|
|
5036
5239
|
inputs_dtype = inputs.dtype
|
|
5037
5240
|
targets_dtype = targets.dtype
|
|
5038
5241
|
_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
5242
|
|
|
5043
5243
|
min_val = Tensor(0, inputs_dtype)
|
|
5044
5244
|
pos_index = targets > 0
|
|
@@ -5259,21 +5459,25 @@ def conv1d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5259
5459
|
, :math:`weight` is the convolution kernel value and :math:`X` represents the input feature map.
|
|
5260
5460
|
|
|
5261
5461
|
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
5462
|
|
|
5264
|
-
- :math:`
|
|
5463
|
+
- :math:`i` corresponds to the batch number, the range is :math:`[0, N-1]`,
|
|
5464
|
+
where :math:`N` is the batch size of the input.
|
|
5465
|
+
|
|
5466
|
+
- :math:`j` corresponds to the output channel, ranging from :math:`[0, C_{out}-1]`,
|
|
5467
|
+
where :math:`C_{out}` is the number of
|
|
5265
5468
|
output channels, which is also equal to the number of kernels.
|
|
5266
5469
|
|
|
5267
|
-
- :math:`k` corresponds to the input channel, ranging from 0
|
|
5470
|
+
- :math:`k` corresponds to the input channel, ranging from :math:`[0, C_{in}-1]`,
|
|
5471
|
+
where :math:`C_{in}` is the number of
|
|
5268
5472
|
input channels, which is also equal to the number of channels in the convolutional kernels.
|
|
5269
5473
|
|
|
5270
|
-
Therefore, in the above formula, :math:`{bias}(C_{
|
|
5271
|
-
output channel, :math:`{weight}(C_{
|
|
5474
|
+
Therefore, in the above formula, :math:`{bias}(C_{\text{out}_j})` represents the bias of the :math:`j`-th
|
|
5475
|
+
output channel, :math:`{weight}(C_{\text{out}_j}, k)` represents the slice of the :math:`j`-th convolutional
|
|
5272
5476
|
kernel in the :math:`k`-th channel, and :math:`{X}(N_i, k)` represents the slice of the :math:`k`-th input
|
|
5273
5477
|
channel in the :math:`i`-th batch of the input feature map.
|
|
5274
5478
|
|
|
5275
|
-
The shape of the convolutional kernel is given by :math:`(
|
|
5276
|
-
where :math
|
|
5479
|
+
The shape of the convolutional kernel is given by :math:`(\text{kernel_size})`,
|
|
5480
|
+
where :math:`\text{kernel_size}` is the width of the kernel.
|
|
5277
5481
|
If we consider the input and output channels as well as the `group` parameter, the complete kernel shape
|
|
5278
5482
|
will be :math:`(C_{out}, C_{in} / \text{group}, \text{kernel_size})`,
|
|
5279
5483
|
where `group` is the number of groups dividing `x`'s input channel when applying group convolution.
|
|
@@ -5284,7 +5488,7 @@ def conv1d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5284
5488
|
|
|
5285
5489
|
Note:
|
|
5286
5490
|
On Ascend platform, only group convolution in depthwise convolution scenarios is supported.
|
|
5287
|
-
That is, when `groups>1`, condition
|
|
5491
|
+
That is, when `groups>1`, condition :math:`C_{in}` = :math:`C_{out}` = `groups` must be satisfied.
|
|
5288
5492
|
|
|
5289
5493
|
Args:
|
|
5290
5494
|
input (Tensor): Input Tensor of shape :math:`(N, C_{in}, L_{in})`.
|
|
@@ -5353,13 +5557,12 @@ def conv1d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5353
5557
|
raise ValueError(f"For 'conv1d', the input must be a 3D Tensor, but got input of {input.ndim}D.")
|
|
5354
5558
|
if weight.ndim != 3:
|
|
5355
5559
|
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)
|
|
5560
|
+
expanded_input = expand_dims_(input, 2)
|
|
5358
5561
|
sqz = _get_cache_prim(P.Squeeze)(2)
|
|
5359
5562
|
weight_shape = weight.shape
|
|
5360
5563
|
out_channel = weight_shape[0]
|
|
5361
5564
|
kernel_size = (1, weight_shape[2])
|
|
5362
|
-
expanded_weight =
|
|
5565
|
+
expanded_weight = expand_dims_(weight, 2)
|
|
5363
5566
|
if isinstance(padding, int):
|
|
5364
5567
|
padding = (0, 0, padding, padding)
|
|
5365
5568
|
elif isinstance(padding, (tuple, list)):
|
|
@@ -5408,12 +5611,15 @@ def conv2d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5408
5611
|
, :math:`weight` is the convolution kernel value and :math:`X` represents the input feature map.
|
|
5409
5612
|
|
|
5410
5613
|
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
5614
|
|
|
5413
|
-
- :math:`
|
|
5414
|
-
|
|
5615
|
+
- :math:`i` corresponds to the batch number, the range is :math:`[0, N-1]`,
|
|
5616
|
+
where :math:`N` is the batch size of the input.
|
|
5617
|
+
|
|
5618
|
+
- :math:`j` corresponds to the output channel, the range is :math:`[0, C_{out}-1]`,
|
|
5619
|
+
where :math:`C_{out}` is the number of output channels, which is also equal to the number of kernels.
|
|
5415
5620
|
|
|
5416
|
-
- :math:`k` corresponds to the input channel,
|
|
5621
|
+
- :math:`k` corresponds to the input channel, the range is :math:`[0, C_{in}-1]`,
|
|
5622
|
+
where :math:`C_{in}` is the number of
|
|
5417
5623
|
input channels, which is also equal to the number of channels in the convolutional kernels.
|
|
5418
5624
|
|
|
5419
5625
|
Therefore, in the above formula, :math:`{bias}(C_{out_j})` represents the bias of the :math:`j`-th
|
|
@@ -5421,8 +5627,9 @@ def conv2d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5421
5627
|
kernel in the :math:`k`-th channel, and :math:`{X}(N_i, k)` represents the slice of the :math:`k`-th input
|
|
5422
5628
|
channel in the :math:`i`-th batch of the input feature map.
|
|
5423
5629
|
|
|
5424
|
-
The shape of the convolutional kernel is given by :math:`(
|
|
5425
|
-
where :math
|
|
5630
|
+
The shape of the convolutional kernel is given by :math:`(\text{kernel_size[0]}, \text{kernel_size[1]})`,
|
|
5631
|
+
where :math:`\text{kernel_size[0]}` and :math:`\text{kernel_size[1]}` are the height and width of the kernel,
|
|
5632
|
+
respectively.
|
|
5426
5633
|
If we consider the input and output channels as well as the `group` parameter, the complete kernel shape
|
|
5427
5634
|
will be :math:`(C_{out}, C_{in} / \text{group}, \text{kernel_size[0]}, \text{kernel_size[1]})`,
|
|
5428
5635
|
where `group` is the number of groups dividing `x`'s input channel when applying group convolution.
|
|
@@ -5433,7 +5640,7 @@ def conv2d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5433
5640
|
|
|
5434
5641
|
Note:
|
|
5435
5642
|
On Ascend platform, only group convolution in depthwise convolution scenarios is supported.
|
|
5436
|
-
That is, when `groups>1`, condition
|
|
5643
|
+
That is, when `groups>1`, condition :math:`C_{in}` = :math:`C_{out}` = `groups` must be satisfied.
|
|
5437
5644
|
|
|
5438
5645
|
Args:
|
|
5439
5646
|
input (Tensor): Tensor of shape :math:`(N, C_{in}, H_{in}, W_{in})`.
|
|
@@ -5478,7 +5685,7 @@ def conv2d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5478
5685
|
TypeError: If `stride`, `padding` or `dilation` is neither an int nor a tuple.
|
|
5479
5686
|
TypeError: `groups` is not an int.
|
|
5480
5687
|
TypeError: If `bias` is not a Tensor.
|
|
5481
|
-
ValueError: If the shape of `bias` is not :math:`C_{out}` .
|
|
5688
|
+
ValueError: If the shape of `bias` is not :math:`(C_{out})` .
|
|
5482
5689
|
ValueError: If `stride` or `dilation` is less than 1.
|
|
5483
5690
|
ValueError: If `pad_mode` is not one of 'same', 'valid' or 'pad'.
|
|
5484
5691
|
ValueError: If `padding` is a tuple/list whose length is not equal to 2.
|
|
@@ -5525,6 +5732,75 @@ def conv2d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5525
5732
|
return output
|
|
5526
5733
|
|
|
5527
5734
|
|
|
5735
|
+
def conv_transpose2d(input, weight, bias=None, stride=1, padding=0, output_padding=0, groups=1, dilation=1):
|
|
5736
|
+
r"""
|
|
5737
|
+
Calculates a 2D transposed convolution, which can be regarded as Conv2d for the gradient of the input,
|
|
5738
|
+
also called deconvolution (although it is not an actual deconvolution).
|
|
5739
|
+
|
|
5740
|
+
The input is typically of shape :math:`(N, C_{in}, H_{in}, W_{in})`,
|
|
5741
|
+
where :math:`N` is batch size, :math:`C_{in}` is space dimension,
|
|
5742
|
+
:math:`H_{in}, W_{in}` are the height and width of the feature layer respectively.
|
|
5743
|
+
|
|
5744
|
+
When Conv2d and Conv2dTranspose are initialized with the same parameters, and `pad_mode` is set to 'pad',
|
|
5745
|
+
:math:`dilation * (kernel\_size - 1) - padding` amount of zero will be paded to the height and width
|
|
5746
|
+
directions of the input, they are inverses of each other in regard to the input and output shapes in this case.
|
|
5747
|
+
However, when `stride` > 1, Conv2d maps multiple input shapes to the same output shape. Deconvolutional network
|
|
5748
|
+
can refer to `Deconvolutional Networks <https://www.matthewzeiler.com/mattzeiler/deconvolutionalnetworks.pdf>`_.
|
|
5749
|
+
|
|
5750
|
+
Args:
|
|
5751
|
+
input (Tensor): Tensor of shape :math:`(N, C_{in}, H_{in}, W_{in})`.
|
|
5752
|
+
weight (Tensor): Tensor of shape
|
|
5753
|
+
:math:`(N, C_{in} / \text{groups}, \text{kernel_size[0]}, \text{kernel_size[1]})`, then the size of kernel
|
|
5754
|
+
is :math:`(\text{kernel_size[0]}, \text{kernel_size[1]})`.
|
|
5755
|
+
bias (Tensor, optional): Bias Tensor with shape :math:`(C_{out})`.
|
|
5756
|
+
When bias is ``None`` , zeros will be used. Default: ``None`` .
|
|
5757
|
+
stride (Union(int, tuple[int]), optional): The distance of kernel moving, an int number that represents
|
|
5758
|
+
the height and width of movement are both strides, or a tuple of two int numbers that
|
|
5759
|
+
represent height and width of movement respectively. Default: ``1`` .
|
|
5760
|
+
padding (Union(int, tuple[int], list[int]), optional): Implicit paddings on both sides of the input `x`.
|
|
5761
|
+
Can be an integer or a tuple/list with 2 integers.
|
|
5762
|
+
output_padding (Union[int, tuple[int]]): The number of padding on the height and width directions of the output.
|
|
5763
|
+
The data type is an integer or a tuple of two integers. If `output_padding` is an integer,
|
|
5764
|
+
then the bottom and right padding are all equal to `output_padding`. If `output_padding` is a tuple of
|
|
5765
|
+
2 integers, then the bottom and right padding is equal to `output_padding[0]`, `output_padding[1]`
|
|
5766
|
+
respectively.
|
|
5767
|
+
groups (int, optional): Splits `input` into groups. Default: ``1`` .
|
|
5768
|
+
dilation (Union(int, tuple[int]), optional): Gaps between kernel elements.The data type is int or a tuple of
|
|
5769
|
+
2 integers. Specifies the dilation rate to use for dilated convolution. If set to be :math:`k > 1`,
|
|
5770
|
+
there will be :math:`k - 1` pixels skipped for each sampling location. Its value must
|
|
5771
|
+
be greater than or equal to 1 and bounded by the height and width of the input `x`. Default: ``1`` .
|
|
5772
|
+
|
|
5773
|
+
Returns:
|
|
5774
|
+
Tensor, the value that applied 2D convolution. The shape is :math:`(N, C_{out}, H_{out}, W_{out})`.
|
|
5775
|
+
To see how different pad modes affect the output shape, please refer to
|
|
5776
|
+
:class:`mindspore.nn.Conv2dTranspose` for more details.
|
|
5777
|
+
|
|
5778
|
+
|
|
5779
|
+
Raises:
|
|
5780
|
+
TypeError: If `stride`, `padding` or `dilation` is neither an int nor a tuple.
|
|
5781
|
+
TypeError: `groups` is not an int.
|
|
5782
|
+
TypeError: If `bias` is not a Tensor.
|
|
5783
|
+
ValueError: If the shape of `bias` is not :math:`(C_{out})` .
|
|
5784
|
+
ValueError: If `stride` or `dilation` is less than 1.
|
|
5785
|
+
ValueError: If `padding` is a tuple/list whose length is not equal to 2.
|
|
5786
|
+
|
|
5787
|
+
Supported Platforms:
|
|
5788
|
+
``Ascend``
|
|
5789
|
+
|
|
5790
|
+
Examples:
|
|
5791
|
+
>>> import mindspore
|
|
5792
|
+
>>> import numpy as np
|
|
5793
|
+
>>> from mindspore import Tensor, ops
|
|
5794
|
+
>>> x = Tensor(np.ones([1, 6, 32, 32]), mindspore.float32)
|
|
5795
|
+
>>> weight = Tensor(np.ones([6, 3, 5, 5]), mindspore.float32)
|
|
5796
|
+
>>> output = ops.conv_transpose2d(x, weight)
|
|
5797
|
+
>>> print(output.shape)
|
|
5798
|
+
(1, 3, 36, 36)
|
|
5799
|
+
"""
|
|
5800
|
+
conv = _get_cache_prim(Convolution)(stride, padding, dilation, True, output_padding, groups)
|
|
5801
|
+
return conv(input, weight, bias)
|
|
5802
|
+
|
|
5803
|
+
|
|
5528
5804
|
def hardsigmoid(input):
|
|
5529
5805
|
r"""
|
|
5530
5806
|
Hard sigmoid activation function.
|
|
@@ -5539,6 +5815,11 @@ def hardsigmoid(input):
|
|
|
5539
5815
|
|
|
5540
5816
|
where :math:`x_i` is an element of the input Tensor.
|
|
5541
5817
|
|
|
5818
|
+
HSigmoid Activation Function Graph:
|
|
5819
|
+
|
|
5820
|
+
.. image:: ../images/HSigmoid.png
|
|
5821
|
+
:align: center
|
|
5822
|
+
|
|
5542
5823
|
Args:
|
|
5543
5824
|
input (Tensor): The input Tensor.
|
|
5544
5825
|
|
|
@@ -5578,10 +5859,15 @@ def hardtanh(input, min_val=-1.0, max_val=1.0):
|
|
|
5578
5859
|
|
|
5579
5860
|
Linear region range :math:`[min\_val, max\_val]` can be adjusted using `min_val` and `max_val`.
|
|
5580
5861
|
|
|
5862
|
+
Hardtanh Activation Function Graph:
|
|
5863
|
+
|
|
5864
|
+
.. image:: ../images/Hardtanh.png
|
|
5865
|
+
:align: center
|
|
5866
|
+
|
|
5581
5867
|
Args:
|
|
5582
5868
|
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`` .
|
|
5869
|
+
min_val (Union[int, float], optional): Minimum value of the linear region range. Default: ``-1.0`` .
|
|
5870
|
+
max_val (Union[int, float], optional): Maximum value of the linear region range. Default: ``1.0`` .
|
|
5585
5871
|
|
|
5586
5872
|
Returns:
|
|
5587
5873
|
Tensor, with the same dtype and shape as `input`.
|
|
@@ -5606,18 +5892,18 @@ def hardtanh(input, min_val=-1.0, max_val=1.0):
|
|
|
5606
5892
|
_check_value_type("min_val", min_val, [int, float], "hardtanh")
|
|
5607
5893
|
_check_value_type("max_val", max_val, [int, float], "hardtanh")
|
|
5608
5894
|
input_dtype = input.dtype
|
|
5609
|
-
input =
|
|
5610
|
-
input =
|
|
5895
|
+
input = maximum_(input, min_val)
|
|
5896
|
+
input = minimum_(input, max_val)
|
|
5611
5897
|
return input.astype(input_dtype)
|
|
5612
5898
|
|
|
5613
5899
|
|
|
5614
5900
|
def huber_loss(input, target, reduction='mean', delta=1.0):
|
|
5615
5901
|
r"""
|
|
5616
5902
|
Calculates the error between the predicted value and the target value,
|
|
5617
|
-
which has the best of both the loss of
|
|
5903
|
+
which has the best of both the loss of :func:`mindspore.ops.l1_loss` and the loss of :func:`mindspore.ops.mse_loss`.
|
|
5618
5904
|
|
|
5619
5905
|
Assuming that the :math:`x` and :math:`y` are 1-D Tensor, length :math:`N`, the `reduction` parameter
|
|
5620
|
-
is set to ``
|
|
5906
|
+
is set to ``'none'`` then calculate the loss of :math:`x` and :math:`y` without dimensionality reduction.
|
|
5621
5907
|
The formula is as follows:
|
|
5622
5908
|
|
|
5623
5909
|
.. math::
|
|
@@ -5658,14 +5944,14 @@ def huber_loss(input, target, reduction='mean', delta=1.0):
|
|
|
5658
5944
|
The value must be greater than zero. Default: ``1.0`` .
|
|
5659
5945
|
|
|
5660
5946
|
Returns:
|
|
5661
|
-
Tensor or Scalar, if `reduction` is ``
|
|
5947
|
+
Tensor or Scalar, if `reduction` is ``'none'``, return a Tensor with same shape and dtype as `input`.
|
|
5662
5948
|
Otherwise, a scalar value will be returned.
|
|
5663
5949
|
|
|
5664
5950
|
Raises:
|
|
5665
5951
|
TypeError: If `input` or `target` is not a Tensor.
|
|
5666
5952
|
TypeError: If dtype of `delta` is neither float nor int.
|
|
5667
5953
|
ValueError: If `delta` is less than or equal to 0.
|
|
5668
|
-
ValueError: If `reduction` is not one of ``
|
|
5954
|
+
ValueError: If `reduction` is not one of ``'none'``, ``'mean'``, ``'sum'``.
|
|
5669
5955
|
ValueError: If `input` and `target` have different shapes and cannot be broadcasted to each other.
|
|
5670
5956
|
|
|
5671
5957
|
Supported Platforms:
|
|
@@ -5684,14 +5970,12 @@ def huber_loss(input, target, reduction='mean', delta=1.0):
|
|
|
5684
5970
|
_check_is_tensor('target', target, "huber_loss")
|
|
5685
5971
|
_check_value_type("delta", delta, [int, float], "huber_loss")
|
|
5686
5972
|
_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)
|
|
5973
|
+
z = sub_(input, target)
|
|
5974
|
+
z = abs_(z)
|
|
5975
|
+
cond = less_(z, delta)
|
|
5976
|
+
l1 = mul_(0.5, square_(z))
|
|
5977
|
+
l2 = mul_(delta, sub_(z, 0.5 * delta))
|
|
5978
|
+
loss = select_(cond, l1, l2)
|
|
5695
5979
|
return _get_loss(loss, reduction, "huber_loss")
|
|
5696
5980
|
|
|
5697
5981
|
|
|
@@ -5743,7 +6027,7 @@ def adaptive_avg_pool1d(input, output_size):
|
|
|
5743
6027
|
"""
|
|
5744
6028
|
def _check(x, output_size):
|
|
5745
6029
|
x_in_shape = x.shape
|
|
5746
|
-
x_dtype =
|
|
6030
|
+
x_dtype = dtype_(x)
|
|
5747
6031
|
if not isinstance(x, (Tensor, Tensor_)):
|
|
5748
6032
|
raise TypeError("For adaptive_avg_pool1d, the input input must be tensor")
|
|
5749
6033
|
|
|
@@ -5763,24 +6047,130 @@ def adaptive_avg_pool1d(input, output_size):
|
|
|
5763
6047
|
|
|
5764
6048
|
_check(input, output_size)
|
|
5765
6049
|
x_in_shape = input.shape
|
|
5766
|
-
expand_ = _get_cache_prim(P.ExpandDims)()
|
|
5767
6050
|
squeeze_ = _get_cache_prim(P.Squeeze)(2)
|
|
5768
|
-
|
|
5769
6051
|
width = x_in_shape[2]
|
|
5770
6052
|
stride = width // output_size
|
|
5771
6053
|
kernel_size = width - (output_size - 1) * stride
|
|
5772
6054
|
stride = (1, width // output_size)
|
|
5773
6055
|
kernel_size = (1, kernel_size)
|
|
5774
|
-
|
|
5775
6056
|
avg_pool_ = _get_cache_prim(P.AvgPool)(kernel_size=kernel_size, strides=stride)
|
|
5776
|
-
|
|
5777
|
-
input = expand_(input, 2)
|
|
6057
|
+
input = expand_dims_(input, 2)
|
|
5778
6058
|
input = avg_pool_(input)
|
|
5779
6059
|
input = squeeze_(input)
|
|
5780
|
-
|
|
5781
6060
|
return input
|
|
5782
6061
|
|
|
5783
6062
|
|
|
6063
|
+
def layer_norm(input, normalized_shape, weight=None, bias=None, eps=1e-5):
|
|
6064
|
+
r"""Applies the Layer Normalization to the input tensor.
|
|
6065
|
+
|
|
6066
|
+
This operator will normalize the input tensor on given axis. LayerNorm is described in the paper
|
|
6067
|
+
`Layer Normalization <https://arxiv.org/abs/1607.06450>`_.
|
|
6068
|
+
|
|
6069
|
+
.. math::
|
|
6070
|
+
y = \frac{x - mean}{\sqrt{variance + \epsilon}} * \gamma + \beta
|
|
6071
|
+
|
|
6072
|
+
where :math:`\gamma` is weight, :math:`\beta` is bias, :math:`\epsilon` is eps.
|
|
6073
|
+
|
|
6074
|
+
Args:
|
|
6075
|
+
input (Tensor): Tensor of shape :math:`(N, \ldots)`. The input of LayerNorm.
|
|
6076
|
+
normalized_shape (Union(int, tuple[int], list[int])): The normalized shape of `input` for LayerNorm.
|
|
6077
|
+
`normalized_shape` equal to `input_shape[begin_norm_axis:]`, where `begin_norm_axis` represents the axis
|
|
6078
|
+
where normalization begins.
|
|
6079
|
+
weight (Tensor, optional): Learnable parameter :math:`\gamma` . Tensor of shape `normalized_shape`.
|
|
6080
|
+
Default: ``None``, has the same data type with `input`. Initialized to ``1`` when `weight` is None.
|
|
6081
|
+
bias (Tensor, optional): Learnable parameter :math:`\beta` . Tensor of shape `normalized_shape`.
|
|
6082
|
+
Default: ``None``, has the same data type with `input`. Initialized to ``0`` when `bias` is None.
|
|
6083
|
+
eps (float, optional): A value added to the denominator for numerical stability(:math:`\epsilon`).
|
|
6084
|
+
Default: ``1e-5`` .
|
|
6085
|
+
|
|
6086
|
+
Returns:
|
|
6087
|
+
- **output** (Tensor) - The normalized input, has the same type and shape as the `input`.
|
|
6088
|
+
|
|
6089
|
+
Raises:
|
|
6090
|
+
TypeError: If `input` is not a Tensor.
|
|
6091
|
+
TypeError: If `normalized_shape` is not an integer, a list or a tuple.
|
|
6092
|
+
TypeError: If `eps` is not a float.
|
|
6093
|
+
|
|
6094
|
+
Supported Platforms:
|
|
6095
|
+
``Ascend``
|
|
6096
|
+
|
|
6097
|
+
Examples:
|
|
6098
|
+
>>> import mindspore
|
|
6099
|
+
>>> import numpy as np
|
|
6100
|
+
>>> from mindspore import Tensor, ops
|
|
6101
|
+
>>> input_x = Tensor(np.array([[1, 2, 3], [1, 2, 3]]), mindspore.float32)
|
|
6102
|
+
>>> normalized_shape = (3,)
|
|
6103
|
+
>>> gamma = Tensor(np.ones(normalized_shape), mindspore.float32)
|
|
6104
|
+
>>> beta = Tensor(np.zeros(normalized_shape), mindspore.float32)
|
|
6105
|
+
>>> eps = 1e-7
|
|
6106
|
+
>>> output = ops.layer_norm(input_x, normalized_shape, gamma, beta, eps)
|
|
6107
|
+
>>> print(output)
|
|
6108
|
+
[[-1.2247448 0. 1.2247448]
|
|
6109
|
+
[-1.2247448 0. 1.2247448]]
|
|
6110
|
+
"""
|
|
6111
|
+
if weight is None:
|
|
6112
|
+
weight = ops.ones(normalized_shape, dtype=input.dtype)
|
|
6113
|
+
if bias is None:
|
|
6114
|
+
bias = ops.zeros(normalized_shape, dtype=input.dtype)
|
|
6115
|
+
layer_norm_ext_op = LayerNormExt()
|
|
6116
|
+
return layer_norm_ext_op(input, normalized_shape, weight, bias, eps)[0]
|
|
6117
|
+
|
|
6118
|
+
|
|
6119
|
+
def group_norm(input, num_groups, weight=None, bias=None, eps=1e-5):
|
|
6120
|
+
r"""Group Normalization over a mini-batch of inputs.
|
|
6121
|
+
|
|
6122
|
+
Group Normalization is widely used in recurrent neural networks. It applies
|
|
6123
|
+
normalization on a mini-batch of inputs for each single training case as described
|
|
6124
|
+
in the paper `Group Normalization <https://arxiv.org/pdf/1803.08494.pdf>`_. Group Normalization
|
|
6125
|
+
divides the channels into groups and computes within each group the mean and variance for normalization,
|
|
6126
|
+
and it performs very stable over a wide range of batch size. :math:`\gamma` and :math:`\beta` are trainable scale
|
|
6127
|
+
and shift.
|
|
6128
|
+
It can be described using the following formula:
|
|
6129
|
+
|
|
6130
|
+
.. math::
|
|
6131
|
+
y = \frac{x - \mathrm{E}[x]}{\sqrt{\mathrm{Var}[x] + \epsilon}} * \gamma + \beta
|
|
6132
|
+
|
|
6133
|
+
where :math:`\gamma` is `weight`, :math:`\beta` is `bias`, :math:`\epsilon` is `eps`.
|
|
6134
|
+
|
|
6135
|
+
Args:
|
|
6136
|
+
input (Tensor) : The input feature with shape :math:`(N, C, *)` where :math:`*` means, any number of
|
|
6137
|
+
additional dimensions.
|
|
6138
|
+
num_groups (int): The number of groups to be divided along the channel dimension.
|
|
6139
|
+
weight (Tensor, optional): The shape :math:`(C,)`, Default: ``None``, has the same data type with `input`.
|
|
6140
|
+
bias (Tensor, optional): The shape :math:`(C,)`, Default: ``None``, has the same data type with `input`.
|
|
6141
|
+
eps (float, optional): A value added to the denominator for numerical stability. Default: ``1e-5`` .
|
|
6142
|
+
|
|
6143
|
+
Returns:
|
|
6144
|
+
Tensor, the normalized and scaled offset tensor, has the same shape and data type as the `input`.
|
|
6145
|
+
|
|
6146
|
+
Raises:
|
|
6147
|
+
TypeError: If `num_groups` is not an int.
|
|
6148
|
+
TypeError: If `eps` is not a float.
|
|
6149
|
+
ValueError: If `num_groups` is less than 1.
|
|
6150
|
+
ValueError: If `C` (the second parameter of dimensions of `input`) is not divided by `num_groups`.
|
|
6151
|
+
|
|
6152
|
+
Supported Platforms:
|
|
6153
|
+
``Ascend`` ``GPU`` ``CPU``
|
|
6154
|
+
|
|
6155
|
+
Examples:
|
|
6156
|
+
>>> import mindspore as ms
|
|
6157
|
+
>>> import numpy as np
|
|
6158
|
+
>>> from mindspore.ops import group_norm
|
|
6159
|
+
>>> x = ms.Tensor(np.ones([1, 2, 4, 4], np.float32))
|
|
6160
|
+
>>> output = group_norm(x, 2)
|
|
6161
|
+
>>> print(output)
|
|
6162
|
+
[[[[0. 0. 0. 0.]
|
|
6163
|
+
[0. 0. 0. 0.]
|
|
6164
|
+
[0. 0. 0. 0.]
|
|
6165
|
+
[0. 0. 0. 0.]]
|
|
6166
|
+
[[0. 0. 0. 0.]
|
|
6167
|
+
[0. 0. 0. 0.]
|
|
6168
|
+
[0. 0. 0. 0.]
|
|
6169
|
+
[0. 0. 0. 0.]]]]
|
|
6170
|
+
"""
|
|
6171
|
+
group_norm_op = GroupNorm()
|
|
6172
|
+
return group_norm_op(input, num_groups, weight, bias, eps)[0]
|
|
6173
|
+
|
|
5784
6174
|
def batch_norm(input_x, running_mean, running_var, weight, bias, training=False, momentum=0.1, eps=1e-5):
|
|
5785
6175
|
r"""
|
|
5786
6176
|
Batch Normalization for input data and updated parameters.
|
|
@@ -5800,7 +6190,8 @@ def batch_norm(input_x, running_mean, running_var, weight, bias, training=False,
|
|
|
5800
6190
|
mean of :math:`x`, :math:`variance` is the variance of :math:`x`.
|
|
5801
6191
|
|
|
5802
6192
|
.. warning::
|
|
5803
|
-
- For
|
|
6193
|
+
- For Atlas 200/300/500 inference product,
|
|
6194
|
+
the result accuracy fails to reach 1‰ due to the square root instruction.
|
|
5804
6195
|
|
|
5805
6196
|
Note:
|
|
5806
6197
|
- If `training` is `False`, `weight`, `bias`, `running_mean` and `running_var` are Tensors.
|
|
@@ -5962,7 +6353,7 @@ def conv3d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5962
6353
|
r"""
|
|
5963
6354
|
Applies a 3D convolution over an input tensor. The input tensor is typically of
|
|
5964
6355
|
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`
|
|
6356
|
+
is channel number, :math:`D, H, W` are the depth, height and width of the feature graph, respectively.
|
|
5966
6357
|
|
|
5967
6358
|
The output is calculated based on formula:
|
|
5968
6359
|
|
|
@@ -5972,26 +6363,30 @@ def conv3d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5972
6363
|
\sum_{k = 0}^{C_{in} - 1} \text{ccor}({\text{weight}(C_{\text{out}_j}, k), \text{X}(N_i, k)})
|
|
5973
6364
|
|
|
5974
6365
|
where :math:`bias` is the output channel bias, :math:`ccor` is
|
|
5975
|
-
the `cross-correlation <https://en.wikipedia.org/wiki/Cross-correlation>`_
|
|
6366
|
+
the `cross-correlation <https://en.wikipedia.org/wiki/Cross-correlation>`_
|
|
5976
6367
|
, :math:`weight` is the convolution kernel value and :math:`X` represents the input feature map.
|
|
5977
6368
|
|
|
5978
6369
|
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
6370
|
|
|
5981
|
-
- :math:`
|
|
6371
|
+
- :math:`i` corresponds to the batch number, the range is :math:`[0, N-1]`,
|
|
6372
|
+
where :math:`N` is the batch size of the input.
|
|
6373
|
+
|
|
6374
|
+
- :math:`j` corresponds to the output channel, the range is :math:`[0, C_{out}-1]`,
|
|
6375
|
+
where :math:`C_{out}` is the number of
|
|
5982
6376
|
output channels, which is also equal to the number of kernels.
|
|
5983
6377
|
|
|
5984
|
-
- :math:`k` corresponds to the input channel,
|
|
6378
|
+
- :math:`k` corresponds to the input channel, the range is :math:`[0, C_{in}-1]`,
|
|
6379
|
+
where :math:`C_{in}` is the number of
|
|
5985
6380
|
input channels, which is also equal to the number of channels in the convolutional kernels.
|
|
5986
6381
|
|
|
5987
|
-
Therefore, in the above formula, :math:`{bias}(C_{
|
|
5988
|
-
output channel, :math:`{weight}(C_{
|
|
6382
|
+
Therefore, in the above formula, :math:`{bias}(C_{\text{out}_j})` represents the bias of the :math:`j`-th
|
|
6383
|
+
output channel, :math:`{weight}(C_{\text{out}_j}, k)` represents the slice of the :math:`j`-th convolutional
|
|
5989
6384
|
kernel in the :math:`k`-th channel, and :math:`{X}(N_i, k)` represents the slice of the :math:`k`-th input
|
|
5990
6385
|
channel in the :math:`i`-th batch of the input feature map.
|
|
5991
6386
|
|
|
5992
6387
|
The shape of the convolutional kernel is given by
|
|
5993
6388
|
:math:`(\text{kernel_size[0]}, \text{kernel_size[1]}, \text{kernel_size[2]})`
|
|
5994
|
-
where :math
|
|
6389
|
+
where :math:`\text{kernel_size[0]}` , :math:`\text{kernel_size[1]}` and :math:`\text{kernel_size[2]}` are the depth,
|
|
5995
6390
|
height and width of the kernel, respectively.
|
|
5996
6391
|
If we consider the input and output channels as well as the `group` parameter, the complete kernel shape
|
|
5997
6392
|
will be :math:`(C_{out}, C_{in} / \text{group}, \text{kernel_size[0]},
|
|
@@ -6002,8 +6397,8 @@ def conv3d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
6002
6397
|
<http://vision.stanford.edu/cs598_spring07/papers/Lecun98.pdf>`_.
|
|
6003
6398
|
|
|
6004
6399
|
Note:
|
|
6005
|
-
1. On Ascend platform,
|
|
6006
|
-
2. On Ascend dilation
|
|
6400
|
+
1. On Ascend platform, :math:`groups = 1` must be satisfied.
|
|
6401
|
+
2. On Ascend platform, :math:`dilation=1` must be satisfied.
|
|
6007
6402
|
|
|
6008
6403
|
Args:
|
|
6009
6404
|
input (Tensor): Tensor of shape :math:`(N, C_{in}, D_{in}, H_{in}, W_{in})`.
|
|
@@ -6042,8 +6437,7 @@ def conv3d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
6042
6437
|
there will be :math:`k - 1` pixels skipped for each sampling location.
|
|
6043
6438
|
The value ranges for the depth, height, and width dimensions are [1, D], [1, H], and [1, W],
|
|
6044
6439
|
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`` .
|
|
6440
|
+
groups (int, optional):The number of groups into which the filter is divided. Default: ``1`` .
|
|
6047
6441
|
|
|
6048
6442
|
Returns:
|
|
6049
6443
|
Tensor, the value that applied 3D convolution. The shape is :math:`(N, C_{out}, D_{out}, H_{out}, W_{out})`.
|
|
@@ -6085,7 +6479,7 @@ def conv3d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
6085
6479
|
TypeError: If `out_channel` or `groups` is not an int.
|
|
6086
6480
|
TypeError: If `stride`, `padding` or `dilation` is neither an int nor a tuple.
|
|
6087
6481
|
TypeError: If `bias` is not a Tensor.
|
|
6088
|
-
ValueError: If the shape of `bias` is not :math:`C_{out}`.
|
|
6482
|
+
ValueError: If the shape of `bias` is not :math:`(C_{out})`.
|
|
6089
6483
|
ValueError: If `stride` or `dilation` is less than 1.
|
|
6090
6484
|
ValueError: If `pad_mode` is not one of 'same', 'valid' or 'pad'.
|
|
6091
6485
|
ValueError: If `padding` is a tuple or list whose length is not equal to 3.
|
|
@@ -6193,21 +6587,19 @@ def pixel_shuffle(input, upscale_factor):
|
|
|
6193
6587
|
_check_positive_int(upscale_factor, "upscale_factor")
|
|
6194
6588
|
_check_is_tensor("input", input, "pixel_shuffle")
|
|
6195
6589
|
_check_pixel_shuffle_unshuffle_input_shape(input, "pixel_shuffle")
|
|
6196
|
-
idx =
|
|
6590
|
+
idx = shape_(input)
|
|
6197
6591
|
length = input.ndim
|
|
6198
6592
|
pre = idx[:-3]
|
|
6199
6593
|
c, h, w = idx[-3:]
|
|
6200
6594
|
_check_pxiel_shuffle_valid(c, upscale_factor)
|
|
6201
6595
|
c = c // upscale_factor ** 2
|
|
6202
6596
|
input_perm = (pre + (c, upscale_factor, upscale_factor, h, w))
|
|
6203
|
-
|
|
6204
|
-
transpose = _get_cache_prim(P.Transpose)()
|
|
6205
|
-
input = reshape(input, input_perm)
|
|
6597
|
+
input = reshape_(input, input_perm)
|
|
6206
6598
|
input_perm = [i for i in range(length - 2)]
|
|
6207
6599
|
input_perm = input_perm + [length, length - 2, length + 1, length - 1]
|
|
6208
6600
|
input_perm = tuple(input_perm)
|
|
6209
|
-
input =
|
|
6210
|
-
input =
|
|
6601
|
+
input = transpose_(input, input_perm)
|
|
6602
|
+
input = reshape_(input, (pre + (c, upscale_factor * h, upscale_factor * w)))
|
|
6211
6603
|
return input
|
|
6212
6604
|
|
|
6213
6605
|
|
|
@@ -6258,7 +6650,7 @@ def pixel_unshuffle(input, downscale_factor):
|
|
|
6258
6650
|
_check_positive_int(downscale_factor, "downscale_factor")
|
|
6259
6651
|
_check_is_tensor("input", input, "pixel_unshuffle")
|
|
6260
6652
|
_check_pixel_shuffle_unshuffle_input_shape(input, "pixel_unshuffle")
|
|
6261
|
-
idx =
|
|
6653
|
+
idx = shape_(input)
|
|
6262
6654
|
length = input.ndim
|
|
6263
6655
|
pre = idx[:-3]
|
|
6264
6656
|
c, h, w = idx[-3:]
|
|
@@ -6266,14 +6658,12 @@ def pixel_unshuffle(input, downscale_factor):
|
|
|
6266
6658
|
h = h // downscale_factor
|
|
6267
6659
|
w = w // downscale_factor
|
|
6268
6660
|
input_perm = (pre + (c, h, downscale_factor, w, downscale_factor))
|
|
6269
|
-
|
|
6270
|
-
transpose = _get_cache_prim(P.Transpose)()
|
|
6271
|
-
input = reshape(input, input_perm)
|
|
6661
|
+
input = reshape_(input, input_perm)
|
|
6272
6662
|
input_perm = [i for i in range(length - 2)]
|
|
6273
6663
|
input_perm = input_perm + [length - 1, length + 1, length - 2, length]
|
|
6274
6664
|
input_perm = tuple(input_perm)
|
|
6275
|
-
input =
|
|
6276
|
-
input =
|
|
6665
|
+
input = transpose_(input, input_perm)
|
|
6666
|
+
input = reshape_(input, (pre + (c * downscale_factor * downscale_factor, h, w)))
|
|
6277
6667
|
return input
|
|
6278
6668
|
|
|
6279
6669
|
|
|
@@ -6290,7 +6680,7 @@ def glu(x, axis=-1):
|
|
|
6290
6680
|
See `Language Modeling with Gated Convluational Networks <https://arxiv.org/abs/1612.08083>`_.
|
|
6291
6681
|
|
|
6292
6682
|
Args:
|
|
6293
|
-
x (Tensor): Tensor to be
|
|
6683
|
+
x (Tensor): Tensor to be split. Its dtype is Number, and shape is :math:`(\ast_1, N, \ast_2)`
|
|
6294
6684
|
where `*` means, any number of additional dimensions.
|
|
6295
6685
|
axis (int, optional): the axis to split the input. It must be int. Default: ``-1`` , the last axis of `x`.
|
|
6296
6686
|
|
|
@@ -6312,9 +6702,6 @@ def glu(x, axis=-1):
|
|
|
6312
6702
|
[[0.05744425 0.11973753]
|
|
6313
6703
|
[0.33409387 0.41398472]]
|
|
6314
6704
|
"""
|
|
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
6705
|
spilt = _get_cache_prim(P.Split)(axis=axis, output_num=2)
|
|
6319
6706
|
x, y = spilt(x)
|
|
6320
6707
|
y = sigmoid_(y)
|
|
@@ -6334,7 +6721,7 @@ def multi_margin_loss(input, target, p=1, margin=1, weight=None, reduction='mean
|
|
|
6334
6721
|
.. math::
|
|
6335
6722
|
\text{loss}(x, y) = \frac{\sum_i \max(0, \text{margin} - x[y] + x[i])^p}{\text{x.size}(0)}
|
|
6336
6723
|
|
|
6337
|
-
where :math:`i\in \{0,⋯,x.size(0)
|
|
6724
|
+
where :math:`i\in \{0,⋯,x.size(0)-1\}` and :math:`i \ne y`.
|
|
6338
6725
|
|
|
6339
6726
|
Args:
|
|
6340
6727
|
input (Tensor): Input , with shape :math:`(N, C)`. Data type only support float32, float16 or float64.
|
|
@@ -6353,8 +6740,8 @@ def multi_margin_loss(input, target, p=1, margin=1, weight=None, reduction='mean
|
|
|
6353
6740
|
- ``'sum'``: the output elements will be summed.
|
|
6354
6741
|
|
|
6355
6742
|
Returns:
|
|
6356
|
-
Tensor. If `reduction` is ``'none'``, returns a Tensor with the same shape as `target`.
|
|
6357
|
-
|
|
6743
|
+
- **outputs** - Tensor. If `reduction` is ``'none'``, returns a Tensor with the same shape as `target`.
|
|
6744
|
+
Otherwise, it is a scalar.
|
|
6358
6745
|
|
|
6359
6746
|
Raises:
|
|
6360
6747
|
TypeError: If dtype of `p` or `target` is not int.
|
|
@@ -6413,10 +6800,11 @@ def multilabel_margin_loss(input, target, reduction='mean'):
|
|
|
6413
6800
|
This allows for different samples to have variable amounts of target classes.
|
|
6414
6801
|
|
|
6415
6802
|
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
|
-
|
|
6803
|
+
input (Tensor): Predict data, :math:`x` in the formula above. Tensor of shape :math:`(C)`
|
|
6804
|
+
or :math:`(N, C)`, where :math:`N` is the batch size and :math:`C` is the number of classes.
|
|
6805
|
+
Data type must be float16 or float32.
|
|
6806
|
+
target (Tensor): Ground truth data, :math:`y` in the formula above, with the same shape as `input`,
|
|
6807
|
+
data type must be int32 and label targets padded by -1.
|
|
6420
6808
|
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
6421
6809
|
``'sum'`` . Default: ``'mean'`` .
|
|
6422
6810
|
|
|
@@ -6492,9 +6880,6 @@ def multilabel_soft_margin_loss(input, target, weight=None, reduction='mean'):
|
|
|
6492
6880
|
Tensor, the data type is the same as input, if the `reduction` is ``'none'``,
|
|
6493
6881
|
its shape is :math:`(N)` , otherwise it is zero.
|
|
6494
6882
|
|
|
6495
|
-
Raises:
|
|
6496
|
-
ValueError: If the rank of `input` or `target` is not 2.
|
|
6497
|
-
|
|
6498
6883
|
Supported Platforms:
|
|
6499
6884
|
``Ascend`` ``GPU`` ``CPU``
|
|
6500
6885
|
|
|
@@ -6509,81 +6894,22 @@ def multilabel_soft_margin_loss(input, target, weight=None, reduction='mean'):
|
|
|
6509
6894
|
cls_name = "multilabel_soft_margin_loss"
|
|
6510
6895
|
_check_is_tensor('input', input, cls_name)
|
|
6511
6896
|
_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
6897
|
|
|
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
6898
|
input_shape = input.shape
|
|
6524
6899
|
if ops.is_sequence_value_unknown(input_shape):
|
|
6525
|
-
input_shape =
|
|
6900
|
+
input_shape = tensor_shape_(input)
|
|
6526
6901
|
|
|
6527
|
-
pos =
|
|
6528
|
-
neg =
|
|
6529
|
-
loss =
|
|
6902
|
+
pos = log_(add_(exp_(-input), 1))
|
|
6903
|
+
neg = log_(add_(exp_(input), 1))
|
|
6904
|
+
loss = mul_(target, pos) + mul_(1 - target, neg)
|
|
6530
6905
|
if weight is not None:
|
|
6531
|
-
loss =
|
|
6906
|
+
loss = mul_(loss, weight)
|
|
6532
6907
|
class_dim = input.ndim - 1
|
|
6533
6908
|
loss = loss.sum(axis=class_dim) / input_shape[class_dim]
|
|
6534
6909
|
return _get_loss(loss, reduction, cls_name)
|
|
6535
6910
|
|
|
6536
6911
|
|
|
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'):
|
|
6912
|
+
def gelu(input, approximate='none'):
|
|
6587
6913
|
r"""
|
|
6588
6914
|
Gaussian Error Linear Units activation function.
|
|
6589
6915
|
|
|
@@ -6604,18 +6930,25 @@ def gelu(input_x, approximate='none'):
|
|
|
6604
6930
|
.. math::
|
|
6605
6931
|
GELU(x_i) = 0.5 * x_i * (1 + \tanh(\sqrt(2 / \pi) * (x_i + 0.044715 * x_i^3)))
|
|
6606
6932
|
|
|
6933
|
+
For the related GELU graph, refer to `GELU <https://en.wikipedia.org/wiki/Activation_function#/media/File:Activation_gelu.png>`_ .
|
|
6934
|
+
|
|
6935
|
+
GELU Activation Function Graph:
|
|
6936
|
+
|
|
6937
|
+
.. image:: ../images/GELU.png
|
|
6938
|
+
:align: center
|
|
6939
|
+
|
|
6607
6940
|
Args:
|
|
6608
|
-
|
|
6941
|
+
input (Tensor): The input of the activation function GeLU, the data type is float16, float32 or float64.
|
|
6609
6942
|
approximate (str): the gelu approximation algorithm to use. Acceptable vaslues are ``'none'`` and ``'tanh'`` .
|
|
6610
6943
|
Default: ``'none'`` .
|
|
6611
6944
|
|
|
6612
6945
|
Returns:
|
|
6613
|
-
Tensor, with the same type and shape as `
|
|
6946
|
+
Tensor, with the same type and shape as `input`.
|
|
6614
6947
|
|
|
6615
6948
|
Raises:
|
|
6616
|
-
TypeError: If `
|
|
6617
|
-
TypeError: If dtype of `
|
|
6618
|
-
ValueError: If `approximate` value is neither `none`
|
|
6949
|
+
TypeError: If `input` is not a Tensor.
|
|
6950
|
+
TypeError: If dtype of `input` is not bfloat16, float16, float32 or float64.
|
|
6951
|
+
ValueError: If `approximate` value is neither `none` nor `tanh`.
|
|
6619
6952
|
|
|
6620
6953
|
Supported Platforms:
|
|
6621
6954
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -6631,17 +6964,17 @@ def gelu(input_x, approximate='none'):
|
|
|
6631
6964
|
if approximate not in ['none', 'tanh']:
|
|
6632
6965
|
raise ValueError("For ops.gelu, approximate value should be either 'none' or 'tanh'.")
|
|
6633
6966
|
|
|
6634
|
-
x_dtype =
|
|
6635
|
-
if x_dtype not in [mstype.float16, mstype.float32, mstype.float64]:
|
|
6967
|
+
x_dtype = dtype_(input)
|
|
6968
|
+
if x_dtype not in [mstype.float16, mstype.float32, mstype.float64, mstype.bfloat16]:
|
|
6636
6969
|
raise TypeError(f"For gelu, the input dtype must be float16, float32 or float64, "
|
|
6637
6970
|
f"but got {x_dtype}.")
|
|
6638
6971
|
if approximate == 'tanh':
|
|
6639
|
-
output =
|
|
6972
|
+
output = gelu_(input)
|
|
6640
6973
|
else:
|
|
6641
|
-
output =
|
|
6642
|
-
output =
|
|
6643
|
-
output =
|
|
6644
|
-
output =
|
|
6974
|
+
output = sqrt_(Tensor(2.0, x_dtype))
|
|
6975
|
+
output = div_(input, output)
|
|
6976
|
+
output = erf_(output) + Tensor(1.0, x_dtype)
|
|
6977
|
+
output = input * output * Tensor(0.5, x_dtype)
|
|
6645
6978
|
|
|
6646
6979
|
return output
|
|
6647
6980
|
|
|
@@ -6691,13 +7024,6 @@ def channel_shuffle(x, groups):
|
|
|
6691
7024
|
return y
|
|
6692
7025
|
|
|
6693
7026
|
|
|
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
7027
|
def lp_pool1d(x, norm_type, kernel_size, stride=None, ceil_mode=False):
|
|
6702
7028
|
r"""
|
|
6703
7029
|
Applying 1D LPPooling operation on an input Tensor can be regarded as forming a 1D input plane.
|
|
@@ -6733,7 +7059,7 @@ def lp_pool1d(x, norm_type, kernel_size, stride=None, ceil_mode=False):
|
|
|
6733
7059
|
L_{out} = \left\lfloor\frac{L_{in} - \text{kernel_size}}{\text{stride}} + 1\right\rfloor
|
|
6734
7060
|
|
|
6735
7061
|
Raises:
|
|
6736
|
-
TypeError: If `x` is not
|
|
7062
|
+
TypeError: If `x` is not a Tensor.
|
|
6737
7063
|
TypeError: If `kernel_size` or `stride` is not an int.
|
|
6738
7064
|
TypeError: If `ceil_mode` is not a bool.
|
|
6739
7065
|
TypeError: If `norm_type` is neither float nor int.
|
|
@@ -6759,7 +7085,6 @@ def lp_pool1d(x, norm_type, kernel_size, stride=None, ceil_mode=False):
|
|
|
6759
7085
|
[51. 54.]
|
|
6760
7086
|
[63. 66.]]]
|
|
6761
7087
|
"""
|
|
6762
|
-
_shape_check(x.shape, [2, 3], "lp_pool1d")
|
|
6763
7088
|
if isinstance(norm_type, (float, int)):
|
|
6764
7089
|
norm_type = float(norm_type)
|
|
6765
7090
|
else:
|
|
@@ -6818,7 +7143,7 @@ def lp_pool2d(x, norm_type, kernel_size, stride=None, ceil_mode=False):
|
|
|
6818
7143
|
W_{out} = \left\lfloor\frac{W_{in} - \text{kernel_size}[1]}{\text{stride}[1]} + 1\right\rfloor
|
|
6819
7144
|
|
|
6820
7145
|
Raises:
|
|
6821
|
-
TypeError: If `x` is not
|
|
7146
|
+
TypeError: If `x` is not a Tensor.
|
|
6822
7147
|
TypeError: If `kernel_size` or `stride` is neither int nor tuple.
|
|
6823
7148
|
TypeError: If `ceil_mode` is not a bool.
|
|
6824
7149
|
TypeError: If `norm_type` is neither float nor int.
|
|
@@ -6852,7 +7177,6 @@ def lp_pool2d(x, norm_type, kernel_size, stride=None, ceil_mode=False):
|
|
|
6852
7177
|
[ 999. 1008. 1017.]]]]
|
|
6853
7178
|
|
|
6854
7179
|
"""
|
|
6855
|
-
_shape_check(x.shape, [4], "lp_pool2d")
|
|
6856
7180
|
if isinstance(norm_type, (float, int)):
|
|
6857
7181
|
norm_type = float(norm_type)
|
|
6858
7182
|
else:
|
|
@@ -6915,13 +7239,13 @@ def mse_loss(input, target, reduction='mean'):
|
|
|
6915
7239
|
if reduction not in ['mean', 'none', 'sum']:
|
|
6916
7240
|
raise ValueError("For ops.mse_loss, `reduction` value should be either 'mean', 'none' or 'sum'.")
|
|
6917
7241
|
|
|
6918
|
-
x =
|
|
7242
|
+
x = square_(input - target)
|
|
6919
7243
|
float_type = (mstype.float16, mstype.float32, mstype.float64)
|
|
6920
7244
|
if x.dtype not in float_type:
|
|
6921
7245
|
input_dtype = mstype.float32
|
|
6922
7246
|
else:
|
|
6923
7247
|
input_dtype = x.dtype
|
|
6924
|
-
x =
|
|
7248
|
+
x = cast_(x, mstype.float32)
|
|
6925
7249
|
|
|
6926
7250
|
average_flag = True
|
|
6927
7251
|
reduce_flag = True
|
|
@@ -6931,12 +7255,12 @@ def mse_loss(input, target, reduction='mean'):
|
|
|
6931
7255
|
reduce_flag = False
|
|
6932
7256
|
|
|
6933
7257
|
if reduce_flag and average_flag:
|
|
6934
|
-
x =
|
|
7258
|
+
x = reduce_mean_(x, _get_axis(x))
|
|
6935
7259
|
|
|
6936
7260
|
if reduce_flag and not average_flag:
|
|
6937
|
-
x =
|
|
7261
|
+
x = reduce_sum_(x, _get_axis(x))
|
|
6938
7262
|
|
|
6939
|
-
return
|
|
7263
|
+
return cast_(x, input_dtype)
|
|
6940
7264
|
|
|
6941
7265
|
|
|
6942
7266
|
def msort(input):
|
|
@@ -6998,7 +7322,7 @@ def triplet_margin_loss(anchor, positive, negative, margin=1.0, p=2, eps=1e-06,
|
|
|
6998
7322
|
Tensor. If `reduction` is ``"none"``, its shape is :math:`(N)`. Otherwise, a scalar value will be returned.
|
|
6999
7323
|
|
|
7000
7324
|
Raises:
|
|
7001
|
-
TypeError: If `anchor` or `positive` or
|
|
7325
|
+
TypeError: If `anchor` or `positive` or `negative` is not a Tensor.
|
|
7002
7326
|
TypeError: If dtype of `anchor`, `positive` and `negative` is not the same.
|
|
7003
7327
|
TypeError: If `margin` is not a float.
|
|
7004
7328
|
TypeError: If `p` is not an int.
|
|
@@ -7337,7 +7661,7 @@ def multi_head_attention_forward(query, key, value, embed_dim_to_check, num_head
|
|
|
7337
7661
|
|
|
7338
7662
|
if attn_mask is not None and attn_mask.dtype == mstype.bool_:
|
|
7339
7663
|
new_attn_mask = ops.zeros_like(attn_mask, dtype=q.dtype)
|
|
7340
|
-
attn_mask = new_attn_mask.masked_fill(attn_mask, float("-inf"))
|
|
7664
|
+
attn_mask = new_attn_mask.masked_fill(attn_mask, ops.cast(float("-inf"), new_attn_mask.dtype))
|
|
7341
7665
|
|
|
7342
7666
|
if attn_mask is not None:
|
|
7343
7667
|
if attn_mask.shape[0] == 1:
|
|
@@ -7446,11 +7770,10 @@ def max_pool2d(x, kernel_size, stride=None, padding=0, dilation=1, return_indice
|
|
|
7446
7770
|
return out
|
|
7447
7771
|
|
|
7448
7772
|
|
|
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):
|
|
7773
|
+
def prompt_flash_attention(query, key, value, attn_mask, actual_seq_lengths, actual_seq_lengths_kv, pse_shift,
|
|
7774
|
+
deq_scale1, quant_scale1, deq_scale2, quant_scale2, quant_offset2, num_heads,
|
|
7775
|
+
scale_value=1.0, pre_tokens=2147483547, next_tokens=0, input_layout='BSH',
|
|
7776
|
+
num_key_value_heads=0, sparse_mode=0, inner_precise=1):
|
|
7454
7777
|
r"""
|
|
7455
7778
|
The interface for fully inference.
|
|
7456
7779
|
B -- Batch size
|
|
@@ -7458,7 +7781,7 @@ def prompt_flash_attention(query, key, value, attn_mask, actual_seq_lengths,
|
|
|
7458
7781
|
H -- Hidden size
|
|
7459
7782
|
|
|
7460
7783
|
Note:
|
|
7461
|
-
|
|
7784
|
+
experiment ops
|
|
7462
7785
|
|
|
7463
7786
|
.. warning::
|
|
7464
7787
|
This is an experimental API that is subject to change or deletion.
|
|
@@ -7472,8 +7795,8 @@ def prompt_flash_attention(query, key, value, attn_mask, actual_seq_lengths,
|
|
|
7472
7795
|
Input tensor of shape :math:`(B, S, H)` / `(B, N, S, D)`.
|
|
7473
7796
|
attn_mask (Tensor) - The attention mask tensor with data type of float16 or float32.
|
|
7474
7797
|
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 (
|
|
7798
|
+
actual_seq_lengths (Tensor): Describe actual sequence length of each input with data type of int64.
|
|
7799
|
+
actual_seq_lengths_kv (Tensor): Describe actual sequence length of each input with data type of int64.
|
|
7477
7800
|
pse_shift (Tensor) - The position encoding tensor with data type of float16 or float32.
|
|
7478
7801
|
dep_scale1 (Tensor)
|
|
7479
7802
|
quant_scale1 (Tensor)
|
|
@@ -7491,6 +7814,7 @@ def prompt_flash_attention(query, key, value, attn_mask, actual_seq_lengths,
|
|
|
7491
7814
|
num_key_value_heads (int): head numbers of key/value which are used in GQA algorithm.
|
|
7492
7815
|
The value o indicates if the key and value have the same head nums, use numHeads. Default: 0.
|
|
7493
7816
|
sparse_mode (int): Default: 0
|
|
7817
|
+
inner_precise (int): 0, float16 high precision. 1, high performance. default 1
|
|
7494
7818
|
|
|
7495
7819
|
|
|
7496
7820
|
Outputs:
|
|
@@ -7512,16 +7836,128 @@ def prompt_flash_attention(query, key, value, attn_mask, actual_seq_lengths,
|
|
|
7512
7836
|
>>> value = Tensor(np.ones((B, N, S, D), dtype=np.float16))
|
|
7513
7837
|
>>> out = ops.prompt_flash_attention(query, key, value, None, None, None, None, None, None, None, None,
|
|
7514
7838
|
None, N, input_layout='BNSD')
|
|
7515
|
-
>>> print(out
|
|
7839
|
+
>>> print(out.shape)
|
|
7516
7840
|
(1, 16, 256, 16)
|
|
7517
7841
|
"""
|
|
7518
7842
|
|
|
7519
7843
|
pfa = _get_cache_prim(NN_OPS.PromptFlashAttention)(num_heads, scale_value, pre_tokens, next_tokens, input_layout,
|
|
7520
|
-
num_key_value_heads, sparse_mode)
|
|
7844
|
+
num_key_value_heads, sparse_mode, inner_precise)
|
|
7521
7845
|
return pfa(query, key, value, attn_mask, actual_seq_lengths, actual_seq_lengths_kv, pse_shift, deq_scale1,
|
|
7522
7846
|
quant_scale1, deq_scale2, quant_scale2, quant_offset2)
|
|
7523
7847
|
|
|
7524
7848
|
|
|
7849
|
+
def incre_flash_attention(query, key, value, attn_mask, actual_seq_lengths, pse_shift, dequant_scale1, quant_scale1,
|
|
7850
|
+
dequant_scale2, quant_scale2, quant_offset2, antiquant_scale, antiquant_offset, block_table,
|
|
7851
|
+
num_heads, input_layout="BSH", scale_value=1.0, num_key_value_heads=0, block_size=0,
|
|
7852
|
+
inner_precise=1):
|
|
7853
|
+
r"""
|
|
7854
|
+
The interface for fully inference.
|
|
7855
|
+
|
|
7856
|
+
B -- Batch size
|
|
7857
|
+
|
|
7858
|
+
S -- Sequence length
|
|
7859
|
+
|
|
7860
|
+
H -- Hidden size
|
|
7861
|
+
|
|
7862
|
+
.. warning::
|
|
7863
|
+
This is an experimental API that is subject to change or deletion.
|
|
7864
|
+
If there is no input parameter and no default value, None needs to be passed.
|
|
7865
|
+
|
|
7866
|
+
Inputs:
|
|
7867
|
+
- **query** (Tensor) - The query tensor with data type of float16 or bfloat16.
|
|
7868
|
+
Input tensor of shape :math:`(B, 1, H)` / :math:`(B, N, 1, D)`.
|
|
7869
|
+
- **key** (TensorList) - The key tensor with data type of float16 or bfloat16.
|
|
7870
|
+
Input tensor of shape :math:`(B, S, H)` / :math:`(B, N, S, D)`.
|
|
7871
|
+
- **value** (TensorList) - The value tensor with data type of float16 or bfloat16.
|
|
7872
|
+
Input tensor of shape :math:`(B, S, H)` / :math:`(B, N, S, D)`.
|
|
7873
|
+
- **attn_mask** (Tensor) - The attention mask tensor with data type of float16 or bool.
|
|
7874
|
+
Input tensor of shape :math:`(B, S)` / :math:`(B, 1, S)` / :math:`(B, 1, 1, S)`.
|
|
7875
|
+
- **actual_seq_lengths** (Tensor) - Describe actual sequence length of each input with data type of int.
|
|
7876
|
+
- **pse_shift** (Tensor) - The position encoding tensor with data type of float16 or float32.
|
|
7877
|
+
- **dequant_scale1** (Tensor) - Quantitative parametor, the tensor with data type of uint64.
|
|
7878
|
+
- **quant_scale1** (Tensor) - Quantitative parametor, the tensor with data type of float.
|
|
7879
|
+
- **dequant_scale2** (Tensor) - Quantitative parametor, the tensor with data type of uint64.
|
|
7880
|
+
- **quant_scale2** (Tensor) - Quantitative parametor, the tensor with data type of float.
|
|
7881
|
+
- **quant_offset2** (Tensor) - Quantitative parametor, the tensor with data type of float.
|
|
7882
|
+
- **antiquant_scale** (Tensor) - Quantitative parametor, the tensor with data type of float.
|
|
7883
|
+
- **antiquant_offset** (Tensor) - Quantitative parametor, the tensor with data type of float.
|
|
7884
|
+
- **block_table** (Tensor) - The tensor with data type of float.
|
|
7885
|
+
- **num_heads** (int) - The number of heads.
|
|
7886
|
+
- **input_layout** (str) - the data layout of the input qkv, support `(BSH)` and `(BNSD)`. Default `BSH`.
|
|
7887
|
+
- **scale_value** (double) - The scale value indicating the scale coefficient, which is used as the scalar of
|
|
7888
|
+
Muls in the calculation. Default: 1.0.
|
|
7889
|
+
- **num_key_value_heads** (int) - head numbers of key/value which are used in GQA algorithm.
|
|
7890
|
+
The value o indicates if the key and value have the same head nums, use numHeads. Default: 0.
|
|
7891
|
+
- **block_size** (int) - Default: 0.
|
|
7892
|
+
- **inner_precise** (int) - Default: 1.
|
|
7893
|
+
|
|
7894
|
+
Outputs:
|
|
7895
|
+
- **attention_out** (Tensor) - Input tensor of shape :math:`(B, 1, H)` / :math:`(B, N, 1, D)`.
|
|
7896
|
+
|
|
7897
|
+
Supported Platforms:
|
|
7898
|
+
``Ascend``
|
|
7899
|
+
"""
|
|
7900
|
+
|
|
7901
|
+
_ifa = _get_cache_prim(NN_OPS.IncreFlashAttention)(num_heads, input_layout, scale_value, num_key_value_heads,
|
|
7902
|
+
block_size, inner_precise)
|
|
7903
|
+
return _ifa(query, key, value, attn_mask, actual_seq_lengths, pse_shift, dequant_scale1, quant_scale1,
|
|
7904
|
+
dequant_scale2, quant_scale2, quant_offset2, antiquant_scale, antiquant_offset, block_table)
|
|
7905
|
+
|
|
7906
|
+
|
|
7907
|
+
def embedding(input, weight, padding_idx=None, max_norm=None, norm_type=2.0, scale_grad_by_freq=False):
|
|
7908
|
+
r"""
|
|
7909
|
+
Retrieve the word embeddings in `weight` using indices specified in `input`.
|
|
7910
|
+
|
|
7911
|
+
.. warning::
|
|
7912
|
+
On Ascend, the behavior is unpredictable when the value of input is invalid.
|
|
7913
|
+
|
|
7914
|
+
Args:
|
|
7915
|
+
input (Tensor): The indices used to lookup in the `weight`. The data type must be mindspore.int32 or
|
|
7916
|
+
mindspore.int64, and the value should be in range `[0, weight.shape[0])`.
|
|
7917
|
+
weight (Parameter): The matrix where to lookup from. The shape must be 2D.
|
|
7918
|
+
padding_idx (int, optional): If the value is not None, the corresponding row of `weight` will not be updated
|
|
7919
|
+
in training. The value should be in range `[-weight.shape[0], weight.shape[0])` if it's not ``None``.
|
|
7920
|
+
Default ``None``.
|
|
7921
|
+
max_norm (float, optional): If not None, firstly get the p-norm result of the `weight` specified by `input`
|
|
7922
|
+
where p is specified by `norm_type`; if the result is larger then `max_norm`, update the `weight`
|
|
7923
|
+
with :math:`\frac{max\_norm}{result+1e^{-7}}` in-place. Default ``None``.
|
|
7924
|
+
norm_type (float, optional): Indicates the value of p in p-norm. Default ``2.0``.
|
|
7925
|
+
scale_grad_by_freq (bool, optional): If ``True`` the gradients will be scaled by the inverse of frequency of
|
|
7926
|
+
the index in `input`. Default ``False``.
|
|
7927
|
+
|
|
7928
|
+
Returns:
|
|
7929
|
+
Tensor, has the same data type as `weight`, the shape is :math:`(*input.shape, weight.shape[1])`.
|
|
7930
|
+
|
|
7931
|
+
Raises:
|
|
7932
|
+
ValueError: If `padding_idx` is out of valid range.
|
|
7933
|
+
ValueError: If the shape of `weight` is invalid.
|
|
7934
|
+
TypeError: `weight` is not a :class:`mindspore.Parameter`.
|
|
7935
|
+
|
|
7936
|
+
Supported Platforms:
|
|
7937
|
+
``Ascend``
|
|
7938
|
+
|
|
7939
|
+
Examples:
|
|
7940
|
+
>>> import mindspore
|
|
7941
|
+
>>> import numpy as np
|
|
7942
|
+
>>> from mindspore import Tensor, Parameter, ops
|
|
7943
|
+
>>> input = Tensor([[1, 0, 1, 1], [0, 0, 1, 0]])
|
|
7944
|
+
>>> weight = Parameter(np.random.randn(3, 3).astype(np.float32))
|
|
7945
|
+
>>> output = ops.embedding(input, weight, max_norm=0.4)
|
|
7946
|
+
>>> print(output)
|
|
7947
|
+
[[[ 5.49015924e-02, 3.47811311e-01, -1.89771220e-01],
|
|
7948
|
+
[ 2.09307984e-01, -2.24846993e-02, 3.40124398e-01],
|
|
7949
|
+
[ 5.49015924e-02, 3.47811311e-01, -1.89771220e-01],
|
|
7950
|
+
[ 5.49015924e-02, 3.47811311e-01, -1.89771220e-01]],
|
|
7951
|
+
[[ 2.09307984e-01, -2.24846993e-02, 3.40124398e-01],
|
|
7952
|
+
[ 2.09307984e-01, -2.24846993e-02, 3.40124398e-01],
|
|
7953
|
+
[ 5.49015924e-02, 3.47811311e-01, -1.89771220e-01],
|
|
7954
|
+
[ 2.09307984e-01, -2.24846993e-02, 3.40124398e-01]]]
|
|
7955
|
+
"""
|
|
7956
|
+
if not isinstance(weight, Parameter):
|
|
7957
|
+
raise TypeError(f"For Embedding, the weight must be a mindspore.Parameter, but got {type(weight)}.")
|
|
7958
|
+
return embedding_op(input, weight, padding_idx, max_norm, norm_type, scale_grad_by_freq)
|
|
7959
|
+
|
|
7960
|
+
|
|
7525
7961
|
__all__ = [
|
|
7526
7962
|
'adaptive_avg_pool1d',
|
|
7527
7963
|
'adaptive_avg_pool2d',
|
|
@@ -7547,6 +7983,7 @@ __all__ = [
|
|
|
7547
7983
|
'dropout1d',
|
|
7548
7984
|
'dropout2d',
|
|
7549
7985
|
'dropout3d',
|
|
7986
|
+
'embedding',
|
|
7550
7987
|
'fast_gelu',
|
|
7551
7988
|
'fractional_max_pool2d',
|
|
7552
7989
|
'fractional_max_pool3d',
|
|
@@ -7560,6 +7997,7 @@ __all__ = [
|
|
|
7560
7997
|
'intopk',
|
|
7561
7998
|
'interpolate',
|
|
7562
7999
|
'upsample',
|
|
8000
|
+
'layer_norm',
|
|
7563
8001
|
'log_softmax',
|
|
7564
8002
|
'mish',
|
|
7565
8003
|
'lrn',
|
|
@@ -7577,6 +8015,7 @@ __all__ = [
|
|
|
7577
8015
|
'softmin',
|
|
7578
8016
|
'pdist',
|
|
7579
8017
|
'pad',
|
|
8018
|
+
'pad_ext',
|
|
7580
8019
|
'prelu',
|
|
7581
8020
|
'mirror_pad',
|
|
7582
8021
|
'cross_entropy',
|
|
@@ -7592,6 +8031,7 @@ __all__ = [
|
|
|
7592
8031
|
'conv3d_transpose',
|
|
7593
8032
|
'conv1d',
|
|
7594
8033
|
'conv2d',
|
|
8034
|
+
'conv_transpose2d',
|
|
7595
8035
|
'sigmoid',
|
|
7596
8036
|
'logsigmoid',
|
|
7597
8037
|
'relu',
|
|
@@ -7616,6 +8056,8 @@ __all__ = [
|
|
|
7616
8056
|
'msort',
|
|
7617
8057
|
'triplet_margin_loss',
|
|
7618
8058
|
'channel_shuffle',
|
|
7619
|
-
'hardsigmoid'
|
|
8059
|
+
'hardsigmoid',
|
|
8060
|
+
'group_norm',
|
|
8061
|
+
'dropout_ext',
|
|
7620
8062
|
]
|
|
7621
8063
|
__all__.sort()
|