diff --git a/mindspore-lite/python/api/converter.py b/mindspore-lite/python/api/converter.py index c932b0b06cfc263b593e419ebd7067f909ab061f..340387f9ef6bc51aee49224e1ea51d58692be8a6 100644 --- a/mindspore-lite/python/api/converter.py +++ b/mindspore-lite/python/api/converter.py @@ -353,8 +353,8 @@ class Converter: """ check_isinstance("input_data_type", input_data_type, DataType) if input_data_type not in [DataType.FLOAT32, DataType.INT8, DataType.UINT8, DataType.UNKNOWN]: - raise ValueError(f"input_data_type must be in [DataType.FLOAT32, DataType.INT8, DataType.UINT8, " - f"DataType.UNKNOWN].") + raise ValueError("input_data_type must be in [DataType.FLOAT32, DataType.INT8, DataType.UINT8, " + "DataType.UNKNOWN].") self._converter.set_input_data_type(data_type_py_cxx_map.get(input_data_type)) @property @@ -392,7 +392,7 @@ class Converter: """ check_isinstance("input_format", input_format, Format) if input_format not in [Format.NCHW, Format.NHWC]: - raise ValueError(f"input_format must be in [Format.NCHW, Format.NHWC].") + raise ValueError("input_format must be in [Format.NCHW, Format.NHWC].") self._converter.set_input_format(format_py_cxx_map.get(input_format)) @property @@ -522,7 +522,7 @@ class Converter: elif len(split_str) == 2: chip_name = split_str[1] else: - raise ValueError(f"chip_name must be single") + raise ValueError("chip_name must be single") check_isinstance("chip_name", chip_name, str) if chip_name not in ["default", "910b"]: raise ValueError(f"chip_name must be in [default, 910b], but got {chip_name}.") @@ -530,7 +530,7 @@ class Converter: self.optimize_user_defined = "ascend_oriented" else: raise ValueError( - f"optimize must be 'none', 'general', 'gpu_oriented', 'ascend_oriented' or 'ascend_oriented:910b'.") + "optimize must be 'none', 'general', 'ascend_oriented'.") @property def output_data_type(self): @@ -577,8 +577,8 @@ class Converter: """ check_isinstance("output_data_type", output_data_type, DataType) if output_data_type not in [DataType.FLOAT32, DataType.INT8, DataType.UINT8, DataType.UNKNOWN]: - raise ValueError(f"output_data_type must be in [DataType.FLOAT32, DataType.INT8, DataType.UINT8, " - f"DataType.UNKNOWN].") + raise ValueError("output_data_type must be in [DataType.FLOAT32, DataType.INT8, DataType.UINT8, " + "DataType.UNKNOWN].") self._converter.set_output_data_type(data_type_py_cxx_map.get(output_data_type)) @property @@ -753,13 +753,13 @@ class Converter: check_isinstance("weight_file", weight_file, str) check_isinstance("config_file", config_file, str) if not os.path.exists(model_file): - raise RuntimeError(f"Perform convert method failed, model_file does not exist!") + raise RuntimeError("Perform convert method failed, model_file does not exist!") if weight_file != "": if not os.path.exists(weight_file): - raise RuntimeError(f"Perform convert method failed, weight_file does not exist!") + raise RuntimeError("Perform convert method failed, weight_file does not exist!") if config_file != "": if not os.path.exists(config_file): - raise RuntimeError(f"Perform convert method failed, config_file does not exist!") + raise RuntimeError("Perform convert method failed, config_file does not exist!") self._converter.set_config_file(config_file) fmk_type_py_cxx_map = { diff --git a/mindspore-lite/tools/converter/adapter/acl/mapper/reduce_mean_mapper.cc b/mindspore-lite/tools/converter/adapter/acl/mapper/reduce_mean_mapper.cc new file mode 100644 index 0000000000000000000000000000000000000000..dcaf644b526efe6629997e4f5e96518be5315922 --- /dev/null +++ b/mindspore-lite/tools/converter/adapter/acl/mapper/reduce_mean_mapper.cc @@ -0,0 +1,42 @@ +/** + * Copyright 2025 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "tools/converter/adapter/acl/mapper/reduce_mean_mapper.h" +#include +#include "tools/converter/adapter/acl/mapper/primitive_mapper_register.h" +#include "tools/converter/adapter/acl/mapper/tbe_op_def.h" + +namespace mindspore { +namespace lite { +STATUS ReduceMeanMapper::Mapper(const CNodePtr &cnode) { + CHECK_NULL_RETURN(cnode); + ValueNodePtr value_node = nullptr; + PrimitivePtr src_prim = nullptr; + if (GetValueNodeAndPrimFromCnode(cnode, &value_node, &src_prim) != lite::RET_OK) { + MS_LOG(ERROR) << "GetValueNodeAndPrimFromCnode failed!"; + return RET_ERROR; + } + if (value_node == nullptr || src_prim == nullptr) { + MS_LOG(ERROR) << "value_node or src_prim is nullptr!"; + return RET_ERROR; + } + src_prim->AddAttr("noop_with_empty_axes", MakeValue(false)); + return lite::RET_OK; +} + +REGISTER_PRIMITIVE_MAPPER(kNameReduceMean, ReduceMeanMapper) +} // namespace lite +} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/acl/mapper/reduce_mean_mapper.h b/mindspore-lite/tools/converter/adapter/acl/mapper/reduce_mean_mapper.h new file mode 100644 index 0000000000000000000000000000000000000000..69842dfc1c851a63f910f8572a06e94fb2f4237e --- /dev/null +++ b/mindspore-lite/tools/converter/adapter/acl/mapper/reduce_mean_mapper.h @@ -0,0 +1,35 @@ +/** + * Copyright 2025 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_ACL_MAPPER_REDUCE_MEAN_MAPPER_H_ +#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_ACL_MAPPER_REDUCE_MEAN_MAPPER_H_ + +#include "tools/converter/adapter/acl/mapper/primitive_mapper.h" +#include "infer/ops_func_impl/reduce_mean.h" +namespace mindspore { +namespace lite { +using mindspore::ops::kNameReduceMean; +class ReduceMeanMapper : public PrimitiveMapper { + public: + ReduceMeanMapper() : PrimitiveMapper(kNameReduceMean) {} + + ~ReduceMeanMapper() override = default; + + STATUS Mapper(const CNodePtr &cnode) override; +}; +} // namespace lite +} // namespace mindspore +#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_ACL_MAPPER_REDUCE_MEAN_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/acl/src/acl_pass_impl.cc b/mindspore-lite/tools/converter/adapter/acl/src/acl_pass_impl.cc index e5fc5c9dbd76f02cd4c5f40e09292c19f8d7778b..c70bca37dc67e251c91963b84f519d3bb9b0f681 100644 --- a/mindspore-lite/tools/converter/adapter/acl/src/acl_pass_impl.cc +++ b/mindspore-lite/tools/converter/adapter/acl/src/acl_pass_impl.cc @@ -20,6 +20,10 @@ #include #include #include +#include +#include +#include +#include #include #include #include "mindspore/ops/op_def/sequence_ops.h" @@ -157,7 +161,6 @@ constexpr auto kNameScatterNdMax = "ScatterNdMax"; const std::set kSocVersionForAscendCFA = { "Ascend910B1", "Ascend910B2", "Ascend910B2C", "Ascend910B3", "Ascend910B4", "Ascend310P3", "Ascend910_9391", "Ascend910_9381", "Ascend910_9392", "Ascend910_9382", "Ascend910_9372", "Ascend910_9361"}; - STATUS ModifyCNodeFormat(const FuncGraphPtr &func_graph, Format format) { CHECK_NULL_RETURN(func_graph); auto node_list = TopoSort(func_graph->get_return()); @@ -852,7 +855,7 @@ STATUS AclPassImpl::MapperForOrgMindIR(const FuncGraphPtr &func_graph) { std::set mindir_mapper = {ops::kNameTranspose, ops::kNameStandardNormal, ops::kNameBatchMatMul, ops::kNameMatMul, ops::kNameAvgPool, ops::kNameBatchNorm, - kNameResizeBilinear, kNameScatterNdMax}; + kNameResizeBilinear, kNameScatterNdMax, ops::kNameReduceMean}; const std::set support_ptq_mindir_types = {prim::kPrimQuantDTypeCast, prim::kPrimAddFusion, prim::kPrimMulFusion}; for (auto graph : all_func_graphs) {