code: def from_pretrained(
      model_name_or_path,
      checkpoint_file="model.pt",
      data_name_or_path=".",
      archive_map=None,
      **kwargs,
  ):
      from fairseq import checkpoint_utils, file_utils
  
      if archive_map is not None:
          if model_name_or_path in archive_map:
              model_name_or_path = archive_map[model_name_or_path]
          if (
              data_name_or_path is not None
              and data_name_or_path in archive_map
          ):
              data_name_or_path = archive_map[data_name_or_path]
  
          # allow archive_map to set default arg_overrides (e.g., tokenizer, bpe)
          # for each model
          if isinstance(model_name_or_path, dict):
              for k, v in model_name_or_path.items():
                  if k == "checkpoint_file":
                      checkpoint_file = v
                  elif (
                      k != "path"
                      # only set kwargs that don't already have overrides
                      and k not in kwargs
                  ):
                      kwargs[k] = v
              model_name_or_path = model_name_or_path["path"]
  
      model_path = file_utils.load_archive_file(model_name_or_path)
  
      # convenience hack for loading data and BPE codes from model archive
      if data_name_or_path.startswith("."):
          kwargs["data"] = os.path.abspath(
              os.path.join(model_path, data_name_or_path)
          )
      else:
          kwargs["data"] = file_utils.load_archive_file(
              data_name_or_path
          )
      for file, arg in {
          "code": "bpe_codes",
          "bpecodes": "bpe_codes",
          "sentencepiece.bpe.model": "sentencepiece_model",
          "merges.txt": "bpe_merges",
          "vocab.json": "bpe_vocab",
      }.items():
          path = os.path.join(model_path, file)
          if os.path.exists(path):
              kwargs[arg] = path
  
      if "user_dir" in kwargs:
          utils.import_user_module(
              argparse.Namespace(user_dir=kwargs["user_dir"])
          )
  
      model_path = [
          os.path.join(model_path, cpt)
          for cpt in checkpoint_file.split(os.pathsep)
      ]
  
      if "is_vocoder" in kwargs:
          args = {"data": kwargs["data"], "model_path": model_path}
          task = None
          models = None
      else:
          (
              models,
              args,
              task,
          ) = checkpoint_utils.load_model_ensemble_and_task(
              model_path,
              arg_overrides=kwargs,
          )
      if "generation_args" in kwargs and kwargs["generation_args"]:
          for key in kwargs["generation_args"]:
              setattr(
                  args["generation"],
                  key,
                  kwargs["generation_args"][key],
              )
  
      return {
          "args": args,
          "task": task,
          "models": models,
      }
  
imports: import argparse
  import copy
  import logging
  import os
  from typing import Any, Dict, Iterator, List
  import torch
  from omegaconf import open_dict
  from torch import nn
  from fairseq import utils
  from fairseq.data import encoders
label_desc: Use image node_id 1 for calling a global function with example usage: from_pretrained(model_name_or_path, checkpoint_file, data_name_or_path, archive_map) and returns: dict