-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[XPU] Add fast_layernorm + leaky_relu fusion #57113
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
9181ab8
to
33d3a16
Compare
@@ -291,6 +291,7 @@ if(WITH_XPU) | |||
${XPU_PASS_DEPS}) | |||
pass_library(gather_squeeze_pass inference DIR xpu DEPS ${XPU_PASS_DEPS}) | |||
pass_library(fast_where_xpu_fuse_pass inference DIR xpu DEPS ${XPU_PASS_DEPS}) | |||
pass_library(fln_act_xpu_fuse_pass inference DIR xpu DEPS ${XPU_PASS_DEPS}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
layer_norm_act_xpu_fuse_pass
@@ -0,0 +1,212 @@ | |||
// Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved. | |||
// | |||
// Licensed under the Apache License, Version 2.0 (the "License"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
layer_norm_act_fuse_pass.cc
After the pass is applied: | ||
x | ||
| | ||
fln_act_xpu |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fln 用 layer_norm 替换
graph: | ||
x | ||
| | ||
layernorm_xpu |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
layer_norm
const std::string& name_scope, | ||
const std::string& act_type); | ||
// declare operator node's name | ||
PATTERN_DECL_NODE(ln); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ln 改成 layer_norm,下同
output | ||
*/ | ||
|
||
struct FLNActXPUPattern : public PatternBase { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FLN改成 LayerNorm
paddle/phi/api/yaml/fused_ops.yaml
Outdated
@@ -101,6 +101,15 @@ | |||
data_type : x | |||
optional : bias, x_max | |||
|
|||
- op : fln_act_xpu |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
layer_norm_act_xpu
->assert_is_op_input("layer_norm", "Scale"); | ||
auto ln_out = pattern->NewNode(ln_out_repr()) | ||
->AsOutput() | ||
->assert_is_op_output("layer_norm", "Y"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
->assert_is_op_input(act_type_, "X"); 加到这里来
另外,需要判断 ln_out 只有一个 output
33d3a16
to
a73a054
Compare
paddle/phi/infermeta/fusion.cc
Outdated
@@ -1014,6 +1014,20 @@ void AddCMulXPUInferMeta(const MetaTensor& x, | |||
out->set_layout(x.layout()); | |||
} | |||
|
|||
void FLNActXPUInferMeta(const MetaTensor& x, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LayerNormActInferMeta
paddle/phi/infermeta/fusion.h
Outdated
@@ -226,6 +226,15 @@ void AddCMulXPUInferMeta(const MetaTensor& x, | |||
const MetaTensor& w, | |||
MetaTensor* out); | |||
|
|||
void FLNActXPUInferMeta(const MetaTensor& x, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
namespace fusion { | ||
|
||
template <typename T, typename Context> | ||
void FLNActXPUKernel(const Context& ctx, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
act.hard_sigmoid_slope = act_param; | ||
} | ||
#ifdef PADDLE_WITH_XPU_PLUGIN | ||
int r = xpu::plugin::fln_act_fusion(ctx.x_context(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fln 是否能统一调整为 layer_norm_act_fusion
a73a054
to
f9582fd
Compare
paddle/phi/api/yaml/fused_ops.yaml
Outdated
args : (Tensor x, Tensor scale, Tensor bias, int begin_norm_axis, float epsilon, int act_type, float act_param) | ||
output : Tensor(out) | ||
infer_meta : | ||
func : LayerNormActInferMeta |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LayerNormActInferMeta 改成 LayerNormActXPUInferMeta
函数名称和算子名称保持一致,下同
namespace patterns { | ||
|
||
/* | ||
change layernorm op to fast_layernorm op |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
描述改一下,第一个字母大写
@@ -70,6 +70,8 @@ XPUOpMap& get_kl2_ops() { | |||
XPUKernelSet({phi::DataType::FLOAT32, phi::DataType::FLOAT16})}, | |||
{"batch_norm", | |||
XPUKernelSet({phi::DataType::FLOAT32, phi::DataType::FLOAT16})}, | |||
{"layer_norm_act_xpu", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
按照字母顺序?或者 fuse 类的算子放一起?
2305a00
to
cd13575
Compare
cd13575
to
d611343
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PR types
Performance optimization
PR changes
OPs
Description
add fast_layternorm and act(leaky_relu) fusion