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

optimize group_norm op forward #39596

Merged
merged 8 commits into from
Mar 1, 2022
Merged

Conversation

Zjq9409
Copy link
Contributor

@Zjq9409 Zjq9409 commented Feb 16, 2022

PR types

Performance optimization

PR changes

OPs

Describe

优化group_norm前向计算,性能数据如下:

op 配置 竞品耗时 优化前 优化前相比竞品 优化后 优化后相比竞品 加速比
shape:[2,256,38,26] format:NCHW num_groups:32 0.02117 0.04225 差于 (99.57%) 0.01795 优于 (17.43%) 2.35
shape:[2,256,152,104] format:NCHW num_groups:32 0.23219 0.16161 优于 (30.40%) 0.15235 优于 (34.88%) 1.06
shape:[2,256,76,52] format:NCHW num_groups:32 0.07497 0.06083 优于 (18.86%) 0.04633 优于 (39.20%) 1.31
shape:[2,256,25,33] format:NCHW num_groups:32 0.01947 0.03758 差于 (93.01%) 0.01700 优于 (14.87%) 2.21
shape:[2,256,100,132] format:NCHW num_groups:32 0.19650 0.13734 优于 (30.11%) 0.12765 优于 (35.29%) 1.08
shape:[2,256,50,66] format:NCHW num_groups:32 0.06498 0.05723 优于 (11.93%) 0.04360 优于 (34.01%) 1.31
shape:[2,256,10,11] format:NCHW num_groups:32 0.01237 0.01240 打平 (0.24%) 0.01210 优于 (5.76%) 1.02
shape:[2,256,13,13] format:NCHW num_groups:32 0.01302 0.01431 差于 (9.91%) 0.01216 优于 (10.72%) 1.18
shape:[2,256,144,128] format:NCHW num_groups:32 0.26362 0.18560 优于 (29.60%) 0.17858 优于 (32.90%) 1.04
shape:[2,256,74,68] format:NCHW num_groups:32 0.09320 0.06974 优于 (25.17%) 0.05837 优于 (38.22%) 1.19
shape:[2,128,25,42] format:NCHW num_groups:32 0.01671 0.02433 差于 (45.60%) 0.01533 优于 (11.49%) 1.59
shape:[2,128,70,76] format:NCHW num_groups:32 0.05383 0.04167 优于 (22.59%) 0.03378 优于 (37.98%) 1.23
shape:[2,256,280,304] format:NCHW num_groups:32 1.15604 0.78128 优于 (32.42%) 0.74375 优于 (34.79%) 1.05
shape:[2,256,304,232] format:NCHW num_groups:32 0.96063 0.64988 优于 (32.35%) 0.61566 优于 (38.55%) 1.06
shape:[2,128,35,38] format:NCHW num_groups:32 0.01805 0.02479 差于 (37.34%) 0.01577 优于 (15.53%) 1.57
shape:[2,256,272,312] format:NCHW num_groups:32 1.14480 0.79385 优于 (30.66%) 0.75510 优于 (34.66%) 1.05
shape:[2,256,320,312] format:NCHW num_groups:32 1.34865 0.94088 优于 (30.24%) 0.90426 优于 (33.77%) 1.04
shape:[2,256,280,200] format:NCHW num_groups:32 0.76366 0.53387 优于 (30.09%) 0.51111 优于 (34.21%) 1.04
shape:[2,128,140,152] format:NCHW num_groups:32 0.16234 0.11581 优于 (28.66%) 0.11129 优于 (31.72%) 1.04
shape:[2,128,136,156] format:NCHW num_groups:32 0.16323 0.11468 优于 (29.74%) 0.10998 优于 (32.62%) 1.04

@paddle-bot-old
Copy link

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

@@ -96,16 +173,18 @@ __global__ void GroupNormForward(const T* x, const T* mean, const T* var,
int H = imsize / W;
int ccid = gid * group_size + cid;
if (ccid >= C) return;
T x_mean = mean[bid * groups + gid];
T x_var = var[bid * groups + gid];
auto ng = bid * groups + gid;
Copy link
Contributor

Choose a reason for hiding this comment

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

这个变量有必要吗

Copy link
Contributor Author

Choose a reason for hiding this comment

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

bid * groups + gid;后续使用了三次,所以定义了一个变量保存,减少后续索引计算量

paddle/fluid/operators/group_norm_op.cu Outdated Show resolved Hide resolved
@Zjq9409 Zjq9409 changed the title optimize group norm forward optimize group_norm op forward Feb 28, 2022
Copy link
Contributor

@ZzSean ZzSean left a comment

Choose a reason for hiding this comment

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

LGTM

@ZzSean ZzSean merged commit 657dd5a into PaddlePaddle:develop Mar 1, 2022
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