diff --git a/paddle/fluid/framework/details/scope_buffered_ssa_graph_executor.cc b/paddle/fluid/framework/details/scope_buffered_ssa_graph_executor.cc index a0fb20a6478a5a378495b919ff6ea85dba168b1e..06a454f4adac9a9110812f52af2676745656f168 100644 --- a/paddle/fluid/framework/details/scope_buffered_ssa_graph_executor.cc +++ b/paddle/fluid/framework/details/scope_buffered_ssa_graph_executor.cc @@ -65,11 +65,14 @@ void ScopeBufferedSSAGraphExecutor::DropLocalExeScopes() { for (auto p : places_) { platform::DeviceContextPool::Instance().Get(p)->Wait(); } + for (auto &scope : local_scopes_) { - auto &local_scope = - *scope->Var(details::kLocalExecScopeName)->GetMutable(); - scope->DeleteScope(local_scope); - VLOG(3) << "Drop local execution scope: " << local_scope; + auto *local_scope_var = scope->FindLocalVar(details::kLocalExecScopeName); + if (local_scope_var != nullptr) { + auto &local_scope = *local_scope_var->GetMutable(); + scope->DeleteScope(local_scope); + VLOG(3) << "Drop local execution scope: " << local_scope; + } } }