You can use the custom_gradient decorator to make a version of tf.identity that will copy intermediate blurry gradients.
`` `from tensorflow.contrib.eager.python import tfe
@ tfe.custom_gradient def gradient_clipping_identity (tensor, max_norm): result = tf.identity (tensor)
def grad (dresult): return tf.clip_by_norm (dresult, max_norm), None
return result, grad,,,
Then use gradient_clipping_identity , as you usually use the identifier, and your gradients will be clipped in the backward pass.
source share