From b052c51374f558c25a29c70918d79205dfec808b Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Mon, 8 Oct 2018 13:46:12 -0700 Subject: Add tf.BenchmarkConfig that returns a session config appropriate for benchmarking. At the moment, it returns a default config with only Grappler dependency optimizer disabled. Many benchmarks wrap the subgraph they want to time in control_flow_ops.group() to avoid including the overhead of copying the output back to the Python client in the measurement. In the graph, this only adds a control dependency between the subgraph output and the fetch node, which in turn (often) causes the dependency optimizer to turn all nodes in the graph into no-ops. PiperOrigin-RevId: 216242463 --- tensorflow/python/platform/benchmark.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tensorflow/python/platform') diff --git a/tensorflow/python/platform/benchmark.py b/tensorflow/python/platform/benchmark.py index fa17b17d10..4f7abb311a 100644 --- a/tensorflow/python/platform/benchmark.py +++ b/tensorflow/python/platform/benchmark.py @@ -27,6 +27,7 @@ import time import six from tensorflow.core.protobuf import config_pb2 +from tensorflow.core.protobuf import rewriter_config_pb2 from tensorflow.core.util import test_log_pb2 from tensorflow.python.client import timeline from tensorflow.python.platform import app @@ -182,6 +183,19 @@ class Benchmark(six.with_metaclass(_BenchmarkRegistrar, object)): throughput=throughput, extras=extras) +@tf_export("test.benchmark_config") +def benchmark_config(): + """Returns a tf.ConfigProto for disabling the dependency optimizer. + + Returns: + A TensorFlow ConfigProto object. + """ + config = config_pb2.ConfigProto() + config.graph_options.rewrite_options.dependency_optimization = ( + rewriter_config_pb2.RewriterConfig.OFF) + return config + + @tf_export("test.Benchmark") class TensorFlowBenchmark(Benchmark): """Abstract class that provides helpers for TensorFlow benchmarks.""" -- cgit v1.2.3