From 42754088269ac52390a6376d29dc421610aee2ba Mon Sep 17 00:00:00 2001 From: Jiabin Yang <360788950@qq.com> Date: Tue, 14 Jun 2022 10:15:40 +0800 Subject: [PATCH] [Eager] Fix custom op error (#43463) * fix custom op error * fix code error --- paddle/fluid/eager/custom_operator/custom_operator_node.cc | 6 +++--- paddle/fluid/pybind/eager_functions.cc | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/paddle/fluid/eager/custom_operator/custom_operator_node.cc b/paddle/fluid/eager/custom_operator/custom_operator_node.cc index 3efcf3b21a..beff23d433 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 c75ac0b52c..311ad7b48e 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++) { -- GitLab