mindspore 2.2.11__cp39-cp39-win_amd64.whl → 2.3.0__cp39-cp39-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of mindspore might be problematic. Click here for more details.
- mindspore/.commit_id +1 -1
- mindspore/__init__.py +7 -5
- mindspore/_c_dataengine.cp39-win_amd64.pyd +0 -0
- mindspore/_c_expression.cp39-win_amd64.pyd +0 -0
- mindspore/_c_mindrecord.cp39-win_amd64.pyd +0 -0
- mindspore/_checkparam.py +76 -18
- mindspore/_extends/builtin_operations.py +2 -1
- mindspore/_extends/graph_kernel/model/graph_parallel.py +16 -6
- mindspore/_extends/parallel_compile/akg_compiler/akg_process.py +3 -16
- mindspore/_extends/parallel_compile/akg_compiler/build_tbe_kernel.py +16 -4
- mindspore/_extends/parallel_compile/akg_compiler/compiler.py +1 -0
- mindspore/_extends/parallel_compile/akg_compiler/gen_custom_op_files.py +96 -0
- mindspore/_extends/parallel_compile/akg_compiler/tbe_topi.py +2 -1
- mindspore/_extends/parallel_compile/akg_compiler/util.py +5 -2
- mindspore/_extends/parse/__init__.py +18 -14
- mindspore/_extends/parse/compile_config.py +258 -0
- mindspore/_extends/parse/namespace.py +2 -2
- mindspore/_extends/parse/parser.py +174 -62
- mindspore/_extends/parse/resources.py +45 -14
- mindspore/_extends/parse/standard_method.py +142 -240
- mindspore/{ops/_op_impl/tbe/atomic_addr_clean.py → _extends/pijit/__init__.py} +6 -16
- mindspore/_extends/pijit/pijit_func_white_list.py +343 -0
- mindspore/_extends/remote/kernel_build_server.py +2 -0
- mindspore/_profiler.py +30 -0
- mindspore/amp.py +51 -24
- mindspore/avcodec-59.dll +0 -0
- mindspore/avdevice-59.dll +0 -0
- mindspore/avfilter-8.dll +0 -0
- mindspore/avformat-59.dll +0 -0
- mindspore/avutil-57.dll +0 -0
- mindspore/boost/adasum.py +1 -1
- mindspore/boost/base.py +1 -1
- mindspore/boost/boost_cell_wrapper.py +2 -2
- mindspore/boost/grad_freeze.py +2 -2
- mindspore/boost/group_loss_scale_manager.py +1 -1
- mindspore/boost/less_batch_normalization.py +9 -6
- mindspore/common/__init__.py +15 -4
- mindspore/common/_jit_fallback_utils.py +2 -3
- mindspore/common/_register_for_adapter.py +7 -0
- mindspore/common/_register_for_recompute.py +48 -0
- mindspore/common/_register_for_tensor.py +8 -9
- mindspore/common/_stub_tensor.py +7 -1
- mindspore/common/_utils.py +5 -17
- mindspore/common/api.py +411 -106
- mindspore/common/auto_dynamic_shape.py +27 -14
- mindspore/common/dtype.py +17 -10
- mindspore/common/dump.py +6 -8
- mindspore/common/file_system.py +48 -0
- mindspore/common/generator.py +260 -0
- mindspore/common/hook_handle.py +51 -4
- mindspore/common/initializer.py +1 -1
- mindspore/common/jit_config.py +34 -14
- mindspore/common/lazy_inline.py +72 -19
- mindspore/common/mindir_util.py +12 -2
- mindspore/common/mutable.py +79 -14
- mindspore/common/no_inline.py +54 -0
- mindspore/common/np_dtype.py +25 -0
- mindspore/common/parameter.py +30 -11
- mindspore/common/recompute.py +262 -0
- mindspore/common/seed.py +9 -9
- mindspore/common/sparse_tensor.py +272 -24
- mindspore/common/symbol.py +122 -0
- mindspore/common/tensor.py +468 -496
- mindspore/communication/__init__.py +6 -11
- mindspore/communication/_comm_helper.py +5 -0
- mindspore/communication/comm_func.py +1140 -0
- mindspore/communication/management.py +118 -102
- mindspore/config/op_info.config +22 -54
- mindspore/context.py +378 -65
- 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 +163 -83
- mindspore/dataset/engine/datasets_audio.py +14 -14
- mindspore/dataset/engine/datasets_standard_format.py +33 -3
- mindspore/dataset/engine/datasets_text.py +38 -38
- mindspore/dataset/engine/datasets_user_defined.py +78 -59
- mindspore/dataset/engine/datasets_vision.py +77 -73
- mindspore/dataset/engine/offload.py +5 -7
- mindspore/dataset/engine/queue.py +56 -38
- mindspore/dataset/engine/validators.py +11 -5
- mindspore/dataset/text/__init__.py +3 -3
- mindspore/dataset/text/transforms.py +408 -121
- mindspore/dataset/text/utils.py +9 -9
- mindspore/dataset/transforms/__init__.py +1 -1
- mindspore/dataset/transforms/transforms.py +261 -76
- mindspore/dataset/utils/browse_dataset.py +9 -9
- mindspore/dataset/vision/__init__.py +8 -8
- mindspore/dataset/vision/c_transforms.py +10 -10
- mindspore/dataset/vision/py_transforms_util.py +3 -3
- mindspore/dataset/vision/transforms.py +2844 -549
- mindspore/dataset/vision/utils.py +161 -10
- mindspore/dataset/vision/validators.py +14 -2
- mindspore/dnnl.dll +0 -0
- mindspore/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 +71 -127
- mindspore/experimental/optim/nadam.py +157 -0
- mindspore/experimental/optim/optimizer.py +15 -8
- mindspore/experimental/optim/radam.py +194 -0
- mindspore/experimental/optim/rmsprop.py +154 -0
- mindspore/experimental/optim/rprop.py +164 -0
- mindspore/experimental/optim/sgd.py +28 -19
- mindspore/hal/__init__.py +40 -0
- mindspore/hal/_ascend.py +57 -0
- mindspore/hal/_base.py +57 -0
- mindspore/hal/_cpu.py +56 -0
- mindspore/hal/_gpu.py +57 -0
- mindspore/hal/device.py +356 -0
- mindspore/hal/event.py +179 -0
- mindspore/hal/memory.py +326 -0
- mindspore/hal/stream.py +339 -0
- mindspore/include/api/data_type.h +2 -2
- mindspore/include/api/dual_abi_helper.h +16 -3
- mindspore/include/api/model.h +4 -3
- mindspore/include/api/status.h +14 -0
- mindspore/include/c_api/model_c.h +173 -0
- mindspore/include/c_api/ms/base/types.h +1 -0
- mindspore/include/c_api/types_c.h +19 -0
- mindspore/include/dataset/execute.h +1 -3
- mindspore/include/dataset/vision.h +54 -2
- mindspore/jpeg62.dll +0 -0
- mindspore/log.py +2 -2
- mindspore/mindrecord/__init__.py +5 -1
- mindspore/mindrecord/config.py +809 -0
- mindspore/mindrecord/filereader.py +25 -0
- mindspore/mindrecord/filewriter.py +76 -58
- mindspore/mindrecord/mindpage.py +40 -6
- mindspore/mindrecord/shardutils.py +3 -2
- mindspore/mindrecord/shardwriter.py +7 -0
- mindspore/mindrecord/tools/cifar100_to_mr.py +53 -66
- mindspore/mindrecord/tools/cifar10_to_mr.py +48 -63
- mindspore/mindrecord/tools/csv_to_mr.py +7 -17
- mindspore/mindrecord/tools/imagenet_to_mr.py +3 -8
- mindspore/mindrecord/tools/mnist_to_mr.py +11 -21
- mindspore/mindrecord/tools/tfrecord_to_mr.py +2 -10
- mindspore/mindspore_backend.dll +0 -0
- mindspore/mindspore_common.dll +0 -0
- mindspore/mindspore_core.dll +0 -0
- mindspore/mindspore_glog.dll +0 -0
- mindspore/mindspore_np_dtype.dll +0 -0
- mindspore/mindspore_shared_lib.dll +0 -0
- mindspore/mint/__init__.py +1137 -0
- mindspore/{rewrite/ast_transformers → mint/linalg}/__init__.py +9 -4
- mindspore/mint/nn/__init__.py +512 -0
- mindspore/mint/nn/functional.py +573 -0
- mindspore/mint/optim/__init__.py +24 -0
- mindspore/mint/optim/adamw.py +185 -0
- mindspore/multiprocessing/__init__.py +72 -0
- mindspore/nn/__init__.py +1 -0
- mindspore/nn/cell.py +213 -257
- mindspore/nn/dynamic_lr.py +2 -2
- mindspore/nn/extend/__init__.py +29 -0
- mindspore/nn/extend/basic.py +140 -0
- mindspore/nn/extend/embedding.py +143 -0
- mindspore/{rewrite/ast_creator_register.py → nn/extend/layer/__init__.py} +9 -19
- mindspore/nn/extend/layer/normalization.py +109 -0
- mindspore/nn/extend/pooling.py +117 -0
- mindspore/nn/layer/activation.py +84 -94
- mindspore/nn/layer/basic.py +177 -82
- mindspore/nn/layer/channel_shuffle.py +3 -16
- mindspore/nn/layer/container.py +3 -3
- mindspore/nn/layer/conv.py +75 -66
- mindspore/nn/layer/embedding.py +103 -45
- mindspore/nn/layer/embedding_service.py +531 -0
- mindspore/nn/layer/embedding_service_layer.py +393 -0
- mindspore/nn/layer/image.py +4 -7
- mindspore/nn/layer/math.py +1 -1
- mindspore/nn/layer/normalization.py +52 -66
- mindspore/nn/layer/padding.py +30 -39
- mindspore/nn/layer/pooling.py +18 -9
- mindspore/nn/layer/rnn_cells.py +6 -16
- mindspore/nn/layer/rnns.py +6 -5
- mindspore/nn/layer/thor_layer.py +1 -2
- mindspore/nn/layer/timedistributed.py +1 -1
- mindspore/nn/layer/transformer.py +52 -50
- mindspore/nn/learning_rate_schedule.py +6 -5
- mindspore/nn/loss/loss.py +63 -84
- mindspore/nn/optim/ada_grad.py +6 -4
- mindspore/nn/optim/adadelta.py +3 -1
- mindspore/nn/optim/adafactor.py +1 -1
- mindspore/nn/optim/adam.py +102 -181
- mindspore/nn/optim/adamax.py +4 -2
- mindspore/nn/optim/adasum.py +3 -3
- mindspore/nn/optim/asgd.py +4 -2
- mindspore/nn/optim/ftrl.py +31 -61
- mindspore/nn/optim/lamb.py +5 -3
- mindspore/nn/optim/lars.py +2 -2
- mindspore/nn/optim/lazyadam.py +6 -4
- mindspore/nn/optim/momentum.py +13 -25
- mindspore/nn/optim/optimizer.py +6 -3
- mindspore/nn/optim/proximal_ada_grad.py +4 -2
- mindspore/nn/optim/rmsprop.py +9 -3
- mindspore/nn/optim/rprop.py +4 -2
- mindspore/nn/optim/sgd.py +7 -4
- mindspore/nn/optim/thor.py +2 -2
- mindspore/nn/probability/distribution/_utils/custom_ops.py +2 -2
- mindspore/nn/probability/distribution/beta.py +2 -2
- mindspore/nn/probability/distribution/categorical.py +4 -6
- mindspore/nn/probability/distribution/cauchy.py +2 -2
- mindspore/nn/probability/distribution/exponential.py +2 -2
- mindspore/nn/probability/distribution/geometric.py +1 -1
- mindspore/nn/probability/distribution/gumbel.py +2 -2
- mindspore/nn/probability/distribution/logistic.py +1 -1
- mindspore/nn/probability/distribution/poisson.py +2 -2
- mindspore/nn/probability/distribution/uniform.py +2 -2
- mindspore/nn/reinforcement/_tensors_queue.py +13 -1
- mindspore/nn/wrap/__init__.py +2 -1
- mindspore/nn/wrap/cell_wrapper.py +58 -13
- mindspore/nn/wrap/grad_reducer.py +148 -8
- mindspore/nn/wrap/loss_scale.py +32 -9
- mindspore/numpy/__init__.py +2 -0
- mindspore/numpy/array_creations.py +2 -0
- mindspore/numpy/array_ops.py +6 -6
- mindspore/numpy/dtypes.py +3 -3
- mindspore/numpy/fft.py +431 -0
- mindspore/numpy/math_ops.py +61 -67
- mindspore/numpy/utils.py +3 -0
- mindspore/opencv_core452.dll +0 -0
- mindspore/opencv_imgcodecs452.dll +0 -0
- mindspore/opencv_imgproc452.dll +0 -0
- mindspore/ops/__init__.py +8 -4
- mindspore/ops/_grad_experimental/grad_array_ops.py +4 -160
- mindspore/ops/_grad_experimental/grad_comm_ops.py +93 -36
- mindspore/ops/_grad_experimental/grad_inner_ops.py +8 -0
- mindspore/ops/_grad_experimental/grad_math_ops.py +92 -287
- mindspore/ops/_grad_experimental/grad_nn_ops.py +0 -53
- mindspore/ops/_grad_experimental/grad_quant_ops.py +3 -3
- mindspore/ops/_grad_experimental/grad_sparse.py +1 -1
- mindspore/ops/_grad_experimental/grad_sparse_ops.py +3 -3
- mindspore/ops/_op_impl/__init__.py +0 -1
- mindspore/ops/_op_impl/aicpu/__init__.py +1 -0
- mindspore/ops/_op_impl/aicpu/gamma.py +2 -0
- mindspore/ops/_op_impl/{cpu/concat.py → aicpu/generate_eod_mask.py} +16 -17
- mindspore/ops/_op_impl/aicpu/log_uniform_candidate_sampler.py +1 -3
- mindspore/ops/_op_impl/aicpu/poisson.py +2 -0
- mindspore/ops/_op_impl/cpu/__init__.py +1 -3
- mindspore/ops/_op_impl/cpu/adam.py +2 -2
- mindspore/ops/_op_impl/cpu/adam_weight_decay.py +3 -2
- mindspore/ops/_op_impl/cpu/maximum_grad.py +16 -14
- mindspore/ops/_op_impl/cpu/minimum_grad.py +8 -0
- mindspore/ops/_vmap/vmap_array_ops.py +164 -101
- mindspore/ops/_vmap/vmap_base.py +8 -1
- mindspore/ops/_vmap/vmap_grad_math_ops.py +95 -9
- mindspore/ops/_vmap/vmap_grad_nn_ops.py +143 -58
- mindspore/ops/_vmap/vmap_image_ops.py +70 -13
- mindspore/ops/_vmap/vmap_math_ops.py +130 -58
- mindspore/ops/_vmap/vmap_nn_ops.py +249 -115
- mindspore/ops/_vmap/vmap_other_ops.py +1 -1
- mindspore/ops/auto_generate/__init__.py +31 -0
- mindspore/ops/auto_generate/cpp_create_prim_instance_helper.py +231 -0
- mindspore/ops/auto_generate/gen_arg_dtype_cast.py +250 -0
- mindspore/ops/auto_generate/gen_arg_handler.py +197 -0
- mindspore/ops/auto_generate/gen_extend_func.py +980 -0
- mindspore/ops/auto_generate/gen_ops_def.py +6443 -0
- mindspore/ops/auto_generate/gen_ops_prim.py +13167 -0
- mindspore/ops/auto_generate/pyboost_inner_prim.py +429 -0
- mindspore/ops/composite/__init__.py +5 -2
- mindspore/ops/composite/base.py +121 -23
- mindspore/ops/composite/math_ops.py +10 -49
- mindspore/ops/composite/multitype_ops/_compile_utils.py +191 -618
- mindspore/ops/composite/multitype_ops/_constexpr_utils.py +25 -134
- mindspore/ops/composite/multitype_ops/add_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/bitwise_and_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/bitwise_or_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/bitwise_xor_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/div_impl.py +8 -0
- mindspore/ops/composite/multitype_ops/equal_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/floordiv_impl.py +8 -0
- mindspore/ops/composite/multitype_ops/getitem_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/greater_equal_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/greater_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/in_impl.py +8 -2
- mindspore/ops/composite/multitype_ops/left_shift_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/less_equal_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/less_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/logic_not_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/logical_and_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/logical_or_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/mod_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/mul_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/negative_impl.py +9 -3
- mindspore/ops/composite/multitype_ops/not_equal_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/not_in_impl.py +6 -1
- mindspore/ops/composite/multitype_ops/ones_like_impl.py +2 -2
- mindspore/ops/composite/multitype_ops/pow_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/right_shift_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/setitem_impl.py +32 -21
- mindspore/ops/composite/multitype_ops/sub_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/zeros_like_impl.py +6 -3
- mindspore/ops/deprecated.py +14 -3
- mindspore/ops/extend/__init__.py +53 -0
- mindspore/ops/extend/array_func.py +218 -0
- mindspore/ops/extend/math_func.py +76 -0
- mindspore/ops/extend/nn_func.py +308 -0
- mindspore/ops/function/__init__.py +31 -11
- mindspore/ops/function/array_func.py +848 -1736
- mindspore/ops/function/clip_func.py +19 -31
- mindspore/ops/function/debug_func.py +2 -5
- mindspore/ops/function/fft_func.py +31 -0
- mindspore/ops/function/grad/grad_func.py +27 -20
- mindspore/ops/function/image_func.py +27 -21
- mindspore/ops/function/linalg_func.py +30 -53
- mindspore/ops/function/math_func.py +916 -2791
- mindspore/ops/function/nn_func.py +1445 -889
- mindspore/ops/function/other_func.py +6 -7
- mindspore/ops/function/parameter_func.py +6 -92
- mindspore/ops/function/random_func.py +254 -108
- mindspore/ops/function/reshard_func.py +102 -0
- mindspore/ops/function/sparse_func.py +4 -4
- mindspore/ops/function/sparse_unary_func.py +11 -18
- mindspore/ops/function/spectral_func.py +1 -1
- mindspore/ops/function/vmap_func.py +15 -14
- mindspore/ops/functional.py +342 -343
- mindspore/ops/op_info_register.py +16 -43
- mindspore/ops/operations/__init__.py +32 -23
- mindspore/ops/operations/_embedding_cache_ops.py +1 -1
- mindspore/ops/operations/_grad_ops.py +21 -853
- mindspore/ops/operations/_infer_ops.py +19 -0
- mindspore/ops/operations/_inner_ops.py +155 -511
- mindspore/ops/operations/_quant_ops.py +4 -4
- mindspore/ops/operations/_rl_inner_ops.py +3 -3
- mindspore/ops/operations/_scalar_ops.py +5 -480
- mindspore/ops/operations/_sequence_ops.py +6 -36
- mindspore/ops/operations/_tensor_array.py +8 -8
- mindspore/ops/operations/array_ops.py +112 -2698
- mindspore/ops/operations/comm_ops.py +801 -118
- mindspore/ops/operations/custom_ops.py +62 -121
- mindspore/ops/operations/debug_ops.py +105 -36
- mindspore/ops/operations/image_ops.py +3 -219
- mindspore/ops/operations/inner_ops.py +54 -40
- mindspore/ops/operations/linalg_ops.py +1 -49
- mindspore/ops/operations/manually_defined/__init__.py +24 -0
- mindspore/ops/operations/manually_defined/_inner.py +61 -0
- mindspore/ops/operations/manually_defined/ops_def.py +2016 -0
- mindspore/ops/operations/math_ops.py +621 -4654
- mindspore/ops/operations/nn_ops.py +316 -2226
- mindspore/ops/operations/other_ops.py +53 -45
- mindspore/ops/operations/random_ops.py +4 -51
- mindspore/ops/operations/reshard_ops.py +53 -0
- mindspore/ops/operations/sparse_ops.py +8 -8
- mindspore/ops/primitive.py +204 -103
- mindspore/ops/silent_check.py +162 -0
- mindspore/ops_generate/__init__.py +27 -0
- mindspore/ops_generate/arg_dtype_cast.py +250 -0
- mindspore/ops_generate/arg_handler.py +197 -0
- mindspore/ops_generate/gen_aclnn_implement.py +263 -0
- mindspore/ops_generate/gen_ops.py +1084 -0
- mindspore/ops_generate/gen_ops_inner_prim.py +131 -0
- mindspore/ops_generate/gen_pyboost_func.py +968 -0
- mindspore/ops_generate/gen_utils.py +209 -0
- mindspore/ops_generate/op_proto.py +138 -0
- mindspore/ops_generate/pyboost_utils.py +354 -0
- mindspore/ops_generate/template.py +239 -0
- mindspore/parallel/__init__.py +7 -4
- mindspore/parallel/_auto_parallel_context.py +155 -6
- 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 +62 -14
- mindspore/parallel/_ps_context.py +1 -1
- mindspore/parallel/_recovery_context.py +1 -1
- mindspore/parallel/_tensor.py +18 -9
- 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 +10 -10
- mindspore/parallel/_utils.py +161 -6
- mindspore/parallel/algo_parameter_config.py +6 -8
- mindspore/parallel/checkpoint_transform.py +369 -64
- mindspore/parallel/cluster/__init__.py +15 -0
- mindspore/parallel/cluster/process_entity/__init__.py +18 -0
- mindspore/parallel/cluster/process_entity/_api.py +344 -0
- mindspore/parallel/cluster/process_entity/_utils.py +126 -0
- mindspore/parallel/cluster/run.py +136 -0
- mindspore/parallel/mpi/__init__.py +1 -1
- mindspore/parallel/mpi/_mpi_config.py +1 -1
- mindspore/parallel/parameter_broadcast.py +152 -0
- mindspore/parallel/shard.py +128 -17
- mindspore/profiler/__init__.py +3 -2
- mindspore/profiler/common/process_pool.py +41 -0
- mindspore/profiler/common/singleton.py +28 -0
- mindspore/profiler/common/util.py +125 -0
- mindspore/profiler/envprofiling.py +2 -2
- mindspore/{_extends/parallel_compile/tbe_compiler → profiler/parser/ascend_analysis}/__init__.py +1 -1
- mindspore/profiler/parser/ascend_analysis/constant.py +53 -0
- mindspore/profiler/parser/ascend_analysis/file_manager.py +159 -0
- mindspore/profiler/parser/ascend_analysis/function_event.py +161 -0
- mindspore/profiler/parser/ascend_analysis/fwk_cann_parser.py +131 -0
- mindspore/profiler/parser/ascend_analysis/fwk_file_parser.py +85 -0
- mindspore/profiler/parser/ascend_analysis/msprof_timeline_parser.py +57 -0
- mindspore/profiler/parser/ascend_analysis/profiler_info_parser.py +116 -0
- mindspore/profiler/parser/ascend_analysis/tlv_decoder.py +86 -0
- mindspore/profiler/parser/ascend_analysis/trace_event_manager.py +68 -0
- mindspore/profiler/parser/ascend_cluster_generator.py +116 -0
- mindspore/profiler/parser/ascend_communicate_generator.py +314 -0
- mindspore/profiler/parser/ascend_flops_generator.py +27 -5
- mindspore/profiler/parser/ascend_fpbp_generator.py +8 -2
- mindspore/profiler/parser/ascend_hccl_generator.py +31 -280
- mindspore/profiler/parser/ascend_integrate_generator.py +42 -0
- mindspore/profiler/parser/ascend_memory_generator.py +185 -0
- mindspore/profiler/parser/ascend_msprof_exporter.py +151 -126
- mindspore/profiler/parser/ascend_msprof_generator.py +75 -274
- mindspore/profiler/parser/ascend_op_generator.py +94 -36
- mindspore/profiler/parser/ascend_timeline_generator.py +297 -131
- mindspore/profiler/parser/base_timeline_generator.py +17 -3
- mindspore/profiler/parser/cpu_gpu_timeline_generator.py +2 -1
- mindspore/profiler/parser/framework_parser.py +11 -4
- mindspore/profiler/parser/integrator.py +3 -1
- mindspore/profiler/parser/memory_usage_parser.py +8 -2
- mindspore/profiler/parser/minddata_analyzer.py +8 -2
- mindspore/profiler/parser/minddata_parser.py +73 -4
- mindspore/profiler/parser/msadvisor_analyzer.py +5 -3
- mindspore/profiler/parser/msadvisor_parser.py +10 -4
- mindspore/profiler/parser/profiler_info.py +16 -1
- mindspore/profiler/profiling.py +522 -195
- mindspore/rewrite/__init__.py +2 -13
- mindspore/rewrite/api/node.py +123 -37
- mindspore/rewrite/api/pattern_engine.py +2 -3
- mindspore/rewrite/api/scoped_value.py +16 -15
- mindspore/rewrite/api/symbol_tree.py +46 -30
- mindspore/rewrite/ast_helpers/__init__.py +3 -6
- mindspore/rewrite/ast_helpers/ast_converter.py +143 -0
- mindspore/rewrite/ast_helpers/ast_finder.py +48 -0
- mindspore/rewrite/ast_helpers/ast_flattener.py +268 -0
- mindspore/rewrite/ast_helpers/ast_modifier.py +160 -92
- mindspore/rewrite/common/__init__.py +1 -2
- mindspore/rewrite/common/config.py +24 -0
- mindspore/rewrite/common/{rewrite_elog.py → error_log.py} +39 -39
- mindspore/rewrite/{namer.py → common/namer.py} +63 -18
- mindspore/rewrite/common/namespace.py +118 -0
- mindspore/rewrite/node/__init__.py +5 -5
- mindspore/rewrite/node/call_function.py +23 -7
- mindspore/rewrite/node/cell_container.py +7 -3
- mindspore/rewrite/node/control_flow.py +53 -28
- mindspore/rewrite/node/node.py +212 -196
- mindspore/rewrite/node/node_manager.py +51 -22
- mindspore/rewrite/node/node_topological_manager.py +3 -23
- mindspore/rewrite/parsers/__init__.py +12 -0
- mindspore/rewrite/parsers/arguments_parser.py +8 -9
- mindspore/rewrite/parsers/assign_parser.py +637 -413
- mindspore/rewrite/parsers/attribute_parser.py +3 -4
- mindspore/rewrite/parsers/class_def_parser.py +115 -148
- mindspore/rewrite/parsers/constant_parser.py +5 -5
- mindspore/rewrite/parsers/container_parser.py +4 -6
- mindspore/rewrite/parsers/expr_parser.py +55 -0
- mindspore/rewrite/parsers/for_parser.py +31 -98
- mindspore/rewrite/parsers/function_def_parser.py +13 -5
- mindspore/rewrite/parsers/if_parser.py +28 -10
- mindspore/rewrite/parsers/module_parser.py +8 -182
- mindspore/rewrite/parsers/parser.py +1 -5
- mindspore/rewrite/parsers/parser_register.py +1 -1
- mindspore/rewrite/parsers/return_parser.py +5 -10
- mindspore/rewrite/parsers/while_parser.py +59 -0
- mindspore/rewrite/sparsify/utils.py +1 -1
- mindspore/rewrite/symbol_tree/__init__.py +20 -0
- mindspore/rewrite/{symbol_tree.py → symbol_tree/symbol_tree.py} +704 -185
- mindspore/rewrite/{symbol_tree_builder.py → symbol_tree/symbol_tree_builder.py} +8 -8
- mindspore/rewrite/{symbol_tree_dumper.py → symbol_tree/symbol_tree_dumper.py} +4 -4
- mindspore/run_check/_check_version.py +6 -14
- mindspore/run_check/run_check.py +1 -1
- mindspore/safeguard/rewrite_obfuscation.py +9 -19
- mindspore/swresample-4.dll +0 -0
- mindspore/swscale-6.dll +0 -0
- mindspore/tinyxml2.dll +0 -0
- mindspore/train/__init__.py +6 -5
- mindspore/train/_utils.py +178 -4
- mindspore/train/amp.py +167 -245
- mindspore/train/anf_ir_pb2.py +14 -2
- mindspore/train/callback/__init__.py +5 -2
- mindspore/train/callback/_backup_and_restore.py +5 -5
- mindspore/train/callback/_callback.py +4 -4
- mindspore/train/callback/_checkpoint.py +151 -37
- mindspore/train/callback/_cluster_monitor.py +201 -0
- mindspore/train/callback/_early_stop.py +2 -2
- mindspore/train/callback/_flops_collector.py +238 -0
- mindspore/train/callback/_landscape.py +16 -11
- mindspore/train/callback/_loss_monitor.py +2 -2
- mindspore/train/callback/_mindio_ttp.py +443 -0
- mindspore/train/callback/_on_request_exit.py +2 -2
- mindspore/train/callback/_reduce_lr_on_plateau.py +2 -2
- mindspore/train/callback/_summary_collector.py +13 -14
- mindspore/train/callback/_time_monitor.py +3 -3
- mindspore/train/data_sink.py +6 -5
- mindspore/train/dataset_helper.py +66 -21
- mindspore/train/loss_scale_manager.py +2 -2
- mindspore/train/metrics/accuracy.py +7 -7
- mindspore/train/metrics/confusion_matrix.py +8 -6
- mindspore/train/metrics/cosine_similarity.py +6 -4
- mindspore/train/metrics/error.py +2 -2
- mindspore/train/metrics/metric.py +3 -3
- mindspore/train/metrics/perplexity.py +2 -1
- mindspore/train/metrics/topk.py +2 -2
- mindspore/train/mind_ir_pb2.py +89 -15
- mindspore/train/model.py +298 -56
- mindspore/train/serialization.py +501 -221
- mindspore/train/summary/_summary_adapter.py +1 -1
- mindspore/train/summary/_writer_pool.py +1 -1
- mindspore/train/summary/summary_record.py +56 -34
- mindspore/train/train_thor/convert_utils.py +3 -3
- mindspore/turbojpeg.dll +0 -0
- mindspore/version.py +1 -1
- {mindspore-2.2.11.dist-info → mindspore-2.3.0.dist-info}/METADATA +3 -3
- mindspore-2.3.0.dist-info/RECORD +1400 -0
- {mindspore-2.2.11.dist-info → mindspore-2.3.0.dist-info}/entry_points.txt +1 -0
- mindspore/_extends/parallel_compile/tbe_compiler/tbe_adapter.py +0 -662
- mindspore/_extends/parallel_compile/tbe_compiler/tbe_helper.py +0 -377
- mindspore/_extends/parallel_compile/tbe_compiler/tbe_job.py +0 -201
- mindspore/_extends/parallel_compile/tbe_compiler/tbe_job_manager.py +0 -515
- mindspore/gen_ops.py +0 -273
- mindspore/nn/layer/flash_attention.py +0 -189
- mindspore/ops/_op_impl/cpu/tensor_shape.py +0 -42
- mindspore/ops/_op_impl/tbe/__init__.py +0 -47
- mindspore/ops/_op_impl/tbe/abs.py +0 -38
- mindspore/ops/_op_impl/tbe/abs_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/abs_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/abs_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/accumulate_n_v2.py +0 -41
- mindspore/ops/_op_impl/tbe/accumulate_n_v2_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/acos.py +0 -37
- mindspore/ops/_op_impl/tbe/acos_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/acos_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/acos_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/acosh.py +0 -37
- mindspore/ops/_op_impl/tbe/acosh_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/acosh_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/acosh_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/act_ulq_clamp_max_grad.py +0 -38
- mindspore/ops/_op_impl/tbe/act_ulq_clamp_min_grad.py +0 -38
- mindspore/ops/_op_impl/tbe/acts_ulq.py +0 -45
- mindspore/ops/_op_impl/tbe/acts_ulq_input_grad.py +0 -38
- mindspore/ops/_op_impl/tbe/adam_apply_one.py +0 -50
- mindspore/ops/_op_impl/tbe/adam_apply_one_assign.py +0 -53
- mindspore/ops/_op_impl/tbe/adam_apply_one_ds.py +0 -51
- mindspore/ops/_op_impl/tbe/adam_apply_one_with_decay.py +0 -54
- mindspore/ops/_op_impl/tbe/adam_apply_one_with_decay_assign.py +0 -54
- mindspore/ops/_op_impl/tbe/adam_apply_one_with_decay_ds.py +0 -55
- mindspore/ops/_op_impl/tbe/adaptive_max_pool2d.py +0 -37
- mindspore/ops/_op_impl/tbe/add.py +0 -42
- mindspore/ops/_op_impl/tbe/add_ds.py +0 -43
- mindspore/ops/_op_impl/tbe/add_n.py +0 -39
- mindspore/ops/_op_impl/tbe/add_n_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/addcdiv.py +0 -41
- mindspore/ops/_op_impl/tbe/addcdiv_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/addcmul.py +0 -43
- mindspore/ops/_op_impl/tbe/addcmul_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/apply_ada_max.py +0 -68
- mindspore/ops/_op_impl/tbe/apply_ada_max_ds.py +0 -69
- mindspore/ops/_op_impl/tbe/apply_adadelta.py +0 -66
- mindspore/ops/_op_impl/tbe/apply_adadelta_ds.py +0 -67
- mindspore/ops/_op_impl/tbe/apply_adagrad.py +0 -55
- mindspore/ops/_op_impl/tbe/apply_adagrad_d_a.py +0 -67
- mindspore/ops/_op_impl/tbe/apply_adagrad_ds.py +0 -56
- mindspore/ops/_op_impl/tbe/apply_adagrad_v2.py +0 -48
- mindspore/ops/_op_impl/tbe/apply_adagrad_v2_ds.py +0 -49
- mindspore/ops/_op_impl/tbe/apply_adam.py +0 -79
- mindspore/ops/_op_impl/tbe/apply_adam_ds.py +0 -80
- mindspore/ops/_op_impl/tbe/apply_adam_with_amsgrad.py +0 -60
- mindspore/ops/_op_impl/tbe/apply_adam_with_amsgrad_ds.py +0 -61
- mindspore/ops/_op_impl/tbe/apply_add_sign.py +0 -65
- mindspore/ops/_op_impl/tbe/apply_add_sign_ds.py +0 -66
- mindspore/ops/_op_impl/tbe/apply_centered_rms_prop.py +0 -77
- mindspore/ops/_op_impl/tbe/apply_centered_rms_prop_ds.py +0 -78
- mindspore/ops/_op_impl/tbe/apply_ftrl.py +0 -67
- mindspore/ops/_op_impl/tbe/apply_ftrl_ds.py +0 -68
- mindspore/ops/_op_impl/tbe/apply_gradient_descent.py +0 -44
- mindspore/ops/_op_impl/tbe/apply_gradient_descent_ds.py +0 -45
- mindspore/ops/_op_impl/tbe/apply_keras_momentum.py +0 -49
- mindspore/ops/_op_impl/tbe/apply_momentum.py +0 -64
- mindspore/ops/_op_impl/tbe/apply_momentum_ds.py +0 -65
- mindspore/ops/_op_impl/tbe/apply_power_sign.py +0 -65
- mindspore/ops/_op_impl/tbe/apply_power_sign_ds.py +0 -66
- mindspore/ops/_op_impl/tbe/apply_proximal_adagrad.py +0 -57
- mindspore/ops/_op_impl/tbe/apply_proximal_adagrad_ds.py +0 -58
- mindspore/ops/_op_impl/tbe/apply_proximal_gradient_descent.py +0 -54
- mindspore/ops/_op_impl/tbe/apply_proximal_gradient_descent_ds.py +0 -55
- mindspore/ops/_op_impl/tbe/apply_rms_prop.py +0 -52
- mindspore/ops/_op_impl/tbe/approximate_equal.py +0 -39
- mindspore/ops/_op_impl/tbe/approximate_equal_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/arg_max.py +0 -38
- mindspore/ops/_op_impl/tbe/arg_max_with_value.py +0 -38
- mindspore/ops/_op_impl/tbe/arg_max_with_value_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/arg_min.py +0 -38
- mindspore/ops/_op_impl/tbe/arg_min_v2_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/arg_min_with_value.py +0 -38
- mindspore/ops/_op_impl/tbe/arg_min_with_value_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/asin.py +0 -37
- mindspore/ops/_op_impl/tbe/asin_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/asin_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/asin_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/asinh.py +0 -37
- mindspore/ops/_op_impl/tbe/asinh_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/asinh_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/asinh_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/assign.py +0 -79
- mindspore/ops/_op_impl/tbe/assign_add.py +0 -59
- mindspore/ops/_op_impl/tbe/assign_add_ds.py +0 -60
- mindspore/ops/_op_impl/tbe/assign_ds.py +0 -80
- mindspore/ops/_op_impl/tbe/assign_sub.py +0 -55
- mindspore/ops/_op_impl/tbe/assign_sub_ds.py +0 -56
- mindspore/ops/_op_impl/tbe/atan.py +0 -37
- mindspore/ops/_op_impl/tbe/atan2.py +0 -38
- mindspore/ops/_op_impl/tbe/atan2_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/atan_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/atan_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/atan_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/atanh.py +0 -37
- mindspore/ops/_op_impl/tbe/atanh_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/avg_pool.py +0 -43
- mindspore/ops/_op_impl/tbe/avg_pool_3d.py +0 -44
- mindspore/ops/_op_impl/tbe/avg_pool_3d_grad.py +0 -45
- mindspore/ops/_op_impl/tbe/avg_pool_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/avg_pool_grad.py +0 -42
- mindspore/ops/_op_impl/tbe/avg_pool_grad_vm.py +0 -42
- mindspore/ops/_op_impl/tbe/basic_lstm_cell.py +0 -57
- mindspore/ops/_op_impl/tbe/basic_lstm_cell_c_state_grad.py +0 -50
- mindspore/ops/_op_impl/tbe/basic_lstm_cell_c_state_grad_v2.py +0 -51
- mindspore/ops/_op_impl/tbe/basic_lstm_cell_input_grad.py +0 -42
- mindspore/ops/_op_impl/tbe/basic_lstm_cell_weight_grad.py +0 -41
- mindspore/ops/_op_impl/tbe/batch_matmul.py +0 -42
- mindspore/ops/_op_impl/tbe/batch_matmul_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/batch_matmul_v2.py +0 -47
- mindspore/ops/_op_impl/tbe/batch_to_space.py +0 -38
- mindspore/ops/_op_impl/tbe/batch_to_space_nd.py +0 -38
- mindspore/ops/_op_impl/tbe/batch_to_space_nd_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/batch_to_space_nd_v2.py +0 -41
- mindspore/ops/_op_impl/tbe/batchnorm.py +0 -58
- mindspore/ops/_op_impl/tbe/batchnorm_grad.py +0 -58
- mindspore/ops/_op_impl/tbe/bce_with_logits_loss.py +0 -42
- mindspore/ops/_op_impl/tbe/bessel_i0e.py +0 -37
- mindspore/ops/_op_impl/tbe/bessel_i0e_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/bessel_i1e.py +0 -37
- mindspore/ops/_op_impl/tbe/bessel_i1e_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/bias_add.py +0 -38
- mindspore/ops/_op_impl/tbe/bias_add_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/bias_add_grad.py +0 -53
- mindspore/ops/_op_impl/tbe/binary_cross_entropy.py +0 -39
- mindspore/ops/_op_impl/tbe/binary_cross_entropy_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/binary_cross_entropy_grad.py +0 -44
- mindspore/ops/_op_impl/tbe/binary_cross_entropy_grad_ds.py +0 -45
- mindspore/ops/_op_impl/tbe/bitwise_and.py +0 -39
- mindspore/ops/_op_impl/tbe/bitwise_and_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/bitwise_or.py +0 -39
- mindspore/ops/_op_impl/tbe/bitwise_or_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/bitwise_xor.py +0 -39
- mindspore/ops/_op_impl/tbe/bitwise_xor_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/bn_infer.py +0 -43
- mindspore/ops/_op_impl/tbe/bn_infer_ds.py +0 -45
- mindspore/ops/_op_impl/tbe/bn_infer_grad.py +0 -41
- mindspore/ops/_op_impl/tbe/bn_infer_grad_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/bn_inference.py +0 -50
- mindspore/ops/_op_impl/tbe/bn_training_reduce.py +0 -38
- mindspore/ops/_op_impl/tbe/bn_training_reduce_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/bn_training_reduce_grad.py +0 -46
- mindspore/ops/_op_impl/tbe/bn_training_reduce_grad_ds.py +0 -47
- mindspore/ops/_op_impl/tbe/bn_training_update.py +0 -52
- mindspore/ops/_op_impl/tbe/bn_training_update_ds.py +0 -53
- mindspore/ops/_op_impl/tbe/bn_training_update_grad.py +0 -44
- mindspore/ops/_op_impl/tbe/bn_training_update_grad_ds.py +0 -45
- mindspore/ops/_op_impl/tbe/bn_training_update_v2.py +0 -48
- mindspore/ops/_op_impl/tbe/bn_training_update_v3.py +0 -51
- mindspore/ops/_op_impl/tbe/bounding_box_decode.py +0 -41
- mindspore/ops/_op_impl/tbe/bounding_box_decode_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/bounding_box_encode.py +0 -38
- mindspore/ops/_op_impl/tbe/broadcast_to.py +0 -40
- mindspore/ops/_op_impl/tbe/broadcast_to_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/cast.py +0 -55
- mindspore/ops/_op_impl/tbe/cast_ds.py +0 -58
- mindspore/ops/_op_impl/tbe/cdist.py +0 -38
- mindspore/ops/_op_impl/tbe/cdist_grad.py +0 -42
- mindspore/ops/_op_impl/tbe/ceil.py +0 -37
- mindspore/ops/_op_impl/tbe/ceil_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/celu.py +0 -39
- mindspore/ops/_op_impl/tbe/centralization.py +0 -39
- mindspore/ops/_op_impl/tbe/check_valid.py +0 -38
- mindspore/ops/_op_impl/tbe/check_valid_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/clip_by_norm_no_div_sum.py +0 -41
- mindspore/ops/_op_impl/tbe/clip_by_norm_no_div_sum_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/clip_by_value.py +0 -41
- mindspore/ops/_op_impl/tbe/clip_by_value_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/concat.py +0 -40
- mindspore/ops/_op_impl/tbe/concat_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/confusion_matrix.py +0 -63
- mindspore/ops/_op_impl/tbe/confusion_mul_grad.py +0 -40
- mindspore/ops/_op_impl/tbe/confusion_softmax_grad.py +0 -41
- mindspore/ops/_op_impl/tbe/confusion_transpose_d.py +0 -39
- mindspore/ops/_op_impl/tbe/conv2d.py +0 -47
- mindspore/ops/_op_impl/tbe/conv2d_backprop_filter.py +0 -42
- mindspore/ops/_op_impl/tbe/conv2d_backprop_filter_ds.py +0 -43
- mindspore/ops/_op_impl/tbe/conv2d_backprop_input.py +0 -42
- mindspore/ops/_op_impl/tbe/conv2d_backprop_input_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/conv2d_ds.py +0 -47
- mindspore/ops/_op_impl/tbe/conv2d_transpose.py +0 -48
- mindspore/ops/_op_impl/tbe/conv3d.py +0 -45
- mindspore/ops/_op_impl/tbe/conv3d_backprop_filter.py +0 -42
- mindspore/ops/_op_impl/tbe/conv3d_backprop_input.py +0 -42
- mindspore/ops/_op_impl/tbe/conv3d_transpose.py +0 -47
- mindspore/ops/_op_impl/tbe/conv3d_transpose_ds.py +0 -48
- mindspore/ops/_op_impl/tbe/cos.py +0 -37
- mindspore/ops/_op_impl/tbe/cos_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/cosh.py +0 -37
- mindspore/ops/_op_impl/tbe/cosh_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/ctc_loss_v2.py +0 -42
- mindspore/ops/_op_impl/tbe/ctc_loss_v2_grad.py +0 -44
- mindspore/ops/_op_impl/tbe/cum_sum.py +0 -42
- mindspore/ops/_op_impl/tbe/cum_sum_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/cummin.py +0 -41
- mindspore/ops/_op_impl/tbe/cumprod.py +0 -42
- mindspore/ops/_op_impl/tbe/data_format_dim_map.py +0 -38
- mindspore/ops/_op_impl/tbe/data_format_dim_map_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/deformable_offsets.py +0 -45
- mindspore/ops/_op_impl/tbe/deformable_offsets_grad.py +0 -48
- mindspore/ops/_op_impl/tbe/depth_to_space_ds.py +0 -49
- mindspore/ops/_op_impl/tbe/depthwise_conv2d.py +0 -44
- mindspore/ops/_op_impl/tbe/depthwise_conv2d_backprop_filter.py +0 -41
- mindspore/ops/_op_impl/tbe/depthwise_conv2d_backprop_input.py +0 -41
- mindspore/ops/_op_impl/tbe/diag.py +0 -38
- mindspore/ops/_op_impl/tbe/diag_part.py +0 -38
- mindspore/ops/_op_impl/tbe/dilation.py +0 -40
- mindspore/ops/_op_impl/tbe/div.py +0 -41
- mindspore/ops/_op_impl/tbe/div_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/div_no_nan.py +0 -41
- mindspore/ops/_op_impl/tbe/div_no_nan_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/dropout_do_mask.py +0 -38
- mindspore/ops/_op_impl/tbe/dropout_do_mask_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/dropout_do_mask_v3.py +0 -39
- mindspore/ops/_op_impl/tbe/dynamic_atomic_addr_clean.py +0 -34
- mindspore/ops/_op_impl/tbe/dynamic_gru_v2.py +0 -95
- mindspore/ops/_op_impl/tbe/dynamic_rnn.py +0 -82
- mindspore/ops/_op_impl/tbe/elu.py +0 -38
- mindspore/ops/_op_impl/tbe/elu_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/elu_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/elu_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/equal.py +0 -42
- mindspore/ops/_op_impl/tbe/equal_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/erf.py +0 -37
- mindspore/ops/_op_impl/tbe/erf_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/erfc.py +0 -37
- mindspore/ops/_op_impl/tbe/erfc_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/erfinv.py +0 -36
- mindspore/ops/_op_impl/tbe/exp.py +0 -40
- mindspore/ops/_op_impl/tbe/exp_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/expand_dims.py +0 -38
- mindspore/ops/_op_impl/tbe/expm1.py +0 -37
- mindspore/ops/_op_impl/tbe/expm1_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/extract_image_patches.py +0 -41
- mindspore/ops/_op_impl/tbe/extract_volume_patches.py +0 -39
- mindspore/ops/_op_impl/tbe/fake_quant_with_min_max_vars.py +0 -39
- mindspore/ops/_op_impl/tbe/fake_quant_with_min_max_vars_gradient.py +0 -43
- mindspore/ops/_op_impl/tbe/fake_quant_with_min_max_vars_per_channel.py +0 -39
- mindspore/ops/_op_impl/tbe/fake_quant_with_min_max_vars_per_channel_gradient.py +0 -43
- mindspore/ops/_op_impl/tbe/fast_gelu.py +0 -37
- mindspore/ops/_op_impl/tbe/fast_gelu_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/fast_gelu_grad.py +0 -41
- mindspore/ops/_op_impl/tbe/fast_gelu_grad_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/fill.py +0 -56
- mindspore/ops/_op_impl/tbe/fill_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/flatten.py +0 -48
- mindspore/ops/_op_impl/tbe/floor.py +0 -37
- mindspore/ops/_op_impl/tbe/floor_div.py +0 -41
- mindspore/ops/_op_impl/tbe/floor_div_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/floor_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/floor_mod.py +0 -39
- mindspore/ops/_op_impl/tbe/floor_mod_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/fused_dbn_dw.py +0 -52
- mindspore/ops/_op_impl/tbe/fused_mul_add.py +0 -38
- mindspore/ops/_op_impl/tbe/fused_mul_add_n.py +0 -48
- mindspore/ops/_op_impl/tbe/fused_mul_add_n_l2loss.py +0 -53
- mindspore/ops/_op_impl/tbe/fused_mul_apply_momentum.py +0 -57
- mindspore/ops/_op_impl/tbe/fused_mul_apply_momentum_extern.py +0 -67
- mindspore/ops/_op_impl/tbe/gather_nd.py +0 -52
- mindspore/ops/_op_impl/tbe/gather_nd_ds.py +0 -48
- mindspore/ops/_op_impl/tbe/gather_v2.py +0 -56
- mindspore/ops/_op_impl/tbe/gather_v2_ds.py +0 -68
- mindspore/ops/_op_impl/tbe/gelu.py +0 -37
- mindspore/ops/_op_impl/tbe/gelu_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/gelu_grad.py +0 -42
- mindspore/ops/_op_impl/tbe/gelu_grad_ds.py +0 -43
- mindspore/ops/_op_impl/tbe/ger.py +0 -43
- mindspore/ops/_op_impl/tbe/ger_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/greater.py +0 -43
- mindspore/ops/_op_impl/tbe/greater_equal.py +0 -41
- mindspore/ops/_op_impl/tbe/greater_equal_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/gru_v2_hidden_grad.py +0 -51
- mindspore/ops/_op_impl/tbe/gru_v2_hidden_grad_cell.py +0 -52
- mindspore/ops/_op_impl/tbe/hard_swish.py +0 -37
- mindspore/ops/_op_impl/tbe/hard_swish_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/hard_swish_grad.py +0 -41
- mindspore/ops/_op_impl/tbe/hard_swish_grad_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/histogram_fixed_width.py +0 -40
- mindspore/ops/_op_impl/tbe/hshrink.py +0 -33
- mindspore/ops/_op_impl/tbe/hshrink_grad.py +0 -37
- mindspore/ops/_op_impl/tbe/hsigmoid.py +0 -45
- mindspore/ops/_op_impl/tbe/hsigmoid_grad.py +0 -39
- mindspore/ops/_op_impl/tbe/ifmr.py +0 -47
- mindspore/ops/_op_impl/tbe/ifmr_ds.py +0 -48
- mindspore/ops/_op_impl/tbe/im2col.py +0 -42
- mindspore/ops/_op_impl/tbe/in_top_k.py +0 -37
- mindspore/ops/_op_impl/tbe/inplace_add.py +0 -39
- mindspore/ops/_op_impl/tbe/inplace_index_add.py +0 -46
- mindspore/ops/_op_impl/tbe/inplace_sub.py +0 -39
- mindspore/ops/_op_impl/tbe/inplace_update.py +0 -39
- mindspore/ops/_op_impl/tbe/inplace_update_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/inv.py +0 -38
- mindspore/ops/_op_impl/tbe/inv_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/inv_grad.py +0 -40
- mindspore/ops/_op_impl/tbe/inv_grad_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/invert.py +0 -37
- mindspore/ops/_op_impl/tbe/invert_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/iou.py +0 -38
- mindspore/ops/_op_impl/tbe/iou_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/is_close.py +0 -40
- mindspore/ops/_op_impl/tbe/kl_div_loss.py +0 -38
- mindspore/ops/_op_impl/tbe/kl_div_loss_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/kl_div_loss_grad.py +0 -40
- mindspore/ops/_op_impl/tbe/l2_loss.py +0 -36
- mindspore/ops/_op_impl/tbe/l2_loss_ds.py +0 -37
- mindspore/ops/_op_impl/tbe/l2_normalize.py +0 -38
- mindspore/ops/_op_impl/tbe/l2_normalize_grad.py +0 -40
- mindspore/ops/_op_impl/tbe/lamb_apply_optimizer_assign.py +0 -55
- mindspore/ops/_op_impl/tbe/lamb_apply_weight_assign.py +0 -42
- mindspore/ops/_op_impl/tbe/lamb_next_mv.py +0 -59
- mindspore/ops/_op_impl/tbe/lamb_next_mv_with_decay.py +0 -59
- mindspore/ops/_op_impl/tbe/lamb_next_right.py +0 -44
- mindspore/ops/_op_impl/tbe/lamb_update_with_lr.py +0 -48
- mindspore/ops/_op_impl/tbe/lamb_update_with_lr_v2.py +0 -44
- mindspore/ops/_op_impl/tbe/lars_update.py +0 -50
- mindspore/ops/_op_impl/tbe/lars_update_ds.py +0 -51
- mindspore/ops/_op_impl/tbe/layer_norm.py +0 -46
- mindspore/ops/_op_impl/tbe/layer_norm_beta_gamma_backprop.py +0 -44
- mindspore/ops/_op_impl/tbe/layer_norm_beta_gamma_backprop_ds.py +0 -45
- mindspore/ops/_op_impl/tbe/layer_norm_beta_gamma_backprop_v2.py +0 -40
- mindspore/ops/_op_impl/tbe/layer_norm_beta_gamma_backprop_v2_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/layer_norm_ds.py +0 -47
- mindspore/ops/_op_impl/tbe/layer_norm_grad.py +0 -48
- mindspore/ops/_op_impl/tbe/layer_norm_x_backprop.py +0 -43
- mindspore/ops/_op_impl/tbe/layer_norm_x_backprop_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/layer_norm_x_backprop_v2.py +0 -45
- mindspore/ops/_op_impl/tbe/layer_norm_x_backprop_v2_ds.py +0 -45
- mindspore/ops/_op_impl/tbe/lerp.py +0 -38
- mindspore/ops/_op_impl/tbe/less.py +0 -41
- mindspore/ops/_op_impl/tbe/less_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/less_equal.py +0 -41
- mindspore/ops/_op_impl/tbe/less_equal_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/log.py +0 -40
- mindspore/ops/_op_impl/tbe/log1p.py +0 -37
- mindspore/ops/_op_impl/tbe/log1p_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/log_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/logical_and.py +0 -37
- mindspore/ops/_op_impl/tbe/logical_and_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/logical_not.py +0 -36
- mindspore/ops/_op_impl/tbe/logical_not_ds.py +0 -37
- mindspore/ops/_op_impl/tbe/logical_or.py +0 -37
- mindspore/ops/_op_impl/tbe/logical_or_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/logsoftmax.py +0 -37
- mindspore/ops/_op_impl/tbe/logsoftmax_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/logsoftmax_grad.py +0 -38
- mindspore/ops/_op_impl/tbe/logsoftmax_grad_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/lp_norm.py +0 -40
- mindspore/ops/_op_impl/tbe/lp_norm_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/lrn.py +0 -41
- mindspore/ops/_op_impl/tbe/lrn_grad.py +0 -42
- mindspore/ops/_op_impl/tbe/lstm_input_grad.py +0 -51
- mindspore/ops/_op_impl/tbe/masked_fill.py +0 -40
- mindspore/ops/_op_impl/tbe/masked_fill_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/matmul.py +0 -53
- mindspore/ops/_op_impl/tbe/matmul_ds.py +0 -47
- mindspore/ops/_op_impl/tbe/matmul_v2.py +0 -50
- mindspore/ops/_op_impl/tbe/matrix_diag.py +0 -45
- mindspore/ops/_op_impl/tbe/matrix_diag_part.py +0 -45
- mindspore/ops/_op_impl/tbe/matrix_set_diag.py +0 -46
- mindspore/ops/_op_impl/tbe/max_pool.py +0 -39
- mindspore/ops/_op_impl/tbe/max_pool3d.py +0 -44
- mindspore/ops/_op_impl/tbe/max_pool3d_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/max_pool3d_grad_grad.py +0 -44
- mindspore/ops/_op_impl/tbe/max_pool_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/max_pool_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/max_pool_grad_grad.py +0 -41
- mindspore/ops/_op_impl/tbe/max_pool_grad_grad_with_argmax.py +0 -41
- mindspore/ops/_op_impl/tbe/max_pool_grad_with_argmax.py +0 -42
- mindspore/ops/_op_impl/tbe/max_pool_with_argmax.py +0 -40
- mindspore/ops/_op_impl/tbe/maximum.py +0 -39
- mindspore/ops/_op_impl/tbe/maximum_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/maximum_grad.py +0 -46
- mindspore/ops/_op_impl/tbe/maximum_grad_ds.py +0 -47
- mindspore/ops/_op_impl/tbe/mem_set.py +0 -38
- mindspore/ops/_op_impl/tbe/minimum.py +0 -40
- mindspore/ops/_op_impl/tbe/minimum_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/minimum_grad.py +0 -46
- mindspore/ops/_op_impl/tbe/minimum_grad_ds.py +0 -47
- mindspore/ops/_op_impl/tbe/mish.py +0 -37
- mindspore/ops/_op_impl/tbe/mod.py +0 -41
- mindspore/ops/_op_impl/tbe/mod_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/mul.py +0 -37
- mindspore/ops/_op_impl/tbe/mul_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/mul_no_nan.py +0 -39
- mindspore/ops/_op_impl/tbe/mul_no_nan_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/multilabel_margin_loss.py +0 -39
- mindspore/ops/_op_impl/tbe/neg.py +0 -39
- mindspore/ops/_op_impl/tbe/neg_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/new_im2col.py +0 -40
- mindspore/ops/_op_impl/tbe/nll_loss.py +0 -41
- mindspore/ops/_op_impl/tbe/nll_loss_grad.py +0 -44
- mindspore/ops/_op_impl/tbe/nms_with_mask.py +0 -39
- mindspore/ops/_op_impl/tbe/not_equal.py +0 -41
- mindspore/ops/_op_impl/tbe/not_equal_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/npu_alloc_float_status.py +0 -34
- mindspore/ops/_op_impl/tbe/npu_clear_float_status.py +0 -35
- mindspore/ops/_op_impl/tbe/npu_clear_float_status_v2.py +0 -35
- mindspore/ops/_op_impl/tbe/npu_get_float_status.py +0 -35
- mindspore/ops/_op_impl/tbe/npu_get_float_status_v2.py +0 -35
- mindspore/ops/_op_impl/tbe/one_hot.py +0 -48
- mindspore/ops/_op_impl/tbe/one_hot_ds.py +0 -45
- mindspore/ops/_op_impl/tbe/ones_like.py +0 -40
- mindspore/ops/_op_impl/tbe/ones_like_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/p_s_r_o_i_pooling.py +0 -40
- mindspore/ops/_op_impl/tbe/p_s_r_o_i_pooling_grad.py +0 -40
- mindspore/ops/_op_impl/tbe/pack.py +0 -58
- mindspore/ops/_op_impl/tbe/pack_ds.py +0 -59
- mindspore/ops/_op_impl/tbe/pad_d.py +0 -40
- mindspore/ops/_op_impl/tbe/pad_d_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/parallel_concat.py +0 -70
- mindspore/ops/_op_impl/tbe/parallel_resize_bilinear.py +0 -45
- mindspore/ops/_op_impl/tbe/parallel_resize_bilinear_grad.py +0 -44
- mindspore/ops/_op_impl/tbe/pdist.py +0 -36
- mindspore/ops/_op_impl/tbe/pooling.py +0 -46
- mindspore/ops/_op_impl/tbe/population_count.py +0 -38
- mindspore/ops/_op_impl/tbe/pow.py +0 -41
- mindspore/ops/_op_impl/tbe/pow_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/prelu.py +0 -37
- mindspore/ops/_op_impl/tbe/prelu_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/prelu_grad.py +0 -40
- mindspore/ops/_op_impl/tbe/range.py +0 -39
- mindspore/ops/_op_impl/tbe/real_div.py +0 -38
- mindspore/ops/_op_impl/tbe/real_div_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/reciprocal.py +0 -36
- mindspore/ops/_op_impl/tbe/reciprocal_ds.py +0 -37
- mindspore/ops/_op_impl/tbe/reciprocal_grad.py +0 -38
- mindspore/ops/_op_impl/tbe/reciprocal_grad_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/reduce_all.py +0 -38
- mindspore/ops/_op_impl/tbe/reduce_all_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/reduce_any.py +0 -38
- mindspore/ops/_op_impl/tbe/reduce_any_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/reduce_max.py +0 -43
- mindspore/ops/_op_impl/tbe/reduce_max_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/reduce_mean.py +0 -40
- mindspore/ops/_op_impl/tbe/reduce_mean_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/reduce_min.py +0 -41
- mindspore/ops/_op_impl/tbe/reduce_min_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/reduce_prod.py +0 -42
- mindspore/ops/_op_impl/tbe/reduce_prod_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/reduce_std.py +0 -44
- mindspore/ops/_op_impl/tbe/reduce_sum.py +0 -39
- mindspore/ops/_op_impl/tbe/reduce_sum_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/relu.py +0 -39
- mindspore/ops/_op_impl/tbe/relu6.py +0 -38
- mindspore/ops/_op_impl/tbe/relu6_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/relu6_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/relu6_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/relu_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/relu_grad.py +0 -41
- mindspore/ops/_op_impl/tbe/relu_grad_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/relu_grad_v2.py +0 -40
- mindspore/ops/_op_impl/tbe/relu_grad_v2_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/relu_v2.py +0 -40
- mindspore/ops/_op_impl/tbe/relu_v2_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/renorm.py +0 -39
- mindspore/ops/_op_impl/tbe/resize_bilinear.py +0 -40
- mindspore/ops/_op_impl/tbe/resize_bilinear_grad.py +0 -41
- mindspore/ops/_op_impl/tbe/resize_bilinear_v2.py +0 -43
- mindspore/ops/_op_impl/tbe/resize_nearest_neighbor.py +0 -40
- mindspore/ops/_op_impl/tbe/resize_nearest_neighbor_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/resize_nearest_neighbor_grad.py +0 -39
- mindspore/ops/_op_impl/tbe/resize_nearest_neighbor_grad_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/reverse_v2_d.py +0 -37
- mindspore/ops/_op_impl/tbe/rint.py +0 -37
- mindspore/ops/_op_impl/tbe/rint_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/roi_align.py +0 -43
- mindspore/ops/_op_impl/tbe/roi_align_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/roi_align_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/roi_align_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/roll.py +0 -42
- mindspore/ops/_op_impl/tbe/round.py +0 -38
- mindspore/ops/_op_impl/tbe/round_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/rsqrt.py +0 -37
- mindspore/ops/_op_impl/tbe/rsqrt_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/rsqrt_grad.py +0 -40
- mindspore/ops/_op_impl/tbe/rsqrt_grad_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/scatter_add.py +0 -44
- mindspore/ops/_op_impl/tbe/scatter_div.py +0 -46
- mindspore/ops/_op_impl/tbe/scatter_max.py +0 -45
- mindspore/ops/_op_impl/tbe/scatter_min.py +0 -45
- mindspore/ops/_op_impl/tbe/scatter_mul.py +0 -44
- mindspore/ops/_op_impl/tbe/scatter_nd.py +0 -41
- mindspore/ops/_op_impl/tbe/scatter_nd_add.py +0 -45
- mindspore/ops/_op_impl/tbe/scatter_nd_d.py +0 -41
- mindspore/ops/_op_impl/tbe/scatter_nd_ds.py +0 -49
- mindspore/ops/_op_impl/tbe/scatter_nd_sub.py +0 -47
- mindspore/ops/_op_impl/tbe/scatter_nd_sub_ds.py +0 -48
- mindspore/ops/_op_impl/tbe/scatter_nd_update.py +0 -47
- mindspore/ops/_op_impl/tbe/scatter_nd_update_ds.py +0 -48
- mindspore/ops/_op_impl/tbe/scatter_non_aliasing_add.py +0 -39
- mindspore/ops/_op_impl/tbe/scatter_non_aliasing_add_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/scatter_sub.py +0 -47
- mindspore/ops/_op_impl/tbe/scatter_sub_ds.py +0 -48
- mindspore/ops/_op_impl/tbe/scatter_update.py +0 -43
- mindspore/ops/_op_impl/tbe/select.py +0 -38
- mindspore/ops/_op_impl/tbe/select_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/selu.py +0 -39
- mindspore/ops/_op_impl/tbe/selu_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/sgd.py +0 -62
- mindspore/ops/_op_impl/tbe/sigmoid.py +0 -37
- mindspore/ops/_op_impl/tbe/sigmoid_cross_entropy_with_logits.py +0 -41
- mindspore/ops/_op_impl/tbe/sigmoid_cross_entropy_with_logits_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/sigmoid_cross_entropy_with_logits_grad.py +0 -42
- mindspore/ops/_op_impl/tbe/sigmoid_cross_entropy_with_logits_grad_ds.py +0 -43
- mindspore/ops/_op_impl/tbe/sigmoid_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/sigmoid_grad.py +0 -39
- mindspore/ops/_op_impl/tbe/sigmoid_grad_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/sign.py +0 -38
- mindspore/ops/_op_impl/tbe/sign_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/sin.py +0 -37
- mindspore/ops/_op_impl/tbe/sin_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/sinh.py +0 -37
- mindspore/ops/_op_impl/tbe/sinh_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/slice.py +0 -58
- mindspore/ops/_op_impl/tbe/smooth_l1_loss.py +0 -45
- mindspore/ops/_op_impl/tbe/smooth_l1_loss_ds.py +0 -46
- mindspore/ops/_op_impl/tbe/smooth_l1_loss_grad.py +0 -46
- mindspore/ops/_op_impl/tbe/smooth_l1_loss_grad_ds.py +0 -47
- mindspore/ops/_op_impl/tbe/soft_margin_loss.py +0 -38
- mindspore/ops/_op_impl/tbe/soft_margin_loss_grad.py +0 -39
- mindspore/ops/_op_impl/tbe/soft_shrink.py +0 -36
- mindspore/ops/_op_impl/tbe/soft_shrink_grad.py +0 -38
- mindspore/ops/_op_impl/tbe/softmax.py +0 -37
- mindspore/ops/_op_impl/tbe/softmax_cross_entropy_with_logits.py +0 -38
- mindspore/ops/_op_impl/tbe/softmax_cross_entropy_with_logits_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/softmax_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/softmax_grad_ext.py +0 -42
- mindspore/ops/_op_impl/tbe/softmax_v2_with_dropout_do_mask_v3.py +0 -39
- mindspore/ops/_op_impl/tbe/softplus.py +0 -37
- mindspore/ops/_op_impl/tbe/softplus_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/softplus_grad.py +0 -38
- mindspore/ops/_op_impl/tbe/softplus_grad_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/softsign.py +0 -37
- mindspore/ops/_op_impl/tbe/softsign_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/sort.py +0 -38
- mindspore/ops/_op_impl/tbe/sort_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/space_to_batch.py +0 -38
- mindspore/ops/_op_impl/tbe/space_to_batch_nd.py +0 -38
- mindspore/ops/_op_impl/tbe/space_to_depth.py +0 -47
- mindspore/ops/_op_impl/tbe/sparse_apply_adadelta.py +0 -56
- mindspore/ops/_op_impl/tbe/sparse_apply_adagrad.py +0 -45
- mindspore/ops/_op_impl/tbe/sparse_apply_adagrad_ds.py +0 -46
- mindspore/ops/_op_impl/tbe/sparse_apply_adagrad_v2.py +0 -46
- mindspore/ops/_op_impl/tbe/sparse_apply_adagrad_v2_ds.py +0 -47
- mindspore/ops/_op_impl/tbe/sparse_apply_ftrl_d.py +0 -53
- mindspore/ops/_op_impl/tbe/sparse_apply_ftrl_d_ds.py +0 -50
- mindspore/ops/_op_impl/tbe/sparse_apply_ftrl_v2.py +0 -50
- mindspore/ops/_op_impl/tbe/sparse_apply_proximal_adagrad.py +0 -66
- mindspore/ops/_op_impl/tbe/sparse_apply_proximal_adagrad_ds.py +0 -67
- mindspore/ops/_op_impl/tbe/sparse_apply_r_m_s_prop.py +0 -57
- mindspore/ops/_op_impl/tbe/sparse_apply_r_m_s_prop_ds.py +0 -58
- mindspore/ops/_op_impl/tbe/sparse_gather_v2.py +0 -56
- mindspore/ops/_op_impl/tbe/sparse_gather_v2_ds.py +0 -58
- mindspore/ops/_op_impl/tbe/split_d.py +0 -38
- mindspore/ops/_op_impl/tbe/split_d_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/split_v.py +0 -39
- mindspore/ops/_op_impl/tbe/splitv.py +0 -39
- mindspore/ops/_op_impl/tbe/sqrt.py +0 -37
- mindspore/ops/_op_impl/tbe/sqrt_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/sqrt_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/sqrt_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/square.py +0 -38
- mindspore/ops/_op_impl/tbe/square_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/square_sum_all.py +0 -40
- mindspore/ops/_op_impl/tbe/square_sum_all_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/square_sum_v1.py +0 -38
- mindspore/ops/_op_impl/tbe/square_sum_v1_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/square_sum_v2.py +0 -39
- mindspore/ops/_op_impl/tbe/squared_difference.py +0 -39
- mindspore/ops/_op_impl/tbe/squared_difference_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/squeeze.py +0 -37
- mindspore/ops/_op_impl/tbe/strided_read.py +0 -38
- mindspore/ops/_op_impl/tbe/strided_slice_d.py +0 -44
- mindspore/ops/_op_impl/tbe/strided_slice_ds.py +0 -71
- mindspore/ops/_op_impl/tbe/strided_slice_grad_d.py +0 -51
- mindspore/ops/_op_impl/tbe/strided_slice_grad_ds.py +0 -57
- mindspore/ops/_op_impl/tbe/strided_write.py +0 -38
- mindspore/ops/_op_impl/tbe/sub.py +0 -39
- mindspore/ops/_op_impl/tbe/sub_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/tan.py +0 -38
- mindspore/ops/_op_impl/tbe/tan_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/tanh.py +0 -37
- mindspore/ops/_op_impl/tbe/tanh_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/tanh_grad.py +0 -39
- mindspore/ops/_op_impl/tbe/tanh_grad_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/tensor_move.py +0 -49
- mindspore/ops/_op_impl/tbe/tensor_move_ds.py +0 -50
- mindspore/ops/_op_impl/tbe/tensor_scatter_update.py +0 -41
- mindspore/ops/_op_impl/tbe/tile.py +0 -37
- mindspore/ops/_op_impl/tbe/tile_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/top_k.py +0 -42
- mindspore/ops/_op_impl/tbe/top_k_ds.py +0 -43
- mindspore/ops/_op_impl/tbe/trans_data.py +0 -167
- mindspore/ops/_op_impl/tbe/trans_data_ds.py +0 -180
- mindspore/ops/_op_impl/tbe/trans_data_rnn.py +0 -44
- mindspore/ops/_op_impl/tbe/transpose.py +0 -60
- mindspore/ops/_op_impl/tbe/transpose_d.py +0 -47
- mindspore/ops/_op_impl/tbe/transpose_nod.py +0 -60
- mindspore/ops/_op_impl/tbe/trunc.py +0 -39
- mindspore/ops/_op_impl/tbe/truncate_div.py +0 -41
- mindspore/ops/_op_impl/tbe/truncate_div_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/truncate_mod.py +0 -41
- mindspore/ops/_op_impl/tbe/truncate_mod_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/unpack.py +0 -38
- mindspore/ops/_op_impl/tbe/unpack_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/unsorted_segment_max.py +0 -49
- mindspore/ops/_op_impl/tbe/unsorted_segment_max_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/unsorted_segment_min.py +0 -49
- mindspore/ops/_op_impl/tbe/unsorted_segment_min_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/unsorted_segment_prod.py +0 -49
- mindspore/ops/_op_impl/tbe/unsorted_segment_prod_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/unsorted_segment_sum.py +0 -38
- mindspore/ops/_op_impl/tbe/unsorted_segment_sum_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/wts_arq.py +0 -40
- mindspore/ops/_op_impl/tbe/xdivy.py +0 -38
- mindspore/ops/_op_impl/tbe/xdivy_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/xlogy.py +0 -38
- mindspore/ops/_op_impl/tbe/xlogy_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/zeros_like.py +0 -41
- mindspore/ops/_op_impl/tbe/zeros_like_ds.py +0 -42
- mindspore/ops/_tracefunc.py +0 -241
- mindspore/ops/arg_dtype_cast.py +0 -54
- mindspore/rewrite/api/tree_node_helper.py +0 -60
- mindspore/rewrite/ast_helpers/ast_creator.py +0 -115
- mindspore/rewrite/ast_transformers/flatten_recursive_stmt.py +0 -267
- mindspore/rewrite/ast_transformers/remove_return_out_of_if.py +0 -228
- mindspore/rewrite/namespace.py +0 -53
- mindspore-2.2.11.dist-info/RECORD +0 -1920
- {mindspore-2.2.11.dist-info → mindspore-2.3.0.dist-info}/WHEEL +0 -0
- {mindspore-2.2.11.dist-info → mindspore-2.3.0.dist-info}/top_level.txt +0 -0
|
@@ -30,6 +30,16 @@ from mindspore.ops.primitive import Primitive
|
|
|
30
30
|
from mindspore.ops.primitive import PrimitiveWithInfer
|
|
31
31
|
from mindspore.ops.primitive import PrimitiveWithCheck
|
|
32
32
|
from mindspore.ops.primitive import prim_attr_register
|
|
33
|
+
from ..auto_generate import (CeLU, Flatten, LogSoftmax, ReLU, ReLU6, Dense, Tanh,
|
|
34
|
+
Elu, Sigmoid, Softmax, SoftplusExt, HSwish, HSigmoid, AvgPool, BiasAdd,
|
|
35
|
+
NLLLoss, OneHot, GeLU, FastGeLU, PReLU, RmsNorm,
|
|
36
|
+
GridSampler3D, GridSampler2D, LayerNorm, LayerNormExt, HShrink, AdamWeightDecay, Dropout,
|
|
37
|
+
ApplyRotaryPosEmb, PagedAttention, PagedAttentionMask, ReshapeAndCache,
|
|
38
|
+
FlashAttentionScore, Embedding, UpsampleNearest1D, UpsampleNearest2D,
|
|
39
|
+
UpsampleNearest3D, UpsampleTrilinear3D,
|
|
40
|
+
UpsampleBilinear2D, UpsampleLinear1D,
|
|
41
|
+
BinaryCrossEntropy, BCEWithLogitsLoss)
|
|
42
|
+
from .manually_defined import BatchNorm
|
|
33
43
|
|
|
34
44
|
|
|
35
45
|
def _check_positive_int_or_tuple(arg_name, arg_value, prim_name, allow_four=False,
|
|
@@ -95,83 +105,6 @@ def _update_attr_by_format(arg_value, arg_format):
|
|
|
95
105
|
return ret
|
|
96
106
|
|
|
97
107
|
|
|
98
|
-
class CeLU(Primitive):
|
|
99
|
-
r"""
|
|
100
|
-
Computes CeLU (Continuously differentiable exponential linear units) of input tensors element-wise.
|
|
101
|
-
|
|
102
|
-
Refer to :func:`mindspore.ops.celu` for more details.
|
|
103
|
-
|
|
104
|
-
.. warning::
|
|
105
|
-
This is an experimental API that is subject to change or deletion.
|
|
106
|
-
|
|
107
|
-
Args:
|
|
108
|
-
alpha (float, optional): The :math:`\alpha` value for the Celu formulation. Default: ``1.0`` .
|
|
109
|
-
|
|
110
|
-
Inputs:
|
|
111
|
-
- **input_x** (Tensor) - The input tensor with a dtype of float16 or float32.
|
|
112
|
-
|
|
113
|
-
Outputs:
|
|
114
|
-
Tensor, with the same type and shape as the `input_x`.
|
|
115
|
-
|
|
116
|
-
Supported Platforms:
|
|
117
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
118
|
-
|
|
119
|
-
Examples:
|
|
120
|
-
>>> import mindspore
|
|
121
|
-
>>> import numpy as np
|
|
122
|
-
>>> from mindspore import Tensor, ops
|
|
123
|
-
>>> input_x = Tensor(np.array([-2.0, -1.0, 1.0, 2.0]), mindspore.float32)
|
|
124
|
-
>>> celu = ops.CeLU(alpha=1.0)
|
|
125
|
-
>>> output = celu(input_x)
|
|
126
|
-
>>> print(output)
|
|
127
|
-
[-0.86466473 -0.63212055 1. 2. ]
|
|
128
|
-
>>> input_x = Tensor(2.1, mindspore.float32)
|
|
129
|
-
>>> output = celu(input_x)
|
|
130
|
-
>>> print(output)
|
|
131
|
-
2.1
|
|
132
|
-
"""
|
|
133
|
-
|
|
134
|
-
@prim_attr_register
|
|
135
|
-
def __init__(self, alpha=1.0):
|
|
136
|
-
"""Initialize CeLU"""
|
|
137
|
-
validator.check_value_type("alpha", alpha, [float], self.name)
|
|
138
|
-
validator.check_float(alpha, 0.0, validator.NE, "alpha", self.name)
|
|
139
|
-
self.alpha = alpha
|
|
140
|
-
self.add_prim_attr('alpha', self.alpha)
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
class Flatten(Primitive):
|
|
144
|
-
r"""
|
|
145
|
-
Flattens a tensor without changing its batch size on the 0-th axis.
|
|
146
|
-
|
|
147
|
-
Refer to :func:`mindspore.ops.flatten` for more details.
|
|
148
|
-
|
|
149
|
-
Inputs:
|
|
150
|
-
- **input_x** (Tensor) - Tensor of shape :math:`(N, \ldots)` to be flattened, where :math:`N` is batch size.
|
|
151
|
-
|
|
152
|
-
Outputs:
|
|
153
|
-
Tensor, the shape of the output tensor is :math:`(N, X)`, where :math:`X` is
|
|
154
|
-
the product of the remaining dimension.
|
|
155
|
-
|
|
156
|
-
Supported Platforms:
|
|
157
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
158
|
-
|
|
159
|
-
Examples:
|
|
160
|
-
>>> import mindspore
|
|
161
|
-
>>> import numpy as np
|
|
162
|
-
>>> from mindspore import Tensor, ops
|
|
163
|
-
>>> input_x = Tensor(np.ones(shape=[1, 2, 3, 4]), mindspore.float32)
|
|
164
|
-
>>> flatten = ops.Flatten()
|
|
165
|
-
>>> output = flatten(input_x)
|
|
166
|
-
>>> print(output.shape)
|
|
167
|
-
(1, 24)
|
|
168
|
-
"""
|
|
169
|
-
|
|
170
|
-
@prim_attr_register
|
|
171
|
-
def __init__(self):
|
|
172
|
-
pass
|
|
173
|
-
|
|
174
|
-
|
|
175
108
|
class AdaptiveAvgPool3D(Primitive):
|
|
176
109
|
r"""
|
|
177
110
|
AdaptiveAvgPool3D operation.
|
|
@@ -427,86 +360,6 @@ class AdaptiveMaxPool3D(Primitive):
|
|
|
427
360
|
self.init_prim_io_names(inputs=['x', 'output_size'], outputs=['y', 'argmax'])
|
|
428
361
|
|
|
429
362
|
|
|
430
|
-
class Softmax(Primitive):
|
|
431
|
-
r"""
|
|
432
|
-
Applies the Softmax operation to the input tensor on the specified axis.
|
|
433
|
-
|
|
434
|
-
Refer to :func:`mindspore.ops.softmax` for more details.
|
|
435
|
-
|
|
436
|
-
Args:
|
|
437
|
-
axis (Union[int, tuple]): The axis to perform the Softmax operation. Default: ``-1`` .
|
|
438
|
-
|
|
439
|
-
Inputs:
|
|
440
|
-
- **logits** (Tensor) - Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
|
|
441
|
-
additional dimensions. Supported dtypes:
|
|
442
|
-
|
|
443
|
-
- Ascend: float16, float32.
|
|
444
|
-
- GPU/CPU: float16, float32, float64.
|
|
445
|
-
|
|
446
|
-
Outputs:
|
|
447
|
-
Tensor, with the same type and shape as the logits.
|
|
448
|
-
|
|
449
|
-
Supported Platforms:
|
|
450
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
451
|
-
|
|
452
|
-
Examples:
|
|
453
|
-
>>> import mindspore
|
|
454
|
-
>>> import numpy as np
|
|
455
|
-
>>> from mindspore import Tensor, ops
|
|
456
|
-
>>> logits = Tensor(np.array([1, 2, 3, 4, 5]), mindspore.float32)
|
|
457
|
-
>>> softmax = ops.Softmax()
|
|
458
|
-
>>> output = softmax(logits)
|
|
459
|
-
>>> print(output)
|
|
460
|
-
[0.01165623 0.03168492 0.08612854 0.23412167 0.6364086 ]
|
|
461
|
-
"""
|
|
462
|
-
|
|
463
|
-
@prim_attr_register
|
|
464
|
-
def __init__(self, axis=-1):
|
|
465
|
-
"""Initialize Softmax."""
|
|
466
|
-
self.init_prim_io_names(inputs=['x'], outputs=['output'])
|
|
467
|
-
validator.check_value_type("axis", axis, [int, tuple], self.name)
|
|
468
|
-
if isinstance(axis, int):
|
|
469
|
-
self.add_prim_attr('axis', (axis,))
|
|
470
|
-
for item in self.axis:
|
|
471
|
-
validator.check_value_type("item of axis", item, [int], self.name)
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
class LogSoftmax(Primitive):
|
|
475
|
-
r"""
|
|
476
|
-
Log Softmax activation function.
|
|
477
|
-
|
|
478
|
-
Refer to :func:`mindspore.ops.log_softmax` for more details.
|
|
479
|
-
|
|
480
|
-
Args:
|
|
481
|
-
axis (int, optional): The axis to perform the Log softmax operation. Default: ``-1`` .
|
|
482
|
-
|
|
483
|
-
Inputs:
|
|
484
|
-
- **logits** (Tensor) - Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
|
|
485
|
-
additional dimensions, with float16 or float32 data type.
|
|
486
|
-
|
|
487
|
-
Outputs:
|
|
488
|
-
Tensor, with the same type and shape as the `logits`.
|
|
489
|
-
|
|
490
|
-
Supported Platforms:
|
|
491
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
492
|
-
|
|
493
|
-
Examples:
|
|
494
|
-
>>> import mindspore
|
|
495
|
-
>>> import numpy as np
|
|
496
|
-
>>> from mindspore import Tensor, ops
|
|
497
|
-
>>> logits = Tensor(np.array([1, 2, 3, 4, 5]), mindspore.float32)
|
|
498
|
-
>>> log_softmax = ops.LogSoftmax()
|
|
499
|
-
>>> output = log_softmax(logits)
|
|
500
|
-
>>> print(output)
|
|
501
|
-
[-4.4519143 -3.4519143 -2.4519143 -1.4519144 -0.4519144]
|
|
502
|
-
"""
|
|
503
|
-
|
|
504
|
-
@prim_attr_register
|
|
505
|
-
def __init__(self, axis=-1):
|
|
506
|
-
"""Initialize LogSoftmax."""
|
|
507
|
-
validator.check_value_type("axis", axis, [int], self.name)
|
|
508
|
-
|
|
509
|
-
|
|
510
363
|
class Softplus(Primitive):
|
|
511
364
|
r"""
|
|
512
365
|
Softplus activation function.
|
|
@@ -586,39 +439,6 @@ class Softsign(Primitive):
|
|
|
586
439
|
self.init_prim_io_names(inputs=['x'], outputs=['output'])
|
|
587
440
|
|
|
588
441
|
|
|
589
|
-
class ReLU(Primitive):
|
|
590
|
-
r"""
|
|
591
|
-
Computes ReLU (Rectified Linear Unit activation function) of input tensors element-wise.
|
|
592
|
-
|
|
593
|
-
Refer to :func:`mindspore.ops.relu` for more details.
|
|
594
|
-
|
|
595
|
-
Inputs:
|
|
596
|
-
- **input_x** (Tensor) - Input Tensor of numeric types.
|
|
597
|
-
|
|
598
|
-
Outputs:
|
|
599
|
-
Tensor, has the same dtype and shape as `input_x`.
|
|
600
|
-
|
|
601
|
-
Supported Platforms:
|
|
602
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
603
|
-
|
|
604
|
-
Examples:
|
|
605
|
-
>>> import mindspore
|
|
606
|
-
>>> import numpy as np
|
|
607
|
-
>>> from mindspore import Tensor, ops
|
|
608
|
-
>>> input_x = Tensor(np.array([[-1.0, 4.0, -8.0], [2.0, -5.0, 9.0]]), mindspore.float32)
|
|
609
|
-
>>> relu = ops.ReLU()
|
|
610
|
-
>>> output = relu(input_x)
|
|
611
|
-
>>> print(output)
|
|
612
|
-
[[0. 4. 0.]
|
|
613
|
-
[2. 0. 9.]]
|
|
614
|
-
"""
|
|
615
|
-
|
|
616
|
-
@prim_attr_register
|
|
617
|
-
def __init__(self):
|
|
618
|
-
"""Initialize ReLU"""
|
|
619
|
-
self.init_prim_io_names(inputs=['x'], outputs=['output'])
|
|
620
|
-
|
|
621
|
-
|
|
622
442
|
class ReLUV3(Primitive):
|
|
623
443
|
r"""
|
|
624
444
|
Computes ReLUV3 (Rectified Linear Unit activation function) of input tensors element-wise.
|
|
@@ -633,7 +453,7 @@ class ReLUV3(Primitive):
|
|
|
633
453
|
Inputs:
|
|
634
454
|
- **input_x** (Tensor) - Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
|
|
635
455
|
additional dimensions, data type is
|
|
636
|
-
`number <https://www.mindspore.cn/docs/en/
|
|
456
|
+
`number <https://www.mindspore.cn/docs/en/master/api_python/mindspore.html#mindspore.dtype>`_.
|
|
637
457
|
|
|
638
458
|
Outputs:
|
|
639
459
|
Tensor of shape :math:`(N, *)`, with the same type and shape as the `input_x`.
|
|
@@ -737,285 +557,18 @@ class SeLU(Primitive):
|
|
|
737
557
|
>>> from mindspore import Tensor, ops
|
|
738
558
|
>>> input_x = Tensor(np.array([[-1.0, 4.0, -8.0], [2.0, -5.0, 9.0]]), mindspore.float32)
|
|
739
559
|
>>> selu = ops.SeLU()
|
|
740
|
-
>>> output = selu(input_x)
|
|
741
|
-
>>> print(output)
|
|
742
|
-
[[-1.1113307 4.202804 -1.7575096]
|
|
743
|
-
[ 2.101402 -1.7462534 9.456309 ]]
|
|
744
|
-
"""
|
|
745
|
-
|
|
746
|
-
@prim_attr_register
|
|
747
|
-
def __init__(self):
|
|
748
|
-
"""Initialize SeLU"""
|
|
749
|
-
self.init_prim_io_names(inputs=['input_x'], outputs=['output'])
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
class ReLU6(PrimitiveWithCheck):
|
|
753
|
-
r"""
|
|
754
|
-
Computes ReLU (Rectified Linear Unit) upper bounded by 6 of input tensors element-wise.
|
|
755
|
-
|
|
756
|
-
Refer to :func:`mindspore.ops.relu6` for more details.
|
|
757
|
-
|
|
758
|
-
Inputs:
|
|
759
|
-
- **input_x** (Tensor) - Tensor of shape :math:`(N, *)`,
|
|
760
|
-
where :math:`*` means any number of additional dimensions.
|
|
761
|
-
Data type must be float16, float32.
|
|
762
|
-
|
|
763
|
-
Outputs:
|
|
764
|
-
Tensor, with the same type and shape as the `input_x`.
|
|
765
|
-
|
|
766
|
-
Supported Platforms:
|
|
767
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
768
|
-
|
|
769
|
-
Examples:
|
|
770
|
-
>>> import mindspore
|
|
771
|
-
>>> import numpy as np
|
|
772
|
-
>>> from mindspore import Tensor, ops
|
|
773
|
-
>>> input_x = Tensor(np.array([[-1.0, 4.0, -8.0], [2.0, -5.0, 9.0]]), mindspore.float32)
|
|
774
|
-
>>> relu6 = ops.ReLU6()
|
|
775
|
-
>>> result = relu6(input_x)
|
|
776
|
-
>>> print(result)
|
|
777
|
-
[[0. 4. 0.]
|
|
778
|
-
[2. 0. 6.]]
|
|
779
|
-
"""
|
|
780
|
-
|
|
781
|
-
@prim_attr_register
|
|
782
|
-
def __init__(self):
|
|
783
|
-
"""Initialize ReLU6"""
|
|
784
|
-
self.init_prim_io_names(inputs=['x'], outputs=['output'])
|
|
785
|
-
|
|
786
|
-
def check_shape(self, input_x):
|
|
787
|
-
pass
|
|
788
|
-
|
|
789
|
-
def check_dtype(self, input_x):
|
|
790
|
-
validator.check_tensor_dtype_valid('input_x', input_x, (mstype.float16, mstype.float32), self.name)
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
class ReLUV2(Primitive):
|
|
794
|
-
r"""
|
|
795
|
-
The ReLUV2 interface is deprecated, please use the :class:`mindspore.ops.ReLU` instead.
|
|
796
|
-
|
|
797
|
-
Rectified Linear Unit activation function.
|
|
798
|
-
|
|
799
|
-
It returns element-wise :math:`\max(0, x)`, specially, the neurons with the negative output
|
|
800
|
-
will be suppressed and the active neurons will stay the same.
|
|
801
|
-
|
|
802
|
-
.. math::
|
|
803
|
-
|
|
804
|
-
\text{ReLU}(x) = (x)^+ = \max(0, x)
|
|
805
|
-
|
|
806
|
-
Inputs:
|
|
807
|
-
- **input_x** (Tensor) - The input tensor must be a 4-D tensor.
|
|
808
|
-
|
|
809
|
-
Outputs:
|
|
810
|
-
- **output** (Tensor) - Has the same type and shape as the `input_x`.
|
|
811
|
-
- **mask** (Tensor) - A tensor, but it is meaningless.
|
|
812
|
-
|
|
813
|
-
Raises:
|
|
814
|
-
TypeError: If `input_x` is not a Tensor.
|
|
815
|
-
ValueError: If shape of `input_x` is not 4-D.
|
|
816
|
-
|
|
817
|
-
Supported Platforms:
|
|
818
|
-
deprecated
|
|
819
|
-
|
|
820
|
-
Examples:
|
|
821
|
-
>>> input_x = Tensor(np.array([[[[1, -2], [-3, 4]], [[-5, 6], [7, -8]]]]), mindspore.float32)
|
|
822
|
-
>>> relu_v2 = ops.ReLUV2()
|
|
823
|
-
>>> output, _= relu_v2(input_x)
|
|
824
|
-
>>> print(output)
|
|
825
|
-
[[[[1. 0.]
|
|
826
|
-
[0. 4.]]
|
|
827
|
-
[[0. 6.]
|
|
828
|
-
[7. 0.]]]]
|
|
829
|
-
"""
|
|
830
|
-
|
|
831
|
-
@prim_attr_register
|
|
832
|
-
def __init__(self):
|
|
833
|
-
"""Initialize ReLUV2"""
|
|
834
|
-
self.init_prim_io_names(inputs=['x'], outputs=['output', 'mask'])
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
class Elu(Primitive):
|
|
838
|
-
r"""
|
|
839
|
-
Exponential Linear Uint activation function.
|
|
840
|
-
|
|
841
|
-
Applies the exponential linear unit function element-wise.
|
|
842
|
-
The activation function is defined as:
|
|
843
|
-
|
|
844
|
-
.. math::
|
|
845
|
-
|
|
846
|
-
\text{ELU}(x)= \left\{
|
|
847
|
-
\begin{array}{align}
|
|
848
|
-
\alpha(e^{x} - 1) & \text{if } x \le 0\\
|
|
849
|
-
x & \text{if } x \gt 0\\
|
|
850
|
-
\end{array}\right.
|
|
851
|
-
|
|
852
|
-
The picture about ELU looks like this `ELU <https://en.wikipedia.org/wiki/
|
|
853
|
-
Activation_function#/media/File:Activation_elu.svg>`_ .
|
|
854
|
-
|
|
855
|
-
Args:
|
|
856
|
-
alpha (float): The alpha value of ELU, the data type is float. Only support '1.0' currently. Default: ``1.0`` .
|
|
857
|
-
|
|
858
|
-
Inputs:
|
|
859
|
-
- **input_x** (Tensor) - The input of ELU is a Tensor of any dimension with data type of
|
|
860
|
-
float16, float32 or float64.
|
|
861
|
-
|
|
862
|
-
Outputs:
|
|
863
|
-
Tensor, has the same shape and data type as `input_x`.
|
|
864
|
-
|
|
865
|
-
Raises:
|
|
866
|
-
TypeError: If `alpha` is not a float.
|
|
867
|
-
TypeError: If dtype of `input_x` is neither float16, float32 nor float64.
|
|
868
|
-
ValueError: If `alpha` is not equal to 1.0.
|
|
869
|
-
|
|
870
|
-
Supported Platforms:
|
|
871
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
872
|
-
|
|
873
|
-
Examples:
|
|
874
|
-
>>> import mindspore
|
|
875
|
-
>>> import numpy as np
|
|
876
|
-
>>> from mindspore import Tensor, ops
|
|
877
|
-
>>> input_x = Tensor(np.array([[-1.0, 4.0, -8.0], [2.0, -5.0, 9.0]]), mindspore.float32)
|
|
878
|
-
>>> elu = ops.Elu()
|
|
879
|
-
>>> output = elu(input_x)
|
|
880
|
-
>>> print(output)
|
|
881
|
-
[[-0.63212055 4. -0.99966455]
|
|
882
|
-
[ 2. -0.99326205 9. ]]
|
|
883
|
-
"""
|
|
884
|
-
|
|
885
|
-
@prim_attr_register
|
|
886
|
-
def __init__(self, alpha=1.0):
|
|
887
|
-
"""Initialize Elu"""
|
|
888
|
-
validator.check_value_type("alpha", alpha, [float], self.name)
|
|
889
|
-
validator.check_number("alpha", alpha, 1.0, validator.EQ, self.name)
|
|
890
|
-
self.init_prim_io_names(inputs=['x'], outputs=['output', 'mask'])
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
class HSwish(Primitive):
|
|
894
|
-
r"""
|
|
895
|
-
Hard swish activation function.
|
|
896
|
-
|
|
897
|
-
Refer to :func:`mindspore.ops.hardswish` for more details.
|
|
898
|
-
|
|
899
|
-
Inputs:
|
|
900
|
-
- **input_x** (Tensor) - The input Tensor.
|
|
901
|
-
|
|
902
|
-
Outputs:
|
|
903
|
-
Tensor, with the same type and shape as the `input_x`.
|
|
904
|
-
|
|
905
|
-
Supported Platforms:
|
|
906
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
907
|
-
|
|
908
|
-
Examples:
|
|
909
|
-
>>> import mindspore
|
|
910
|
-
>>> import numpy as np
|
|
911
|
-
>>> from mindspore import Tensor, ops
|
|
912
|
-
>>> hswish = ops.HSwish()
|
|
913
|
-
>>> input_x = Tensor(np.array([-1, -2, 0, 2, 1]), mindspore.float16)
|
|
914
|
-
>>> result = hswish(input_x)
|
|
915
|
-
>>> print(result)
|
|
916
|
-
[-0.3333 -0.3333 0 1.666 0.6665]
|
|
917
|
-
"""
|
|
918
|
-
|
|
919
|
-
@prim_attr_register
|
|
920
|
-
def __init__(self):
|
|
921
|
-
"""Initialize HSwish."""
|
|
922
|
-
self.init_prim_io_names(inputs=['x'], outputs=['output'])
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
class Sigmoid(Primitive):
|
|
926
|
-
r"""
|
|
927
|
-
Sigmoid activation function.
|
|
928
|
-
|
|
929
|
-
Refer to :func:`mindspore.ops.sigmoid` for more details.
|
|
930
|
-
|
|
931
|
-
Inputs:
|
|
932
|
-
- **input_x** (Tensor) - Tensor of any dimension.
|
|
933
|
-
|
|
934
|
-
Outputs:
|
|
935
|
-
Tensor, with the same type and shape as the input_x.
|
|
936
|
-
|
|
937
|
-
Supported Platforms:
|
|
938
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
939
|
-
|
|
940
|
-
Examples:
|
|
941
|
-
>>> import mindspore
|
|
942
|
-
>>> import numpy as np
|
|
943
|
-
>>> from mindspore import Tensor, ops
|
|
944
|
-
>>> input_x = Tensor(np.array([1, 2, 3, 4, 5]), mindspore.float32)
|
|
945
|
-
>>> sigmoid = ops.Sigmoid()
|
|
946
|
-
>>> output = sigmoid(input_x)
|
|
947
|
-
>>> print(output)
|
|
948
|
-
[0.7310586 0.880797 0.95257413 0.98201376 0.9933072 ]
|
|
949
|
-
"""
|
|
950
|
-
|
|
951
|
-
@prim_attr_register
|
|
952
|
-
def __init__(self):
|
|
953
|
-
"""Initialize Sigmoid."""
|
|
954
|
-
self.init_prim_io_names(inputs=['x'], outputs=['output'])
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
class HSigmoid(Primitive):
|
|
958
|
-
r"""
|
|
959
|
-
Hard sigmoid activation function.
|
|
960
|
-
|
|
961
|
-
Refer to :func:`mindspore.ops.hardsigmoid` for more details.
|
|
962
|
-
|
|
963
|
-
Inputs:
|
|
964
|
-
- **input_x** (Tensor) - The input Tensor.
|
|
965
|
-
|
|
966
|
-
Outputs:
|
|
967
|
-
Tensor, with the same type and shape as the `input_x`.
|
|
968
|
-
|
|
969
|
-
Supported Platforms:
|
|
970
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
971
|
-
|
|
972
|
-
Examples:
|
|
973
|
-
>>> import mindspore
|
|
974
|
-
>>> import numpy as np
|
|
975
|
-
>>> from mindspore import Tensor, ops
|
|
976
|
-
>>> hsigmoid = ops.HSigmoid()
|
|
977
|
-
>>> input_x = Tensor(np.array([-1, -2, 0, 2, 1]), mindspore.float16)
|
|
978
|
-
>>> result = hsigmoid(input_x)
|
|
979
|
-
>>> print(result)
|
|
980
|
-
[0.3333 0.1666 0.5 0.8335 0.6665]
|
|
981
|
-
"""
|
|
982
|
-
|
|
983
|
-
@prim_attr_register
|
|
984
|
-
def __init__(self):
|
|
985
|
-
"""Initialize HSigmoid."""
|
|
986
|
-
self.init_prim_io_names(inputs=['input_x'], outputs=['output'])
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
class Tanh(Primitive):
|
|
990
|
-
r"""
|
|
991
|
-
Computes hyperbolic tangent of input element-wise.
|
|
992
|
-
|
|
993
|
-
Refer to :func:`mindspore.ops.tanh` for more details.
|
|
994
|
-
|
|
995
|
-
Inputs:
|
|
996
|
-
- **input_x** (Tensor) - Input Tensor of any dimension.
|
|
997
|
-
|
|
998
|
-
Outputs:
|
|
999
|
-
Tensor, with the same type and shape as the `input_x`.
|
|
1000
|
-
|
|
1001
|
-
Supported Platforms:
|
|
1002
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
1003
|
-
|
|
1004
|
-
Examples:
|
|
1005
|
-
>>> import mindspore
|
|
1006
|
-
>>> import numpy as np
|
|
1007
|
-
>>> from mindspore import Tensor, ops
|
|
1008
|
-
>>> input_x = Tensor(np.array([1, 2, 3, 4, 5]), mindspore.float32)
|
|
1009
|
-
>>> tanh = ops.Tanh()
|
|
1010
|
-
>>> output = tanh(input_x)
|
|
560
|
+
>>> output = selu(input_x)
|
|
1011
561
|
>>> print(output)
|
|
1012
|
-
[
|
|
562
|
+
[[-1.1113307 4.202804 -1.7575096]
|
|
563
|
+
[ 2.101402 -1.7462534 9.456309 ]]
|
|
1013
564
|
"""
|
|
1014
565
|
|
|
1015
566
|
@prim_attr_register
|
|
1016
567
|
def __init__(self):
|
|
1017
|
-
"""Initialize
|
|
1018
|
-
self.init_prim_io_names(inputs=['
|
|
568
|
+
"""Initialize SeLU"""
|
|
569
|
+
self.init_prim_io_names(inputs=['input_x'], outputs=['output'])
|
|
570
|
+
|
|
571
|
+
|
|
1019
572
|
|
|
1020
573
|
|
|
1021
574
|
class FusedBatchNorm(Primitive):
|
|
@@ -1229,137 +782,6 @@ class InstanceNormV2(Primitive):
|
|
|
1229
782
|
validator.check_bool(is_training, "is_training", self.name)
|
|
1230
783
|
|
|
1231
784
|
|
|
1232
|
-
class BatchNorm(PrimitiveWithInfer):
|
|
1233
|
-
r"""
|
|
1234
|
-
Batch Normalization for input data and updated parameters.
|
|
1235
|
-
|
|
1236
|
-
Batch Normalization is widely used in convolutional neural networks. This operation
|
|
1237
|
-
applies Batch Normalization over inputs to avoid internal covariate shift as described
|
|
1238
|
-
in the paper `Batch Normalization: Accelerating Deep Network Training by Reducing Internal
|
|
1239
|
-
Covariate Shift <https://arxiv.org/abs/1502.03167>`_. It rescales and recenters the
|
|
1240
|
-
features using a mini-batch of data and the learned parameters can be described
|
|
1241
|
-
in the following formula,
|
|
1242
|
-
|
|
1243
|
-
.. math::
|
|
1244
|
-
|
|
1245
|
-
y = \frac{x - mean}{\sqrt{variance + \epsilon}} * \gamma + \beta
|
|
1246
|
-
|
|
1247
|
-
where :math:`\gamma` is scale, :math:`\beta` is bias, :math:`\epsilon` is epsilon,
|
|
1248
|
-
:math:`mean` is the mean of :math:`x`,
|
|
1249
|
-
:math:`variance` is the variance of :math:`x`.
|
|
1250
|
-
|
|
1251
|
-
.. warning::
|
|
1252
|
-
- If the operation is used for inference, and outputs "reserve_space_1" and "reserve_space_2" are available,
|
|
1253
|
-
then "reserve_space_1" has the same value as "mean" and "reserve_space_2" has the same value as "variance".
|
|
1254
|
-
- For Ascend 310, the result accuracy fails to reach 1‰ due to the square root instruction.
|
|
1255
|
-
|
|
1256
|
-
Args:
|
|
1257
|
-
is_training (bool): If `is_training` is ``True`` , `mean` and `variance` are computed during training.
|
|
1258
|
-
If `is_training` is ``False`` , they're loaded from checkpoint during inference. Default: ``False`` .
|
|
1259
|
-
epsilon (float): A small value added for numerical stability. Default: ``1e-5``, value must be (0, 1] .
|
|
1260
|
-
momentum (float): The hyper parameter to compute moving average for running_mean and running_var
|
|
1261
|
-
(e.g. :math:`new\_running\_mean = (1 - momentum) * running\_mean + momentum * current\_mean`).
|
|
1262
|
-
Momentum value must be [0, 1]. Default: ``0.1`` .
|
|
1263
|
-
data_format (str): The optional value for data format, is ``'NHWC'`` or ``'NCHW'``, and the ``'NHWC'`` format
|
|
1264
|
-
is only supported in GPU target. Default: ``"NCHW"`` .
|
|
1265
|
-
|
|
1266
|
-
Inputs:
|
|
1267
|
-
If `is_training` is ``False`` , inputs are Tensors.
|
|
1268
|
-
|
|
1269
|
-
- **input_x** (Tensor) - Tensor of shape :math:`(N, C)`, with float16 or float32 data type.
|
|
1270
|
-
- **scale** (Tensor) - Tensor of shape :math:`(C,)`, with float16 or float32 data type.
|
|
1271
|
-
- **bias** (Tensor) - Tensor of shape :math:`(C,)`, has the same data type with `scale`.
|
|
1272
|
-
- **mean** (Tensor) - Tensor of shape :math:`(C,)`, has the same data type with `scale`.
|
|
1273
|
-
- **variance** (Tensor) - Tensor of shape :math:`(C,)`, has the same data type with `scale`.
|
|
1274
|
-
|
|
1275
|
-
If `is_training` is ``True`` , `scale`, `bias`, `mean` and `variance` are Parameters.
|
|
1276
|
-
|
|
1277
|
-
- **input_x** (Tensor) - Tensor of shape :math:`(N, C)`, with float16 or float32 data type.
|
|
1278
|
-
- **scale** (Parameter) - Parameter of shape :math:`(C,)`, with float16 or float32 data type.
|
|
1279
|
-
- **bias** (Parameter) - Parameter of shape :math:`(C,)`, has the same data type with `scale`.
|
|
1280
|
-
- **mean** (Parameter) - Parameter of shape :math:`(C,)`, has the same data type with `scale`.
|
|
1281
|
-
- **variance** (Parameter) - Parameter of shape :math:`(C,)`, has the same data type with `scale`.
|
|
1282
|
-
|
|
1283
|
-
Outputs:
|
|
1284
|
-
Tuple of 5 Tensors, the normalized inputs and the updated parameters.
|
|
1285
|
-
|
|
1286
|
-
- **output_x** (Tensor) - The same type and shape as the input_x. The shape is :math:`(N, C)`.
|
|
1287
|
-
- **batch_mean** (Tensor) - Tensor of shape :math:`(C,)`.
|
|
1288
|
-
- **batch_variance** (Tensor) - Tensor of shape :math:`(C,)`.
|
|
1289
|
-
- **reserve_space_1** (Tensor) - Tensor of shape :math:`(C,)`.
|
|
1290
|
-
- **reserve_space_2** (Tensor) - Tensor of shape :math:`(C,)`.
|
|
1291
|
-
|
|
1292
|
-
Raises:
|
|
1293
|
-
TypeError: If `is_training` is not a bool.
|
|
1294
|
-
TypeError: If dtype of `epsilon` or `momentum` is not float.
|
|
1295
|
-
TypeError: If `data_format` is not a str.
|
|
1296
|
-
TypeError: If `input_x`, `scale`, `bias`, `mean` or `variance` is not a Tensor.
|
|
1297
|
-
TypeError: If dtype of `input_x`, `scale` is neither float16 nor float32.
|
|
1298
|
-
|
|
1299
|
-
Supported Platforms:
|
|
1300
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
1301
|
-
|
|
1302
|
-
Examples:
|
|
1303
|
-
>>> import mindspore
|
|
1304
|
-
>>> import numpy as np
|
|
1305
|
-
>>> from mindspore import Tensor, ops
|
|
1306
|
-
>>> input_x = Tensor(np.ones([2, 2]), mindspore.float32)
|
|
1307
|
-
>>> scale = Tensor(np.ones([2]), mindspore.float32)
|
|
1308
|
-
>>> bias = Tensor(np.ones([2]), mindspore.float32)
|
|
1309
|
-
>>> mean = Tensor(np.ones([2]), mindspore.float32)
|
|
1310
|
-
>>> variance = Tensor(np.ones([2]), mindspore.float32)
|
|
1311
|
-
>>> batch_norm = ops.BatchNorm()
|
|
1312
|
-
>>> output = batch_norm(input_x, scale, bias, mean, variance)
|
|
1313
|
-
>>> print(output[0])
|
|
1314
|
-
[[1. 1.]
|
|
1315
|
-
[1. 1.]]
|
|
1316
|
-
"""
|
|
1317
|
-
|
|
1318
|
-
__mindspore_signature__ = (
|
|
1319
|
-
sig.make_sig('input_x', dtype=sig.sig_dtype.T1),
|
|
1320
|
-
sig.make_sig('scale', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T2),
|
|
1321
|
-
sig.make_sig('bias', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T2),
|
|
1322
|
-
sig.make_sig('mean', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T3),
|
|
1323
|
-
sig.make_sig('variance', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T3)
|
|
1324
|
-
)
|
|
1325
|
-
|
|
1326
|
-
@prim_attr_register
|
|
1327
|
-
def __init__(self, is_training=False, epsilon=1e-5, momentum=0.1, data_format="NCHW"):
|
|
1328
|
-
"""Initialize BatchNorm."""
|
|
1329
|
-
if is_training is False:
|
|
1330
|
-
self.set_signatures(tuple())
|
|
1331
|
-
else:
|
|
1332
|
-
self.add_prim_attr('side_effect_mem', True)
|
|
1333
|
-
validator.check_value_type('is_training', is_training, (bool,), self.name)
|
|
1334
|
-
validator.check_float_range(epsilon, 0, 1, validator.INC_RIGHT, 'epsilon', self.name)
|
|
1335
|
-
validator.check_float_range(momentum, 0, 1, validator.INC_BOTH, 'momentum', self.name)
|
|
1336
|
-
self.format = validator.check_string(data_format, ['NCHW', 'NHWC'], 'format', self.name)
|
|
1337
|
-
if context.get_context("device_target") != "GPU" and self.format == "NHWC":
|
|
1338
|
-
raise ValueError(f"For '{self.name}', the 'NHWC' format is only supported in GPU target, "
|
|
1339
|
-
f"but got the 'data_format' is {self.format} and "
|
|
1340
|
-
f"the platform is {context.get_context('device_target')}.")
|
|
1341
|
-
self.add_prim_attr('data_format', self.format)
|
|
1342
|
-
self.init_prim_io_names(inputs=['x', 'scale', 'offset', 'mean', 'variance'],
|
|
1343
|
-
outputs=['y', 'batch_mean', 'batch_variance', 'reserve_space_1', 'reserve_space_2'])
|
|
1344
|
-
|
|
1345
|
-
def infer_shape(self, input_x, scale, bias, mean, variance):
|
|
1346
|
-
input_x_channel = input_x[-1] if self.format == "NHWC" else input_x[1]
|
|
1347
|
-
validator.check_equal_int(len(scale), 1, "scale rank", self.name)
|
|
1348
|
-
validator.check("scale shape", scale, "bias shape", bias, validator.EQ, self.name)
|
|
1349
|
-
validator.check("scale shape[0]", scale[0], "input_x channel", input_x_channel, validator.EQ, self.name)
|
|
1350
|
-
if not self.is_training:
|
|
1351
|
-
validator.check_equal_int(len(mean), 1, "mean rank", self.name)
|
|
1352
|
-
validator.check("mean shape", mean, "variance shape", variance, validator.EQ, self.name)
|
|
1353
|
-
validator.check("mean shape", mean, "scale shape", scale, validator.EQ, self.name)
|
|
1354
|
-
return input_x, scale, scale, scale, scale
|
|
1355
|
-
|
|
1356
|
-
def infer_dtype(self, input_x, scale, bias, mean, variance):
|
|
1357
|
-
validator.check_tensor_dtype_valid("input_x", input_x, [mstype.float16, mstype.float32], self.name)
|
|
1358
|
-
args = {"scale": scale, "bias": bias, "mean": mean, "variance": variance}
|
|
1359
|
-
validator.check_tensors_dtypes_same_and_valid(args, [mstype.float16, mstype.float32], self.name)
|
|
1360
|
-
return input_x, mstype.float32, mstype.float32, mstype.float32, mstype.float32
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
785
|
class Conv2D(Primitive):
|
|
1364
786
|
r"""
|
|
1365
787
|
2D convolution layer.
|
|
@@ -1379,21 +801,26 @@ class Conv2D(Primitive):
|
|
|
1379
801
|
, :math:`weight` is the convolution kernel value and :math:`X` represents the input feature map.
|
|
1380
802
|
|
|
1381
803
|
Here are the indices' meanings:
|
|
1382
|
-
- :math:`i` corresponds to the batch number, ranging from 0 to N-1, where N is the batch size of the input.
|
|
1383
804
|
|
|
1384
|
-
- :math:`
|
|
805
|
+
- :math:`i` corresponds to the batch number, the range is :math:`[0, N-1]`,
|
|
806
|
+
where :math:`N` is the batch size of the input.
|
|
807
|
+
|
|
808
|
+
- :math:`j` corresponds to the output channel, the range is :math:`[0, C_{out}-1]`,
|
|
809
|
+
where :math:`C_{out}` is the number of
|
|
1385
810
|
output channels, which is also equal to the number of kernels.
|
|
1386
811
|
|
|
1387
|
-
- :math:`k` corresponds to the input channel,
|
|
812
|
+
- :math:`k` corresponds to the input channel, the range is :math:`[0, C_{in}-1]`,
|
|
813
|
+
where :math:`C_{in}` is the number of
|
|
1388
814
|
input channels, which is also equal to the number of channels in the convolutional kernels.
|
|
1389
815
|
|
|
1390
|
-
Therefore, in the above formula, :math:`{bias}(C_{
|
|
1391
|
-
output channel, :math:`{weight}(C_{
|
|
816
|
+
Therefore, in the above formula, :math:`{bias}(C_{\text{out}_j})` represents the bias of the :math:`j`-th
|
|
817
|
+
output channel, :math:`{weight}(C_{\text{out}_j}, k)` represents the slice of the :math:`j`-th convolutional
|
|
1392
818
|
kernel in the :math:`k`-th channel, and :math:`{X}(N_i, k)` represents the slice of the :math:`k`-th input
|
|
1393
819
|
channel in the :math:`i`-th batch of the input feature map.
|
|
1394
820
|
|
|
1395
|
-
The shape of the convolutional kernel is given by :math:`(
|
|
1396
|
-
where :math
|
|
821
|
+
The shape of the convolutional kernel is given by :math:`(\text{kernel_size[0]},\text{kernel_size[1]})`,
|
|
822
|
+
where :math:`\text{kernel_size[0]}`
|
|
823
|
+
and :math:`\text{kernel_size[1]}` are the height and width of the kernel, respectively.
|
|
1397
824
|
If we consider the input and output channels as well as the `group` parameter, the complete kernel shape
|
|
1398
825
|
will be :math:`(C_{out}, C_{in} / \text{group}, \text{kernel_size[0]}, \text{kernel_size[1]})`,
|
|
1399
826
|
where `group` is the number of groups dividing `x`'s input channel when applying group convolution.
|
|
@@ -1450,7 +877,7 @@ class Conv2D(Primitive):
|
|
|
1450
877
|
group (int, optional): Specifies the number of groups dividing `x`'s input channel when applying
|
|
1451
878
|
group convolution. Default: ``1`` .
|
|
1452
879
|
data_format (str, optional): The optional value for data format, is ``'NHWC'`` or ``'NCHW'`` .
|
|
1453
|
-
Default: ``"NCHW"
|
|
880
|
+
Default: ``"NCHW"``. (NHWC is only supported in GPU now.)
|
|
1454
881
|
|
|
1455
882
|
Inputs:
|
|
1456
883
|
- **x** (Tensor) - Input tensor of shape :math:`(N, C_{in}, H_{in}, W_{in})` or
|
|
@@ -1844,13 +1271,13 @@ class MaxPool(_Pool):
|
|
|
1844
1271
|
not only the height of movement but also the width of movement, or a tuple of two int numbers that
|
|
1845
1272
|
represent height and width of movement respectively. Default: ``1`` .
|
|
1846
1273
|
pad_mode (str, optional): Specifies the padding mode with a padding value of 0. It can be set to:
|
|
1847
|
-
``
|
|
1274
|
+
``'same'`` or ``'valid'`` . Default: ``'valid'`` .
|
|
1848
1275
|
|
|
1849
|
-
- ``
|
|
1276
|
+
- ``'same'``: Pad the input around its edges so that the shape of input and output
|
|
1850
1277
|
are the same when `stride` is set to ``1``.
|
|
1851
1278
|
The amount of padding to is calculated by the operator internally, If the amount is even, it is
|
|
1852
1279
|
uniformly distributed around the input, if it is odd, the excess amount goes to the right/bottom side.
|
|
1853
|
-
- ``
|
|
1280
|
+
- ``'valid'``: No padding is applied to the input, and the output returns the maximum
|
|
1854
1281
|
possible height and width. Extra pixels that could not complete a full stride will
|
|
1855
1282
|
be discarded.
|
|
1856
1283
|
|
|
@@ -1869,8 +1296,8 @@ class MaxPool(_Pool):
|
|
|
1869
1296
|
|
|
1870
1297
|
Raises:
|
|
1871
1298
|
TypeError: If `kernel_size` or `strides` is neither int nor tuple.
|
|
1872
|
-
ValueError: If `pad_mode` is neither 'valid' nor 'same' with not case sensitive.
|
|
1873
|
-
ValueError: If `data_format` is neither 'NCHW' nor 'NHWC'
|
|
1299
|
+
ValueError: If `pad_mode` is neither ``'valid'`` nor ``'same'`` with not case sensitive.
|
|
1300
|
+
ValueError: If `data_format` is neither ``'NCHW'`` nor ``'NHWC'``.
|
|
1874
1301
|
ValueError: If `kernel_size` or `strides` is less than 1.
|
|
1875
1302
|
ValueError: If length of shape of `input` is not equal to 4.
|
|
1876
1303
|
|
|
@@ -2033,10 +1460,10 @@ class MaxPool3D(Primitive):
|
|
|
2033
1460
|
pad[3], pad[4] and pad[5] correspondingly.
|
|
2034
1461
|
ceil_mode (Union[bool, None]): Whether to use ceil instead of floor to calculate output shape.
|
|
2035
1462
|
Only effective in "pad" mode.
|
|
2036
|
-
When
|
|
1463
|
+
When `pad_mode` is ``"pad"`` and "ceil_mode" is ``None`` , `ceil_mode` will be set as ``False``.
|
|
2037
1464
|
Default: ``None`` .
|
|
2038
|
-
data_format (str) : The optional value for data format. Currently only support ``
|
|
2039
|
-
Default: ``
|
|
1465
|
+
data_format (str) : The optional value for data format. Currently only support ``"NCDHW"`` .
|
|
1466
|
+
Default: ``"NCDHW"`` .
|
|
2040
1467
|
|
|
2041
1468
|
Inputs:
|
|
2042
1469
|
- **x** (Tensor) - Tensor of shape :math:`(N, C, D_{in}, H_{in}, W_{in})`.
|
|
@@ -2049,10 +1476,10 @@ class MaxPool3D(Primitive):
|
|
|
2049
1476
|
TypeError: If `kernel_size` or `strides` is neither an int nor a tuple.
|
|
2050
1477
|
TypeError: If `pad_mode` or `data_format` is not a string.
|
|
2051
1478
|
ValueError: If numbers in `kernel_size` or `strides` are not positive.
|
|
2052
|
-
ValueError: If `pad_mode` is not one of
|
|
2053
|
-
ValueError: If `pad_mode` is
|
|
1479
|
+
ValueError: If `pad_mode` is not one of ``"SAME"``, ``"VALID"`` or ``"PAD"``.
|
|
1480
|
+
ValueError: If `pad_mode` is ``"SAME"`` or ``"VALID"``, `ceil_mode` is not ``None``.
|
|
2054
1481
|
ValueError: If `kernel_size` or `strides` is a tuple whose length is not equal to 3.
|
|
2055
|
-
ValueError: If `data_format` is not
|
|
1482
|
+
ValueError: If `data_format` is not ``"NCDHW"``.
|
|
2056
1483
|
|
|
2057
1484
|
Supported Platforms:
|
|
2058
1485
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -2278,7 +1705,7 @@ class MaxUnpool3D(Primitive):
|
|
|
2278
1705
|
ValueError: If numbers in `strides` or `ksize` is negative.
|
|
2279
1706
|
ValueError: If numbers in `pads` is negative.
|
|
2280
1707
|
ValueError: If `ksize`, `strides` or `pads` is a tuple whose length is not equal to 3.
|
|
2281
|
-
ValueError: If `data_format` is not a str or is neither
|
|
1708
|
+
ValueError: If `data_format` is not a str or is neither ``'NCDHW'`` nor ``'NDHWC'``.
|
|
2282
1709
|
ValueError: If `output_shape` whose length is neither 0 or 5.
|
|
2283
1710
|
ValueError: If `output_shape` is not close to output size range
|
|
2284
1711
|
computed by attr `ksize, strides, pads`.
|
|
@@ -2321,98 +1748,6 @@ class MaxUnpool3D(Primitive):
|
|
|
2321
1748
|
self.output_shape = output_shape
|
|
2322
1749
|
|
|
2323
1750
|
|
|
2324
|
-
class AvgPool(Primitive):
|
|
2325
|
-
r"""
|
|
2326
|
-
Average pooling operation.
|
|
2327
|
-
|
|
2328
|
-
Refer to :func:`mindspore.ops.avg_pool2d` for more details.
|
|
2329
|
-
|
|
2330
|
-
Args:
|
|
2331
|
-
kernel_size (Union[int, tuple[int]]): The size of kernel used to take the average value,
|
|
2332
|
-
is an int number that represents height and width of the kernel, or a tuple
|
|
2333
|
-
of two int numbers that represent height and width respectively. Default: ``1`` .
|
|
2334
|
-
strides (Union[int, tuple[int]]): The distance of kernel moving, an int number that represents
|
|
2335
|
-
the height and width of movement are both strides, or a tuple of two int numbers that
|
|
2336
|
-
represent height and width of movement respectively. Default: ``1`` .
|
|
2337
|
-
pad_mode (str, optional): Specifies the padding mode with a padding value of 0. It can be set to:
|
|
2338
|
-
``"same"`` or ``"valid"`` . Default: ``"valid"`` .
|
|
2339
|
-
|
|
2340
|
-
- ``"same"``: Pad the input around its edges so that the shape of input and output
|
|
2341
|
-
are the same when `stride` is set to ``1``.
|
|
2342
|
-
The amount of padding to is calculated by the operator internally, If the amount is even, it is
|
|
2343
|
-
uniformly distributed around the input, if it is odd, the excess amount goes to the right/bottom side.
|
|
2344
|
-
- ``"valid"``: No padding is applied to the input, and the output returns the maximum
|
|
2345
|
-
possible height and width. Extra pixels that could not complete a full stride will
|
|
2346
|
-
be discarded.
|
|
2347
|
-
|
|
2348
|
-
data_format (str, optional): The format of input and output data. It should be ``'NHWC'`` or ``'NCHW'`` .
|
|
2349
|
-
Default: ``'NCHW'`` .
|
|
2350
|
-
|
|
2351
|
-
Inputs:
|
|
2352
|
-
- **x** (Tensor) - Tensor of shape :math:`(N, C_{in}, H_{in}, W_{in})`.
|
|
2353
|
-
Supported dtypes: float16, float32, float64.
|
|
2354
|
-
|
|
2355
|
-
Outputs:
|
|
2356
|
-
Tensor, with shape :math:`(N, C_{out}, H_{out}, W_{out})`.
|
|
2357
|
-
|
|
2358
|
-
Raises:
|
|
2359
|
-
TypeError: If `kernel_size` or `strides` is neither int nor tuple.
|
|
2360
|
-
TypeError: If dtype of `x` is not float16, float32 or float64.
|
|
2361
|
-
ValueError: If `kernel_size` or `strides` is less than 1.
|
|
2362
|
-
ValueError: If `pad_mode` is neither 'valid' nor 'same' with not case sensitive.
|
|
2363
|
-
ValueError: If `data_format` is neither 'NCHW' nor 'NHWC'.
|
|
2364
|
-
ValueError: If length of shape of `x` is not equal to 4.
|
|
2365
|
-
|
|
2366
|
-
Supported Platforms:
|
|
2367
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
2368
|
-
|
|
2369
|
-
Examples:
|
|
2370
|
-
>>> import mindspore
|
|
2371
|
-
>>> import numpy as np
|
|
2372
|
-
>>> from mindspore import Tensor, ops, nn
|
|
2373
|
-
>>> class Net(nn.Cell):
|
|
2374
|
-
... def __init__(self):
|
|
2375
|
-
... super(Net, self).__init__()
|
|
2376
|
-
... self.avgpool_op = ops.AvgPool(pad_mode="VALID", kernel_size=2, strides=1)
|
|
2377
|
-
...
|
|
2378
|
-
... def construct(self, x):
|
|
2379
|
-
... result = self.avgpool_op(x)
|
|
2380
|
-
... return result
|
|
2381
|
-
...
|
|
2382
|
-
>>> x = Tensor(np.arange(1 * 3 * 3 * 4).reshape(1, 3, 3, 4), mindspore.float32)
|
|
2383
|
-
>>> net = Net()
|
|
2384
|
-
>>> output = net(x)
|
|
2385
|
-
>>> print(output)
|
|
2386
|
-
[[[[ 2.5 3.5 4.5]
|
|
2387
|
-
[ 6.5 7.5 8.5]]
|
|
2388
|
-
[[14.5 15.5 16.5]
|
|
2389
|
-
[18.5 19.5 20.5]]
|
|
2390
|
-
[[26.5 27.5 28.5]
|
|
2391
|
-
[30.5 31.5 32.5]]]]
|
|
2392
|
-
"""
|
|
2393
|
-
|
|
2394
|
-
@prim_attr_register
|
|
2395
|
-
def __init__(self, kernel_size=1, strides=1, pad_mode="valid", data_format="NCHW"):
|
|
2396
|
-
"""Initialize AvgPool."""
|
|
2397
|
-
self.init_prim_io_names(inputs=['x'], outputs=['output'])
|
|
2398
|
-
validator.check_value_type('kernel_size', kernel_size, [int, tuple], self.name)
|
|
2399
|
-
validator.check_value_type('strides', strides, [int, tuple], self.name)
|
|
2400
|
-
validator.check_value_type('pad_mode', pad_mode, [str], self.name)
|
|
2401
|
-
self.pad_mode = validator.check_string(pad_mode.upper(), ['VALID', 'SAME'], 'pad_mode', self.name)
|
|
2402
|
-
self.add_prim_attr("pad_mode", self.pad_mode)
|
|
2403
|
-
self.format = validator.check_string(data_format, ['NCHW', 'NHWC'], 'format', self.name)
|
|
2404
|
-
if context.get_context("device_target") != "GPU" and self.format == "NHWC":
|
|
2405
|
-
raise ValueError(f"For '{self.name}', the 'NHWC' format is only supported in GPU target, "
|
|
2406
|
-
f"but got the 'data_format' is {self.format} and "
|
|
2407
|
-
f"the platform is {context.get_context('device_target')}.")
|
|
2408
|
-
self.add_prim_attr('data_format', self.format)
|
|
2409
|
-
self.kernel_size = _check_positive_int_or_tuple(
|
|
2410
|
-
"kernel_size", kernel_size, self.name, allow_four=False, ret_four=True)
|
|
2411
|
-
self.add_prim_attr("kernel_size", self.kernel_size)
|
|
2412
|
-
self.strides = _check_positive_int_or_tuple("strides", strides, self.name, allow_four=False, ret_four=True)
|
|
2413
|
-
self.add_prim_attr("strides", self.strides)
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
1751
|
class AvgPoolV1(Primitive):
|
|
2417
1752
|
r"""
|
|
2418
1753
|
Average-pooling operation.
|
|
@@ -2641,7 +1976,7 @@ class MaxPool3DWithArgmax(Primitive):
|
|
|
2641
1976
|
TypeError: If `ksize` , `strides` , `pads` or `dilation` is not int or tuple.
|
|
2642
1977
|
ValueError: If `ksize` or `strides` is less than 1.
|
|
2643
1978
|
ValueError: If `pads` is less than 0.
|
|
2644
|
-
ValueError: If `data_format` is not 'NCDHW'
|
|
1979
|
+
ValueError: If `data_format` is not ``'NCDHW'``.
|
|
2645
1980
|
ValueError: If `argmax_type` is not mindspore.int64 or mindspore.int32.
|
|
2646
1981
|
|
|
2647
1982
|
Supported Platforms:
|
|
@@ -2700,216 +2035,76 @@ class Conv2DTranspose(Conv2DBackpropInput):
|
|
|
2700
2035
|
out_channel (int): The dimensionality of the output space.
|
|
2701
2036
|
kernel_size (Union[int, tuple[int]]): The size of the convolution window.
|
|
2702
2037
|
pad_mode (str, optional): Specifies the padding mode with a padding value of 0. It can be set to:
|
|
2703
|
-
``"same"`` , ``"valid"`` or ``"pad"`` . Default: ``"valid"`` .
|
|
2704
|
-
|
|
2705
|
-
- ``"same"``: Pad the input around its edges so that the shape of input and output
|
|
2706
|
-
are the same when `stride` is set to ``1``.
|
|
2707
|
-
The amount of padding to is calculated by the operator internally, If the amount is even, it is
|
|
2708
|
-
uniformly distributed around the input, if it is odd, the excess amount goes to the right/bottom side.
|
|
2709
|
-
If this mode is set, `pad` must be 0.
|
|
2710
|
-
- ``"valid"``: No padding is applied to the input, and the output returns the maximum
|
|
2711
|
-
possible height and width. Extra pixels that could not complete a full stride will
|
|
2712
|
-
be discarded. If this mode is set, `pad` must be 0.
|
|
2713
|
-
- ``"pad"``: Pad the input with a specified amount. In this mode, the amount of padding
|
|
2714
|
-
in the height and width directions is determined by the `pad` parameter.
|
|
2715
|
-
If this mode is set, `pad` must be greater than or equal to 0.
|
|
2716
|
-
|
|
2717
|
-
Please refer to :class:`mindspore.nn.Conv2dTranspose` for more specifications about `pad_mode`.
|
|
2718
|
-
pad (Union[int, tuple[int]]): The pad value to be filled. Default: ``0`` . If `pad` is an integer, the paddings
|
|
2719
|
-
of top, bottom, left and right are the same, equal to pad. If `pad` is a tuple of four integers,
|
|
2720
|
-
the padding of top, bottom, left and right equal to pad[0], pad[1], pad[2], and pad[3]
|
|
2721
|
-
correspondingly.
|
|
2722
|
-
pad_list (Union[str, None]): The pad list like (top, bottom, left, right). Default: ``None`` .
|
|
2723
|
-
mode (int): Modes for different convolutions. The value is currently not used. Default: ``1`` .
|
|
2724
|
-
stride (Union[int, tuple[int]]): The stride to be applied to the convolution filter. Default: ``1`` .
|
|
2725
|
-
dilation (Union[int, tuple[int]]): Specifies the dilation rate to be used for the dilated convolution.
|
|
2726
|
-
Default: ``1`` .
|
|
2727
|
-
group (int): Splits input into groups. Default: ``1`` .
|
|
2728
|
-
data_format (str): The format of input and output data. It should be ``'NHWC'`` or ``'NCHW'`` .
|
|
2729
|
-
Default is ``'NCHW'`` .
|
|
2730
|
-
|
|
2731
|
-
Inputs:
|
|
2732
|
-
- **dout** (Tensor) - the gradients with respect to the output of the convolution.
|
|
2733
|
-
The shape conforms to the default data_format :math:`(N, C_{out}, H_{out}, W_{out})`.
|
|
2734
|
-
- **weight** (Tensor) - Set size of kernel is :math:`(K_1, K_2)`, then the shape is
|
|
2735
|
-
:math:`(C_{out}, C_{in}, K_1, K_2)`.
|
|
2736
|
-
- **input_size** (Tensor) - A tuple describes the shape of the input which conforms to the format
|
|
2737
|
-
:math:`(N, C_{in}, H_{in}, W_{in})`.
|
|
2738
|
-
|
|
2739
|
-
Outputs:
|
|
2740
|
-
Tensor, the gradients with respect to the input of convolution. It has the same shape as the input.
|
|
2741
|
-
|
|
2742
|
-
Raises:
|
|
2743
|
-
TypeError: If `kernel_size`, `stride`, `pad` or `dilation` is neither an int nor a tuple.
|
|
2744
|
-
TypeError: If `out_channel` or `group` is not an int.
|
|
2745
|
-
ValueError: If `kernel_size`, `stride` or `dilation` is less than 1.
|
|
2746
|
-
ValueError: If `pad_mode` is not one of 'same', 'valid' or 'pad'.
|
|
2747
|
-
ValueError: If `padding` is a tuple whose length is not equal to 4.
|
|
2748
|
-
ValueError: If `pad_mode` it not equal to 'pad' and `pad` is not equal to (0, 0, 0, 0).
|
|
2749
|
-
ValueError: If `data_format` is neither 'NCHW' nor 'NHWC'.
|
|
2750
|
-
|
|
2751
|
-
Supported Platforms:
|
|
2752
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
2753
|
-
|
|
2754
|
-
Examples:
|
|
2755
|
-
>>> import mindspore
|
|
2756
|
-
>>> import numpy as np
|
|
2757
|
-
>>> from mindspore import Tensor, ops
|
|
2758
|
-
>>> dout = Tensor(np.ones([10, 32, 30, 30]), mindspore.float32)
|
|
2759
|
-
>>> weight = Tensor(np.ones([32, 32, 3, 3]), mindspore.float32)
|
|
2760
|
-
>>> x = Tensor(np.ones([10, 32, 32, 32]))
|
|
2761
|
-
>>> conv2d_transpose_input = ops.Conv2DTranspose(out_channel=32, kernel_size=3)
|
|
2762
|
-
>>> output = conv2d_transpose_input(dout, weight, ops.shape(x))
|
|
2763
|
-
>>> print(output.shape)
|
|
2764
|
-
(10, 32, 32, 32)
|
|
2765
|
-
"""
|
|
2766
|
-
|
|
2767
|
-
@prim_attr_register
|
|
2768
|
-
def __init__(self, out_channel, kernel_size, pad_mode="valid", pad=0,
|
|
2769
|
-
pad_list=None, mode=1, stride=1, dilation=1, group=1, data_format="NCHW"):
|
|
2770
|
-
"""Initialize Conv2DTranspose."""
|
|
2771
|
-
super(Conv2DTranspose, self).__init__(out_channel, kernel_size, pad_mode, pad,
|
|
2772
|
-
pad_list, mode, stride, dilation, group, data_format)
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
class BiasAdd(Primitive):
|
|
2776
|
-
r"""
|
|
2777
|
-
Returns the sum of the input Tensor and the bias Tensor. Before adding, the bias Tensor will be broadcasted to be
|
|
2778
|
-
consistent with the shape of the input Tensor.
|
|
2779
|
-
|
|
2780
|
-
Args:
|
|
2781
|
-
data_format (str, optional): The format of input and output data.
|
|
2782
|
-
It should be ``"NHWC"`` , ``"NCHW"`` or ``"NCDHW"`` .
|
|
2783
|
-
Default is ``"NCHW"`` .
|
|
2784
|
-
|
|
2785
|
-
Inputs:
|
|
2786
|
-
- **input_x** (Tensor) - The input tensor. The shape can be 2-5 dimensions. Supported dtypes:
|
|
2787
|
-
|
|
2788
|
-
- Ascend/CPU: all Number type.
|
|
2789
|
-
- GPU: float16, float32, int8.
|
|
2790
|
-
|
|
2791
|
-
- **bias** (Tensor) - The bias tensor, with shape :math:`(C)`. C must be the same as channel dimension C of
|
|
2792
|
-
`input_x`. It has the same type as `input_x`.
|
|
2793
|
-
|
|
2794
|
-
Outputs:
|
|
2795
|
-
Tensor, with the same shape and data type as `input_x`.
|
|
2796
|
-
|
|
2797
|
-
Raises:
|
|
2798
|
-
TypeError: If `data_format` is not a str.
|
|
2799
|
-
ValueError: If value of `data_format` is not in the range of ['NHWC','NCHW','NCDHW'].
|
|
2800
|
-
TypeError: If `input_x` or `bias` is not a Tensor.
|
|
2801
|
-
TypeError: If dtype of `input_x` and `bias` is inconsistent.
|
|
2802
|
-
TypeError: If dimension of `input_x` is not in the range [2, 5].
|
|
2803
|
-
|
|
2804
|
-
Supported Platforms:
|
|
2805
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
2806
|
-
|
|
2807
|
-
Examples:
|
|
2808
|
-
>>> import mindspore
|
|
2809
|
-
>>> import numpy as np
|
|
2810
|
-
>>> from mindspore import Tensor, ops
|
|
2811
|
-
>>> input_x = Tensor(np.arange(6).reshape((2, 3)), mindspore.float32)
|
|
2812
|
-
>>> bias = Tensor(np.random.random(3).reshape((3,)), mindspore.float32)
|
|
2813
|
-
>>> bias_add = ops.BiasAdd()
|
|
2814
|
-
>>> output = bias_add(input_x, bias)
|
|
2815
|
-
>>> print(output.shape)
|
|
2816
|
-
(2, 3)
|
|
2817
|
-
"""
|
|
2818
|
-
|
|
2819
|
-
@prim_attr_register
|
|
2820
|
-
def __init__(self, data_format="NCHW"):
|
|
2821
|
-
"""Initialize BiasAdd."""
|
|
2822
|
-
self.init_prim_io_names(inputs=['x', 'b'], outputs=['output'])
|
|
2823
|
-
self.format = validator.check_string(data_format, ['NCHW', 'NHWC', 'NCDHW'], 'format', self.name)
|
|
2824
|
-
self.add_prim_attr('data_format', self.format)
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
class NLLLoss(Primitive):
|
|
2828
|
-
r"""
|
|
2829
|
-
Gets the negative log likelihood loss between logits and labels.
|
|
2830
|
-
|
|
2831
|
-
The nll loss with :math:`reduction = none` can be described as:
|
|
2832
|
-
|
|
2833
|
-
.. math::
|
|
2834
|
-
|
|
2835
|
-
\ell(x, t)=L=\left\{l_{1}, \ldots, l_{N}\right\}^{\top},
|
|
2836
|
-
\quad l_{n}=-w_{t_{n}} x_{n, t_{n}},
|
|
2837
|
-
\quad w_{c}=\text { weight }[c] \cdot 1
|
|
2838
|
-
|
|
2839
|
-
where :math:`x` is the logits, :math:`t` is the labels, :math:`w` is the weight,
|
|
2840
|
-
N is the batch size, :math:`c` belonging to [0, C-1] is class index, where :math:`C` is the number of classes.
|
|
2841
|
-
|
|
2842
|
-
If :math:`reduction \neq none` (default ``'mean'`` ), then
|
|
2843
|
-
|
|
2844
|
-
.. math::
|
|
2845
|
-
|
|
2846
|
-
\ell(x, t)=\left\{\begin{array}{ll}
|
|
2847
|
-
\sum_{n=1}^{N} \frac{1}{\sum_{n=1}^{N} w_{t n}} l_{n}, & \text { if reduction }=\text { 'mean'; } \\
|
|
2848
|
-
\sum_{n=1}^{N} l_{n}, & \text { if reduction }=\text { 'sum' }
|
|
2849
|
-
\end{array}\right.
|
|
2850
|
-
|
|
2851
|
-
Args:
|
|
2852
|
-
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
2853
|
-
``'sum'`` . Default: ``'mean'`` .
|
|
2038
|
+
``"same"`` , ``"valid"`` or ``"pad"`` . Default: ``"valid"`` .
|
|
2854
2039
|
|
|
2855
|
-
- ``
|
|
2856
|
-
|
|
2857
|
-
|
|
2040
|
+
- ``"same"``: Pad the input around its edges so that the shape of input and output
|
|
2041
|
+
are the same when `stride` is set to ``1``.
|
|
2042
|
+
The amount of padding to is calculated by the operator internally, If the amount is even, it is
|
|
2043
|
+
uniformly distributed around the input, if it is odd, the excess amount goes to the right/bottom side.
|
|
2044
|
+
If this mode is set, `pad` must be 0.
|
|
2045
|
+
- ``"valid"``: No padding is applied to the input, and the output returns the maximum
|
|
2046
|
+
possible height and width. Extra pixels that could not complete a full stride will
|
|
2047
|
+
be discarded. If this mode is set, `pad` must be 0.
|
|
2048
|
+
- ``"pad"``: Pad the input with a specified amount. In this mode, the amount of padding
|
|
2049
|
+
in the height and width directions is determined by the `pad` parameter.
|
|
2050
|
+
If this mode is set, `pad` must be greater than or equal to 0.
|
|
2858
2051
|
|
|
2859
|
-
|
|
2860
|
-
|
|
2052
|
+
Please refer to :class:`mindspore.nn.Conv2dTranspose` for more specifications about `pad_mode`.
|
|
2053
|
+
pad (Union[int, tuple[int]]): The pad value to be filled. Default: ``0`` . If `pad` is an integer, the paddings
|
|
2054
|
+
of top, bottom, left and right are the same, equal to pad. If `pad` is a tuple of four integers,
|
|
2055
|
+
the padding of top, bottom, left and right equal to pad[0], pad[1], pad[2], and pad[3]
|
|
2056
|
+
correspondingly.
|
|
2057
|
+
pad_list (Union[str, None]): The pad list like (top, bottom, left, right). Default: ``None`` .
|
|
2058
|
+
mode (int): Modes for different convolutions. The value is currently not used. Default: ``1`` .
|
|
2059
|
+
stride (Union[int, tuple[int]]): The stride to be applied to the convolution filter. Default: ``1`` .
|
|
2060
|
+
dilation (Union[int, tuple[int]]): Specifies the dilation rate to be used for the dilated convolution.
|
|
2061
|
+
Default: ``1`` .
|
|
2062
|
+
group (int): Splits input into groups. Default: ``1`` .
|
|
2063
|
+
data_format (str): The format of input and output data. It should be ``'NHWC'`` or ``'NCHW'`` .
|
|
2064
|
+
Default is ``'NCHW'`` .
|
|
2861
2065
|
|
|
2862
2066
|
Inputs:
|
|
2863
|
-
- **
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2067
|
+
- **dout** (Tensor) - the gradients with respect to the output of the convolution.
|
|
2068
|
+
The shape conforms to the default data_format :math:`(N, C_{out}, H_{out}, W_{out})`.
|
|
2069
|
+
- **weight** (Tensor) - Set size of kernel is :math:`(K_1, K_2)`, then the shape is
|
|
2070
|
+
:math:`(C_{out}, C_{in}, K_1, K_2)`.
|
|
2071
|
+
- **input_size** (Tensor) - A tuple describes the shape of the input which conforms to the format
|
|
2072
|
+
:math:`(N, C_{in}, H_{in}, W_{in})`.
|
|
2868
2073
|
|
|
2869
2074
|
Outputs:
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
- **loss** (Tensor) - When `reduction` is ``'none'`` and `logits` is a 2D tensor,
|
|
2873
|
-
the `loss` shape is :math:`(N,)`. Otherwise, the `loss` is a scalar.
|
|
2874
|
-
The data type is the same with `input's`.
|
|
2875
|
-
- **total_weight** (Tensor) - The `total_weight` is a scalar. The data type is the same with `weight's`.
|
|
2075
|
+
Tensor, the gradients with respect to the input of convolution. It has the same shape as the input.
|
|
2876
2076
|
|
|
2877
2077
|
Raises:
|
|
2878
|
-
TypeError: If
|
|
2879
|
-
TypeError: If
|
|
2880
|
-
ValueError: If `
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
and `weight` should be equal to each other.
|
|
2886
|
-
ValueError: If the value of `labels` exceed :math:`[0, C-1]`, where :math:`C` is the number of classes.
|
|
2078
|
+
TypeError: If `kernel_size`, `stride`, `pad` or `dilation` is neither an int nor a tuple.
|
|
2079
|
+
TypeError: If `out_channel` or `group` is not an int.
|
|
2080
|
+
ValueError: If `kernel_size`, `stride` or `dilation` is less than 1.
|
|
2081
|
+
ValueError: If `pad_mode` is not one of ``'same'``, ``'valid'`` or ``'pad'``.
|
|
2082
|
+
ValueError: If `padding` is a tuple whose length is not equal to 4.
|
|
2083
|
+
ValueError: If `pad_mode` it not equal to ``'pad'`` and `pad` is not equal to (0, 0, 0, 0).
|
|
2084
|
+
ValueError: If `data_format` is neither ``'NCHW'`` nor ``'NHWC'``.
|
|
2887
2085
|
|
|
2888
2086
|
Supported Platforms:
|
|
2889
2087
|
``Ascend`` ``GPU`` ``CPU``
|
|
2890
2088
|
|
|
2891
2089
|
Examples:
|
|
2090
|
+
>>> import mindspore
|
|
2892
2091
|
>>> import numpy as np
|
|
2893
2092
|
>>> from mindspore import Tensor, ops
|
|
2894
|
-
>>>
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
>>>
|
|
2898
|
-
>>>
|
|
2899
|
-
>>>
|
|
2900
|
-
|
|
2901
|
-
>>> print(loss)
|
|
2902
|
-
-0.52507716
|
|
2903
|
-
>>> print(weight)
|
|
2904
|
-
1.1503246
|
|
2093
|
+
>>> dout = Tensor(np.ones([10, 32, 30, 30]), mindspore.float32)
|
|
2094
|
+
>>> weight = Tensor(np.ones([32, 32, 3, 3]), mindspore.float32)
|
|
2095
|
+
>>> x = Tensor(np.ones([10, 32, 32, 32]))
|
|
2096
|
+
>>> conv2d_transpose_input = ops.Conv2DTranspose(out_channel=32, kernel_size=3)
|
|
2097
|
+
>>> output = conv2d_transpose_input(dout, weight, ops.shape(x))
|
|
2098
|
+
>>> print(output.shape)
|
|
2099
|
+
(10, 32, 32, 32)
|
|
2905
2100
|
"""
|
|
2906
2101
|
|
|
2907
2102
|
@prim_attr_register
|
|
2908
|
-
def __init__(self,
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
self.
|
|
2912
|
-
|
|
2103
|
+
def __init__(self, out_channel, kernel_size, pad_mode="valid", pad=0,
|
|
2104
|
+
pad_list=None, mode=1, stride=1, dilation=1, group=1, data_format="NCHW"):
|
|
2105
|
+
"""Initialize Conv2DTranspose."""
|
|
2106
|
+
super(Conv2DTranspose, self).__init__(out_channel, kernel_size, pad_mode, pad,
|
|
2107
|
+
pad_list, mode, stride, dilation, group, data_format)
|
|
2913
2108
|
|
|
2914
2109
|
|
|
2915
2110
|
class SoftmaxCrossEntropyWithLogits(Primitive):
|
|
@@ -3232,7 +2427,7 @@ class MultiMarginLoss(Primitive):
|
|
|
3232
2427
|
or float64.
|
|
3233
2428
|
- **target** (Tensor) - Ground truth labels, with shape :math:`(N,)`. Data type only support int64. The
|
|
3234
2429
|
value of target should be non-negative, less than C.
|
|
3235
|
-
- **weight** (Tensor) - The rescaling weight to each class with shape :math:`(C,)`. Data type only
|
|
2430
|
+
- **weight** (Tensor, optional) - The rescaling weight to each class with shape :math:`(C,)`. Data type only
|
|
3236
2431
|
support float16, float32 or float64.
|
|
3237
2432
|
|
|
3238
2433
|
Outputs:
|
|
@@ -3254,6 +2449,11 @@ class MultiMarginLoss(Primitive):
|
|
|
3254
2449
|
>>> print(output)
|
|
3255
2450
|
0.6666667
|
|
3256
2451
|
"""
|
|
2452
|
+
__mindspore_signature__ = (
|
|
2453
|
+
sig.make_sig('x'),
|
|
2454
|
+
sig.make_sig('target'),
|
|
2455
|
+
sig.make_sig('weight', default=None)
|
|
2456
|
+
)
|
|
3257
2457
|
|
|
3258
2458
|
@prim_attr_register
|
|
3259
2459
|
def __init__(self, p=1, margin=1.0, reduction="mean"):
|
|
@@ -3264,6 +2464,9 @@ class MultiMarginLoss(Primitive):
|
|
|
3264
2464
|
self.reduction = validator.check_string(reduction, ['none', 'sum', 'mean'], 'reduction', self.name)
|
|
3265
2465
|
self.init_prim_io_names(inputs=['x', 'target', 'weight'], outputs=['y'])
|
|
3266
2466
|
|
|
2467
|
+
def __call__(self, x, target, weight=None):
|
|
2468
|
+
return super().__call__(x, target, weight)
|
|
2469
|
+
|
|
3267
2470
|
|
|
3268
2471
|
class SoftMarginLoss(Primitive):
|
|
3269
2472
|
r"""
|
|
@@ -3412,7 +2615,9 @@ class RNNTLoss(PrimitiveWithInfer):
|
|
|
3412
2615
|
blank_label (int): blank label. Default: ``0`` .
|
|
3413
2616
|
|
|
3414
2617
|
Inputs:
|
|
3415
|
-
- **acts** (Tensor) - Tensor of shape :math:`(B, T, U, V)
|
|
2618
|
+
- **acts** (Tensor) - Tensor of shape :math:`(B, T, U, V)`, where :math:`B` is batch,
|
|
2619
|
+
:math:`T` is sequence length, :math:`U` is label length and :math:`V` is output dim.
|
|
2620
|
+
Data type must be float16 or float32.
|
|
3416
2621
|
- **labels** (Tensor) - Tensor of shape :math:`(B, U-1)`. Data type is int32.
|
|
3417
2622
|
- **input_lengths** (Tensor) - Tensor of shape :math:`(B,)`. Data type is int32.
|
|
3418
2623
|
- **label_lengths** (Tensor) - Tensor of shape :math:`(B,)`. Data type is int32.
|
|
@@ -3734,389 +2939,50 @@ class ApplyCenteredRMSProp(Primitive):
|
|
|
3734
2939
|
>>> output = net(mean_grad, mean_square, moment, grad, 0.0, 1e-10, 0.001, 0.01)
|
|
3735
2940
|
>>> print(net.var.asnumpy())
|
|
3736
2941
|
[[0.68377227 0.68377227]
|
|
3737
|
-
[0.68377227 0.68377227]]
|
|
3738
|
-
"""
|
|
3739
|
-
|
|
3740
|
-
@prim_attr_register
|
|
3741
|
-
def __init__(self, use_locking=False):
|
|
3742
|
-
"""Initialize ApplyCenteredRMSProp."""
|
|
3743
|
-
self.use_locking = validator.check_value_type("use_locking", use_locking, [bool], self.name)
|
|
3744
|
-
self.add_prim_attr('side_effect_mem', True)
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
class LayerNorm(Primitive):
|
|
3748
|
-
r"""
|
|
3749
|
-
Applies the Layer Normalization to the input tensor.
|
|
3750
|
-
|
|
3751
|
-
This operator will normalize the input tensor on given axis. LayerNorm is described in the paper
|
|
3752
|
-
`Layer Normalization <https://arxiv.org/abs/1607.06450>`_.
|
|
3753
|
-
|
|
3754
|
-
.. math::
|
|
3755
|
-
y = \frac{x - mean}{\sqrt{variance + \epsilon}} * \gamma + \beta
|
|
3756
|
-
|
|
3757
|
-
where :math:`\gamma` is scale, :math:`\beta` is bias, :math:`\epsilon` is epsilon.
|
|
3758
|
-
|
|
3759
|
-
Args:
|
|
3760
|
-
begin_norm_axis (int): The begin axis of the `input_x` to apply LayerNorm,
|
|
3761
|
-
the value must be in [-1, rank(input_x)). Default: ``1`` .
|
|
3762
|
-
begin_params_axis (int): The begin axis of the parameter input (`gamma`, `beta`) to
|
|
3763
|
-
apply LayerNorm, the value must be in [-1, rank(input_x)). Default: ``1`` .
|
|
3764
|
-
epsilon (float): A value added to the denominator for numerical stability(:math:`\epsilon`). Default: ``1e-7`` .
|
|
3765
|
-
|
|
3766
|
-
Inputs:
|
|
3767
|
-
- **input_x** (Tensor) - Tensor of shape :math:`(N, \ldots)`.
|
|
3768
|
-
The input of LayerNorm. Supported dtypes: float16, float32, float64.
|
|
3769
|
-
- **gamma** (Tensor) - Tensor of shape :math:`(P_\text{begin_params_axis}, \ldots, P_\text{rank(input_x)-1})`.
|
|
3770
|
-
The learnable parameter :math:`\gamma` as the scale on norm. Supported dtypes: float16, float32, float64.
|
|
3771
|
-
- **beta** (Tensor) - Tensor of shape :math:`(P_\text{begin_params_axis}, \ldots, P_\text{rank(input_x)-1})`.
|
|
3772
|
-
The learnable parameter :math:`\beta` as the scale on norm. Supported dtypes: float16, float32, float64.
|
|
3773
|
-
|
|
3774
|
-
Outputs:
|
|
3775
|
-
tuple[Tensor], tuple of 3 tensors, the normalized input and the updated parameters.
|
|
3776
|
-
|
|
3777
|
-
- **output_x** (Tensor) - The normalized input, has the same type and shape as the `input_x`.
|
|
3778
|
-
- **mean** (Tensor) - The first `begin_norm_axis` dimensions of `mean` shape is the same as `input_x`,
|
|
3779
|
-
and the remaining dimensions are 1. Suppose the shape of the `input_x` is :math:`(x_1, x_2, \ldots, x_R)`,
|
|
3780
|
-
the shape of the `mean` is :math:`(x_1, \ldots, x_{begin_params_axis}, 1, \ldots, 1)`
|
|
3781
|
-
(when `begin_params_axis=0`, the shape of `mean` is :math:`(1, \ldots, 1)` ).
|
|
3782
|
-
- **variance** (Tensor) - Shape is the same as `mean` .
|
|
3783
|
-
|
|
3784
|
-
Raises:
|
|
3785
|
-
TypeError: If `begin_norm_axis` or `begin_params_axis` is not an int.
|
|
3786
|
-
TypeError: If `epsilon` is not a float.
|
|
3787
|
-
TypeError: If `input_x`, `gamma` or `beta` is not a Tensor.
|
|
3788
|
-
|
|
3789
|
-
Supported Platforms:
|
|
3790
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
3791
|
-
|
|
3792
|
-
Examples:
|
|
3793
|
-
>>> import mindspore
|
|
3794
|
-
>>> import numpy as np
|
|
3795
|
-
>>> from mindspore import Tensor, ops
|
|
3796
|
-
>>> input_x = Tensor(np.array([[1, 2, 3], [1, 2, 3]]), mindspore.float32)
|
|
3797
|
-
>>> gamma = Tensor(np.ones([3]), mindspore.float32)
|
|
3798
|
-
>>> beta = Tensor(np.ones([3]), mindspore.float32)
|
|
3799
|
-
>>> layer_norm = ops.LayerNorm()
|
|
3800
|
-
>>> output, mean, variance = layer_norm(input_x, gamma, beta)
|
|
3801
|
-
>>> print(output)
|
|
3802
|
-
[[-0.2247448 1. 2.2247448]
|
|
3803
|
-
[-0.2247448 1. 2.2247448]]
|
|
3804
|
-
>>> print(mean)
|
|
3805
|
-
[[2.]
|
|
3806
|
-
[2.]]
|
|
3807
|
-
>>> print(variance)
|
|
3808
|
-
[[0.6666667]
|
|
3809
|
-
[0.6666667]]
|
|
3810
|
-
"""
|
|
3811
|
-
|
|
3812
|
-
@prim_attr_register
|
|
3813
|
-
def __init__(self, begin_norm_axis=1, begin_params_axis=1, epsilon=1e-7):
|
|
3814
|
-
"""Initialize LayerNorm."""
|
|
3815
|
-
validator.check_value_type('begin_norm_axis', begin_norm_axis, [int], self.name)
|
|
3816
|
-
validator.check_value_type('begin_params_axis', begin_params_axis, [int], self.name)
|
|
3817
|
-
validator.check_value_type('epsilon', epsilon, [float], self.name)
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
class L2Normalize(Primitive):
|
|
3821
|
-
r"""
|
|
3822
|
-
L2 Normalization Operator.
|
|
3823
|
-
|
|
3824
|
-
This operator will normalize the input using the given axis. The function is shown as follows:
|
|
3825
|
-
|
|
3826
|
-
.. math::
|
|
3827
|
-
\displaylines{{\text{output} = \frac{x}{\sqrt{\text{max}( \sum_{i}^{}\left | x_i \right | ^2, \epsilon)}}}}
|
|
3828
|
-
|
|
3829
|
-
where :math:`\epsilon` is epsilon and :math:`\sum_{i}^{}\left | x_i \right | ^2` calculate the sum of squares of
|
|
3830
|
-
the input `x` along the dimension `axis`.
|
|
3831
|
-
|
|
3832
|
-
Note:
|
|
3833
|
-
On Ascend, input data type of float64 is currently not supported.
|
|
3834
|
-
|
|
3835
|
-
Args:
|
|
3836
|
-
axis (Union[list(int), tuple(int), int]): Specify the axis for calculating the L2 norm. Default: ``0`` .
|
|
3837
|
-
epsilon (float): A small value added for numerical stability. Default: ``1e-4`` .
|
|
3838
|
-
|
|
3839
|
-
Inputs:
|
|
3840
|
-
- **x** (Tensor) - Input to compute the normalization. Tensor of shape :math:`(N, *)`,
|
|
3841
|
-
where :math:`*` means any number of additional dimensions.
|
|
3842
|
-
Data type must be float16, float32 or float64.
|
|
3843
|
-
|
|
3844
|
-
Outputs:
|
|
3845
|
-
Tensor, with the same type and shape as the `x`.
|
|
3846
|
-
|
|
3847
|
-
Raises:
|
|
3848
|
-
TypeError: If `axis` is not one of the following: list, tuple or int.
|
|
3849
|
-
TypeError: If `epsilon` is not a float.
|
|
3850
|
-
TypeError: If `x` is not a Tensor.
|
|
3851
|
-
TypeError: If dtype of `x` is not in [float16, float32, float64].
|
|
3852
|
-
ValueError: If dimension of `x` is not greater than 0.
|
|
3853
|
-
|
|
3854
|
-
Supported Platforms:
|
|
3855
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
3856
|
-
|
|
3857
|
-
Examples:
|
|
3858
|
-
>>> import mindspore
|
|
3859
|
-
>>> import numpy as np
|
|
3860
|
-
>>> from mindspore import Tensor, ops
|
|
3861
|
-
>>> l2_normalize = ops.L2Normalize()
|
|
3862
|
-
>>> x = Tensor(np.random.randint(-256, 256, (2, 3, 4)), mindspore.float32)
|
|
3863
|
-
>>> output = l2_normalize(x)
|
|
3864
|
-
>>> print(output.shape)
|
|
3865
|
-
(2, 3, 4)
|
|
3866
|
-
"""
|
|
3867
|
-
|
|
3868
|
-
@prim_attr_register
|
|
3869
|
-
def __init__(self, axis=0, epsilon=1e-4):
|
|
3870
|
-
"""Initialize L2Normalize."""
|
|
3871
|
-
axis = [axis] if isinstance(axis, int) else axis
|
|
3872
|
-
validator.check_value_type('axis', axis, [list, tuple], self.name)
|
|
3873
|
-
validator.check_value_type('epsilon', epsilon, [int, float], self.name)
|
|
3874
|
-
self.add_prim_attr('axis', axis)
|
|
3875
|
-
self.init_attrs['axis'] = axis
|
|
3876
|
-
if len(axis) != 1:
|
|
3877
|
-
raise TypeError(f"For '{self.name}', the length of 'axis' must be 1, but got {len(axis)}, "
|
|
3878
|
-
f"later will support multiple axis!")
|
|
3879
|
-
self.axis = axis
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
class ResizeBilinear(PrimitiveWithInfer):
|
|
3883
|
-
r"""
|
|
3884
|
-
This API is deprecated, please use the :class:`mindspore.ops.ResizeBilinearV2` instead.
|
|
3885
|
-
For general resizing with other interpolation methods, refer to :func:`mindspore.ops.interpolate` for more details.
|
|
3886
|
-
|
|
3887
|
-
Note:
|
|
3888
|
-
Dynamic shape feature is not supported for now.
|
|
3889
|
-
|
|
3890
|
-
Supported Platforms:
|
|
3891
|
-
Deprecated
|
|
3892
|
-
"""
|
|
3893
|
-
|
|
3894
|
-
@prim_attr_register
|
|
3895
|
-
def __init__(self, size, align_corners=False, half_pixel_centers=False):
|
|
3896
|
-
"""Initialize ResizeBilinear."""
|
|
3897
|
-
validator.check_value_type("size", size, [tuple, list], self.name)
|
|
3898
|
-
validator.check_equal_int(len(size), 2, "size len", self.name)
|
|
3899
|
-
for item in size:
|
|
3900
|
-
validator.check_positive_int(item, 'size item', self.name)
|
|
3901
|
-
validator.check_value_type("size item", item, int, self.name)
|
|
3902
|
-
self.align_corners = validator.check_value_type("align_corners", align_corners, [bool], self.name)
|
|
3903
|
-
self.half_pixel_centers = validator.check_value_type("half_pixel_centers",
|
|
3904
|
-
half_pixel_centers, [bool], self.name)
|
|
3905
|
-
if half_pixel_centers and align_corners:
|
|
3906
|
-
raise ValueError(f"If half_pixel_centers is True, align_corners must be False, but got {align_corners}")
|
|
3907
|
-
for i, value in enumerate(size):
|
|
3908
|
-
validator.check_positive_int(value, f'{i}th value of size', self.name)
|
|
3909
|
-
|
|
3910
|
-
def infer_shape(self, input_shape):
|
|
3911
|
-
validator.check("dimension of input", len(input_shape), "", 4, validator.EQ, self.name)
|
|
3912
|
-
input_shape = list(input_shape)
|
|
3913
|
-
batch, channel, _, _ = input_shape
|
|
3914
|
-
out_shape = [batch, channel]
|
|
3915
|
-
for i in self.size:
|
|
3916
|
-
out_shape.append(int(i))
|
|
3917
|
-
return out_shape
|
|
3918
|
-
|
|
3919
|
-
def infer_dtype(self, input_dtype):
|
|
3920
|
-
validator.check_tensor_dtype_valid('input_dtype', input_dtype, [mstype.float16, mstype.float32],
|
|
3921
|
-
self.name)
|
|
3922
|
-
return input_dtype
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
class UpsampleTrilinear3D(Primitive):
|
|
3926
|
-
r"""
|
|
3927
|
-
Performs upsampling with trilinear interpolation across 3dims for 5dim input Tensor.
|
|
3928
|
-
|
|
3929
|
-
This operator scale up the volumetric input with specified `output_size` or `scales` factors,
|
|
3930
|
-
using trilinear upscaling algorithm.
|
|
3931
|
-
|
|
3932
|
-
Note:
|
|
3933
|
-
One of `scales` and `output_size` must be specified. And it is an error if both are specified.
|
|
3934
|
-
|
|
3935
|
-
Args:
|
|
3936
|
-
align_corners (bool, optional): An optional bool. Default: ``False``.
|
|
3937
|
-
If ``True``, the input and output tensors are aligned by the center points of their corner pixels,
|
|
3938
|
-
preserving the values at the corner pixels.
|
|
3939
|
-
If ``False`` , the input and output tensors are aligned by the corner points of their corner pixels,
|
|
3940
|
-
and the interpolation use edge value padding for out of boundary values.
|
|
3941
|
-
|
|
3942
|
-
Inputs:
|
|
3943
|
-
- **x** (Tensor) - 5D tensor of shape :math:`(N, C, D_{in}, H_{in}, W_{in})`. Supporting types:
|
|
3944
|
-
[float16, float32, float64].
|
|
3945
|
-
- **output_size** (Union[tuple[int], list[int]]): A tuple or list of 3 int elements
|
|
3946
|
-
:math:`(output\_depth, output\_height, output\_width)`. Default: ``None``.
|
|
3947
|
-
- **scales** (Union[tuple[float], list[float]]): A tuple or list of 3 float
|
|
3948
|
-
elements :math:`(scale\_depth, scale\_height, scale\_width)`. Default: ``None``.
|
|
3949
|
-
|
|
3950
|
-
Outputs:
|
|
3951
|
-
- **y** (Tensor) - Upsampled output with the same data type as `x`, whose shape is
|
|
3952
|
-
:math:`(N, C, D_{out}, H_{out}, W_{out})`.
|
|
3953
|
-
|
|
3954
|
-
Raises:
|
|
3955
|
-
TypeError: When `output_size` is not ``None`` and `output_size` is not list[int] or tuple[int].
|
|
3956
|
-
TypeError: When `scales` is not ``None`` and `scales` is not list[float] or tuple[float].
|
|
3957
|
-
TypeError: If dtype of `x` is not in [float16, float32, float64].
|
|
3958
|
-
TypeError: If type of `align_corners` is not bool.
|
|
3959
|
-
ValueError: If any value of `output_size` is negative or zero when `output_size` is not ``None``.
|
|
3960
|
-
ValueError: If any value of `scales` is negative or zero when `scales` is not ``None``.
|
|
3961
|
-
ValueError: If shape of `x` is not 5D.
|
|
3962
|
-
ValueError: If none of `scales` and `output_size` is specified or both specified.
|
|
3963
|
-
ValueError: If size of `scales` is not equal 3 when `scales` is specified.
|
|
3964
|
-
ValueError: If size of `output_size` is not equal 3 when `output_size` is specified.
|
|
3965
|
-
|
|
3966
|
-
Supported Platforms:
|
|
3967
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
3968
|
-
|
|
3969
|
-
Examples:
|
|
3970
|
-
>>> import numpy as np
|
|
3971
|
-
>>> from mindspore import Tensor, ops
|
|
3972
|
-
>>> net = ops.UpsampleTrilinear3D()
|
|
3973
|
-
>>> in_x = Tensor(input_data=np.random.randn(2, 3, 4, 512, 256))
|
|
3974
|
-
>>> output_size=[4, 64, 48]
|
|
3975
|
-
>>> out = net(in_x, output_size, None)
|
|
3976
|
-
>>> print(out.shape)
|
|
3977
|
-
(2, 3, 4, 64, 48)
|
|
3978
|
-
>>>
|
|
3979
|
-
>>> net = ops.UpsampleTrilinear3D()
|
|
3980
|
-
>>> in_x = Tensor(np.arange(1, 5, dtype=np.float32).reshape((1, 1, 1, 2, 2)))
|
|
3981
|
-
>>> output_size=[2, 4, 4]
|
|
3982
|
-
>>> out = net(in_x, output_size, None)
|
|
3983
|
-
>>> print(out)
|
|
3984
|
-
[[[[[1. 1.25 1.75 2. ]
|
|
3985
|
-
[1.5 1.75 2.25 2.5 ]
|
|
3986
|
-
[2.5 2.75 3.25 3.5 ]
|
|
3987
|
-
[3. 3.25 3.75 4. ]]
|
|
3988
|
-
[[1. 1.25 1.75 2. ]
|
|
3989
|
-
[1.5 1.75 2.25 2.5 ]
|
|
3990
|
-
[2.5 2.75 3.25 3.5 ]
|
|
3991
|
-
[3. 3.25 3.75 4. ]]]]]
|
|
3992
|
-
"""
|
|
3993
|
-
|
|
3994
|
-
@prim_attr_register
|
|
3995
|
-
def __init__(self, align_corners=False):
|
|
3996
|
-
"""Initialize UpsampleTrilinear3D."""
|
|
3997
|
-
self.init_prim_io_names(inputs=['x', 'output_size', 'scales'], outputs=['y'])
|
|
3998
|
-
self.align_corners = align_corners
|
|
3999
|
-
validator.check_bool(self.align_corners, "align_corners", self.name)
|
|
4000
|
-
self.add_prim_attr('align_corners', self.align_corners)
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
class OneHot(Primitive):
|
|
4004
|
-
r"""
|
|
4005
|
-
Computes a one-hot tensor.
|
|
4006
|
-
|
|
4007
|
-
The locations represented by indices in `indices` take value `on_value`, while all
|
|
4008
|
-
other locations take value `off_value`.
|
|
4009
|
-
|
|
4010
|
-
Note:
|
|
4011
|
-
If the input indices is rank `N`, the output will have rank `N+1`. The new axis is created at dimension `axis`.
|
|
4012
|
-
On Ascend, if `on_value` is Int64 dtype, `indices` must be Int64 dtype.
|
|
4013
|
-
|
|
4014
|
-
Args:
|
|
4015
|
-
axis (int): Position to insert the value. e.g. If shape of `indices` is :math:`(N, C)`, and `axis` is -1,
|
|
4016
|
-
the output shape will be :math:`(N, C, D)`, If `axis` is 0, the output shape will be :math:`(D, N, C)`.
|
|
4017
|
-
Default: ``-1`` .
|
|
4018
|
-
|
|
4019
|
-
Inputs:
|
|
4020
|
-
- **indices** (Tensor) - A tensor of indices. Tensor of shape :math:`(X_0, \ldots, X_n)`.
|
|
4021
|
-
Data type must be int32 or int64.
|
|
4022
|
-
- **depth** (int) - A scalar defining the depth of the one-hot dimension.
|
|
4023
|
-
- **on_value** (Tensor) - A value to fill in output when `indices[j] = i`. Data type must be int32, int64,
|
|
4024
|
-
float16 or float32.
|
|
4025
|
-
- **off_value** (Tensor) - A value to fill in output when `indices[j] != i`.
|
|
4026
|
-
It has the same data type as `on_value`.
|
|
4027
|
-
|
|
4028
|
-
Outputs:
|
|
4029
|
-
Tensor, one-hot tensor. Tensor of shape :math:`(X_0, \ldots, X_{axis}, \text{depth} ,X_{axis+1}, \ldots, X_n)`,
|
|
4030
|
-
and it has the same data type as `on_value`.
|
|
4031
|
-
|
|
4032
|
-
Raises:
|
|
4033
|
-
TypeError: If `axis` or `depth` is not an int.
|
|
4034
|
-
TypeError: If dtype of `indices` is not int32 or int64.
|
|
4035
|
-
TypeError: If `indices`, `on_value` or `off_value` is not a Tensor.
|
|
4036
|
-
ValueError: If `axis` is not in range [-1, len(indices_shape)].
|
|
4037
|
-
ValueError: If `depth` is less than 0.
|
|
4038
|
-
|
|
4039
|
-
Supported Platforms:
|
|
4040
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
4041
|
-
|
|
4042
|
-
Examples:
|
|
4043
|
-
>>> import mindspore
|
|
4044
|
-
>>> import numpy as np
|
|
4045
|
-
>>> from mindspore import Tensor, ops
|
|
4046
|
-
>>> indices = Tensor(np.array([0, 1, 2]), mindspore.int32)
|
|
4047
|
-
>>> depth, on_value, off_value = 3, Tensor(1.0, mindspore.float32), Tensor(0.0, mindspore.float32)
|
|
4048
|
-
>>> onehot = ops.OneHot()
|
|
4049
|
-
>>> output = onehot(indices, depth, on_value, off_value)
|
|
4050
|
-
>>> print(output)
|
|
4051
|
-
[[1. 0. 0.]
|
|
4052
|
-
[0. 1. 0.]
|
|
4053
|
-
[0. 0. 1.]]
|
|
4054
|
-
"""
|
|
4055
|
-
|
|
4056
|
-
@prim_attr_register
|
|
4057
|
-
def __init__(self, axis=-1):
|
|
4058
|
-
"""Initialize OneHot."""
|
|
4059
|
-
self.init_prim_io_names(inputs=['indices', 'depth', 'on_value', 'off_value'], outputs=['output'])
|
|
4060
|
-
validator.check_value_type("axis", axis, [int], self.name)
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
class GeLU(Primitive):
|
|
4064
|
-
r"""
|
|
4065
|
-
Gaussian Error Linear Units activation function.
|
|
4066
|
-
|
|
4067
|
-
GeLU is described in the paper `Gaussian Error Linear Units (GELUs) <https://arxiv.org/abs/1606.08415>`_.
|
|
4068
|
-
And also please refer to `BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding
|
|
4069
|
-
<https://arxiv.org/abs/1810.04805>`_.
|
|
4070
|
-
|
|
4071
|
-
GeLU is defined as follows:
|
|
4072
|
-
|
|
4073
|
-
.. math::
|
|
4074
|
-
GELU(x_i) = x_i*P(X < x_i)
|
|
4075
|
-
|
|
4076
|
-
where :math:`P` is the cumulative distribution function of the standard Gaussian distribution,
|
|
4077
|
-
:math:`x_i` is the input element.
|
|
4078
|
-
|
|
4079
|
-
Inputs:
|
|
4080
|
-
- **x** (Tensor) - The input of the activation function GeLU, the data type is float16, float32 or float64.
|
|
4081
|
-
|
|
4082
|
-
Outputs:
|
|
4083
|
-
Tensor, with the same type and shape as `x`.
|
|
4084
|
-
|
|
4085
|
-
Raises:
|
|
4086
|
-
TypeError: If `x` is not a Tensor.
|
|
4087
|
-
TypeError: If dtype of `x` is not float16, float32 or float64.
|
|
4088
|
-
|
|
4089
|
-
Supported Platforms:
|
|
4090
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
4091
|
-
|
|
4092
|
-
Examples:
|
|
4093
|
-
>>> import mindspore
|
|
4094
|
-
>>> import numpy as np
|
|
4095
|
-
>>> from mindspore import Tensor, ops
|
|
4096
|
-
>>> x = Tensor(np.array([1.0, 2.0, 3.0]), mindspore.float32)
|
|
4097
|
-
>>> gelu = ops.GeLU()
|
|
4098
|
-
>>> result = gelu(x)
|
|
4099
|
-
>>> print(result)
|
|
4100
|
-
[0.841192 1.9545976 2.9963627]
|
|
2942
|
+
[0.68377227 0.68377227]]
|
|
4101
2943
|
"""
|
|
4102
2944
|
|
|
4103
2945
|
@prim_attr_register
|
|
4104
|
-
def __init__(self):
|
|
4105
|
-
"""Initialize
|
|
4106
|
-
self.
|
|
2946
|
+
def __init__(self, use_locking=False):
|
|
2947
|
+
"""Initialize ApplyCenteredRMSProp."""
|
|
2948
|
+
self.use_locking = validator.check_value_type("use_locking", use_locking, [bool], self.name)
|
|
2949
|
+
self.add_prim_attr('side_effect_mem', True)
|
|
4107
2950
|
|
|
4108
2951
|
|
|
4109
|
-
class
|
|
2952
|
+
class L2Normalize(Primitive):
|
|
4110
2953
|
r"""
|
|
4111
|
-
|
|
2954
|
+
L2 Normalization Operator.
|
|
2955
|
+
|
|
2956
|
+
This operator will normalize the input using the given axis. The function is shown as follows:
|
|
2957
|
+
|
|
2958
|
+
.. math::
|
|
2959
|
+
\displaylines{{\text{output} = \frac{x}{\sqrt{\text{max}( \sum_{i}^{}\left | x_i \right | ^2, \epsilon)}}}}
|
|
2960
|
+
|
|
2961
|
+
where :math:`\epsilon` is epsilon and :math:`\sum_{i}^{}\left | x_i \right | ^2` calculate the sum of squares of
|
|
2962
|
+
the input `x` along the dimension `axis`.
|
|
2963
|
+
|
|
2964
|
+
Note:
|
|
2965
|
+
On Ascend, input data type of float64 is currently not supported.
|
|
4112
2966
|
|
|
4113
|
-
|
|
2967
|
+
Args:
|
|
2968
|
+
axis (Union[list(int), tuple(int), int], optional): Specify the axis for calculating the L2 norm.
|
|
2969
|
+
Default: ``0`` .
|
|
2970
|
+
epsilon (float, optional): A small value added for numerical stability. Default: ``1e-4`` .
|
|
4114
2971
|
|
|
4115
2972
|
Inputs:
|
|
4116
|
-
- **x** (Tensor) - Input to compute the
|
|
2973
|
+
- **x** (Tensor) - Input to compute the normalization. Tensor of shape :math:`(N, *)`,
|
|
2974
|
+
where :math:`*` means any number of additional dimensions.
|
|
2975
|
+
Data type must be float16, float32 or float64.
|
|
4117
2976
|
|
|
4118
2977
|
Outputs:
|
|
4119
|
-
Tensor, with the same type and shape as `x`.
|
|
2978
|
+
Tensor, with the same type and shape as the `x`.
|
|
2979
|
+
|
|
2980
|
+
Raises:
|
|
2981
|
+
TypeError: If `axis` is not one of the following: list, tuple or int.
|
|
2982
|
+
TypeError: If `epsilon` is not a float.
|
|
2983
|
+
TypeError: If `x` is not a Tensor.
|
|
2984
|
+
TypeError: If dtype of `x` is not in [float16, float32, float64].
|
|
2985
|
+
ValueError: If dimension of `x` is not greater than 0.
|
|
4120
2986
|
|
|
4121
2987
|
Supported Platforms:
|
|
4122
2988
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -4125,18 +2991,25 @@ class FastGeLU(Primitive):
|
|
|
4125
2991
|
>>> import mindspore
|
|
4126
2992
|
>>> import numpy as np
|
|
4127
2993
|
>>> from mindspore import Tensor, ops
|
|
4128
|
-
>>>
|
|
4129
|
-
>>>
|
|
4130
|
-
>>> output =
|
|
4131
|
-
>>> print(output)
|
|
4132
|
-
|
|
4133
|
-
[ 1.9375000e+00 -1.0052517e-03 8.9824219e+00]]
|
|
2994
|
+
>>> l2_normalize = ops.L2Normalize()
|
|
2995
|
+
>>> x = Tensor(np.random.randint(-256, 256, (2, 3, 4)), mindspore.float32)
|
|
2996
|
+
>>> output = l2_normalize(x)
|
|
2997
|
+
>>> print(output.shape)
|
|
2998
|
+
(2, 3, 4)
|
|
4134
2999
|
"""
|
|
4135
3000
|
|
|
4136
3001
|
@prim_attr_register
|
|
4137
|
-
def __init__(self):
|
|
4138
|
-
"""Initialize
|
|
4139
|
-
|
|
3002
|
+
def __init__(self, axis=0, epsilon=1e-4):
|
|
3003
|
+
"""Initialize L2Normalize."""
|
|
3004
|
+
axis = [axis] if isinstance(axis, int) else axis
|
|
3005
|
+
validator.check_value_type('axis', axis, [list, tuple], self.name)
|
|
3006
|
+
validator.check_value_type('epsilon', epsilon, [int, float], self.name)
|
|
3007
|
+
self.add_prim_attr('axis', axis)
|
|
3008
|
+
self.init_attrs['axis'] = axis
|
|
3009
|
+
if len(axis) != 1:
|
|
3010
|
+
raise TypeError(f"For '{self.name}', the length of 'axis' must be 1, but got {len(axis)}, "
|
|
3011
|
+
f"later will support multiple axis!")
|
|
3012
|
+
self.axis = axis
|
|
4140
3013
|
|
|
4141
3014
|
|
|
4142
3015
|
class GetNext(Primitive):
|
|
@@ -4193,55 +3066,6 @@ class GetNext(Primitive):
|
|
|
4193
3066
|
validator.check_value_type("output_num", output_num, [int], self.name)
|
|
4194
3067
|
|
|
4195
3068
|
|
|
4196
|
-
class PReLU(PrimitiveWithInfer):
|
|
4197
|
-
r"""
|
|
4198
|
-
Parametric Rectified Linear Unit activation function.
|
|
4199
|
-
|
|
4200
|
-
Refer to :func:`mindspore.ops.prelu` for more details.
|
|
4201
|
-
|
|
4202
|
-
Inputs:
|
|
4203
|
-
- **x** (Tensor) - The input Tensor of the activation function. The data type is float16 or float32.
|
|
4204
|
-
The shape is :math:`(N, C, *)` where :math:`*` means, any number of additional dimensions.
|
|
4205
|
-
- **weight** (Tensor) - Weight Tensor. The data type is float16 or float32.
|
|
4206
|
-
The weight can only be a vector, and the length is the same as the number of channels C of the `input_x`.
|
|
4207
|
-
On GPU devices, when the input is a scalar, the shape is 1.
|
|
4208
|
-
|
|
4209
|
-
Outputs:
|
|
4210
|
-
Tensor, with the same type as `x`.
|
|
4211
|
-
|
|
4212
|
-
Supported Platforms:
|
|
4213
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
4214
|
-
|
|
4215
|
-
Examples:
|
|
4216
|
-
>>> import mindspore
|
|
4217
|
-
>>> import numpy as np
|
|
4218
|
-
>>> from mindspore import Tensor, nn, ops
|
|
4219
|
-
>>> class Net(nn.Cell):
|
|
4220
|
-
... def __init__(self):
|
|
4221
|
-
... super(Net, self).__init__()
|
|
4222
|
-
... self.prelu = ops.PReLU()
|
|
4223
|
-
... def construct(self, x, weight):
|
|
4224
|
-
... result = self.prelu(x, weight)
|
|
4225
|
-
... return result
|
|
4226
|
-
...
|
|
4227
|
-
>>> x = Tensor(np.arange(-6, 6).reshape((2, 3, 2)), mindspore.float32)
|
|
4228
|
-
>>> weight = Tensor(np.array([0.1, 0.6, -0.3]), mindspore.float32)
|
|
4229
|
-
>>> net = Net()
|
|
4230
|
-
>>> output = net(x, weight)
|
|
4231
|
-
>>> print(output)
|
|
4232
|
-
[[[-0.60 -0.50]
|
|
4233
|
-
[-2.40 -1.80]
|
|
4234
|
-
[ 0.60 0.30]]
|
|
4235
|
-
[[ 0.00 1.00]
|
|
4236
|
-
[ 2.00 3.00]
|
|
4237
|
-
[ 4.0 5.00]]]
|
|
4238
|
-
"""
|
|
4239
|
-
|
|
4240
|
-
@prim_attr_register
|
|
4241
|
-
def __init__(self):
|
|
4242
|
-
self.init_prim_io_names(inputs=['x', 'weight'], outputs=['output'])
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
3069
|
class LSTM(Primitive):
|
|
4246
3070
|
r"""
|
|
4247
3071
|
Performs the Long Short-Term Memory (LSTM) on the input.
|
|
@@ -4383,105 +3207,6 @@ class SigmoidCrossEntropyWithLogits(Primitive):
|
|
|
4383
3207
|
self.init_prim_io_names(inputs=['predict', 'target'], outputs=['loss'])
|
|
4384
3208
|
|
|
4385
3209
|
|
|
4386
|
-
class BCEWithLogitsLoss(PrimitiveWithInfer):
|
|
4387
|
-
r"""
|
|
4388
|
-
Adds sigmoid activation function to input `logits`, and uses the given logits to compute binary cross entropy
|
|
4389
|
-
between the logits and the label.
|
|
4390
|
-
|
|
4391
|
-
Sets input logits as :math:`X`, input label as :math:`Y`, input weight as :math:`W`, output as :math:`L`. Then,
|
|
4392
|
-
|
|
4393
|
-
.. math::
|
|
4394
|
-
|
|
4395
|
-
\begin{array}{ll} \\
|
|
4396
|
-
p_{ij} = sigmoid(X_{ij}) = \frac{1}{1 + e^{-X_{ij}}} \\
|
|
4397
|
-
L_{ij} = -[Y_{ij}log(p_{ij}) + (1 - Y_{ij})log(1 - p_{ij})]
|
|
4398
|
-
\end{array}
|
|
4399
|
-
|
|
4400
|
-
:math:`i` indicates the :math:`i^{th}` sample, :math:`j` indicates the category. Then,
|
|
4401
|
-
|
|
4402
|
-
.. math::
|
|
4403
|
-
\ell(x, y) = \begin{cases}
|
|
4404
|
-
L, & \text{if reduction} = \text{'none';}\\
|
|
4405
|
-
\operatorname{mean}(L), & \text{if reduction} = \text{'mean';}\\
|
|
4406
|
-
\operatorname{sum}(L), & \text{if reduction} = \text{'sum'.}
|
|
4407
|
-
\end{cases}
|
|
4408
|
-
|
|
4409
|
-
:math:`\ell` indicates the method of calculating the loss. There are three methods:
|
|
4410
|
-
the first method is to provide the loss value directly,
|
|
4411
|
-
the second method is to calculate the average value of all losses,
|
|
4412
|
-
and the third method is to calculate the sum of all losses.
|
|
4413
|
-
|
|
4414
|
-
This operator will multiply the output by the corresponding weight.
|
|
4415
|
-
The tensor `weight` assigns different weights to each piece of data in the batch,
|
|
4416
|
-
and the tensor `pos_weight` adds corresponding weights to the positive examples of each category.
|
|
4417
|
-
|
|
4418
|
-
In addition, it can trade off recall and precision by adding weights to positive examples.
|
|
4419
|
-
In the case of multi-label classification the loss can be described as:
|
|
4420
|
-
|
|
4421
|
-
.. math::
|
|
4422
|
-
\begin{array}{ll} \\
|
|
4423
|
-
p_{ij,c} = sigmoid(X_{ij,c}) = \frac{1}{1 + e^{-X_{ij,c}}} \\
|
|
4424
|
-
L_{ij,c} = -[P_{c}Y_{ij,c} * log(p_{ij,c}) + (1 - Y_{ij,c})log(1 - p_{ij,c})]
|
|
4425
|
-
\end{array}
|
|
4426
|
-
|
|
4427
|
-
where c is the class number (c>1 for multi-label binary classification, c=1 for single-label binary classification),
|
|
4428
|
-
n is the number of the sample in the batch and :math:`P_c` is the weight of the positive answer for the class c.
|
|
4429
|
-
:math:`P_c>1` increases the recall, :math:`P_c<1` increases the precision.
|
|
4430
|
-
|
|
4431
|
-
Args:
|
|
4432
|
-
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
4433
|
-
``'sum'`` . Default: ``'mean'`` .
|
|
4434
|
-
|
|
4435
|
-
- ``'none'``: no reduction will be applied.
|
|
4436
|
-
- ``'mean'``: compute and return the weighted mean of elements in the output.
|
|
4437
|
-
- ``'sum'``: the output elements will be summed.
|
|
4438
|
-
|
|
4439
|
-
Inputs:
|
|
4440
|
-
- **logits** (Tensor) - Input logits. Data type must be float16 or float32.
|
|
4441
|
-
Tensor of shape :math:`(N, *)` where :math:`*` means, any number of additional dimensions.
|
|
4442
|
-
- **label** (Tensor) - Ground truth label, has the same shape as `logits`.
|
|
4443
|
-
Data type must be float16 or float32.
|
|
4444
|
-
- **weight** (Tensor) - A rescaling weight applied to the loss of each batch element. It can be
|
|
4445
|
-
broadcast to a tensor with shape of `logits`. Data type must be float16 or float32.
|
|
4446
|
-
- **pos_weight** (Tensor) - A weight of positive examples. Must be a vector with length equal to the
|
|
4447
|
-
number of classes. It can be broadcast to a tensor with shape of `logits`.
|
|
4448
|
-
Data type must be float16 or float32.
|
|
4449
|
-
|
|
4450
|
-
Outputs:
|
|
4451
|
-
Tensor or Scalar, if `reduction` is ``'none'``, it's a tensor with the same shape and type as input `logits`.
|
|
4452
|
-
Otherwise, the output is a scalar.
|
|
4453
|
-
|
|
4454
|
-
Raises:
|
|
4455
|
-
TypeError: If any input is not Tensor.
|
|
4456
|
-
TypeError: If data type of any input is neither float16 nor float32.
|
|
4457
|
-
TypeError: If data type of `reduction` is not string.
|
|
4458
|
-
ValueError: If `weight` or `pos_weight` can not be broadcast to a tensor with shape of `logits`.
|
|
4459
|
-
ValueError: If `reduction` is not one of ``'none'``, ``'mean'`` or ``'sum'``.
|
|
4460
|
-
|
|
4461
|
-
Supported Platforms:
|
|
4462
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
4463
|
-
|
|
4464
|
-
Examples:
|
|
4465
|
-
>>> import mindspore
|
|
4466
|
-
>>> import numpy as np
|
|
4467
|
-
>>> from mindspore import Tensor, ops
|
|
4468
|
-
>>> logits = Tensor(np.array([[-0.8, 1.2, 0.7], [-0.1, -0.4, 0.7]]), mindspore.float32)
|
|
4469
|
-
>>> label = Tensor(np.array([[0.3, 0.8, 1.2], [-0.6, 0.1, 2.2]]), mindspore.float32)
|
|
4470
|
-
>>> weight = Tensor(np.array([1.0, 1.0, 1.0]), mindspore.float32)
|
|
4471
|
-
>>> pos_weight = Tensor(np.array([1.0, 1.0, 1.0]), mindspore.float32)
|
|
4472
|
-
>>> loss = ops.BCEWithLogitsLoss()
|
|
4473
|
-
>>> output = loss(logits, label, weight, pos_weight)
|
|
4474
|
-
>>> print(output)
|
|
4475
|
-
0.3463612
|
|
4476
|
-
"""
|
|
4477
|
-
|
|
4478
|
-
@prim_attr_register
|
|
4479
|
-
def __init__(self, reduction='mean'):
|
|
4480
|
-
"""Initialize BCEWithLogitsLoss"""
|
|
4481
|
-
super().__init__("BCEWithLogitsLoss")
|
|
4482
|
-
self.reduction = validator.check_string(reduction, ['none', 'sum', 'mean'], 'reduction', self.name)
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
3210
|
class Pad(Primitive):
|
|
4486
3211
|
r"""
|
|
4487
3212
|
Pads the input tensor according to the paddings.
|
|
@@ -4729,18 +3454,18 @@ class ComputeAccidentalHits(Primitive):
|
|
|
4729
3454
|
num_true (int): The number of target classes per training example. Default: ``1`` .
|
|
4730
3455
|
|
|
4731
3456
|
Inputs:
|
|
4732
|
-
- **true_classes** (Tensor) - The target classes. With data type of
|
|
3457
|
+
- **true_classes** (Tensor) - The target classes. With data type of int64
|
|
4733
3458
|
and shape :math:`(batch\_size, num\_true)`.
|
|
4734
3459
|
- **sampled_candidates** (Tensor) - The Candidate sampling results of operators, types of training samples,
|
|
4735
|
-
with data type of
|
|
3460
|
+
with data type of int64 and shape :math:`(num\_sampled, )`.
|
|
4736
3461
|
|
|
4737
3462
|
Outputs:
|
|
4738
3463
|
Tuple of 3 Tensors.
|
|
4739
3464
|
|
|
4740
3465
|
- **indices** (Tensor) - A Tensor with shape :math:`(num\_accidental\_hits, )`,
|
|
4741
|
-
with
|
|
3466
|
+
with data type of int32.
|
|
4742
3467
|
- **ids** (Tensor) - A Tensor with shape :math:`(num\_accidental\_hits, )`,
|
|
4743
|
-
with
|
|
3468
|
+
with data type of int64.
|
|
4744
3469
|
- **weights** (Tensor) - A Tensor with shape :math:`(num\_accidental\_hits, )`, with the type float32.
|
|
4745
3470
|
|
|
4746
3471
|
Raises:
|
|
@@ -4795,8 +3520,9 @@ class ROIAlign(Primitive):
|
|
|
4795
3520
|
|
|
4796
3521
|
|
|
4797
3522
|
Inputs:
|
|
4798
|
-
- **features** (Tensor) - The input features, whose shape must be :math:`(N, C, H, W)
|
|
4799
|
-
|
|
3523
|
+
- **features** (Tensor) - The input features, whose shape must be :math:`(N, C, H, W)`, with data type of
|
|
3524
|
+
float16 or float32.
|
|
3525
|
+
- **rois** (Tensor) - The shape is :math:`(rois\_n, 5)`, with data type of float16 or float32.
|
|
4800
3526
|
`rois_n` represents the number of RoI. The size of the second dimension must be `5` and the `5` colunms
|
|
4801
3527
|
are :math:`(image\_index, top\_left\_x, top\_left\_y, bottom\_right\_x, bottom\_right\_y)`.
|
|
4802
3528
|
`image_index` represents the index of image. `top_left_x` and `top_left_y` represent the `x, y`
|
|
@@ -4917,6 +3643,7 @@ class Adam(Primitive):
|
|
|
4917
3643
|
>>> import mindspore
|
|
4918
3644
|
>>> import numpy as np
|
|
4919
3645
|
>>> from mindspore import Tensor, nn, ops
|
|
3646
|
+
>>> from mindspore import Parameter
|
|
4920
3647
|
>>> class Net(nn.Cell):
|
|
4921
3648
|
... def __init__(self):
|
|
4922
3649
|
... super(Net, self).__init__()
|
|
@@ -4957,120 +3684,6 @@ class Adam(Primitive):
|
|
|
4957
3684
|
self.add_prim_attr('side_effect_mem', True)
|
|
4958
3685
|
|
|
4959
3686
|
|
|
4960
|
-
class AdamWeightDecay(Primitive):
|
|
4961
|
-
r"""
|
|
4962
|
-
Updates gradients by the Adaptive Moment Estimation algorithm with weight decay (AdamWeightDecay).
|
|
4963
|
-
|
|
4964
|
-
The Adam algorithm is proposed in `Adam: A Method for Stochastic Optimization <https://arxiv.org/abs/1412.6980>`_.
|
|
4965
|
-
The AdamWeightDecay variant was proposed in `Decoupled Weight Decay Regularization
|
|
4966
|
-
<https://arxiv.org/abs/1711.05101>`_.
|
|
4967
|
-
|
|
4968
|
-
The updating formulas are as follows,
|
|
4969
|
-
|
|
4970
|
-
.. math::
|
|
4971
|
-
\begin{array}{ll} \\
|
|
4972
|
-
m = \beta_1 * m + (1 - \beta_1) * g \\
|
|
4973
|
-
v = \beta_2 * v + (1 - \beta_2) * g * g \\
|
|
4974
|
-
update = \frac{m}{\sqrt{v} + \epsilon} \\
|
|
4975
|
-
update =
|
|
4976
|
-
\begin{cases}
|
|
4977
|
-
update + weight\_decay * w
|
|
4978
|
-
& \text{ if } weight\_decay > 0 \\
|
|
4979
|
-
update
|
|
4980
|
-
& \text{ otherwise }
|
|
4981
|
-
\end{cases} \\
|
|
4982
|
-
w = w - lr * update
|
|
4983
|
-
\end{array}
|
|
4984
|
-
|
|
4985
|
-
:math:`m` represents the 1st moment vector, :math:`v` represents the 2nd moment vector, :math:`g` represents
|
|
4986
|
-
`gradient`, :math:`\beta_1, \beta_2` represent `beta1` and `beta2`,
|
|
4987
|
-
:math:`lr` represents `learning_rate`, :math:`w` represents `var`, :math:`decay` represents `weight_decay`,
|
|
4988
|
-
:math:`\epsilon` represents `epsilon`.
|
|
4989
|
-
|
|
4990
|
-
Args:
|
|
4991
|
-
use_locking (bool): Whether to enable a lock to protect variable tensors from being updated.
|
|
4992
|
-
If ``True`` , updates of the var, m, and v tensors will be protected by a lock.
|
|
4993
|
-
If ``False`` , the result is unpredictable. Default: ``False`` .
|
|
4994
|
-
|
|
4995
|
-
Inputs:
|
|
4996
|
-
- **var** (Parameter) - Weights to be updated. The shape is :math:`(N, *)` where :math:`*` means,
|
|
4997
|
-
any number of additional dimensions. The data type can be float16 or float32.
|
|
4998
|
-
- **m** (Parameter) - The 1st moment vector in the updating formula,
|
|
4999
|
-
it should have the the shape as `var`. The data type can be float16 or float32.
|
|
5000
|
-
- **v** (Parameter) - The 2nd moment vector in the updating formula,
|
|
5001
|
-
it should have the same shape as `m`.
|
|
5002
|
-
- **lr** (float) - :math:`lr` in the updating formula. The paper suggested value is :math:`10^{-8}`,
|
|
5003
|
-
the data type should be float32.
|
|
5004
|
-
- **beta1** (float) - The exponential decay rate for the 1st moment estimations,
|
|
5005
|
-
the data type should be float32. The paper suggested value is :math:`0.9`
|
|
5006
|
-
- **beta2** (float) - The exponential decay rate for the 2nd moment estimations,
|
|
5007
|
-
the data type should be float32. The paper suggested value is :math:`0.999`
|
|
5008
|
-
- **epsilon** (float) - Term added to the denominator to improve numerical stability,
|
|
5009
|
-
the data type should be float32.
|
|
5010
|
-
- **decay** (float) - The weight decay value, must be a scalar tensor with float32 data type.
|
|
5011
|
-
Default: ``0.0`` .
|
|
5012
|
-
- **gradient** (Tensor) - Gradient, has the same shape as `var`.
|
|
5013
|
-
|
|
5014
|
-
Outputs:
|
|
5015
|
-
Tuple of 3 Tensor, the updated parameters.
|
|
5016
|
-
|
|
5017
|
-
- **var** (Tensor) - The same shape and data type as `var`.
|
|
5018
|
-
- **m** (Tensor) - The same shape and data type as `m`.
|
|
5019
|
-
- **v** (Tensor) - The same shape and data type as `v`.
|
|
5020
|
-
|
|
5021
|
-
Raises:
|
|
5022
|
-
TypeError: If `use_locking` is not a bool.
|
|
5023
|
-
TypeError: If `lr`, `beta1`, `beta2`, `epsilon` or `decay` is not a float32.
|
|
5024
|
-
TypeError: If `var`, `m` or `v` is not a Parameter with dtype float16 or float32.
|
|
5025
|
-
TypeError: If `gradient` is not a Tensor.
|
|
5026
|
-
ValueError: If `eps` <= 0.
|
|
5027
|
-
ValueError: If `beta1`, `beta2` is not in range (0.0,1.0).
|
|
5028
|
-
ValueError: If `decay` < 0.
|
|
5029
|
-
|
|
5030
|
-
Supported Platforms:
|
|
5031
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
5032
|
-
|
|
5033
|
-
Examples:
|
|
5034
|
-
>>> import numpy as np
|
|
5035
|
-
>>> import mindspore.nn as nn
|
|
5036
|
-
>>> from mindspore import Tensor, Parameter, ops
|
|
5037
|
-
>>> class Net(nn.Cell):
|
|
5038
|
-
... def __init__(self):
|
|
5039
|
-
... super(Net, self).__init__()
|
|
5040
|
-
... self.adam_weight_decay = ops.AdamWeightDecay()
|
|
5041
|
-
... self.var = Parameter(Tensor(np.ones([2, 2]).astype(np.float32)), name="var")
|
|
5042
|
-
... self.m = Parameter(Tensor(np.ones([2, 2]).astype(np.float32)), name="m")
|
|
5043
|
-
... self.v = Parameter(Tensor(np.ones([2, 2]).astype(np.float32)), name="v")
|
|
5044
|
-
... def construct(self, lr, beta1, beta2, epsilon, decay, grad):
|
|
5045
|
-
... out = self.adam_weight_decay(self.var, self.m, self.v, lr, beta1, beta2,
|
|
5046
|
-
... epsilon, decay, grad)
|
|
5047
|
-
... return out
|
|
5048
|
-
>>> net = Net()
|
|
5049
|
-
>>> gradient = Tensor(np.ones([2, 2]).astype(np.float32))
|
|
5050
|
-
>>> output = net(0.001, 0.9, 0.999, 1e-8, 0.0, gradient)
|
|
5051
|
-
>>> print(net.var.asnumpy())
|
|
5052
|
-
[[0.999 0.999]
|
|
5053
|
-
[0.999 0.999]]
|
|
5054
|
-
"""
|
|
5055
|
-
__mindspore_signature__ = (
|
|
5056
|
-
sig.make_sig('var', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T),
|
|
5057
|
-
sig.make_sig('m', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T2),
|
|
5058
|
-
sig.make_sig('v', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T2),
|
|
5059
|
-
sig.make_sig('lr', dtype=sig.sig_dtype.T1),
|
|
5060
|
-
sig.make_sig('beta1', dtype=sig.sig_dtype.T1),
|
|
5061
|
-
sig.make_sig('beta2', dtype=sig.sig_dtype.T1),
|
|
5062
|
-
sig.make_sig('epsilon', dtype=sig.sig_dtype.T1),
|
|
5063
|
-
sig.make_sig('decay', dtype=sig.sig_dtype.T1),
|
|
5064
|
-
sig.make_sig('gradient', dtype=sig.sig_dtype.T)
|
|
5065
|
-
)
|
|
5066
|
-
|
|
5067
|
-
@prim_attr_register
|
|
5068
|
-
def __init__(self, use_locking=False):
|
|
5069
|
-
"""Initialize AdamWeightDecay."""
|
|
5070
|
-
self.add_prim_attr('side_effect_mem', True)
|
|
5071
|
-
validator.check_value_type("use_locking", use_locking, [bool], self.name)
|
|
5072
|
-
|
|
5073
|
-
|
|
5074
3687
|
class AdamNoUpdateParam(Primitive):
|
|
5075
3688
|
r"""
|
|
5076
3689
|
Updates gradients by the Adaptive Moment Estimation (Adam) algorithm. This operator do not update the parameter, but
|
|
@@ -5631,16 +4244,20 @@ class KLDivLoss(Primitive):
|
|
|
5631
4244
|
Note:
|
|
5632
4245
|
- On Ascend, float64 dtype is not currently supported.
|
|
5633
4246
|
- The output aligns with the mathematical definition of Kullback-Leibler divergence
|
|
5634
|
-
only when `reduction` is set to 'batchmean'
|
|
4247
|
+
only when `reduction` is set to ``'batchmean'``.
|
|
4248
|
+
- On Ascend, the value of `reduction` must be one of ``'batchmean'``, ``'none'`` or ``'sum'``.
|
|
4249
|
+
- On GPU, the value of `reduction` must be one of ``'mean'``, ``'none'`` or ``'sum'``.
|
|
4250
|
+
- On CPU, the value of `reduction` must be one of ``'mean'``, ``'batchmean'``, ``'none'``
|
|
4251
|
+
or ``'sum'``.
|
|
5635
4252
|
|
|
5636
4253
|
Args:
|
|
5637
4254
|
reduction (str): Specifies the reduction to be applied to the output.
|
|
5638
4255
|
Default: ``'mean'`` .
|
|
5639
4256
|
|
|
5640
|
-
-
|
|
5641
|
-
-
|
|
5642
|
-
-
|
|
5643
|
-
|
|
4257
|
+
- ``'none'``: no reduction will be applied.
|
|
4258
|
+
- ``'mean'``: compute and return the mean of elements in the output.
|
|
4259
|
+
- ``'sum'``: the output elements will be summed.
|
|
4260
|
+
- ``'batchmean'``: average loss is taken over the batch, similar to the mean mode.
|
|
5644
4261
|
|
|
5645
4262
|
Inputs:
|
|
5646
4263
|
- **logits** (Tensor) - The input Tensor. The data type must be float16, float32 or float64.
|
|
@@ -5686,94 +4303,14 @@ class KLDivLoss(Primitive):
|
|
|
5686
4303
|
device_target = context.get_context("device_target")
|
|
5687
4304
|
if device_target == "CPU":
|
|
5688
4305
|
support_mode = ['none', 'mean', 'batchmean', 'sum']
|
|
5689
|
-
elif device_target == "GPU":
|
|
5690
|
-
support_mode = ['none', 'mean', 'sum']
|
|
5691
|
-
elif device_target == "Ascend":
|
|
5692
|
-
support_mode = ['none', 'batchmean', 'sum', 'mean']
|
|
5693
|
-
else:
|
|
5694
|
-
raise ValueError(f"'{self.name}' unknown device target: '{device_target}'")
|
|
5695
|
-
|
|
5696
|
-
self.reduction = validator.check_string(reduction, support_mode, 'reduction', self.name)
|
|
5697
|
-
|
|
5698
|
-
|
|
5699
|
-
class BinaryCrossEntropy(Primitive):
|
|
5700
|
-
r"""
|
|
5701
|
-
Computes the binary cross entropy between the logits and the labels.
|
|
5702
|
-
|
|
5703
|
-
Sets logits as :math:`x`, labels as :math:`y`, output as :math:`\ell(x, y)`.
|
|
5704
|
-
Let,
|
|
5705
|
-
|
|
5706
|
-
.. math::
|
|
5707
|
-
L = \{l_1,\dots,l_N\}^\top, \quad
|
|
5708
|
-
l_n = - w_n \left[ y_n \cdot \log x_n + (1 - y_n) \cdot \log (1 - x_n) \right]
|
|
5709
|
-
|
|
5710
|
-
In which, :math:`L` indicates the loss of all batch_sizes, :math:`l` indicates the loss of one batch_size,
|
|
5711
|
-
and n indicates one batch_size in the 1-N range, :math:`w_n` indicates the
|
|
5712
|
-
weight of :math:`n`-th batch of binary cross entropy. Then,
|
|
5713
|
-
|
|
5714
|
-
.. math::
|
|
5715
|
-
\ell(x, y) = \begin{cases}
|
|
5716
|
-
L, & \text{if reduction} = \text{'none';}\\
|
|
5717
|
-
\operatorname{mean}(L), & \text{if reduction} = \text{'mean';}\\
|
|
5718
|
-
\operatorname{sum}(L), & \text{if reduction} = \text{'sum'.}
|
|
5719
|
-
\end{cases}
|
|
5720
|
-
|
|
5721
|
-
.. warning::
|
|
5722
|
-
- The value of :math:`x` must range from 0 to 1.
|
|
5723
|
-
|
|
5724
|
-
Args:
|
|
5725
|
-
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
5726
|
-
``'sum'`` . Default: ``'mean'`` .
|
|
5727
|
-
|
|
5728
|
-
- ``'none'``: no reduction will be applied.
|
|
5729
|
-
- ``'mean'``: compute and return the weighted mean of elements in the output.
|
|
5730
|
-
- ``'sum'``: the output elements will be summed.
|
|
5731
|
-
|
|
5732
|
-
Inputs:
|
|
5733
|
-
- **logits** (Tensor) - The predictive value whose data type must be float16 or float32,
|
|
5734
|
-
The shape is :math:`(N, *)` where :math:`*` means, any number of additional dimensions.
|
|
5735
|
-
- **labels** (Tensor) - The target value which has the same shape and data type as `logits`.
|
|
5736
|
-
- **weight** (Tensor, optional) - A rescaling weight applied to the loss of each batch element.
|
|
5737
|
-
And it must have the same shape and data type as `logits`. Default: ``None`` .
|
|
5738
|
-
|
|
5739
|
-
Outputs:
|
|
5740
|
-
Tensor or Scalar. Returns Tensor that has the same dtype and shape as `logits` if `reduction` is 'none'.
|
|
5741
|
-
Otherwise, returns a scalar Tensor.
|
|
5742
|
-
|
|
5743
|
-
Raises:
|
|
5744
|
-
TypeError: If dtype of `logits`, `labels` or `weight` (if given) is neither float16 nor float32.
|
|
5745
|
-
ValueError: If `reduction` is not one of ``'none'``, ``'mean'`` or ``'sum'``.
|
|
5746
|
-
ValueError: If shape of `labels` is not the same as `logits` or `weight` (if given).
|
|
5747
|
-
TypeError: If `logits`, `labels` or `weight` is not a Tensor.
|
|
5748
|
-
|
|
5749
|
-
Supported Platforms:
|
|
5750
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
5751
|
-
|
|
5752
|
-
Examples:
|
|
5753
|
-
>>> import mindspore
|
|
5754
|
-
>>> import numpy as np
|
|
5755
|
-
>>> from mindspore import Tensor, nn, ops
|
|
5756
|
-
>>> class Net(nn.Cell):
|
|
5757
|
-
... def __init__(self):
|
|
5758
|
-
... super(Net, self).__init__()
|
|
5759
|
-
... self.binary_cross_entropy = ops.BinaryCrossEntropy()
|
|
5760
|
-
... def construct(self, logits, labels, weight):
|
|
5761
|
-
... result = self.binary_cross_entropy(logits, labels, weight)
|
|
5762
|
-
... return result
|
|
5763
|
-
...
|
|
5764
|
-
>>> net = Net()
|
|
5765
|
-
>>> logits = Tensor(np.array([0.2, 0.7, 0.1]), mindspore.float32)
|
|
5766
|
-
>>> labels = Tensor(np.array([0., 1., 0.]), mindspore.float32)
|
|
5767
|
-
>>> weight = Tensor(np.array([1, 2, 2]), mindspore.float32)
|
|
5768
|
-
>>> output = net(logits, labels, weight)
|
|
5769
|
-
>>> print(output)
|
|
5770
|
-
0.38240486
|
|
5771
|
-
"""
|
|
4306
|
+
elif device_target == "GPU":
|
|
4307
|
+
support_mode = ['none', 'mean', 'sum']
|
|
4308
|
+
elif device_target == "Ascend":
|
|
4309
|
+
support_mode = ['none', 'batchmean', 'sum', 'mean']
|
|
4310
|
+
else:
|
|
4311
|
+
raise ValueError(f"'{self.name}' unknown device target: '{device_target}'")
|
|
5772
4312
|
|
|
5773
|
-
|
|
5774
|
-
def __init__(self, reduction='mean'):
|
|
5775
|
-
"""Initialize BinaryCrossEntropy."""
|
|
5776
|
-
self.reduction = validator.check_string(reduction, ['none', 'mean', 'sum'], 'reduction', self.name)
|
|
4313
|
+
self.reduction = validator.check_string(reduction, support_mode, 'reduction', self.name)
|
|
5777
4314
|
|
|
5778
4315
|
|
|
5779
4316
|
class ApplyAdaMax(Primitive):
|
|
@@ -6496,22 +5033,21 @@ class ApplyAddSign(Primitive):
|
|
|
6496
5033
|
is the last moment of :math:`m_{t+1}`, :math:`lr` represents scaling factor `lr`, :math:`g` represents `grad`,
|
|
6497
5034
|
:math:`\alpha` represents `alpha`, :math:`\beta` represents `beta`.
|
|
6498
5035
|
|
|
6499
|
-
|
|
5036
|
+
The data type of all inputs must be float16 or float32 on Ascend and float16, float32 or float64 on CPU and GPU.
|
|
5037
|
+
|
|
5038
|
+
Inputs of `var`, `accum` and `grad` , `sign_decay` and `beta` comply with the implicit type conversion rules
|
|
6500
5039
|
to make the data types consistent.
|
|
6501
5040
|
If they have different data types, the lower priority data type will be converted to
|
|
6502
5041
|
the relatively highest priority data type.
|
|
6503
|
-
The data type of inputs must be float16 or float32 on Ascend and float16, float32 or float64 on CPU and GPU.
|
|
6504
5042
|
|
|
6505
5043
|
Inputs:
|
|
6506
|
-
- **var** (Parameter) - Variable tensor to be updated.
|
|
5044
|
+
- **var** (Parameter) - Variable tensor to be updated.
|
|
6507
5045
|
The shape is :math:`(N, *)` where :math:`*` means, any number of additional dimensions.
|
|
6508
5046
|
- **m** (Parameter) - Variable tensor to be updated, has the same data type as `var`.
|
|
6509
5047
|
- **lr** (Union[Number, Tensor]) - The learning rate value, must be a scalar.
|
|
6510
|
-
|
|
6511
|
-
- **
|
|
6512
|
-
- **sign_decay** (Union[Number, Tensor]) - Must be a scalar. With float16, float32 or float64 data type.
|
|
5048
|
+
- **alpha** (Union[Number, Tensor]) - Must be a scalar.
|
|
5049
|
+
- **sign_decay** (Union[Number, Tensor]) - Must be a scalar.
|
|
6513
5050
|
- **beta** (Union[Number, Tensor]) - The exponential decay rate, must be a scalar.
|
|
6514
|
-
With float16, float32 or float64 data type.
|
|
6515
5051
|
- **grad** (Tensor) - A tensor of the same shape as `var`, for the gradient.
|
|
6516
5052
|
|
|
6517
5053
|
Outputs:
|
|
@@ -6521,7 +5057,8 @@ class ApplyAddSign(Primitive):
|
|
|
6521
5057
|
- **m** (Tensor) - The same shape and data type as `m`.
|
|
6522
5058
|
|
|
6523
5059
|
Raises:
|
|
6524
|
-
TypeError: If dtype of `var`, `lr
|
|
5060
|
+
TypeError: If dtype of `var`, `lr` and `alpha` is not float16, float32 or float64.
|
|
5061
|
+
TypeError: If dtype of `sign_decay` and `beta` are both not float16, float32 or float64.
|
|
6525
5062
|
TypeError: If `lr`, `alpha` or `sign_decay` is neither a Number nor a Tensor.
|
|
6526
5063
|
TypeError: If `grad` is not a Tensor.
|
|
6527
5064
|
TypeError: If the data type of `var`, `accum` and `grad` conversion of Parameter is not supported.
|
|
@@ -6828,9 +5365,12 @@ class LARSUpdate(PrimitiveWithInfer):
|
|
|
6828
5365
|
For more details, please refer to :class:`mindspore.nn.LARS`.
|
|
6829
5366
|
|
|
6830
5367
|
Args:
|
|
6831
|
-
epsilon (float): Term added to the denominator to improve numerical stability.
|
|
6832
|
-
|
|
6833
|
-
|
|
5368
|
+
epsilon (float, optional): Term added to the denominator to improve numerical stability.
|
|
5369
|
+
Default: ``1e-05`` .
|
|
5370
|
+
hyperpara (float, optional): Trust coefficient for calculating the local learning rate.
|
|
5371
|
+
Default: ``0.001`` .
|
|
5372
|
+
use_clip (bool, optional): Whether to use clip operation for calculating the local learning rate.
|
|
5373
|
+
Default: ``False`` .
|
|
6834
5374
|
|
|
6835
5375
|
Inputs:
|
|
6836
5376
|
- **weight** (Tensor) - A tensor, representing the weight.
|
|
@@ -7032,7 +5572,7 @@ class SparseApplyFtrl(Primitive):
|
|
|
7032
5572
|
Examples:
|
|
7033
5573
|
>>> import mindspore
|
|
7034
5574
|
>>> import numpy as np
|
|
7035
|
-
>>> from mindspore import Tensor, nn, Parameter
|
|
5575
|
+
>>> from mindspore import Tensor, nn, Parameter, ops
|
|
7036
5576
|
>>> class SparseApplyFtrlNet(nn.Cell):
|
|
7037
5577
|
... def __init__(self):
|
|
7038
5578
|
... super(SparseApplyFtrlNet, self).__init__()
|
|
@@ -7130,69 +5670,6 @@ class SparseApplyFtrlV2(PrimitiveWithInfer):
|
|
|
7130
5670
|
return var_dtype, accum_dtype, linear_dtype
|
|
7131
5671
|
|
|
7132
5672
|
|
|
7133
|
-
class Dropout(PrimitiveWithCheck):
|
|
7134
|
-
r"""
|
|
7135
|
-
During training, randomly zeroes some of the elements of the input tensor
|
|
7136
|
-
with probability :math:`1 - keep\_prob` from a Bernoulli distribution. It plays the
|
|
7137
|
-
role of reducing neuron correlation and avoid overfitting.
|
|
7138
|
-
|
|
7139
|
-
Refer to :func:`mindspore.ops.dropout` for more details.
|
|
7140
|
-
|
|
7141
|
-
Args:
|
|
7142
|
-
keep_prob (float, optional): The keep rate, between 0 and 1, e.g. keep_prob = 0.9,
|
|
7143
|
-
means dropping out 10% of input units. Default: ``0.5`` .
|
|
7144
|
-
Seed0 (int, optional): Seed0 value for random generating. Default: ``0`` .
|
|
7145
|
-
Seed1 (int, optional): Seed1 value for random generating. Default: ``0`` .
|
|
7146
|
-
|
|
7147
|
-
Inputs:
|
|
7148
|
-
- **x** (Tensor) - The input Tensor of shape :math:`(*, N)`, with data type of float16, float32 or float64.
|
|
7149
|
-
|
|
7150
|
-
Outputs:
|
|
7151
|
-
- **output** (Tensor) - With the same shape and data type as `x`.
|
|
7152
|
-
- **mask** (Tensor) - The mask applied to `x`.
|
|
7153
|
-
|
|
7154
|
-
- On GPU and CPU, `mask` has the same shape and data type as `x`.
|
|
7155
|
-
- On Ascend, to achieve a better performance, it is denoted as a 1-D Tensor
|
|
7156
|
-
with Uint8 data type. It has shape :math:`(byte\_counts, )` where :math:`byte\_counts` is the
|
|
7157
|
-
number of bytes needed to mask the input `x`, :math:`byte\_counts` is calculated using the
|
|
7158
|
-
following formula:
|
|
7159
|
-
|
|
7160
|
-
.. math::
|
|
7161
|
-
|
|
7162
|
-
byte\_counts = \text{ceil}(\text{cumprod}(x.shape) / 128) * 16
|
|
7163
|
-
|
|
7164
|
-
If shape of `x` is :math:`(2, 3, 4, 5, 6)`, the shape of `mask` will be :math:`(96, )`.
|
|
7165
|
-
|
|
7166
|
-
Supported Platforms:
|
|
7167
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
7168
|
-
|
|
7169
|
-
Examples:
|
|
7170
|
-
>>> import mindspore
|
|
7171
|
-
>>> import numpy as np
|
|
7172
|
-
>>> from mindspore import Tensor, ops
|
|
7173
|
-
>>> dropout = ops.Dropout(keep_prob=0.5)
|
|
7174
|
-
>>> x = Tensor(np.ones([1, 2, 3, 4, 5]), mindspore.float32)
|
|
7175
|
-
>>> output, mask = dropout(x)
|
|
7176
|
-
>>> print(output.shape, mask.shape, mask.dtype)
|
|
7177
|
-
(1, 2, 3, 4, 5) (16,) UInt8
|
|
7178
|
-
"""
|
|
7179
|
-
|
|
7180
|
-
@prim_attr_register
|
|
7181
|
-
def __init__(self, keep_prob=0.5, Seed0=0, Seed1=0):
|
|
7182
|
-
"""Initialize Dropout."""
|
|
7183
|
-
self.seed0 = validator.check_value_type("Seed0", Seed0, [int], self.name)
|
|
7184
|
-
self.seed1 = validator.check_value_type("Seed1", Seed1, [int], self.name)
|
|
7185
|
-
self.keep_prob = validator.check_float_range(keep_prob, 0, 1, validator.INC_RIGHT, "keep_prob", self.name)
|
|
7186
|
-
self.add_prim_attr("side_effect_hidden", True)
|
|
7187
|
-
|
|
7188
|
-
def check_shape(self, x_shape):
|
|
7189
|
-
validator.check_int(len(x_shape), 1, validator.GE, "x_shape", self.name)
|
|
7190
|
-
|
|
7191
|
-
def check_dtype(self, x_dtype):
|
|
7192
|
-
valid_dtypes = (mstype.float16, mstype.float32, mstype.float64)
|
|
7193
|
-
validator.check_tensor_dtype_valid("x", x_dtype, valid_dtypes, self.name)
|
|
7194
|
-
|
|
7195
|
-
|
|
7196
5673
|
class Dropout2D(PrimitiveWithInfer):
|
|
7197
5674
|
r"""
|
|
7198
5675
|
During training, randomly zeroes some channels of the input tensor with probability :math:`1-keep\_prob`
|
|
@@ -7544,7 +6021,7 @@ class DynamicRNN(Primitive):
|
|
|
7544
6021
|
- **w** (Tensor) - Weight. Tensor of shape :math:`(input\_size + hidden\_size, 4 * hidden\_size)`.
|
|
7545
6022
|
The data type must be float16.
|
|
7546
6023
|
- **b** (Tensor) - Bias. Tensor of shape :math:`(4 * hidden\_size)`.
|
|
7547
|
-
The data type must be float16
|
|
6024
|
+
The data type must be float16.
|
|
7548
6025
|
- **seq_length** (Tensor) - The length of each batch. Tensor of shape :math:`(batch\_size, )`.
|
|
7549
6026
|
Only `None` is currently supported.
|
|
7550
6027
|
- **init_h** (Tensor) - Hidden state of initial time. Tensor of shape :math:`(1, batch\_size, hidden\_size)`.
|
|
@@ -7613,11 +6090,13 @@ class DynamicRNN(Primitive):
|
|
|
7613
6090
|
self.forget_bias = validator.check_value_type("forget_bias", forget_bias, [float], self.name)
|
|
7614
6091
|
self.cell_depth = validator.check_value_type("cell_depth", cell_depth, [int], self.name)
|
|
7615
6092
|
self.keep_prob = validator.check_value_type("keep_prob", keep_prob, [float], self.name)
|
|
6093
|
+
validator.check_number_range(keep_prob, 0.0, 1.0, validator.INC_BOTH, float, "keep_prob")
|
|
7616
6094
|
self.cell_clip = validator.check_value_type("cell_clip", cell_clip, [float], self.name)
|
|
7617
6095
|
self.num_proj = validator.check_non_negative_int(num_proj, "num_proj", self.name)
|
|
7618
6096
|
self.forget_bias = validator.check_value_type("forget_bias", forget_bias, [float], self.name)
|
|
7619
6097
|
self.use_peephole = validator.check_value_type("use_peephole", use_peephole, [bool], self.name)
|
|
7620
6098
|
self.time_major = validator.check_value_type("time_major", time_major, [bool], self.name)
|
|
6099
|
+
validator.check("time_major", time_major, "the supported value", True, validator.EQ, self.name)
|
|
7621
6100
|
self.is_training = validator.check_value_type("is_training", is_training, [bool], self.name)
|
|
7622
6101
|
validator.check_value_type("cell_type", cell_type, [str], self.name)
|
|
7623
6102
|
self.cell_type = validator.check_string(cell_type, ['LSTM'], "cell_type", self.name)
|
|
@@ -7648,21 +6127,21 @@ class DynamicGRUV2(Primitive):
|
|
|
7648
6127
|
:math:`\sigma` is the sigmoid function, and :math:`*` is the Hadamard product.
|
|
7649
6128
|
|
|
7650
6129
|
Args:
|
|
7651
|
-
direction (str): A string identifying the direction in the operator. Default: ``'UNIDIRECTIONAL'`` .
|
|
6130
|
+
direction (str, optional): A string identifying the direction in the operator. Default: ``'UNIDIRECTIONAL'`` .
|
|
7652
6131
|
Only ``'UNIDIRECTIONAL'`` is currently supported.
|
|
7653
|
-
cell_depth (int): An integer identifying the cell depth in the operator. Default: ``1`` .
|
|
7654
|
-
keep_prob (float): A float identifying the keep prob in the operator. Default: ``1.0`` .
|
|
7655
|
-
cell_clip (float): A float identifying the cell clip in the operator. Default: ``-1.0`` .
|
|
7656
|
-
num_proj (int): An integer identifying the number projection in the operator. Default: ``0`` .
|
|
7657
|
-
time_major (bool): A bool identifying the time major in the operator. Default: ``True`` .
|
|
7658
|
-
activation (str) : A string identifying the type of activation function in the operator.
|
|
6132
|
+
cell_depth (int, optional): An integer identifying the cell depth in the operator. Default: ``1`` .
|
|
6133
|
+
keep_prob (float, optional): A float identifying the keep prob in the operator. Default: ``1.0`` .
|
|
6134
|
+
cell_clip (float, optional): A float identifying the cell clip in the operator. Default: ``-1.0`` .
|
|
6135
|
+
num_proj (int, optional): An integer identifying the number projection in the operator. Default: ``0`` .
|
|
6136
|
+
time_major (bool, optional): A bool identifying the time major in the operator. Default: ``True`` .
|
|
6137
|
+
activation (str, optional) : A string identifying the type of activation function in the operator.
|
|
7659
6138
|
Default: ``'tanh'`` . Only ``'tanh'`` is currently supported.
|
|
7660
|
-
gate_order (str): A string identifying the gate order in weight and bias. Default: ``'rzh'`` .
|
|
6139
|
+
gate_order (str, optional): A string identifying the gate order in weight and bias. Default: ``'rzh'`` .
|
|
7661
6140
|
``'zrh'`` is another option. Here, ``'rzh'`` means the gate order is: reset gate, update gate, hidden gate.
|
|
7662
6141
|
``'zrh'`` means the gate order is: update gate, reset gate, hidden gate.
|
|
7663
|
-
reset_after (bool): A bool identifying whether to apply reset gate after matrix multiplication.
|
|
6142
|
+
reset_after (bool, optional): A bool identifying whether to apply reset gate after matrix multiplication.
|
|
7664
6143
|
Default: ``True`` .
|
|
7665
|
-
is_training (bool): A bool identifying is training in the operator. Default: ``True`` .
|
|
6144
|
+
is_training (bool, optional): A bool identifying is training in the operator. Default: ``True`` .
|
|
7666
6145
|
|
|
7667
6146
|
Inputs:
|
|
7668
6147
|
- **x** (Tensor) - Current words.
|
|
@@ -8006,8 +6485,9 @@ class Conv3D(Primitive):
|
|
|
8006
6485
|
|
|
8007
6486
|
Applies a 3D convolution over an input tensor which is typically of shape
|
|
8008
6487
|
:math:`(N, C_{in}, D_{in}, H_{in}, W_{in})`,
|
|
8009
|
-
where :math:`N` is batch size, :math:`C` is channel number,
|
|
8010
|
-
:math:`H
|
|
6488
|
+
where :math:`N` is batch size, :math:`C` is channel number,
|
|
6489
|
+
:math:`D, H, W`
|
|
6490
|
+
are the depth, height and width of the feature map, respectively.
|
|
8011
6491
|
|
|
8012
6492
|
The output is calculated based on formula:
|
|
8013
6493
|
|
|
@@ -8018,25 +6498,30 @@ class Conv3D(Primitive):
|
|
|
8018
6498
|
|
|
8019
6499
|
where :math:`bias` is the output channel bias, :math:`ccor` is
|
|
8020
6500
|
the `cross-correlation <https://en.wikipedia.org/wiki/Cross-correlation>`_,
|
|
8021
|
-
|
|
6501
|
+
:math:`weight` is the convolution kernel value and :math:`X` represents the input feature map.
|
|
8022
6502
|
|
|
8023
6503
|
Here are the indices' meanings:
|
|
8024
|
-
- :math:`i` corresponds to the batch number, ranging from 0 to N-1, where N is the batch size of the input.
|
|
8025
6504
|
|
|
8026
|
-
- :math:`
|
|
6505
|
+
- :math:`i` corresponds to the batch number, the range is :math:`[0, N-1]`,
|
|
6506
|
+
where :math:`N` is the batch size of the input.
|
|
6507
|
+
|
|
6508
|
+
- :math:`j` corresponds to the output channel, the range is :math:`[0, C_{out}-1]`,
|
|
6509
|
+
where :math:`C_{out}` is the number of
|
|
8027
6510
|
output channels, which is also equal to the number of kernels.
|
|
8028
6511
|
|
|
8029
|
-
- :math:`k` corresponds to the input channel,
|
|
6512
|
+
- :math:`k` corresponds to the input channel, the range is :math:`[0, C_{in}-1]`,
|
|
6513
|
+
where :math:`C_{in}` is the number of
|
|
8030
6514
|
input channels, which is also equal to the number of channels in the convolutional kernels.
|
|
8031
6515
|
|
|
8032
|
-
Therefore, in the above formula, :math:`{bias}(C_{
|
|
8033
|
-
output channel, :math:`{weight}(C_{
|
|
6516
|
+
Therefore, in the above formula, :math:`{bias}(C_{\text{out}_j})` represents the bias of the :math:`j`-th
|
|
6517
|
+
output channel, :math:`{weight}(C_{\text{out}_j}, k)`represents the slice of the :math:`j`-th convolutional
|
|
8034
6518
|
kernel in the :math:`k`-th channel, and :math:`{X}(N_i, k)` represents the slice of the :math:`k`-th input
|
|
8035
6519
|
channel in the :math:`i`-th batch of the input feature map.
|
|
8036
6520
|
|
|
8037
6521
|
The shape of the convolutional kernel is given by
|
|
8038
6522
|
:math:`(\text{kernel_size[0]}, \text{kernel_size[1]}, \text{kernel_size[2]})`
|
|
8039
|
-
where :math
|
|
6523
|
+
where :math:`\text{kernel_size[0]}` ,
|
|
6524
|
+
:math:`\text{kernel_size[1]}` and :math:`\text{kernel_size[2]}` are the depth,
|
|
8040
6525
|
height and width of the kernel, respectively.
|
|
8041
6526
|
If we consider the input and output channels as well as the `group` parameter, the complete kernel shape
|
|
8042
6527
|
will be :math:`(C_{out}, C_{in} / \text{group}, \text{kernel_size[0]},
|
|
@@ -8047,8 +6532,8 @@ class Conv3D(Primitive):
|
|
|
8047
6532
|
<http://vision.stanford.edu/cs598_spring07/papers/Lecun98.pdf>`_.
|
|
8048
6533
|
|
|
8049
6534
|
Note:
|
|
8050
|
-
1. On Ascend platform,
|
|
8051
|
-
2. On Ascend
|
|
6535
|
+
1. On Ascend platform, :math:`groups=1` must be satisfied.
|
|
6536
|
+
2. On Ascend :math:`dilation` on depth only supports the case of 1.
|
|
8052
6537
|
|
|
8053
6538
|
Args:
|
|
8054
6539
|
out_channel (int): Specifies output channel :math:`C_{out}`.
|
|
@@ -8670,7 +7155,7 @@ class Conv3DTranspose(Primitive):
|
|
|
8670
7155
|
\times (\text{kernel_size}[2] - 1) + \text{output_padding}[2] + 1
|
|
8671
7156
|
|
|
8672
7157
|
Note:
|
|
8673
|
-
In Ascend,
|
|
7158
|
+
In Ascend, only support :math:`group=1`.
|
|
8674
7159
|
|
|
8675
7160
|
Args:
|
|
8676
7161
|
in_channel (int): The channel of the input x.
|
|
@@ -8738,7 +7223,7 @@ class Conv3DTranspose(Primitive):
|
|
|
8738
7223
|
ValueError: If `pad` is a tuple whose length is not equal to 6.
|
|
8739
7224
|
ValueError: If `pad_mode` is not equal to 'pad' and `pad` is not equal to (0, 0, 0, 0, 0, 0).
|
|
8740
7225
|
ValueError: If `data_format` is not 'NCDHW'.
|
|
8741
|
-
TypeError: If data type of dout and weight is
|
|
7226
|
+
TypeError: If data type of dout and weight is neither float16 nor float32.
|
|
8742
7227
|
ValueError: If bias is not none. The rank of dout and weight is not 5.
|
|
8743
7228
|
|
|
8744
7229
|
Supported Platforms:
|
|
@@ -9013,46 +7498,6 @@ class SoftShrink(Primitive):
|
|
|
9013
7498
|
validator.check_number("lambd", lambd, 0, validator.GE, self.name)
|
|
9014
7499
|
|
|
9015
7500
|
|
|
9016
|
-
class HShrink(Primitive):
|
|
9017
|
-
r"""
|
|
9018
|
-
Hard Shrink activation function.
|
|
9019
|
-
|
|
9020
|
-
Refer to :func:`mindspore.ops.hardshrink` for more details.
|
|
9021
|
-
|
|
9022
|
-
Args:
|
|
9023
|
-
lambd (float, optional): The threshold :math:`\lambda` defined by the Hard Shrink formula. Default: ``0.5`` .
|
|
9024
|
-
|
|
9025
|
-
Inputs:
|
|
9026
|
-
- **input_x** (Tensor) - The input of Hard Shrink with data type of float16 or float32.
|
|
9027
|
-
|
|
9028
|
-
Outputs:
|
|
9029
|
-
Tensor, the same shape and data type as the input.
|
|
9030
|
-
|
|
9031
|
-
Supported Platforms:
|
|
9032
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
9033
|
-
|
|
9034
|
-
Examples:
|
|
9035
|
-
>>> import mindspore as ms
|
|
9036
|
-
>>> import mindspore.ops as ops
|
|
9037
|
-
>>> from mindspore import Tensor, nn
|
|
9038
|
-
>>> import numpy as np
|
|
9039
|
-
>>> input_x = Tensor(np.array([[0.5, 1, 2.0], [0.0533, 0.0776, -2.1233]]), ms.float32)
|
|
9040
|
-
>>> hshrink = ops.HShrink()
|
|
9041
|
-
>>> output = hshrink(input_x)
|
|
9042
|
-
>>> print(output)
|
|
9043
|
-
[[ 0. 1. 2. ]
|
|
9044
|
-
[ 0. 0. -2.1233]]
|
|
9045
|
-
"""
|
|
9046
|
-
|
|
9047
|
-
@prim_attr_register
|
|
9048
|
-
def __init__(self, lambd=0.5):
|
|
9049
|
-
"""Initialize HShrink"""
|
|
9050
|
-
validator.check_value_type('lambd', lambd, [float], self.name)
|
|
9051
|
-
if lambd < 0.0:
|
|
9052
|
-
lambd = 0.0
|
|
9053
|
-
self.add_prim_attr('lambd', lambd)
|
|
9054
|
-
|
|
9055
|
-
|
|
9056
7501
|
class ApplyAdagradDA(Primitive):
|
|
9057
7502
|
r"""
|
|
9058
7503
|
Update `var` according to the proximal adagrad scheme.
|
|
@@ -9097,11 +7542,9 @@ class ApplyAdagradDA(Primitive):
|
|
|
9097
7542
|
- **global_step** ([Number, Tensor]) - Training step number. Must be a scalar. With int32 or int64 data type.
|
|
9098
7543
|
|
|
9099
7544
|
Outputs:
|
|
9100
|
-
Tuple of
|
|
7545
|
+
Tuple of 1 Tensors, the updated parameters.
|
|
9101
7546
|
|
|
9102
7547
|
- **var** (Tensor) - The same shape and data type as `var`.
|
|
9103
|
-
- **gradient_accumulator** (Tensor) - The same shape and data type as `gradient_accumulator`.
|
|
9104
|
-
- **gradient_squared_accumulator** (Tensor) - The same shape and data type as `gradient_squared_accumulator`.
|
|
9105
7548
|
|
|
9106
7549
|
Raises:
|
|
9107
7550
|
TypeError: If `var`, `gradient_accumulator` or `gradient_squared_accumulator` is not a Parameter.
|
|
@@ -9152,11 +7595,7 @@ class ApplyAdagradDA(Primitive):
|
|
|
9152
7595
|
>>> print(output)
|
|
9153
7596
|
(Tensor(shape=[2, 2], dtype=Float32, value=
|
|
9154
7597
|
[[-7.39064650e-04, -1.36888528e-03],
|
|
9155
|
-
[-5.96988888e-04, -1.42478070e-03]])
|
|
9156
|
-
[[ 4.00000006e-01, 7.00000048e-01],
|
|
9157
|
-
[ 2.00000003e-01, 6.99999988e-01]]), Tensor(shape=[2, 2], dtype=Float32, value=
|
|
9158
|
-
[[ 2.90000021e-01, 2.60000020e-01],
|
|
9159
|
-
[ 1.09999999e-01, 2.40000010e-01]]))
|
|
7598
|
+
[-5.96988888e-04, -1.42478070e-03]]))
|
|
9160
7599
|
"""
|
|
9161
7600
|
|
|
9162
7601
|
__mindspore_signature__ = (
|
|
@@ -9668,6 +8107,14 @@ class ApplyAdamWithAmsgradV2(Primitive):
|
|
|
9668
8107
|
var:=var-lr_t*m_t/(\sqrt{\hat v_t}+\epsilon) \\
|
|
9669
8108
|
\end{array}
|
|
9670
8109
|
|
|
8110
|
+
:math:`t` represents updating step while :math:`m` represents the 1st moment vector,
|
|
8111
|
+
:math:`v` represents the 2nd moment vector, :math:`\hat v_t` represents `vhat`,
|
|
8112
|
+
:math:`lr` represents learning rate,
|
|
8113
|
+
:math:`g` represents `grad`, :math:`\beta_1, \beta_2` represent `beta1` and `beta2`,
|
|
8114
|
+
:math:`\beta_1^{t}` represents `beta1_power`, :math:`\beta_2^{t}` represents `beta2_power`,
|
|
8115
|
+
:math:`var` represents the variable to be updated,
|
|
8116
|
+
:math:`\epsilon` represents `epsilon`.
|
|
8117
|
+
|
|
9671
8118
|
All of the inputs are consistent with implicit type conversion rules,
|
|
9672
8119
|
which ensure that the data types are the same. If they have different data types, the lower precision data type
|
|
9673
8120
|
will be converted to the data type with relatively higher precision.
|
|
@@ -9716,7 +8163,7 @@ class ApplyAdamWithAmsgradV2(Primitive):
|
|
|
9716
8163
|
``Ascend`` ``GPU`` ``CPU``
|
|
9717
8164
|
|
|
9718
8165
|
Examples:
|
|
9719
|
-
>>>
|
|
8166
|
+
>>> from mindspore import ops
|
|
9720
8167
|
>>> import mindspore.nn as nn
|
|
9721
8168
|
>>> from mindspore import Tensor, Parameter
|
|
9722
8169
|
>>> import numpy as np
|
|
@@ -9769,83 +8216,6 @@ class ApplyAdamWithAmsgradV2(Primitive):
|
|
|
9769
8216
|
self.add_prim_attr("side_effect_mem", True)
|
|
9770
8217
|
|
|
9771
8218
|
|
|
9772
|
-
class GridSampler3D(Primitive):
|
|
9773
|
-
"""
|
|
9774
|
-
Given an input and a grid, the output is calculated using the input values
|
|
9775
|
-
and pixel positions in the grid. Only volume (5-D) input is supported.
|
|
9776
|
-
|
|
9777
|
-
.. warning::
|
|
9778
|
-
This is an experimental API that is subject to change or deletion.
|
|
9779
|
-
|
|
9780
|
-
Refer to :func:`mindspore.ops.grid_sample` for more details.
|
|
9781
|
-
|
|
9782
|
-
Args:
|
|
9783
|
-
interpolation_mode (str, optional): An optional string specifying the interpolation method.
|
|
9784
|
-
The optional values are ``"bilinear"`` or ``"nearest"`` . Default: ``"bilinear"`` .
|
|
9785
|
-
|
|
9786
|
-
- ``"nearest"``: Nearest neighbor interpolation. Each output pixel is assigned the value of the
|
|
9787
|
-
nearest input pixel. This method is simple and fast but can result in blocky or pixelated outputs.
|
|
9788
|
-
- ``"bilinear"``: Bilinear interpolation. Each output pixel is a weighted average of the four nearest input
|
|
9789
|
-
pixels, computed using bilinear interpolation. This method produces smoother results compared
|
|
9790
|
-
to nearest neighbor interpolation.
|
|
9791
|
-
|
|
9792
|
-
padding_mode (str, optional): An optional string specifying the pad method.
|
|
9793
|
-
The optional values are ``"zeros"`` , ``"border"`` or ``"reflection"`` . Default: ``"zeros"`` .
|
|
9794
|
-
When the sampling grid is outside input's bounds, effects of various padding modes are as follows:
|
|
9795
|
-
|
|
9796
|
-
- ``"zeros"``: Pads the input tensor with zeros.
|
|
9797
|
-
- ``"border"``: Pads the input tensor with the values of the pixels on the border of the tensor.
|
|
9798
|
-
- ``"reflection"``: Pads the input tensor by reflecting the values of the pixels at the
|
|
9799
|
-
boundary of the tensor.
|
|
9800
|
-
|
|
9801
|
-
align_corners (bool, optional): An optional bool specifying alignment method. If set to ``True`` ,
|
|
9802
|
-
the extrema (-1 and 1) are considered as referring to
|
|
9803
|
-
the center points of the input’s corner pixels. If set to ``False`` , they are instead considered as
|
|
9804
|
-
referring to the corner points of the input’s corner pixels, making the sampling more resolution agnostic.
|
|
9805
|
-
Default: ``False`` .
|
|
9806
|
-
|
|
9807
|
-
Inputs:
|
|
9808
|
-
- **input_x** (Tensor) - A 5-D tensor with dtype of float16, float32 or float64
|
|
9809
|
-
and shape of :math:`(N, C, D_{in}, H_{in}, W_{in})`.
|
|
9810
|
-
- **grid** (Tensor) - A 5-D tensor whose dtype is the same as `input_x` and whose shape is :math:`(N, D_{out},
|
|
9811
|
-
H_{out}, W_{out}, 3)`.
|
|
9812
|
-
|
|
9813
|
-
Outputs:
|
|
9814
|
-
A 5-D Tensor whose dtype is the same as `input_x` and whose shape is :math:`(N, C, D_{out}, H_{out}, W_{out})`.
|
|
9815
|
-
|
|
9816
|
-
Supported Platforms:
|
|
9817
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
9818
|
-
|
|
9819
|
-
Examples:
|
|
9820
|
-
>>> import numpy as np
|
|
9821
|
-
>>> from mindspore import Tensor, ops
|
|
9822
|
-
>>> gridsampler = ops.GridSampler3D(interpolation_mode='bilinear', padding_mode='zeros', align_corners=True)
|
|
9823
|
-
>>> input_x = Tensor(np.arange(32).reshape((2, 2, 2, 2, 2)).astype(np.float32))
|
|
9824
|
-
>>> grid = Tensor(np.arange(-0.2, 1, 0.1).reshape((2, 2, 1, 1, 3)).astype(np.float32))
|
|
9825
|
-
>>> output = gridsampler(input_x, grid)
|
|
9826
|
-
>>> print(output)
|
|
9827
|
-
[[[[[ 3.3 ]]
|
|
9828
|
-
[[ 4.35 ]]]
|
|
9829
|
-
[[[11.300001]]
|
|
9830
|
-
[[12.349999]]]]
|
|
9831
|
-
[[[[21.4 ]]
|
|
9832
|
-
[[22.449999]]]
|
|
9833
|
-
[[[29.4 ]]
|
|
9834
|
-
[[30.449999]]]]]
|
|
9835
|
-
"""
|
|
9836
|
-
|
|
9837
|
-
@prim_attr_register
|
|
9838
|
-
def __init__(self, interpolation_mode='bilinear', padding_mode='zeros', align_corners=False):
|
|
9839
|
-
"""Initialize GridSampler3D."""
|
|
9840
|
-
validator.check_string(interpolation_mode, ['bilinear', 'nearest'], 'interpolation_mode', self.name)
|
|
9841
|
-
validator.check_string(padding_mode, ['zeros', 'border', 'reflection'], 'padding_mode', self.name)
|
|
9842
|
-
validator.check_bool(align_corners, 'align_corners', self.name)
|
|
9843
|
-
self.init_prim_io_names(inputs=['input_x', 'grid'], outputs=['output'])
|
|
9844
|
-
self.add_prim_attr('interpolation_mode', interpolation_mode)
|
|
9845
|
-
self.add_prim_attr('padding_mode', padding_mode)
|
|
9846
|
-
self.add_prim_attr('align_corners', align_corners)
|
|
9847
|
-
|
|
9848
|
-
|
|
9849
8219
|
class FractionalMaxPool(Primitive):
|
|
9850
8220
|
r"""
|
|
9851
8221
|
Performs fractional max pooling on the input.
|
|
@@ -9991,6 +8361,9 @@ class FractionalMaxPool3DWithFixedKsize(Primitive):
|
|
|
9991
8361
|
``Ascend`` ``GPU`` ``CPU``
|
|
9992
8362
|
|
|
9993
8363
|
Examples:
|
|
8364
|
+
>>> import numpy as np
|
|
8365
|
+
>>> from mindspore import Tensor, ops
|
|
8366
|
+
>>> from mindspore import dtype as mstype
|
|
9994
8367
|
>>> x = Tensor(np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])
|
|
9995
8368
|
... .reshape([1, 1, 2, 2, 4]), mstype.float32)
|
|
9996
8369
|
>>> random_samples = Tensor(np.array([0.7, 0.7, 0.7]).reshape([1, 1, 3]), mstype.float32)
|
|
@@ -10395,104 +8768,21 @@ class DeformableOffsets(Primitive):
|
|
|
10395
8768
|
self.add_prim_attr('modulated', self.modulated)
|
|
10396
8769
|
|
|
10397
8770
|
|
|
10398
|
-
class GridSampler2D(Primitive):
|
|
10399
|
-
"""
|
|
10400
|
-
This operation samples 2d `input_x` by using interpolation based on flow field grid,
|
|
10401
|
-
which is usually gennerated by :func:`mindspore.ops.affine_grid`.
|
|
10402
|
-
|
|
10403
|
-
.. warning::
|
|
10404
|
-
This is an experimental API that is subject to change or deletion.
|
|
10405
|
-
|
|
10406
|
-
Refer to :func:`mindspore.ops.grid_sample` for more details.
|
|
10407
|
-
|
|
10408
|
-
Args:
|
|
10409
|
-
interpolation_mode (str, optional): An optional string specifying the interpolation method.
|
|
10410
|
-
The optional values are
|
|
10411
|
-
``"bilinear"`` or ``"nearest"`` . Default: ``"bilinear"`` .
|
|
10412
|
-
|
|
10413
|
-
- ``"nearest"``: Nearest neighbor interpolation. Each output pixel is assigned the value of the
|
|
10414
|
-
nearest input pixel. This method is simple and fast but can result in blocky or pixelated outputs.
|
|
10415
|
-
- ``"bilinear"``: Bilinear interpolation. Each output pixel is a weighted average of the four nearest input
|
|
10416
|
-
pixels, computed using bilinear interpolation. This method produces smoother results compared
|
|
10417
|
-
to nearest neighbor interpolation.
|
|
10418
|
-
|
|
10419
|
-
padding_mode (str, optional): An optional string specifying the pad method.
|
|
10420
|
-
The optional values are ``"zeros"`` , ``"border"`` or ``"reflection"`` . Default: ``"zeros"`` .
|
|
10421
|
-
When the sampling grid is outside input's bounds, effects of various padding modes are as follows:
|
|
10422
|
-
|
|
10423
|
-
- ``"zeros"``: Pads the input tensor with zeros.
|
|
10424
|
-
- ``"border"``: Pads the input tensor with the values of the pixels on the border of the tensor.
|
|
10425
|
-
- ``"reflection"``: Pads the input tensor by reflecting the values of the pixels at the
|
|
10426
|
-
boundary of the tensor.
|
|
10427
|
-
|
|
10428
|
-
align_corners (bool, optional): An optional bool. When set to ``True`` ,
|
|
10429
|
-
the centers of the corner pixels of the input
|
|
10430
|
-
and output tensors are aligned. When set to ``False`` , it is not aligned. Default: ``False`` .
|
|
10431
|
-
|
|
10432
|
-
Inputs:
|
|
10433
|
-
- **input_x** (Tensor) - A 4-D tensor with shape
|
|
10434
|
-
:math:`(N, C, H_{in}, W_{in})`. Supported dtypes:
|
|
10435
|
-
|
|
10436
|
-
- Ascend: float16, float32.
|
|
10437
|
-
- GPU/CPU: float16, float32, float64.
|
|
10438
|
-
|
|
10439
|
-
- **grid** (Tensor) - A 4-D tensor whose dtype is the same as `input_x` and whose shape is
|
|
10440
|
-
:math:`(N, H_{out}, W_{out}, 2)`.
|
|
10441
|
-
Used to specify the sampling pixel locations normalized by the input spatial
|
|
10442
|
-
dimensions.
|
|
10443
|
-
|
|
10444
|
-
Outputs:
|
|
10445
|
-
A 4-D Tensor whose dtype is the same as `input_x` and whose shape is :math:`(N, C, H_{out}, W_{out})`.
|
|
10446
|
-
|
|
10447
|
-
Supported Platforms:
|
|
10448
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
10449
|
-
|
|
10450
|
-
Examples:
|
|
10451
|
-
>>> import numpy as np
|
|
10452
|
-
>>> from mindspore import Tensor, ops
|
|
10453
|
-
>>> gridsampler = ops.GridSampler2D(interpolation_mode='bilinear', padding_mode='zeros', align_corners=True)
|
|
10454
|
-
>>> input_x = Tensor(np.arange(16).reshape((2, 2, 2, 2)).astype(np.float32))
|
|
10455
|
-
>>> grid = Tensor(np.arange(-9, 9, 0.5).reshape((2, 3, 3, 2)).astype(np.float32))
|
|
10456
|
-
>>> output = gridsampler(input_x, grid)
|
|
10457
|
-
>>> print(output)
|
|
10458
|
-
[[[[ 0. 0. 0. ]
|
|
10459
|
-
[ 0. 0. 0. ]
|
|
10460
|
-
[ 0. 0. 0.5 ]]
|
|
10461
|
-
[[ 0. 0. 0. ]
|
|
10462
|
-
[ 0. 0. 0. ]
|
|
10463
|
-
[ 0. 1.5 4.5 ]]]
|
|
10464
|
-
[[[10. 8.25 1.375]
|
|
10465
|
-
[ 0. 0. 0. ]
|
|
10466
|
-
[ 0. 0. 0. ]]
|
|
10467
|
-
[[14. 11.25 1.875]
|
|
10468
|
-
[ 0. 0. 0. ]
|
|
10469
|
-
[ 0. 0. 0. ]]]]
|
|
10470
|
-
"""
|
|
10471
|
-
|
|
10472
|
-
@prim_attr_register
|
|
10473
|
-
def __init__(self, interpolation_mode='bilinear', padding_mode='zeros', align_corners=False):
|
|
10474
|
-
"""Initialize GridSampler2D."""
|
|
10475
|
-
validator.check_string(interpolation_mode, ['bilinear', 'nearest'], 'interpolation_mode', self.name)
|
|
10476
|
-
validator.check_string(padding_mode, ['zeros', 'border', 'reflection'], 'padding_mode', self.name)
|
|
10477
|
-
validator.check_bool(align_corners, 'align_corners', self.name)
|
|
10478
|
-
self.init_prim_io_names(inputs=['input', 'grid'], outputs=['output'])
|
|
10479
|
-
self.add_prim_attr('interpolation_mode', interpolation_mode)
|
|
10480
|
-
self.add_prim_attr('padding_mode', padding_mode)
|
|
10481
|
-
self.add_prim_attr('align_corners', align_corners)
|
|
10482
|
-
|
|
10483
|
-
|
|
10484
8771
|
class Pdist(Primitive):
|
|
10485
8772
|
r"""
|
|
10486
8773
|
Computes the p-norm distance between each pair of row vectors in the input.
|
|
10487
8774
|
|
|
10488
8775
|
Refer to :func:`mindspore.ops.pdist` for more details.
|
|
10489
8776
|
|
|
8777
|
+
Note:
|
|
8778
|
+
The pdist operator involves exponentiation, the inf/nan calculation result may be generated
|
|
8779
|
+
when the float16 input is used. The float32 input is recommended.
|
|
8780
|
+
|
|
10490
8781
|
Args:
|
|
10491
8782
|
p (float, optional): The order of norm distance, :math:`p∈[0, ∞)`. Default: ``2.0`` .
|
|
10492
8783
|
|
|
10493
8784
|
Inputs:
|
|
10494
|
-
- **x** (Tensor) - Input tensor
|
|
10495
|
-
one-dim or multi-dim. Supported dtypes: float16, float32 or float64.
|
|
8785
|
+
- **x** (Tensor) - Input tensor. Supported dtypes: float16, float32 or float64.
|
|
10496
8786
|
|
|
10497
8787
|
Outputs:
|
|
10498
8788
|
Tensor, has the same dtype as `x`.
|
|
@@ -10519,71 +8809,6 @@ class Pdist(Primitive):
|
|
|
10519
8809
|
self.init_prim_io_names(inputs=['x'], outputs=['y'])
|
|
10520
8810
|
|
|
10521
8811
|
|
|
10522
|
-
class UpsampleNearest3D(Primitive):
|
|
10523
|
-
r"""
|
|
10524
|
-
Performs nearest neighbor upsampling operation.
|
|
10525
|
-
|
|
10526
|
-
This operator scale up the volumetric input with specified `output_size` or `scales` factors, using nearest
|
|
10527
|
-
neighbor algorithm.
|
|
10528
|
-
|
|
10529
|
-
One of `output_size` or `scales` must be given, and can not specified both at the same time.
|
|
10530
|
-
|
|
10531
|
-
Inputs:
|
|
10532
|
-
- **x** (Tensor) - 5D tensor of shape :math:`(N, C, D_{in}, H_{in}, W_{in})`.
|
|
10533
|
-
Supporting types: [float16, float32, float64].
|
|
10534
|
-
- **output_size** (Union[tuple[int], list[int]]): A tuple or list of int specifying the output volumetric size.
|
|
10535
|
-
Default: ``None``.
|
|
10536
|
-
- **scales** (Union[tuple[float], list[float]]): A tuple or list of float specifying the upsampling factors.
|
|
10537
|
-
Default: ``None``.
|
|
10538
|
-
|
|
10539
|
-
Outputs:
|
|
10540
|
-
- **y** (Tensor) - Upsampled output with the same type as `x` , whose shape is
|
|
10541
|
-
:math:`(N, C, D_{out}, H_{out}, W_{out})`.
|
|
10542
|
-
|
|
10543
|
-
Raises:
|
|
10544
|
-
TypeError: When `output_size` is not ``None`` and `output_size` is not list[int] or tuple[int].
|
|
10545
|
-
TypeError: When `scales` is not ``None`` and `scales` is not list[float] or tuple[float].
|
|
10546
|
-
TypeError: If dtype of `x` is not int [uint8, float16, float32, float64].
|
|
10547
|
-
ValueError: If any value of `output_size` is negative or zero when `output_size` is not ``None``.
|
|
10548
|
-
ValueError: If any value of `scales` is negative or zero when `scales` is not ``None``.
|
|
10549
|
-
ValueError: If shape of `x` is not 5D.
|
|
10550
|
-
ValueError: If none of `scales` and `output_size` is specified or both specified.
|
|
10551
|
-
ValueError: If size of `scales` is not equal 3 when `scales` is specified.
|
|
10552
|
-
ValueError: If size of `output_size` is not equal 3 when `output_size` is specified.
|
|
10553
|
-
|
|
10554
|
-
Supported Platforms:
|
|
10555
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
10556
|
-
|
|
10557
|
-
Examples:
|
|
10558
|
-
>>> import numpy as np
|
|
10559
|
-
>>> from mindspore import Tensor, ops
|
|
10560
|
-
>>> from mindspore import dtype as mstype
|
|
10561
|
-
>>> x = Tensor(np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])
|
|
10562
|
-
... .reshape([1, 1, 2, 2, 4]), mstype.float32)
|
|
10563
|
-
>>> output_size = [3, 4, 5]
|
|
10564
|
-
>>> net = ops.UpsampleNearest3D()
|
|
10565
|
-
>>> output = net(x, output_size, None)
|
|
10566
|
-
>>> print(output)
|
|
10567
|
-
[[[[[ 1. 1. 2. 3. 4.]
|
|
10568
|
-
[ 1. 1. 2. 3. 4.]
|
|
10569
|
-
[ 5. 5. 6. 7. 8.]
|
|
10570
|
-
[ 5. 5. 6. 7. 8.]]
|
|
10571
|
-
[[ 1. 1. 2. 3. 4.]
|
|
10572
|
-
[ 1. 1. 2. 3. 4.]
|
|
10573
|
-
[ 5. 5. 6. 7. 8.]
|
|
10574
|
-
[ 5. 5. 6. 7. 8.]]
|
|
10575
|
-
[[ 9. 9. 10. 11. 12.]
|
|
10576
|
-
[ 9. 9. 10. 11. 12.]
|
|
10577
|
-
[13. 13. 14. 15. 16.]
|
|
10578
|
-
[13. 13. 14. 15. 16.]]]]]
|
|
10579
|
-
"""
|
|
10580
|
-
|
|
10581
|
-
@prim_attr_register
|
|
10582
|
-
def __init__(self):
|
|
10583
|
-
"""Initialize UpsampleNearest3D."""
|
|
10584
|
-
self.init_prim_io_names(inputs=['x', 'output_size', 'scales'], outputs=['y'])
|
|
10585
|
-
|
|
10586
|
-
|
|
10587
8812
|
class SparseApplyAdagradDA(Primitive):
|
|
10588
8813
|
r"""
|
|
10589
8814
|
Update `var` according to the proximal adagrad scheme.
|
|
@@ -11226,54 +9451,6 @@ class MaxPoolWithArgmaxV2(Primitive):
|
|
|
11226
9451
|
self.add_prim_attr("ceil_mode", self.ceil_mode)
|
|
11227
9452
|
|
|
11228
9453
|
|
|
11229
|
-
class Dense(Primitive):
|
|
11230
|
-
r"""
|
|
11231
|
-
The dense connected fusion operator.
|
|
11232
|
-
|
|
11233
|
-
Applies dense connected operator for the input. The implement of the operation is as:
|
|
11234
|
-
|
|
11235
|
-
.. math::
|
|
11236
|
-
output = x @ w ^ T + b,
|
|
11237
|
-
|
|
11238
|
-
where :math:`x` is the input tensor, :math:`w` is a weight matrix with the same data type as the :math:`x` ,
|
|
11239
|
-
and :math:`b` is a bias vector with the same data type as the :math:`x` (only if `b` is not ``None``).
|
|
11240
|
-
|
|
11241
|
-
Inputs:
|
|
11242
|
-
- **x** (Tensor) - The shape must meet the following requirement: :math:`len(x.shape)>0`.
|
|
11243
|
-
- **w** (Tensor) - The shape must meet the following requirements:
|
|
11244
|
-
If :math:`len(x.shape)>1`, :math:`len(w.shape)=2`. If :math:`len(x.shape)=1`, :math:`len(w.shape)=1`.
|
|
11245
|
-
:math:`w.shape[-1]=x.shape[-1]`.
|
|
11246
|
-
- **b** (Union[Tensor, None]) - If `b` is not ``None``, the shape must meet the following requirements:
|
|
11247
|
-
If :math:`len(x.shape)>1`, :math:`len(b.shape)=0` or :math:`len(b.shape)=1` .
|
|
11248
|
-
If :math:`len(b.shape)=1`, :math:`b.shape[0]=w.shape[0]`.
|
|
11249
|
-
If :math:`len(x.shape)=1`, :math:`len(b.shape)=0`.
|
|
11250
|
-
|
|
11251
|
-
Outputs:
|
|
11252
|
-
If :math:`len(x.shape)>1`, Tensor of shape :math:`(*x.shape[:-1], w.shape[0])`.
|
|
11253
|
-
If :math:`len(x.shape)=1`, Tensor of shape :math:`()`.
|
|
11254
|
-
|
|
11255
|
-
Supported Platforms:
|
|
11256
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
11257
|
-
|
|
11258
|
-
Examples:
|
|
11259
|
-
>>> import numpy as np
|
|
11260
|
-
>>> from mindspore import Tensor, ops
|
|
11261
|
-
>>> x = Tensor(np.random.random((4, 5, 6, 7)).astype(np.float32))
|
|
11262
|
-
>>> weight = Tensor(np.random.random((6, 7)).astype(np.float32))
|
|
11263
|
-
>>> bias = Tensor(np.random.random((6,)).astype(np.float32))
|
|
11264
|
-
>>> dense = ops.Dense()
|
|
11265
|
-
>>> output = dense(x, weight, bias)
|
|
11266
|
-
>>> print(output.shape)
|
|
11267
|
-
(4, 5, 6, 6)
|
|
11268
|
-
"""
|
|
11269
|
-
|
|
11270
|
-
@prim_attr_register
|
|
11271
|
-
def __init__(self):
|
|
11272
|
-
"""Initialize Dense."""
|
|
11273
|
-
self.init_prim_io_names(inputs=['x', 'w', 'b'], outputs=["output"])
|
|
11274
|
-
self.add_prim_attr("has_bias", True)
|
|
11275
|
-
|
|
11276
|
-
|
|
11277
9454
|
class WKV(Primitive):
|
|
11278
9455
|
r"""
|
|
11279
9456
|
The WKV computation is similar to AFT(Zhai et al., 2021), but W is now a channel-wise vector multiplied
|
|
@@ -11334,7 +9511,8 @@ class PromptFlashAttention(Primitive):
|
|
|
11334
9511
|
S -- Sequence length
|
|
11335
9512
|
H -- Hidden size
|
|
11336
9513
|
|
|
11337
|
-
|
|
9514
|
+
Note:
|
|
9515
|
+
experiment ops
|
|
11338
9516
|
|
|
11339
9517
|
.. warning::
|
|
11340
9518
|
This is an experimental API that is subject to change or deletion.
|
|
@@ -11351,6 +9529,7 @@ class PromptFlashAttention(Primitive):
|
|
|
11351
9529
|
num_key_value_heads (int): head numbers of key/value which are used in GQA algorithm.
|
|
11352
9530
|
The value o indicates if the key and value have the same head nums, use numHeads. Default: 0.
|
|
11353
9531
|
sparse_mode (int): Default: 0
|
|
9532
|
+
inner_precise (int): 0, float16 high precision. 1, high performance. default 1
|
|
11354
9533
|
|
|
11355
9534
|
Inputs:
|
|
11356
9535
|
- **query** (Tensor) - The query tensor with data type of float16 or float32.
|
|
@@ -11361,20 +9540,19 @@ class PromptFlashAttention(Primitive):
|
|
|
11361
9540
|
Input tensor of shape :math:`(B, S, H)` / `(B, N, S, D)`.
|
|
11362
9541
|
- **attn_mask** (Tensor) - The attention mask tensor with data type of float16 or float32.
|
|
11363
9542
|
For each element, 0 indicates retention and 1 indicates discard. Input tensor of shape :math:`(B, 1, S, S)`.
|
|
11364
|
-
- **actual_seq_lengths** (Tensor): Describe actual sequence length of each input with data type of
|
|
11365
|
-
- **actual_seq_lengths_kv** (Tensor): Describe actual sequence length of each input with data type of
|
|
11366
|
-
- **
|
|
9543
|
+
- **actual_seq_lengths** (Tensor): Describe actual sequence length of each input with data type of int64.
|
|
9544
|
+
- **actual_seq_lengths_kv** (Tensor): Describe actual sequence length of each input with data type of int64.
|
|
9545
|
+
- **pse_shift** (Tensor) - The position encoding tensor with data type of float16 or float32.
|
|
11367
9546
|
- **dep_scale1** (Tensor)
|
|
11368
9547
|
- **quant_scale1** (Tensor)
|
|
11369
9548
|
- **deq_scale2** (Tensor)
|
|
11370
9549
|
- **quant_scale2** (Tensor)
|
|
11371
9550
|
- **quant_offset2** (Tensor)
|
|
11372
9551
|
|
|
11373
|
-
|
|
11374
9552
|
Outputs:
|
|
11375
9553
|
- **attention_out** (Tensor) - Input tensor of shape :math:`(B, S, H)` / `(B, N, S, D)`.
|
|
11376
9554
|
|
|
11377
|
-
|
|
9555
|
+
Supported Platforms:
|
|
11378
9556
|
``Ascend``
|
|
11379
9557
|
|
|
11380
9558
|
Examples:
|
|
@@ -11388,15 +9566,16 @@ class PromptFlashAttention(Primitive):
|
|
|
11388
9566
|
>>> query = Tensor(np.ones((B, N, S, D), dtype=np.float16))
|
|
11389
9567
|
>>> key = Tensor(np.ones((B, N, S, D), dtype=np.float16))
|
|
11390
9568
|
>>> value = Tensor(np.ones((B, N, S, D), dtype=np.float16))
|
|
9569
|
+
>>> attn_mask = Tensor(np.ones((B, 1, S, S), dtype=np.float16))
|
|
11391
9570
|
>>> pfa = P.PromptFlashAttention(N, input_layout='BNSD')
|
|
11392
|
-
>>> out = pfa(query, key, value,
|
|
11393
|
-
>>> print(out
|
|
9571
|
+
>>> out = pfa(query, key, value, attn_mask, None, None, None, None, None, None, None, None)
|
|
9572
|
+
>>> print(out.shape)
|
|
11394
9573
|
(1, 16, 256, 16)
|
|
11395
9574
|
"""
|
|
11396
9575
|
|
|
11397
9576
|
@prim_attr_register
|
|
11398
|
-
def __init__(self, num_heads, scale_value=1.0, pre_tokens=
|
|
11399
|
-
num_key_value_heads=0, sparse_mode=0):
|
|
9577
|
+
def __init__(self, num_heads, scale_value=1.0, pre_tokens=214748647, next_tokens=0, input_layout='BSH',
|
|
9578
|
+
num_key_value_heads=0, sparse_mode=0, inner_precise=1):
|
|
11400
9579
|
"""Initialize PromptFlashAttention."""
|
|
11401
9580
|
validator.check_value_type('num_heads', num_heads, [int], self.name)
|
|
11402
9581
|
validator.check_value_type('scale_value', scale_value, [float], self.name)
|
|
@@ -11405,175 +9584,86 @@ class PromptFlashAttention(Primitive):
|
|
|
11405
9584
|
validator.check_value_type('input_layout', input_layout, [str], self.name)
|
|
11406
9585
|
validator.check_value_type('num_key_value_heads', num_key_value_heads, [int], self.name)
|
|
11407
9586
|
validator.check_value_type('sparse_mode', sparse_mode, [int], self.name)
|
|
9587
|
+
validator.check_value_type('inner_precise', inner_precise, [int], self.name)
|
|
11408
9588
|
self.init_prim_io_names(inputs=["query", "key", "value", "attn_mask", "actual_seq_lengths",
|
|
11409
|
-
"actual_seq_lengths_kv", "
|
|
9589
|
+
"actual_seq_lengths_kv", "pse_shift", "deq_scale1", "quant_scale1",
|
|
11410
9590
|
"deq_scale2", "quant_scale2", "quant_offset2"],
|
|
11411
9591
|
outputs=["attention_out"])
|
|
11412
9592
|
|
|
11413
9593
|
|
|
11414
|
-
class
|
|
9594
|
+
class IncreFlashAttention(Primitive):
|
|
11415
9595
|
r"""
|
|
11416
|
-
|
|
11417
|
-
.. warning::
|
|
11418
|
-
This is an experimental API that is subject to change or deletion.
|
|
11419
|
-
B -- Batch size
|
|
11420
|
-
S1 -- Sequence length of query
|
|
11421
|
-
S2 -- Sequence length of key and value
|
|
11422
|
-
N1 -- Num heads of query
|
|
11423
|
-
N2 -- Num heads of key and value, and N2 must be a factor of N1
|
|
11424
|
-
D -- head size
|
|
11425
|
-
H1 -- Hidden size of query, which equals to N1 * D
|
|
11426
|
-
H2 -- Hidden size of key and value, which equals to N2 * D
|
|
11427
|
-
Args:
|
|
11428
|
-
head_num (int): The head num of query.
|
|
11429
|
-
keep_prob (float): The keep probability of dropout. Default: 1.0.
|
|
11430
|
-
scale_value (float): The scale value. Default: 1.0.
|
|
11431
|
-
pre_tokens (int): Previous tokens. Default: 65536.
|
|
11432
|
-
next_tokens (int): Next tokens. Default: 65536.
|
|
11433
|
-
inner_precise (int): Specify the execution mode, where 0 indicates high precision mode and 1 indicates high
|
|
11434
|
-
performance mode. Only support 0 currently. Default: 0.
|
|
11435
|
-
input_layout (str, optional): Specifies the layout of `query`, the value must be one of ["BSH", "BNSD"].
|
|
11436
|
-
Default: "BSH".
|
|
11437
|
-
sparse_mode (int): Default 0.
|
|
11438
|
-
|
|
11439
|
-
Inputs:
|
|
11440
|
-
- **query** (Tensor[float16, float32, bfloat16]) - The query tensor.
|
|
11441
|
-
Input tensor of shape :math:`(B, S1, H1)` or `(B, N1, S1, D)`.
|
|
11442
|
-
- **key** (Tensor[float16, float32, bfloat16]) - The key tensor.
|
|
11443
|
-
Input tensor of shape :math:`(B, S2, H2)` or `(B, N2, S2, D)`.
|
|
11444
|
-
- **value** (Tensor[float16, float32, bfloat16]) - The value tensor.
|
|
11445
|
-
Input tensor of shape :math:`(B, S2, H2)` or `(B, N2, S2, D)`.
|
|
11446
|
-
- **real_shift** (Tensor[float16, float32, bfloat16], None) - The position embedding code.
|
|
11447
|
-
Input tensor of shape :math: `(B, N1, S1, S2)` or `(B, N1, 1, S2)`.
|
|
11448
|
-
- **drop_mask** (Tensor[uint8], None) - The dropout mask tensor.
|
|
11449
|
-
Input tensor of shape :math:`(B, N1, S1, S2 // 8) or None`.
|
|
11450
|
-
- **padding_mask** (None) - The padding mask of float16 or float32, not implemented yet.
|
|
11451
|
-
- **attn_mask** (Tensor[uint8], None) - The attention mask tensor.
|
|
11452
|
-
For each element, 0 indicates retention and 1 indicates discard.
|
|
11453
|
-
Input tensor of shape :math:`(B, N1, S1, S2)`, `(B, 1, S1, S2)` or `(S1, S2)`.
|
|
11454
|
-
- **prefix** (Tensor[int64], None) - Not implemented yet.
|
|
11455
|
-
Input tensor of shape :math:`(B,)`.
|
|
11456
|
-
|
|
11457
|
-
Outputs:
|
|
11458
|
-
- **softmax_max** (Tensor[float32]) - (B, N1, S1, 8)
|
|
11459
|
-
- **softmax_sum** (Tensor[float32]) - (B, N1, S1, 8)
|
|
11460
|
-
- **softmax_out** (Tensor[float32]) - Useless output, ignore it. Output tensor of shape : `()`
|
|
11461
|
-
- **attention_out** (Tensor[float16, float32, bfloat16]) - The output of attention, its shape, and data type
|
|
11462
|
-
are the same as the query.
|
|
11463
|
-
|
|
11464
|
-
Supported Platforms:
|
|
11465
|
-
``Ascend``
|
|
11466
|
-
"""
|
|
11467
|
-
|
|
11468
|
-
@prim_attr_register
|
|
11469
|
-
def __init__(self, head_num, keep_prob=1.0, scale_value=1.0, pre_tokens=65536, next_tokens=65536, inner_precise=0,
|
|
11470
|
-
input_layout="BSH", sparse_mode=0):
|
|
11471
|
-
"""Initialize FlashAttentionScore"""
|
|
11472
|
-
validator.check_value_type('head_num', head_num, [int], self.name)
|
|
11473
|
-
validator.check_value_type('keep_prob', keep_prob, [int, float], self.name)
|
|
11474
|
-
validator.check_float(keep_prob, 0.0, validator.GE, "keep_prob", self.name)
|
|
11475
|
-
validator.check_float(keep_prob, 1.0, validator.LE, "keep_prob", self.name)
|
|
11476
|
-
validator.check_value_type('scale_value', scale_value, [float], self.name)
|
|
11477
|
-
validator.check_value_type('pre_tokens', pre_tokens, [int], self.name)
|
|
11478
|
-
validator.check_value_type('next_tokens', next_tokens, [int], self.name)
|
|
11479
|
-
validator.check_value_type('inner_precise', inner_precise, [int], self.name)
|
|
11480
|
-
validator.check_value_type('sparse_mode', sparse_mode, [int], self.name)
|
|
11481
|
-
if inner_precise not in [0]:
|
|
11482
|
-
raise ValueError(f"Attribute 'inner_precise' must be 0, but got {inner_precise}")
|
|
11483
|
-
validator.check_value_type('input_layout', input_layout, [str], self.name)
|
|
11484
|
-
if input_layout not in ["BSH", "BNSD"]:
|
|
11485
|
-
raise ValueError(f"Attribute 'input_layout' must be either 'BSH' or 'BNSD', but got {input_layout}")
|
|
11486
|
-
self.init_prim_io_names(
|
|
11487
|
-
inputs=['query', 'key', 'value', 'real_shift', 'drop_mask', 'padding_mask', 'attn_mask', 'prefix'],
|
|
11488
|
-
outputs=['softmax_max', 'softmax_sum', 'softmax_out', 'attention_out'])
|
|
9596
|
+
The interface for fully inference.
|
|
11489
9597
|
|
|
9598
|
+
B -- Batch size
|
|
11490
9599
|
|
|
11491
|
-
|
|
11492
|
-
r"""
|
|
11493
|
-
The RmsNorm operator is a normalization operation, and its formula is:
|
|
9600
|
+
S -- Sequence length
|
|
11494
9601
|
|
|
11495
|
-
|
|
11496
|
-
y=\frac{x_i}{\sqrt{\frac{1}{n}}\sum_{i=1}^{n}{ x_i^2}+\varepsilon }\gamma_i
|
|
9602
|
+
H -- Hidden size
|
|
11497
9603
|
|
|
11498
9604
|
.. warning::
|
|
11499
9605
|
This is an experimental API that is subject to change or deletion.
|
|
9606
|
+
If there is no input parameter and no default value, None needs to be passed.
|
|
11500
9607
|
|
|
11501
9608
|
Args:
|
|
11502
|
-
|
|
11503
|
-
|
|
11504
|
-
|
|
11505
|
-
|
|
11506
|
-
|
|
11507
|
-
|
|
11508
|
-
|
|
11509
|
-
|
|
11510
|
-
|
|
11511
|
-
|
|
11512
|
-
|
|
11513
|
-
|
|
11514
|
-
|
|
11515
|
-
|
|
9609
|
+
- **num_heads** (int) - The number of heads.
|
|
9610
|
+
- **input_layout** (str) - the data layout of the input qkv, support `(BSH)` and `(BNSD)`. Default `BSH`.
|
|
9611
|
+
- **scale_value** (double) - The scale value indicating the scale coefficient, which is used as the scalar of
|
|
9612
|
+
Muls in the calculation. Default: 1.0.
|
|
9613
|
+
- **num_key_value_heads** (int) - head numbers of key/value which are used in GQA algorithm.
|
|
9614
|
+
The value o indicates if the key and value have the same head nums, use numHeads. Default: 0.
|
|
9615
|
+
- **block_size** (int) - Default: 0.
|
|
9616
|
+
- **inner_precise** (int) - Default: 1.
|
|
9617
|
+
|
|
9618
|
+
Inputs:
|
|
9619
|
+
- **query** (Tensor) - The query tensor with data type of float16 or bfloat16.
|
|
9620
|
+
Input tensor of shape :math:`(B, 1, H)` / :math:`(B, N, 1, D)`.
|
|
9621
|
+
- **key** (TensorList) - The key tensor with data type of float16 or bfloat16.
|
|
9622
|
+
Input tensor of shape :math:`(B, S, H)` / :math:`(B, N, S, D)`.
|
|
9623
|
+
- **value** (TensorList) - The value tensor with data type of float16 or bfloat16.
|
|
9624
|
+
Input tensor of shape :math:`(B, S, H)` / :math:`(B, N, S, D)`.
|
|
9625
|
+
- **attn_mask** (Tensor) - The attention mask tensor with data type of float16 or bool.
|
|
9626
|
+
Input tensor of shape :math:`(B, S)` / :math:`(B, 1, S)` / :math:`(B, 1, 1, S)`.
|
|
9627
|
+
- **actual_seq_lengths** (Tensor) - Describe actual sequence length of each input with data type of int.
|
|
9628
|
+
- **pse_shift** (Tensor) - The position encoding tensor with data type of float16 or float32.
|
|
9629
|
+
- **dequant_scale1** (Tensor) - Quantitative parametor, the tensor with data type of uint64.
|
|
9630
|
+
- **quant_scale1** (Tensor) - Quantitative parametor, the tensor with data type of float.
|
|
9631
|
+
- **dequant_scale2** (Tensor) - Quantitative parametor, the tensor with data type of uint64.
|
|
9632
|
+
- **quant_scale2** (Tensor) - Quantitative parametor, the tensor with data type of float.
|
|
9633
|
+
- **quant_offset2** (Tensor) - Quantitative parametor, the tensor with data type of float.
|
|
9634
|
+
- **antiquant_scale** (Tensor) - Quantitative parametor, the tensor with data type of float.
|
|
9635
|
+
- **antiquant_offset** (Tensor) - Quantitative parametor, the tensor with data type of float.
|
|
9636
|
+
- **block_table** (Tensor) - The tensor with data type of float.
|
|
9637
|
+
|
|
9638
|
+
Outputs:
|
|
9639
|
+
- **attention_out** (Tensor) - Input tensor of shape :math:`(B, 1, H)` / :math:`(B, N, 1, D)`.
|
|
11516
9640
|
|
|
11517
9641
|
Supported Platforms:
|
|
11518
9642
|
``Ascend``
|
|
11519
9643
|
"""
|
|
11520
9644
|
|
|
11521
9645
|
@prim_attr_register
|
|
11522
|
-
def __init__(self,
|
|
11523
|
-
|
|
11524
|
-
|
|
11525
|
-
|
|
11526
|
-
|
|
11527
|
-
|
|
11528
|
-
|
|
11529
|
-
|
|
11530
|
-
|
|
11531
|
-
|
|
11532
|
-
|
|
11533
|
-
|
|
11534
|
-
|
|
11535
|
-
"""Initialize PagedAttention"""
|
|
11536
|
-
validator.check_value_type('head_num', head_num, [int], self.name)
|
|
11537
|
-
validator.check_value_type('scale_value', scale_value, [float], self.name) # scale after qkbmm
|
|
11538
|
-
validator.check_value_type('kv_head_num', kv_head_num, [int], self.name) # for MQA
|
|
11539
|
-
self.init_prim_io_names(
|
|
11540
|
-
inputs=['query', 'key_cache', 'value_cache', 'block_tables', 'context_lens'],
|
|
11541
|
-
outputs=['attention_out'])
|
|
11542
|
-
|
|
11543
|
-
|
|
11544
|
-
class PagedAttentionMask(Primitive):
|
|
11545
|
-
r"""
|
|
11546
|
-
.. warning::
|
|
11547
|
-
This is an experimental API that is subject to change or deletion.
|
|
11548
|
-
"""
|
|
11549
|
-
@prim_attr_register
|
|
11550
|
-
def __init__(self, head_num, scale_value=1.0, kv_head_num=0):
|
|
11551
|
-
"""Initialize PagedAttentionMask"""
|
|
11552
|
-
validator.check_value_type('head_num', head_num, [int], self.name)
|
|
11553
|
-
validator.check_value_type('scale_value', scale_value, [float], self.name) # scale after qkbmm
|
|
11554
|
-
validator.check_value_type('kv_head_num', kv_head_num, [int], self.name) # for MQA
|
|
11555
|
-
self.init_prim_io_names(
|
|
11556
|
-
inputs=['query', 'key_cache', 'value_cache', 'block_tables', 'context_lens', 'alibi_mask'],
|
|
11557
|
-
outputs=['attention_out'])
|
|
9646
|
+
def __init__(self, num_heads, input_layout="BSH", scale_value=1.0, num_key_value_heads=0, block_size=0,
|
|
9647
|
+
inner_precise=1):
|
|
9648
|
+
"""Initialize IncreFlashAttention."""
|
|
9649
|
+
validator.check_value_type('num_heads', num_heads, [int], self.name)
|
|
9650
|
+
validator.check_value_type('input_layout', input_layout, [str], self.name)
|
|
9651
|
+
validator.check_value_type('scale_value', scale_value, [float], self.name)
|
|
9652
|
+
validator.check_value_type('num_key_value_heads', num_key_value_heads, [int], self.name)
|
|
9653
|
+
validator.check_value_type('block_size', block_size, [int], self.name)
|
|
9654
|
+
validator.check_value_type('inner_precise', inner_precise, [int], self.name)
|
|
9655
|
+
self.init_prim_io_names(inputs=["query", "key", "value", "attn_mask", "actual_seq_lengths", "pse_shift",
|
|
9656
|
+
"dequant_scale1", "quant_scale1", "dequant_scale2", "quant_scale2",
|
|
9657
|
+
"quant_offset2", "antiquant_scale", "antiquant_offset", "block_table"],
|
|
9658
|
+
outputs=["attention_out"])
|
|
11558
9659
|
|
|
11559
9660
|
|
|
11560
|
-
class
|
|
9661
|
+
class AllFinite(Primitive):
|
|
11561
9662
|
r"""
|
|
11562
|
-
|
|
11563
|
-
This is an experimental API that is subject to change or deletion.
|
|
9663
|
+
Check all gradients is finite.
|
|
11564
9664
|
"""
|
|
11565
|
-
__mindspore_signature__ = (
|
|
11566
|
-
sig.make_sig('key', dtype=sig.sig_dtype.T),
|
|
11567
|
-
sig.make_sig('value', dtype=sig.sig_dtype.T),
|
|
11568
|
-
sig.make_sig('key_cache', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T),
|
|
11569
|
-
sig.make_sig('value_cache', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T),
|
|
11570
|
-
sig.make_sig('slot_mapping', dtype=sig.sig_dtype.T1),
|
|
11571
|
-
)
|
|
11572
|
-
|
|
11573
9665
|
@prim_attr_register
|
|
11574
9666
|
def __init__(self):
|
|
11575
|
-
"""Initialize
|
|
11576
|
-
self.init_prim_io_names(
|
|
11577
|
-
|
|
11578
|
-
outputs=['key_out'])
|
|
11579
|
-
self.add_prim_attr('side_effect_mem', True)
|
|
9667
|
+
"""Initialize"""
|
|
9668
|
+
self.init_prim_io_names(inputs=['gradients'],
|
|
9669
|
+
outputs=["is_finite"])
|