title: tf.function and tf.while loop in Tensorflow 2.0
body: <p>I am trying to parallelize loop using <code>tf.while_loop</code>. As suggested <a href="https://stackoverflow.com/questions/59299060/tf-2-0-while-loop-and-parallel-iterations">here</a>, the <code>parallel_iterations</code> argument doesn't make a difference in the eager mode. So I attempted to wrap <code>tf.while_loop</code> with <code>tf.function</code>. However, after adding the decorator,the behavior of the iteration variable changes.</p>
  
  <p>For example, this piece of code works.</p>
  
  <pre><code>result = np.zeros(10)
  iteration = tf.constant(0)
  c = lambda i: tf.less(i, 10)
  def print_fun(iteration):
      result[iteration] = iteration
      iteration += 1
      return (iteration,)
  tf.while_loop(c, print_fun, [iteration])
  </code></pre>
  
  <p>If I add the decorator, bug occurs.</p>
  
  <pre><code>result = np.zeros(10)
  iteration = tf.constant(0)
  c = lambda i: tf.less(i, 10)
  def print_fun(iteration):
      result[iteration] = iteration
      iteration += 1
      return (iteration,)
  
  @tf.function
  def run_graph():
      iteration = tf.constant(0)
      tf.while_loop(c, print_fun, [iteration])
  
  run_graph()
  </code></pre>
  
  <p>From my debugging process, I found that variable <code>iteration</code> changes from a tensor  to a placeholder. Why is that? How should I modify the code to eliminate the bug?</p>
  
  <p>Thanks.</p>