aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/python/training/queue_runner_impl.py
diff options
context:
space:
mode:
authorGravatar Derek Murray <mrry@google.com>2017-04-10 16:27:56 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2017-04-10 17:45:05 -0700
commitc0095c97099213cac22c87dad59200194a6f4f48 (patch)
tree11471478585b299aeec4bd676a21aad078adb11e /tensorflow/python/training/queue_runner_impl.py
parentd34eec7ec3b604b9f34dc0fc262577719514fcde (diff)
Adds `tf.Session.make_callable()`.
This method returns a Python callable that has the same semantics as `tf.Session.run()`, but can cache some of the work that must be done to map Tensor-like objects to the arguments of the underlying C API function. The initial implementation is optimized for single-`Tensor` and single-`Operation` fetches, and delegates to `tf.Session.run()` for handling feeds. Since most queue runners use a single-`Operation` `run()` call, switch the `tf.train.QueueRunner` implementation to use `make_callable()` Using this new interface can improve the latency of small steps (measurements from my workstation): * The median time to fetch a 4-byte tensor decreases from 99us to 52us (-47us). * The median time to run a trivial op decreases from 80us to 31us (-49us). Change: 152757301
Diffstat (limited to 'tensorflow/python/training/queue_runner_impl.py')
-rw-r--r--tensorflow/python/training/queue_runner_impl.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/tensorflow/python/training/queue_runner_impl.py b/tensorflow/python/training/queue_runner_impl.py
index 3901470fbc..d713e222ae 100644
--- a/tensorflow/python/training/queue_runner_impl.py
+++ b/tensorflow/python/training/queue_runner_impl.py
@@ -227,11 +227,14 @@ class QueueRunner(object):
"""
decremented = False
try:
+ # Make a cached callable from the `enqueue_op` to decrease the
+ # Python overhead in the queue-runner loop.
+ enqueue_callable = sess.make_callable(enqueue_op)
while True:
if coord and coord.should_stop():
break
try:
- sess.run(enqueue_op)
+ enqueue_callable()
except self._queue_closed_exception_types: # pylint: disable=catching-non-exception
# This exception indicates that a queue was closed.
with self._lock: