class_docstr: Performs automatic optimization (forward, zero grad, backward, optimizer step)
docstr: Performs the optimizer step and some sanity checking.
  
  Args:
      batch_idx: the index of the current batch
      train_step_and_backward_closure: the closure function performing the train step and computing the
          gradients. By default, called by the optimizer (if possible)
code: def _optimizer_step(
      self,
      batch_idx: int,
      train_step_and_backward_closure: Callable[[], Optional[Tensor]],
  ) -> None:
      """Performs the optimizer step and some sanity checking.
  
      Args:
          batch_idx: the index of the current batch
          train_step_and_backward_closure: the closure function performing the train step and computing the
              gradients. By default, called by the optimizer (if possible)
  
      """
      trainer = self.trainer
  
      # wraps into LightningOptimizer only for running step
      optimizer = trainer.strategy._lightning_optimizers[0]
  
      # if `strategy.handles_gradient_accumulation`, this method will be called to route into the strategy, but we
      # need to check again if `should_accumulate` before increasing the counters
      should_accumulate = trainer.fit_loop._should_accumulate()
      if not should_accumulate:
          self.optim_progress.optimizer.step.increment_ready()
  
      # model hook
      call._call_lightning_module_hook(
          trainer,
          "optimizer_step",
          trainer.current_epoch,
          batch_idx,
          optimizer,
          train_step_and_backward_closure,
      )
  
      if not should_accumulate:
          self.optim_progress.optimizer.step.increment_completed()
  
imports: from dataclasses import dataclass, field
  from functools import partial
  from typing import Any, Callable, Dict, Mapping, Optional, OrderedDict
  import torch
  from torch import Tensor
  from torch.optim import Optimizer
  from typing_extensions import override
  import lightning.pytorch
  from lightning.pytorch.loops.loop import _Loop
  from lightning.pytorch.loops.optimization.closure import AbstractClosure, OutputResult
  from lightning.pytorch.loops.progress import _OptimizationProgress
  from lightning.pytorch.loops.utilities import _block_parallel_sync_behavior
  from lightning.pytorch.trainer import call
  from lightning.pytorch.utilities.exceptions import MisconfigurationException
  from lightning.pytorch.utilities.rank_zero import WarningCache
  from lightning.pytorch.utilities.types import STEP_OUTPUT
label_desc: Use image node_id 7 for calling the _AutomaticOptimization obj's underlying member method code with example usage: obj._optimizer_step(batch_idx, train_step_and_backward_closure) without return types