-
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
add weight_norm & remove_weight_norm #26131
Conversation
Thanks for your contribution! |
✅ This PR's description meets the template requirements! |
__all__ = ['weight_norm', 'remove_weight_norm'] | ||
|
||
|
||
def l2_norm(x, axis, epsilon=1e-12, name=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.
用l2_normalize
也一样吧?
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.
不可以.. layers. l2_normalize只返回了out,但是这里是要用到另一个norm输出..
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.
oh, understood.
python/paddle/fluid/param_attr.py
Outdated
@@ -216,6 +216,8 @@ class WeightNormParamAttr(ParamAttr): | |||
It is recommended to use ``minimize(loss, grad_clip=clip)`` to clip gradient. | |||
There are three clipping strategies: :ref:`api_fluid_clip_GradientClipByGlobalNorm` , | |||
:ref:`api_fluid_clip_GradientClipByNorm` , :ref:`api_fluid_clip_GradientClipByValue` . | |||
|
|||
Please use 'paddle.nn.utils.weight_norm' in dygraph mode. |
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.
move this line to the beginning of the docstring would be better. (i.e.: Line 206)
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.
done, thanks
.. code-block:: python | ||
|
||
import numpy as np | ||
import paddle.fluid as fluid |
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.
no need to import fluid
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.
done, thanks
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
conv = Conv2D(3, 5, 3) | ||
wn = weight_norm(conv) | ||
remove_weight_norm(conv) | ||
print(conv.weight.shape) |
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.
这个print能体现remove_weight_norm生效了么?
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.
换成 print conv.weight_g 了,谢谢~
|
||
def weight_norm(layer, name='weight', dim=0): | ||
""" | ||
This weight_norm layer apply weight normalization to a parameter according to the |
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.
applies?
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.
done, thanks
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
Others
PR changes
APIs
Describe
Add weight_norm and remove_weight_norm for dygraph