code: def maybe_call_fn_and_grads(
      fn,
      fn_arg_list,
      result=None,
      grads=None,
      check_non_none_grads=True,
      name=None,
  ):
      """Calls `fn` and computes the gradient of the result wrt `args_list`."""
      with tf.name_scope(name or "maybe_call_fn_and_grads"):
          fn_arg_list = (
              list(fn_arg_list)
              if is_list_like(fn_arg_list)
              else [fn_arg_list]
          )
          result, grads = _value_and_gradients(
              fn, fn_arg_list, result, grads
          )
          if not all(
              dtype_util.is_floating(r.dtype)
              for r in (result if is_list_like(result) else [result])
          ):  # pylint: disable=superfluous-parens
              raise TypeError(
                  "Function result must be a `Tensor` with `float` "
                  "`dtype`."
              )
          if len(fn_arg_list) != len(grads):
              raise ValueError(
                  "Function args must be in one-to-one correspondence "
                  "with grads."
              )
          if check_non_none_grads and any(g is None for g in grads):
              raise ValueError(
                  "Encountered `None` gradient.\n"
                  "  fn_arg_list: {}\n"
                  "  grads: {}".format(fn_arg_list, grads)
              )
          return result, grads
  
imports: import warnings
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import broadcast_util
  from tensorflow_probability.python.internal import distribution_util
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import tensorshape_util
  from tensorflow_probability.python.math.gradient import value_and_gradient
  from tensorflow.python.util import deprecation
label_desc: Use image node_id 14 for calling a global function with example usage: maybe_call_fn_and_grads(fn, fn_arg_list, result, grads, check_non_none_grads, name) and returns: result,  grads