class_docstr: The basic Trainer for basic training and evaluation strategies in text generation systems.
  
  This class defines common functions for training and evaluation processes of most text generation system models,
  including `fit()`, `evaluate()`, `resume_checkpoint()` and some other features helpful for model training and
  evaluation.
  
  Generally speaking, this class can serve most text generation system models, If the training process of the model
  is to simply optimize a single loss without involving any complex training strategies, such as adversarial learning,
  pre-training and so on.
  
  Initializing the Trainer needs two parameters: `config` and `model`. `config` records the parameters' information
  for controlling training and evaluation, such as `learning_rate`, `epochs` and so on.
  More information can be found in [placeholder]. `model` is the instantiated object of a Model Class.
class_docstr_tok: ["The","basic","Trainer","for","basic","training","and","evaluation","strategies","in","text","generation","systems",".","This","class","defines","common","functions","for","training","and","evaluation","processes","of","most","text","generation","system","models",",","including","`","fit","(",")","`",",","`","evaluate","(",")","`",",","`","resume_checkpoint","(",")","`","and","some","other","features","helpful","for","model","training","and","evaluation",".","Generally","speaking",",","this","class","can","serve","most","text","generation","system","models",",","If","the","training","process","of","the","model","is","to","simply","optimize","a","single","loss","without","involving","any","complex","training","strategies",",","such","as","adversarial","learning",",","pre-training","and","so","on",".","Initializing","the","Trainer","needs","two","parameters",":","`","config","`","and","`","model","`",".","`","config","`","records","the","parameters","'","information","for","controlling","training","and","evaluation",",","such","as","`","learning_rate","`",",","`","epochs","`","and","so","on",".","More","information","can","be","found","in","[","placeholder","]",".","`","model","`","is","the","instantiated","object","of","a","Model","Class","."]
docstr: Load training information.
  
  Args:
      resume_dir: the checkpoint file (specific by `model_path`).
docstr_tok: ["Load","training","information",".","Args",":","resume_dir",":","the","checkpoint","file","(","specific","by","`","model_path","`",")","."]
code: def resume_checkpoint(self, resume_dir: str):
      r"""Load training information.
  
      Args:
          resume_dir: the checkpoint file (specific by `model_path`).
      """
      # check
      self.logger.info(
          "Resuming checkpoint from {}...".format(resume_dir)
      )
      resume_checkpoint = os.path.join(
          resume_dir, "textbox_configuration.pt"
      )
      resume_optimizer = os.path.join(resume_dir, "optimizer.pt")
      if os.path.isfile(resume_checkpoint):
          checkpoint = torch.load(
              resume_checkpoint, map_location=self.device
          )
      else:
          self.logger.warning(
              'Checkpoint file "{}" not found. Resuming stopped.'.format(
                  resume_dir
              )
          )
          return
      if (
          checkpoint["config"]["optimizer"].lower()
          != self.config["optimizer"]
      ):
          self.logger.warning(
              "Optimizer configuration given in config file is different from that of checkpoint. "
              "This may yield an exception while state_dict is being loaded."
          )
      if os.path.isfile(resume_optimizer):
          optim_state_dict = torch.load(
              resume_optimizer, map_location=self.device
          )
          self.optimizer.load_state_dict(optim_state_dict)
      else:
          self.logger.warning(
              'Checkpoint file "{}" not found. Resuming stopped.'.format(
                  resume_dir
              )
          )
          return
  
      # load start epoch and early stopping
      self.start_epoch = (
          checkpoint["epoch"] + 1
      )  # start from the next step
      self._summary_tracker.axes = checkpoint["timestamp"]
      self.stopping_count = checkpoint["stopping_count"]
      self._summary_tracker.best_valid_score = checkpoint[
          "best_valid_score"
      ]
      self._summary_tracker.best_valid_timestamp = (
          self._summary_tracker.axes
      )
      self.valid_result_dict = {
          self._summary_tracker.axes.valid_epoch: checkpoint["summary"]
      }
  
      if checkpoint["config"]["seed"]:
          init_seed(
              checkpoint["config"]["seed"],
              checkpoint["config"]["reproducibility"],
          )
          set_seed(checkpoint["config"]["seed"])
  
      # load architecture params from checkpoint
      if (
          checkpoint["config"]["model_name"]
          != self.config["model_name"]
      ):
          self.logger.warning(
              "Architecture configuration given in config file is different from that of checkpoint. "
              "This may yield an exception while state_dict is being loaded."
          )
  
      # load optimizer state from checkpoint only when optimizer type is not changed
  
      self.logger.info(
          "Checkpoint loaded. Resume training from epoch {} steps {}".format(
              self.start_epoch,
              self._summary_tracker.axes.train_step + 1,
          )
      )
  
imports: import collections
  import os
  from accelerate.logging import get_logger
  from typing import Optional, Union, List, Dict
  import math
  import torch
  import torch.optim
  import transformers
  from accelerate import Accelerator
  from accelerate.utils import set_seed
  from torch.utils.data import DataLoader
  from tqdm import tqdm
  from textbox import Config
  from textbox.utils.dashboard import get_dashboard, Timestamp, EpochTracker
  from .scheduler import AbstractScheduler, InverseSquareRootScheduler, CosineScheduler, LinearScheduler, ConstantScheduler
  from torch.utils.data import DataLoader
  from ..evaluator import BaseEvaluator
  from ..model.abstract_model import AbstractModel
  from ..utils import serialized_save, init_seed
  from ..utils.enum_type import PLM_MODELS, RNN_MODELS
label_desc: Use image node_id 12 for calling the Trainer obj's underlying member method code with example usage: obj.resume_checkpoint(resume_dir) without return types