-
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
【Hackathon 5th No.103】move skip_layernorm/fused_bias_dropout_residual_layer_norm to phi #58396
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
AddOutput("BiasDropoutResidualOut", "Output of bias + dropout + residual.") | ||
.AsIntermediate(); | ||
AddOutput("DropoutMaskOut", "The random sampled dropout mask.") | ||
.AsIntermediate(); | ||
AddOutput("LnMean", "Mean of the current mini batch.").AsIntermediate(); | ||
AddOutput("LnVariance", "Variance of the current mini batch.") | ||
.AsIntermediate(); | ||
AddOutput("Y", "Result."); |
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.
在forward中确实设置了5个output,但在backword设置了6个output呀_(:з」∠)_
if (this->HasInput("Bias")) { | ||
op->SetInput("Bias", this->Input("Bias")); | ||
op->SetOutput(framework::GradVarName("Bias"), this->InputGrad("Bias")); | ||
} | ||
if (this->HasInput("LnScale")) { | ||
op->SetInput("LnScale", this->Input("LnScale")); | ||
op->SetOutput(framework::GradVarName("LnScale"), | ||
this->InputGrad("LnScale")); | ||
} | ||
if (this->HasInput("LnBias")) { | ||
op->SetInput("LnBias", this->Input("LnBias")); | ||
op->SetOutput(framework::GradVarName("LnBias"), | ||
this->InputGrad("LnBias")); | ||
} | ||
if (this->HasOutput("LnMean")) { | ||
op->SetInput("LnMean", this->Output("LnMean")); | ||
} | ||
if (this->HasOutput("LnVariance")) { | ||
op->SetInput("LnVariance", this->Output("LnVariance")); | ||
} | ||
if (this->HasOutput("BiasDropoutResidualOut")) { | ||
op->SetInput("BiasDropoutResidualOut", | ||
this->Output("BiasDropoutResidualOut")); | ||
} | ||
op->SetInput("DropoutMaskOut", this->Output("DropoutMaskOut")); | ||
op->SetOutput(framework::GradVarName("X"), this->InputGrad("X")); | ||
op->SetOutput(framework::GradVarName("Residual"), | ||
this->InputGrad("Residual")); | ||
op->SetOutput(framework::GradVarName("BiasDropoutResidualOut"), | ||
this->OutputGrad("BiasDropoutResidualOut")); |
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.
这个backward确实SetOutput
6次,因为前3个Output是受可选参数控制的我还把他们加在了optional里,但是仍然报错,(:з」∠)
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.
现在主要问题还是这个地方
Sorry to inform you that 8092f50's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually. |
这个pr可以尽快推进下哈~ 有工作依赖fc的迁移 |
卡在前向和反向的输出数量上了。。实在看不出来哪里有问题_(:з)∠)_ |
先把skip_layernorm和fused_bias_dropout_residual_layer_norm两个交了? |
分开,可以先把fc搞了 |
fc需要确保开启那个flag也能跑通哈 |
好的,晚上我看看 |
fc的pr在#58777 这里,但是有点小问题,写在fc的pr里了 |
@zeroRains 可以更新下这个PR了 |
Sorry to inform you that b3ea0d5's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually. |
|
将算子加入到 |
两个算子的单测,均已通过~ |
infer_meta : | ||
func : SkipLayerNormInferMeta | ||
kernel : | ||
func : skip_layer |
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.
data_type : 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.
done
👍,开启那个flags也是可以通过的吗? |
是的~ |
- backward_op : fused_bias_dropout_residual_layer_norm_grad | ||
forward: fused_bias_dropout_residual_layer_norm (Tensor x, Tensor residual, Tensor bias, Tensor ln_scale, Tensor ln_bias, float dropout_rate, bool is_test, bool dropout_fix_seed, int dropout_seed, str dropout_implementation, float ln_epsilon) -> Tensor(bias_dropout_residual_out), Tensor(dropout_mask_out), Tensor(ln_mean), Tensor(ln_variance), Tensor(y) | ||
args : (Tensor y_grad, Tensor x, Tensor residual, Tensor bias, Tensor ln_scale, Tensor ln_bias, Tensor ln_mean, Tensor ln_variance, Tensor bias_dropout_residual_out, Tensor dropout_mask_out, float dropout_rate = 0.5f, bool is_test = false, bool dropout_fix_seed = true, int dropout_seed = true, str dropout_implementation = "downgrade_in_infer", float ln_epsilon = 1e-5) | ||
output : Tensor(bias_grad), Tensor(ln_scale_grad), Tensor(ln_bias_grad), Tensor(x_grad), Tensor(residual_grad) |
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.
grad的顺序需要按照forward里的tensor顺序排
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.
done
paddle/phi/api/yaml/fused_ops.yaml
Outdated
- op : fused_bias_dropout_residual_layer_norm | ||
args : (Tensor x, Tensor residual, Tensor bias, Tensor ln_scale, Tensor ln_bias, float dropout_rate = 0.5f, bool is_test = false, bool dropout_fix_seed = true, int dropout_seed = true, str dropout_implementation = "downgrade_in_infer", float ln_epsilon = 1e-5) | ||
optional : bias, ln_scale, ln_bias | ||
output : Tensor(bias_dropout_residual_out), Tensor(dropout_mask_out), Tensor(ln_mean), Tensor(ln_variance), Tensor(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.
标记为intermediate的tensor放在后面,没有标记intermediate的在前面
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.
done
paddle/phi/infermeta/fusion.h
Outdated
void SkipLayerNormInferMeta(const MetaTensor& x, | ||
const MetaTensor& y, | ||
const MetaTensor& scale, | ||
const MetaTensor& bias, | ||
const float epsilon, | ||
const int begin_norm_axis, | ||
MetaTensor* out); | ||
|
||
void FusedBiasDropoutResidualLnInferMeta( |
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.
InferMeta函数按照字母序放置
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.
done
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.
这个SkipLayerNormFunctor
看着只有skip_layernorm
的kernel在用,直接放到skip_layernorm_kernel.cu
中吧
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.
直接复制到skip_layernorm_kernel中会有一些奇怪的匹配问题,得再看看
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.
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.
不改也行
kernel->OutputAt(1).SetDataType(phi::DataType::UINT8); | ||
kernel->OutputAt(2).SetDataType(kernel_key.dtype()); | ||
kernel->OutputAt(3).SetDataType(kernel_key.dtype()); | ||
kernel->OutputAt(3).SetDataType(kernel_key.dtype()); |
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.
和kernel_key
dtype相同的就不需要设置了,可以去掉
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.
done
#include "paddle/phi/core/errors.h" | ||
#include "paddle/phi/core/kernel_registry.h" | ||
#include "paddle/phi/core/tensor_utils.h" | ||
#include "paddle/phi/kernels/funcs/blas/blas.h" |
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.
blas.h有使用到吗?
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.
确实没有,已删除
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
…_layer_norm to phi (PaddlePaddle#58396) * temp commit * move skip_layernorm to phi, but have abug in include skip_layernorm_functor.h * temp save * move skip_layernorm to phi * move fused_bias_dropout_layer_norm to phi * roback move fc to file but have a bug in onednn roback * change the register name * fix the forward input len smaller than backward output len * roback * add in vjp_interface_black_list * fix parse * fix the bug * Update fused_ops.yaml * update
@zeroRains 提个PR修复一下吧 |
已提交,#59461 ,sorry |
PR types
Others
PR changes
Others
Description
move skip_layernorm/fused_bias_dropout_residual_layer_norm to phi
#57262