mindspore 2.2.14__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 +4 -4
- mindspore/_akg/akg/composite/build_module.py +155 -11
- mindspore/_akg/akg/config/repository.json +38 -0
- mindspore/_akg/akg/ms/info_version_adapt.py +29 -0
- mindspore/_akg/akg/tvm/contrib/nvcc.py +4 -1
- mindspore/_akg/akg/utils/ascend_profilier/path_manager.py +2 -1
- mindspore/_akg/akg/utils/composite_op_helper.py +4 -2
- mindspore/_akg/akg/utils/dump_ascend_meta.py +2 -2
- mindspore/_akg/akg/utils/gen_random.py +14 -8
- mindspore/_akg/akg/utils/op_dsl.py +11 -0
- mindspore/_akg/akg/utils/tbe_codegen_utils.py +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 -433
- mindspore/communication/__init__.py +3 -3
- mindspore/communication/_comm_helper.py +5 -0
- mindspore/communication/management.py +53 -38
- mindspore/config/op_info.config +22 -54
- mindspore/context.py +167 -59
- mindspore/dataset/__init__.py +5 -5
- mindspore/dataset/audio/__init__.py +6 -6
- mindspore/dataset/audio/transforms.py +711 -158
- mindspore/dataset/callback/ds_callback.py +2 -2
- mindspore/dataset/engine/cache_client.py +2 -2
- mindspore/dataset/engine/datasets.py +72 -38
- mindspore/dataset/engine/datasets_audio.py +14 -14
- mindspore/dataset/engine/datasets_standard_format.py +33 -3
- mindspore/dataset/engine/datasets_text.py +38 -38
- mindspore/dataset/engine/datasets_user_defined.py +7 -7
- mindspore/dataset/engine/datasets_vision.py +75 -71
- mindspore/dataset/engine/offload.py +5 -7
- mindspore/dataset/text/__init__.py +3 -3
- mindspore/dataset/text/transforms.py +408 -121
- mindspore/dataset/text/utils.py +9 -9
- mindspore/dataset/transforms/__init__.py +1 -1
- mindspore/dataset/transforms/transforms.py +261 -76
- mindspore/dataset/utils/browse_dataset.py +9 -9
- mindspore/dataset/vision/__init__.py +3 -3
- mindspore/dataset/vision/c_transforms.py +5 -5
- mindspore/dataset/vision/transforms.py +2264 -514
- mindspore/dataset/vision/utils.py +40 -9
- mindspore/dataset/vision/validators.py +7 -1
- mindspore/experimental/optim/__init__.py +12 -2
- mindspore/experimental/optim/adadelta.py +161 -0
- mindspore/experimental/optim/adagrad.py +168 -0
- mindspore/experimental/optim/adam.py +35 -34
- mindspore/experimental/optim/adamax.py +170 -0
- mindspore/experimental/optim/adamw.py +40 -16
- mindspore/experimental/optim/asgd.py +153 -0
- mindspore/experimental/optim/lr_scheduler.py +60 -119
- 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 +6325 -1767
- mindspore/lib/plugin/ascend/custom_aicpu_ops/op_proto/libcust_op_proto.so +0 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_api/include/aclnn_add_custom.h +49 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_api/include/aclnn_decoder_kv_cache.h +59 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_api/include/aclnn_prompt_kv_cache.h +59 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_api/lib/libcust_opapi.so +0 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/config/ascend310p/aic-ascend310p-ops-info.json +52 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/config/ascend910/aic-ascend910-ops-info.json +232 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/config/ascend910b/aic-ascend910b-ops-info.json +232 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/custom_ascendc_ops_impl/dynamic/add_custom.cpp +81 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/custom_ascendc_ops_impl/dynamic/add_custom.py +134 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/custom_ascendc_ops_impl/dynamic/decoder_kv_cache.cpp +192 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/custom_ascendc_ops_impl/dynamic/decoder_kv_cache.py +134 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/custom_ascendc_ops_impl/dynamic/prompt_kv_cache.cpp +274 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/custom_ascendc_ops_impl/dynamic/prompt_kv_cache.py +134 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/op_tiling/lib/linux/x86_64/libcust_opmaster_rt2.0.so +0 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/op_tiling/liboptiling.so +0 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_proto/inc/op_proto.h +39 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_proto/lib/linux/x86_64/libcust_opsproto_rt2.0.so +0 -0
- mindspore/lib/plugin/ascend/libakg.so +0 -0
- mindspore/lib/plugin/ascend/libascend_collective.so +0 -0
- mindspore/lib/plugin/ascend/libdvpp_utils.so +0 -0
- mindspore/lib/plugin/ascend/libhccl_plugin.so +0 -0
- mindspore/lib/plugin/ascend/libmindspore_cpu_kernels.so +0 -0
- mindspore/lib/plugin/cpu/libakg.so +0 -0
- mindspore/lib/plugin/gpu/libcuda_ops.so.10 +0 -0
- mindspore/lib/plugin/gpu/libcuda_ops.so.11 +0 -0
- mindspore/lib/plugin/gpu10.1/libakg.so +0 -0
- mindspore/lib/plugin/gpu10.1/libnccl.so.2 +0 -0
- mindspore/lib/plugin/gpu10.1/libnvidia_collective.so +0 -0
- mindspore/lib/plugin/gpu11.1/libakg.so +0 -0
- mindspore/lib/plugin/gpu11.1/libnccl.so.2 +0 -0
- mindspore/lib/plugin/gpu11.1/libnvidia_collective.so +0 -0
- mindspore/lib/plugin/gpu11.6/libakg.so +0 -0
- mindspore/lib/plugin/gpu11.6/libnccl.so.2 +0 -0
- mindspore/lib/plugin/gpu11.6/libnvidia_collective.so +0 -0
- mindspore/lib/plugin/{libmindspore_ascend.so.1 → libmindspore_ascend.so.2} +0 -0
- mindspore/lib/plugin/libmindspore_gpu.so.10.1 +0 -0
- mindspore/lib/plugin/libmindspore_gpu.so.11.1 +0 -0
- mindspore/lib/plugin/libmindspore_gpu.so.11.6 +0 -0
- mindspore/mindrecord/__init__.py +5 -1
- mindspore/mindrecord/config.py +809 -0
- mindspore/mindrecord/filereader.py +25 -0
- mindspore/mindrecord/filewriter.py +74 -56
- mindspore/mindrecord/mindpage.py +40 -6
- mindspore/mindrecord/shardutils.py +3 -2
- mindspore/mindrecord/shardwriter.py +7 -0
- mindspore/mindrecord/tools/cifar100_to_mr.py +8 -13
- mindspore/mindrecord/tools/cifar10_to_mr.py +9 -15
- mindspore/mindrecord/tools/csv_to_mr.py +4 -9
- mindspore/mindrecord/tools/imagenet_to_mr.py +3 -8
- mindspore/mindrecord/tools/mnist_to_mr.py +7 -12
- mindspore/mindrecord/tools/tfrecord_to_mr.py +1 -6
- mindspore/multiprocessing/__init__.py +68 -0
- mindspore/nn/cell.py +86 -133
- mindspore/nn/dynamic_lr.py +2 -2
- mindspore/nn/layer/activation.py +79 -90
- 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 +105 -44
- 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 +43 -64
- mindspore/nn/optim/ada_grad.py +4 -2
- mindspore/nn/optim/adadelta.py +3 -1
- mindspore/nn/optim/adafactor.py +1 -1
- mindspore/nn/optim/adam.py +102 -181
- mindspore/nn/optim/adamax.py +4 -2
- mindspore/nn/optim/adasum.py +2 -2
- mindspore/nn/optim/asgd.py +4 -2
- mindspore/nn/optim/ftrl.py +31 -61
- mindspore/nn/optim/lamb.py +5 -3
- mindspore/nn/optim/lars.py +2 -2
- mindspore/nn/optim/lazyadam.py +6 -4
- mindspore/nn/optim/momentum.py +13 -25
- mindspore/nn/optim/optimizer.py +6 -3
- mindspore/nn/optim/proximal_ada_grad.py +4 -2
- mindspore/nn/optim/rmsprop.py +9 -3
- mindspore/nn/optim/rprop.py +4 -2
- mindspore/nn/optim/sgd.py +6 -5
- mindspore/nn/optim/thor.py +2 -2
- mindspore/nn/probability/distribution/_utils/custom_ops.py +2 -2
- mindspore/nn/probability/distribution/beta.py +2 -2
- mindspore/nn/probability/distribution/categorical.py +4 -6
- mindspore/nn/probability/distribution/cauchy.py +2 -2
- mindspore/nn/probability/distribution/exponential.py +1 -1
- mindspore/nn/probability/distribution/gumbel.py +2 -2
- mindspore/nn/probability/distribution/poisson.py +2 -2
- mindspore/nn/probability/distribution/uniform.py +2 -2
- mindspore/nn/reinforcement/_tensors_queue.py +13 -1
- mindspore/nn/wrap/__init__.py +2 -1
- mindspore/nn/wrap/cell_wrapper.py +33 -12
- mindspore/nn/wrap/grad_reducer.py +148 -8
- mindspore/nn/wrap/loss_scale.py +7 -7
- mindspore/numpy/__init__.py +2 -0
- mindspore/numpy/array_creations.py +2 -0
- mindspore/numpy/array_ops.py +1 -5
- mindspore/numpy/fft.py +431 -0
- mindspore/numpy/math_ops.py +54 -60
- mindspore/numpy/utils.py +3 -0
- mindspore/ops/__init__.py +5 -4
- mindspore/ops/_grad_experimental/grad_array_ops.py +4 -129
- mindspore/ops/_grad_experimental/grad_comm_ops.py +16 -22
- mindspore/ops/_grad_experimental/grad_math_ops.py +68 -283
- mindspore/ops/_grad_experimental/grad_nn_ops.py +0 -53
- mindspore/ops/_grad_experimental/grad_quant_ops.py +3 -3
- mindspore/ops/_grad_experimental/grad_sparse.py +1 -1
- mindspore/ops/_grad_experimental/grad_sparse_ops.py +3 -3
- mindspore/ops/_op_impl/__init__.py +0 -1
- mindspore/ops/_op_impl/aicpu/gamma.py +2 -0
- mindspore/ops/_op_impl/aicpu/generate_eod_mask.py +1 -1
- mindspore/ops/_op_impl/aicpu/log_uniform_candidate_sampler.py +1 -3
- mindspore/ops/_op_impl/aicpu/poisson.py +2 -0
- mindspore/ops/_op_impl/cpu/__init__.py +1 -3
- mindspore/ops/_op_impl/cpu/adam.py +2 -2
- mindspore/ops/_op_impl/cpu/adam_weight_decay.py +3 -2
- mindspore/ops/_op_impl/cpu/maximum_grad.py +16 -14
- mindspore/ops/_op_impl/cpu/minimum_grad.py +8 -0
- mindspore/ops/_vmap/vmap_array_ops.py +137 -101
- mindspore/ops/_vmap/vmap_base.py +8 -1
- mindspore/ops/_vmap/vmap_grad_math_ops.py +95 -9
- mindspore/ops/_vmap/vmap_grad_nn_ops.py +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 +251 -1440
- mindspore/ops/function/clip_func.py +12 -13
- mindspore/ops/function/debug_func.py +1 -4
- mindspore/ops/function/fft_func.py +31 -0
- mindspore/ops/function/grad/grad_func.py +24 -17
- mindspore/ops/function/image_func.py +27 -21
- mindspore/ops/function/linalg_func.py +35 -68
- mindspore/ops/function/math_func.py +451 -2360
- mindspore/ops/function/nn_func.py +459 -780
- mindspore/ops/function/other_func.py +4 -5
- mindspore/ops/function/parameter_func.py +5 -93
- mindspore/ops/function/random_func.py +24 -80
- mindspore/ops/function/sparse_unary_func.py +9 -16
- mindspore/ops/function/spectral_func.py +1 -1
- mindspore/ops/function/vmap_func.py +14 -14
- mindspore/ops/functional.py +56 -62
- mindspore/ops/op_info_register.py +22 -19
- mindspore/ops/operations/__init__.py +19 -19
- mindspore/ops/operations/_grad_ops.py +20 -723
- mindspore/ops/operations/_inner_ops.py +178 -286
- mindspore/ops/operations/_scalar_ops.py +5 -480
- mindspore/ops/operations/_sequence_ops.py +4 -34
- mindspore/ops/operations/array_ops.py +99 -2491
- mindspore/ops/operations/comm_ops.py +38 -46
- mindspore/ops/operations/custom_ops.py +8 -8
- mindspore/ops/operations/debug_ops.py +100 -31
- mindspore/ops/operations/image_ops.py +1 -217
- mindspore/ops/operations/inner_ops.py +3 -38
- mindspore/ops/operations/linalg_ops.py +1 -49
- mindspore/{rewrite/ast_transformers → ops/operations/manually_defined}/__init__.py +11 -4
- mindspore/ops/operations/manually_defined/_inner.py +61 -0
- mindspore/ops/operations/manually_defined/ops_def.py +1391 -0
- mindspore/ops/operations/math_ops.py +703 -4601
- mindspore/ops/operations/nn_ops.py +374 -1748
- mindspore/ops/operations/other_ops.py +50 -42
- mindspore/ops/operations/random_ops.py +3 -52
- mindspore/ops/primitive.py +196 -96
- 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 +5 -4
- mindspore/parallel/_auto_parallel_context.py +21 -76
- 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 +30 -46
- mindspore/parallel/_ps_context.py +1 -1
- mindspore/parallel/_recovery_context.py +1 -1
- mindspore/parallel/_tensor.py +19 -7
- mindspore/parallel/_transformer/__init__.py +1 -1
- mindspore/parallel/_transformer/layers.py +1 -1
- mindspore/parallel/_transformer/loss.py +1 -1
- mindspore/parallel/_transformer/moe.py +1 -1
- mindspore/parallel/_transformer/op_parallel_config.py +1 -1
- mindspore/parallel/_transformer/transformer.py +1 -1
- mindspore/parallel/_utils.py +131 -6
- mindspore/parallel/algo_parameter_config.py +6 -6
- mindspore/parallel/checkpoint_transform.py +180 -196
- 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 +14 -9
- mindspore/profiler/parser/ascend_communicate_generator.py +0 -1
- mindspore/profiler/parser/ascend_flops_generator.py +20 -4
- mindspore/profiler/parser/ascend_hccl_generator.py +25 -277
- mindspore/profiler/parser/ascend_msprof_exporter.py +112 -132
- mindspore/profiler/parser/ascend_msprof_generator.py +68 -285
- mindspore/profiler/parser/ascend_op_generator.py +75 -42
- mindspore/profiler/parser/ascend_timeline_generator.py +293 -135
- mindspore/profiler/parser/base_timeline_generator.py +6 -0
- mindspore/profiler/parser/framework_parser.py +3 -2
- mindspore/profiler/parser/integrator.py +3 -1
- mindspore/profiler/parser/msadvisor_analyzer.py +1 -1
- mindspore/profiler/parser/msadvisor_parser.py +1 -1
- mindspore/profiler/parser/profiler_info.py +5 -0
- mindspore/profiler/profiling.py +296 -166
- mindspore/rewrite/__init__.py +2 -13
- mindspore/rewrite/api/node.py +121 -35
- mindspore/rewrite/api/pattern_engine.py +2 -3
- mindspore/rewrite/api/scoped_value.py +16 -15
- mindspore/rewrite/api/symbol_tree.py +45 -29
- mindspore/rewrite/ast_helpers/__init__.py +3 -6
- mindspore/rewrite/ast_helpers/ast_converter.py +143 -0
- mindspore/rewrite/ast_helpers/ast_finder.py +48 -0
- mindspore/rewrite/ast_helpers/ast_flattener.py +268 -0
- mindspore/rewrite/ast_helpers/ast_modifier.py +160 -92
- mindspore/rewrite/common/__init__.py +1 -2
- mindspore/rewrite/common/config.py +24 -0
- mindspore/rewrite/common/{rewrite_elog.py → error_log.py} +39 -39
- mindspore/rewrite/{namer.py → common/namer.py} +63 -18
- mindspore/rewrite/common/namespace.py +118 -0
- mindspore/rewrite/node/__init__.py +5 -5
- mindspore/rewrite/node/call_function.py +23 -7
- mindspore/rewrite/node/cell_container.py +7 -3
- mindspore/rewrite/node/control_flow.py +53 -28
- mindspore/rewrite/node/node.py +212 -196
- mindspore/rewrite/node/node_manager.py +51 -22
- mindspore/rewrite/node/node_topological_manager.py +3 -23
- mindspore/rewrite/parsers/__init__.py +12 -0
- mindspore/rewrite/parsers/arguments_parser.py +8 -9
- mindspore/rewrite/parsers/assign_parser.py +635 -413
- mindspore/rewrite/parsers/attribute_parser.py +3 -4
- mindspore/rewrite/parsers/class_def_parser.py +107 -144
- mindspore/rewrite/parsers/constant_parser.py +5 -5
- mindspore/rewrite/parsers/container_parser.py +4 -6
- mindspore/rewrite/parsers/expr_parser.py +55 -0
- mindspore/rewrite/parsers/for_parser.py +31 -98
- mindspore/rewrite/parsers/function_def_parser.py +13 -5
- mindspore/rewrite/parsers/if_parser.py +28 -10
- mindspore/rewrite/parsers/module_parser.py +8 -182
- mindspore/rewrite/parsers/parser.py +1 -5
- mindspore/rewrite/parsers/parser_register.py +1 -1
- mindspore/rewrite/parsers/return_parser.py +5 -10
- mindspore/rewrite/parsers/while_parser.py +59 -0
- mindspore/rewrite/sparsify/utils.py +1 -1
- mindspore/rewrite/symbol_tree/__init__.py +20 -0
- mindspore/rewrite/{symbol_tree.py → symbol_tree/symbol_tree.py} +704 -185
- mindspore/rewrite/{symbol_tree_builder.py → symbol_tree/symbol_tree_builder.py} +8 -8
- mindspore/rewrite/{symbol_tree_dumper.py → symbol_tree/symbol_tree_dumper.py} +4 -4
- mindspore/run_check/_check_version.py +6 -14
- mindspore/run_check/run_check.py +1 -1
- mindspore/safeguard/rewrite_obfuscation.py +9 -19
- mindspore/scipy/__init__.py +2 -1
- mindspore/scipy/fft.py +133 -0
- mindspore/scipy/linalg.py +140 -55
- mindspore/scipy/ops.py +15 -71
- mindspore/scipy/ops_grad.py +5 -34
- mindspore/scipy/optimize/line_search.py +2 -2
- mindspore/scipy/optimize/minimize.py +1 -1
- mindspore/train/__init__.py +3 -2
- mindspore/train/_utils.py +178 -4
- mindspore/train/amp.py +167 -245
- mindspore/train/callback/_backup_and_restore.py +4 -4
- mindspore/train/callback/_callback.py +4 -4
- mindspore/train/callback/_checkpoint.py +39 -13
- mindspore/train/callback/_early_stop.py +2 -2
- mindspore/train/callback/_landscape.py +14 -8
- mindspore/train/callback/_loss_monitor.py +2 -2
- mindspore/train/callback/_on_request_exit.py +2 -2
- mindspore/train/callback/_reduce_lr_on_plateau.py +2 -2
- mindspore/train/callback/_summary_collector.py +7 -7
- mindspore/train/callback/_time_monitor.py +2 -2
- mindspore/train/data_sink.py +1 -1
- mindspore/train/dataset_helper.py +13 -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 +24 -22
- mindspore/train/serialization.py +256 -132
- mindspore/train/summary/summary_record.py +51 -28
- mindspore/train/train_thor/convert_utils.py +3 -3
- mindspore/version.py +1 -1
- {mindspore-2.2.14.dist-info → mindspore-2.3.0rc1.dist-info}/METADATA +2 -2
- {mindspore-2.2.14.dist-info → mindspore-2.3.0rc1.dist-info}/RECORD +515 -1061
- {mindspore-2.2.14.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/nn/layer/flash_attention.py +0 -189
- mindspore/ops/_op_impl/cpu/concat.py +0 -39
- mindspore/ops/_op_impl/cpu/tensor_shape.py +0 -42
- mindspore/ops/_op_impl/tbe/__init__.py +0 -47
- mindspore/ops/_op_impl/tbe/abs.py +0 -38
- mindspore/ops/_op_impl/tbe/abs_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/abs_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/abs_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/accumulate_n_v2.py +0 -41
- mindspore/ops/_op_impl/tbe/accumulate_n_v2_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/acos.py +0 -37
- mindspore/ops/_op_impl/tbe/acos_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/acos_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/acos_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/acosh.py +0 -37
- mindspore/ops/_op_impl/tbe/acosh_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/acosh_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/acosh_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/act_ulq_clamp_max_grad.py +0 -38
- mindspore/ops/_op_impl/tbe/act_ulq_clamp_min_grad.py +0 -38
- mindspore/ops/_op_impl/tbe/acts_ulq.py +0 -45
- mindspore/ops/_op_impl/tbe/acts_ulq_input_grad.py +0 -38
- mindspore/ops/_op_impl/tbe/adam_apply_one.py +0 -50
- mindspore/ops/_op_impl/tbe/adam_apply_one_assign.py +0 -53
- mindspore/ops/_op_impl/tbe/adam_apply_one_ds.py +0 -51
- mindspore/ops/_op_impl/tbe/adam_apply_one_with_decay.py +0 -54
- mindspore/ops/_op_impl/tbe/adam_apply_one_with_decay_assign.py +0 -54
- mindspore/ops/_op_impl/tbe/adam_apply_one_with_decay_ds.py +0 -55
- mindspore/ops/_op_impl/tbe/adaptive_max_pool2d.py +0 -37
- mindspore/ops/_op_impl/tbe/add.py +0 -42
- mindspore/ops/_op_impl/tbe/add_ds.py +0 -43
- mindspore/ops/_op_impl/tbe/add_n.py +0 -39
- mindspore/ops/_op_impl/tbe/add_n_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/addcdiv.py +0 -41
- mindspore/ops/_op_impl/tbe/addcdiv_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/addcmul.py +0 -43
- mindspore/ops/_op_impl/tbe/addcmul_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/apply_ada_max.py +0 -68
- mindspore/ops/_op_impl/tbe/apply_ada_max_ds.py +0 -69
- mindspore/ops/_op_impl/tbe/apply_adadelta.py +0 -66
- mindspore/ops/_op_impl/tbe/apply_adadelta_ds.py +0 -67
- mindspore/ops/_op_impl/tbe/apply_adagrad.py +0 -55
- mindspore/ops/_op_impl/tbe/apply_adagrad_d_a.py +0 -67
- mindspore/ops/_op_impl/tbe/apply_adagrad_ds.py +0 -56
- mindspore/ops/_op_impl/tbe/apply_adagrad_v2.py +0 -48
- mindspore/ops/_op_impl/tbe/apply_adagrad_v2_ds.py +0 -49
- mindspore/ops/_op_impl/tbe/apply_adam.py +0 -79
- mindspore/ops/_op_impl/tbe/apply_adam_ds.py +0 -80
- mindspore/ops/_op_impl/tbe/apply_adam_with_amsgrad.py +0 -60
- mindspore/ops/_op_impl/tbe/apply_adam_with_amsgrad_ds.py +0 -61
- mindspore/ops/_op_impl/tbe/apply_add_sign.py +0 -65
- mindspore/ops/_op_impl/tbe/apply_add_sign_ds.py +0 -66
- mindspore/ops/_op_impl/tbe/apply_centered_rms_prop.py +0 -77
- mindspore/ops/_op_impl/tbe/apply_centered_rms_prop_ds.py +0 -78
- mindspore/ops/_op_impl/tbe/apply_ftrl.py +0 -67
- mindspore/ops/_op_impl/tbe/apply_ftrl_ds.py +0 -68
- mindspore/ops/_op_impl/tbe/apply_gradient_descent.py +0 -44
- mindspore/ops/_op_impl/tbe/apply_gradient_descent_ds.py +0 -45
- mindspore/ops/_op_impl/tbe/apply_keras_momentum.py +0 -49
- mindspore/ops/_op_impl/tbe/apply_momentum.py +0 -64
- mindspore/ops/_op_impl/tbe/apply_momentum_ds.py +0 -65
- mindspore/ops/_op_impl/tbe/apply_power_sign.py +0 -65
- mindspore/ops/_op_impl/tbe/apply_power_sign_ds.py +0 -66
- mindspore/ops/_op_impl/tbe/apply_proximal_adagrad.py +0 -57
- mindspore/ops/_op_impl/tbe/apply_proximal_adagrad_ds.py +0 -58
- mindspore/ops/_op_impl/tbe/apply_proximal_gradient_descent.py +0 -54
- mindspore/ops/_op_impl/tbe/apply_proximal_gradient_descent_ds.py +0 -55
- mindspore/ops/_op_impl/tbe/apply_rms_prop.py +0 -52
- mindspore/ops/_op_impl/tbe/approximate_equal.py +0 -39
- mindspore/ops/_op_impl/tbe/approximate_equal_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/arg_max.py +0 -38
- mindspore/ops/_op_impl/tbe/arg_max_with_value.py +0 -38
- mindspore/ops/_op_impl/tbe/arg_max_with_value_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/arg_min.py +0 -38
- mindspore/ops/_op_impl/tbe/arg_min_v2_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/arg_min_with_value.py +0 -38
- mindspore/ops/_op_impl/tbe/arg_min_with_value_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/asin.py +0 -37
- mindspore/ops/_op_impl/tbe/asin_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/asin_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/asin_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/asinh.py +0 -37
- mindspore/ops/_op_impl/tbe/asinh_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/asinh_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/asinh_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/assign.py +0 -79
- mindspore/ops/_op_impl/tbe/assign_add.py +0 -59
- mindspore/ops/_op_impl/tbe/assign_add_ds.py +0 -60
- mindspore/ops/_op_impl/tbe/assign_ds.py +0 -80
- mindspore/ops/_op_impl/tbe/assign_sub.py +0 -55
- mindspore/ops/_op_impl/tbe/assign_sub_ds.py +0 -56
- mindspore/ops/_op_impl/tbe/atan.py +0 -37
- mindspore/ops/_op_impl/tbe/atan2.py +0 -38
- mindspore/ops/_op_impl/tbe/atan2_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/atan_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/atan_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/atan_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/atanh.py +0 -37
- mindspore/ops/_op_impl/tbe/atanh_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/avg_pool.py +0 -43
- mindspore/ops/_op_impl/tbe/avg_pool_3d.py +0 -44
- mindspore/ops/_op_impl/tbe/avg_pool_3d_grad.py +0 -45
- mindspore/ops/_op_impl/tbe/avg_pool_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/avg_pool_grad.py +0 -42
- mindspore/ops/_op_impl/tbe/avg_pool_grad_vm.py +0 -42
- mindspore/ops/_op_impl/tbe/basic_lstm_cell.py +0 -57
- mindspore/ops/_op_impl/tbe/basic_lstm_cell_c_state_grad.py +0 -50
- mindspore/ops/_op_impl/tbe/basic_lstm_cell_c_state_grad_v2.py +0 -51
- mindspore/ops/_op_impl/tbe/basic_lstm_cell_input_grad.py +0 -42
- mindspore/ops/_op_impl/tbe/basic_lstm_cell_weight_grad.py +0 -41
- mindspore/ops/_op_impl/tbe/batch_matmul.py +0 -42
- mindspore/ops/_op_impl/tbe/batch_matmul_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/batch_matmul_v2.py +0 -47
- mindspore/ops/_op_impl/tbe/batch_to_space.py +0 -38
- mindspore/ops/_op_impl/tbe/batch_to_space_nd.py +0 -38
- mindspore/ops/_op_impl/tbe/batch_to_space_nd_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/batch_to_space_nd_v2.py +0 -41
- mindspore/ops/_op_impl/tbe/batchnorm.py +0 -58
- mindspore/ops/_op_impl/tbe/batchnorm_grad.py +0 -58
- mindspore/ops/_op_impl/tbe/bce_with_logits_loss.py +0 -42
- mindspore/ops/_op_impl/tbe/bessel_i0e.py +0 -37
- mindspore/ops/_op_impl/tbe/bessel_i0e_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/bessel_i1e.py +0 -37
- mindspore/ops/_op_impl/tbe/bessel_i1e_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/bias_add.py +0 -38
- mindspore/ops/_op_impl/tbe/bias_add_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/bias_add_grad.py +0 -53
- mindspore/ops/_op_impl/tbe/binary_cross_entropy.py +0 -39
- mindspore/ops/_op_impl/tbe/binary_cross_entropy_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/binary_cross_entropy_grad.py +0 -44
- mindspore/ops/_op_impl/tbe/binary_cross_entropy_grad_ds.py +0 -45
- mindspore/ops/_op_impl/tbe/bitwise_and.py +0 -39
- mindspore/ops/_op_impl/tbe/bitwise_and_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/bitwise_or.py +0 -39
- mindspore/ops/_op_impl/tbe/bitwise_or_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/bitwise_xor.py +0 -39
- mindspore/ops/_op_impl/tbe/bitwise_xor_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/bn_infer.py +0 -43
- mindspore/ops/_op_impl/tbe/bn_infer_ds.py +0 -45
- mindspore/ops/_op_impl/tbe/bn_infer_grad.py +0 -41
- mindspore/ops/_op_impl/tbe/bn_infer_grad_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/bn_inference.py +0 -50
- mindspore/ops/_op_impl/tbe/bn_training_reduce.py +0 -38
- mindspore/ops/_op_impl/tbe/bn_training_reduce_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/bn_training_reduce_grad.py +0 -46
- mindspore/ops/_op_impl/tbe/bn_training_reduce_grad_ds.py +0 -47
- mindspore/ops/_op_impl/tbe/bn_training_update.py +0 -52
- mindspore/ops/_op_impl/tbe/bn_training_update_ds.py +0 -53
- mindspore/ops/_op_impl/tbe/bn_training_update_grad.py +0 -44
- mindspore/ops/_op_impl/tbe/bn_training_update_grad_ds.py +0 -45
- mindspore/ops/_op_impl/tbe/bn_training_update_v2.py +0 -48
- mindspore/ops/_op_impl/tbe/bn_training_update_v3.py +0 -51
- mindspore/ops/_op_impl/tbe/bounding_box_decode.py +0 -41
- mindspore/ops/_op_impl/tbe/bounding_box_decode_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/bounding_box_encode.py +0 -38
- mindspore/ops/_op_impl/tbe/broadcast_to.py +0 -40
- mindspore/ops/_op_impl/tbe/broadcast_to_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/cast.py +0 -55
- mindspore/ops/_op_impl/tbe/cast_ds.py +0 -58
- mindspore/ops/_op_impl/tbe/cdist.py +0 -38
- mindspore/ops/_op_impl/tbe/cdist_grad.py +0 -42
- mindspore/ops/_op_impl/tbe/ceil.py +0 -37
- mindspore/ops/_op_impl/tbe/ceil_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/celu.py +0 -39
- mindspore/ops/_op_impl/tbe/centralization.py +0 -39
- mindspore/ops/_op_impl/tbe/check_valid.py +0 -38
- mindspore/ops/_op_impl/tbe/check_valid_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/clip_by_norm_no_div_sum.py +0 -41
- mindspore/ops/_op_impl/tbe/clip_by_norm_no_div_sum_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/clip_by_value.py +0 -41
- mindspore/ops/_op_impl/tbe/clip_by_value_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/concat.py +0 -40
- mindspore/ops/_op_impl/tbe/concat_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/confusion_matrix.py +0 -63
- mindspore/ops/_op_impl/tbe/confusion_mul_grad.py +0 -40
- mindspore/ops/_op_impl/tbe/confusion_softmax_grad.py +0 -41
- mindspore/ops/_op_impl/tbe/confusion_transpose_d.py +0 -39
- mindspore/ops/_op_impl/tbe/conv2d.py +0 -47
- mindspore/ops/_op_impl/tbe/conv2d_backprop_filter.py +0 -42
- mindspore/ops/_op_impl/tbe/conv2d_backprop_filter_ds.py +0 -43
- mindspore/ops/_op_impl/tbe/conv2d_backprop_input.py +0 -42
- mindspore/ops/_op_impl/tbe/conv2d_backprop_input_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/conv2d_ds.py +0 -47
- mindspore/ops/_op_impl/tbe/conv2d_transpose.py +0 -48
- mindspore/ops/_op_impl/tbe/conv3d.py +0 -45
- mindspore/ops/_op_impl/tbe/conv3d_backprop_filter.py +0 -42
- mindspore/ops/_op_impl/tbe/conv3d_backprop_input.py +0 -42
- mindspore/ops/_op_impl/tbe/conv3d_transpose.py +0 -47
- mindspore/ops/_op_impl/tbe/conv3d_transpose_ds.py +0 -48
- mindspore/ops/_op_impl/tbe/cos.py +0 -37
- mindspore/ops/_op_impl/tbe/cos_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/cosh.py +0 -37
- mindspore/ops/_op_impl/tbe/cosh_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/ctc_loss_v2.py +0 -42
- mindspore/ops/_op_impl/tbe/ctc_loss_v2_grad.py +0 -44
- mindspore/ops/_op_impl/tbe/cum_sum.py +0 -42
- mindspore/ops/_op_impl/tbe/cum_sum_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/cummin.py +0 -41
- mindspore/ops/_op_impl/tbe/cumprod.py +0 -42
- mindspore/ops/_op_impl/tbe/data_format_dim_map.py +0 -38
- mindspore/ops/_op_impl/tbe/data_format_dim_map_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/deformable_offsets.py +0 -45
- mindspore/ops/_op_impl/tbe/deformable_offsets_grad.py +0 -48
- mindspore/ops/_op_impl/tbe/depth_to_space_ds.py +0 -49
- mindspore/ops/_op_impl/tbe/depthwise_conv2d.py +0 -44
- mindspore/ops/_op_impl/tbe/depthwise_conv2d_backprop_filter.py +0 -41
- mindspore/ops/_op_impl/tbe/depthwise_conv2d_backprop_input.py +0 -41
- mindspore/ops/_op_impl/tbe/diag.py +0 -38
- mindspore/ops/_op_impl/tbe/diag_part.py +0 -38
- mindspore/ops/_op_impl/tbe/dilation.py +0 -40
- mindspore/ops/_op_impl/tbe/div.py +0 -41
- mindspore/ops/_op_impl/tbe/div_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/div_no_nan.py +0 -41
- mindspore/ops/_op_impl/tbe/div_no_nan_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/dropout_do_mask.py +0 -38
- mindspore/ops/_op_impl/tbe/dropout_do_mask_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/dropout_do_mask_v3.py +0 -39
- mindspore/ops/_op_impl/tbe/dynamic_atomic_addr_clean.py +0 -34
- mindspore/ops/_op_impl/tbe/dynamic_gru_v2.py +0 -95
- mindspore/ops/_op_impl/tbe/dynamic_rnn.py +0 -82
- mindspore/ops/_op_impl/tbe/elu.py +0 -38
- mindspore/ops/_op_impl/tbe/elu_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/elu_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/elu_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/equal.py +0 -42
- mindspore/ops/_op_impl/tbe/equal_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/erf.py +0 -37
- mindspore/ops/_op_impl/tbe/erf_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/erfc.py +0 -37
- mindspore/ops/_op_impl/tbe/erfc_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/erfinv.py +0 -36
- mindspore/ops/_op_impl/tbe/exp.py +0 -40
- mindspore/ops/_op_impl/tbe/exp_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/expand_dims.py +0 -38
- mindspore/ops/_op_impl/tbe/expm1.py +0 -37
- mindspore/ops/_op_impl/tbe/expm1_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/extract_image_patches.py +0 -41
- mindspore/ops/_op_impl/tbe/extract_volume_patches.py +0 -39
- mindspore/ops/_op_impl/tbe/fake_quant_with_min_max_vars.py +0 -39
- mindspore/ops/_op_impl/tbe/fake_quant_with_min_max_vars_gradient.py +0 -43
- mindspore/ops/_op_impl/tbe/fake_quant_with_min_max_vars_per_channel.py +0 -39
- mindspore/ops/_op_impl/tbe/fake_quant_with_min_max_vars_per_channel_gradient.py +0 -43
- mindspore/ops/_op_impl/tbe/fast_gelu.py +0 -37
- mindspore/ops/_op_impl/tbe/fast_gelu_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/fast_gelu_grad.py +0 -41
- mindspore/ops/_op_impl/tbe/fast_gelu_grad_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/fill.py +0 -56
- mindspore/ops/_op_impl/tbe/fill_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/flatten.py +0 -48
- mindspore/ops/_op_impl/tbe/floor.py +0 -37
- mindspore/ops/_op_impl/tbe/floor_div.py +0 -41
- mindspore/ops/_op_impl/tbe/floor_div_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/floor_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/floor_mod.py +0 -39
- mindspore/ops/_op_impl/tbe/floor_mod_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/fused_dbn_dw.py +0 -52
- mindspore/ops/_op_impl/tbe/fused_mul_add.py +0 -38
- mindspore/ops/_op_impl/tbe/fused_mul_add_n.py +0 -48
- mindspore/ops/_op_impl/tbe/fused_mul_add_n_l2loss.py +0 -53
- mindspore/ops/_op_impl/tbe/fused_mul_apply_momentum.py +0 -57
- mindspore/ops/_op_impl/tbe/fused_mul_apply_momentum_extern.py +0 -67
- mindspore/ops/_op_impl/tbe/gather_nd.py +0 -52
- mindspore/ops/_op_impl/tbe/gather_nd_ds.py +0 -48
- mindspore/ops/_op_impl/tbe/gather_v2.py +0 -56
- mindspore/ops/_op_impl/tbe/gather_v2_ds.py +0 -68
- mindspore/ops/_op_impl/tbe/gelu.py +0 -37
- mindspore/ops/_op_impl/tbe/gelu_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/gelu_grad.py +0 -42
- mindspore/ops/_op_impl/tbe/gelu_grad_ds.py +0 -43
- mindspore/ops/_op_impl/tbe/ger.py +0 -43
- mindspore/ops/_op_impl/tbe/ger_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/greater.py +0 -43
- mindspore/ops/_op_impl/tbe/greater_equal.py +0 -41
- mindspore/ops/_op_impl/tbe/greater_equal_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/gru_v2_hidden_grad.py +0 -51
- mindspore/ops/_op_impl/tbe/gru_v2_hidden_grad_cell.py +0 -52
- mindspore/ops/_op_impl/tbe/hard_swish.py +0 -37
- mindspore/ops/_op_impl/tbe/hard_swish_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/hard_swish_grad.py +0 -41
- mindspore/ops/_op_impl/tbe/hard_swish_grad_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/histogram_fixed_width.py +0 -40
- mindspore/ops/_op_impl/tbe/hshrink.py +0 -33
- mindspore/ops/_op_impl/tbe/hshrink_grad.py +0 -37
- mindspore/ops/_op_impl/tbe/hsigmoid.py +0 -45
- mindspore/ops/_op_impl/tbe/hsigmoid_grad.py +0 -39
- mindspore/ops/_op_impl/tbe/ifmr.py +0 -47
- mindspore/ops/_op_impl/tbe/ifmr_ds.py +0 -48
- mindspore/ops/_op_impl/tbe/im2col.py +0 -42
- mindspore/ops/_op_impl/tbe/in_top_k.py +0 -37
- mindspore/ops/_op_impl/tbe/inplace_add.py +0 -39
- mindspore/ops/_op_impl/tbe/inplace_index_add.py +0 -46
- mindspore/ops/_op_impl/tbe/inplace_sub.py +0 -39
- mindspore/ops/_op_impl/tbe/inplace_update.py +0 -39
- mindspore/ops/_op_impl/tbe/inplace_update_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/inv.py +0 -38
- mindspore/ops/_op_impl/tbe/inv_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/inv_grad.py +0 -40
- mindspore/ops/_op_impl/tbe/inv_grad_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/invert.py +0 -37
- mindspore/ops/_op_impl/tbe/invert_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/iou.py +0 -38
- mindspore/ops/_op_impl/tbe/iou_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/is_close.py +0 -40
- mindspore/ops/_op_impl/tbe/kl_div_loss.py +0 -38
- mindspore/ops/_op_impl/tbe/kl_div_loss_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/kl_div_loss_grad.py +0 -40
- mindspore/ops/_op_impl/tbe/l2_loss.py +0 -36
- mindspore/ops/_op_impl/tbe/l2_loss_ds.py +0 -37
- mindspore/ops/_op_impl/tbe/l2_normalize.py +0 -38
- mindspore/ops/_op_impl/tbe/l2_normalize_grad.py +0 -40
- mindspore/ops/_op_impl/tbe/lamb_apply_optimizer_assign.py +0 -55
- mindspore/ops/_op_impl/tbe/lamb_apply_weight_assign.py +0 -42
- mindspore/ops/_op_impl/tbe/lamb_next_mv.py +0 -59
- mindspore/ops/_op_impl/tbe/lamb_next_mv_with_decay.py +0 -59
- mindspore/ops/_op_impl/tbe/lamb_next_right.py +0 -44
- mindspore/ops/_op_impl/tbe/lamb_update_with_lr.py +0 -48
- mindspore/ops/_op_impl/tbe/lamb_update_with_lr_v2.py +0 -44
- mindspore/ops/_op_impl/tbe/lars_update.py +0 -50
- mindspore/ops/_op_impl/tbe/lars_update_ds.py +0 -51
- mindspore/ops/_op_impl/tbe/layer_norm.py +0 -46
- mindspore/ops/_op_impl/tbe/layer_norm_beta_gamma_backprop.py +0 -44
- mindspore/ops/_op_impl/tbe/layer_norm_beta_gamma_backprop_ds.py +0 -45
- mindspore/ops/_op_impl/tbe/layer_norm_beta_gamma_backprop_v2.py +0 -40
- mindspore/ops/_op_impl/tbe/layer_norm_beta_gamma_backprop_v2_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/layer_norm_ds.py +0 -47
- mindspore/ops/_op_impl/tbe/layer_norm_grad.py +0 -48
- mindspore/ops/_op_impl/tbe/layer_norm_x_backprop.py +0 -43
- mindspore/ops/_op_impl/tbe/layer_norm_x_backprop_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/layer_norm_x_backprop_v2.py +0 -45
- mindspore/ops/_op_impl/tbe/layer_norm_x_backprop_v2_ds.py +0 -45
- mindspore/ops/_op_impl/tbe/lerp.py +0 -38
- mindspore/ops/_op_impl/tbe/less.py +0 -41
- mindspore/ops/_op_impl/tbe/less_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/less_equal.py +0 -41
- mindspore/ops/_op_impl/tbe/less_equal_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/log.py +0 -40
- mindspore/ops/_op_impl/tbe/log1p.py +0 -37
- mindspore/ops/_op_impl/tbe/log1p_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/log_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/logical_and.py +0 -37
- mindspore/ops/_op_impl/tbe/logical_and_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/logical_not.py +0 -36
- mindspore/ops/_op_impl/tbe/logical_not_ds.py +0 -37
- mindspore/ops/_op_impl/tbe/logical_or.py +0 -37
- mindspore/ops/_op_impl/tbe/logical_or_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/logsoftmax.py +0 -37
- mindspore/ops/_op_impl/tbe/logsoftmax_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/logsoftmax_grad.py +0 -38
- mindspore/ops/_op_impl/tbe/logsoftmax_grad_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/lp_norm.py +0 -40
- mindspore/ops/_op_impl/tbe/lp_norm_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/lrn.py +0 -41
- mindspore/ops/_op_impl/tbe/lrn_grad.py +0 -42
- mindspore/ops/_op_impl/tbe/lstm_input_grad.py +0 -51
- mindspore/ops/_op_impl/tbe/masked_fill.py +0 -40
- mindspore/ops/_op_impl/tbe/masked_fill_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/matmul.py +0 -53
- mindspore/ops/_op_impl/tbe/matmul_ds.py +0 -47
- mindspore/ops/_op_impl/tbe/matmul_v2.py +0 -50
- mindspore/ops/_op_impl/tbe/matrix_diag.py +0 -45
- mindspore/ops/_op_impl/tbe/matrix_diag_part.py +0 -45
- mindspore/ops/_op_impl/tbe/matrix_set_diag.py +0 -46
- mindspore/ops/_op_impl/tbe/max_pool.py +0 -39
- mindspore/ops/_op_impl/tbe/max_pool3d.py +0 -44
- mindspore/ops/_op_impl/tbe/max_pool3d_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/max_pool3d_grad_grad.py +0 -44
- mindspore/ops/_op_impl/tbe/max_pool_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/max_pool_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/max_pool_grad_grad.py +0 -41
- mindspore/ops/_op_impl/tbe/max_pool_grad_grad_with_argmax.py +0 -41
- mindspore/ops/_op_impl/tbe/max_pool_grad_with_argmax.py +0 -42
- mindspore/ops/_op_impl/tbe/max_pool_with_argmax.py +0 -40
- mindspore/ops/_op_impl/tbe/maximum.py +0 -39
- mindspore/ops/_op_impl/tbe/maximum_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/maximum_grad.py +0 -46
- mindspore/ops/_op_impl/tbe/maximum_grad_ds.py +0 -47
- mindspore/ops/_op_impl/tbe/mem_set.py +0 -38
- mindspore/ops/_op_impl/tbe/minimum.py +0 -40
- mindspore/ops/_op_impl/tbe/minimum_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/minimum_grad.py +0 -46
- mindspore/ops/_op_impl/tbe/minimum_grad_ds.py +0 -47
- mindspore/ops/_op_impl/tbe/mish.py +0 -37
- mindspore/ops/_op_impl/tbe/mod.py +0 -41
- mindspore/ops/_op_impl/tbe/mod_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/mul.py +0 -37
- mindspore/ops/_op_impl/tbe/mul_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/mul_no_nan.py +0 -39
- mindspore/ops/_op_impl/tbe/mul_no_nan_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/multilabel_margin_loss.py +0 -39
- mindspore/ops/_op_impl/tbe/neg.py +0 -39
- mindspore/ops/_op_impl/tbe/neg_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/new_im2col.py +0 -40
- mindspore/ops/_op_impl/tbe/nll_loss.py +0 -41
- mindspore/ops/_op_impl/tbe/nll_loss_grad.py +0 -44
- mindspore/ops/_op_impl/tbe/nms_with_mask.py +0 -39
- mindspore/ops/_op_impl/tbe/not_equal.py +0 -41
- mindspore/ops/_op_impl/tbe/not_equal_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/npu_alloc_float_status.py +0 -34
- mindspore/ops/_op_impl/tbe/npu_clear_float_status.py +0 -35
- mindspore/ops/_op_impl/tbe/npu_clear_float_status_v2.py +0 -35
- mindspore/ops/_op_impl/tbe/npu_get_float_status.py +0 -35
- mindspore/ops/_op_impl/tbe/npu_get_float_status_v2.py +0 -35
- mindspore/ops/_op_impl/tbe/one_hot.py +0 -48
- mindspore/ops/_op_impl/tbe/one_hot_ds.py +0 -45
- mindspore/ops/_op_impl/tbe/ones_like.py +0 -40
- mindspore/ops/_op_impl/tbe/ones_like_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/p_s_r_o_i_pooling.py +0 -40
- mindspore/ops/_op_impl/tbe/p_s_r_o_i_pooling_grad.py +0 -40
- mindspore/ops/_op_impl/tbe/pack.py +0 -58
- mindspore/ops/_op_impl/tbe/pack_ds.py +0 -59
- mindspore/ops/_op_impl/tbe/pad_d.py +0 -40
- mindspore/ops/_op_impl/tbe/pad_d_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/parallel_concat.py +0 -70
- mindspore/ops/_op_impl/tbe/parallel_resize_bilinear.py +0 -45
- mindspore/ops/_op_impl/tbe/parallel_resize_bilinear_grad.py +0 -44
- mindspore/ops/_op_impl/tbe/pdist.py +0 -36
- mindspore/ops/_op_impl/tbe/pooling.py +0 -46
- mindspore/ops/_op_impl/tbe/population_count.py +0 -38
- mindspore/ops/_op_impl/tbe/pow.py +0 -41
- mindspore/ops/_op_impl/tbe/pow_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/prelu.py +0 -37
- mindspore/ops/_op_impl/tbe/prelu_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/prelu_grad.py +0 -40
- mindspore/ops/_op_impl/tbe/range.py +0 -39
- mindspore/ops/_op_impl/tbe/real_div.py +0 -38
- mindspore/ops/_op_impl/tbe/real_div_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/reciprocal.py +0 -36
- mindspore/ops/_op_impl/tbe/reciprocal_ds.py +0 -37
- mindspore/ops/_op_impl/tbe/reciprocal_grad.py +0 -38
- mindspore/ops/_op_impl/tbe/reciprocal_grad_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/reduce_all.py +0 -38
- mindspore/ops/_op_impl/tbe/reduce_all_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/reduce_any.py +0 -38
- mindspore/ops/_op_impl/tbe/reduce_any_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/reduce_max.py +0 -43
- mindspore/ops/_op_impl/tbe/reduce_max_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/reduce_mean.py +0 -40
- mindspore/ops/_op_impl/tbe/reduce_mean_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/reduce_min.py +0 -41
- mindspore/ops/_op_impl/tbe/reduce_min_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/reduce_prod.py +0 -42
- mindspore/ops/_op_impl/tbe/reduce_prod_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/reduce_std.py +0 -44
- mindspore/ops/_op_impl/tbe/reduce_sum.py +0 -39
- mindspore/ops/_op_impl/tbe/reduce_sum_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/relu.py +0 -39
- mindspore/ops/_op_impl/tbe/relu6.py +0 -38
- mindspore/ops/_op_impl/tbe/relu6_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/relu6_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/relu6_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/relu_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/relu_grad.py +0 -41
- mindspore/ops/_op_impl/tbe/relu_grad_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/relu_grad_v2.py +0 -40
- mindspore/ops/_op_impl/tbe/relu_grad_v2_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/relu_v2.py +0 -40
- mindspore/ops/_op_impl/tbe/relu_v2_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/renorm.py +0 -39
- mindspore/ops/_op_impl/tbe/resize_bilinear.py +0 -40
- mindspore/ops/_op_impl/tbe/resize_bilinear_grad.py +0 -41
- mindspore/ops/_op_impl/tbe/resize_bilinear_v2.py +0 -43
- mindspore/ops/_op_impl/tbe/resize_nearest_neighbor.py +0 -40
- mindspore/ops/_op_impl/tbe/resize_nearest_neighbor_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/resize_nearest_neighbor_grad.py +0 -39
- mindspore/ops/_op_impl/tbe/resize_nearest_neighbor_grad_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/reverse_v2_d.py +0 -37
- mindspore/ops/_op_impl/tbe/rint.py +0 -37
- mindspore/ops/_op_impl/tbe/rint_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/roi_align.py +0 -43
- mindspore/ops/_op_impl/tbe/roi_align_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/roi_align_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/roi_align_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/roll.py +0 -42
- mindspore/ops/_op_impl/tbe/round.py +0 -38
- mindspore/ops/_op_impl/tbe/round_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/rsqrt.py +0 -37
- mindspore/ops/_op_impl/tbe/rsqrt_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/rsqrt_grad.py +0 -40
- mindspore/ops/_op_impl/tbe/rsqrt_grad_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/scatter_add.py +0 -44
- mindspore/ops/_op_impl/tbe/scatter_div.py +0 -46
- mindspore/ops/_op_impl/tbe/scatter_max.py +0 -45
- mindspore/ops/_op_impl/tbe/scatter_min.py +0 -45
- mindspore/ops/_op_impl/tbe/scatter_mul.py +0 -44
- mindspore/ops/_op_impl/tbe/scatter_nd.py +0 -41
- mindspore/ops/_op_impl/tbe/scatter_nd_add.py +0 -45
- mindspore/ops/_op_impl/tbe/scatter_nd_d.py +0 -41
- mindspore/ops/_op_impl/tbe/scatter_nd_ds.py +0 -49
- mindspore/ops/_op_impl/tbe/scatter_nd_sub.py +0 -47
- mindspore/ops/_op_impl/tbe/scatter_nd_sub_ds.py +0 -48
- mindspore/ops/_op_impl/tbe/scatter_nd_update.py +0 -47
- mindspore/ops/_op_impl/tbe/scatter_nd_update_ds.py +0 -48
- mindspore/ops/_op_impl/tbe/scatter_non_aliasing_add.py +0 -39
- mindspore/ops/_op_impl/tbe/scatter_non_aliasing_add_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/scatter_sub.py +0 -47
- mindspore/ops/_op_impl/tbe/scatter_sub_ds.py +0 -48
- mindspore/ops/_op_impl/tbe/scatter_update.py +0 -43
- mindspore/ops/_op_impl/tbe/select.py +0 -38
- mindspore/ops/_op_impl/tbe/select_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/selu.py +0 -39
- mindspore/ops/_op_impl/tbe/selu_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/sgd.py +0 -62
- mindspore/ops/_op_impl/tbe/sigmoid.py +0 -37
- mindspore/ops/_op_impl/tbe/sigmoid_cross_entropy_with_logits.py +0 -41
- mindspore/ops/_op_impl/tbe/sigmoid_cross_entropy_with_logits_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/sigmoid_cross_entropy_with_logits_grad.py +0 -42
- mindspore/ops/_op_impl/tbe/sigmoid_cross_entropy_with_logits_grad_ds.py +0 -43
- mindspore/ops/_op_impl/tbe/sigmoid_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/sigmoid_grad.py +0 -39
- mindspore/ops/_op_impl/tbe/sigmoid_grad_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/sign.py +0 -38
- mindspore/ops/_op_impl/tbe/sign_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/sin.py +0 -37
- mindspore/ops/_op_impl/tbe/sin_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/sinh.py +0 -37
- mindspore/ops/_op_impl/tbe/sinh_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/slice.py +0 -58
- mindspore/ops/_op_impl/tbe/smooth_l1_loss.py +0 -45
- mindspore/ops/_op_impl/tbe/smooth_l1_loss_ds.py +0 -46
- mindspore/ops/_op_impl/tbe/smooth_l1_loss_grad.py +0 -46
- mindspore/ops/_op_impl/tbe/smooth_l1_loss_grad_ds.py +0 -47
- mindspore/ops/_op_impl/tbe/soft_margin_loss.py +0 -38
- mindspore/ops/_op_impl/tbe/soft_margin_loss_grad.py +0 -39
- mindspore/ops/_op_impl/tbe/soft_shrink.py +0 -36
- mindspore/ops/_op_impl/tbe/soft_shrink_grad.py +0 -38
- mindspore/ops/_op_impl/tbe/softmax.py +0 -37
- mindspore/ops/_op_impl/tbe/softmax_cross_entropy_with_logits.py +0 -38
- mindspore/ops/_op_impl/tbe/softmax_cross_entropy_with_logits_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/softmax_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/softmax_grad_ext.py +0 -42
- mindspore/ops/_op_impl/tbe/softmax_v2_with_dropout_do_mask_v3.py +0 -39
- mindspore/ops/_op_impl/tbe/softplus.py +0 -37
- mindspore/ops/_op_impl/tbe/softplus_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/softplus_grad.py +0 -38
- mindspore/ops/_op_impl/tbe/softplus_grad_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/softsign.py +0 -37
- mindspore/ops/_op_impl/tbe/softsign_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/sort.py +0 -38
- mindspore/ops/_op_impl/tbe/sort_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/space_to_batch.py +0 -38
- mindspore/ops/_op_impl/tbe/space_to_batch_nd.py +0 -38
- mindspore/ops/_op_impl/tbe/space_to_depth.py +0 -47
- mindspore/ops/_op_impl/tbe/sparse_apply_adadelta.py +0 -56
- mindspore/ops/_op_impl/tbe/sparse_apply_adagrad.py +0 -45
- mindspore/ops/_op_impl/tbe/sparse_apply_adagrad_ds.py +0 -46
- mindspore/ops/_op_impl/tbe/sparse_apply_adagrad_v2.py +0 -46
- mindspore/ops/_op_impl/tbe/sparse_apply_adagrad_v2_ds.py +0 -47
- mindspore/ops/_op_impl/tbe/sparse_apply_ftrl_d.py +0 -53
- mindspore/ops/_op_impl/tbe/sparse_apply_ftrl_d_ds.py +0 -50
- mindspore/ops/_op_impl/tbe/sparse_apply_ftrl_v2.py +0 -50
- mindspore/ops/_op_impl/tbe/sparse_apply_proximal_adagrad.py +0 -66
- mindspore/ops/_op_impl/tbe/sparse_apply_proximal_adagrad_ds.py +0 -67
- mindspore/ops/_op_impl/tbe/sparse_apply_r_m_s_prop.py +0 -57
- mindspore/ops/_op_impl/tbe/sparse_apply_r_m_s_prop_ds.py +0 -58
- mindspore/ops/_op_impl/tbe/sparse_gather_v2.py +0 -56
- mindspore/ops/_op_impl/tbe/sparse_gather_v2_ds.py +0 -58
- mindspore/ops/_op_impl/tbe/split_d.py +0 -38
- mindspore/ops/_op_impl/tbe/split_d_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/split_v.py +0 -39
- mindspore/ops/_op_impl/tbe/splitv.py +0 -39
- mindspore/ops/_op_impl/tbe/sqrt.py +0 -37
- mindspore/ops/_op_impl/tbe/sqrt_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/sqrt_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/sqrt_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/square.py +0 -38
- mindspore/ops/_op_impl/tbe/square_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/square_sum_all.py +0 -40
- mindspore/ops/_op_impl/tbe/square_sum_all_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/square_sum_v1.py +0 -38
- mindspore/ops/_op_impl/tbe/square_sum_v1_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/square_sum_v2.py +0 -39
- mindspore/ops/_op_impl/tbe/squared_difference.py +0 -39
- mindspore/ops/_op_impl/tbe/squared_difference_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/squeeze.py +0 -37
- mindspore/ops/_op_impl/tbe/strided_read.py +0 -38
- mindspore/ops/_op_impl/tbe/strided_slice_d.py +0 -44
- mindspore/ops/_op_impl/tbe/strided_slice_ds.py +0 -71
- mindspore/ops/_op_impl/tbe/strided_slice_grad_d.py +0 -51
- mindspore/ops/_op_impl/tbe/strided_slice_grad_ds.py +0 -57
- mindspore/ops/_op_impl/tbe/strided_write.py +0 -38
- mindspore/ops/_op_impl/tbe/sub.py +0 -39
- mindspore/ops/_op_impl/tbe/sub_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/tan.py +0 -38
- mindspore/ops/_op_impl/tbe/tan_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/tanh.py +0 -37
- mindspore/ops/_op_impl/tbe/tanh_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/tanh_grad.py +0 -39
- mindspore/ops/_op_impl/tbe/tanh_grad_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/tensor_move.py +0 -49
- mindspore/ops/_op_impl/tbe/tensor_move_ds.py +0 -50
- mindspore/ops/_op_impl/tbe/tensor_scatter_update.py +0 -41
- mindspore/ops/_op_impl/tbe/tile.py +0 -37
- mindspore/ops/_op_impl/tbe/tile_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/top_k.py +0 -42
- mindspore/ops/_op_impl/tbe/top_k_ds.py +0 -43
- mindspore/ops/_op_impl/tbe/trans_data.py +0 -167
- mindspore/ops/_op_impl/tbe/trans_data_ds.py +0 -180
- mindspore/ops/_op_impl/tbe/trans_data_rnn.py +0 -44
- mindspore/ops/_op_impl/tbe/transpose.py +0 -60
- mindspore/ops/_op_impl/tbe/transpose_d.py +0 -47
- mindspore/ops/_op_impl/tbe/transpose_nod.py +0 -60
- mindspore/ops/_op_impl/tbe/trunc.py +0 -39
- mindspore/ops/_op_impl/tbe/truncate_div.py +0 -41
- mindspore/ops/_op_impl/tbe/truncate_div_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/truncate_mod.py +0 -41
- mindspore/ops/_op_impl/tbe/truncate_mod_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/unpack.py +0 -38
- mindspore/ops/_op_impl/tbe/unpack_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/unsorted_segment_max.py +0 -49
- mindspore/ops/_op_impl/tbe/unsorted_segment_max_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/unsorted_segment_min.py +0 -49
- mindspore/ops/_op_impl/tbe/unsorted_segment_min_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/unsorted_segment_prod.py +0 -49
- mindspore/ops/_op_impl/tbe/unsorted_segment_prod_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/unsorted_segment_sum.py +0 -38
- mindspore/ops/_op_impl/tbe/unsorted_segment_sum_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/wts_arq.py +0 -40
- mindspore/ops/_op_impl/tbe/xdivy.py +0 -38
- mindspore/ops/_op_impl/tbe/xdivy_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/xlogy.py +0 -38
- mindspore/ops/_op_impl/tbe/xlogy_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/zeros_like.py +0 -41
- mindspore/ops/_op_impl/tbe/zeros_like_ds.py +0 -42
- mindspore/ops/_tracefunc.py +0 -241
- mindspore/ops/arg_dtype_cast.py +0 -54
- mindspore/rewrite/api/tree_node_helper.py +0 -60
- mindspore/rewrite/ast_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.14.dist-info → mindspore-2.3.0rc1.dist-info}/WHEEL +0 -0
- {mindspore-2.2.14.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
|
|
2178
|
+
|
|
2179
|
+
ori_i = new_length > 1 ? (new_i + 0.5) * ori_length / new_length - 0.5 : 0 # 'align_corners' = False
|
|
2248
2180
|
|
|
2249
|
-
|
|
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.
|
|
2250
2186
|
|
|
2251
|
-
This is only valid for 'linear'
|
|
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,10 +2682,10 @@ 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``
|
|
@@ -2814,45 +2757,11 @@ def softplus(input, beta=1, threshold=20): # pylint:disable=redefined-outer-name
|
|
|
2814
2757
|
>>> print(output)
|
|
2815
2758
|
[0.7443967 0.79813886 30. 25.]
|
|
2816
2759
|
"""
|
|
2817
|
-
softplus_op = _get_cache_prim(P.Softplus)()
|
|
2818
2760
|
scaling_input = beta * input
|
|
2819
|
-
op_output = (1 / beta) *
|
|
2761
|
+
op_output = (1 / beta) * softplus_(scaling_input)
|
|
2820
2762
|
return ops.select(input * beta > threshold, input, op_output)
|
|
2821
2763
|
|
|
2822
2764
|
|
|
2823
|
-
def silu(x):
|
|
2824
|
-
r"""
|
|
2825
|
-
Computes Sigmoid Linear Unit of input element-wise. The SiLU function is defined as:
|
|
2826
|
-
|
|
2827
|
-
.. math::
|
|
2828
|
-
\text{SiLU}(x) = x * \sigma(x),
|
|
2829
|
-
|
|
2830
|
-
where the Logistic Sigmoid function is defined as:
|
|
2831
|
-
|
|
2832
|
-
.. math::
|
|
2833
|
-
|
|
2834
|
-
\text{sigma}(x_i) = \frac{1}{1 + \exp(-x_i)},
|
|
2835
|
-
|
|
2836
|
-
where :math:`x_i` is an element of the x.
|
|
2837
|
-
|
|
2838
|
-
For more details, please refer to :class:`mindspore.nn.SiLU`.
|
|
2839
|
-
|
|
2840
|
-
Supported Platforms:
|
|
2841
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
2842
|
-
|
|
2843
|
-
Examples:
|
|
2844
|
-
>>> import numpy as np
|
|
2845
|
-
>>> import mindspore
|
|
2846
|
-
>>> from mindspore import Tensor, ops
|
|
2847
|
-
>>> x = Tensor(np.array([-1, 2, -3, 2, -1]), mindspore.float16)
|
|
2848
|
-
>>> output = ops.silu(x)
|
|
2849
|
-
>>> print(output)
|
|
2850
|
-
[-0.269 1.762 -0.1423 1.762 -0.269]
|
|
2851
|
-
"""
|
|
2852
|
-
silu_ = _get_cache_prim(SiLU)()
|
|
2853
|
-
return silu_(x)
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
2765
|
def selu(input_x):
|
|
2857
2766
|
r"""
|
|
2858
2767
|
Activation function SeLU (Scaled exponential Linear Unit).
|
|
@@ -2872,14 +2781,20 @@ def selu(input_x):
|
|
|
2872
2781
|
|
|
2873
2782
|
See more details in `Self-Normalizing Neural Networks <https://arxiv.org/abs/1706.02515>`_.
|
|
2874
2783
|
|
|
2784
|
+
SeLU Activation Function Graph:
|
|
2785
|
+
|
|
2786
|
+
.. image:: ../images/SeLU.png
|
|
2787
|
+
:align: center
|
|
2788
|
+
|
|
2875
2789
|
Args:
|
|
2876
|
-
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).
|
|
2877
2792
|
|
|
2878
2793
|
Returns:
|
|
2879
2794
|
Tensor, with the same type and shape as the `input_x`.
|
|
2880
2795
|
|
|
2881
2796
|
Raises:
|
|
2882
|
-
TypeError: If dtype of `input_x` is
|
|
2797
|
+
TypeError: If dtype of `input_x` is not int8, int32, float16, float32, or float64.
|
|
2883
2798
|
|
|
2884
2799
|
Supported Platforms:
|
|
2885
2800
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -2897,41 +2812,6 @@ def selu(input_x):
|
|
|
2897
2812
|
return selu_(input_x)
|
|
2898
2813
|
|
|
2899
2814
|
|
|
2900
|
-
def sigmoid(input):
|
|
2901
|
-
r"""
|
|
2902
|
-
Computes Sigmoid of input element-wise. The Sigmoid function is defined as:
|
|
2903
|
-
|
|
2904
|
-
.. math::
|
|
2905
|
-
|
|
2906
|
-
\text{sigmoid}(input_i) = \frac{1}{1 + \exp(-input_i)}
|
|
2907
|
-
|
|
2908
|
-
where :math:`input_i` is an element of the input.
|
|
2909
|
-
|
|
2910
|
-
Args:
|
|
2911
|
-
input (Tensor): Tensor of any dimension, the data type is float16, float32, float64, complex64 or complex128.
|
|
2912
|
-
|
|
2913
|
-
Returns:
|
|
2914
|
-
Tensor, with the same type and shape as the input.
|
|
2915
|
-
|
|
2916
|
-
Raises:
|
|
2917
|
-
TypeError: If dtype of `input` is not float16, float32, float64, complex64 or complex128.
|
|
2918
|
-
TypeError: If `input` is not a Tensor.
|
|
2919
|
-
|
|
2920
|
-
Supported Platforms:
|
|
2921
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
2922
|
-
|
|
2923
|
-
Examples:
|
|
2924
|
-
>>> import mindspore
|
|
2925
|
-
>>> import numpy as np
|
|
2926
|
-
>>> from mindspore import Tensor, ops
|
|
2927
|
-
>>> input = Tensor(np.array([1, 2, 3, 4, 5]), mindspore.float32)
|
|
2928
|
-
>>> output = ops.sigmoid(input)
|
|
2929
|
-
>>> print(output)
|
|
2930
|
-
[0.7310586 0.880797 0.95257413 0.98201376 0.9933072 ]
|
|
2931
|
-
"""
|
|
2932
|
-
return _get_cache_prim(NN_OPS.Sigmoid)()(input)
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
2815
|
def logsigmoid(x):
|
|
2936
2816
|
r"""
|
|
2937
2817
|
Applies logsigmoid activation element-wise. The input is a Tensor with any valid shape.
|
|
@@ -2943,6 +2823,11 @@ def logsigmoid(x):
|
|
|
2943
2823
|
|
|
2944
2824
|
where :math:`x_{i}` is the element of the input.
|
|
2945
2825
|
|
|
2826
|
+
LogSigmoid Activation Function Graph:
|
|
2827
|
+
|
|
2828
|
+
.. image:: ../images/LogSigmoid.png
|
|
2829
|
+
:align: center
|
|
2830
|
+
|
|
2946
2831
|
Args:
|
|
2947
2832
|
x (Tensor): The input of LogSigmoid with data type of float16 or float32.
|
|
2948
2833
|
The shape is :math:`(N,*)` where :math:`*` means, any number of additional dimensions.
|
|
@@ -2965,8 +2850,8 @@ def logsigmoid(x):
|
|
|
2965
2850
|
>>> print(output)
|
|
2966
2851
|
[-0.31326166 -0.12692806 -0.04858734]
|
|
2967
2852
|
"""
|
|
2968
|
-
output =
|
|
2969
|
-
ret =
|
|
2853
|
+
output = sigmoid_(x)
|
|
2854
|
+
ret = log_(output)
|
|
2970
2855
|
return ret
|
|
2971
2856
|
|
|
2972
2857
|
|
|
@@ -3113,13 +2998,11 @@ def bidense(input1, input2, weight, bias=None):
|
|
|
3113
2998
|
input1 = input1.reshape((-1, input1_shape[-1]))
|
|
3114
2999
|
input2 = input2.reshape((-1, input2_shape[-1]))
|
|
3115
3000
|
batch_size = input1.shape[0]
|
|
3116
|
-
matmul_ = P.MatMul()
|
|
3117
3001
|
output = matmul_(input1, weight.transpose(1, 2, 0).view(input1_shape[-1], -1))
|
|
3118
3002
|
output = output.view(batch_size, input2_shape[-1], weight.shape[0])
|
|
3119
3003
|
output = output.transpose(2, 0, 1) * input2
|
|
3120
3004
|
output = output.sum(2).swapaxes(0, 1)
|
|
3121
3005
|
if bias is not None:
|
|
3122
|
-
bias_add_ = P.BiasAdd()
|
|
3123
3006
|
output = bias_add_(output, bias)
|
|
3124
3007
|
if len(input1_shape) != 2:
|
|
3125
3008
|
output_shape = input1_shape[:-1] + (-1,)
|
|
@@ -3189,7 +3072,7 @@ def deformable_conv2d(x, weight, offsets, kernel_size, strides, padding, bias=No
|
|
|
3189
3072
|
TypeError: If `strides`, `padding`, `kernel_size` or `dilations` is not a tuple with integer elements.
|
|
3190
3073
|
TypeError: If `modulated` is not a bool.
|
|
3191
3074
|
ValueError: If the tuple size of `strides`, `padding`, `kernel_size` or `dilations` is not expected.
|
|
3192
|
-
ValueError: The N or C dimensions of
|
|
3075
|
+
ValueError: The N or C dimensions of `strides` or `dilations` is not set to 1.
|
|
3193
3076
|
ValueError: If `modulated` is not set to True.
|
|
3194
3077
|
|
|
3195
3078
|
.. warning::
|
|
@@ -3214,13 +3097,10 @@ def deformable_conv2d(x, weight, offsets, kernel_size, strides, padding, bias=No
|
|
|
3214
3097
|
deformable_groups,
|
|
3215
3098
|
modulated)
|
|
3216
3099
|
fm_offset = deformable_offsets(x, offsets)
|
|
3217
|
-
|
|
3218
3100
|
weight_shape = weight.shape
|
|
3219
3101
|
out_channel = weight_shape[0]
|
|
3220
3102
|
strides_conv = (kernel_size[0], kernel_size[1])
|
|
3221
3103
|
conv = _get_cache_prim(P.Conv2D)(out_channel, kernel_size, 1, "valid", 0, strides_conv, 1, groups)
|
|
3222
|
-
bias_add_ = _get_cache_prim(P.BiasAdd)()
|
|
3223
|
-
|
|
3224
3104
|
output = conv(fm_offset, weight)
|
|
3225
3105
|
if bias is not None:
|
|
3226
3106
|
output = bias_add_(output, bias)
|
|
@@ -3231,9 +3111,7 @@ def pdist(input, p=2.0):
|
|
|
3231
3111
|
r"""
|
|
3232
3112
|
Calculates the distance between every pair of row vectors in
|
|
3233
3113
|
the input using the p-norm. If the input `input` is a 2D Tensor with shape :math:`(N, M)`,
|
|
3234
|
-
the `output` must be a 1D Tensor with shape :math:`(N * (N - 1) / 2,)`.
|
|
3235
|
-
dimension with shape :math:`(*B, N, M)`, then the `output` must be a Tensor with
|
|
3236
|
-
shape :math:`(*B, N * (N - 1) / 2)`.
|
|
3114
|
+
the `output` must be a 1D Tensor with shape :math:`(N * (N - 1) / 2,)`.
|
|
3237
3115
|
|
|
3238
3116
|
.. math::
|
|
3239
3117
|
y[n] = \sqrt[p]{{\mid x_{i} - x_{j} \mid}^p}
|
|
@@ -3241,8 +3119,7 @@ def pdist(input, p=2.0):
|
|
|
3241
3119
|
where :math:`x_{i}, x_{j}` are two different row vectors in the input.
|
|
3242
3120
|
|
|
3243
3121
|
Args:
|
|
3244
|
-
input (Tensor): Input tensor
|
|
3245
|
-
dtype: float16, float32 or float64.
|
|
3122
|
+
input (Tensor): Input tensor. dtype: float16, float32 or float64.
|
|
3246
3123
|
p (float): The order of norm distance, :math:`p∈[0, ∞)`. Default: ``2.0`` .
|
|
3247
3124
|
|
|
3248
3125
|
Returns:
|
|
@@ -3288,8 +3165,10 @@ def pad(input_x, padding, mode='constant', value=None):
|
|
|
3288
3165
|
Pads the input tensor according to the padding.
|
|
3289
3166
|
|
|
3290
3167
|
Args:
|
|
3291
|
-
input_x (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of additional dimensions
|
|
3292
|
-
|
|
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.
|
|
3293
3172
|
:math:`\left\lfloor\frac{\text{len(padding)}}{2}\right\rfloor` dimensions
|
|
3294
3173
|
of `input_x` will be padded.
|
|
3295
3174
|
|
|
@@ -3298,49 +3177,49 @@ def pad(input_x, padding, mode='constant', value=None):
|
|
|
3298
3177
|
:math:`(\text{padding_left}, \text{padding_right})`;
|
|
3299
3178
|
|
|
3300
3179
|
Example: to pad the last 2 dimensions of the input tensor, then use
|
|
3301
|
-
:math:`(\text{padding_left}, \text{padding_right}
|
|
3302
|
-
:math:`\text{padding_top}, \text{padding_bottom})`;
|
|
3180
|
+
:math:`(\text{padding_left}, \text{padding_right}, \text{padding_top}, \text{padding_bottom})`;
|
|
3303
3181
|
|
|
3304
3182
|
Example: to pad the last 3 dimensions, use
|
|
3305
|
-
:math:`(\text{padding_left}, \text{padding_right}
|
|
3306
|
-
|
|
3307
|
-
:math:`\text{padding_front}, \text{padding_back})` and so on.
|
|
3183
|
+
:math:`(\text{padding_left}, \text{padding_right}, \text{padding_top}, \text{padding_bottom},
|
|
3184
|
+
\text{padding_front}, \text{padding_back})` and so on.
|
|
3308
3185
|
|
|
3309
|
-
mode (str, optional): Pad filling mode, ``
|
|
3186
|
+
mode (str, optional): Pad filling mode, ``'constant'`` , ``'reflect'`` , ``'replicate'`` or ``'circular'`` .
|
|
3310
3187
|
Default: ``'constant'`` .
|
|
3311
3188
|
|
|
3312
|
-
For
|
|
3189
|
+
For ``'constant'`` mode, please refer to :class:`mindspore.nn.ConstantPad1d` as an example to understand
|
|
3313
3190
|
this filling pattern and extend the padding pattern to n dimensions.
|
|
3314
3191
|
|
|
3315
|
-
For
|
|
3192
|
+
For ``'reflect'`` mode, please refer to :class:`mindspore.nn.ReflectionPad1d` as an example to understand
|
|
3316
3193
|
this filling pattern.
|
|
3317
3194
|
The reflect mode is used to pad the last two dimensions of 3D or 4D input, or the last dimension of 2D or
|
|
3318
3195
|
3D input.
|
|
3319
3196
|
|
|
3320
|
-
For
|
|
3197
|
+
For ``'replicate'`` mode, please refer to :class:`mindspore.nn.ReplicationPad1d` as an example to understand
|
|
3321
3198
|
this filling pattern.
|
|
3322
3199
|
The replicate mode is used to pad the last three dimensions of 4D or 5D input, the last two dimensions of 3D
|
|
3323
3200
|
or 4D input, or the last dimension of 2D or 3D input.
|
|
3324
3201
|
|
|
3325
|
-
For
|
|
3202
|
+
For ``'circular'`` mode, the pixels from one edge of the image are wrapped around to the opposite edge,
|
|
3326
3203
|
such that the pixel on the right edge of the image is replaced with the pixel on the left edge,
|
|
3327
3204
|
and the pixel on the bottom edge is replaced with the pixel on the top edge.
|
|
3328
3205
|
The circular mode is used to pad the last three dimensions of 4D or 5D input, the last two dimensions of 3D
|
|
3329
3206
|
or 4D input, or the last dimension of 2D or 3D input.
|
|
3330
3207
|
|
|
3331
|
-
value (Union[int, float, None], optional): Valid only in
|
|
3332
|
-
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.
|
|
3333
3210
|
Default: ``None`` .
|
|
3334
3211
|
|
|
3335
3212
|
Returns:
|
|
3336
3213
|
Tensor, the tensor after padding.
|
|
3337
3214
|
|
|
3338
3215
|
Raises:
|
|
3339
|
-
TypeError: If `
|
|
3216
|
+
TypeError: If `padding` is not an int of tuple or int of list.
|
|
3340
3217
|
TypeError: If `input_x` is not a Tensor.
|
|
3341
3218
|
ValueError: If length of `padding` is not even.
|
|
3342
3219
|
ValueError: If length of `padding` is greater than 6.
|
|
3343
|
-
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.
|
|
3344
3223
|
|
|
3345
3224
|
Supported Platforms:
|
|
3346
3225
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -3397,7 +3276,7 @@ def pad(input_x, padding, mode='constant', value=None):
|
|
|
3397
3276
|
return input_x
|
|
3398
3277
|
if not isinstance(padding, Tensor):
|
|
3399
3278
|
_check_pad_inputs(padding)
|
|
3400
|
-
padding =
|
|
3279
|
+
padding = tuple(padding)
|
|
3401
3280
|
is_expand = False
|
|
3402
3281
|
if mode == "constant":
|
|
3403
3282
|
value = 0 if value is None else value
|
|
@@ -3410,7 +3289,7 @@ def pad(input_x, padding, mode='constant', value=None):
|
|
|
3410
3289
|
raise ValueError(f"For 'pad', the padding mode '{mode}' can not set value, but got value {value}.")
|
|
3411
3290
|
if mode == "replicate":
|
|
3412
3291
|
mode = "edge"
|
|
3413
|
-
if padding
|
|
3292
|
+
if len(padding) // 2 + 1 == input_x.ndim:
|
|
3414
3293
|
input_x = input_x.expand_dims(0)
|
|
3415
3294
|
is_expand = True
|
|
3416
3295
|
out = PadV3(mode=mode, paddings_contiguous=True)(input_x, padding, value)
|
|
@@ -3419,142 +3298,6 @@ def pad(input_x, padding, mode='constant', value=None):
|
|
|
3419
3298
|
return out
|
|
3420
3299
|
|
|
3421
3300
|
|
|
3422
|
-
def relu(input):
|
|
3423
|
-
r"""
|
|
3424
|
-
Computes ReLU (Rectified Linear Unit activation function) of input tensors element-wise.
|
|
3425
|
-
|
|
3426
|
-
It returns :math:`\max(input,\ 0)` element-wise. Specially, the neurons with the negative output
|
|
3427
|
-
will be suppressed and the active neurons will stay the same.
|
|
3428
|
-
|
|
3429
|
-
.. math::
|
|
3430
|
-
|
|
3431
|
-
ReLU(input) = (input)^+ = \max(0, input)
|
|
3432
|
-
|
|
3433
|
-
Note:
|
|
3434
|
-
In general, this operator is more commonly used. The difference from `ReLuV2` is that the `ReLuV2` will
|
|
3435
|
-
output one more Mask.
|
|
3436
|
-
|
|
3437
|
-
Args:
|
|
3438
|
-
input (Tensor): Input Tensor of numeric types.
|
|
3439
|
-
|
|
3440
|
-
Returns:
|
|
3441
|
-
Tensor, has the same dtype and shape as `input_x`.
|
|
3442
|
-
|
|
3443
|
-
Raises:
|
|
3444
|
-
TypeError: If dtype of `input` is not a number.
|
|
3445
|
-
TypeError: If `input` is not a Tensor.
|
|
3446
|
-
|
|
3447
|
-
Supported Platforms:
|
|
3448
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
3449
|
-
|
|
3450
|
-
Examples:
|
|
3451
|
-
>>> import mindspore
|
|
3452
|
-
>>> import numpy as np
|
|
3453
|
-
>>> from mindspore import Tensor, ops
|
|
3454
|
-
>>> input_x = Tensor(np.array([[-1.0, 4.0, -8.0], [2.0, -5.0, 9.0]]), mindspore.float32)
|
|
3455
|
-
>>> output = ops.relu(input_x)
|
|
3456
|
-
>>> print(output)
|
|
3457
|
-
[[0. 4. 0.]
|
|
3458
|
-
[2. 0. 9.]]
|
|
3459
|
-
"""
|
|
3460
|
-
relu_ = _get_cache_prim(NN_OPS.ReLU)()
|
|
3461
|
-
return relu_(input)
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
def relu6(x):
|
|
3465
|
-
r"""
|
|
3466
|
-
Computes ReLU (Rectified Linear Unit) upper bounded by 6 of input tensors element-wise.
|
|
3467
|
-
|
|
3468
|
-
.. math::
|
|
3469
|
-
|
|
3470
|
-
\text{ReLU6}(x) = \min(\max(0,x), 6)
|
|
3471
|
-
|
|
3472
|
-
It returns :math:`\min(\max(0,x), 6)` element-wise.
|
|
3473
|
-
|
|
3474
|
-
Args:
|
|
3475
|
-
x (Tensor): Tensor of shape :math:`(N, *)`,
|
|
3476
|
-
where :math:`*` means any number of additional dimensions.
|
|
3477
|
-
Data type must be float16, float32.
|
|
3478
|
-
|
|
3479
|
-
Returns:
|
|
3480
|
-
Tensor, with the same dtype and shape as the `x`.
|
|
3481
|
-
|
|
3482
|
-
Raises:
|
|
3483
|
-
TypeError: If dtype of `x` is neither float16 nor float32.
|
|
3484
|
-
TypeError: If `x` is not a Tensor.
|
|
3485
|
-
|
|
3486
|
-
Supported Platforms:
|
|
3487
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
3488
|
-
|
|
3489
|
-
Examples:
|
|
3490
|
-
>>> import mindspore
|
|
3491
|
-
>>> import numpy as np
|
|
3492
|
-
>>> from mindspore import Tensor, ops
|
|
3493
|
-
>>> input_x = Tensor(np.array([[-1.0, 4.0, -8.0], [2.0, -5.0, 9.0]]), mindspore.float32)
|
|
3494
|
-
>>> result = ops.relu6(input_x)
|
|
3495
|
-
>>> print(result)
|
|
3496
|
-
[[0. 4. 0.]
|
|
3497
|
-
[2. 0. 6.]]
|
|
3498
|
-
"""
|
|
3499
|
-
relu6_ = _get_cache_prim(NN_OPS.ReLU6)()
|
|
3500
|
-
return relu6_(x)
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
def prelu(x, weight):
|
|
3504
|
-
r"""
|
|
3505
|
-
Parametric Rectified Linear Unit activation function.
|
|
3506
|
-
|
|
3507
|
-
PReLU is described in the paper `Delving Deep into Rectifiers: Surpassing Human-Level Performance on
|
|
3508
|
-
ImageNet Classification <https://arxiv.org/abs/1502.01852>`_. Defined as follows:
|
|
3509
|
-
|
|
3510
|
-
.. math::
|
|
3511
|
-
prelu(x_i)= \max(0, x_i) + \min(0, w * x_i),
|
|
3512
|
-
|
|
3513
|
-
where :math:`x_i` is an element of a channel of the input, `w` is the weight of the channel.
|
|
3514
|
-
|
|
3515
|
-
Note:
|
|
3516
|
-
Scalar or 1-D Tensor is not supported on Ascend.
|
|
3517
|
-
|
|
3518
|
-
Args:
|
|
3519
|
-
x (Tensor): The input Tensor of the activation function. The data type is float16 or float32.
|
|
3520
|
-
The shape is :math:`(N, *)` where :math:`*` means, any number of additional dimensions.
|
|
3521
|
-
weight (Tensor): Weight Tensor. The data type is float16 or float32.
|
|
3522
|
-
The weight can only be a Tensor, and the length is the same as the number of channels C of the `input_x`.
|
|
3523
|
-
On GPU devices, when the input is a scalar, the shape is :math:`(1,)` .
|
|
3524
|
-
|
|
3525
|
-
Returns:
|
|
3526
|
-
Tensor, with the same shape and dtype as `x`.
|
|
3527
|
-
|
|
3528
|
-
For detailed information, please refer to :class:`mindspore.nn.PReLU`.
|
|
3529
|
-
|
|
3530
|
-
Raises:
|
|
3531
|
-
TypeError: If dtype of `x` or `weight` is neither float16 nor float32.
|
|
3532
|
-
TypeError: If the `x` or the `weight` is not a Tensor.
|
|
3533
|
-
ValueError: If the `x` is a 0-D or 1-D Tensor on Ascend.
|
|
3534
|
-
ValueError: If the `weight` is not a 1-D Tensor.
|
|
3535
|
-
|
|
3536
|
-
Supported Platforms:
|
|
3537
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
3538
|
-
|
|
3539
|
-
Examples:
|
|
3540
|
-
>>> import mindspore
|
|
3541
|
-
>>> import numpy as np
|
|
3542
|
-
>>> from mindspore import Tensor, ops
|
|
3543
|
-
>>> x = Tensor(np.arange(-6, 6).reshape((2, 3, 2)), mindspore.float32)
|
|
3544
|
-
>>> weight = Tensor(np.array([0.1, 0.6, -0.3]), mindspore.float32)
|
|
3545
|
-
>>> output = ops.prelu(x, weight)
|
|
3546
|
-
>>> print(output)
|
|
3547
|
-
[[[-0.60 -0.50]
|
|
3548
|
-
[-2.40 -1.80]
|
|
3549
|
-
[ 0.60 0.30]]
|
|
3550
|
-
[[ 0.00 1.00]
|
|
3551
|
-
[ 2.00 3.00]
|
|
3552
|
-
[ 4.0 5.00]]]
|
|
3553
|
-
"""
|
|
3554
|
-
prelu_ = _get_cache_prim(NN_OPS.PReLU)()
|
|
3555
|
-
return prelu_(x, weight)
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
3301
|
def rrelu(input, lower=1.0 / 8, upper=1.0 / 3):
|
|
3559
3302
|
r"""
|
|
3560
3303
|
|
|
@@ -3583,7 +3326,7 @@ def rrelu(input, lower=1.0 / 8, upper=1.0 / 3):
|
|
|
3583
3326
|
TypeError: If `lower` is not a float or an int.
|
|
3584
3327
|
TypeError: If `upper` is not a float or an int.
|
|
3585
3328
|
TypeError: If `input` is not a Tensor.
|
|
3586
|
-
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.
|
|
3587
3330
|
ValueError: If `lower` is greater than upper.
|
|
3588
3331
|
|
|
3589
3332
|
Supported Platforms:
|
|
@@ -3612,13 +3355,12 @@ def rrelu(input, lower=1.0 / 8, upper=1.0 / 3):
|
|
|
3612
3355
|
_upper = Tensor(upper, mstype.float32)
|
|
3613
3356
|
_size = input.shape
|
|
3614
3357
|
if ops.is_sequence_value_unknown(_size):
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
sign_matrix = _get_cache_prim(P.Sign)()(input)
|
|
3358
|
+
_size = tensor_shape_(input)
|
|
3359
|
+
sign_matrix = sign_(input)
|
|
3618
3360
|
negative_filter = sign_matrix.clip(None, 0)
|
|
3619
3361
|
positive_filter = sign_matrix.clip(0, None)
|
|
3620
|
-
|
|
3621
|
-
mask = ops.uniform(_size, _lower, _upper).astype(
|
|
3362
|
+
input_dtype = dtype_(input)
|
|
3363
|
+
mask = ops.uniform(_size, _lower, _upper).astype(input_dtype)
|
|
3622
3364
|
negative_mask = negative_filter * mask * -1
|
|
3623
3365
|
total_mask = negative_mask + positive_filter
|
|
3624
3366
|
out = total_mask * input
|
|
@@ -3686,6 +3428,21 @@ def _innner_log_softmax(inputs, axis):
|
|
|
3686
3428
|
return inputs - logsumexp(inputs, axis, True)
|
|
3687
3429
|
|
|
3688
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
|
+
|
|
3689
3446
|
def cross_entropy(input, target, weight=None, ignore_index=-100, reduction='mean', label_smoothing=0.0):
|
|
3690
3447
|
r"""
|
|
3691
3448
|
The cross entropy loss between input and target.
|
|
@@ -3743,7 +3500,7 @@ def cross_entropy(input, target, weight=None, ignore_index=-100, reduction='mean
|
|
|
3743
3500
|
`input` is expected to be log-probabilities, data type must be float16 or float32.
|
|
3744
3501
|
target (Tensor): For class indices, tensor of shape :math:`()`, :math:`(N)` or
|
|
3745
3502
|
:math:`(N, d_1, d_2, ..., d_K)` , data type must be int32. For probabilities, tensor of shape :math:`(C,)` ,
|
|
3746
|
-
:math:`(N, C)` or :math:`(N, C, d_1, d_2, ..., d_K)` , data type must be float16 or float32.
|
|
3503
|
+
:math:`(N, C)` or :math:`(N, C, d_1, d_2, ..., d_K)` , data type must be float16 or float32 or float64.
|
|
3747
3504
|
weight (Tensor): A rescaling weight applied to the loss of each batch element.
|
|
3748
3505
|
If not None, the shape is :math:`(C,)`, data type must be float16 or float32. Default: ``None`` .
|
|
3749
3506
|
ignore_index (int): Specifies a target value that is ignored
|
|
@@ -3776,12 +3533,7 @@ def cross_entropy(input, target, weight=None, ignore_index=-100, reduction='mean
|
|
|
3776
3533
|
>>> target = ms.Tensor(np.random.randn(3, 5), ms.float32)
|
|
3777
3534
|
>>> output = ms.ops.cross_entropy(inputs, target)
|
|
3778
3535
|
"""
|
|
3779
|
-
|
|
3780
|
-
_check_is_tensor('target', target, "cross_entropy_loss")
|
|
3781
|
-
_check_is_tensor('weight', weight, "cross_entropy_loss")
|
|
3782
|
-
check_int_const(ignore_index, 'ignore_index', "cross_entropy_loss")
|
|
3783
|
-
check_non_negative_float_const(label_smoothing, 'label_smoothing', "cross_entropy_loss")
|
|
3784
|
-
check_string_const(reduction, ['none', 'mean', 'sum'], 'reduction', "cross_entropy_loss")
|
|
3536
|
+
_check_cross_entropy_inputs(input, target, weight, ignore_index, reduction, label_smoothing)
|
|
3785
3537
|
class_dim = 0 if input.ndim == 1 else 1
|
|
3786
3538
|
if target.dtype in [mstype.float32, mstype.float16]:
|
|
3787
3539
|
return _cross_entropy(input, target, class_dim, weight, reduction, label_smoothing)
|
|
@@ -3790,8 +3542,6 @@ def cross_entropy(input, target, weight=None, ignore_index=-100, reduction='mean
|
|
|
3790
3542
|
|
|
3791
3543
|
def _cross_entropy(inputs, target, target_dim, weight=None, reduction='mean', label_smoothing=0.0):
|
|
3792
3544
|
"""cross entropy inner function"""
|
|
3793
|
-
_ones_like = _get_cache_prim(P.OnesLike)()
|
|
3794
|
-
|
|
3795
3545
|
class_dim = 0 if inputs.ndim == 1 else 1
|
|
3796
3546
|
n_classes = inputs.shape[class_dim]
|
|
3797
3547
|
inputs = _innner_log_softmax(inputs, class_dim)
|
|
@@ -3799,7 +3549,7 @@ def _cross_entropy(inputs, target, target_dim, weight=None, reduction='mean', la
|
|
|
3799
3549
|
target = target * (1 - label_smoothing) + label_smoothing / n_classes
|
|
3800
3550
|
|
|
3801
3551
|
if weight is None:
|
|
3802
|
-
weight =
|
|
3552
|
+
weight = ones_like_(inputs)
|
|
3803
3553
|
elif inputs.ndim != 1:
|
|
3804
3554
|
broadcast_shape = [1 for _ in range(inputs.ndim)]
|
|
3805
3555
|
broadcast_shape[1] = weight.shape[0]
|
|
@@ -3829,7 +3579,7 @@ def nll_loss(inputs, target, weight=None, ignore_index=-100, reduction='mean', l
|
|
|
3829
3579
|
N is the batch size, :math:`c` belonging to :math:`[0, C-1]` is class index, where :math:`C` is the number of
|
|
3830
3580
|
classes.
|
|
3831
3581
|
|
|
3832
|
-
If `reduction` is not ``None`` (default 'mean'), then
|
|
3582
|
+
If `reduction` is not ``None`` (default ``'mean'``), then
|
|
3833
3583
|
|
|
3834
3584
|
.. math::
|
|
3835
3585
|
|
|
@@ -3897,37 +3647,31 @@ def nll_loss(inputs, target, weight=None, ignore_index=-100, reduction='mean', l
|
|
|
3897
3647
|
|
|
3898
3648
|
def _nll_loss(inputs, target, target_dim=-1, weight=None, ignore_index=None, reduction='none', label_smoothing=0.0):
|
|
3899
3649
|
"""nll loss inner function"""
|
|
3900
|
-
_neg = _get_cache_prim(P.Neg)()
|
|
3901
|
-
_gather_d = _get_cache_prim(P.GatherD)()
|
|
3902
|
-
_gather = _get_cache_prim(P.Gather)()
|
|
3903
|
-
_ones_like = _get_cache_prim(P.OnesLike)()
|
|
3904
|
-
_equal = _get_cache_prim(P.Equal)()
|
|
3905
|
-
|
|
3906
3650
|
if target.ndim == inputs.ndim - 1:
|
|
3907
3651
|
target = target.expand_dims(target_dim)
|
|
3908
3652
|
if ignore_index is not None:
|
|
3909
|
-
non_pad_mask =
|
|
3910
|
-
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))
|
|
3911
3655
|
else:
|
|
3912
3656
|
non_pad_mask = target
|
|
3913
3657
|
if weight is not None:
|
|
3914
|
-
loss_weights =
|
|
3658
|
+
loss_weights = gather_(weight, target, 0)
|
|
3915
3659
|
orig_shape = inputs.shape
|
|
3916
3660
|
if inputs.ndim != 2:
|
|
3917
3661
|
inputs = inputs.view(orig_shape[:2] + (-1,))
|
|
3918
3662
|
weight = weight.view(weight.shape + (1,))
|
|
3919
3663
|
weighted_inputs = inputs * weight
|
|
3920
3664
|
weighted_inputs = weighted_inputs.view(orig_shape)
|
|
3921
|
-
loss =
|
|
3922
|
-
smooth_loss =
|
|
3665
|
+
loss = neg_(gather_d_(weighted_inputs, target_dim, target))
|
|
3666
|
+
smooth_loss = neg_(weighted_inputs.sum(axis=target_dim, keepdims=True))
|
|
3923
3667
|
else:
|
|
3924
|
-
loss =
|
|
3925
|
-
smooth_loss =
|
|
3926
|
-
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)
|
|
3927
3671
|
if ignore_index is not None:
|
|
3928
|
-
loss = loss.masked_fill(non_pad_mask, 0.)
|
|
3929
|
-
loss_weights = loss_weights.masked_fill(non_pad_mask, 0.)
|
|
3930
|
-
smooth_loss = smooth_loss.masked_fill(non_pad_mask, 0.)
|
|
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))
|
|
3931
3675
|
|
|
3932
3676
|
loss = loss.squeeze(target_dim)
|
|
3933
3677
|
smooth_loss = smooth_loss.squeeze(target_dim)
|
|
@@ -3949,8 +3693,9 @@ def l1_loss(input, target, reduction='mean'):
|
|
|
3949
3693
|
r"""
|
|
3950
3694
|
Calculate the mean absolute error between the `input` value and the `target` value.
|
|
3951
3695
|
|
|
3952
|
-
Assuming that the :math:`x` and :math:`y` are 1-D Tensor,
|
|
3953
|
-
|
|
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.
|
|
3954
3699
|
|
|
3955
3700
|
The formula is as follows:
|
|
3956
3701
|
|
|
@@ -3959,7 +3704,7 @@ def l1_loss(input, target, reduction='mean'):
|
|
|
3959
3704
|
|
|
3960
3705
|
where :math:`N` is the batch size.
|
|
3961
3706
|
|
|
3962
|
-
If `reduction` is ``
|
|
3707
|
+
If `reduction` is ``'mean'`` or ``'sum'`` , then:
|
|
3963
3708
|
|
|
3964
3709
|
.. math::
|
|
3965
3710
|
\ell(x, y) =
|
|
@@ -3980,13 +3725,13 @@ def l1_loss(input, target, reduction='mean'):
|
|
|
3980
3725
|
- ``'sum'``: the output elements will be summed.
|
|
3981
3726
|
|
|
3982
3727
|
Returns:
|
|
3983
|
-
Tensor or Scalar, if `reduction` is ``
|
|
3728
|
+
Tensor or Scalar, if `reduction` is ``'none'``, return a Tensor with same shape and dtype as `input`.
|
|
3984
3729
|
Otherwise, a scalar value will be returned.
|
|
3985
3730
|
|
|
3986
3731
|
Raises:
|
|
3987
3732
|
TypeError: If `input` is not a Tensor.
|
|
3988
3733
|
TypeError: If `target` is not a Tensor.
|
|
3989
|
-
ValueError: If `reduction` is not one of ``
|
|
3734
|
+
ValueError: If `reduction` is not one of ``'none'``, ``'mean'`` or ``'sum'``.
|
|
3990
3735
|
|
|
3991
3736
|
Supported Platforms:
|
|
3992
3737
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -4004,7 +3749,7 @@ def l1_loss(input, target, reduction='mean'):
|
|
|
4004
3749
|
_check_is_tensor('target', target, "l1_loss")
|
|
4005
3750
|
if reduction not in ('mean', 'sum', 'none'):
|
|
4006
3751
|
raise ValueError(f"For l1_loss, the 'reduction' must be in ['mean', 'sum', 'none'], but got {reduction}.")
|
|
4007
|
-
loss =
|
|
3752
|
+
loss = abs_(input - target)
|
|
4008
3753
|
return _get_loss(loss, reduction, "l1_loss")
|
|
4009
3754
|
|
|
4010
3755
|
|
|
@@ -4039,6 +3784,7 @@ def smooth_l1_loss(input, target, beta=1.0, reduction='none'):
|
|
|
4039
3784
|
|
|
4040
3785
|
Args:
|
|
4041
3786
|
input (Tensor): Tensor of shape :math:`(N, *)` where :math:`*` means, any number of additional dimensions.
|
|
3787
|
+
Data type is float16, float32 or float64.
|
|
4042
3788
|
target (Tensor): Ground truth data, tensor of shape :math:`(N, *)`, same shape and dtype as the `input`.
|
|
4043
3789
|
beta (float): A parameter used to control the point where the function will change between
|
|
4044
3790
|
L1 to L2 loss. The value should be greater than zero. Default: ``1.0`` .
|
|
@@ -4117,13 +3863,13 @@ def threshold(input, thr, value):
|
|
|
4117
3863
|
_check_is_tensor('input', input, "threshold")
|
|
4118
3864
|
_check_value_type("thr", thr, [float, int], "threshold")
|
|
4119
3865
|
_check_value_type("value", value, [float, int], "threshold")
|
|
4120
|
-
cond =
|
|
3866
|
+
cond = greater_(input, thr)
|
|
4121
3867
|
input_type = input.dtype
|
|
4122
3868
|
value = Tensor(value, input_type)
|
|
4123
3869
|
input_shape = input.shape
|
|
4124
|
-
shape_tensor =
|
|
4125
|
-
value =
|
|
4126
|
-
return
|
|
3870
|
+
shape_tensor = tuple_to_tensor_(input_shape, mstype.int64)
|
|
3871
|
+
value = fillv2_(shape_tensor, value)
|
|
3872
|
+
return select_(cond, input, value)
|
|
4127
3873
|
|
|
4128
3874
|
|
|
4129
3875
|
def leaky_relu(input, alpha=0.2):
|
|
@@ -4141,6 +3887,11 @@ def leaky_relu(input, alpha=0.2):
|
|
|
4141
3887
|
For more details, see `Rectifier Nonlinearities Improve Neural Network Acoustic Models
|
|
4142
3888
|
<https://ai.stanford.edu/~amaas/papers/relu_hybrid_icml2013_final.pdf>`_.
|
|
4143
3889
|
|
|
3890
|
+
LeakyReLU Activation Function Graph:
|
|
3891
|
+
|
|
3892
|
+
.. image:: ../images/LeakyReLU.png
|
|
3893
|
+
:align: center
|
|
3894
|
+
|
|
4144
3895
|
Args:
|
|
4145
3896
|
input (Tensor): The input of leaky_relu is a Tensor of any dimension.
|
|
4146
3897
|
alpha (Union[int, float]): Slope of the activation function when the element of `input` is less than 0.
|
|
@@ -4167,10 +3918,10 @@ def leaky_relu(input, alpha=0.2):
|
|
|
4167
3918
|
"""
|
|
4168
3919
|
_check_is_tensor('input', input, "leaky_relu")
|
|
4169
3920
|
_check_value_type("alpha", alpha, [float, int], "leaky_relu")
|
|
4170
|
-
select_op =
|
|
3921
|
+
select_op = maximum_
|
|
4171
3922
|
if alpha > 1:
|
|
4172
|
-
select_op =
|
|
4173
|
-
alpha =
|
|
3923
|
+
select_op = minimum_
|
|
3924
|
+
alpha = cast_(F.scalar_to_tensor(alpha), input.dtype)
|
|
4174
3925
|
return select_op(alpha * input, input)
|
|
4175
3926
|
|
|
4176
3927
|
|
|
@@ -4211,48 +3962,6 @@ def intopk(x1, x2, k):
|
|
|
4211
3962
|
_in_topk = _get_cache_prim(P.InTopK)(k)
|
|
4212
3963
|
return _in_topk(x1, x2)
|
|
4213
3964
|
|
|
4214
|
-
|
|
4215
|
-
def log_softmax(logits, axis=-1):
|
|
4216
|
-
r"""
|
|
4217
|
-
Applies the Log Softmax function to the input tensor on the specified axis.
|
|
4218
|
-
Supposes a slice in the given axis, :math:`x` for each element :math:`x_i`,
|
|
4219
|
-
the Log Softmax function is shown as follows:
|
|
4220
|
-
|
|
4221
|
-
.. math::
|
|
4222
|
-
\text{output}(x_i) = \log \left(\frac{\exp(x_i)} {\sum_{j = 0}^{N-1}\exp(x_j)}\right),
|
|
4223
|
-
|
|
4224
|
-
where :math:`N` is the length of the Tensor.
|
|
4225
|
-
|
|
4226
|
-
Args:
|
|
4227
|
-
logits (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
|
|
4228
|
-
additional dimensions, with float16 or float32 data type.
|
|
4229
|
-
axis (int): The axis to perform the Log softmax operation. Default: ``-1`` .
|
|
4230
|
-
|
|
4231
|
-
Returns:
|
|
4232
|
-
Tensor, with the same type and shape as the logits.
|
|
4233
|
-
|
|
4234
|
-
Raises:
|
|
4235
|
-
TypeError: If `axis` is not an int.
|
|
4236
|
-
TypeError: If dtype of `logits` is neither float16 nor float32.
|
|
4237
|
-
ValueError: If `axis` is not in range [-len(logits.shape), len(logits.shape)).
|
|
4238
|
-
ValueError: If dimension of `logits` is less than 1.
|
|
4239
|
-
|
|
4240
|
-
Supported Platforms:
|
|
4241
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
4242
|
-
|
|
4243
|
-
Examples:
|
|
4244
|
-
>>> import mindspore
|
|
4245
|
-
>>> import numpy as np
|
|
4246
|
-
>>> from mindspore import Tensor, ops
|
|
4247
|
-
>>> logits = Tensor(np.array([1, 2, 3, 4, 5]), mindspore.float32)
|
|
4248
|
-
>>> output = ops.log_softmax(logits)
|
|
4249
|
-
>>> print(output)
|
|
4250
|
-
[-4.4519143 -3.4519143 -2.4519143 -1.4519144 -0.4519144]
|
|
4251
|
-
"""
|
|
4252
|
-
_log_softmax = _get_cache_prim(P.LogSoftmax)(axis)
|
|
4253
|
-
return _log_softmax(logits)
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
3965
|
def lrn(x, depth_radius=5, bias=1.0, alpha=1.0, beta=0.5, norm_region="ACROSS_CHANNELS"):
|
|
4257
3966
|
r"""
|
|
4258
3967
|
Local Response Normalization.
|
|
@@ -4321,6 +4030,11 @@ def mish(x):
|
|
|
4321
4030
|
See more details in `A Self Regularized Non-Monotonic Neural Activation Function
|
|
4322
4031
|
<https://arxiv.org/abs/1908.08681>`_.
|
|
4323
4032
|
|
|
4033
|
+
Mish Activation Function Graph:
|
|
4034
|
+
|
|
4035
|
+
.. image:: ../images/Mish.png
|
|
4036
|
+
:align: center
|
|
4037
|
+
|
|
4324
4038
|
Args:
|
|
4325
4039
|
x (Tensor): The input Tensor.
|
|
4326
4040
|
Supported dtypes:
|
|
@@ -4387,21 +4101,15 @@ def _get_loss(x, reduction, cls_name, weights=1.0):
|
|
|
4387
4101
|
if reduction not in ('mean', 'sum', 'none'):
|
|
4388
4102
|
raise ValueError(f"For '{cls_name}', the 'reduction' must be in ['mean', 'sum', 'none'], "
|
|
4389
4103
|
f"but got {reduction}.")
|
|
4390
|
-
|
|
4391
|
-
reduce_mean = P.ReduceMean()
|
|
4392
|
-
reduce_sum = P.ReduceSum()
|
|
4393
|
-
mul = P.Mul()
|
|
4394
|
-
cast = P.Cast()
|
|
4395
|
-
|
|
4396
4104
|
input_dtype = x.dtype
|
|
4397
|
-
x =
|
|
4398
|
-
weights =
|
|
4399
|
-
x =
|
|
4105
|
+
x = cast_(x, mstype.float32)
|
|
4106
|
+
weights = cast_(weights, mstype.float32)
|
|
4107
|
+
x = mul_(weights, x)
|
|
4400
4108
|
if reduction == 'mean':
|
|
4401
|
-
x =
|
|
4109
|
+
x = reduce_mean_(x, _get_axis(x))
|
|
4402
4110
|
if reduction == 'sum':
|
|
4403
|
-
x =
|
|
4404
|
-
x =
|
|
4111
|
+
x = reduce_sum_(x, _get_axis(x))
|
|
4112
|
+
x = cast_(x, input_dtype)
|
|
4405
4113
|
return x
|
|
4406
4114
|
|
|
4407
4115
|
|
|
@@ -4412,20 +4120,6 @@ def check_input_dtype(param_name1, input_data1, param_name2, input_data2, cls_na
|
|
|
4412
4120
|
f'but got {param_name1} dtype:{input_data1.dtype}, {param_name2} dtype:{input_data2.dtype}.')
|
|
4413
4121
|
|
|
4414
4122
|
|
|
4415
|
-
def check_input_shape(param_name1, input_data1, param_name2, input_data2, cls_name):
|
|
4416
|
-
"""Check the shape of input1 and input2."""
|
|
4417
|
-
if input_data1.shape != input_data2.shape:
|
|
4418
|
-
raise ValueError(f'For {cls_name}, the {param_name1} shape should be equal to {param_name2} shape, '
|
|
4419
|
-
f'but got {param_name1} shape:{input_data1.shape}, {param_name2} shape:{input_data2.shape}.')
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
def _check_type_and_shape_same(param_name1, input_data1, param_name2, input_data2, cls_name):
|
|
4423
|
-
"""check input1 and input2 type and shape same"""
|
|
4424
|
-
check_input_dtype(param_name1, input_data1, param_name2, input_data2, cls_name)
|
|
4425
|
-
check_input_shape(param_name1, input_data1, param_name2, input_data2, cls_name)
|
|
4426
|
-
return 0
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
4123
|
def margin_ranking_loss(input1, input2, target, margin=0.0, reduction='mean'):
|
|
4430
4124
|
r"""
|
|
4431
4125
|
MarginRankingLoss creates a criterion that measures the loss.
|
|
@@ -4450,7 +4144,7 @@ def margin_ranking_loss(input1, input2, target, margin=0.0, reduction='mean'):
|
|
|
4450
4144
|
- ``'sum'``: the output elements will be summed.
|
|
4451
4145
|
|
|
4452
4146
|
Returns:
|
|
4453
|
-
Tensor or Scalar. if `reduction` is ``
|
|
4147
|
+
Tensor or Scalar. if `reduction` is ``'none'``, its shape is the same as `input1`.
|
|
4454
4148
|
Otherwise, a scalar value will be returned.
|
|
4455
4149
|
|
|
4456
4150
|
Raises:
|
|
@@ -4480,10 +4174,9 @@ def margin_ranking_loss(input1, input2, target, margin=0.0, reduction='mean'):
|
|
|
4480
4174
|
_check_is_tensor('input1', input1, "margin_ranking_loss")
|
|
4481
4175
|
_check_is_tensor('input2', input2, "margin_ranking_loss")
|
|
4482
4176
|
_check_is_tensor('target', target, "margin_ranking_loss")
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
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)
|
|
4487
4180
|
return _get_loss(x, reduction, "margin_ranking_loss")
|
|
4488
4181
|
|
|
4489
4182
|
|
|
@@ -4511,7 +4204,7 @@ def cosine_embedding_loss(input1, input2, target, margin=0.0, reduction="mean"):
|
|
|
4511
4204
|
input2 (Tensor): Tensor of shape :math:`(N, *)`, same shape and dtype as `input1`.
|
|
4512
4205
|
target (Tensor): Contains value 1 or -1. Suppose the shape of `input1` is
|
|
4513
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)`.
|
|
4514
|
-
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``.
|
|
4515
4208
|
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
4516
4209
|
``'sum'`` . Default: ``'mean'`` .
|
|
4517
4210
|
|
|
@@ -4526,7 +4219,7 @@ def cosine_embedding_loss(input1, input2, target, margin=0.0, reduction="mean"):
|
|
|
4526
4219
|
Raises:
|
|
4527
4220
|
TypeError: If `margin` is not a float.
|
|
4528
4221
|
ValueError: If `reduction` is not one of ``'none'``, ``'mean'``, ``'sum'``.
|
|
4529
|
-
ValueError: If `margin` is not in range [-1, 1].
|
|
4222
|
+
ValueError: If `margin` is not in range [-1.0, 1.0].
|
|
4530
4223
|
|
|
4531
4224
|
Supported Platforms:
|
|
4532
4225
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -4546,7 +4239,7 @@ def cosine_embedding_loss(input1, input2, target, margin=0.0, reduction="mean"):
|
|
|
4546
4239
|
_check_is_tensor('input1', input1, "ops.cosine_embedding_loss")
|
|
4547
4240
|
_check_is_tensor('input2', input2, "ops.cosine_embedding_loss")
|
|
4548
4241
|
_check_is_tensor('target', target, "ops.cosine_embedding_loss")
|
|
4549
|
-
|
|
4242
|
+
check_input_dtype('input1', input1, 'input2', input2, 'ops.cosine_embedding_loss')
|
|
4550
4243
|
_check_reduced_shape_valid(ops.shape(input1), ops.shape(target), (1,),
|
|
4551
4244
|
"ops.cosine_embedding_loss", "input1", "target")
|
|
4552
4245
|
if input1.dtype in (mstype.int32, mstype.int64):
|
|
@@ -4560,14 +4253,14 @@ def cosine_embedding_loss(input1, input2, target, margin=0.0, reduction="mean"):
|
|
|
4560
4253
|
if margin_f > 1.0 or margin_f < -1.0:
|
|
4561
4254
|
raise ValueError(f"For ops.cosine_embedding_loss, the value of 'margin' should be in [-1, 1],"
|
|
4562
4255
|
f"but got {margin_f}.")
|
|
4563
|
-
prod_sum =
|
|
4564
|
-
square1 =
|
|
4565
|
-
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,))
|
|
4566
4259
|
denom = ops.sqrt(square1) * ops.sqrt(square2)
|
|
4567
4260
|
cosine = prod_sum / denom
|
|
4568
4261
|
|
|
4569
4262
|
pos_value = 1.0 - cosine
|
|
4570
|
-
neg_value =
|
|
4263
|
+
neg_value = maximum_(cosine - margin_f, 0.0)
|
|
4571
4264
|
zeros = ops.zeros_like(cosine)
|
|
4572
4265
|
pos_part = ops.select(target == 1, pos_value, zeros)
|
|
4573
4266
|
neg_part = ops.select(target == -1, neg_value, zeros)
|
|
@@ -4624,7 +4317,7 @@ def max_pool3d(x, kernel_size, stride=None, padding=0, dilation=1, ceil_mode=Fal
|
|
|
4624
4317
|
W_{out} = \left\lfloor\frac{W_{in} + 2 \times \text{padding}[2] - \text{dilation}[2] \times
|
|
4625
4318
|
(\text{kernel_size}[2] - 1) - 1}{\text{stride}[2]} + 1\right\rfloor
|
|
4626
4319
|
|
|
4627
|
-
- **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
|
|
4628
4321
|
only when `return_indices` is ``True`` .
|
|
4629
4322
|
|
|
4630
4323
|
Raises:
|
|
@@ -4702,9 +4395,9 @@ def grid_sample(input, grid, mode='bilinear', padding_mode='zeros', align_corner
|
|
|
4702
4395
|
|
|
4703
4396
|
padding_mode (str): An optional string specifying the pad method. The optional values are "zeros", "border" or
|
|
4704
4397
|
"reflection". Default: ``'zeros'`` .
|
|
4705
|
-
align_corners (bool):
|
|
4706
|
-
the center points of the input
|
|
4707
|
-
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:
|
|
4708
4401
|
``False`` .
|
|
4709
4402
|
|
|
4710
4403
|
Returns:
|
|
@@ -4777,8 +4470,8 @@ def ctc_loss(log_probs, targets, input_lengths, target_lengths, blank=0, reducti
|
|
|
4777
4470
|
log_probs (Tensor): A tensor of shape :math:`(T, N, C)`, where T is input length, N is batch size and C is
|
|
4778
4471
|
number of classes (including blank).
|
|
4779
4472
|
targets (Tensor): Target sequences. A tensor of shape :math:`(N, S)`, where S is max target length.
|
|
4780
|
-
input_lengths (Union(tuple, Tensor)): Lengths of the input. A tuple or Tensor of shape(N)
|
|
4781
|
-
target_lengths (Union(tuple, Tensor)): Lengths of the target. A tuple or Tensor of shape(N)
|
|
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)`.
|
|
4782
4475
|
blank (int, optional): The blank label. Default: ``0`` .
|
|
4783
4476
|
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
4784
4477
|
``'sum'`` . Default: ``'mean'`` .
|
|
@@ -4925,17 +4618,10 @@ def gaussian_nll_loss(x, target, var, full=False, eps=1e-6, reduction='mean'):
|
|
|
4925
4618
|
if not x.shape == var.shape:
|
|
4926
4619
|
if x.shape[:-1] == var.shape:
|
|
4927
4620
|
var = var.unsqueeze(dim=-1)
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
raise ValueError(f"For 'gaussian_nll_loss', 'var' must be able to correctly broadcast to 'x' and 'target'.")
|
|
4933
|
-
max_op = P.Maximum()
|
|
4934
|
-
log_op = P.Log()
|
|
4935
|
-
square_op = P.Square()
|
|
4936
|
-
maxima = max_op(var, eps)
|
|
4937
|
-
logarithm = log_op(maxima)
|
|
4938
|
-
squared_loss = square_op(x - target)
|
|
4621
|
+
|
|
4622
|
+
maxima = maximum_(var, eps)
|
|
4623
|
+
logarithm = log_(maxima)
|
|
4624
|
+
squared_loss = square_(x - target)
|
|
4939
4625
|
c = 0 if not full else 0.5 * log(2 * pi)
|
|
4940
4626
|
loss = 0.5 * (logarithm + squared_loss / maxima) + c
|
|
4941
4627
|
if reduction == 'mean':
|
|
@@ -4945,12 +4631,6 @@ def gaussian_nll_loss(x, target, var, full=False, eps=1e-6, reduction='mean'):
|
|
|
4945
4631
|
return loss
|
|
4946
4632
|
|
|
4947
4633
|
|
|
4948
|
-
@_primexpr
|
|
4949
|
-
def _check_hinge_embedding_loss(shape, shape2):
|
|
4950
|
-
if shape2 != shape:
|
|
4951
|
-
raise ValueError(f"For 'HingeEmbeddingLoss' the input tensor and the labels must have the same shape.")
|
|
4952
|
-
|
|
4953
|
-
|
|
4954
4634
|
@_primexpr
|
|
4955
4635
|
def _check_hinge_embedding_loss_type(inputs_dtype, targets_dtype, inputs, targets, margin, reduction):
|
|
4956
4636
|
"""Check hinge embedding loss type."""
|
|
@@ -4998,7 +4678,7 @@ def hinge_embedding_loss(inputs, targets, margin=1.0, reduction='mean'):
|
|
|
4998
4678
|
inputs (Tensor): Predicted values, represented as :math:`x` in the formula.
|
|
4999
4679
|
targets (Tensor): Label values, represented as :math:`y` in the formula.
|
|
5000
4680
|
Has the same shape as `inputs`, contains -1 or 1.
|
|
5001
|
-
margin (float, int): Threshold defined by Hinge Embedding Loss
|
|
4681
|
+
margin (float, int): Threshold defined by Hinge Embedding Loss `margin`.
|
|
5002
4682
|
Represented as :math:`\Delta` in the formula. Default: ``1.0`` .
|
|
5003
4683
|
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
5004
4684
|
``'sum'`` . Default: ``'mean'`` .
|
|
@@ -5008,7 +4688,7 @@ def hinge_embedding_loss(inputs, targets, margin=1.0, reduction='mean'):
|
|
|
5008
4688
|
- ``'sum'``: the output elements will be summed.
|
|
5009
4689
|
|
|
5010
4690
|
Returns:
|
|
5011
|
-
Tensor or Tensor scalar, the computed loss depending on
|
|
4691
|
+
Tensor or Tensor scalar, the computed loss depending on `reduction`.
|
|
5012
4692
|
|
|
5013
4693
|
Raises:
|
|
5014
4694
|
TypeError: If `inputs` is not a Tensor.
|
|
@@ -5036,9 +4716,6 @@ def hinge_embedding_loss(inputs, targets, margin=1.0, reduction='mean'):
|
|
|
5036
4716
|
inputs_dtype = inputs.dtype
|
|
5037
4717
|
targets_dtype = targets.dtype
|
|
5038
4718
|
_check_hinge_embedding_loss_type(inputs_dtype, targets_dtype, inputs, targets, margin, reduction)
|
|
5039
|
-
_shape = inputs.shape
|
|
5040
|
-
_t_shape = targets.shape
|
|
5041
|
-
_check_hinge_embedding_loss(_shape, _t_shape)
|
|
5042
4719
|
|
|
5043
4720
|
min_val = Tensor(0, inputs_dtype)
|
|
5044
4721
|
pos_index = targets > 0
|
|
@@ -5259,21 +4936,25 @@ def conv1d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5259
4936
|
, :math:`weight` is the convolution kernel value and :math:`X` represents the input feature map.
|
|
5260
4937
|
|
|
5261
4938
|
Here are the indices' meanings:
|
|
5262
|
-
- :math:`i` corresponds to the batch number, ranging from 0 to N-1, where N is the batch size of the input.
|
|
5263
4939
|
|
|
5264
|
-
- :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
|
|
5265
4945
|
output channels, which is also equal to the number of kernels.
|
|
5266
4946
|
|
|
5267
|
-
- :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
|
|
5268
4949
|
input channels, which is also equal to the number of channels in the convolutional kernels.
|
|
5269
4950
|
|
|
5270
|
-
Therefore, in the above formula, :math:`{bias}(C_{
|
|
5271
|
-
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
|
|
5272
4953
|
kernel in the :math:`k`-th channel, and :math:`{X}(N_i, k)` represents the slice of the :math:`k`-th input
|
|
5273
4954
|
channel in the :math:`i`-th batch of the input feature map.
|
|
5274
4955
|
|
|
5275
|
-
The shape of the convolutional kernel is given by :math:`(
|
|
5276
|
-
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.
|
|
5277
4958
|
If we consider the input and output channels as well as the `group` parameter, the complete kernel shape
|
|
5278
4959
|
will be :math:`(C_{out}, C_{in} / \text{group}, \text{kernel_size})`,
|
|
5279
4960
|
where `group` is the number of groups dividing `x`'s input channel when applying group convolution.
|
|
@@ -5284,7 +4965,7 @@ def conv1d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5284
4965
|
|
|
5285
4966
|
Note:
|
|
5286
4967
|
On Ascend platform, only group convolution in depthwise convolution scenarios is supported.
|
|
5287
|
-
That is, when `groups>1`, condition
|
|
4968
|
+
That is, when `groups>1`, condition :math:`C_{in}` = :math:`C_{out}` = `groups` must be satisfied.
|
|
5288
4969
|
|
|
5289
4970
|
Args:
|
|
5290
4971
|
input (Tensor): Input Tensor of shape :math:`(N, C_{in}, L_{in})`.
|
|
@@ -5353,13 +5034,12 @@ def conv1d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5353
5034
|
raise ValueError(f"For 'conv1d', the input must be a 3D Tensor, but got input of {input.ndim}D.")
|
|
5354
5035
|
if weight.ndim != 3:
|
|
5355
5036
|
raise ValueError(f"For 'conv1d', the weight must be a 3D Tensor, but got input of {weight.ndim}D.")
|
|
5356
|
-
|
|
5357
|
-
expanded_input = _expand(input, 2)
|
|
5037
|
+
expanded_input = expand_dims_(input, 2)
|
|
5358
5038
|
sqz = _get_cache_prim(P.Squeeze)(2)
|
|
5359
5039
|
weight_shape = weight.shape
|
|
5360
5040
|
out_channel = weight_shape[0]
|
|
5361
5041
|
kernel_size = (1, weight_shape[2])
|
|
5362
|
-
expanded_weight =
|
|
5042
|
+
expanded_weight = expand_dims_(weight, 2)
|
|
5363
5043
|
if isinstance(padding, int):
|
|
5364
5044
|
padding = (0, 0, padding, padding)
|
|
5365
5045
|
elif isinstance(padding, (tuple, list)):
|
|
@@ -5408,12 +5088,15 @@ def conv2d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5408
5088
|
, :math:`weight` is the convolution kernel value and :math:`X` represents the input feature map.
|
|
5409
5089
|
|
|
5410
5090
|
Here are the indices' meanings:
|
|
5411
|
-
- :math:`i` corresponds to the batch number, ranging from 0 to N-1, where N is the batch size of the input.
|
|
5412
5091
|
|
|
5413
|
-
- :math:`
|
|
5414
|
-
|
|
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.
|
|
5415
5094
|
|
|
5416
|
-
- :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
|
|
5417
5100
|
input channels, which is also equal to the number of channels in the convolutional kernels.
|
|
5418
5101
|
|
|
5419
5102
|
Therefore, in the above formula, :math:`{bias}(C_{out_j})` represents the bias of the :math:`j`-th
|
|
@@ -5421,8 +5104,9 @@ def conv2d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5421
5104
|
kernel in the :math:`k`-th channel, and :math:`{X}(N_i, k)` represents the slice of the :math:`k`-th input
|
|
5422
5105
|
channel in the :math:`i`-th batch of the input feature map.
|
|
5423
5106
|
|
|
5424
|
-
The shape of the convolutional kernel is given by :math:`(
|
|
5425
|
-
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.
|
|
5426
5110
|
If we consider the input and output channels as well as the `group` parameter, the complete kernel shape
|
|
5427
5111
|
will be :math:`(C_{out}, C_{in} / \text{group}, \text{kernel_size[0]}, \text{kernel_size[1]})`,
|
|
5428
5112
|
where `group` is the number of groups dividing `x`'s input channel when applying group convolution.
|
|
@@ -5433,7 +5117,7 @@ def conv2d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5433
5117
|
|
|
5434
5118
|
Note:
|
|
5435
5119
|
On Ascend platform, only group convolution in depthwise convolution scenarios is supported.
|
|
5436
|
-
That is, when `groups>1`, condition
|
|
5120
|
+
That is, when `groups>1`, condition :math:`C_{in}` = :math:`C_{out}` = `groups` must be satisfied.
|
|
5437
5121
|
|
|
5438
5122
|
Args:
|
|
5439
5123
|
input (Tensor): Tensor of shape :math:`(N, C_{in}, H_{in}, W_{in})`.
|
|
@@ -5478,7 +5162,7 @@ def conv2d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5478
5162
|
TypeError: If `stride`, `padding` or `dilation` is neither an int nor a tuple.
|
|
5479
5163
|
TypeError: `groups` is not an int.
|
|
5480
5164
|
TypeError: If `bias` is not a Tensor.
|
|
5481
|
-
ValueError: If the shape of `bias` is not :math:`C_{out}` .
|
|
5165
|
+
ValueError: If the shape of `bias` is not :math:`(C_{out})` .
|
|
5482
5166
|
ValueError: If `stride` or `dilation` is less than 1.
|
|
5483
5167
|
ValueError: If `pad_mode` is not one of 'same', 'valid' or 'pad'.
|
|
5484
5168
|
ValueError: If `padding` is a tuple/list whose length is not equal to 2.
|
|
@@ -5539,6 +5223,11 @@ def hardsigmoid(input):
|
|
|
5539
5223
|
|
|
5540
5224
|
where :math:`x_i` is an element of the input Tensor.
|
|
5541
5225
|
|
|
5226
|
+
HSigmoid Activation Function Graph:
|
|
5227
|
+
|
|
5228
|
+
.. image:: ../images/HSigmoid.png
|
|
5229
|
+
:align: center
|
|
5230
|
+
|
|
5542
5231
|
Args:
|
|
5543
5232
|
input (Tensor): The input Tensor.
|
|
5544
5233
|
|
|
@@ -5578,10 +5267,15 @@ def hardtanh(input, min_val=-1.0, max_val=1.0):
|
|
|
5578
5267
|
|
|
5579
5268
|
Linear region range :math:`[min\_val, max\_val]` can be adjusted using `min_val` and `max_val`.
|
|
5580
5269
|
|
|
5270
|
+
Hardtanh Activation Function Graph:
|
|
5271
|
+
|
|
5272
|
+
.. image:: ../images/Hardtanh.png
|
|
5273
|
+
:align: center
|
|
5274
|
+
|
|
5581
5275
|
Args:
|
|
5582
5276
|
input (Tensor): Input Tensor.
|
|
5583
|
-
min_val (Union[int, float]): Minimum value of the linear region range. Default: ``-1.0`` .
|
|
5584
|
-
max_val (Union[int, float]): Maximum value of the linear region range. Default: ``1.0`` .
|
|
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`` .
|
|
5585
5279
|
|
|
5586
5280
|
Returns:
|
|
5587
5281
|
Tensor, with the same dtype and shape as `input`.
|
|
@@ -5606,18 +5300,18 @@ def hardtanh(input, min_val=-1.0, max_val=1.0):
|
|
|
5606
5300
|
_check_value_type("min_val", min_val, [int, float], "hardtanh")
|
|
5607
5301
|
_check_value_type("max_val", max_val, [int, float], "hardtanh")
|
|
5608
5302
|
input_dtype = input.dtype
|
|
5609
|
-
input =
|
|
5610
|
-
input =
|
|
5303
|
+
input = maximum_(input, min_val)
|
|
5304
|
+
input = minimum_(input, max_val)
|
|
5611
5305
|
return input.astype(input_dtype)
|
|
5612
5306
|
|
|
5613
5307
|
|
|
5614
5308
|
def huber_loss(input, target, reduction='mean', delta=1.0):
|
|
5615
5309
|
r"""
|
|
5616
5310
|
Calculates the error between the predicted value and the target value,
|
|
5617
|
-
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`.
|
|
5618
5312
|
|
|
5619
5313
|
Assuming that the :math:`x` and :math:`y` are 1-D Tensor, length :math:`N`, the `reduction` parameter
|
|
5620
|
-
is set to ``
|
|
5314
|
+
is set to ``'none'`` then calculate the loss of :math:`x` and :math:`y` without dimensionality reduction.
|
|
5621
5315
|
The formula is as follows:
|
|
5622
5316
|
|
|
5623
5317
|
.. math::
|
|
@@ -5658,14 +5352,14 @@ def huber_loss(input, target, reduction='mean', delta=1.0):
|
|
|
5658
5352
|
The value must be greater than zero. Default: ``1.0`` .
|
|
5659
5353
|
|
|
5660
5354
|
Returns:
|
|
5661
|
-
Tensor or Scalar, if `reduction` is ``
|
|
5355
|
+
Tensor or Scalar, if `reduction` is ``'none'``, return a Tensor with same shape and dtype as `input`.
|
|
5662
5356
|
Otherwise, a scalar value will be returned.
|
|
5663
5357
|
|
|
5664
5358
|
Raises:
|
|
5665
5359
|
TypeError: If `input` or `target` is not a Tensor.
|
|
5666
5360
|
TypeError: If dtype of `delta` is neither float nor int.
|
|
5667
5361
|
ValueError: If `delta` is less than or equal to 0.
|
|
5668
|
-
ValueError: If `reduction` is not one of ``
|
|
5362
|
+
ValueError: If `reduction` is not one of ``'none'``, ``'mean'``, ``'sum'``.
|
|
5669
5363
|
ValueError: If `input` and `target` have different shapes and cannot be broadcasted to each other.
|
|
5670
5364
|
|
|
5671
5365
|
Supported Platforms:
|
|
@@ -5684,14 +5378,12 @@ def huber_loss(input, target, reduction='mean', delta=1.0):
|
|
|
5684
5378
|
_check_is_tensor('target', target, "huber_loss")
|
|
5685
5379
|
_check_value_type("delta", delta, [int, float], "huber_loss")
|
|
5686
5380
|
_check_number_gt_value("delta", delta, 0.0, "huber_loss")
|
|
5687
|
-
|
|
5688
|
-
|
|
5689
|
-
|
|
5690
|
-
|
|
5691
|
-
|
|
5692
|
-
|
|
5693
|
-
l2 = multi(delta, sub(z, 0.5 * delta))
|
|
5694
|
-
loss = _get_cache_prim(P.Select)()(cond, l1, l2)
|
|
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)
|
|
5695
5387
|
return _get_loss(loss, reduction, "huber_loss")
|
|
5696
5388
|
|
|
5697
5389
|
|
|
@@ -5743,7 +5435,7 @@ def adaptive_avg_pool1d(input, output_size):
|
|
|
5743
5435
|
"""
|
|
5744
5436
|
def _check(x, output_size):
|
|
5745
5437
|
x_in_shape = x.shape
|
|
5746
|
-
x_dtype =
|
|
5438
|
+
x_dtype = dtype_(x)
|
|
5747
5439
|
if not isinstance(x, (Tensor, Tensor_)):
|
|
5748
5440
|
raise TypeError("For adaptive_avg_pool1d, the input input must be tensor")
|
|
5749
5441
|
|
|
@@ -5763,21 +5455,16 @@ def adaptive_avg_pool1d(input, output_size):
|
|
|
5763
5455
|
|
|
5764
5456
|
_check(input, output_size)
|
|
5765
5457
|
x_in_shape = input.shape
|
|
5766
|
-
expand_ = _get_cache_prim(P.ExpandDims)()
|
|
5767
5458
|
squeeze_ = _get_cache_prim(P.Squeeze)(2)
|
|
5768
|
-
|
|
5769
5459
|
width = x_in_shape[2]
|
|
5770
5460
|
stride = width // output_size
|
|
5771
5461
|
kernel_size = width - (output_size - 1) * stride
|
|
5772
5462
|
stride = (1, width // output_size)
|
|
5773
5463
|
kernel_size = (1, kernel_size)
|
|
5774
|
-
|
|
5775
5464
|
avg_pool_ = _get_cache_prim(P.AvgPool)(kernel_size=kernel_size, strides=stride)
|
|
5776
|
-
|
|
5777
|
-
input = expand_(input, 2)
|
|
5465
|
+
input = expand_dims_(input, 2)
|
|
5778
5466
|
input = avg_pool_(input)
|
|
5779
5467
|
input = squeeze_(input)
|
|
5780
|
-
|
|
5781
5468
|
return input
|
|
5782
5469
|
|
|
5783
5470
|
|
|
@@ -5800,7 +5487,8 @@ def batch_norm(input_x, running_mean, running_var, weight, bias, training=False,
|
|
|
5800
5487
|
mean of :math:`x`, :math:`variance` is the variance of :math:`x`.
|
|
5801
5488
|
|
|
5802
5489
|
.. warning::
|
|
5803
|
-
- For
|
|
5490
|
+
- For Atlas 200/300/500 inference product,
|
|
5491
|
+
the result accuracy fails to reach 1‰ due to the square root instruction.
|
|
5804
5492
|
|
|
5805
5493
|
Note:
|
|
5806
5494
|
- If `training` is `False`, `weight`, `bias`, `running_mean` and `running_var` are Tensors.
|
|
@@ -5962,7 +5650,7 @@ def conv3d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5962
5650
|
r"""
|
|
5963
5651
|
Applies a 3D convolution over an input tensor. The input tensor is typically of
|
|
5964
5652
|
shape :math:`(N, C_{in}, D_{in}, H_{in}, W_{in})`, where :math:`N` is batch size, :math:`C`
|
|
5965
|
-
is channel number, :math:`D`
|
|
5653
|
+
is channel number, :math:`D, H, W` are the depth, height and width of the feature graph, respectively.
|
|
5966
5654
|
|
|
5967
5655
|
The output is calculated based on formula:
|
|
5968
5656
|
|
|
@@ -5972,26 +5660,30 @@ def conv3d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
5972
5660
|
\sum_{k = 0}^{C_{in} - 1} \text{ccor}({\text{weight}(C_{\text{out}_j}, k), \text{X}(N_i, k)})
|
|
5973
5661
|
|
|
5974
5662
|
where :math:`bias` is the output channel bias, :math:`ccor` is
|
|
5975
|
-
the `cross-correlation <https://en.wikipedia.org/wiki/Cross-correlation>`_
|
|
5663
|
+
the `cross-correlation <https://en.wikipedia.org/wiki/Cross-correlation>`_
|
|
5976
5664
|
, :math:`weight` is the convolution kernel value and :math:`X` represents the input feature map.
|
|
5977
5665
|
|
|
5978
5666
|
Here are the indices' meanings:
|
|
5979
|
-
- :math:`i` corresponds to the batch number, ranging from 0 to N-1, where N is the batch size of the input.
|
|
5980
5667
|
|
|
5981
|
-
- :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
|
|
5982
5673
|
output channels, which is also equal to the number of kernels.
|
|
5983
5674
|
|
|
5984
|
-
- :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
|
|
5985
5677
|
input channels, which is also equal to the number of channels in the convolutional kernels.
|
|
5986
5678
|
|
|
5987
|
-
Therefore, in the above formula, :math:`{bias}(C_{
|
|
5988
|
-
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
|
|
5989
5681
|
kernel in the :math:`k`-th channel, and :math:`{X}(N_i, k)` represents the slice of the :math:`k`-th input
|
|
5990
5682
|
channel in the :math:`i`-th batch of the input feature map.
|
|
5991
5683
|
|
|
5992
5684
|
The shape of the convolutional kernel is given by
|
|
5993
5685
|
:math:`(\text{kernel_size[0]}, \text{kernel_size[1]}, \text{kernel_size[2]})`
|
|
5994
|
-
where :math
|
|
5686
|
+
where :math:`\text{kernel_size[0]}` , :math:`\text{kernel_size[1]}` and :math:`\text{kernel_size[2]}` are the depth,
|
|
5995
5687
|
height and width of the kernel, respectively.
|
|
5996
5688
|
If we consider the input and output channels as well as the `group` parameter, the complete kernel shape
|
|
5997
5689
|
will be :math:`(C_{out}, C_{in} / \text{group}, \text{kernel_size[0]},
|
|
@@ -6002,8 +5694,8 @@ def conv3d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
6002
5694
|
<http://vision.stanford.edu/cs598_spring07/papers/Lecun98.pdf>`_.
|
|
6003
5695
|
|
|
6004
5696
|
Note:
|
|
6005
|
-
1. On Ascend platform,
|
|
6006
|
-
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.
|
|
6007
5699
|
|
|
6008
5700
|
Args:
|
|
6009
5701
|
input (Tensor): Tensor of shape :math:`(N, C_{in}, D_{in}, H_{in}, W_{in})`.
|
|
@@ -6042,8 +5734,7 @@ def conv3d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
6042
5734
|
there will be :math:`k - 1` pixels skipped for each sampling location.
|
|
6043
5735
|
The value ranges for the depth, height, and width dimensions are [1, D], [1, H], and [1, W],
|
|
6044
5736
|
respectively. Default: ``1`` .
|
|
6045
|
-
groups (int, optional):The number of groups into which the filter is divided.
|
|
6046
|
-
and `out_channels` must be divisible by `group`. Default: ``1`` .
|
|
5737
|
+
groups (int, optional):The number of groups into which the filter is divided. Default: ``1`` .
|
|
6047
5738
|
|
|
6048
5739
|
Returns:
|
|
6049
5740
|
Tensor, the value that applied 3D convolution. The shape is :math:`(N, C_{out}, D_{out}, H_{out}, W_{out})`.
|
|
@@ -6085,7 +5776,7 @@ def conv3d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
6085
5776
|
TypeError: If `out_channel` or `groups` is not an int.
|
|
6086
5777
|
TypeError: If `stride`, `padding` or `dilation` is neither an int nor a tuple.
|
|
6087
5778
|
TypeError: If `bias` is not a Tensor.
|
|
6088
|
-
ValueError: If the shape of `bias` is not :math:`C_{out}`.
|
|
5779
|
+
ValueError: If the shape of `bias` is not :math:`(C_{out})`.
|
|
6089
5780
|
ValueError: If `stride` or `dilation` is less than 1.
|
|
6090
5781
|
ValueError: If `pad_mode` is not one of 'same', 'valid' or 'pad'.
|
|
6091
5782
|
ValueError: If `padding` is a tuple or list whose length is not equal to 3.
|
|
@@ -6193,21 +5884,19 @@ def pixel_shuffle(input, upscale_factor):
|
|
|
6193
5884
|
_check_positive_int(upscale_factor, "upscale_factor")
|
|
6194
5885
|
_check_is_tensor("input", input, "pixel_shuffle")
|
|
6195
5886
|
_check_pixel_shuffle_unshuffle_input_shape(input, "pixel_shuffle")
|
|
6196
|
-
idx =
|
|
5887
|
+
idx = shape_(input)
|
|
6197
5888
|
length = input.ndim
|
|
6198
5889
|
pre = idx[:-3]
|
|
6199
5890
|
c, h, w = idx[-3:]
|
|
6200
5891
|
_check_pxiel_shuffle_valid(c, upscale_factor)
|
|
6201
5892
|
c = c // upscale_factor ** 2
|
|
6202
5893
|
input_perm = (pre + (c, upscale_factor, upscale_factor, h, w))
|
|
6203
|
-
|
|
6204
|
-
transpose = _get_cache_prim(P.Transpose)()
|
|
6205
|
-
input = reshape(input, input_perm)
|
|
5894
|
+
input = reshape_(input, input_perm)
|
|
6206
5895
|
input_perm = [i for i in range(length - 2)]
|
|
6207
5896
|
input_perm = input_perm + [length, length - 2, length + 1, length - 1]
|
|
6208
5897
|
input_perm = tuple(input_perm)
|
|
6209
|
-
input =
|
|
6210
|
-
input =
|
|
5898
|
+
input = transpose_(input, input_perm)
|
|
5899
|
+
input = reshape_(input, (pre + (c, upscale_factor * h, upscale_factor * w)))
|
|
6211
5900
|
return input
|
|
6212
5901
|
|
|
6213
5902
|
|
|
@@ -6258,7 +5947,7 @@ def pixel_unshuffle(input, downscale_factor):
|
|
|
6258
5947
|
_check_positive_int(downscale_factor, "downscale_factor")
|
|
6259
5948
|
_check_is_tensor("input", input, "pixel_unshuffle")
|
|
6260
5949
|
_check_pixel_shuffle_unshuffle_input_shape(input, "pixel_unshuffle")
|
|
6261
|
-
idx =
|
|
5950
|
+
idx = shape_(input)
|
|
6262
5951
|
length = input.ndim
|
|
6263
5952
|
pre = idx[:-3]
|
|
6264
5953
|
c, h, w = idx[-3:]
|
|
@@ -6266,14 +5955,12 @@ def pixel_unshuffle(input, downscale_factor):
|
|
|
6266
5955
|
h = h // downscale_factor
|
|
6267
5956
|
w = w // downscale_factor
|
|
6268
5957
|
input_perm = (pre + (c, h, downscale_factor, w, downscale_factor))
|
|
6269
|
-
|
|
6270
|
-
transpose = _get_cache_prim(P.Transpose)()
|
|
6271
|
-
input = reshape(input, input_perm)
|
|
5958
|
+
input = reshape_(input, input_perm)
|
|
6272
5959
|
input_perm = [i for i in range(length - 2)]
|
|
6273
5960
|
input_perm = input_perm + [length - 1, length + 1, length - 2, length]
|
|
6274
5961
|
input_perm = tuple(input_perm)
|
|
6275
|
-
input =
|
|
6276
|
-
input =
|
|
5962
|
+
input = transpose_(input, input_perm)
|
|
5963
|
+
input = reshape_(input, (pre + (c * downscale_factor * downscale_factor, h, w)))
|
|
6277
5964
|
return input
|
|
6278
5965
|
|
|
6279
5966
|
|
|
@@ -6290,7 +5977,7 @@ def glu(x, axis=-1):
|
|
|
6290
5977
|
See `Language Modeling with Gated Convluational Networks <https://arxiv.org/abs/1612.08083>`_.
|
|
6291
5978
|
|
|
6292
5979
|
Args:
|
|
6293
|
-
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)`
|
|
6294
5981
|
where `*` means, any number of additional dimensions.
|
|
6295
5982
|
axis (int, optional): the axis to split the input. It must be int. Default: ``-1`` , the last axis of `x`.
|
|
6296
5983
|
|
|
@@ -6312,9 +5999,6 @@ def glu(x, axis=-1):
|
|
|
6312
5999
|
[[0.05744425 0.11973753]
|
|
6313
6000
|
[0.33409387 0.41398472]]
|
|
6314
6001
|
"""
|
|
6315
|
-
if not isinstance(x, Tensor) or x.size == 0:
|
|
6316
|
-
raise TypeError("glu does not support scalars because halving size must be even")
|
|
6317
|
-
|
|
6318
6002
|
spilt = _get_cache_prim(P.Split)(axis=axis, output_num=2)
|
|
6319
6003
|
x, y = spilt(x)
|
|
6320
6004
|
y = sigmoid_(y)
|
|
@@ -6334,7 +6018,7 @@ def multi_margin_loss(input, target, p=1, margin=1, weight=None, reduction='mean
|
|
|
6334
6018
|
.. math::
|
|
6335
6019
|
\text{loss}(x, y) = \frac{\sum_i \max(0, \text{margin} - x[y] + x[i])^p}{\text{x.size}(0)}
|
|
6336
6020
|
|
|
6337
|
-
where :math:`i\in \{0,⋯,x.size(0)
|
|
6021
|
+
where :math:`i\in \{0,⋯,x.size(0)-1\}` and :math:`i \ne y`.
|
|
6338
6022
|
|
|
6339
6023
|
Args:
|
|
6340
6024
|
input (Tensor): Input , with shape :math:`(N, C)`. Data type only support float32, float16 or float64.
|
|
@@ -6353,8 +6037,8 @@ def multi_margin_loss(input, target, p=1, margin=1, weight=None, reduction='mean
|
|
|
6353
6037
|
- ``'sum'``: the output elements will be summed.
|
|
6354
6038
|
|
|
6355
6039
|
Returns:
|
|
6356
|
-
Tensor. If `reduction` is ``'none'``, returns a Tensor with the same shape as `target`.
|
|
6357
|
-
|
|
6040
|
+
- **outputs** - Tensor. If `reduction` is ``'none'``, returns a Tensor with the same shape as `target`.
|
|
6041
|
+
Otherwise, it is a scalar.
|
|
6358
6042
|
|
|
6359
6043
|
Raises:
|
|
6360
6044
|
TypeError: If dtype of `p` or `target` is not int.
|
|
@@ -6413,10 +6097,11 @@ def multilabel_margin_loss(input, target, reduction='mean'):
|
|
|
6413
6097
|
This allows for different samples to have variable amounts of target classes.
|
|
6414
6098
|
|
|
6415
6099
|
Args:
|
|
6416
|
-
input (Tensor): Predict data. Tensor of shape :math:`(C)`
|
|
6417
|
-
is the batch size and :math:`C` is the number of classes.
|
|
6418
|
-
|
|
6419
|
-
|
|
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.
|
|
6420
6105
|
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
6421
6106
|
``'sum'`` . Default: ``'mean'`` .
|
|
6422
6107
|
|
|
@@ -6492,9 +6177,6 @@ def multilabel_soft_margin_loss(input, target, weight=None, reduction='mean'):
|
|
|
6492
6177
|
Tensor, the data type is the same as input, if the `reduction` is ``'none'``,
|
|
6493
6178
|
its shape is :math:`(N)` , otherwise it is zero.
|
|
6494
6179
|
|
|
6495
|
-
Raises:
|
|
6496
|
-
ValueError: If the rank of `input` or `target` is not 2.
|
|
6497
|
-
|
|
6498
6180
|
Supported Platforms:
|
|
6499
6181
|
``Ascend`` ``GPU`` ``CPU``
|
|
6500
6182
|
|
|
@@ -6509,81 +6191,22 @@ def multilabel_soft_margin_loss(input, target, weight=None, reduction='mean'):
|
|
|
6509
6191
|
cls_name = "multilabel_soft_margin_loss"
|
|
6510
6192
|
_check_is_tensor('input', input, cls_name)
|
|
6511
6193
|
_check_is_tensor('target', target, cls_name)
|
|
6512
|
-
if input.ndim != 2 or target.ndim != 2:
|
|
6513
|
-
raise ValueError(
|
|
6514
|
-
"For 'MultiLabelSoftMarginLoss', the inputs must be 2d tensor, but got dims: "
|
|
6515
|
-
f"input: {input.ndim}, target: {target.ndim} "
|
|
6516
|
-
)
|
|
6517
6194
|
|
|
6518
|
-
mul_op = _get_cache_prim(P.Mul)()
|
|
6519
|
-
exp_op = _get_cache_prim(P.Exp)()
|
|
6520
|
-
add_op = _get_cache_prim(P.Add)()
|
|
6521
|
-
log_op = _get_cache_prim(P.Log)()
|
|
6522
|
-
dyn_shape = _get_cache_prim(P.TensorShape)()
|
|
6523
6195
|
input_shape = input.shape
|
|
6524
6196
|
if ops.is_sequence_value_unknown(input_shape):
|
|
6525
|
-
input_shape =
|
|
6197
|
+
input_shape = tensor_shape_(input)
|
|
6526
6198
|
|
|
6527
|
-
pos =
|
|
6528
|
-
neg =
|
|
6529
|
-
loss =
|
|
6199
|
+
pos = log_(add_(exp_(-input), 1))
|
|
6200
|
+
neg = log_(add_(exp_(input), 1))
|
|
6201
|
+
loss = mul_(target, pos) + mul_(1 - target, neg)
|
|
6530
6202
|
if weight is not None:
|
|
6531
|
-
loss =
|
|
6203
|
+
loss = mul_(loss, weight)
|
|
6532
6204
|
class_dim = input.ndim - 1
|
|
6533
6205
|
loss = loss.sum(axis=class_dim) / input_shape[class_dim]
|
|
6534
6206
|
return _get_loss(loss, reduction, cls_name)
|
|
6535
6207
|
|
|
6536
6208
|
|
|
6537
|
-
def
|
|
6538
|
-
r"""
|
|
6539
|
-
Exponential Linear Unit activation function.
|
|
6540
|
-
|
|
6541
|
-
Applies the exponential linear unit function element-wise.
|
|
6542
|
-
The activation function is defined as:
|
|
6543
|
-
|
|
6544
|
-
.. math::
|
|
6545
|
-
|
|
6546
|
-
\text{ELU}(x)= \left\{
|
|
6547
|
-
\begin{array}{align}
|
|
6548
|
-
\alpha(e^{x} - 1) & \text{if } x \le 0\\
|
|
6549
|
-
x & \text{if } x \gt 0\\
|
|
6550
|
-
\end{array}\right.
|
|
6551
|
-
|
|
6552
|
-
Where :math:`x` is the element of input Tensor `input_x`, :math:`\alpha` is param `alpha`,
|
|
6553
|
-
it determines the smoothness of ELU.
|
|
6554
|
-
The picture about ELU looks like this `ELU <https://en.wikipedia.org/wiki/
|
|
6555
|
-
Activation_function#/media/File:Activation_elu.svg>`_ .
|
|
6556
|
-
|
|
6557
|
-
Args:
|
|
6558
|
-
input_x (Tensor): The input of ELU is a Tensor of any dimension with data type of float16 or float32.
|
|
6559
|
-
alpha (float, optional): The alpha value of ELU, the data type is float. Only support '1.0' currently.
|
|
6560
|
-
Default: ``1.0`` .
|
|
6561
|
-
|
|
6562
|
-
Returns:
|
|
6563
|
-
Tensor, has the same shape and data type as `input_x`.
|
|
6564
|
-
|
|
6565
|
-
Raises:
|
|
6566
|
-
TypeError: If `alpha` is not a float.
|
|
6567
|
-
TypeError: If dtype of `input_x` is neither float16 nor float32.
|
|
6568
|
-
ValueError: If `alpha` is not equal to 1.0.
|
|
6569
|
-
|
|
6570
|
-
Supported Platforms:
|
|
6571
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
6572
|
-
|
|
6573
|
-
Examples:
|
|
6574
|
-
>>> import mindspore
|
|
6575
|
-
>>> import numpy as np
|
|
6576
|
-
>>> from mindspore import Tensor, ops
|
|
6577
|
-
>>> x = Tensor(np.array([[-1.0, 4.0, -8.0], [2.0, -5.0, 9.0]]), mindspore.float32)
|
|
6578
|
-
>>> output = ops.elu(x)
|
|
6579
|
-
>>> print(output)
|
|
6580
|
-
[[-0.63212055 4. -0.99966455]
|
|
6581
|
-
[ 2. -0.99326205 9. ]]
|
|
6582
|
-
"""
|
|
6583
|
-
return _get_cache_prim(P.Elu)(alpha=alpha)(input_x)
|
|
6584
|
-
|
|
6585
|
-
|
|
6586
|
-
def gelu(input_x, approximate='none'):
|
|
6209
|
+
def gelu(input, approximate='none'):
|
|
6587
6210
|
r"""
|
|
6588
6211
|
Gaussian Error Linear Units activation function.
|
|
6589
6212
|
|
|
@@ -6604,18 +6227,25 @@ def gelu(input_x, approximate='none'):
|
|
|
6604
6227
|
.. math::
|
|
6605
6228
|
GELU(x_i) = 0.5 * x_i * (1 + \tanh(\sqrt(2 / \pi) * (x_i + 0.044715 * x_i^3)))
|
|
6606
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
|
+
|
|
6607
6237
|
Args:
|
|
6608
|
-
|
|
6238
|
+
input (Tensor): The input of the activation function GeLU, the data type is float16, float32 or float64.
|
|
6609
6239
|
approximate (str): the gelu approximation algorithm to use. Acceptable vaslues are ``'none'`` and ``'tanh'`` .
|
|
6610
6240
|
Default: ``'none'`` .
|
|
6611
6241
|
|
|
6612
6242
|
Returns:
|
|
6613
|
-
Tensor, with the same type and shape as `
|
|
6243
|
+
Tensor, with the same type and shape as `input`.
|
|
6614
6244
|
|
|
6615
6245
|
Raises:
|
|
6616
|
-
TypeError: If `
|
|
6617
|
-
TypeError: If dtype of `
|
|
6618
|
-
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`.
|
|
6619
6249
|
|
|
6620
6250
|
Supported Platforms:
|
|
6621
6251
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -6631,17 +6261,17 @@ def gelu(input_x, approximate='none'):
|
|
|
6631
6261
|
if approximate not in ['none', 'tanh']:
|
|
6632
6262
|
raise ValueError("For ops.gelu, approximate value should be either 'none' or 'tanh'.")
|
|
6633
6263
|
|
|
6634
|
-
x_dtype =
|
|
6635
|
-
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]:
|
|
6636
6266
|
raise TypeError(f"For gelu, the input dtype must be float16, float32 or float64, "
|
|
6637
6267
|
f"but got {x_dtype}.")
|
|
6638
6268
|
if approximate == 'tanh':
|
|
6639
|
-
output =
|
|
6269
|
+
output = gelu_(input)
|
|
6640
6270
|
else:
|
|
6641
|
-
output =
|
|
6642
|
-
output =
|
|
6643
|
-
output =
|
|
6644
|
-
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)
|
|
6645
6275
|
|
|
6646
6276
|
return output
|
|
6647
6277
|
|
|
@@ -6691,13 +6321,6 @@ def channel_shuffle(x, groups):
|
|
|
6691
6321
|
return y
|
|
6692
6322
|
|
|
6693
6323
|
|
|
6694
|
-
@_primexpr
|
|
6695
|
-
def _shape_check(in_shape, dim_list, prim_name=None):
|
|
6696
|
-
msg_prefix = f"For '{prim_name}', the" if prim_name else "The"
|
|
6697
|
-
if len(in_shape) not in dim_list:
|
|
6698
|
-
raise ValueError(f"{msg_prefix} input must has dim in {dim_list}, but got {len(in_shape)}")
|
|
6699
|
-
|
|
6700
|
-
|
|
6701
6324
|
def lp_pool1d(x, norm_type, kernel_size, stride=None, ceil_mode=False):
|
|
6702
6325
|
r"""
|
|
6703
6326
|
Applying 1D LPPooling operation on an input Tensor can be regarded as forming a 1D input plane.
|
|
@@ -6733,7 +6356,7 @@ def lp_pool1d(x, norm_type, kernel_size, stride=None, ceil_mode=False):
|
|
|
6733
6356
|
L_{out} = \left\lfloor\frac{L_{in} - \text{kernel_size}}{\text{stride}} + 1\right\rfloor
|
|
6734
6357
|
|
|
6735
6358
|
Raises:
|
|
6736
|
-
TypeError: If `x` is not
|
|
6359
|
+
TypeError: If `x` is not a Tensor.
|
|
6737
6360
|
TypeError: If `kernel_size` or `stride` is not an int.
|
|
6738
6361
|
TypeError: If `ceil_mode` is not a bool.
|
|
6739
6362
|
TypeError: If `norm_type` is neither float nor int.
|
|
@@ -6759,7 +6382,6 @@ def lp_pool1d(x, norm_type, kernel_size, stride=None, ceil_mode=False):
|
|
|
6759
6382
|
[51. 54.]
|
|
6760
6383
|
[63. 66.]]]
|
|
6761
6384
|
"""
|
|
6762
|
-
_shape_check(x.shape, [2, 3], "lp_pool1d")
|
|
6763
6385
|
if isinstance(norm_type, (float, int)):
|
|
6764
6386
|
norm_type = float(norm_type)
|
|
6765
6387
|
else:
|
|
@@ -6818,7 +6440,7 @@ def lp_pool2d(x, norm_type, kernel_size, stride=None, ceil_mode=False):
|
|
|
6818
6440
|
W_{out} = \left\lfloor\frac{W_{in} - \text{kernel_size}[1]}{\text{stride}[1]} + 1\right\rfloor
|
|
6819
6441
|
|
|
6820
6442
|
Raises:
|
|
6821
|
-
TypeError: If `x` is not
|
|
6443
|
+
TypeError: If `x` is not a Tensor.
|
|
6822
6444
|
TypeError: If `kernel_size` or `stride` is neither int nor tuple.
|
|
6823
6445
|
TypeError: If `ceil_mode` is not a bool.
|
|
6824
6446
|
TypeError: If `norm_type` is neither float nor int.
|
|
@@ -6852,7 +6474,6 @@ def lp_pool2d(x, norm_type, kernel_size, stride=None, ceil_mode=False):
|
|
|
6852
6474
|
[ 999. 1008. 1017.]]]]
|
|
6853
6475
|
|
|
6854
6476
|
"""
|
|
6855
|
-
_shape_check(x.shape, [4], "lp_pool2d")
|
|
6856
6477
|
if isinstance(norm_type, (float, int)):
|
|
6857
6478
|
norm_type = float(norm_type)
|
|
6858
6479
|
else:
|
|
@@ -6915,13 +6536,13 @@ def mse_loss(input, target, reduction='mean'):
|
|
|
6915
6536
|
if reduction not in ['mean', 'none', 'sum']:
|
|
6916
6537
|
raise ValueError("For ops.mse_loss, `reduction` value should be either 'mean', 'none' or 'sum'.")
|
|
6917
6538
|
|
|
6918
|
-
x =
|
|
6539
|
+
x = square_(input - target)
|
|
6919
6540
|
float_type = (mstype.float16, mstype.float32, mstype.float64)
|
|
6920
6541
|
if x.dtype not in float_type:
|
|
6921
6542
|
input_dtype = mstype.float32
|
|
6922
6543
|
else:
|
|
6923
6544
|
input_dtype = x.dtype
|
|
6924
|
-
x =
|
|
6545
|
+
x = cast_(x, mstype.float32)
|
|
6925
6546
|
|
|
6926
6547
|
average_flag = True
|
|
6927
6548
|
reduce_flag = True
|
|
@@ -6931,12 +6552,12 @@ def mse_loss(input, target, reduction='mean'):
|
|
|
6931
6552
|
reduce_flag = False
|
|
6932
6553
|
|
|
6933
6554
|
if reduce_flag and average_flag:
|
|
6934
|
-
x =
|
|
6555
|
+
x = reduce_mean_(x, _get_axis(x))
|
|
6935
6556
|
|
|
6936
6557
|
if reduce_flag and not average_flag:
|
|
6937
|
-
x =
|
|
6558
|
+
x = reduce_sum_(x, _get_axis(x))
|
|
6938
6559
|
|
|
6939
|
-
return
|
|
6560
|
+
return cast_(x, input_dtype)
|
|
6940
6561
|
|
|
6941
6562
|
|
|
6942
6563
|
def msort(input):
|
|
@@ -6998,7 +6619,7 @@ def triplet_margin_loss(anchor, positive, negative, margin=1.0, p=2, eps=1e-06,
|
|
|
6998
6619
|
Tensor. If `reduction` is ``"none"``, its shape is :math:`(N)`. Otherwise, a scalar value will be returned.
|
|
6999
6620
|
|
|
7000
6621
|
Raises:
|
|
7001
|
-
TypeError: If `anchor` or `positive` or
|
|
6622
|
+
TypeError: If `anchor` or `positive` or `negative` is not a Tensor.
|
|
7002
6623
|
TypeError: If dtype of `anchor`, `positive` and `negative` is not the same.
|
|
7003
6624
|
TypeError: If `margin` is not a float.
|
|
7004
6625
|
TypeError: If `p` is not an int.
|
|
@@ -7337,7 +6958,7 @@ def multi_head_attention_forward(query, key, value, embed_dim_to_check, num_head
|
|
|
7337
6958
|
|
|
7338
6959
|
if attn_mask is not None and attn_mask.dtype == mstype.bool_:
|
|
7339
6960
|
new_attn_mask = ops.zeros_like(attn_mask, dtype=q.dtype)
|
|
7340
|
-
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))
|
|
7341
6962
|
|
|
7342
6963
|
if attn_mask is not None:
|
|
7343
6964
|
if attn_mask.shape[0] == 1:
|
|
@@ -7446,11 +7067,10 @@ def max_pool2d(x, kernel_size, stride=None, padding=0, dilation=1, return_indice
|
|
|
7446
7067
|
return out
|
|
7447
7068
|
|
|
7448
7069
|
|
|
7449
|
-
def prompt_flash_attention(query, key, value, attn_mask, actual_seq_lengths,
|
|
7450
|
-
|
|
7451
|
-
|
|
7452
|
-
|
|
7453
|
-
num_key_value_heads=0, sparse_mode=0):
|
|
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):
|
|
7454
7074
|
r"""
|
|
7455
7075
|
The interface for fully inference.
|
|
7456
7076
|
B -- Batch size
|
|
@@ -7458,7 +7078,7 @@ def prompt_flash_attention(query, key, value, attn_mask, actual_seq_lengths,
|
|
|
7458
7078
|
H -- Hidden size
|
|
7459
7079
|
|
|
7460
7080
|
Note:
|
|
7461
|
-
|
|
7081
|
+
experiment ops
|
|
7462
7082
|
|
|
7463
7083
|
.. warning::
|
|
7464
7084
|
This is an experimental API that is subject to change or deletion.
|
|
@@ -7472,8 +7092,8 @@ def prompt_flash_attention(query, key, value, attn_mask, actual_seq_lengths,
|
|
|
7472
7092
|
Input tensor of shape :math:`(B, S, H)` / `(B, N, S, D)`.
|
|
7473
7093
|
attn_mask (Tensor) - The attention mask tensor with data type of float16 or float32.
|
|
7474
7094
|
For each element, 0 indicates retention and 1 indicates discard. Input tensor of shape :math:`(B, 1, S, S)`.
|
|
7475
|
-
actual_seq_lengths (
|
|
7476
|
-
actual_seq_lengths_kv (
|
|
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.
|
|
7477
7097
|
pse_shift (Tensor) - The position encoding tensor with data type of float16 or float32.
|
|
7478
7098
|
dep_scale1 (Tensor)
|
|
7479
7099
|
quant_scale1 (Tensor)
|
|
@@ -7491,6 +7111,7 @@ def prompt_flash_attention(query, key, value, attn_mask, actual_seq_lengths,
|
|
|
7491
7111
|
num_key_value_heads (int): head numbers of key/value which are used in GQA algorithm.
|
|
7492
7112
|
The value o indicates if the key and value have the same head nums, use numHeads. Default: 0.
|
|
7493
7113
|
sparse_mode (int): Default: 0
|
|
7114
|
+
inner_precise (int): 0, float16 high precision. 1, high performance. default 1
|
|
7494
7115
|
|
|
7495
7116
|
|
|
7496
7117
|
Outputs:
|
|
@@ -7512,16 +7133,74 @@ def prompt_flash_attention(query, key, value, attn_mask, actual_seq_lengths,
|
|
|
7512
7133
|
>>> value = Tensor(np.ones((B, N, S, D), dtype=np.float16))
|
|
7513
7134
|
>>> out = ops.prompt_flash_attention(query, key, value, None, None, None, None, None, None, None, None,
|
|
7514
7135
|
None, N, input_layout='BNSD')
|
|
7515
|
-
>>> print(out
|
|
7136
|
+
>>> print(out.shape)
|
|
7516
7137
|
(1, 16, 256, 16)
|
|
7517
7138
|
"""
|
|
7518
7139
|
|
|
7519
7140
|
pfa = _get_cache_prim(NN_OPS.PromptFlashAttention)(num_heads, scale_value, pre_tokens, next_tokens, input_layout,
|
|
7520
|
-
num_key_value_heads, sparse_mode)
|
|
7141
|
+
num_key_value_heads, sparse_mode, inner_precise)
|
|
7521
7142
|
return pfa(query, key, value, attn_mask, actual_seq_lengths, actual_seq_lengths_kv, pse_shift, deq_scale1,
|
|
7522
7143
|
quant_scale1, deq_scale2, quant_scale2, quant_offset2)
|
|
7523
7144
|
|
|
7524
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
|
+
|
|
7525
7204
|
__all__ = [
|
|
7526
7205
|
'adaptive_avg_pool1d',
|
|
7527
7206
|
'adaptive_avg_pool2d',
|