Skip to content

Commit

Permalink
Benchmarks with backprop enabled (and removes overhead).
Browse files Browse the repository at this point in the history
Before:
np.array([[3]])                          took 1.50us (30000 iterations)
Tensor([[3]])                            took 16.30us (30000 iterations)
MatMul [2, 2]: np.dot                         took 0.61us (30000 iterations)
MatMul [2, 2]: tf.matmul                      took 60.53us (30000 iterations)
MatMul [2, 2]: gen_math_ops.mat_mul           took 25.72us (30000 iterations)
MatMul [2, 2]: TFE_Py_Execute                 took 2.82us (30000 iterations)
MatMul [2, 2]: defun(tf.matmul)               took 45.70us (30000 iterations)
MatMul [100, 784]: np.dot                         took 383.32us (1000 iterations)
MatMul [100, 784]: tf.matmul                      took 350.35us (1000 iterations)
MatMul [100, 784]: gen_math_ops.mat_mul           took 315.97us (1000 iterations)
MatMul [100, 784]: TFE_Py_Execute                 took 249.42us (1000 iterations)
MatMul [100, 784]: defun(tf.matmul)               took 280.95us (1000 iterations)

If backprop is enabled:
np.array([[3]])                          took 0.83us (30000 iterations)
Tensor([[3]])                            took 15.21us (30000 iterations)
MatMul [2, 2]: np.dot                         took 0.63us (30000 iterations)
MatMul [2, 2]: tf.matmul                      took 76.31us (30000 iterations)
MatMul [2, 2]: gen_math_ops.mat_mul           took 38.66us (30000 iterations)
MatMul [2, 2]: TFE_Py_Execute                 took 2.31us (30000 iterations)
MatMul [2, 2]: defun(tf.matmul)               took 51.96us (30000 iterations)
MatMul [100, 784]: np.dot                         took 378.34us (1000 iterations)
MatMul [100, 784]: tf.matmul                      took 352.09us (1000 iterations)
MatMul [100, 784]: gen_math_ops.mat_mul           took 364.28us (1000 iterations)
MatMul [100, 784]: TFE_Py_Execute                 took 350.68us (1000 iterations)
MatMul [100, 784]: defun(tf.matmul)               took 377.19us (1000 iterations)

After:
np.array([[3]])                          took 0.86us (30000 iterations)
Tensor([[3]])                            took 15.19us (30000 iterations)
MatMul [2, 2]: np.dot                         took 0.60us (30000 iterations)
MatMul [2, 2]: tf.matmul                      took 64.51us (30000 iterations)
MatMul [2, 2]: gen_math_ops.mat_mul           took 28.34us (30000 iterations)
MatMul [2, 2]: TFE_Py_Execute                 took 2.38us (30000 iterations)
MatMul [2, 2]: defun(tf.matmul)               took 48.50us (30000 iterations)
MatMul [100, 784]: np.dot                         took 475.27us (1000 iterations)
MatMul [100, 784]: tf.matmul                      took 399.50us (1000 iterations)
MatMul [100, 784]: gen_math_ops.mat_mul           took 307.80us (1000 iterations)
MatMul [100, 784]: TFE_Py_Execute                 took 272.83us (1000 iterations)
MatMul [100, 784]: defun(tf.matmul)               took 350.06us (1000 iterations)
PiperOrigin-RevId: 165765641
  • Loading branch information
alextp authored and tensorflower-gardener committed Aug 18, 2017
1 parent d902bab commit d685bbc
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions tensorflow/python/eager/BUILD
Expand Up @@ -307,6 +307,7 @@ py_test(
srcs = ["benchmarks_test.py"],
srcs_version = "PY2AND3",
deps = [
":backprop",
":context",
":function",
":tensor",
Expand Down
2 changes: 2 additions & 0 deletions tensorflow/python/eager/backprop.py
Expand Up @@ -134,6 +134,8 @@ def _record_gradient(op_name, inputs, attrs, results, name):
Raises:
An exception on error.
"""
if not any(ag_core.isnode(x) for x in inputs):
return results
num_outputs = len(results)
if num_outputs == 0:
return results
Expand Down
1 change: 1 addition & 0 deletions tensorflow/python/eager/benchmarks_test.py
Expand Up @@ -33,6 +33,7 @@
from six.moves import xrange # pylint: disable=redefined-builtin

from tensorflow.python import pywrap_tensorflow
from tensorflow.python.eager import backprop # pylint: disable=unused-import
from tensorflow.python.eager import context
from tensorflow.python.eager import function
from tensorflow.python.eager import tensor
Expand Down

0 comments on commit d685bbc

Please sign in to comment.