title: Confused by the behavior of `tf.cond`
body: <p>I need a conditional control flow in my graph. If <code>pred</code> is <code>True</code>, the graph should call an op that updates a variable and then returns it, otherwise it returns the variable unchanged. A simplified version is:</p>
  
  <pre class="lang-py prettyprint-override"><code>pred = tf.constant(True)
  x = tf.Variable([1])
  assign_x_2 = tf.assign(x, [2])
  def update_x_2():
    with tf.control_dependencies([assign_x_2]):
      return tf.identity(x)
  y = tf.cond(pred, update_x_2, lambda: tf.identity(x))
  with tf.Session() as session:
    session.run(tf.initialize_all_variables())
    print(y.eval())
  </code></pre>
  
  <p>However, I find that both <code>pred=True</code> and <code>pred=False</code> lead to the same result <code>y=[2]</code>, which means the assign op is also called when <code>update_x_2</code> is not selected by <code>tf.cond</code>. How to explain this? And how to solve this problem?</p>