From 65dab4a900b44e081f37ee7ee55e45d97449133b Mon Sep 17 00:00:00 2001 From: qiuleilei Date: Thu, 25 Sep 2025 20:16:16 +0800 Subject: [PATCH] [lite][bugfix]support onnx parser MultiScaleDeformableAttn ops --- ...nx_multi_scale_deformable_attn_function.cc | 43 +++++++++++++++++++ ...nnx_multi_scale_deformable_attn_function.h | 34 +++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 mindspore-lite/tools/converter/parser/onnx/onnx_multi_scale_deformable_attn_function.cc create mode 100644 mindspore-lite/tools/converter/parser/onnx/onnx_multi_scale_deformable_attn_function.h diff --git a/mindspore-lite/tools/converter/parser/onnx/onnx_multi_scale_deformable_attn_function.cc b/mindspore-lite/tools/converter/parser/onnx/onnx_multi_scale_deformable_attn_function.cc new file mode 100644 index 00000000..c80abbbb --- /dev/null +++ b/mindspore-lite/tools/converter/parser/onnx/onnx_multi_scale_deformable_attn_function.cc @@ -0,0 +1,43 @@ +/** + * 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/parser/onnx/onnx_multi_scale_deformable_attn_function.h" +#include +#include +#include +#include "infer/custom.h" +#include "nnacl_c/op_base.h" + +namespace mindspore { +namespace lite { +PrimitiveCPtr OnnxMultiScaleDeformableAttnFunctionParser::Parse(const onnx::GraphProto &onnx_graph, + const onnx::NodeProto &onnx_node) { + auto prim = std::make_unique(); + MS_CHECK_TRUE_RET(prim != nullptr, nullptr); + std::vector input_name = {"value", "value_spatial_shapes", "value_level_start_index", + "sampling_locations", "attention_weights"}; + std::vector output_name = {"output"}; + prim->AddAttr("input_names", api::MakeValue(input_name)); + prim->AddAttr("output_names", api::MakeValue(output_name)); + prim->set_type("MultiScaleDeformableAttnFunction"); + prim->AddAttr("reg_op_name", api::MakeValue("MultiScaleDeformableAttnFunction")); + return prim->GetPrim(); +} + +OnnxNodeRegistrar g_onnxMultiScaleDeformableAttnFunctionParser("MultiScaleDeformableAttnFunction", + new OnnxMultiScaleDeformableAttnFunctionParser()); +} // namespace lite +} // namespace mindspore diff --git a/mindspore-lite/tools/converter/parser/onnx/onnx_multi_scale_deformable_attn_function.h b/mindspore-lite/tools/converter/parser/onnx/onnx_multi_scale_deformable_attn_function.h new file mode 100644 index 00000000..daaae85a --- /dev/null +++ b/mindspore-lite/tools/converter/parser/onnx/onnx_multi_scale_deformable_attn_function.h @@ -0,0 +1,34 @@ +/** + * 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_PARSER_ONNX_ONNX_MULTI_SCALE_DEFORMABLE_ATTN_FUNCTION_PARSER_H_ +#define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_ONNX_ONNX_MULTI_SCALE_DEFORMABLE_ATTN_FUNCTION_PARSER_H_ + +#include "tools/converter/parser/onnx/onnx_node_parser.h" +#include "tools/converter/parser/onnx/onnx_node_parser_registry.h" + +namespace mindspore { +namespace lite { +class OnnxMultiScaleDeformableAttnFunctionParser : public OnnxNodeParser { + public: + OnnxMultiScaleDeformableAttnFunctionParser() : OnnxNodeParser("MultiScaleDeformableAttnFunction") {} + ~OnnxMultiScaleDeformableAttnFunctionParser() override = default; + + PrimitiveCPtr Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node) override; +}; +} // namespace lite +} // namespace mindspore +#endif // MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_ONNX_ONNX_MULTI_SCALE_DEFORMABLE_ATTN_FUNCTION_PARSER_H_ -- Gitee