diff --git a/paddle/fluid/eager/custom_operator/custom_operator_node.cc b/paddle/fluid/eager/custom_operator/custom_operator_node.cc index 3efcf3b21a4e3e819bbfba348991dd46344ac644..beff23d433421b7bb197d9e452af771a7f02e400 100644 --- a/paddle/fluid/eager/custom_operator/custom_operator_node.cc +++ b/paddle/fluid/eager/custom_operator/custom_operator_node.cc @@ -263,9 +263,9 @@ RunCustomOpNode::operator()( trace_backward, &(ins_auto_grad_metas[i])); } - if (require_any_grad) { - auto meta_info_map = egr::Controller::Instance().GetOpMetaInfoMap(); - const auto& vec_map = meta_info_map.at(op_type_); + auto meta_info_map = egr::Controller::Instance().GetOpMetaInfoMap(); + const auto& vec_map = meta_info_map.at(op_type_); + if (require_any_grad && (vec_map.size() > 2)) { paddle::platform::RecordEvent node_creation_record_event( "Custom Op " + op_type_ + " double_grad node_creation", paddle::platform::TracerEventType::OperatorInner, 1); diff --git a/paddle/fluid/pybind/eager_functions.cc b/paddle/fluid/pybind/eager_functions.cc index c75ac0b52c52c4e20c3714fed764dc8152760620..311ad7b48ed7b099b819ba6daaab189c4517b4d8 100644 --- a/paddle/fluid/pybind/eager_functions.cc +++ b/paddle/fluid/pybind/eager_functions.cc @@ -384,7 +384,7 @@ static PyObject* eager_api_run_costum_op(PyObject* self, PyObject* args, require_any_grad || egr::EagerUtils::ComputeRequireGrad( trace_backward, &(ins_auto_grad_metas[i])); } - if (require_any_grad) { + if (require_any_grad && (vec_map.size() > 1)) { VLOG(6) << " Construct Grad for Custom Op: " << op_type; ConstructFwdAndBwdMap(vec_map, op_type); for (size_t i = 0; i < outs_auto_grad_metas.size(); i++) {