code: def dry_run_from_params(params, serialization_dir):
      prepare_environment(params)
  
      vocab_params = params.pop("vocabulary", {})
      os.makedirs(serialization_dir, exist_ok=True)
      vocab_dir = os.path.join(serialization_dir, "vocabulary")
  
      if os.path.isdir(vocab_dir) and os.listdir(vocab_dir) is not None:
          raise ConfigurationError(
              "The 'vocabulary' directory in the provided "
              "serialization directory is non-empty"
          )
  
      all_datasets = datasets_from_params(params)
      datasets_for_vocab_creation = set(
          params.pop("datasets_for_vocab_creation", all_datasets)
      )
  
      for dataset in datasets_for_vocab_creation:
          if dataset not in all_datasets:
              raise ConfigurationError(
                  "invalid 'dataset_for_vocab_creation' {dataset}"
              )
  
      logger.info(
          "From dataset instances, %s will be considered for vocabulary creation.",
          ", ".join(datasets_for_vocab_creation),
      )
  
      instances = [
          instance
          for key, dataset in list(all_datasets.items())
          for instance in dataset
          if key in datasets_for_vocab_creation
      ]
  
      vocab = Vocabulary.from_params(vocab_params, instances)
      dataset = Batch(instances)
      dataset.index_instances(vocab)
      dataset.print_statistics()
      vocab.print_statistics()
  
      logger.info("writing the vocabulary to {vocab_dir}.")
      vocab.save_to_files(vocab_dir)
  
      model = Model.from_params(vocab=vocab, params=params.pop("model"))
      trainer_params = params.pop("trainer")
      no_grad_regexes = trainer_params.pop("no_grad", ())
      for name, parameter in model.named_parameters():
          if any(re.search(regex, name) for regex in no_grad_regexes):
              parameter.requires_grad_(False)
  
      (
          frozen_parameter_names,
          tunable_parameter_names,
      ) = get_frozen_and_tunable_parameter_names(model)
      logger.info(
          "Following parameters are Frozen  (without gradient):"
      )
      for name in frozen_parameter_names:
          logger.info(name)
      logger.info("Following parameters are Tunable (with gradient):")
      for name in tunable_parameter_names:
          logger.info(name)
  
file_path: magnitude/pymagnitude/third_party/allennlp/commands/dry_run.py
imports: from __future__ import absolute_import
  import argparse
  import logging
  import os
  import re
  from allennlp.commands.train import datasets_from_params
  from allennlp.commands.subcommand import Subcommand
  from allennlp.common.checks import ConfigurationError
  from allennlp.common.params import Params
  from allennlp.common.util import prepare_environment, get_frozen_and_tunable_parameter_names
  from allennlp.data import Vocabulary
  from allennlp.data.dataset import Batch
  from allennlp.models import Model
label_desc: Use image node_id 2 for calling a global function with example usage: dry_run_from_params(params, serialization_dir) without return types