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","."]
docstr: Initializes the counter that is used when to communicate and aggregate gradients
  and the tensorflow variables that store the locally aggregated gradients.
docstr_tok: ["Initializes","the","counter","that","is","used","when","to","communicate","and","aggregate","gradients","and","the","tensorflow","variables","that","store","the","locally","aggregated","gradients","."]
code: def _init_aggregation_vars(self, grads):
      """
      Initializes the counter that is used when to communicate and aggregate gradients
      and the tensorflow variables that store the locally aggregated gradients.
      """
      variable_scope_name = (
          "aggregation_variables_" + self.name + str(self.rank)
      )
      with tf.compat.v1.variable_scope(
          variable_scope_name, reuse=tf.compat.v1.AUTO_REUSE
      ):
          self.counter = tf.compat.v1.get_variable(
              "aggregation_counter",
              shape=(),
              dtype=tf.int32,
              trainable=False,
              initializer=tf.compat.v1.zeros_initializer(),
              collections=[tf.compat.v1.GraphKeys.LOCAL_VARIABLES],
          )
          for idx, grad in enumerate(grads):
              grad = self._maybe_convert_grad(grad)
  
              # Handle grads that are None.
              if grad is None:
                  self.num_none_grad_updates += 1
                  continue
              self.not_none_indexes[idx] = len(
                  self.locally_aggregated_grads
              )
  
              # Create shadow variable.
              grad_aggregation_variable_name = str(idx)
              zero_grad = tf.zeros(
                  shape=grad.get_shape().as_list(), dtype=grad.dtype
              )
              grad_aggregation_variable = tf.compat.v1.get_variable(
                  grad_aggregation_variable_name,
                  trainable=False,
                  initializer=zero_grad,
                  collections=[
                      tf.compat.v1.GraphKeys.LOCAL_VARIABLES,
                      "aggregating_collection",
                  ],
              )
              self.locally_aggregated_grads.append(
                  grad_aggregation_variable
              )
          assert len(
              self.locally_aggregated_grads
          ) + self.num_none_grad_updates == len(grads)
  
      # We expect to get a `sess` when we need to manually do a `sess.run(...)`
      # for the variables to be initialized. This is the `tf.keras`
      # optimizers.
      if self.optimizer_type == self._OPTIMIZER_TYPE_KERAS:
          session = tf.compat.v1.keras.backend.get_session(
              op_input_list=()
          )
          vars_init_op = tf.compat.v1.variables_initializer(
              [
                  self.counter,
                  *get_not_none_from_list(
                      self.locally_aggregated_grads
                  ),
              ]
          )
          session.run(vars_init_op)
  
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 4 for calling the LocalGradientAggregationHelper obj's underlying member method code with example usage: obj._init_aggregation_vars(grads) without return types