diff --git a/paddle/fluid/framework/operator.cc b/paddle/fluid/framework/operator.cc index 96339412e6b6d8c08fd771793018599fcbdf6b92..019ad295cc455634265154ed9d8510b30c80b46c 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 f696353b5d816945c179095de838c689f322d20f..385297fc1dea6691800d4d7f42643493be4adf2e 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",