From e838a4b4e5342d9fd69cda1d0311dc2067ce6f87 Mon Sep 17 00:00:00 2001 From: Yuang Liu Date: Wed, 26 Jul 2023 13:37:52 +0800 Subject: [PATCH] skip CopyOrAdd when tmp grad is None (#55679) --- paddle/fluid/eager/accumulation/accumulation_node.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/paddle/fluid/eager/accumulation/accumulation_node.cc b/paddle/fluid/eager/accumulation/accumulation_node.cc index dd0cb9b43e6..c271d9f4937 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; } -- GitLab