From 464ed246571a0da5d1fb5eca13b8dce0fce6f384 Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Wed, 22 Mar 2017 15:55:25 -0800 Subject: Add comments for how after_run() and end() behave if session.run() raises exception. Change: 150947137 --- tensorflow/python/training/session_run_hook.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'tensorflow/python/training/session_run_hook.py') 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. """ -- cgit v1.2.3