Skip to content

Commit 73a8755

Browse files
caisqtensorflower-gardener
authored andcommitted
tfdbg: usability improvement: register the has_inf_or_nan filter by default
This saves users an extra line to add during debugging. has_inf_or_nan is a common use case. PiperOrigin-RevId: 169445420
1 parent a818005 commit 73a8755

5 files changed

Lines changed: 14 additions & 5 deletions

File tree

tensorflow/docs_src/programmers_guide/debugger.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ so you can activate tfdbg CLI with the `--debug` flag at the command line.
6464
from tensorflow.python import debug as tf_debug
6565

6666
sess = tf_debug.LocalCLIDebugWrapperSession(sess)
67-
sess.add_tensor_filter("has_inf_or_nan", tf_debug.has_inf_or_nan)
6867
```
6968

7069
This wrapper has the same interface as Session, so enabling debugging requires
@@ -246,13 +245,18 @@ some procedural-language debuggers:
246245
tfdbg> run -f has_inf_or_nan
247246
```
248247
249-
> NOTE: The preceding command works properly because we have registered a filter
250-
> for `nan`s and `inf`s called `has_inf_or_nan` (as explained previously).
248+
> NOTE: The preceding command works properly because a tensor filter called
249+
> `has_inf_or_nan` has been registered for you when the wrapped session is
250+
> created. This filter detects `nan`s and `inf`s (as explained previously).
251251
> If you have registered any other filters, you can
252252
> use "run -f" to have tfdbg run until any tensor triggers that filter (cause
253253
> the filter to return True).
254254
>
255255
> ``` python
256+
> def my_filter_callable(datum, tensor):
257+
> # A filter that detects zero-valued scalars.
258+
> return len(tensor.shape) == 0 and tensor == 0.0
259+
>
256260
> sess.add_tensor_filter('my_filter', my_filter_callable)
257261
> ```
258262
>

tensorflow/python/debug/examples/debug_mnist.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ def nn_layer(input_tensor, input_dim, output_dim, layer_name, act=tf.nn.relu):
122122

123123
if FLAGS.debug:
124124
sess = tf_debug.LocalCLIDebugWrapperSession(sess, ui_type=FLAGS.ui_type)
125-
sess.add_tensor_filter("has_inf_or_nan", tf_debug.has_inf_or_nan)
126125

127126
# Add this point, sess is a debug wrapper around the actual Session if
128127
# FLAGS.debug is true. In that case, calling run() will launch the CLI.

tensorflow/python/debug/examples/debug_tflearn_iris.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ def main(_):
113113
if FLAGS.debug:
114114
debug_hook = tf_debug.LocalCLIDebugHook(ui_type=FLAGS.ui_type,
115115
dump_root=FLAGS.dump_root)
116-
debug_hook.add_tensor_filter("has_inf_or_nan", tf_debug.has_inf_or_nan)
117116
hooks = [debug_hook]
118117

119118
if not FLAGS.use_experiment:

tensorflow/python/debug/wrappers/local_cli_wrapper.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ def __init__(self,
9595

9696
# Registered tensor filters.
9797
self._tensor_filters = {}
98+
# Register frequently-used filter(s).
99+
self.add_tensor_filter("has_inf_or_nan", debug_data.has_inf_or_nan)
98100

99101
# Below are the state variables of this wrapper object.
100102
# _active_tensor_filter: what (if any) tensor filter is in effect. If such

tensorflow/python/debug/wrappers/local_cli_wrapper_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,11 @@ def testRunTillFilterPassesShouldLaunchCLIAtCorrectRun(self):
421421

422422
def v_greater_than_twelve(datum, tensor):
423423
return datum.node_name == "v" and tensor > 12.0
424+
425+
# Verify that adding the same tensor filter more than once is tolerated
426+
# (i.e., as if it were added only once).
427+
wrapped_sess.add_tensor_filter("v_greater_than_twelve",
428+
v_greater_than_twelve)
424429
wrapped_sess.add_tensor_filter("v_greater_than_twelve",
425430
v_greater_than_twelve)
426431

0 commit comments

Comments
 (0)