{"action":"closed","issue":{"url":"https://api.github.com/repos/tensorflow/tensorflow/issues/11162","repository_url":"https://api.github.com/repos/tensorflow/tensorflow","labels_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/11162/labels{/name}","comments_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/11162/comments","events_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/11162/events","html_url":"https://github.com/tensorflow/tensorflow/issues/11162","id":239670708,"number":11162,"title":"Rank mismatch error when using contrib.seq2seq.AttentionWrapper in a dynamic_rnn with sequence_length","user":{"login":"dgaddy","id":2405798,"avatar_url":"https://avatars0.githubusercontent.com/u/2405798?v=3","gravatar_id":"","url":"https://api.github.com/users/dgaddy","html_url":"https://github.com/dgaddy","followers_url":"https://api.github.com/users/dgaddy/followers","following_url":"https://api.github.com/users/dgaddy/following{/other_user}","gists_url":"https://api.github.com/users/dgaddy/gists{/gist_id}","starred_url":"https://api.github.com/users/dgaddy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dgaddy/subscriptions","organizations_url":"https://api.github.com/users/dgaddy/orgs","repos_url":"https://api.github.com/users/dgaddy/repos","events_url":"https://api.github.com/users/dgaddy/events{/privacy}","received_events_url":"https://api.github.com/users/dgaddy/received_events","type":"User","site_admin":false},"labels":[{"id":473184161,"url":"https://api.github.com/repos/tensorflow/tensorflow/labels/type:support","name":"type:support","color":"b60205","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-06-30T03:51:30Z","updated_at":"2017-06-30T23:54:58Z","closed_at":"2017-06-30T23:54:58Z","body":"### System information\r\nLinux Ubuntu 16.04\r\nTensorFlow installed from pip binary\r\nTensorFlow version 1.2.0 (v1.2.0-rc2-21-g12f033d)\r\nPython 3.6.1 Anaconda 4.4.0\r\nCUDA 8.0 / cuDNN 5.1\r\nTITAN X (Pascal) 11.9GB\r\n\r\n### Describe the problem\r\n\r\nError: `Shapes must be equal rank, but are 0 and 1 for 'rnn/while/Select_4' (op: 'Select') with input shapes: [10], [], [].` when using `tf.contrib.seq2seq.AttentionWrapper` in a `dynamic_rnn` with `seqence_length` provided.\r\n\r\nCode to reproduce:\r\n\r\n```\r\nimport tensorflow as tf\r\nfrom tensorflow.contrib.rnn import LSTMCell, MultiRNNCell\r\nimport numpy as np\r\n\r\nencoder_outputs = tf.constant(np.random.rand(10,20,512).astype(np.float32))\r\ndecoder_inputs = tf.constant(np.random.rand(10,20,512).astype(np.float32))\r\nlengths = tf.constant(np.random.randint(5,20,(10,),dtype=np.int32))\r\n\r\ncell = LSTMCell(512)\r\nattention_mechanism = tf.contrib.seq2seq.LuongAttention(512, encoder_outputs)\r\nattn_cell = tf.contrib.seq2seq.AttentionWrapper(\r\n          cell, attention_mechanism, attention_layer_size=256)\r\n\r\no, s = tf.nn.dynamic_rnn(attn_cell, decoder_inputs, lengths, dtype=tf.float32)\r\n# this works: o, s = tf.nn.dynamic_rnn(attn_cell, decoder_inputs, dtype=tf.float32)\r\n# this works: o, s = tf.nn.dynamic_rnn(cell, decoder_inputs, lengths, dtype=tf.float32)\r\n\r\nwith tf.Session() as sess:\r\n    tf.global_variables_initializer().run()\r\n    sess.run(o)\r\n```\r\n\r\n### Traceback\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"/home/dgaddy/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/common_shapes.py\", line 671, in _call_cpp_shape_fn_impl\r\n    input_tensors_as_shapes, status)\r\n  File \"/home/dgaddy/anaconda3/lib/python3.6/contextlib.py\", line 89, in __exit__\r\n    next(self.gen)\r\n  File \"/home/dgaddy/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/errors_impl.py\", line 466, in raise_exception_on_not_ok_status\r\n    pywrap_tensorflow.TF_GetCode(status))\r\ntensorflow.python.framework.errors_impl.InvalidArgumentError: Shapes must be equal rank, but are 0 and 1 for 'rnn/while/Select_4' (op: 'Select') with input shapes: [10], [], [].\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n  File \"test.py\", line 14, in <module>\r\n    o, s = tf.nn.dynamic_rnn(attn_cell, decoder_inputs, lengths, dtype=tf.float32)\r\n  File \"/home/dgaddy/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/rnn.py\", line 574, in dynamic_rnn\r\n    dtype=dtype)\r\n  File \"/home/dgaddy/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/rnn.py\", line 737, in _dynamic_rnn_loop\r\n    swap_memory=swap_memory)\r\n  File \"/home/dgaddy/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py\", line 2770, in while_loop\r\n    result = context.BuildLoop(cond, body, loop_vars, shape_invariants)\r\n  File \"/home/dgaddy/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py\", line 2599, in BuildLoop\r\n    pred, body, original_loop_vars, loop_vars, shape_invariants)\r\n  File \"/home/dgaddy/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py\", line 2549, in _BuildLoop\r\n    body_result = body(*packed_vars_for_body)\r\n  File \"/home/dgaddy/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/rnn.py\", line 720, in _time_step\r\n    skip_conditionals=True)\r\n  File \"/home/dgaddy/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/rnn.py\", line 210, in _rnn_step\r\n    final_output_and_state = _copy_some_through(new_output, new_state)\r\n  File \"/home/dgaddy/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/rnn.py\", line 182, in _copy_some_through\r\n    for state, new_state in zip(flat_state, flat_new_state)]\r\n  File \"/home/dgaddy/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/rnn.py\", line 182, in <listcomp>\r\n    for state, new_state in zip(flat_state, flat_new_state)]\r\n  File \"/home/dgaddy/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/rnn.py\", line 171, in _copy_one_through\r\n    return array_ops.where(copy_cond, output, new_output)\r\n  File \"/home/dgaddy/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/array_ops.py\", line 2328, in where\r\n    return gen_math_ops._select(condition=condition, t=x, e=y, name=name)\r\n  File \"/home/dgaddy/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/gen_math_ops.py\", line 2145, in _select\r\n    name=name)\r\n  File \"/home/dgaddy/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py\", line 767, in apply_op\r\n    op_def=op_def)\r\n  File \"/home/dgaddy/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py\", line 2508, in create_op\r\n    set_shapes_for_outputs(ret)\r\n  File \"/home/dgaddy/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py\", line 1873, in set_shapes_for_outputs\r\n    shapes = shape_func(op)\r\n  File \"/home/dgaddy/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py\", line 1823, in call_with_requiring\r\n    return call_cpp_shape_fn(op, require_shape_fn=True)\r\n  File \"/home/dgaddy/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/common_shapes.py\", line 610, in call_cpp_shape_fn\r\n    debug_python_shape_fn, require_shape_fn)\r\n  File \"/home/dgaddy/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/common_shapes.py\", line 676, in _call_cpp_shape_fn_impl\r\n    raise ValueError(err.message)\r\nValueError: Shapes must be equal rank, but are 0 and 1 for 'rnn/while/Select_4' (op: 'Select') with input shapes: [10], [], [].\r\n```"}}
{"actor":{"display_login":"ali01"}}