title: Try to understand AutoGraph and tf.function: print loss in tf.function
body: <pre class="lang-py prettyprint-override"><code>def train_one_step():
      with tf.GradientTape() as tape:
          a = tf.random.normal([1, 3, 1])
          b = tf.random.normal([1, 3, 1])
          loss = mse(a, b)
  
      tf.print('inner tf print', loss)
      print("inner py print", loss)
  
      return loss
  
  
  @tf.function
  def train():
      loss = train_one_step()
  
      tf.print('outer tf print', loss)
      print('outer py print', loss)
  
      return loss
  
  loss = train()
  tf.print('outest tf print', loss)
  print("outest py print", loss)
  </code></pre>
  
  <p>I'm trying to understand tf.functional more. I printed the loss in four places with different methods. and it produces results like this</p>
  
  <pre><code>inner py print Tensor("mean_absolute_error/weighted_loss/value:0", shape=(), dtype=float32)
  outer py print Tensor("mean_absolute_error/weighted_loss/value:0", shape=(), dtype=float32)
  inner tf print 1.82858419
  outer tf print 1.82858419
  outest tf print 1.82858419
  outest py print tf.Tensor(1.8285842, shape=(), dtype=float32)
  </code></pre>
  
  <ol>
  <li>what's the difference between tf.print and python print?</li>
  <li>looks like python print will be executed during graph evaluation, but tf print only when executed?</li>
  <li>the above only apply when there's tf.function decorator? outside that, tf.print runs before python print?</li>
  </ol>