, tf.Graph.gradient_override_map. densorflow docs :
@tf.RegisterGradient("CustomSquare")
def _custom_square_grad(op, grad):
with tf.Graph().as_default() as g:
c = tf.constant(5.0)
s_1 = tf.square(c)
with g.gradient_override_map({"Square": "CustomSquare"}):
s_2 = tf.square(s_2)
, net-re-fa.