class_docstr: Gradient accumulation utility. When used with a distribution strategy, the accumulator should be called in a
  replica context. Gradients will be accumulated locally on each replica and without synchronization. Users should
  then call `.gradients`, scale the gradients if required, and pass the result to `apply_gradients`.
class_docstr_tok: ["Gradient","accumulation","utility",".","When","used","with","a","distribution","strategy",",","the","accumulator","should","be","called","in","a","replica","context",".","Gradients","will","be","accumulated","locally","on","each","replica","and","without","synchronization",".","Users","should","then","call","`",".gradients","`",",","scale","the","gradients","if","required",",","and","pass","the","result","to","`","apply_gradients","`","."]
docstr: Accumulates `gradients` on the current replica.
docstr_tok: ["Accumulates","`","gradients","`","on","the","current","replica","."]
code: def __call__(self, gradients):
      """Accumulates `gradients` on the current replica."""
      if not self._gradients:
          _ = self.step  # Create the step variable.
          self._gradients.extend(
              [
                  tf.Variable(
                      tf.zeros_like(gradient),
                      trainable=False,
                      synchronization=tf.VariableSynchronization.ON_READ,
                      aggregation=tf.VariableAggregation.ONLY_FIRST_REPLICA,
                  )
                  if gradient is not None
                  else gradient
                  for gradient in gradients
              ]
          )
      if len(gradients) != len(self._gradients):
          raise ValueError(
              f"Expected {len(self._gradients)} gradients, but got {len(gradients)}"
          )
  
      for accum_gradient, gradient in zip(self._gradients, gradients):
          if accum_gradient is not None and gradient is not None:
              accum_gradient.assign_add(gradient)
  
      self._accum_steps.assign_add(1)
  
imports: import re
  from typing import Callable, List, Optional, Union
  import tensorflow
label_desc: Use image node_id 4 for calling the GradientAccumulator obj's underlying member method code with example usage: obj.__call__(gradients) without return types