diff --git a/tensorflow/core/common_runtime/simple_graph_execution_state.cc b/tensorflow/core/common_runtime/simple_graph_execution_state.cc index 41e685bdc7f..2a974d18402 100644 --- a/tensorflow/core/common_runtime/simple_graph_execution_state.cc +++ b/tensorflow/core/common_runtime/simple_graph_execution_state.cc @@ -290,6 +290,10 @@ Status SimpleGraphExecutionState::InitBaseGraph( Status SimpleGraphExecutionState::OptimizeGraph( const BuildGraphOptions& options, std::unique_ptr* optimized_graph) { #ifndef IS_MOBILE_PLATFORM + if (session_options_->config.graph_options().place_pruned_graph()) { + return errors::InvalidArgument("Can't optimize a pruned graph"); + } + const RewriterConfig& rewrite_options = session_options_->config.graph_options().rewrite_options(); diff --git a/tensorflow/core/grappler/grappler_item.cc b/tensorflow/core/grappler/grappler_item.cc index d27ddb17f11..61b68b25f4f 100644 --- a/tensorflow/core/grappler/grappler_item.cc +++ b/tensorflow/core/grappler/grappler_item.cc @@ -26,6 +26,16 @@ limitations under the License. namespace tensorflow { namespace grappler { +GrapplerItem::GrapplerItem(const GrapplerItem& other, GraphDef&& graphDef) { + id = other.id; + feed = other.feed; + fetch = other.fetch; + init_ops = other.init_ops; + expected_init_time = other.expected_init_time; + queue_runners = other.queue_runners; + graph.Swap(&graphDef); +} + std::vector GrapplerItem::MainOpsFanin() const { return ComputeTransitiveFanin(graph, fetch); } diff --git a/tensorflow/core/grappler/grappler_item.h b/tensorflow/core/grappler/grappler_item.h index 1e7a9dfaf5d..4159b2bfba2 100644 --- a/tensorflow/core/grappler/grappler_item.h +++ b/tensorflow/core/grappler/grappler_item.h @@ -34,6 +34,9 @@ namespace grappler { // nodes, and potentially a set of nodes to feed. // TODO(volunteer_needed): turn this struct into a class. struct GrapplerItem { + GrapplerItem() {} + GrapplerItem(const GrapplerItem& other, GraphDef&& graphDef); + string id; // A unique id for this item // Inputs diff --git a/tensorflow/core/grappler/optimizers/meta_optimizer.cc b/tensorflow/core/grappler/optimizers/meta_optimizer.cc index 1cd341b6276..01921f368de 100644 --- a/tensorflow/core/grappler/optimizers/meta_optimizer.cc +++ b/tensorflow/core/grappler/optimizers/meta_optimizer.cc @@ -103,8 +103,7 @@ Status MetaOptimizer::Optimize(Cluster* cluster, const GrapplerItem& item, TF_RETURN_IF_ERROR(optimizer->Optimize(cluster, item, optimized_graph)); already_optimized = true; } else { - GrapplerItem optimized_item = item; - optimized_item.graph = *optimized_graph; + GrapplerItem optimized_item(item, std::move(*optimized_graph)); TF_RETURN_IF_ERROR( optimizer->Optimize(cluster, optimized_item, optimized_graph)); }