code: def load_archive(
      archive_file, cuda_device=-1, overrides="", weights_file=None
  ):
      """
      Instantiates an Archive from an archived `tar.gz` file.
  
      Parameters
      ----------
      archive_file: ``str``
          The archive file to load the model from.
      weights_file: ``str``, optional (default = None)
          The weights file to use.  If unspecified, weights.th in the archive_file will be used.
      cuda_device: ``int``, optional (default = -1)
          If `cuda_device` is >= 0, the model will be loaded onto the
          corresponding GPU. Otherwise it will be loaded onto the CPU.
      overrides: ``str``, optional (default = "")
          JSON overrides to apply to the unarchived ``Params`` object.
      """
      # redirect to the cache, if necessary
      resolved_archive_file = cached_path(archive_file)
  
      if resolved_archive_file == archive_file:
          logger.info("loading archive file {archive_file}")
      else:
          logger.info(
              "loading archive file {archive_file} from cache at {resolved_archive_file}"
          )
  
      tempdir = None
      if os.path.isdir(resolved_archive_file):
          serialization_dir = resolved_archive_file
      else:
          # Extract archive to temp dir
          tempdir = tempfile.mkdtemp()
          logger.info(
              "extracting archive file {resolved_archive_file} to temp dir {tempdir}"
          )
          with tarfile.open(resolved_archive_file, "r:gz") as archive:
              archive.extractall(tempdir)
  
          serialization_dir = tempdir
  
      # Check for supplemental files in archive
      fta_filename = os.path.join(serialization_dir, _FTA_NAME)
      if os.path.exists(fta_filename):
          with open(fta_filename, "r") as fta_file:
              files_to_archive = json.loads(fta_file.read())
  
          # Add these replacements to overrides
          replacements_dict = {}
          for key, _ in list(files_to_archive.items()):
              replacement_filename = os.path.join(
                  serialization_dir, "fta/{key}"
              )
              replacements_dict[key] = replacement_filename
  
          overrides_dict = parse_overrides(overrides)
          combined_dict = with_fallback(
              preferred=unflatten(replacements_dict),
              fallback=overrides_dict,
          )
          overrides = json.dumps(combined_dict)
  
      # Load config
      config = Params.from_file(
          os.path.join(serialization_dir, CONFIG_NAME), overrides
      )
      config.loading_from_archive = True
  
      if weights_file:
          weights_path = weights_file
      else:
          weights_path = os.path.join(serialization_dir, _WEIGHTS_NAME)
  
      # Instantiate model. Use a duplicate of the config, as it will get consumed.
      model = Model.load(
          config.duplicate(),
          weights_file=weights_path,
          serialization_dir=serialization_dir,
          cuda_device=cuda_device,
      )
  
      if tempdir:
          # Clean up temp dir
          shutil.rmtree(tempdir)
  
      return Archive(model=model, config=config)
  
file_path: magnitude/pymagnitude/third_party/allennlp/models/archival.py
imports: from __future__ import with_statement
  from __future__ import absolute_import
  import json
  import logging
  import os
  import tempfile
  import tarfile
  import shutil
  from allennlp.common.file_utils import cached_path
  from allennlp.common.params import Params, unflatten, with_fallback, parse_overrides
  from allennlp.models.model import Model, _DEFAULT_WEIGHTS
  from io import open
label_desc: Use image node_id 2 for calling a global function with example usage: load_archive(archive_file, cuda_device, overrides, weights_file) and returns: Archive