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

Fix api for ErrorClipByValue, code demo of clip_by_norm. test=develop #27654

Merged
merged 13 commits into from
Sep 30, 2020
13 changes: 9 additions & 4 deletions python/paddle/fluid/layers/nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -12413,12 +12413,17 @@ def clip_by_norm(x, max_norm, name=None):
Examples:
.. code-block:: python

import paddle.fluid as fluid
input = fluid.data(
name='data', shape=[None, 1], dtype='float32')
reward = fluid.layers.clip_by_norm(x=input, max_norm=1.0)
import paddle
import numpy as np

paddle.disable_static()
input = paddle.to_tensor(data=np.array([[0.1, 0.2], [0.3, 0.4]]), dtype="float32")
reward = paddle.nn.clip_by_norm(x=input, max_norm=1.0)
"""

if in_dygraph_mode():
return core.ops.clip_by_norm(x, 'max_norm', max_norm)

helper = LayerHelper("clip_by_norm", **locals())
check_variable_and_dtype(x, 'X', ['float32'], 'clip_by_norm')
check_type(max_norm, 'max_norm', (float), 'clip_by_norm')
Expand Down
1 change: 0 additions & 1 deletion python/paddle/nn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
__all__ += weight_norm_hook.__all__

# TODO: define alias in nn directory
# from .clip import ErrorClipByValue #DEFINE_ALIAS
from .clip import GradientClipByGlobalNorm #DEFINE_ALIAS
from .clip import GradientClipByNorm #DEFINE_ALIAS
from .clip import GradientClipByValue #DEFINE_ALIAS
Expand Down