Commit 543bc6a8 authored by Tom Hennigan's avatar Tom Hennigan Committed by TensorFlower Gardener
Browse files

Only watch tensors on the current tape rather than all of them.

This allows fine grained control over recording in some cases, for example the
following where we want d2y but not d2z:

    x1 = tf.Variable(2.0, trainable=False)
    x2 = tf.Variable(2.0, trainable=False)

    with tf.GradientTape() as tape1:
      with tf.GradientTape() as tape2:
        tape1.watch(x1)
        tape2.watch([x1, x2])
        y = x1 ** 3
        z = x2 ** 2
        dy, dz = tape2.gradient([y, z], [x1, x2])
      d2y, d2z = tape1.gradient([dy, dz], [x1, x2])

      assert d2z is None

PiperOrigin-RevId: 211206506
parent dcbd97c2
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment