chore: import upstream snapshot with attribution
cffconvert / validate (push) Has been skipped
License Check / license-check (push) Failing after 2s

This commit is contained in:
wehub-resource-sync
2026-07-13 12:14:16 +08:00
commit 8a852e4b4e
36502 changed files with 9277225 additions and 0 deletions
+115
View File
@@ -0,0 +1,115 @@
load("@rules_shell//shell:sh_test.bzl", "sh_test")
load("@xla//third_party/rules_python/python:py_binary.bzl", "py_binary")
package(
# copybara:uncomment default_applicable_licenses = ["//tensorflow:license"],
licenses = ["notice"],
)
py_binary(
name = "debug_fibonacci",
srcs = ["debug_fibonacci.py"],
strict_deps = True,
deps = [
"//tensorflow:tensorflow_py",
"//tensorflow/python/debug:debug_py",
"//third_party/py/numpy",
],
)
py_binary(
name = "debug_errors",
srcs = ["debug_errors.py"],
strict_deps = True,
deps = [
"//tensorflow:tensorflow_py",
"//tensorflow/python/debug:debug_py",
"//third_party/py/numpy",
],
)
py_binary(
name = "debug_keras",
srcs = ["debug_keras.py"],
strict_deps = True,
deps = [
"//tensorflow:tensorflow_py",
"//tensorflow/python/debug:debug_py",
"//third_party/py/numpy",
],
)
py_binary(
name = "debug_mnist",
srcs = ["debug_mnist_v1.py"],
main = "debug_mnist_v1.py",
strict_deps = True,
deps = [
"//tensorflow:tensorflow_py",
"//tensorflow/python/debug:debug_py",
],
)
sh_test(
name = "examples_v1_debug_errors_test",
srcs = ["examples_v1_debug_errors_test.sh"],
data = [
":debug_errors",
],
tags = [
"no_windows",
"noasan", # TODO(b/190625515)
"v1only",
],
)
sh_test(
name = "examples_v1_debug_fibonacci_test",
srcs = ["examples_v1_debug_fibonacci_test.sh"],
data = [
":debug_fibonacci",
],
tags = [
"no_windows",
"v1only",
],
)
sh_test(
name = "examples_v1_debug_keras_test",
size = "medium",
srcs = ["examples_v1_debug_keras_test.sh"],
data = [
":debug_keras",
],
tags = [
"no_windows",
"noasan", # TODO(b/190625515)
"v1only",
],
)
sh_test(
name = "examples_v1_debug_mnist_test",
srcs = ["examples_v1_debug_mnist_test.sh"],
data = [
":debug_mnist",
],
tags = [
"no_windows",
"noasan", # TODO(b/193153560)
"v1only",
],
)
sh_test(
name = "examples_v1_offline_analyzer_test",
srcs = ["examples_v1_offline_analyzer_test.sh"],
data = [
"//tensorflow/python/debug/cli:offline_analyzer",
],
tags = [
"no_windows",
"v1only",
],
)
@@ -0,0 +1,93 @@
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Example of debugging TensorFlow runtime errors using tfdbg."""
import argparse
import sys
import tempfile
import numpy as np
import tensorflow
from tensorflow.python import debug as tf_debug
tf = tensorflow.compat.v1
def main(_):
sess = tf.Session()
# Construct the TensorFlow network.
ph_float = tf.placeholder(tf.float32, name="ph_float")
x = tf.transpose(ph_float, name="x")
v = tf.Variable(np.array([[-2.0], [-3.0], [6.0]], dtype=np.float32), name="v")
m = tf.constant(
np.array([[0.0, 1.0, 2.0], [-4.0, -1.0, 0.0]]),
dtype=tf.float32,
name="m")
y = tf.matmul(m, x, name="y")
z = tf.matmul(m, v, name="z")
if FLAGS.debug:
if FLAGS.use_random_config_path:
_, config_file_path = tempfile.mkstemp(".tfdbg_config")
else:
config_file_path = None
sess = tf_debug.LocalCLIDebugWrapperSession(
sess, ui_type=FLAGS.ui_type, 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]])}))
elif FLAGS.error == "uninitialized_variable":
print(sess.run(z))
elif FLAGS.error == "no_error":
print(sess.run(y, feed_dict={ph_float: np.array([[0.0, 1.0, 2.0]])}))
else:
raise ValueError("Unrecognized error type: " + FLAGS.error)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.register("type", "bool", lambda v: v.lower() == "true")
parser.add_argument(
"--error",
type=str,
default="shape_mismatch",
help="""\
Type of the error to generate (shape_mismatch | uninitialized_variable |
no_error).\
""")
parser.add_argument(
"--ui_type",
type=str,
default="readline",
help="Command-line user interface type (only readline is supported)")
parser.add_argument(
"--debug",
type="bool",
nargs="?",
const=True,
default=False,
help="Use debugger to track down bad values during training")
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.""")
FLAGS, unparsed = parser.parse_known_args()
with tf.Graph().as_default():
tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
@@ -0,0 +1,100 @@
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Demo of the tfdbg readline UI: A TF network computing Fibonacci sequence."""
import argparse
import sys
import numpy as np
import tensorflow
from tensorflow.python import debug as tf_debug
tf = tensorflow.compat.v1
FLAGS = None
def main(_):
sess = tf.Session()
# Construct the TensorFlow network.
n0 = tf.Variable(
np.ones([FLAGS.tensor_size] * 2), dtype=tf.int32, name="node_00")
n1 = tf.Variable(
np.ones([FLAGS.tensor_size] * 2), dtype=tf.int32, name="node_01")
for i in range(2, FLAGS.length):
n0, n1 = n1, tf.add(n0, n1, name="node_%.2d" % i)
sess.run(tf.global_variables_initializer())
# Wrap the TensorFlow Session object for debugging.
if FLAGS.debug and FLAGS.tensorboard_debug_address:
raise ValueError(
"The --debug and --tensorboard_debug_address flags are mutually "
"exclusive.")
if FLAGS.debug:
sess = tf_debug.LocalCLIDebugWrapperSession(sess)
def has_negative(_, tensor):
return np.any(tensor < 0)
sess.add_tensor_filter("has_inf_or_nan", tf_debug.has_inf_or_nan)
sess.add_tensor_filter("has_negative", has_negative)
elif FLAGS.tensorboard_debug_address:
sess = tf_debug.TensorBoardDebugWrapperSession(
sess, FLAGS.tensorboard_debug_address)
print("Fibonacci number at position %d:\n%s" % (FLAGS.length, sess.run(n1)))
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.register("type", "bool", lambda v: v.lower() == "true")
parser.add_argument(
"--tensor_size",
type=int,
default=1,
help="""\
Size of tensor. E.g., if the value is 30, the tensors will have shape
[30, 30].\
""")
parser.add_argument(
"--length",
type=int,
default=20,
help="Length of the fibonacci sequence to compute.")
parser.add_argument(
"--ui_type",
type=str,
default="readline",
help="Command-line user interface type (only readline is supported)")
parser.add_argument(
"--debug",
dest="debug",
action="store_true",
help="Use TensorFlow Debugger (tfdbg). Mutually exclusive with the "
"--tensorboard_debug_address flag.")
parser.add_argument(
"--tensorboard_debug_address",
type=str,
default=None,
help="Connect to the TensorBoard Debugger Plugin backend specified by "
"the gRPC address (e.g., localhost:1234). Mutually exclusive with the "
"--debug flag.")
FLAGS, unparsed = parser.parse_known_args()
with tf.Graph().as_default():
tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
@@ -0,0 +1,102 @@
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""tfdbg example: debugging tf.keras models training on tf.data.Dataset."""
import argparse
import sys
import tempfile
import numpy as np
import tensorflow
from tensorflow.python import debug as tf_debug
tf = tensorflow.compat.v1
def main(_):
# Create a dummy dataset.
num_examples = 8
steps_per_epoch = 2
input_dims = 3
output_dims = 1
xs = np.zeros([num_examples, input_dims])
ys = np.zeros([num_examples, output_dims])
dataset = tf.data.Dataset.from_tensor_slices(
(xs, ys)).repeat(num_examples).batch(int(num_examples / steps_per_epoch))
sess = tf.Session()
if FLAGS.debug:
# Use the command-line interface (CLI) of tfdbg.
if FLAGS.use_random_config_path:
_, config_file_path = tempfile.mkstemp(".tfdbg_config")
else:
config_file_path = 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(
sess, FLAGS.tensorboard_debug_address)
tf.keras.backend.set_session(sess)
# Create a dummy model.
model = tf.keras.Sequential(
[tf.keras.layers.Dense(1, input_shape=[input_dims])])
model.compile(loss="mse", optimizer="sgd")
# Train the model using the dummy dataset created above.
model.fit(dataset, epochs=FLAGS.epochs, steps_per_epoch=steps_per_epoch)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.register("type", "bool", lambda v: v.lower() == "true")
parser.add_argument(
"--debug",
type="bool",
nargs="?",
const=True,
default=False,
help="Use debugger to track down bad values during training. "
"Mutually exclusive with the --tensorboard_debug_address flag.")
parser.add_argument(
"--ui_type",
type=str,
default="readline",
help="Command-line user interface type (only readline is supported).")
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,
default=None,
help="Connect to the TensorBoard Debugger Plugin backend specified by "
"the gRPC address (e.g., localhost:1234). Mutually exclusive with the "
"--debug flag.")
parser.add_argument(
"--epochs",
type=int,
default=2,
help="Number of epochs to train the model for.")
FLAGS, unparsed = parser.parse_known_args()
with tf.Graph().as_default():
tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
@@ -0,0 +1,235 @@
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Demo of the tfdbg readline CLI: Locating the source of bad numerical values.
The neural network in this demo is larged based on the tutorial at:
tensorflow/examples/tutorials/mnist/mnist_with_summaries.py
But modifications are made so that problematic numerical values (infs and nans)
appear in nodes of the graph during training.
"""
import argparse
import sys
import tempfile
import tensorflow
from tensorflow.python import debug as tf_debug
tf = tensorflow.compat.v1
IMAGE_SIZE = 28
HIDDEN_SIZE = 500
NUM_LABELS = 10
RAND_SEED = 42
FLAGS = None
def parse_args():
"""Parses commandline arguments.
Returns:
A tuple (parsed, unparsed) of the parsed object and a group of unparsed
arguments that did not match the parser.
"""
parser = argparse.ArgumentParser()
parser.register("type", "bool", lambda v: v.lower() == "true")
parser.add_argument(
"--max_steps",
type=int,
default=10,
help="Number of steps to run trainer.")
parser.add_argument(
"--train_batch_size",
type=int,
default=100,
help="Batch size used during training.")
parser.add_argument(
"--learning_rate",
type=float,
default=0.025,
help="Initial learning rate.")
parser.add_argument(
"--data_dir",
type=str,
default="/tmp/mnist_data",
help="Directory for storing data")
parser.add_argument(
"--ui_type",
type=str,
default="readline",
help="Command-line user interface type (only readline is supported)")
parser.add_argument(
"--fake_data",
type="bool",
nargs="?",
const=True,
default=False,
help="Use fake MNIST data for unit testing")
parser.add_argument(
"--debug",
type="bool",
nargs="?",
const=True,
default=False,
help="Use debugger to track down bad values during training. "
"Mutually exclusive with the --tensorboard_debug_address flag.")
parser.add_argument(
"--tensorboard_debug_address",
type=str,
default=None,
help="Connect to the TensorBoard Debugger Plugin backend specified by "
"the gRPC address (e.g., localhost:1234). Mutually exclusive with the "
"--debug flag.")
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.""")
return parser.parse_known_args()
def main(_):
# Import data
if FLAGS.fake_data:
imgs = tf.random.uniform(maxval=256, shape=(10, 28, 28), dtype=tf.int32)
labels = tf.random.uniform(maxval=10, shape=(10,), dtype=tf.int32)
mnist_train = imgs, labels
mnist_test = imgs, labels
else:
mnist_train, mnist_test = tf.keras.datasets.mnist.load_data()
def format_example(imgs, labels):
imgs = tf.reshape(imgs, [-1, 28 * 28])
imgs = tf.cast(imgs, tf.float32) / 255.0
labels = tf.one_hot(labels, depth=10, dtype=tf.float32)
return imgs, labels
ds_train = tf.data.Dataset.from_tensor_slices(mnist_train)
ds_train = ds_train.shuffle(
1000, seed=RAND_SEED).repeat().batch(FLAGS.train_batch_size)
ds_train = ds_train.map(format_example)
it_train = ds_train.make_initializable_iterator()
ds_test = tf.data.Dataset.from_tensors(mnist_test).repeat()
ds_test = ds_test.map(format_example)
it_test = ds_test.make_initializable_iterator()
sess = tf.InteractiveSession()
# Create the MNIST neural network graph.
# Input placeholders.
with tf.name_scope("input"):
handle = tf.placeholder(tf.string, shape=())
iterator = tf.data.Iterator.from_string_handle(
handle, (tf.float32, tf.float32),
((None, IMAGE_SIZE * IMAGE_SIZE), (None, 10)))
x, y_ = iterator.get_next()
def weight_variable(shape):
"""Create a weight variable with appropriate initialization."""
initial = tf.truncated_normal(shape, stddev=0.1, seed=RAND_SEED)
return tf.Variable(initial)
def bias_variable(shape):
"""Create a bias variable with appropriate initialization."""
initial = tf.constant(0.1, shape=shape)
return tf.Variable(initial)
def nn_layer(input_tensor, input_dim, output_dim, layer_name, act=tf.nn.relu):
"""Reusable code for making a simple neural net layer."""
# Adding a name scope ensures logical grouping of the layers in the graph.
with tf.name_scope(layer_name):
# This Variable will hold the state of the weights for the layer
with tf.name_scope("weights"):
weights = weight_variable([input_dim, output_dim])
with tf.name_scope("biases"):
biases = bias_variable([output_dim])
with tf.name_scope("Wx_plus_b"):
preactivate = tf.matmul(input_tensor, weights) + biases
activations = act(preactivate)
return activations
hidden = nn_layer(x, IMAGE_SIZE**2, HIDDEN_SIZE, "hidden")
logits = nn_layer(hidden, HIDDEN_SIZE, NUM_LABELS, "output", tf.identity)
y = tf.nn.softmax(logits)
with tf.name_scope("cross_entropy"):
# The following line is the culprit of the bad numerical values that appear
# during training of this graph. Log of zero gives inf, which is first seen
# in the intermediate tensor "cross_entropy/Log:0" during the 4th run()
# call. A multiplication of the inf values with zeros leads to nans,
# which is first in "cross_entropy/mul:0".
#
# You can use the built-in, numerically-stable implementation to fix this
# issue:
# diff = tf.nn.softmax_cross_entropy_with_logits(labels=y_, logits=logits)
diff = -(y_ * tf.log(y))
with tf.name_scope("total"):
cross_entropy = tf.reduce_mean(diff)
with tf.name_scope("train"):
train_step = tf.train.AdamOptimizer(
FLAGS.learning_rate).minimize(cross_entropy)
with tf.name_scope("accuracy"):
with tf.name_scope("correct_prediction"):
correct_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1))
with tf.name_scope("accuracy"):
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
sess.run(tf.global_variables_initializer())
sess.run(it_train.initializer)
sess.run(it_test.initializer)
train_handle = sess.run(it_train.string_handle())
test_handle = sess.run(it_test.string_handle())
if FLAGS.debug and FLAGS.tensorboard_debug_address:
raise ValueError(
"The --debug and --tensorboard_debug_address flags are mutually "
"exclusive.")
if FLAGS.debug:
if FLAGS.use_random_config_path:
_, config_file_path = tempfile.mkstemp(".tfdbg_config")
else:
config_file_path = None
sess = tf_debug.LocalCLIDebugWrapperSession(
sess, ui_type=FLAGS.ui_type, config_file_path=config_file_path)
elif FLAGS.tensorboard_debug_address:
sess = tf_debug.TensorBoardDebugWrapperSession(
sess, FLAGS.tensorboard_debug_address)
# Add this point, sess is a debug wrapper around the actual Session if
# FLAGS.debug is true. In that case, calling run() will launch the CLI.
for i in range(FLAGS.max_steps):
acc = sess.run(accuracy, feed_dict={handle: test_handle})
print("Accuracy at step %d: %s" % (i, acc))
sess.run(train_step, feed_dict={handle: train_handle})
if __name__ == "__main__":
FLAGS, unparsed = parse_args()
with tf.Graph().as_default():
tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
@@ -0,0 +1,66 @@
#!/bin/bash
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
#
# Bash unit tests for TensorFlow Debugger (tfdbg) Python examples that do not
# involve downloading data.
#
# Command-line flags:
# --virtualenv: (optional) If set, will test the examples and binaries
# against pip install of TensorFlow in a virtualenv.
set -e
# Filter out LOG(INFO)
export TF_CPP_MIN_LOG_LEVEL=1
IS_VIRTUALENV=0
PYTHON_BIN_PATH=""
while true; do
if [[ -z "$1" ]]; then
break
elif [[ "$1" == "--virtualenv" ]]; then
IS_VIRTUALENV=1
PYTHON_BIN_PATH=$(which python)
echo
echo "IS_VIRTUALENV = ${IS_VIRTUALENV}"
echo "PYTHON_BIN_PATH = ${PYTHON_BIN_PATH}"
echo "Will test tfdbg debug_errors against virtualenv pip install."
echo
fi
shift 1
done
if [[ -z "${PYTHON_BIN_PATH}" ]]; then
DEBUG_ERRORS_BIN="$TEST_SRCDIR/org_tensorflow/tensorflow/python/debug/examples/v1/debug_errors"
else
DEBUG_ERRORS_BIN="${PYTHON_BIN_PATH} -m tensorflow.python.debug.examples.v1.debug_errors"
fi
# Override the default ui_type=curses to allow the test to pass in a tty-less
# test environment.
cat << EOF | ${DEBUG_ERRORS_BIN} --error=no_error --ui_type=readline
run
exit
EOF
cat << EOF | ${DEBUG_ERRORS_BIN} --error=uninitialized_variable --debug --ui_type=readline --use_random_config_path
run
ni -a -d -t v/read
exit
EOF
echo
echo "SUCCESS: tfdbg debug_errors test PASSED"
@@ -0,0 +1,60 @@
#!/bin/bash
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
#
# Bash unit tests for TensorFlow Debugger (tfdbg) Python examples that do not
# involve downloading data.
#
# Command-line flags:
# --virtualenv: (optional) If set, will test the examples and binaries
# against pip install of TensorFlow in a virtualenv.
set -e
# Filter out LOG(INFO)
export TF_CPP_MIN_LOG_LEVEL=1
IS_VIRTUALENV=0
PYTHON_BIN_PATH=""
while true; do
if [[ -z "$1" ]]; then
break
elif [[ "$1" == "--virtualenv" ]]; then
IS_VIRTUALENV=1
PYTHON_BIN_PATH=$(which python)
echo
echo "IS_VIRTUALENV = ${IS_VIRTUALENV}"
echo "PYTHON_BIN_PATH = ${PYTHON_BIN_PATH}"
echo "Will test tfdbg debug_fibonacci against virtualenv pip install."
echo
fi
shift 1
done
if [[ -z "${PYTHON_BIN_PATH}" ]]; then
DEBUG_FIBONACCI_BIN="$TEST_SRCDIR/org_tensorflow/tensorflow/python/debug/examples/v1/debug_fibonacci"
else
DEBUG_FIBONACCI_BIN="${PYTHON_BIN_PATH} -m tensorflow.python.debug.examples.v1.debug_fibonacci"
fi
# Override the default ui_type=curses to allow the test to pass in a tty-less
# test environment.
cat << EOF | ${DEBUG_FIBONACCI_BIN} --tensor_size=2 --ui_type=readline
run
exit
EOF
echo
echo "SUCCESS: tfdbg debug_fibonacci test PASSED"
@@ -0,0 +1,66 @@
#!/bin/bash
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
#
# Bash unit tests for TensorFlow Debugger (tfdbg) Python examples that do not
# involve downloading data.
#
# Command-line flags:
# --virtualenv: (optional) If set, will test the examples and binaries
# against pip install of TensorFlow in a virtualenv.
set -e
# Filter out LOG(INFO)
export TF_CPP_MIN_LOG_LEVEL=1
IS_VIRTUALENV=0
PYTHON_BIN_PATH=""
while true; do
if [[ -z "$1" ]]; then
break
elif [[ "$1" == "--virtualenv" ]]; then
IS_VIRTUALENV=1
PYTHON_BIN_PATH=$(which python)
echo
echo "IS_VIRTUALENV = ${IS_VIRTUALENV}"
echo "PYTHON_BIN_PATH = ${PYTHON_BIN_PATH}"
echo "Will test tfdbg debug_keras against virtualenv pip install."
echo
fi
shift 1
done
if [[ -z "${PYTHON_BIN_PATH}" ]]; then
DEBUG_KERAS_BIN="$TEST_SRCDIR/org_tensorflow/tensorflow/python/debug/examples/v1/debug_keras"
else
DEBUG_KERAS_BIN="${PYTHON_BIN_PATH} -m tensorflow.python.debug.examples.v1.debug_keras"
fi
# Override the default ui_type=curses to allow the test to pass in a tty-less
# test environment.
# Test debugging of tf.keras.
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 --use_random_config_path
run -t 11
EOF
echo
echo "SUCCESS: tfdbg debug_keras test PASSED"
@@ -0,0 +1,61 @@
#!/bin/bash
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
#
# Bash unit tests for TensorFlow Debugger (tfdbg) Python examples that do not
# involve downloading data.
#
# Command-line flags:
# --virtualenv: (optional) If set, will test the examples and binaries
# against pip install of TensorFlow in a virtualenv.
set -e
# Filter out LOG(INFO)
export TF_CPP_MIN_LOG_LEVEL=1
IS_VIRTUALENV=0
PYTHON_BIN_PATH=""
while true; do
if [[ -z "$1" ]]; then
break
elif [[ "$1" == "--virtualenv" ]]; then
IS_VIRTUALENV=1
PYTHON_BIN_PATH=$(which python)
echo
echo "IS_VIRTUALENV = ${IS_VIRTUALENV}"
echo "PYTHON_BIN_PATH = ${PYTHON_BIN_PATH}"
echo "Will test tfdbg examples and binaries against virtualenv pip install."
echo
fi
shift 1
done
if [[ -z "${PYTHON_BIN_PATH}" ]]; then
DEBUG_MNIST_BIN="$TEST_SRCDIR/org_tensorflow/tensorflow/python/debug/examples/v1/debug_mnist"
else
DEBUG_MNIST_BIN="${PYTHON_BIN_PATH} -m tensorflow.python.debug.examples.v1.debug_mnist"
fi
# Override the default ui_type=curses to allow the test to pass in a tty-less
# test environment.
cat << EOF | ${DEBUG_MNIST_BIN} --debug --max_steps=1 --fake_data --ui_type=readline --use_random_config_path
run -t 1
run --node_name_filter hidden --op_type_filter MatMul
run -f has_inf_or_nan
EOF
echo
echo "SUCCESS: tfdbg debug_mnist test PASSED"
@@ -0,0 +1,70 @@
#!/bin/bash
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
#
# Bash unit tests for the binary offline_analyzer.
#
# Command-line flags:
# --virtualenv: (optional) If set, will test the examples and binaries
# against pip install of TensorFlow in a virtualenv.
set -e
# Filter out LOG(INFO)
export TF_CPP_MIN_LOG_LEVEL=1
IS_VIRTUALENV=0
PYTHON_BIN_PATH=""
while true; do
if [[ -z "$1" ]]; then
break
elif [[ "$1" == "--virtualenv" ]]; then
IS_VIRTUALENV=1
PYTHON_BIN_PATH=$(which python)
echo
echo "IS_VIRTUALENV = ${IS_VIRTUALENV}"
echo "PYTHON_BIN_PATH = ${PYTHON_BIN_PATH}"
echo "Will test tfdbg offline analyzer against virtualenv pip install."
echo
fi
shift 1
done
if [[ -z "${PYTHON_BIN_PATH}" ]]; then
OFFLINE_ANALYZER_BIN="$TEST_SRCDIR/org_tensorflow/tensorflow/python/debug/cli/offline_analyzer"
else
OFFLINE_ANALYZER_BIN="${PYTHON_BIN_PATH} -m tensorflow.python.debug.cli.offline_analyzer"
fi
# Test offline_analyzer.
echo
echo "Testing offline_analyzer"
echo
# TODO(cais): Generate an actual debug dump and load it with offline_analyzer,
# so that we can test the binary runs with a non-error exit code.
set +e
OUTPUT=$(${OFFLINE_ANALYZER_BIN} 2>&1)
set -e
EXPECTED_OUTPUT="ERROR: dump_dir flag is empty."
if ! echo "${OUTPUT}" | grep -q "${EXPECTED_OUTPUT}"; then
echo "ERROR: offline_analyzer output didn't match expectation: ${OUTPUT}" 1>&2
echo "Expected output: ${EXPECTED_OUTPUT}"
exit 1
fi
echo
echo "SUCCESS: tfdbg offline analyzer test PASSED"
+130
View File
@@ -0,0 +1,130 @@
#!/bin/bash
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
#
# Bash unit tests for TensorFlow Debugger (tfdbg) Python examples that do not
# involve downloading data. Also tests the binary offline_analyzer.
#
# Command-line flags:
# --virtualenv: (optional) If set, will test the examples and binaries
# against pip install of TensorFlow in a virtualenv.
set -e
# Filter out LOG(INFO)
export TF_CPP_MIN_LOG_LEVEL=1
IS_VIRTUALENV=0
PYTHON_BIN_PATH=""
while true; do
if [[ -z "$1" ]]; then
break
elif [[ "$1" == "--virtualenv" ]]; then
IS_VIRTUALENV=1
PYTHON_BIN_PATH=$(which python)
echo
echo "IS_VIRTUALENV = ${IS_VIRTUALENV}"
echo "PYTHON_BIN_PATH = ${PYTHON_BIN_PATH}"
echo "Will test tfdbg examples and binaries against virtualenv pip install."
echo
fi
shift 1
done
if [[ -z "${PYTHON_BIN_PATH}" ]]; then
DEBUG_FIBONACCI_BIN="$TEST_SRCDIR/org_tensorflow/tensorflow/python/debug/examples/v1/debug_fibonacci"
DEBUG_ERRORS_BIN="$TEST_SRCDIR/org_tensorflow/tensorflow/python/debug/examples/v1/debug_errors"
DEBUG_MNIST_BIN="$TEST_SRCDIR/org_tensorflow/tensorflow/python/debug/examples/v1/debug_mnist"
DEBUG_TFLEARN_IRIS_BIN="$TEST_SRCDIR/org_tensorflow/tensorflow/python/debug/examples/v1/debug_tflearn_iris"
DEBUG_KERAS_BIN="$TEST_SRCDIR/org_tensorflow/tensorflow/python/debug/examples/v1/debug_keras"
OFFLINE_ANALYZER_BIN="$TEST_SRCDIR/org_tensorflow/tensorflow/python/debug/cli/offline_analyzer"
else
DEBUG_FIBONACCI_BIN="${PYTHON_BIN_PATH} -m tensorflow.python.debug.examples.v1.debug_fibonacci"
DEBUG_ERRORS_BIN="${PYTHON_BIN_PATH} -m tensorflow.python.debug.examples.v1.debug_errors"
DEBUG_MNIST_BIN="${PYTHON_BIN_PATH} -m tensorflow.python.debug.examples.v1.debug_mnist"
DEBUG_TFLEARN_IRIS_BIN="${PYTHON_BIN_PATH} -m tensorflow.python.debug.examples.v1.debug_tflearn_iris"
DEBUG_KERAS_BIN="${PYTHON_BIN_PATH} -m tensorflow.python.debug.examples.v1.debug_keras"
OFFLINE_ANALYZER_BIN="${PYTHON_BIN_PATH} -m tensorflow.python.debug.cli.offline_analyzer"
fi
# Override the default ui_type=curses to allow the test to pass in a tty-less
# test environment.
cat << EOF | ${DEBUG_FIBONACCI_BIN} --tensor_size=2 --ui_type=readline
run
exit
EOF
cat << EOF | ${DEBUG_ERRORS_BIN} --error=no_error --ui_type=readline
run
exit
EOF
cat << EOF | ${DEBUG_ERRORS_BIN} --error=uninitialized_variable --debug --ui_type=readline --use_random_config_path
run
ni -a -d -t v/read
exit
EOF
cat << EOF | ${DEBUG_MNIST_BIN} --debug --max_steps=1 --fake_data --ui_type=readline --use_random_config_path
run -t 1
run --node_name_filter hidden --op_type_filter MatMul
run -f has_inf_or_nan
EOF
# Test the custom dump_root option.
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 --use_random_config_path
run -p
run -f has_inf_or_nan
EOF
# Verify that the dump root has been cleaned up on exit.
if [[ -d "${CUSTOM_DUMP_ROOT}" ]]; then
echo "ERROR: dump root at ${CUSTOM_DUMP_ROOT} failed to be cleaned up." 1>&2
exit 1
fi
# Test debugging of tf.keras.
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 --use_random_config_path
run -t 11
EOF
# Test offline_analyzer.
echo
echo "Testing offline_analyzer"
echo
# TODO(cais): Generate an actual debug dump and load it with offline_analyzer,
# so that we can test the binary runs with a non-error exit code.
set +e
OUTPUT=$(${OFFLINE_ANALYZER_BIN} 2>&1)
set -e
EXPECTED_OUTPUT="ERROR: dump_dir flag is empty."
if ! echo "${OUTPUT}" | grep -q "${EXPECTED_OUTPUT}"; then
echo "ERROR: offline_analyzer output didn't match expectation: ${OUTPUT}" 1>&2
echo "Expected output: ${EXPECTED_OUTPUT}"
exit 1
fi
echo
echo "SUCCESS: tfdbg examples and binaries test PASSED"