class_docstr: Base class of solver.
class_docstr_tok: ["Base","class","of","solver","."]
docstr: Clip the gradients.
docstr_tok: ["Clip","the","gradients","."]
code: def clip_gradients(self, grads_and_vars, clip_ratio):
      """Clip the gradients."""
      is_zip_obj = False
      if isinstance(grads_and_vars, zip):
          grads_and_vars = list(grads_and_vars)
          is_zip_obj = True
  
      with tf.variable_scope("grad"):
          for grad, var in grads_and_vars:
              if grad is not None:
                  tf.summary.histogram(var.name[:-2], grad)
              else:
                  logging.debug("%s gradient is None" % (var.name))
  
      # not clip
      if not clip_ratio:
          if is_zip_obj:
              grads, variables = zip(*grads_and_vars)
              grads_and_vars = zip(grads, variables)
          return grads_and_vars
  
      gradients, variables = zip(*grads_and_vars)
      clipped, global_norm = tf.clip_by_global_norm(
          gradients, clip_ratio
      )
      grad_and_var_clipped = zip(clipped, variables)
  
      tf.summary.scalar("gradient/global_norm", global_norm)
      return grad_and_var_clipped
  
imports: import abc
  import math
  import delta.compat
  import tensorflow_addons
  from absl import logging
  from delta import utils
  from delta.utils import optimizer
  from delta.utils.register import registers
label_desc: Use image node_id 9 for calling the Solver obj's underlying member method code with example usage: obj.clip_gradients(grads_and_vars, clip_ratio) and returns: grad_and_var_clipped, grads_and_vars