title: Replicating RegisterGradient and gradient_override_map in Keras
body: <p>Following is the code for registering a gradient and overriding an operation's gradient in tensorflow. </p>
  
  <pre><code># Registering a gradient
  some_multiplier = 0.5 
  
  @tf.RegisterGradient("AdaGrad")
  def _ada_grad(op, grad):
      return grad * some_multiplier 
  
  # Overriding 
  g = tf.get_default_graph()
  with g.gradient_override_map({"Ada": "AdaGrad"}):
      model.loss = tf.identity(model.loss, name="Ada")
  </code></pre>
  
  <p>I want to replicate the same thing in keras. I couldn't find any way to do it after searching a lot of things. </p>
  
  <p>I tried the following code but it didn't work. 
  The gradient is not being modified. I got the same result with and without gradient override. I checked it with setting <code>some_multiplier</code> to zero.  </p>
  
  <pre><code>model = Model(...) # Keras model
  model.compile(loss='sparse_categorical_crossentropy', optimizer=adadelta, metrics=['accuracy']) # Compiling Keras Model
  
  @tf.RegisterGradient("AdaGrad")
  def _ada_grad(op, grad):
      return grad * some_multiplier 
  
  g = tf.get_default_graph()
  with g.gradient_override_map({"Ada": "AdaGrad"}):
      model.total_loss = tf.identity(model.total_loss, name="Ada")
  </code></pre>