code: def _grad_variance(self):
      
      grad_var_ops = []
      tensor_to_avg = []
      for t, g in zip(self._vars, self._grad):
        if isinstance(g, tf.IndexedSlices):
          tensor_to_avg.append(
              tf.reshape(tf.unsorted_segment_sum(g.values,
                                                 g.indices,
                                                 g.dense_shape[0]),
                         shape=t.get_shape()))
        else:
          tensor_to_avg.append(g)
      avg_op = self._moving_averager.apply(tensor_to_avg)
      grad_var_ops.append(avg_op)
      with tf.control_dependencies([avg_op]):
        self._grad_avg = [self._moving_averager.average(val)
                          for val in tensor_to_avg]
        self._grad_avg_squared = [tf.square(val) for val in self._grad_avg]
  
      # Compute Variance
      self._grad_var = tf.maximum(
          tf.constant(1e-6, dtype=self._grad_norm_squared_avg.dtype),
          self._grad_norm_squared_avg
          - tf.add_n([tf.reduce_sum(val) for val in self._grad_avg_squared]))
      if self._sparsity_debias:
        self._grad_var *= self._sparsity_avg
      return grad_var_ops
docs: Estimate of gradient Variance.
  
      Returns:
        C_t ops.