mindspore 2.7.0__cp310-cp310-win_amd64.whl → 2.7.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.

Files changed (290) hide show
  1. mindspore/.commit_id +1 -1
  2. mindspore/__init__.py +4 -1
  3. mindspore/_c_dataengine.cp310-win_amd64.pyd +0 -0
  4. mindspore/_c_expression.cp310-win_amd64.pyd +0 -0
  5. mindspore/_c_mindrecord.cp310-win_amd64.pyd +0 -0
  6. mindspore/_extends/parse/compile_config.py +24 -1
  7. mindspore/_extends/parse/deprecated/deprecated_tensor_method.py +6 -2
  8. mindspore/_extends/parse/resources.py +1 -1
  9. mindspore/_extends/parse/standard_method.py +8 -1
  10. mindspore/_extends/parse/trope.py +2 -1
  11. mindspore/_extends/pijit/pijit_func_white_list.py +7 -22
  12. mindspore/avcodec-59.dll +0 -0
  13. mindspore/avdevice-59.dll +0 -0
  14. mindspore/avfilter-8.dll +0 -0
  15. mindspore/avformat-59.dll +0 -0
  16. mindspore/avutil-57.dll +0 -0
  17. mindspore/boost/base.py +29 -2
  18. mindspore/common/_decorator.py +3 -2
  19. mindspore/common/_grad_function.py +3 -1
  20. mindspore/common/_tensor_cpp_method.py +1 -1
  21. mindspore/common/_tensor_docs.py +275 -64
  22. mindspore/common/_utils.py +0 -44
  23. mindspore/common/api.py +285 -35
  24. mindspore/common/dump.py +7 -108
  25. mindspore/common/dynamic_shape/auto_dynamic_shape.py +1 -3
  26. mindspore/common/hook_handle.py +60 -0
  27. mindspore/common/jit_config.py +5 -1
  28. mindspore/common/jit_trace.py +27 -12
  29. mindspore/common/lazy_inline.py +5 -3
  30. mindspore/common/parameter.py +13 -107
  31. mindspore/common/recompute.py +4 -11
  32. mindspore/common/tensor.py +16 -169
  33. mindspore/communication/_comm_helper.py +11 -1
  34. mindspore/communication/comm_func.py +138 -4
  35. mindspore/communication/management.py +85 -1
  36. mindspore/config/op_info.config +0 -15
  37. mindspore/context.py +5 -85
  38. mindspore/dataset/engine/datasets.py +8 -4
  39. mindspore/dataset/engine/datasets_vision.py +1 -1
  40. mindspore/dataset/engine/validators.py +1 -15
  41. mindspore/dnnl.dll +0 -0
  42. mindspore/{experimental/llm_boost/ascend_native → graph}/__init__.py +7 -7
  43. mindspore/graph/custom_pass.py +55 -0
  44. mindspore/include/dataset/execute.h +2 -2
  45. mindspore/jpeg62.dll +0 -0
  46. mindspore/mindrecord/__init__.py +3 -3
  47. mindspore/mindrecord/common/exceptions.py +1 -0
  48. mindspore/mindrecord/config.py +1 -1
  49. mindspore/{parallel/mpi → mindrecord/core}/__init__.py +4 -1
  50. mindspore/mindrecord/{shardheader.py → core/shardheader.py} +2 -1
  51. mindspore/mindrecord/{shardindexgenerator.py → core/shardindexgenerator.py} +1 -1
  52. mindspore/mindrecord/{shardreader.py → core/shardreader.py} +2 -1
  53. mindspore/mindrecord/{shardsegment.py → core/shardsegment.py} +2 -2
  54. mindspore/mindrecord/{shardutils.py → core/shardutils.py} +1 -1
  55. mindspore/mindrecord/{shardwriter.py → core/shardwriter.py} +1 -1
  56. mindspore/mindrecord/filereader.py +4 -4
  57. mindspore/mindrecord/filewriter.py +5 -5
  58. mindspore/mindrecord/mindpage.py +2 -2
  59. mindspore/mindrecord/tools/cifar10.py +1 -1
  60. mindspore/mindrecord/tools/cifar100.py +1 -1
  61. mindspore/mindrecord/tools/cifar100_to_mr.py +1 -1
  62. mindspore/mindrecord/tools/cifar10_to_mr.py +1 -1
  63. mindspore/mindrecord/tools/csv_to_mr.py +1 -1
  64. mindspore/mindrecord/tools/imagenet_to_mr.py +1 -1
  65. mindspore/mindrecord/tools/mnist_to_mr.py +1 -1
  66. mindspore/mindrecord/tools/tfrecord_to_mr.py +1 -1
  67. mindspore/mindspore_backend_common.dll +0 -0
  68. mindspore/mindspore_backend_manager.dll +0 -0
  69. mindspore/mindspore_cluster.dll +0 -0
  70. mindspore/mindspore_common.dll +0 -0
  71. mindspore/mindspore_core.dll +0 -0
  72. mindspore/mindspore_cpu.dll +0 -0
  73. mindspore/mindspore_dump.dll +0 -0
  74. mindspore/mindspore_frontend.dll +0 -0
  75. mindspore/mindspore_glog.dll +0 -0
  76. mindspore/mindspore_hardware_abstract.dll +0 -0
  77. mindspore/mindspore_memory_pool.dll +0 -0
  78. mindspore/mindspore_ms_backend.dll +0 -0
  79. mindspore/mindspore_ops.dll +0 -0
  80. mindspore/{mindspore_ops_host.dll → mindspore_ops_cpu.dll} +0 -0
  81. mindspore/mindspore_profiler.dll +0 -0
  82. mindspore/mindspore_pyboost.dll +0 -0
  83. mindspore/mindspore_pynative.dll +0 -0
  84. mindspore/mindspore_runtime_pipeline.dll +0 -0
  85. mindspore/mindspore_runtime_utils.dll +0 -0
  86. mindspore/mindspore_tools.dll +0 -0
  87. mindspore/mint/__init__.py +15 -10
  88. mindspore/mint/distributed/distributed.py +182 -62
  89. mindspore/mint/nn/__init__.py +2 -16
  90. mindspore/mint/nn/functional.py +4 -110
  91. mindspore/mint/nn/layer/__init__.py +0 -2
  92. mindspore/mint/nn/layer/activation.py +0 -6
  93. mindspore/mint/nn/layer/basic.py +0 -47
  94. mindspore/mint/nn/layer/conv.py +4 -4
  95. mindspore/mint/nn/layer/normalization.py +8 -13
  96. mindspore/mint/nn/layer/pooling.py +0 -4
  97. mindspore/nn/__init__.py +1 -3
  98. mindspore/nn/cell.py +16 -66
  99. mindspore/nn/layer/basic.py +49 -1
  100. mindspore/nn/layer/container.py +16 -0
  101. mindspore/nn/layer/embedding.py +4 -169
  102. mindspore/nn/layer/normalization.py +2 -1
  103. mindspore/nn/layer/thor_layer.py +4 -85
  104. mindspore/nn/optim/ada_grad.py +0 -1
  105. mindspore/nn/optim/adafactor.py +0 -1
  106. mindspore/nn/optim/adam.py +31 -124
  107. mindspore/nn/optim/adamax.py +0 -1
  108. mindspore/nn/optim/asgd.py +0 -1
  109. mindspore/nn/optim/ftrl.py +8 -102
  110. mindspore/nn/optim/lamb.py +0 -1
  111. mindspore/nn/optim/lars.py +0 -3
  112. mindspore/nn/optim/lazyadam.py +25 -218
  113. mindspore/nn/optim/momentum.py +5 -43
  114. mindspore/nn/optim/optimizer.py +6 -55
  115. mindspore/nn/optim/proximal_ada_grad.py +0 -1
  116. mindspore/nn/optim/rmsprop.py +0 -1
  117. mindspore/nn/optim/rprop.py +0 -1
  118. mindspore/nn/optim/sgd.py +0 -1
  119. mindspore/nn/optim/tft_wrapper.py +0 -1
  120. mindspore/nn/optim/thor.py +0 -2
  121. mindspore/nn/probability/bijector/bijector.py +7 -8
  122. mindspore/nn/probability/bijector/gumbel_cdf.py +2 -2
  123. mindspore/nn/probability/bijector/power_transform.py +20 -21
  124. mindspore/nn/probability/bijector/scalar_affine.py +5 -5
  125. mindspore/nn/probability/bijector/softplus.py +13 -14
  126. mindspore/nn/wrap/grad_reducer.py +4 -74
  127. mindspore/numpy/array_creations.py +2 -2
  128. mindspore/numpy/fft.py +9 -9
  129. mindspore/{nn/reinforcement → onnx}/__init__.py +5 -8
  130. mindspore/onnx/onnx_export.py +137 -0
  131. mindspore/opencv_core4110.dll +0 -0
  132. mindspore/opencv_imgcodecs4110.dll +0 -0
  133. mindspore/{opencv_imgproc452.dll → opencv_imgproc4110.dll} +0 -0
  134. mindspore/ops/__init__.py +2 -0
  135. mindspore/ops/_grad_experimental/grad_comm_ops.py +38 -2
  136. mindspore/ops/_op_impl/aicpu/__init__.py +0 -10
  137. mindspore/ops/_op_impl/cpu/__init__.py +0 -5
  138. mindspore/ops/auto_generate/cpp_create_prim_instance_helper.py +16 -22
  139. mindspore/ops/auto_generate/gen_extend_func.py +2 -7
  140. mindspore/ops/auto_generate/gen_ops_def.py +98 -141
  141. mindspore/ops/auto_generate/gen_ops_prim.py +12708 -12686
  142. mindspore/ops/communication.py +97 -0
  143. mindspore/ops/composite/__init__.py +5 -2
  144. mindspore/ops/composite/base.py +15 -1
  145. mindspore/ops/composite/multitype_ops/__init__.py +3 -1
  146. mindspore/ops/composite/multitype_ops/_compile_utils.py +150 -8
  147. mindspore/ops/composite/multitype_ops/add_impl.py +7 -0
  148. mindspore/ops/composite/multitype_ops/mod_impl.py +27 -0
  149. mindspore/ops/function/__init__.py +1 -0
  150. mindspore/ops/function/array_func.py +14 -12
  151. mindspore/ops/function/comm_func.py +3883 -0
  152. mindspore/ops/function/debug_func.py +3 -4
  153. mindspore/ops/function/math_func.py +45 -54
  154. mindspore/ops/function/nn_func.py +75 -294
  155. mindspore/ops/function/random_func.py +9 -18
  156. mindspore/ops/functional.py +2 -0
  157. mindspore/ops/functional_overload.py +354 -18
  158. mindspore/ops/operations/__init__.py +2 -5
  159. mindspore/ops/operations/_custom_ops_utils.py +7 -9
  160. mindspore/ops/operations/_inner_ops.py +1 -38
  161. mindspore/ops/operations/_rl_inner_ops.py +0 -933
  162. mindspore/ops/operations/array_ops.py +1 -0
  163. mindspore/ops/operations/comm_ops.py +94 -2
  164. mindspore/ops/operations/custom_ops.py +228 -19
  165. mindspore/ops/operations/debug_ops.py +27 -29
  166. mindspore/ops/operations/manually_defined/ops_def.py +27 -306
  167. mindspore/ops/operations/nn_ops.py +2 -2
  168. mindspore/ops/operations/sparse_ops.py +0 -83
  169. mindspore/ops/primitive.py +1 -17
  170. mindspore/ops/tensor_method.py +72 -3
  171. mindspore/ops_generate/aclnn/aclnn_kernel_register_auto_cc_generator.py +5 -5
  172. mindspore/ops_generate/aclnn/gen_aclnn_implement.py +8 -8
  173. mindspore/ops_generate/api/functions_cc_generator.py +53 -4
  174. mindspore/ops_generate/api/tensor_func_reg_cpp_generator.py +25 -11
  175. mindspore/ops_generate/common/gen_constants.py +11 -10
  176. mindspore/ops_generate/common/op_proto.py +18 -1
  177. mindspore/ops_generate/common/template.py +102 -245
  178. mindspore/ops_generate/common/template_utils.py +212 -0
  179. mindspore/ops_generate/gen_custom_ops.py +69 -0
  180. mindspore/ops_generate/op_def/ops_def_cc_generator.py +78 -7
  181. mindspore/ops_generate/op_def_py/base_op_prim_py_generator.py +360 -0
  182. mindspore/ops_generate/op_def_py/custom_op_prim_py_generator.py +140 -0
  183. mindspore/ops_generate/op_def_py/op_def_py_generator.py +54 -7
  184. mindspore/ops_generate/op_def_py/op_prim_py_generator.py +5 -312
  185. mindspore/ops_generate/pyboost/auto_grad_impl_cc_generator.py +74 -17
  186. mindspore/ops_generate/pyboost/auto_grad_reg_cc_generator.py +22 -5
  187. mindspore/ops_generate/pyboost/op_template_parser.py +3 -2
  188. mindspore/ops_generate/pyboost/pyboost_functions_cpp_generator.py +21 -5
  189. mindspore/ops_generate/pyboost/pyboost_functions_h_generator.py +2 -2
  190. mindspore/ops_generate/pyboost/pyboost_functions_impl_cpp_generator.py +30 -10
  191. mindspore/ops_generate/pyboost/pyboost_grad_function_cpp_generator.py +10 -3
  192. mindspore/ops_generate/pyboost/pyboost_internal_kernel_info_adapter_generator.py +1 -1
  193. mindspore/ops_generate/pyboost/pyboost_native_grad_functions_generator.py +19 -9
  194. mindspore/ops_generate/pyboost/pyboost_op_cpp_code_generator.py +71 -28
  195. mindspore/ops_generate/pyboost/pyboost_overload_functions_cpp_generator.py +10 -9
  196. mindspore/ops_generate/pyboost/pyboost_utils.py +27 -16
  197. mindspore/ops_generate/resources/yaml_loader.py +13 -0
  198. mindspore/ops_generate/tensor_py_cc_generator.py +2 -2
  199. mindspore/parallel/_cell_wrapper.py +1 -1
  200. mindspore/parallel/_parallel_serialization.py +1 -4
  201. mindspore/parallel/_utils.py +29 -6
  202. mindspore/parallel/checkpoint_transform.py +18 -2
  203. mindspore/parallel/cluster/process_entity/_api.py +24 -32
  204. mindspore/parallel/cluster/process_entity/_utils.py +9 -5
  205. mindspore/{experimental/llm_boost/atb → parallel/distributed}/__init__.py +21 -23
  206. mindspore/parallel/distributed/distributed_data_parallel.py +393 -0
  207. mindspore/parallel/distributed/flatten_grad_buffer.py +295 -0
  208. mindspore/parallel/strategy.py +336 -0
  209. mindspore/parallel/transform_safetensors.py +117 -16
  210. mindspore/profiler/analysis/viewer/ascend_kernel_details_viewer.py +3 -0
  211. mindspore/profiler/analysis/viewer/ms_minddata_viewer.py +1 -1
  212. mindspore/profiler/common/constant.py +5 -0
  213. mindspore/profiler/common/file_manager.py +9 -0
  214. mindspore/profiler/common/msprof_cmd_tool.py +38 -2
  215. mindspore/profiler/common/path_manager.py +56 -24
  216. mindspore/profiler/common/profiler_context.py +2 -12
  217. mindspore/profiler/common/profiler_info.py +3 -3
  218. mindspore/profiler/common/profiler_path_manager.py +13 -0
  219. mindspore/profiler/common/util.py +30 -3
  220. mindspore/profiler/experimental_config.py +2 -1
  221. mindspore/profiler/platform/npu_profiler.py +33 -6
  222. mindspore/run_check/_check_version.py +108 -24
  223. mindspore/runtime/__init__.py +3 -2
  224. mindspore/runtime/executor.py +11 -3
  225. mindspore/runtime/memory.py +112 -0
  226. mindspore/swresample-4.dll +0 -0
  227. mindspore/swscale-6.dll +0 -0
  228. mindspore/tinyxml2.dll +0 -0
  229. mindspore/{experimental/llm_boost → tools}/__init__.py +5 -5
  230. mindspore/tools/data_dump.py +130 -0
  231. mindspore/tools/sdc_detect.py +91 -0
  232. mindspore/tools/stress_detect.py +63 -0
  233. mindspore/train/__init__.py +6 -6
  234. mindspore/train/_utils.py +5 -18
  235. mindspore/train/amp.py +6 -4
  236. mindspore/train/callback/_checkpoint.py +0 -9
  237. mindspore/train/callback/_train_fault_tolerance.py +69 -18
  238. mindspore/train/data_sink.py +1 -5
  239. mindspore/train/model.py +38 -211
  240. mindspore/train/serialization.py +126 -387
  241. mindspore/turbojpeg.dll +0 -0
  242. mindspore/utils/__init__.py +6 -3
  243. mindspore/utils/dlpack.py +92 -0
  244. mindspore/utils/dryrun.py +1 -1
  245. mindspore/utils/runtime_execution_order_check.py +10 -0
  246. mindspore/utils/sdc_detect.py +14 -12
  247. mindspore/utils/stress_detect.py +43 -0
  248. mindspore/utils/utils.py +144 -8
  249. mindspore/version.py +1 -1
  250. {mindspore-2.7.0.dist-info → mindspore-2.7.1.dist-info}/METADATA +3 -2
  251. {mindspore-2.7.0.dist-info → mindspore-2.7.1.dist-info}/RECORD +254 -267
  252. mindspore/experimental/llm_boost/ascend_native/llama_boost_ascend_native.py +0 -210
  253. mindspore/experimental/llm_boost/ascend_native/llm_boost.py +0 -52
  254. mindspore/experimental/llm_boost/atb/boost_base.py +0 -385
  255. mindspore/experimental/llm_boost/atb/llama_boost.py +0 -137
  256. mindspore/experimental/llm_boost/atb/qwen_boost.py +0 -124
  257. mindspore/experimental/llm_boost/register.py +0 -130
  258. mindspore/experimental/llm_boost/utils.py +0 -31
  259. mindspore/include/OWNERS +0 -7
  260. mindspore/mindspore_cpu_res_manager.dll +0 -0
  261. mindspore/mindspore_ops_kernel_common.dll +0 -0
  262. mindspore/mindspore_res_manager.dll +0 -0
  263. mindspore/nn/optim/_dist_optimizer_registry.py +0 -111
  264. mindspore/nn/reinforcement/_batch_read_write.py +0 -142
  265. mindspore/nn/reinforcement/_tensors_queue.py +0 -152
  266. mindspore/nn/reinforcement/tensor_array.py +0 -145
  267. mindspore/opencv_core452.dll +0 -0
  268. mindspore/opencv_imgcodecs452.dll +0 -0
  269. mindspore/ops/_op_impl/aicpu/priority_replay_buffer.py +0 -113
  270. mindspore/ops/_op_impl/aicpu/reservoir_replay_buffer.py +0 -96
  271. mindspore/ops/_op_impl/aicpu/sparse_cross.py +0 -42
  272. mindspore/ops/_op_impl/cpu/buffer_append.py +0 -28
  273. mindspore/ops/_op_impl/cpu/buffer_get.py +0 -28
  274. mindspore/ops/_op_impl/cpu/buffer_sample.py +0 -28
  275. mindspore/ops/_op_impl/cpu/priority_replay_buffer.py +0 -42
  276. mindspore/ops/operations/_tensor_array.py +0 -359
  277. mindspore/ops/operations/rl_ops.py +0 -288
  278. mindspore/parallel/_offload_context.py +0 -275
  279. mindspore/parallel/_recovery_context.py +0 -115
  280. mindspore/parallel/_transformer/__init__.py +0 -35
  281. mindspore/parallel/_transformer/layers.py +0 -765
  282. mindspore/parallel/_transformer/loss.py +0 -251
  283. mindspore/parallel/_transformer/moe.py +0 -693
  284. mindspore/parallel/_transformer/op_parallel_config.py +0 -222
  285. mindspore/parallel/_transformer/transformer.py +0 -3124
  286. mindspore/parallel/mpi/_mpi_config.py +0 -116
  287. mindspore/train/memory_profiling_pb2.py +0 -298
  288. {mindspore-2.7.0.dist-info → mindspore-2.7.1.dist-info}/WHEEL +0 -0
  289. {mindspore-2.7.0.dist-info → mindspore-2.7.1.dist-info}/entry_points.txt +0 -0
  290. {mindspore-2.7.0.dist-info → mindspore-2.7.1.dist-info}/top_level.txt +0 -0
@@ -55,10 +55,18 @@ class PyboostFunctionsImplGenerator(BaseGenerator):
55
55
  'auto ${output} = PyNativeAlgo::Common::ConvertStubNodeToTensor(${input}, ${need_contiguous}, '
56
56
  'op_run_info->requires_grad);\n'
57
57
  )
58
+ self.convert_to_tensor_view_template = Template(
59
+ 'auto ${output} = PyNativeAlgo::Common::ConvertStubNodeToTensor(${input}, ${need_contiguous}, '
60
+ 'requires_grad);\n'
61
+ )
58
62
  self.convert_to_tensor_list_template = Template(
59
63
  'auto ${output} = PyNativeAlgo::Common::ConvertStubNodeToValueTuple(${input}, ${need_contiguous}, '
60
64
  'op_run_info->requires_grad);\n'
61
65
  )
66
+ self.convert_to_tensor_list_view_template = Template(
67
+ 'auto ${output} = PyNativeAlgo::Common::ConvertStubNodeToValueTuple(${input}, ${need_contiguous}, '
68
+ 'requires_grad);\n'
69
+ )
62
70
  self.implicit_cast_template = Template(
63
71
  '// Do mixed precision and implicit cast\n' \
64
72
  'static const std::vector<std::vector<size_t>> same_type_table{${same_type}};\n' \
@@ -73,8 +81,10 @@ class PyboostFunctionsImplGenerator(BaseGenerator):
73
81
  self.OP_DEF_INC_HEAD_TEMPLATE = template.OP_DEF_INC_HEAD_TEMPLATE
74
82
 
75
83
  self.PYBOOST_CORE_BODY_TEMPLATE = template.PYBOOST_CORE_BODY_TEMPLATE
84
+ self.PYBOOST_CORE_BODY_VIEW_TEMPLATE = template.PYBOOST_CORE_BODY_VIEW_TEMPLATE
76
85
  self.PYBOOST_CORE_BODY_COMM_TEMPLATE = template.PYBOOST_CORE_BODY_COMM_TEMPLATE
77
86
  self.PYBOOST_CORE_BODY_SYNC_TEMPLATE = template.PYBOOST_CORE_BODY_SYNC_TEMPLATE
87
+ self.PYBOOST_CORE_BODY_VIEW_SYNC_TEMPLATE = template.PYBOOST_CORE_BODY_VIEW_SYNC_TEMPLATE
78
88
 
79
89
  def generate(self, work_path, op_protos):
80
90
  """
@@ -148,10 +158,10 @@ class PyboostFunctionsImplGenerator(BaseGenerator):
148
158
  cast_args_str = self._get_cast_to_value_str(op_proto)
149
159
  op_input_args_str = self._get_input_args_str(op_proto)
150
160
  output_num_str = len(op_proto.op_returns)
161
+ has_side_effect_str = 'true' if op_proto.op_view or op_proto.op_inplace else 'false'
151
162
  pyboost_core_body_tpl = self._get_pyboost_core_body_tpl(op_proto)
152
163
  if op_proto.op_view:
153
164
  implicit_cast_str = ''
154
- cast_args_str = call_args_str
155
165
  else:
156
166
  implicit_cast_str = self.implicit_cast_template.replace(cast_args=cast_args_str,
157
167
  type_num=type_num,
@@ -170,6 +180,7 @@ class PyboostFunctionsImplGenerator(BaseGenerator):
170
180
  call_args=call_args_str,
171
181
  cast_args=cast_args_str,
172
182
  output_num=output_num_str,
183
+ has_side_effect=has_side_effect_str,
173
184
  operator_name=op_proto.op_name)
174
185
 
175
186
  def _generate_parser_func(self, op_proto: OpProto) -> str:
@@ -232,23 +243,28 @@ class PyboostFunctionsImplGenerator(BaseGenerator):
232
243
  """
233
244
  convert_stub_str = ''
234
245
  need_contiguous = 'true'
246
+ convert_to_tensor_template = self.convert_to_tensor_template
247
+ convert_to_tensor_list_template = self.convert_to_tensor_list_template
235
248
  if op_proto.op_view:
236
249
  # View/ACLNN op does not need to convert to contiguous tensor.
237
250
  need_contiguous = 'false'
251
+ convert_to_tensor_template = self.convert_to_tensor_view_template
252
+ convert_to_tensor_list_template = self.convert_to_tensor_list_view_template
253
+
238
254
  for op_arg in op_proto.op_args:
239
255
  if pyboost_utils.is_tensor(op_arg):
240
256
  convert_stub_output_name = op_arg.arg_name + '_optional' if is_optional_param(op_arg) \
241
257
  else op_arg.arg_name + "_tensor"
242
- convert_stub_str += self.convert_to_tensor_template.replace(input=op_arg.arg_name,
243
- output=convert_stub_output_name,
244
- need_contiguous=need_contiguous)
258
+ convert_stub_str += convert_to_tensor_template.replace(input=op_arg.arg_name,
259
+ output=convert_stub_output_name,
260
+ need_contiguous=need_contiguous)
245
261
  elif pyboost_utils.is_tensor_list(op_arg):
246
262
  # To adapt the cases where TensorList is optional.
247
263
  convert_stub_output_name = op_arg.arg_name + '_optional' if is_optional_param(op_arg) \
248
264
  else op_arg.arg_name + "_tensor_list"
249
- convert_stub_str += self.convert_to_tensor_list_template.replace(input=op_arg.arg_name,
250
- output=convert_stub_output_name,
251
- need_contiguous=need_contiguous)
265
+ convert_stub_str += convert_to_tensor_list_template.replace(input=op_arg.arg_name,
266
+ output=convert_stub_output_name,
267
+ need_contiguous=need_contiguous)
252
268
  return convert_stub_str
253
269
 
254
270
  def _get_call_args_str(self, op_proto: OpProto):
@@ -311,6 +327,10 @@ class PyboostFunctionsImplGenerator(BaseGenerator):
311
327
  def _get_pyboost_core_body_tpl(self, op_proto: OpProto):
312
328
  if len(op_proto.op_returns) == 1 and is_tensor_list(op_proto.op_returns[0]):
313
329
  # op output size is unknown
314
- return self.PYBOOST_CORE_BODY_SYNC_TEMPLATE
315
- return self.PYBOOST_CORE_BODY_COMM_TEMPLATE \
316
- if op_proto.op_dispatch.is_comm_op else self.PYBOOST_CORE_BODY_TEMPLATE
330
+ return self.PYBOOST_CORE_BODY_VIEW_SYNC_TEMPLATE\
331
+ if op_proto.op_view else self.PYBOOST_CORE_BODY_SYNC_TEMPLATE
332
+ if op_proto.op_view:
333
+ return self.PYBOOST_CORE_BODY_VIEW_TEMPLATE
334
+ if op_proto.op_dispatch.is_comm_op:
335
+ return self.PYBOOST_CORE_BODY_COMM_TEMPLATE
336
+ return self.PYBOOST_CORE_BODY_TEMPLATE
@@ -49,6 +49,8 @@ class PyboostGradFunctionsGenerator(BaseGenerator):
49
49
  self.GEN_OPS_DEF_HEADER_TEMPLATE = template.GEN_OPS_DEF_HEADER_TEMPLATE
50
50
  self.contiguous_template = Template(
51
51
  "convert_$arg_name = runtime::ValueConverter::ContiguousTensorValue($device_target, convert_$arg_name);\n")
52
+ self.PYBOOST_GRAD_FUNCTION_TEMPLATE = template.PYBOOST_GRAD_FUNCTION_TEMPLATE
53
+ self.PYBOOST_VIEW_GRAD_FUNCTION_TEMPLATE = template.PYBOOST_VIEW_GRAD_FUNCTION_TEMPLATE
52
54
 
53
55
  def generate(self, work_path, op_protos):
54
56
  """
@@ -69,8 +71,7 @@ class PyboostGradFunctionsGenerator(BaseGenerator):
69
71
  pyboost_func_reg_def = ''
70
72
  pyboost_func_include_headers_str = ''
71
73
  for op_proto in op_protos:
72
- if (op_proto.op_dispatch is None) or (not op_proto.op_dispatch.enable) \
73
- or op_proto.op_dispatch.is_comm_op:
74
+ if (op_proto.op_dispatch is None) or (not op_proto.op_dispatch.enable):
74
75
  continue
75
76
  op_parser = OpTemplateParser(op_proto)
76
77
  op_pyboost_func_name = op_parser.get_pyboost_func_name()
@@ -85,7 +86,8 @@ class PyboostGradFunctionsGenerator(BaseGenerator):
85
86
  for op_arg in op_proto.op_args:
86
87
  call_arg = 'convert_' + op_arg.arg_name
87
88
  call_args_str.append(call_arg)
88
- pyboost_func_str += template.PYBOOST_GRAD_FUNCTION_TEMPLATE.replace(
89
+ pyboost_grad_function_template = self._get_pyboost_grad_function_template(op_proto)
90
+ pyboost_func_str += pyboost_grad_function_template.replace(
89
91
  func_name=op_pyboost_func_name,
90
92
  op_name=op_name_str,
91
93
  op_args=op_args_str,
@@ -108,6 +110,11 @@ class PyboostGradFunctionsGenerator(BaseGenerator):
108
110
  file_name = "pyboost_grad_functions.cc"
109
111
  save_file(save_path, file_name, pyboost_func_file)
110
112
 
113
+ def _get_pyboost_grad_function_template(self, op_proto: OpProto):
114
+ if op_proto.op_view:
115
+ return self.PYBOOST_VIEW_GRAD_FUNCTION_TEMPLATE
116
+ return self.PYBOOST_GRAD_FUNCTION_TEMPLATE
117
+
111
118
  def _convert_value_type(self, op_proto: OpProto) -> str:
112
119
  """
113
120
  Generates the code for converting the operator's input values to the required types.
@@ -51,7 +51,7 @@ class PyboostKernelInfoAdapterGenerator(BaseGenerator):
51
51
  self.kernel_info_adapter_cpp_template = template.PYBOOST_INTERNAL_KERNEL_INFO_ADAPTER_CPP_TEMPLATE
52
52
  self.kernel_info_adapter_register_template = Template(KERNEL_INFO_ADAPTER_REGISTER)
53
53
  self.merged_op_headers_template = Template(
54
- "#include \"plugin/device/ascend/kernel/internal/pyboost/${operator_name}.h\"\n")
54
+ "#include \"kernel/ascend/internal/pyboost/${operator_name}.h\"\n")
55
55
 
56
56
  def generate(self, work_path, op_protos):
57
57
  """
@@ -51,8 +51,11 @@ class PyboostGradFunctionsCppGenerator(BaseGenerator):
51
51
 
52
52
  def __init__(self):
53
53
  self.PYBOOST_NATIVE_GRAD_FUNCTION_TEMPLATE = template.PYBOOST_NATIVE_GRAD_FUNCTION_TEMPLATE
54
+ self.PYBOOST_NATIVE_VIEW_GRAD_FUNCTION_TEMPLATE = template.PYBOOST_NATIVE_VIEW_GRAD_FUNCTION_TEMPLATE
54
55
  self.PYBOOST_NATIVE_GRAD_FUNCTIONS_TEMPLATE = template.PYBOOST_NATIVE_GRAD_FUNCTIONS_TEMPLATE
55
56
  self.native_function_multi_output_template = template.MULTI_OUTPUT_TEMPLATE
57
+ self.native_view_function_output_template =\
58
+ "const auto &output_value = runtime::ValueConverter::ToValue(outputs);\n"
56
59
  self.native_function_single_output_template = "const auto &output_value = op->outputs()[0];\n"
57
60
  self.native_include_header_template = Template(
58
61
  f'#include "{K.MS_PYBOOST_BASE_PATH}/auto_generate/${{operator_name}}.h"\n')
@@ -93,15 +96,15 @@ class PyboostGradFunctionsCppGenerator(BaseGenerator):
93
96
  output_expr = self._get_output_expr(op_proto)
94
97
 
95
98
  pyboost_func_str += \
96
- template.PYBOOST_NATIVE_GRAD_FUNCTION_TEMPLATE.replace(func_name=op_proto.op_class.name,
97
- op_name=op_proto.op_class.name,
98
- op_args=op_args_str,
99
- convert_body=convert_value_type_str,
100
- call_args=call_args_str,
101
- call_args_with_type=call_args_with_type,
102
- first_var_name=first_var_name,
103
- output_expr=output_expr,
104
- operator_name=op_proto.op_name)
99
+ self._get_native_grad_function_template(op_proto).replace(func_name=op_proto.op_class.name,
100
+ op_name=op_proto.op_class.name,
101
+ op_args=op_args_str,
102
+ convert_body=convert_value_type_str,
103
+ call_args=call_args_str,
104
+ call_args_with_type=call_args_with_type,
105
+ first_var_name=first_var_name,
106
+ output_expr=output_expr,
107
+ operator_name=op_proto.op_name)
105
108
  pyboost_func_str = pyboost_func_str + template.NEW_LINE
106
109
  pyboost_func_include_headers_str += (
107
110
  self.native_include_header_template.replace(operator_name=op_proto.op_name))
@@ -114,6 +117,11 @@ class PyboostGradFunctionsCppGenerator(BaseGenerator):
114
117
  save_file(os.path.join(work_path, K.PYBOOST_NATIVE_GRAD_FUNC_GEN_PATH),
115
118
  "pyboost_native_grad_functions.cc", native_grad_func_file)
116
119
 
120
+ def _get_native_grad_function_template(self, op_proto):
121
+ if op_proto.op_view:
122
+ return self.PYBOOST_NATIVE_VIEW_GRAD_FUNCTION_TEMPLATE
123
+ return self.PYBOOST_NATIVE_GRAD_FUNCTION_TEMPLATE
124
+
117
125
  def _convert_native_value_type(self, op_proto: OpProto) -> str:
118
126
  """
119
127
  Generates native value conversion functions for operator arguments.
@@ -172,6 +180,8 @@ class PyboostGradFunctionsCppGenerator(BaseGenerator):
172
180
  Returns:
173
181
  str: The output expression used in the function implementation.
174
182
  """
183
+ if op_proto.op_view:
184
+ return self.native_view_function_output_template
175
185
  output_expr = self.native_function_single_output_template
176
186
  if pyboost_utils.is_op_multi_output(op_proto.op_returns):
177
187
  output_expr = self.native_function_multi_output_template
@@ -40,6 +40,25 @@ def check_no_basic_int_type(op_args):
40
40
  return True
41
41
 
42
42
 
43
+ def get_inplace_indices(op_proto):
44
+ """
45
+ Extracts the indices of inplace arguments from the operation prototype.
46
+
47
+ Args:
48
+ op_proto (OpProto): The operator prototype containing argument information.
49
+
50
+ Returns:
51
+ list: A list of indices for inplace arguments.
52
+ """
53
+ inplace_args = []
54
+ for arg in op_proto.op_returns:
55
+ if arg.inplace != '':
56
+ inplace_args.append(arg.inplace)
57
+ input_args = [arg.arg_name for arg in op_proto.op_args]
58
+ inplace_indices = [input_args.index(arg) for arg in inplace_args]
59
+ return inplace_indices
60
+
61
+
43
62
  class PyboostCommonOpHeaderGenerator(BaseGenerator):
44
63
  """
45
64
  Generates common C++ headers for PyBoost operations.
@@ -68,6 +87,8 @@ class PyboostCommonOpHeaderGenerator(BaseGenerator):
68
87
  None
69
88
  """
70
89
  for op_proto in op_protos:
90
+ if is_op_multi_output(op_proto.op_returns):
91
+ print(op_proto.op_name)
71
92
  if op_proto.op_dispatch is None:
72
93
  continue
73
94
  op_parser = OpTemplateParser(op_proto)
@@ -114,8 +135,11 @@ class PyboostOpHeaderGenerator(BaseGenerator):
114
135
  raise ValueError(
115
136
  f"Device must be ascend, gpu, or cpu, {device} is not supported")
116
137
  self.PYBOOST_OP_HEADER_TEMPLATE = template_dict[device]
117
- self.code_generate_path = f"{K.MS_OPS_KERNEL_PATH}/{device}/pyboost/auto_generate/"
118
- self.hccl_code_generate_path = "mindspore/ccsrc/plugin/device/ascend/kernel/hccl/pyboost/auto_generate/"
138
+ if device == "ascend":
139
+ self.code_generate_path = f"{K.MS_OPS_KERNEL_PATH}/ascend/aclnn/pyboost_impl/auto_generate/"
140
+ else:
141
+ self.code_generate_path = f"{K.MS_OPS_KERNEL_PATH}/{device}/pyboost/auto_generate/"
142
+ self.hccl_code_generate_path = "mindspore/ops/kernel/ascend/hccl/pyboost/auto_generate/"
119
143
  self.device = device
120
144
 
121
145
  def generate(self, work_path, op_protos):
@@ -174,7 +198,10 @@ class PyboostInternalOpHeaderGenerator(BaseGenerator):
174
198
  raise ValueError(
175
199
  f"Currently, only support 'ascend' for internal operations, {device} is not supported.")
176
200
  self.pyboost_internal_op_header_template = template.PYBOOST_ASCEND_INTERNAL_OP_HEADER_TEMPLATE
177
- self.code_generate_path = f"{K.MS_OPS_KERNEL_PATH}/{device}/pyboost/internal/auto_generate/"
201
+ if device == "ascend":
202
+ self.code_generate_path = f"{K.MS_OPS_KERNEL_PATH}/ascend/aclnn/pyboost_impl/internal/auto_generate/"
203
+ else:
204
+ self.code_generate_path = f"{K.MS_OPS_KERNEL_PATH}/{device}/pyboost/internal/auto_generate/"
178
205
  self.device = device
179
206
 
180
207
  def generate(self, work_path, op_protos):
@@ -234,7 +261,7 @@ class PyboostOpCppGenerator:
234
261
  PYBOOST_CUSTOMIZE_CALL_TEMPLATE = template.PYBOOST_ASCEND_CUSTOMIZE_CALL_TEMPLATE
235
262
  PYBOOST_SINGLE_OP_HEADER_TEMPLATE = template.PYBOOST_ASCEND_SINGLE_OP_HEADER_TEMPLATE
236
263
  PYBOOST_SINGLE_OP_SOURCE_TEMPLATE = template.PYBOOST_ASCEND_SINGLE_OP_SOURCE_TEMPLATE
237
- gen_path = f"{K.MS_OPS_KERNEL_PATH}/ascend/pyboost/auto_generate/"
264
+ gen_path = f"{K.MS_OPS_KERNEL_PATH}/ascend/aclnn/pyboost_impl/auto_generate/"
238
265
  self.device_reg_str = "Ascend"
239
266
  elif device == 'cpu':
240
267
  PYBOOST_CUSTOMIZE_CALL_TEMPLATE = template.PYBOOST_CPU_CUSTOMIZE_CALL_TEMPLATE
@@ -296,9 +323,12 @@ class PyboostOpCppGenerator:
296
323
  if arg.inplace != '':
297
324
  check_inplace_func = f'ThrowExpectionWhenInternalOverlap({arg.inplace}_tensor);'
298
325
  break
326
+ inplace_indices = get_inplace_indices(op_proto)
327
+ inplace_indices_str = ', '.join(str(i) for i in inplace_indices)
299
328
  call_impl = self.PYBOOST_CUSTOMIZE_CALL_TEMPLATE.replace(
300
329
  call_args=call_args,
301
330
  return_values=call_func_outputs,
331
+ inplace_indices=inplace_indices_str,
302
332
  customize_func=getattr(
303
333
  op_proto.op_dispatch, self.device) + "Customize",
304
334
  check_expression=check_inplace_func,
@@ -309,10 +339,16 @@ must be provided for comm op {operator_name}")
309
339
 
310
340
  if is_ascend_comm_op:
311
341
  customize_include = \
312
- f'#include "mindspore/ccsrc/plugin/device/ascend/kernel/hccl/pyboost/{operator_name.lower()}.h"\n'
342
+ f'#include "mindspore/ops/kernel/ascend/hccl/pyboost/{operator_name.lower()}.h"\n'
313
343
  else:
314
- customize_include = \
315
- f'#include "{K.MS_OPS_KERNEL_PATH}/{self.device}/pyboost/customize/{operator_name.lower()}.h"\n'
344
+ if self.device == 'ascend':
345
+ customize_include = (
346
+ f'#include "{K.MS_OPS_KERNEL_PATH}/ascend/aclnn/pyboost_impl/customize/'
347
+ f'{operator_name.lower()}.h"\n'
348
+ )
349
+ else:
350
+ customize_include = \
351
+ f'#include "{K.MS_OPS_KERNEL_PATH}/{self.device}/pyboost/customize/{operator_name.lower()}.h"\n'
316
352
 
317
353
  register_custom = self._get_register_custom_kernel(op_proto)
318
354
  cpp_func_return = _generate_cpp_func_return(op_proto)
@@ -386,7 +422,7 @@ class PyboostViewOpCppGenerator:
386
422
  PYBOOST_VIEW_CALL_TEMPLATE = template.PYBOOST_ASCEND_VIEW_CALL_TEMPLATE
387
423
  PYBOOST_SINGLE_OP_HEADER_TEMPLATE = template.PYBOOST_ASCEND_SINGLE_OP_HEADER_TEMPLATE
388
424
  PYBOOST_SINGLE_OP_SOURCE_TEMPLATE = template.PYBOOST_ASCEND_SINGLE_OP_SOURCE_TEMPLATE
389
- gen_path = f"{K.MS_OPS_KERNEL_PATH}/ascend/pyboost/auto_generate/"
425
+ gen_path = f"{K.MS_OPS_KERNEL_PATH}/ascend/aclnn/pyboost_impl/auto_generate/"
390
426
  self.device_reg_str = "Ascend"
391
427
  elif device == 'cpu':
392
428
  PYBOOST_VIEW_CALL_TEMPLATE = template.PYBOOST_CPU_VIEW_CALL_TEMPLATE
@@ -425,7 +461,6 @@ class PyboostViewOpCppGenerator:
425
461
  merge_op_header (list): A list to store the generated C++ header code for view operations.
426
462
  merge_op_function (list): A list to store the generated C++ source code for view operations.
427
463
  """
428
- calc_args_temp = Template("{${call_args}}")
429
464
  for op_proto in op_protos:
430
465
  if op_proto.op_dispatch is None:
431
466
  continue
@@ -433,7 +468,7 @@ class PyboostViewOpCppGenerator:
433
468
  continue
434
469
  if getattr(op_proto.op_dispatch, self.device) == 'None':
435
470
  continue
436
- if not op_proto.op_view:
471
+ if not op_proto.op_view or not op_proto.bprop_expander:
437
472
  continue
438
473
 
439
474
  op_parser = OpTemplateParser(op_proto)
@@ -441,16 +476,12 @@ class PyboostViewOpCppGenerator:
441
476
  call_args = OpTemplateParser.parse_original_call_args(op_proto.op_args)
442
477
  if op_proto.op_view and not check_no_basic_int_type(op_proto.op_args):
443
478
  call_args_with_type = op_parser.parse_call_args_with_types(True)
444
- storage_calc_str = op_proto.op_class.name + "BasicType"
445
- calc_func_args_str = call_args
446
479
  else:
447
480
  call_args_with_type = op_parser.parse_call_args_with_types()
448
- storage_calc_str = op_proto.op_class.name
449
- calc_func_args_str = calc_args_temp.replace(call_args=call_args)
481
+ storage_calc_str = op_proto.op_class.name
450
482
  _, call_func_outputs = op_parser.generate_pyboost_outputs()
451
483
  call_impl = self.PYBOOST_VIEW_CALL_TEMPLATE.replace(op_name=op_proto.op_class.name,
452
484
  storage_calc=storage_calc_str,
453
- calc_func_args=calc_func_args_str,
454
485
  call_args=call_args,
455
486
  call_tensors=call_args_tensor,
456
487
  return_values=call_func_outputs,
@@ -499,7 +530,7 @@ class AclnnOpCppCodeGenerator:
499
530
  if device == 'ascend':
500
531
  PYBOOST_CALL_TEMPLATE = template.PYBOOST_ASCEND_CALL_TEMPLATE
501
532
  PYBOOST_SINGLE_OP_SOURCE_TEMPLATE = template.PYBOOST_ASCEND_SINGLE_OP_SOURCE_TEMPLATE
502
- gen_path = f"{K.MS_OPS_KERNEL_PATH}/ascend/pyboost/auto_generate/"
533
+ gen_path = f"{K.MS_OPS_KERNEL_PATH}/ascend/aclnn/pyboost_impl/auto_generate/"
503
534
  self.device_reg_str = "Ascend"
504
535
  elif device == 'cpu':
505
536
  PYBOOST_CALL_TEMPLATE = template.PYBOOST_CPU_CALL_TEMPLATE
@@ -517,9 +548,14 @@ class AclnnOpCppCodeGenerator:
517
548
  self.PYBOOST_REG_OP_TEMPLATE = Template('MS_REG_PYBOOST_OP(${device}, ${op_name});' \
518
549
  '${register_custom_kernel}')
519
550
  self.PYBOOST_CALL_TEMPLATE = PYBOOST_CALL_TEMPLATE
520
- self.PYBOOST_SINGLE_OP_HEADER_TEMPLATE = template.Template(
521
- '#include "kernel/${device}/pyboost/auto_generate/${operator_name}.h"\n'
522
- )
551
+ if device == "ascend":
552
+ self.PYBOOST_SINGLE_OP_HEADER_TEMPLATE = template.Template(
553
+ '#include "kernel/ascend/aclnn/pyboost_impl/auto_generate/${operator_name}.h"\n'
554
+ )
555
+ else:
556
+ self.PYBOOST_SINGLE_OP_HEADER_TEMPLATE = template.Template(
557
+ '#include "kernel/${device}/pyboost/auto_generate/${operator_name}.h"\n'
558
+ )
523
559
 
524
560
  self.PYBOOST_SINGLE_OP_SOURCE_TEMPLATE = PYBOOST_SINGLE_OP_SOURCE_TEMPLATE
525
561
  self.gen_path = gen_path
@@ -581,6 +617,8 @@ class AclnnOpCppCodeGenerator:
581
617
  else:
582
618
  call_args_with_type = op_parser.parse_call_args_with_types()
583
619
  inplace_process = _generate_inplace_process_cpp_code(op_proto)
620
+ inplace_indices = get_inplace_indices(op_proto)
621
+ inplace_indices_str = ', '.join(str(i) for i in inplace_indices)
584
622
  call_impl = self.PYBOOST_CALL_TEMPLATE.replace(aclnn_name=aclnn_name,
585
623
  call_args=call_args,
586
624
  call_tensors=call_args_tensor,
@@ -597,6 +635,7 @@ class AclnnOpCppCodeGenerator:
597
635
  return_values=call_func_outputs,
598
636
  outputs=real_output,
599
637
  inplace_process=inplace_process,
638
+ inplace_indices=inplace_indices_str,
600
639
  cast_input_code=cast_input_code,
601
640
  real_call_args_tensor=real_call_args_tensor,
602
641
  class_name=op_proto.op_class.name,
@@ -636,11 +675,11 @@ class AclnnOpCppCodeGenerator:
636
675
  is_tensor = real_call_args_tensor[i] in call_tensors
637
676
  if is_tensor:
638
677
  cast_input += f'const auto &real_{tensor} = PyBoostUtils::CastTensor({tensor}, ' \
639
- f'select_kernel.input_type()[{i}].dtype, "CPU");\n'
678
+ f'select_kernel.input_type()[{i}].dtype, device::DeviceType::kCPU);\n'
640
679
  real_call_args_tensor[i] = "real_" + real_call_args_tensor[i]
641
680
  if is_tuple_tensor:
642
681
  cast_input += f'const auto &real_{tensor} = PyBoostUtils::CastTensor({tensor}, ' \
643
- f'select_kernel.input_type()[{i}].dtype, "CPU");\n'
682
+ f'select_kernel.input_type()[{i}].dtype, device::DeviceType::kCPU);\n'
644
683
  real_call_args_tensor[i] = "PyBoostUtils::ConvertTensorVectorToTuple(real_" + real_call_args_tensor[
645
684
  i] + ")"
646
685
  if cast_input != "":
@@ -710,9 +749,9 @@ class InternalOpCppCodeGenerator:
710
749
  self.internal_single_op_source_template = template.PYBOOST_INTERNAL_SINGLE_OP_SOURCE_TEMPLATE
711
750
  self.internal_single_op_customize_source_template = template.PYBOOST_INTERNAL_SINGLE_OP_CUSTOMIZE_TEMPLATE
712
751
  self.customize_inc_template = Template(
713
- '#include "{ms_ops_kernel_path}/ascend/pyboost/internal/customize/${operator_name}.h"\n'
752
+ '#include "${ms_ops_kernel_path}/ascend/aclnn/pyboost_impl/internal/customize/${operator_name}.h"\n'
714
753
  )
715
- self.gen_path = f"{K.MS_OPS_KERNEL_PATH}/ascend/pyboost/internal/auto_generate/"
754
+ self.gen_path = f"{K.MS_OPS_KERNEL_PATH}/ascend/aclnn/pyboost_impl/internal/auto_generate/"
716
755
 
717
756
  def generate_internal_op_cpp_code(self, work_path, op_protos):
718
757
  """
@@ -819,13 +858,13 @@ class InternalOpCppCodeGenerator:
819
858
  return_type=cpp_func_return)
820
859
  save_path = os.path.join(work_path, self.gen_path)
821
860
  save_file(save_path, f"{op_proto.op_name}.h", internal_op_header_str)
822
- self.customize_inc_template.replace(
861
+ customize_inc_str = self.customize_inc_template.replace(
823
862
  ms_ops_kernel_path=K.MS_OPS_KERNEL_PATH,
824
863
  operator_name=op_proto.op_name)
825
864
  merge_op_header.append(
826
865
  self.internal_single_op_header_template.replace(
827
866
  operator_name=op_proto.op_name,
828
- customize_inc=self.customize_inc_template))
867
+ customize_inc=customize_inc_str))
829
868
 
830
869
  # generate op function
831
870
  _, call_func_outputs = op_parser.generate_pyboost_outputs()
@@ -890,10 +929,10 @@ class PyboostOpFunctionGenerator(BaseGenerator):
890
929
  self.PYBOOST_ASCEND_OP_SOURCE_TEMPLATE = template.PYBOOST_ASCEND_OP_SOURCE_TEMPLATE
891
930
  self.PYBOOST_CPU_OP_SOURCE_TEMPLATE = template.PYBOOST_CPU_OP_SOURCE_TEMPLATE
892
931
  self.PYBOOST_GPU_OP_SOURCE_TEMPLATE = template.PYBOOST_GPU_OP_SOURCE_TEMPLATE
893
- self.ascend_gen_path = f"{K.MS_OPS_KERNEL_PATH}/ascend/pyboost/auto_generate/"
932
+ self.ascend_gen_path = f"{K.MS_OPS_KERNEL_PATH}/ascend/aclnn/pyboost_impl/auto_generate/"
894
933
  self.cpu_gen_path = f"{K.MS_OPS_KERNEL_PATH}/cpu/pyboost/auto_generate/"
895
934
  self.gpu_gen_path = f"{K.MS_OPS_KERNEL_PATH}/gpu/pyboost/auto_generate/"
896
- self.hccl_gen_path = "mindspore/ccsrc/plugin/device/ascend/kernel/hccl/pyboost/auto_generate/"
935
+ self.hccl_gen_path = "mindspore/ops/kernel/ascend/hccl/pyboost/auto_generate/"
897
936
 
898
937
  def generate(self, work_path, op_protos):
899
938
  """
@@ -1009,6 +1048,7 @@ class PyboostOpFunctionGenerator(BaseGenerator):
1009
1048
  ops_inc_head_set = set()
1010
1049
  for op_name_inc in op_inc_list[i]:
1011
1050
  ops_inc_head_set.add(template.OP_DEF_INC_HEAD_TEMPLATE.replace(prefix_char=op_name_inc[0].lower()))
1051
+ op_header += '#include "kernel/cpu/pyboost/pyboost_op_plugin_utils.h"\n'
1012
1052
  cpu_pyboost_op_source = self.PYBOOST_CPU_OP_SOURCE_TEMPLATE.replace(
1013
1053
  merge_op_header=op_header, merge_op_function=op_function, ops_inc=list(sorted(ops_inc_head_set)))
1014
1054
  save_file(os.path.join(work_path, self.cpu_gen_path), f"pyboost_cpu_ops_{i}.cc",
@@ -1150,7 +1190,10 @@ def delete_residual_files(work_path, op_protos):
1150
1190
  for op_proto in op_protos:
1151
1191
  all_operator_name.append(op_proto.op_name)
1152
1192
  devices = ["ascend", "gpu", "cpu"]
1153
- code_generate_path_list = [f"{K.MS_OPS_KERNEL_PATH}/{device}/pyboost/auto_generate/" for device in devices]
1193
+ code_generate_path_list = [f"{K.MS_OPS_KERNEL_PATH}/{device}/pyboost/auto_generate/"
1194
+ if device != "ascend" else
1195
+ f"{K.MS_OPS_KERNEL_PATH}/ascend/aclnn/pyboost_impl/auto_generate/"
1196
+ for device in devices]
1154
1197
  code_generate_path_list.append(
1155
1198
  f"{K.MS_COMMON_PYBOOST_KERNEL_PATH}/auto_generate/")
1156
1199
  for code_generate_path in code_generate_path_list:
@@ -48,7 +48,7 @@ class PyboostOverloadFunctionsGenerator(BaseGenerator):
48
48
  self.PYBOOST_MINT_CLASS_DEF = template.PYBOOST_MINT_CLASS_DEF
49
49
  self.PYBOOST_OVERLOAD_MINT_CLASS_DEF = template.PYBOOST_OVERLOAD_MINT_CLASS_DEF
50
50
  self.TENSOR_FUNC_UT_BODY = template.TENSOR_FUNC_UT_BODY
51
- self.TENSOR_FUNC_UT_OVERLOAD_BODY = template.TENSOR_FUNC_UT_OVERLOAD_BODY
51
+ self.PYBOOST_OVERLOAD_UT_BODY = template.PYBOOST_OVERLOAD_UT_BODY
52
52
 
53
53
  self.single_case_template = Template(
54
54
  'case ${case_id}:\n'
@@ -56,11 +56,11 @@ class PyboostOverloadFunctionsGenerator(BaseGenerator):
56
56
  ' break;\n'
57
57
  )
58
58
  self.device_dispatcher_template = Template(
59
- 'if (backend == kAscendDevice || backend == kDavinciDevice) {\n'
59
+ 'if (backend == device::DeviceType::kAscend) {\n'
60
60
  ' ${ascend_dispatcher}\n'
61
- '} else if (backend == kCPUDevice) {\n'
61
+ '} else if (backend == device::DeviceType::kCPU) {\n'
62
62
  ' ${cpu_dispatcher}\n'
63
- '} else if (backend == kGPUDevice) {\n'
63
+ '} else if (backend == device::DeviceType::kGPU) {\n'
64
64
  ' ${gpu_dispatcher}\n'
65
65
  '} else {\n'
66
66
  ' MS_LOG(ERROR) << "Device target is not supported!";\n'
@@ -71,8 +71,8 @@ class PyboostOverloadFunctionsGenerator(BaseGenerator):
71
71
  '${arg_handler_processor}\n'
72
72
  'MS_LOG(INFO) << "Call Tensor${class_name}";\n'
73
73
  'auto res = ${pyboost_base_func_name}_OP(${prim_name}, parse_args.src_types_, ${convert_args});\n'
74
- 'trace::Capture(parse_args.arg_list_, mindspore::prim::kPrim${class_name}, &res);\n'
75
- 'return res;\n'
74
+ 'trace::CapturePy(parse_args.arg_list_, mindspore::prim::kPrim${class_name}, &res);\n'
75
+ 'return py::reinterpret_steal<py::object>(res);\n'
76
76
  )
77
77
  self.callback_python_template = Template(
78
78
  'MS_LOG(INFO) << "Callback python method: ${py_method}";\n'
@@ -161,13 +161,14 @@ class PyboostOverloadFunctionsGenerator(BaseGenerator):
161
161
  op_args = func_proto.op_proto.op_args
162
162
  max_size = len(op_args)
163
163
  ut_body = self.TENSOR_FUNC_UT_BODY.replace(py_method=func_proto.py_method)
164
- func_call_body_list.append(self.PYBOOST_MINT_CLASS_DEF.replace(
164
+ func_call_body = self.PYBOOST_MINT_CLASS_DEF.replace(
165
165
  class_name=class_name,
166
166
  func_name=func_name,
167
167
  device_dispatcher=device_dispatcher_str,
168
168
  signatures=signature_str,
169
169
  max_args=max_size,
170
- ut_body=ut_body))
170
+ ut_body=ut_body)
171
+ func_call_body_list.append(func_call_body)
171
172
  cpp_class_name_list.append(class_name)
172
173
  return func_call_body_list, cpp_class_name_list
173
174
 
@@ -202,7 +203,7 @@ class PyboostOverloadFunctionsGenerator(BaseGenerator):
202
203
  signatures_str = self._generate_func_signatures_str(func_protos)
203
204
  dispatch_cases = self._get_dispatch_cases(func_protos)
204
205
  ut_dispatch_cases = self._get_ut_dispatch_cases(func_protos)
205
- ut_overload_body = self.TENSOR_FUNC_UT_OVERLOAD_BODY.replace(ut_dispatch_cases=ut_dispatch_cases)
206
+ ut_overload_body = self.PYBOOST_OVERLOAD_UT_BODY.replace(ut_dispatch_cases=ut_dispatch_cases)
206
207
 
207
208
  max_size = 0
208
209
  for tensor_proto in func_protos:
@@ -78,14 +78,14 @@ def get_convert_type_str(dtype: str, optional, use_basic_type=False):
78
78
  'float': 'ToFloat',
79
79
  'bool': 'ToBool',
80
80
  'number': 'ToScalar',
81
- 'tuple[int]': 'ToIntList<py::tuple>',
82
- 'tuple[float]': 'ToFloatList<py::tuple>',
83
- 'tuple[bool]': 'ToBoolList<py::tuple>',
84
- 'tuple[tensor]': 'ToTensorList<py::tuple>',
85
- 'list[int]': 'ToIntList<py::list>',
86
- 'list[float]': 'ToFloatList<py::list>',
87
- 'list[bool]': 'ToBoolList<py::list>',
88
- 'list[tensor]': 'ToTensorList<py::list>',
81
+ 'tuple[int]': 'ToIntList<CPythonTuple>',
82
+ 'tuple[float]': 'ToFloatList<CPythonTuple>',
83
+ 'tuple[bool]': 'ToBoolList<CPythonTuple>',
84
+ 'tuple[tensor]': 'ToTensorList<CPythonTuple>',
85
+ 'list[int]': 'ToIntList<CPythonList>',
86
+ 'list[float]': 'ToFloatList<CPythonList>',
87
+ 'list[bool]': 'ToBoolList<CPythonList>',
88
+ 'list[tensor]': 'ToTensorList<CPythonList>',
89
89
  'tensor': 'ToTensor',
90
90
  'str': 'ToString',
91
91
  'type': 'ToDtype',
@@ -97,14 +97,14 @@ def get_convert_type_str(dtype: str, optional, use_basic_type=False):
97
97
  'tensor': 'ToTensorOptional',
98
98
  'type': 'ToDtypeOptional',
99
99
  'str': 'ToStringOptional',
100
- 'tuple[int]': 'ToIntListOptional<py::tuple>',
101
- 'tuple[float]': 'ToFloatListOptional<py::tuple>',
102
- 'tuple[bool]': 'ToBoolListOptional<py::tuple>',
103
- 'tuple[tensor]': 'ToTensorListOptional<py::tuple>',
104
- 'list[int]': 'ToIntListOptional<py::list>',
105
- 'list[float]': 'ToFloatListOptional<py::list>',
106
- 'list[bool]': 'ToBoolListOptional<py::list>',
107
- 'list[tensor]': 'ToTensorListOptional<py::list>',
100
+ 'tuple[int]': 'ToIntListOptional<CPythonTuple>',
101
+ 'tuple[float]': 'ToFloatListOptional<CPythonTuple>',
102
+ 'tuple[bool]': 'ToBoolListOptional<CPythonTuple>',
103
+ 'tuple[tensor]': 'ToTensorListOptional<CPythonTuple>',
104
+ 'list[int]': 'ToIntListOptional<CPythonList>',
105
+ 'list[float]': 'ToFloatListOptional<CPythonList>',
106
+ 'list[bool]': 'ToBoolListOptional<CPythonList>',
107
+ 'list[tensor]': 'ToTensorListOptional<CPythonList>',
108
108
  }
109
109
  basic_optional_type_convert = {
110
110
  'tuple[int]': "ToBasicIntVectorOptional",
@@ -385,6 +385,17 @@ def get_input_dtype(dtype: str, optional, use_basic_type=False):
385
385
  raise TypeError(f"""Unsupported convert type {dtype} for args.""")
386
386
 
387
387
 
388
+ def get_output_dtype(dtype: str):
389
+ type_convert = {
390
+ 'tensor': "mindspore::tensor::TensorPtr",
391
+ 'tuple[tensor]': "std::vector<mindspore::tensor::TensorPtr>",
392
+ 'list[tensor]': "std::vector<mindspore::tensor::TensorPtr>",
393
+ }
394
+ if dtype in type_convert:
395
+ return type_convert[dtype]
396
+ raise TypeError(f"""Unsupported convert type {dtype} for args.""")
397
+
398
+
388
399
  def is_cube(class_name):
389
400
  cube_set = {'Bmm', 'Baddbmm', 'MatMulExt', 'Mv'}
390
401
  if class_name in cube_set:
@@ -29,6 +29,7 @@ class YamlLoader(ResourceLoader):
29
29
  """
30
30
  YamlLoader is a utility class for loading yaml files.
31
31
  """
32
+
32
33
  def __init__(self, resouce_type: ResourceType, yaml_path: Union[Sequence[str], str]):
33
34
  """
34
35
  Initialize YamlLoader.
@@ -65,15 +66,26 @@ class OpDocYamlLoader(YamlLoader):
65
66
  """
66
67
  OpDocYamlLoader is a class for loading op primitive doc yaml files.
67
68
  """
69
+
68
70
  def __init__(self):
69
71
  op_doc_yaml_path = os.path.join(K.WORK_DIR, K.MS_OP_DEF_YAML_PATH, "doc")
70
72
  super().__init__(ResourceType.OP_DOC_YAML, op_doc_yaml_path)
71
73
 
72
74
 
75
+ class CustomOpDocYamlLoader(YamlLoader):
76
+ """
77
+ CustomOpDocYamlLoader is a class for loading op primitive doc yaml files.
78
+ """
79
+
80
+ def __init__(self, doc_yaml_path):
81
+ super().__init__(ResourceType.OP_DOC_YAML, doc_yaml_path)
82
+
83
+
73
84
  class TensorMethodDocYamlLoader(YamlLoader):
74
85
  """
75
86
  TensorMethodDocYamlLoader is a class for loading tensor method doc yaml files.
76
87
  """
88
+
77
89
  def __init__(self):
78
90
  tensor_method_doc_yaml_path = os.path.join(K.WORK_DIR, K.MS_TENSOR_METHOD_DOC_YAML_PATH)
79
91
  super().__init__(ResourceType.TENSOR_METHOD_DOC_YAML, tensor_method_doc_yaml_path)
@@ -83,6 +95,7 @@ class MintFuncDocYamlLoader(YamlLoader):
83
95
  """
84
96
  MintFuncDocYamlLoader is a class for loading mint func doc yaml files.
85
97
  """
98
+
86
99
  def __init__(self):
87
100
  mint_func_doc_yaml_path = os.path.join(K.WORK_DIR, K.MS_MINT_FUNC_DOC_YAML_PATH)
88
101
  super().__init__(ResourceType.MINT_FUNC_DOC_YAML, mint_func_doc_yaml_path)