From b94b3ac04f1d4edec8e62f18fd2f47005c062a83 Mon Sep 17 00:00:00 2001 From: wz1qqx <55830058+wz1qqx@users.noreply.github.com> Date: Wed, 28 Jun 2023 22:46:06 -0700 Subject: [PATCH] [XPU]add layer_norm fuse pass (#54930) --- paddle/fluid/framework/ir/layer_norm_fuse_pass.cc | 6 +----- .../ir/xpu/reshape2_matmul_xpu_fuse_pass.cc | 15 ++------------- paddle/fluid/inference/api/paddle_pass_builder.cc | 1 + 3 files changed, 4 insertions(+), 18 deletions(-) diff --git a/paddle/fluid/framework/ir/layer_norm_fuse_pass.cc b/paddle/fluid/framework/ir/layer_norm_fuse_pass.cc index 5a65ba86b6b..47a3e9b69fb 100644 --- a/paddle/fluid/framework/ir/layer_norm_fuse_pass.cc +++ b/paddle/fluid/framework/ir/layer_norm_fuse_pass.cc @@ -403,12 +403,10 @@ void LayerNormFusePass::ApplyImpl(Graph* graph) const { x_mean_out, x_sub_mean, x_sub_mean_out, - sqr_pow, x_sub_mean_sqr, x_sub_mean_sqr_out, std_dev, std_dev_out, - eps, std_dev_eps, std_dev_eps_out, std_dev_eps_sqrt, @@ -417,9 +415,7 @@ void LayerNormFusePass::ApplyImpl(Graph* graph) const { division_out, scale, scale_out, - shift, - gamma, - beta}); + shift}); found_layer_norm_count++; }; diff --git a/paddle/fluid/framework/ir/xpu/reshape2_matmul_xpu_fuse_pass.cc b/paddle/fluid/framework/ir/xpu/reshape2_matmul_xpu_fuse_pass.cc index ac07447f0d3..8383501c30b 100644 --- a/paddle/fluid/framework/ir/xpu/reshape2_matmul_xpu_fuse_pass.cc +++ b/paddle/fluid/framework/ir/xpu/reshape2_matmul_xpu_fuse_pass.cc @@ -24,16 +24,6 @@ #include "paddle/fluid/framework/op_version_registry.h" #include "paddle/fluid/platform/enforce.h" -namespace phi { -class DenseTensor; -} // namespace phi - -namespace paddle { -namespace framework { -class Scope; -} // namespace framework -} // namespace paddle - namespace paddle { namespace framework { namespace ir { @@ -163,9 +153,8 @@ Squeeze2MatmulPattern::Squeeze2MatmulPattern(PDPattern* pattern, ->assert_more([](Node* node) { auto squeeze2_in_x_shape = node->Var()->GetShape(); size_t squeeze2_in_rank = squeeze2_in_x_shape.size(); - bool nice_shape = - squeeze2_in_x_shape[2] == 1 && squeeze2_in_x_shape[3] == 1; - return squeeze2_in_rank == 4 && nice_shape; + return squeeze2_in_rank == 4 && + (squeeze2_in_x_shape[2] == 1 && squeeze2_in_x_shape[3] == 1); }); auto* squeeze2 = pattern->NewNode(squeeze2_repr()) ->assert_is_op("squeeze2") diff --git a/paddle/fluid/inference/api/paddle_pass_builder.cc b/paddle/fluid/inference/api/paddle_pass_builder.cc index 41b90c63b1e..ea852d1467f 100644 --- a/paddle/fluid/inference/api/paddle_pass_builder.cc +++ b/paddle/fluid/inference/api/paddle_pass_builder.cc @@ -532,6 +532,7 @@ XpuPassStrategy::XpuPassStrategy() : PassStrategy({}) { "fused_multi_transformer_xpu_pass", "relu6_fuse_pass", "sigmoid_elementmul_fuse_pass", + "layer_norm_fuse_pass", "matmul_weight_trans_pass", "map_matmulv2_to_matmul_xpu_pass", "reshape2_matmul_xpu_fuse_pass", -- GitLab