FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

tfdbg: expose Python API · codeplaysoftware/tensorflow@5c93dbd · GitHub

Repository navigation

Commit 5c93dbd

Browse files
authored andcommitted
tfdbg: expose Python API
Change: 136175079
1 parent a174e71 commit 5c93dbd

12 files changed

Lines changed: 104 additions & 65 deletions

File tree

‎tensorflow/python/BUILD‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ py_library(
4040
":summary",
4141
":training",
4242
"//tensorflow/contrib:contrib_py",
43+
"//tensorflow/python/debug:debug_py",
4344
],
4445
)
4546

‎tensorflow/python/debug/BUILD‎

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ exports_files(["LICENSE"])
1515

1616
load("//tensorflow:tensorflow.bzl", "cuda_py_test")
1717

18+
py_library(
19+
name = "debug_py",
20+
srcs = ["__init__.py"],
21+
srcs_version = "PY2AND3",
22+
deps = [
23+
":debug_data",
24+
":debug_utils",
25+
":local_cli_wrapper",
26+
],
27+
)
28+
1829
py_library(
1930
name = "debug_data",
2031
srcs = ["debug_data.py"],
@@ -32,7 +43,7 @@ py_library(
3243

3344
py_library(
3445
name = "framework",
35-
srcs = ["framework.py"],
46+
srcs = ["wrappers/framework.py"],
3647
srcs_version = "PY2AND3",
3748
deps = [
3849
":debug_utils",
@@ -82,8 +93,8 @@ py_library(
8293
)
8394

8495
py_library(
85-
name = "local_cli",
86-
srcs = ["local_cli.py"],
96+
name = "local_cli_wrapper",
97+
srcs = ["wrappers/local_cli_wrapper.py"],
8798
srcs_version = "PY2AND3",
8899
deps = [
89100
":analyzer_cli",
@@ -99,19 +110,14 @@ py_binary(
99110
name = "debug_fibonacci",
100111
srcs = ["examples/debug_fibonacci.py"],
101112
srcs_version = "PY2AND3",
102-
deps = [
103-
":local_cli",
104-
"//tensorflow:tensorflow_py",
105-
],
113+
deps = ["//tensorflow:tensorflow_py"],
106114
)
107115

108116
py_binary(
109117
name = "debug_mnist",
110118
srcs = ["examples/debug_mnist.py"],
111119
srcs_version = "PY2AND3",
112120
deps = [
113-
":debug_data",
114-
":local_cli",
115121
"//tensorflow:tensorflow_py",
116122
"//tensorflow/examples/tutorials/mnist:input_data",
117123
],
@@ -151,9 +157,7 @@ py_test(
151157
py_test(
152158
name = "framework_test",
153159
size = "small",
154-
srcs = [
155-
"framework_test.py",
156-
],
160+
srcs = ["wrappers/framework_test.py"],
157161
srcs_version = "PY2AND3",
158162
deps = [
159163
":debug_data",
@@ -255,14 +259,14 @@ cuda_py_test(
255259
)
256260

257261
py_test(
258-
name = "local_cli_test",
262+
name = "local_cli_wrapper_test",
259263
size = "small",
260264
srcs = [
261-
"local_cli_test.py",
265+
"wrappers/local_cli_wrapper_test.py",
262266
],
263267
srcs_version = "PY2AND3",
264268
deps = [
265-
":local_cli",
269+
":local_cli_wrapper",
266270
"//tensorflow:tensorflow_py",
267271
"//tensorflow/python:framework_test_lib",
268272
],
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# ==============================================================================
15+
"""Public Python API of TensorFlow Debugger (tfdbg)."""
16+
17+
from __future__ import absolute_import
18+
from __future__ import division
19+
from __future__ import print_function
20+
21+
# pylint: disable=unused-imports
22+
from tensorflow.python.debug.debug_data import DebugDumpDir
23+
from tensorflow.python.debug.debug_data import DebugTensorDatum
24+
from tensorflow.python.debug.debug_data import has_inf_or_nan
25+
from tensorflow.python.debug.debug_data import load_tensor_from_event_file
26+
27+
from tensorflow.python.debug.debug_utils import add_debug_tensor_watch
28+
from tensorflow.python.debug.debug_utils import watch_graph
29+
from tensorflow.python.debug.debug_utils import watch_graph_with_blacklists
30+
31+
from tensorflow.python.debug.wrappers.local_cli_wrapper import LocalCLIDebugWrapperSession

‎tensorflow/python/debug/debug_data.py‎

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def parse_node_or_tensor_name(name):
7878
return name, None
7979

8080

81-
def get_tensor_name(node_name, output_slot):
81+
def _get_tensor_name(node_name, output_slot):
8282
"""Get tensor name given node name and output slot index.
8383
8484
Args:
@@ -92,7 +92,7 @@ def get_tensor_name(node_name, output_slot):
9292
return "%s:%d" % (node_name, output_slot)
9393

9494

95-
def get_tensor_watch_key(node_name, output_slot, debug_op):
95+
def _get_tensor_watch_key(node_name, output_slot, debug_op):
9696
"""Get the string representation of a debug watch on a tensor.
9797
9898
Args:
@@ -106,10 +106,10 @@ def get_tensor_watch_key(node_name, output_slot, debug_op):
106106
A string representing the debug watch on the tensor (i.e., the "watch
107107
key").
108108
"""
109-
return "%s:%s" % (get_tensor_name(node_name, output_slot), debug_op)
109+
return "%s:%s" % (_get_tensor_name(node_name, output_slot), debug_op)
110110

111111

112-
def is_copy_node(node_name):
112+
def _is_copy_node(node_name):
113113
"""Determine whether a node name is that of a debug Copy node.
114114
115115
Such nodes are inserted by TensorFlow core upon request in
@@ -125,7 +125,7 @@ def is_copy_node(node_name):
125125
return node_name.startswith("__copy_")
126126

127127

128-
def is_debug_node(node_name):
128+
def _is_debug_node(node_name):
129129
"""Determine whether a node name is that of a debug node.
130130
131131
Such nodes are inserted by TensorFlow core upon request in
@@ -140,7 +140,7 @@ def is_debug_node(node_name):
140140
return node_name.startswith("__dbg_")
141141

142142

143-
def parse_debug_node_name(node_name):
143+
def _parse_debug_node_name(node_name):
144144
"""Parse the name of a debug node.
145145
146146
Args:
@@ -282,7 +282,7 @@ def output_slot(self):
282282

283283
@property
284284
def tensor_name(self):
285-
return get_tensor_name(self.node_name, self.output_slot)
285+
return _get_tensor_name(self.node_name, self.output_slot)
286286

287287
@property
288288
def watch_key(self):
@@ -291,7 +291,8 @@ def watch_key(self):
291291
Returns:
292292
A watch key, in the form of <tensor_name>:<debug_op>.
293293
"""
294-
return get_tensor_watch_key(self.node_name, self.output_slot, self.debug_op)
294+
return _get_tensor_watch_key(self.node_name, self.output_slot,
295+
self.debug_op)
295296

296297
@property
297298
def file_path(self):
@@ -467,12 +468,12 @@ def _load_partition_graphs(self, partition_graphs):
467468

468469
for pg in self._partition_graphs:
469470
for node in pg.node:
470-
if is_debug_node(node.name):
471+
if _is_debug_node(node.name):
471472
# This is a debug node. Parse the node name and retrieve the
472473
# information about debug watches on tensors. But do not include
473474
# the node in the graph.
474475
(watched_node_name, watched_output_slot, _,
475-
debug_op) = parse_debug_node_name(node.name)
476+
debug_op) = _parse_debug_node_name(node.name)
476477

477478
if watched_node_name not in self._debug_watches:
478479
self._debug_watches[
@@ -507,7 +508,7 @@ def _load_partition_graphs(self, partition_graphs):
507508
self._node_op_types[node.name] = node.op
508509

509510
for inp in node.input:
510-
if is_copy_node(inp) and node.op == "_Send":
511+
if _is_copy_node(inp) and node.op == "_Send":
511512
copy_send_nodes.append(node.name)
512513

513514
if inp.startswith("^"):
@@ -524,14 +525,14 @@ def _load_partition_graphs(self, partition_graphs):
524525
if node in copy_send_nodes:
525526
continue
526527

527-
if is_copy_node(node):
528+
if _is_copy_node(node):
528529
copy_nodes.append(node)
529530

530531
inputs = self._node_inputs[node]
531532

532533
for i in xrange(len(inputs)):
533534
inp = inputs[i]
534-
if is_copy_node(inp):
535+
if _is_copy_node(inp):
535536
# Find the input to the Copy node, which should be the original
536537
# input to the node.
537538
orig_inp = self._node_inputs[inp][0]
@@ -556,7 +557,7 @@ def _load_partition_graphs(self, partition_graphs):
556557
ctrl_inputs = self._node_ctrl_inputs[node]
557558
debug_op_inputs = []
558559
for ctrl_inp in ctrl_inputs:
559-
if is_debug_node(ctrl_inp):
560+
if _is_debug_node(ctrl_inp):
560561
debug_op_inputs.append(ctrl_inp)
561562
for debug_op_inp in debug_op_inputs:
562563
ctrl_inputs.remove(debug_op_inp)
@@ -922,7 +923,7 @@ def debug_watch_keys(self, node_name):
922923
debug_ops = self._debug_watches[node_name][watched_slot]
923924
for debug_op in debug_ops:
924925
watch_keys.append(
925-
get_tensor_watch_key(node_name, watched_slot, debug_op))
926+
_get_tensor_watch_key(node_name, watched_slot, debug_op))
926927

927928
return watch_keys
928929

@@ -987,7 +988,7 @@ def get_tensor_file_paths(self, node_name, output_slot, debug_op):
987988
ValueError: If the tensor does not exist in the debub dump data.
988989
"""
989990

990-
watch_key = get_tensor_watch_key(node_name, output_slot, debug_op)
991+
watch_key = _get_tensor_watch_key(node_name, output_slot, debug_op)
991992
if watch_key not in self._watch_key_to_datum:
992993
raise ValueError("Watch key \"%s\" does not exist in the debug dump" %
993994
watch_key)
@@ -1012,7 +1013,7 @@ def get_tensors(self, node_name, output_slot, debug_op):
10121013
ValueError: If the tensor does not exist in the debub dump data.
10131014
"""
10141015

1015-
watch_key = get_tensor_watch_key(node_name, output_slot, debug_op)
1016+
watch_key = _get_tensor_watch_key(node_name, output_slot, debug_op)
10161017
if watch_key not in self._watch_key_to_datum:
10171018
raise ValueError("Watch key \"%s\" does not exist in the debug dump" %
10181019
watch_key)
@@ -1039,7 +1040,7 @@ def get_rel_timestamps(self, node_name, output_slot, debug_op):
10391040
ValueError: If the tensor does not exist in the debub dump data.
10401041
"""
10411042

1042-
watch_key = get_tensor_watch_key(node_name, output_slot, debug_op)
1043+
watch_key = _get_tensor_watch_key(node_name, output_slot, debug_op)
10431044
if watch_key not in self._watch_key_to_datum:
10441045
raise ValueError("Watch key \"%s\" does not exist in the debug dump" %
10451046
watch_key)

‎tensorflow/python/debug/debug_data_test.py‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,32 +47,32 @@ def testParseTensorName(self):
4747
class NodeNameChecksTest(test_util.TensorFlowTestCase):
4848

4949
def testIsCopyNode(self):
50-
self.assertTrue(debug_data.is_copy_node("__copy_ns1/ns2/node3_0"))
50+
self.assertTrue(debug_data._is_copy_node("__copy_ns1/ns2/node3_0"))
5151

52-
self.assertFalse(debug_data.is_copy_node("copy_ns1/ns2/node3_0"))
53-
self.assertFalse(debug_data.is_copy_node("_copy_ns1/ns2/node3_0"))
54-
self.assertFalse(debug_data.is_copy_node("_copyns1/ns2/node3_0"))
55-
self.assertFalse(debug_data.is_copy_node("__dbg_ns1/ns2/node3_0"))
52+
self.assertFalse(debug_data._is_copy_node("copy_ns1/ns2/node3_0"))
53+
self.assertFalse(debug_data._is_copy_node("_copy_ns1/ns2/node3_0"))
54+
self.assertFalse(debug_data._is_copy_node("_copyns1/ns2/node3_0"))
55+
self.assertFalse(debug_data._is_copy_node("__dbg_ns1/ns2/node3_0"))
5656

5757
def testIsDebugNode(self):
5858
self.assertTrue(
59-
debug_data.is_debug_node("__dbg_ns1/ns2/node3:0_0_DebugIdentity"))
59+
debug_data._is_debug_node("__dbg_ns1/ns2/node3:0_0_DebugIdentity"))
6060

6161
self.assertFalse(
62-
debug_data.is_debug_node("dbg_ns1/ns2/node3:0_0_DebugIdentity"))
62+
debug_data._is_debug_node("dbg_ns1/ns2/node3:0_0_DebugIdentity"))
6363
self.assertFalse(
64-
debug_data.is_debug_node("_dbg_ns1/ns2/node3:0_0_DebugIdentity"))
64+
debug_data._is_debug_node("_dbg_ns1/ns2/node3:0_0_DebugIdentity"))
6565
self.assertFalse(
66-
debug_data.is_debug_node("_dbgns1/ns2/node3:0_0_DebugIdentity"))
67-
self.assertFalse(debug_data.is_debug_node("__copy_ns1/ns2/node3_0"))
66+
debug_data._is_debug_node("_dbgns1/ns2/node3:0_0_DebugIdentity"))
67+
self.assertFalse(debug_data._is_debug_node("__copy_ns1/ns2/node3_0"))
6868

6969

7070
class ParseDebugNodeNameTest(test_util.TensorFlowTestCase):
7171

7272
def testParseDebugNodeName_valid(self):
7373
debug_node_name_1 = "__dbg_ns_a/ns_b/node_c:1_0_DebugIdentity"
7474
(watched_node, watched_output_slot, debug_op_index,
75-
debug_op) = debug_data.parse_debug_node_name(debug_node_name_1)
75+
debug_op) = debug_data._parse_debug_node_name(debug_node_name_1)
7676

7777
self.assertEqual("ns_a/ns_b/node_c", watched_node)
7878
self.assertEqual(1, watched_output_slot)
@@ -83,20 +83,20 @@ def testParseDebugNodeName_invalidPrefix(self):
8383
invalid_debug_node_name_1 = "__copy_ns_a/ns_b/node_c:1_0_DebugIdentity"
8484

8585
with self.assertRaisesRegexp(ValueError, "Invalid prefix"):
86-
debug_data.parse_debug_node_name(invalid_debug_node_name_1)
86+
debug_data._parse_debug_node_name(invalid_debug_node_name_1)
8787

8888
def testParseDebugNodeName_missingDebugOpIndex(self):
8989
invalid_debug_node_name_1 = "__dbg_node1:0_DebugIdentity"
9090

9191
with self.assertRaisesRegexp(ValueError, "Invalid debug node name"):
92-
debug_data.parse_debug_node_name(invalid_debug_node_name_1)
92+
debug_data._parse_debug_node_name(invalid_debug_node_name_1)
9393

9494
def testParseDebugNodeName_invalidWatchedTensorName(self):
9595
invalid_debug_node_name_1 = "__dbg_node1_0_DebugIdentity"
9696

9797
with self.assertRaisesRegexp(ValueError,
9898
"Invalid tensor name in debug node name"):
99-
debug_data.parse_debug_node_name(invalid_debug_node_name_1)
99+
debug_data._parse_debug_node_name(invalid_debug_node_name_1)
100100

101101

102102
class HasNanOrInfTest(test_util.TensorFlowTestCase):

‎tensorflow/python/debug/examples/README.md‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ wrapper:
5050

5151
```python
5252
if FLAGS.debug:
53-
sess = local_cli.LocalCLIDebugWrapperSession(sess)
54-
sess.add_tensor_filter("has_inf_or_nan", debug_data.has_inf_or_nan)
53+
sess = tf_debug.LocalCLIDebugWrapperSession(sess)
54+
sess.add_tensor_filter("has_inf_or_nan", tf_debug.has_inf_or_nan)
5555
```
5656

5757
This wrapper has the same interface as Session, so debugging requires no other
@@ -299,3 +299,8 @@ Frequently-asked questions:
299299
model, check out
300300
[tfprof](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/tfprof)
301301
and other profiling tools for TensorFlow.
302+
303+
* **Q**: How do I link tfdbg against my Session in Bazel?<br />
304+
**A**: In your BUILD rule, declare the dependency: `"//tensorflow:tensorflow_py"`.
305+
In your Python file, do:
306+
`from tensorflow.python import debug import tf_debug`

‎tensorflow/python/debug/examples/debug_fibonacci.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from six.moves import xrange # pylint: disable=redefined-builtin
2222
import tensorflow as tf
2323

24-
from tensorflow.python.debug import local_cli
24+
from tensorflow.python import debug as tf_debug
2525

2626
flags = tf.app.flags
2727
FLAGS = flags.FLAGS
@@ -48,7 +48,7 @@ def main(_):
4848
sess.run(tf.initialize_all_variables())
4949

5050
# Wrap the TensorFlow Session object for debugging.
51-
sess = local_cli.LocalCLIDebugWrapperSession(sess)
51+
sess = tf_debug.LocalCLIDebugWrapperSession(sess)
5252

5353
sess.run(n1)
5454

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL