import tensorflow as tf x1 = tf.Variable(4) # Does dot work. x2 = tf.Variable(4.) # Works. x3 = tf.Variable(4.0) # Works. x4 = tf.Variable(4, dtype=tf.float32) # Works. with tf.GradientTape(persistent=True) as tape: y1 = x1 ** 2 y2 = x2 ** 2 y3 = x3 ** 2 y4 = x4 ** 2 dy_dx_1 = tape.gradient(y1, x1) dy_dx_2 = tape.gradient(y2, x2) dy_dx_3 = tape.gradient(y3, x3) dy_dx_4 = tape.gradient(y4, x4) del tape f"{dy_dx_1}, {dy_dx_2}, {dy_dx_3}, {dy_dx_4}"
None, 8.0, 8.0, 8.0