aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/contrib/tfprof
diff options
context:
space:
mode:
authorGravatar Justine Tunney <jart@google.com>2016-12-29 22:46:24 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2016-12-29 23:06:59 -0800
commite121667dc609de978a223c56ee906368d2c4ceef (patch)
tree7d4e1f1e1b4fd469487872c0cd34ddace5ac570c /tensorflow/contrib/tfprof
parent7815fcba7767aa1eb3196c5861e174f8b3c43bab (diff)
Remove so many more hourglass imports
Change: 143230429
Diffstat (limited to 'tensorflow/contrib/tfprof')
-rw-r--r--tensorflow/contrib/tfprof/python/tools/tfprof/BUILD28
-rw-r--r--tensorflow/contrib/tfprof/python/tools/tfprof/model_analyzer_test.py72
-rw-r--r--tensorflow/contrib/tfprof/python/tools/tfprof/print_model_analysis_test.py38
-rw-r--r--tensorflow/contrib/tfprof/python/tools/tfprof/tfprof_logger.py17
-rw-r--r--tensorflow/contrib/tfprof/python/tools/tfprof/tfprof_logger_test.py63
5 files changed, 148 insertions, 70 deletions
diff --git a/tensorflow/contrib/tfprof/python/tools/tfprof/BUILD b/tensorflow/contrib/tfprof/python/tools/tfprof/BUILD
index a9de4f181e..e62b2671eb 100644
--- a/tensorflow/contrib/tfprof/python/tools/tfprof/BUILD
+++ b/tensorflow/contrib/tfprof/python/tools/tfprof/BUILD
@@ -22,7 +22,16 @@ py_test(
srcs_version = "PY2AND3",
deps = [
":model_analyzer",
- "//tensorflow:tensorflow_py",
+ "//tensorflow/core:protos_all_py",
+ "//tensorflow/python:array_ops",
+ "//tensorflow/python:client",
+ "//tensorflow/python:client_testlib",
+ "//tensorflow/python:framework_for_generated_wrappers",
+ "//tensorflow/python:init_ops",
+ "//tensorflow/python:nn_ops",
+ "//tensorflow/python:platform",
+ "//tensorflow/python:variable_scope",
+ "//tensorflow/python:variables",
],
)
@@ -32,6 +41,7 @@ py_library(
srcs_version = "PY2AND3",
deps = [
"//tensorflow/python:framework_for_generated_wrappers",
+ "//tensorflow/python:platform",
"//tensorflow/tools/tfprof:protos_all_py",
"@six_archive//:six",
],
@@ -42,7 +52,13 @@ tf_py_test(
srcs = ["tfprof_logger_test.py"],
additional_deps = [
":tfprof_logger",
- "//tensorflow:tensorflow_py",
+ "//tensorflow/contrib/copy_graph:copy_graph_py",
+ "//tensorflow/core:protos_all_py",
+ "//tensorflow/python:array_ops",
+ "//tensorflow/python:client",
+ "//tensorflow/python:client_testlib",
+ "//tensorflow/python:framework_for_generated_wrappers",
+ "//tensorflow/python:math_ops",
"//tensorflow/tools/tfprof:protos_all_py",
],
)
@@ -67,9 +83,15 @@ py_test(
srcs_version = "PY2AND3",
deps = [
":pywrap_tensorflow_print_model_analysis_lib",
- "//tensorflow:tensorflow_py",
+ "//tensorflow/python:array_ops",
+ "//tensorflow/python:client",
+ "//tensorflow/python:client_testlib",
+ "//tensorflow/python:framework_for_generated_wrappers",
"//tensorflow/python:framework_test_lib",
+ "//tensorflow/python:init_ops",
+ "//tensorflow/python:nn_ops",
"//tensorflow/python:platform_test",
+ "//tensorflow/python:variable_scope",
"//tensorflow/tools/tfprof:protos_all_py",
],
)
diff --git a/tensorflow/contrib/tfprof/python/tools/tfprof/model_analyzer_test.py b/tensorflow/contrib/tfprof/python/tools/tfprof/model_analyzer_test.py
index 03f2e0df86..441c19b468 100644
--- a/tensorflow/contrib/tfprof/python/tools/tfprof/model_analyzer_test.py
+++ b/tensorflow/contrib/tfprof/python/tools/tfprof/model_analyzer_test.py
@@ -12,67 +12,87 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
+
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
+import sys
+
+# TODO: #6568 Remove this hack that makes dlopen() not crash.
+if hasattr(sys, 'getdlopenflags') and hasattr(sys, 'setdlopenflags'):
+ import ctypes
+ sys.setdlopenflags(sys.getdlopenflags() | ctypes.RTLD_GLOBAL)
+
+from tensorflow.core.protobuf import config_pb2
+from tensorflow.python.client import session
+from tensorflow.python.framework import dtypes
+from tensorflow.python.framework import ops
+from tensorflow.python.ops import array_ops
+from tensorflow.python.ops import init_ops
+from tensorflow.python.ops import nn_ops
+from tensorflow.python.ops import variable_scope
+from tensorflow.python.ops import variables
+from tensorflow.python.platform import gfile
+from tensorflow.python.platform import test
-import tensorflow as tf
+# XXX: this depends on pywrap_tensorflow and must come later
+from tensorflow.contrib.tfprof.python.tools.tfprof import model_analyzer
-class PrintModelAnalysisTest(tf.test.TestCase):
+class PrintModelAnalysisTest(test.TestCase):
def _BuildSmallModel(self):
- image = tf.zeros([2, 6, 6, 3])
- kernel = tf.get_variable(
+ image = array_ops.zeros([2, 6, 6, 3])
+ kernel = variable_scope.get_variable(
'DW', [3, 3, 3, 6],
- tf.float32,
- initializer=tf.random_normal_initializer(stddev=0.001))
- x = tf.nn.conv2d(image, kernel, [1, 2, 2, 1], padding='SAME')
- kernel = tf.get_variable(
+ dtypes.float32,
+ initializer=init_ops.random_normal_initializer(stddev=0.001))
+ x = nn_ops.conv2d(image, kernel, [1, 2, 2, 1], padding='SAME')
+ kernel = variable_scope.get_variable(
'DW2', [2, 2, 6, 12],
- tf.float32,
- initializer=tf.random_normal_initializer(stddev=0.001))
- x = tf.nn.conv2d(x, kernel, [1, 2, 2, 1], padding='SAME')
+ dtypes.float32,
+ initializer=init_ops.random_normal_initializer(stddev=0.001))
+ x = nn_ops.conv2d(x, kernel, [1, 2, 2, 1], padding='SAME')
return x
def testDumpToFile(self):
- opts = tf.contrib.tfprof.model_analyzer.TRAINABLE_VARS_PARAMS_STAT_OPTIONS
- opts['dump_to_file'] = os.path.join(tf.test.get_temp_dir(), 'dump')
+ opts = model_analyzer.TRAINABLE_VARS_PARAMS_STAT_OPTIONS
+ opts['dump_to_file'] = os.path.join(test.get_temp_dir(), 'dump')
- with tf.Session() as sess, tf.device('/cpu:0'):
+ with session.Session() as sess, ops.device('/cpu:0'):
_ = self._BuildSmallModel()
- tf.contrib.tfprof.model_analyzer.print_model_analysis(
- sess.graph, tfprof_options=opts)
+ model_analyzer.print_model_analysis(sess.graph, tfprof_options=opts)
- with tf.gfile.Open(opts['dump_to_file'], 'r') as f:
+ with gfile.Open(opts['dump_to_file'], 'r') as f:
self.assertEqual(u'_TFProfRoot (--/450 params)\n'
' DW (3x3x3x6, 162/162 params)\n'
' DW2 (2x2x6x12, 288/288 params)\n',
f.read().decode('utf-8'))
def testSelectEverything(self):
- opts = tf.contrib.tfprof.model_analyzer.TRAINABLE_VARS_PARAMS_STAT_OPTIONS
- opts['dump_to_file'] = os.path.join(tf.test.get_temp_dir(), 'dump')
+ opts = model_analyzer.TRAINABLE_VARS_PARAMS_STAT_OPTIONS
+ opts['dump_to_file'] = os.path.join(test.get_temp_dir(), 'dump')
opts['account_type_regexes'] = ['.*']
opts['select'] = [
'bytes', 'params', 'float_ops', 'num_hidden_ops', 'device', 'op_types'
]
- with tf.Session() as sess, tf.device('/cpu:0'):
+ with session.Session() as sess, ops.device('/cpu:0'):
x = self._BuildSmallModel()
- sess.run(tf.global_variables_initializer())
- run_meta = tf.RunMetadata()
+ sess.run(variables.global_variables_initializer())
+ run_meta = config_pb2.RunMetadata()
_ = sess.run(x,
- options=tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE),
+ options=config_pb2.RunOptions(
+ trace_level=config_pb2.RunOptions.FULL_TRACE),
run_metadata=run_meta)
- tf.contrib.tfprof.model_analyzer.print_model_analysis(
+ model_analyzer.print_model_analysis(
sess.graph, run_meta, tfprof_options=opts)
- with tf.gfile.Open(opts['dump_to_file'], 'r') as f:
+ with gfile.Open(opts['dump_to_file'], 'r') as f:
# pylint: disable=line-too-long
self.assertEqual(
'_TFProfRoot (0/450 params, 0/10.44k flops, 0B/5.28KB, _kTFScopeParent)\n Conv2D (0/0 params, 5.83k/5.83k flops, 432B/432B, /job:localhost/replica:0/task:0/cpu:0, /job:localhost/replica:0/task:0/cpu:0|Conv2D)\n Conv2D_1 (0/0 params, 4.61k/4.61k flops, 384B/384B, /job:localhost/replica:0/task:0/cpu:0, /job:localhost/replica:0/task:0/cpu:0|Conv2D)\n DW (3x3x3x6, 162/162 params, 0/0 flops, 648B/1.30KB, /job:localhost/replica:0/task:0/cpu:0, /job:localhost/replica:0/task:0/cpu:0|VariableV2|_trainable_variables)\n DW/Assign (0/0 params, 0/0 flops, 0B/0B, /device:CPU:0, /device:CPU:0|Assign)\n DW/Initializer (0/0 params, 0/0 flops, 0B/0B, _kTFScopeParent)\n DW/Initializer/random_normal (0/0 params, 0/0 flops, 0B/0B, Add)\n DW/Initializer/random_normal/RandomStandardNormal (0/0 params, 0/0 flops, 0B/0B, RandomStandardNormal)\n DW/Initializer/random_normal/mean (0/0 params, 0/0 flops, 0B/0B, Const)\n DW/Initializer/random_normal/mul (0/0 params, 0/0 flops, 0B/0B, Mul)\n DW/Initializer/random_normal/shape (0/0 params, 0/0 flops, 0B/0B, Const)\n DW/Initializer/random_normal/stddev (0/0 params, 0/0 flops, 0B/0B, Const)\n DW/read (0/0 params, 0/0 flops, 648B/648B, /job:localhost/replica:0/task:0/cpu:0, /job:localhost/replica:0/task:0/cpu:0|Identity)\n DW2 (2x2x6x12, 288/288 params, 0/0 flops, 1.15KB/2.30KB, /job:localhost/replica:0/task:0/cpu:0, /job:localhost/replica:0/task:0/cpu:0|VariableV2|_trainable_variables)\n DW2/Assign (0/0 params, 0/0 flops, 0B/0B, /device:CPU:0, /device:CPU:0|Assign)\n DW2/Initializer (0/0 params, 0/0 flops, 0B/0B, _kTFScopeParent)\n DW2/Initializer/random_normal (0/0 params, 0/0 flops, 0B/0B, Add)\n DW2/Initializer/random_normal/RandomStandardNormal (0/0 params, 0/0 flops, 0B/0B, RandomStandardNormal)\n DW2/Initializer/random_normal/mean (0/0 params, 0/0 flops, 0B/0B, Const)\n DW2/Initializer/random_normal/mul (0/0 params, 0/0 flops, 0B/0B, Mul)\n DW2/Initializer/random_normal/shape (0/0 params, 0/0 flops, 0B/0B, Const)\n DW2/Initializer/random_normal/stddev (0/0 params, 0/0 flops, 0B/0B, Const)\n DW2/read (0/0 params, 0/0 flops, 1.15KB/1.15KB, /job:localhost/replica:0/task:0/cpu:0, /job:localhost/replica:0/task:0/cpu:0|Identity)\n init (0/0 params, 0/0 flops, 0B/0B, /device:CPU:0, /device:CPU:0|NoOp)\n zeros (0/0 params, 0/0 flops, 864B/864B, /job:localhost/replica:0/task:0/cpu:0, /job:localhost/replica:0/task:0/cpu:0|Const)\n',
@@ -81,4 +101,4 @@ class PrintModelAnalysisTest(tf.test.TestCase):
if __name__ == '__main__':
- tf.test.main()
+ test.main()
diff --git a/tensorflow/contrib/tfprof/python/tools/tfprof/print_model_analysis_test.py b/tensorflow/contrib/tfprof/python/tools/tfprof/print_model_analysis_test.py
index 46bdf2dcb2..07ed324d7c 100644
--- a/tensorflow/contrib/tfprof/python/tools/tfprof/print_model_analysis_test.py
+++ b/tensorflow/contrib/tfprof/python/tools/tfprof/print_model_analysis_test.py
@@ -13,16 +13,34 @@
# limitations under the License.
# ==============================================================================
"""print_model_analysis test."""
+
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
-import tensorflow as tf
+import sys
+
+# TODO: #6568 Remove this hack that makes dlopen() not crash.
+if hasattr(sys, 'getdlopenflags') and hasattr(sys, 'setdlopenflags'):
+ import ctypes
+ sys.setdlopenflags(sys.getdlopenflags() | ctypes.RTLD_GLOBAL)
+
from google.protobuf import text_format
-from tensorflow.contrib.tfprof.python.tools.tfprof import pywrap_tensorflow_print_model_analysis_lib as print_mdl
+
+from tensorflow.python.client import session
+from tensorflow.python.framework import dtypes
+from tensorflow.python.framework import ops
+from tensorflow.python.ops import array_ops
+from tensorflow.python.ops import init_ops
+from tensorflow.python.ops import nn_ops
+from tensorflow.python.ops import variable_scope
+from tensorflow.python.platform import test
from tensorflow.tools.tfprof import tfprof_options_pb2
from tensorflow.tools.tfprof import tfprof_output_pb2
+# XXX: this depends on pywrap_tensorflow and must come later
+from tensorflow.contrib.tfprof.python.tools.tfprof import pywrap_tensorflow_print_model_analysis_lib as print_mdl
+
# pylint: disable=bad-whitespace
# pylint: disable=bad-continuation
TEST_OPTIONS = {
@@ -47,15 +65,15 @@ TEST_OPTIONS = {
# pylint: enable=bad-continuation
-class PrintModelAnalysisTest(tf.test.TestCase):
+class PrintModelAnalysisTest(test.TestCase):
def _BuildSmallModel(self):
- image = tf.zeros([2, 6, 6, 3])
- kernel = tf.get_variable(
+ image = array_ops.zeros([2, 6, 6, 3])
+ kernel = variable_scope.get_variable(
'DW', [6, 6, 3, 6],
- tf.float32,
- initializer=tf.random_normal_initializer(stddev=0.001))
- x = tf.nn.conv2d(image, kernel, [1, 2, 2, 1], padding='SAME')
+ dtypes.float32,
+ initializer=init_ops.random_normal_initializer(stddev=0.001))
+ x = nn_ops.conv2d(image, kernel, [1, 2, 2, 1], padding='SAME')
return x
def testPrintModelAnalysis(self):
@@ -83,7 +101,7 @@ class PrintModelAnalysisTest(tf.test.TestCase):
opts.select.append(p)
opts.viz = TEST_OPTIONS['viz']
- with tf.Session() as sess, tf.device('/cpu:0'):
+ with session.Session() as sess, ops.device('/cpu:0'):
_ = self._BuildSmallModel()
tfprof_pb = tfprof_output_pb2.TFProfNode()
tfprof_pb.ParseFromString(
@@ -229,4 +247,4 @@ class PrintModelAnalysisTest(tf.test.TestCase):
if __name__ == '__main__':
- tf.test.main()
+ test.main()
diff --git a/tensorflow/contrib/tfprof/python/tools/tfprof/tfprof_logger.py b/tensorflow/contrib/tfprof/python/tools/tfprof/tfprof_logger.py
index 50ec954ff8..e8cf84b6c7 100644
--- a/tensorflow/contrib/tfprof/python/tools/tfprof/tfprof_logger.py
+++ b/tensorflow/contrib/tfprof/python/tools/tfprof/tfprof_logger.py
@@ -24,8 +24,9 @@ import os
import sys
import six
-import tensorflow as tf
from tensorflow.python.framework import ops
+from tensorflow.python.framework import tensor_shape
+from tensorflow.python.platform import gfile
from tensorflow.tools.tfprof import tfprof_log_pb2
TRAINABLE_VARIABLES = '_trainable_variables'
@@ -50,7 +51,8 @@ def _fill_missing_graph_shape(graph, run_meta):
if op.outputs[i].get_shape().is_fully_defined():
continue
node_stat_dims = node_stat_out.tensor_description.shape.dim
- node_stat_shape = tf.TensorShape([d.size for d in node_stat_dims])
+ node_stat_shape = tensor_shape.TensorShape(
+ [d.size for d in node_stat_dims])
try:
op.outputs[i].set_shape(op.outputs[i].get_shape().merge_with(
node_stat_shape))
@@ -91,7 +93,7 @@ def _get_logged_ops(graph, run_meta=None):
entry.float_ops = int(stats.value)
logged_ops[entry.name] = entry
- for v in graph.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES):
+ for v in graph.get_collection(ops.GraphKeys.TRAINABLE_VARIABLES):
if v.op.name not in logged_ops:
entry = tfprof_log_pb2.OpLogEntry()
entry.name = v.op.name
@@ -100,10 +102,9 @@ def _get_logged_ops(graph, run_meta=None):
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)
+ 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
@@ -156,5 +157,5 @@ def write_op_log(graph, log_dir, op_log=None, run_meta=None):
"""
op_log = _merge_default_with_oplog(graph, op_log, run_meta)
- with tf.gfile.Open(os.path.join(log_dir, 'tfprof_log'), 'w') as log:
+ with gfile.Open(os.path.join(log_dir, 'tfprof_log'), 'w') as log:
log.write(op_log.SerializeToString())
diff --git a/tensorflow/contrib/tfprof/python/tools/tfprof/tfprof_logger_test.py b/tensorflow/contrib/tfprof/python/tools/tfprof/tfprof_logger_test.py
index 56a470e5f5..9a7fe9a887 100644
--- a/tensorflow/contrib/tfprof/python/tools/tfprof/tfprof_logger_test.py
+++ b/tensorflow/contrib/tfprof/python/tools/tfprof/tfprof_logger_test.py
@@ -12,61 +12,78 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
+
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
-import tensorflow as tf
+import sys
+
+# TODO: #6568 Remove this hack that makes dlopen() not crash.
+if hasattr(sys, 'getdlopenflags') and hasattr(sys, 'setdlopenflags'):
+ import ctypes
+ sys.setdlopenflags(sys.getdlopenflags() | ctypes.RTLD_GLOBAL)
+
+from tensorflow.contrib.copy_graph.python.util import copy_elements
+from tensorflow.contrib.tfprof.python.tools.tfprof import tfprof_logger
+from tensorflow.core.protobuf import config_pb2
+from tensorflow.python.client import session
+from tensorflow.python.framework import constant_op
+from tensorflow.python.framework import dtypes
+from tensorflow.python.framework import ops
+from tensorflow.python.ops import array_ops
+from tensorflow.python.ops import math_ops
+from tensorflow.python.platform import test
-class TFProfLoggerTest(tf.test.TestCase):
+class TFProfLoggerTest(test.TestCase):
def _BuildSmallPlaceholderlModel(self):
- a = tf.placeholder(tf.int32, [2, 2])
- b = tf.placeholder(tf.int32, [2, 2])
- y = tf.matmul(a, b)
+ a = array_ops.placeholder(dtypes.int32, [2, 2])
+ b = array_ops.placeholder(dtypes.int32, [2, 2])
+ y = math_ops.matmul(a, b)
return a, b, y
def _BuildSmallModel(self):
- a = tf.constant([[1, 2], [3, 4]])
- b = tf.constant([[1, 2], [3, 4]])
- return tf.matmul(a, b)
+ a = constant_op.constant([[1, 2], [3, 4]])
+ b = constant_op.constant([[1, 2], [3, 4]])
+ return math_ops.matmul(a, b)
def testFillMissingShape(self):
a, b, y = self._BuildSmallPlaceholderlModel()
- run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
- run_metadata = tf.RunMetadata()
- sess = tf.Session()
+ run_options = config_pb2.RunOptions(
+ trace_level=config_pb2.RunOptions.FULL_TRACE)
+ run_metadata = config_pb2.RunMetadata()
+ sess = session.Session()
sess.run(y,
options=run_options,
run_metadata=run_metadata,
feed_dict={a: [[1, 2], [2, 3]],
b: [[1, 2], [2, 3]]})
- graph2 = tf.Graph()
+ graph2 = ops.Graph()
# Use copy_op_to_graph to remove shape information.
- y2 = tf.contrib.copy_graph.copy_op_to_graph(y, graph2, [])
+ y2 = copy_elements.copy_op_to_graph(y, graph2, [])
self.assertEquals('<unknown>', str(y2.get_shape()))
- tf.contrib.tfprof.tfprof_logger._fill_missing_graph_shape(graph2,
- run_metadata)
+ tfprof_logger._fill_missing_graph_shape(graph2, run_metadata)
self.assertEquals('(2, 2)', str(y2.get_shape()))
def testFailedFillMissingShape(self):
y = self._BuildSmallModel()
- run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
- run_metadata = tf.RunMetadata()
- sess = tf.Session()
+ run_options = config_pb2.RunOptions(
+ trace_level=config_pb2.RunOptions.FULL_TRACE)
+ run_metadata = config_pb2.RunMetadata()
+ sess = session.Session()
sess.run(y, options=run_options, run_metadata=run_metadata)
- graph2 = tf.Graph()
- y2 = tf.contrib.copy_graph.copy_op_to_graph(y, graph2, [])
+ graph2 = ops.Graph()
+ y2 = copy_elements.copy_op_to_graph(y, graph2, [])
self.assertEquals('<unknown>', str(y2.get_shape()))
# run_metadata has special name for MatMul, hence failed to fill shape.
- tf.contrib.tfprof.tfprof_logger._fill_missing_graph_shape(graph2,
- run_metadata)
+ tfprof_logger._fill_missing_graph_shape(graph2, run_metadata)
self.assertEquals('<unknown>', str(y2.get_shape()))
if __name__ == '__main__':
- tf.test.main()
+ test.main()