class_docstr: A container to hold the result of a :class:`Closure` call.
  
  It is created from the output of :meth:`~lightning.pytorch.core.LightningModule.training_step`.
  
  Attributes:
      closure_loss: The loss with a graph attached.
      loss: A detached copy of the closure loss.
      extra: Any keys other than the loss returned.
code: def from_training_step_output(
      cls, training_step_output: STEP_OUTPUT, normalize: int = 1
  ) -> "ClosureResult":
      closure_loss, extra = None, {}
  
      if isinstance(training_step_output, Mapping):
          closure_loss = training_step_output.get("loss")
          if closure_loss is None:
              raise MisconfigurationException(
                  "In automatic_optimization, when `training_step` returns a dict, the 'loss' key needs to be present"
              )
          extra = {
              k: v
              for k, v in training_step_output.items()
              if k != "loss"
          }
      elif isinstance(training_step_output, Tensor):
          closure_loss = training_step_output
      elif training_step_output is not None:
          raise MisconfigurationException(
              "In automatic optimization, `training_step` must return a Tensor, a dict, or None (where the step will"
              " be skipped)."
          )
  
      if closure_loss is not None:
          # accumulate the loss. If ``accumulate_grad_batches == 1``, no effect
          # note: avoid in-place operation `x /= y` here on purpose
          closure_loss = closure_loss / normalize
  
      return cls(closure_loss, extra=extra)
  
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 3 for calling the ClosureResult obj's underlying member method code with example usage: obj.from_training_step_output(cls, training_step_output, normalize) and returns: cls