提交 18718b6f 编写于 作者: B Benoit Steiner 提交者: TensorFlower Gardener

Misc grappler improvements:

 * Avoid copying optimized graphs since that takes time.
 * Avoid optimizing a pruned graph, since it's already been pruned there isn't much to gain

PiperOrigin-RevId: 163842122
上级 90abbf68
......@@ -290,6 +290,10 @@ Status SimpleGraphExecutionState::InitBaseGraph(
Status SimpleGraphExecutionState::OptimizeGraph(
const BuildGraphOptions& options, std::unique_ptr<Graph>* 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();
......
......@@ -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<const NodeDef*> GrapplerItem::MainOpsFanin() const {
return ComputeTransitiveFanin(graph, fetch);
}
......
......@@ -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
......
......@@ -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));
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册