aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/python/training/session_run_hook.py
diff options
context:
space:
mode:
authorGravatar A. Unique TensorFlower <gardener@tensorflow.org>2017-03-22 15:55:25 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2017-03-22 17:08:28 -0700
commit464ed246571a0da5d1fb5eca13b8dce0fce6f384 (patch)
tree44d07ccad05f9202178a125c0842da0d02c9a29e /tensorflow/python/training/session_run_hook.py
parent81761d7d07018af6665a20afe74b99b18ba02728 (diff)
Add comments for how after_run() and end() behave if session.run() raises
exception. Change: 150947137
Diffstat (limited to 'tensorflow/python/training/session_run_hook.py')
-rw-r--r--tensorflow/python/training/session_run_hook.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/tensorflow/python/training/session_run_hook.py b/tensorflow/python/training/session_run_hook.py
index 13f8ba1b6e..09da63eb68 100644
--- a/tensorflow/python/training/session_run_hook.py
+++ b/tensorflow/python/training/session_run_hook.py
@@ -62,15 +62,24 @@ look at following code:
sess.run(your_fetches)
Above user code leads to following execution:
- call hooks.begin
+ call hooks.begin()
sess = tf.Session()
+ call hooks.after_create_session()
while not stop is requested:
call hooks.before_run()
- results = sess.run(merged_fetches)
+ try:
+ results = sess.run(merged_fetches)
+ except (errors.OutOfRangeError, StopIteration):
+ break
call hooks.after_run()
call hooks.end()
sess.close()
+Note that if sess.run() raises OutOfRangeError or StopIteration then
+hooks.after_run() will not be called but hooks.end() will still be called.
+If sess.run() raises any other exception then neither hooks.after_run() nor
+hooks.end() will be called.
+
@@SessionRunHook
@@SessionRunArgs
@@SessionRunContext
@@ -149,6 +158,8 @@ class SessionRunHook(object):
The `run_context` argument is the same one send to `before_run` call.
`run_context.request_stop()` can be called to stop the iteration.
+ If `session.run()` raises any exceptions then `after_run()` is not called.
+
Args:
run_context: A `SessionRunContext` object.
run_values: A SessionRunValues object.
@@ -161,6 +172,12 @@ class SessionRunHook(object):
The `session` argument can be used in case the hook wants to run final ops,
such as saving a last checkpoint.
+ If `session.run()` raises exception other than OutOfRangeError or
+ StopIteration then `end()` is not called.
+ Note the difference between `end()` and `after_run()` behavior when
+ `session.run()` raises OutOfRangeError or StopIteration. In that case
+ `end()` is called but `after_run()` is not called.
+
Args:
session: A TensorFlow Session that will be soon closed.
"""