{"action":"created","issue":{"url":"https://api.github.com/repos/tensorflow/tensorflow/issues/21224","repository_url":"https://api.github.com/repos/tensorflow/tensorflow","labels_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/21224/labels{/name}","comments_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/21224/comments","events_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/21224/events","html_url":"https://github.com/tensorflow/tensorflow/issues/21224","id":345545477,"node_id":"MDU6SXNzdWUzNDU1NDU0Nzc=","number":21224,"title":"tf.while_loop - Eager mode allows a changing input size by default, while Graph mode does not","user":{"login":"RanFeldesh","id":8627404,"node_id":"MDQ6VXNlcjg2Mjc0MDQ=","avatar_url":"https://avatars1.githubusercontent.com/u/8627404?v=4","gravatar_id":"","url":"https://api.github.com/users/RanFeldesh","html_url":"https://github.com/RanFeldesh","followers_url":"https://api.github.com/users/RanFeldesh/followers","following_url":"https://api.github.com/users/RanFeldesh/following{/other_user}","gists_url":"https://api.github.com/users/RanFeldesh/gists{/gist_id}","starred_url":"https://api.github.com/users/RanFeldesh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RanFeldesh/subscriptions","organizations_url":"https://api.github.com/users/RanFeldesh/orgs","repos_url":"https://api.github.com/users/RanFeldesh/repos","events_url":"https://api.github.com/users/RanFeldesh/events{/privacy}","received_events_url":"https://api.github.com/users/RanFeldesh/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"jart","id":49262,"node_id":"MDQ6VXNlcjQ5MjYy","avatar_url":"https://avatars1.githubusercontent.com/u/49262?v=4","gravatar_id":"","url":"https://api.github.com/users/jart","html_url":"https://github.com/jart","followers_url":"https://api.github.com/users/jart/followers","following_url":"https://api.github.com/users/jart/following{/other_user}","gists_url":"https://api.github.com/users/jart/gists{/gist_id}","starred_url":"https://api.github.com/users/jart/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jart/subscriptions","organizations_url":"https://api.github.com/users/jart/orgs","repos_url":"https://api.github.com/users/jart/repos","events_url":"https://api.github.com/users/jart/events{/privacy}","received_events_url":"https://api.github.com/users/jart/received_events","type":"User","site_admin":false},"assignees":[{"login":"jart","id":49262,"node_id":"MDQ6VXNlcjQ5MjYy","avatar_url":"https://avatars1.githubusercontent.com/u/49262?v=4","gravatar_id":"","url":"https://api.github.com/users/jart","html_url":"https://github.com/jart","followers_url":"https://api.github.com/users/jart/followers","following_url":"https://api.github.com/users/jart/following{/other_user}","gists_url":"https://api.github.com/users/jart/gists{/gist_id}","starred_url":"https://api.github.com/users/jart/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jart/subscriptions","organizations_url":"https://api.github.com/users/jart/orgs","repos_url":"https://api.github.com/users/jart/repos","events_url":"https://api.github.com/users/jart/events{/privacy}","received_events_url":"https://api.github.com/users/jart/received_events","type":"User","site_admin":false}],"milestone":null,"comments":2,"created_at":"2018-07-29T16:52:29Z","updated_at":"2018-11-29T19:12:48Z","closed_at":null,"author_association":"NONE","body":"### System information\r\n- **Have I written custom code (as opposed to using a stock example script provided in TensorFlow)**: YES\r\n- **OS Platform and Distribution (e.g., Linux Ubuntu 16.04)**: Window10\r\n- **Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device**: Unknown\r\n- **TensorFlow installed from (source or binary)**: Binary\r\n- **TensorFlow version (use command below)**: 1.9\r\n- **Python version**: 3.6\r\n- **Bazel version (if compiling from source)**: NA\r\n- **GCC/Compiler version (if compiling from source)**: NA\r\n- **CUDA/cuDNN version**: NA\r\n- **GPU model and memory**: CPU version\r\n- **Exact command to reproduce**:\r\n\r\n### Describe the problem\r\nWith tf.while_loop - Eager mode allows a changing input size by default, while Graph mode does not.\r\nThis seems to me like a consistency issue.\r\nWhen eager and graph mode are consistent it allows to debug in eager, and when done run as graph. Inconsistency between eager and graph modes requires an extra debugging step in the graph mode. \r\n\r\nThe error message in graph mode:\r\n\"ValueError: Input tensor 'while/Const_1:0' enters the loop with shape (), but has shape (2, 1) after one iteration. To allow the shape to vary across iterations, use the `shape_invariants` argument of tf.while_loop to specify a less-specific shape.\"\r\nBut works perfectly in eager mode.\r\n### Source code / logs\r\n*** EAGER (WORKS) ***:\r\nimport tensorflow as tf\r\nimport numpy as np\r\ntf.enable_eager_execution()\r\n\r\nbatch = 2\r\ntime = 3\r\ninput_depth = 5\r\ninpt = tf.constant(np.random.normal(size=(batch, input_depth)).astype(np.float32))\r\n\r\ndef timestep(t, dns_output):\r\n    dns_output = dns(inpt)\r\n    return t+1, dns_output\r\n\r\n\r\ndns = tf.layers.Dense(units=1)\r\n_, dns_output = tf.while_loop(lambda t, dns_output: t < time, timestep, (0, 0))\r\n\r\nprint(dns_output)\r\n\r\n***Graph (Error)***:\r\nimport tensorflow as tf\r\nimport numpy as np\r\n\r\nbatch = 2\r\ntime = 3\r\ninput_depth = 5\r\ndense_units = 1\r\ninpt = tf.constant(np.random.normal(size=(batch, input_depth)).astype(np.float32))\r\n\r\ndef timestep(t, dns_output):\r\n    dns_output = dns(inpt)\r\n    print(dns_output)\r\n    return t+1, dns_output\r\n\r\n\r\ndns = tf.layers.Dense(units=dense_units)\r\n\r\n_, dns_output1 = tf.while_loop(lambda t, dns_output: t < time, timestep, (0, 0))\r\n\r\nsess = tf.Session()\r\nsess.run(tf.global_variables_initializer())\r\nout = sess.run(dns_output1)\r\nprint(out)\r\n\r\n***Graph (No Error, works)***:\r\nimport tensorflow as tf\r\nimport numpy as np\r\n\r\nbatch = 2\r\ntime = 3\r\ninput_depth = 5\r\ndense_units = 1\r\ninpt = tf.constant(np.random.normal(size=(batch, input_depth)).astype(np.float32))\r\n\r\ndef timestep(t, dns_output):\r\n    dns_output = dns(inpt)\r\n    return t+1, dns_output\r\n\r\n\r\ndns = tf.layers.Dense(units=dense_units)\r\ndns_output_temp = tf.zeros(shape=[batch, dense_units])\r\n_, dns_output1 = tf.while_loop(lambda t, dns_output: t < time, timestep, (0, dns_output_temp))\r\n\r\nsess = tf.Session()\r\nsess.run(tf.global_variables_initializer())\r\nout = sess.run(dns_output1)\r\nprint(out)\r\n"},"comment":{"url":"https://api.github.com/repos/tensorflow/tensorflow/issues/comments/442957034","html_url":"https://github.com/tensorflow/tensorflow/issues/21224#issuecomment-442957034","issue_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/21224","id":442957034,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0Mjk1NzAzNA==","user":{"login":"tensorflowbutler","id":28546240,"node_id":"MDQ6VXNlcjI4NTQ2MjQw","avatar_url":"https://avatars2.githubusercontent.com/u/28546240?v=4","gravatar_id":"","url":"https://api.github.com/users/tensorflowbutler","html_url":"https://github.com/tensorflowbutler","followers_url":"https://api.github.com/users/tensorflowbutler/followers","following_url":"https://api.github.com/users/tensorflowbutler/following{/other_user}","gists_url":"https://api.github.com/users/tensorflowbutler/gists{/gist_id}","starred_url":"https://api.github.com/users/tensorflowbutler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tensorflowbutler/subscriptions","organizations_url":"https://api.github.com/users/tensorflowbutler/orgs","repos_url":"https://api.github.com/users/tensorflowbutler/repos","events_url":"https://api.github.com/users/tensorflowbutler/events{/privacy}","received_events_url":"https://api.github.com/users/tensorflowbutler/received_events","type":"User","site_admin":false},"created_at":"2018-11-29T19:12:48Z","updated_at":"2018-11-29T19:12:48Z","author_association":"MEMBER","body":"Nagging Assignee @jart: It has been 122 days with no activity and this issue has an assignee. Please update the label and/or status accordingly."}}
{"actor":{"display_login":"tensorflowbutler"}}