From 7e39134874fb8315ea941c661f32394eaf667c3b Mon Sep 17 00:00:00 2001 From: Eugene Zhulenev Date: Wed, 13 May 2020 15:05:25 -0700 Subject: [PATCH] [Grappler] Do not add control edges from placeholder inputs in function inlining PiperOrigin-RevId: 311412339 Change-Id: Ie40c0c44f1d6b42b53c259f8ad92d171577cd9c7 --- tensorflow/core/grappler/optimizers/function_optimizer.cc | 8 ++++++++ 1 file changed, 8 insertions(+) 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); }