From 32a0eb508f305c4220a42cbc7e624609a76069d8 Mon Sep 17 00:00:00 2001 From: hong <43953930+phlrain@users.noreply.github.com> Date: Wed, 4 Dec 2019 15:22:40 +0800 Subject: [PATCH] Pick disable reshape inplace in dygraph (#21486) * disable reshape inplace in dygraph model; test=develop (#21157) * fix ExecutionContext::HasInput and ExecutionContext::HasOutput depend on the scope structure, test=develop (#20721) --- paddle/fluid/framework/operator.cc | 26 ++------------------------ python/paddle/fluid/layers/nn.py | 4 ++-- 2 files changed, 4 insertions(+), 26 deletions(-) diff --git a/paddle/fluid/framework/operator.cc b/paddle/fluid/framework/operator.cc index 96339412e6b..019ad295cc4 100644 --- a/paddle/fluid/framework/operator.cc +++ b/paddle/fluid/framework/operator.cc @@ -414,34 +414,12 @@ Tensor* GetMutableLoDTensorOrSelectedRowsValueFromVar(Variable* var) { } bool ExecutionContext::HasInput(const std::string& name) const { - if (!op_.HasInputs(name)) { - return false; - } - auto& ins = Inputs(name); - size_t length = ins.size(); - if (length == 0) { - return false; - } - PADDLE_ENFORCE_EQ(length, 1UL, - "Input %s should not have more than one inputs", name); - auto arg = ins[0]; - auto* var = arg == kEmptyVarName ? nullptr : scope_.FindVar(arg); + auto* var = InputVar(name); return var != nullptr; } bool ExecutionContext::HasOutput(const std::string& name) const { - if (!op_.HasOutputs(name)) { - return false; - } - auto& outs = Outputs(name); - size_t length = outs.size(); - if (length == 0) { - return false; - } - PADDLE_ENFORCE_EQ(length, 1UL, - "Output %s should not have more than one inputs", name); - auto arg = outs[0]; - auto* var = arg == kEmptyVarName ? nullptr : scope_.FindVar(arg); + auto* var = OutputVar(name); return var != nullptr; } diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index f696353b5d8..385297fc1de 100755 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -9011,8 +9011,8 @@ def reshape(x, shape, actual_shape=None, act=None, inplace=False, name=None): actual_shape.stop_gradient = True inputs["Shape"] = actual_shape - out = x if inplace else helper.create_variable_for_type_inference( - dtype=x.dtype) + out = x if inplace and not in_dygraph_mode( + ) else helper.create_variable_for_type_inference(dtype=x.dtype) x_shape = helper.create_variable_for_type_inference(dtype=x.dtype) helper.append_op( type="reshape2", -- GitLab