Backpropagating through multiple forward passes
问题 In usual backprop, we forward-prop once, compute gradients, then apply them to update weights. But suppose we wish to forward-prop twice , and backprop through both , and apply gradients only then (skip on first). Suppose the following: x = tf.Variable([2.]) w = tf.Variable([4.]) with tf.GradientTape(persistent=True) as tape: w.assign(w * x) y = w * w # w^2 * x print(tape.gradient(y, x)) # >>None From docs, a tf.Variable is a stateful object, which blocks gradients , and weights are tf