{"action":"opened","issue":{"url":"https://api.github.com/repos/tensorflow/tensorflow/issues/6058","repository_url":"https://api.github.com/repos/tensorflow/tensorflow","labels_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/6058/labels{/name}","comments_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/6058/comments","events_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/6058/events","html_url":"https://github.com/tensorflow/tensorflow/issues/6058","id":193315008,"number":6058,"title":"tf.cond() + tf.dynamic_rnn() gives AttributeError: 'NoneType' object has no attribute 'pivot'","user":{"login":"wengong-jin","id":2518060,"avatar_url":"https://avatars.githubusercontent.com/u/2518060?v=3","gravatar_id":"","url":"https://api.github.com/users/wengong-jin","html_url":"https://github.com/wengong-jin","followers_url":"https://api.github.com/users/wengong-jin/followers","following_url":"https://api.github.com/users/wengong-jin/following{/other_user}","gists_url":"https://api.github.com/users/wengong-jin/gists{/gist_id}","starred_url":"https://api.github.com/users/wengong-jin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wengong-jin/subscriptions","organizations_url":"https://api.github.com/users/wengong-jin/orgs","repos_url":"https://api.github.com/users/wengong-jin/repos","events_url":"https://api.github.com/users/wengong-jin/events{/privacy}","received_events_url":"https://api.github.com/users/wengong-jin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-12-03T21:35:52Z","updated_at":"2016-12-03T21:35:52Z","closed_at":null,"body":"### Environment info\r\nOperating System: ubuntu 14.04.5\r\nInstalled version of CUDA and cuDNN: cuda7.5 + cuDNNv5\r\nInstalled from pip package: 0.11.0rc0\r\n\r\n### Code\r\n```python\r\nimport tensorflow as tf\r\n\r\ndef linear(input_, output_size, scope, init_bias=0.0):\r\n    shape = input_.get_shape().as_list()\r\n    with tf.variable_scope(scope):\r\n        W = tf.get_variable(\"Matrix\", [shape[-1], output_size], tf.float32, tf.random_normal_initializer(stddev=1.0 / math.sqrt(shape[-1])))\r\n    with tf.variable_scope(scope):\r\n        b = tf.get_variable(\"bias\", [output_size], initializer=tf.constant_initializer(init_bias))\r\n    return tf.matmul(input_, W) + b\r\n\r\nbatch_size = 64\r\nhidden_size = 300\r\nvocab_size = 10000\r\n\r\nsession = tf.Session()\r\nsource = tf.placeholder(tf.float32, [batch_size, 10, hidden_size])\r\nsrc_len = tf.placeholder(tf.int32, [batch_size])\r\nenc_holder = tf.placeholder(tf.float32, [batch_size, hidden_size])\r\ndecode_mode = tf.placeholder(tf.bool)\r\nlabel = tf.placeholder(tf.int32, [batch_size])\r\n\r\ndef encoder():\r\n    src_cell = tf.nn.rnn_cell.GRUCell(hidden_size)\r\n    src_init = src_cell.zero_state(batch_size, tf.float32)\r\n    src_hiddens, src_final = tf.nn.dynamic_rnn(src_cell, source, initial_state=src_init, sequence_length=src_len, scope=\"encoder\")\r\n    return src_final\r\n\r\ndecode_state = tf.cond(decode_mode, lambda:enc_holder, lambda:encoder())\r\noutputs = linear(decode_state, vocab_size, \"output\")\r\nloss = tf.nn.sparse_softmax_cross_entropy_with_logits(outputs, label)\r\noptimizer = tf.train.AdamOptimizer().minimize(loss)\r\n```\r\n\r\n## Error Message:\r\n```\r\nTraceback (most recent call last):\r\n  File \"issue.py\", line 33, in <module>\r\n    optimizer = tf.train.AdamOptimizer().minimize(loss)\r\n  File \"~/anaconda2/lib/python2.7/site-packages/tensorflow/python/training/optimizer.py\", line 196, in minimize\r\n    grad_loss=grad_loss)\r\n  File \"~/anaconda2/lib/python2.7/site-packages/tensorflow/python/training/optimizer.py\", line 253, in compute_gradients\r\n    colocate_gradients_with_ops=colocate_gradients_with_ops)\r\n  File \"~/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/gradients.py\", line 469, in gradients\r\n    in_grads = _AsList(grad_fn(op, *out_grads))\r\n  File \"~/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/control_flow_grad.py\", line 91, in _MergeGrad\r\n    return control_flow_ops._SwitchRefOrTensor(grad, grad_ctxt.pivot)\r\nAttributeError: 'NoneType' object has no attribute 'pivot'\r\n```\r\n## Note\r\nIf I change the line \r\n```python\r\ndecode_state = tf.cond(decode_mode, lambda:enc_holder, lambda:encoder())\r\n```\r\nto\r\n```python\r\ndecode_state = tf.cond(decode_mode, lambda:enc_holder, lambda:enc_holder)\r\n```\r\nor\r\n```python\r\ndecode_state = encoder()\r\n```\r\nNo error thrown. So I guess there must be something wrong when tf.cond() + tf.dynamic_rnn() is combined. "}}
{"actor":{"display_login":"wengong-jin"}}