From f74237cd73c35b8a63d7981a190a302d0ebcd03f Mon Sep 17 00:00:00 2001 From: kangguangli Date: Mon, 8 May 2023 17:59:07 +0800 Subject: [PATCH] fix: newExe didnot gc transferred variable (#53545) --- .../new_executor/interpreter/interpreter_util.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/paddle/fluid/framework/new_executor/interpreter/interpreter_util.cc b/paddle/fluid/framework/new_executor/interpreter/interpreter_util.cc index 3e630c32278..99c1ba3d983 100644 --- a/paddle/fluid/framework/new_executor/interpreter/interpreter_util.cc +++ b/paddle/fluid/framework/new_executor/interpreter/interpreter_util.cc @@ -844,6 +844,22 @@ void BuildOpFuncList(const platform::Place& place, interpreter::LogDeviceMemoryStats(place); } } + + // in the unused_var_map, we did not record the variable who are created in + // ApplyDataTransform. So we erase these variables here. + std::deque>* garbages = + new std::deque>(); + for (const auto& transferred_var : var_scope->DataTransferAddedVars()) { + const auto& var_name = transferred_var.first; + auto* var = local_scope->FindVar(var_name); + if (var == nullptr) continue; + VLOG(6) << "Erase variable " << var_name; + if (var->IsType()) { + garbages->emplace_back( + var->GetMutable()->MoveMemoryHolder()); + } + } + delete garbages; } void BuildVariableScope(const framework::BlockDesc& block, -- GitLab