code: def _hessian_vector_product(ys, xs, v):
      """Multiply the Hessian of `ys` wrt `xs` by `v`.
  
      This is an efficient construction that uses a backprop-like approach
      to compute the product between the Hessian and another vector. The
      Hessian is usually too large to be explicitly computed or even
      represented, but this method allows us to at least multiply by it
      for the same big-O cost as backprop.
  
      Implicit Hessian-vector products are the main practical, scalable way
      of using second derivatives with neural networks. They allow us to
      do things like construct Krylov subspaces and approximate conjugate
      gradient descent.
  
      Example: if `y` = 1/2 `x`^T A `x`, then `hessian_vector_product(y,
      x, v)` will return an expression that evaluates to the same values
      as (A + A.T) `v`.
  
      Args:
        ys: A scalar value, or a tensor or list of tensors to be summed to
            yield a scalar.
        xs: A list of tensors that we should construct the Hessian over.
        v: A list of tensors, with the same shapes as xs, that we want to
           multiply by the Hessian.
  
      Returns:
        A list of tensors (or if the list would be length 1, a single tensor)
        containing the product between the Hessian and `v`.
  
      Raises:
        ValueError: `xs` and `v` have different length.
  
      """
  
      # Validate the input
      length = len(xs)
      if len(v) != length:
          raise ValueError("xs and v must have the same length.")
  
      # First backprop
      grads = gradients(ys, xs)
  
      assert len(grads) == length
      elemwise_products = [
          math_ops.multiply(grad_elem, array_ops.stop_gradient(v_elem))
          for grad_elem, v_elem in zip(grads, v)
          if grad_elem is not None
      ]
  
      # Second backprop
      return gradients(elemwise_products, xs)
  
imports: from tensorflow.compiler.jit.ops import xla_ops_grad
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import ops
  from tensorflow.python.ops import array_grad
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import check_ops
  from tensorflow.python.ops import control_flow_grad
  from tensorflow.python.ops import cudnn_rnn_grad
  from tensorflow.python.ops import gradients_util
  from tensorflow.python.ops import image_grad
  from tensorflow.python.ops import io_ops
  from tensorflow.python.ops import linalg_grad
  from tensorflow.python.ops import linalg_ops
  from tensorflow.python.ops import logging_ops
  from tensorflow.python.ops import lookup_grad
  from tensorflow.python.ops import manip_grad
  from tensorflow.python.ops import math_grad
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import nccl_ops
  from tensorflow.python.ops import nn_grad
  from tensorflow.python.ops import optional_grad
  from tensorflow.python.ops import parsing_grad
  from tensorflow.python.ops import proto_ops
  from tensorflow.python.ops import random_grad
  from tensorflow.python.ops import rnn_grad
  from tensorflow.python.ops import sdca_ops
  from tensorflow.python.ops import sets
  from tensorflow.python.ops import sparse_grad
  from tensorflow.python.ops import tensor_array_grad
  from tensorflow.python.ops import tensor_array_ops
  from tensorflow.python.ops import while_loop
  from tensorflow.python.ops.linalg.sparse import sparse_csr_matrix_grad
  from tensorflow.python.ops.signal import fft_ops
  from tensorflow.python.ops.unconnected_gradients import UnconnectedGradients
  from tensorflow.python.training import checkpoint_ops
  from tensorflow.python.util.tf_export import tf_export
label_desc: Use image node_id 3 for calling a global function with example usage: _hessian_vector_product(ys, xs, v) and returns: gradients