未验证 提交 2b2e8b85 编写于 作者: A Aurelius84 提交者: GitHub

Fix persistable var is GC as unexpected (#36932)

* Fix persistable var is GC as unexpected

* polish code and rebase develop
上级 71d375bb
......@@ -502,11 +502,11 @@ void InterpreterCore::CheckGC(const Instruction& instr) {
for (auto var_id : instr.GCCheckVars()) {
bool is_ready =
atomic_var_ref[var_id]->fetch_sub(1, std::memory_order_relaxed) == 1;
if (is_ready && var_scope.VarDesc(var_id) &&
!var_scope.VarDesc(var_id)->Persistable()) {
gc_.Add(var_scope.Var(var_id), gc_event_.at(instr_id),
&instr.DeviceContext());
} else if (is_ready && var_scope.VarDesc(var_id) == nullptr) {
// ignore all persistable var while GC
if (var_scope.VarDesc(var_id) && var_scope.VarDesc(var_id)->Persistable()) {
continue;
}
if (is_ready) {
gc_.Add(var_scope.Var(var_id), gc_event_.at(instr_id),
&instr.DeviceContext());
}
......
......@@ -146,7 +146,7 @@ void build_variable_scope(const framework::ProgramDesc& pdesc,
if (nullptr == var_desc_tmp) {
VLOG(3) << "update var:" << var_name << " desc from nullptr into "
<< var_desc;
var_scope->VarMetaInfo(var_name).vardesc_ = var_desc;
var_scope->SetVarDesc(var_name, var_desc);
}
}
}
......
......@@ -564,6 +564,11 @@ class VariableScope : public ScopeBase {
vec_meta_info_.push_back(info);
}
void SetVarDesc(const std::string& name, framework::VarDesc* var_desc) {
CheckExist(name);
vec_meta_info_[VarId(name)].vardesc_ = var_desc;
}
paddle::framework::VarDesc* VarDesc(const std::string& name) const {
return VarDesc(VarId(name));
}
......@@ -573,10 +578,6 @@ class VariableScope : public ScopeBase {
return vec_meta_info_[id].vardesc_;
}
VariableMetaInfo& VarMetaInfo(const std::string& name) {
return vec_meta_info_[VarId(name)];
}
void CheckExist(int id) const {
PADDLE_ENFORCE_LT(id, var_list_.size(),
platform::errors::PreconditionNotMet(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册