class_docstr: A trainer for training models. 
class_docstr_tok: ["A","trainer","for","training","models","."]
docstr: Load a model from file, with preloaded pretrain embeddings. Here we allow the pretrain to be None or a dummy input,
  and the actual use of pretrain embeddings will depend on the boolean config "pretrain" in the loaded args.
docstr_tok: ["Load","a","model","from","file",",","with","preloaded","pretrain","embeddings",".","Here","we","allow","the","pretrain","to","be","None","or","a","dummy","input",",","and","the","actual","use","of","pretrain","embeddings","will","depend","on","the","boolean","config","``","pretrain","''","in","the","loaded","args","."]
code: def load(self, filename, pretrain, args=None, foundation_cache=None):
      """
      Load a model from file, with preloaded pretrain embeddings. Here we allow the pretrain to be None or a dummy input,
      and the actual use of pretrain embeddings will depend on the boolean config "pretrain" in the loaded args.
      """
      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 is not None:
          self.args.update(args)
      # preserve old models which were created before transformers were added
      if "bert_model" not in self.args:
          self.args["bert_model"] = None
      self.vocab = MultiVocab.load_state_dict(checkpoint["vocab"])
      # load model
      emb_matrix = None
      if (
          self.args["pretrain"] and pretrain is not None
      ):  # we use pretrain only if args['pretrain'] == True and pretrain is not None
          emb_matrix = pretrain.emb
      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
          )
      self.model = Parser(
          self.args,
          self.vocab,
          emb_matrix=emb_matrix,
          foundation_cache=foundation_cache,
      )
      self.model.load_state_dict(checkpoint["model"], strict=False)
  
file_path: stanza/stanza/models/depparse/trainer.py
imports: import sys
  import logging
  import torch
  from torch import nn
  from stanza.models.common.trainer import Trainer
  from stanza.models.common import utils, loss
  from stanza.models.common.foundation_cache import NoTransformerFoundationCache
  from stanza.models.common.chuliu_edmonds import chuliu_edmonds_one_root
  from stanza.models.depparse.model import Parser
  from stanza.models.pos.vocab import MultiVocab
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