Tensorflow control_dependencies not working with list
<p>I have a cost, which depends on two list of variables <code>a</code> and <code>b</code>.<br>
I want to :</p>

<ol>
<li>calculate both gradients of the cost at the current point, </li>
<li>update the loss w.r.t. the first list of variables (<code>a</code>)</li>
<li>update the loss w.r.t. the second list of variable (<code>b</code>).</li>
</ol>

<p>In that order.</p>

<p>To do this I tried something like this:  </p>

<p><strong>EDIT:</strong> Following @Yaroslav Bulatov's answer I tried the following:</p>

<pre><code>opt=tf.train.GradientDescentOptimizer(0.001)
grad_cost_wrt_a=opt.compute_gradients(cost,[a])
grad_cost_wrt_b=opt.compute_gradients(cost,[b])

with tf.control_dependencies(grad_cost_wrt_a[0]):
  with tf.control_dependencies(grad_cost_wrt_b[0]):
    update_wrt_a=opt.apply_gradients(grad_cost_wrt_a)
      with tf.control_dependencies([update_wrt_a]):
        update_wrt_b=opt.apply_gradients(grad_cost_wrt_b)
</code></pre>

<p>Wondering if this is doing the right thing ? If a and b are list of variables.</p>

<p>To be able to then do:</p>

<pre><code>sess.run([update_wrt_a,update_wrt_b],feed_dict={x: x_input, y: y_input})
</code></pre>

<p>First this does not work I get:
cannot convert a list into a Tensor or Operation but control_dependencies is supposed to recieve a list of tensors...</p>

<p>Then bonus question do I really need all those control_dependencies ?</p>

<p>Your <code>grad_cost_wrt_a</code> and <code>grad_cost_wrt_b</code> variables are lists, do something like <code>grad_cost_wrt_a[0], grad_cost_wrt_b[0]</code></p>

python tensorflow deep-learning