diff --git a/tensorflow/core/grappler/optimizers/function_optimizer.cc b/tensorflow/core/grappler/optimizers/function_optimizer.cc index eaccff3b127..ed3af955c13 100644 --- a/tensorflow/core/grappler/optimizers/function_optimizer.cc +++ b/tensorflow/core/grappler/optimizers/function_optimizer.cc @@ -1122,7 +1122,15 @@ void AddStrictInputSemantics(Node* caller, Graph* g) { VLOG(3) << "Add control edges from all data inputs to enforce strict " "semantics with regard to function inputs"; + + // Do not add control edges from placeholders, because it will prevent + // pruning, and they can't produce any side effects anyway. + const auto is_placeholder = [](const Node* node) -> bool { + return node->type_string() == "Placeholder"; + }; + for (const Node* node : data_inputs) { + if (is_placeholder(node)) continue; g->AddControlEdge(g->FindNodeId(node->id()), caller, /*allow_duplicates=*/true); }