code: def find_learning_rate_model(
      params: Params,
      serialization_dir: str,
      start_lr: float = 1e-5,
      end_lr: float = 10,
      num_batches: int = 100,
      linear_steps: bool = False,
      stopping_factor: float = None,
      force: bool = False,
  ) -> None:
      """
      Runs learning rate search for given `num_batches` and saves the results in ``serialization_dir``
  
      # Parameters
  
      params : `Params`
          A parameter object specifying an AllenNLP Experiment.
      serialization_dir : `str`
          The directory in which to save results.
      start_lr : `float`
          Learning rate to start the search.
      end_lr : `float`
          Learning rate upto which search is done.
      num_batches : `int`
          Number of mini-batches to run Learning rate finder.
      linear_steps : `bool`
          Increase learning rate linearly if False exponentially.
      stopping_factor : `float`
          Stop the search when the current loss exceeds the best loss recorded by
          multiple of stopping factor. If `None` search proceeds till the `end_lr`
      force : `bool`
          If True and the serialization directory already exists, everything in it will
          be removed prior to finding the learning rate.
      """
      create_serialization_dir(
          params, serialization_dir, recover=False, force=force
      )
  
      prepare_environment(params)
  
      cuda_device = params.params.get("trainer").get("cuda_device", -1)
      check_for_gpu(cuda_device)
      distributed_params = params.params.get("distributed")
      # See https://github.com/allenai/allennlp/issues/3658
      assert (
          not distributed_params
      ), "find-lr is not compatible with DistributedDataParallel."
  
      all_data_loaders = data_loaders_from_params(params)
      datasets_for_vocab_creation = set(
          params.pop("datasets_for_vocab_creation", all_data_loaders)
      )
  
      for dataset in datasets_for_vocab_creation:
          if dataset not in all_data_loaders:
              raise ConfigurationError(
                  f"invalid 'dataset_for_vocab_creation' {dataset}"
              )
  
      logger.info(
          "From dataset instances, %s will be considered for vocabulary creation.",
          ", ".join(datasets_for_vocab_creation),
      )
      vocab = Vocabulary.from_params(
          params.pop("vocabulary", {}),
          instances=(
              instance
              for key, data_loader in all_data_loaders.items()
              if key in datasets_for_vocab_creation
              for instance in data_loader.iter_instances()
          ),
      )
  
      model = Model.from_params(
          vocab=vocab,
          params=params.pop("model"),
          serialization_dir=serialization_dir,
      )
  
      all_data_loaders["train"].index_with(vocab)
  
      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)
  
      trainer_choice = trainer_params.pop("type", "gradient_descent")
      if trainer_choice != "gradient_descent":
          raise ConfigurationError(
              "currently find-learning-rate only works with the GradientDescentTrainer"
          )
      trainer: GradientDescentTrainer = Trainer.from_params(  # type: ignore
          model=model,
          serialization_dir=serialization_dir,
          data_loader=all_data_loaders["train"],
          params=trainer_params,
      )
  
      logger.info(
          f"Starting learning rate search from {start_lr} to {end_lr} in {num_batches} iterations."
      )
      learning_rates, losses = search_learning_rate(
          trainer,
          start_lr=start_lr,
          end_lr=end_lr,
          num_batches=num_batches,
          linear_steps=linear_steps,
          stopping_factor=stopping_factor,
      )
      logger.info("Finished learning rate search.")
      losses = _smooth(losses, 0.98)
  
      _save_plot(
          learning_rates,
          losses,
          os.path.join(serialization_dir, "lr-losses.png"),
      )
  
imports: import argparse
  import logging
  import math
  import os
  import re
  from typing import List, Tuple
  import itertools
  from allennlp.commands.subcommand import Subcommand
  from allennlp.common import Params, Tqdm
  from allennlp.common import logging
  from allennlp.common.checks import check_for_gpu, ConfigurationError
  from allennlp.common.util import prepare_environment
  from allennlp.data import Vocabulary
  from allennlp.models import Model
  from allennlp.training import GradientDescentTrainer, Trainer
  from allennlp.training.util import create_serialization_dir, data_loaders_from_params
label_desc: Use image node_id 2 for calling a global function with example usage: find_learning_rate_model(params, serialization_dir, start_lr, end_lr, num_batches, linear_steps, stopping_factor, force) without return types