class_docstr: Optimizer that implements the YellowFin algorithm.
  
  Implemented as a wrapper around tf.train.MomentumOptimizer
class_docstr_tok: ["Optimizer","that","implements","the","YellowFin","algorithm",".","Implemented","as","a","wrapper","around","tf.train.MomentumOptimizer"]
code: def apply_gradients(self, grads_tvars, global_step=None, name=None):
      self._grads, self._tvars = zip(
          *[(g, t) for g, t in grads_tvars if g is not None]
      )
  
      # for manual gradient clipping
      if self._clip_thresh_var is not None:
          self._grads, self._grads_norm = tf.clip_by_global_norm(
              self._grads, self._clip_thresh_var
          )
  
      # loosely adaptive clipping of gradient in case exploding gradient ruins statistics
      if self._use_adapt_grad_clip:
          thresh = tf.cond(
              self._do_tune,
              lambda: tf.sqrt(
                  self._stat_protect_fac
                  * self._adapt_grad_clip_thresh**2
              ),
              lambda: tf.to_float(tf.constant(LARGE_FLOAT_VAL)),
          )
          self._grads, self._grads_norm = tf.clip_by_global_norm(
              self._grads, thresh
          )
  
      with tf.variable_scope("before_apply"):
          before_apply_op = self.before_apply()
  
      with tf.variable_scope("update_hyper"):
          with tf.control_dependencies([before_apply_op]):
              update_hyper_op = self.update_hyper_param()
  
      with tf.variable_scope("apply_updates"):
          with tf.control_dependencies([update_hyper_op]):
              # clip exploding gradient according to h_max
              if self._use_adapt_grad_clip:
                  thresh = tf.cond(
                      tf.greater(
                          tf.global_norm(self._grads),
                          self._adapt_grad_clip_thresh,
                      ),
                      lambda: self._adapt_grad_clip_target_val,
                      lambda: tf.to_float(tf.constant(LARGE_FLOAT_VAL)),
                  )
                  (
                      self._grads,
                      self._grads_norm,
                  ) = tf.clip_by_global_norm(self._grads, thresh)
  
              apply_grad_op = self._optimizer.apply_gradients(
                  zip(self._grads, self._tvars), global_step, name
              )
  
      with tf.control_dependencies([apply_grad_op]):
          self._increment_global_step_op = tf.assign(
              self._global_step, self._global_step + 1
          )
  
          self._adapt_grad_clip_thresh_op = tf.assign(
              self._adapt_grad_clip_thresh, tf.sqrt(self._h_max)
          )
          self._adapt_grad_clip_target_val_op = tf.assign(
              self._adapt_grad_clip_target_val, tf.sqrt(self._h_max)
          )
          # self._adapt_grad_clip_target_val_op = \
          #   tf.assign(self._adapt_grad_clip_target_val, tf.sqrt(tf.sqrt(self._h_max * self._h_min)))
  
      return tf.group(
          before_apply_op,
          update_hyper_op,
          apply_grad_op,
          self._adapt_grad_clip_thresh_op,
          self._adapt_grad_clip_target_val_op,
          self._increment_global_step_op,
      )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import numpy
  import delta.compat
  from tensorflow.python.framework import ops
label_desc: Use image node_id 12 for calling the YFOptimizer obj's underlying member method code with example usage: obj.apply_gradients(grads_tvars, global_step, name) and returns: tf