class_docstr: A trainer for training models. 
class_docstr_tok: ["A","trainer","for","training","models","."]
code: def load(
      self, filename, pretrain=None, args=None, foundation_cache=None
  ):
      try:
          checkpoint = torch.load(
              filename, lambda storage, loc: storage
          )
      except BaseException:
          logger.error("Cannot load model from {}".format(filename))
          raise
      self.args = checkpoint["config"]
      if args:
          self.args.update(args)
      # if predict_tagset was not explicitly set in the args,
      # we use the value the model was trained with
      for keep_arg in ("predict_tagset", "train_scheme", "scheme"):
          if self.args.get(keep_arg, None) is None:
              self.args[keep_arg] = checkpoint["config"].get(
                  keep_arg, None
              )
  
      self.vocab = MultiVocab.load_state_dict(checkpoint["vocab"])
  
      emb_matrix = None
      if pretrain is not None:
          emb_matrix = pretrain.emb
  
      force_bert_saved = False
      if any(
          x.startswith("bert_model.")
          for x in checkpoint["model"].keys()
      ):
          logger.debug(
              "Model %s has a finetuned transformer.  Not using transformer cache to make sure the finetuned version of the transformer isn't accidentally used elsewhere",
              filename,
          )
          foundation_cache = NoTransformerFoundationCache(
              foundation_cache
          )
          force_bert_saved = True
      if any(x.startswith("crit.") for x in checkpoint["model"].keys()):
          logger.debug(
              "Old model format detected.  Updating to the new format with one column of tags"
          )
          checkpoint["model"]["crits.0._transitions"] = checkpoint[
              "model"
          ].pop("crit._transitions")
          checkpoint["model"]["tag_clfs.0.weight"] = checkpoint[
              "model"
          ].pop("tag_clf.weight")
          checkpoint["model"]["tag_clfs.0.bias"] = checkpoint[
              "model"
          ].pop("tag_clf.bias")
      self.model = NERTagger(
          self.args,
          self.vocab,
          emb_matrix=emb_matrix,
          foundation_cache=foundation_cache,
          force_bert_saved=force_bert_saved,
      )
      self.model.load_state_dict(checkpoint["model"], strict=False)
  
      # there is a possible issue with the delta embeddings.
      # specifically, with older models trained without the delta
      # embedding matrix
      # if those models have been trained with the embedding
      # modifications saved as part of the base embedding,
      # we need to resave the model with the updated embedding
      # otherwise the resulting model will be broken
      if (
          "delta" not in self.model.vocab
          and "word_emb.weight" in checkpoint["model"].keys()
          and "word_emb" in self.model.unsaved_modules
      ):
          logger.debug(
              "Removing word_emb from unsaved_modules so that resaving %s will keep the saved embedding",
              filename,
          )
          self.model.unsaved_modules.remove("word_emb")
  
imports: import sys
  import logging
  import torch
  from torch import nn
  from stanza.models.common.foundation_cache import NoTransformerFoundationCache
  from stanza.models.common.trainer import Trainer
  from stanza.models.common.vocab import VOCAB_PREFIX, VOCAB_PREFIX_SIZE
  from stanza.models.common import utils, loss
  from stanza.models.ner.model import NERTagger
  from stanza.models.ner.vocab import MultiVocab
  from stanza.models.common.crf import viterbi_decode
label_desc: Use image node_id 5 for calling the Trainer obj's underlying member method code with example usage: obj.load(filename, pretrain, args, foundation_cache) without return types