class_docstr: A more manual implementation of PyTorch Lightning's ``Trainer`` class, attempting to port over
  the most commonly used ``Trainer`` arguments into a training loop with more transparency and
  faster training times.
  
  Through extensive experimentation, we found that PyTorch Lightning's ``Trainer`` was training
  Collie models about 25% slower than the more manual, typical PyTorch training loop boilerplate.
  Thus, we created the ``CollieMinimalTrainer``, which shares a similar API to PyTorch Lightning's
  ``Trainer`` object (both in instantiation and in usage), with a standard PyTorch training loop
  in its place.
  
  While PyTorch Lightning's ``Trainer`` offers more flexibility and customization through the
  addition of the additional ``Trainer`` arguments and ``callbacks``, we designed this class as a
  way to train a model in production, where we might be more focused on faster training times and
  less on hyperparameter tuning and R&D, where one might instead opt to use PyTorch Lightning's
  ``Trainer`` class.
  
  Note that the arguments the ``CollieMinimalTrainer`` trainer accepts will be slightly different
  than the ones that the ``CollieTrainer`` accept, and defaults are also not guaranteed to be
  equal as the two libraries evolve. Notable changes are:
  
  * If ``gpus > 1``, only a single GPU will be used and any other GPUs will remain unused. Multi-
    GPU training is not supported in ``CollieMinimalTrainer`` at this time.
  
  * ``logger == True`` has no meaning in ``CollieMinimalTrainer`` - a default logger will NOT be
    created if set to ``True``.
  
  * There is no way to pass in ``callbacks`` at this time. Instead, we will implement the most
    used ones during training here, manually, in favor of greater speed over customization.
    To use early stopping, set the ``early_stopping_patience`` to an integer other than ``None``.
  
  .. code-block:: python
  
      from collie.model import CollieMinimalTrainer, MatrixFactorizationModel
  
  
      # notice how similar the usage is to the standard ``CollieTrainer``
      model = MatrixFactorizationModel(train=train)
      trainer = CollieMinimalTrainer(model)
      trainer.fit(model)
  
  Model results should NOT be significantly different whether trained with ``CollieTrainer`` or
  ``CollieMinimalTrainer``.
  
  If there's an argument you would like to see added to ``CollieMinimalTrainer`` that is present
  in ``CollieTrainer`` used during productionalized model training, make an Issue or a PR in
  GitHub!
  
  Parameters
  ----------
  model: collie.model.BasePipeline
      Initialized Collie model
  max_epochs: int
      Stop training once this number of epochs is reached
  gpus: bool or int
      Whether to train on the GPU (``gpus == True`` or ``gpus > 0``) or the CPU
  logger: LightningLoggerBase
      Logger for experiment tracking. Set ``logger = None`` or ``logger = False`` to disable
      logging
  early_stopping_patience: int
      Number of epochs of patience to have without any improvement in loss before stopping
      training early. Validation epoch loss will be used if there is a validation DataLoader
      present, else training epoch loss will be used. Set ``early_stopping_patience = None`` or
      ``early_stopping_patience = False`` to disable early stopping
  log_every_n_steps: int
      How often to log within steps, if ``logger`` is enabled
  flush_logs_every_n_steps: int
      How often to flush logs to disk, if ``logger`` is enabled
  enable_model_summary: bool
      Whether to enable or disable the model summarization
  weights_summary: str
      Deprecated, replaced with ``enable_model_summary``. Prints summary of the weights when
      training begins
  detect_anomaly: bool
      Context-manager that enable anomaly detection for the autograd engine. This does two things:
  
      * Running the forward pass with detection enabled will allow the backward pass to print the
        traceback of the forward operation that created the failing backward function.
  
      * Any backward computation that generate “nan” value will raise an error.
  
      Warning: This mode should be enabled only for debugging as the different tests will slow
      down your program execution.
  terminate_on_nan: bool
      Deprecated, replaced with ``detect_anomaly``. If set to ``True``, will terminate training
      (by raising a ``ValueError``) at the end of each training batch, if any of the parameters
      or the loss are NaN or +/- infinity
  benchmark: bool
      If set to ``True``, enables ``cudnn.benchmark``
  deterministic: bool
      If set to ``True``, enables ``cudnn.deterministic``
  progress_bar_refresh_rate: int
      How often to refresh progress bar (in steps), if ``verbosity > 0``
  verbosity: Union[bool, int]
      How verbose to be in training.
  
      * ``0`` disables all printouts, including ``weights_summary``
  
      * ``1`` prints ``weights_summary`` (if applicable) and epoch losses
  
      * ``2`` prints ``weights_summary`` (if applicable), epoch losses, and progress bars
class_docstr_tok: ["A","more","manual","implementation","of","PyTorch","Lightning","'s","``","Trainer","``","class",",","attempting","to","port","over","the","most","commonly","used","``","Trainer","``","arguments","into","a","training","loop","with","more","transparency","and","faster","training","times",".","Through","extensive","experimentation",",","we","found","that","PyTorch","Lightning","'s","``","Trainer","``","was","training","Collie","models","about","25","%","slower","than","the","more","manual",",","typical","PyTorch","training","loop","boilerplate",".","Thus",",","we","created","the","``","CollieMinimalTrainer","``",",","which","shares","a","similar","API","to","PyTorch","Lightning's","``","Trainer","``","object","(","both","in","instantiation","and","in","usage",")",",","with","a","standard","PyTorch","training","loop","in","its","place",".","While","PyTorch","Lightning","'s","``","Trainer","``","offers","more","flexibility","and","customization","through","the","addition","of","the","additional","``","Trainer","``","arguments","and","``","callbacks","``",",","we","designed","this","class","as","a","way","to","train","a","model","in","production",",","where","we","might","be","more","focused","on","faster","training","times","and","less","on","hyperparameter","tuning","and","R","&","D",",","where","one","might","instead","opt","to","use","PyTorch","Lightning's","``","Trainer","``","class",".","Note","that","the","arguments","the","``","CollieMinimalTrainer","``","trainer","accepts","will","be","slightly","different","than","the","ones","that","the","``","CollieTrainer","``","accept",",","and","defaults","are","also","not","guaranteed","to","be","equal","as","the","two","libraries","evolve",".","Notable","changes","are",":","*","If","``","gpus",">","1","``",",","only","a","single","GPU","will","be","used","and","any","other","GPUs","will","remain","unused",".","Multi-","GPU","training","is","not","supported","in","``","CollieMinimalTrainer","``","at","this","time",".","*","``","logger","==","True","``","has","no","meaning","in","``","CollieMinimalTrainer","``","-","a","default","logger","will","NOT","be","created","if","set","to","``","True","``",".","*","There","is","no","way","to","pass","in","``","callbacks","``","at","this","time",".","Instead",",","we","will","implement","the","most","used","ones","during","training","here",",","manually",",","in","favor","of","greater","speed","over","customization",".","To","use","early","stopping",",","set","the","``","early_stopping_patience","``","to","an","integer","other","than","``","None","``",".","..","code-block",":",":","python","from","collie.model","import","CollieMinimalTrainer",",","MatrixFactorizationModel","#","notice","how","similar","the","usage","is","to","the","standard","``","CollieTrainer","``","model","=","MatrixFactorizationModel","(","train=train",")","trainer","=","CollieMinimalTrainer","(","model",")","trainer.fit","(","model",")","Model","results","should","NOT","be","significantly","different","whether","trained","with","``","CollieTrainer","``","or","``","CollieMinimalTrainer","``",".","If","there","'s","an","argument","you","would","like","to","see","added","to","``","CollieMinimalTrainer","``","that","is","present","in","``","CollieTrainer","``","used","during","productionalized","model","training",",","make","an","Issue","or","a","PR","in","GitHub","!","Parameters","--","--","--","--","--","model",":","collie.model.BasePipeline","Initialized","Collie","model","max_epochs",":","int","Stop","training","once","this","number","of","epochs","is","reached","gpus",":","bool","or","int","Whether","to","train","on","the","GPU","(","``","gpus","==","True","``","or","``","gpus",">","0","``",")","or","the","CPU","logger",":","LightningLoggerBase","Logger","for","experiment","tracking",".","Set","``","logger","=","None","``","or","``","logger","=","False","``","to","disable","logging","early_stopping_patience",":","int","Number","of","epochs","of","patience","to","have","without","any","improvement","in","loss","before","stopping","training","early",".","Validation","epoch","loss","will","be","used","if","there","is","a","validation","DataLoader","present",",","else","training","epoch","loss","will","be","used",".","Set","``","early_stopping_patience","=","None","``","or","``","early_stopping_patience","=","False","``","to","disable","early","stopping","log_every_n_steps",":","int","How","often","to","log","within","steps",",","if","``","logger","``","is","enabled","flush_logs_every_n_steps",":","int","How","often","to","flush","logs","to","disk",",","if","``","logger","``","is","enabled","enable_model_summary",":","bool","Whether","to","enable","or","disable","the","model","summarization","weights_summary",":","str","Deprecated",",","replaced","with","``","enable_model_summary","``",".","Prints","summary","of","the","weights","when","training","begins","detect_anomaly",":","bool","Context-manager","that","enable","anomaly","detection","for","the","autograd","engine",".","This","does","two","things",":","*","Running","the","forward","pass","with","detection","enabled","will","allow","the","backward","pass","to","print","the","traceback","of","the","forward","operation","that","created","the","failing","backward","function",".","*","Any","backward","computation","that","generate","\u201c","nan","\u201d","value","will","raise","an","error",".","Warning",":","This","mode","should","be","enabled","only","for","debugging","as","the","different","tests","will","slow","down","your","program","execution",".","terminate_on_nan",":","bool","Deprecated",",","replaced","with","``","detect_anomaly","``",".","If","set","to","``","True","``",",","will","terminate","training","(","by","raising","a","``","ValueError","``",")","at","the","end","of","each","training","batch",",","if","any","of","the","parameters","or","the","loss","are","NaN","or","+\/-","infinity","benchmark",":","bool","If","set","to","``","True","``",",","enables","``","cudnn.benchmark","``","deterministic",":","bool","If","set","to","``","True","``",",","enables","``","cudnn.deterministic","``","progress_bar_refresh_rate",":","int","How","often","to","refresh","progress","bar","(","in","steps",")",",","if","``","verbosity",">","0","``","verbosity",":","Union","[","bool",",","int","]","How","verbose","to","be","in","training",".","*","``","0","``","disables","all","printouts",",","including","``","weights_summary","``","*","``","1","``","prints","``","weights_summary","``","(","if","applicable",")","and","epoch","losses","*","``","2","``","prints","``","weights_summary","``","(","if","applicable",")",",","epoch","losses",",","and","progress","bars"]
docstr: Runs the full optimization routine.
  
  Parameters
  ----------
  model: collie.model.BasePipeline
      Initialized Collie model
docstr_tok: ["Runs","the","full","optimization","routine",".","Parameters","--","--","--","--","--","model",":","collie.model.BasePipeline","Initialized","Collie","model"]
code: def fit(self, model: BasePipeline) -> None:
      """
      Runs the full optimization routine.
  
      Parameters
      ----------
      model: collie.model.BasePipeline
          Initialized Collie model
  
      """
      if (
          not hasattr(self, "first_run_pre_training_setup_complete_")
          or not self.first_run_pre_training_setup_complete_
      ):
          self._pre_training_setup(model=model)
          self.first_run_pre_training_setup_complete_ = True
  
      self._initialize_optimizers_and_lr_schedulers(model=model)
  
      with torch.autograd.set_detect_anomaly(self.detect_anomaly):
          self._fit(model)
  
imports: import sys
  from typing import Optional, Tuple, Union
  import warnings
  from pytorch_lightning import Trainer
  from pytorch_lightning.utilities import move_data_to_device
  import torch
  from tqdm.auto import tqdm
  from collie.model.base.base_pipeline import BasePipeline
  from collie.model.base.layers import MultiLRScheduler, MultiOptimizer
label_desc: Use image node_id 4 for calling the CollieMinimalTrainer obj's underlying member method code with example usage: obj.fit(model) without return types