import tensorflow as tf x1 = tf.constant(1.) x2 = tf.constant(2.) with tf.GradientTape(persistent=True) as tape: tape.watch(x2) y1 = x1 ** 2 y2 = x2 ** 2 dydx1 = tape.gradient(y1, x1) dydx2 = tape.gradient(y2, x2) del tape f"{dydx1}, {dydx2}"
None, 4.0