已合并
refactor: 移除 dynamic_rnn/dynamic_rnnv2 系列 TF 插件并修复 einsum TF 插件注册 #9925
refactor: 移除 dynamic_rnn/dynamic_rnnv2 系列 TF 插件并修复 einsum TF 插件注册 #9925
已合并
Nice try创建于 9月7日
共 4 个文件变更+5-247
@@ -15,15 +15,17 @@
15#include "register/register.h"15#include "register/register.h"
16 16 
17namespace domi {17namespace domi {
18-static Status AutoMappingFnEinSum(const ge::Operator& op_src, ge::Operator& op)18+static Status AutoMappingFnEinSum(const google::protobuf::Message* op_src, ge::Operator& op)
19{19{
20- AutoMappingByOpFn(op_src, op);20+ map<string, pair<string, string>> value;
21+ value["in"] = pair<string, string>("x", "N");
22+ (void)AutoMappingFnDynamic(op_src, op, value);
21 return SUCCESS;23 return SUCCESS;
22}24}
23 25 
24REGISTER_CUSTOM_OP("Einsum")26REGISTER_CUSTOM_OP("Einsum")
25 .FrameworkType(TENSORFLOW)27 .FrameworkType(TENSORFLOW)
26 .OriginOpType("Einsum")28 .OriginOpType("Einsum")
27- .ParseParamsByOperatorFn(AutoMappingFnEinSum)29+ .ParseParamsFn(AutoMappingFnEinSum)
28 .ImplyType(ImplyType::TVM);30 .ImplyType(ImplyType::TVM);
29} // namespace domi31} // namespace domi
@@ -1,106 +0,0 @@
1-/**
2- * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3- * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4- * CANN Open Software License Agreement Version 2.0 (the "License").
5- * Please refer to the License for details. You may not use this file except in compliance with the License.
6- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7- * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8- * See LICENSE in the root of the software repository for the full text of the License.
9- */
10- 
11-/*!
12- * \file block_lstm_tf_plugin.cpp
13- * \brief
14- */
15-#include <string>
16-#include <vector>
17-#include <map>
18-#include "register/register.h"
19-#include "framework/plugin_util.h"
20-#include "graph/operator.h"
21-#include "stub_ops.h"
22-#include "rnn/dynamic_rnn/op_graph/dynamic_rnn_proto.h"
23- 
24-#include "log/log.h"
25-#include "graph/types.h"
26- 
27-namespace domi {
28-using namespace ge;
29- 
30-static Status ParseParamsRNN(const ge::Operator& op_src, ge::Operator& op)
31-{
32- // Set original_type
33- op.SetAttr("original_type", "BlockLSTM");
34- 
35- // 未调用 AutoMappingByOpFn,TF 源节点属性不会自动映射到目标算子;
36- // 因此从 op_src(携带 TF 源节点属性)显式解析后写入目标算子,缺失时保持默认值。
37- float forget_bias = 0.0f;
38- (void)op_src.GetAttr("forget_bias", forget_bias);
39- (void)op.SetAttr("forget_bias", forget_bias);
40- 
41- float cell_clip = 3.0f;
42- (void)op_src.GetAttr("cell_clip", cell_clip);
43- (void)op.SetAttr("cell_clip", cell_clip);
44- 
45- bool use_peephole = false;
46- (void)op_src.GetAttr("use_peephole", use_peephole);
47- (void)op.SetAttr("use_peephole", use_peephole);
48- 
49- return SUCCESS;
50-}
51- 
52-static Status ParseOpToGraphRNN(const ge::Operator& op, ge::Graph& graph)
53-{
54- ge::Operator data_0 = op::Data("seq_len_max").set_attr_index(0);
55- ge::Operator data_1 = op::Data("x").set_attr_index(1);
56- ge::Operator data_2 = op::Data("cs_prev").set_attr_index(2);
57- ge::Operator data_3 = op::Data("h_prev").set_attr_index(3);
58- ge::Operator data_4 = op::Data("w").set_attr_index(4);
59- ge::Operator data_8 = op::Data("b").set_attr_index(8);
60- 
61- float forget_bias = 0.0;
62- if (op.GetAttr("forget_bias", forget_bias) != ge::GRAPH_SUCCESS) {
63- OP_LOGE(GetOpName(op).c_str(), "get attr forget_bias failed.");
64- return FAILED;
65- }
66- 
67- float cell_clip = 3.0;
68- if (op.GetAttr("cell_clip", cell_clip) != ge::GRAPH_SUCCESS) {
69- OP_LOGE(GetOpName(op).c_str(), "get attr cell_clip failed.");
70- return FAILED;
71- }
72- 
73- bool use_peephole = false;
74- if (op.GetAttr("use_peephole", use_peephole) != ge::GRAPH_SUCCESS) {
75- OP_LOGE(GetOpName(op).c_str(), "get attr use_peephole failed.");
76- return FAILED;
77- }
78- 
79- auto cast = op::Cast().set_input_x(data_0).set_attr_dst_type(3);
80- auto rnn = op::DynamicRNN()
81- .set_input_x(data_1)
82- .set_input_w(data_4)
83- .set_input_b(data_8)
84- .set_input_seq_length(cast)
85- .set_input_init_h(data_3)
86- .set_input_init_c(data_2)
87- .set_attr_forget_bias(forget_bias)
88- .set_attr_cell_clip(cell_clip)
89- .set_attr_use_peephole(use_peephole)
90- .set_attr_cell_type("BLOCKLSTM");
91- 
92- std::vector<ge::Operator> inputs{data_1, data_4, data_8, data_0, data_3, data_2};
93- std::vector<std::pair<ge::Operator, std::vector<size_t>>> output_indexs;
94- output_indexs.emplace_back(rnn, vector<std::size_t>{3, 2, 5, 6, 4, 7, 1});
95- graph.SetInputs(inputs).SetOutputs(output_indexs);
96- return SUCCESS;
97-}
98- 
99-// register BlockLSTM op info to GE
100-REGISTER_CUSTOM_OP("DynamicRNN")
101- .FrameworkType(TENSORFLOW)
102- .OriginOpType("BlockLSTM")
103- .ParseParamsByOperatorFn(ParseParamsRNN)
104- .ParseOpToGraphFn(ParseOpToGraphRNN)
105- .ImplyType(ImplyType::TVM);
106-} // namespace domi
@@ -1,96 +0,0 @@
1-/**
2- * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3- * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4- * CANN Open Software License Agreement Version 2.0 (the "License").
5- * Please refer to the License for details. You may not use this file except in compliance with the License.
6- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7- * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8- * See LICENSE in the root of the software repository for the full text of the License.
9- */
10- 
11-/*!
12- * \file dynamic_rnn_tf_plugin.cpp
13- * \brief
14- */
15- 
16-#include <cstring>
17-#include <string>
18-#include <vector>
19- 
20-#include "register/register.h"
21-#include "framework/plugin_util.h"
22-#include "graph/operator.h"
23-#include "log/log.h"
24- 
25-namespace domi {
26-uint32_t wRnnInputPosition = 1;
27-static const char* const kForgetBias = "lstm_cell/add/y";
28-static const char* const kTransposeNode = "Transpose";
29- 
30-static Status DynamicRNNParserParams(const std::vector<ge::Operator>& inside_nodes, ge::Operator& op)
31-{
32- OP_LOGI(GetOpName(op).c_str(), "Enter DynamicRNN fusion parser.");
33- 
34- // 基于融合子图算子恢复旧 NodeDef 解析语义(node_def.pb.h 在新工具链已不存在,改用算子版融合解析):
35- // - 子图含 Transpose 节点 → time_major=false
36- // - 名为 lstm_cell/add/y 的 Const 节点 → 从 value 张量解析 forget_bias
37- bool time_major = true;
38- float forget_bias = 0.0f;
39- for (const auto& node : inside_nodes) {
40- ge::AscendString node_type;
41- if (node.GetOpType(node_type) == ge::GRAPH_SUCCESS && std::string(node_type.GetString()) == kTransposeNode) {
42- time_major = false;
43- }
44- 
45- ge::AscendString node_name;
46- if (node.GetName(node_name) != ge::GRAPH_SUCCESS) {
47- continue;
48- }
49- if (std::string(node_name.GetString()).find(kForgetBias) == std::string::npos) {
50- continue;
51- }
52- ge::Tensor const_value;
53- if (node.GetAttr("value", const_value) != ge::GRAPH_SUCCESS) {
54- OP_LOGE(GetOpName(op).c_str(), "parse forget_bias from const node %s failed", node_name.GetString());
55- return PARAM_INVALID;
56- }
57- const uint8_t* value_data = const_value.GetData();
58- const size_t value_size = const_value.GetSize();
59- if (value_data == nullptr || value_size < sizeof(float)) {
60- OP_LOGE(GetOpName(op).c_str(), "parse forget_bias from const node %s failed", node_name.GetString());
61- return PARAM_INVALID;
62- }
63- (void)memcpy(&forget_bias, value_data, sizeof(float));
64- }
65- op.SetAttr("time_major", time_major);
66- op.SetAttr("forget_bias", forget_bias);
67- OP_LOGD(GetOpName(op).c_str(), "parser stage set DynamicRNN's attr time_major is %s forget_bias is %.1f",
68- time_major ? "true" : "false", forget_bias);
69- 
70- ge::TensorDesc input_desc = op.GetInputDesc(wRnnInputPosition);
71- input_desc.SetOriginFormat(ge::FORMAT_HWCN);
72- input_desc.SetFormat(ge::FORMAT_HWCN);
73- 
74- if (op.UpdateInputDesc(wRnnInputPosition, input_desc) != ge::GRAPH_SUCCESS) {
75- OP_LOGE(GetOpName(op).c_str(), "Update input desc fail, index:%u.", wRnnInputPosition);
76- return FAILED;
77- }
78- 
79- return SUCCESS;
80-}
81- 
82-// 来自 dynamic_rnn_plugin.cc:TF 原生 DynamicRNN
83-REGISTER_CUSTOM_OP("DynamicRNN")
84- .FrameworkType(TENSORFLOW)
85- .OriginOpType("DynamicRNN")
86- .ParseParamsByOperatorFn(AutoMappingByOpFn)
87- .FusionParseParamsFn(DynamicRNNParserParams)
88- .ImplyType(ImplyType::TVM);
89- 
90-// 来自 dynamic_rnn_tf_plugin.cc:DynamicRnn(保持原独立注册语义,不附加融合解析)
91-REGISTER_CUSTOM_OP("DynamicRNN")
92- .FrameworkType(TENSORFLOW)
93- .OriginOpType("DynamicRnn")
94- .ParseParamsByOperatorFn(AutoMappingByOpFn)
95- .ImplyType(ImplyType::TVM);
96-} // namespace domi
@@ -1,42 +0,0 @@
1-/**
2- * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3- * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4- * CANN Open Software License Agreement Version 2.0 (the "License").
5- * Please refer to the License for details. You may not use this file except in compliance with the License.
6- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7- * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8- * See LICENSE in the root of the software repository for the full text of the License.
9- */
10- 
11-/*!
12- * \file dynamic_rnnv2_tf_plugin.cpp
13- * \brief DynamicRnnV2 / DynamicRNNV2 TensorFlow plugin mapping.
14- */
15-#include "register/register.h"
16- 
17-namespace domi {
18-static Status ParseParamsDynamicRNN(const ge::Operator& op_src, ge::Operator& op_dest)
19-{
20- AutoMappingByOpFn(op_src, op_dest);
21- op_dest.SetAttr("is_misplaced", true);
22- return SUCCESS;
23-}
24- 
25-REGISTER_CUSTOM_OP("DynamicRNN")
26- .FrameworkType(TENSORFLOW)
27- .OriginOpType("DynamicRnnV2")
28- .ParseParamsByOperatorFn(ParseParamsDynamicRNN)
29- .ImplyType(ImplyType::TVM);
30- 
31-REGISTER_CUSTOM_OP("DynamicRNNV2")
32- .FrameworkType(TENSORFLOW)
33- .OriginOpType("DynamicRnnv2WithoutSeqlength")
34- .ParseParamsByOperatorFn(ParseParamsDynamicRNN)
35- .ImplyType(ImplyType::TVM);
36- 
37-REGISTER_CUSTOM_OP("DynamicRNNV2")
38- .FrameworkType(TENSORFLOW)
39- .OriginOpType("DynamicRnnv2WithSeqlength")
40- .ParseParamsByOperatorFn(AutoMappingByOpFn)
41- .ImplyType(ImplyType::TVM);
42-} // namespace domi