code: def hessians(
      ys,
      xs,
      name="hessians",
      colocate_gradients_with_ops=False,
      gate_gradients=False,
      aggregation_method=None,
  ):
      """Constructs the Hessian of sum of `ys` with respect to `x` in `xs`.
  
      `hessians()` adds ops to the graph to output the Hessian matrix of `ys`
      with respect to `xs`.  It returns a list of `Tensor` of length `len(xs)`
      where each tensor is the Hessian of `sum(ys)`.
  
      The Hessian is a matrix of second-order partial derivatives of a scalar
      tensor (see https://en.wikipedia.org/wiki/Hessian_matrix for more details).
  
      Args:
        ys: A `Tensor` or list of tensors to be differentiated.
        xs: A `Tensor` or list of tensors to be used for differentiation.
        name: Optional name to use for grouping all the gradient ops together.
          defaults to 'hessians'.
        colocate_gradients_with_ops: See `gradients()` documentation for details.
        gate_gradients: See `gradients()` documentation for details.
        aggregation_method: See `gradients()` documentation for details.
  
      Returns:
        A list of Hessian matrices of `sum(ys)` for each `x` in `xs`.
  
      Raises:
        LookupError: if one of the operations between `xs` and `ys` does not
          have a registered gradient function.
      """
      xs = gradients_util._AsList(
          xs
      )  # pylint: disable=protected-access
      kwargs = {
          "colocate_gradients_with_ops": colocate_gradients_with_ops,
          "gate_gradients": gate_gradients,
          "aggregation_method": aggregation_method,
      }
      # Compute first-order derivatives and iterate for each x in xs.
      hessians = []
      _gradients = gradients(ys, xs, **kwargs)
      for gradient, x in zip(_gradients, xs):
          # change shape to one-dimension without graph branching
          gradient = array_ops.reshape(gradient, [-1])
  
          # Declare an iterator and tensor array loop variables for the gradients.
          n = array_ops.size(x)
          loop_vars = [
              array_ops.constant(0, dtypes.int32),
              tensor_array_ops.TensorArray(x.dtype, n),
          ]
          # Iterate over all elements of the gradient and compute second order
          # derivatives.
          _, hessian = while_loop.while_loop(
              lambda j, _: j < n,
              lambda j, result: (
                  j + 1,
                  result.write(j, gradients(gradient[j], x)[0]),
              ),
              loop_vars,
          )
  
          _shape = array_ops.shape(x)
          _reshaped_hessian = array_ops.reshape(
              hessian.stack(), array_ops.concat((_shape, _shape), 0)
          )
          hessians.append(_reshaped_hessian)
      return hessians
  
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 4 for calling a global function with example usage: hessians(ys, xs, name, colocate_gradients_with_ops, gate_gradients, aggregation_method) and returns: hessians