docstr: Restores a model from a serialization_dir to the last saved checkpoint.
  This includes an epoch count and optimizer state, which is serialized separately
  from  model parameters. This function should only be used to continue training -
  if you wish to load a model for inference/load parts of a model into a new
  computation graph, you should use the native Pytorch functions:
  `` model.load_state_dict(torch.load("/path/to/model/weights.th"))``
  
  If ``self._serialization_dir`` does not exist or does not contain any checkpointed weights,
  this function will do nothing and return 0.
  
  Returns
  -------
  epoch: int
      The epoch at which to resume training, which should be one after the epoch
      in the saved training state.
docstr_tok: ["Restores","a","model","from","a","serialization_dir","to","the","last","saved","checkpoint",".","This","includes","an","epoch","count","and","optimizer","state",",","which","is","serialized","separately","from","model","parameters",".","This","function","should","only","be","used","to","continue","training","-","if","you","wish","to","load","a","model","for","inference\/load","parts","of","a","model","into","a","new","computation","graph",",","you","should","use","the","native","Pytorch","functions",":","``","model.load_state_dict","(","torch.load","(","``","\/path\/to\/model\/weights.th","''",")",")","``","If","``","self._serialization_dir","``","does","not","exist","or","does","not","contain","any","checkpointed","weights",",","this","function","will","do","nothing","and","return","0",".","Returns","--","--","--","-","epoch",":","int","The","epoch","at","which","to","resume","training",",","which","should","be","one","after","the","epoch","in","the","saved","training","state","."]
code: def _restore_checkpoint(self):
      """
      Restores a model from a serialization_dir to the last saved checkpoint.
      This includes an epoch count and optimizer state, which is serialized separately
      from  model parameters. This function should only be used to continue training -
      if you wish to load a model for inference/load parts of a model into a new
      computation graph, you should use the native Pytorch functions:
      `` model.load_state_dict(torch.load("/path/to/model/weights.th"))``
  
      If ``self._serialization_dir`` does not exist or does not contain any checkpointed weights,
      this function will do nothing and return 0.
  
      Returns
      -------
      epoch: int
          The epoch at which to resume training, which should be one after the epoch
          in the saved training state.
      """
      latest_checkpoint = self.find_latest_checkpoint()
  
      if latest_checkpoint is None:
          # No checkpoint to restore, start at 0
          return 0, []
  
      model_path, training_state_path = latest_checkpoint
  
      # Load the parameters onto CPU, then transfer to GPU.
      # This avoids potential OOM on GPU for large models that
      # load parameters onto GPU then make a new GPU copy into the parameter
      # buffer. The GPU transfer happens implicitly in load_state_dict.
      model_state = torch.load(
          model_path, map_location=util.device_mapping(-1)
      )
      training_state = torch.load(
          training_state_path, map_location=util.device_mapping(-1)
      )
      self._model.load_state_dict(model_state)
      self._optimizer.load_state_dict(training_state["optimizer"])
      move_optimizer_to_cuda(self._optimizer)
  
      # We didn't used to save `validation_metric_per_epoch`, so we can't assume
      # that it's part of the trainer state. If it's not there, an empty list is all
      # we can do.
      if "val_metric_per_epoch" not in training_state:
          logger.warning(
              "trainer state `val_metric_per_epoch` not found, using empty list"
          )
          val_metric_per_epoch = []
      else:
          val_metric_per_epoch = training_state["val_metric_per_epoch"]
  
      if isinstance(training_state["epoch"], int):
          epoch_to_return = training_state["epoch"] + 1
      else:
          epoch_to_return = (
              int(training_state["epoch"].split(".")[0]) + 1
          )
  
      # For older checkpoints with batch_num_total missing, default to old behavior where
      # it is unchanged.
      batch_num_total = training_state.get("batch_num_total")
      if batch_num_total is not None:
          self._batch_num_total = batch_num_total
  
      return epoch_to_return, val_metric_per_epoch
  
imports: from __future__ import with_statement
  from __future__ import division
  from __future__ import absolute_import
  import logging
  import os
  import shutil
  import time
  import re
  import datetime
  import traceback
  import torch
  import torch.optim.lr_scheduler
  from torch.nn.parallel import replicate, parallel_apply
  from torch.nn.parallel.scatter_gather import scatter_kwargs, gather
  from allennlp.common import Params
  from allennlp.common.checks import ConfigurationError
  from allennlp.common.util import peak_memory_mb, gpu_memory_mb
  from allennlp.common.tqdm import Tqdm
  from allennlp.data.instance import Instance
  from allennlp.data.iterators.data_iterator import DataIterator
  from allennlp.models.model import Model
  from allennlp.nn import util
  from allennlp.training.learning_rate_schedulers import LearningRateScheduler
  from allennlp.training.optimizers import Optimizer
label_desc: Use image node_id 20 for calling the Trainer obj's underlying member method code with example usage: obj._restore_checkpoint() and returns: epoch_to_return,  val_metric_per_epoch, int,  list