code: def apply_grad_processors(opt, gradprocs):
      """
      Wrapper around optimizers to apply gradient processors.
  
      Args:
          opt (tf.train.Optimizer):
          gradprocs (list[GradientProcessor]): gradient processors to add to the
              optimizer.
  
      Returns:
          a :class:`tf.train.Optimizer` instance which runs the gradient
          processors before updating the variables.
      """
      assert isinstance(gradprocs, (list, tuple)), gradprocs
      for gp in gradprocs:
          assert isinstance(gp, GradientProcessor), gp
  
      class _ApplyGradientProcessor(ProxyOptimizer):
          def __init__(self, opt, gradprocs):
              self._gradprocs = gradprocs[:]
              super(_ApplyGradientProcessor, self).__init__(opt)
  
          def apply_gradients(
              self, grads_and_vars, global_step=None, name=None
          ):
              g = self._apply(grads_and_vars)
              return self._opt.apply_gradients(g, global_step, name)
  
          def _apply(self, g):
              for proc in self._gradprocs:
                  g = proc.process(g)
              return g
  
      return _ApplyGradientProcessor(opt, gradprocs)
  
imports: from contextlib import contextmanager
  import tensorflow
  from ..tfutils.common import get_tf_version_tuple
  from ..compat import tfv1
  from ..utils.develop import HIDE_DOC
  from .gradproc import FilterNoneGrad, GradientProcessor
label_desc: Use image node_id 1 for calling a global function with example usage: apply_grad_processors(opt, gradprocs) and returns: _ApplyGradientProcessor, self, g