diff options
author | 2017-12-08 16:30:02 -0800 | |
---|---|---|
committer | 2017-12-08 16:33:27 -0800 | |
commit | a0c21217fcf2993c5625a726c62a04b749afcddf (patch) | |
tree | 75b02abe7c2cd17894201a95fe41225e4c24ed3f /tensorflow/python/profiler | |
parent | ddfd6253fe0870779abc78be52c872d86b03f577 (diff) |
Make profiler memory profiling work with tf.while_loop
PiperOrigin-RevId: 178443834
Diffstat (limited to 'tensorflow/python/profiler')
-rw-r--r-- | tensorflow/python/profiler/model_analyzer_test.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tensorflow/python/profiler/model_analyzer_test.py b/tensorflow/python/profiler/model_analyzer_test.py index ccfb9aac53..5d524c8c74 100644 --- a/tensorflow/python/profiler/model_analyzer_test.py +++ b/tensorflow/python/profiler/model_analyzer_test.py @@ -29,9 +29,12 @@ from tensorflow.core.profiler import profile_pb2 from tensorflow.core.protobuf import config_pb2 from tensorflow.core.protobuf import rewriter_config_pb2 from tensorflow.python.client import session +from tensorflow.python.framework import dtypes from tensorflow.python.framework import ops from tensorflow.python.framework import test_util from tensorflow.python.ops import array_ops +from tensorflow.python.ops import control_flow_ops +from tensorflow.python.ops import gradients from tensorflow.python.ops import random_ops from tensorflow.python.ops import variables from tensorflow.python.platform import gfile @@ -730,6 +733,43 @@ class PrintModelAnalysisTest(test.TestCase): self.assertEqual(n.output_bytes, n2.output_bytes) self.assertEqual(n.residual_bytes, n2.residual_bytes) + def testTraceLoopBytes(self): + if not test.is_gpu_available(): return + ops.reset_default_graph() + steps = 100 + + with ops.device('/gpu:0'): + x = array_ops.ones((100, 100), dtype=dtypes.float32) + n = array_ops.constant(steps, dtype=dtypes.int32) + x1 = array_ops.ones((100, 100)) + + x *= x1 + def loop_body(i, x): + x *= x + return i + 1, x + + _, y = control_flow_ops.while_loop( + lambda i, x: i < n, loop_body, + [array_ops.constant(0), x]) + + grad = gradients.gradients(y, [x1]) + + with session.Session() as sess: + run_options = config_pb2.RunOptions( + trace_level=config_pb2.RunOptions.FULL_TRACE) + run_metadata = config_pb2.RunMetadata() + sess.run(grad, options=run_options, run_metadata=run_metadata) + + options = option_builder.ProfileOptionBuilder.time_and_memory() + options['min_bytes'] = 0 + options['min_micros'] = 0 + options['select'] = ('bytes', 'peak_bytes', 'output_bytes', + 'residual_bytes') + options['output'] = 'none' + ret_pb = model_analyzer.profile( + sess.graph, run_meta=run_metadata, cmd='scope', options=options) + self.assertGreater(ret_pb.total_requested_bytes, 1000000) + if __name__ == '__main__': test.main() |