Skip to content

Commit 36c402b

Browse files
[Paddle Inference]Fix transfer_layout_elim_pass.cc bug (#60076) (#60096)
[Paddle Inference]Fix transfer_layout_elim_pass.cc bug (#60076)
1 parent fbba94f commit 36c402b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

paddle/fluid/framework/ir/transfer_layout_elim_pass.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ void TransferLayoutElimPass::PutTranferlayoutAfterOp(
120120
auto *new_transfer_layout_node =
121121
graph->CreateOpNode(&new_transfer_layout_desc);
122122

123-
for (auto other_op : var2->outputs) {
123+
// must use a tmp variable var_out, because var2->outputs will be changed in
124+
// loop.
125+
auto var_out = var2->outputs;
126+
for (auto other_op : var_out) {
124127
IR_NODE_UNLINK(var2, other_op);
125128
other_op->Op()->RenameInput(var2->Name(), var2_dot_name);
126129
IR_NODE_LINK_TO(var2_dot, other_op);
@@ -244,6 +247,9 @@ void TransferLayoutElimPass::ApplyImpl(ir::Graph *graph) const {
244247
return "";
245248
};
246249

250+
int move_down_count = 0;
251+
int elim_count = 0;
252+
247253
while (true) {
248254
auto op_node_sorted = framework::ir::TopologyVarientSort(
249255
*graph, static_cast<framework::ir::SortKind>(0));
@@ -309,6 +315,7 @@ void TransferLayoutElimPass::ApplyImpl(ir::Graph *graph) const {
309315
}
310316
op_node->Op()->SetAttr("axis", modify_axis);
311317
modify = true;
318+
move_down_count++;
312319
break;
313320
}
314321
if (is_pool_like_op) {
@@ -318,21 +325,26 @@ void TransferLayoutElimPass::ApplyImpl(ir::Graph *graph) const {
318325
transfer_format(
319326
op_node->Op()->GetAttrIfExists<std::string>("data_format")));
320327
modify = true;
328+
move_down_count++;
321329
break;
322330
}
323331
if (is_act_like_op) {
324332
PutTranferlayoutAfterOp(op_node, graph, nullptr);
325333
modify = true;
334+
move_down_count++;
326335
break;
327336
}
328337
if (is_elim_op) {
329338
ElimTwoTranferlayout(op_node, graph, &modify);
339+
elim_count++;
330340
break;
331341
}
332342
}
333343
}
334344
if (!modify) break;
335345
}
346+
LOG(INFO) << "move down " << move_down_count << " transfer_layout";
347+
LOG(INFO) << "eliminate " << elim_count << " pair of transfer_layout";
336348
}
337349

338350
} // namespace ir

0 commit comments

Comments
 (0)