mindspore 2.5.0__cp310-cp310-win_amd64.whl → 2.6.0__cp310-cp310-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of mindspore might be problematic. Click here for more details.
- mindspore/.commit_id +1 -1
- mindspore/Microsoft.VisualStudio.Telemetry.dll +0 -0
- mindspore/Newtonsoft.Json.dll +0 -0
- mindspore/__init__.py +6 -4
- mindspore/_c_dataengine.cp310-win_amd64.pyd +0 -0
- mindspore/_c_expression.cp310-win_amd64.pyd +0 -0
- mindspore/_c_mindrecord.cp310-win_amd64.pyd +0 -0
- mindspore/_check_jit_forbidden_api.py +3 -0
- mindspore/_checkparam.py +3 -33
- mindspore/_deprecated/__init__.py +17 -0
- mindspore/_deprecated/jit.py +198 -0
- mindspore/_extends/builtin_operations.py +1 -1
- mindspore/_extends/parse/__init__.py +6 -7
- mindspore/_extends/parse/compile_config.py +19 -0
- mindspore/_extends/parse/deprecated/deprecated_tensor_method.py +22 -3
- mindspore/_extends/parse/jit_fallback_modules/__init__.py +0 -0
- mindspore/_extends/parse/jit_fallback_modules/check_utils.py +123 -0
- mindspore/_extends/parse/jit_fallback_modules/third_party_modules.py +50 -0
- mindspore/_extends/parse/parser.py +25 -194
- mindspore/_extends/parse/resources.py +1 -5
- mindspore/_extends/parse/standard_method.py +109 -75
- mindspore/_extends/pijit/__init__.py +2 -2
- mindspore/_extends/pijit/pijit_func_white_list.py +16 -11
- mindspore/_extends/pijit/tensor_func_list.py +27 -0
- mindspore/_extends/utils.py +1 -1
- mindspore/amp.py +4 -4
- mindspore/atlprov.dll +0 -0
- mindspore/avcodec-59.dll +0 -0
- mindspore/avdevice-59.dll +0 -0
- mindspore/avfilter-8.dll +0 -0
- mindspore/avformat-59.dll +0 -0
- mindspore/avutil-57.dll +0 -0
- mindspore/boost/__init__.py +2 -2
- mindspore/boost/base.py +3 -7
- mindspore/boost/boost_cell_wrapper.py +2 -2
- mindspore/c1.dll +0 -0
- mindspore/c1xx.dll +0 -0
- mindspore/c2.dll +0 -0
- mindspore/common/__init__.py +4 -3
- mindspore/common/_grad_function.py +56 -0
- mindspore/common/_pijit_context.py +14 -5
- mindspore/common/_register_for_tensor.py +1 -1
- mindspore/common/_stub_tensor.py +5 -10
- mindspore/common/_tensor_cpp_method.py +1 -1
- mindspore/common/_tensor_docs.py +2014 -3386
- mindspore/common/api.py +386 -355
- mindspore/common/auto_dynamic_shape.py +41 -44
- mindspore/common/dtype.py +5 -2
- mindspore/common/dump.py +7 -5
- mindspore/common/file_system.py +3 -0
- mindspore/common/generator.py +3 -0
- mindspore/common/hook_handle.py +5 -3
- mindspore/common/initializer.py +10 -6
- mindspore/common/jit_begin_end.py +94 -0
- mindspore/common/jit_config.py +6 -1
- mindspore/common/jit_context.py +76 -0
- mindspore/common/jit_trace.py +378 -0
- mindspore/common/lazy_inline.py +2 -2
- mindspore/common/mutable.py +5 -4
- mindspore/common/parameter.py +106 -39
- mindspore/common/seed.py +2 -2
- mindspore/common/sparse_tensor.py +23 -17
- mindspore/common/tensor.py +332 -714
- mindspore/communication/__init__.py +7 -5
- mindspore/communication/_comm_helper.py +47 -2
- mindspore/communication/comm_func.py +70 -53
- mindspore/communication/management.py +83 -17
- mindspore/context.py +228 -571
- mindspore/dataset/__init__.py +44 -20
- mindspore/dataset/audio/__init__.py +2 -8
- mindspore/dataset/audio/transforms.py +3 -17
- mindspore/dataset/core/config.py +3 -3
- mindspore/dataset/engine/cache_client.py +1 -1
- mindspore/dataset/engine/datasets.py +102 -120
- mindspore/dataset/engine/datasets_audio.py +22 -22
- mindspore/dataset/engine/datasets_standard_format.py +43 -24
- mindspore/dataset/engine/datasets_text.py +78 -85
- mindspore/dataset/engine/datasets_user_defined.py +109 -77
- mindspore/dataset/engine/datasets_vision.py +111 -108
- mindspore/dataset/engine/iterators.py +5 -3
- mindspore/dataset/engine/obs/obs_mindrecord_dataset.py +1 -1
- mindspore/dataset/engine/samplers.py +279 -57
- mindspore/dataset/engine/serializer_deserializer.py +2 -1
- mindspore/dataset/engine/validators.py +10 -0
- mindspore/dataset/text/__init__.py +7 -6
- mindspore/dataset/text/transforms.py +6 -5
- mindspore/dataset/text/utils.py +3 -3
- mindspore/dataset/transforms/__init__.py +0 -9
- mindspore/dataset/transforms/transforms.py +3 -3
- mindspore/dataset/utils/browse_dataset.py +1 -1
- mindspore/dataset/vision/__init__.py +2 -9
- mindspore/dataset/vision/transforms.py +202 -158
- mindspore/dataset/vision/utils.py +7 -5
- mindspore/device_context/ascend/op_debug.py +60 -1
- mindspore/device_context/ascend/op_tuning.py +0 -4
- mindspore/device_manager.py +39 -3
- mindspore/dnnl.dll +0 -0
- mindspore/dpcmi.dll +0 -0
- mindspore/experimental/es/embedding_service.py +35 -27
- mindspore/experimental/llm_boost/ascend_native/llama_boost_ascend_native.py +0 -2
- mindspore/experimental/map_parameter.py +4 -4
- mindspore/experimental/optim/adadelta.py +22 -26
- mindspore/experimental/optim/adagrad.py +4 -4
- mindspore/experimental/optim/adam.py +4 -0
- mindspore/experimental/optim/adamax.py +4 -4
- mindspore/experimental/optim/adamw.py +4 -0
- mindspore/experimental/optim/asgd.py +1 -1
- mindspore/experimental/optim/lr_scheduler.py +40 -22
- mindspore/experimental/optim/radam.py +5 -5
- mindspore/experimental/optim/rprop.py +1 -1
- mindspore/experimental/optim/sgd.py +1 -1
- mindspore/hal/contiguous_tensors_handle.py +6 -10
- mindspore/hal/device.py +55 -81
- mindspore/hal/event.py +38 -55
- mindspore/hal/memory.py +115 -147
- mindspore/hal/stream.py +81 -125
- mindspore/include/dataset/constants.h +7 -4
- mindspore/include/dataset/execute.h +2 -2
- mindspore/jpeg62.dll +0 -0
- mindspore/log.py +40 -2
- mindspore/mindrecord/__init__.py +20 -7
- mindspore/mindspore_backend_common.dll +0 -0
- mindspore/mindspore_backend_manager.dll +0 -0
- mindspore/mindspore_common.dll +0 -0
- mindspore/mindspore_core.dll +0 -0
- mindspore/mindspore_dump.dll +0 -0
- mindspore/mindspore_frontend.dll +0 -0
- mindspore/mindspore_glog.dll +0 -0
- mindspore/mindspore_memory_pool.dll +0 -0
- mindspore/mindspore_ms_backend.dll +0 -0
- mindspore/mindspore_ops.dll +0 -0
- mindspore/{mindspore_backend.dll → mindspore_ops_host.dll} +0 -0
- mindspore/mindspore_ops_kernel_common.dll +0 -0
- mindspore/mindspore_profiler.dll +0 -0
- mindspore/mindspore_pyboost.dll +0 -0
- mindspore/mindspore_pynative.dll +0 -0
- mindspore/mindspore_res_manager.dll +0 -0
- mindspore/mindspore_runtime_pipeline.dll +0 -0
- mindspore/mint/__init__.py +133 -702
- mindspore/mint/distributed/__init__.py +5 -1
- mindspore/mint/distributed/distributed.py +198 -113
- mindspore/mint/linalg/__init__.py +2 -0
- mindspore/mint/nn/__init__.py +280 -18
- mindspore/mint/nn/functional.py +282 -64
- mindspore/mint/nn/layer/__init__.py +4 -0
- mindspore/mint/nn/layer/_functions.py +7 -3
- mindspore/mint/nn/layer/activation.py +120 -13
- mindspore/mint/nn/layer/conv.py +234 -28
- mindspore/mint/nn/layer/normalization.py +15 -16
- mindspore/mint/nn/layer/padding.py +1 -1
- mindspore/mint/nn/layer/pooling.py +66 -1
- mindspore/mint/optim/__init__.py +2 -1
- mindspore/mint/optim/sgd.py +171 -0
- mindspore/msobj140.dll +0 -0
- mindspore/mspdb140.dll +0 -0
- mindspore/mspdbcore.dll +0 -0
- mindspore/mspdbst.dll +0 -0
- mindspore/mspft140.dll +0 -0
- mindspore/msvcdis140.dll +0 -0
- mindspore/msvcp140_1.dll +0 -0
- mindspore/msvcp140_2.dll +0 -0
- mindspore/msvcp140_atomic_wait.dll +0 -0
- mindspore/msvcp140_codecvt_ids.dll +0 -0
- mindspore/nn/__init__.py +4 -1
- mindspore/nn/cell.py +1253 -179
- mindspore/nn/layer/activation.py +23 -21
- mindspore/nn/layer/basic.py +22 -16
- mindspore/nn/layer/container.py +1 -1
- mindspore/nn/layer/conv.py +53 -42
- mindspore/nn/layer/embedding.py +9 -8
- mindspore/nn/layer/normalization.py +48 -42
- mindspore/nn/layer/pooling.py +75 -31
- mindspore/nn/layer/transformer.py +11 -10
- mindspore/nn/learning_rate_schedule.py +4 -2
- mindspore/nn/loss/loss.py +27 -19
- mindspore/nn/optim/ada_grad.py +6 -5
- mindspore/nn/optim/adadelta.py +9 -7
- mindspore/nn/optim/adafactor.py +1 -1
- mindspore/nn/optim/adam.py +18 -14
- mindspore/nn/optim/adamax.py +8 -7
- mindspore/nn/optim/adasum.py +5 -5
- mindspore/nn/optim/asgd.py +3 -1
- mindspore/nn/optim/ftrl.py +11 -9
- mindspore/nn/optim/lamb.py +1 -1
- mindspore/nn/optim/lazyadam.py +12 -10
- mindspore/nn/optim/momentum.py +7 -6
- mindspore/nn/optim/optimizer.py +2 -2
- mindspore/nn/optim/proximal_ada_grad.py +12 -10
- mindspore/nn/optim/rmsprop.py +13 -12
- mindspore/nn/optim/rprop.py +9 -7
- mindspore/nn/optim/sgd.py +9 -6
- mindspore/nn/optim/tft_wrapper.py +5 -2
- mindspore/nn/probability/bijector/bijector.py +17 -11
- mindspore/nn/probability/bijector/gumbel_cdf.py +5 -5
- mindspore/nn/probability/bijector/invert.py +2 -2
- mindspore/nn/probability/bijector/scalar_affine.py +3 -3
- mindspore/nn/probability/bijector/softplus.py +3 -2
- mindspore/nn/probability/distribution/beta.py +3 -3
- mindspore/nn/probability/distribution/categorical.py +1 -1
- mindspore/nn/probability/distribution/cauchy.py +4 -2
- mindspore/nn/probability/distribution/exponential.py +6 -7
- mindspore/nn/probability/distribution/gamma.py +2 -2
- mindspore/nn/probability/distribution/gumbel.py +2 -2
- mindspore/nn/probability/distribution/half_normal.py +5 -3
- mindspore/nn/probability/distribution/logistic.py +5 -3
- mindspore/nn/probability/distribution/poisson.py +1 -1
- mindspore/nn/probability/distribution/uniform.py +5 -3
- mindspore/nn/reinforcement/_tensors_queue.py +1 -1
- mindspore/nn/reinforcement/tensor_array.py +1 -1
- mindspore/nn/wrap/__init__.py +6 -6
- mindspore/nn/wrap/cell_wrapper.py +178 -117
- mindspore/nn/wrap/grad_reducer.py +45 -36
- mindspore/nn/wrap/loss_scale.py +3 -3
- mindspore/numpy/array_creations.py +3 -3
- mindspore/numpy/array_ops.py +1 -1
- mindspore/numpy/utils.py +1 -2
- mindspore/numpy/utils_const.py +1 -2
- mindspore/opencv_core452.dll +0 -0
- mindspore/opencv_imgcodecs452.dll +0 -0
- mindspore/opencv_imgproc452.dll +0 -0
- mindspore/ops/__init__.py +3 -2
- mindspore/ops/_grad_experimental/grad_comm_ops.py +18 -3
- mindspore/ops/_grad_experimental/grad_debug_ops.py +8 -1
- mindspore/ops/_grad_experimental/taylor_rule.py +29 -0
- mindspore/ops/_register_for_op.py +0 -11
- mindspore/{ops_generate → ops/_utils}/arg_dtype_cast.py +123 -4
- mindspore/{ops_generate → ops/_utils}/arg_handler.py +3 -4
- mindspore/ops/_vmap/vmap_array_ops.py +32 -6
- mindspore/ops/_vmap/vmap_grad_nn_ops.py +2 -1
- mindspore/ops/_vmap/vmap_math_ops.py +4 -7
- mindspore/ops/_vmap/vmap_nn_ops.py +9 -8
- mindspore/ops/auto_generate/__init__.py +4 -3
- mindspore/ops/auto_generate/cpp_create_prim_instance_helper.py +127 -52
- mindspore/ops/auto_generate/gen_extend_func.py +286 -208
- mindspore/ops/auto_generate/gen_ops_def.py +2783 -2335
- mindspore/ops/auto_generate/gen_ops_prim.py +8992 -2686
- mindspore/ops/auto_generate/pyboost_inner_prim.py +106 -76
- mindspore/ops/composite/__init__.py +2 -1
- mindspore/ops/composite/base.py +19 -24
- mindspore/ops/composite/math_ops.py +6 -16
- mindspore/ops/composite/multitype_ops/__init__.py +5 -2
- mindspore/ops/composite/multitype_ops/_compile_utils.py +4 -5
- mindspore/ops/composite/multitype_ops/_constexpr_utils.py +1 -2
- mindspore/ops/composite/multitype_ops/add_impl.py +2 -1
- mindspore/ops/composite/multitype_ops/bitwise_and_impl.py +2 -1
- mindspore/ops/composite/multitype_ops/bitwise_or_impl.py +2 -1
- mindspore/ops/composite/multitype_ops/bitwise_xor_impl.py +2 -1
- mindspore/ops/composite/multitype_ops/div_impl.py +6 -4
- mindspore/ops/composite/multitype_ops/equal_impl.py +4 -3
- mindspore/ops/composite/multitype_ops/floordiv_impl.py +2 -1
- mindspore/ops/composite/multitype_ops/getitem_impl.py +3 -2
- mindspore/ops/composite/multitype_ops/greater_equal_impl.py +4 -3
- mindspore/ops/composite/multitype_ops/greater_impl.py +4 -3
- mindspore/ops/composite/multitype_ops/in_impl.py +2 -1
- mindspore/ops/composite/multitype_ops/invert_impl.py +50 -0
- mindspore/ops/composite/multitype_ops/left_shift_impl.py +2 -1
- mindspore/ops/composite/multitype_ops/less_equal_impl.py +4 -3
- mindspore/ops/composite/multitype_ops/less_impl.py +4 -3
- mindspore/ops/composite/multitype_ops/logic_not_impl.py +3 -2
- mindspore/ops/composite/multitype_ops/logical_and_impl.py +2 -1
- mindspore/ops/composite/multitype_ops/logical_or_impl.py +2 -1
- mindspore/ops/composite/multitype_ops/mod_impl.py +2 -1
- mindspore/ops/composite/multitype_ops/mul_impl.py +3 -2
- mindspore/ops/composite/multitype_ops/negative_impl.py +2 -1
- mindspore/ops/composite/multitype_ops/not_equal_impl.py +2 -1
- mindspore/ops/composite/multitype_ops/not_in_impl.py +2 -1
- mindspore/ops/composite/multitype_ops/ones_like_impl.py +18 -0
- mindspore/ops/composite/multitype_ops/pow_impl.py +2 -1
- mindspore/ops/composite/multitype_ops/right_shift_impl.py +2 -1
- mindspore/ops/composite/multitype_ops/setitem_impl.py +2 -1
- mindspore/ops/composite/multitype_ops/sub_impl.py +2 -1
- mindspore/ops/function/__init__.py +28 -2
- mindspore/ops/function/_add_attr_func.py +58 -0
- mindspore/ops/function/array_func.py +1631 -2347
- mindspore/ops/function/clip_func.py +38 -45
- mindspore/ops/function/debug_func.py +36 -44
- mindspore/ops/function/grad/__init__.py +1 -0
- mindspore/ops/function/grad/grad_func.py +104 -71
- mindspore/ops/function/image_func.py +1 -1
- mindspore/ops/function/linalg_func.py +46 -78
- mindspore/ops/function/math_func.py +3024 -3855
- mindspore/ops/function/nn_func.py +678 -274
- mindspore/ops/function/other_func.py +159 -1
- mindspore/ops/function/parameter_func.py +17 -30
- mindspore/ops/function/random_func.py +216 -361
- mindspore/ops/function/reshard_func.py +4 -70
- mindspore/ops/function/sparse_func.py +3 -3
- mindspore/ops/function/sparse_unary_func.py +5 -5
- mindspore/ops/function/spectral_func.py +25 -58
- mindspore/ops/function/vmap_func.py +26 -18
- mindspore/ops/functional.py +8 -5
- mindspore/ops/functional_overload.py +655 -4
- mindspore/ops/op_info_register.py +32 -244
- mindspore/ops/operations/__init__.py +21 -14
- mindspore/ops/operations/_custom_ops_utils.py +235 -0
- mindspore/ops/operations/_grad_ops.py +1 -10
- mindspore/ops/operations/_inner_ops.py +5 -76
- mindspore/ops/operations/_ms_kernel.py +4 -10
- mindspore/ops/operations/_rl_inner_ops.py +1 -1
- mindspore/ops/operations/_scalar_ops.py +3 -2
- mindspore/ops/operations/_sequence_ops.py +1 -1
- mindspore/ops/operations/_tensor_array.py +1 -1
- mindspore/ops/operations/array_ops.py +39 -24
- mindspore/ops/operations/comm_ops.py +150 -107
- mindspore/ops/operations/custom_ops.py +287 -32
- mindspore/ops/operations/debug_ops.py +119 -16
- mindspore/ops/operations/inner_ops.py +1 -1
- mindspore/ops/operations/linalg_ops.py +1 -58
- mindspore/ops/operations/manually_defined/_inner.py +1 -1
- mindspore/ops/operations/manually_defined/ops_def.py +746 -79
- mindspore/ops/operations/math_ops.py +21 -18
- mindspore/ops/operations/nn_ops.py +67 -224
- mindspore/ops/operations/other_ops.py +62 -9
- mindspore/ops/operations/random_ops.py +13 -7
- mindspore/ops/operations/reshard_ops.py +1 -1
- mindspore/ops/operations/sparse_ops.py +2 -2
- mindspore/ops/primitive.py +43 -32
- mindspore/ops/tensor_method.py +243 -17
- mindspore/ops_generate/__init__.py +0 -5
- mindspore/ops_generate/aclnn/__init__.py +0 -0
- mindspore/ops_generate/{aclnn_kernel_register_auto_cc_generator.py → aclnn/aclnn_kernel_register_auto_cc_generator.py} +43 -18
- mindspore/ops_generate/{gen_aclnn_implement.py → aclnn/gen_aclnn_implement.py} +49 -51
- mindspore/ops_generate/api/__init__.py +0 -0
- mindspore/ops_generate/{add_tensor_docs_generator.py → api/add_tensor_docs_generator.py} +9 -7
- mindspore/ops_generate/{cpp_create_prim_instance_helper_generator.py → api/cpp_create_prim_instance_helper_generator.py} +6 -9
- mindspore/ops_generate/{functional_map_cpp_generator.py → api/functional_map_cpp_generator.py} +25 -12
- mindspore/ops_generate/{functional_overload_py_generator.py → api/functional_overload_py_generator.py} +8 -6
- mindspore/ops_generate/{functions_cc_generator.py → api/functions_cc_generator.py} +14 -10
- mindspore/ops_generate/api/gen_api.py +103 -0
- mindspore/ops_generate/{op_api_proto.py → api/op_api_proto.py} +98 -69
- mindspore/ops_generate/{tensor_func_reg_cpp_generator.py → api/tensor_func_reg_cpp_generator.py} +82 -43
- mindspore/ops_generate/common/__init__.py +0 -0
- mindspore/ops_generate/common/gen_constants.py +91 -0
- mindspore/ops_generate/{gen_utils.py → common/gen_utils.py} +72 -19
- mindspore/ops_generate/{op_proto.py → common/op_proto.py} +64 -1
- mindspore/ops_generate/{template.py → common/template.py} +96 -84
- mindspore/ops_generate/gen_ops.py +23 -325
- mindspore/ops_generate/op_def/__init__.py +0 -0
- mindspore/ops_generate/op_def/gen_op_def.py +90 -0
- mindspore/ops_generate/{lite_ops_cpp_generator.py → op_def/lite_ops_cpp_generator.py} +47 -11
- mindspore/ops_generate/{ops_def_cc_generator.py → op_def/ops_def_cc_generator.py} +18 -10
- mindspore/ops_generate/{ops_def_h_generator.py → op_def/ops_def_h_generator.py} +5 -5
- mindspore/ops_generate/{ops_name_h_generator.py → op_def/ops_name_h_generator.py} +30 -15
- mindspore/ops_generate/op_def/ops_primitive_h_generator.py +125 -0
- mindspore/ops_generate/op_def_py/__init__.py +0 -0
- mindspore/ops_generate/op_def_py/gen_op_def_py.py +47 -0
- mindspore/ops_generate/{op_def_py_generator.py → op_def_py/op_def_py_generator.py} +6 -5
- mindspore/ops_generate/{op_prim_py_generator.py → op_def_py/op_prim_py_generator.py} +24 -15
- mindspore/ops_generate/pyboost/__init__.py +0 -0
- mindspore/ops_generate/{auto_grad_impl_cc_generator.py → pyboost/auto_grad_impl_cc_generator.py} +11 -7
- mindspore/ops_generate/{auto_grad_reg_cc_generator.py → pyboost/auto_grad_reg_cc_generator.py} +7 -7
- mindspore/ops_generate/{gen_pyboost_func.py → pyboost/gen_pyboost_func.py} +40 -16
- mindspore/ops_generate/{op_template_parser.py → pyboost/op_template_parser.py} +105 -24
- mindspore/ops_generate/{pyboost_functions_cpp_generator.py → pyboost/pyboost_functions_cpp_generator.py} +55 -18
- mindspore/ops_generate/{pyboost_functions_h_generator.py → pyboost/pyboost_functions_h_generator.py} +42 -10
- mindspore/ops_generate/{pyboost_functions_py_generator.py → pyboost/pyboost_functions_py_generator.py} +6 -6
- mindspore/ops_generate/{pyboost_grad_function_cpp_generator.py → pyboost/pyboost_grad_function_cpp_generator.py} +11 -10
- mindspore/ops_generate/{pyboost_inner_prim_generator.py → pyboost/pyboost_inner_prim_generator.py} +8 -7
- mindspore/ops_generate/{pyboost_native_grad_functions_generator.py → pyboost/pyboost_native_grad_functions_generator.py} +14 -10
- mindspore/ops_generate/{pyboost_op_cpp_code_generator.py → pyboost/pyboost_op_cpp_code_generator.py} +140 -53
- mindspore/ops_generate/{pyboost_overload_functions_cpp_generator.py → pyboost/pyboost_overload_functions_cpp_generator.py} +28 -15
- mindspore/ops_generate/{pyboost_utils.py → pyboost/pyboost_utils.py} +88 -4
- mindspore/ops_generate/resources/__init__.py +0 -0
- mindspore/ops_generate/resources/resource_list.py +30 -0
- mindspore/ops_generate/resources/resource_loader.py +36 -0
- mindspore/ops_generate/resources/resource_manager.py +64 -0
- mindspore/ops_generate/resources/yaml_loader.py +88 -0
- mindspore/ops_generate/tensor_py_cc_generator.py +122 -0
- mindspore/parallel/__init__.py +6 -2
- mindspore/parallel/_auto_parallel_context.py +140 -12
- mindspore/parallel/_cell_wrapper.py +132 -15
- mindspore/parallel/_parallel_serialization.py +95 -4
- mindspore/parallel/_ps_context.py +1 -1
- mindspore/parallel/_recovery_context.py +7 -2
- mindspore/parallel/_tensor.py +142 -18
- mindspore/parallel/_utils.py +198 -25
- mindspore/parallel/algo_parameter_config.py +3 -3
- mindspore/parallel/auto_parallel.py +732 -0
- mindspore/parallel/checkpoint_convert.py +159 -0
- mindspore/parallel/checkpoint_transform.py +658 -37
- mindspore/parallel/cluster/process_entity/_api.py +151 -19
- mindspore/parallel/cluster/run.py +1 -1
- mindspore/parallel/function/__init__.py +24 -0
- mindspore/parallel/function/reshard_func.py +258 -0
- mindspore/parallel/nn/__init__.py +25 -0
- mindspore/parallel/nn/parallel_cell_wrapper.py +263 -0
- mindspore/parallel/nn/parallel_grad_reducer.py +169 -0
- mindspore/parallel/parameter_broadcast.py +24 -13
- mindspore/parallel/shard.py +137 -62
- mindspore/parallel/transform_safetensors.py +288 -95
- mindspore/pgodb140.dll +0 -0
- mindspore/pgort140.dll +0 -0
- mindspore/profiler/__init__.py +9 -5
- mindspore/profiler/analysis/parser/ascend_cann_parser.py +6 -2
- mindspore/profiler/analysis/parser/ms_framework_parser.py +4 -4
- mindspore/profiler/analysis/parser/timeline_assembly_factory/ascend_timeline_assembler.py +7 -4
- mindspore/profiler/analysis/parser/timeline_assembly_factory/trace_view_container.py +25 -0
- mindspore/profiler/analysis/parser/timeline_creator/fwk_timeline_creator.py +3 -3
- mindspore/profiler/analysis/parser/timeline_event/fwk_event.py +241 -86
- mindspore/profiler/analysis/viewer/ascend_communication_viewer.py +41 -2
- mindspore/profiler/analysis/viewer/ascend_kernel_details_viewer.py +33 -35
- mindspore/profiler/analysis/viewer/ascend_memory_viewer.py +7 -0
- mindspore/profiler/analysis/viewer/ascend_op_memory_viewer.py +8 -3
- mindspore/profiler/analysis/viewer/ascend_step_trace_time_viewer.py +141 -30
- mindspore/profiler/analysis/viewer/ms_dataset_viewer.py +5 -6
- mindspore/profiler/common/ascend_msprof_exporter.py +5 -4
- mindspore/profiler/common/constant.py +12 -0
- mindspore/profiler/common/msprof_cmd_tool.py +42 -23
- mindspore/profiler/common/path_manager.py +24 -0
- mindspore/profiler/common/profiler_context.py +26 -2
- mindspore/profiler/common/profiler_meta_data.py +74 -0
- mindspore/profiler/common/profiler_parameters.py +59 -18
- mindspore/profiler/common/profiler_path_manager.py +66 -7
- mindspore/profiler/dynamic_profiler.py +112 -79
- mindspore/profiler/envprofiler.py +26 -1
- mindspore/profiler/experimental_config.py +197 -0
- mindspore/profiler/mstx.py +57 -14
- mindspore/profiler/platform/npu_profiler.py +33 -7
- mindspore/profiler/profiler.py +541 -45
- mindspore/profiler/profiler_action_controller.py +1 -1
- mindspore/profiler/profiler_interface.py +4 -0
- mindspore/profiler/schedule.py +57 -22
- mindspore/rewrite/api/node.py +15 -13
- mindspore/rewrite/api/symbol_tree.py +1 -1
- mindspore/run_check/_check_version.py +25 -14
- mindspore/run_check/run_check.py +1 -1
- mindspore/runtime/__init__.py +2 -2
- mindspore/runtime/executor.py +40 -11
- mindspore/runtime/memory.py +37 -13
- mindspore/safeguard/rewrite_obfuscation.py +12 -9
- mindspore/swresample-4.dll +0 -0
- mindspore/swscale-6.dll +0 -0
- mindspore/tbbmalloc.dll +0 -0
- mindspore/tinyxml2.dll +0 -0
- mindspore/train/__init__.py +8 -8
- mindspore/train/_utils.py +43 -9
- mindspore/train/amp.py +1 -1
- mindspore/train/callback/__init__.py +2 -2
- mindspore/train/callback/_callback.py +2 -16
- mindspore/train/callback/_checkpoint.py +24 -40
- mindspore/train/callback/_cluster_monitor.py +14 -18
- mindspore/train/callback/_flops_collector.py +2 -3
- mindspore/train/callback/_history.py +7 -4
- mindspore/train/callback/_lambda_callback.py +2 -2
- mindspore/train/callback/_landscape.py +0 -3
- mindspore/train/callback/_loss_monitor.py +2 -1
- mindspore/train/callback/_on_request_exit.py +6 -5
- mindspore/train/callback/_reduce_lr_on_plateau.py +11 -6
- mindspore/train/callback/_summary_collector.py +8 -13
- mindspore/train/callback/_time_monitor.py +2 -1
- mindspore/train/callback/{_tft_register.py → _train_fault_tolerance.py} +204 -105
- mindspore/train/data_sink.py +25 -2
- mindspore/train/dataset_helper.py +4 -5
- mindspore/train/loss_scale_manager.py +8 -7
- mindspore/train/metrics/accuracy.py +3 -3
- mindspore/train/metrics/confusion_matrix.py +9 -9
- mindspore/train/metrics/error.py +3 -3
- mindspore/train/metrics/hausdorff_distance.py +4 -4
- mindspore/train/metrics/mean_surface_distance.py +3 -3
- mindspore/train/metrics/metric.py +0 -12
- mindspore/train/metrics/occlusion_sensitivity.py +4 -2
- mindspore/train/metrics/precision.py +8 -6
- mindspore/train/metrics/recall.py +9 -9
- mindspore/train/metrics/root_mean_square_surface_distance.py +2 -2
- mindspore/train/mind_ir_pb2.py +19 -12
- mindspore/train/model.py +262 -127
- mindspore/train/serialization.py +246 -988
- mindspore/train/summary/_summary_adapter.py +2 -2
- mindspore/train/summary/summary_record.py +1 -1
- mindspore/turbojpeg.dll +0 -0
- mindspore/utils/__init__.py +3 -2
- mindspore/utils/dryrun.py +4 -2
- mindspore/utils/hooks.py +81 -0
- mindspore/utils/runtime_execution_order_check.py +2 -0
- mindspore/utils/utils.py +138 -4
- mindspore/vcmeta.dll +0 -0
- mindspore/vcruntime140.dll +0 -0
- mindspore/vcruntime140_1.dll +0 -0
- mindspore/version.py +1 -1
- {mindspore-2.5.0.dist-info → mindspore-2.6.0.dist-info}/METADATA +2 -1
- {mindspore-2.5.0.dist-info → mindspore-2.6.0.dist-info}/RECORD +485 -440
- mindspore/_install_custom.py +0 -43
- mindspore/common/_register_for_adapter.py +0 -74
- mindspore/ops/auto_generate/gen_arg_dtype_cast.py +0 -252
- mindspore/ops/auto_generate/gen_arg_handler.py +0 -136
- mindspore/ops/operations/_opaque_predicate_registry.py +0 -41
- mindspore/ops_generate/gen_constants.py +0 -190
- mindspore/ops_generate/gen_ops_inner_prim.py +0 -131
- mindspore/ops_generate/ops_primitive_h_generator.py +0 -81
- /mindspore/ops_generate/{base_generator.py → common/base_generator.py} +0 -0
- {mindspore-2.5.0.dist-info → mindspore-2.6.0.dist-info}/WHEEL +0 -0
- {mindspore-2.5.0.dist-info → mindspore-2.6.0.dist-info}/entry_points.txt +0 -0
- {mindspore-2.5.0.dist-info → mindspore-2.6.0.dist-info}/top_level.txt +0 -0
|
@@ -29,7 +29,7 @@ import mindspore.common.dtype as mstype
|
|
|
29
29
|
from mindspore.ops.function.math_func import logsumexp, div
|
|
30
30
|
from mindspore.ops.function.random_func import _get_seed, _set_prim_op_user_data
|
|
31
31
|
from mindspore.common.tensor import Tensor
|
|
32
|
-
from mindspore._c_expression import
|
|
32
|
+
from mindspore._c_expression import TensorPy as Tensor_
|
|
33
33
|
from mindspore.ops._primitive_cache import _get_cache_prim
|
|
34
34
|
from mindspore import _checkparam as validator
|
|
35
35
|
from mindspore.ops.composite.multitype_ops._constexpr_utils import raise_value_error
|
|
@@ -41,10 +41,11 @@ from mindspore.ops.operations.nn_ops import TripletMarginLoss
|
|
|
41
41
|
from mindspore.ops.operations._sequence_ops import TupleToTensor, TensorToTuple, ListToTensor
|
|
42
42
|
from mindspore.common.api import _function_forbid_reuse
|
|
43
43
|
from mindspore.ops.auto_generate import log_softmax, dense, prelu, celu, fast_gelu, silu, elu, sigmoid, relu6, \
|
|
44
|
-
softmax_impl, swiglu, logsigmoid_op
|
|
44
|
+
softmax_impl, swiglu, logsigmoid_op, kl_div_op, divs_op
|
|
45
45
|
from mindspore.ops.auto_generate import relu_op, inplace_relu_op
|
|
46
46
|
from mindspore.ops.auto_generate import group_norm_op, rms_norm, add_rms_norm, layer_norm_ext_op, batch_norm_ext_op,\
|
|
47
47
|
mse_loss_ext
|
|
48
|
+
# 1
|
|
48
49
|
from mindspore.ops.auto_generate import (reflection_pad_1d_op, reflection_pad_2d_op, add_layernorm_v2_op,
|
|
49
50
|
reflection_pad_3d_op, # pylint: disable=W0611
|
|
50
51
|
replication_pad_1d_op, replication_pad_2d_op, replication_pad_3d_op,
|
|
@@ -53,16 +54,58 @@ from mindspore.ops.auto_generate import (reflection_pad_1d_op, reflection_pad_2d
|
|
|
53
54
|
upsample_linear1d_op, upsample_bilinear2d_op, upsample_bicubic2d_op,
|
|
54
55
|
upsample_trilinear3d_impl, fill_scalar_op, floor_op, nllloss_2d_op,
|
|
55
56
|
masked_fill_op, masked_select, ones, flatten_ext, conv_transpose2d)
|
|
57
|
+
# 2
|
|
58
|
+
|
|
59
|
+
# 3
|
|
60
|
+
|
|
61
|
+
# 4
|
|
62
|
+
|
|
63
|
+
# 5
|
|
64
|
+
|
|
65
|
+
# 6
|
|
66
|
+
|
|
67
|
+
# 7
|
|
68
|
+
|
|
69
|
+
# 8
|
|
70
|
+
|
|
71
|
+
# 9
|
|
72
|
+
|
|
73
|
+
# 10
|
|
74
|
+
|
|
75
|
+
# 11
|
|
76
|
+
|
|
77
|
+
# 12
|
|
78
|
+
|
|
79
|
+
# 13
|
|
80
|
+
|
|
81
|
+
# 14
|
|
82
|
+
|
|
83
|
+
# 15
|
|
84
|
+
from mindspore.ops.auto_generate import avg_pool3d_ext_op
|
|
85
|
+
# 16
|
|
86
|
+
|
|
87
|
+
# 17
|
|
88
|
+
|
|
89
|
+
# 18
|
|
90
|
+
|
|
91
|
+
# 19
|
|
92
|
+
|
|
93
|
+
# 20
|
|
94
|
+
|
|
56
95
|
from mindspore.ops.auto_generate.gen_ops_prim import embedding_op, MaxPoolWithIndices, \
|
|
57
96
|
PromptFlashAttention, MaxPoolWithMask
|
|
58
|
-
from mindspore.ops.auto_generate.gen_ops_prim import conv3d_ext_op, conv3d_padding_op, conv2d_ext_op,
|
|
97
|
+
from mindspore.ops.auto_generate.gen_ops_prim import conv3d_ext_op, conv3d_padding_op, conv2d_ext_op, \
|
|
98
|
+
conv2d_padding_op, conv1d_ext_op, conv1d_padding_op, speed_fusion_attention_op
|
|
59
99
|
from mindspore.common.generator import default_generator
|
|
60
100
|
from mindspore.ops.auto_generate import hardshrink, hardsigmoid, hardswish
|
|
61
101
|
from mindspore.ops.auto_generate import softshrink
|
|
102
|
+
from mindspore.ops.auto_generate import soft_margin_loss
|
|
103
|
+
from mindspore.ops.auto_generate import moe_token_permute, moe_token_unpermute
|
|
62
104
|
from mindspore.ops.auto_generate import adaptive_avg_pool2d_ext_op
|
|
63
105
|
from mindspore.ops.auto_generate.pyboost_inner_prim import nllloss_impl
|
|
106
|
+
from mindspore.ops.auto_generate.pyboost_inner_prim import adaptive_max_pool2d_impl
|
|
64
107
|
from mindspore.ops.function.array_func import gather_ext
|
|
65
|
-
from mindspore.ops.operations.manually_defined import flash_attention_score
|
|
108
|
+
from mindspore.ops.operations.manually_defined import flash_attention_score, fused_infer_attention_score
|
|
66
109
|
|
|
67
110
|
abs_ = P.Abs()
|
|
68
111
|
add_ = P.Add()
|
|
@@ -160,11 +203,11 @@ def adaptive_avg_pool2d(input, output_size):
|
|
|
160
203
|
.. math::
|
|
161
204
|
|
|
162
205
|
out\_shape = \begin{cases}
|
|
163
|
-
input\_shape[-2] + output\_size[1], & \text{if } output\_size text{ is (None, w);}\\
|
|
164
|
-
output\_size[0] + input\_shape[-1], & \text{if } output\_size text{ is (h, None);}\\
|
|
165
|
-
input\_shape[-2:], & \text{if } output\_size text{ is (None, None);}\\
|
|
166
|
-
(h, h), & \text{if } output\_size text{ is h;}\\
|
|
167
|
-
(h, w), & \text{if } output\_size text{ is (h, w)}
|
|
206
|
+
input\_shape[-2] + output\_size[1], & \text{if } output\_size \text{ is (None, w);}\\
|
|
207
|
+
output\_size[0] + input\_shape[-1], & \text{if } output\_size \text{ is (h, None);}\\
|
|
208
|
+
input\_shape[-2:], & \text{if } output\_size \text{ is (None, None);}\\
|
|
209
|
+
(h, h), & \text{if } output\_size \text{ is h;}\\
|
|
210
|
+
(h, w), & \text{if } output\_size \text{ is (h, w)}
|
|
168
211
|
\end{cases}
|
|
169
212
|
|
|
170
213
|
Raises:
|
|
@@ -406,13 +449,15 @@ def avg_pool1d(input_x, kernel_size=1, stride=1, padding=0, ceil_mode=False, cou
|
|
|
406
449
|
|
|
407
450
|
Args:
|
|
408
451
|
input_x (Tensor): Tensor of shape :math:`(N, C_{in}, L_{in})`.
|
|
409
|
-
kernel_size (int): The size of kernel window used to take the average value. Default: ``1`` .
|
|
410
|
-
stride (Union(int, tuple[int])): The distance of kernel moving. `stride` can either be an int
|
|
452
|
+
kernel_size (int, optional): The size of kernel window used to take the average value. Default: ``1`` .
|
|
453
|
+
stride (Union(int, tuple[int]), optional): The distance of kernel moving. `stride` can either be an int
|
|
411
454
|
number or a tuple of one int number. Default: ``1`` .
|
|
412
|
-
padding (Union(int, tuple[int])): The pad value to be filled. `padding` can either be an integer
|
|
455
|
+
padding (Union(int, tuple[int]), optional): The pad value to be filled. `padding` can either be an integer
|
|
413
456
|
or a tuple of one integer. Default: ``0`` .
|
|
414
|
-
ceil_mode (bool): If True, apply ceil instead of floor to compute the output shape.
|
|
415
|
-
|
|
457
|
+
ceil_mode (bool, optional): If True, apply ceil instead of floor to compute the output shape.
|
|
458
|
+
Default: ``False``.
|
|
459
|
+
count_include_pad (bool, optional): If True, include the zero-padding in the averaging calculation.
|
|
460
|
+
Default: ``True`` .
|
|
416
461
|
|
|
417
462
|
Returns:
|
|
418
463
|
Tensor of shape :math:`(N, C_{out}, L_{out})`.
|
|
@@ -786,6 +831,77 @@ def avg_pool3d(input_x, kernel_size=1, stride=1, padding=0, ceil_mode=False, cou
|
|
|
786
831
|
return avg_pool_op(input_x)
|
|
787
832
|
|
|
788
833
|
|
|
834
|
+
def avg_pool3d_ext(input, kernel_size, stride=None, padding=0, ceil_mode=False, count_include_pad=True,
|
|
835
|
+
divisor_override=None):
|
|
836
|
+
r"""
|
|
837
|
+
Applies a 3D average pooling over an input Tensor which can be regarded as a composition of
|
|
838
|
+
3D input planes. Typically the input is of shape :math:`(N, C, D_{in}, H_{in}, W_{in})` ,
|
|
839
|
+
outputs regional average in the :math:`(D_{in}, H_{in}, W_{in})` -dimension.
|
|
840
|
+
Given kernel size :math:`(kD, kH, kW)` and `stride` , the operation is as follows.
|
|
841
|
+
|
|
842
|
+
.. math::
|
|
843
|
+
\text{output}(N_i, C_j, d, h, w) = \frac{1}{kD * kH * kW} \sum_{l=0}^{kD-1} \sum_{m=0}^{kH-1} \sum_{n=0}^{kW-1}
|
|
844
|
+
|
|
845
|
+
\text{input}(N_i, C_j, stride[0] \times d + l, stride[1] \times h + m, stride[2] \times w + n)
|
|
846
|
+
|
|
847
|
+
.. warning::
|
|
848
|
+
This is an experimental API that is subject to change or deletion.
|
|
849
|
+
|
|
850
|
+
Note:
|
|
851
|
+
This interface currently does not support Atlas A2 training series products.
|
|
852
|
+
|
|
853
|
+
Args:
|
|
854
|
+
input (Tensor): Tensor of shape :math:`(N, C, D_{in}, H_{in}, W_{in})` or :math:`(C, D_{in}, H_{in}, W_{in})`.
|
|
855
|
+
kernel_size (Union[int, tuple[int], list[int]]): The size of kernel used to take the average value.
|
|
856
|
+
Can be a single number or a tuple :math:`(kD, kH, kW)` .
|
|
857
|
+
stride (Union[int, tuple[int], list[int]], optional): The distance of kernel moving.
|
|
858
|
+
Can be a single number or a tuple :math:`(sD, sH, sW)` . Default: ``None``,
|
|
859
|
+
where its value is equal to `kernel_size`.
|
|
860
|
+
padding (Union[int, tuple[int], list[int]], optional): Implicit zero padding to be added on both sides.
|
|
861
|
+
Can be a single number or a tuple :math:`(padD, padH, padW)` . Default: ``0``.
|
|
862
|
+
ceil_mode (bool, optional): If True, apply ceil instead of floor to compute the output shape.
|
|
863
|
+
Default: ``False``.
|
|
864
|
+
count_include_pad (bool, optional): If True, include the zero-padding in the averaging calculation.
|
|
865
|
+
Default: ``True`` .
|
|
866
|
+
divisor_override (int, optional): If specified, it will be used as divisor in the averaging calculation,
|
|
867
|
+
otherwise size of pooling region will be used. Default: ``None``.
|
|
868
|
+
|
|
869
|
+
Returns:
|
|
870
|
+
Tensor, with shape :math:`(N, C, D_{out}, H_{out}, W_{out})` or :math:`(C, D_{out}, H_{out}, W_{out})`.
|
|
871
|
+
|
|
872
|
+
.. math::
|
|
873
|
+
\begin{array}{ll} \\
|
|
874
|
+
D_{out} = \frac{D_{in} + 2 \times padding[0] - kernel\_size[0]}{stride[0]} + 1 \\
|
|
875
|
+
H_{out} = \frac{H_{in} + 2 \times padding[1] - kernel\_size[0]}{stride[1]} + 1 \\
|
|
876
|
+
W_{out} = \frac{W_{in} + 2 \times padding[2] - kernel\_size[1]}{stride[2]} + 1
|
|
877
|
+
\end{array}
|
|
878
|
+
|
|
879
|
+
Raises:
|
|
880
|
+
TypeError: If `input` is not a Tensor.
|
|
881
|
+
TypeError: If `kernel_size` or `stride` is neither int nor tuple.
|
|
882
|
+
TypeError: If `ceil_mode` or `count_include_pad` is not a bool.
|
|
883
|
+
TypeError: If `divisor_override` is not an int or None.
|
|
884
|
+
ValueError: If the dimension of `input` is not equal to `4` or `5`.
|
|
885
|
+
ValueError: If `kernel_size` or `stride` is less than 1.
|
|
886
|
+
ValueError: If value of `padding` is less than `0`.
|
|
887
|
+
ValueError: If `kernel_size`, `padding` or `stride` is a tuple whose length is not equal to `1` or `3`.
|
|
888
|
+
|
|
889
|
+
Supported Platforms:
|
|
890
|
+
``Ascend``
|
|
891
|
+
|
|
892
|
+
Examples:
|
|
893
|
+
>>> import mindspore
|
|
894
|
+
>>> import numpy as np
|
|
895
|
+
>>> from mindspore import Tensor, ops
|
|
896
|
+
>>> input_x = Tensor(np.arange(1 * 2 * 2 * 2 * 3).reshape((1, 2, 2, 2, 3)), mindspore.float16)
|
|
897
|
+
>>> output = ops.avg_pool3d_ext(input_x, kernel_size=2, stride=1)
|
|
898
|
+
>>> print(output)
|
|
899
|
+
[[[[[ 5. 6.]]]
|
|
900
|
+
[[[17. 18.]]]]]
|
|
901
|
+
"""
|
|
902
|
+
return avg_pool3d_ext_op(input, kernel_size, stride, padding, ceil_mode, count_include_pad, divisor_override)
|
|
903
|
+
|
|
904
|
+
|
|
789
905
|
@constexpr
|
|
790
906
|
def is_ascend_backend():
|
|
791
907
|
"""Check if the Ascend is used"""
|
|
@@ -905,7 +1021,7 @@ def adaptive_max_pool2d(input, output_size, return_indices=False):
|
|
|
905
1021
|
\end{align}
|
|
906
1022
|
|
|
907
1023
|
Note:
|
|
908
|
-
|
|
1024
|
+
In KBK mode, `output_size` does not support mutable.
|
|
909
1025
|
|
|
910
1026
|
Args:
|
|
911
1027
|
input (Tensor): A 3D or 4D tensor,
|
|
@@ -914,7 +1030,7 @@ def adaptive_max_pool2d(input, output_size, return_indices=False):
|
|
|
914
1030
|
or an int H for :math:`(H, H)`. :math:`H` and :math:`W` can be int or None.
|
|
915
1031
|
If it is None, it means the output size is the same as the input size.
|
|
916
1032
|
|
|
917
|
-
return_indices (bool): If `return_indices` is ``True`` , the indices of max value would be output.
|
|
1033
|
+
return_indices (bool, optional): If `return_indices` is ``True`` , the indices of max value would be output.
|
|
918
1034
|
Default: ``False`` .
|
|
919
1035
|
|
|
920
1036
|
Returns:
|
|
@@ -966,11 +1082,17 @@ def adaptive_max_pool2d(input, output_size, return_indices=False):
|
|
|
966
1082
|
[[8. 9.]]
|
|
967
1083
|
[[8. 9.]]]]
|
|
968
1084
|
"""
|
|
1085
|
+
output_size_ = None
|
|
969
1086
|
_check_adaptive_max_pool2d(return_indices)
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
1087
|
+
|
|
1088
|
+
if isinstance(output_size, int):
|
|
1089
|
+
output_size_ = (output_size, output_size)
|
|
1090
|
+
else:
|
|
1091
|
+
output_size_ = tuple(-1 if val is None else val for val in output_size)
|
|
1092
|
+
|
|
1093
|
+
if return_indices:
|
|
1094
|
+
return adaptive_max_pool2d_impl(input, output_size_)
|
|
1095
|
+
return adaptive_max_pool2d_impl(input, output_size_)[0]
|
|
974
1096
|
|
|
975
1097
|
|
|
976
1098
|
def adaptive_max_pool3d(input, output_size, return_indices=False):
|
|
@@ -1445,7 +1567,7 @@ def dropout(input, p=0.5, training=True, seed=None):
|
|
|
1445
1567
|
input (Tensor): The input Tensor of shape :math:`(*, N)`, with data type of float16, float32 or float64.
|
|
1446
1568
|
p (float, optional): The dropping rate, between 0 and 1, e.g. p = 0.1,
|
|
1447
1569
|
means dropping out 10% of input units. Default: ``0.5`` .
|
|
1448
|
-
training (bool): Apply dropout if is True. Default: ``True``.
|
|
1570
|
+
training (bool, optional): Apply dropout if is True. Default: ``True``.
|
|
1449
1571
|
seed (int, optional): Seed is used as entropy source for Random number engines generating pseudo-random numbers.
|
|
1450
1572
|
Default: ``None`` , which will be treated as ``0`` .
|
|
1451
1573
|
|
|
@@ -1623,7 +1745,7 @@ def dropout2d(input, p=0.5, training=True):
|
|
|
1623
1745
|
input (Tensor): A `4D` tensor with shape :math:`(N, C, H, W)`, where `N` is the batch size, `C` is the number
|
|
1624
1746
|
of channels, `H` is the feature height, and `W` is the feature width. The data type must be int8,
|
|
1625
1747
|
int16, int32, int64, float16, float32 or float64.
|
|
1626
|
-
p (float): The dropping probability of a channel
|
|
1748
|
+
p (float): The dropping probability of a channel. The range is [0.0, 1.0], e.g. `p` = 0.8,
|
|
1627
1749
|
which means dropping out 80% of channels. Default: ``0.5`` .
|
|
1628
1750
|
training(bool): If `training` is True, applying dropout, otherwise, not applying. Default: ``True`` .
|
|
1629
1751
|
|
|
@@ -2035,6 +2157,75 @@ def kl_div(logits, labels, reduction='mean'):
|
|
|
2035
2157
|
return _get_cache_prim(P.KLDivLoss)(reduction=reduction)(logits, labels)
|
|
2036
2158
|
|
|
2037
2159
|
|
|
2160
|
+
def kl_div_ext(input, target, reduction='mean', log_target=False):
|
|
2161
|
+
r"""
|
|
2162
|
+
Computes the Kullback-Leibler divergence between the `input` and the `target`.
|
|
2163
|
+
|
|
2164
|
+
For tensors of the same shape :math:`x` and :math:`y`,
|
|
2165
|
+
the updating formulas of KLDivLoss algorithm are as follows,
|
|
2166
|
+
|
|
2167
|
+
.. math::
|
|
2168
|
+
L(x, y) = y \cdot (\log y - x)
|
|
2169
|
+
|
|
2170
|
+
Then,
|
|
2171
|
+
|
|
2172
|
+
.. math::
|
|
2173
|
+
\ell(x, y) = \begin{cases}
|
|
2174
|
+
L(x, y), & \text{if reduction} = \text{'none';}\\
|
|
2175
|
+
\operatorname{mean}(L(x, y)), & \text{if reduction} = \text{'mean';}\\
|
|
2176
|
+
\operatorname{sum}(L(x, y)) / x.\operatorname{shape}[0], & \text{if reduction} = \text{'batchmean';}\\
|
|
2177
|
+
\operatorname{sum}(L(x, y)), & \text{if reduction} = \text{'sum'.}
|
|
2178
|
+
\end{cases}
|
|
2179
|
+
|
|
2180
|
+
where :math:`x` represents `input`, :math:`y` represents `target`, and :math:`\ell(x, y)` represents the output.
|
|
2181
|
+
|
|
2182
|
+
Note:
|
|
2183
|
+
The output aligns with the mathematical definition of Kullback-Leibler divergence
|
|
2184
|
+
only when `reduction` is set to ``'batchmean'``.
|
|
2185
|
+
|
|
2186
|
+
Args:
|
|
2187
|
+
input (Tensor): The input Tensor. The data type must be float16, float32 or bfloat16(only supported by Atlas A2
|
|
2188
|
+
training series products).
|
|
2189
|
+
target (Tensor): The target Tensor which has the same type as `input`. The shapes of `target` and `input`
|
|
2190
|
+
should be broadcastable.
|
|
2191
|
+
reduction (str, optional): Specifies the reduction to be applied to the output. Default: ``'mean'``.
|
|
2192
|
+
log_target (bool, optional): Specifies whether `target` is passed in the log space. Default: ``False``.
|
|
2193
|
+
|
|
2194
|
+
Returns:
|
|
2195
|
+
Tensor, has the same dtype as `input`. If `reduction` is ``'none'``, then output has the shape as broadcast
|
|
2196
|
+
result of the `input` and `target`. Otherwise, it is a scalar Tensor.
|
|
2197
|
+
|
|
2198
|
+
Raises:
|
|
2199
|
+
TypeError: If neither `input` nor `target` is a Tensor.
|
|
2200
|
+
TypeError: If dtype of `input` or `target` is not float16, float32 or bfloat16.
|
|
2201
|
+
TypeError: If dtype of `target` is not the same as `input`.
|
|
2202
|
+
ValueError: If `reduction` is not one of ``'none'``, ``'mean'``, ``'sum'``, ``'batchmean'``.
|
|
2203
|
+
ValueError: If shapes of `target` and `input` can not be broadcastable.
|
|
2204
|
+
|
|
2205
|
+
Supported Platforms:
|
|
2206
|
+
``Ascend``
|
|
2207
|
+
|
|
2208
|
+
Examples:
|
|
2209
|
+
>>> import mindspore as ms
|
|
2210
|
+
>>> from mindspore import ops
|
|
2211
|
+
>>> import numpy as np
|
|
2212
|
+
>>> input = ms.Tensor(np.array([[0.5, 0.5], [0.4, 0.6]]), ms.float32)
|
|
2213
|
+
>>> target = ms.Tensor(np.array([[0., 1.], [1., 0.]]), ms.float32)
|
|
2214
|
+
>>> output = ops.kl_div_ext(input, target, reduction='mean', log_target=False)
|
|
2215
|
+
>>> print(output)
|
|
2216
|
+
-0.225
|
|
2217
|
+
"""
|
|
2218
|
+
if reduction == 'batchmean':
|
|
2219
|
+
reduced = kl_div_op(input, target, 'sum', log_target)
|
|
2220
|
+
else:
|
|
2221
|
+
reduced = kl_div_op(input, target, reduction, log_target)
|
|
2222
|
+
|
|
2223
|
+
if reduction == 'batchmean' and input.ndim != 0:
|
|
2224
|
+
reduced = divs_op(reduced, input.shape[0])
|
|
2225
|
+
|
|
2226
|
+
return reduced
|
|
2227
|
+
|
|
2228
|
+
|
|
2038
2229
|
@constexpr
|
|
2039
2230
|
def _check_axis_in_range(axis, ndim):
|
|
2040
2231
|
"""Checks axes are with the bounds of ndim"""
|
|
@@ -2094,33 +2285,22 @@ def _check_input_tensor(arg_name, *tensors):
|
|
|
2094
2285
|
|
|
2095
2286
|
def flip(input, dims):
|
|
2096
2287
|
"""
|
|
2097
|
-
Reverses
|
|
2098
|
-
|
|
2099
|
-
The shape of the tensor is preserved, but the elements are reordered.
|
|
2288
|
+
Reverses elements in a tensor along the given dims.
|
|
2100
2289
|
|
|
2101
2290
|
Args:
|
|
2102
|
-
input (Tensor):
|
|
2103
|
-
dims (Union[list[int], tuple[int]]):
|
|
2104
|
-
Flipping is performed on all of the axes specified in the tuple,
|
|
2105
|
-
If `dims` is a tuple of integers contains negative, it counts from the last to the first axis.
|
|
2291
|
+
input (Tensor): The input tensor.
|
|
2292
|
+
dims (Union[list[int], tuple[int]]): The dimension to flip.
|
|
2106
2293
|
|
|
2107
2294
|
Returns:
|
|
2108
|
-
Tensor
|
|
2109
|
-
|
|
2110
|
-
Raises:
|
|
2111
|
-
TypeError: If the input is not a tensor.
|
|
2112
|
-
ValueError: If `dims` is None.
|
|
2113
|
-
ValueError: If `dims` is not a list/tuple of ints.
|
|
2295
|
+
Tensor
|
|
2114
2296
|
|
|
2115
2297
|
Supported Platforms:
|
|
2116
2298
|
``Ascend`` ``GPU`` ``CPU``
|
|
2117
2299
|
|
|
2118
2300
|
Examples:
|
|
2119
2301
|
>>> import mindspore
|
|
2120
|
-
>>>
|
|
2121
|
-
>>>
|
|
2122
|
-
>>> input = mindspore.Tensor(np.arange(1, 9).reshape((2, 2, 2)))
|
|
2123
|
-
>>> output = ops.flip(input, (0, 2))
|
|
2302
|
+
>>> input = mindspore.tensor(mindspore.ops.arange(1, 9).reshape((2, 2, 2)))
|
|
2303
|
+
>>> output = mindspore.ops.flip(input, (0, 2))
|
|
2124
2304
|
>>> print(output)
|
|
2125
2305
|
[[[6 5]
|
|
2126
2306
|
[8 7]]
|
|
@@ -2133,26 +2313,21 @@ def flip(input, dims):
|
|
|
2133
2313
|
|
|
2134
2314
|
def flipud(input):
|
|
2135
2315
|
"""
|
|
2136
|
-
|
|
2316
|
+
Flip the input tensor in up/down direction.
|
|
2137
2317
|
|
|
2138
2318
|
Args:
|
|
2139
|
-
input (Tensor):
|
|
2319
|
+
input (Tensor): The input tensor, the dimension must be at least 2.
|
|
2140
2320
|
|
|
2141
2321
|
Returns:
|
|
2142
|
-
Tensor
|
|
2143
|
-
|
|
2144
|
-
Raises:
|
|
2145
|
-
TypeError: If the input is not a tensor.
|
|
2322
|
+
Tensor
|
|
2146
2323
|
|
|
2147
2324
|
Supported Platforms:
|
|
2148
2325
|
``Ascend`` ``GPU`` ``CPU``
|
|
2149
2326
|
|
|
2150
2327
|
Examples:
|
|
2151
|
-
>>> import mindspore
|
|
2152
|
-
>>>
|
|
2153
|
-
>>>
|
|
2154
|
-
>>> input = ms.Tensor(np.arange(1, 9).reshape((2, 2, 2)))
|
|
2155
|
-
>>> output = ops.flipud(input)
|
|
2328
|
+
>>> import mindspore
|
|
2329
|
+
>>> input = mindspore.tensor(mindspore.ops.arange(1, 9).reshape((2, 2, 2)))
|
|
2330
|
+
>>> output = mindspore.ops.flipud(input)
|
|
2156
2331
|
>>> print(output)
|
|
2157
2332
|
[[[5 6]
|
|
2158
2333
|
[7 8]]
|
|
@@ -2164,26 +2339,21 @@ def flipud(input):
|
|
|
2164
2339
|
|
|
2165
2340
|
def fliplr(input):
|
|
2166
2341
|
"""
|
|
2167
|
-
|
|
2342
|
+
Flip the input tensor in left/right direction.
|
|
2168
2343
|
|
|
2169
2344
|
Args:
|
|
2170
|
-
input (Tensor):
|
|
2345
|
+
input (Tensor): The input tensor, the dimension must be at least 2.
|
|
2171
2346
|
|
|
2172
2347
|
Returns:
|
|
2173
|
-
Tensor
|
|
2174
|
-
|
|
2175
|
-
Raises:
|
|
2176
|
-
TypeError: If the input is not a tensor.
|
|
2348
|
+
Tensor
|
|
2177
2349
|
|
|
2178
2350
|
Supported Platforms:
|
|
2179
2351
|
``Ascend`` ``GPU`` ``CPU``
|
|
2180
2352
|
|
|
2181
2353
|
Examples:
|
|
2182
|
-
>>> import mindspore
|
|
2183
|
-
>>>
|
|
2184
|
-
>>>
|
|
2185
|
-
>>> input = ms.Tensor(np.arange(1, 9).reshape((2, 2, 2)))
|
|
2186
|
-
>>> output = ops.fliplr(input)
|
|
2354
|
+
>>> import mindspore
|
|
2355
|
+
>>> input = mindspore.tensor(mindspore.ops.arange(1, 9).reshape((2, 2, 2)))
|
|
2356
|
+
>>> output = mindspore.ops.fliplr(input)
|
|
2187
2357
|
>>> print(output)
|
|
2188
2358
|
[[[3 4]
|
|
2189
2359
|
[1 2]]
|
|
@@ -2195,29 +2365,33 @@ def fliplr(input):
|
|
|
2195
2365
|
|
|
2196
2366
|
def is_floating_point(input):
|
|
2197
2367
|
"""
|
|
2198
|
-
|
|
2199
|
-
mindspore.float32, mindspore.float16.
|
|
2368
|
+
If the data type of the tensor is a floating point data type, return True. Otherwise return False.
|
|
2200
2369
|
|
|
2201
2370
|
Args:
|
|
2202
2371
|
input (Tensor): The input Tensor.
|
|
2203
2372
|
|
|
2204
2373
|
Returns:
|
|
2205
|
-
Bool
|
|
2374
|
+
Bool
|
|
2206
2375
|
|
|
2207
2376
|
Supported Platforms:
|
|
2208
2377
|
``Ascend`` ``GPU`` ``CPU``
|
|
2209
2378
|
|
|
2210
2379
|
Examples:
|
|
2211
|
-
>>> import mindspore
|
|
2212
|
-
>>>
|
|
2213
|
-
>>>
|
|
2214
|
-
>>> x = ms.Tensor([1, 2, 3], ms.float32)
|
|
2215
|
-
>>> y = ms.Tensor([1, 2, 3], ms.int64)
|
|
2216
|
-
>>> output = ops.is_floating_point(x)
|
|
2217
|
-
>>> output2 = ops.is_floating_point(y)
|
|
2218
|
-
>>> print(output)
|
|
2380
|
+
>>> import mindspore
|
|
2381
|
+
>>> input = mindspore.tensor([False, 0j, 1, 2.1, 1+2j], mindspore.float64)
|
|
2382
|
+
>>> mindspore.ops.is_floating_point(input)
|
|
2219
2383
|
True
|
|
2220
|
-
>>>
|
|
2384
|
+
>>>
|
|
2385
|
+
>>> input = mindspore.tensor([False, 0j, 1, 2.1, 1+2j], mindspore.float32)
|
|
2386
|
+
>>> mindspore.ops.is_floating_point(input)
|
|
2387
|
+
True
|
|
2388
|
+
>>>
|
|
2389
|
+
>>> input = mindspore.tensor([False, 0j, 1, 2.1, 1+2j], mindspore.float16)
|
|
2390
|
+
>>> mindspore.ops.is_floating_point(input)
|
|
2391
|
+
True
|
|
2392
|
+
>>>
|
|
2393
|
+
>>> input = mindspore.tensor([False, 0j, 1, 2.1, 1+2j], mindspore.int32)
|
|
2394
|
+
>>> mindspore.ops.is_floating_point(input)
|
|
2221
2395
|
False
|
|
2222
2396
|
"""
|
|
2223
2397
|
return input.dtype in [mstype.float32, mstype.bfloat16, mstype.float16, mstype.float64]
|
|
@@ -2339,12 +2513,20 @@ def interpolate(input,
|
|
|
2339
2513
|
If scale_factor is a tuple or list, its length should be the same as the number of dimensions in input
|
|
2340
2514
|
after removing the first two dimensions N, C.
|
|
2341
2515
|
One and only one of size and scale_factor can be set to None. Default: ``None`` .
|
|
2342
|
-
mode (str): The sampling algorithm.
|
|
2343
|
-
One of
|
|
2344
|
-
|
|
2345
|
-
|
|
2516
|
+
mode (str, optional): The sampling algorithm. Default: ``"nearest"`` .
|
|
2517
|
+
One of the following sampling methods can be used:
|
|
2518
|
+
|
|
2519
|
+
- 'nearest': the nearest neighbours interpolation.
|
|
2520
|
+
- 'linear': Linear interpolation, 3D only.
|
|
2521
|
+
- 'bilinear': Bilinear interpolation, 4D only.
|
|
2522
|
+
- 'trilinear': Trilinear interpolation, 5D only.
|
|
2523
|
+
- 'bicubic': Double trilinear interpolation, 4D only.
|
|
2524
|
+
- 'area': area interpolation.
|
|
2525
|
+
- 'nearest-exact': matches Scikit-Image and PIL nearest neighbours interpolation algorithms and fixes
|
|
2526
|
+
knows issues with `nearest`, for 3D and 4D.
|
|
2346
2527
|
|
|
2347
|
-
align_corners (bool): Whether to use corner alignment for coordinate mapping.
|
|
2528
|
+
align_corners (bool, optional): Whether to use corner alignment for coordinate mapping.
|
|
2529
|
+
Assuming a transformation is
|
|
2348
2530
|
applied to the input Tensor along the x-axis, the specific calculation formula is as follows:
|
|
2349
2531
|
|
|
2350
2532
|
.. code-block::
|
|
@@ -2361,9 +2543,10 @@ def interpolate(input,
|
|
|
2361
2543
|
|
|
2362
2544
|
This is only valid for ``'linear'``, ``'bilinear'``, or ``'bicubic'`` modes. Default: ``False`` .
|
|
2363
2545
|
recompute_scale_factor (bool, optional): Recalculate `scale_factor`.
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2546
|
+
|
|
2547
|
+
- If True, the parameter `size` will be calculated using the value of the `scale_factor`,
|
|
2548
|
+
and finally scaled using the value of `size`.
|
|
2549
|
+
- If False, the value of `size` or `scale_factor` will be used for direct interpolation. Default: ``None`` .
|
|
2367
2550
|
|
|
2368
2551
|
.. note::
|
|
2369
2552
|
The 'nearest-exact' mode is the same as the nearest-neighbor interpolation algorithm used in
|
|
@@ -2722,7 +2905,7 @@ def interpolate_ext(input,
|
|
|
2722
2905
|
the corresponding coordinate of the original
|
|
2723
2906
|
data along the x-axis.
|
|
2724
2907
|
|
|
2725
|
-
This is only valid for ``'linear'``, ``'bilinear'``, or ``'bicubic'`` modes. Default: ``
|
|
2908
|
+
This is only valid for ``'linear'``, ``'bilinear'``, or ``'bicubic'`` modes. Default: ``None`` .
|
|
2726
2909
|
recompute_scale_factor (bool, optional): Recalculate `scale_factor`.
|
|
2727
2910
|
If True, the parameter `size` will be calculated using the value of the `scale_factor`,
|
|
2728
2911
|
and finally scaled using the value of `size`.
|
|
@@ -2755,20 +2938,6 @@ def interpolate_ext(input,
|
|
|
2755
2938
|
Returns:
|
|
2756
2939
|
Tensor, sampled, whose dimensions and dtype are the same as `input`.
|
|
2757
2940
|
|
|
2758
|
-
Shape:
|
|
2759
|
-
- Input: :math:`(N, C, W_{in})`, :math:`(N, C, H_{in}, W_{in})` or :math:`(N, C, D_{in}, H_{in}, W_{in})`
|
|
2760
|
-
- Output: :math:`(N, C, W_{out})`, :math:`(N, C, H_{out}, W_{out})`
|
|
2761
|
-
or :math:`(N, C, D_{out}, H_{out}, W_{out})`, where
|
|
2762
|
-
|
|
2763
|
-
.. math::
|
|
2764
|
-
D_{out} = \left\lfloor D_{in} \times \text{scale\_factor} \right\rfloor
|
|
2765
|
-
|
|
2766
|
-
.. math::
|
|
2767
|
-
H_{out} = \left\lfloor H_{in} \times \text{scale\_factor} \right\rfloor
|
|
2768
|
-
|
|
2769
|
-
.. math::
|
|
2770
|
-
W_{out} = \left\lfloor W_{in} \times \text{scale\_factor} \right\rfloor
|
|
2771
|
-
|
|
2772
2941
|
Raises:
|
|
2773
2942
|
TypeError: `input` is not a Tensor.
|
|
2774
2943
|
ValueError: Both `size` and `scale_factor` are not empty.
|
|
@@ -2929,58 +3098,6 @@ def softsign(x):
|
|
|
2929
3098
|
return softsign_(x)
|
|
2930
3099
|
|
|
2931
3100
|
|
|
2932
|
-
def soft_margin_loss(input, target, reduction='mean'):
|
|
2933
|
-
r"""
|
|
2934
|
-
Calculate the soft margin loss of input and target.
|
|
2935
|
-
|
|
2936
|
-
Creates a criterion that optimizes a two-class classification
|
|
2937
|
-
logistic loss between input tensor :math:`x` and target tensor :math:`y`
|
|
2938
|
-
(containing 1 or -1).
|
|
2939
|
-
|
|
2940
|
-
.. math::
|
|
2941
|
-
\text{loss}(x, y) = \sum_i \frac{\log(1 + \exp(-y[i]*x[i]))}{\text{x.nelement}()}
|
|
2942
|
-
|
|
2943
|
-
where :math:`x.nelement()` is the number of elements of :math:`x`.
|
|
2944
|
-
|
|
2945
|
-
.. warning::
|
|
2946
|
-
This is an experimental API that is subject to change or deletion.
|
|
2947
|
-
|
|
2948
|
-
Args:
|
|
2949
|
-
input (Tensor): Predict data. Data type must be float16 or float32.
|
|
2950
|
-
target (Tensor): Ground truth data, with the same type and shape as `input`.
|
|
2951
|
-
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
2952
|
-
``'sum'`` . Default: ``'mean'`` .
|
|
2953
|
-
|
|
2954
|
-
- ``'none'``: no reduction will be applied.
|
|
2955
|
-
- ``'mean'``: compute and return the mean of elements in the output.
|
|
2956
|
-
- ``'sum'``: the output elements will be summed.
|
|
2957
|
-
|
|
2958
|
-
Outputs:
|
|
2959
|
-
Tensor or Scalar. If `reduction` is ``'none'``, its shape is the same as `input`.
|
|
2960
|
-
Otherwise, a scalar value will be returned.
|
|
2961
|
-
|
|
2962
|
-
Raises:
|
|
2963
|
-
TypeError: If `input` or `target` is not a Tensor.
|
|
2964
|
-
TypeError: If dtype of `input` or `target` is neither float16 nor float32.
|
|
2965
|
-
ValueError: If shape of `input` is not the same as that of `target`.
|
|
2966
|
-
ValueError: If `reduction` is not one of ``'none'``, ``'mean'`` or ``'sum'``.
|
|
2967
|
-
|
|
2968
|
-
Supported Platforms:
|
|
2969
|
-
``Ascend`` ``GPU``
|
|
2970
|
-
|
|
2971
|
-
Examples:
|
|
2972
|
-
>>> import mindspore
|
|
2973
|
-
>>> import numpy as np
|
|
2974
|
-
>>> from mindspore import Tensor, ops
|
|
2975
|
-
>>> logits = Tensor(np.array([[0.3, 0.7], [0.5, 0.5]]), mindspore.float32)
|
|
2976
|
-
>>> labels = Tensor(np.array([[-1, 1], [1, -1]]), mindspore.float32)
|
|
2977
|
-
>>> output = ops.soft_margin_loss(logits, labels)
|
|
2978
|
-
>>> print(output)
|
|
2979
|
-
0.6764238
|
|
2980
|
-
"""
|
|
2981
|
-
soft_margin_loss_op = _get_cache_prim(P.SoftMarginLoss)(reduction=reduction)
|
|
2982
|
-
output = soft_margin_loss_op(input, target)
|
|
2983
|
-
return output
|
|
2984
3101
|
|
|
2985
3102
|
|
|
2986
3103
|
def softmax(input, axis=-1, *, dtype=None):
|
|
@@ -3277,7 +3394,7 @@ def selu(input_x):
|
|
|
3277
3394
|
|
|
3278
3395
|
def logsigmoid(x):
|
|
3279
3396
|
r"""
|
|
3280
|
-
Applies
|
|
3397
|
+
Applies LogSigmoid activation element-wise. The input is a Tensor with any valid shape.
|
|
3281
3398
|
|
|
3282
3399
|
Logsigmoid is defined as:
|
|
3283
3400
|
|
|
@@ -3911,8 +4028,10 @@ def rrelu(input, lower=1.0 / 8, upper=1.0 / 3):
|
|
|
3911
4028
|
|
|
3912
4029
|
Args:
|
|
3913
4030
|
input (Tensor): The input of rrelu is a Tensor of any dimension.
|
|
3914
|
-
lower (Union[int, float]): Slope of the activation function at data of `input`
|
|
3915
|
-
|
|
4031
|
+
lower (Union[int, float]): Slope of the activation function at data of `input` is less than 0.
|
|
4032
|
+
Default: ``1.0 / 8`` .
|
|
4033
|
+
upper (Union[int, float]): Slope of the activation function at data of `input` is less than 0.
|
|
4034
|
+
Default: ``1.0 / 3`` .
|
|
3916
4035
|
|
|
3917
4036
|
Returns:
|
|
3918
4037
|
Tensor, after rrelu, has the same type and shape as the `input`.
|
|
@@ -4174,7 +4293,7 @@ def nll_loss(inputs, target, weight=None, ignore_index=-100, reduction='mean', l
|
|
|
4174
4293
|
N is the batch size, :math:`c` belonging to :math:`[0, C-1]` is class index, where :math:`C` is the number of
|
|
4175
4294
|
classes.
|
|
4176
4295
|
|
|
4177
|
-
If `reduction` is not ``None`` (default ``'mean'``), then
|
|
4296
|
+
If `reduction` is not ``'None'`` (default ``'mean'``), then
|
|
4178
4297
|
|
|
4179
4298
|
.. math::
|
|
4180
4299
|
|
|
@@ -4301,7 +4420,7 @@ def nll_loss_ext(input, target, weight=None, ignore_index=-100, reduction='mean'
|
|
|
4301
4420
|
:math:`N` is the batch size, :math:`c` belonging to :math:`[0, C-1]` is class index,
|
|
4302
4421
|
where :math:`C` is the number of classes.
|
|
4303
4422
|
|
|
4304
|
-
If `reduction` is not ``None`` (default ``'mean'``), then
|
|
4423
|
+
If `reduction` is not ``'None'`` (default ``'mean'``), then
|
|
4305
4424
|
|
|
4306
4425
|
.. math::
|
|
4307
4426
|
|
|
@@ -4353,7 +4472,7 @@ def nll_loss_ext(input, target, weight=None, ignore_index=-100, reduction='mean'
|
|
|
4353
4472
|
return _nllloss_nd(input, target, weight, ignore_index, reduction)
|
|
4354
4473
|
|
|
4355
4474
|
|
|
4356
|
-
def _nllloss_nd(input, target, weight=None,
|
|
4475
|
+
def _nllloss_nd(input, target, weight=None, ignore_index=-100, reduction='mean'):
|
|
4357
4476
|
"""nllloss_nd inner function"""
|
|
4358
4477
|
input_dim = input.ndim
|
|
4359
4478
|
class_dim = 0 if input_dim == 1 else 1
|
|
@@ -4366,9 +4485,9 @@ def _nllloss_nd(input, target, weight=None, ingore_index=-100, reduction='mean')
|
|
|
4366
4485
|
raise ValueError(f"input bacth_size should be equal to target batch_size, but got {input.shape[0]} and "
|
|
4367
4486
|
f"{target.shape[0]}")
|
|
4368
4487
|
if input_dim == 1 or input_dim == 2:
|
|
4369
|
-
return nllloss_impl(input, target, weight, reduction,
|
|
4488
|
+
return nllloss_impl(input, target, weight, reduction, ignore_index)[0]
|
|
4370
4489
|
if input_dim == 4:
|
|
4371
|
-
return nllloss_2d_op(input, target, weight, reduction,
|
|
4490
|
+
return nllloss_2d_op(input, target, weight, reduction, ignore_index)[0]
|
|
4372
4491
|
# input_dim==3 or input_dim>4
|
|
4373
4492
|
n = input.shape[0]
|
|
4374
4493
|
c = input.shape[1]
|
|
@@ -4382,8 +4501,8 @@ def _nllloss_nd(input, target, weight=None, ingore_index=-100, reduction='mean')
|
|
|
4382
4501
|
else:
|
|
4383
4502
|
target = target.view((n, 0, 0))
|
|
4384
4503
|
if reduction != 'none':
|
|
4385
|
-
return nllloss_2d_op(input, target, weight, reduction,
|
|
4386
|
-
ret = nllloss_2d_op(input, target, weight, reduction,
|
|
4504
|
+
return nllloss_2d_op(input, target, weight, reduction, ignore_index)[0]
|
|
4505
|
+
ret = nllloss_2d_op(input, target, weight, reduction, ignore_index)[0]
|
|
4387
4506
|
return ret.view(out_size)
|
|
4388
4507
|
|
|
4389
4508
|
|
|
@@ -4411,10 +4530,10 @@ def _cross_entropy_for_probabilities(input, target, weight, reduction, label_smo
|
|
|
4411
4530
|
raise ValueError(f"redution value {reduction} not valid.")
|
|
4412
4531
|
|
|
4413
4532
|
|
|
4414
|
-
def _cross_entropy_for_class_indices(input, target, weight,
|
|
4533
|
+
def _cross_entropy_for_class_indices(input, target, weight, ignore_index, reduction, label_smoothing, class_dim,
|
|
4415
4534
|
n_classes):
|
|
4416
4535
|
"""cross_entropy inner function for class indices"""
|
|
4417
|
-
nllloss = _nllloss_nd(input, target, weight,
|
|
4536
|
+
nllloss = _nllloss_nd(input, target, weight, ignore_index, reduction)
|
|
4418
4537
|
if label_smoothing > 0.0:
|
|
4419
4538
|
if weight is not None:
|
|
4420
4539
|
weight_ = weight
|
|
@@ -4428,7 +4547,7 @@ def _cross_entropy_for_class_indices(input, target, weight, ingore_index, reduct
|
|
|
4428
4547
|
smooth_loss = -loss.sum(class_dim)
|
|
4429
4548
|
else:
|
|
4430
4549
|
smooth_loss = -input.sum(class_dim)
|
|
4431
|
-
ignore_mask = ops.eq(target,
|
|
4550
|
+
ignore_mask = ops.eq(target, ignore_index)
|
|
4432
4551
|
smooth_loss = masked_fill_op(smooth_loss, ignore_mask, 0)
|
|
4433
4552
|
if reduction == "mean":
|
|
4434
4553
|
true_mask = ~ignore_mask
|
|
@@ -4454,7 +4573,7 @@ def _cross_entropy_for_class_indices(input, target, weight, ingore_index, reduct
|
|
|
4454
4573
|
return nllloss
|
|
4455
4574
|
|
|
4456
4575
|
|
|
4457
|
-
def cross_entropy_ext(input, target, weight=None,
|
|
4576
|
+
def cross_entropy_ext(input, target, weight=None, ignore_index=-100, reduction='mean', label_smoothing=0.0):
|
|
4458
4577
|
r"""
|
|
4459
4578
|
The cross entropy loss between input and target.
|
|
4460
4579
|
|
|
@@ -4511,13 +4630,13 @@ def cross_entropy_ext(input, target, weight=None, ingore_index=-100, reduction='
|
|
|
4511
4630
|
Note:
|
|
4512
4631
|
Dynamic shape, dynamic rank and variable constant input are not supported in `strict graph mode
|
|
4513
4632
|
(jit_syntax_level=mindspore.STRICT)
|
|
4514
|
-
<https://www.mindspore.cn/
|
|
4633
|
+
<https://www.mindspore.cn/tutorials/en/master/compile/static_graph.html>`_.
|
|
4515
4634
|
|
|
4516
4635
|
Args:
|
|
4517
4636
|
input (Tensor): :math:`(N)` or :math:`(N, C)` where `C = number of classes` or :math:`(N, C, H, W)`
|
|
4518
4637
|
in case of 2D Loss, or :math:`(N, C, d_1, d_2, ..., d_K)`.
|
|
4519
|
-
`input` is expected to be log-probabilities, data type must be float16 or float32 or bfloat16
|
|
4520
|
-
by Atlas A2 training series products).
|
|
4638
|
+
`input` is expected to be log-probabilities, data type must be float16 or float32 or bfloat16
|
|
4639
|
+
(only supported by Atlas A2 training series products).
|
|
4521
4640
|
target (Tensor): For class indices, tensor of shape :math:`()`, :math:`(N)` or
|
|
4522
4641
|
:math:`(N, d_1, d_2, ..., d_K)` , data type must be int32 or int64. For probabilities, tensor of shape
|
|
4523
4642
|
:math:`(N,)` , :math:`(N, C)` or :math:`(N, C, d_1, d_2, ..., d_K)` , data type must be float16 or float32
|
|
@@ -4577,7 +4696,7 @@ def cross_entropy_ext(input, target, weight=None, ingore_index=-100, reduction='
|
|
|
4577
4696
|
return _cross_entropy_for_probabilities(input, target, weight, reduction, label_smoothing, class_dim,
|
|
4578
4697
|
n_classes)
|
|
4579
4698
|
# for class indices
|
|
4580
|
-
return _cross_entropy_for_class_indices(input, target, weight,
|
|
4699
|
+
return _cross_entropy_for_class_indices(input, target, weight, ignore_index, reduction, label_smoothing,
|
|
4581
4700
|
class_dim, n_classes)
|
|
4582
4701
|
|
|
4583
4702
|
|
|
@@ -4596,7 +4715,7 @@ def l1_loss(input, target, reduction='mean'):
|
|
|
4596
4715
|
|
|
4597
4716
|
where :math:`N` is the batch size.
|
|
4598
4717
|
|
|
4599
|
-
If `reduction` is ``'mean'`` or ``'sum'`` , then:
|
|
4718
|
+
If `reduction` is set to ``'mean'`` or ``'sum'`` , then:
|
|
4600
4719
|
|
|
4601
4720
|
.. math::
|
|
4602
4721
|
\ell(x, y) =
|
|
@@ -4801,8 +4920,8 @@ def leaky_relu(input, alpha=0.2):
|
|
|
4801
4920
|
|
|
4802
4921
|
Args:
|
|
4803
4922
|
input (Tensor): The input of leaky_relu is a Tensor of any dimension.
|
|
4804
|
-
alpha (Union[int, float]): Slope of the activation function when
|
|
4805
|
-
|
|
4923
|
+
alpha (Union[int, float], optional): Slope of the activation function when
|
|
4924
|
+
the element of `input` is less than 0. Default: ``0.2`` .
|
|
4806
4925
|
|
|
4807
4926
|
Returns:
|
|
4808
4927
|
Tensor, has the same type and shape as the `input`.
|
|
@@ -4834,37 +4953,25 @@ def leaky_relu(input, alpha=0.2):
|
|
|
4834
4953
|
|
|
4835
4954
|
def intopk(x1, x2, k):
|
|
4836
4955
|
r"""
|
|
4837
|
-
|
|
4956
|
+
Return whether the elements in second input tensor exist among the top `k` elements of the first input tensor.
|
|
4838
4957
|
|
|
4839
4958
|
Args:
|
|
4840
|
-
x1 (Tensor):
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
must be equal to the first dimension of `x1`. The values of `x2` can not be negative and
|
|
4844
|
-
must be equal to or less than index of x1's second dimension.
|
|
4845
|
-
k (int): Specifies the number of top elements to be used for computing precision along the last dimension.
|
|
4959
|
+
x1 (Tensor): The 2-D input tensor.
|
|
4960
|
+
x2 (Tensor): The 1-D input tensor, should satisfy :math:`x2.shape[0] = x1.shape[0]` .
|
|
4961
|
+
k (int): Top `k` elements.
|
|
4846
4962
|
|
|
4847
4963
|
Returns:
|
|
4848
|
-
|
|
4849
|
-
if the label in the first `k` predictions for sample `i` is in `x1`, then the value is True, otherwise False.
|
|
4850
|
-
|
|
4851
|
-
Raises:
|
|
4852
|
-
TypeError: If `k` is not an int.
|
|
4853
|
-
TypeError: If `x1` or `x2` is not a Tensor.
|
|
4854
|
-
TypeError: If dtype of `x1` is neither float16 nor float32.
|
|
4964
|
+
A 1-D tensor whose data type is bool, has the same shape with `x2`.
|
|
4855
4965
|
|
|
4856
4966
|
Supported Platforms:
|
|
4857
4967
|
``Ascend`` ``GPU`` ``CPU``
|
|
4858
4968
|
|
|
4859
4969
|
Examples:
|
|
4860
4970
|
>>> import mindspore
|
|
4861
|
-
>>>
|
|
4862
|
-
>>>
|
|
4863
|
-
>>>
|
|
4864
|
-
|
|
4865
|
-
>>> output = ops.intopk(x1, x2, 3)
|
|
4866
|
-
>>> print(output)
|
|
4867
|
-
[ True False]
|
|
4971
|
+
>>> x1 = mindspore.tensor([[1, 8, 5, 2, 7], [4, 9, 1, 3, 5]], mindspore.float32)
|
|
4972
|
+
>>> x2 = mindspore.tensor([1, 3], mindspore.int32)
|
|
4973
|
+
>>> mindspore.ops.intopk(x1, x2, 3)
|
|
4974
|
+
Tensor(shape=[2], dtype=Bool, value= [ True, False])
|
|
4868
4975
|
"""
|
|
4869
4976
|
_in_topk = _get_cache_prim(P.InTopK)(k)
|
|
4870
4977
|
return _in_topk(x1, x2)
|
|
@@ -6121,6 +6228,127 @@ def conv2d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
6121
6228
|
return output
|
|
6122
6229
|
|
|
6123
6230
|
|
|
6231
|
+
def conv1d_ext(input, weight, bias=None, stride=1, padding=0, dilation=1, groups=1):
|
|
6232
|
+
r"""
|
|
6233
|
+
Applies a 1D convolution over an input tensor. The input tenor is typically
|
|
6234
|
+
of shape :math:`(N, C_{in}, L_{in})`,
|
|
6235
|
+
where :math:`N` is batch size, :math:`C` is channel number, :math:`L` is sequence length.
|
|
6236
|
+
|
|
6237
|
+
The output is calculated based on formula:
|
|
6238
|
+
|
|
6239
|
+
.. math::
|
|
6240
|
+
|
|
6241
|
+
\text{out}(N_i, C_{\text{out}_j}) = \text{bias}(C_{\text{out}_j}) +
|
|
6242
|
+
\sum_{k = 0}^{C_{in} - 1} \text{ccor}({\text{weight}(C_{\text{out}_j}, k), \text{X}(N_i, k)})
|
|
6243
|
+
|
|
6244
|
+
where :math:`bias` is the output channel bias, :math:`ccor` is
|
|
6245
|
+
the `cross-correlation <https://en.wikipedia.org/wiki/Cross-correlation>`_,
|
|
6246
|
+
:math:`weight` is the convolution kernel value and :math:`X` represents the input feature map.
|
|
6247
|
+
|
|
6248
|
+
- :math:`i` corresponds to the batch number, the range is :math:`[0, N-1]`,
|
|
6249
|
+
where :math:`N` is the batch size of the input.
|
|
6250
|
+
|
|
6251
|
+
- :math:`j` corresponds to the output channel, the range is :math:`[0, C_{out}-1]`,
|
|
6252
|
+
where :math:`C_{out}` is the number of
|
|
6253
|
+
output channels, which is also equal to the number of kernels.
|
|
6254
|
+
|
|
6255
|
+
- :math:`k` corresponds to the input channel, the range is :math:`[0, C_{in}-1]`,
|
|
6256
|
+
where :math:`C_{in}` is the number of
|
|
6257
|
+
input channels, which is also equal to the number of channels in the convolutional kernels.
|
|
6258
|
+
|
|
6259
|
+
Therefore, in the above formula, :math:`{bias}(C_{\text{out}_j})` represents the bias of the :math:`j`-th
|
|
6260
|
+
output channel, :math:`{weight}(C_{\text{out}_j}, k)` represents the slice of the :math:`j`-th convolutional
|
|
6261
|
+
kernel in the :math:`k`-th channel, and :math:`{X}(N_i, k)` represents the slice of the :math:`k`-th input
|
|
6262
|
+
channel in the :math:`i`-th batch of the input feature map.
|
|
6263
|
+
|
|
6264
|
+
The shape of the convolutional kernel is given by :math:`(\text{kernel_size})`,
|
|
6265
|
+
where :math:`\text{kernel_size}` is the length of the kernel.
|
|
6266
|
+
If we consider the input and output channels as well as the `groups` parameter, the complete kernel shape
|
|
6267
|
+
will be :math:`(C_{out}, C_{in} / \text{groups}, \text{kernel_size})`,
|
|
6268
|
+
where `groups` is the number of groups dividing `x`'s input channel when applying groups convolution.
|
|
6269
|
+
|
|
6270
|
+
For more details about convolution layer, please refer to `Gradient Based Learning Applied to Document Recognition
|
|
6271
|
+
<http://vision.stanford.edu/cs598_spring07/papers/Lecun98.pdf>`_.
|
|
6272
|
+
|
|
6273
|
+
.. warning::
|
|
6274
|
+
This is an experimental API that is subject to change or deletion.
|
|
6275
|
+
|
|
6276
|
+
Args:
|
|
6277
|
+
input (Tensor): Tensor of shape :math:`(N, C_{in}, L_{in})` or :math:`(C_{in}, L_{in})`.
|
|
6278
|
+
weight (Tensor): Tensor of shape
|
|
6279
|
+
:math:`(N, C_{in} / \text{groups}, \text{kernel_size})`, then the size of kernel
|
|
6280
|
+
is :math:`(\text{kernel_size})`.
|
|
6281
|
+
bias (Tensor, optional): Bias Tensor with shape :math:`(C_{out})`.
|
|
6282
|
+
When bias is ``None`` , zeros will be used. Default: ``None`` .
|
|
6283
|
+
stride (Union[int, tuple[int], list[int]], optional): The movement stride of the 1D convolution kernel.
|
|
6284
|
+
The data type is an integer or a tuple of one integer. Default: ``1`` .` .
|
|
6285
|
+
padding (Union[int, tuple[int], list[int], str], optional): The number of padding
|
|
6286
|
+
on the input.
|
|
6287
|
+
The data type is an integer or a tuple of one integer or string {`valid`, `same`}.
|
|
6288
|
+
The value should be greater than or equal to 0. Default: ``0`` .
|
|
6289
|
+
|
|
6290
|
+
- ``"same"``: Pad the input around its edges so that the shape of input and output
|
|
6291
|
+
are the same when `stride` is set to ``1``.
|
|
6292
|
+
The amount of padding to is calculated by the operator internally, If the amount is even, it is
|
|
6293
|
+
uniformly distributed around the input, if it is odd, the excess amount goes to the right side.
|
|
6294
|
+
If this mode is set, `stride` must be 1.
|
|
6295
|
+
|
|
6296
|
+
- ``"valid"``: No padding is applied to the input, and the output returns the maximum
|
|
6297
|
+
possible length. Extra sequence that could not complete a full stride will
|
|
6298
|
+
be discarded.
|
|
6299
|
+
|
|
6300
|
+
dilation (Union[int, tuple[int], list[int]], optional): Specifies the dilation rate to use for
|
|
6301
|
+
dilated convolution. It can be a single int or a tuple of 1 integer.
|
|
6302
|
+
Assuming :math:`dilation=(d)`, the convolutional kernel samples the input with a
|
|
6303
|
+
spacing of :math:`d-1` elements in the length direction.
|
|
6304
|
+
Default: ``1`` .
|
|
6305
|
+
groups (int, optional): Splits filter into groups, `in_channels` and `out_channels` must be
|
|
6306
|
+
divisible by `groups`. If the groups is equal to `in_channels` and `out_channels`,
|
|
6307
|
+
this 1D convolution layer also can be called 1D depthwise convolution layer. Default: ``1`` .
|
|
6308
|
+
|
|
6309
|
+
- :math:`(C_{in} \text{ % } \text{groups} == 0)` , :math:`(C_{out} \text{ % } \text{groups} == 0)` ,
|
|
6310
|
+
:math:`(C_{out} >= \text{groups})` , :math:`(\text{kernel_size[1]} = C_{in} / \text{groups})`。
|
|
6311
|
+
|
|
6312
|
+
Returns:
|
|
6313
|
+
Tensor, the value that applied 1D convolution. The shape is :math:`(N, C_{out}, L_{out})`.
|
|
6314
|
+
To see how different pad modes affect the output shape, please refer to
|
|
6315
|
+
:class:`mindspore.mint.nn.Conv1d` for more details.
|
|
6316
|
+
|
|
6317
|
+
Raises:
|
|
6318
|
+
ValueError: Args and size of the input feature map should satisfy the output formula to ensure that the size of
|
|
6319
|
+
the output feature map is positive; otherwise, an error will be reported.
|
|
6320
|
+
RuntimeError: On Ascend, due to the limitation of the L1 cache size of different NPU chip, if input size or
|
|
6321
|
+
kernel size is too large, it may trigger an error.
|
|
6322
|
+
TypeError: If `in_channels`, `out_channels` or `groups` is not an int.
|
|
6323
|
+
TypeError: If `kernel_size`, `stride` or `dilation` is neither an int not a tuple.
|
|
6324
|
+
ValueError: If `in_channels`, `out_channels`, `kernel_size`, `stride` or `dilation` is less than 1.
|
|
6325
|
+
ValueError: If `padding` is less than 0.
|
|
6326
|
+
ValueError: If `padding` is `same` , `stride` is not equal to 1.
|
|
6327
|
+
ValueError: The input parameters do not satisfy the convolution output formula.
|
|
6328
|
+
ValueError: The KernelSize cannot exceed the size of the input feature map.
|
|
6329
|
+
ValueError: The value of padding cannot cause the calculation area to exceed the input size.
|
|
6330
|
+
|
|
6331
|
+
Supported Platforms:
|
|
6332
|
+
``Ascend``
|
|
6333
|
+
|
|
6334
|
+
Examples:
|
|
6335
|
+
>>> import mindspore
|
|
6336
|
+
>>> import numpy as np
|
|
6337
|
+
>>> from mindspore import Tensor, ops, mint
|
|
6338
|
+
>>> x = Tensor(np.ones([10, 32, 32]), mindspore.float32)
|
|
6339
|
+
>>> weight = Tensor(np.ones([32, 32, 3]), mindspore.float32)
|
|
6340
|
+
>>> output = mint.nn.functional.conv1d(x, weight)
|
|
6341
|
+
>>> print(output.shape)
|
|
6342
|
+
(10, 32, 30)
|
|
6343
|
+
"""
|
|
6344
|
+
if isinstance(padding, (int, tuple, list)):
|
|
6345
|
+
return conv1d_ext_op(input, weight, bias, stride, padding, dilation, groups)
|
|
6346
|
+
if isinstance(padding, str):
|
|
6347
|
+
return conv1d_padding_op(input, weight, bias, stride, padding, dilation, groups)
|
|
6348
|
+
raise TypeError(f"For conv1d, the parameter 'padding' must be a tuple/list " \
|
|
6349
|
+
f"or a string, but got {type(padding)}")
|
|
6350
|
+
|
|
6351
|
+
|
|
6124
6352
|
def _check_stride_when_same_mode(stride):
|
|
6125
6353
|
""" stride must be 1 when pad mode is same """
|
|
6126
6354
|
if isinstance(stride, int):
|
|
@@ -6220,10 +6448,10 @@ def conv2d_ext(input, weight, bias=None, stride=1, padding=0, dilation=1, groups
|
|
|
6220
6448
|
is :math:`(\text{kernel_size[0]}, \text{kernel_size[1]})`.
|
|
6221
6449
|
bias (Tensor, optional): Bias Tensor with shape :math:`(C_{out})`.
|
|
6222
6450
|
When bias is ``None`` , zeros will be used. Default: ``None`` .
|
|
6223
|
-
stride (Union(int, tuple[int]), optional): The distance of kernel moving, an int number that
|
|
6224
|
-
the height and width of movement are both strides, or a tuple of two int numbers that
|
|
6451
|
+
stride (Union(int, tuple[int], list[int]), optional): The distance of kernel moving, an int number that
|
|
6452
|
+
represents the height and width of movement are both strides, or a tuple of two int numbers that
|
|
6225
6453
|
represent height and width of movement respectively. Default: ``1`` .
|
|
6226
|
-
padding (Union[int, tuple[int], str], optional): The number of padding
|
|
6454
|
+
padding (Union[int, tuple[int], list[int], str], optional): The number of padding
|
|
6227
6455
|
on the height and width directions of the input.
|
|
6228
6456
|
The data type is an integer or a tuple of two integers or string {`valid`, `same`}. If `padding` is an
|
|
6229
6457
|
integer, then `padding_{H}` and `padding_{W}` are all equal to `padding`.
|
|
@@ -6241,8 +6469,9 @@ def conv2d_ext(input, weight, bias=None, stride=1, padding=0, dilation=1, groups
|
|
|
6241
6469
|
possible height and width. Extra pixels that could not complete a full stride will
|
|
6242
6470
|
be discarded.
|
|
6243
6471
|
|
|
6244
|
-
dilation (Union(int, tuple[int]), optional): Gaps between kernel elements.The data type
|
|
6245
|
-
2 integers. Specifies the dilation rate to use for dilated convolution.
|
|
6472
|
+
dilation (Union(int, tuple[int], list[int]), optional): Gaps between kernel elements.The data type
|
|
6473
|
+
is int or a tuple of 2 integers. Specifies the dilation rate to use for dilated convolution.
|
|
6474
|
+
If set to be :math:`k > 1`,
|
|
6246
6475
|
there will be :math:`k - 1` pixels skipped for each sampling location. Its value must
|
|
6247
6476
|
be greater than or equal to 1 and bounded by the height and width of the input `x`. Default: ``1`` .
|
|
6248
6477
|
groups (int, optional): Splits `input` into groups. Default: ``1`` .
|
|
@@ -7031,39 +7260,8 @@ def conv3d(input, weight, bias=None, stride=1, pad_mode="valid", padding=0, dila
|
|
|
7031
7260
|
|
|
7032
7261
|
Returns:
|
|
7033
7262
|
Tensor, the value that applied 3D convolution. The shape is :math:`(N, C_{out}, D_{out}, H_{out}, W_{out})`.
|
|
7034
|
-
|
|
7035
|
-
`
|
|
7036
|
-
|
|
7037
|
-
.. math::
|
|
7038
|
-
\begin{array}{ll} \\
|
|
7039
|
-
D_{out} = \left \lceil{\frac{D_{in}}{\text{stride[0]}}} \right \rceil \\
|
|
7040
|
-
H_{out} = \left \lceil{\frac{H_{in}}{\text{stride[1]}}} \right \rceil \\
|
|
7041
|
-
W_{out} = \left \lceil{\frac{W_{in}}{\text{stride[2]}}} \right \rceil \\
|
|
7042
|
-
\end{array}
|
|
7043
|
-
|
|
7044
|
-
`pad_mode` is ``"valid"``:
|
|
7045
|
-
|
|
7046
|
-
.. math::
|
|
7047
|
-
\begin{array}{ll} \\
|
|
7048
|
-
D_{out} = \left \lfloor{\frac{D_{in} - \text{dilation[0]} \times (\text{kernel_size[0]} - 1) }
|
|
7049
|
-
{\text{stride[0]}} + 1} \right \rfloor \\
|
|
7050
|
-
H_{out} = \left \lfloor{\frac{H_{in} - \text{dilation[1]} \times (\text{kernel_size[1]} - 1) }
|
|
7051
|
-
{\text{stride[1]}} + 1} \right \rfloor \\
|
|
7052
|
-
W_{out} = \left \lfloor{\frac{W_{in} - \text{dilation[2]} \times (\text{kernel_size[2]} - 1) }
|
|
7053
|
-
{\text{stride[2]}} + 1} \right \rfloor \\
|
|
7054
|
-
\end{array}
|
|
7055
|
-
|
|
7056
|
-
`pad_mode` is ``"pad"``:
|
|
7057
|
-
|
|
7058
|
-
.. math::
|
|
7059
|
-
\begin{array}{ll} \\
|
|
7060
|
-
D_{out} = \left \lfloor{\frac{D_{in} + padding[0] + padding[1] - (\text{dilation[0]} - 1) \times
|
|
7061
|
-
\text{kernel_size[0]} - 1 }{\text{stride[0]}} + 1} \right \rfloor \\
|
|
7062
|
-
H_{out} = \left \lfloor{\frac{H_{in} + padding[2] + padding[3] - (\text{dilation[1]} - 1) \times
|
|
7063
|
-
\text{kernel_size[1]} - 1 }{\text{stride[1]}} + 1} \right \rfloor \\
|
|
7064
|
-
W_{out} = \left \lfloor{\frac{W_{in} + padding[4] + padding[5] - (\text{dilation[2]} - 1) \times
|
|
7065
|
-
\text{kernel_size[2]} - 1 }{\text{stride[2]}} + 1} \right \rfloor \\
|
|
7066
|
-
\end{array}
|
|
7263
|
+
To see how different pad modes affect the output shape, please refer to
|
|
7264
|
+
:class:`mindspore.nn.Conv3d` for more details.
|
|
7067
7265
|
|
|
7068
7266
|
Raises:
|
|
7069
7267
|
TypeError: If `out_channel` or `groups` is not an int.
|
|
@@ -7206,10 +7404,11 @@ def conv3d_ext(input, weight, bias=None, stride=1, padding=0, dilation=1, groups
|
|
|
7206
7404
|
kw)`, then the shape is :math:`(C_{out}, C_{in} / groups, kd, kh, kw)`.
|
|
7207
7405
|
bias (Tensor, optional): Bias Tensor with shape :math:`(C_{out})`.
|
|
7208
7406
|
When bias is ``None`` , zeros will be used. Default: ``None`` .
|
|
7209
|
-
stride (Union(int, tuple[int]), optional): The distance of kernel moving, an int
|
|
7210
|
-
the depth, the height and width of movement are both strides, or a
|
|
7407
|
+
stride (Union(int, tuple[int], list[int]), optional): The distance of kernel moving, an int
|
|
7408
|
+
number that represents the depth, the height and width of movement are both strides, or a
|
|
7409
|
+
tuple of triple int numbers that
|
|
7211
7410
|
represent the depth, height and width of movement respectively. Default: ``1`` .
|
|
7212
|
-
padding (Union(int, tuple[int], str), optional): Implicit paddings on both sides of the input `x`.
|
|
7411
|
+
padding (Union(int, tuple[int], list[int], str), optional): Implicit paddings on both sides of the input `x`.
|
|
7213
7412
|
Can be a string, one integer or a tuple/list with 3 integers.
|
|
7214
7413
|
If `padding` is a string, the optional values are ``"same"`` , ``"valid"``.
|
|
7215
7414
|
|
|
@@ -7224,7 +7423,8 @@ def conv3d_ext(input, weight, bias=None, stride=1, padding=0, dilation=1, groups
|
|
|
7224
7423
|
If `padding` is one integer, the paddings of top, bottom, left and right are the same, equal to padding.
|
|
7225
7424
|
If `padding` is a tuple/list with 3 integers, the padding of head, tail, top, bottom,
|
|
7226
7425
|
left and right equal to pad[0], pad[0], pad[1], pad[1], pad[2] and pad[2] correspondingly. Default: ``0`` .
|
|
7227
|
-
dilation (Union[int, tuple[int]], optional): Controlling the space between the kernel points.
|
|
7426
|
+
dilation (Union[int, tuple[int], list[int]], optional): Controlling the space between the kernel points.
|
|
7427
|
+
Default: ``1`` .
|
|
7228
7428
|
groups (int, optional): Splits `input` into groups. Default: ``1`` .
|
|
7229
7429
|
|
|
7230
7430
|
Returns:
|
|
@@ -7450,9 +7650,6 @@ def glu_ext(input, dim=-1):
|
|
|
7450
7650
|
Here :math:`\sigma` is the sigmoid function, and :math:`\otimes` is the Hadamard product.
|
|
7451
7651
|
See `Language Modeling with Gated Convluational Networks <https://arxiv.org/abs/1612.08083>`_.
|
|
7452
7652
|
|
|
7453
|
-
.. warning::
|
|
7454
|
-
This is an experimental API that is subject to change or deletion.
|
|
7455
|
-
|
|
7456
7653
|
Args:
|
|
7457
7654
|
input (Tensor): Tensor to be calculated. Dtype is floating point and the shape
|
|
7458
7655
|
is :math:`(\ast_1, N, \ast_2)` where `*` means, any number of additional dimensions. :math:`N`
|
|
@@ -7461,6 +7658,9 @@ def glu_ext(input, dim=-1):
|
|
|
7461
7658
|
dim (int, optional): The dimension to split the input `input`. The value range is `[-r, r)` where `r`
|
|
7462
7659
|
is the number of dimensions of `input`. Default: ``-1`` , the last dimension in `input`.
|
|
7463
7660
|
|
|
7661
|
+
Returns:
|
|
7662
|
+
Tensor, the same dtype as the input `input`. The shape is :math:`(\ast_1, M, \ast_2)` where :math:`M=N/2`.
|
|
7663
|
+
|
|
7464
7664
|
Raises:
|
|
7465
7665
|
TypeError: If `input` is not a Tensor or `dim` is not an int.
|
|
7466
7666
|
IndexError: If the value of `dim` is out of the range of `[-r, r)`, where `r` is the number
|
|
@@ -7472,9 +7672,9 @@ def glu_ext(input, dim=-1):
|
|
|
7472
7672
|
``Ascend`` ``CPU``
|
|
7473
7673
|
|
|
7474
7674
|
Examples:
|
|
7475
|
-
>>> from mindspore import Tensor,
|
|
7476
|
-
>>> input = Tensor([[0.1,0.2,0.3,0.4],[0.5,0.6,0.7,0.8]])
|
|
7477
|
-
>>> output =
|
|
7675
|
+
>>> from mindspore import Tensor, ops
|
|
7676
|
+
>>> input = Tensor([[0.1, 0.2, 0.3, 0.4], [0.5, 0.6, 0.7, 0.8]])
|
|
7677
|
+
>>> output = ops.function.nn_func.glu_ext(input)
|
|
7478
7678
|
>>> print(output)
|
|
7479
7679
|
[[0.05744425 0.11973753]
|
|
7480
7680
|
[0.33409387 0.41398472]]
|
|
@@ -7642,7 +7842,8 @@ def multilabel_soft_margin_loss(input, target, weight=None, reduction='mean'):
|
|
|
7642
7842
|
Args:
|
|
7643
7843
|
input (Tensor): A tensor of shape :math:`(N, C)` , where N is batch size and C is number of classes.
|
|
7644
7844
|
target (Tensor): The label target Tensor which has the same shape as `input`.
|
|
7645
|
-
weight (Union[Tensor, int, float]): The manual rescaling weight given to each class.
|
|
7845
|
+
weight (Union[Tensor, int, float], optional): The manual rescaling weight given to each class.
|
|
7846
|
+
Default: ``None``.
|
|
7646
7847
|
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
7647
7848
|
``'sum'`` . Default: ``'mean'`` .
|
|
7648
7849
|
|
|
@@ -7759,30 +7960,19 @@ def channel_shuffle(x, groups):
|
|
|
7759
7960
|
shape in the final output.
|
|
7760
7961
|
|
|
7761
7962
|
Args:
|
|
7762
|
-
x (Tensor):
|
|
7763
|
-
with float16, float32, int8, int16, int32, int64, uint8, uint16, uint32, uint64 data type.
|
|
7963
|
+
x (Tensor): The input tensor.
|
|
7764
7964
|
groups (int): Number of groups to divide channels in.
|
|
7765
7965
|
|
|
7766
7966
|
Returns:
|
|
7767
|
-
|
|
7768
|
-
|
|
7769
|
-
Raises:
|
|
7770
|
-
TypeError: If data type of `x` is not one of the following:
|
|
7771
|
-
float16, float32, int8, int16, int32, int64, uint8, uint16, uint32, uint64.
|
|
7772
|
-
TypeError: If dim of `x` is < 4.
|
|
7773
|
-
TypeError: If `groups` is not a positive number.
|
|
7774
|
-
ValueError: If channel number of `x` is not divisible by `groups`.
|
|
7967
|
+
Tensor
|
|
7775
7968
|
|
|
7776
7969
|
Supported Platforms:
|
|
7777
7970
|
``Ascend`` ``CPU``
|
|
7778
7971
|
|
|
7779
7972
|
Examples:
|
|
7780
7973
|
>>> import mindspore
|
|
7781
|
-
>>>
|
|
7782
|
-
>>>
|
|
7783
|
-
>>> group = 2
|
|
7784
|
-
>>> x = Tensor(np.arange(1* 4 * 2 * 2).reshape(1, 4, 2, 2).astype(np.int16))
|
|
7785
|
-
>>> y = mindspore.ops.channel_shuffle(x, group)
|
|
7974
|
+
>>> x = mindspore.tensor(mindspore.ops.arange(0, 16, dtype=mindspore.int16).reshape(1, 4, 2, 2))
|
|
7975
|
+
>>> y = mindspore.ops.channel_shuffle(x, groups=2)
|
|
7786
7976
|
>>> print(y)
|
|
7787
7977
|
[[[[ 0 1]
|
|
7788
7978
|
[ 2 3]]
|
|
@@ -8135,35 +8325,36 @@ def mse_loss(input, target, reduction='mean'):
|
|
|
8135
8325
|
|
|
8136
8326
|
def msort(input):
|
|
8137
8327
|
r"""
|
|
8138
|
-
|
|
8139
|
-
|
|
8140
|
-
ops.msort(t) is equivalent to ops.Sort(axis=0)(t)[0]. See also :class:`mindspore.ops.Sort()`.
|
|
8328
|
+
Return a tensor obtained by sorting the input tensor in ascending order along its first dimension.
|
|
8141
8329
|
|
|
8142
|
-
|
|
8143
|
-
|
|
8330
|
+
`ops.msort(input)` is equivalent to `ops.sort(axis=0)(input)[0]`. See also :class:`mindspore.ops.Sort()` for more
|
|
8331
|
+
details.
|
|
8144
8332
|
|
|
8145
8333
|
Args:
|
|
8146
|
-
input (Tensor): The input to sort
|
|
8334
|
+
input (Tensor): The input tensor to sort.
|
|
8147
8335
|
|
|
8148
8336
|
Returns:
|
|
8149
|
-
|
|
8150
|
-
|
|
8151
|
-
Raises:
|
|
8152
|
-
TypeError: If dtype of `input` is neither float16 nor float32.
|
|
8337
|
+
Tensor
|
|
8153
8338
|
|
|
8154
8339
|
Supported Platforms:
|
|
8155
8340
|
``Ascend`` ``GPU`` ``CPU``
|
|
8156
8341
|
|
|
8157
8342
|
Examples:
|
|
8158
|
-
>>> import mindspore
|
|
8159
|
-
>>>
|
|
8160
|
-
|
|
8161
|
-
|
|
8162
|
-
>>>
|
|
8163
|
-
|
|
8164
|
-
[[4
|
|
8165
|
-
[5
|
|
8166
|
-
[8
|
|
8343
|
+
>>> import mindspore
|
|
8344
|
+
>>> input = mindspore.tensor([[8, 2, 1],
|
|
8345
|
+
... [5, 9, 3],
|
|
8346
|
+
... [4, 6, 7]])
|
|
8347
|
+
>>> mindspore.ops.msort(input)
|
|
8348
|
+
Tensor(shape=[3, 3], dtype=Int64, value=
|
|
8349
|
+
[[4, 2, 1],
|
|
8350
|
+
[5, 6, 3],
|
|
8351
|
+
[8, 9, 7]])
|
|
8352
|
+
>>> # is equivalent to `ops.sort(axis=0)(input)[0]`
|
|
8353
|
+
>>> mindspore.ops.sort(input, axis=0)[0]
|
|
8354
|
+
Tensor(shape=[3, 3], dtype=Int64, value=
|
|
8355
|
+
[[4, 2, 1],
|
|
8356
|
+
[5, 6, 3],
|
|
8357
|
+
[8, 9, 7]])
|
|
8167
8358
|
"""
|
|
8168
8359
|
return ops.Sort(axis=0)(input)[0]
|
|
8169
8360
|
|
|
@@ -9168,6 +9359,215 @@ def embedding(input, weight, padding_idx=None, max_norm=None, norm_type=2.0, sca
|
|
|
9168
9359
|
return embedding_op(input, weight, padding_idx, max_norm, norm_type, scale_grad_by_freq)
|
|
9169
9360
|
|
|
9170
9361
|
|
|
9362
|
+
def speed_fusion_attention(query, key, value, head_num, input_layout, *, pse=None, padding_mask=None, atten_mask=None,
|
|
9363
|
+
scale=1.0, keep_prob=1.0, pre_tokens=2147483647, next_tokens=2147483647, inner_precise=0,
|
|
9364
|
+
prefix=None, actual_seq_qlen=None, actual_seq_kvlen=None, sparse_mode=0,
|
|
9365
|
+
gen_mask_parallel=True, sync=False, pse_type=1, q_start_idx=None, kv_start_idx=None):
|
|
9366
|
+
r"""
|
|
9367
|
+
The interface is used for self-attention fusion computing.
|
|
9368
|
+
If `pse_type` is ``1`` , calculation formula is:
|
|
9369
|
+
|
|
9370
|
+
.. math::
|
|
9371
|
+
attention\_out = Dropout(Softmax(Mask(scale * (pse + query * key^{T}), atten\_mask)), keep\_prob) * value
|
|
9372
|
+
|
|
9373
|
+
If `pse_type` is other valid value, calculation formula is:
|
|
9374
|
+
|
|
9375
|
+
.. math::
|
|
9376
|
+
attention\_out = Dropout(Softmax(Mask(scale * (query * key^{T}) + pse, atten\_mask)), keep\_prob) * value
|
|
9377
|
+
|
|
9378
|
+
- B: Batch size. Value range 1 to 2k.
|
|
9379
|
+
- S1: Sequence length of query. Value range 1 to 512k.
|
|
9380
|
+
- S2: Sequence length of key and value. Value range 1 to 512k.
|
|
9381
|
+
- N1: Num heads of query. Value range 1 to 256.
|
|
9382
|
+
- N2: Num heads of key and value, and N2 must be a factor of N1.
|
|
9383
|
+
- D: Head size. The value ranges is a multiple of 16, with the max value of 512.
|
|
9384
|
+
- H1: Hidden size of query, which equals to N1 * D.
|
|
9385
|
+
- H2: Hidden size of key and value, which equals to N2 * D.
|
|
9386
|
+
|
|
9387
|
+
.. warning::
|
|
9388
|
+
- This is an experimental API that is subject to change or deletion.
|
|
9389
|
+
- Only support on Atlas A2 training series.
|
|
9390
|
+
|
|
9391
|
+
Note:
|
|
9392
|
+
This interface is not supported in `graph mode (mode=mindspore.GRAPH_MODE)
|
|
9393
|
+
<https://www.mindspore.cn/tutorials/en/master/compile/static_graph.html>`_.
|
|
9394
|
+
|
|
9395
|
+
Args:
|
|
9396
|
+
query (Tensor): The query tensor. Input tensor of shape :math:`(B, S1, H1)`,
|
|
9397
|
+
:math:`(B, N1, S1, D)`, :math:`(S1, B, H1)`, :math:`(B, S1, N1, D)` or :math:`(T1, N1, D)`.
|
|
9398
|
+
key (Tensor): The key tensor. Input tensor of shape :math:`(B, S2, H2)`,
|
|
9399
|
+
:math:`(B, N2, S2, D)`, :math:`(S2, B, H2)`, :math:`(B, S2, N2, D)` or :math:`(T2, N2, D)`.
|
|
9400
|
+
value (Tensor): The value tensor. Input tensor of shape :math:`(B, S2, H2)`,
|
|
9401
|
+
:math:`(B, N2, S2, D)`, :math:`(S2, B, H2)`, :math:`(B, S2, N2, D)` or :math:`(T2, N2, D)`.
|
|
9402
|
+
The `key` and `value` should have the same shape.
|
|
9403
|
+
head_num (int): The head num of query, equal to N1.
|
|
9404
|
+
input_layout (str): Specifies the layout of input `query`, `key` and `value`. The value can be ``"BSH"`` ,
|
|
9405
|
+
``"BNSD"`` , ``"SBH"`` , ``"BSND"`` or ``"TND"`` . ``"TND"`` is an experimental format.
|
|
9406
|
+
When `input_layout` is ``"TND"`` , the following restrictions must be met.
|
|
9407
|
+
There are two lists that represent the length of the input sequence: list_seq_q and list_seq_k. Each
|
|
9408
|
+
value in the list indicates the length of the sequence in the batch. For example, list_seq_q = [4, 2, 6],
|
|
9409
|
+
list_seq_k = [10, 3, 9]. The element of list indicate S. T1 is sum(list_seq_q) = 12, T2 is
|
|
9410
|
+
sum(list_seq_k) = 22.
|
|
9411
|
+
max_seqlen_q = max(list_seq_q), max_seqlen_k = max(list_seq_k).
|
|
9412
|
+
qk_pointer = sum(list_seq_q * list_seq_k), which is the sum of the element multiplication.
|
|
9413
|
+
|
|
9414
|
+
- The lengths of two lists are the same, and size of list is batch. batch is less than or equal to 1024.
|
|
9415
|
+
- When `input_layout` is ``"TND"`` , `actual_seq_qlen` and `actual_seq_kvlen` must be not ``None`` .
|
|
9416
|
+
Otherwise, they are ``None`` .
|
|
9417
|
+
- The `actual_seq_qlen` and `actual_seq_kvlen` are the cumulative sum of sequence of key/value, so they must
|
|
9418
|
+
be non-decreasing.
|
|
9419
|
+
- If `pse` is not ``None`` , list_seq_q and list_seq_k must be same. The maximum value of list_seq_q and
|
|
9420
|
+
list_seq_k is greater than 1024. `pse` should be :math:`(B, N1, 1024, S2)` and
|
|
9421
|
+
:math:`(1, N1, 1024, S2)`, and S2 is equal to max_seqlen_k.
|
|
9422
|
+
- `atten_mask` must be a lower trianglar matrix, so `sparse_mode` should be 2 or 3. The shape of
|
|
9423
|
+
`atten_mask` should be :math:`(2048, 2048)`.
|
|
9424
|
+
- Prefix is ``None`` .
|
|
9425
|
+
- `next_tokens` is 0, and `pre_tokens` is not less than max_seqlen_q.
|
|
9426
|
+
- When `sparse_mode` is 3, S1 of each batch should be less than or equal to S2.
|
|
9427
|
+
- 0 should not exist in list_seq_k.
|
|
9428
|
+
|
|
9429
|
+
Keyword Args:
|
|
9430
|
+
pse (Tensor, optional): The position embedding code, dtype is same as `query`. Default: ``None`` .
|
|
9431
|
+
If S is greater than 1024 and the mask of the lower triangle is used, enter only the inverse 1024 lines of
|
|
9432
|
+
the lower triangle for memory optimization. Input tensor of shape :math:`(B, N1, S1, S2)`,
|
|
9433
|
+
:math:`(1, N1, S1, S2)`, :math:`(B, N1, 1024, S2)`, :math:`(1, N1, 1024, S2)`.
|
|
9434
|
+
|
|
9435
|
+
- ALiBi scenario: `pse` must meet the ALiBi rule, and `sparse_mode` is 2 or 3 for the lower triangle.
|
|
9436
|
+
In this scenario, `pse` is :math:`(B, N1, 1024, S2)`, :math:`(1, N1, 1024, S2)`.
|
|
9437
|
+
- Non-ALiBi scenario: `pse` is :math:`(B, N1, S1, S2)`, :math:`(1, N1, S1, S2)`.
|
|
9438
|
+
- The shape of `pse` should be :math:`(B, N1, 1024, S2)` and :math:`(1, N1, 1024, S2)` when `input_layout`
|
|
9439
|
+
is ``"TND"`` .
|
|
9440
|
+
- If `pse_type` is 2 or 3, dtype of `pse` must be float32, and shape of `pse` should be :math:`(B, N1)` or
|
|
9441
|
+
:math:`(N1,)`.
|
|
9442
|
+
|
|
9443
|
+
padding_mask (Tensor, optional): Reserved parameter. Not implemented yet. Default: ``None`` .
|
|
9444
|
+
atten_mask (Tensor, optional): The attention mask tensor. For each element, 0/False indicates retention and
|
|
9445
|
+
1/True indicates discard. Input tensor of shape :math:`(B, N1, S1, S2)`, :math:`(B, 1, S1, S2)`,
|
|
9446
|
+
:math:`(S1, S2)` or :math:`(2048, 2048)`. Default: ``None`` .
|
|
9447
|
+
|
|
9448
|
+
- In compression scenario, `sparse_mode` is 2, 3, or 4, `atten_mask` must be :math:`(2048, 2048)`.
|
|
9449
|
+
- When `sparse_mode` is 5, `atten_mask` must be :math:`(B, N1, S1, S2)`, :math:`(B, 1, S1, S2)`.
|
|
9450
|
+
- When `sparse_mode` is 0 and 1, `atten_mask` should be :math:`(B, N1, S1, S2)`, :math:`(B, 1, S1, S2)`,
|
|
9451
|
+
:math:`(S1, S2)`.
|
|
9452
|
+
|
|
9453
|
+
scale (float, optional): The scale factor of score. Generally, the value is 1.0 / (D ** 0.5). Default: ``1.0`` .
|
|
9454
|
+
keep_prob (float, optional): The keep probability of dropout. Value range is (0.0, 1.0]. Default: ``1.0`` .
|
|
9455
|
+
pre_tokens (int, optional): Parameter for sparse computation, represents how many tokens are counted forward.
|
|
9456
|
+
When `sparse_mode` is set to 1, 2, 3, or 5, this parameter does not take effect. Default: ``2147483647`` .
|
|
9457
|
+
next_tokens (int, optional): Parameter for sparse computation, represents how many tokens are counted backward.
|
|
9458
|
+
When `sparse_mode` is set to 1, 2, 3, or 5, this parameter does not take effect. Default: ``2147483647`` .
|
|
9459
|
+
The value of pre_tokens corresponds to S1, and the value of next_tokens corresponds to S2. They define the
|
|
9460
|
+
valid area on the `atten_mask` matrix. It must ensure that the band is not empty.
|
|
9461
|
+
The following values are not allowed:
|
|
9462
|
+
|
|
9463
|
+
- pre_tokens < 0 and next_tokens < 0.
|
|
9464
|
+
- (pre_tokens < 0 and next_tokens >= 0) and (next_tokens < abs(pre_tokens) or abs(pre_tokens) >= S2).
|
|
9465
|
+
- (pre_tokens >= 0 and next_tokens < 0) and (abs(next_tokens) > pre_tokens or abs(next_tokens) >= S1).
|
|
9466
|
+
|
|
9467
|
+
inner_precise (int, optional): The parameter is reserved and not implemented yet. Default: ``0`` .
|
|
9468
|
+
prefix (Union[tuple[int], list[int]], optional): N value of each Batch in the prefix sparse calculation
|
|
9469
|
+
scenario. Input tensor of shape :math:`(B,)`. B max value 32. Not none only when sparse_mode is 5.
|
|
9470
|
+
If S1 > S2, N ranges from 0 to S2. If S1 <= S2, N ranges from S2 - S1 to S2. Default: ``None`` .
|
|
9471
|
+
actual_seq_qlen (Union[tuple[int], list[int]], optional): Size of query corresponding to each batch, array
|
|
9472
|
+
with increasing values and the last value equal to T1. Default: ``None`` .
|
|
9473
|
+
actual_seq_kvlen (Union[tuple[int], list[int]], optional): Size of key and value corresponding to each batch,
|
|
9474
|
+
array with increasing values and the last value equal to T2. Default: ``None`` .
|
|
9475
|
+
sparse_mode (int, optional): Indicates sparse mode. Default ``0`` .
|
|
9476
|
+
|
|
9477
|
+
- 0: Indicates the defaultMask mode. If `atten_mask` is not passed, the mask operation is not performed,
|
|
9478
|
+
and preTokens and nextTokens(internally assigned as INT_MAX) are ignored. If passed in, the full
|
|
9479
|
+
`atten_mask` matrix (S1 * S2) needs to be passed in, indicating that the part between preTokens and
|
|
9480
|
+
nextTokens needs to be calculated.
|
|
9481
|
+
- 1: Represents allMask, that is, passing in the complete `atten_mask` matrix.
|
|
9482
|
+
- 2: Representing the leftUpCausal mode corresponds to the lower triangle scenario divided by the left
|
|
9483
|
+
vertex, and the optimized `atten_mask` matrix (2048*2048) is required.
|
|
9484
|
+
- 3: Representing the rightDownCausal model corresponds to the lower triangle scene divided by the lower
|
|
9485
|
+
right vertex, and the optimized `atten_mask` matrix (2048*2048) is required.
|
|
9486
|
+
- 4: Represents the band scenario, that is, the part between counting preTokens and nextTokens, and the
|
|
9487
|
+
optimized `atten_mask` matrix (2048*2048) is required.
|
|
9488
|
+
- 5: Represents the prefix scenario, that is, on the basis of rightDownCasual, a matrix with length S1 and
|
|
9489
|
+
width N is added to the left side. The value of N is obtained by the new input prefix, and the N value
|
|
9490
|
+
of each Batch axis is different. Currently not enabled.
|
|
9491
|
+
- 6: Represents the global scenario. Currently not enabled.
|
|
9492
|
+
- 7: Represents the dilated scenario. Currently not enabled.
|
|
9493
|
+
- 8: Represents the block_local scenario. Currently not enabled.
|
|
9494
|
+
|
|
9495
|
+
gen_mask_parallel (bool, optional): Debug parameter, a switch to control dropout_gen_mask execution method.
|
|
9496
|
+
If ``True`` , dropout_gen_mask is executed in parallel. If ``False`` , execution is serial.
|
|
9497
|
+
Not implemented yet. Default: ``True`` .
|
|
9498
|
+
sync (bool, optional): Debug parameter, a switch to control dropout_gen_mask execution method.
|
|
9499
|
+
If ``True`` , dropout_gen_mask is executed synchronously. If ``False`` , execution is asynchronous.
|
|
9500
|
+
Not implemented yet. Default: ``False`` .
|
|
9501
|
+
pse_type (int, optional): Indicates how to use `pse`. Default ``1`` .
|
|
9502
|
+
|
|
9503
|
+
- 0: `pse` is passed from outside, and the calculation process is to first mul `scale` and then add `pse`.
|
|
9504
|
+
- 1: `pse` is passed from outside, and the calculation process is to add `pse` first and then mul `scale`.
|
|
9505
|
+
- 2: `pse` is generated internally and generates standard alibi position information. The internally
|
|
9506
|
+
generated alibi matrix 0 line is aligned with the upper left corner of :math:`query * key^{T}`.
|
|
9507
|
+
- 3: `pse` is generated internally, and the generated alibi position information is based on the standard
|
|
9508
|
+
and then the square root of sqrt is done. The internally generated alibi matrix 0 line is aligned with
|
|
9509
|
+
the upper left corner of :math:`query * key^{T}`.
|
|
9510
|
+
|
|
9511
|
+
q_start_idx (Union[tuple[int], list[int]], optional): Int array with length 1. Default: ``None`` .
|
|
9512
|
+
When pse_type is configured as ``2`` or ``3`` , it indicates the number of cells that the internally
|
|
9513
|
+
generated alibi code is offset in the S1 direction. A positive number indicates that 0 moves diagonally
|
|
9514
|
+
upward.
|
|
9515
|
+
kv_start_idx (Union[tuple[int], list[int]], optional): Int array with length 1. Default: ``None`` .
|
|
9516
|
+
When pse_type is configured as ``2`` or ``3`` , it indicates the number of cells that the internally
|
|
9517
|
+
generated alibi code is offset in the S2 direction. A positive number indicates that 0 moves diagonally
|
|
9518
|
+
upward.
|
|
9519
|
+
|
|
9520
|
+
Returns:
|
|
9521
|
+
A tuple of tensors containing `attention_out`, `softmax_max`, `softmax_sum`, `softmax_out`, `seed`, `offset`
|
|
9522
|
+
and `numels` .
|
|
9523
|
+
|
|
9524
|
+
- `attention_out` is the output of attention, it's shape, and data type are the same as the query.
|
|
9525
|
+
- `softmax_max` is the max intermediate result calculated by Softmax, used for grad calculation.
|
|
9526
|
+
- `softmax_sum` is the sum intermediate result calculated by Softmax, used for grad calculation.
|
|
9527
|
+
- `softmax_out` is a reserved parameter.
|
|
9528
|
+
- `seed` is generated seed, used for Dropout.
|
|
9529
|
+
- `offset` is generated offset, used for Dropout.
|
|
9530
|
+
- `numels` is the length of generated dropout_mask.
|
|
9531
|
+
|
|
9532
|
+
Raises:
|
|
9533
|
+
TypeError: `query`, `key` and `value` don't have the same dtype.
|
|
9534
|
+
TypeError: Dtype of `atten_mask` is not bool or uint8.
|
|
9535
|
+
TypeError: `scale` or `keep_prob` is not a float number.
|
|
9536
|
+
TypeError: `input_layout` is not a string.
|
|
9537
|
+
TypeError: `head_num` is not an int.
|
|
9538
|
+
TypeError: `sparse_mode` is not an int.
|
|
9539
|
+
TypeError: `pse` is not Tensor type.
|
|
9540
|
+
TypeError: `padding_mask` is not Tensor type.
|
|
9541
|
+
TypeError: `atten_mask` is not Tensor type.
|
|
9542
|
+
TypeError: `pse_type` is not an int.
|
|
9543
|
+
ValueError: `input_layout` is a string but not valid.
|
|
9544
|
+
ValueError: The specified value of `sparse_mode` is invalid.
|
|
9545
|
+
ValueError: The specified value of `pse_type` is invalid.
|
|
9546
|
+
|
|
9547
|
+
Supported Platforms:
|
|
9548
|
+
``Ascend``
|
|
9549
|
+
|
|
9550
|
+
Examples:
|
|
9551
|
+
>>> import mindspore
|
|
9552
|
+
>>> import mindspore.common.dtype as mstype
|
|
9553
|
+
>>> import numpy as np
|
|
9554
|
+
>>> from mindspore import ops, Tensor
|
|
9555
|
+
>>> query = Tensor(np.ones([2, 4, 64]), dtype=mstype.float16)
|
|
9556
|
+
>>> key = Tensor(np.ones([2, 4, 64]), dtype=mstype.float16)
|
|
9557
|
+
>>> value = Tensor(np.ones([2, 4, 64]), dtype=mstype.float16)
|
|
9558
|
+
>>> head_num = 4
|
|
9559
|
+
>>> input_layout = "BSH"
|
|
9560
|
+
>>> output = ops.speed_fusion_attention(query, key, value, head_num, input_layout)
|
|
9561
|
+
>>> print(output[0].shape)
|
|
9562
|
+
(2, 4, 64)
|
|
9563
|
+
"""
|
|
9564
|
+
seed, offset = default_generator._step(generator_step_) # pylint: disable=protected-access
|
|
9565
|
+
return speed_fusion_attention_op(query, key, value, head_num, input_layout, seed, offset, pse, padding_mask,
|
|
9566
|
+
atten_mask, scale, keep_prob, pre_tokens, next_tokens, inner_precise, prefix,
|
|
9567
|
+
actual_seq_qlen, actual_seq_kvlen, sparse_mode, gen_mask_parallel, sync, pse_type,
|
|
9568
|
+
q_start_idx, kv_start_idx)
|
|
9569
|
+
|
|
9570
|
+
|
|
9171
9571
|
__all__ = [
|
|
9172
9572
|
'adaptive_avg_pool1d',
|
|
9173
9573
|
'adaptive_avg_pool2d',
|
|
@@ -9198,6 +9598,7 @@ __all__ = [
|
|
|
9198
9598
|
'fast_gelu',
|
|
9199
9599
|
'fractional_max_pool2d',
|
|
9200
9600
|
'fractional_max_pool3d',
|
|
9601
|
+
'speed_fusion_attention',
|
|
9201
9602
|
'pixel_shuffle',
|
|
9202
9603
|
'pixel_unshuffle',
|
|
9203
9604
|
'hardshrink',
|
|
@@ -9205,6 +9606,7 @@ __all__ = [
|
|
|
9205
9606
|
'incre_flash_attention',
|
|
9206
9607
|
'prompt_flash_attention',
|
|
9207
9608
|
'flash_attention_score',
|
|
9609
|
+
'fused_infer_attention_score',
|
|
9208
9610
|
'flip',
|
|
9209
9611
|
'fliplr',
|
|
9210
9612
|
'flipud',
|
|
@@ -9225,7 +9627,6 @@ __all__ = [
|
|
|
9225
9627
|
'softplus',
|
|
9226
9628
|
'selu',
|
|
9227
9629
|
'silu',
|
|
9228
|
-
'soft_margin_loss',
|
|
9229
9630
|
'softmax',
|
|
9230
9631
|
'softmin',
|
|
9231
9632
|
'pdist',
|
|
@@ -9247,6 +9648,7 @@ __all__ = [
|
|
|
9247
9648
|
'conv2d',
|
|
9248
9649
|
'conv_transpose2d',
|
|
9249
9650
|
'sigmoid',
|
|
9651
|
+
'soft_margin_loss',
|
|
9250
9652
|
'logsigmoid',
|
|
9251
9653
|
'relu',
|
|
9252
9654
|
'relu6',
|
|
@@ -9264,6 +9666,8 @@ __all__ = [
|
|
|
9264
9666
|
'gaussian_nll_loss',
|
|
9265
9667
|
'lp_pool1d',
|
|
9266
9668
|
'lp_pool2d',
|
|
9669
|
+
'moe_token_permute',
|
|
9670
|
+
'moe_token_unpermute',
|
|
9267
9671
|
'max_unpool1d',
|
|
9268
9672
|
'max_unpool2d',
|
|
9269
9673
|
'max_unpool3d',
|