From 521cded21531fa2f4aad5d6e36d7797c2c075ce6 Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Wed, 23 Mar 2022 23:11:07 +0800 Subject: [PATCH] [new-exec] gc skip var that is not tensor, selectedrows, tensorarray (#40859) --- .../framework/new_executor/interpretercore.cc | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/paddle/fluid/framework/new_executor/interpretercore.cc b/paddle/fluid/framework/new_executor/interpretercore.cc index 62e801b7695..25cb15d2cc8 100644 --- a/paddle/fluid/framework/new_executor/interpretercore.cc +++ b/paddle/fluid/framework/new_executor/interpretercore.cc @@ -234,10 +234,26 @@ void InterpreterCore::Convert( gc_check_input_list.erase(last, gc_check_input_list.end()); for (auto var_id : gc_check_input_list) { - vec_meta_info[var_id].var_ref_count_++; - instr.AddGCCheckVar(var_id); - VLOG(4) << "clear " << global_scope_->GetNameById(var_id) << " after " - << instr.OpBase()->Type(); + paddle::framework::Variable* var = global_scope_->Var(var_id); + if (var->IsType() || var->IsType() || + var->IsType()) { + vec_meta_info[var_id].var_ref_count_++; + // TODO(zhiqiu): not all var needs to be checked, var need to be checked + // only + // after the last_live_op. For example, + // b = op1(a) + // c = op2(a, b) + // in this case, a is the input of op1 and op2, we only need to check + // a after op2, because op2 always uses a after op1. + instr.AddGCCheckVar(var_id); + VLOG(4) << "clear " << global_scope_->GetNameById(var_id) << " after " + << instr.OpBase()->Type(); + } else { + VLOG(4) << "not clear " << global_scope_->GetNameById(var_id) + << " after " << instr.OpBase()->Type() + << " because its type is " + << framework::ToTypeName(var->Type()); + } } } -- GitLab