class_docstr: A training loop.
class_docstr_tok: ["A","training","loop","."]
code: def _forward_pass(
      self,
      batch: BatchType,
      start: int,
      stop: int,
      current_batch_size: int,
      label_smoothing: float,
      slice_size: Optional[int],
      backward: bool = True,
  ) -> float:
      # forward pass
      loss = self._process_batch(
          batch=batch,
          start=start,
          stop=stop,
          label_smoothing=label_smoothing,
          slice_size=slice_size,
      )
  
      # raise error when non-finite loss occurs (NaN, +/-inf)
      if not torch.isfinite(loss):
          raise NonFiniteLossError("Loss is non-finite.")
  
      # correction for loss reduction
      if self.model.loss.reduction == "mean":
          this_sub_batch_size = stop - start
          loss *= this_sub_batch_size / current_batch_size
  
      # backward pass
      if backward:
          loss.backward()
      current_epoch_loss = loss.item()
  
      self.model.post_forward_pass()
      # TODO why not call torch.cuda.empty_cache()? or call self._free_graph_and_cache()?
  
      return current_epoch_loss
  
imports: import gc
  import logging
  import os
  import pathlib
  import pickle
  import random
  import time
  from abc import ABC, abstractmethod
  from contextlib import ExitStack
  from datetime import datetime
  from hashlib import md5
  from tempfile import NamedTemporaryFile, TemporaryDirectory
  from typing import IO, Any, ClassVar, Generic, List, Mapping, Optional, Tuple, TypeVar, Union
  import numpy
  import torch
  from class_resolver import HintOrType, OptionalKwargs
  from class_resolver.contrib.torch import lr_scheduler_resolver, optimizer_resolver
  from torch.optim.optimizer import Optimizer
  from torch.utils.data import DataLoader
  from tqdm.autonotebook import tqdm, trange
  from .callbacks import GradientAbsClippingTrainingCallback, GradientNormClippingTrainingCallback, LearningRateSchedulerTrainingCallback, MultiTrainingCallback, OptimizerTrainingCallback, StopperTrainingCallback, TrackerTrainingCallback, TrainingCallback, TrainingCallbackHint, TrainingCallbackKwargsHint
  from ..constants import PYKEEN_CHECKPOINTS, PYKEEN_DEFAULT_CHECKPOINT
  from ..lr_schedulers import LRScheduler
  from ..models import RGCN, Model
  from ..stoppers import Stopper
  from ..trackers import ResultTracker, tracker_resolver
  from ..triples import CoreTriplesFactory, TriplesFactory
  from ..typing import InductiveMode
  from ..utils import format_relative_comparison, get_batchnorm_modules, get_preferred_device, is_cuda_oom_error, is_cudnn_error, normalize_string
label_desc: Use image node_id 10 for calling the TrainingLoop obj's underlying member method code with example usage: obj._forward_pass(batch, start, stop, current_batch_size, label_smoothing, slice_size, backward) and returns: current_epoch_loss