aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/contrib/tfprof
diff options
context:
space:
mode:
authorGravatar A. Unique TensorFlower <gardener@tensorflow.org>2016-11-09 18:16:12 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2016-11-09 18:23:41 -0800
commitf5bd8e1c34a0ee6f6067119744b4b1c8fd9077b3 (patch)
treec8e41475a9a0eb9a6444bea8ac5b90626d300c1f /tensorflow/contrib/tfprof
parente01b641fc26a39ae62dc6a0a1379571e5857d8c8 (diff)
Improve tfprof doc. Support binary GraphDef.
Change: 138711410
Diffstat (limited to 'tensorflow/contrib/tfprof')
-rw-r--r--tensorflow/contrib/tfprof/README.md72
-rw-r--r--tensorflow/contrib/tfprof/python/tools/tfprof/tfprof_logger.py7
2 files changed, 67 insertions, 12 deletions
diff --git a/tensorflow/contrib/tfprof/README.md b/tensorflow/contrib/tfprof/README.md
index e103cb2121..c7ff4a2921 100644
--- a/tensorflow/contrib/tfprof/README.md
+++ b/tensorflow/contrib/tfprof/README.md
@@ -1,17 +1,11 @@
# tfprof: A Profiling Tool for TensorFlow Models
-Internal User Please Use: go/tfprof
+# Full Docment in tensorflow/tools/tfprof/README.md
Author: Xin Pan (xpan@google.com, github: panyx0718)
Consultants: Jon Shlens, Pete Warden
-
-## Introduction
-
-tfprof is a profiling tool for TensorFlow that analyzes model architectures
-and measures system performance.
-
###Major Features
1. Measure model parameters, float operations, tensor shapes.
@@ -20,9 +14,63 @@ and measures system performance.
4. Explore model based on name scope or graph structure.
5. Selectively grouping/filtering/accounting/ordering ops.
-tfprof can be used as CommandLine Interface (CLI) and Python API.
-CLI locates in tensorflow/tools/tfprof.
-Python API locates in tensorflow/contrib/tfprof.
-Tutorial locates in tensorflow/tools/tfprof/README.md
+tfprof can be used as Python API, Interactive CLI and One-shot Script.
+
+## Python API Tutorials
+
+tfprof is part of TensorFlow core. Simply ```import tensorflow as tf```.
+
+### Examine the shapes and sizes of all trainiable Variables.
+```python
+# Print trainable variable parameter statistics to stdout.
+param_stats = tf.contrib.tfprof.model_analyzer.print_model_analysis(
+ tf.get_default_graph(),
+ tfprof_options=tf.contrib.tfprof.model_analyzer.
+ TRAINABLE_VARS_PARAMS_STAT_OPTIONS)
+
+# param_stats is tensorflow.tfprof.TFProfNode proto. It organize the statistics
+# of each graph node in tree scructure. Let's print the root below.
+sys.stdout.write('total_params: %d\n' % param_stats.total_parameters)
+```
+
+### Examine the number of floating point operations
+``` python
+# Print to stdout an analysis of the number of floating point operations in the
+# model broken down by individual operations.
+#
+# Note: Only Ops with RegisterStatistics('flops') defined have flop stats. It
+# also requires complete shape information. It is common that shape is unknown
+# statically. To complete the shape, provide run-time shape information with
+# tf.RunMetadata to the API (See next example on how to provide RunMetadata).
+tf.contrib.tfprof.model_analyzer.print_model_analysis(
+ tf.get_default_graph(),
+ tfprof_options=tf.contrib.tfprof.model_analyzer.FLOAT_OPS_OPTIONS)
+```
+
+### Examine the timing and memory usage
+You will first need to run the following set up in your model in order to
+compute the memory and timing statistics.
+
+```python
+# Generate the meta information for the model that contains the memory usage
+# and timing information.
+run_metadata = tf.RunMetadata()
+with tf.Session() as sess:
+ _ = sess.run(train_op,
+ options=tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE),
+ run_metadata=run_metadata)
+```
+
+Finally, you may run `print_model_analysis` to explore the timing and memory
+demands of the model.
+
+``` python
+# Print to stdout an analysis of the memory usage and the timing information
+# from running the graph broken down by operations.
+tf.contrib.tfprof.model_analyzer.print_model_analysis(
+ tf.get_default_graph(),
+ run_meta=run_metadata,
+ tfprof_options=tf.contrib.tfprof.model_analyzer.PRINT_ALL_TIMING_MEMORY)
+```
-Enjoy! \ No newline at end of file
+Users can change ```tfprof_options``` to fully leverage tfprof's power.
diff --git a/tensorflow/contrib/tfprof/python/tools/tfprof/tfprof_logger.py b/tensorflow/contrib/tfprof/python/tools/tfprof/tfprof_logger.py
index 1f710bc970..a89d966939 100644
--- a/tensorflow/contrib/tfprof/python/tools/tfprof/tfprof_logger.py
+++ b/tensorflow/contrib/tfprof/python/tools/tfprof/tfprof_logger.py
@@ -71,6 +71,7 @@ def _get_logged_ops(graph, run_meta=None):
if run_meta:
graph = _fill_missing_graph_shape(graph, run_meta)
+ op_missing_shape = 0
logged_ops = {}
graph_def = graph.as_graph_def()
for node in graph_def.node:
@@ -78,6 +79,7 @@ def _get_logged_ops(graph, run_meta=None):
stats = ops.get_stats_for_node_def(graph, node, REGISTERED_FLOP_STATS)
except ValueError:
# Catch Exception When shape is incomplete. Skip it.
+ op_missing_shape += 1
stats = None
if not stats or not stats.value:
@@ -96,6 +98,11 @@ def _get_logged_ops(graph, run_meta=None):
logged_ops[entry.name] = entry
else:
logged_ops[v.op.name].types.append(TRAINABLE_VARIABLES)
+ if op_missing_shape > 0 and not run_meta:
+ sys.stderr.write(
+ '%d ops no flops stats due to incomplete shapes. '
+ 'Consider passing run_meta to use run_time shapes.\n' %
+ op_missing_shape)
return logged_ops