From e92b1770917c5eb58a3fb72f931b7a90bfd4155c Mon Sep 17 00:00:00 2001 From: zhoutianzi666 <17801055074@163.com> Date: Mon, 19 Sep 2022 01:53:10 +0000 Subject: [PATCH] commit --- .../framework/ir/preln_residual_bias_fuse_pass.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/paddle/fluid/framework/ir/preln_residual_bias_fuse_pass.cc b/paddle/fluid/framework/ir/preln_residual_bias_fuse_pass.cc index 43f48f87c09a5..195c05170e476 100644 --- a/paddle/fluid/framework/ir/preln_residual_bias_fuse_pass.cc +++ b/paddle/fluid/framework/ir/preln_residual_bias_fuse_pass.cc @@ -164,6 +164,17 @@ void PrelnResidualBiasFusePass::ApplyImpl(ir::Graph *graph) const { GET_IR_NODE_FROM_SUBGRAPH(layer_norm_mean, layer_norm_mean, fused_pattern); GET_IR_NODE_FROM_SUBGRAPH( layer_norm_variance, layer_norm_variance, fused_pattern); + + // We can not accept that two or more layer_norm is connected to + // elementwise1_out. This will lead to two or more PrelnResidualBias + // patterns is found near elementwise1_out, and these patterns will interact + // on each other. + int num_layer_norm = 0; + for (auto op : elementwise1_out->outputs) { + if (op->Name() == "layer_norm") num_layer_norm++; + if (num_layer_norm >= 2) return; + } + std::unordered_set del_node_set; // Create an PrelnResidualBias op node OpDesc new_desc;