class_docstr: Handles the main model training procedure. This includes performing evaluation on the dev set at regular
  intervals during training as well as evaluation on the test set at the end of training.
class_docstr_tok: ["Handles","the","main","model","training","procedure",".","This","includes","performing","evaluation","on","the","dev","set","at","regular","intervals","during","training","as","well","as","evaluation","on","the","test","set","at","the","end","of","training","."]
docstr: Try loading a saved Trainer checkpoint. If no checkpoint found, it creates a new instance of Trainer.
  
  :param data_silo: A DataSilo object that will contain the train, dev and test datasets as PyTorch DataLoaders
  :type data_silo: DataSilo
  :param checkpoint_root_dir: Path of the directory where all train checkpoints are saved. Each individual
         checkpoint is stored in a sub-directory under it.
  :type checkpoint_root_dir: Path
  :param resume_from_checkpoint: the checkpoint name to start training from, e.g., "epoch_1_step_4532". It
         defaults to "latest", using the checkpoint with the highest train steps.
  :type resume_from_checkpoint: str
docstr_tok: ["Try","loading","a","saved","Trainer","checkpoint",".","If","no","checkpoint","found",",","it","creates","a","new","instance","of","Trainer",".",":","param","data_silo",":","A","DataSilo","object","that","will","contain","the","train",",","dev","and","test","datasets","as","PyTorch","DataLoaders",":","type","data_silo",":","DataSilo",":","param","checkpoint_root_dir",":","Path","of","the","directory","where","all","train","checkpoints","are","saved",".","Each","individual","checkpoint","is","stored","in","a","sub-directory","under","it",".",":","type","checkpoint_root_dir",":","Path",":","param","resume_from_checkpoint",":","the","checkpoint","name","to","start","training","from",",","e.g.",",","``","epoch_1_step_4532","''",".","It","defaults","to","``","latest","''",",","using","the","checkpoint","with","the","highest","train","steps",".",":","type","resume_from_checkpoint",":","str"]
code: def create_or_load_checkpoint(
      cls,
      data_silo,
      checkpoint_root_dir,
      model,
      optimizer,
      local_rank=-1,
      resume_from_checkpoint="latest",
      **kwargs,
  ):
      """
      Try loading a saved Trainer checkpoint. If no checkpoint found, it creates a new instance of Trainer.
  
      :param data_silo: A DataSilo object that will contain the train, dev and test datasets as PyTorch DataLoaders
      :type data_silo: DataSilo
      :param checkpoint_root_dir: Path of the directory where all train checkpoints are saved. Each individual
             checkpoint is stored in a sub-directory under it.
      :type checkpoint_root_dir: Path
      :param resume_from_checkpoint: the checkpoint name to start training from, e.g., "epoch_1_step_4532". It
             defaults to "latest", using the checkpoint with the highest train steps.
      :type resume_from_checkpoint: str
      """
      checkpoint_to_load = None
      if checkpoint_root_dir:
          if checkpoint_root_dir.exists():
              if resume_from_checkpoint == "latest":
                  saved_checkpoints = cls._get_checkpoints(
                      checkpoint_root_dir
                  )
                  if saved_checkpoints:
                      checkpoint_to_load = saved_checkpoints[
                          0
                      ]  # latest checkpoint
                  else:
                      checkpoint_to_load = None
              else:
                  checkpoint_to_load = (
                      checkpoint_root_dir / resume_from_checkpoint
                  )
  
      if checkpoint_to_load:
          # TODO load empty model class from config instead of passing here?
          trainer = cls._load_checkpoint(
              path=checkpoint_to_load,
              data_silo=data_silo,
              model=model,
              optimizer=optimizer,
              local_rank=local_rank,
          )
          logging.info(
              f"Resuming training from the train checkpoint at {checkpoint_to_load} ..."
          )
      else:
          logging.info(
              f"No train checkpoints found. Starting a new training ..."
          )
          trainer = Trainer(
              data_silo=data_silo,
              model=model,
              optimizer=optimizer,
              local_rank=local_rank,
              checkpoint_root_dir=checkpoint_root_dir,
              **kwargs,
          )
      return trainer
  
imports: import logging
  import sys
  import torch
  from pathlib import Path
  from tqdm import tqdm
  import numpy
  import shutil
  import dill
  from farm.utils import MLFlowLogger
  from farm.utils import GracefulKiller, set_all_seeds
  from farm.eval import Evaluator
  from farm.data_handler.data_silo import DataSilo
  from farm.visual.ascii.images import GROWING_TREE
  from farm.modeling.adaptive_model import AdaptiveModel
  from farm.modeling.biadaptive_model import BiAdaptiveModel
  from farm.modeling.optimization import get_scheduler
label_desc: Use image node_id 6 for calling the Trainer obj's underlying member method code with example usage: obj.create_or_load_checkpoint(cls, data_silo, checkpoint_root_dir, model, optimizer, local_rank, resume_from_checkpoint) and returns: trainer