Skip to content
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
2 changes: 1 addition & 1 deletion paddle/fluid/operators/unique_op.cu
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ static void UniqueFlattendCUDATensor(const framework::ExecutionContext& context,
thrust::sort_by_key(thrust::device, in_data_hat, in_data_hat + num_input,
sorted_indices_data);

// 1. Calculate op result: 'out'
// 1. Calculate op result: 'out'
Tensor range;
range.Resize(framework::make_ddim({num_input + 1}));
auto range_data_ptr = range.mutable_data<IndexT>(context.GetPlace());
Expand Down
22 changes: 7 additions & 15 deletions paddle/fluid/pybind/imperative.cc
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,6 @@ void BindImperative(py::module *m_ptr) {
.. code-block:: python

import paddle
paddle.disable_static()

linear = Linear(32, 64)
data = paddle.uniform(shape=[30, 10, 32], -1, 1)
x = linear(data)
Expand All @@ -704,19 +702,13 @@ void BindImperative(py::module *m_ptr) {
.. code-block:: python

import paddle
paddle.disable_static()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ret = paddle.sums(inputs2)这行应该跑不了吧。

另外,感觉可以用一个更加简洁的示例。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


inputs = []
for _ in range(10):
tmp = paddle.ones([2, 2])
tmp.stop_gradient=False
inputs.append(tmp)
ret = paddle.sums(inputs2)
loss = paddle.sum(ret)
loss.backward()
print("Before clear_gradient {}".format(loss.grad))
loss.clear_gradient()
print("After clear_gradient {}".format(loss.grad))
input = paddle.uniform([10, 2])
linear = paddle.nn.Linear(2, 3)
out = linear(input)
out.backward()
print("Before clear_gradient, linear.weight.grad: {}".format(linear.weight.grad))
linear.weight.clear_gradient()
print("After clear_gradient, linear.weight.grad: {}".format(linear.weight.grad))
)DOC")
.def("clone",
[](std::shared_ptr<imperative::VarBase> &self) {
Expand Down
6 changes: 1 addition & 5 deletions python/paddle/framework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
'get_default_dtype', 'set_default_dtype'
]

__all__ += [
'grad', 'LayerList', 'load', 'save', 'to_variable', 'no_grad',
'DataParallel'
]
__all__ += ['grad', 'LayerList', 'load', 'save', 'no_grad', 'DataParallel']

from . import random
from .random import seed
Expand All @@ -39,7 +36,6 @@

from paddle.fluid import core #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
from .io import load
Expand Down
4 changes: 0 additions & 4 deletions python/paddle/framework/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,6 @@ def save(obj, path):

import paddle

paddle.disable_static()

emb = paddle.nn.Embedding(10, 10)
layer_state_dict = emb.state_dict()
paddle.save(layer_state_dict, "emb.pdparams")
Expand Down Expand Up @@ -318,8 +316,6 @@ def load(path, **configs):
.. code-block:: python

import paddle

paddle.disable_static()

emb = paddle.nn.Embedding(10, 10)
layer_state_dict = emb.state_dict()
Expand Down
Loading