From 626ea8009bc5b77cabaf6ad19d4b0f621e790b6f Mon Sep 17 00:00:00 2001 From: wanghuancoder Date: Tue, 23 May 2023 15:53:14 +0800 Subject: [PATCH] fix 2 bug of eager (#54041) --- paddle/fluid/eager/backward.cc | 5 +++++ paddle/fluid/eager/pylayer/py_layer_node.cc | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/paddle/fluid/eager/backward.cc b/paddle/fluid/eager/backward.cc index 0477c5d5f90..dd310757956 100644 --- a/paddle/fluid/eager/backward.cc +++ b/paddle/fluid/eager/backward.cc @@ -141,6 +141,7 @@ std::vector RunBackward( std::deque orig_queue; std::unordered_map> node_input_buffers_dict; + std::unordered_set visited; for (size_t i = 0; i < tensors.size(); i++) { const paddle::Tensor& tensor = tensors[i]; @@ -215,6 +216,10 @@ std::vector RunBackward( } // Prepare queue, potential startup_nodes + if (visited.count(grad_node)) { + continue; + } + visited.insert(grad_node); queue.push_back(grad_node); } diff --git a/paddle/fluid/eager/pylayer/py_layer_node.cc b/paddle/fluid/eager/pylayer/py_layer_node.cc index 4dac92b63dd..3f88c22148c 100644 --- a/paddle/fluid/eager/pylayer/py_layer_node.cc +++ b/paddle/fluid/eager/pylayer/py_layer_node.cc @@ -163,7 +163,7 @@ GradNodePyLayer::operator()( {paddle::pybind::UnSafeGetTensorFromPyObject(obj)}); } else if (obj == Py_None) { VLOG(4) << "Got None for Tensor with pos: " << i; - grad_out.push_back({}); + grad_out.push_back({paddle::Tensor()}); } else { PADDLE_THROW(phi::errors::InvalidArgument( "We can only support Tensor or None for backward output, " -- GitLab