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

Fix NaN for softmax with long softmax_dim. #57851

Merged
merged 4 commits into from
Oct 9, 2023

Conversation

Xreki
Copy link
Contributor

@Xreki Xreki commented Sep 28, 2023

PR types

Bug fixes

PR changes

OPs

Description

Pcard-70459

  1. 修复softmax函数出现NaN #55685 ,softmax长维度分支、前向结果在小输入数据出现NaN问题。
  2. 简化KeMatrixSoftmaxForward代码,主要包括以下几点:
    • 移除BatchSize模板,外层实际传入的为BlockDim,Kernel中实际并没有用到,增大了编译负担
    • 移除VecSize模板,对于每种数据类型,使用的VecSize是固定的,没有必要为多种VecSize特化
  3. 为前向的switchdefault分支添加报错信息;反向添加报错后,log_softmax算子单测会fail,待反向计算问题解决后再添加。
    • log_softmax反向没有执行Kernel、单测通过的原因分析 @ZzSean :shape太大了,算出来的梯度接近0,如下
a1e0d7eb0660b30fcae2c4a0215d2887

@paddle-bot
Copy link

paddle-bot bot commented Sep 28, 2023

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@Xreki Xreki changed the title Fix nan for softmax with long softmax_dim. Fix NaN for softmax with long softmax_dim. Sep 28, 2023
@paddle-ci-bot
Copy link

paddle-ci-bot bot commented Oct 6, 2023

Sorry to inform you that 15089a9's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually.

@Xreki Xreki requested a review from ZzSean October 9, 2023 06:08
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

@Xreki Xreki merged commit ac3ae61 into PaddlePaddle:develop Oct 9, 2023
26 of 27 checks passed
@Xreki Xreki deleted the op/fix_softmax_nan branch October 9, 2023 09:04
Frida-a pushed a commit to Frida-a/Paddle that referenced this pull request Oct 14, 2023
* Fix nan for softmax with long softmax_dim.

* Simplify codes.

* Remove the PADDLE_THROW in backward.
jiahy0825 pushed a commit to jiahy0825/Paddle that referenced this pull request Oct 16, 2023
* Fix nan for softmax with long softmax_dim.

* Simplify codes.

* Remove the PADDLE_THROW in backward.
danleifeng pushed a commit to danleifeng/Paddle that referenced this pull request Nov 14, 2023
* Fix nan for softmax with long softmax_dim.

* Simplify codes.

* Remove the PADDLE_THROW in backward.
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.

None yet

2 participants