Code

Persistent Gradient Tape in TensorFlow

When using TensorFlow's tf.GradientTape to record operations for automatic differentiation, the tape can normally only be used to compute a gradient once. If the user needs to invoke the gradient() method multiple times—such as computing the gradient of a final output and separately computing the gradient of a detached intermediate variable—the tape must be instantiated with the persistent=True argument. This parameter ensures that the compute graph is explicitly preserved after the first gradient calculation.

0

1

Updated 2026-05-02

Contributors are:

Who are from:

Tags

D2L

Dive into Deep Learning @ D2L