Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transfer block_id to CreateVarNode in multi_devices_graph_pass #44366

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions paddle/fluid/framework/ir/graph_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -579,27 +579,14 @@ void GraphToProgram(const Graph &graph,

VLOG(3) << "Graph to program need convert " << graph.SubGraphsSize()
<< " sub graph";

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

因可能存在子block与父block中原本就存在同名变量的情况,PR #44278 的修复方案不完备,在此PR中进行删除。

std::unordered_set<std::string> vars_in_root_block;
for (const proto::VarDesc &var : block->vars()) {
vars_in_root_block.insert(var.name());
}

for (size_t idx = 0; idx < graph.SubGraphsSize(); ++idx) {
// avoid kRootBlockIndex not 0
if (idx == kRootBlockIndex) continue;

block = program_pb.add_blocks();
block->set_idx(idx);
block->set_parent_idx(kRootBlockIndex);

Graph *subgraph = graph.GetSubGraph(idx);
subgraph->SetNotOwned<std::unordered_set<std::string>>(
kGraphToProgramVarsToRemove, &vars_in_root_block);

GraphToBlock(*subgraph, block, sort_kind);

subgraph->Erase(kGraphToProgramVarsToRemove);
GraphToBlock(*graph.GetSubGraph(idx), block, sort_kind);
}
} else {
GraphToBlock(graph, block, sort_kind);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,12 @@ details::VarHandle *CreateOrGetLatestVarHandle(ir::Graph *graph,
details::VarHandle *var = nullptr;
if (var_holder.empty()) {
if (node->Var()) {
var = new details::VarHandle(graph->CreateVarNode(node->Var()),
0,
place_offset,
node->Name(),
place);
var = new details::VarHandle(
graph->CreateVarNode(node->Var(), node->GetVarNodeBlockId()),
0,
place_offset,
node->Name(),
place);
} else {
var = new details::VarHandle(
graph->CreateEmptyNode(node->Name(), ir::Node::Type::kVariable),
Expand Down Expand Up @@ -376,7 +377,8 @@ void MultiDevSSAGraphBuilderBase::CreateOpHandleIOs(ir::Graph *result,
for (ir::Node *output : node->outputs) {
ir::Node *new_node = nullptr;
if (output->Var()) {
new_node = result->CreateVarNode(output->Var());
new_node =
result->CreateVarNode(output->Var(), output->GetVarNodeBlockId());
} else {
new_node =
result->CreateEmptyNode(output->Name(), ir::Node::Type::kVariable);
Expand Down Expand Up @@ -696,7 +698,8 @@ void MultiDevSSAGraphBuilderBase::CreateScaleLossGradOp(

CreateOpOutput(result,
op_handle,
result->CreateVarNode(out_var_node->Var()),
result->CreateVarNode(out_var_node->Var(),
out_var_node->GetVarNodeBlockId()),
places_[i],
i);
}
Expand Down Expand Up @@ -1225,7 +1228,8 @@ int DistSSAGraphBuilder::CreateRPCOp(ir::Graph *result, ir::Node *node) const {
p = places_[outvar_dev_id];
ir::Node *new_node = nullptr;
if (output->Var()) {
new_node = result->CreateVarNode(output->Var());
new_node =
result->CreateVarNode(output->Var(), output->GetVarNodeBlockId());
} else {
new_node =
result->CreateEmptyNode(output->Name(), ir::Node::Type::kVariable);
Expand Down