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 before_apply(self):
      self._moving_averager = tf.train.ExponentialMovingAverage(
          decay=self._beta, zero_debias=self._zero_debias
      )
      assert self._grads is not None and len(self._grads) > 0
      before_apply_ops = []
  
      # get per var g**2 and norm**2
      self._grad_squared = []
      self._grad_norm_squared = []
      for v, g in zip(self._tvars, self._grads):
          if g is None:
              continue
          with ops.colocate_with(v):
              self._grad_squared.append(tf.square(g))
      self._grad_norm_squared = [
          tf.reduce_sum(grad_squared)
          for grad_squared in self._grad_squared
      ]
  
      if self._sparsity_debias:
          avg_op_sparsity = self.grad_sparsity()
          before_apply_ops.append(avg_op_sparsity)
  
      # the following running average on squared norm of gradient is shared
      # by `grad_variance` and `dist_to_opt`
      avg_op = self._moving_averager.apply(self._grad_norm_squared)
      with tf.control_dependencies([avg_op]):
          self._grad_norm_squared_avg = [
              self._moving_averager.average(val)
              for val in self._grad_norm_squared
          ]
          self._grad_norm_squared = tf.add_n(self._grad_norm_squared)
          self._grad_norm_squared_avg = tf.add_n(
              self._grad_norm_squared_avg
          )
      before_apply_ops.append(avg_op)
  
      with tf.control_dependencies([avg_op]):
          curv_range_ops = self.curvature_range()
          before_apply_ops += curv_range_ops
          grad_var_ops = self.grad_variance()
          before_apply_ops += grad_var_ops
          dist_to_opt_ops = self.dist_to_opt()
          before_apply_ops += dist_to_opt_ops
      return tf.group(*before_apply_ops)
  
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 6 for calling the YFOptimizer obj's underlying member method code with example usage: obj.before_apply() and returns: tf