已合并
feat: ReportFuse 补写 _datadump_original_op_names 和 _original_op_attrs_map 维测属性 #4344
why you创建于 19 天前
feat: ReportFuse 补写 _datadump_original_op_names 和 _original_op_attrs_map 维测属性 #4344
已合并
共 2 个文件变更+61-0
| @@ -15,6 +15,7 @@ | |||
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | + | ||
| 18 | 19 | ||
| 19 | 20 | ||
| 20 | namespace ge { | 21 | namespace ge { |
| @@ -65,6 +66,15 @@ bool MarkPassNameOnReplacementNodes(const std::vector<NodePtr> &before_nodes, co | |||
| 65 | } | 66 | } |
| 66 | return true; | 67 | return true; |
| 67 | } | 68 | } |
| 69 | + | ||
| 70 | +void RecordDatadumpAttrsIdempotently(const std::vector<NodePtr> &before_nodes, const std::vector<NodePtr> &after_nodes, | ||
| 71 | + const std::string &pass_name) { | ||
| 72 | + for (const auto &node : after_nodes) { | ||
| 73 | + const auto op_desc = node->GetOpDesc(); | ||
| 74 | + fe::GraphPassUtil::RecordOriginalNames(before_nodes, node); | ||
| 75 | + fe::GraphPassUtil::RecordOriginalOpAttrs(before_nodes, op_desc, pass_name); | ||
| 76 | + } | ||
| 77 | +} | ||
| 68 | } // namespace | 78 | } // namespace |
| 69 | 79 | ||
| 70 | bool GraphFuseInspectorUtils::CanFuse(const std::vector<GNode> &nodes_before_fuse, AscendString &failed_reason) { | 80 | bool GraphFuseInspectorUtils::CanFuse(const std::vector<GNode> &nodes_before_fuse, AscendString &failed_reason) { |
| @@ -132,6 +142,7 @@ Status GraphFuseInspectorUtils::ReportFuse(const std::vector<GNode> &nodes_befor | |||
| 132 | if (!MarkPassNameOnReplacementNodes(before_nodes, after_nodes, pass_name_str)) { | 142 | if (!MarkPassNameOnReplacementNodes(before_nodes, after_nodes, pass_name_str)) { |
| 133 | return FAILED; | 143 | return FAILED; |
| 134 | } | 144 | } |
| 145 | + RecordDatadumpAttrsIdempotently(before_nodes, after_nodes, pass_name_str); | ||
| 135 | FusionUtils::RecordFusionStatistic(owner_graph->GetSessionID(), std::to_string(owner_graph->GetGraphID()), | 146 | FusionUtils::RecordFusionStatistic(owner_graph->GetSessionID(), std::to_string(owner_graph->GetGraphID()), |
| 136 | pass_name_str, 1, 1); | 147 | pass_name_str, 1, 1); |
| 137 | return SUCCESS; | 148 | return SUCCESS; |
| @@ -15,6 +15,7 @@ | |||
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | + | ||
| 18 | 19 | ||
| 19 | 20 | ||
| 20 | 21 | ||
| @@ -226,5 +227,54 @@ TEST_F(UtestGraphFuseInspectorUtils, ReportFuseWithAfterFuseFailedOnNodesBelongT | |||
| 226 | ctx.SetPassName("ut_pass"); | 227 | ctx.SetPassName("ut_pass"); |
| 227 | EXPECT_EQ(GraphFuseInspectorUtils::ReportFuse(ToGNodes({graph1_nodes[0]}), ToGNodes({graph2_nodes[0]}), ctx), FAILED); | 228 | EXPECT_EQ(GraphFuseInspectorUtils::ReportFuse(ToGNodes({graph1_nodes[0]}), ToGNodes({graph2_nodes[0]}), ctx), FAILED); |
| 228 | } | 229 | } |
| 230 | + | ||
| 231 | +TEST_F(UtestGraphFuseInspectorUtils, ReportFuseWritesDatadumpAttrs) { | ||
| 232 | + ut::GraphBuilder builder("rewrite_graph"); | ||
| 233 | + const auto data = builder.AddNode("data", "Data", 0, 1); | ||
| 234 | + const auto matmul = builder.AddNode("matmul", "MatMul", 1, 1); | ||
| 235 | + const auto add = builder.AddNode("add", "Add", 1, 1); | ||
| 236 | + const auto netoutput = builder.AddNode("netoutput", "NetOutput", 1, 0); | ||
| 237 | + builder.AddDataEdge(data, 0, matmul, 0); | ||
| 238 | + builder.AddDataEdge(matmul, 0, add, 0); | ||
| 239 | + builder.AddDataEdge(add, 0, netoutput, 0); | ||
| 240 | + const auto graph = builder.GetGraph(); | ||
| 241 | + ASSERT_NE(graph, nullptr); | ||
| 242 | + | ||
| 243 | + // 模拟 GraphBasedPass 手动改图:新建 GEMM 替换 MatMul+Add | ||
| 244 | + const auto gemm = graph->AddNode(std::make_shared<OpDesc>("gemm", "GEMM")); | ||
| 245 | + ASSERT_NE(gemm, nullptr); | ||
| 246 | + GraphUtils::RemoveEdge(data->GetOutDataAnchor(0), matmul->GetInDataAnchor(0)); | ||
| 247 | + GraphUtils::RemoveEdge(matmul->GetOutDataAnchor(0), add->GetInDataAnchor(0)); | ||
| 248 | + GraphUtils::RemoveEdge(add->GetOutDataAnchor(0), netoutput->GetInDataAnchor(0)); | ||
| 249 | + GraphUtils::AddEdge(data->GetOutDataAnchor(0), gemm->GetInDataAnchor(0)); | ||
| 250 | + GraphUtils::AddEdge(gemm->GetOutDataAnchor(0), netoutput->GetInDataAnchor(0)); | ||
| 251 | + | ||
| 252 | + const std::vector<NodePtr> before_nodes = {matmul, add}; | ||
| 253 | + const std::vector<NodePtr> after_nodes = {gemm}; | ||
| 254 | + | ||
| 255 | + CustomPassContext ctx; | ||
| 256 | + ctx.SetPassName("ut_rewrite_pass"); | ||
| 257 | + EXPECT_EQ(GraphFuseInspectorUtils::ReportFuse(ToGNodes(before_nodes), ToGNodes(after_nodes), ctx), SUCCESS); | ||
| 258 | + | ||
| 259 | + // 验证 _datadump_original_op_names | ||
| 260 | + std::vector<std::string> original_names; | ||
| 261 | + EXPECT_TRUE(AttrUtils::GetListStr(gemm->GetOpDesc(), ATTR_NAME_DATA_DUMP_ORIGIN_OP_NAMES, original_names)); | ||
| 262 | + EXPECT_EQ(original_names.size(), 2U); | ||
| 263 | + EXPECT_EQ(original_names[0], "matmul"); | ||
| 264 | + EXPECT_EQ(original_names[1], "add"); | ||
| 265 | + | ||
| 266 | + // 验证 _datadump_original_op_types | ||
| 267 | + std::vector<std::string> original_types; | ||
| 268 | + EXPECT_TRUE(AttrUtils::GetListStr(gemm->GetOpDesc(), ATTR_NAME_DATA_DUMP_ORIGIN_OP_TYPES, original_types)); | ||
| 269 | + EXPECT_EQ(original_types.size(), 2U); | ||
| 270 | + EXPECT_EQ(original_types[0], "MatMul"); | ||
| 271 | + EXPECT_EQ(original_types[1], "Add"); | ||
| 272 | + | ||
| 273 | + // 验证 pass_name | ||
| 274 | + std::vector<std::string> pass_names; | ||
| 275 | + EXPECT_TRUE(AttrUtils::GetListStr(gemm->GetOpDesc(), "pass_name", pass_names)); | ||
| 276 | + ASSERT_FALSE(pass_names.empty()); | ||
| 277 | + EXPECT_EQ(pass_names.back(), "ut_rewrite_pass"); | ||
| 278 | +} | ||
| 229 | } // namespace fusion | 279 | } // namespace fusion |
| 230 | } // namespace ge | 280 | } // namespace ge |