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 BatchNorm for fp16 #36376

Merged
merged 2 commits into from
Oct 13, 2021
Merged

Conversation

GuoxiaWang
Copy link
Contributor

PR types

Bug fixes

PR changes

APIs

Describe

fix BatchNorm for fp16

@paddle-bot-old
Copy link

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

ceci3
ceci3 previously approved these changes Oct 12, 2021
Copy link
Contributor

@ceci3 ceci3 left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -563,7 +563,10 @@ def __init__(self,
self._bias_attr = bias_attr
self._use_global_stats = use_global_stats

self._dtype = 'float32'
if get_default_dtype() == 'float16':
Copy link
Contributor

Choose a reason for hiding this comment

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

这样的话default type是fp16的话,不是还是强制改成了fp32嘛?

Copy link
Contributor Author

@GuoxiaWang GuoxiaWang Oct 13, 2021

Choose a reason for hiding this comment

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

是必须强制改成fp32,因为精度问题,batchnorm 是明确要求参数不能是fp16的,一般fp16输入都是用fp32的来表达参数,输入可以是fp16,区别在于 set_default_dtype,这个会改变全局的 dtype,而这个位置应该只是改变当前层的 dtype,所以应该只改变局部dtype,而不是全局 dtype

@sandyhouse sandyhouse merged commit 8fd1b6a into PaddlePaddle:develop Oct 13, 2021
GuoxiaWang added a commit to GuoxiaWang/Paddle that referenced this pull request Oct 25, 2021
fuyinno4 pushed a commit that referenced this pull request Oct 27, 2021
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.

3 participants