[tfdbg] Improve how examples binaries handle config file paths
PiperOrigin-RevId: 259556240
This commit is contained in:
parent
af07a124fa
commit
8b0c84d30d
@ -1171,7 +1171,6 @@ sh_test(
|
||||
":offline_analyzer",
|
||||
],
|
||||
tags = [
|
||||
"no_oss", # TODO(b/137652456): remove when fixed
|
||||
"no_windows",
|
||||
],
|
||||
)
|
||||
|
@ -19,6 +19,7 @@ from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
@ -41,10 +42,12 @@ def main(_):
|
||||
z = tf.matmul(m, v, name="z")
|
||||
|
||||
if FLAGS.debug:
|
||||
config_file_path = (tempfile.mktemp(".tfdbg_config")
|
||||
if FLAGS.use_random_config_path else None)
|
||||
sess = tf_debug.LocalCLIDebugWrapperSession(
|
||||
sess,
|
||||
ui_type=FLAGS.ui_type,
|
||||
use_random_config_path=FLAGS.use_random_config_path)
|
||||
config_file_path=config_file_path)
|
||||
|
||||
if FLAGS.error == "shape_mismatch":
|
||||
print(sess.run(y, feed_dict={ph_float: np.array([[0.0], [1.0], [2.0]])}))
|
||||
|
@ -20,6 +20,7 @@ from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
@ -41,7 +42,12 @@ def main(_):
|
||||
sess = tf.Session()
|
||||
if FLAGS.debug:
|
||||
# Use the command-line interface (CLI) of tfdbg.
|
||||
sess = tf_debug.LocalCLIDebugWrapperSession(sess, ui_type=FLAGS.ui_type)
|
||||
config_file_path = (tempfile.mktemp(".tfdbg_config")
|
||||
if FLAGS.use_random_config_path else None)
|
||||
sess = tf_debug.LocalCLIDebugWrapperSession(
|
||||
sess,
|
||||
ui_type=FLAGS.ui_type,
|
||||
config_file_path=config_file_path)
|
||||
elif FLAGS.tensorboard_debug_address:
|
||||
# Use the TensorBoard Debugger Plugin (GUI of tfdbg).
|
||||
sess = tf_debug.TensorBoardDebugWrapperSession(
|
||||
@ -73,6 +79,14 @@ if __name__ == "__main__":
|
||||
type=str,
|
||||
default="curses",
|
||||
help="Command-line user interface type (curses | readline).")
|
||||
parser.add_argument(
|
||||
"--use_random_config_path",
|
||||
type="bool",
|
||||
nargs="?",
|
||||
const=True,
|
||||
default=False,
|
||||
help="""If set, set config file path to a random file in the temporary
|
||||
directory.""")
|
||||
parser.add_argument(
|
||||
"--tensorboard_debug_address",
|
||||
type=str,
|
||||
|
@ -26,6 +26,7 @@ from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
import tensorflow as tf
|
||||
|
||||
@ -125,10 +126,12 @@ def main(_):
|
||||
"The --debug and --tensorboard_debug_address flags are mutually "
|
||||
"exclusive.")
|
||||
if FLAGS.debug:
|
||||
config_file_path = (tempfile.mktemp(".tfdbg_config")
|
||||
if FLAGS.use_random_config_path else None)
|
||||
sess = tf_debug.LocalCLIDebugWrapperSession(
|
||||
sess,
|
||||
ui_type=FLAGS.ui_type,
|
||||
use_random_config_path=FLAGS.use_random_config_path)
|
||||
config_file_path=config_file_path)
|
||||
elif FLAGS.tensorboard_debug_address:
|
||||
sess = tf_debug.TensorBoardDebugWrapperSession(
|
||||
sess, FLAGS.tensorboard_debug_address)
|
||||
|
@ -58,8 +58,11 @@ def main(_):
|
||||
"exclusive.")
|
||||
hooks = []
|
||||
if FLAGS.debug:
|
||||
config_file_path = (tempfile.mktemp(".tfdbg_config")
|
||||
if FLAGS.use_random_config_path else None)
|
||||
hooks.append(tf_debug.LocalCLIDebugHook(ui_type=FLAGS.ui_type,
|
||||
dump_root=FLAGS.dump_root))
|
||||
dump_root=FLAGS.dump_root,
|
||||
config_file_path=config_file_path))
|
||||
elif FLAGS.tensorboard_debug_address:
|
||||
hooks.append(tf_debug.TensorBoardDebugHook(FLAGS.tensorboard_debug_address))
|
||||
|
||||
@ -122,6 +125,14 @@ if __name__ == "__main__":
|
||||
type=str,
|
||||
default="",
|
||||
help="Optional custom root directory for temporary debug dump data")
|
||||
parser.add_argument(
|
||||
"--use_random_config_path",
|
||||
type="bool",
|
||||
nargs="?",
|
||||
const=True,
|
||||
default=False,
|
||||
help="""If set, set config file path to a random file in the temporary
|
||||
directory.""")
|
||||
parser.add_argument(
|
||||
"--tensorboard_debug_address",
|
||||
type=str,
|
||||
|
@ -87,7 +87,7 @@ EOF
|
||||
CUSTOM_DUMP_ROOT=$(mktemp -d)
|
||||
mkdir -p ${CUSTOM_DUMP_ROOT}
|
||||
|
||||
cat << EOF | ${DEBUG_TFLEARN_IRIS_BIN} --debug --train_steps=2 --dump_root="${CUSTOM_DUMP_ROOT}" --ui_type=readline
|
||||
cat << EOF | ${DEBUG_TFLEARN_IRIS_BIN} --debug --train_steps=2 --dump_root="${CUSTOM_DUMP_ROOT}" --ui_type=readline --use_random_config_path
|
||||
run -p
|
||||
run -f has_inf_or_nan
|
||||
EOF
|
||||
@ -99,12 +99,12 @@ if [[ -d "${CUSTOM_DUMP_ROOT}" ]]; then
|
||||
fi
|
||||
|
||||
# Test debugging of tf.keras.
|
||||
cat << EOF | ${DEBUG_KERAS_BIN} --debug --ui_type=readline
|
||||
cat << EOF | ${DEBUG_KERAS_BIN} --debug --ui_type=readline --use_random_config_path
|
||||
run -f has_inf_or_nan
|
||||
EOF
|
||||
|
||||
# Test debugging of tf.keras, with non-debug runs included.
|
||||
cat << EOF | ${DEBUG_KERAS_BIN} --debug --ui_type=readline
|
||||
cat << EOF | ${DEBUG_KERAS_BIN} --debug --ui_type=readline --use_random_config_path
|
||||
run -t 10
|
||||
EOF
|
||||
|
||||
|
@ -36,7 +36,11 @@ class LocalCLIDebugHook(session_run_hook.SessionRunHook):
|
||||
available.
|
||||
"""
|
||||
|
||||
def __init__(self, ui_type="curses", dump_root=None, thread_name_filter=None):
|
||||
def __init__(self,
|
||||
ui_type="curses",
|
||||
dump_root=None,
|
||||
thread_name_filter=None,
|
||||
config_file_path=None):
|
||||
"""Create a local debugger command-line interface (CLI) hook.
|
||||
|
||||
Args:
|
||||
@ -49,6 +53,8 @@ class LocalCLIDebugHook(session_run_hook.SessionRunHook):
|
||||
thread_name_filter: Regular-expression white list for threads on which the
|
||||
wrapper session will be active. See doc of `BaseDebugWrapperSession` for
|
||||
more details.
|
||||
config_file_path: Optional override to the default configuration file
|
||||
path, which is at `${HOME}/.tfdbg_config`.
|
||||
"""
|
||||
|
||||
self._ui_type = ui_type
|
||||
@ -56,6 +62,7 @@ class LocalCLIDebugHook(session_run_hook.SessionRunHook):
|
||||
self._thread_name_filter = thread_name_filter
|
||||
self._session_wrapper = None
|
||||
self._pending_tensor_filters = {}
|
||||
self._config_file_path = config_file_path
|
||||
|
||||
def add_tensor_filter(self, filter_name, tensor_filter):
|
||||
"""Add a tensor filter.
|
||||
@ -87,7 +94,8 @@ class LocalCLIDebugHook(session_run_hook.SessionRunHook):
|
||||
run_context.session,
|
||||
ui_type=self._ui_type,
|
||||
dump_root=self._dump_root,
|
||||
thread_name_filter=self._thread_name_filter)
|
||||
thread_name_filter=self._thread_name_filter,
|
||||
config_file_path=self._config_file_path)
|
||||
|
||||
# Actually register tensor filters registered prior to the construction
|
||||
# of the underlying LocalCLIDebugWrapperSession object.
|
||||
|
@ -54,7 +54,7 @@ class LocalCLIDebugWrapperSession(framework.BaseDebugWrapperSession):
|
||||
log_usage=True,
|
||||
ui_type="curses",
|
||||
thread_name_filter=None,
|
||||
use_random_config_path=False):
|
||||
config_file_path=False):
|
||||
"""Constructor of LocalCLIDebugWrapperSession.
|
||||
|
||||
Args:
|
||||
@ -69,8 +69,8 @@ class LocalCLIDebugWrapperSession(framework.BaseDebugWrapperSession):
|
||||
(curses | readline)
|
||||
thread_name_filter: Regular-expression white list for thread name. See
|
||||
the doc of `BaseDebugWrapperSession` for details.
|
||||
use_random_config_path: If true, set config file path to a random file in
|
||||
the temporary directory.
|
||||
config_file_path: Optional override to the default configuration file
|
||||
path, which is at `${HOME}/.tfdbg_config`.
|
||||
|
||||
Raises:
|
||||
ValueError: If dump_root is an existing and non-empty directory or if
|
||||
@ -127,9 +127,8 @@ class LocalCLIDebugWrapperSession(framework.BaseDebugWrapperSession):
|
||||
self._is_run_start = True
|
||||
self._ui_type = ui_type
|
||||
self._config = None
|
||||
if use_random_config_path:
|
||||
self._config = cli_config.CLIConfig(
|
||||
config_file_path=os.path.join(tempfile.mkdtemp(), ".tfdbg_config"))
|
||||
if config_file_path:
|
||||
self._config = cli_config.CLIConfig(config_file_path=config_file_path)
|
||||
|
||||
def _is_disk_usage_reset_each_run(self):
|
||||
# The dumped tensors are all cleaned up after every Session.run
|
||||
|
Loading…
Reference in New Issue
Block a user