mindspore 2.3.0__cp310-cp310-win_amd64.whl → 2.4.1__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/__init__.py +3 -1
- 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/_checkparam.py +50 -9
- mindspore/_extends/parse/compile_config.py +41 -0
- mindspore/_extends/parse/parser.py +9 -7
- mindspore/_extends/parse/standard_method.py +52 -14
- mindspore/_extends/pijit/pijit_func_white_list.py +350 -24
- mindspore/amp.py +24 -10
- mindspore/common/__init__.py +6 -4
- mindspore/common/_pijit_context.py +190 -0
- mindspore/common/_register_for_tensor.py +2 -1
- mindspore/common/_tensor_overload.py +139 -0
- mindspore/common/api.py +102 -87
- mindspore/common/dump.py +5 -6
- mindspore/common/generator.py +1 -7
- mindspore/common/hook_handle.py +14 -26
- mindspore/common/initializer.py +51 -15
- mindspore/common/mindir_util.py +2 -2
- mindspore/common/parameter.py +62 -15
- mindspore/common/recompute.py +39 -9
- mindspore/common/sparse_tensor.py +7 -3
- mindspore/common/tensor.py +183 -37
- mindspore/communication/__init__.py +1 -1
- mindspore/communication/_comm_helper.py +38 -3
- mindspore/communication/comm_func.py +315 -60
- mindspore/communication/management.py +14 -14
- mindspore/context.py +132 -22
- mindspore/dataset/__init__.py +1 -1
- mindspore/dataset/audio/__init__.py +1 -1
- mindspore/dataset/core/config.py +7 -0
- mindspore/dataset/core/validator_helpers.py +7 -0
- mindspore/dataset/engine/cache_client.py +1 -1
- mindspore/dataset/engine/datasets.py +72 -44
- mindspore/dataset/engine/datasets_audio.py +7 -7
- mindspore/dataset/engine/datasets_standard_format.py +53 -3
- mindspore/dataset/engine/datasets_text.py +20 -20
- mindspore/dataset/engine/datasets_user_defined.py +174 -104
- mindspore/dataset/engine/datasets_vision.py +33 -33
- mindspore/dataset/engine/iterators.py +29 -0
- mindspore/dataset/engine/obs/util.py +7 -0
- mindspore/dataset/engine/queue.py +114 -60
- mindspore/dataset/engine/serializer_deserializer.py +2 -2
- mindspore/dataset/engine/validators.py +34 -14
- mindspore/dataset/text/__init__.py +1 -4
- mindspore/dataset/transforms/__init__.py +0 -3
- mindspore/dataset/utils/line_reader.py +2 -0
- mindspore/dataset/vision/__init__.py +1 -4
- mindspore/dataset/vision/utils.py +1 -1
- mindspore/dataset/vision/validators.py +2 -1
- mindspore/{nn/extend → experimental/es}/__init__.py +4 -11
- mindspore/experimental/es/embedding_service.py +883 -0
- mindspore/{nn/layer → experimental/es}/embedding_service_layer.py +218 -30
- mindspore/experimental/llm_boost/__init__.py +21 -0
- mindspore/{nn/extend/layer → experimental/llm_boost/atb}/__init__.py +4 -8
- mindspore/experimental/llm_boost/atb/boost_base.py +211 -0
- mindspore/experimental/llm_boost/atb/llama_boost.py +115 -0
- mindspore/experimental/llm_boost/atb/qwen_boost.py +101 -0
- mindspore/experimental/llm_boost/register.py +129 -0
- mindspore/experimental/llm_boost/utils.py +31 -0
- mindspore/experimental/optim/adamw.py +85 -0
- mindspore/experimental/optim/optimizer.py +3 -0
- mindspore/hal/__init__.py +3 -3
- mindspore/hal/contiguous_tensors_handle.py +175 -0
- mindspore/hal/stream.py +18 -0
- mindspore/include/api/model_group.h +13 -1
- mindspore/include/api/types.h +10 -10
- mindspore/include/dataset/config.h +2 -2
- mindspore/include/dataset/constants.h +2 -2
- mindspore/include/dataset/execute.h +2 -2
- mindspore/include/dataset/vision.h +4 -0
- mindspore/log.py +1 -1
- mindspore/mindrecord/filewriter.py +68 -51
- mindspore/mindspore_backend.dll +0 -0
- mindspore/mindspore_common.dll +0 -0
- mindspore/mindspore_core.dll +0 -0
- mindspore/mindspore_np_dtype.dll +0 -0
- mindspore/mindspore_ops.dll +0 -0
- mindspore/mint/__init__.py +983 -46
- mindspore/mint/distributed/__init__.py +31 -0
- mindspore/mint/distributed/distributed.py +254 -0
- mindspore/mint/nn/__init__.py +268 -23
- mindspore/mint/nn/functional.py +125 -19
- mindspore/mint/nn/layer/__init__.py +39 -0
- mindspore/mint/nn/layer/activation.py +133 -0
- mindspore/mint/nn/layer/normalization.py +477 -0
- mindspore/mint/nn/layer/pooling.py +110 -0
- mindspore/mint/optim/adamw.py +26 -13
- mindspore/mint/special/__init__.py +63 -0
- mindspore/multiprocessing/__init__.py +2 -1
- mindspore/nn/__init__.py +0 -1
- mindspore/nn/cell.py +276 -96
- mindspore/nn/layer/activation.py +211 -44
- mindspore/nn/layer/basic.py +137 -10
- mindspore/nn/layer/embedding.py +137 -2
- mindspore/nn/layer/normalization.py +101 -5
- mindspore/nn/layer/padding.py +34 -48
- mindspore/nn/layer/pooling.py +161 -7
- mindspore/nn/layer/transformer.py +3 -3
- mindspore/nn/loss/__init__.py +2 -2
- mindspore/nn/loss/loss.py +84 -6
- mindspore/nn/optim/__init__.py +2 -1
- mindspore/nn/optim/adadelta.py +1 -1
- mindspore/nn/optim/adam.py +1 -1
- mindspore/nn/optim/lamb.py +1 -1
- mindspore/nn/optim/tft_wrapper.py +124 -0
- mindspore/nn/wrap/cell_wrapper.py +12 -23
- mindspore/nn/wrap/grad_reducer.py +5 -5
- mindspore/nn/wrap/loss_scale.py +17 -3
- mindspore/numpy/__init__.py +1 -1
- mindspore/numpy/array_creations.py +65 -68
- mindspore/numpy/array_ops.py +64 -60
- mindspore/numpy/fft.py +610 -75
- mindspore/numpy/logic_ops.py +11 -10
- mindspore/numpy/math_ops.py +85 -84
- mindspore/numpy/utils_const.py +4 -4
- mindspore/opencv_core452.dll +0 -0
- mindspore/opencv_imgcodecs452.dll +0 -0
- mindspore/opencv_imgproc452.dll +0 -0
- mindspore/ops/__init__.py +6 -4
- mindspore/ops/_grad_experimental/grad_array_ops.py +0 -11
- mindspore/ops/_grad_experimental/grad_comm_ops.py +67 -4
- mindspore/ops/_grad_experimental/grad_math_ops.py +0 -22
- mindspore/ops/_vmap/vmap_array_ops.py +2 -4
- mindspore/ops/_vmap/vmap_math_ops.py +17 -1
- mindspore/ops/_vmap/vmap_nn_ops.py +43 -2
- mindspore/ops/auto_generate/cpp_create_prim_instance_helper.py +91 -7
- mindspore/ops/auto_generate/gen_arg_dtype_cast.py +2 -0
- mindspore/ops/auto_generate/gen_extend_func.py +767 -13
- mindspore/ops/auto_generate/gen_ops_def.py +2452 -364
- mindspore/ops/auto_generate/gen_ops_prim.py +5442 -1756
- mindspore/ops/auto_generate/pyboost_inner_prim.py +176 -56
- mindspore/ops/composite/base.py +85 -48
- mindspore/ops/composite/multitype_ops/_compile_utils.py +1 -0
- mindspore/ops/composite/multitype_ops/not_in_impl.py +2 -2
- mindspore/ops/function/__init__.py +22 -0
- mindspore/ops/function/array_func.py +492 -153
- mindspore/ops/function/debug_func.py +113 -1
- mindspore/ops/function/fft_func.py +15 -2
- mindspore/ops/function/grad/grad_func.py +3 -2
- mindspore/ops/function/math_func.py +564 -207
- mindspore/ops/function/nn_func.py +817 -383
- mindspore/ops/function/other_func.py +3 -2
- mindspore/ops/function/random_func.py +402 -12
- mindspore/ops/function/reshard_func.py +13 -11
- mindspore/ops/function/sparse_unary_func.py +1 -1
- mindspore/ops/function/vmap_func.py +3 -2
- mindspore/ops/functional.py +24 -14
- mindspore/ops/op_info_register.py +3 -3
- mindspore/ops/operations/__init__.py +7 -2
- mindspore/ops/operations/_grad_ops.py +2 -76
- mindspore/ops/operations/_infer_ops.py +1 -1
- mindspore/ops/operations/_inner_ops.py +71 -94
- mindspore/ops/operations/array_ops.py +14 -146
- mindspore/ops/operations/comm_ops.py +63 -53
- mindspore/ops/operations/custom_ops.py +83 -19
- mindspore/ops/operations/debug_ops.py +42 -10
- mindspore/ops/operations/manually_defined/_inner.py +12 -0
- mindspore/ops/operations/manually_defined/ops_def.py +273 -20
- mindspore/ops/operations/math_ops.py +12 -223
- mindspore/ops/operations/nn_ops.py +20 -114
- mindspore/ops/operations/other_ops.py +7 -4
- mindspore/ops/operations/random_ops.py +46 -1
- mindspore/ops/primitive.py +18 -6
- mindspore/ops_generate/arg_dtype_cast.py +2 -0
- mindspore/ops_generate/gen_aclnn_implement.py +11 -11
- mindspore/ops_generate/gen_constants.py +36 -0
- mindspore/ops_generate/gen_ops.py +67 -52
- mindspore/ops_generate/gen_ops_inner_prim.py +1 -1
- mindspore/ops_generate/gen_pyboost_func.py +131 -47
- mindspore/ops_generate/op_proto.py +10 -3
- mindspore/ops_generate/pyboost_utils.py +14 -1
- mindspore/ops_generate/template.py +43 -21
- mindspore/parallel/__init__.py +3 -1
- mindspore/parallel/_auto_parallel_context.py +31 -9
- mindspore/parallel/_cell_wrapper.py +85 -0
- mindspore/parallel/_parallel_serialization.py +47 -19
- mindspore/parallel/_tensor.py +127 -13
- mindspore/parallel/_utils.py +53 -22
- mindspore/parallel/algo_parameter_config.py +5 -5
- mindspore/parallel/checkpoint_transform.py +46 -39
- mindspore/parallel/cluster/process_entity/__init__.py +1 -1
- mindspore/parallel/cluster/process_entity/_api.py +31 -23
- mindspore/parallel/cluster/process_entity/_utils.py +2 -27
- mindspore/parallel/parameter_broadcast.py +3 -4
- mindspore/parallel/shard.py +162 -31
- mindspore/parallel/transform_safetensors.py +1146 -0
- mindspore/profiler/__init__.py +2 -1
- mindspore/profiler/common/constant.py +29 -0
- mindspore/profiler/common/registry.py +47 -0
- mindspore/profiler/common/util.py +28 -0
- mindspore/profiler/dynamic_profiler.py +694 -0
- mindspore/profiler/envprofiling.py +17 -19
- mindspore/profiler/parser/ascend_analysis/constant.py +18 -0
- mindspore/profiler/parser/ascend_analysis/file_manager.py +25 -4
- mindspore/profiler/parser/ascend_analysis/function_event.py +43 -19
- mindspore/profiler/parser/ascend_analysis/fwk_cann_parser.py +31 -26
- mindspore/profiler/parser/ascend_analysis/fwk_file_parser.py +56 -10
- mindspore/profiler/parser/ascend_analysis/msprof_timeline_parser.py +55 -8
- mindspore/profiler/parser/ascend_analysis/path_manager.py +313 -0
- mindspore/profiler/parser/ascend_analysis/profiler_info_parser.py +27 -20
- mindspore/profiler/parser/ascend_analysis/trace_event_manager.py +9 -2
- mindspore/profiler/parser/ascend_msprof_exporter.py +5 -4
- mindspore/profiler/parser/ascend_timeline_generator.py +27 -25
- mindspore/profiler/parser/base_timeline_generator.py +19 -25
- mindspore/profiler/parser/cpu_gpu_timeline_generator.py +25 -12
- mindspore/profiler/parser/framework_parser.py +1 -391
- mindspore/profiler/parser/gpu_analysis/__init__.py +14 -0
- mindspore/profiler/parser/gpu_analysis/function_event.py +44 -0
- mindspore/profiler/parser/gpu_analysis/fwk_file_parser.py +89 -0
- mindspore/profiler/parser/gpu_analysis/profiler_info_parser.py +72 -0
- mindspore/profiler/parser/memory_usage_parser.py +0 -154
- mindspore/profiler/parser/profiler_info.py +78 -6
- mindspore/profiler/profiler.py +153 -0
- mindspore/profiler/profiling.py +285 -413
- mindspore/rewrite/__init__.py +1 -2
- mindspore/rewrite/common/namespace.py +4 -4
- mindspore/rewrite/symbol_tree/symbol_tree.py +3 -3
- mindspore/run_check/_check_version.py +39 -104
- mindspore/safeguard/rewrite_obfuscation.py +591 -247
- mindspore/train/__init__.py +4 -3
- mindspore/train/_utils.py +105 -19
- mindspore/train/amp.py +171 -53
- mindspore/train/callback/__init__.py +2 -2
- mindspore/train/callback/_callback.py +4 -4
- mindspore/train/callback/_checkpoint.py +97 -31
- mindspore/train/callback/_cluster_monitor.py +1 -1
- mindspore/train/callback/_flops_collector.py +1 -0
- mindspore/train/callback/_loss_monitor.py +3 -3
- mindspore/train/callback/_on_request_exit.py +145 -31
- mindspore/train/callback/_summary_collector.py +5 -5
- mindspore/train/callback/_tft_register.py +375 -0
- mindspore/train/dataset_helper.py +15 -3
- mindspore/train/metrics/metric.py +3 -3
- mindspore/train/metrics/roc.py +4 -4
- mindspore/train/mind_ir_pb2.py +44 -39
- mindspore/train/model.py +154 -58
- mindspore/train/serialization.py +342 -128
- mindspore/utils/__init__.py +21 -0
- mindspore/utils/utils.py +60 -0
- mindspore/version.py +1 -1
- {mindspore-2.3.0.dist-info → mindspore-2.4.1.dist-info}/METADATA +13 -7
- {mindspore-2.3.0.dist-info → mindspore-2.4.1.dist-info}/RECORD +248 -242
- mindspore/include/c_api/ms/abstract.h +0 -67
- mindspore/include/c_api/ms/attribute.h +0 -197
- mindspore/include/c_api/ms/base/handle_types.h +0 -43
- mindspore/include/c_api/ms/base/macros.h +0 -32
- mindspore/include/c_api/ms/base/status.h +0 -33
- mindspore/include/c_api/ms/base/types.h +0 -283
- mindspore/include/c_api/ms/context.h +0 -102
- mindspore/include/c_api/ms/graph.h +0 -160
- mindspore/include/c_api/ms/node.h +0 -606
- mindspore/include/c_api/ms/tensor.h +0 -161
- mindspore/include/c_api/ms/value.h +0 -84
- mindspore/mindspore_shared_lib.dll +0 -0
- mindspore/nn/extend/basic.py +0 -140
- mindspore/nn/extend/embedding.py +0 -143
- mindspore/nn/extend/layer/normalization.py +0 -109
- mindspore/nn/extend/pooling.py +0 -117
- mindspore/nn/layer/embedding_service.py +0 -531
- mindspore/ops/_op_impl/aicpu/strided_slice_v2.py +0 -93
- mindspore/ops/_op_impl/aicpu/strided_slice_v2_grad.py +0 -66
- mindspore/ops/extend/__init__.py +0 -53
- mindspore/ops/extend/array_func.py +0 -218
- mindspore/ops/extend/math_func.py +0 -76
- mindspore/ops/extend/nn_func.py +0 -308
- mindspore/ops/silent_check.py +0 -162
- mindspore/profiler/parser/msadvisor_analyzer.py +0 -82
- mindspore/profiler/parser/msadvisor_parser.py +0 -240
- mindspore/train/callback/_mindio_ttp.py +0 -443
- {mindspore-2.3.0.dist-info → mindspore-2.4.1.dist-info}/WHEEL +0 -0
- {mindspore-2.3.0.dist-info → mindspore-2.4.1.dist-info}/entry_points.txt +0 -0
- {mindspore-2.3.0.dist-info → mindspore-2.4.1.dist-info}/top_level.txt +0 -0
|
@@ -28,6 +28,7 @@ import template
|
|
|
28
28
|
from template import CppTemplate
|
|
29
29
|
from op_proto import OpProto
|
|
30
30
|
from gen_utils import check_change_and_replace_file, py_licence_str, write_file
|
|
31
|
+
import gen_constants as K
|
|
31
32
|
|
|
32
33
|
|
|
33
34
|
@dataclass
|
|
@@ -47,7 +48,7 @@ def generate_pyboost_base_op_header_code(work_path, op_name_str, operator_name,
|
|
|
47
48
|
op_name_upper=op_name_str.upper(),
|
|
48
49
|
call_args=call_args_with_type,
|
|
49
50
|
return_type=cpp_func_return)
|
|
50
|
-
op_header_dir_path = os.path.join(work_path, "
|
|
51
|
+
op_header_dir_path = os.path.join(work_path, f"{K.MS_COMMON_PYBOOST_KERNEL_PATH}/auto_generate/")
|
|
51
52
|
pathlib.Path(op_header_dir_path).mkdir(parents=True, exist_ok=True)
|
|
52
53
|
tmp_op_file_path = os.path.join(op_header_dir_path, "tmp_" + operator_name + ".h")
|
|
53
54
|
dst_op_file_path = os.path.join(op_header_dir_path, operator_name + ".h")
|
|
@@ -187,35 +188,28 @@ def generate_pyboost_op_source_code(work_path, op_proto, template_paths, convert
|
|
|
187
188
|
return_values=converter.call_func_outputs,
|
|
188
189
|
customize_func=op_proto.ascend + "Customize",
|
|
189
190
|
)
|
|
190
|
-
customize_include =
|
|
191
|
-
operator_name.lower())
|
|
191
|
+
customize_include = f'#include "{K.MS_OPS_KERNEL_PATH}/ascend/pyboost/customize/{operator_name.lower()}.h"'
|
|
192
192
|
elif is_cpu and op_proto.cpu != 'default':
|
|
193
193
|
call_impl = cus_tpl.replace(call_args=converter.call_args,
|
|
194
194
|
return_values=converter.call_func_outputs,
|
|
195
195
|
customize_func=op_proto.cpu + "Customize",
|
|
196
196
|
)
|
|
197
|
-
customize_include =
|
|
198
|
-
operator_name.lower())
|
|
197
|
+
customize_include = f'#include "{K.MS_OPS_KERNEL_PATH}/cpu/pyboost/customize/{operator_name.lower()}.h"'
|
|
199
198
|
register_custom_kernel = "MS_REG_PYBOOST_CPU_CUSTOM_KERNEL({});".format(op_name_str)
|
|
200
199
|
elif is_gpu and op_proto.gpu != 'default':
|
|
201
200
|
call_impl = cus_tpl.replace(call_args=converter.call_args,
|
|
202
201
|
return_values=converter.call_func_outputs,
|
|
203
202
|
customize_func=op_proto.gpu + "Customize",
|
|
204
203
|
)
|
|
205
|
-
customize_include =
|
|
206
|
-
operator_name.lower())
|
|
204
|
+
customize_include = f'#include "{K.MS_OPS_KERNEL_PATH}/gpu/pyboost/customize/{operator_name.lower()}.h"'
|
|
207
205
|
register_custom_kernel = "MS_REG_PYBOOST_GPU_CUSTOM_KERNEL({});".format(op_name_str)
|
|
208
206
|
elif op_proto.is_view:
|
|
209
|
-
set_output_abs = "SetOutputAbstract();"
|
|
210
|
-
if converter.call_func_outputs == "outputs_":
|
|
211
|
-
set_output_abs = "SetOutputTupleAbstract();"
|
|
212
207
|
call_impl = view_tpl.replace(op_name=op_proto.class_name,
|
|
213
208
|
call_args=converter.call_args,
|
|
214
209
|
call_tensors=call_args_tensor,
|
|
215
210
|
return_values=converter.call_func_outputs,
|
|
216
|
-
input=converter.call_args[0]
|
|
217
|
-
|
|
218
|
-
customize_include = "#include \"mindspore/core/ops/view/{}_strides_calc.h\"".format(proto_operator_name)
|
|
211
|
+
input=converter.call_args[0])
|
|
212
|
+
customize_include = f'#include "{K.MS_OPS_VIEW_PATH}/{proto_operator_name}_strides_calc.h"'
|
|
219
213
|
else:
|
|
220
214
|
cast_input_code, real_call_args_tensor = generate_tensor_cpu_cast_input_code(
|
|
221
215
|
converter.call_args_with_tensor, call_args_tensor)
|
|
@@ -226,7 +220,7 @@ def generate_pyboost_op_source_code(work_path, op_proto, template_paths, convert
|
|
|
226
220
|
aclnn_name = AclnnUtils.get_aclnn_interface(op_name_str)
|
|
227
221
|
if converter.inplace_process != '':
|
|
228
222
|
real_output = ''
|
|
229
|
-
customize_include = '#include "
|
|
223
|
+
customize_include = f'#include "{K.MS_OP_DEF_AUTO_GENERATE_PATH}/gen_ops_primitive.h"'
|
|
230
224
|
|
|
231
225
|
call_impl = call_tpl.replace(aclnn_name=aclnn_name,
|
|
232
226
|
call_args=converter.call_args,
|
|
@@ -270,10 +264,10 @@ def generate_pyboost_op_register_source_code(work_path, all_ops, all_operator_na
|
|
|
270
264
|
for op_name in all_ops:
|
|
271
265
|
factory_str += "template class OpFactory<{0}>;\n".format(op_name)
|
|
272
266
|
for operator_name in all_operator_names:
|
|
273
|
-
include_str +=
|
|
267
|
+
include_str += f'#include "{K.MS_COMMON_PYBOOST_KERNEL_PATH}/auto_generate/{operator_name}.h"\n'
|
|
274
268
|
op_register_file_str = template.PYBOOST_OP_REGISTER_TEMPLATE.replace(op_includes=include_str,
|
|
275
269
|
op_factory_templates=factory_str)
|
|
276
|
-
op_register_dir_path = os.path.join(work_path, "
|
|
270
|
+
op_register_dir_path = os.path.join(work_path, f"{K.MS_COMMON_PYBOOST_KERNEL_PATH}/auto_generate/")
|
|
277
271
|
pathlib.Path(op_register_dir_path).mkdir(parents=True, exist_ok=True)
|
|
278
272
|
tmp_op_register_file_path = os.path.join(op_register_dir_path, "tmp_" + "op_register.cc")
|
|
279
273
|
dst_op_register_file_path = os.path.join(op_register_dir_path, "op_register.cc")
|
|
@@ -353,19 +347,22 @@ def generate_pyboost_outputs(op_proto):
|
|
|
353
347
|
return op_outputs, call_outputs
|
|
354
348
|
|
|
355
349
|
|
|
356
|
-
def generate_ops_header_files(work_path, yaml_data):
|
|
350
|
+
def generate_ops_header_files(work_path, yaml_data, extra_ops=None):
|
|
357
351
|
"""
|
|
358
352
|
:param work_path:
|
|
359
353
|
:param yaml_data:
|
|
354
|
+
:prama extra_ops(default:None):
|
|
360
355
|
:return: void
|
|
361
356
|
"""
|
|
362
357
|
extern_str = ''
|
|
363
|
-
extern_template = CppTemplate("
|
|
358
|
+
extern_template = CppTemplate("OPS_API extern OpDef g${op_name};\n")
|
|
364
359
|
for operator_name, operator_data in yaml_data.items():
|
|
365
360
|
op_proto = OpProto.load_from_yaml(operator_name, operator_data)
|
|
366
361
|
extern_str += extern_template.replace(op_name=op_proto.class_name)
|
|
362
|
+
for class_name in extra_ops:
|
|
363
|
+
extern_str += extern_template.replace(op_name=class_name)
|
|
367
364
|
ops_header_file = template.GEN_OPS_DEF_HEADER_TEMPLATE.replace(extern_variable=extern_str)
|
|
368
|
-
dir_path = os.path.join(work_path,
|
|
365
|
+
dir_path = os.path.join(work_path, K.MS_OP_DEF_AUTO_GENERATE_PATH)
|
|
369
366
|
pathlib.Path(dir_path).mkdir(parents=True, exist_ok=True)
|
|
370
367
|
dst_file_path = os.path.join(dir_path, "gen_ops_def.h")
|
|
371
368
|
tmp_file_path = os.path.join(dir_path, "tmp_gen_ops_def.h")
|
|
@@ -396,10 +393,10 @@ def get_convert_tensor_template():
|
|
|
396
393
|
Get convert tensor template
|
|
397
394
|
"""
|
|
398
395
|
convert_to_tensor_template = CppTemplate(
|
|
399
|
-
'auto ${output} = PyNativeAlgo::Common::ConvertStubNodeToTensor(${input}, ${need_contiguous}, '\
|
|
396
|
+
'auto ${output} = PyNativeAlgo::Common::ConvertStubNodeToTensor(${input}, ${need_contiguous}, ' \
|
|
400
397
|
'op_run_info->requires_grad);\n')
|
|
401
398
|
convert_to_tensor_list_template = CppTemplate(
|
|
402
|
-
'auto ${output} = PyNativeAlgo::Common::ConvertStubNodeToValueTuple(${input}, ${need_contiguous}, '\
|
|
399
|
+
'auto ${output} = PyNativeAlgo::Common::ConvertStubNodeToValueTuple(${input}, ${need_contiguous}, ' \
|
|
403
400
|
'op_run_info->requires_grad);\n')
|
|
404
401
|
return convert_to_tensor_template, convert_to_tensor_list_template
|
|
405
402
|
|
|
@@ -411,7 +408,8 @@ def generate_pyboost_functions(work_path, yaml_data):
|
|
|
411
408
|
pyboost_func_str = ''
|
|
412
409
|
pyboost_func_pybind_def = ''
|
|
413
410
|
pyboost_func_include_headers_str = ''
|
|
414
|
-
pyboost_func_include_header_template = CppTemplate(
|
|
411
|
+
pyboost_func_include_header_template = CppTemplate(
|
|
412
|
+
f'#include "{K.MS_COMMON_PYBOOST_KERNEL_PATH}/auto_generate/${{operator_name}}.h"\n')
|
|
415
413
|
for operator_name, operator_data in yaml_data.items():
|
|
416
414
|
op_proto = OpProto.load_from_yaml(operator_name, operator_data)
|
|
417
415
|
if not op_proto.is_dispatch:
|
|
@@ -498,15 +496,18 @@ def generate_pyboost_functions(work_path, yaml_data):
|
|
|
498
496
|
call_args_str.append(call_arg)
|
|
499
497
|
cast_args_str.append(cast_arg)
|
|
500
498
|
type_num, same_type = gen_signature_same_type_table(op_proto.indexes, operator_data)
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
499
|
+
|
|
500
|
+
funcion_tpl = template.PYBOOS_COMM_FUNCTION_TEMPLATE \
|
|
501
|
+
if op_proto.is_comm_op else template.PYBOOST_FUNCTION_TEMPLATE
|
|
502
|
+
pyboost_func_str += funcion_tpl.replace(func_name=op_proto.pyboost_function_name,
|
|
503
|
+
op_def_name=op_def_name_str, same_type=same_type,
|
|
504
|
+
type_num=type_num, parser_body=parser_body_str,
|
|
505
|
+
op_name=op_name_str,
|
|
506
|
+
convert_stub=convert_stub_str,
|
|
507
|
+
optional_to_value=optional_to_value_str,
|
|
508
|
+
call_args=call_args_str, grad_args=grad_args_str,
|
|
509
|
+
cast_args=cast_args_str, op_args=op_args_str,
|
|
510
|
+
class_name=op_proto.class_name)
|
|
510
511
|
pyboost_func_str = pyboost_func_str + template.NEW_LINE + template.NEW_LINE
|
|
511
512
|
pyboost_func_pybind_def += template.REGISTER_DEFINE_TEMPLATE.replace(
|
|
512
513
|
pyboost_op_name=get_pyboost_name(op_proto.operator_name),
|
|
@@ -531,7 +532,7 @@ def convert_value_type(op_proto: OpProto) -> str:
|
|
|
531
532
|
:return: str
|
|
532
533
|
"""
|
|
533
534
|
convert_template = CppTemplate(
|
|
534
|
-
"auto $arg_name = ValueConverter::${convert_func}(op_runner_info->inputs
|
|
535
|
+
"auto convert_$arg_name = ValueConverter::${convert_func}(op_runner_info->inputs[$arg_index]);\n")
|
|
535
536
|
parser_func_str = ''
|
|
536
537
|
for index, arg in enumerate(op_proto.op_args):
|
|
537
538
|
is_optional = is_optional_param(arg)
|
|
@@ -541,9 +542,26 @@ def convert_value_type(op_proto: OpProto) -> str:
|
|
|
541
542
|
return parser_func_str
|
|
542
543
|
|
|
543
544
|
|
|
544
|
-
def
|
|
545
|
+
def convert_native_value_type(op_proto: OpProto) -> str:
|
|
546
|
+
"""
|
|
547
|
+
Generate native convert func
|
|
548
|
+
:param op_proto:
|
|
549
|
+
:return: str
|
|
550
|
+
"""
|
|
551
|
+
convert_template = CppTemplate(
|
|
552
|
+
"auto convert_$arg_name = runtime::ValueConverter::${convert_func}(ConvertNode2Value($arg_name));\n")
|
|
553
|
+
parser_func_str = ''
|
|
554
|
+
for arg in op_proto.op_args:
|
|
555
|
+
is_optional = is_optional_param(arg)
|
|
556
|
+
convert_type_str = get_value_convert_type_str(arg.arg_dtype, is_optional)
|
|
557
|
+
parser_func_str += convert_template.replace(arg_name=arg.arg_name, convert_func=convert_type_str)
|
|
558
|
+
return parser_func_str
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
def contiguous_tensor_value(op_proto: OpProto, device_target: str) -> str:
|
|
545
562
|
"""
|
|
546
563
|
Generate parser func
|
|
564
|
+
:param device_target:
|
|
547
565
|
:param op_proto:
|
|
548
566
|
:return: str
|
|
549
567
|
"""
|
|
@@ -551,13 +569,13 @@ def contiguous_tensor_value(op_proto: OpProto) -> str:
|
|
|
551
569
|
if op_proto.is_view:
|
|
552
570
|
return ''
|
|
553
571
|
contiguous_template = CppTemplate(
|
|
554
|
-
"$arg_name = ValueConverter::ContiguousTensorValue(
|
|
572
|
+
"convert_$arg_name = runtime::ValueConverter::ContiguousTensorValue($device_target, convert_$arg_name);\n")
|
|
555
573
|
contiguous_func_str = ''
|
|
556
574
|
need_contiguous_dtype = {'tensor', 'tuple[tensor]'}
|
|
557
575
|
for arg in op_proto.op_args:
|
|
558
576
|
if arg.arg_dtype not in need_contiguous_dtype:
|
|
559
577
|
continue
|
|
560
|
-
contiguous_func_str += contiguous_template.replace(arg_name=arg.arg_name)
|
|
578
|
+
contiguous_func_str += contiguous_template.replace(arg_name=arg.arg_name, device_target=device_target)
|
|
561
579
|
return contiguous_func_str
|
|
562
580
|
|
|
563
581
|
|
|
@@ -568,7 +586,8 @@ def generate_pyboost_grad_functions(work_path, yaml_data):
|
|
|
568
586
|
pyboost_func_str = ''
|
|
569
587
|
pyboost_func_reg_def = ''
|
|
570
588
|
pyboost_func_include_headers_str = ''
|
|
571
|
-
pyboost_func_include_header_template = CppTemplate(
|
|
589
|
+
pyboost_func_include_header_template = CppTemplate(
|
|
590
|
+
f'#include "{K.MS_COMMON_PYBOOST_KERNEL_PATH}/auto_generate/${{operator_name}}.h"\n')
|
|
572
591
|
for operator_name, operator_data in yaml_data.items():
|
|
573
592
|
if not is_pyboost_enable(operator_data):
|
|
574
593
|
continue
|
|
@@ -579,11 +598,12 @@ def generate_pyboost_grad_functions(work_path, yaml_data):
|
|
|
579
598
|
op_name_str = op_proto.class_name
|
|
580
599
|
op_args_str = [op_arg.arg_name for op_arg in op_proto.op_args]
|
|
581
600
|
convert_value_type_str = convert_value_type(op_proto)
|
|
582
|
-
|
|
601
|
+
device_target = "op_runner_info->device_target"
|
|
602
|
+
convert_value_type_str += contiguous_tensor_value(op_proto, device_target)
|
|
583
603
|
|
|
584
604
|
call_args_str = []
|
|
585
605
|
for op_arg in op_proto.op_args:
|
|
586
|
-
call_arg = op_arg.arg_name
|
|
606
|
+
call_arg = 'convert_' + op_arg.arg_name
|
|
587
607
|
call_args_str.append(call_arg)
|
|
588
608
|
pyboost_func_str += template.PYBOOST_GRAD_FUNCTION_TEMPLATE.replace(func_name=op_proto.pyboost_function_name,
|
|
589
609
|
op_name=op_name_str,
|
|
@@ -609,6 +629,70 @@ def generate_pyboost_grad_functions(work_path, yaml_data):
|
|
|
609
629
|
check_change_and_replace_file(dst_file_path, tmp_file_path)
|
|
610
630
|
|
|
611
631
|
|
|
632
|
+
def generate_pyboost_native_grad_functions(work_path, yaml_data):
|
|
633
|
+
"""
|
|
634
|
+
Generate pyboost native grad functions file from yaml.
|
|
635
|
+
"""
|
|
636
|
+
pyboost_func_str = ''
|
|
637
|
+
pyboost_func_include_headers_str = ''
|
|
638
|
+
native_function_headers_str = ''
|
|
639
|
+
native_include_header_template = CppTemplate(
|
|
640
|
+
f'#include "{K.MS_COMMON_PYBOOST_KERNEL_PATH}/auto_generate/${{operator_name}}.h"\n')
|
|
641
|
+
native_function_header_template = CppTemplate("static NodePtr $func_name(${call_args_with_type});\n")
|
|
642
|
+
native_function_sigle_output_template = "const auto &output_value = op->outputs()[0];\n"
|
|
643
|
+
native_function_multi_output_template = template.MULTI_OUTPUT_TEMPLATE
|
|
644
|
+
for operator_name, operator_data in yaml_data.items():
|
|
645
|
+
if not is_pyboost_enable(operator_data):
|
|
646
|
+
continue
|
|
647
|
+
op_proto = OpProto.load_from_yaml(operator_name, operator_data)
|
|
648
|
+
if not op_proto.is_dispatch:
|
|
649
|
+
continue
|
|
650
|
+
operator_name = op_proto.operator_name
|
|
651
|
+
op_name_str = op_proto.class_name
|
|
652
|
+
op_args_str = [op_arg.arg_name for op_arg in op_proto.op_args]
|
|
653
|
+
convert_value_type_str = convert_native_value_type(op_proto)
|
|
654
|
+
convert_value_type_str += contiguous_tensor_value(op_proto, "device_target_")
|
|
655
|
+
first_var_name = op_proto.op_args[0].arg_name
|
|
656
|
+
call_args_str = []
|
|
657
|
+
call_args_with_type = []
|
|
658
|
+
output_expr = native_function_sigle_output_template
|
|
659
|
+
if op_proto.is_multi_output:
|
|
660
|
+
output_expr = native_function_multi_output_template
|
|
661
|
+
for op_arg in op_proto.op_args:
|
|
662
|
+
call_arg = 'convert_' + op_arg.arg_name
|
|
663
|
+
call_args_str.append(call_arg)
|
|
664
|
+
call_args_with_type.append('const NodePtr &' + op_arg.arg_name)
|
|
665
|
+
pyboost_func_str += \
|
|
666
|
+
template.PYBOOST_NATIVE_GRAD_FUNCTION_TEMPLATE.replace(func_name=op_name_str,
|
|
667
|
+
op_name=op_name_str,
|
|
668
|
+
op_args=op_args_str,
|
|
669
|
+
convert_body=convert_value_type_str,
|
|
670
|
+
call_args=call_args_str,
|
|
671
|
+
call_args_with_type=call_args_with_type,
|
|
672
|
+
first_var_name=first_var_name,
|
|
673
|
+
output_expr=output_expr)
|
|
674
|
+
pyboost_func_str = pyboost_func_str + template.NEW_LINE
|
|
675
|
+
pyboost_func_include_headers_str += native_include_header_template.replace(operator_name=operator_name)
|
|
676
|
+
func_header = native_function_header_template.replace(func_name=op_name_str,
|
|
677
|
+
call_args_with_type=call_args_with_type)
|
|
678
|
+
native_function_headers_str += func_header
|
|
679
|
+
native_grad_func_file = \
|
|
680
|
+
template.PYBOOST_NATIVE_GRAD_FUNCTIONS_TEMPLATE.replace(include_op_header=pyboost_func_include_headers_str,
|
|
681
|
+
function_body=pyboost_func_str)
|
|
682
|
+
native_grad_func_header_file = template.PYBOOST_NATIVE_GRAD_FUNCTIONS_HEADER_TEMPLATE.replace(
|
|
683
|
+
native_grad_func_def=native_function_headers_str)
|
|
684
|
+
dir_path = os.path.join(work_path, "mindspore/ccsrc/pipeline/pynative/grad/function/auto_generate")
|
|
685
|
+
pathlib.Path(dir_path).mkdir(parents=True, exist_ok=True)
|
|
686
|
+
tmp_file_path = os.path.join(dir_path, "tmp_pyboost_native_grad_functions.cc")
|
|
687
|
+
dst_file_path = os.path.join(dir_path, "pyboost_native_grad_functions.cc")
|
|
688
|
+
write_file(tmp_file_path, native_grad_func_file)
|
|
689
|
+
check_change_and_replace_file(dst_file_path, tmp_file_path)
|
|
690
|
+
tmp_file_path = os.path.join(dir_path, "tmp_pyboost_native_grad_functions.h")
|
|
691
|
+
dst_file_path = os.path.join(dir_path, "pyboost_native_grad_functions.h")
|
|
692
|
+
write_file(tmp_file_path, native_grad_func_header_file)
|
|
693
|
+
check_change_and_replace_file(dst_file_path, tmp_file_path)
|
|
694
|
+
|
|
695
|
+
|
|
612
696
|
def generate_inplace_process_cpp_code(op_proto):
|
|
613
697
|
""" generate_ref_process_cpp_code """
|
|
614
698
|
inplace_process = f'// RefOps update output by input tensor\n'
|
|
@@ -640,9 +724,8 @@ def get_auto_generate_template():
|
|
|
640
724
|
template.PYBOOST_CPU_CUSTOMIZE_CALL_TEMPLATE]
|
|
641
725
|
op_view_template_path = [template.PYBOOST_ASCEND_VIEW_CALL_TEMPLATE, template.PYBOOST_GPU_VIEW_CALL_TEMPLATE,
|
|
642
726
|
template.PYBOOST_CPU_VIEW_CALL_TEMPLATE]
|
|
643
|
-
code_generate_path = ["
|
|
644
|
-
"
|
|
645
|
-
"mindspore/ccsrc/plugin/device/cpu/kernel/pyboost/auto_generate/"]
|
|
727
|
+
code_generate_path = [f"{K.MS_OPS_KERNEL_PATH}/{device}/pyboost/auto_generate/" for device in
|
|
728
|
+
["ascend", "gpu", "cpu"]]
|
|
646
729
|
return TemplatePaths(op_header_template_path, op_call_template_path, op_source_template_path,
|
|
647
730
|
op_custom_template_path,
|
|
648
731
|
op_view_template_path, code_generate_path)
|
|
@@ -692,7 +775,6 @@ class OpTemplateConverter:
|
|
|
692
775
|
call_args_with_types.append("const " + type_name + " &" + arg_name)
|
|
693
776
|
return call_args_with_types
|
|
694
777
|
|
|
695
|
-
|
|
696
778
|
@staticmethod
|
|
697
779
|
def parse_need_malloc_tensors(op_args, call_args):
|
|
698
780
|
"""
|
|
@@ -716,7 +798,6 @@ class OpTemplateConverter:
|
|
|
716
798
|
call_args_with_tensor.append(call_arg)
|
|
717
799
|
return need_malloc_tensors, tensor_list_convert, call_args_with_tensor
|
|
718
800
|
|
|
719
|
-
|
|
720
801
|
@staticmethod
|
|
721
802
|
def parse_original_call_args(op_args):
|
|
722
803
|
"""
|
|
@@ -760,7 +841,7 @@ def delete_residual_files(work_path, all_operator_name, code_generate_path_list)
|
|
|
760
841
|
"""
|
|
761
842
|
Delete residual files.
|
|
762
843
|
"""
|
|
763
|
-
code_generate_path_list.append("
|
|
844
|
+
code_generate_path_list.append(f"{K.MS_COMMON_PYBOOST_KERNEL_PATH}/auto_generate/")
|
|
764
845
|
for code_generate_path in code_generate_path_list:
|
|
765
846
|
all_files_name = []
|
|
766
847
|
code_generate_path = os.path.join(work_path, code_generate_path)
|
|
@@ -839,7 +920,8 @@ def gen_pyboost_inner_prim(work_path, op_yaml_data):
|
|
|
839
920
|
arg_handler = arg_info.get('arg_handler')
|
|
840
921
|
processed_arg = arg_name
|
|
841
922
|
if arg_handler is not None and arg_handler != 'dtype_to_type_id':
|
|
842
|
-
process_func +=
|
|
923
|
+
process_func += \
|
|
924
|
+
f"""converted_{arg_name} = {arg_handler}('{operator_name}', '{arg_name}', {arg_name})\n"""
|
|
843
925
|
processed_arg = 'converted_' + arg_name
|
|
844
926
|
input_args.append(arg_name)
|
|
845
927
|
processed_args.append(processed_arg)
|
|
@@ -952,17 +1034,19 @@ def gen_signature_same_type_table(args_map, operator_data):
|
|
|
952
1034
|
return type_num, signature_table
|
|
953
1035
|
|
|
954
1036
|
|
|
955
|
-
def gen_pyboost_code(work_path, ops_yaml_data, doc_yaml_data):
|
|
1037
|
+
def gen_pyboost_code(work_path, ops_yaml_data, doc_yaml_data, extra_ops):
|
|
956
1038
|
""" gen_pyboost_code """
|
|
957
1039
|
# generate pyboost inner prim
|
|
958
1040
|
gen_pyboost_inner_prim(work_path, ops_yaml_data)
|
|
959
1041
|
# generate pyboost py func
|
|
960
1042
|
gen_pyboost_py_func(work_path, ops_yaml_data, doc_yaml_data)
|
|
961
1043
|
# generate ops header file
|
|
962
|
-
generate_ops_header_files(work_path, ops_yaml_data)
|
|
1044
|
+
generate_ops_header_files(work_path, ops_yaml_data, extra_ops)
|
|
963
1045
|
# generate pyboost functions
|
|
964
1046
|
generate_pyboost_functions(work_path, ops_yaml_data)
|
|
965
1047
|
# generate pyboost grad functions
|
|
966
1048
|
generate_pyboost_grad_functions(work_path, ops_yaml_data)
|
|
1049
|
+
# generate pyboost native grad functions
|
|
1050
|
+
generate_pyboost_native_grad_functions(work_path, ops_yaml_data)
|
|
967
1051
|
# generate pyboost backend cpp code
|
|
968
1052
|
generate_pyboost_op_cpp_code(work_path, ops_yaml_data)
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
# ============================================================================
|
|
15
15
|
"""Op Proto."""
|
|
16
|
-
from pyboost_utils import convert_python_func_name_to_c
|
|
16
|
+
from pyboost_utils import convert_python_func_name_to_c, is_op_multi_output
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
class Arg:
|
|
@@ -44,7 +44,9 @@ class OpProto:
|
|
|
44
44
|
gpu,
|
|
45
45
|
ascend,
|
|
46
46
|
prim_init,
|
|
47
|
-
is_dispatch
|
|
47
|
+
is_dispatch,
|
|
48
|
+
is_multi_output,
|
|
49
|
+
is_comm_op):
|
|
48
50
|
self.operator_name = operator_name
|
|
49
51
|
self.class_name = class_name
|
|
50
52
|
self.op_args = op_args
|
|
@@ -58,6 +60,8 @@ class OpProto:
|
|
|
58
60
|
self.ascend = ascend
|
|
59
61
|
self.prim_init = prim_init
|
|
60
62
|
self.is_dispatch = is_dispatch
|
|
63
|
+
self.is_multi_output = is_multi_output
|
|
64
|
+
self.is_comm_op = is_comm_op
|
|
61
65
|
|
|
62
66
|
@staticmethod
|
|
63
67
|
def get_device_special_name(dispatch, gpu, cpu, ascend):
|
|
@@ -109,6 +113,7 @@ class OpProto:
|
|
|
109
113
|
|
|
110
114
|
is_pyboost = False
|
|
111
115
|
is_dispatch = False
|
|
116
|
+
is_comm_op = False
|
|
112
117
|
gpu = default_str
|
|
113
118
|
cpu = default_str
|
|
114
119
|
ascend = default_str
|
|
@@ -117,6 +122,7 @@ class OpProto:
|
|
|
117
122
|
is_dispatch = True
|
|
118
123
|
is_pyboost = yaml[dispatch_key].get('enable')
|
|
119
124
|
gpu, cpu, ascend = OpProto.get_device_special_name(yaml[dispatch_key], gpu, cpu, ascend)
|
|
125
|
+
is_comm_op = yaml[dispatch_key].get('is_comm_op')
|
|
120
126
|
return_dict = yaml['returns']
|
|
121
127
|
class_name = convert_python_func_name_to_c(op_name)
|
|
122
128
|
class_key = 'class'
|
|
@@ -130,9 +136,10 @@ class OpProto:
|
|
|
130
136
|
dtype = return_dict[return_name]['dtype']
|
|
131
137
|
arg = Arg(return_name, dtype, type_cast=[], inplace=inplace)
|
|
132
138
|
return_args.append(arg)
|
|
139
|
+
is_multi_output = is_op_multi_output(return_args)
|
|
133
140
|
is_view = False
|
|
134
141
|
if 'view' in yaml.keys():
|
|
135
142
|
is_view = True
|
|
136
143
|
op_proto = OpProto(op_name, op_args, return_args, class_name,
|
|
137
|
-
is_pyboost, is_view, cpu, gpu, ascend, prim_init, is_dispatch)
|
|
144
|
+
is_pyboost, is_view, cpu, gpu, ascend, prim_init, is_dispatch, is_multi_output, is_comm_op)
|
|
138
145
|
return op_proto
|
|
@@ -44,6 +44,19 @@ def is_list(op_arg):
|
|
|
44
44
|
return False
|
|
45
45
|
|
|
46
46
|
|
|
47
|
+
def is_op_multi_output(args):
|
|
48
|
+
"""
|
|
49
|
+
is multi output
|
|
50
|
+
:param args:
|
|
51
|
+
:return: bool
|
|
52
|
+
"""
|
|
53
|
+
if len(args) > 1:
|
|
54
|
+
return True
|
|
55
|
+
if len(args) == 1 and is_tensor_list(args[0]):
|
|
56
|
+
return True
|
|
57
|
+
return False
|
|
58
|
+
|
|
59
|
+
|
|
47
60
|
def get_index(index: int):
|
|
48
61
|
"""
|
|
49
62
|
get index
|
|
@@ -339,7 +352,7 @@ class AclnnUtils:
|
|
|
339
352
|
"""
|
|
340
353
|
aclnn utils
|
|
341
354
|
"""
|
|
342
|
-
work_path = os.path.join(os.path.dirname(os.path.
|
|
355
|
+
work_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../../../")
|
|
343
356
|
aclnn_map = safe_load_yaml(os.path.join(work_path, "./mindspore/python/mindspore/ops_generate/aclnn_config.yaml"))
|
|
344
357
|
|
|
345
358
|
@staticmethod
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"""Template."""
|
|
16
16
|
import re
|
|
17
17
|
import os
|
|
18
|
+
import gen_constants as K
|
|
18
19
|
|
|
19
20
|
|
|
20
21
|
class CppTemplate:
|
|
@@ -79,14 +80,14 @@ class CppTemplate:
|
|
|
79
80
|
|
|
80
81
|
|
|
81
82
|
NEW_LINE = "\n"
|
|
82
|
-
WORK_PATH = os.path.join(os.path.dirname(os.path.
|
|
83
|
+
WORK_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../../../")
|
|
83
84
|
|
|
84
85
|
PYTHON_PRIM_TEMPLATE = CppTemplate("""
|
|
85
86
|
|
|
86
87
|
class _Pyboost${class_name}Prim(${class_name}Prim_):
|
|
87
88
|
def __call__(self, ${input_args}):
|
|
88
89
|
${process_func}
|
|
89
|
-
return _convert_stub(super().__call__(${
|
|
90
|
+
return _convert_stub(super().__call__(${processed_args}))
|
|
90
91
|
|
|
91
92
|
|
|
92
93
|
${func_impl_name}_impl = _Pyboost${class_name}Prim()
|
|
@@ -119,6 +120,9 @@ REGISTER_PYBOOST_GRAD_TEMPLATE = CppTemplate("${register_func}")
|
|
|
119
120
|
PYBOOST_FUNCTION_TEMPLATE = CppTemplate.load_from_file(
|
|
120
121
|
os.path.join(WORK_PATH, './mindspore/ccsrc/pipeline/pynative/op_function/template/pyboost_function.tpl'))
|
|
121
122
|
|
|
123
|
+
PYBOOS_COMM_FUNCTION_TEMPLATE = CppTemplate.load_from_file(
|
|
124
|
+
os.path.join(WORK_PATH, './mindspore/ccsrc/pipeline/pynative/op_function/template/pyboost_comm_function.tpl'))
|
|
125
|
+
|
|
122
126
|
PYBOOST_HEADER_TEMPLATE = CppTemplate.load_from_file(
|
|
123
127
|
os.path.join(WORK_PATH, './mindspore/ccsrc/pipeline/pynative/op_function/template/pyboost_function_header.tpl'))
|
|
124
128
|
|
|
@@ -126,83 +130,93 @@ PYBOOST_GRAD_FUNCTION_TEMPLATE = CppTemplate.load_from_file(
|
|
|
126
130
|
os.path.join(WORK_PATH, './mindspore/ccsrc/runtime/pynative/op_function/template/pyboost_grad_function.tpl'))
|
|
127
131
|
|
|
128
132
|
PYBOOST_GRAD_HEADER_TEMPLATE = CppTemplate.load_from_file(
|
|
133
|
+
os.path.join(WORK_PATH, './mindspore/ccsrc/runtime/pynative/op_function/template/pyboost_grad_function_header.tpl'))
|
|
134
|
+
|
|
135
|
+
PYBOOST_NATIVE_GRAD_FUNCTION_TEMPLATE = CppTemplate.load_from_file(
|
|
136
|
+
os.path.join(WORK_PATH, './mindspore/ccsrc/pipeline/pynative/grad/function/template/native_grad_function.tpl'))
|
|
137
|
+
|
|
138
|
+
PYBOOST_NATIVE_GRAD_FUNCTIONS_TEMPLATE = CppTemplate.load_from_file(
|
|
129
139
|
os.path.join(WORK_PATH,
|
|
130
|
-
'./mindspore/ccsrc/
|
|
140
|
+
'./mindspore/ccsrc/pipeline/pynative/grad/function/template/pyboost_native_grad_functions.tpl'))
|
|
141
|
+
|
|
142
|
+
PYBOOST_NATIVE_GRAD_FUNCTIONS_HEADER_TEMPLATE = CppTemplate.load_from_file(
|
|
143
|
+
os.path.join(WORK_PATH,
|
|
144
|
+
'./mindspore/ccsrc/pipeline/pynative/grad/function/template/pyboost_native_grad_functions_header.tpl'))
|
|
131
145
|
|
|
132
146
|
GEN_OPS_DEF_HEADER_TEMPLATE = CppTemplate.load_from_file(
|
|
133
147
|
os.path.join(WORK_PATH, './mindspore/python/mindspore/ops_generate/gen_ops_def_header.tpl'))
|
|
134
148
|
|
|
135
149
|
PYBOOST_BASE_OP_DEFINE_TEMPLATE = CppTemplate.load_from_file(
|
|
136
|
-
os.path.join(WORK_PATH, './
|
|
150
|
+
os.path.join(WORK_PATH, f'./{K.MS_COMMON_PYBOOST_KERNEL_PATH}/template/pyboost_op_header.tpl'))
|
|
137
151
|
|
|
138
152
|
PYBOOST_OP_REGISTER_TEMPLATE = CppTemplate.load_from_file(
|
|
139
|
-
os.path.join(WORK_PATH, './
|
|
153
|
+
os.path.join(WORK_PATH, f'./{K.MS_COMMON_PYBOOST_KERNEL_PATH}/template/pyboost_op_register.tpl'))
|
|
140
154
|
|
|
141
155
|
# Ascend op generate
|
|
142
156
|
PYBOOST_ASCEND_OP_HEADER_TEMPLATE = CppTemplate.load_from_file(
|
|
143
157
|
os.path.join(WORK_PATH,
|
|
144
|
-
'./
|
|
158
|
+
f'./{K.MS_OPS_KERNEL_PATH}/ascend/pyboost/template/pyboost_aclnn_header_template.tpl'))
|
|
145
159
|
|
|
146
160
|
PYBOOST_ASCEND_OP_SOURCE_TEMPLATE = CppTemplate.load_from_file(
|
|
147
161
|
os.path.join(WORK_PATH,
|
|
148
|
-
'./
|
|
162
|
+
f'./{K.MS_OPS_KERNEL_PATH}/ascend/pyboost/template/pyboost_aclnn_source_template.tpl'))
|
|
149
163
|
|
|
150
164
|
PYBOOST_ASCEND_CALL_TEMPLATE = CppTemplate.load_from_file(
|
|
151
165
|
os.path.join(WORK_PATH,
|
|
152
|
-
'./
|
|
166
|
+
f'./{K.MS_OPS_KERNEL_PATH}/ascend/pyboost/template/pyboost_ascend_call_template.tpl'))
|
|
153
167
|
|
|
154
168
|
PYBOOST_ASCEND_VIEW_CALL_TEMPLATE = CppTemplate.load_from_file(
|
|
155
169
|
os.path.join(WORK_PATH,
|
|
156
|
-
'./
|
|
170
|
+
f'./{K.MS_COMMON_PYBOOST_KERNEL_PATH}/template/'
|
|
157
171
|
'pyboost_view_template.tpl'))
|
|
158
172
|
|
|
159
173
|
PYBOOST_ASCEND_CUSTOMIZE_CALL_TEMPLATE = CppTemplate.load_from_file(
|
|
160
174
|
os.path.join(WORK_PATH,
|
|
161
|
-
'./
|
|
175
|
+
f'./{K.MS_OPS_KERNEL_PATH}/ascend/pyboost/template'
|
|
162
176
|
'/pyboost_ascend_customize_call_template.tpl'))
|
|
163
177
|
|
|
164
178
|
# GPU op generate
|
|
165
179
|
PYBOOST_GPU_OP_HEADER_TEMPLATE = CppTemplate.load_from_file(
|
|
166
180
|
os.path.join(WORK_PATH,
|
|
167
|
-
'./mindspore/
|
|
181
|
+
'./mindspore/ops/kernel/gpu/pyboost/template/pyboost_gpu_header_template.tpl'))
|
|
168
182
|
|
|
169
183
|
PYBOOST_GPU_OP_SOURCE_TEMPLATE = CppTemplate.load_from_file(
|
|
170
184
|
os.path.join(WORK_PATH,
|
|
171
|
-
'./mindspore/
|
|
185
|
+
'./mindspore/ops/kernel/gpu/pyboost/template/pyboost_gpu_source_template.tpl'))
|
|
172
186
|
|
|
173
187
|
PYBOOST_GPU_CALL_TEMPLATE = CppTemplate.load_from_file(
|
|
174
188
|
os.path.join(WORK_PATH,
|
|
175
|
-
'./mindspore/
|
|
189
|
+
'./mindspore/ops/kernel/gpu/pyboost/template/pyboost_gpu_call_template.tpl'))
|
|
176
190
|
|
|
177
191
|
PYBOOST_GPU_VIEW_CALL_TEMPLATE = CppTemplate.load_from_file(
|
|
178
192
|
os.path.join(WORK_PATH,
|
|
179
|
-
'./
|
|
193
|
+
f'./{K.MS_COMMON_PYBOOST_KERNEL_PATH}/template/pyboost_view_template.tpl'))
|
|
180
194
|
|
|
181
195
|
PYBOOST_GPU_CUSTOMIZE_CALL_TEMPLATE = CppTemplate.load_from_file(
|
|
182
196
|
os.path.join(WORK_PATH,
|
|
183
|
-
'./mindspore/
|
|
197
|
+
'./mindspore/ops/kernel/gpu/pyboost/template'
|
|
184
198
|
'/pyboost_gpu_customize_call_template.tpl'))
|
|
185
199
|
|
|
186
200
|
# CPU op generate
|
|
187
201
|
PYBOOST_CPU_OP_HEADER_TEMPLATE = CppTemplate.load_from_file(
|
|
188
202
|
os.path.join(WORK_PATH,
|
|
189
|
-
'./
|
|
203
|
+
f'./{K.MS_OPS_KERNEL_PATH}/cpu/pyboost/template/pyboost_cpu_header_template.tpl'))
|
|
190
204
|
|
|
191
205
|
PYBOOST_CPU_OP_SOURCE_TEMPLATE = CppTemplate.load_from_file(
|
|
192
206
|
os.path.join(WORK_PATH,
|
|
193
|
-
'./
|
|
207
|
+
f'./{K.MS_OPS_KERNEL_PATH}/cpu/pyboost/template/pyboost_cpu_source_template.tpl'))
|
|
194
208
|
|
|
195
209
|
PYBOOST_CPU_CALL_TEMPLATE = CppTemplate.load_from_file(
|
|
196
210
|
os.path.join(WORK_PATH,
|
|
197
|
-
'./
|
|
211
|
+
f'./{K.MS_OPS_KERNEL_PATH}/cpu/pyboost/template/pyboost_cpu_call_template.tpl'))
|
|
198
212
|
|
|
199
213
|
PYBOOST_CPU_VIEW_CALL_TEMPLATE = CppTemplate.load_from_file(
|
|
200
214
|
os.path.join(WORK_PATH,
|
|
201
|
-
'./
|
|
215
|
+
f'./{K.MS_COMMON_PYBOOST_KERNEL_PATH}/template/pyboost_view_template.tpl'))
|
|
202
216
|
|
|
203
217
|
PYBOOST_CPU_CUSTOMIZE_CALL_TEMPLATE = CppTemplate.load_from_file(
|
|
204
218
|
os.path.join(WORK_PATH,
|
|
205
|
-
'./
|
|
219
|
+
f'./{K.MS_OPS_KERNEL_PATH}/cpu/pyboost/template'
|
|
206
220
|
'/pyboost_cpu_customize_call_template.tpl'))
|
|
207
221
|
|
|
208
222
|
PYBOOST_PY_FUNC_IMPORT_HEADEAR = CppTemplate(
|
|
@@ -224,7 +238,7 @@ OpDef g${class_name} = {
|
|
|
224
238
|
${input_args}
|
|
225
239
|
},
|
|
226
240
|
/* .returns_ = */ {
|
|
227
|
-
${return_args}
|
|
241
|
+
${return_args}
|
|
228
242
|
},
|
|
229
243
|
/*.signatures_ =*/ {
|
|
230
244
|
${signatures}
|
|
@@ -236,4 +250,12 @@ OpDef g${class_name} = {
|
|
|
236
250
|
/*.enable_dispatch_ =*/${enable_dispatch},
|
|
237
251
|
/*.is_view_ =*/${is_view},
|
|
238
252
|
};
|
|
253
|
+
REGISTER_PRIMITIVE_OP_DEF(${class_name}, &g${class_name});
|
|
239
254
|
""")
|
|
255
|
+
|
|
256
|
+
MULTI_OUTPUT_TEMPLATE = """
|
|
257
|
+
ValuePtrList values;
|
|
258
|
+
(void)std::transform(op->outputs().begin(), op->outputs().end(), std::back_inserter(values),
|
|
259
|
+
[](const auto &value){ return value;});
|
|
260
|
+
auto output_value = std::make_shared<ValueTuple>(values);
|
|
261
|
+
"""
|
mindspore/parallel/__init__.py
CHANGED
|
@@ -22,7 +22,9 @@ from mindspore.parallel.checkpoint_transform import rank_list_for_transform, tra
|
|
|
22
22
|
load_segmented_checkpoints
|
|
23
23
|
from mindspore.parallel.parameter_broadcast import parameter_broadcast
|
|
24
24
|
from mindspore.parallel.shard import shard, Layout
|
|
25
|
+
from mindspore.parallel.transform_safetensors import safetensors_to_ckpt, ckpt_to_safetensors, unified_safetensors
|
|
25
26
|
|
|
26
27
|
__all__ = ["set_algo_parameters", "reset_algo_parameters", "get_algo_parameters", "rank_list_for_transform",
|
|
27
28
|
"transform_checkpoint_by_rank", "transform_checkpoints", "merge_pipeline_strategys", "shard",
|
|
28
|
-
"sync_pipeline_shared_parameters", "Layout", "parameter_broadcast", "load_segmented_checkpoints"
|
|
29
|
+
"sync_pipeline_shared_parameters", "Layout", "parameter_broadcast", "load_segmented_checkpoints",
|
|
30
|
+
"safetensors_to_ckpt", "ckpt_to_safetensors", "unified_safetensors"]
|