class_docstr: Internal wrapper around a torch optimizer.
  
  Conditionally will perform `step` and `zero_grad` if gradients should be synchronized when performing gradient
  accumulation.
  
  Args:
      optimizer (`torch.optim.optimizer.Optimizer`):
          The optimizer to wrap.
      device_placement (`bool`, *optional*, defaults to `True`):
          Whether or not the optimizer should handle device placement. If so, it will place the state dictionary of
          `optimizer` on the right device.
      scaler (`torch.cuda.amp.grad_scaler.GradScaler`, *optional*):
          The scaler to use in the step function if training with mixed precision.
class_docstr_tok: ["Internal","wrapper","around","a","torch","optimizer",".","Conditionally","will","perform","`","step","`","and","`","zero_grad","`","if","gradients","should","be","synchronized","when","performing","gradient","accumulation",".","Args",":","optimizer","(","`","torch.optim.optimizer.Optimizer","`",")",":","The","optimizer","to","wrap",".","device_placement","(","`","bool","`",",","*","optional","*",",","defaults","to","`","True","`",")",":","Whether","or","not","the","optimizer","should","handle","device","placement",".","If","so",",","it","will","place","the","state","dictionary","of","`","optimizer","`","on","the","right","device",".","scaler","(","`","torch.cuda.amp.grad_scaler.GradScaler","`",",","*","optional","*",")",":","The","scaler","to","use","in","the","step","function","if","training","with","mixed","precision","."]
code: def step(self, closure=None):
      if self.gradient_state.sync_gradients:
          if (
              self.accelerator_state.distributed_type
              == DistributedType.TPU
          ):
              optimizer_args = (
                  {"closure": closure} if closure is not None else {}
              )
              xm.optimizer_step(
                  self.optimizer, optimizer_args=optimizer_args
              )
          elif self.scaler is not None:
              self.optimizer.step = self._optimizer_patched_step_method
  
              self.scaler.step(self.optimizer, closure)
              self.scaler.update()
  
              if not self._accelerate_step_called:
                  # If the optimizer step was skipped, gradient overflow was detected.
                  self._is_overflow = True
              else:
                  self._is_overflow = False
              # Reset the step method to the original one
              self.optimizer.step = self._optimizer_original_step_method
              # Reset the indicator
              self._accelerate_step_called = False
          else:
              self.optimizer.step(closure)
  
imports: import inspect
  import warnings
  import torch
  from .state import AcceleratorState, GradientState
  from .utils import DistributedType, honor_type, is_tpu_available
label_desc: Use image node_id 12 for calling the AcceleratedOptimizer obj's underlying member method code with example usage: obj.step(closure) without return types