TensorFlow 2.0 Beta is available Learn more

tfp.math.value_and_gradient

Computes f(*xs) and its gradients wrt to *xs.

tfp.math.value_and_gradient(
    f,
    xs,
    use_gradient_tape=False,
    name=None
)

Defined in python/math/gradient.py.

Args:

  • f: Python callable to be differentiated. If f returns a scalar, this scalar will be differentiated. If f returns a tensor or list of tensors, by default a scalar will be computed by adding all their values to produce a single scalar. If desired, the tensors can be elementwise multiplied by the tensors passed as the dy keyword argument to the returned gradient function.
  • xs: Python list of parameters of f for which to differentiate. (Can also be single Tensor.)
  • use_gradient_tape: Python bool indicating that tf.GradientTape should be used regardless of tf.executing_eagerly() status. Default value: False.
  • name: Python str name prefixed to ops created by this function. Default value: None (i.e., 'value_and_gradient').

Returns:

  • y: y = f(*xs).
  • dydx: Gradient of y wrt each of xs.