class_docstr: Implements the Slanted Triangular Learning Rate schedule with optional gradual
  unfreezing and discriminative fine-tuning. The schedule corresponds to first
  linearly increasing the learning rate over some number of epochs, and then linearly
  decreasing it over the remaining epochs.
  
  If we gradually unfreeze, then in the first epoch of training, only the top
  layer is trained; in the second epoch, the top two layers are trained, etc.
  During freezing, the learning rate is increased and annealed over one epoch.
  After freezing finished, the learning rate is increased and annealed over
  the remaining training iterations.
  
  Note that with this schedule, early stopping should typically be avoided.
  
  Registered as a `LearningRateScheduler` with name "slanted_triangular".
  
  # Parameters
  
  optimizer : `torch.optim.Optimizer`
      This argument does not get an entry in a configuration file for the object.
  num_epochs : `int`, required.
      The total number of epochs for which the model should be trained.
  num_steps_per_epoch : `Optional[int]`, optional (default = `None`)
      The number of steps (updates, batches) per training epoch.
  cut_frac : `float`, optional (default = `0.1`).
      The fraction of the steps to increase the learning rate.
  ratio : `float`, optional (default = `32`).
      The ratio of the smallest to the (largest) base learning rate.
  gradual_unfreezing : `bool`, optional (default = `False`).
      Whether gradual unfreezing should be used.
  discriminative_fine_tuning : `bool`, optional (default = `False`).
      Whether discriminative fine-tuning (different learning rates per layer)
      are used.
  decay_factor : `float`, optional (default = `0.38`).
      The decay factor by which the learning rate is reduced with
      discriminative fine-tuning when going a layer deeper.
code: def __init__(
      self,
      optimizer: torch.optim.Optimizer,
      num_epochs: int,
      num_steps_per_epoch: Optional[int] = None,
      cut_frac: float = 0.1,
      ratio: int = 32,
      last_epoch: int = -1,
      gradual_unfreezing: bool = False,
      discriminative_fine_tuning: bool = False,
      decay_factor: float = 0.38,
  ) -> None:
      self.num_epochs = num_epochs
      self.num_steps_per_epoch = num_steps_per_epoch
      self.cut_frac = cut_frac
      self.ratio = ratio
      self.gradual_unfreezing = gradual_unfreezing
      self.freezing_current = self.gradual_unfreezing
      self.is_first_epoch = True
      # track the actual number of steps for each epoch
      self.batch_num_total_epoch_end: List[int] = []
      if self.gradual_unfreezing:
          assert not optimizer.param_groups[-1][
              "params"
          ], "The default group should be empty."
      if self.gradual_unfreezing or discriminative_fine_tuning:
          assert len(optimizer.param_groups) > 2, (
              "There should be at least 3 param_groups (2 + empty default group)"
              " for gradual unfreezing / discriminative fine-tuning to make sense."
          )
      super().__init__(optimizer, last_epoch)
      self.step()
      if discriminative_fine_tuning:
          # skip the last param_group if it is has no parameters
          exponent = 0
          for i in range(len(self.base_values) - 1, -1, -1):
              param_group = optimizer.param_groups[i]
              if param_group["params"]:
                  param_group["lr"] = (
                      self.base_values[i] * decay_factor**exponent
                  )
                  self.base_values[i] = param_group["lr"]
                  exponent += 1
      # set up for the first batch
      self.last_batch_num_total = -1
      self.step_batch(0)
  
file_path: allennlp/allennlp/training/learning_rate_schedulers/slanted_triangular.py
imports: import logging
  from typing import List, Optional
  import torch
  from allennlp.training.learning_rate_schedulers.learning_rate_scheduler import LearningRateScheduler
label_desc: Use image node_id 1 to create a new SlantedTriangular object from inherited base classes: LearningRateScheduler with example: obj = SlantedTriangular(optimizer, num_epochs, num_steps_per_epoch, cut_frac, ratio, last_epoch, gradual_unfreezing, discriminative_fine_tuning, decay_factor)