未验证 提交 626ea800 编写于 作者: W wanghuancoder 提交者: GitHub

fix 2 bug of eager (#54041)

上级 b49a7e26
...@@ -141,6 +141,7 @@ std::vector<paddle::Tensor> RunBackward( ...@@ -141,6 +141,7 @@ std::vector<paddle::Tensor> RunBackward(
std::deque<GradNodeBase*> orig_queue; std::deque<GradNodeBase*> orig_queue;
std::unordered_map<GradNodeBase*, std::unique_ptr<GradTensorHolder>> std::unordered_map<GradNodeBase*, std::unique_ptr<GradTensorHolder>>
node_input_buffers_dict; node_input_buffers_dict;
std::unordered_set<GradNodeBase*> visited;
for (size_t i = 0; i < tensors.size(); i++) { for (size_t i = 0; i < tensors.size(); i++) {
const paddle::Tensor& tensor = tensors[i]; const paddle::Tensor& tensor = tensors[i];
...@@ -215,6 +216,10 @@ std::vector<paddle::Tensor> RunBackward( ...@@ -215,6 +216,10 @@ std::vector<paddle::Tensor> RunBackward(
} }
// Prepare queue, potential startup_nodes // Prepare queue, potential startup_nodes
if (visited.count(grad_node)) {
continue;
}
visited.insert(grad_node);
queue.push_back(grad_node); queue.push_back(grad_node);
} }
......
...@@ -163,7 +163,7 @@ GradNodePyLayer::operator()( ...@@ -163,7 +163,7 @@ GradNodePyLayer::operator()(
{paddle::pybind::UnSafeGetTensorFromPyObject(obj)}); {paddle::pybind::UnSafeGetTensorFromPyObject(obj)});
} else if (obj == Py_None) { } else if (obj == Py_None) {
VLOG(4) << "Got None for Tensor with pos: " << i; VLOG(4) << "Got None for Tensor with pos: " << i;
grad_out.push_back({}); grad_out.push_back({paddle::Tensor()});
} else { } else {
PADDLE_THROW(phi::errors::InvalidArgument( PADDLE_THROW(phi::errors::InvalidArgument(
"We can only support Tensor or None for backward output, " "We can only support Tensor or None for backward output, "
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册