diff --git a/paddle/fluid/eager/accumulation/accumulation_node.cc b/paddle/fluid/eager/accumulation/accumulation_node.cc index dd0cb9b43e68872e7f34c62ce16c349ccc5a8140..c271d9f49377fb4a89fce0bb7cf0f012c1032504 100644 --- a/paddle/fluid/eager/accumulation/accumulation_node.cc +++ b/paddle/fluid/eager/accumulation/accumulation_node.cc @@ -124,7 +124,10 @@ GradNodeAccumulation::operator()( if (!weak_grad_.expired() && !is_new_grad) { auto grad = weak_grad_.lock(); - CopyOrAddTensor(grad.get(), grad_out, is_fake_empty_); + if (grad_out.defined() && grad_out.initialized()) { + CopyOrAddTensor(grad.get(), grad_out, is_fake_empty_); + } + // else { do nothing since there is no valid value in grad out tensor } is_fake_empty_ = false; }