Skip to content

Commit d627ca4

Browse files
Forwarding out of range errors rather than capturing them within the base TFDBG
wrapper session. Several use cases expect the error to be raised to cancel their iterations (namely the NMT Tutorial [1]). [1]: https://research.googleblog.com/2017/07/building-your-own-neural-machine.html PiperOrigin-RevId: 170773133
1 parent a2b23b0 commit d627ca4

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

tensorflow/python/debug/wrappers/dumping_wrapper.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def __init__(self,
3636
session_root,
3737
watch_fn=None,
3838
thread_name_filter=None,
39+
pass_through_operrors=None,
3940
log_usage=True):
4041
"""Constructor of DumpingDebugWrapperSession.
4142
@@ -56,6 +57,8 @@ def __init__(self,
5657
thread_name_filter: Regular-expression white list for threads on which the
5758
wrapper session will be active. See doc of `BaseDebugWrapperSession` for
5859
more details.
60+
pass_through_operrors: If true, all captured OpErrors will be
61+
propagated. By default this captures all OpErrors.
5962
log_usage: (`bool`) whether the usage of this class is to be logged.
6063
6164
Raises:
@@ -67,7 +70,8 @@ def __init__(self,
6770
pass # No logging for open-source.
6871

6972
framework.NonInteractiveDebugWrapperSession.__init__(
70-
self, sess, watch_fn=watch_fn, thread_name_filter=thread_name_filter)
73+
self, sess, watch_fn=watch_fn, thread_name_filter=thread_name_filter,
74+
pass_through_operrors=pass_through_operrors)
7175

7276
if gfile.Exists(session_root):
7377
if not gfile.IsDirectory(session_root):

tensorflow/python/debug/wrappers/framework.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ class BaseDebugWrapperSession(session.SessionInterface):
337337
# TODO(cais): Add on_cont_start and on_cont_end callbacks once the stepper is
338338
# is available.
339339

340-
def __init__(self, sess, thread_name_filter=None):
340+
def __init__(self, sess, thread_name_filter=None,
341+
pass_through_operrors=False):
341342
"""Constructor of `BaseDebugWrapperSession`.
342343
343344
Args:
@@ -349,6 +350,8 @@ def __init__(self, sess, thread_name_filter=None):
349350
by applying the `match` method of the compiled pattern. The default
350351
`None` means that the wrapper session will be active on all threads.
351352
E.g., r"MainThread$", r"QueueRunnerThread.*".
353+
pass_through_operrors: If True, all captured OpErrors will be
354+
propagated. By default this captures all OpErrors.
352355
353356
Raises:
354357
ValueError: On invalid `OnSessionInitAction` value.
@@ -361,6 +364,8 @@ def __init__(self, sess, thread_name_filter=None):
361364
self._sess = sess
362365
self._thread_name_filter_pattern = (re.compile(thread_name_filter)
363366
if thread_name_filter else None)
367+
# TODO(cais/kstevens): Unittest this pass through feature.
368+
self._pass_through_operrors = pass_through_operrors
364369

365370
# Keeps track of number of run calls that have been performed on this
366371
# debug-wrapper session. The count can be used for purposes such as
@@ -480,6 +485,8 @@ def run(self,
480485
options=decorated_run_options,
481486
run_metadata=run_metadata)
482487
except errors.OpError as op_error:
488+
if self._pass_through_operrors:
489+
raise op_error
483490
tf_error = op_error
484491
retvals = op_error
485492

@@ -783,7 +790,8 @@ def __repr__(self):
783790
class NonInteractiveDebugWrapperSession(BaseDebugWrapperSession):
784791
"""Base class for non-interactive (i.e., non-CLI) debug wrapper sessions."""
785792

786-
def __init__(self, sess, watch_fn=None, thread_name_filter=None):
793+
def __init__(self, sess, watch_fn=None, thread_name_filter=None,
794+
pass_through_operrors=False):
787795
"""Constructor of DumpingDebugWrapperSession.
788796
789797
Args:
@@ -802,12 +810,15 @@ def __init__(self, sess, watch_fn=None, thread_name_filter=None):
802810
thread_name_filter: Regular-expression white list for threads on which the
803811
wrapper session will be active. See doc of `BaseDebugWrapperSession` for
804812
more details.
813+
pass_through_operrors: If true, all captured OpErrors will be
814+
propagated. By default this captures all OpErrors.
805815
Raises:
806816
TypeError: If a non-None `watch_fn` is specified and it is not callable.
807817
"""
808818

809819
BaseDebugWrapperSession.__init__(
810-
self, sess, thread_name_filter=thread_name_filter)
820+
self, sess, thread_name_filter=thread_name_filter,
821+
pass_through_operrors=pass_through_operrors)
811822

812823
self._watch_fn = None
813824
if watch_fn is not None:

0 commit comments

Comments
 (0)