docstr: A single training step, running forward and backward. The optimizer step is called separately, as this is
  given as a closure to the optimizer step.
  
  Args:
      model: the lightning module to train
      batch: the batch to run the forward on
      batch_idx: index of the current batch w.r.t the current epoch
docstr_tok: ["A","single","training","step",",","running","forward","and","backward",".","The","optimizer","step","is","called","separately",",","as","this","is","given","as","a","closure","to","the","optimizer","step",".","Args",":","model",":","the","lightning","module","to","train","batch",":","the","batch","to","run","the","forward","on","batch_idx",":","index","of","the","current","batch","w.r.t","the","current","epoch"]
code: def training_step(
      self, model: L.LightningModule, batch: Any, batch_idx: int
  ) -> torch.Tensor:
      """A single training step, running forward and backward. The optimizer step is called separately, as this is
      given as a closure to the optimizer step.
  
      Args:
          model: the lightning module to train
          batch: the batch to run the forward on
          batch_idx: index of the current batch w.r.t the current epoch
  
      """
      outputs: Union[
          torch.Tensor, Mapping[str, Any]
      ] = model.training_step(batch, batch_idx=batch_idx)
  
      loss = (
          outputs
          if isinstance(outputs, torch.Tensor)
          else outputs["loss"]
      )
  
      self.fabric.call("on_before_backward", loss)
      self.fabric.backward(loss)
      self.fabric.call("on_after_backward")
  
      # avoid gradients in stored/accumulated values -> prevents potential OOM
      self._current_train_return = apply_to_collection(
          outputs, dtype=torch.Tensor, function=lambda x: x.detach()
      )
  
      return loss
  
imports: import os
  from collections.abc import Mapping
  from functools import partial
  from typing import Any, Iterable, List, Literal, Optional, Tuple, Union, cast
  import lightning
  import torch
  from lightning.fabric.accelerators import Accelerator
  from lightning.fabric.loggers import Logger
  from lightning.fabric.strategies import Strategy
  from lightning.fabric.wrappers import _unwrap_objects
  from lightning.pytorch.utilities.model_helpers import is_overridden
  from lightning_utilities import apply_to_collection
  from tqdm import tqdm
label_desc: Use image node_id 5 for calling the MyCustomTrainer obj's underlying member method code with example usage: obj.training_step(model, batch, batch_idx) and returns: loss