Skip to content
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

Implement Fused BN + Add + Relu with cudnnFusedOps API. #35955

Merged
merged 8 commits into from
Oct 9, 2021

Conversation

ZzSean
Copy link
Contributor

@ZzSean ZzSean commented Sep 23, 2021

PR types

New features

PR changes

OPs

Describe

Add bn_add_relu test

  x mean invstd eq_scale eq_bias y y_hf
base 0.600098 0.574712 3.685992 3.685992 -2.118384 0.093573 0.093567
fuse 0.600098 0.574712 3.685993 3.685547 -2.119141 0.092547 0.092529

对于原始的batchnorm来说,中间所有结果的计算都是 float类型,只是在最后输出时做了一次fp32->fp16的cast;
而在融合计算中,虽然mean和std等结果都与原始相同,但是bn_finalize会输出一个fp16类型的eq_scale和eq_bias,用来进行最后的乘加,因此最终的结果会出现误差,提高单测阈值至2e-3

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

paddle/fluid/operators/fused/cudnn_bn_add_relu_test.cc Outdated Show resolved Hide resolved
paddle/fluid/operators/fused/cudnn_bn_add_relu_test.cc Outdated Show resolved Hide resolved
paddle/fluid/operators/fused/cudnn_bn_add_relu_test.cc Outdated Show resolved Hide resolved
paddle/fluid/operators/fused/cudnn_bn_add_relu_test.cc Outdated Show resolved Hide resolved
paddle/fluid/operators/fused/cudnn_bn_stats_finalize.cu.h Outdated Show resolved Hide resolved
Copy link
Contributor

@Xreki Xreki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM,代码后续PR继续完善。

fwd_workspace_byte_);
}

void Backward(const platform::CUDADeviceContext &ctx, T *dy_ptr, T *x_ptr,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉Forward、Backward实现在不同的类里面比较好,因为这两个Forward、Backward并不是完全对应的。

@@ -0,0 +1,292 @@
/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cudnn_bn_stats_finalize.cu.h和cudnn_scale_bias_add_relu.cu.h两个文件可以考虑合并成一个。

@Xreki Xreki changed the title Add bn_add_relu test Implement Fused BN + Add + Relu with cudnnFusedOps API. Oct 9, 2021
@Xreki Xreki merged commit 7e6c0ce into PaddlePaddle:develop Oct 9, 2021
@ZzSean ZzSean deleted the cudnn_bn_add_relu_test branch October 15, 2021 06:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants