code: def test_variable_tracking(self):
      value_and_gradient = value_and_gradient_with_auto_expansion
      q = normal.Normal(
          tf.Variable(1.0), tf.Variable(1.0, trainable=False)
      )
      r = normal.Normal(0.0, tf.Variable(1.0))
      self.evaluate([v.initializer for v in q.variables + r.variables])
  
      y, dydx = self.evaluate(
          value_and_gradient(kullback_leibler.kl_divergence, q, r)
      )
      self.assertAllClose(0.5, y, atol=1e-6, rtol=1e-6)
      self.assertAllClose([[1.0], [-1.0]], dydx, atol=1e-6, rtol=1e-6)
  
      y, dydx = self.evaluate(
          value_and_gradient(
              lambda: kullback_leibler.kl_divergence(q, r), q, r
          )
      )
      self.assertAllClose(0.5, y, atol=1e-6, rtol=1e-6)
      self.assertAllClose([[1.0], [-1.0]], dydx, atol=1e-6, rtol=1e-6)
  
      y, dydx = self.evaluate(
          value_and_gradient(
              lambda: kullback_leibler.kl_divergence(q, r),
              *q.trainable_variables,
              r,
          )
      )
      self.assertAllClose(0.5, y, atol=1e-6, rtol=1e-6)
      self.assertAllClose([1.0, [-1.0]], dydx, atol=1e-6, rtol=1e-6)
  
      y, dydx = self.evaluate(
          value_and_gradient(
              lambda *_: kullback_leibler.kl_divergence(q, r), q, r
          )
      )
      self.assertAllClose(0.5, y, atol=1e-6, rtol=1e-6)
      self.assertAllClose([[1.0], [-1.0]], dydx, atol=1e-6, rtol=1e-6)
  
      y, dydx = self.evaluate(
          value_and_gradient(
              lambda **kw: kullback_leibler.kl_divergence(  # pylint: disable=g-long-lambda
                  normal.Normal(kw["loc_q"], 1),
                  normal.Normal(0, kw["scale_r"]),
              ),
              loc_q=1.0,
              scale_r=1.0,
          )
      )
      self.assertAllClose(0.5, y, atol=1e-6, rtol=1e-6)
      self.assertAllCloseNested(
          {"loc_q": 1.0, "scale_r": -1.0}, dydx, atol=1e-6, rtol=1e-6
      )
  
imports: import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import kullback_leibler
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.math import gradient
  from tensorflow_probability.python.math.gradient import batch_jacobian
  from tensorflow_probability.python.math.gradient import value_and_gradient_with_auto_expansion
label_desc: Use image node_id 10 for calling the GradientTest obj's underlying member method code with example usage: obj.test_variable_tracking() without return types