8000 Created a proto to configure the amount of graph rewriting taking place. · jbenjos/tensorflow@95cdab3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 95cdab3

Browse files
Created a proto to configure the amount of graph rewriting taking place.
Change: 150648084
1 parent be54889 commit 95cdab3

File tree

12 files changed

+41
-6
lines changed

12 files changed

+41
-6
lines changed

tensorflow/contrib/cmake/tf_core_framework.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ set(tf_proto_text_srcs
106106
"tensorflow/core/lib/core/error_codes.proto"
107107
"tensorflow/core/protobuf/config.proto"
108108
"tensorflow/core/protobuf/debug.proto"
109+
"tensorflow/core/protobuf/rewriter_config.proto"
109110
"tensorflow/core/protobuf/tensor_bundle.proto"
110111
"tensorflow/core/protobuf/saver.proto"
111112
"tensorflow/core/util/memmapped_file_system.proto"

tensorflow/contrib/makefile/proto_text_pb_cc_files.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ tensorflow/core/protobuf/queue_runner.pb.cc
88
tensorflow/core/protobuf/named_tensor.pb.cc
99
tensorflow/core/protobuf/meta_graph.pb.cc
1010
tensorflow/core/protobuf/config.pb.cc
11+
tensorflow/core/protobuf/rewriter_config.pb.cc
1112
tensorflow/core/protobuf/debug.pb.cc
1213
tensorflow/core/lib/core/error_codes.pb.cc
1314
tensorflow/core/framework/versions.pb.cc

tensorflow/contrib/makefile/proto_text_pb_h_files.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ tensorflow/core/protobuf/named_tensor.pb.h
99
tensorflow/core/protobuf/meta_graph.pb.h
1010
tensorflow/core/protobuf/config.pb.h
1111
tensorflow/core/protobuf/debug.pb.h
12+
tensorflow/core/protobuf/rewriter_config.pb.h
1213
tensorflow/core/protobuf/tensor_bundle.pb.h
1314
tensorflow/core/lib/core/error_codes.pb.h
1415
tensorflow/core/framework/versions.pb.h

tensorflow/contrib/makefile/tf_pb_text_files.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ tensorflow/core/util/memmapped_file_system.pb_text.cc
33
tensorflow/core/protobuf/saver.pb_text.cc
44
tensorflow/core/protobuf/config.pb_text.cc
55
tensorflow/core/protobuf/debug.pb_text.cc
6+
tensorflow/core/protobuf/rewriter_config.pb_text.cc
67
tensorflow/core/protobuf/tensor_bundle.pb_text.cc
78
tensorflow/core/lib/core/error_codes.pb_text.cc
89
tensorflow/core/framework/versions.pb_text.cc

tensorflow/contrib/makefile/tf_proto_files.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ tensorflow/core/protobuf/named_tensor.proto
99
tensorflow/core/protobuf/meta_graph.proto
1010
tensorflow/core/protobuf/config.proto
1111
tensorflow/core/protobuf/debug.proto
12+
tensorflow/core/protobuf/rewriter_config.proto
1213
tensorflow/core/protobuf/tensor_bundle.proto
1314
tensorflow/core/lib/core/error_codes.proto
1415
tensorflow/core/framework/versions.proto

tensorflow/core/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ CORE_PROTO_SRCS = [
155155
"protobuf/config.proto",
156156
"protobuf/debug.proto",
157157
"protobuf/queue_runner.proto",
158+
"protobuf/rewriter_config.proto",
158159
"protobuf/tensor_bundle.proto",
159160
"protobuf/saver.proto",
160161
"util/memmapped_file_system.proto",

tensorflow/core/common_runtime/simple_graph_execution_state.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,9 @@ Status SimpleGraphExecutionState::InitBaseGraph(
232232
const GraphDef* graph_def = &original_graph_def_;
233233

234234
GraphDef optimized_graph;
235-
if (false) {
235+
const RewriterConfig& rewrite_options =
236+
session_options_->config.graph_options().rewrite_options();
237+
if (grappler::MetaOptimizerEnabled(rewrite_options)) {
236238
// Adding this functionalty in steps. The first step is to make sure
237239
// we don't break dependencies. The second step will be to turn the
238240
// functionality on by default.
@@ -265,7 +267,7 @@ Status SimpleGraphExecutionState::InitBaseGraph(
265267
}
266268

267269
if (s.ok()) {
268-
s = grappler::RunMetaOptimizer(item, &optimized_graph);
270+
s = grappler::RunMetaOptimizer(item, rewrite_options, &optimized_graph);
269271
}
270272
if (s.ok()) {
271273
graph_def = &optimized_graph;

tensorflow/core/grappler/optimizers/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ cc_library(
6464
deps = [
6565
":layout_optimizer",
6666
"//tensorflow/core:lib",
67+
"//tensorflow/core:protos_all_cc",
6768
"//tensorflow/core/grappler:grappler_item",
6869
],
6970
)

tensorflow/core/grappler/optimizers/meta_optimizer.cc

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,23 @@ limitations under the License.
1515

1616
#include "tensorflow/core/grappler/optimizers/meta_optimizer.h"
1717
#include "tensorflow/core/grappler/optimizers/layout_optimizer.h"
18+
#include "tensorflow/core/lib/core/status.h"
1819

1920
namespace tensorflow {
2021
namespace grappler {
2122

22-
Status RunMetaOptimizer(const GrapplerItem& item, GraphDef* optimized_graph) {
23-
LayoutOptimizer layout_optimizer;
24-
return layout_optimizer.Optimize(nullptr, item, optimized_graph);
23+
bool MetaOptimizerEnabled(const RewriterConfig& cfg) {
24+
// We've only open sourced a single optimizer for now.
25+
return cfg.optimize_tensor_layout();
26+
}
27+
28+
Status RunMetaOptimizer(const GrapplerItem& item, const RewriterConfig& cfg,
29+
GraphDef* optimized_graph) {
30+
if (cfg.optimize_tensor_layout()) {
31+
LayoutOptimizer layout_optimizer;
32+
return layout_optimizer.Optimize(nullptr, item, optimized_graph);
33+
}
34+
return Status::OK();
2535
}
2636

2737
} // namespace grappler

tensorflow/core/grappler/optimizers/meta_optimizer.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@ limitations under the License.
1818

1919
#include "tensorflow/core/grappler/grappler_item.h"
2020
#include "tensorflow/core/lib/core/status.h"
21+
#include "tensorflow/core/protobuf/rewriter_config.pb.h"
2122

2223
namespace tensorflow {
2324
namespace grappler {
2425

25-
Status RunMetaOptimizer(const GrapplerItem& item, GraphDef* optimized_graph);
26+
bool MetaOptimizerEnabled(const RewriterConfig& cfg);
27+
28+
Status RunMetaOptimizer(const GrapplerItem& item, const RewriterConfig& cfg,
29+
GraphDef* optimized_graph);
2630

2731
} // namespace grappler
2832
} // namespace tensorflow

0 commit comments

Comments
 (0)
0