code: def archive_model(
      serialization_dir, weights=_DEFAULT_WEIGHTS, files_to_archive=None
  ):
      """
      Archive the model weights, its training configuration, and its
      vocabulary to `model.tar.gz`. Include the additional ``files_to_archive``
      if provided.
  
      Parameters
      ----------
      serialization_dir: ``str``
          The directory where the weights and vocabulary are written out.
      weights: ``str``, optional (default=_DEFAULT_WEIGHTS)
          Which weights file to include in the archive. The default is ``best.th``.
      files_to_archive: ``Dict[str, str]``, optional (default=None)
          A mapping {flattened_key -> filename} of supplementary files to include
          in the archive. That is, if you wanted to include ``params['model']['weights']``
          then you would specify the key as `"model.weights"`.
      """
      weights_file = os.path.join(serialization_dir, weights)
      if not os.path.exists(weights_file):
          logger.error(
              "weights file %s does not exist, unable to archive model",
              weights_file,
          )
          return
  
      config_file = os.path.join(serialization_dir, CONFIG_NAME)
      if not os.path.exists(config_file):
          logger.error(
              "config file %s does not exist, unable to archive model",
              config_file,
          )
  
      # If there are files we want to archive, write out the mapping
      # so that we can use it during de-archiving.
      if files_to_archive:
          fta_filename = os.path.join(serialization_dir, _FTA_NAME)
          with open(fta_filename, "w") as fta_file:
              fta_file.write(json.dumps(files_to_archive))
  
      archive_file = os.path.join(serialization_dir, "model.tar.gz")
      logger.info(
          "archiving weights and vocabulary to %s", archive_file
      )
      with tarfile.open(archive_file, "w:gz") as archive:
          archive.add(config_file, arcname=CONFIG_NAME)
          archive.add(weights_file, arcname=_WEIGHTS_NAME)
          archive.add(
              os.path.join(serialization_dir, "vocabulary"),
              arcname="vocabulary",
          )
  
          # If there are supplemental files to archive:
          if files_to_archive:
              # Archive the { flattened_key -> original_filename } mapping.
              archive.add(fta_filename, arcname=_FTA_NAME)
              # And add each requested file to the archive.
              for key, filename in list(files_to_archive.items()):
                  archive.add(filename, arcname="fta/{key}")
  
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 1 for calling a global function with example usage: archive_model(serialization_dir, weights, files_to_archive) without return types