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

Update add clip MSELoss and no_grad docs #28530

Merged
merged 1 commit into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion python/paddle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@
from .fluid.dygraph.base import enable_dygraph as disable_static #DEFINE_ALIAS
from .fluid.dygraph.base import disable_dygraph as enable_static #DEFINE_ALIAS
from .fluid.framework import in_dygraph_mode as in_dynamic_mode #DEFINE_ALIAS
from .fluid.dygraph.base import no_grad_ as no_grad #DEFINE_ALIAS
from .fluid.layers import crop_tensor as crop #DEFINE_ALIAS

from . import jit
Expand Down
2 changes: 0 additions & 2 deletions python/paddle/fluid/dygraph/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,6 @@ class no_grad_:
import numpy as np
import paddle

paddle.disable_static()

# use as generator

data = np.array([[2, 3], [4, 5]]).astype('float32')
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/framework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from ..fluid.core import VarBase #DEFINE_ALIAS

from paddle.fluid import core #DEFINE_ALIAS
from ..fluid.dygraph.base import no_grad #DEFINE_ALIAS
from ..fluid.dygraph.base import no_grad_ as no_grad #DEFINE_ALIAS
from ..fluid.dygraph.base import to_variable #DEFINE_ALIAS
from ..fluid.dygraph.base import grad #DEFINE_ALIAS
from .io import save
Expand Down
3 changes: 1 addition & 2 deletions python/paddle/nn/layer/loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,12 +418,11 @@ class MSELoss(fluid.dygraph.layers.Layer):
input_data = np.array([1.5]).astype("float32")
label_data = np.array([1.7]).astype("float32")

paddle.disable_static()
mse_loss = paddle.nn.loss.MSELoss()
input = paddle.to_tensor(input_data)
label = paddle.to_tensor(label_data)
output = mse_loss(input, label)
print(output.numpy())
print(output)
# [0.04000002]
"""

Expand Down
16 changes: 4 additions & 12 deletions python/paddle/tensor/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,18 +273,15 @@ def _elementwise_op(helper):

def add(x, y, name=None):
"""
Examples:
Examples:

.. code-block:: python

import paddle

paddle.disable_static()
x = paddle.to_tensor([2, 3, 4], 'float64')
y = paddle.to_tensor([1, 5, 2], 'float64')
z = paddle.add(x, y)
np_z = z.numpy()
print(np_z) # [3., 8., 6. ]
print(z) # [3., 8., 6. ]

"""
op_type = 'elementwise_add'
Expand Down Expand Up @@ -1358,9 +1355,6 @@ def addcmul(input, tensor1, tensor2, value=1.0, name=None):

def clip(x, min=None, max=None, name=None):
"""
:alias_main: paddle.clip
:alias: paddle.clip,paddle.tensor.clip,paddle.tensor.math.clip

**clip layer**

This operator clip all elements in input into the range [ min, max ] and return
Expand All @@ -1387,15 +1381,13 @@ def clip(x, min=None, max=None, name=None):
.. code-block:: python

import paddle

paddle.disable_static()
x1 = paddle.to_tensor([[1.2, 3.5], [4.5, 6.4]], 'float32')
out1 = paddle.clip(x1, min=3.5, max=5.0)
out2 = paddle.clip(x1, min=2.5)
print(out1.numpy())
print(out1)
# [[3.5, 3.5]
# [4.5, 5.0]]
print(out2.numpy())
print(out2)
# [[2.5, 3.5]
# [[4.5, 6.4]
"""
Expand Down