title: How can I keep state from train step to train step?
body: <p>I have a tensor in my computation graph that I'd like to add a row to after every train step. How can I accomplish this?</p>
  
  <p>More detail: I'm grabbing gradients from <code>optimizer.compute_gradients</code>, and I'd like to modify those gradients based on the gradient history. Here is the code that I'm trying to use:</p>
  
  <pre class="lang-python prettyprint-override"><code>def process_gradient(gradient, optimizer, name):
    reshaped_gradient = flatten(gradient)
  
    if gradient.name in optimizer._slots:
      optimizer._slots[gradient.name] += [reshaped_gradient]
    else:
      optimizer._slots[gradient.name] = [reshaped_gradient]
  
    # each 
    gradients_over_time = tf.stack(optimizer._slots[gradient.name])
  
    print('gradients_over_time.get_shape()', gradients_over_time.get_shape())
  
    return gradient
  
  ...
  
  grads_and_vars = optimizer.compute_gradients(cost_function)
  train_step = optimizer.apply_gradients([(process_gradient(grad, optimizer, str(i)), var) for i, (grad, var) in enumerate(grads_and_vars)])
  </code></pre>
  
  <p>I've also tried keeping a variable around that I use to keep track of rows by concatenating new rows onto, but that didn't work.</p>