code: def add_gradients_summaries(grads_and_vars, step):
      """Add summaries to gradients.
  
      Args:
        grads_and_vars: A list of gradient to variable pairs (tuples).
        step: Variable to use for summaries.
      """
      with tf.name_scope("summarize_grads"):
          for grad, var in grads_and_vars:
              if grad is not None:
                  if isinstance(grad, tf.IndexedSlices):
                      grad_values = grad.values
                  else:
                      grad_values = grad
                  var_name = var.name.replace(":", "_")
                  tf.compat.v2.summary.histogram(
                      name=var_name + "_gradient",
                      data=grad_values,
                      step=step,
                  )
                  tf.compat.v2.summary.scalar(
                      name=var_name + "_gradient_norm",
                      data=tf.linalg.global_norm([grad_values]),
                      step=step,
                  )
              else:
                  logging.info("Var %s has no gradient", var.name)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import copy
  import functools
  import inspect
  from absl import logging
  import numpy
  import six
  import tensorflow
  from tf_agents.utils import common
  from tensorflow.python.util import tf_decorator
label_desc: Use image node_id 5 for calling a global function with example usage: add_gradients_summaries(grads_and_vars, step) without return types