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

[Bug fix] Fix kaiming initializer div zero #49656

Merged

Conversation

wanghuancoder
Copy link
Contributor

@wanghuancoder wanghuancoder commented Jan 9, 2023

PR types

Bug fixes

PR changes

Others

Describe

KaimingUniform初始化器,在如下代码下会发生除0问题:
paddle.nn.initializer.KaimingUniform has divide by 0 problem in following case:

import paddle
import numpy as np

paddle.enable_static()
x = paddle.static.data(name='x', shape=[1, 0, 0], dtype='float32')

kaiming = paddle.nn.initializer.KaimingUniform(0)
param_attr = paddle.ParamAttr(initializer=kaiming)

paddle.static.nn.prelu(x, 'all', param_attr=param_attr)
  • 原因:这个初始化器,默认是使用Tensor shape的一个维度作为fan_in的,也可以由用户指定fan_in的值。但均不能为0。
  • 解决方案:对这两种情况添加检查、报错。同时为这种场景添加单测case。
  • Reason: This initializer uses one dimension of Tensor shape as fan_in by default, besides, users can also specify the value of fan_in. But both of them can not be 0.
  • Solution: Add parameter check, error reporting, and unit-test for these two scenarios.

@paddle-bot
Copy link

paddle-bot bot commented Jan 9, 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.

@wanghuancoder wanghuancoder merged commit 35fa30d into PaddlePaddle:develop Jan 10, 2023
@Ligoml Ligoml mentioned this pull request Jan 18, 2023
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