-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[Eager]Support Lazy initialization for nn.Layer #44990
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
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
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.
现在实现OK,但是还是希望能够有更好的办法隐藏LazyInit调用。
如昨天讨论,暂时还没有比较好的方式能够实现概念的完全隐藏 |
b236fb3
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
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
__all__ = ["LazyInit"] | ||
|
||
|
||
class LazyGuard(object): |
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.
- 为了保持外部开发者的代码统一,建议使用一种使用方式 LazyInit 或者 LazyGuard
- 考虑到使用Guard和不使用Guard的时候会需要做代码缩进的调整,改动量较大,Paddle一般不推荐使用Guard的方式,推荐使用LazyInit(Linear)这种方式,除非这种写法写起来确实很麻烦。
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.
已移除 LazyInit中的__enter__和__exit__ 函数
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
PR types
New features
PR changes
APIs
Describe
what's New?
动态图 Layer 实例化时,新增模型参数延迟初始化功能
新增 LazyInit 类接口,支持两种方式触发参数的Lazy初始化
LazyInit(Model)(...)
,即在实例化时,用 LazyInit 进行包裹with LazyInit() as lz
方式,在with block内的所有Parameter参数都会lazy初始化给EagerParamBase 新增一个initialize() 接口,用于应用Lazy hook函数,以自定义初始化param的数据.