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

[xdoctest] reformat example code with google style in No 101 #55968

Merged
merged 6 commits into from
Aug 14, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 22 additions & 23 deletions python/paddle/nn/utils/weight_norm_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,15 @@ def weight_norm(layer, name='weight', dim=0):
Examples:
.. code-block:: python

from paddle.nn import Conv2D
from paddle.nn.utils import weight_norm

conv = Conv2D(3, 5, 3)
wn = weight_norm(conv)
print(conv.weight_g.shape)
# [5]
print(conv.weight_v.shape)
# [5, 3, 3, 3]
>>> from paddle.nn import Conv2D
>>> from paddle.nn.utils import weight_norm

>>> conv = Conv2D(3, 5, 3)
>>> wn = weight_norm(conv)
>>> print(conv.weight_g.shape)
[5]
>>> print(conv.weight_v.shape)
[5, 3, 3, 3]
"""
WeightNorm.apply(layer, name, dim)
return layer
Expand All @@ -219,21 +219,20 @@ def remove_weight_norm(layer, name='weight'):
Examples:
.. code-block:: python

import paddle
from paddle.nn import Conv2D
from paddle.nn.utils import weight_norm, remove_weight_norm

conv = Conv2D(3, 5, 3)
wn = weight_norm(conv)
print(conv.weight_g)
# Parameter containing:
# Tensor(shape=[5], dtype=float32, place=Place(gpu:0), stop_gradient=False,
# [0., 0., 0., 0., 0.])
# Conv2D(3, 5, kernel_size=[3, 3], data_format=NCHW)

remove_weight_norm(conv)
>>> import paddle
>>> from paddle.nn import Conv2D
>>> from paddle.nn.utils import weight_norm, remove_weight_norm
>>> paddle.seed(2023)

>>> conv = Conv2D(3, 5, 3)
>>> wn = weight_norm(conv)
>>> print(conv.weight_g)
Parameter containing:
Tensor(shape=[5], dtype=float32, place=Place(cpu), stop_gradient=False,
[1.35883713, 1.32126212, 1.56303072, 1.20874095, 1.22893476])
>>> remove_weight_norm(conv)
# The following is the effect after removing the weight norm:
# print(conv.weight_g)
>>> print(conv.weight_g)
# AttributeError: 'Conv2D' object has no attribute 'weight_g'
"""
for k, hook in layer._forward_pre_hooks.items():
Expand Down