-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[API compatibility] add nn.init.* functions #74478
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
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #74478 +/- ##
==========================================
Coverage ? 98.38%
==========================================
Files ? 5
Lines ? 62
Branches ? 0
==========================================
Hits ? 61
Misses ? 1
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
python/paddle/nn/__init__.py
Outdated
@@ -319,4 +321,5 @@ | |||
'LPPool2D', | |||
'ZeroPad1D', | |||
'ZeroPad3D', | |||
'init', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个导出来是作为1个api吗,好像不用导出来
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
应该是由于__all__的原因,不导出的话这样使用会报错:
import paddle
tensor = paddle.zeros([32, 64])
paddle.nn.init.kaiming_uniform_(tensor)
AttributeError: module 'paddle.nn' has no attribute 'init'
python/paddle/nn/init.py
Outdated
|
||
def _no_grad_uniform_(tensor, a, b): | ||
with paddle.no_grad(): | ||
tensor.set_value( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
静态图下这个能跑不,如果不能跑 可以考虑复用之前的initializer,先实例化然后call:
init = paddle.nn.initializer()
init(param)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改
return (b - a) * random.random() + a | ||
|
||
def calculate_gain(self, nonlinearity, param): | ||
recommended_gain = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这些是从torch的calculate_gain里查到的吗,也补充到paddle的calculate_gain里吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个函数paddle也有一个在nn.initializer.initializer下,为了能够与torch的torch.nn.init.calculate_gain的调用接口对应,也将这个函数引用到了paddle.nn.init文件中,可以paddle.nn.init.calculate_gain调用使用
python/paddle/nn/init.py
Outdated
a: float = 0, | ||
mode: str = "fan_in", | ||
nonlinearity: str = "leaky_relu", | ||
block: paddle.pir.Block | None = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个block建议先不加,这个是老IR用的,以后如果确实需要再加。这个对用户会有一些理解成本。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的,已经去掉
python/paddle/nn/__init__.py
Outdated
@@ -12,6 +12,8 @@ | |||
# See the License for the specific language governing permissions and | |||
# limitations under the License. | |||
|
|||
from paddle.nn import init as init |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里不需要导入init,直接paddle.nn.init会自动访问到 init.py
下面的函数吧,看torch是这样的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
python/paddle/nn/init.py
Outdated
from ..base.framework import in_dygraph_mode, in_pir_mode | ||
from .initializer.constant import Constant | ||
from .initializer.dirac import Dirac | ||
from .initializer.initializer import calculate_gain as calculate_gain_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个为何需要先别名成其他的,然后又别名回来
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改
python/paddle/nn/init.py
Outdated
) | ||
return new_tensor | ||
else: | ||
new_tensor = paddle.eye( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改
/re-run all-failed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/re-run coverage build |
d330635
d10e3bc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* add nn.init.kaiming_uniform_ * update kaiming_uniform_ * update unit test for kaiming_uniform_ * add nn.init.kaiming_uniform_ * update kaiming_uniform_ * update unit test for kaiming_uniform_ * add xavier_uniform_, kaiming_normal_, uniform_ * add unit test for xavier_uniform_, kaiming_normal_, uniform_ * add xavier_normal_ and its unit test * add normal_ and its unit test * fix: remove 'block' parameter from init.*() function * fix * add nn.init.constant_, nn.init.ones_, nn.init.zeros_ * support paddle.pir.Value type * add dirac_, eye_, orthogonal_ * update unit test for nn.init.* * update init * add paddle.pir.Value * update unit test for nn.init.orthogonal_ * fix unit test for nn.init.eye_ * fix: skip unit test on dcu
PR Category
User Experience
PR Types
New features
Description
add init functions:
Pcard-75624