Skip to content

Commit 2a7efef

Browse files
authored
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.
1 parent c55f221 commit 2a7efef

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

paddle/fluid/imperative/partial_grad_engine.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -870,12 +870,14 @@ void PartialGradTask::RunEachOp(OpBase *op) {
870870
if (create_graph_) {
871871
auto double_grad_node = CreateGradOpNode(op->InnerOp(), tmp_ins, tmp_outs,
872872
op->Attrs(), op->place());
873-
if (double_grad_node) {
874-
VLOG(10) << "Create " << double_grad_node->size()
875-
<< " double grad op(s) for " << op->Type()
876-
<< ", pending ops: " << GradPendingOpTypes(*double_grad_node);
877-
double_grad_nodes_.emplace_back(std::move(double_grad_node));
878-
}
873+
PADDLE_ENFORCE_NOT_NULL(
874+
double_grad_node,
875+
platform::errors::NotFound("The Op %s doesn't have any grad op.",
876+
op->Type()));
877+
VLOG(10) << "Create " << double_grad_node->size()
878+
<< " double grad op(s) for " << op->Type()
879+
<< ", pending ops: " << GradPendingOpTypes(*double_grad_node);
880+
double_grad_nodes_.emplace_back(std::move(double_grad_node));
879881
}
880882

881883
VLOG(10) << "There are " << grads_to_accumulate_.size() << " to sum gradient";

0 commit comments

Comments
 (0)