class_docstr: A training loop.
class_docstr_tok: ["A","training","loop","."]
docstr: Initialize the training loop.
  
  :param model: The model to train
  :param triples_factory: The training triples factory
  :param optimizer: The optimizer to use while training the model
  :param optimizer_kwargs:
      additional keyword-based parameters to instantiate the optimizer (if necessary). `params` will be added
      automatically based on the `model`.
  :param lr_scheduler: The learning rate scheduler you want to use while training the model
  :param lr_scheduler_kwargs:
      additional keyword-based parameters to instantiate the LR scheduler (if necessary). `optimizer` will be
      added automatically.
  :param automatic_memory_optimization: bool
      Whether to automatically optimize the sub-batch size during
      training and batch size during evaluation with regards to the hardware at hand.
  :param mode: The inductive training mode. None if transductive.
  :param result_tracker:
      the result tracker
  :param result_tracker_kwargs:
      additional keyword-based parameters to instantiate the result tracker
docstr_tok: ["Initialize","the","training","loop",".",":","param","model",":","The","model","to","train",":","param","triples_factory",":","The","training","triples","factory",":","param","optimizer",":","The","optimizer","to","use","while","training","the","model",":","param","optimizer_kwargs",":","additional","keyword-based","parameters","to","instantiate","the","optimizer","(","if","necessary",")",".","`","params","`","will","be","added","automatically","based","on","the","`","model","`",".",":","param","lr_scheduler",":","The","learning","rate","scheduler","you","want","to","use","while","training","the","model",":","param","lr_scheduler_kwargs",":","additional","keyword-based","parameters","to","instantiate","the","LR","scheduler","(","if","necessary",")",".","`","optimizer","`","will","be","added","automatically",".",":","param","automatic_memory_optimization",":","bool","Whether","to","automatically","optimize","the","sub-batch","size","during","training","and","batch","size","during","evaluation","with","regards","to","the","hardware","at","hand",".",":","param","mode",":","The","inductive","training","mode",".","None","if","transductive",".",":","param","result_tracker",":","the","result","tracker",":","param","result_tracker_kwargs",":","additional","keyword-based","parameters","to","instantiate","the","result","tracker"]
code: def __init__(
      self,
      model: Model,
      triples_factory: CoreTriplesFactory,
      optimizer: HintOrType[Optimizer] = None,
      optimizer_kwargs: OptionalKwargs = None,
      lr_scheduler: HintOrType[LRScheduler] = None,
      lr_scheduler_kwargs: OptionalKwargs = None,
      automatic_memory_optimization: bool = True,
      mode: Optional[InductiveMode] = None,
      result_tracker: HintOrType[ResultTracker] = None,
      result_tracker_kwargs: OptionalKwargs = None,
  ) -> None:
      """Initialize the training loop.
  
      :param model: The model to train
      :param triples_factory: The training triples factory
      :param optimizer: The optimizer to use while training the model
      :param optimizer_kwargs:
          additional keyword-based parameters to instantiate the optimizer (if necessary). `params` will be added
          automatically based on the `model`.
      :param lr_scheduler: The learning rate scheduler you want to use while training the model
      :param lr_scheduler_kwargs:
          additional keyword-based parameters to instantiate the LR scheduler (if necessary). `optimizer` will be
          added automatically.
      :param automatic_memory_optimization: bool
          Whether to automatically optimize the sub-batch size during
          training and batch size during evaluation with regards to the hardware at hand.
      :param mode: The inductive training mode. None if transductive.
      :param result_tracker:
          the result tracker
      :param result_tracker_kwargs:
          additional keyword-based parameters to instantiate the result tracker
      """
      self.model = model
      self.optimizer = optimizer_resolver.make(
          optimizer,
          pos_kwargs=optimizer_kwargs,
          params=model.get_grad_params(),
      )
      self.lr_scheduler = lr_scheduler_resolver.make_safe(
          lr_scheduler,
          pos_kwargs=lr_scheduler_kwargs,
          optimizer=self.optimizer,
      )
      self.losses_per_epochs = []
      self._should_stop = False
      self.automatic_memory_optimization = automatic_memory_optimization
      self.mode = mode
      self.result_tracker = tracker_resolver.make(
          query=result_tracker, pos_kwargs=result_tracker_kwargs
      )
  
      logger.debug(
          "we don't really need the triples factory: %s",
          triples_factory,
      )
  
      # The internal epoch state tracks the last finished epoch of the training loop to allow for
      # seamless loading and saving of training checkpoints
      self._epoch = 0
  
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 1 to create a new TrainingLoop object from inherited base classes: Generic, ABC with example: obj = TrainingLoop(model, triples_factory, optimizer, optimizer_kwargs, lr_scheduler, lr_scheduler_kwargs, automatic_memory_optimization, mode, result_tracker, result_tracker_kwargs)