From 2a7efefe24ce5a0c1f9f01cbf326067bfafee7f1 Mon Sep 17 00:00:00 2001 From: Zhen Wang Date: Wed, 5 Aug 2020 18:18:28 +0800 Subject: [PATCH] Add some error messages for the op without double grads. (#25951) (#25963) * Add some error messages for the op without double grads. * fix the test_imperative_double_grad UT. --- paddle/fluid/imperative/partial_grad_engine.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/paddle/fluid/imperative/partial_grad_engine.cc b/paddle/fluid/imperative/partial_grad_engine.cc index 342d046db73..c9081ddd8a9 100644 --- a/paddle/fluid/imperative/partial_grad_engine.cc +++ b/paddle/fluid/imperative/partial_grad_engine.cc @@ -870,12 +870,14 @@ void PartialGradTask::RunEachOp(OpBase *op) { if (create_graph_) { auto double_grad_node = CreateGradOpNode(op->InnerOp(), tmp_ins, tmp_outs, op->Attrs(), op->place()); - if (double_grad_node) { - VLOG(10) << "Create " << double_grad_node->size() - << " double grad op(s) for " << op->Type() - << ", pending ops: " << GradPendingOpTypes(*double_grad_node); - double_grad_nodes_.emplace_back(std::move(double_grad_node)); - } + PADDLE_ENFORCE_NOT_NULL( + double_grad_node, + platform::errors::NotFound("The Op %s doesn't have any grad op.", + op->Type())); + VLOG(10) << "Create " << double_grad_node->size() + << " double grad op(s) for " << op->Type() + << ", pending ops: " << GradPendingOpTypes(*double_grad_node); + double_grad_nodes_.emplace_back(std::move(double_grad_node)); } VLOG(10) << "There are " << grads_to_accumulate_.size() << " to sum gradient"; -- GitLab