diff --git a/paddle/fluid/framework/details/ssa_graph_builder.cc b/paddle/fluid/framework/details/ssa_graph_builder.cc index d24669a8f8dfd5801239c036619531b4c16433d8..c4ee088507b37d50e9821db3ac4f1d8c55bc75ea 100644 --- a/paddle/fluid/framework/details/ssa_graph_builder.cc +++ b/paddle/fluid/framework/details/ssa_graph_builder.cc @@ -135,9 +135,11 @@ bool SSAGraphBuilder::IsValidGraph(const SSAGraph *graph) const { while (!pending_vars.empty()) { run_all_ops(ready_ops); + if (ready_vars.empty()) { return false; } + for (auto ready_var : ready_vars) { pending_vars.erase(ready_var); for (auto *op : ready_var->pending_ops_) {