class_docstr: LocalGradientAggregationHelper aggregates gradient updates locally,
  and communicates the updates across machines only once every
  backward_passes_per_step. Only supports graph mode execution.
class_docstr_tok: ["LocalGradientAggregationHelper","aggregates","gradient","updates","locally",",","and","communicates","the","updates","across","machines","only","once","every","backward_passes_per_step",".","Only","supports","graph","mode","execution","."]
code: def __init__(
      self,
      backward_passes_per_step,
      allreduce_func,
      sparse_as_dense,
      average_aggregated_gradients,
      rank,
      optimizer_type,
      process_set=global_process_set,
      scale_local_gradients=True,
      name="",
  ):
      self._allreduce_grads = allreduce_func
      self.name = name
      # backward_passes_per_step controls how often gradient updates are
      # synchronized.
      self.backward_passes_per_step = backward_passes_per_step
      if self.backward_passes_per_step <= 0:
          raise ValueError("backward_passes_per_step must be > 0")
  
      # average_aggregated_gradients controls whether gradient updates that are
      # aggregated, should be divided by `backward_passes_per_step`.
      self.average_aggregated_gradients = average_aggregated_gradients
  
      # This is going to be [N] data structure holding the aggregated gradient updates
      # N is the number of parameters.
      self.locally_aggregated_grads = []
  
      # Used to know when to allreduce and apply gradients. We allreduce when `self.counter`
      # is equal to `self.backward_passes_per_step`. We apply gradients when `self.counter` is
      # equal to 0.
      self.counter = None
  
      self.sparse_as_dense = sparse_as_dense
      self.rank = rank
      self.optimizer_type = optimizer_type
  
      # Contains the mapping of indexes of grad updates that are not None to their index in
      # locally_aggregated_grads which only contains not None gradients. When performing
      # gradient aggregation we have to remove them from the list of grads prior to passing
      # the list into a tf.cond().
      self.not_none_indexes = {}
      self.num_none_grad_updates = 0
  
      self.process_set = process_set
      self.scale_local_gradients = scale_local_gradients
      self._local_vars = set()
  
file_path: horovod/horovod/tensorflow/gradient_aggregation.py
imports: import os
  import tensorflow
  from packaging import version
  from horovod.tensorflow.mpi_ops import size_op
  from horovod.tensorflow.mpi_ops import global_process_set
label_desc: Use image node_id 1 to create a new LocalGradientAggregationHelper object  with example: obj = LocalGradientAggregationHelper(backward_passes_per_step, allreduce_func, sparse_as_dense, average_aggregated_gradients, rank, optimizer_type, process_set, scale_local_gradients, name)