mindspore 2.7.0rc1__cp311-cp311-win_amd64.whl → 2.7.1__cp311-cp311-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of mindspore might be problematic. Click here for more details.
- mindspore/.commit_id +1 -1
- mindspore/__init__.py +5 -2
- mindspore/_c_dataengine.cp311-win_amd64.pyd +0 -0
- mindspore/_c_expression.cp311-win_amd64.pyd +0 -0
- mindspore/_c_mindrecord.cp311-win_amd64.pyd +0 -0
- mindspore/_checkparam.py +2 -2
- mindspore/_extends/builtin_operations.py +3 -3
- mindspore/_extends/parallel_compile/akg_compiler/custom.py +1109 -0
- mindspore/_extends/parallel_compile/akg_compiler/gen_custom_op_files.py +1 -1
- mindspore/_extends/parse/__init__.py +3 -3
- mindspore/_extends/parse/compile_config.py +24 -1
- mindspore/_extends/parse/deprecated/deprecated_tensor_method.py +6 -3
- mindspore/_extends/parse/parser.py +28 -22
- mindspore/_extends/parse/resources.py +1 -1
- mindspore/_extends/parse/standard_method.py +23 -2
- mindspore/_extends/parse/trope.py +2 -1
- mindspore/_extends/pijit/pijit_func_white_list.py +9 -27
- mindspore/amp.py +0 -18
- 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/base.py +29 -2
- mindspore/common/__init__.py +18 -12
- mindspore/common/_decorator.py +3 -2
- mindspore/common/_grad_function.py +3 -1
- mindspore/common/_tensor_cpp_method.py +1 -1
- mindspore/common/_tensor_docs.py +371 -96
- mindspore/common/_utils.py +7 -43
- mindspore/common/api.py +434 -135
- mindspore/common/dtype.py +98 -57
- mindspore/common/dump.py +7 -108
- mindspore/common/dynamic_shape/__init__.py +0 -0
- mindspore/common/{auto_dynamic_shape.py → dynamic_shape/auto_dynamic_shape.py} +15 -23
- mindspore/common/dynamic_shape/enable_dynamic.py +197 -0
- mindspore/common/file_system.py +59 -9
- mindspore/common/hook_handle.py +82 -3
- mindspore/common/jit_config.py +5 -1
- mindspore/common/jit_trace.py +27 -12
- mindspore/common/lazy_inline.py +5 -3
- mindspore/common/np_dtype.py +3 -3
- mindspore/common/parameter.py +17 -127
- mindspore/common/recompute.py +4 -13
- mindspore/common/tensor.py +50 -217
- mindspore/communication/_comm_helper.py +11 -1
- mindspore/communication/comm_func.py +138 -4
- mindspore/communication/management.py +85 -1
- mindspore/config/op_info.config +0 -15
- mindspore/context.py +20 -106
- mindspore/dataset/__init__.py +1 -1
- mindspore/dataset/audio/transforms.py +1 -1
- mindspore/dataset/core/config.py +35 -1
- mindspore/dataset/engine/datasets.py +338 -319
- mindspore/dataset/engine/datasets_user_defined.py +38 -22
- mindspore/dataset/engine/datasets_vision.py +1 -1
- mindspore/dataset/engine/validators.py +1 -15
- mindspore/dataset/transforms/c_transforms.py +2 -2
- mindspore/dataset/transforms/transforms.py +3 -3
- mindspore/dataset/vision/__init__.py +1 -1
- mindspore/dataset/vision/py_transforms.py +8 -8
- mindspore/dataset/vision/transforms.py +17 -5
- mindspore/dataset/vision/utils.py +632 -21
- mindspore/device_context/ascend/op_tuning.py +35 -1
- mindspore/dnnl.dll +0 -0
- mindspore/{profiler/common/validator → graph}/__init__.py +9 -1
- mindspore/graph/custom_pass.py +55 -0
- mindspore/include/api/cell.h +28 -4
- mindspore/include/api/cfg.h +24 -7
- mindspore/include/api/context.h +1 -0
- mindspore/include/api/delegate.h +0 -2
- mindspore/include/api/dual_abi_helper.h +100 -19
- mindspore/include/api/graph.h +14 -1
- mindspore/include/api/kernel.h +16 -3
- mindspore/include/api/kernel_api.h +9 -1
- mindspore/include/api/metrics/accuracy.h +9 -0
- mindspore/include/api/model.h +5 -1
- mindspore/include/api/model_group.h +4 -0
- mindspore/include/api/model_parallel_runner.h +2 -0
- mindspore/include/api/status.h +48 -10
- mindspore/include/api/types.h +6 -1
- mindspore/include/dataset/constants.h +9 -0
- mindspore/include/dataset/execute.h +2 -2
- mindspore/jpeg62.dll +0 -0
- mindspore/mindrecord/__init__.py +3 -3
- mindspore/mindrecord/common/exceptions.py +1 -0
- mindspore/mindrecord/config.py +1 -1
- mindspore/{parallel/mpi → mindrecord/core}/__init__.py +4 -1
- mindspore/mindrecord/{shardheader.py → core/shardheader.py} +2 -1
- mindspore/mindrecord/{shardindexgenerator.py → core/shardindexgenerator.py} +1 -1
- mindspore/mindrecord/{shardreader.py → core/shardreader.py} +2 -1
- mindspore/mindrecord/{shardsegment.py → core/shardsegment.py} +2 -2
- mindspore/mindrecord/{shardutils.py → core/shardutils.py} +1 -1
- mindspore/mindrecord/{shardwriter.py → core/shardwriter.py} +1 -1
- mindspore/mindrecord/filereader.py +4 -4
- mindspore/mindrecord/filewriter.py +5 -5
- mindspore/mindrecord/mindpage.py +2 -2
- mindspore/mindrecord/tools/cifar10.py +4 -3
- mindspore/mindrecord/tools/cifar100.py +1 -1
- mindspore/mindrecord/tools/cifar100_to_mr.py +1 -1
- mindspore/mindrecord/tools/cifar10_to_mr.py +6 -6
- mindspore/mindrecord/tools/csv_to_mr.py +1 -1
- mindspore/mindrecord/tools/imagenet_to_mr.py +1 -1
- mindspore/mindrecord/tools/mnist_to_mr.py +1 -1
- mindspore/mindrecord/tools/tfrecord_to_mr.py +1 -1
- mindspore/mindspore_backend_common.dll +0 -0
- mindspore/mindspore_backend_manager.dll +0 -0
- mindspore/mindspore_cluster.dll +0 -0
- mindspore/mindspore_common.dll +0 -0
- mindspore/mindspore_core.dll +0 -0
- mindspore/mindspore_cpu.dll +0 -0
- mindspore/mindspore_dump.dll +0 -0
- mindspore/mindspore_frontend.dll +0 -0
- mindspore/mindspore_glog.dll +0 -0
- mindspore/mindspore_hardware_abstract.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_ops_host.dll → mindspore_ops_cpu.dll} +0 -0
- mindspore/mindspore_profiler.dll +0 -0
- mindspore/mindspore_pyboost.dll +0 -0
- mindspore/mindspore_pynative.dll +0 -0
- mindspore/mindspore_runtime_pipeline.dll +0 -0
- mindspore/mindspore_runtime_utils.dll +0 -0
- mindspore/mindspore_tools.dll +0 -0
- mindspore/mint/__init__.py +15 -10
- mindspore/mint/distributed/__init__.py +4 -0
- mindspore/mint/distributed/distributed.py +392 -69
- mindspore/mint/nn/__init__.py +2 -16
- mindspore/mint/nn/functional.py +4 -110
- mindspore/mint/nn/layer/__init__.py +0 -2
- mindspore/mint/nn/layer/_functions.py +1 -2
- mindspore/mint/nn/layer/activation.py +0 -6
- mindspore/mint/nn/layer/basic.py +0 -47
- mindspore/mint/nn/layer/conv.py +10 -10
- mindspore/mint/nn/layer/normalization.py +11 -16
- mindspore/mint/nn/layer/pooling.py +0 -4
- mindspore/nn/__init__.py +1 -3
- mindspore/nn/cell.py +231 -239
- mindspore/nn/layer/activation.py +4 -2
- mindspore/nn/layer/basic.py +56 -14
- mindspore/nn/layer/container.py +16 -0
- mindspore/nn/layer/embedding.py +4 -169
- mindspore/nn/layer/image.py +1 -1
- mindspore/nn/layer/normalization.py +2 -1
- mindspore/nn/layer/thor_layer.py +4 -85
- mindspore/nn/optim/ada_grad.py +0 -1
- mindspore/nn/optim/adafactor.py +0 -1
- mindspore/nn/optim/adam.py +32 -127
- mindspore/nn/optim/adamax.py +0 -1
- mindspore/nn/optim/asgd.py +0 -1
- mindspore/nn/optim/ftrl.py +8 -102
- mindspore/nn/optim/lamb.py +1 -4
- mindspore/nn/optim/lars.py +0 -3
- mindspore/nn/optim/lazyadam.py +25 -218
- mindspore/nn/optim/momentum.py +5 -43
- mindspore/nn/optim/optimizer.py +6 -55
- mindspore/nn/optim/proximal_ada_grad.py +0 -1
- mindspore/nn/optim/rmsprop.py +0 -1
- mindspore/nn/optim/rprop.py +0 -1
- mindspore/nn/optim/sgd.py +0 -1
- mindspore/nn/optim/tft_wrapper.py +2 -4
- mindspore/nn/optim/thor.py +0 -2
- mindspore/nn/probability/bijector/bijector.py +7 -8
- mindspore/nn/probability/bijector/gumbel_cdf.py +2 -2
- mindspore/nn/probability/bijector/power_transform.py +20 -21
- mindspore/nn/probability/bijector/scalar_affine.py +5 -5
- mindspore/nn/probability/bijector/softplus.py +13 -14
- mindspore/nn/probability/distribution/_utils/utils.py +2 -2
- mindspore/nn/wrap/cell_wrapper.py +39 -5
- mindspore/nn/wrap/grad_reducer.py +4 -89
- mindspore/numpy/array_creations.py +4 -4
- mindspore/numpy/fft.py +9 -9
- mindspore/numpy/utils_const.py +1 -1
- mindspore/{nn/reinforcement → onnx}/__init__.py +5 -8
- mindspore/onnx/onnx_export.py +137 -0
- mindspore/opencv_core4110.dll +0 -0
- mindspore/opencv_imgcodecs4110.dll +0 -0
- mindspore/{opencv_imgproc452.dll → opencv_imgproc4110.dll} +0 -0
- mindspore/ops/__init__.py +2 -0
- mindspore/ops/_grad_experimental/grad_comm_ops.py +38 -2
- mindspore/ops/_grad_experimental/grad_inner_ops.py +0 -9
- mindspore/ops/_op_impl/aicpu/__init__.py +0 -10
- mindspore/ops/_op_impl/cpu/__init__.py +1 -5
- mindspore/ops/_op_impl/cpu/{buffer_append.py → joinedstr_op.py} +8 -8
- mindspore/ops/auto_generate/cpp_create_prim_instance_helper.py +28 -24
- mindspore/ops/auto_generate/gen_extend_func.py +6 -11
- mindspore/ops/auto_generate/gen_ops_def.py +385 -154
- mindspore/ops/auto_generate/gen_ops_prim.py +5676 -5167
- mindspore/ops/communication.py +97 -0
- mindspore/ops/composite/__init__.py +5 -2
- mindspore/ops/composite/base.py +16 -2
- mindspore/ops/composite/multitype_ops/__init__.py +3 -1
- mindspore/ops/composite/multitype_ops/_compile_utils.py +150 -8
- mindspore/ops/composite/multitype_ops/_constexpr_utils.py +1 -1
- mindspore/ops/composite/multitype_ops/add_impl.py +7 -0
- mindspore/ops/composite/multitype_ops/mod_impl.py +27 -0
- mindspore/ops/function/__init__.py +2 -0
- mindspore/ops/function/array_func.py +24 -18
- mindspore/ops/function/comm_func.py +3883 -0
- mindspore/ops/function/debug_func.py +7 -6
- mindspore/ops/function/grad/grad_func.py +4 -12
- mindspore/ops/function/math_func.py +89 -86
- mindspore/ops/function/nn_func.py +92 -313
- mindspore/ops/function/random_func.py +9 -18
- mindspore/ops/functional.py +4 -1
- mindspore/ops/functional_overload.py +377 -30
- mindspore/ops/operations/__init__.py +2 -5
- mindspore/ops/operations/_custom_ops_utils.py +7 -9
- mindspore/ops/operations/_inner_ops.py +12 -50
- mindspore/ops/operations/_rl_inner_ops.py +0 -933
- mindspore/ops/operations/array_ops.py +5 -50
- mindspore/ops/operations/comm_ops.py +95 -17
- mindspore/ops/operations/custom_ops.py +237 -22
- mindspore/ops/operations/debug_ops.py +33 -35
- mindspore/ops/operations/manually_defined/ops_def.py +39 -318
- mindspore/ops/operations/math_ops.py +5 -5
- mindspore/ops/operations/nn_ops.py +3 -3
- mindspore/ops/operations/sparse_ops.py +0 -83
- mindspore/ops/primitive.py +4 -27
- mindspore/ops/tensor_method.py +88 -10
- mindspore/ops_generate/aclnn/aclnn_kernel_register_auto_cc_generator.py +5 -5
- mindspore/ops_generate/aclnn/gen_aclnn_implement.py +8 -8
- mindspore/ops_generate/api/functions_cc_generator.py +53 -4
- mindspore/ops_generate/api/tensor_func_reg_cpp_generator.py +25 -11
- mindspore/ops_generate/common/gen_constants.py +11 -10
- mindspore/ops_generate/common/op_proto.py +18 -1
- mindspore/ops_generate/common/template.py +102 -245
- mindspore/ops_generate/common/template_utils.py +212 -0
- mindspore/ops_generate/gen_custom_ops.py +69 -0
- mindspore/ops_generate/op_def/ops_def_cc_generator.py +78 -7
- mindspore/ops_generate/op_def_py/base_op_prim_py_generator.py +360 -0
- mindspore/ops_generate/op_def_py/custom_op_prim_py_generator.py +140 -0
- mindspore/ops_generate/op_def_py/op_def_py_generator.py +54 -7
- mindspore/ops_generate/op_def_py/op_prim_py_generator.py +5 -312
- mindspore/ops_generate/pyboost/auto_grad_impl_cc_generator.py +74 -17
- mindspore/ops_generate/pyboost/auto_grad_reg_cc_generator.py +22 -5
- mindspore/ops_generate/pyboost/gen_pyboost_func.py +0 -16
- mindspore/ops_generate/pyboost/op_template_parser.py +3 -2
- mindspore/ops_generate/pyboost/pyboost_functions_cpp_generator.py +21 -5
- mindspore/ops_generate/pyboost/pyboost_functions_h_generator.py +2 -2
- mindspore/ops_generate/pyboost/pyboost_functions_impl_cpp_generator.py +30 -10
- mindspore/ops_generate/pyboost/pyboost_grad_function_cpp_generator.py +10 -3
- mindspore/ops_generate/pyboost/pyboost_internal_kernel_info_adapter_generator.py +1 -1
- mindspore/ops_generate/pyboost/pyboost_native_grad_functions_generator.py +19 -9
- mindspore/ops_generate/pyboost/pyboost_op_cpp_code_generator.py +71 -28
- mindspore/ops_generate/pyboost/pyboost_overload_functions_cpp_generator.py +10 -9
- mindspore/ops_generate/pyboost/pyboost_utils.py +27 -16
- mindspore/ops_generate/resources/yaml_loader.py +13 -0
- mindspore/ops_generate/tensor_py_cc_generator.py +2 -2
- mindspore/parallel/_auto_parallel_context.py +5 -15
- mindspore/parallel/_cell_wrapper.py +1 -1
- mindspore/parallel/_parallel_serialization.py +4 -6
- mindspore/parallel/_ps_context.py +2 -2
- mindspore/parallel/_utils.py +34 -17
- mindspore/parallel/auto_parallel.py +23 -9
- mindspore/parallel/checkpoint_transform.py +20 -2
- mindspore/parallel/cluster/process_entity/_api.py +28 -33
- mindspore/parallel/cluster/process_entity/_utils.py +9 -5
- mindspore/parallel/cluster/run.py +5 -3
- mindspore/{experimental/llm_boost/ascend_native → parallel/distributed}/__init__.py +21 -22
- mindspore/parallel/distributed/distributed_data_parallel.py +393 -0
- mindspore/parallel/distributed/flatten_grad_buffer.py +295 -0
- mindspore/parallel/function/reshard_func.py +6 -5
- mindspore/parallel/nn/parallel_cell_wrapper.py +40 -3
- mindspore/parallel/nn/parallel_grad_reducer.py +0 -8
- mindspore/parallel/shard.py +7 -21
- mindspore/parallel/strategy.py +336 -0
- mindspore/parallel/transform_safetensors.py +127 -20
- mindspore/profiler/analysis/viewer/ascend_kernel_details_viewer.py +13 -9
- mindspore/profiler/analysis/viewer/ascend_op_memory_viewer.py +1 -1
- mindspore/profiler/analysis/viewer/ms_minddata_viewer.py +1 -1
- mindspore/profiler/common/constant.py +5 -0
- mindspore/profiler/common/file_manager.py +9 -0
- mindspore/profiler/common/msprof_cmd_tool.py +40 -4
- mindspore/profiler/common/path_manager.py +65 -24
- mindspore/profiler/common/profiler_context.py +27 -14
- mindspore/profiler/common/profiler_info.py +3 -3
- mindspore/profiler/common/profiler_meta_data.py +1 -0
- mindspore/profiler/common/profiler_op_analyse.py +10 -6
- mindspore/profiler/common/profiler_path_manager.py +13 -0
- mindspore/profiler/common/util.py +30 -3
- mindspore/profiler/dynamic_profiler.py +91 -46
- mindspore/profiler/envprofiler.py +30 -5
- mindspore/profiler/experimental_config.py +18 -2
- mindspore/profiler/platform/cpu_profiler.py +10 -4
- mindspore/profiler/platform/npu_profiler.py +34 -7
- mindspore/profiler/profiler.py +193 -145
- mindspore/profiler/profiler_action_controller.py +1 -1
- mindspore/profiler/profiler_interface.py +2 -2
- mindspore/rewrite/symbol_tree/symbol_tree.py +1 -1
- mindspore/run_check/_check_version.py +108 -24
- mindspore/runtime/__init__.py +9 -6
- mindspore/runtime/executor.py +35 -0
- mindspore/runtime/memory.py +113 -0
- mindspore/runtime/thread_bind_core.py +1 -1
- mindspore/swresample-4.dll +0 -0
- mindspore/swscale-6.dll +0 -0
- mindspore/tinyxml2.dll +0 -0
- mindspore/{experimental/llm_boost → tools}/__init__.py +5 -5
- mindspore/tools/data_dump.py +130 -0
- mindspore/tools/sdc_detect.py +91 -0
- mindspore/tools/stress_detect.py +63 -0
- mindspore/train/__init__.py +6 -6
- mindspore/train/_utils.py +8 -21
- mindspore/train/amp.py +6 -7
- mindspore/train/callback/_callback.py +2 -1
- mindspore/train/callback/_checkpoint.py +1 -17
- mindspore/train/callback/_flops_collector.py +10 -6
- mindspore/train/callback/_train_fault_tolerance.py +72 -25
- mindspore/train/data_sink.py +5 -9
- mindspore/train/dataset_helper.py +5 -5
- mindspore/train/model.py +41 -230
- mindspore/train/serialization.py +160 -401
- mindspore/train/train_thor/model_thor.py +2 -2
- mindspore/turbojpeg.dll +0 -0
- mindspore/utils/__init__.py +6 -3
- mindspore/utils/dlpack.py +92 -0
- mindspore/utils/dryrun.py +1 -1
- mindspore/utils/runtime_execution_order_check.py +10 -0
- mindspore/utils/sdc_detect.py +14 -12
- mindspore/utils/stress_detect.py +43 -0
- mindspore/utils/utils.py +152 -16
- mindspore/version.py +1 -1
- {mindspore-2.7.0rc1.dist-info → mindspore-2.7.1.dist-info}/METADATA +3 -2
- {mindspore-2.7.0rc1.dist-info → mindspore-2.7.1.dist-info}/RECORD +330 -344
- mindspore/_extends/remote/kernel_build_server_ascend.py +0 -75
- mindspore/communication/_hccl_management.py +0 -297
- mindspore/experimental/llm_boost/ascend_native/llama_boost_ascend_native.py +0 -207
- mindspore/experimental/llm_boost/ascend_native/llm_boost.py +0 -52
- mindspore/experimental/llm_boost/atb/__init__.py +0 -23
- mindspore/experimental/llm_boost/atb/boost_base.py +0 -385
- mindspore/experimental/llm_boost/atb/llama_boost.py +0 -137
- mindspore/experimental/llm_boost/atb/qwen_boost.py +0 -124
- mindspore/experimental/llm_boost/register.py +0 -130
- mindspore/experimental/llm_boost/utils.py +0 -31
- mindspore/include/OWNERS +0 -7
- mindspore/mindspore_cpu_res_manager.dll +0 -0
- mindspore/mindspore_ops_kernel_common.dll +0 -0
- mindspore/mindspore_res_manager.dll +0 -0
- mindspore/nn/optim/_dist_optimizer_registry.py +0 -111
- mindspore/nn/reinforcement/_batch_read_write.py +0 -142
- mindspore/nn/reinforcement/_tensors_queue.py +0 -152
- mindspore/nn/reinforcement/tensor_array.py +0 -145
- mindspore/opencv_core452.dll +0 -0
- mindspore/opencv_imgcodecs452.dll +0 -0
- mindspore/ops/_op_impl/aicpu/priority_replay_buffer.py +0 -113
- mindspore/ops/_op_impl/aicpu/reservoir_replay_buffer.py +0 -96
- mindspore/ops/_op_impl/aicpu/sparse_cross.py +0 -42
- mindspore/ops/_op_impl/cpu/buffer_get.py +0 -28
- mindspore/ops/_op_impl/cpu/buffer_sample.py +0 -28
- mindspore/ops/_op_impl/cpu/priority_replay_buffer.py +0 -42
- mindspore/ops/operations/_tensor_array.py +0 -359
- mindspore/ops/operations/rl_ops.py +0 -288
- mindspore/parallel/_offload_context.py +0 -275
- mindspore/parallel/_recovery_context.py +0 -115
- mindspore/parallel/_transformer/__init__.py +0 -35
- mindspore/parallel/_transformer/layers.py +0 -765
- mindspore/parallel/_transformer/loss.py +0 -251
- mindspore/parallel/_transformer/moe.py +0 -693
- mindspore/parallel/_transformer/op_parallel_config.py +0 -222
- mindspore/parallel/_transformer/transformer.py +0 -3124
- mindspore/parallel/mpi/_mpi_config.py +0 -116
- mindspore/profiler/common/validator/validate_path.py +0 -84
- mindspore/train/memory_profiling_pb2.py +0 -298
- mindspore/utils/hooks.py +0 -81
- /mindspore/common/{_auto_dynamic.py → dynamic_shape/_auto_dynamic.py} +0 -0
- {mindspore-2.7.0rc1.dist-info → mindspore-2.7.1.dist-info}/WHEEL +0 -0
- {mindspore-2.7.0rc1.dist-info → mindspore-2.7.1.dist-info}/entry_points.txt +0 -0
- {mindspore-2.7.0rc1.dist-info → mindspore-2.7.1.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
# Copyright 2025 Huawei Technologies Co., Ltd
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
# ============================================================================
|
|
15
|
+
"""Templates for code auto generation."""
|
|
16
|
+
import re
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class Template:
|
|
20
|
+
"""
|
|
21
|
+
template for generate c++/python code
|
|
22
|
+
"""
|
|
23
|
+
regular_str = r"(^[^\n\S]*)?\$([^\d\W]\w*|\{,?[^\d\W]\w*\,?})"
|
|
24
|
+
regular_match = re.compile(regular_str, re.MULTILINE)
|
|
25
|
+
|
|
26
|
+
def __init__(self, code_pattern):
|
|
27
|
+
self.code_pattern = code_pattern
|
|
28
|
+
|
|
29
|
+
@staticmethod
|
|
30
|
+
def load_from_file(file_path):
|
|
31
|
+
"""load template from file"""
|
|
32
|
+
with open(file_path, "r") as f:
|
|
33
|
+
return Template(f.read())
|
|
34
|
+
|
|
35
|
+
def replace(self, **kwargs):
|
|
36
|
+
"""
|
|
37
|
+
replace param.
|
|
38
|
+
:param kwargs:
|
|
39
|
+
:return:
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
def find(key: str):
|
|
43
|
+
if key in kwargs:
|
|
44
|
+
return kwargs[key]
|
|
45
|
+
raise TypeError(f"{key} should be in kwargs!")
|
|
46
|
+
|
|
47
|
+
def add_indent(indent, var):
|
|
48
|
+
return "".join([indent + line + "\n" for data in var for line in str(data).splitlines()]).rstrip()
|
|
49
|
+
|
|
50
|
+
def extract_variable(key):
|
|
51
|
+
start = ""
|
|
52
|
+
end = ""
|
|
53
|
+
if key[0] == "{":
|
|
54
|
+
key = key[1:-1]
|
|
55
|
+
if key[0] == ",":
|
|
56
|
+
start = ","
|
|
57
|
+
key = key[1:]
|
|
58
|
+
if key[-1] == ",":
|
|
59
|
+
end = ", "
|
|
60
|
+
key = key[:-1]
|
|
61
|
+
return find(key), start, end
|
|
62
|
+
|
|
63
|
+
def match_rule(match):
|
|
64
|
+
indent = match.group(1)
|
|
65
|
+
key = match.group(2)
|
|
66
|
+
var, start, end = extract_variable(key)
|
|
67
|
+
if indent is not None:
|
|
68
|
+
if not isinstance(var, list):
|
|
69
|
+
return add_indent(indent, [var])
|
|
70
|
+
return add_indent(indent, var)
|
|
71
|
+
if isinstance(var, list):
|
|
72
|
+
code = ", ".join(str(x) for x in var)
|
|
73
|
+
if not var:
|
|
74
|
+
return code
|
|
75
|
+
return start + code + end
|
|
76
|
+
return str(var)
|
|
77
|
+
|
|
78
|
+
return self.regular_match.sub(match_rule, self.code_pattern)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
NEW_LINE = "\n"
|
|
82
|
+
|
|
83
|
+
PYTHON_PRIM_TEMPLATE = Template("""
|
|
84
|
+
|
|
85
|
+
class _Pyboost${class_name}Prim(${class_name}Prim_):
|
|
86
|
+
def __call__(self, ${input_args}):
|
|
87
|
+
${process_func}
|
|
88
|
+
return super().__call__([${processed_args}])
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
${func_impl_name}_impl = _Pyboost${class_name}Prim()
|
|
92
|
+
""")
|
|
93
|
+
|
|
94
|
+
IMPORT_PYBOOST_PRIM_HEADER = f"""
|
|
95
|
+
from mindspore.ops._utils.arg_handler import *
|
|
96
|
+
"""
|
|
97
|
+
|
|
98
|
+
IMPORT_PYBOOST_FUNC_HEADER = f"""
|
|
99
|
+
from mindspore.common import dtype as mstype
|
|
100
|
+
from mindspore.ops.auto_generate.pyboost_inner_prim import *
|
|
101
|
+
|
|
102
|
+
"""
|
|
103
|
+
|
|
104
|
+
PY_LICENSE_STR = f"""# Copyright 2023 Huawei Technologies Co., Ltd
|
|
105
|
+
#
|
|
106
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
107
|
+
# you may not use this file except in compliance with the License.
|
|
108
|
+
# You may obtain a copy of the License at
|
|
109
|
+
#
|
|
110
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
111
|
+
#
|
|
112
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
113
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
114
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
115
|
+
# See the License for the specific language governing permissions and
|
|
116
|
+
# limitations under the License.
|
|
117
|
+
# ============================================================================
|
|
118
|
+
"""
|
|
119
|
+
|
|
120
|
+
OPS_PY_PRIM_HEADER = f"""
|
|
121
|
+
\"\"\"Operators definition generated by gen_ops.py, includes primitive classes.\"\"\"
|
|
122
|
+
|
|
123
|
+
from mindspore.ops.primitive import Primitive, prim_arg_register
|
|
124
|
+
from mindspore.ops import signature as sig
|
|
125
|
+
from mindspore.common import dtype as mstype
|
|
126
|
+
from mindspore.common._decorator import deprecated
|
|
127
|
+
from mindspore.ops._primitive_cache import _get_cache_prim
|
|
128
|
+
from mindspore.ops._utils.arg_dtype_cast import type_it
|
|
129
|
+
from mindspore.ops._utils.arg_handler import *
|
|
130
|
+
from mindspore._c_expression import OpDtype
|
|
131
|
+
from mindspore.common.jit_context import jit_context
|
|
132
|
+
from mindspore._checkparam import is_stub_tensor
|
|
133
|
+
"""
|
|
134
|
+
|
|
135
|
+
OPS_PY_DEF_HEADER = f"""
|
|
136
|
+
\"\"\"Operators definition generated by gen_ops.py, includes functions.\"\"\"
|
|
137
|
+
|
|
138
|
+
from .gen_ops_prim import *
|
|
139
|
+
from .pyboost_inner_prim import *
|
|
140
|
+
from mindspore.ops.operations.manually_defined.ops_def import *
|
|
141
|
+
from mindspore.ops._primitive_cache import _get_cache_prim
|
|
142
|
+
"""
|
|
143
|
+
|
|
144
|
+
CUSTOM_OPS_PY_DEF_HEADER = f"""
|
|
145
|
+
\"\"\"Operators definition generated by gen_ops.py, includes functions.\"\"\"
|
|
146
|
+
|
|
147
|
+
from .gen_ops_prim import *
|
|
148
|
+
"""
|
|
149
|
+
|
|
150
|
+
PRIMITIVE_CLASS_DESC = """ r\"\"\"
|
|
151
|
+
.. code-block::
|
|
152
|
+
|
|
153
|
+
prim = ops.$class_name($init_args_str)
|
|
154
|
+
out = prim($input_args_str)
|
|
155
|
+
|
|
156
|
+
is equivalent to
|
|
157
|
+
|
|
158
|
+
.. code-block::
|
|
159
|
+
|
|
160
|
+
ops.$func_name($args_str)
|
|
161
|
+
|
|
162
|
+
Refer to :func:`mindspore.ops.$func_name` for more details.
|
|
163
|
+
\"\"\"
|
|
164
|
+
"""
|
|
165
|
+
|
|
166
|
+
CC_LICENSE_STR = f"""/**
|
|
167
|
+
* Copyright 2023-2025 Huawei Technologies Co., Ltd
|
|
168
|
+
*
|
|
169
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
170
|
+
* you may not use this file except in compliance with the License.
|
|
171
|
+
* You may obtain a copy of the License at
|
|
172
|
+
*
|
|
173
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
174
|
+
*
|
|
175
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
176
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
177
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
178
|
+
* See the License for the specific language governing permissions and
|
|
179
|
+
* limitations under the License.
|
|
180
|
+
*/"""
|
|
181
|
+
|
|
182
|
+
OP_PROTO_TEMPLATE = Template("""
|
|
183
|
+
${func_impl_declaration}
|
|
184
|
+
OpDef g${class_name} = {
|
|
185
|
+
/*.name_=*/"${class_name}",
|
|
186
|
+
/*.args_=*/ {
|
|
187
|
+
${input_args}
|
|
188
|
+
},
|
|
189
|
+
/* .returns_ = */ {
|
|
190
|
+
${return_args}
|
|
191
|
+
},
|
|
192
|
+
/*.signatures_ =*/ {
|
|
193
|
+
${signatures}
|
|
194
|
+
},
|
|
195
|
+
/*.indexes_ =*/ {
|
|
196
|
+
${indexes}
|
|
197
|
+
},
|
|
198
|
+
/*.func_impl_=*/${func_impl_define},
|
|
199
|
+
/*.enable_dispatch_ =*/${enable_dispatch},
|
|
200
|
+
/*.is_view_ =*/${is_view},
|
|
201
|
+
/*.is_graph_view_ =*/${is_graph_view},
|
|
202
|
+
};
|
|
203
|
+
REGISTER_PRIMITIVE_OP_DEF(${class_name}, &g${class_name});
|
|
204
|
+
""")
|
|
205
|
+
|
|
206
|
+
OP_PRIM_CLASS_DEFINE_TEMPLATE = Template("""
|
|
207
|
+
|
|
208
|
+
class ${class_name}(Primitive):
|
|
209
|
+
${class_desc}${signature_code}${deprecated_code}
|
|
210
|
+
${init_method}
|
|
211
|
+
|
|
212
|
+
${call_method}""")
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Copyright 2025 Huawei Technologies Co., Ltd
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
# ============================================================================
|
|
15
|
+
"""
|
|
16
|
+
Auto generate custom ops files.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
import logging
|
|
20
|
+
import argparse
|
|
21
|
+
from resources.resource_manager import ResourceManager
|
|
22
|
+
from resources.resource_list import ResourceType
|
|
23
|
+
from resources.yaml_loader import CustomOpDocYamlLoader
|
|
24
|
+
from op_def.ops_def_cc_generator import CustomOpsDefCcGenerator
|
|
25
|
+
from op_def_py.custom_op_prim_py_generator import CustomOpPrimPyGenerator
|
|
26
|
+
from op_def_py.op_def_py_generator import CustomOpDefPyGenerator
|
|
27
|
+
from common.op_proto import CustomOpProtoLoader
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def get_config():
|
|
31
|
+
"""get config from user"""
|
|
32
|
+
parser = argparse.ArgumentParser()
|
|
33
|
+
parser.add_argument("-m", "--module_name", type=str, required=True)
|
|
34
|
+
parser.add_argument("-i", "--input_path", type=str, required=True)
|
|
35
|
+
parser.add_argument("-o", "--output_path", type=str, required=True)
|
|
36
|
+
parser.add_argument("-d", "--doc_path", type=str, required=True)
|
|
37
|
+
return parser.parse_args()
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def generate_custom_op_def(module_name, input_path, doc_path, output_path):
|
|
41
|
+
"""Automatically generate all necessary files for custom operators."""
|
|
42
|
+
resource_mgr = ResourceManager()
|
|
43
|
+
resource_mgr.register_resource(CustomOpProtoLoader(input_path))
|
|
44
|
+
op_protos = resource_mgr.get_resource(ResourceType.OP_PROTO)
|
|
45
|
+
doc_dict = dict()
|
|
46
|
+
if doc_path != "":
|
|
47
|
+
resource_mgr.register_resource(CustomOpDocYamlLoader(doc_path))
|
|
48
|
+
doc_dict = resource_mgr.get_resource(ResourceType.OP_DOC_YAML)
|
|
49
|
+
|
|
50
|
+
generator = CustomOpsDefCcGenerator()
|
|
51
|
+
generator.generate(output_path, op_protos)
|
|
52
|
+
generator = CustomOpPrimPyGenerator()
|
|
53
|
+
generator.generate(output_path, module_name, op_protos, doc_dict, "gen")
|
|
54
|
+
generator = CustomOpDefPyGenerator()
|
|
55
|
+
generator.generate(output_path, op_protos, doc_dict, "gen")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def main():
|
|
59
|
+
"""main function"""
|
|
60
|
+
args = get_config()
|
|
61
|
+
generate_custom_op_def(args.module_name, args.input_path, args.doc_path, args.output_path)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
if __name__ == "__main__":
|
|
65
|
+
try:
|
|
66
|
+
main()
|
|
67
|
+
except Exception as e:
|
|
68
|
+
logging.critical("Auto generate failed, err info: %s", e)
|
|
69
|
+
raise e
|
|
@@ -24,11 +24,10 @@ import common.gen_utils as gen_utils
|
|
|
24
24
|
|
|
25
25
|
# refactored
|
|
26
26
|
from common.op_proto import OpProto
|
|
27
|
-
import common.
|
|
27
|
+
import common.template_utils as template
|
|
28
28
|
|
|
29
29
|
from common.base_generator import BaseGenerator
|
|
30
30
|
|
|
31
|
-
|
|
32
31
|
CC_OPS_DEF = """
|
|
33
32
|
|
|
34
33
|
#include "$auto_generate_path/gen_ops_def.h"
|
|
@@ -72,8 +71,12 @@ class OpsDefCcGenerator(BaseGenerator):
|
|
|
72
71
|
operator_name = op_proto.op_name
|
|
73
72
|
class_name = op_proto.op_class.name
|
|
74
73
|
if not op_proto.func_op:
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
if op_proto.op_dispatch and op_proto.op_dispatch.is_comm_op:
|
|
75
|
+
gen_include_list.append(self.include_template.replace(path=K.MS_OPS_COMM_FUNC_IMPL_PATH,
|
|
76
|
+
operator_name=operator_name))
|
|
77
|
+
else:
|
|
78
|
+
gen_include_list.append(self.include_template.replace(path=K.MS_OPS_FUNC_IMPL_PATH,
|
|
79
|
+
operator_name=operator_name))
|
|
77
80
|
func_impl_declaration_str = self.func_impl_declaration_template.replace(class_name=class_name)
|
|
78
81
|
else:
|
|
79
82
|
func_impl_declaration_str = self.empty_func_impl_declaration_template.replace(class_name=class_name)
|
|
@@ -85,7 +88,6 @@ class OpsDefCcGenerator(BaseGenerator):
|
|
|
85
88
|
# Process outputs.
|
|
86
89
|
return_args_str = get_cc_op_def_return(args_dict, op_proto)
|
|
87
90
|
|
|
88
|
-
|
|
89
91
|
inputs_args = self.process_args(op_proto.op_args)
|
|
90
92
|
signature_code = generate_cc_op_signature(op_proto.op_args_signature, inputs_args)
|
|
91
93
|
enable_dispatch = "true" if op_proto.op_dispatch and op_proto.op_dispatch.enable else "false"
|
|
@@ -112,9 +114,9 @@ class OpsDefCcGenerator(BaseGenerator):
|
|
|
112
114
|
save_path = os.path.join(work_path, K.MS_OP_DEF_AUTO_GENERATE_PATH)
|
|
113
115
|
for numbering in range(math.ceil(op_size / max_op_size_in_one_file)):
|
|
114
116
|
gen_include = ''.join(
|
|
115
|
-
gen_include_list[numbering*max_op_size_in_one_file: (numbering+1)*max_op_size_in_one_file])
|
|
117
|
+
gen_include_list[numbering * max_op_size_in_one_file: (numbering + 1) * max_op_size_in_one_file])
|
|
116
118
|
gen_cc = ''.join(
|
|
117
|
-
gen_cc_list[numbering*max_op_size_in_one_file: (numbering+1)*max_op_size_in_one_file])
|
|
119
|
+
gen_cc_list[numbering * max_op_size_in_one_file: (numbering + 1) * max_op_size_in_one_file])
|
|
118
120
|
cc_ops_def = self.CC_OPS_DEF_TEMPLATE.replace(auto_generate_path=K.MS_OP_DEF_AUTO_GENERATE_PATH,
|
|
119
121
|
gen_include=gen_include,
|
|
120
122
|
gen_cc_code=gen_cc)
|
|
@@ -148,6 +150,75 @@ class OpsDefCcGenerator(BaseGenerator):
|
|
|
148
150
|
return inputs_name
|
|
149
151
|
|
|
150
152
|
|
|
153
|
+
class CustomOpsDefCcGenerator(OpsDefCcGenerator):
|
|
154
|
+
"""
|
|
155
|
+
Generates C++ definition files for operators.
|
|
156
|
+
"""
|
|
157
|
+
|
|
158
|
+
def __init__(self):
|
|
159
|
+
"""
|
|
160
|
+
Initializes templates for generating C++ operator definitions.
|
|
161
|
+
"""
|
|
162
|
+
super(CustomOpsDefCcGenerator, self).__init__()
|
|
163
|
+
|
|
164
|
+
self.include_template = template.Template("""#include "${path}/${operator_name}.h\"\n""")
|
|
165
|
+
self.func_impl_declaration_template = template.Template("extern OpFuncImpl &g${class_name}FuncImpl;")
|
|
166
|
+
self.empty_func_impl_declaration_template = template.Template("static OpFuncImpl g${class_name}FuncImpl;")
|
|
167
|
+
self.func_impl_define_template = template.Template("g${class_name}FuncImpl")
|
|
168
|
+
self.OP_PROTO_TEMPLATE = template.OP_PROTO_TEMPLATE
|
|
169
|
+
self.CC_OPS_DEF_TEMPLATE = template.Template(CC_OPS_DEF)
|
|
170
|
+
|
|
171
|
+
def generate(self, work_path, op_protos):
|
|
172
|
+
"""
|
|
173
|
+
Generates C++ code for operator definitions and saves it to a file.
|
|
174
|
+
|
|
175
|
+
Args:
|
|
176
|
+
work_path (str): The directory to save the generated files.
|
|
177
|
+
op_protos (list): A list of operator prototypes.
|
|
178
|
+
"""
|
|
179
|
+
gen_cc_list = list()
|
|
180
|
+
gen_include_list = list()
|
|
181
|
+
|
|
182
|
+
for op_proto in op_protos:
|
|
183
|
+
class_name = "Custom_" + op_proto.op_name
|
|
184
|
+
func_impl_declaration_str = self.func_impl_declaration_template.replace(class_name=class_name)
|
|
185
|
+
func_impl_define = self.func_impl_define_template.replace(class_name=class_name)
|
|
186
|
+
|
|
187
|
+
# process input
|
|
188
|
+
args_dict, cc_index_str, input_args_str = process_input_args(op_proto)
|
|
189
|
+
|
|
190
|
+
# Process outputs.
|
|
191
|
+
return_args_str = get_cc_op_def_return(args_dict, op_proto)
|
|
192
|
+
|
|
193
|
+
inputs_args = self.process_args(op_proto.op_args)
|
|
194
|
+
signature_code = generate_cc_op_signature(op_proto.op_args_signature, inputs_args)
|
|
195
|
+
enable_dispatch = "true" if op_proto.op_dispatch and op_proto.op_dispatch.enable else "false"
|
|
196
|
+
is_view = "true" if op_proto.op_view else "false"
|
|
197
|
+
is_graph_view = "true" if op_proto.op_graph_view else "false"
|
|
198
|
+
op_def_cc = self.OP_PROTO_TEMPLATE.replace(class_name=class_name,
|
|
199
|
+
input_args=input_args_str,
|
|
200
|
+
return_args=return_args_str,
|
|
201
|
+
signatures=signature_code,
|
|
202
|
+
indexes=cc_index_str,
|
|
203
|
+
enable_dispatch=enable_dispatch,
|
|
204
|
+
is_view=is_view,
|
|
205
|
+
is_graph_view=is_graph_view,
|
|
206
|
+
func_impl_declaration=func_impl_declaration_str,
|
|
207
|
+
func_impl_define=func_impl_define)
|
|
208
|
+
|
|
209
|
+
gen_cc_list.append(op_def_cc)
|
|
210
|
+
|
|
211
|
+
gen_include = ''.join(gen_include_list)
|
|
212
|
+
gen_cc = ''.join(gen_cc_list)
|
|
213
|
+
cc_ops_def = self.CC_OPS_DEF_TEMPLATE.replace(auto_generate_path=K.MS_OP_DEF_AUTO_GENERATE_PATH,
|
|
214
|
+
gen_include=gen_include,
|
|
215
|
+
gen_cc_code=gen_cc)
|
|
216
|
+
|
|
217
|
+
file_name = f"gen_custom_ops_def.cc"
|
|
218
|
+
ops_def_cc_file_str = template.CC_LICENSE_STR + cc_ops_def
|
|
219
|
+
gen_utils.save_file(work_path, file_name, ops_def_cc_file_str)
|
|
220
|
+
|
|
221
|
+
|
|
151
222
|
def process_input_args(op_proto: OpProto):
|
|
152
223
|
"""
|
|
153
224
|
Processes input arguments for C++ code generation.
|