未验证 提交 33653195 编写于 作者: L Leo Chen 提交者: GitHub

[new-exec] sync scope and variable_scope when init executor (#37445)

* sync scope and variable_scope when init executor

* set var_desc for new var
上级 30dbdbaa
......@@ -123,9 +123,10 @@ std::shared_ptr<OperatorBase> TransferLayout(const std::string& var_name,
auto var_type = var_scope->Var(var_name)->Type();
InitializeVariable(ptr, static_cast<proto::VarType::Type>(var_type));
VLOG(3) << "Create Variable " << var_name << " locally, which pointer is "
<< ptr << "Variable Type " << var_type;
var_scope->SetVarDesc(var_name, nullptr);
VLOG(3) << "Create Variable " << *new_var_name
<< " locally, which pointer is " << ptr << "Variable Type "
<< var_type;
var_scope->SetVarDesc(*new_var_name, nullptr);
// 2. Construct VariableNameMap
VariableNameMap in_name_map = {{"X", {var_name}}};
......@@ -156,9 +157,10 @@ std::shared_ptr<OperatorBase> TransferDtype(const std::string& var_name,
auto var_type = var_scope->Var(var_name)->Type();
InitializeVariable(ptr, static_cast<proto::VarType::Type>(var_type));
VLOG(3) << "Create Variable " << var_name << " locally, which pointer is "
<< ptr << "Variable Type " << var_type;
var_scope->SetVarDesc(var_name, nullptr);
VLOG(3) << "Create Variable " << *new_var_name
<< " locally, which pointer is " << ptr << "Variable Type "
<< var_type;
var_scope->SetVarDesc(*new_var_name, nullptr);
// 2. Construct VariableNameMap
VariableNameMap in_name_map = {{"X", {var_name}}};
......@@ -194,9 +196,10 @@ std::shared_ptr<OperatorBase> TransferDevice(const std::string& var_name,
auto var_type = var_scope->Var(var_name)->Type();
InitializeVariable(ptr, static_cast<proto::VarType::Type>(var_type));
VLOG(3) << "Create Variable " << var_name << " locally, which pointer is "
<< ptr << "Variable Type " << var_type;
var_scope->SetVarDesc(var_name, nullptr);
VLOG(3) << "Create Variable " << *new_var_name
<< " locally, which pointer is " << ptr << "Variable Type "
<< var_type;
var_scope->SetVarDesc(*new_var_name, nullptr);
// 2. Construct VariableNameMap
VariableNameMap in_name_map = {{"X", {var_name}}};
......
......@@ -24,23 +24,28 @@ StandaloneExecutor::StandaloneExecutor(const platform::Place& place,
startup_prog_(startup_prog),
main_prog_(main_prog),
global_scope_(VariableScope(scope)) {
// NOTE(zhiqiu): it is needed to sync thhe variables in scope to
// variable_scope,
// since the some variable only exists in startup program, e.g,
// lod_tensor_blocking_queue_0 used in dataloader.
// These variables may be created in scope during runing startup program with
// original executor.
if (scope) {
auto name_list = scope->LocalVarNames();
for (auto name : name_list) {
auto v = scope->Var(name);
if (!global_scope_.HasVar(name)) {
global_scope_.AddVar(name, *v);
}
}
}
// NOTE(zhiqiu): for startup_program, initialize scope and run once
// if startup_program is empty, the scope is initialize during first run
if (startup_prog.Block(0).AllOps().size() > 0) {
VLOG(4) << "Run startup program";
// init scope
BuildVariableScope(startup_prog, &global_scope_);
if (scope != nullptr) {
auto name_list = scope->LocalVarNames();
for (auto name : name_list) {
auto v = scope->Var(name);
if (!global_scope_.HasVar(name)) {
global_scope_.AddVar(name, *v);
}
}
}
std::vector<paddle::framework::OpFuncNode> vec_func_list;
// No need to use_local_scope for startup_program, its variables are
// persistable
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册