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 the computation of log_softmax #40612

Merged
merged 2 commits into from
Mar 16, 2022

Conversation

ZzSean
Copy link
Contributor

@ZzSean ZzSean commented Mar 16, 2022

PR types

Performance optimization

PR changes

OPs

Describe

Optimize the computation of log_softmax。
合入#38992后,部分case性能有回退,原因是在softmax的基础上实现log softmax,存在重复计算,优化完计算后,性能与之前持平

config dev(3.12) dev(3.15) 合入PR38992后 该PR
2 0.06279 0.06437 0.06280
3 0.03381 0.04106 0.03358
4 0.0051 0.00566 0.00512
5 0.0051 0.00584 0.00514

@paddle-bot-old
Copy link

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

@@ -293,9 +288,10 @@ __global__ void WarpSoftmaxForward(T* softmax,
}

// data src
AccT srcdata_raw[kBatchSize][kLoopsV][kVSize];
AccT srcdata[kBatchSize][kLoopsV][kVSize];
T src_tmp[kBatchSize][kLoopsV][kVSize];
Copy link
Contributor

Choose a reason for hiding this comment

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

这样弄了3个寄存器数组,srcdata_rawsrcdatasrc_tmp,含义从变量名很难区分。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

修改了变量名,并添加了注释


HOSTDEVICE explicit inline ExpSubFunctor(Tx y) : y((Tx)(y)) {}
struct ExpFunctor {
HOSTDEVICE explicit inline ExpFunctor() {}
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.

已删除

@ZzSean ZzSean merged commit 2dec25d into PaddlePaddle:develop Mar 16, 2022
liqitong-a pushed a commit to liqitong-a/Paddle that referenced this pull request Mar 17, 2022
* Optimize the computation of log_softmax

* modify the var name
@ZzSean ZzSean deleted the opt_logsoftmax_compute branch April 14, 2022 09:00
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