Skip to content

Commit e838a4b

Browse files
authored
skip CopyOrAdd when tmp grad is None (#55679)
1 parent 2ade1f9 commit e838a4b

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

paddle/fluid/eager/accumulation/accumulation_node.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ GradNodeAccumulation::operator()(
124124

125125
if (!weak_grad_.expired() && !is_new_grad) {
126126
auto grad = weak_grad_.lock();
127-
CopyOrAddTensor(grad.get(), grad_out, is_fake_empty_);
127+
if (grad_out.defined() && grad_out.initialized()) {
128+
CopyOrAddTensor(grad.get(), grad_out, is_fake_empty_);
129+
}
130+
// else { do nothing since there is no valid value in grad out tensor }
128131
is_fake_empty_ = false;
129132
}
130133

0 commit comments

Comments
 (0)