From c7e0a8bebfed08bf6f4e523d778e1dcee8e200db Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Mon, 28 Sep 2020 18:42:36 +0800 Subject: [PATCH] Remove inplace argument when calling nn.reshape() (#27376) * remove inplace argument * fix sample code * fix sample code --- python/paddle/fluid/dygraph/parallel.py | 2 +- python/paddle/fluid/layers/loss.py | 2 +- python/paddle/fluid/layers/nn.py | 8 +++++--- python/paddle/tensor/manipulation.py | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/python/paddle/fluid/dygraph/parallel.py b/python/paddle/fluid/dygraph/parallel.py index de761cad529..344ae55ee9d 100644 --- a/python/paddle/fluid/dygraph/parallel.py +++ b/python/paddle/fluid/dygraph/parallel.py @@ -416,7 +416,7 @@ class DataParallel(layers.Layer): g_var_shapes.append(g_var.shape) flattened_vars.append( nn.reshape( - x=g_var, shape=[np.prod(g_var.shape)], inplace=True)) + x=g_var, shape=[np.prod(g_var.shape)])) coalesced_grad = nn.concat(flattened_vars) coalesced_grads_and_grad_vars.append( [coalesced_grad, grad_vars, g_var_shapes]) diff --git a/python/paddle/fluid/layers/loss.py b/python/paddle/fluid/layers/loss.py index 037c7e85004..dce7494c190 100644 --- a/python/paddle/fluid/layers/loss.py +++ b/python/paddle/fluid/layers/loss.py @@ -1755,7 +1755,7 @@ def npair_loss(anchor, positive, labels, l2_reg=0.002): Beta = 0.25 batch_size = labels.shape[0] - labels = nn.reshape(labels, shape=[batch_size, 1], inplace=True) + labels = nn.reshape(labels, shape=[batch_size, 1]) labels = nn.expand(labels, expand_times=[1, batch_size]) labels = equal(labels, nn.transpose(labels, perm=[1, 0])).astype('float32') diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index b5148c215e9..4a15ecb2004 100755 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -6101,15 +6101,17 @@ def reshape(x, shape, actual_shape=None, act=None, inplace=False, name=None): Examples: .. code-block:: python - + + import paddle import paddle.fluid as fluid - + paddle.enable_static() + # example 1: # attr shape is a list which doesn't contain Tensors. data_1 = fluid.data( name='data_1', shape=[2, 4, 6], dtype='float32') reshaped_1 = fluid.layers.reshape( - x=data_1, shape=[-1, 0, 3, 2], inplace=True) + x=data_1, shape=[-1, 0, 3, 2]) # the shape of reshaped_1 is [2,4,3,2]. # example 2: diff --git a/python/paddle/tensor/manipulation.py b/python/paddle/tensor/manipulation.py index dc6a04a4723..6345a01f14a 100644 --- a/python/paddle/tensor/manipulation.py +++ b/python/paddle/tensor/manipulation.py @@ -363,7 +363,7 @@ def roll(x, shifts, axis=None, name=None): outputs={'Out': out}, attrs={'axis': axis, 'shifts': shifts}) - out = layers.reshape(out, shape=origin_shape, inplace=True) + out = layers.reshape(out, shape=origin_shape) return out -- GitLab