diff --git a/paddle/fluid/framework/operator.cc b/paddle/fluid/framework/operator.cc index 1a719e6b7da1468d3470944ff026b15b372fd2e8..a608d1bd3af731146f9a87e943af603912197cb1 100644 --- a/paddle/fluid/framework/operator.cc +++ b/paddle/fluid/framework/operator.cc @@ -417,34 +417,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; }