import tensorflow as tf tf.compat.v1.disable_eager_execution() a = tf.constant([[1,7,3]],dtype=tf.float32) b = tf.cast(a,dtype=tf.int32) f = tf.gradients(b,a) with