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 grad_sparsity(self):
      # If the sparse minibatch gradient has 10 percent of its entries
      # non-zero, its sparsity is 0.1.
      # The norm of dense gradient averaged from full dataset
      # are roughly estimated norm of minibatch
      # sparse gradient norm * sqrt(sparsity)
      # An extension maybe only correct the sparse blob.
      non_zero_cnt = tf.add_n(
          [tf.count_nonzero(g) for g in self._grads]
      )
      all_entry_cnt = tf.add_n([tf.size(g) for g in self._grads])
      self._sparsity = tf.cast(
          non_zero_cnt, self._grads[0].dtype
      ) / tf.cast(all_entry_cnt, self._grads[0].dtype)
      avg_op = self._moving_averager.apply(
          [
              self._sparsity,
          ]
      )
      with tf.control_dependencies([avg_op]):
          self._sparsity_avg = self._moving_averager.average(
              self._sparsity
          )
      return avg_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 5 for calling the YFOptimizer obj's underlying member method code with example usage: obj.grad_sparsity() and returns: avg_op