Skip to content

Commit ceef49a

Browse files
authored
Merge pull request #12969 from panyx0718/cherry-pick-fix-program-to-graph
Merge pull request #12780 from panyx0718/ir4
2 parents df11b40 + 45ab8f9 commit ceef49a

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

paddle/fluid/framework/ir/graph.cc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,15 @@ Graph::Graph(const ProgramDesc &program) : program_(program) {
117117
}
118118
// For output args, always create a new var.
119119
for (auto &each_var_name : op->OutputArgumentNames()) {
120-
ir::Node *var = CreateVarNode(all_vars.at(each_var_name));
120+
ir::Node *var = nullptr;
121+
if (all_vars.count(each_var_name) != 0) {
122+
var = CreateVarNode(all_vars.at(each_var_name));
123+
} else {
124+
// Operation output vars can be @EMPTY@. For example, while_grad
125+
// can have multi @EMPTY@ outputs with no VarDesc.
126+
// TODO(panyx0718): Add a test.
127+
var = CreateEmptyNode(each_var_name, ir::Node::Type::kVariable);
128+
}
121129
var_nodes[each_var_name].push_back(var);
122130
node->outputs.push_back(var);
123131
var->inputs.push_back(node);
@@ -208,7 +216,8 @@ Graph::Graph(const ProgramDesc &program) : program_(program) {
208216
// Add write after write dependence
209217
ir::Node *upstream_op =
210218
(*it_old)->inputs.empty() ? nullptr : (*it_old)->inputs[0];
211-
if (upstream_op) {
219+
// TODO(zcd): Add a test.
220+
if (upstream_op && upstream_op != write_op) {
212221
ir::Node *dep_var = CreateControlDepVar();
213222
write_op->inputs.push_back(dep_var);
214223
upstream_op->outputs.push_back(dep_var);

0 commit comments

Comments
 (0)