Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cherry-pick] tfdbg: fix a bug in graph validation related to tf.while_loops #8869

Merged
merged 3 commits into from Mar 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions tensorflow/python/debug/BUILD
Expand Up @@ -485,7 +485,9 @@ py_library(
"//tensorflow/python:math_ops",
"//tensorflow/python:parsing_ops",
"//tensorflow/python:platform_test",
"//tensorflow/python:rnn",
"//tensorflow/python:state_ops",
"//tensorflow/python:tensor_array_grad",
"//tensorflow/python:training",
"//tensorflow/python:variables",
"//third_party/py/numpy",
Expand Down
4 changes: 4 additions & 0 deletions tensorflow/python/debug/lib/debug_data.py
Expand Up @@ -934,8 +934,12 @@ def _validate_dump_with_graphs(self):
for inp in inputs:
inp_node = get_node_name(inp)
inp_output_slot = get_output_slot(inp)
# Inputs from Enter and NextIteration nodes are not validated because
# DebugNodeInserter::InsertNodes() in the debugger core skips creating
# control edges from debug ops watching these types of nodes.
if (inp_node in self._debug_watches and
inp_output_slot in self._debug_watches[inp_node] and
self._node_op_types.get(inp) not in ("Enter", "NextIteration") and
(inp_node, inp_output_slot) not in pending_inputs[node]):
pending_inputs[node].append((inp_node, inp_output_slot))

Expand Down
58 changes: 58 additions & 0 deletions tensorflow/python/debug/lib/session_debug_testlib.py
Expand Up @@ -43,13 +43,36 @@
from tensorflow.python.ops import data_flow_ops
from tensorflow.python.ops import math_ops
from tensorflow.python.ops import parsing_ops
from tensorflow.python.ops import rnn
from tensorflow.python.ops import rnn_cell_impl
from tensorflow.python.ops import state_ops
from tensorflow.python.ops import variables
import tensorflow.python.ops.tensor_array_grad # pylint: disable=unused-import
from tensorflow.python.platform import googletest
from tensorflow.python.platform import test
from tensorflow.python.training import gradient_descent


class _RNNCellForTest(rnn_cell_impl._RNNCell): # pylint: disable=protected-access
"""RNN cell for testing."""

def __init__(self, input_output_size, state_size):
self._input_output_size = input_output_size
self._state_size = state_size
self._w = variables.Variable(1.0, dtype=dtypes.float32, name="w")

@property
def output_size(self):
return self._input_output_size

@property
def state_size(self):
return self._state_size

def __call__(self, input_, state, scope=None):
return (math_ops.multiply(self._w, input_), state)


class SessionDebugTestBase(test_util.TensorFlowTestCase):
"""Base class for unit tests of tfdbg running with tf.Session."""

Expand Down Expand Up @@ -436,6 +459,41 @@ def testDebugWhileLoopWatchingWholeGraphWorks(self):
[[12], [14], [16]],
dump.get_tensors("while/NextIteration", 0, "DebugIdentity"))

def testDebugTrainingDynamicRNNWorks(self):
with session.Session() as sess:
input_size = 3
state_size = 2
time_steps = 4
batch_size = 2

input_values = np.random.randn(time_steps, batch_size, input_size)
sequence_length = np.random.randint(0, time_steps, size=batch_size)
concat_inputs = array_ops.placeholder(
dtypes.float32, shape=(time_steps, batch_size, input_size))

outputs_dynamic, _ = rnn.dynamic_rnn(
_RNNCellForTest(input_size, state_size),
inputs=concat_inputs,
sequence_length=sequence_length,
time_major=True,
dtype=dtypes.float32)
toy_loss = math_ops.reduce_sum(outputs_dynamic * outputs_dynamic)
train_op = gradient_descent.GradientDescentOptimizer(
learning_rate=0.1).minimize(toy_loss, name="train_op")

sess.run(variables.global_variables_initializer())

run_options = config_pb2.RunOptions(output_partition_graphs=True)
debug_utils.watch_graph(run_options,
sess.graph,
debug_urls=self._debug_urls())
run_metadata = config_pb2.RunMetadata()
sess.run(train_op, feed_dict={concat_inputs: input_values},
options=run_options, run_metadata=run_metadata)

debug_data.DebugDumpDir(
self._dump_root, partition_graphs=run_metadata.partition_graphs)

def testDebugCondWatchingWholeGraphWorks(self):
with session.Session() as sess:
x = variables.Variable(10.0, name="x")
Expand Down