mindspore 2.2.11__cp37-cp37m-manylinux1_x86_64.whl → 2.3.0rc1__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.
Potentially problematic release.
This version of mindspore might be problematic. Click here for more details.
- mindspore/.commit_id +1 -1
- mindspore/__init__.py +5 -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/topi/cpp/impl.py +1 -1
- mindspore/_akg/akg/tvm/_ffi/base.py +1 -1
- 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 +5 -5
- 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 +58 -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 +124 -204
- mindspore/_extends/remote/kernel_build_server.py +2 -0
- mindspore/_mindspore_offline_debug.cpython-37m-x86_64-linux-gnu.so +0 -0
- mindspore/_profiler.py +30 -0
- 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 +3 -1
- mindspore/common/_jit_fallback_utils.py +2 -3
- mindspore/common/_register_for_adapter.py +7 -0
- mindspore/common/_stub_tensor.py +6 -1
- mindspore/common/_utils.py +5 -17
- mindspore/common/api.py +91 -48
- mindspore/common/auto_dynamic_shape.py +27 -14
- mindspore/common/dtype.py +5 -4
- mindspore/common/dump.py +5 -4
- mindspore/common/initializer.py +1 -1
- mindspore/common/jit_config.py +20 -11
- mindspore/common/lazy_inline.py +58 -17
- mindspore/common/mindir_util.py +12 -2
- mindspore/common/mutable.py +79 -14
- mindspore/common/parameter.py +19 -4
- mindspore/common/seed.py +9 -9
- mindspore/common/sparse_tensor.py +251 -18
- mindspore/common/symbol.py +122 -0
- mindspore/common/tensor.py +321 -435
- mindspore/communication/__init__.py +3 -3
- mindspore/communication/_comm_helper.py +5 -0
- mindspore/communication/management.py +56 -38
- mindspore/config/op_info.config +22 -54
- mindspore/context.py +192 -54
- 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 +95 -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/engine/validators.py +1 -1
- 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/py_transforms_util.py +2 -2
- 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 +65 -125
- 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 +337 -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 +7 -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 +6365 -1759
- 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.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/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 +53 -66
- mindspore/mindrecord/tools/cifar10_to_mr.py +48 -63
- mindspore/mindrecord/tools/csv_to_mr.py +7 -17
- mindspore/mindrecord/tools/imagenet_to_mr.py +3 -8
- mindspore/mindrecord/tools/mnist_to_mr.py +11 -21
- mindspore/mindrecord/tools/tfrecord_to_mr.py +2 -10
- mindspore/multiprocessing/__init__.py +68 -0
- mindspore/nn/cell.py +86 -133
- mindspore/nn/dynamic_lr.py +2 -2
- mindspore/nn/layer/activation.py +80 -91
- mindspore/nn/layer/basic.py +4 -80
- 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 +107 -46
- mindspore/nn/layer/image.py +4 -7
- mindspore/nn/layer/normalization.py +46 -38
- mindspore/nn/layer/padding.py +26 -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 +44 -65
- mindspore/nn/optim/ada_grad.py +6 -4
- 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 +4 -2
- 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 +53 -59
- mindspore/numpy/utils.py +3 -0
- mindspore/ops/__init__.py +7 -3
- mindspore/ops/_grad_experimental/grad_array_ops.py +4 -160
- mindspore/ops/_grad_experimental/grad_comm_ops.py +14 -18
- mindspore/ops/_grad_experimental/grad_inner_ops.py +8 -0
- mindspore/ops/_grad_experimental/grad_math_ops.py +92 -287
- 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/__init__.py +1 -0
- mindspore/ops/_op_impl/aicpu/gamma.py +2 -0
- mindspore/ops/_op_impl/{cpu/concat.py → aicpu/generate_eod_mask.py} +16 -17
- 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 +102 -56
- mindspore/ops/_vmap/vmap_image_ops.py +70 -13
- mindspore/ops/_vmap/vmap_math_ops.py +74 -49
- mindspore/ops/_vmap/vmap_nn_ops.py +164 -89
- 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 +133 -0
- mindspore/ops/auto_generate/gen_arg_dtype_cast.py +248 -0
- mindspore/ops/auto_generate/gen_arg_handler.py +147 -0
- mindspore/ops/auto_generate/gen_extend_func.py +130 -0
- mindspore/ops/auto_generate/gen_ops_def.py +4786 -0
- mindspore/ops/auto_generate/gen_ops_prim.py +8335 -0
- mindspore/ops/auto_generate/pyboost_inner_prim.py +77 -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 +166 -601
- mindspore/ops/composite/multitype_ops/_constexpr_utils.py +15 -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 +46 -0
- mindspore/ops/extend/array_func.py +152 -0
- mindspore/ops/extend/math_func.py +76 -0
- mindspore/ops/{_op_impl/tbe/atomic_addr_clean.py → extend/nn_func.py} +5 -15
- mindspore/ops/function/__init__.py +19 -11
- mindspore/ops/function/array_func.py +248 -1436
- mindspore/ops/function/clip_func.py +12 -13
- mindspore/ops/function/debug_func.py +2 -5
- 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 +30 -53
- mindspore/ops/function/math_func.py +450 -2356
- mindspore/ops/function/nn_func.py +470 -789
- mindspore/ops/function/other_func.py +4 -5
- mindspore/ops/function/parameter_func.py +6 -92
- mindspore/ops/function/random_func.py +24 -80
- mindspore/ops/function/sparse_unary_func.py +11 -18
- mindspore/ops/function/spectral_func.py +1 -1
- mindspore/ops/function/vmap_func.py +15 -14
- mindspore/ops/functional.py +56 -62
- mindspore/ops/op_info_register.py +22 -19
- mindspore/ops/operations/__init__.py +19 -19
- mindspore/ops/operations/_embedding_cache_ops.py +1 -1
- mindspore/ops/operations/_grad_ops.py +20 -723
- mindspore/ops/operations/_inner_ops.py +233 -286
- mindspore/ops/operations/_quant_ops.py +4 -4
- mindspore/ops/operations/_rl_inner_ops.py +1 -1
- mindspore/ops/operations/_scalar_ops.py +5 -480
- mindspore/ops/operations/_sequence_ops.py +4 -34
- mindspore/ops/operations/array_ops.py +100 -2481
- mindspore/ops/operations/comm_ops.py +38 -46
- mindspore/ops/operations/custom_ops.py +9 -9
- mindspore/ops/operations/debug_ops.py +101 -32
- mindspore/ops/operations/image_ops.py +3 -219
- mindspore/ops/operations/inner_ops.py +52 -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 +1391 -0
- mindspore/ops/operations/math_ops.py +752 -4588
- mindspore/ops/operations/nn_ops.py +380 -1750
- mindspore/ops/operations/other_ops.py +50 -42
- mindspore/ops/operations/random_ops.py +3 -50
- mindspore/ops/operations/sparse_ops.py +4 -4
- mindspore/ops/primitive.py +196 -96
- mindspore/ops/silent_check.py +162 -0
- mindspore/ops_generate/__init__.py +27 -0
- mindspore/ops_generate/arg_dtype_cast.py +248 -0
- mindspore/ops_generate/arg_handler.py +147 -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 +129 -0
- mindspore/ops_generate/gen_pyboost_func.py +932 -0
- mindspore/ops_generate/gen_utils.py +188 -0
- mindspore/ops_generate/op_proto.py +138 -0
- mindspore/ops_generate/pyboost_utils.py +364 -0
- mindspore/ops_generate/template.py +238 -0
- mindspore/parallel/__init__.py +6 -4
- mindspore/parallel/_auto_parallel_context.py +28 -4
- 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 +28 -12
- mindspore/parallel/_ps_context.py +1 -1
- mindspore/parallel/_recovery_context.py +1 -1
- mindspore/parallel/_tensor.py +22 -8
- 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 +9 -9
- mindspore/parallel/_utils.py +131 -6
- mindspore/parallel/algo_parameter_config.py +6 -6
- mindspore/parallel/checkpoint_transform.py +156 -26
- 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 +108 -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 +104 -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 +116 -0
- mindspore/profiler/parser/ascend_communicate_generator.py +314 -0
- mindspore/profiler/parser/ascend_flops_generator.py +27 -5
- mindspore/profiler/parser/ascend_fpbp_generator.py +8 -2
- mindspore/profiler/parser/ascend_hccl_generator.py +27 -279
- mindspore/profiler/parser/ascend_msprof_exporter.py +122 -118
- mindspore/profiler/parser/ascend_msprof_generator.py +67 -273
- mindspore/profiler/parser/ascend_op_generator.py +68 -27
- mindspore/profiler/parser/ascend_timeline_generator.py +292 -131
- mindspore/profiler/parser/base_timeline_generator.py +17 -3
- mindspore/profiler/parser/cpu_gpu_timeline_generator.py +2 -1
- mindspore/profiler/parser/framework_parser.py +11 -4
- mindspore/profiler/parser/integrator.py +3 -1
- mindspore/profiler/parser/memory_usage_parser.py +8 -2
- mindspore/profiler/parser/minddata_analyzer.py +8 -2
- mindspore/profiler/parser/minddata_parser.py +1 -1
- mindspore/profiler/parser/msadvisor_analyzer.py +5 -3
- mindspore/profiler/parser/msadvisor_parser.py +10 -4
- mindspore/profiler/parser/profiler_info.py +5 -0
- mindspore/profiler/profiling.py +373 -171
- mindspore/rewrite/__init__.py +2 -13
- mindspore/rewrite/api/node.py +122 -36
- mindspore/rewrite/api/pattern_engine.py +2 -3
- mindspore/rewrite/api/scoped_value.py +16 -15
- mindspore/rewrite/api/symbol_tree.py +46 -30
- 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/callback/_backup_and_restore.py +4 -4
- mindspore/train/callback/_callback.py +4 -4
- mindspore/train/callback/_checkpoint.py +47 -21
- mindspore/train/callback/_early_stop.py +2 -2
- mindspore/train/callback/_landscape.py +15 -10
- 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 +13 -14
- mindspore/train/callback/_time_monitor.py +2 -2
- mindspore/train/data_sink.py +1 -1
- mindspore/train/dataset_helper.py +19 -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 +75 -6
- mindspore/train/model.py +41 -27
- mindspore/train/serialization.py +262 -133
- mindspore/train/summary/_writer_pool.py +1 -1
- mindspore/train/summary/summary_record.py +56 -34
- mindspore/train/train_thor/convert_utils.py +3 -3
- mindspore/version.py +1 -1
- {mindspore-2.2.11.dist-info → mindspore-2.3.0rc1.dist-info}/METADATA +2 -2
- {mindspore-2.2.11.dist-info → mindspore-2.3.0rc1.dist-info}/RECORD +532 -1075
- {mindspore-2.2.11.dist-info → mindspore-2.3.0rc1.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/lib/plugin/libmindspore_ascend.so.1 +0 -0
- mindspore/nn/layer/flash_attention.py +0 -189
- 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_creator_register.py +0 -37
- 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.11.dist-info → mindspore-2.3.0rc1.dist-info}/WHEEL +0 -0
- {mindspore-2.2.11.dist-info → mindspore-2.3.0rc1.dist-info}/top_level.txt +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright
|
|
1
|
+
# Copyright 2023 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.
|
|
@@ -38,22 +38,56 @@ from mindspore.ops.operations.nn_ops import FractionalMaxPoolWithFixedKsize, Fra
|
|
|
38
38
|
from mindspore.ops.operations.nn_ops import PadV3
|
|
39
39
|
from mindspore.ops.operations.nn_ops import ChannelShuffle
|
|
40
40
|
from mindspore.ops.operations.nn_ops import TripletMarginLoss
|
|
41
|
-
from mindspore.ops.operations._inner_ops import SiLU
|
|
42
41
|
from mindspore.ops.operations._sequence_ops import TupleToTensor, TensorToTuple, ListToTensor
|
|
43
42
|
from mindspore.common.api import _function_forbid_reuse
|
|
43
|
+
from mindspore.ops.auto_generate import log_softmax, prelu, celu, relu, fast_gelu, silu, elu, sigmoid, relu6
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
abs_ = P.Abs()
|
|
46
|
+
add_ = P.Add()
|
|
47
|
+
bias_add_ = P.BiasAdd()
|
|
48
|
+
cast_ = P.Cast()
|
|
49
|
+
div_ = P.Div()
|
|
50
|
+
dtype_ = P.DType()
|
|
51
|
+
equal_ = P.Equal()
|
|
52
|
+
erf_ = P.Erf()
|
|
53
|
+
exp_ = P.Exp()
|
|
54
|
+
expand_dims_ = P.ExpandDims()
|
|
55
|
+
fillv2_ = P.FillV2()
|
|
56
|
+
gather_ = P.Gather()
|
|
57
|
+
gather_d_ = P.GatherD()
|
|
58
|
+
gelu_ = P.GeLU()
|
|
59
|
+
greater_ = P.Greater()
|
|
48
60
|
hardswish_ = P.HSwish()
|
|
61
|
+
less_ = P.Less()
|
|
62
|
+
list_to_tensor_ = ListToTensor()
|
|
63
|
+
log_ = P.Log()
|
|
64
|
+
matmul_ = P.MatMul()
|
|
65
|
+
maximum_ = P.Maximum()
|
|
66
|
+
minimum_ = P.Minimum()
|
|
49
67
|
mish_ = NN_OPS.Mish()
|
|
50
|
-
|
|
68
|
+
mul_ = P.Mul()
|
|
69
|
+
neg_ = P.Neg()
|
|
70
|
+
ones_like_ = P.OnesLike()
|
|
71
|
+
reduce_mean_ = P.ReduceMean()
|
|
72
|
+
reduce_sum_ = P.ReduceSum()
|
|
73
|
+
reshape_ = P.Reshape()
|
|
51
74
|
scalar_to_tensor_ = P.ScalarToTensor()
|
|
52
|
-
|
|
53
|
-
|
|
75
|
+
select_ = P.Select()
|
|
76
|
+
selu_ = NN_OPS.SeLU()
|
|
77
|
+
shape_ = P.Shape()
|
|
78
|
+
sigmoid_ = P.Sigmoid()
|
|
79
|
+
sign_ = P.Sign()
|
|
80
|
+
slice_ = P.Slice()
|
|
81
|
+
softplus_ = P.Softplus()
|
|
82
|
+
softsign_ = P.Softsign()
|
|
83
|
+
sqrt_ = P.Sqrt()
|
|
84
|
+
square_ = P.Square()
|
|
85
|
+
sub_ = P.Sub()
|
|
86
|
+
tensor_shape_ = P.TensorShape()
|
|
54
87
|
tensor_to_tuple_ = TensorToTuple()
|
|
55
|
-
|
|
56
|
-
|
|
88
|
+
transpose_ = P.Transpose()
|
|
89
|
+
tuple_to_tensor_ = TupleToTensor()
|
|
90
|
+
|
|
57
91
|
check_positive_int_const = validator.check_positive_int
|
|
58
92
|
check_positive_int_sequence_const = validator.check_positive_int_sequence
|
|
59
93
|
check_positive_float_const = validator.check_positive_float
|
|
@@ -103,11 +137,11 @@ def adaptive_avg_pool2d(input, output_size):
|
|
|
103
137
|
.. math::
|
|
104
138
|
|
|
105
139
|
out\_shape = \begin{cases}
|
|
106
|
-
input\
|
|
107
|
-
output\_size[0] + input\
|
|
108
|
-
input\
|
|
109
|
-
(h, h), & \text{if
|
|
110
|
-
(h, w), & \text{if
|
|
140
|
+
input\_shape[-2] + output\_size[1], & \text{if } output\_size text{ is (None, w);}\\
|
|
141
|
+
output\_size[0] + input\_shape[-1], & \text{if } output\_size text{ is (h, None);}\\
|
|
142
|
+
input\_shape[-2:], & \text{if } output\_size text{ is (None, None);}\\
|
|
143
|
+
(h, h), & \text{if } output\_size text{ is h;}\\
|
|
144
|
+
(h, w), & \text{if } output\_size text{ is (h, w)}
|
|
111
145
|
\end{cases}
|
|
112
146
|
|
|
113
147
|
Raises:
|
|
@@ -275,7 +309,7 @@ def avg_pool1d(input_x, kernel_size=1, stride=1, padding=0, ceil_mode=False, cou
|
|
|
275
309
|
Tensor of shape :math:`(N, C_{out}, L_{out})`.
|
|
276
310
|
|
|
277
311
|
Raises:
|
|
278
|
-
TypeError: If `input_x` is not
|
|
312
|
+
TypeError: If `input_x` is not a Tensor.
|
|
279
313
|
TypeError: If `kernel_size` or `stride` is not an int.
|
|
280
314
|
TypeError: If `ceil_mode` or `count_include_pad` is not a bool.
|
|
281
315
|
ValueError: If length of shape of `input_x` is not equal to `3`.
|
|
@@ -298,9 +332,6 @@ def avg_pool1d(input_x, kernel_size=1, stride=1, padding=0, ceil_mode=False, cou
|
|
|
298
332
|
if not isinstance(input_x, (Tensor, Tensor_)):
|
|
299
333
|
raise TypeError("For avg_pool1d, the input input_x must be tensor")
|
|
300
334
|
|
|
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
335
|
_check_avgpool_1d_type_and_int(kernel_size, stride, ceil_mode, count_include_pad)
|
|
305
336
|
if isinstance(padding, int):
|
|
306
337
|
check_non_negative_int(padding, 'padding', 'avg_pool1d')
|
|
@@ -319,7 +350,6 @@ def avg_pool1d(input_x, kernel_size=1, stride=1, padding=0, ceil_mode=False, cou
|
|
|
319
350
|
raise ValueError("For avg_pool1d, stride should be int or tuple of length 1.")
|
|
320
351
|
stride = stride[0]
|
|
321
352
|
|
|
322
|
-
expand_op = _get_cache_prim(P.ExpandDims)()
|
|
323
353
|
squeeze_op = _get_cache_prim(P.Squeeze)((2, 3))
|
|
324
354
|
avg_pool_op = _get_cache_prim(P.AvgPool3D)(kernel_size=(1, 1, kernel_size),
|
|
325
355
|
strides=(1, 1, stride),
|
|
@@ -327,8 +357,8 @@ def avg_pool1d(input_x, kernel_size=1, stride=1, padding=0, ceil_mode=False, cou
|
|
|
327
357
|
pad=padding,
|
|
328
358
|
ceil_mode=ceil_mode,
|
|
329
359
|
count_include_pad=count_include_pad)
|
|
330
|
-
input_x =
|
|
331
|
-
input_x =
|
|
360
|
+
input_x = expand_dims_(input_x, 2)
|
|
361
|
+
input_x = expand_dims_(input_x, 2)
|
|
332
362
|
input_x = avg_pool_op(input_x)
|
|
333
363
|
input_x = squeeze_op(input_x)
|
|
334
364
|
return input_x
|
|
@@ -429,7 +459,7 @@ def avg_pool2d(input_x, kernel_size=1, stride=1, padding=0, ceil_mode=False, cou
|
|
|
429
459
|
Tensor, with shape :math:`(N, C_{out}, H_{out}, W_{out})`.
|
|
430
460
|
|
|
431
461
|
Raises:
|
|
432
|
-
TypeError: If `input_x` is not
|
|
462
|
+
TypeError: If `input_x` is not a Tensor.
|
|
433
463
|
TypeError: If `kernel_size` or `stride` is neither int nor tuple.
|
|
434
464
|
TypeError: If `ceil_mode` or `count_include_pad` is not a bool.
|
|
435
465
|
TypeError: If `divisor_override` is not an int.
|
|
@@ -459,15 +489,10 @@ def avg_pool2d(input_x, kernel_size=1, stride=1, padding=0, ceil_mode=False, cou
|
|
|
459
489
|
if not isinstance(input_x, (Tensor, Tensor_)):
|
|
460
490
|
raise TypeError("For avg_pool2d, the input input_x must be tensor")
|
|
461
491
|
|
|
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
492
|
kernel_size = _check_avgpool_2d_kernel_size(kernel_size)
|
|
466
493
|
stride = _check_avgpool_2d_stride(stride)
|
|
467
494
|
padding = _check_avgpool_2d_padding(padding)
|
|
468
495
|
_check_avg_pool2d_type_and_value(ceil_mode, count_include_pad, divisor_override)
|
|
469
|
-
|
|
470
|
-
expand_op = _get_cache_prim(P.ExpandDims)()
|
|
471
496
|
squeeze_op = _get_cache_prim(P.Squeeze)(2)
|
|
472
497
|
avg_pool_op = _get_cache_prim(P.AvgPool3D)(kernel_size=kernel_size,
|
|
473
498
|
strides=stride,
|
|
@@ -476,7 +501,7 @@ def avg_pool2d(input_x, kernel_size=1, stride=1, padding=0, ceil_mode=False, cou
|
|
|
476
501
|
ceil_mode=ceil_mode,
|
|
477
502
|
count_include_pad=count_include_pad,
|
|
478
503
|
divisor_override=divisor_override)
|
|
479
|
-
input_x =
|
|
504
|
+
input_x = expand_dims_(input_x, 2)
|
|
480
505
|
input_x = avg_pool_op(input_x)
|
|
481
506
|
input_x = squeeze_op(input_x)
|
|
482
507
|
return input_x
|
|
@@ -537,7 +562,7 @@ def avg_pool3d(input_x, kernel_size=1, stride=1, padding=0, ceil_mode=False, cou
|
|
|
537
562
|
Tensor, with shape :math:`(N, C, D_{out}, H_{out}, W_{out})`. Has the same data type with `input_x`.
|
|
538
563
|
|
|
539
564
|
Raises:
|
|
540
|
-
TypeError: If `input_x` is not
|
|
565
|
+
TypeError: If `input_x` is not a Tensor.
|
|
541
566
|
TypeError: If `kernel_size`, `stride` or `padding` is neither an int not a tuple.
|
|
542
567
|
TypeError: If `ceil_mode` or `count_include_pad` is not a bool.
|
|
543
568
|
TypeError: If `divisor_override` is not an int.
|
|
@@ -563,9 +588,6 @@ def avg_pool3d(input_x, kernel_size=1, stride=1, padding=0, ceil_mode=False, cou
|
|
|
563
588
|
if not isinstance(input_x, (Tensor, Tensor_)):
|
|
564
589
|
raise TypeError("For avg_pool3d, the input input_x must be tensor")
|
|
565
590
|
|
|
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
591
|
_check_avg_pool3d_padding(padding)
|
|
570
592
|
|
|
571
593
|
avg_pool_op = _get_cache_prim(P.AvgPool3D)(kernel_size=kernel_size,
|
|
@@ -638,7 +660,7 @@ def adaptive_max_pool1d(input, output_size):
|
|
|
638
660
|
_check_adaptive_max_pool1d_output_size(output_size)
|
|
639
661
|
|
|
640
662
|
x_in_shape = input.shape
|
|
641
|
-
x_dtype =
|
|
663
|
+
x_dtype = dtype_(input)
|
|
642
664
|
|
|
643
665
|
if len(x_in_shape) != 3:
|
|
644
666
|
raise ValueError(f"For adaptive_max_pool1d input must have 3 dim, but got {len(x_in_shape)}.")
|
|
@@ -657,18 +679,14 @@ def adaptive_max_pool1d(input, output_size):
|
|
|
657
679
|
raise TypeError(f"For adaptive_max_pool1d, the input dtype must be float16 or float32, "
|
|
658
680
|
f"but got {x_dtype}.")
|
|
659
681
|
|
|
660
|
-
expand_ = _get_cache_prim(P.ExpandDims)()
|
|
661
682
|
squeeze_ = _get_cache_prim(P.Squeeze)(2)
|
|
662
|
-
|
|
663
683
|
width = x_in_shape[2]
|
|
664
684
|
stride = width // output_size
|
|
665
685
|
kernel_size = width - (output_size - 1) * stride
|
|
666
686
|
stride = (1, width // output_size)
|
|
667
687
|
kernel_size = (1, kernel_size)
|
|
668
|
-
|
|
669
688
|
max_pool_ = _get_cache_prim(NN_OPS.MaxPool)(kernel_size=kernel_size, strides=stride)
|
|
670
|
-
|
|
671
|
-
input = expand_(input, 2)
|
|
689
|
+
input = expand_dims_(input, 2)
|
|
672
690
|
input = max_pool_(input)
|
|
673
691
|
input = squeeze_(input)
|
|
674
692
|
|
|
@@ -807,6 +825,8 @@ def adaptive_max_pool3d(input, output_size, return_indices=False):
|
|
|
807
825
|
>>> print(output[1].asnumpy())
|
|
808
826
|
[[[[33 35]]]]
|
|
809
827
|
"""
|
|
828
|
+
if isinstance(output_size, int):
|
|
829
|
+
output_size = (output_size, output_size, output_size)
|
|
810
830
|
adaptive_max_pool3d_ = _get_cache_prim(NN_OPS.AdaptiveMaxPool3D)()
|
|
811
831
|
output_size_ = Tensor(output_size, dtype=mstype.int32)
|
|
812
832
|
out = adaptive_max_pool3d_(input, output_size_)
|
|
@@ -814,18 +834,6 @@ def adaptive_max_pool3d(input, output_size, return_indices=False):
|
|
|
814
834
|
return output
|
|
815
835
|
|
|
816
836
|
|
|
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
837
|
def max_unpool1d(x, indices, kernel_size, stride=None, padding=0, output_size=None):
|
|
830
838
|
r"""
|
|
831
839
|
Computes the inverse of `max_pool1d`.
|
|
@@ -836,7 +844,7 @@ def max_unpool1d(x, indices, kernel_size, stride=None, padding=0, output_size=No
|
|
|
836
844
|
|
|
837
845
|
.. math::
|
|
838
846
|
\begin{array}{ll} \\
|
|
839
|
-
H_{out} = (
|
|
847
|
+
H_{out} = (H_{in} - 1) \times stride[0] - 2 \times padding[0] + kernel\_size[0] \\
|
|
840
848
|
\end{array}
|
|
841
849
|
|
|
842
850
|
Args:
|
|
@@ -885,13 +893,8 @@ def max_unpool1d(x, indices, kernel_size, stride=None, padding=0, output_size=No
|
|
|
885
893
|
if stride is None:
|
|
886
894
|
stride = kernel_size
|
|
887
895
|
|
|
888
|
-
|
|
889
|
-
x_shape = shape(x)
|
|
890
|
-
indices_shape = shape(indices)
|
|
896
|
+
x_shape = shape_(x)
|
|
891
897
|
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
898
|
|
|
896
899
|
if output_size is None:
|
|
897
900
|
output_size = ()
|
|
@@ -1009,13 +1012,8 @@ def max_unpool2d(x, indices, kernel_size, stride=None, padding=0, output_size=No
|
|
|
1009
1012
|
if stride is None:
|
|
1010
1013
|
stride = kernel_size
|
|
1011
1014
|
|
|
1012
|
-
|
|
1013
|
-
x_shape = shape(x)
|
|
1014
|
-
indices_shape = shape(indices)
|
|
1015
|
+
x_shape = shape_(x)
|
|
1015
1016
|
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
1017
|
|
|
1020
1018
|
if output_size is None:
|
|
1021
1019
|
output_size = ()
|
|
@@ -1118,12 +1116,8 @@ def max_unpool3d(x, indices, kernel_size, stride=None, padding=0, output_size=No
|
|
|
1118
1116
|
if stride is None:
|
|
1119
1117
|
stride = kernel_size
|
|
1120
1118
|
|
|
1121
|
-
x_shape =
|
|
1122
|
-
indices_shape = P.Shape()(indices)
|
|
1119
|
+
x_shape = shape_(x)
|
|
1123
1120
|
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
1121
|
|
|
1128
1122
|
if output_size is None:
|
|
1129
1123
|
output_size = ()
|
|
@@ -1294,49 +1288,6 @@ def dropout(input, p=0.5, training=True, seed=None):
|
|
|
1294
1288
|
return out
|
|
1295
1289
|
|
|
1296
1290
|
|
|
1297
|
-
def celu(x, alpha=1.0):
|
|
1298
|
-
r"""
|
|
1299
|
-
celu activation function, computes celu (Continuously differentiable exponential
|
|
1300
|
-
linear units) of input tensors element-wise. The formula is defined as follows:
|
|
1301
|
-
|
|
1302
|
-
.. math::
|
|
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.
|
|
1310
|
-
|
|
1311
|
-
Args:
|
|
1312
|
-
x (Tensor): The input of celu with data type of float16 or float32.
|
|
1313
|
-
alpha (float, optional): The :math:`\alpha` value for the Celu formulation. Default: 1.0
|
|
1314
|
-
|
|
1315
|
-
Returns:
|
|
1316
|
-
Tensor, has the same data type and shape as the input.
|
|
1317
|
-
|
|
1318
|
-
Raises:
|
|
1319
|
-
TypeError: If `alpha` is not a float.
|
|
1320
|
-
TypeError: If `x` is not a Tensor.
|
|
1321
|
-
TypeError: If dtype of `x` is neither float16 nor float32.
|
|
1322
|
-
ValueError: If `alpha` has the value of 0.
|
|
1323
|
-
|
|
1324
|
-
Supported Platforms:
|
|
1325
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
1326
|
-
|
|
1327
|
-
Examples:
|
|
1328
|
-
>>> import mindspore
|
|
1329
|
-
>>> import numpy as np
|
|
1330
|
-
>>> from mindspore import Tensor, ops
|
|
1331
|
-
>>> x = Tensor(np.array([-2.0, -1.0, 1.0, 2.0]), mindspore.float32)
|
|
1332
|
-
>>> output = ops.celu(x, alpha=1.0)
|
|
1333
|
-
>>> print(output)
|
|
1334
|
-
[-0.86466473 -0.63212055 1. 2. ]
|
|
1335
|
-
"""
|
|
1336
|
-
celu_op = _get_cache_prim(P.CeLU)(alpha)
|
|
1337
|
-
return celu_op(x)
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
1291
|
def dropout1d(input, p=0.5, training=True):
|
|
1341
1292
|
r"""
|
|
1342
1293
|
During training, randomly zeroes some channels of the input tensor with probability `p`
|
|
@@ -1520,42 +1471,6 @@ def dropout3d(input, p=0.5, training=True):
|
|
|
1520
1471
|
return out
|
|
1521
1472
|
|
|
1522
1473
|
|
|
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
1474
|
@_primexpr
|
|
1560
1475
|
def _check_float_range_inc_neither(arg_value, lower_limit, upper_limit, arg_name=None, prim_name=None):
|
|
1561
1476
|
"""
|
|
@@ -1574,7 +1489,7 @@ def _check_fractional_output_size_ratio(output_size, output_ratio, cls_name):
|
|
|
1574
1489
|
def fractional_max_pool2d(input, kernel_size, output_size=None, output_ratio=None, return_indices=False,
|
|
1575
1490
|
_random_samples=None):
|
|
1576
1491
|
r"""
|
|
1577
|
-
Applies the 2D FractionalMaxPool
|
|
1492
|
+
Applies the 2D FractionalMaxPool operation over `input`. The output Tensor shape can be determined by either
|
|
1578
1493
|
`output_size` or `output_ratio`, and the step size is determined by `_random_samples`. `output_size` will take
|
|
1579
1494
|
effect when `output_size` and `output_ratio` are set at the same time.
|
|
1580
1495
|
And `output_size` and `output_ratio` can not be ``None`` at the same time.
|
|
@@ -1686,7 +1601,7 @@ def fractional_max_pool2d(input, kernel_size, output_size=None, output_ratio=Non
|
|
|
1686
1601
|
def fractional_max_pool3d(input, kernel_size, output_size=None, output_ratio=None, return_indices=False,
|
|
1687
1602
|
_random_samples=None):
|
|
1688
1603
|
r"""
|
|
1689
|
-
Applies the 3D FractionalMaxPool
|
|
1604
|
+
Applies the 3D FractionalMaxPool operation over `input`. The output Tensor shape can be determined by either
|
|
1690
1605
|
`output_size` or `output_ratio`, and the step size is determined by `_random_samples`. `output_size` will take
|
|
1691
1606
|
effect when `output_size` and `output_ratio` are set at the same time.
|
|
1692
1607
|
And `output_size` and `output_ratio` can not be ``None`` at the same time.
|
|
@@ -1707,7 +1622,7 @@ def fractional_max_pool3d(input, kernel_size, output_size=None, output_ratio=Non
|
|
|
1707
1622
|
is an int number that represents depth, height and width of the kernel, or a tuple
|
|
1708
1623
|
of three int numbers that represent depth, height and width respectively.
|
|
1709
1624
|
The value must be a positive integer.
|
|
1710
|
-
output_size (Union[int, tuple[int]], optional): The
|
|
1625
|
+
output_size (Union[int, tuple[int]], optional): The shape of the target `output_size`,
|
|
1711
1626
|
is an int number that represents depth, height and width, or a tuple
|
|
1712
1627
|
of three int numbers that represent depth, height and width respectively.
|
|
1713
1628
|
The value must be a positive integer.
|
|
@@ -1813,10 +1728,10 @@ def kl_div(logits, labels, reduction='mean'):
|
|
|
1813
1728
|
|
|
1814
1729
|
.. math::
|
|
1815
1730
|
\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'.}
|
|
1731
|
+
L(x, target), & \text{if reduction} = \text{'none';}\\
|
|
1732
|
+
\operatorname{mean}(L(x, target)), & \text{if reduction} = \text{'mean';}\\
|
|
1733
|
+
\operatorname{sum}(L(x, target)) / x.\operatorname{shape}[0], & \text{if reduction} = \text{'batchmean';}\\
|
|
1734
|
+
\operatorname{sum}(L(x, target)), & \text{if reduction} = \text{'sum'.}
|
|
1820
1735
|
\end{cases}
|
|
1821
1736
|
|
|
1822
1737
|
where :math:`x` represents `logits`.
|
|
@@ -1826,7 +1741,7 @@ def kl_div(logits, labels, reduction='mean'):
|
|
|
1826
1741
|
Note:
|
|
1827
1742
|
- Currently it does not support float64 input on `Ascend`.
|
|
1828
1743
|
- The output aligns with the mathematical definition of Kullback-Leibler divergence
|
|
1829
|
-
only when `reduction` is set to 'batchmean'
|
|
1744
|
+
only when `reduction` is set to ``'batchmean'``.
|
|
1830
1745
|
|
|
1831
1746
|
Args:
|
|
1832
1747
|
logits (Tensor): The input Tensor. The data type must be float16, float32 or float64.
|
|
@@ -1834,6 +1749,11 @@ def kl_div(logits, labels, reduction='mean'):
|
|
|
1834
1749
|
reduction (str): Specifies the reduction to be applied to the output.
|
|
1835
1750
|
Its value must be one of ``'none'`` , ``'mean'`` , ``'batchmean'`` or ``'sum'`` . Default: ``'mean'`` .
|
|
1836
1751
|
|
|
1752
|
+
- ``'none'``: no reduction will be applied.
|
|
1753
|
+
- ``'mean'``: compute and return the mean of elements in the output.
|
|
1754
|
+
- ``'sum'``: the output elements will be summed.
|
|
1755
|
+
- ``'batchmean'``: the summed output elements divided by batch size.
|
|
1756
|
+
|
|
1837
1757
|
Returns:
|
|
1838
1758
|
Tensor or Scalar, if `reduction` is ``'none'``, then output is a tensor and has the same shape as `logits`.
|
|
1839
1759
|
Otherwise, it is a scalar.
|
|
@@ -1841,7 +1761,7 @@ def kl_div(logits, labels, reduction='mean'):
|
|
|
1841
1761
|
Raises:
|
|
1842
1762
|
TypeError: If `reduction` is not a str.
|
|
1843
1763
|
TypeError: If neither `logits` nor `labels` is a Tensor.
|
|
1844
|
-
TypeError: If dtype of `logits` or `labels` is not
|
|
1764
|
+
TypeError: If dtype of `logits` or `labels` is not the supported type.
|
|
1845
1765
|
|
|
1846
1766
|
Supported Platforms:
|
|
1847
1767
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -1861,20 +1781,20 @@ def kl_div(logits, labels, reduction='mean'):
|
|
|
1861
1781
|
f"'['none', 'mean', 'batchmean', 'sum']', but got '{reduction}'.")
|
|
1862
1782
|
|
|
1863
1783
|
if reduction == 'batchmean':
|
|
1864
|
-
kl_div_sum = P.KLDivLoss(reduction='sum')(logits, labels)
|
|
1865
|
-
shape =
|
|
1784
|
+
kl_div_sum = _get_cache_prim(P.KLDivLoss)(reduction='sum')(logits, labels)
|
|
1785
|
+
shape = shape_(logits)
|
|
1866
1786
|
batch_size = shape[0]
|
|
1867
1787
|
return kl_div_sum / batch_size
|
|
1868
1788
|
|
|
1869
1789
|
if reduction == 'mean':
|
|
1870
|
-
kl_div_sum = P.KLDivLoss(reduction='sum')(logits, labels)
|
|
1871
|
-
shape =
|
|
1790
|
+
kl_div_sum = _get_cache_prim(P.KLDivLoss)(reduction='sum')(logits, labels)
|
|
1791
|
+
shape = shape_(logits)
|
|
1872
1792
|
total_size = 1
|
|
1873
1793
|
for dim in shape:
|
|
1874
1794
|
total_size = total_size * dim
|
|
1875
1795
|
return kl_div_sum / total_size
|
|
1876
1796
|
|
|
1877
|
-
return P.KLDivLoss(reduction=reduction)(logits, labels)
|
|
1797
|
+
return _get_cache_prim(P.KLDivLoss)(reduction=reduction)(logits, labels)
|
|
1878
1798
|
|
|
1879
1799
|
|
|
1880
1800
|
def hardshrink(x, lambd=0.5):
|
|
@@ -1891,9 +1811,15 @@ def hardshrink(x, lambd=0.5):
|
|
|
1891
1811
|
0, & \text{ otherwise }
|
|
1892
1812
|
\end{cases}
|
|
1893
1813
|
|
|
1814
|
+
HShrink Activation Function Graph:
|
|
1815
|
+
|
|
1816
|
+
.. image:: ../images/HShrink.png
|
|
1817
|
+
:align: center
|
|
1818
|
+
|
|
1894
1819
|
Args:
|
|
1895
1820
|
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.
|
|
1821
|
+
lambd (float, optional): The threshold :math:`\lambda` defined by the Hard Shrink formula.
|
|
1822
|
+
Default: ``0.5`` .
|
|
1897
1823
|
|
|
1898
1824
|
Returns:
|
|
1899
1825
|
Tensor, has the same data type and shape as the input `x`.
|
|
@@ -1995,7 +1921,7 @@ def flip(input, dims):
|
|
|
1995
1921
|
Raises:
|
|
1996
1922
|
TypeError: If the input is not a tensor.
|
|
1997
1923
|
ValueError: If `dims` is None.
|
|
1998
|
-
ValueError: If `dims` is not a tuple of ints.
|
|
1924
|
+
ValueError: If `dims` is not a list/tuple of ints.
|
|
1999
1925
|
|
|
2000
1926
|
Supported Platforms:
|
|
2001
1927
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -2105,7 +2031,7 @@ def is_floating_point(input):
|
|
|
2105
2031
|
>>> print(output2)
|
|
2106
2032
|
False
|
|
2107
2033
|
"""
|
|
2108
|
-
return input.dtype in [mstype.float32, mstype.float16, mstype.float64]
|
|
2034
|
+
return input.dtype in [mstype.float32, mstype.bfloat16, mstype.float16, mstype.float64]
|
|
2109
2035
|
|
|
2110
2036
|
|
|
2111
2037
|
def hardswish(x):
|
|
@@ -2120,6 +2046,11 @@ def hardswish(x):
|
|
|
2120
2046
|
|
|
2121
2047
|
where :math:`x_i` is an element of the input Tensor.
|
|
2122
2048
|
|
|
2049
|
+
HSwish Activation Function Graph:
|
|
2050
|
+
|
|
2051
|
+
.. image:: ../images/HSwish.png
|
|
2052
|
+
:align: center
|
|
2053
|
+
|
|
2123
2054
|
Args:
|
|
2124
2055
|
x (Tensor): The input to compute the Hard Swish.
|
|
2125
2056
|
|
|
@@ -2153,7 +2084,7 @@ def _is_dim_unknown(shape):
|
|
|
2153
2084
|
def _interploate_make_tuple(rank, value):
|
|
2154
2085
|
s = tuple_to_tensor_((rank,), mstype.int32)
|
|
2155
2086
|
v = Tensor(value)
|
|
2156
|
-
t =
|
|
2087
|
+
t = fillv2_(s, v)
|
|
2157
2088
|
out = tensor_to_tuple_(t)
|
|
2158
2089
|
return out
|
|
2159
2090
|
|
|
@@ -2238,17 +2169,22 @@ def interpolate(input,
|
|
|
2238
2169
|
'area', 'nearest-exact'(matches Scikit-Image and PIL nearest neighbours interpolation algorithms and fixes
|
|
2239
2170
|
knows issues with `nearest`, 3D and 4D). Default: ``"nearest"`` .
|
|
2240
2171
|
|
|
2241
|
-
align_corners (bool):
|
|
2242
|
-
|
|
2243
|
-
Default: ``None`` .
|
|
2172
|
+
align_corners (bool): Whether to use corner alignment for coordinate mapping. Assuming a transformation is
|
|
2173
|
+
applied to the input Tensor along the x-axis, the specific calculation formula is as follows:
|
|
2244
2174
|
|
|
2245
2175
|
.. code-block::
|
|
2246
2176
|
|
|
2247
|
-
|
|
2177
|
+
ori_i = new_length != 1 ? new_i * (ori_length - 1) / (new_length - 1) : 0 # 'align_corners' = True
|
|
2248
2178
|
|
|
2249
|
-
|
|
2179
|
+
ori_i = new_length > 1 ? (new_i + 0.5) * ori_length / new_length - 0.5 : 0 # 'align_corners' = False
|
|
2250
2180
|
|
|
2251
|
-
|
|
2181
|
+
Among them, :math:`ori\_length` and :math:`new\_length` represent the length of the Tensor before and after
|
|
2182
|
+
transformation along the x-axis respectively; :math:`new\_i` represents the coordinate of the i-th element
|
|
2183
|
+
along the x-axis after transformation; :math:`ori\_i` represents
|
|
2184
|
+
the corresponding coordinate of the original
|
|
2185
|
+
data along the x-axis.
|
|
2186
|
+
|
|
2187
|
+
This is only valid for ``'linear'``, ``'bilinear'``, or ``'bicubic'`` modes. Default: ``False`` .
|
|
2252
2188
|
recompute_scale_factor (bool, optional): Recalculate `scale_factor`.
|
|
2253
2189
|
If True, the parameter `size` will be calculated using the value of the `scale_factor`,
|
|
2254
2190
|
and finally scaled using the value of `size`.
|
|
@@ -2331,7 +2267,7 @@ def interpolate(input,
|
|
|
2331
2267
|
x = x.unsqueeze(-1)
|
|
2332
2268
|
x = _get_cache_prim(P.ResizeNearestNeighborV2)()(
|
|
2333
2269
|
x, size)
|
|
2334
|
-
x = P.Squeeze(-1)(x)
|
|
2270
|
+
x = _get_cache_prim(P.Squeeze)(-1)(x)
|
|
2335
2271
|
elif size is not None and x_rank == 4:
|
|
2336
2272
|
size = seq.TupleToTensor()(size[:2], mstype.int32)
|
|
2337
2273
|
x = _get_cache_prim(P.ResizeNearestNeighborV2)()(
|
|
@@ -2383,7 +2319,7 @@ def interpolate(input,
|
|
|
2383
2319
|
align_corners=False,
|
|
2384
2320
|
half_pixel_centers=True)
|
|
2385
2321
|
x = resize(x, size)
|
|
2386
|
-
x = P.Squeeze(-1)(x)
|
|
2322
|
+
x = _get_cache_prim(P.Squeeze)(-1)(x)
|
|
2387
2323
|
if x_rank == 4:
|
|
2388
2324
|
if isinstance(size, int):
|
|
2389
2325
|
size = F.scalar_to_tensor(size, mstype.int32)
|
|
@@ -2533,13 +2469,18 @@ def upsample(input, size=None, scale_factor=None, mode="nearest", align_corners=
|
|
|
2533
2469
|
|
|
2534
2470
|
def softsign(x):
|
|
2535
2471
|
r"""
|
|
2536
|
-
|
|
2472
|
+
SoftSign activation function.
|
|
2537
2473
|
|
|
2538
2474
|
The function is shown as follows:
|
|
2539
2475
|
|
|
2540
2476
|
.. math::
|
|
2541
2477
|
\text{SoftSign}(x) = \frac{x}{1 + |x|}
|
|
2542
2478
|
|
|
2479
|
+
Softsign Activation Function Graph:
|
|
2480
|
+
|
|
2481
|
+
.. image:: ../images/Softsign.png
|
|
2482
|
+
:align: center
|
|
2483
|
+
|
|
2543
2484
|
Args:
|
|
2544
2485
|
x (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
|
|
2545
2486
|
additional dimensions, with float16 or float32 data type.
|
|
@@ -2584,7 +2525,7 @@ def soft_margin_loss(input, target, reduction='mean'):
|
|
|
2584
2525
|
|
|
2585
2526
|
Args:
|
|
2586
2527
|
input (Tensor): Predict data. Data type must be float16 or float32.
|
|
2587
|
-
target (Tensor): Ground truth data, with the same type and shape as `
|
|
2528
|
+
target (Tensor): Ground truth data, with the same type and shape as `input`.
|
|
2588
2529
|
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
2589
2530
|
``'sum'`` . Default: ``'mean'`` .
|
|
2590
2531
|
|
|
@@ -2593,7 +2534,7 @@ def soft_margin_loss(input, target, reduction='mean'):
|
|
|
2593
2534
|
- ``'sum'``: the output elements will be summed.
|
|
2594
2535
|
|
|
2595
2536
|
Outputs:
|
|
2596
|
-
Tensor or Scalar. If `reduction` is ``'none'``, its shape is the same as `
|
|
2537
|
+
Tensor or Scalar. If `reduction` is ``'none'``, its shape is the same as `input`.
|
|
2597
2538
|
Otherwise, a scalar value will be returned.
|
|
2598
2539
|
|
|
2599
2540
|
Raises:
|
|
@@ -2620,34 +2561,31 @@ def soft_margin_loss(input, target, reduction='mean'):
|
|
|
2620
2561
|
return output
|
|
2621
2562
|
|
|
2622
2563
|
|
|
2623
|
-
def softmax(
|
|
2564
|
+
def softmax(input, axis=-1, *, dtype=None):
|
|
2624
2565
|
r"""
|
|
2625
2566
|
Applies the Softmax operation to the input tensor on the specified axis.
|
|
2626
|
-
Suppose a slice in the given axis :math:`
|
|
2567
|
+
Suppose a slice in the given axis :math:`axis`, then for each element :math:`input_i`,
|
|
2627
2568
|
the Softmax function is shown as follows:
|
|
2628
2569
|
|
|
2629
2570
|
.. math::
|
|
2630
|
-
\text{output}(
|
|
2571
|
+
\text{output}(input_i) = \frac{\exp(input_i)}{\sum_{j = 0}^{N-1}\exp(input_j)},
|
|
2631
2572
|
|
|
2632
2573
|
where :math:`N` is the length of the tensor.
|
|
2633
2574
|
|
|
2634
2575
|
Args:
|
|
2635
|
-
|
|
2636
|
-
x (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
|
|
2576
|
+
input (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
|
|
2637
2577
|
additional dimensions, with float16 or float32 data type.
|
|
2578
|
+
axis (int, optional): The axis to perform the Softmax operation. Default: ``-1`` .
|
|
2638
2579
|
|
|
2639
2580
|
Keyword Args:
|
|
2640
|
-
dtype (:class:`mindspore.dtype`, optional): When set, `
|
|
2581
|
+
dtype (:class:`mindspore.dtype`, optional): When set, `input` will be converted to the specified type,
|
|
2641
2582
|
`dtype`, before execution, and dtype of returned Tensor will also be `dtype`. Default: ``None`` .
|
|
2642
2583
|
|
|
2643
2584
|
Returns:
|
|
2644
|
-
Tensor, with the same type and shape as the
|
|
2585
|
+
Tensor, with the same type and shape as the `input`.
|
|
2645
2586
|
|
|
2646
2587
|
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))
|
|
2588
|
+
TypeError: If `axis` is not an int.
|
|
2651
2589
|
|
|
2652
2590
|
Supported Platforms:
|
|
2653
2591
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -2656,8 +2594,8 @@ def softmax(x, axis=-1, *, dtype=None):
|
|
|
2656
2594
|
>>> import mindspore
|
|
2657
2595
|
>>> import numpy as np
|
|
2658
2596
|
>>> from mindspore import Tensor, ops
|
|
2659
|
-
>>>
|
|
2660
|
-
>>> output = ops.softmax(
|
|
2597
|
+
>>> input = Tensor(np.array([1, 2, 3, 4, 5]), mindspore.float32)
|
|
2598
|
+
>>> output = ops.softmax(input)
|
|
2661
2599
|
>>> print(output)
|
|
2662
2600
|
[0.01165623 0.03168492 0.08612854 0.23412167 0.6364086 ]
|
|
2663
2601
|
"""
|
|
@@ -2666,9 +2604,9 @@ def softmax(x, axis=-1, *, dtype=None):
|
|
|
2666
2604
|
type_axis = type(axis).__name__
|
|
2667
2605
|
raise TypeError(f" the type of 'axis' must be 'int', but got '{axis}' with type '{type_axis}'.")
|
|
2668
2606
|
if dtype is not None:
|
|
2669
|
-
|
|
2670
|
-
softmax_ = _get_cache_prim(P.Softmax)(axis
|
|
2671
|
-
return softmax_(
|
|
2607
|
+
input = ops.cast(input, dtype)
|
|
2608
|
+
softmax_ = _get_cache_prim(P.Softmax)(axis)
|
|
2609
|
+
return softmax_(input)
|
|
2672
2610
|
|
|
2673
2611
|
|
|
2674
2612
|
def softmin(x, axis=-1, *, dtype=None):
|
|
@@ -2692,7 +2630,7 @@ def softmin(x, axis=-1, *, dtype=None):
|
|
|
2692
2630
|
`dtype`, before execution, and dtype of returned Tensor will also be `dtype`. Default: ``None`` .
|
|
2693
2631
|
|
|
2694
2632
|
Returns:
|
|
2695
|
-
Tensor, with the same type and shape as
|
|
2633
|
+
Tensor, with the same type and shape as `x`.
|
|
2696
2634
|
|
|
2697
2635
|
Raises:
|
|
2698
2636
|
TypeError: If `axis` is not an int or a tuple.
|
|
@@ -2715,7 +2653,7 @@ def softmin(x, axis=-1, *, dtype=None):
|
|
|
2715
2653
|
|
|
2716
2654
|
if dtype is not None:
|
|
2717
2655
|
x = ops.cast(x, dtype)
|
|
2718
|
-
softmax_ = _get_cache_prim(P.Softmax)(axis
|
|
2656
|
+
softmax_ = _get_cache_prim(P.Softmax)(axis)
|
|
2719
2657
|
return softmax_(-1*x)
|
|
2720
2658
|
|
|
2721
2659
|
|
|
@@ -2731,6 +2669,11 @@ def softshrink(x, lambd=0.5):
|
|
|
2731
2669
|
0, & \text{ otherwise }
|
|
2732
2670
|
\end{cases}
|
|
2733
2671
|
|
|
2672
|
+
SoftShrink Activation Function Graph:
|
|
2673
|
+
|
|
2674
|
+
.. image:: ../images/Softshrink.png
|
|
2675
|
+
:align: center
|
|
2676
|
+
|
|
2734
2677
|
Args:
|
|
2735
2678
|
x (Tensor): The input of soft shrink with data type of float16 or float32.
|
|
2736
2679
|
lambd (float): The :math:`\lambda` must be no less than zero. Default: ``0.5`` .
|
|
@@ -2739,15 +2682,16 @@ def softshrink(x, lambd=0.5):
|
|
|
2739
2682
|
Tensor, has the same shape and data type as `x`.
|
|
2740
2683
|
|
|
2741
2684
|
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.
|
|
2685
|
+
TypeError: If `lambd` is not a float.
|
|
2686
|
+
TypeError: If `x` is not a Tensor.
|
|
2687
|
+
TypeError: If dtype of `x` is neither float16 nor float32.
|
|
2688
|
+
ValueError: If `lambd` is less than 0.
|
|
2746
2689
|
|
|
2747
2690
|
Supported Platforms:
|
|
2748
2691
|
``Ascend`` ``GPU`` ``CPU``
|
|
2749
2692
|
|
|
2750
2693
|
Examples:
|
|
2694
|
+
>>> import mindspore
|
|
2751
2695
|
>>> from mindspore import Tensor
|
|
2752
2696
|
>>> from mindspore import ops
|
|
2753
2697
|
>>> import numpy as np
|
|
@@ -2813,45 +2757,11 @@ def softplus(input, beta=1, threshold=20): # pylint:disable=redefined-outer-name
|
|
|
2813
2757
|
>>> print(output)
|
|
2814
2758
|
[0.7443967 0.79813886 30. 25.]
|
|
2815
2759
|
"""
|
|
2816
|
-
softplus_op = _get_cache_prim(P.Softplus)()
|
|
2817
2760
|
scaling_input = beta * input
|
|
2818
|
-
op_output = (1 / beta) *
|
|
2761
|
+
op_output = (1 / beta) * softplus_(scaling_input)
|
|
2819
2762
|
return ops.select(input * beta > threshold, input, op_output)
|
|
2820
2763
|
|
|
2821
2764
|
|
|
2822
|
-
def silu(x):
|
|
2823
|
-
r"""
|
|
2824
|
-
Computes Sigmoid Linear Unit of input element-wise. The SiLU function is defined as:
|
|
2825
|
-
|
|
2826
|
-
.. math::
|
|
2827
|
-
\text{SiLU}(x) = x * \sigma(x),
|
|
2828
|
-
|
|
2829
|
-
where the Logistic Sigmoid function is defined as:
|
|
2830
|
-
|
|
2831
|
-
.. math::
|
|
2832
|
-
|
|
2833
|
-
\text{sigma}(x_i) = \frac{1}{1 + \exp(-x_i)},
|
|
2834
|
-
|
|
2835
|
-
where :math:`x_i` is an element of the x.
|
|
2836
|
-
|
|
2837
|
-
For more details, please refer to :class:`mindspore.nn.SiLU`.
|
|
2838
|
-
|
|
2839
|
-
Supported Platforms:
|
|
2840
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
2841
|
-
|
|
2842
|
-
Examples:
|
|
2843
|
-
>>> import numpy as np
|
|
2844
|
-
>>> import mindspore
|
|
2845
|
-
>>> from mindspore import Tensor, ops
|
|
2846
|
-
>>> x = Tensor(np.array([-1, 2, -3, 2, -1]), mindspore.float16)
|
|
2847
|
-
>>> output = ops.silu(x)
|
|
2848
|
-
>>> print(output)
|
|
2849
|
-
[-0.269 1.762 -0.1423 1.762 -0.269]
|
|
2850
|
-
"""
|
|
2851
|
-
silu_ = _get_cache_prim(SiLU)()
|
|
2852
|
-
return silu_(x)
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
2765
|
def selu(input_x):
|
|
2856
2766
|
r"""
|
|
2857
2767
|
Activation function SeLU (Scaled exponential Linear Unit).
|
|
@@ -2871,14 +2781,20 @@ def selu(input_x):
|
|
|
2871
2781
|
|
|
2872
2782
|
See more details in `Self-Normalizing Neural Networks <https://arxiv.org/abs/1706.02515>`_.
|
|
2873
2783
|
|
|
2784
|
+
SeLU Activation Function Graph:
|
|
2785
|
+
|
|
2786
|
+
.. image:: ../images/SeLU.png
|
|
2787
|
+
:align: center
|
|
2788
|
+
|
|
2874
2789
|
Args:
|
|
2875
|
-
input_x (Tensor): Tensor of any dimension,
|
|
2790
|
+
input_x (Tensor): Tensor of any dimension,
|
|
2791
|
+
the data type is int8, int32, float16, float32, or float64 (CPU, GPU only).
|
|
2876
2792
|
|
|
2877
2793
|
Returns:
|
|
2878
2794
|
Tensor, with the same type and shape as the `input_x`.
|
|
2879
2795
|
|
|
2880
2796
|
Raises:
|
|
2881
|
-
TypeError: If dtype of `input_x` is
|
|
2797
|
+
TypeError: If dtype of `input_x` is not int8, int32, float16, float32, or float64.
|
|
2882
2798
|
|
|
2883
2799
|
Supported Platforms:
|
|
2884
2800
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -2896,41 +2812,6 @@ def selu(input_x):
|
|
|
2896
2812
|
return selu_(input_x)
|
|
2897
2813
|
|
|
2898
2814
|
|
|
2899
|
-
def sigmoid(input):
|
|
2900
|
-
r"""
|
|
2901
|
-
Computes Sigmoid of input element-wise. The Sigmoid function is defined as:
|
|
2902
|
-
|
|
2903
|
-
.. math::
|
|
2904
|
-
|
|
2905
|
-
\text{sigmoid}(input_i) = \frac{1}{1 + \exp(-input_i)}
|
|
2906
|
-
|
|
2907
|
-
where :math:`input_i` is an element of the input.
|
|
2908
|
-
|
|
2909
|
-
Args:
|
|
2910
|
-
input (Tensor): Tensor of any dimension, the data type is float16, float32, float64, complex64 or complex128.
|
|
2911
|
-
|
|
2912
|
-
Returns:
|
|
2913
|
-
Tensor, with the same type and shape as the input.
|
|
2914
|
-
|
|
2915
|
-
Raises:
|
|
2916
|
-
TypeError: If dtype of `input` is not float16, float32, float64, complex64 or complex128.
|
|
2917
|
-
TypeError: If `input` is not a Tensor.
|
|
2918
|
-
|
|
2919
|
-
Supported Platforms:
|
|
2920
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
2921
|
-
|
|
2922
|
-
Examples:
|
|
2923
|
-
>>> import mindspore
|
|
2924
|
-
>>> import numpy as np
|
|
2925
|
-
>>> from mindspore import Tensor, ops
|
|
2926
|
-
>>> input = Tensor(np.array([1, 2, 3, 4, 5]), mindspore.float32)
|
|
2927
|
-
>>> output = ops.sigmoid(input)
|
|
2928
|
-
>>> print(output)
|
|
2929
|
-
[0.7310586 0.880797 0.95257413 0.98201376 0.9933072 ]
|
|
2930
|
-
"""
|
|
2931
|
-
return _get_cache_prim(NN_OPS.Sigmoid)()(input)
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
2815
|
def logsigmoid(x):
|
|
2935
2816
|
r"""
|
|
2936
2817
|
Applies logsigmoid activation element-wise. The input is a Tensor with any valid shape.
|
|
@@ -2942,6 +2823,11 @@ def logsigmoid(x):
|
|
|
2942
2823
|
|
|
2943
2824
|
where :math:`x_{i}` is the element of the input.
|
|
2944
2825
|
|
|
2826
|
+
LogSigmoid Activation Function Graph:
|
|
2827
|
+
|
|
2828
|
+
.. image:: ../images/LogSigmoid.png
|
|
2829
|
+
:align: center
|
|
2830
|
+
|
|
2945
2831
|
Args:
|
|
2946
2832
|
x (Tensor): The input of LogSigmoid with data type of float16 or float32.
|
|
2947
2833
|
The shape is :math:`(N,*)` where :math:`*` means, any number of additional dimensions.
|
|
@@ -2964,8 +2850,8 @@ def logsigmoid(x):
|
|
|
2964
2850
|
>>> print(output)
|
|
2965
2851
|
[-0.31326166 -0.12692806 -0.04858734]
|
|
2966
2852
|
"""
|
|
2967
|
-
output =
|
|
2968
|
-
ret =
|
|
2853
|
+
output = sigmoid_(x)
|
|
2854
|
+
ret = log_(output)
|
|
2969
2855
|
return ret
|
|
2970
2856
|
|
|
2971
2857
|
|
|
@@ -3000,11 +2886,12 @@ def dense(input, weight, bias=None):
|
|
|
3000
2886
|
|
|
3001
2887
|
Examples:
|
|
3002
2888
|
>>> import numpy as np
|
|
2889
|
+
>>> import mindspore
|
|
3003
2890
|
>>> from mindspore import Tensor, ops
|
|
3004
|
-
>>> input =
|
|
3005
|
-
>>> weight =
|
|
3006
|
-
>>> bias =
|
|
3007
|
-
>>> output =
|
|
2891
|
+
>>> input = Tensor([[-1., 1., 2.], [-3., -3., 1.]], mindspore.float32)
|
|
2892
|
+
>>> weight = Tensor([[-2., -2., -2.], [0., -1., 0.]], mindspore.float32)
|
|
2893
|
+
>>> bias = Tensor([0., 1.], mindspore.float32)
|
|
2894
|
+
>>> output = ops.dense(input, weight, bias)
|
|
3008
2895
|
>>> print(output)
|
|
3009
2896
|
[[-4. 0.]
|
|
3010
2897
|
[10. 4.]]
|
|
@@ -3111,13 +2998,11 @@ def bidense(input1, input2, weight, bias=None):
|
|
|
3111
2998
|
input1 = input1.reshape((-1, input1_shape[-1]))
|
|
3112
2999
|
input2 = input2.reshape((-1, input2_shape[-1]))
|
|
3113
3000
|
batch_size = input1.shape[0]
|
|
3114
|
-
matmul_ = P.MatMul()
|
|
3115
3001
|
output = matmul_(input1, weight.transpose(1, 2, 0).view(input1_shape[-1], -1))
|
|
3116
3002
|
output = output.view(batch_size, input2_shape[-1], weight.shape[0])
|
|
3117
3003
|
output = output.transpose(2, 0, 1) * input2
|
|
3118
3004
|
output = output.sum(2).swapaxes(0, 1)
|
|
3119
3005
|
if bias is not None:
|
|
3120
|
-
bias_add_ = P.BiasAdd()
|
|
3121
3006
|
output = bias_add_(output, bias)
|
|
3122
3007
|
if len(input1_shape) != 2:
|
|
3123
3008
|
output_shape = input1_shape[:-1] + (-1,)
|
|
@@ -3187,7 +3072,7 @@ def deformable_conv2d(x, weight, offsets, kernel_size, strides, padding, bias=No
|
|
|
3187
3072
|
TypeError: If `strides`, `padding`, `kernel_size` or `dilations` is not a tuple with integer elements.
|
|
3188
3073
|
TypeError: If `modulated` is not a bool.
|
|
3189
3074
|
ValueError: If the tuple size of `strides`, `padding`, `kernel_size` or `dilations` is not expected.
|
|
3190
|
-
ValueError: The N or C dimensions of
|
|
3075
|
+
ValueError: The N or C dimensions of `strides` or `dilations` is not set to 1.
|
|
3191
3076
|
ValueError: If `modulated` is not set to True.
|
|
3192
3077
|
|
|
3193
3078
|
.. warning::
|
|
@@ -3212,13 +3097,10 @@ def deformable_conv2d(x, weight, offsets, kernel_size, strides, padding, bias=No
|
|
|
3212
3097
|
deformable_groups,
|
|
3213
3098
|
modulated)
|
|
3214
3099
|
fm_offset = deformable_offsets(x, offsets)
|
|
3215
|
-
|
|
3216
3100
|
weight_shape = weight.shape
|
|
3217
3101
|
out_channel = weight_shape[0]
|
|
3218
3102
|
strides_conv = (kernel_size[0], kernel_size[1])
|
|
3219
3103
|
conv = _get_cache_prim(P.Conv2D)(out_channel, kernel_size, 1, "valid", 0, strides_conv, 1, groups)
|
|
3220
|
-
bias_add_ = _get_cache_prim(P.BiasAdd)()
|
|
3221
|
-
|
|
3222
3104
|
output = conv(fm_offset, weight)
|
|
3223
3105
|
if bias is not None:
|
|
3224
3106
|
output = bias_add_(output, bias)
|
|
@@ -3229,9 +3111,7 @@ def pdist(input, p=2.0):
|
|
|
3229
3111
|
r"""
|
|
3230
3112
|
Calculates the distance between every pair of row vectors in
|
|
3231
3113
|
the input using the p-norm. If the input `input` is a 2D Tensor with shape :math:`(N, M)`,
|
|
3232
|
-
the `output` must be a 1D Tensor with shape :math:`(N * (N - 1) / 2,)`.
|
|
3233
|
-
dimension with shape :math:`(*B, N, M)`, then the `output` must be a Tensor with
|
|
3234
|
-
shape :math:`(*B, N * (N - 1) / 2)`.
|
|
3114
|
+
the `output` must be a 1D Tensor with shape :math:`(N * (N - 1) / 2,)`.
|
|
3235
3115
|
|
|
3236
3116
|
.. math::
|
|
3237
3117
|
y[n] = \sqrt[p]{{\mid x_{i} - x_{j} \mid}^p}
|
|
@@ -3239,8 +3119,7 @@ def pdist(input, p=2.0):
|
|
|
3239
3119
|
where :math:`x_{i}, x_{j}` are two different row vectors in the input.
|
|
3240
3120
|
|
|
3241
3121
|
Args:
|
|
3242
|
-
input (Tensor): Input tensor
|
|
3243
|
-
dtype: float16, float32 or float64.
|
|
3122
|
+
input (Tensor): Input tensor. dtype: float16, float32 or float64.
|
|
3244
3123
|
p (float): The order of norm distance, :math:`p∈[0, ∞)`. Default: ``2.0`` .
|
|
3245
3124
|
|
|
3246
3125
|
Returns:
|
|
@@ -3286,8 +3165,10 @@ def pad(input_x, padding, mode='constant', value=None):
|
|
|
3286
3165
|
Pads the input tensor according to the padding.
|
|
3287
3166
|
|
|
3288
3167
|
Args:
|
|
3289
|
-
input_x (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of additional dimensions
|
|
3290
|
-
|
|
3168
|
+
input_x (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of additional dimensions
|
|
3169
|
+
which is required to be no more than 5 in Ascend.
|
|
3170
|
+
padding (Union[tuple[int], list[int], Tensor]): Filling position of pad where the negative value is not
|
|
3171
|
+
supported while running in Ascend.
|
|
3291
3172
|
:math:`\left\lfloor\frac{\text{len(padding)}}{2}\right\rfloor` dimensions
|
|
3292
3173
|
of `input_x` will be padded.
|
|
3293
3174
|
|
|
@@ -3296,49 +3177,49 @@ def pad(input_x, padding, mode='constant', value=None):
|
|
|
3296
3177
|
:math:`(\text{padding_left}, \text{padding_right})`;
|
|
3297
3178
|
|
|
3298
3179
|
Example: to pad the last 2 dimensions of the input tensor, then use
|
|
3299
|
-
:math:`(\text{padding_left}, \text{padding_right}
|
|
3300
|
-
:math:`\text{padding_top}, \text{padding_bottom})`;
|
|
3180
|
+
:math:`(\text{padding_left}, \text{padding_right}, \text{padding_top}, \text{padding_bottom})`;
|
|
3301
3181
|
|
|
3302
3182
|
Example: to pad the last 3 dimensions, use
|
|
3303
|
-
:math:`(\text{padding_left}, \text{padding_right}
|
|
3304
|
-
|
|
3305
|
-
:math:`\text{padding_front}, \text{padding_back})` and so on.
|
|
3183
|
+
:math:`(\text{padding_left}, \text{padding_right}, \text{padding_top}, \text{padding_bottom},
|
|
3184
|
+
\text{padding_front}, \text{padding_back})` and so on.
|
|
3306
3185
|
|
|
3307
|
-
mode (str, optional): Pad filling mode, ``
|
|
3186
|
+
mode (str, optional): Pad filling mode, ``'constant'`` , ``'reflect'`` , ``'replicate'`` or ``'circular'`` .
|
|
3308
3187
|
Default: ``'constant'`` .
|
|
3309
3188
|
|
|
3310
|
-
For
|
|
3189
|
+
For ``'constant'`` mode, please refer to :class:`mindspore.nn.ConstantPad1d` as an example to understand
|
|
3311
3190
|
this filling pattern and extend the padding pattern to n dimensions.
|
|
3312
3191
|
|
|
3313
|
-
For
|
|
3192
|
+
For ``'reflect'`` mode, please refer to :class:`mindspore.nn.ReflectionPad1d` as an example to understand
|
|
3314
3193
|
this filling pattern.
|
|
3315
3194
|
The reflect mode is used to pad the last two dimensions of 3D or 4D input, or the last dimension of 2D or
|
|
3316
3195
|
3D input.
|
|
3317
3196
|
|
|
3318
|
-
For
|
|
3197
|
+
For ``'replicate'`` mode, please refer to :class:`mindspore.nn.ReplicationPad1d` as an example to understand
|
|
3319
3198
|
this filling pattern.
|
|
3320
3199
|
The replicate mode is used to pad the last three dimensions of 4D or 5D input, the last two dimensions of 3D
|
|
3321
3200
|
or 4D input, or the last dimension of 2D or 3D input.
|
|
3322
3201
|
|
|
3323
|
-
For
|
|
3202
|
+
For ``'circular'`` mode, the pixels from one edge of the image are wrapped around to the opposite edge,
|
|
3324
3203
|
such that the pixel on the right edge of the image is replaced with the pixel on the left edge,
|
|
3325
3204
|
and the pixel on the bottom edge is replaced with the pixel on the top edge.
|
|
3326
3205
|
The circular mode is used to pad the last three dimensions of 4D or 5D input, the last two dimensions of 3D
|
|
3327
3206
|
or 4D input, or the last dimension of 2D or 3D input.
|
|
3328
3207
|
|
|
3329
|
-
value (Union[int, float, None], optional): Valid only in
|
|
3330
|
-
Set the padding value in
|
|
3208
|
+
value (Union[int, float, None], optional): Valid only in ``'constant'`` mode.
|
|
3209
|
+
Set the padding value in ``'constant'`` mode. If the value is None, 0 is used as the default padding value.
|
|
3331
3210
|
Default: ``None`` .
|
|
3332
3211
|
|
|
3333
3212
|
Returns:
|
|
3334
3213
|
Tensor, the tensor after padding.
|
|
3335
3214
|
|
|
3336
3215
|
Raises:
|
|
3337
|
-
TypeError: If `
|
|
3216
|
+
TypeError: If `padding` is not an int of tuple or int of list.
|
|
3338
3217
|
TypeError: If `input_x` is not a Tensor.
|
|
3339
3218
|
ValueError: If length of `padding` is not even.
|
|
3340
3219
|
ValueError: If length of `padding` is greater than 6.
|
|
3341
|
-
ValueError: If mode is not
|
|
3220
|
+
ValueError: If `mode` is not ``'constant'`` and `value` not ``None``.
|
|
3221
|
+
ValueError: If rank of `input_x` is more than 5 while running in Ascend.
|
|
3222
|
+
ValueError: If `paddings` contains negative value while running in Ascend.
|
|
3342
3223
|
|
|
3343
3224
|
Supported Platforms:
|
|
3344
3225
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -3395,7 +3276,7 @@ def pad(input_x, padding, mode='constant', value=None):
|
|
|
3395
3276
|
return input_x
|
|
3396
3277
|
if not isinstance(padding, Tensor):
|
|
3397
3278
|
_check_pad_inputs(padding)
|
|
3398
|
-
padding =
|
|
3279
|
+
padding = tuple(padding)
|
|
3399
3280
|
is_expand = False
|
|
3400
3281
|
if mode == "constant":
|
|
3401
3282
|
value = 0 if value is None else value
|
|
@@ -3408,7 +3289,7 @@ def pad(input_x, padding, mode='constant', value=None):
|
|
|
3408
3289
|
raise ValueError(f"For 'pad', the padding mode '{mode}' can not set value, but got value {value}.")
|
|
3409
3290
|
if mode == "replicate":
|
|
3410
3291
|
mode = "edge"
|
|
3411
|
-
if padding
|
|
3292
|
+
if len(padding) // 2 + 1 == input_x.ndim:
|
|
3412
3293
|
input_x = input_x.expand_dims(0)
|
|
3413
3294
|
is_expand = True
|
|
3414
3295
|
out = PadV3(mode=mode, paddings_contiguous=True)(input_x, padding, value)
|
|
@@ -3417,142 +3298,6 @@ def pad(input_x, padding, mode='constant', value=None):
|
|
|
3417
3298
|
return out
|
|
3418
3299
|
|
|
3419
3300
|
|
|
3420
|
-
def relu(input):
|
|
3421
|
-
r"""
|
|
3422
|
-
Computes ReLU (Rectified Linear Unit activation function) of input tensors element-wise.
|
|
3423
|
-
|
|
3424
|
-
It returns :math:`\max(input,\ 0)` element-wise. Specially, the neurons with the negative output
|
|
3425
|
-
will be suppressed and the active neurons will stay the same.
|
|
3426
|
-
|
|
3427
|
-
.. math::
|
|
3428
|
-
|
|
3429
|
-
ReLU(input) = (input)^+ = \max(0, input)
|
|
3430
|
-
|
|
3431
|
-
Note:
|
|
3432
|
-
In general, this operator is more commonly used. The difference from `ReLuV2` is that the `ReLuV2` will
|
|
3433
|
-
output one more Mask.
|
|
3434
|
-
|
|
3435
|
-
Args:
|
|
3436
|
-
input (Tensor): Input Tensor of numeric types.
|
|
3437
|
-
|
|
3438
|
-
Returns:
|
|
3439
|
-
Tensor, has the same dtype and shape as `input_x`.
|
|
3440
|
-
|
|
3441
|
-
Raises:
|
|
3442
|
-
TypeError: If dtype of `input` is not a number.
|
|
3443
|
-
TypeError: If `input` is not a Tensor.
|
|
3444
|
-
|
|
3445
|
-
Supported Platforms:
|
|
3446
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
3447
|
-
|
|
3448
|
-
Examples:
|
|
3449
|
-
>>> import mindspore
|
|
3450
|
-
>>> import numpy as np
|
|
3451
|
-
>>> from mindspore import Tensor, ops
|
|
3452
|
-
>>> input_x = Tensor(np.array([[-1.0, 4.0, -8.0], [2.0, -5.0, 9.0]]), mindspore.float32)
|
|
3453
|
-
>>> output = ops.relu(input_x)
|
|
3454
|
-
>>> print(output)
|
|
3455
|
-
[[0. 4. 0.]
|
|
3456
|
-
[2. 0. 9.]]
|
|
3457
|
-
"""
|
|
3458
|
-
relu_ = _get_cache_prim(NN_OPS.ReLU)()
|
|
3459
|
-
return relu_(input)
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
def relu6(x):
|
|
3463
|
-
r"""
|
|
3464
|
-
Computes ReLU (Rectified Linear Unit) upper bounded by 6 of input tensors element-wise.
|
|
3465
|
-
|
|
3466
|
-
.. math::
|
|
3467
|
-
|
|
3468
|
-
\text{ReLU6}(x) = \min(\max(0,x), 6)
|
|
3469
|
-
|
|
3470
|
-
It returns :math:`\min(\max(0,x), 6)` element-wise.
|
|
3471
|
-
|
|
3472
|
-
Args:
|
|
3473
|
-
x (Tensor): Tensor of shape :math:`(N, *)`,
|
|
3474
|
-
where :math:`*` means any number of additional dimensions.
|
|
3475
|
-
Data type must be float16, float32.
|
|
3476
|
-
|
|
3477
|
-
Returns:
|
|
3478
|
-
Tensor, with the same dtype and shape as the `x`.
|
|
3479
|
-
|
|
3480
|
-
Raises:
|
|
3481
|
-
TypeError: If dtype of `x` is neither float16 nor float32.
|
|
3482
|
-
TypeError: If `x` is not a Tensor.
|
|
3483
|
-
|
|
3484
|
-
Supported Platforms:
|
|
3485
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
3486
|
-
|
|
3487
|
-
Examples:
|
|
3488
|
-
>>> import mindspore
|
|
3489
|
-
>>> import numpy as np
|
|
3490
|
-
>>> from mindspore import Tensor, ops
|
|
3491
|
-
>>> input_x = Tensor(np.array([[-1.0, 4.0, -8.0], [2.0, -5.0, 9.0]]), mindspore.float32)
|
|
3492
|
-
>>> result = ops.relu6(input_x)
|
|
3493
|
-
>>> print(result)
|
|
3494
|
-
[[0. 4. 0.]
|
|
3495
|
-
[2. 0. 6.]]
|
|
3496
|
-
"""
|
|
3497
|
-
relu6_ = _get_cache_prim(NN_OPS.ReLU6)()
|
|
3498
|
-
return relu6_(x)
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
def prelu(x, weight):
|
|
3502
|
-
r"""
|
|
3503
|
-
Parametric Rectified Linear Unit activation function.
|
|
3504
|
-
|
|
3505
|
-
PReLU is described in the paper `Delving Deep into Rectifiers: Surpassing Human-Level Performance on
|
|
3506
|
-
ImageNet Classification <https://arxiv.org/abs/1502.01852>`_. Defined as follows:
|
|
3507
|
-
|
|
3508
|
-
.. math::
|
|
3509
|
-
prelu(x_i)= \max(0, x_i) + \min(0, w * x_i),
|
|
3510
|
-
|
|
3511
|
-
where :math:`x_i` is an element of a channel of the input, `w` is the weight of the channel.
|
|
3512
|
-
|
|
3513
|
-
Note:
|
|
3514
|
-
Scalar or 1-D Tensor is not supported on Ascend.
|
|
3515
|
-
|
|
3516
|
-
Args:
|
|
3517
|
-
x (Tensor): The input Tensor of the activation function. The data type is float16 or float32.
|
|
3518
|
-
The shape is :math:`(N, *)` where :math:`*` means, any number of additional dimensions.
|
|
3519
|
-
weight (Tensor): Weight Tensor. The data type is float16 or float32.
|
|
3520
|
-
The weight can only be a Tensor, and the length is the same as the number of channels C of the `input_x`.
|
|
3521
|
-
On GPU devices, when the input is a scalar, the shape is :math:`(1,)` .
|
|
3522
|
-
|
|
3523
|
-
Returns:
|
|
3524
|
-
Tensor, with the same shape and dtype as `x`.
|
|
3525
|
-
|
|
3526
|
-
For detailed information, please refer to :class:`mindspore.nn.PReLU`.
|
|
3527
|
-
|
|
3528
|
-
Raises:
|
|
3529
|
-
TypeError: If dtype of `x` or `weight` is neither float16 nor float32.
|
|
3530
|
-
TypeError: If the `x` or the `weight` is not a Tensor.
|
|
3531
|
-
ValueError: If the `x` is a 0-D or 1-D Tensor on Ascend.
|
|
3532
|
-
ValueError: If the `weight` is not a 1-D Tensor.
|
|
3533
|
-
|
|
3534
|
-
Supported Platforms:
|
|
3535
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
3536
|
-
|
|
3537
|
-
Examples:
|
|
3538
|
-
>>> import mindspore
|
|
3539
|
-
>>> import numpy as np
|
|
3540
|
-
>>> from mindspore import Tensor, ops
|
|
3541
|
-
>>> x = Tensor(np.arange(-6, 6).reshape((2, 3, 2)), mindspore.float32)
|
|
3542
|
-
>>> weight = Tensor(np.array([0.1, 0.6, -0.3]), mindspore.float32)
|
|
3543
|
-
>>> output = ops.prelu(x, weight)
|
|
3544
|
-
>>> print(output)
|
|
3545
|
-
[[[-0.60 -0.50]
|
|
3546
|
-
[-2.40 -1.80]
|
|
3547
|
-
[ 0.60 0.30]]
|
|
3548
|
-
[[ 0.00 1.00]
|
|
3549
|
-
[ 2.00 3.00]
|
|
3550
|
-
[ 4.0 5.00]]]
|
|
3551
|
-
"""
|
|
3552
|
-
prelu_ = _get_cache_prim(NN_OPS.PReLU)()
|
|
3553
|
-
return prelu_(x, weight)
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
3301
|
def rrelu(input, lower=1.0 / 8, upper=1.0 / 3):
|
|
3557
3302
|
r"""
|
|
3558
3303
|
|
|
@@ -3581,7 +3326,7 @@ def rrelu(input, lower=1.0 / 8, upper=1.0 / 3):
|
|
|
3581
3326
|
TypeError: If `lower` is not a float or an int.
|
|
3582
3327
|
TypeError: If `upper` is not a float or an int.
|
|
3583
3328
|
TypeError: If `input` is not a Tensor.
|
|
3584
|
-
TypeError: If `input` is not a Tensor of mindspore.float16 or
|
|
3329
|
+
TypeError: If `input` is not a Tensor of mindspore.float16 or mindspore.float32.
|
|
3585
3330
|
ValueError: If `lower` is greater than upper.
|
|
3586
3331
|
|
|
3587
3332
|
Supported Platforms:
|
|
@@ -3610,13 +3355,12 @@ def rrelu(input, lower=1.0 / 8, upper=1.0 / 3):
|
|
|
3610
3355
|
_upper = Tensor(upper, mstype.float32)
|
|
3611
3356
|
_size = input.shape
|
|
3612
3357
|
if ops.is_sequence_value_unknown(_size):
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
sign_matrix = _get_cache_prim(P.Sign)()(input)
|
|
3358
|
+
_size = tensor_shape_(input)
|
|
3359
|
+
sign_matrix = sign_(input)
|
|
3616
3360
|
negative_filter = sign_matrix.clip(None, 0)
|
|
3617
3361
|
positive_filter = sign_matrix.clip(0, None)
|
|
3618
|
-
|
|
3619
|
-
mask = ops.uniform(_size, _lower, _upper).astype(
|
|
3362
|
+
input_dtype = dtype_(input)
|
|
3363
|
+
mask = ops.uniform(_size, _lower, _upper).astype(input_dtype)
|
|
3620
3364
|
negative_mask = negative_filter * mask * -1
|
|
3621
3365
|
total_mask = negative_mask + positive_filter
|
|
3622
3366
|
out = total_mask * input
|
|
@@ -3684,6 +3428,21 @@ def _innner_log_softmax(inputs, axis):
|
|
|
3684
3428
|
return inputs - logsumexp(inputs, axis, True)
|
|
3685
3429
|
|
|
3686
3430
|
|
|
3431
|
+
def _check_cross_entropy_inputs(input, target, weight, ignore_index, reduction, label_smoothing):
|
|
3432
|
+
"""
|
|
3433
|
+
Check inputs for cross_entropy().
|
|
3434
|
+
"""
|
|
3435
|
+
_check_is_tensor('input', input, "cross_entropy_loss")
|
|
3436
|
+
_check_is_tensor('target', target, "cross_entropy_loss")
|
|
3437
|
+
_check_is_tensor('weight', weight, "cross_entropy_loss")
|
|
3438
|
+
check_int_const(ignore_index, 'ignore_index', "cross_entropy_loss")
|
|
3439
|
+
check_non_negative_float_const(label_smoothing, 'label_smoothing', "cross_entropy_loss")
|
|
3440
|
+
check_string_const(reduction, ['none', 'mean', 'sum'], 'reduction', "cross_entropy_loss")
|
|
3441
|
+
if input.dtype not in [mstype.float64, mstype.float32, mstype.float16]:
|
|
3442
|
+
raise TypeError(f'For cross_entropy, the input dtype should be mstype.float64, mstype.float32 or'
|
|
3443
|
+
f'mstype.float16, but got dtype:{input.dtype}.')
|
|
3444
|
+
|
|
3445
|
+
|
|
3687
3446
|
def cross_entropy(input, target, weight=None, ignore_index=-100, reduction='mean', label_smoothing=0.0):
|
|
3688
3447
|
r"""
|
|
3689
3448
|
The cross entropy loss between input and target.
|
|
@@ -3741,7 +3500,7 @@ def cross_entropy(input, target, weight=None, ignore_index=-100, reduction='mean
|
|
|
3741
3500
|
`input` is expected to be log-probabilities, data type must be float16 or float32.
|
|
3742
3501
|
target (Tensor): For class indices, tensor of shape :math:`()`, :math:`(N)` or
|
|
3743
3502
|
:math:`(N, d_1, d_2, ..., d_K)` , data type must be int32. For probabilities, tensor of shape :math:`(C,)` ,
|
|
3744
|
-
:math:`(N, C)` or :math:`(N, C, d_1, d_2, ..., d_K)` , data type must be float16 or float32.
|
|
3503
|
+
:math:`(N, C)` or :math:`(N, C, d_1, d_2, ..., d_K)` , data type must be float16 or float32 or float64.
|
|
3745
3504
|
weight (Tensor): A rescaling weight applied to the loss of each batch element.
|
|
3746
3505
|
If not None, the shape is :math:`(C,)`, data type must be float16 or float32. Default: ``None`` .
|
|
3747
3506
|
ignore_index (int): Specifies a target value that is ignored
|
|
@@ -3774,12 +3533,7 @@ def cross_entropy(input, target, weight=None, ignore_index=-100, reduction='mean
|
|
|
3774
3533
|
>>> target = ms.Tensor(np.random.randn(3, 5), ms.float32)
|
|
3775
3534
|
>>> output = ms.ops.cross_entropy(inputs, target)
|
|
3776
3535
|
"""
|
|
3777
|
-
|
|
3778
|
-
_check_is_tensor('target', target, "cross_entropy_loss")
|
|
3779
|
-
_check_is_tensor('weight', weight, "cross_entropy_loss")
|
|
3780
|
-
check_int_const(ignore_index, 'ignore_index', "cross_entropy_loss")
|
|
3781
|
-
check_non_negative_float_const(label_smoothing, 'label_smoothing', "cross_entropy_loss")
|
|
3782
|
-
check_string_const(reduction, ['none', 'mean', 'sum'], 'reduction', "cross_entropy_loss")
|
|
3536
|
+
_check_cross_entropy_inputs(input, target, weight, ignore_index, reduction, label_smoothing)
|
|
3783
3537
|
class_dim = 0 if input.ndim == 1 else 1
|
|
3784
3538
|
if target.dtype in [mstype.float32, mstype.float16]:
|
|
3785
3539
|
return _cross_entropy(input, target, class_dim, weight, reduction, label_smoothing)
|
|
@@ -3788,8 +3542,6 @@ def cross_entropy(input, target, weight=None, ignore_index=-100, reduction='mean
|
|
|
3788
3542
|
|
|
3789
3543
|
def _cross_entropy(inputs, target, target_dim, weight=None, reduction='mean', label_smoothing=0.0):
|
|
3790
3544
|
"""cross entropy inner function"""
|
|
3791
|
-
_ones_like = _get_cache_prim(P.OnesLike)()
|
|
3792
|
-
|
|
3793
3545
|
class_dim = 0 if inputs.ndim == 1 else 1
|
|
3794
3546
|
n_classes = inputs.shape[class_dim]
|
|
3795
3547
|
inputs = _innner_log_softmax(inputs, class_dim)
|
|
@@ -3797,7 +3549,7 @@ def _cross_entropy(inputs, target, target_dim, weight=None, reduction='mean', la
|
|
|
3797
3549
|
target = target * (1 - label_smoothing) + label_smoothing / n_classes
|
|
3798
3550
|
|
|
3799
3551
|
if weight is None:
|
|
3800
|
-
weight =
|
|
3552
|
+
weight = ones_like_(inputs)
|
|
3801
3553
|
elif inputs.ndim != 1:
|
|
3802
3554
|
broadcast_shape = [1 for _ in range(inputs.ndim)]
|
|
3803
3555
|
broadcast_shape[1] = weight.shape[0]
|
|
@@ -3827,7 +3579,7 @@ def nll_loss(inputs, target, weight=None, ignore_index=-100, reduction='mean', l
|
|
|
3827
3579
|
N is the batch size, :math:`c` belonging to :math:`[0, C-1]` is class index, where :math:`C` is the number of
|
|
3828
3580
|
classes.
|
|
3829
3581
|
|
|
3830
|
-
If `reduction` is not ``None`` (default 'mean'), then
|
|
3582
|
+
If `reduction` is not ``None`` (default ``'mean'``), then
|
|
3831
3583
|
|
|
3832
3584
|
.. math::
|
|
3833
3585
|
|
|
@@ -3895,37 +3647,31 @@ def nll_loss(inputs, target, weight=None, ignore_index=-100, reduction='mean', l
|
|
|
3895
3647
|
|
|
3896
3648
|
def _nll_loss(inputs, target, target_dim=-1, weight=None, ignore_index=None, reduction='none', label_smoothing=0.0):
|
|
3897
3649
|
"""nll loss inner function"""
|
|
3898
|
-
_neg = _get_cache_prim(P.Neg)()
|
|
3899
|
-
_gather_d = _get_cache_prim(P.GatherD)()
|
|
3900
|
-
_gather = _get_cache_prim(P.Gather)()
|
|
3901
|
-
_ones_like = _get_cache_prim(P.OnesLike)()
|
|
3902
|
-
_equal = _get_cache_prim(P.Equal)()
|
|
3903
|
-
|
|
3904
3650
|
if target.ndim == inputs.ndim - 1:
|
|
3905
3651
|
target = target.expand_dims(target_dim)
|
|
3906
3652
|
if ignore_index is not None:
|
|
3907
|
-
non_pad_mask =
|
|
3908
|
-
target = target.masked_fill(non_pad_mask, 0)
|
|
3653
|
+
non_pad_mask = equal_(target, ignore_index)
|
|
3654
|
+
target = target.masked_fill(non_pad_mask, ops.cast(0, target.dtype))
|
|
3909
3655
|
else:
|
|
3910
3656
|
non_pad_mask = target
|
|
3911
3657
|
if weight is not None:
|
|
3912
|
-
loss_weights =
|
|
3658
|
+
loss_weights = gather_(weight, target, 0)
|
|
3913
3659
|
orig_shape = inputs.shape
|
|
3914
3660
|
if inputs.ndim != 2:
|
|
3915
3661
|
inputs = inputs.view(orig_shape[:2] + (-1,))
|
|
3916
3662
|
weight = weight.view(weight.shape + (1,))
|
|
3917
3663
|
weighted_inputs = inputs * weight
|
|
3918
3664
|
weighted_inputs = weighted_inputs.view(orig_shape)
|
|
3919
|
-
loss =
|
|
3920
|
-
smooth_loss =
|
|
3665
|
+
loss = neg_(gather_d_(weighted_inputs, target_dim, target))
|
|
3666
|
+
smooth_loss = neg_(weighted_inputs.sum(axis=target_dim, keepdims=True))
|
|
3921
3667
|
else:
|
|
3922
|
-
loss =
|
|
3923
|
-
smooth_loss =
|
|
3924
|
-
loss_weights =
|
|
3668
|
+
loss = neg_(gather_d_(inputs, target_dim, target))
|
|
3669
|
+
smooth_loss = neg_(inputs.sum(axis=target_dim, keepdims=True))
|
|
3670
|
+
loss_weights = ones_like_(loss)
|
|
3925
3671
|
if ignore_index is not None:
|
|
3926
|
-
loss = loss.masked_fill(non_pad_mask, 0.)
|
|
3927
|
-
loss_weights = loss_weights.masked_fill(non_pad_mask, 0.)
|
|
3928
|
-
smooth_loss = smooth_loss.masked_fill(non_pad_mask, 0.)
|
|
3672
|
+
loss = loss.masked_fill(non_pad_mask, ops.cast(0, loss.dtype))
|
|
3673
|
+
loss_weights = loss_weights.masked_fill(non_pad_mask, ops.cast(0, loss_weights.dtype))
|
|
3674
|
+
smooth_loss = smooth_loss.masked_fill(non_pad_mask, ops.cast(0, smooth_loss.dtype))
|
|
3929
3675
|
|
|
3930
3676
|
loss = loss.squeeze(target_dim)
|
|
3931
3677
|
smooth_loss = smooth_loss.squeeze(target_dim)
|
|
@@ -3947,8 +3693,9 @@ def l1_loss(input, target, reduction='mean'):
|
|
|
3947
3693
|
r"""
|
|
3948
3694
|
Calculate the mean absolute error between the `input` value and the `target` value.
|
|
3949
3695
|
|
|
3950
|
-
Assuming that the :math:`x` and :math:`y` are 1-D Tensor,
|
|
3951
|
-
|
|
3696
|
+
Assuming that the :math:`x` and :math:`y` (predicted and target value) are 1-D Tensor,
|
|
3697
|
+
length :math:`N`, `reduction` is set to ``'none'``, then calculate the loss of
|
|
3698
|
+
:math:`x` and :math:`y` without dimensionality reduction.
|
|
3952
3699
|
|
|
3953
3700
|
The formula is as follows:
|
|
3954
3701
|
|
|
@@ -3957,7 +3704,7 @@ def l1_loss(input, target, reduction='mean'):
|
|
|
3957
3704
|
|
|
3958
3705
|
where :math:`N` is the batch size.
|
|
3959
3706
|
|
|
3960
|
-
If `reduction` is ``
|
|
3707
|
+
If `reduction` is ``'mean'`` or ``'sum'`` , then:
|
|
3961
3708
|
|
|
3962
3709
|
.. math::
|
|
3963
3710
|
\ell(x, y) =
|
|
@@ -3978,13 +3725,13 @@ def l1_loss(input, target, reduction='mean'):
|
|
|
3978
3725
|
- ``'sum'``: the output elements will be summed.
|
|
3979
3726
|
|
|
3980
3727
|
Returns:
|
|
3981
|
-
Tensor or Scalar, if `reduction` is ``
|
|
3728
|
+
Tensor or Scalar, if `reduction` is ``'none'``, return a Tensor with same shape and dtype as `input`.
|
|
3982
3729
|
Otherwise, a scalar value will be returned.
|
|
3983
3730
|
|
|
3984
3731
|
Raises:
|
|
3985
3732
|
TypeError: If `input` is not a Tensor.
|
|
3986
3733
|
TypeError: If `target` is not a Tensor.
|
|
3987
|
-
ValueError: If `reduction` is not one of ``
|
|
3734
|
+
ValueError: If `reduction` is not one of ``'none'``, ``'mean'`` or ``'sum'``.
|
|
3988
3735
|
|
|
3989
3736
|
Supported Platforms:
|
|
3990
3737
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -3992,8 +3739,8 @@ def l1_loss(input, target, reduction='mean'):
|
|
|
3992
3739
|
Examples:
|
|
3993
3740
|
>>> from mindspore import Tensor, ops
|
|
3994
3741
|
>>> from mindspore import dtype as mstype
|
|
3995
|
-
>>> x =
|
|
3996
|
-
>>> target =
|
|
3742
|
+
>>> x = Tensor([[1, 2, 3], [4, 5, 6]], mstype.float32)
|
|
3743
|
+
>>> target = Tensor([[6, 5, 4], [3, 2, 1]], mstype.float32)
|
|
3997
3744
|
>>> output = ops.l1_loss(x, target, reduction="mean")
|
|
3998
3745
|
>>> print(output)
|
|
3999
3746
|
3.0
|
|
@@ -4002,7 +3749,7 @@ def l1_loss(input, target, reduction='mean'):
|
|
|
4002
3749
|
_check_is_tensor('target', target, "l1_loss")
|
|
4003
3750
|
if reduction not in ('mean', 'sum', 'none'):
|
|
4004
3751
|
raise ValueError(f"For l1_loss, the 'reduction' must be in ['mean', 'sum', 'none'], but got {reduction}.")
|
|
4005
|
-
loss =
|
|
3752
|
+
loss = abs_(input - target)
|
|
4006
3753
|
return _get_loss(loss, reduction, "l1_loss")
|
|
4007
3754
|
|
|
4008
3755
|
|
|
@@ -4037,6 +3784,7 @@ def smooth_l1_loss(input, target, beta=1.0, reduction='none'):
|
|
|
4037
3784
|
|
|
4038
3785
|
Args:
|
|
4039
3786
|
input (Tensor): Tensor of shape :math:`(N, *)` where :math:`*` means, any number of additional dimensions.
|
|
3787
|
+
Data type is float16, float32 or float64.
|
|
4040
3788
|
target (Tensor): Ground truth data, tensor of shape :math:`(N, *)`, same shape and dtype as the `input`.
|
|
4041
3789
|
beta (float): A parameter used to control the point where the function will change between
|
|
4042
3790
|
L1 to L2 loss. The value should be greater than zero. Default: ``1.0`` .
|
|
@@ -4115,13 +3863,13 @@ def threshold(input, thr, value):
|
|
|
4115
3863
|
_check_is_tensor('input', input, "threshold")
|
|
4116
3864
|
_check_value_type("thr", thr, [float, int], "threshold")
|
|
4117
3865
|
_check_value_type("value", value, [float, int], "threshold")
|
|
4118
|
-
cond =
|
|
3866
|
+
cond = greater_(input, thr)
|
|
4119
3867
|
input_type = input.dtype
|
|
4120
3868
|
value = Tensor(value, input_type)
|
|
4121
3869
|
input_shape = input.shape
|
|
4122
|
-
shape_tensor =
|
|
4123
|
-
value =
|
|
4124
|
-
return
|
|
3870
|
+
shape_tensor = tuple_to_tensor_(input_shape, mstype.int64)
|
|
3871
|
+
value = fillv2_(shape_tensor, value)
|
|
3872
|
+
return select_(cond, input, value)
|
|
4125
3873
|
|
|
4126
3874
|
|
|
4127
3875
|
def leaky_relu(input, alpha=0.2):
|
|
@@ -4139,6 +3887,11 @@ def leaky_relu(input, alpha=0.2):
|
|
|
4139
3887
|
For more details, see `Rectifier Nonlinearities Improve Neural Network Acoustic Models
|
|
4140
3888
|
<https://ai.stanford.edu/~amaas/papers/relu_hybrid_icml2013_final.pdf>`_.
|
|
4141
3889
|
|
|
3890
|
+
LeakyReLU Activation Function Graph:
|
|
3891
|
+
|
|
3892
|
+
.. image:: ../images/LeakyReLU.png
|
|
3893
|
+
:align: center
|
|
3894
|
+
|
|
4142
3895
|
Args:
|
|
4143
3896
|
input (Tensor): The input of leaky_relu is a Tensor of any dimension.
|
|
4144
3897
|
alpha (Union[int, float]): Slope of the activation function when the element of `input` is less than 0.
|
|
@@ -4165,10 +3918,10 @@ def leaky_relu(input, alpha=0.2):
|
|
|
4165
3918
|
"""
|
|
4166
3919
|
_check_is_tensor('input', input, "leaky_relu")
|
|
4167
3920
|
_check_value_type("alpha", alpha, [float, int], "leaky_relu")
|
|
4168
|
-
select_op =
|
|
3921
|
+
select_op = maximum_
|
|
4169
3922
|
if alpha > 1:
|
|
4170
|
-
select_op =
|
|
4171
|
-
alpha =
|
|
3923
|
+
select_op = minimum_
|
|
3924
|
+
alpha = cast_(F.scalar_to_tensor(alpha), input.dtype)
|
|
4172
3925
|
return select_op(alpha * input, input)
|
|
4173
3926
|
|
|
4174
3927
|
|
|
@@ -4209,48 +3962,6 @@ def intopk(x1, x2, k):
|
|
|
4209
3962
|
_in_topk = _get_cache_prim(P.InTopK)(k)
|
|
4210
3963
|
return _in_topk(x1, x2)
|
|
4211
3964
|
|
|
4212
|
-
|
|
4213
|
-
def log_softmax(logits, axis=-1):
|
|
4214
|
-
r"""
|
|
4215
|
-
Applies the Log Softmax function to the input tensor on the specified axis.
|
|
4216
|
-
Supposes a slice in the given axis, :math:`x` for each element :math:`x_i`,
|
|
4217
|
-
the Log Softmax function is shown as follows:
|
|
4218
|
-
|
|
4219
|
-
.. math::
|
|
4220
|
-
\text{output}(x_i) = \log \left(\frac{\exp(x_i)} {\sum_{j = 0}^{N-1}\exp(x_j)}\right),
|
|
4221
|
-
|
|
4222
|
-
where :math:`N` is the length of the Tensor.
|
|
4223
|
-
|
|
4224
|
-
Args:
|
|
4225
|
-
logits (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
|
|
4226
|
-
additional dimensions, with float16 or float32 data type.
|
|
4227
|
-
axis (int): The axis to perform the Log softmax operation. Default: ``-1`` .
|
|
4228
|
-
|
|
4229
|
-
Returns:
|
|
4230
|
-
Tensor, with the same type and shape as the logits.
|
|
4231
|
-
|
|
4232
|
-
Raises:
|
|
4233
|
-
TypeError: If `axis` is not an int.
|
|
4234
|
-
TypeError: If dtype of `logits` is neither float16 nor float32.
|
|
4235
|
-
ValueError: If `axis` is not in range [-len(logits.shape), len(logits.shape)).
|
|
4236
|
-
ValueError: If dimension of `logits` is less than 1.
|
|
4237
|
-
|
|
4238
|
-
Supported Platforms:
|
|
4239
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
4240
|
-
|
|
4241
|
-
Examples:
|
|
4242
|
-
>>> import mindspore
|
|
4243
|
-
>>> import numpy as np
|
|
4244
|
-
>>> from mindspore import Tensor, ops
|
|
4245
|
-
>>> logits = Tensor(np.array([1, 2, 3, 4, 5]), mindspore.float32)
|
|
4246
|
-
>>> output = ops.log_softmax(logits)
|
|
4247
|
-
>>> print(output)
|
|
4248
|
-
[-4.4519143 -3.4519143 -2.4519143 -1.4519144 -0.4519144]
|
|
4249
|
-
"""
|
|
4250
|
-
_log_softmax = _get_cache_prim(P.LogSoftmax)(axis)
|
|
4251
|
-
return _log_softmax(logits)
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
3965
|
def lrn(x, depth_radius=5, bias=1.0, alpha=1.0, beta=0.5, norm_region="ACROSS_CHANNELS"):
|
|
4255
3966
|
r"""
|
|
4256
3967
|
Local Response Normalization.
|
|
@@ -4319,6 +4030,11 @@ def mish(x):
|
|
|
4319
4030
|
See more details in `A Self Regularized Non-Monotonic Neural Activation Function
|
|
4320
4031
|
<https://arxiv.org/abs/1908.08681>`_.
|
|
4321
4032
|
|
|
4033
|
+
Mish Activation Function Graph:
|
|
4034
|
+
|
|
4035
|
+
.. image:: ../images/Mish.png
|
|
4036
|
+
:align: center
|
|
4037
|
+
|
|
4322
4038
|
Args:
|
|
4323
4039
|
x (Tensor): The input Tensor.
|
|
4324
4040
|
Supported dtypes:
|
|
@@ -4385,21 +4101,15 @@ def _get_loss(x, reduction, cls_name, weights=1.0):
|
|
|
4385
4101
|
if reduction not in ('mean', 'sum', 'none'):
|
|
4386
4102
|
raise ValueError(f"For '{cls_name}', the 'reduction' must be in ['mean', 'sum', 'none'], "
|
|
4387
4103
|
f"but got {reduction}.")
|
|
4388
|
-
|
|
4389
|
-
reduce_mean = P.ReduceMean()
|
|
4390
|
-
reduce_sum = P.ReduceSum()
|
|
4391
|
-
mul = P.Mul()
|
|
4392
|
-
cast = P.Cast()
|
|
4393
|
-
|
|
4394
4104
|
input_dtype = x.dtype
|
|
4395
|
-
x =
|
|
4396
|
-
weights =
|
|
4397
|
-
x =
|
|
4105
|
+
x = cast_(x, mstype.float32)
|
|
4106
|
+
weights = cast_(weights, mstype.float32)
|
|
4107
|
+
x = mul_(weights, x)
|
|
4398
4108
|
if reduction == 'mean':
|
|
4399
|
-
x =
|
|
4109
|
+
x = reduce_mean_(x, _get_axis(x))
|
|
4400
4110
|
if reduction == 'sum':
|
|
4401
|
-
x =
|
|
4402
|
-
x =
|
|
4111
|
+
x = reduce_sum_(x, _get_axis(x))
|
|
4112
|
+
x = cast_(x, input_dtype)
|
|
4403
4113
|
return x
|
|
4404
4114
|
|
|
4405
4115
|
|
|
@@ -4410,20 +4120,6 @@ def check_input_dtype(param_name1, input_data1, param_name2, input_data2, cls_na
|
|
|
4410
4120
|
f'but got {param_name1} dtype:{input_data1.dtype}, {param_name2} dtype:{input_data2.dtype}.')
|
|
4411
4121
|
|
|
4412
4122
|
|
|
4413
|
-
def check_input_shape(param_name1, input_data1, param_name2, input_data2, cls_name):
|
|
4414
|
-
"""Check the shape of input1 and input2."""
|
|
4415
|
-
if input_data1.shape != input_data2.shape:
|
|
4416
|
-
raise ValueError(f'For {cls_name}, the {param_name1} shape should be equal to {param_name2} shape, '
|
|
4417
|
-
f'but got {param_name1} shape:{input_data1.shape}, {param_name2} shape:{input_data2.shape}.')
|
|
4418
|
-
|
|
4419
|
-
|
|
4420
|
-
def _check_type_and_shape_same(param_name1, input_data1, param_name2, input_data2, cls_name):
|
|
4421
|
-
"""check input1 and input2 type and shape same"""
|
|
4422
|
-
check_input_dtype(param_name1, input_data1, param_name2, input_data2, cls_name)
|
|
4423
|
-
check_input_shape(param_name1, input_data1, param_name2, input_data2, cls_name)
|
|
4424
|
-
return 0
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
4123
|
def margin_ranking_loss(input1, input2, target, margin=0.0, reduction='mean'):
|
|
4428
4124
|
r"""
|
|
4429
4125
|
MarginRankingLoss creates a criterion that measures the loss.
|
|
@@ -4448,7 +4144,7 @@ def margin_ranking_loss(input1, input2, target, margin=0.0, reduction='mean'):
|
|
|
4448
4144
|
- ``'sum'``: the output elements will be summed.
|
|
4449
4145
|
|
|
4450
4146
|
Returns:
|
|
4451
|
-
Tensor or Scalar. if `reduction` is ``
|
|
4147
|
+
Tensor or Scalar. if `reduction` is ``'none'``, its shape is the same as `input1`.
|
|
4452
4148
|
Otherwise, a scalar value will be returned.
|
|
4453
4149
|
|
|
4454
4150
|
Raises:
|
|
@@ -4478,10 +4174,9 @@ def margin_ranking_loss(input1, input2, target, margin=0.0, reduction='mean'):
|
|
|
4478
4174
|
_check_is_tensor('input1', input1, "margin_ranking_loss")
|
|
4479
4175
|
_check_is_tensor('input2', input2, "margin_ranking_loss")
|
|
4480
4176
|
_check_is_tensor('target', target, "margin_ranking_loss")
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
x = maximum(-target * (input1 - input2) + margin, 0)
|
|
4177
|
+
check_input_dtype('input1', input1, 'input2', input2, 'margin_ranking_loss')
|
|
4178
|
+
check_input_dtype('target', target, 'input1', input1, 'margin_ranking_loss')
|
|
4179
|
+
x = maximum_(-target * (input1 - input2) + margin, 0)
|
|
4485
4180
|
return _get_loss(x, reduction, "margin_ranking_loss")
|
|
4486
4181
|
|
|
4487
4182
|
|
|
@@ -4509,7 +4204,7 @@ def cosine_embedding_loss(input1, input2, target, margin=0.0, reduction="mean"):
|
|
|
4509
4204
|
input2 (Tensor): Tensor of shape :math:`(N, *)`, same shape and dtype as `input1`.
|
|
4510
4205
|
target (Tensor): Contains value 1 or -1. Suppose the shape of `input1` is
|
|
4511
4206
|
: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)`.
|
|
4512
|
-
margin (float, optional): Should be in [-1.0, 1.0]. Default: 0.0
|
|
4207
|
+
margin (float, optional): Should be in [-1.0, 1.0]. Default: ``0.0``.
|
|
4513
4208
|
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
4514
4209
|
``'sum'`` . Default: ``'mean'`` .
|
|
4515
4210
|
|
|
@@ -4524,7 +4219,7 @@ def cosine_embedding_loss(input1, input2, target, margin=0.0, reduction="mean"):
|
|
|
4524
4219
|
Raises:
|
|
4525
4220
|
TypeError: If `margin` is not a float.
|
|
4526
4221
|
ValueError: If `reduction` is not one of ``'none'``, ``'mean'``, ``'sum'``.
|
|
4527
|
-
ValueError: If `margin` is not in range [-1, 1].
|
|
4222
|
+
ValueError: If `margin` is not in range [-1.0, 1.0].
|
|
4528
4223
|
|
|
4529
4224
|
Supported Platforms:
|
|
4530
4225
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -4544,7 +4239,7 @@ def cosine_embedding_loss(input1, input2, target, margin=0.0, reduction="mean"):
|
|
|
4544
4239
|
_check_is_tensor('input1', input1, "ops.cosine_embedding_loss")
|
|
4545
4240
|
_check_is_tensor('input2', input2, "ops.cosine_embedding_loss")
|
|
4546
4241
|
_check_is_tensor('target', target, "ops.cosine_embedding_loss")
|
|
4547
|
-
|
|
4242
|
+
check_input_dtype('input1', input1, 'input2', input2, 'ops.cosine_embedding_loss')
|
|
4548
4243
|
_check_reduced_shape_valid(ops.shape(input1), ops.shape(target), (1,),
|
|
4549
4244
|
"ops.cosine_embedding_loss", "input1", "target")
|
|
4550
4245
|
if input1.dtype in (mstype.int32, mstype.int64):
|
|
@@ -4558,14 +4253,14 @@ def cosine_embedding_loss(input1, input2, target, margin=0.0, reduction="mean"):
|
|
|
4558
4253
|
if margin_f > 1.0 or margin_f < -1.0:
|
|
4559
4254
|
raise ValueError(f"For ops.cosine_embedding_loss, the value of 'margin' should be in [-1, 1],"
|
|
4560
4255
|
f"but got {margin_f}.")
|
|
4561
|
-
prod_sum =
|
|
4562
|
-
square1 =
|
|
4563
|
-
square2 =
|
|
4256
|
+
prod_sum = reduce_sum_(input1 * input2, (1,))
|
|
4257
|
+
square1 = reduce_sum_(ops.square(input1), (1,))
|
|
4258
|
+
square2 = reduce_sum_(ops.square(input2), (1,))
|
|
4564
4259
|
denom = ops.sqrt(square1) * ops.sqrt(square2)
|
|
4565
4260
|
cosine = prod_sum / denom
|
|
4566
4261
|
|
|
4567
4262
|
pos_value = 1.0 - cosine
|
|
4568
|
-
neg_value =
|
|
4263
|
+
neg_value = maximum_(cosine - margin_f, 0.0)
|
|
4569
4264
|
zeros = ops.zeros_like(cosine)
|
|
4570
4265
|
pos_part = ops.select(target == 1, pos_value, zeros)
|
|
4571
4266
|
neg_part = ops.select(target == -1, neg_value, zeros)
|
|
@@ -4622,7 +4317,7 @@ def max_pool3d(x, kernel_size, stride=None, padding=0, dilation=1, ceil_mode=Fal
|
|
|
4622
4317
|
W_{out} = \left\lfloor\frac{W_{in} + 2 \times \text{padding}[2] - \text{dilation}[2] \times
|
|
4623
4318
|
(\text{kernel_size}[2] - 1) - 1}{\text{stride}[2]} + 1\right\rfloor
|
|
4624
4319
|
|
|
4625
|
-
- **argmax** (Tensor) - Index corresponding to the maximum value. Data type is int64. It will be
|
|
4320
|
+
- **argmax** (Tensor) - Index corresponding to the maximum value. Data type is int64. It will be returned
|
|
4626
4321
|
only when `return_indices` is ``True`` .
|
|
4627
4322
|
|
|
4628
4323
|
Raises:
|
|
@@ -4700,9 +4395,9 @@ def grid_sample(input, grid, mode='bilinear', padding_mode='zeros', align_corner
|
|
|
4700
4395
|
|
|
4701
4396
|
padding_mode (str): An optional string specifying the pad method. The optional values are "zeros", "border" or
|
|
4702
4397
|
"reflection". Default: ``'zeros'`` .
|
|
4703
|
-
align_corners (bool):
|
|
4704
|
-
the center points of the input
|
|
4705
|
-
to the corner points of the input
|
|
4398
|
+
align_corners (bool): If set to `True`, the extrema (-1 and 1) are considered as referring to
|
|
4399
|
+
the center points of the input's corner pixels. If set to `False`, they are instead considered as referring
|
|
4400
|
+
to the corner points of the input's corner pixels, making the sampling more resolution agnostic. Default:
|
|
4706
4401
|
``False`` .
|
|
4707
4402
|
|
|
4708
4403
|
Returns:
|
|
@@ -4775,8 +4470,8 @@ def ctc_loss(log_probs, targets, input_lengths, target_lengths, blank=0, reducti
|
|
|
4775
4470
|
log_probs (Tensor): A tensor of shape :math:`(T, N, C)`, where T is input length, N is batch size and C is
|
|
4776
4471
|
number of classes (including blank).
|
|
4777
4472
|
targets (Tensor): Target sequences. A tensor of shape :math:`(N, S)`, where S is max target length.
|
|
4778
|
-
input_lengths (Union(tuple, Tensor)): Lengths of the input. A tuple or Tensor of shape(N)
|
|
4779
|
-
target_lengths (Union(tuple, Tensor)): Lengths of the target. A tuple or Tensor of shape(N)
|
|
4473
|
+
input_lengths (Union(tuple, Tensor)): Lengths of the input. A tuple or Tensor of shape :math:`(N)`.
|
|
4474
|
+
target_lengths (Union(tuple, Tensor)): Lengths of the target. A tuple or Tensor of shape :math:`(N)`.
|
|
4780
4475
|
blank (int, optional): The blank label. Default: ``0`` .
|
|
4781
4476
|
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
4782
4477
|
``'sum'`` . Default: ``'mean'`` .
|
|
@@ -4923,17 +4618,10 @@ def gaussian_nll_loss(x, target, var, full=False, eps=1e-6, reduction='mean'):
|
|
|
4923
4618
|
if not x.shape == var.shape:
|
|
4924
4619
|
if x.shape[:-1] == var.shape:
|
|
4925
4620
|
var = var.unsqueeze(dim=-1)
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
raise ValueError(f"For 'gaussian_nll_loss', 'var' must be able to correctly broadcast to 'x' and 'target'.")
|
|
4931
|
-
max_op = P.Maximum()
|
|
4932
|
-
log_op = P.Log()
|
|
4933
|
-
square_op = P.Square()
|
|
4934
|
-
maxima = max_op(var, eps)
|
|
4935
|
-
logarithm = log_op(maxima)
|
|
4936
|
-
squared_loss = square_op(x - target)
|
|
4621
|
+
|
|
4622
|
+
maxima = maximum_(var, eps)
|
|
4623
|
+
logarithm = log_(maxima)
|
|
4624
|
+
squared_loss = square_(x - target)
|
|
4937
4625
|
c = 0 if not full else 0.5 * log(2 * pi)
|
|
4938
4626
|
loss = 0.5 * (logarithm + squared_loss / maxima) + c
|
|
4939
4627
|
if reduction == 'mean':
|
|
@@ -4943,12 +4631,6 @@ def gaussian_nll_loss(x, target, var, full=False, eps=1e-6, reduction='mean'):
|
|
|
4943
4631
|
return loss
|
|
4944
4632
|
|
|
4945
4633
|
|
|
4946
|
-
@_primexpr
|
|
4947
|
-
def _check_hinge_embedding_loss(shape, shape2):
|
|
4948
|
-
if shape2 != shape:
|
|
4949
|
-
raise ValueError(f"For 'HingeEmbeddingLoss' the input tensor and the labels must have the same shape.")
|
|
4950
|
-
|
|
4951
|
-
|
|
4952
4634
|
@_primexpr
|
|
4953
4635
|
def _check_hinge_embedding_loss_type(inputs_dtype, targets_dtype, inputs, targets, margin, reduction):
|
|
4954
4636
|
"""Check hinge embedding loss type."""
|
|
@@ -4996,7 +4678,7 @@ def hinge_embedding_loss(inputs, targets, margin=1.0, reduction='mean'):
|
|
|
4996
4678
|
inputs (Tensor): Predicted values, represented as :math:`x` in the formula.
|
|
4997
4679
|
targets (Tensor): Label values, represented as :math:`y` in the formula.
|
|
4998
4680
|
Has the same shape as `inputs`, contains -1 or 1.
|
|
4999
|
-
margin (float, int): Threshold defined by Hinge Embedding Loss
|
|
4681
|
+
margin (float, int): Threshold defined by Hinge Embedding Loss `margin`.
|
|
5000
4682
|
Represented as :math:`\Delta` in the formula. Default: ``1.0`` .
|
|
5001
4683
|
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
5002
4684
|
``'sum'`` . Default: ``'mean'`` .
|
|
@@ -5006,7 +4688,7 @@ def hinge_embedding_loss(inputs, targets, margin=1.0, reduction='mean'):
|
|
|
5006
4688
|
- ``'sum'``: the output elements will be summed.
|
|
5007
4689
|
|
|
5008
4690
|
Returns:
|
|
5009
|
-
Tensor or Tensor scalar, the computed loss depending on
|
|
4691
|
+
Tensor or Tensor scalar, the computed loss depending on `reduction`.
|
|
5010
4692
|
|
|
5011
4693
|
Raises:
|
|
5012
4694
|
TypeError: If `inputs` is not a Tensor.
|
|
@@ -5034,9 +4716,6 @@ def hinge_embedding_loss(inputs, targets, margin=1.0, reduction='mean'):
|
|
|
5034
4716
|
inputs_dtype = inputs.dtype
|
|
5035
4717
|
targets_dtype = targets.dtype
|
|
5036
4718
|
_check_hinge_embedding_loss_type(inputs_dtype, targets_dtype, inputs, targets, margin, reduction)
|
|
5037
|
-
_shape = inputs.shape
|
|
5038
|
-
_t_shape = targets.shape
|
|
5039
|
-
_check_hinge_embedding_loss(_shape, _t_shape)
|
|
5040
4719
|
|
|
5041
4720
|
min_val = Tensor(0, inputs_dtype)
|
|
5042
4721
|
pos_index = targets > 0
|
|
@@ -5257,21 +4936,25 @@ def conv1d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5257
4936
|
, :math:`weight` is the convolution kernel value and :math:`X` represents the input feature map.
|
|
5258
4937
|
|
|
5259
4938
|
Here are the indices' meanings:
|
|
5260
|
-
- :math:`i` corresponds to the batch number, ranging from 0 to N-1, where N is the batch size of the input.
|
|
5261
4939
|
|
|
5262
|
-
- :math:`
|
|
4940
|
+
- :math:`i` corresponds to the batch number, the range is :math:`[0, N-1]`,
|
|
4941
|
+
where :math:`N` is the batch size of the input.
|
|
4942
|
+
|
|
4943
|
+
- :math:`j` corresponds to the output channel, ranging from :math:`[0, C_{out}-1]`,
|
|
4944
|
+
where :math:`C_{out}` is the number of
|
|
5263
4945
|
output channels, which is also equal to the number of kernels.
|
|
5264
4946
|
|
|
5265
|
-
- :math:`k` corresponds to the input channel, ranging from 0
|
|
4947
|
+
- :math:`k` corresponds to the input channel, ranging from :math:`[0, C_{in}-1]`,
|
|
4948
|
+
where :math:`C_{in}` is the number of
|
|
5266
4949
|
input channels, which is also equal to the number of channels in the convolutional kernels.
|
|
5267
4950
|
|
|
5268
|
-
Therefore, in the above formula, :math:`{bias}(C_{
|
|
5269
|
-
output channel, :math:`{weight}(C_{
|
|
4951
|
+
Therefore, in the above formula, :math:`{bias}(C_{\text{out}_j})` represents the bias of the :math:`j`-th
|
|
4952
|
+
output channel, :math:`{weight}(C_{\text{out}_j}, k)` represents the slice of the :math:`j`-th convolutional
|
|
5270
4953
|
kernel in the :math:`k`-th channel, and :math:`{X}(N_i, k)` represents the slice of the :math:`k`-th input
|
|
5271
4954
|
channel in the :math:`i`-th batch of the input feature map.
|
|
5272
4955
|
|
|
5273
|
-
The shape of the convolutional kernel is given by :math:`(
|
|
5274
|
-
where :math
|
|
4956
|
+
The shape of the convolutional kernel is given by :math:`(\text{kernel_size})`,
|
|
4957
|
+
where :math:`\text{kernel_size}` is the width of the kernel.
|
|
5275
4958
|
If we consider the input and output channels as well as the `group` parameter, the complete kernel shape
|
|
5276
4959
|
will be :math:`(C_{out}, C_{in} / \text{group}, \text{kernel_size})`,
|
|
5277
4960
|
where `group` is the number of groups dividing `x`'s input channel when applying group convolution.
|
|
@@ -5282,7 +4965,7 @@ def conv1d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5282
4965
|
|
|
5283
4966
|
Note:
|
|
5284
4967
|
On Ascend platform, only group convolution in depthwise convolution scenarios is supported.
|
|
5285
|
-
That is, when `groups>1`, condition
|
|
4968
|
+
That is, when `groups>1`, condition :math:`C_{in}` = :math:`C_{out}` = `groups` must be satisfied.
|
|
5286
4969
|
|
|
5287
4970
|
Args:
|
|
5288
4971
|
input (Tensor): Input Tensor of shape :math:`(N, C_{in}, L_{in})`.
|
|
@@ -5342,7 +5025,7 @@ def conv1d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5342
5025
|
>>> from mindspore import Tensor, ops
|
|
5343
5026
|
>>> x = Tensor(np.arange(64).reshape((4, 4, 4)), mindspore.float32)
|
|
5344
5027
|
>>> weight = Tensor(np.arange(8).reshape((2, 2, 2)), mindspore.float32)
|
|
5345
|
-
>>> bias = Tensor([-0.12345, 2.7683],
|
|
5028
|
+
>>> bias = Tensor([-0.12345, 2.7683], mindspore.float32)
|
|
5346
5029
|
>>> output = ops.conv1d(x, weight, pad_mode='pad', padding=(1,), bias=bias, groups=2)
|
|
5347
5030
|
>>> print(output.shape)
|
|
5348
5031
|
(4, 2, 5)
|
|
@@ -5351,13 +5034,12 @@ def conv1d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5351
5034
|
raise ValueError(f"For 'conv1d', the input must be a 3D Tensor, but got input of {input.ndim}D.")
|
|
5352
5035
|
if weight.ndim != 3:
|
|
5353
5036
|
raise ValueError(f"For 'conv1d', the weight must be a 3D Tensor, but got input of {weight.ndim}D.")
|
|
5354
|
-
|
|
5355
|
-
expanded_input = _expand(input, 2)
|
|
5037
|
+
expanded_input = expand_dims_(input, 2)
|
|
5356
5038
|
sqz = _get_cache_prim(P.Squeeze)(2)
|
|
5357
5039
|
weight_shape = weight.shape
|
|
5358
5040
|
out_channel = weight_shape[0]
|
|
5359
5041
|
kernel_size = (1, weight_shape[2])
|
|
5360
|
-
expanded_weight =
|
|
5042
|
+
expanded_weight = expand_dims_(weight, 2)
|
|
5361
5043
|
if isinstance(padding, int):
|
|
5362
5044
|
padding = (0, 0, padding, padding)
|
|
5363
5045
|
elif isinstance(padding, (tuple, list)):
|
|
@@ -5406,12 +5088,15 @@ def conv2d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5406
5088
|
, :math:`weight` is the convolution kernel value and :math:`X` represents the input feature map.
|
|
5407
5089
|
|
|
5408
5090
|
Here are the indices' meanings:
|
|
5409
|
-
- :math:`i` corresponds to the batch number, ranging from 0 to N-1, where N is the batch size of the input.
|
|
5410
5091
|
|
|
5411
|
-
- :math:`
|
|
5412
|
-
|
|
5092
|
+
- :math:`i` corresponds to the batch number, the range is :math:`[0, N-1]`,
|
|
5093
|
+
where :math:`N` is the batch size of the input.
|
|
5413
5094
|
|
|
5414
|
-
- :math:`
|
|
5095
|
+
- :math:`j` corresponds to the output channel, the range is :math:`[0, C_{out}-1]`,
|
|
5096
|
+
where :math:`C_{out}` is the number of output channels, which is also equal to the number of kernels.
|
|
5097
|
+
|
|
5098
|
+
- :math:`k` corresponds to the input channel, the range is :math:`[0, C_{in}-1]`,
|
|
5099
|
+
where :math:`C_{in}` is the number of
|
|
5415
5100
|
input channels, which is also equal to the number of channels in the convolutional kernels.
|
|
5416
5101
|
|
|
5417
5102
|
Therefore, in the above formula, :math:`{bias}(C_{out_j})` represents the bias of the :math:`j`-th
|
|
@@ -5419,8 +5104,9 @@ def conv2d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5419
5104
|
kernel in the :math:`k`-th channel, and :math:`{X}(N_i, k)` represents the slice of the :math:`k`-th input
|
|
5420
5105
|
channel in the :math:`i`-th batch of the input feature map.
|
|
5421
5106
|
|
|
5422
|
-
The shape of the convolutional kernel is given by :math:`(
|
|
5423
|
-
where :math
|
|
5107
|
+
The shape of the convolutional kernel is given by :math:`(\text{kernel_size[0]}, \text{kernel_size[1]})`,
|
|
5108
|
+
where :math:`\text{kernel_size[0]}` and :math:`\text{kernel_size[1]}` are the height and width of the kernel,
|
|
5109
|
+
respectively.
|
|
5424
5110
|
If we consider the input and output channels as well as the `group` parameter, the complete kernel shape
|
|
5425
5111
|
will be :math:`(C_{out}, C_{in} / \text{group}, \text{kernel_size[0]}, \text{kernel_size[1]})`,
|
|
5426
5112
|
where `group` is the number of groups dividing `x`'s input channel when applying group convolution.
|
|
@@ -5431,7 +5117,7 @@ def conv2d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5431
5117
|
|
|
5432
5118
|
Note:
|
|
5433
5119
|
On Ascend platform, only group convolution in depthwise convolution scenarios is supported.
|
|
5434
|
-
That is, when `groups>1`, condition
|
|
5120
|
+
That is, when `groups>1`, condition :math:`C_{in}` = :math:`C_{out}` = `groups` must be satisfied.
|
|
5435
5121
|
|
|
5436
5122
|
Args:
|
|
5437
5123
|
input (Tensor): Tensor of shape :math:`(N, C_{in}, H_{in}, W_{in})`.
|
|
@@ -5476,7 +5162,7 @@ def conv2d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5476
5162
|
TypeError: If `stride`, `padding` or `dilation` is neither an int nor a tuple.
|
|
5477
5163
|
TypeError: `groups` is not an int.
|
|
5478
5164
|
TypeError: If `bias` is not a Tensor.
|
|
5479
|
-
ValueError: If the shape of `bias` is not :math:`C_{out}` .
|
|
5165
|
+
ValueError: If the shape of `bias` is not :math:`(C_{out})` .
|
|
5480
5166
|
ValueError: If `stride` or `dilation` is less than 1.
|
|
5481
5167
|
ValueError: If `pad_mode` is not one of 'same', 'valid' or 'pad'.
|
|
5482
5168
|
ValueError: If `padding` is a tuple/list whose length is not equal to 2.
|
|
@@ -5537,6 +5223,11 @@ def hardsigmoid(input):
|
|
|
5537
5223
|
|
|
5538
5224
|
where :math:`x_i` is an element of the input Tensor.
|
|
5539
5225
|
|
|
5226
|
+
HSigmoid Activation Function Graph:
|
|
5227
|
+
|
|
5228
|
+
.. image:: ../images/HSigmoid.png
|
|
5229
|
+
:align: center
|
|
5230
|
+
|
|
5540
5231
|
Args:
|
|
5541
5232
|
input (Tensor): The input Tensor.
|
|
5542
5233
|
|
|
@@ -5576,10 +5267,15 @@ def hardtanh(input, min_val=-1.0, max_val=1.0):
|
|
|
5576
5267
|
|
|
5577
5268
|
Linear region range :math:`[min\_val, max\_val]` can be adjusted using `min_val` and `max_val`.
|
|
5578
5269
|
|
|
5270
|
+
Hardtanh Activation Function Graph:
|
|
5271
|
+
|
|
5272
|
+
.. image:: ../images/Hardtanh.png
|
|
5273
|
+
:align: center
|
|
5274
|
+
|
|
5579
5275
|
Args:
|
|
5580
5276
|
input (Tensor): Input Tensor.
|
|
5581
|
-
min_val (Union[int, float]): Minimum value of the linear region range. Default: ``-1.0`` .
|
|
5582
|
-
max_val (Union[int, float]): Maximum value of the linear region range. Default: ``1.0`` .
|
|
5277
|
+
min_val (Union[int, float], optional): Minimum value of the linear region range. Default: ``-1.0`` .
|
|
5278
|
+
max_val (Union[int, float], optional): Maximum value of the linear region range. Default: ``1.0`` .
|
|
5583
5279
|
|
|
5584
5280
|
Returns:
|
|
5585
5281
|
Tensor, with the same dtype and shape as `input`.
|
|
@@ -5604,18 +5300,18 @@ def hardtanh(input, min_val=-1.0, max_val=1.0):
|
|
|
5604
5300
|
_check_value_type("min_val", min_val, [int, float], "hardtanh")
|
|
5605
5301
|
_check_value_type("max_val", max_val, [int, float], "hardtanh")
|
|
5606
5302
|
input_dtype = input.dtype
|
|
5607
|
-
input =
|
|
5608
|
-
input =
|
|
5303
|
+
input = maximum_(input, min_val)
|
|
5304
|
+
input = minimum_(input, max_val)
|
|
5609
5305
|
return input.astype(input_dtype)
|
|
5610
5306
|
|
|
5611
5307
|
|
|
5612
5308
|
def huber_loss(input, target, reduction='mean', delta=1.0):
|
|
5613
5309
|
r"""
|
|
5614
5310
|
Calculates the error between the predicted value and the target value,
|
|
5615
|
-
which has the best of both the loss of
|
|
5311
|
+
which has the best of both the loss of :func:`mindspore.ops.l1_loss` and the loss of :func:`mindspore.ops.mse_loss`.
|
|
5616
5312
|
|
|
5617
5313
|
Assuming that the :math:`x` and :math:`y` are 1-D Tensor, length :math:`N`, the `reduction` parameter
|
|
5618
|
-
is set to ``
|
|
5314
|
+
is set to ``'none'`` then calculate the loss of :math:`x` and :math:`y` without dimensionality reduction.
|
|
5619
5315
|
The formula is as follows:
|
|
5620
5316
|
|
|
5621
5317
|
.. math::
|
|
@@ -5656,14 +5352,14 @@ def huber_loss(input, target, reduction='mean', delta=1.0):
|
|
|
5656
5352
|
The value must be greater than zero. Default: ``1.0`` .
|
|
5657
5353
|
|
|
5658
5354
|
Returns:
|
|
5659
|
-
Tensor or Scalar, if `reduction` is ``
|
|
5355
|
+
Tensor or Scalar, if `reduction` is ``'none'``, return a Tensor with same shape and dtype as `input`.
|
|
5660
5356
|
Otherwise, a scalar value will be returned.
|
|
5661
5357
|
|
|
5662
5358
|
Raises:
|
|
5663
5359
|
TypeError: If `input` or `target` is not a Tensor.
|
|
5664
5360
|
TypeError: If dtype of `delta` is neither float nor int.
|
|
5665
5361
|
ValueError: If `delta` is less than or equal to 0.
|
|
5666
|
-
ValueError: If `reduction` is not one of ``
|
|
5362
|
+
ValueError: If `reduction` is not one of ``'none'``, ``'mean'``, ``'sum'``.
|
|
5667
5363
|
ValueError: If `input` and `target` have different shapes and cannot be broadcasted to each other.
|
|
5668
5364
|
|
|
5669
5365
|
Supported Platforms:
|
|
@@ -5682,14 +5378,12 @@ def huber_loss(input, target, reduction='mean', delta=1.0):
|
|
|
5682
5378
|
_check_is_tensor('target', target, "huber_loss")
|
|
5683
5379
|
_check_value_type("delta", delta, [int, float], "huber_loss")
|
|
5684
5380
|
_check_number_gt_value("delta", delta, 0.0, "huber_loss")
|
|
5685
|
-
|
|
5686
|
-
|
|
5687
|
-
|
|
5688
|
-
|
|
5689
|
-
|
|
5690
|
-
|
|
5691
|
-
l2 = multi(delta, sub(z, 0.5 * delta))
|
|
5692
|
-
loss = _get_cache_prim(P.Select)()(cond, l1, l2)
|
|
5381
|
+
z = sub_(input, target)
|
|
5382
|
+
z = abs_(z)
|
|
5383
|
+
cond = less_(z, delta)
|
|
5384
|
+
l1 = mul_(0.5, square_(z))
|
|
5385
|
+
l2 = mul_(delta, sub_(z, 0.5 * delta))
|
|
5386
|
+
loss = select_(cond, l1, l2)
|
|
5693
5387
|
return _get_loss(loss, reduction, "huber_loss")
|
|
5694
5388
|
|
|
5695
5389
|
|
|
@@ -5741,7 +5435,7 @@ def adaptive_avg_pool1d(input, output_size):
|
|
|
5741
5435
|
"""
|
|
5742
5436
|
def _check(x, output_size):
|
|
5743
5437
|
x_in_shape = x.shape
|
|
5744
|
-
x_dtype =
|
|
5438
|
+
x_dtype = dtype_(x)
|
|
5745
5439
|
if not isinstance(x, (Tensor, Tensor_)):
|
|
5746
5440
|
raise TypeError("For adaptive_avg_pool1d, the input input must be tensor")
|
|
5747
5441
|
|
|
@@ -5761,21 +5455,16 @@ def adaptive_avg_pool1d(input, output_size):
|
|
|
5761
5455
|
|
|
5762
5456
|
_check(input, output_size)
|
|
5763
5457
|
x_in_shape = input.shape
|
|
5764
|
-
expand_ = _get_cache_prim(P.ExpandDims)()
|
|
5765
5458
|
squeeze_ = _get_cache_prim(P.Squeeze)(2)
|
|
5766
|
-
|
|
5767
5459
|
width = x_in_shape[2]
|
|
5768
5460
|
stride = width // output_size
|
|
5769
5461
|
kernel_size = width - (output_size - 1) * stride
|
|
5770
5462
|
stride = (1, width // output_size)
|
|
5771
5463
|
kernel_size = (1, kernel_size)
|
|
5772
|
-
|
|
5773
5464
|
avg_pool_ = _get_cache_prim(P.AvgPool)(kernel_size=kernel_size, strides=stride)
|
|
5774
|
-
|
|
5775
|
-
input = expand_(input, 2)
|
|
5465
|
+
input = expand_dims_(input, 2)
|
|
5776
5466
|
input = avg_pool_(input)
|
|
5777
5467
|
input = squeeze_(input)
|
|
5778
|
-
|
|
5779
5468
|
return input
|
|
5780
5469
|
|
|
5781
5470
|
|
|
@@ -5798,7 +5487,8 @@ def batch_norm(input_x, running_mean, running_var, weight, bias, training=False,
|
|
|
5798
5487
|
mean of :math:`x`, :math:`variance` is the variance of :math:`x`.
|
|
5799
5488
|
|
|
5800
5489
|
.. warning::
|
|
5801
|
-
- For
|
|
5490
|
+
- For Atlas 200/300/500 inference product,
|
|
5491
|
+
the result accuracy fails to reach 1‰ due to the square root instruction.
|
|
5802
5492
|
|
|
5803
5493
|
Note:
|
|
5804
5494
|
- If `training` is `False`, `weight`, `bias`, `running_mean` and `running_var` are Tensors.
|
|
@@ -5960,7 +5650,7 @@ def conv3d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5960
5650
|
r"""
|
|
5961
5651
|
Applies a 3D convolution over an input tensor. The input tensor is typically of
|
|
5962
5652
|
shape :math:`(N, C_{in}, D_{in}, H_{in}, W_{in})`, where :math:`N` is batch size, :math:`C`
|
|
5963
|
-
is channel number, :math:`D`
|
|
5653
|
+
is channel number, :math:`D, H, W` are the depth, height and width of the feature graph, respectively.
|
|
5964
5654
|
|
|
5965
5655
|
The output is calculated based on formula:
|
|
5966
5656
|
|
|
@@ -5970,26 +5660,30 @@ def conv3d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5970
5660
|
\sum_{k = 0}^{C_{in} - 1} \text{ccor}({\text{weight}(C_{\text{out}_j}, k), \text{X}(N_i, k)})
|
|
5971
5661
|
|
|
5972
5662
|
where :math:`bias` is the output channel bias, :math:`ccor` is
|
|
5973
|
-
the `cross-correlation <https://en.wikipedia.org/wiki/Cross-correlation>`_
|
|
5663
|
+
the `cross-correlation <https://en.wikipedia.org/wiki/Cross-correlation>`_
|
|
5974
5664
|
, :math:`weight` is the convolution kernel value and :math:`X` represents the input feature map.
|
|
5975
5665
|
|
|
5976
5666
|
Here are the indices' meanings:
|
|
5977
|
-
- :math:`i` corresponds to the batch number, ranging from 0 to N-1, where N is the batch size of the input.
|
|
5978
5667
|
|
|
5979
|
-
- :math:`
|
|
5668
|
+
- :math:`i` corresponds to the batch number, the range is :math:`[0, N-1]`,
|
|
5669
|
+
where :math:`N` is the batch size of the input.
|
|
5670
|
+
|
|
5671
|
+
- :math:`j` corresponds to the output channel, the range is :math:`[0, C_{out}-1]`,
|
|
5672
|
+
where :math:`C_{out}` is the number of
|
|
5980
5673
|
output channels, which is also equal to the number of kernels.
|
|
5981
5674
|
|
|
5982
|
-
- :math:`k` corresponds to the input channel,
|
|
5675
|
+
- :math:`k` corresponds to the input channel, the range is :math:`[0, C_{in}-1]`,
|
|
5676
|
+
where :math:`C_{in}` is the number of
|
|
5983
5677
|
input channels, which is also equal to the number of channels in the convolutional kernels.
|
|
5984
5678
|
|
|
5985
|
-
Therefore, in the above formula, :math:`{bias}(C_{
|
|
5986
|
-
output channel, :math:`{weight}(C_{
|
|
5679
|
+
Therefore, in the above formula, :math:`{bias}(C_{\text{out}_j})` represents the bias of the :math:`j`-th
|
|
5680
|
+
output channel, :math:`{weight}(C_{\text{out}_j}, k)` represents the slice of the :math:`j`-th convolutional
|
|
5987
5681
|
kernel in the :math:`k`-th channel, and :math:`{X}(N_i, k)` represents the slice of the :math:`k`-th input
|
|
5988
5682
|
channel in the :math:`i`-th batch of the input feature map.
|
|
5989
5683
|
|
|
5990
5684
|
The shape of the convolutional kernel is given by
|
|
5991
5685
|
:math:`(\text{kernel_size[0]}, \text{kernel_size[1]}, \text{kernel_size[2]})`
|
|
5992
|
-
where :math
|
|
5686
|
+
where :math:`\text{kernel_size[0]}` , :math:`\text{kernel_size[1]}` and :math:`\text{kernel_size[2]}` are the depth,
|
|
5993
5687
|
height and width of the kernel, respectively.
|
|
5994
5688
|
If we consider the input and output channels as well as the `group` parameter, the complete kernel shape
|
|
5995
5689
|
will be :math:`(C_{out}, C_{in} / \text{group}, \text{kernel_size[0]},
|
|
@@ -6000,8 +5694,8 @@ def conv3d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
6000
5694
|
<http://vision.stanford.edu/cs598_spring07/papers/Lecun98.pdf>`_.
|
|
6001
5695
|
|
|
6002
5696
|
Note:
|
|
6003
|
-
1. On Ascend platform,
|
|
6004
|
-
2. On Ascend dilation
|
|
5697
|
+
1. On Ascend platform, :math:`groups = 1` must be satisfied.
|
|
5698
|
+
2. On Ascend platform, :math:`dilation=1` must be satisfied.
|
|
6005
5699
|
|
|
6006
5700
|
Args:
|
|
6007
5701
|
input (Tensor): Tensor of shape :math:`(N, C_{in}, D_{in}, H_{in}, W_{in})`.
|
|
@@ -6040,8 +5734,7 @@ def conv3d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
6040
5734
|
there will be :math:`k - 1` pixels skipped for each sampling location.
|
|
6041
5735
|
The value ranges for the depth, height, and width dimensions are [1, D], [1, H], and [1, W],
|
|
6042
5736
|
respectively. Default: ``1`` .
|
|
6043
|
-
groups (int, optional):The number of groups into which the filter is divided.
|
|
6044
|
-
and `out_channels` must be divisible by `group`. Default: ``1`` .
|
|
5737
|
+
groups (int, optional):The number of groups into which the filter is divided. Default: ``1`` .
|
|
6045
5738
|
|
|
6046
5739
|
Returns:
|
|
6047
5740
|
Tensor, the value that applied 3D convolution. The shape is :math:`(N, C_{out}, D_{out}, H_{out}, W_{out})`.
|
|
@@ -6083,7 +5776,7 @@ def conv3d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
6083
5776
|
TypeError: If `out_channel` or `groups` is not an int.
|
|
6084
5777
|
TypeError: If `stride`, `padding` or `dilation` is neither an int nor a tuple.
|
|
6085
5778
|
TypeError: If `bias` is not a Tensor.
|
|
6086
|
-
ValueError: If the shape of `bias` is not :math:`C_{out}`.
|
|
5779
|
+
ValueError: If the shape of `bias` is not :math:`(C_{out})`.
|
|
6087
5780
|
ValueError: If `stride` or `dilation` is less than 1.
|
|
6088
5781
|
ValueError: If `pad_mode` is not one of 'same', 'valid' or 'pad'.
|
|
6089
5782
|
ValueError: If `padding` is a tuple or list whose length is not equal to 3.
|
|
@@ -6191,21 +5884,19 @@ def pixel_shuffle(input, upscale_factor):
|
|
|
6191
5884
|
_check_positive_int(upscale_factor, "upscale_factor")
|
|
6192
5885
|
_check_is_tensor("input", input, "pixel_shuffle")
|
|
6193
5886
|
_check_pixel_shuffle_unshuffle_input_shape(input, "pixel_shuffle")
|
|
6194
|
-
idx =
|
|
5887
|
+
idx = shape_(input)
|
|
6195
5888
|
length = input.ndim
|
|
6196
5889
|
pre = idx[:-3]
|
|
6197
5890
|
c, h, w = idx[-3:]
|
|
6198
5891
|
_check_pxiel_shuffle_valid(c, upscale_factor)
|
|
6199
5892
|
c = c // upscale_factor ** 2
|
|
6200
5893
|
input_perm = (pre + (c, upscale_factor, upscale_factor, h, w))
|
|
6201
|
-
|
|
6202
|
-
transpose = _get_cache_prim(P.Transpose)()
|
|
6203
|
-
input = reshape(input, input_perm)
|
|
5894
|
+
input = reshape_(input, input_perm)
|
|
6204
5895
|
input_perm = [i for i in range(length - 2)]
|
|
6205
5896
|
input_perm = input_perm + [length, length - 2, length + 1, length - 1]
|
|
6206
5897
|
input_perm = tuple(input_perm)
|
|
6207
|
-
input =
|
|
6208
|
-
input =
|
|
5898
|
+
input = transpose_(input, input_perm)
|
|
5899
|
+
input = reshape_(input, (pre + (c, upscale_factor * h, upscale_factor * w)))
|
|
6209
5900
|
return input
|
|
6210
5901
|
|
|
6211
5902
|
|
|
@@ -6256,7 +5947,7 @@ def pixel_unshuffle(input, downscale_factor):
|
|
|
6256
5947
|
_check_positive_int(downscale_factor, "downscale_factor")
|
|
6257
5948
|
_check_is_tensor("input", input, "pixel_unshuffle")
|
|
6258
5949
|
_check_pixel_shuffle_unshuffle_input_shape(input, "pixel_unshuffle")
|
|
6259
|
-
idx =
|
|
5950
|
+
idx = shape_(input)
|
|
6260
5951
|
length = input.ndim
|
|
6261
5952
|
pre = idx[:-3]
|
|
6262
5953
|
c, h, w = idx[-3:]
|
|
@@ -6264,14 +5955,12 @@ def pixel_unshuffle(input, downscale_factor):
|
|
|
6264
5955
|
h = h // downscale_factor
|
|
6265
5956
|
w = w // downscale_factor
|
|
6266
5957
|
input_perm = (pre + (c, h, downscale_factor, w, downscale_factor))
|
|
6267
|
-
|
|
6268
|
-
transpose = _get_cache_prim(P.Transpose)()
|
|
6269
|
-
input = reshape(input, input_perm)
|
|
5958
|
+
input = reshape_(input, input_perm)
|
|
6270
5959
|
input_perm = [i for i in range(length - 2)]
|
|
6271
5960
|
input_perm = input_perm + [length - 1, length + 1, length - 2, length]
|
|
6272
5961
|
input_perm = tuple(input_perm)
|
|
6273
|
-
input =
|
|
6274
|
-
input =
|
|
5962
|
+
input = transpose_(input, input_perm)
|
|
5963
|
+
input = reshape_(input, (pre + (c * downscale_factor * downscale_factor, h, w)))
|
|
6275
5964
|
return input
|
|
6276
5965
|
|
|
6277
5966
|
|
|
@@ -6288,7 +5977,7 @@ def glu(x, axis=-1):
|
|
|
6288
5977
|
See `Language Modeling with Gated Convluational Networks <https://arxiv.org/abs/1612.08083>`_.
|
|
6289
5978
|
|
|
6290
5979
|
Args:
|
|
6291
|
-
x (Tensor): Tensor to be
|
|
5980
|
+
x (Tensor): Tensor to be split. Its dtype is Number, and shape is :math:`(\ast_1, N, \ast_2)`
|
|
6292
5981
|
where `*` means, any number of additional dimensions.
|
|
6293
5982
|
axis (int, optional): the axis to split the input. It must be int. Default: ``-1`` , the last axis of `x`.
|
|
6294
5983
|
|
|
@@ -6310,9 +5999,6 @@ def glu(x, axis=-1):
|
|
|
6310
5999
|
[[0.05744425 0.11973753]
|
|
6311
6000
|
[0.33409387 0.41398472]]
|
|
6312
6001
|
"""
|
|
6313
|
-
if not isinstance(x, Tensor) or x.size == 0:
|
|
6314
|
-
raise TypeError("glu does not support scalars because halving size must be even")
|
|
6315
|
-
|
|
6316
6002
|
spilt = _get_cache_prim(P.Split)(axis=axis, output_num=2)
|
|
6317
6003
|
x, y = spilt(x)
|
|
6318
6004
|
y = sigmoid_(y)
|
|
@@ -6332,7 +6018,7 @@ def multi_margin_loss(input, target, p=1, margin=1, weight=None, reduction='mean
|
|
|
6332
6018
|
.. math::
|
|
6333
6019
|
\text{loss}(x, y) = \frac{\sum_i \max(0, \text{margin} - x[y] + x[i])^p}{\text{x.size}(0)}
|
|
6334
6020
|
|
|
6335
|
-
where :math:`i\in \{0,⋯,x.size(0)
|
|
6021
|
+
where :math:`i\in \{0,⋯,x.size(0)-1\}` and :math:`i \ne y`.
|
|
6336
6022
|
|
|
6337
6023
|
Args:
|
|
6338
6024
|
input (Tensor): Input , with shape :math:`(N, C)`. Data type only support float32, float16 or float64.
|
|
@@ -6351,8 +6037,8 @@ def multi_margin_loss(input, target, p=1, margin=1, weight=None, reduction='mean
|
|
|
6351
6037
|
- ``'sum'``: the output elements will be summed.
|
|
6352
6038
|
|
|
6353
6039
|
Returns:
|
|
6354
|
-
Tensor. If `reduction` is ``'none'``, returns a Tensor with the same shape as `target`.
|
|
6355
|
-
|
|
6040
|
+
- **outputs** - Tensor. If `reduction` is ``'none'``, returns a Tensor with the same shape as `target`.
|
|
6041
|
+
Otherwise, it is a scalar.
|
|
6356
6042
|
|
|
6357
6043
|
Raises:
|
|
6358
6044
|
TypeError: If dtype of `p` or `target` is not int.
|
|
@@ -6411,10 +6097,11 @@ def multilabel_margin_loss(input, target, reduction='mean'):
|
|
|
6411
6097
|
This allows for different samples to have variable amounts of target classes.
|
|
6412
6098
|
|
|
6413
6099
|
Args:
|
|
6414
|
-
input (Tensor): Predict data. Tensor of shape :math:`(C)`
|
|
6415
|
-
is the batch size and :math:`C` is the number of classes.
|
|
6416
|
-
|
|
6417
|
-
|
|
6100
|
+
input (Tensor): Predict data, :math:`x` in the formula above. Tensor of shape :math:`(C)`
|
|
6101
|
+
or :math:`(N, C)`, where :math:`N` is the batch size and :math:`C` is the number of classes.
|
|
6102
|
+
Data type must be float16 or float32.
|
|
6103
|
+
target (Tensor): Ground truth data, :math:`y` in the formula above, with the same shape as `input`,
|
|
6104
|
+
data type must be int32 and label targets padded by -1.
|
|
6418
6105
|
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
6419
6106
|
``'sum'`` . Default: ``'mean'`` .
|
|
6420
6107
|
|
|
@@ -6490,9 +6177,6 @@ def multilabel_soft_margin_loss(input, target, weight=None, reduction='mean'):
|
|
|
6490
6177
|
Tensor, the data type is the same as input, if the `reduction` is ``'none'``,
|
|
6491
6178
|
its shape is :math:`(N)` , otherwise it is zero.
|
|
6492
6179
|
|
|
6493
|
-
Raises:
|
|
6494
|
-
ValueError: If the rank of `input` or `target` is not 2.
|
|
6495
|
-
|
|
6496
6180
|
Supported Platforms:
|
|
6497
6181
|
``Ascend`` ``GPU`` ``CPU``
|
|
6498
6182
|
|
|
@@ -6507,81 +6191,22 @@ def multilabel_soft_margin_loss(input, target, weight=None, reduction='mean'):
|
|
|
6507
6191
|
cls_name = "multilabel_soft_margin_loss"
|
|
6508
6192
|
_check_is_tensor('input', input, cls_name)
|
|
6509
6193
|
_check_is_tensor('target', target, cls_name)
|
|
6510
|
-
if input.ndim != 2 or target.ndim != 2:
|
|
6511
|
-
raise ValueError(
|
|
6512
|
-
"For 'MultiLabelSoftMarginLoss', the inputs must be 2d tensor, but got dims: "
|
|
6513
|
-
f"input: {input.ndim}, target: {target.ndim} "
|
|
6514
|
-
)
|
|
6515
6194
|
|
|
6516
|
-
mul_op = _get_cache_prim(P.Mul)()
|
|
6517
|
-
exp_op = _get_cache_prim(P.Exp)()
|
|
6518
|
-
add_op = _get_cache_prim(P.Add)()
|
|
6519
|
-
log_op = _get_cache_prim(P.Log)()
|
|
6520
|
-
dyn_shape = _get_cache_prim(P.TensorShape)()
|
|
6521
6195
|
input_shape = input.shape
|
|
6522
6196
|
if ops.is_sequence_value_unknown(input_shape):
|
|
6523
|
-
input_shape =
|
|
6197
|
+
input_shape = tensor_shape_(input)
|
|
6524
6198
|
|
|
6525
|
-
pos =
|
|
6526
|
-
neg =
|
|
6527
|
-
loss =
|
|
6199
|
+
pos = log_(add_(exp_(-input), 1))
|
|
6200
|
+
neg = log_(add_(exp_(input), 1))
|
|
6201
|
+
loss = mul_(target, pos) + mul_(1 - target, neg)
|
|
6528
6202
|
if weight is not None:
|
|
6529
|
-
loss =
|
|
6203
|
+
loss = mul_(loss, weight)
|
|
6530
6204
|
class_dim = input.ndim - 1
|
|
6531
6205
|
loss = loss.sum(axis=class_dim) / input_shape[class_dim]
|
|
6532
6206
|
return _get_loss(loss, reduction, cls_name)
|
|
6533
6207
|
|
|
6534
6208
|
|
|
6535
|
-
def
|
|
6536
|
-
r"""
|
|
6537
|
-
Exponential Linear Unit activation function.
|
|
6538
|
-
|
|
6539
|
-
Applies the exponential linear unit function element-wise.
|
|
6540
|
-
The activation function is defined as:
|
|
6541
|
-
|
|
6542
|
-
.. math::
|
|
6543
|
-
|
|
6544
|
-
\text{ELU}(x)= \left\{
|
|
6545
|
-
\begin{array}{align}
|
|
6546
|
-
\alpha(e^{x} - 1) & \text{if } x \le 0\\
|
|
6547
|
-
x & \text{if } x \gt 0\\
|
|
6548
|
-
\end{array}\right.
|
|
6549
|
-
|
|
6550
|
-
Where :math:`x` is the element of input Tensor `input_x`, :math:`\alpha` is param `alpha`,
|
|
6551
|
-
it determines the smoothness of ELU.
|
|
6552
|
-
The picture about ELU looks like this `ELU <https://en.wikipedia.org/wiki/
|
|
6553
|
-
Activation_function#/media/File:Activation_elu.svg>`_ .
|
|
6554
|
-
|
|
6555
|
-
Args:
|
|
6556
|
-
input_x (Tensor): The input of ELU is a Tensor of any dimension with data type of float16 or float32.
|
|
6557
|
-
alpha (float, optional): The alpha value of ELU, the data type is float. Only support '1.0' currently.
|
|
6558
|
-
Default: ``1.0`` .
|
|
6559
|
-
|
|
6560
|
-
Returns:
|
|
6561
|
-
Tensor, has the same shape and data type as `input_x`.
|
|
6562
|
-
|
|
6563
|
-
Raises:
|
|
6564
|
-
TypeError: If `alpha` is not a float.
|
|
6565
|
-
TypeError: If dtype of `input_x` is neither float16 nor float32.
|
|
6566
|
-
ValueError: If `alpha` is not equal to 1.0.
|
|
6567
|
-
|
|
6568
|
-
Supported Platforms:
|
|
6569
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
6570
|
-
|
|
6571
|
-
Examples:
|
|
6572
|
-
>>> import mindspore
|
|
6573
|
-
>>> import numpy as np
|
|
6574
|
-
>>> from mindspore import Tensor, ops
|
|
6575
|
-
>>> x = Tensor(np.array([[-1.0, 4.0, -8.0], [2.0, -5.0, 9.0]]), mindspore.float32)
|
|
6576
|
-
>>> output = ops.elu(x)
|
|
6577
|
-
>>> print(output)
|
|
6578
|
-
[[-0.63212055 4. -0.99966455]
|
|
6579
|
-
[ 2. -0.99326205 9. ]]
|
|
6580
|
-
"""
|
|
6581
|
-
return _get_cache_prim(P.Elu)(alpha=alpha)(input_x)
|
|
6582
|
-
|
|
6583
|
-
|
|
6584
|
-
def gelu(input_x, approximate='none'):
|
|
6209
|
+
def gelu(input, approximate='none'):
|
|
6585
6210
|
r"""
|
|
6586
6211
|
Gaussian Error Linear Units activation function.
|
|
6587
6212
|
|
|
@@ -6602,18 +6227,25 @@ def gelu(input_x, approximate='none'):
|
|
|
6602
6227
|
.. math::
|
|
6603
6228
|
GELU(x_i) = 0.5 * x_i * (1 + \tanh(\sqrt(2 / \pi) * (x_i + 0.044715 * x_i^3)))
|
|
6604
6229
|
|
|
6230
|
+
For the related GELU graph, refer to `GELU <https://en.wikipedia.org/wiki/Activation_function#/media/File:Activation_gelu.png>`_ .
|
|
6231
|
+
|
|
6232
|
+
GELU Activation Function Graph:
|
|
6233
|
+
|
|
6234
|
+
.. image:: ../images/GELU.png
|
|
6235
|
+
:align: center
|
|
6236
|
+
|
|
6605
6237
|
Args:
|
|
6606
|
-
|
|
6238
|
+
input (Tensor): The input of the activation function GeLU, the data type is float16, float32 or float64.
|
|
6607
6239
|
approximate (str): the gelu approximation algorithm to use. Acceptable vaslues are ``'none'`` and ``'tanh'`` .
|
|
6608
6240
|
Default: ``'none'`` .
|
|
6609
6241
|
|
|
6610
6242
|
Returns:
|
|
6611
|
-
Tensor, with the same type and shape as `
|
|
6243
|
+
Tensor, with the same type and shape as `input`.
|
|
6612
6244
|
|
|
6613
6245
|
Raises:
|
|
6614
|
-
TypeError: If `
|
|
6615
|
-
TypeError: If dtype of `
|
|
6616
|
-
ValueError: If `approximate` value is neither `none`
|
|
6246
|
+
TypeError: If `input` is not a Tensor.
|
|
6247
|
+
TypeError: If dtype of `input` is not bfloat16, float16, float32 or float64.
|
|
6248
|
+
ValueError: If `approximate` value is neither `none` nor `tanh`.
|
|
6617
6249
|
|
|
6618
6250
|
Supported Platforms:
|
|
6619
6251
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -6629,17 +6261,17 @@ def gelu(input_x, approximate='none'):
|
|
|
6629
6261
|
if approximate not in ['none', 'tanh']:
|
|
6630
6262
|
raise ValueError("For ops.gelu, approximate value should be either 'none' or 'tanh'.")
|
|
6631
6263
|
|
|
6632
|
-
x_dtype =
|
|
6633
|
-
if x_dtype not in [mstype.float16, mstype.float32, mstype.float64]:
|
|
6264
|
+
x_dtype = dtype_(input)
|
|
6265
|
+
if x_dtype not in [mstype.float16, mstype.float32, mstype.float64, mstype.bfloat16]:
|
|
6634
6266
|
raise TypeError(f"For gelu, the input dtype must be float16, float32 or float64, "
|
|
6635
6267
|
f"but got {x_dtype}.")
|
|
6636
6268
|
if approximate == 'tanh':
|
|
6637
|
-
output =
|
|
6269
|
+
output = gelu_(input)
|
|
6638
6270
|
else:
|
|
6639
|
-
output =
|
|
6640
|
-
output =
|
|
6641
|
-
output =
|
|
6642
|
-
output =
|
|
6271
|
+
output = sqrt_(Tensor(2.0, x_dtype))
|
|
6272
|
+
output = div_(input, output)
|
|
6273
|
+
output = erf_(output) + Tensor(1.0, x_dtype)
|
|
6274
|
+
output = input * output * Tensor(0.5, x_dtype)
|
|
6643
6275
|
|
|
6644
6276
|
return output
|
|
6645
6277
|
|
|
@@ -6689,13 +6321,6 @@ def channel_shuffle(x, groups):
|
|
|
6689
6321
|
return y
|
|
6690
6322
|
|
|
6691
6323
|
|
|
6692
|
-
@_primexpr
|
|
6693
|
-
def _shape_check(in_shape, dim_list, prim_name=None):
|
|
6694
|
-
msg_prefix = f"For '{prim_name}', the" if prim_name else "The"
|
|
6695
|
-
if len(in_shape) not in dim_list:
|
|
6696
|
-
raise ValueError(f"{msg_prefix} input must has dim in {dim_list}, but got {len(in_shape)}")
|
|
6697
|
-
|
|
6698
|
-
|
|
6699
6324
|
def lp_pool1d(x, norm_type, kernel_size, stride=None, ceil_mode=False):
|
|
6700
6325
|
r"""
|
|
6701
6326
|
Applying 1D LPPooling operation on an input Tensor can be regarded as forming a 1D input plane.
|
|
@@ -6731,7 +6356,7 @@ def lp_pool1d(x, norm_type, kernel_size, stride=None, ceil_mode=False):
|
|
|
6731
6356
|
L_{out} = \left\lfloor\frac{L_{in} - \text{kernel_size}}{\text{stride}} + 1\right\rfloor
|
|
6732
6357
|
|
|
6733
6358
|
Raises:
|
|
6734
|
-
TypeError: If `x` is not
|
|
6359
|
+
TypeError: If `x` is not a Tensor.
|
|
6735
6360
|
TypeError: If `kernel_size` or `stride` is not an int.
|
|
6736
6361
|
TypeError: If `ceil_mode` is not a bool.
|
|
6737
6362
|
TypeError: If `norm_type` is neither float nor int.
|
|
@@ -6757,7 +6382,6 @@ def lp_pool1d(x, norm_type, kernel_size, stride=None, ceil_mode=False):
|
|
|
6757
6382
|
[51. 54.]
|
|
6758
6383
|
[63. 66.]]]
|
|
6759
6384
|
"""
|
|
6760
|
-
_shape_check(x.shape, [2, 3], "lp_pool1d")
|
|
6761
6385
|
if isinstance(norm_type, (float, int)):
|
|
6762
6386
|
norm_type = float(norm_type)
|
|
6763
6387
|
else:
|
|
@@ -6816,7 +6440,7 @@ def lp_pool2d(x, norm_type, kernel_size, stride=None, ceil_mode=False):
|
|
|
6816
6440
|
W_{out} = \left\lfloor\frac{W_{in} - \text{kernel_size}[1]}{\text{stride}[1]} + 1\right\rfloor
|
|
6817
6441
|
|
|
6818
6442
|
Raises:
|
|
6819
|
-
TypeError: If `x` is not
|
|
6443
|
+
TypeError: If `x` is not a Tensor.
|
|
6820
6444
|
TypeError: If `kernel_size` or `stride` is neither int nor tuple.
|
|
6821
6445
|
TypeError: If `ceil_mode` is not a bool.
|
|
6822
6446
|
TypeError: If `norm_type` is neither float nor int.
|
|
@@ -6850,7 +6474,6 @@ def lp_pool2d(x, norm_type, kernel_size, stride=None, ceil_mode=False):
|
|
|
6850
6474
|
[ 999. 1008. 1017.]]]]
|
|
6851
6475
|
|
|
6852
6476
|
"""
|
|
6853
|
-
_shape_check(x.shape, [4], "lp_pool2d")
|
|
6854
6477
|
if isinstance(norm_type, (float, int)):
|
|
6855
6478
|
norm_type = float(norm_type)
|
|
6856
6479
|
else:
|
|
@@ -6913,13 +6536,13 @@ def mse_loss(input, target, reduction='mean'):
|
|
|
6913
6536
|
if reduction not in ['mean', 'none', 'sum']:
|
|
6914
6537
|
raise ValueError("For ops.mse_loss, `reduction` value should be either 'mean', 'none' or 'sum'.")
|
|
6915
6538
|
|
|
6916
|
-
x =
|
|
6539
|
+
x = square_(input - target)
|
|
6917
6540
|
float_type = (mstype.float16, mstype.float32, mstype.float64)
|
|
6918
6541
|
if x.dtype not in float_type:
|
|
6919
6542
|
input_dtype = mstype.float32
|
|
6920
6543
|
else:
|
|
6921
6544
|
input_dtype = x.dtype
|
|
6922
|
-
x =
|
|
6545
|
+
x = cast_(x, mstype.float32)
|
|
6923
6546
|
|
|
6924
6547
|
average_flag = True
|
|
6925
6548
|
reduce_flag = True
|
|
@@ -6929,12 +6552,12 @@ def mse_loss(input, target, reduction='mean'):
|
|
|
6929
6552
|
reduce_flag = False
|
|
6930
6553
|
|
|
6931
6554
|
if reduce_flag and average_flag:
|
|
6932
|
-
x =
|
|
6555
|
+
x = reduce_mean_(x, _get_axis(x))
|
|
6933
6556
|
|
|
6934
6557
|
if reduce_flag and not average_flag:
|
|
6935
|
-
x =
|
|
6558
|
+
x = reduce_sum_(x, _get_axis(x))
|
|
6936
6559
|
|
|
6937
|
-
return
|
|
6560
|
+
return cast_(x, input_dtype)
|
|
6938
6561
|
|
|
6939
6562
|
|
|
6940
6563
|
def msort(input):
|
|
@@ -6996,7 +6619,7 @@ def triplet_margin_loss(anchor, positive, negative, margin=1.0, p=2, eps=1e-06,
|
|
|
6996
6619
|
Tensor. If `reduction` is ``"none"``, its shape is :math:`(N)`. Otherwise, a scalar value will be returned.
|
|
6997
6620
|
|
|
6998
6621
|
Raises:
|
|
6999
|
-
TypeError: If `anchor` or `positive` or
|
|
6622
|
+
TypeError: If `anchor` or `positive` or `negative` is not a Tensor.
|
|
7000
6623
|
TypeError: If dtype of `anchor`, `positive` and `negative` is not the same.
|
|
7001
6624
|
TypeError: If `margin` is not a float.
|
|
7002
6625
|
TypeError: If `p` is not an int.
|
|
@@ -7335,7 +6958,7 @@ def multi_head_attention_forward(query, key, value, embed_dim_to_check, num_head
|
|
|
7335
6958
|
|
|
7336
6959
|
if attn_mask is not None and attn_mask.dtype == mstype.bool_:
|
|
7337
6960
|
new_attn_mask = ops.zeros_like(attn_mask, dtype=q.dtype)
|
|
7338
|
-
attn_mask = new_attn_mask.masked_fill(attn_mask, float("-inf"))
|
|
6961
|
+
attn_mask = new_attn_mask.masked_fill(attn_mask, ops.cast(float("-inf"), new_attn_mask.dtype))
|
|
7339
6962
|
|
|
7340
6963
|
if attn_mask is not None:
|
|
7341
6964
|
if attn_mask.shape[0] == 1:
|
|
@@ -7444,11 +7067,10 @@ def max_pool2d(x, kernel_size, stride=None, padding=0, dilation=1, return_indice
|
|
|
7444
7067
|
return out
|
|
7445
7068
|
|
|
7446
7069
|
|
|
7447
|
-
def prompt_flash_attention(query, key, value,
|
|
7448
|
-
|
|
7449
|
-
|
|
7450
|
-
|
|
7451
|
-
num_key_value_heads=0, sparse_mode=0):
|
|
7070
|
+
def prompt_flash_attention(query, key, value, attn_mask, actual_seq_lengths, actual_seq_lengths_kv, pse_shift,
|
|
7071
|
+
deq_scale1, quant_scale1, deq_scale2, quant_scale2, quant_offset2, num_heads,
|
|
7072
|
+
scale_value=1.0, pre_tokens=2147483547, next_tokens=0, input_layout='BSH',
|
|
7073
|
+
num_key_value_heads=0, sparse_mode=0, inner_precise=1):
|
|
7452
7074
|
r"""
|
|
7453
7075
|
The interface for fully inference.
|
|
7454
7076
|
B -- Batch size
|
|
@@ -7456,7 +7078,7 @@ def prompt_flash_attention(query, key, value, padding_mask, attn_mask, actual_se
|
|
|
7456
7078
|
H -- Hidden size
|
|
7457
7079
|
|
|
7458
7080
|
Note:
|
|
7459
|
-
|
|
7081
|
+
experiment ops
|
|
7460
7082
|
|
|
7461
7083
|
.. warning::
|
|
7462
7084
|
This is an experimental API that is subject to change or deletion.
|
|
@@ -7468,11 +7090,11 @@ def prompt_flash_attention(query, key, value, padding_mask, attn_mask, actual_se
|
|
|
7468
7090
|
Input tensor of shape :math:`(B, S, H)` / `(B, N, S, D)`.
|
|
7469
7091
|
value (Tensor) - The value tensor with data type of float16 or float32.
|
|
7470
7092
|
Input tensor of shape :math:`(B, S, H)` / `(B, N, S, D)`.
|
|
7471
|
-
padding_mask (Tensor) - The padding mask tensor with data type of float16 or float32
|
|
7472
7093
|
attn_mask (Tensor) - The attention mask tensor with data type of float16 or float32.
|
|
7473
7094
|
For each element, 0 indicates retention and 1 indicates discard. Input tensor of shape :math:`(B, 1, S, S)`.
|
|
7474
|
-
actual_seq_lengths (
|
|
7475
|
-
actual_seq_lengths_kv (
|
|
7095
|
+
actual_seq_lengths (Tensor): Describe actual sequence length of each input with data type of int64.
|
|
7096
|
+
actual_seq_lengths_kv (Tensor): Describe actual sequence length of each input with data type of int64.
|
|
7097
|
+
pse_shift (Tensor) - The position encoding tensor with data type of float16 or float32.
|
|
7476
7098
|
dep_scale1 (Tensor)
|
|
7477
7099
|
quant_scale1 (Tensor)
|
|
7478
7100
|
deq_scale2 (Tensor)
|
|
@@ -7489,6 +7111,7 @@ def prompt_flash_attention(query, key, value, padding_mask, attn_mask, actual_se
|
|
|
7489
7111
|
num_key_value_heads (int): head numbers of key/value which are used in GQA algorithm.
|
|
7490
7112
|
The value o indicates if the key and value have the same head nums, use numHeads. Default: 0.
|
|
7491
7113
|
sparse_mode (int): Default: 0
|
|
7114
|
+
inner_precise (int): 0, float16 high precision. 1, high performance. default 1
|
|
7492
7115
|
|
|
7493
7116
|
|
|
7494
7117
|
Outputs:
|
|
@@ -7510,16 +7133,74 @@ def prompt_flash_attention(query, key, value, padding_mask, attn_mask, actual_se
|
|
|
7510
7133
|
>>> value = Tensor(np.ones((B, N, S, D), dtype=np.float16))
|
|
7511
7134
|
>>> out = ops.prompt_flash_attention(query, key, value, None, None, None, None, None, None, None, None,
|
|
7512
7135
|
None, N, input_layout='BNSD')
|
|
7513
|
-
>>> print(out
|
|
7136
|
+
>>> print(out.shape)
|
|
7514
7137
|
(1, 16, 256, 16)
|
|
7515
7138
|
"""
|
|
7516
7139
|
|
|
7517
7140
|
pfa = _get_cache_prim(NN_OPS.PromptFlashAttention)(num_heads, scale_value, pre_tokens, next_tokens, input_layout,
|
|
7518
|
-
num_key_value_heads, sparse_mode)
|
|
7519
|
-
return pfa(query, key, value,
|
|
7141
|
+
num_key_value_heads, sparse_mode, inner_precise)
|
|
7142
|
+
return pfa(query, key, value, attn_mask, actual_seq_lengths, actual_seq_lengths_kv, pse_shift, deq_scale1,
|
|
7520
7143
|
quant_scale1, deq_scale2, quant_scale2, quant_offset2)
|
|
7521
7144
|
|
|
7522
7145
|
|
|
7146
|
+
def incre_flash_attention(query, key, value, attn_mask, actual_seq_lengths, pse_shift, dequant_scale1, quant_scale1,
|
|
7147
|
+
dequant_scale2, quant_scale2, quant_offset2, antiquant_scale, antiquant_offset, block_table,
|
|
7148
|
+
num_heads, input_layout="BSH", scale_value=1.0, num_key_value_heads=0, block_size=0,
|
|
7149
|
+
inner_precise=1):
|
|
7150
|
+
r"""
|
|
7151
|
+
The interface for fully inference.
|
|
7152
|
+
|
|
7153
|
+
B -- Batch size
|
|
7154
|
+
|
|
7155
|
+
S -- Sequence length
|
|
7156
|
+
|
|
7157
|
+
H -- Hidden size
|
|
7158
|
+
|
|
7159
|
+
.. warning::
|
|
7160
|
+
This is an experimental API that is subject to change or deletion.
|
|
7161
|
+
If there is no input parameter and no default value, None needs to be passed.
|
|
7162
|
+
|
|
7163
|
+
Inputs:
|
|
7164
|
+
- **query** (Tensor) - The query tensor with data type of float16 or bfloat16.
|
|
7165
|
+
Input tensor of shape :math:`(B, 1, H)` / :math:`(B, N, 1, D)`.
|
|
7166
|
+
- **key** (TensorList) - The key tensor with data type of float16 or bfloat16.
|
|
7167
|
+
Input tensor of shape :math:`(B, S, H)` / :math:`(B, N, S, D)`.
|
|
7168
|
+
- **value** (TensorList) - The value tensor with data type of float16 or bfloat16.
|
|
7169
|
+
Input tensor of shape :math:`(B, S, H)` / :math:`(B, N, S, D)`.
|
|
7170
|
+
- **attn_mask** (Tensor) - The attention mask tensor with data type of float16 or bool.
|
|
7171
|
+
Input tensor of shape :math:`(B, S)` / :math:`(B, 1, S)` / :math:`(B, 1, 1, S)`.
|
|
7172
|
+
- **actual_seq_lengths** (Tensor) - Describe actual sequence length of each input with data type of int.
|
|
7173
|
+
- **pse_shift** (Tensor) - The position encoding tensor with data type of float16 or float32.
|
|
7174
|
+
- **dequant_scale1** (Tensor) - Quantitative parametor, the tensor with data type of uint64.
|
|
7175
|
+
- **quant_scale1** (Tensor) - Quantitative parametor, the tensor with data type of float.
|
|
7176
|
+
- **dequant_scale2** (Tensor) - Quantitative parametor, the tensor with data type of uint64.
|
|
7177
|
+
- **quant_scale2** (Tensor) - Quantitative parametor, the tensor with data type of float.
|
|
7178
|
+
- **quant_offset2** (Tensor) - Quantitative parametor, the tensor with data type of float.
|
|
7179
|
+
- **antiquant_scale** (Tensor) - Quantitative parametor, the tensor with data type of float.
|
|
7180
|
+
- **antiquant_offset** (Tensor) - Quantitative parametor, the tensor with data type of float.
|
|
7181
|
+
- **block_table** (Tensor) - The tensor with data type of float.
|
|
7182
|
+
- **num_heads** (int) - The number of heads.
|
|
7183
|
+
- **input_layout** (str) - the data layout of the input qkv, support `(BSH)` and `(BNSD)`. Default `BSH`.
|
|
7184
|
+
- **scale_value** (double) - The scale value indicating the scale coefficient, which is used as the scalar of
|
|
7185
|
+
Muls in the calculation. Default: 1.0.
|
|
7186
|
+
- **num_key_value_heads** (int) - head numbers of key/value which are used in GQA algorithm.
|
|
7187
|
+
The value o indicates if the key and value have the same head nums, use numHeads. Default: 0.
|
|
7188
|
+
- **block_size** (int) - Default: 0.
|
|
7189
|
+
- **inner_precise** (int) - Default: 1.
|
|
7190
|
+
|
|
7191
|
+
Outputs:
|
|
7192
|
+
- **attention_out** (Tensor) - Input tensor of shape :math:`(B, 1, H)` / :math:`(B, N, 1, D)`.
|
|
7193
|
+
|
|
7194
|
+
Supported Platforms:
|
|
7195
|
+
``Ascend``
|
|
7196
|
+
"""
|
|
7197
|
+
|
|
7198
|
+
_ifa = _get_cache_prim(NN_OPS.IncreFlashAttention)(num_heads, input_layout, scale_value, num_key_value_heads,
|
|
7199
|
+
block_size, inner_precise)
|
|
7200
|
+
return _ifa(query, key, value, attn_mask, actual_seq_lengths, pse_shift, dequant_scale1, quant_scale1,
|
|
7201
|
+
dequant_scale2, quant_scale2, quant_offset2, antiquant_scale, antiquant_offset, block_table)
|
|
7202
|
+
|
|
7203
|
+
|
|
7523
7204
|
__all__ = [
|
|
7524
7205
|
'adaptive_avg_pool1d',
|
|
7525
7206
|
'adaptive_avg_pool2d',
|