-
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
[xdoctest][task 239] reformat example code with google style in python/paddle/incubate/asp/asp.py
#56731
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
>>> # Need to set excluded layers before calling decorate | ||
>>> paddle.incubate.asp.set_excluded_layers([my_layer.linear1.full_name()]) | ||
|
||
>>> optimizer = paddle.incubate.asp.decorate(optimizer) |
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.
to @megemini :自己记录一下 ~ 下面一段程序:
In [1]: >>> import paddle
...: >>> class MyLayer(paddle.nn.Layer):
...: ... def __init__(self):
...: ... super().__init__()
...: ... self.linear1 = paddle.nn.Linear(4624, 100)
...: ...
...: ... def forward(self, img):
...: ... prediction = self.linear1(img)
...: ... return prediction
...: >>> my_layer = MyLayer()
...: >>> optimizer = paddle.optimizer.SGD(
...: ... learning_rate=0.01, parameters=my_layer.parameters())
...: >>> optimizer = paddle.incubate.asp.decorate(optimizer)
W0829 13:57:09.095414 11450 gpu_resources.cc:119] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 11.6
W0829 13:57:09.102089 11450 gpu_resources.cc:149] device: 0, cuDNN Version: 8.4.
In [2]: optimizer.state_dict()
Out[2]:
{'linear_0.w_0.asp_mask': Parameter containing:
Tensor(shape=[4624, 100], dtype=float32, place=Place(gpu:0), stop_gradient=True,
[[1., 1., 1., ..., 1., 1., 1.],
[1., 1., 1., ..., 1., 1., 1.],
[1., 1., 1., ..., 1., 1., 1.],
...,
[1., 1., 1., ..., 1., 1., 1.],
[1., 1., 1., ..., 1., 1., 1.],
[1., 1., 1., ..., 1., 1., 1.]])}
In [3]: >>> my_layer = MyLayer()
...: >>> optimizer = paddle.optimizer.SGD(
...: ... learning_rate=0.01, parameters=my_layer.parameters())
...: >>> optimizer = paddle.incubate.asp.decorate(optimizer)
In [4]: optimizer.state_dict()
Out[4]:
{'linear_0.w_0.asp_mask': Parameter containing:
Tensor(shape=[4624, 100], dtype=float32, place=Place(gpu:0), stop_gradient=True,
[[1., 1., 1., ..., 1., 1., 1.],
[1., 1., 1., ..., 1., 1., 1.],
[1., 1., 1., ..., 1., 1., 1.],
...,
[1., 1., 1., ..., 1., 1., 1.],
[1., 1., 1., ..., 1., 1., 1.],
[1., 1., 1., ..., 1., 1., 1.]]),
'linear_1.w_0.asp_mask': Parameter containing:
Tensor(shape=[4624, 100], dtype=float32, place=Place(gpu:0), stop_gradient=True,
[[1., 1., 1., ..., 1., 1., 1.],
[1., 1., 1., ..., 1., 1., 1.],
[1., 1., 1., ..., 1., 1., 1.],
...,
[1., 1., 1., ..., 1., 1., 1.],
[1., 1., 1., ..., 1., 1., 1.],
[1., 1., 1., ..., 1., 1., 1.]])}
In [5]:
由于之前提到的 layer 全局名称的问题,这里的 optimizer 会累计参数 ~
也不清楚这样有没有影响?(至少 save 的文件大小有影响 ... ...)
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.
LGTMeow 🐾
@mingxu1067 是否可以补充一下~ |
…on/paddle/incubate/asp/asp.py` (PaddlePaddle#56731) * [Doctest]fix No.239, test=docs_preview * fix style
PR types
Others
PR changes
Others
Description
修改如下文件的示例代码,使其通过
xdoctest
检查:python/paddle/incubate/asp/asp.py
预览:
Related links
@sunzhongkai588 @SigureMo @megemini