In the below code:
dy is computed as 1. How is this value getting computed (whats the math)? as per tf.custom_gradient guide, dy is upstream by gradient
Why final gradients is getting multiplied by clip_norm value(0.6)? (It means final_gradients of (v * v) is getting multiplied by 0.6 , gradient of v * v is 2v, why is multiplied by 0.6?)
@tf.custom_gradient def clip_gradients(y): print('y',y) def backward(dy): print('dy',dy) return tf.clip_by_norm(dy, 0.6) return y, backward v = tf.Variable(3.0) with tf.GradientTape() as t: output = clip_gradients(v * v) print('output',output) print('Final Gradient is ',t.gradient(output, v))
'''
Code output
y tf.Tensor(9.0, shape=(), dtype=float32)
output tf.Tensor(9.0, shape=(), dtype=float32)
dy tf.Tensor(1.0, shape=(), dtype=float32)
Final Gradient is tf.Tensor(3.6000001, shape=(), dtype=float32)