class_docstr: An implementation of a :class:`AbstractClosure` for automatic optimization in Lightning that combines three
  elementary closures into one: ``training_step``, ``backward`` and ``zero_grad``.
  
  The Closure gets created by the training loop(s) and is then passed to the
  :meth:`torch.optim.Optimizer.step` method. An optimizer is responsible for calling the closure and optionally
  do something with the output.
  
  Args:
      step_fn: This is typically the :meth:`lightning.pytorch.core.module.LightningModule.training_step
          wrapped with processing for its outputs
      backward_fn: A function that takes a loss value as input, performs back-propagation and returns the loss value.
          Can be set to ``None`` to skip the backward operation.
      zero_grad_fn: A function that zeroes the gradients. Can be set to ``None`` to skip zero_grad, for example
          when accumulating gradients.
  
  Example:
  
      closure = Closure()
      optimizer = torch.optim.Adam(...)
      optimizer.step(closure)
code: def closure(self, *args: Any, **kwargs: Any) -> ClosureResult:
      step_output = self._step_fn()
  
      if step_output.closure_loss is None:
          self.warning_cache.warn(
              "`training_step` returned `None`. If this was on purpose, ignore this warning..."
          )
  
      if self._zero_grad_fn is not None:
          self._zero_grad_fn()
  
      if (
          self._backward_fn is not None
          and step_output.closure_loss is not None
      ):
          self._backward_fn(step_output.closure_loss)
  
      return step_output
  
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 2 for calling the Closure obj's underlying member method code with example usage: obj.closure() and returns: step_output