<p dir="auto">See three examples:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import tensorflow as tf

x = tf.constant(1.0)
x = tf.Print(x, ['x'])
y = tf.constant(2.0)
y = tf.Print(y, ['y'])
z = tf.constant(3.0)
z = tf.Print(z, ['z'])

with tf.Session() as sess:
    print(sess.run([x,y,z]))"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">tensorflow</span> <span class="pl-k">as</span> <span class="pl-s1">tf</span>

<span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-en">constant</span>(<span class="pl-c1">1.0</span>)
<span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-v">Print</span>(<span class="pl-s1">x</span>, [<span class="pl-s">'x'</span>])
<span class="pl-s1">y</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-en">constant</span>(<span class="pl-c1">2.0</span>)
<span class="pl-s1">y</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-v">Print</span>(<span class="pl-s1">y</span>, [<span class="pl-s">'y'</span>])
<span class="pl-s1">z</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-en">constant</span>(<span class="pl-c1">3.0</span>)
<span class="pl-s1">z</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-v">Print</span>(<span class="pl-s1">z</span>, [<span class="pl-s">'z'</span>])

<span class="pl-k">with</span> <span class="pl-s1">tf</span>.<span class="pl-v">Session</span>() <span class="pl-k">as</span> <span class="pl-s1">sess</span>:
    <span class="pl-en">print</span>(<span class="pl-s1">sess</span>.<span class="pl-en">run</span>([<span class="pl-s1">x</span>,<span class="pl-s1">y</span>,<span class="pl-s1">z</span>]))</pre></div>
<p dir="auto">The sequence of output of <code class="notranslate">tf.Print</code> is indeterminate, which means <code class="notranslate">sess.run</code> don't executes tensors from left to right.</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import tensorflow as tf

x = tf.constant(1.0)
x = tf.Print(x, ['x'])
y = tf.constant(2.0)
y = tf.Print(y, ['y'])
with tf.control_dependencies([x, y]):
    z = tf.constant(3.0)
    z = tf.Print(z, ['z'])

with tf.Session() as sess:
    print(sess.run(z))"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">tensorflow</span> <span class="pl-k">as</span> <span class="pl-s1">tf</span>

<span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-en">constant</span>(<span class="pl-c1">1.0</span>)
<span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-v">Print</span>(<span class="pl-s1">x</span>, [<span class="pl-s">'x'</span>])
<span class="pl-s1">y</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-en">constant</span>(<span class="pl-c1">2.0</span>)
<span class="pl-s1">y</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-v">Print</span>(<span class="pl-s1">y</span>, [<span class="pl-s">'y'</span>])
<span class="pl-k">with</span> <span class="pl-s1">tf</span>.<span class="pl-en">control_dependencies</span>([<span class="pl-s1">x</span>, <span class="pl-s1">y</span>]):
    <span class="pl-s1">z</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-en">constant</span>(<span class="pl-c1">3.0</span>)
    <span class="pl-s1">z</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-v">Print</span>(<span class="pl-s1">z</span>, [<span class="pl-s">'z'</span>])

<span class="pl-k">with</span> <span class="pl-s1">tf</span>.<span class="pl-v">Session</span>() <span class="pl-k">as</span> <span class="pl-s1">sess</span>:
    <span class="pl-en">print</span>(<span class="pl-s1">sess</span>.<span class="pl-en">run</span>(<span class="pl-s1">z</span>))</pre></div>
<p dir="auto">The sequence  of <code class="notranslate">x</code> and <code class="notranslate">y</code> is indeterminate, which means <code class="notranslate">control_dependencies</code> don't executes tensors from left to right.</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import tensorflow as tf

x = tf.constant(1.0)
x = tf.Print(x, ['x'])
y = tf.constant(2.0)
y = tf.Print(y, ['y'])
d = tf.constant(3.0)
d = tf.Print(d, ['d'])
with tf.control_dependencies([x, y]):
    z = tf.add(d, 3.)
    z = tf.Print(z, ['z'])

with tf.Session() as sess:
    print(sess.run(z))"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">tensorflow</span> <span class="pl-k">as</span> <span class="pl-s1">tf</span>

<span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-en">constant</span>(<span class="pl-c1">1.0</span>)
<span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-v">Print</span>(<span class="pl-s1">x</span>, [<span class="pl-s">'x'</span>])
<span class="pl-s1">y</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-en">constant</span>(<span class="pl-c1">2.0</span>)
<span class="pl-s1">y</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-v">Print</span>(<span class="pl-s1">y</span>, [<span class="pl-s">'y'</span>])
<span class="pl-s1">d</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-en">constant</span>(<span class="pl-c1">3.0</span>)
<span class="pl-s1">d</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-v">Print</span>(<span class="pl-s1">d</span>, [<span class="pl-s">'d'</span>])
<span class="pl-k">with</span> <span class="pl-s1">tf</span>.<span class="pl-en">control_dependencies</span>([<span class="pl-s1">x</span>, <span class="pl-s1">y</span>]):
    <span class="pl-s1">z</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-en">add</span>(<span class="pl-s1">d</span>, <span class="pl-c1">3.</span>)
    <span class="pl-s1">z</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-v">Print</span>(<span class="pl-s1">z</span>, [<span class="pl-s">'z'</span>])

<span class="pl-k">with</span> <span class="pl-s1">tf</span>.<span class="pl-v">Session</span>() <span class="pl-k">as</span> <span class="pl-s1">sess</span>:
    <span class="pl-en">print</span>(<span class="pl-s1">sess</span>.<span class="pl-en">run</span>(<span class="pl-s1">z</span>))</pre></div>
<p dir="auto">The sequence of <code class="notranslate">x</code>, <code class="notranslate">y</code> and <code class="notranslate">d</code> is indeterminate.</p>
<p dir="auto">Is it intentional behavior or bug?  I find that if the sequence is indeterminate, the program may get different result.</p>
<p dir="auto">Another example I can't explain:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import tensorflow as tf

x = tf.placeholder(tf.float32, [])
y = tf.Variable(2.)
op = tf.assign(y, x)
op = tf.Print(op, ['op'])

with tf.control_dependencies([op]):
    q = tf.Print(y, [y])


with tf.Session() as sess:
    tf.global_variables_initializer().run()
    print(sess.run([q], feed_dict={x: -1.0}))"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">tensorflow</span> <span class="pl-k">as</span> <span class="pl-s1">tf</span>

<span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-en">placeholder</span>(<span class="pl-s1">tf</span>.<span class="pl-s1">float32</span>, [])
<span class="pl-s1">y</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-v">Variable</span>(<span class="pl-c1">2.</span>)
<span class="pl-s1">op</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-en">assign</span>(<span class="pl-s1">y</span>, <span class="pl-s1">x</span>)
<span class="pl-s1">op</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-v">Print</span>(<span class="pl-s1">op</span>, [<span class="pl-s">'op'</span>])

<span class="pl-k">with</span> <span class="pl-s1">tf</span>.<span class="pl-en">control_dependencies</span>([<span class="pl-s1">op</span>]):
    <span class="pl-s1">q</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-v">Print</span>(<span class="pl-s1">y</span>, [<span class="pl-s1">y</span>])


<span class="pl-k">with</span> <span class="pl-s1">tf</span>.<span class="pl-v">Session</span>() <span class="pl-k">as</span> <span class="pl-s1">sess</span>:
    <span class="pl-s1">tf</span>.<span class="pl-en">global_variables_initializer</span>().<span class="pl-en">run</span>()
    <span class="pl-en">print</span>(<span class="pl-s1">sess</span>.<span class="pl-en">run</span>([<span class="pl-s1">q</span>], <span class="pl-s1">feed_dict</span><span class="pl-c1">=</span>{<span class="pl-s1">x</span>: <span class="pl-c1">-</span><span class="pl-c1">1.0</span>}))</pre></div>
<p dir="auto">The <code class="notranslate">[op]</code> is printed before <code class="notranslate">[y]</code>, but <code class="notranslate">q=2.0</code>, why? If <code class="notranslate">op</code> is executed before <code class="notranslate">y</code>, y will be assigned by <code class="notranslate">x</code>, which means <code class="notranslate">y=-1.0</code>, and <code class="notranslate">q</code> should be <code class="notranslate">-1.0</code>.</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import tensorflow as tf

w = tf.Variable(0)
op1 = tf.assign(w, 1)
op2 = tf.assign(w, 2)
op_1 = tf.constant('op1')
op_2 = tf.constant('op2')

op1 = tf.Print(op1, [op_1])
op2 = tf.Print(op2, [op_2])

with tf.control_dependencies([op2]):
    with tf.control_dependencies([op1]):
        op = tf.no_op()

with tf.Session() as sess:
    tf.global_variables_initializer().run()
    sess.run(op)
    print(sess.run(w))"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">tensorflow</span> <span class="pl-k">as</span> <span class="pl-s1">tf</span>

<span class="pl-s1">w</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-v">Variable</span>(<span class="pl-c1">0</span>)
<span class="pl-s1">op1</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-en">assign</span>(<span class="pl-s1">w</span>, <span class="pl-c1">1</span>)
<span class="pl-s1">op2</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-en">assign</span>(<span class="pl-s1">w</span>, <span class="pl-c1">2</span>)
<span class="pl-s1">op_1</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-en">constant</span>(<span class="pl-s">'op1'</span>)
<span class="pl-s1">op_2</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-en">constant</span>(<span class="pl-s">'op2'</span>)

<span class="pl-s1">op1</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-v">Print</span>(<span class="pl-s1">op1</span>, [<span class="pl-s1">op_1</span>])
<span class="pl-s1">op2</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-v">Print</span>(<span class="pl-s1">op2</span>, [<span class="pl-s1">op_2</span>])

<span class="pl-k">with</span> <span class="pl-s1">tf</span>.<span class="pl-en">control_dependencies</span>([<span class="pl-s1">op2</span>]):
    <span class="pl-k">with</span> <span class="pl-s1">tf</span>.<span class="pl-en">control_dependencies</span>([<span class="pl-s1">op1</span>]):
        <span class="pl-s1">op</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-en">no_op</span>()

<span class="pl-k">with</span> <span class="pl-s1">tf</span>.<span class="pl-v">Session</span>() <span class="pl-k">as</span> <span class="pl-s1">sess</span>:
    <span class="pl-s1">tf</span>.<span class="pl-en">global_variables_initializer</span>().<span class="pl-en">run</span>()
    <span class="pl-s1">sess</span>.<span class="pl-en">run</span>(<span class="pl-s1">op</span>)
    <span class="pl-en">print</span>(<span class="pl-s1">sess</span>.<span class="pl-en">run</span>(<span class="pl-s1">w</span>))</pre></div>
<p dir="auto">It sometimes prints <code class="notranslate">1</code> and sometimes prints <code class="notranslate">2</code>.</p>
<p dir="auto">Another example:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import tensorflow as tf

w = tf.Variable(0)
op1 = tf.assign(w, 0)
op2 = tf.assign(w, 2)
op_1 = tf.constant('op1')
op_2 = tf.constant('op2')

op1 = tf.Print(op1, [op_1])
op2 = tf.Print(op2, [op_2])

with tf.control_dependencies([op1]):
    op3 = tf.no_op()

with tf.control_dependencies([op3, op2]):
    op4 = tf.no_op()


with tf.Session() as sess:
    tf.global_variables_initializer().run()
    sess.run(op4)
    print(sess.run(w))"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">tensorflow</span> <span class="pl-k">as</span> <span class="pl-s1">tf</span>

<span class="pl-s1">w</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-v">Variable</span>(<span class="pl-c1">0</span>)
<span class="pl-s1">op1</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-en">assign</span>(<span class="pl-s1">w</span>, <span class="pl-c1">0</span>)
<span class="pl-s1">op2</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-en">assign</span>(<span class="pl-s1">w</span>, <span class="pl-c1">2</span>)
<span class="pl-s1">op_1</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-en">constant</span>(<span class="pl-s">'op1'</span>)
<span class="pl-s1">op_2</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-en">constant</span>(<span class="pl-s">'op2'</span>)

<span class="pl-s1">op1</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-v">Print</span>(<span class="pl-s1">op1</span>, [<span class="pl-s1">op_1</span>])
<span class="pl-s1">op2</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-v">Print</span>(<span class="pl-s1">op2</span>, [<span class="pl-s1">op_2</span>])

<span class="pl-k">with</span> <span class="pl-s1">tf</span>.<span class="pl-en">control_dependencies</span>([<span class="pl-s1">op1</span>]):
    <span class="pl-s1">op3</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-en">no_op</span>()

<span class="pl-k">with</span> <span class="pl-s1">tf</span>.<span class="pl-en">control_dependencies</span>([<span class="pl-s1">op3</span>, <span class="pl-s1">op2</span>]):
    <span class="pl-s1">op4</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-en">no_op</span>()


<span class="pl-k">with</span> <span class="pl-s1">tf</span>.<span class="pl-v">Session</span>() <span class="pl-k">as</span> <span class="pl-s1">sess</span>:
    <span class="pl-s1">tf</span>.<span class="pl-en">global_variables_initializer</span>().<span class="pl-en">run</span>()
    <span class="pl-s1">sess</span>.<span class="pl-en">run</span>(<span class="pl-s1">op4</span>)
    <span class="pl-en">print</span>(<span class="pl-s1">sess</span>.<span class="pl-en">run</span>(<span class="pl-s1">w</span>))</pre></div>
<p dir="auto">Sometimes <code class="notranslate">0</code> and sometimes <code class="notranslate">2</code>.</p>