title: How tf.gradients work in TensorFlow
body: <p>Given I have a linear model as the following I would like to get the gradient vector with regards to W and b.</p>
  
  <pre><code># tf Graph Input
  X = tf.placeholder("float")
  Y = tf.placeholder("float")
  
  # Set model weights
  W = tf.Variable(rng.randn(), name="weight")
  b = tf.Variable(rng.randn(), name="bias")
  
  # Construct a linear model
  pred = tf.add(tf.mul(X, W), b)
  
  # Mean squared error
  cost = tf.reduce_sum(tf.pow(pred-Y, 2))/(2*n_samples)
  </code></pre>
  
  <p>However if I try something like this where cost is a function of <code>cost(x,y,w,b)</code> and I only want to gradients with respect to <code>w and b</code>:</p>
  
  <pre><code>grads = tf.gradients(cost, tf.all_variable())
  </code></pre>
  
  <p>My placeholders will also be included (X and Y). 
  Even if I do get a gradient with <code>[x,y,w,b]</code> how do I know which element in the gradient that belong to each parameter since it is just a list without names to which parameter the derivative has be taken with regards to?</p>
  
  <p>In this question I'm using parts of this <a href="https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/2_BasicModels/linear_regression.ipynb" rel="noreferrer">code</a> and I build on <a href="https://stackoverflow.com/questions/39167070/implementing-gradient-descent-in-tensorflow-instead-of-using-the-one-provided-wi">this</a> question. </p>