class_docstr: The WarmupReduceLROnPlateau scheduler.
  
  This scheduler is the combination of WarmupLR and ReduceLROnPlateau:
  
  WarmupLR:
      lr = optimizer.lr * warmup_step ** 0.5
           * min(step ** -0.5, step * warmup_step ** -1.5)
  WarmupReduceLROnPlateau:
      if step <= warmup_step:
          lr = optimizer.lr * warmup_step ** 0.5
               * min(step ** -0.5, step * warmup_step ** -1.5)
      else:
          lr = (
              optimizer.lr * factor
              if no improvement for a 'patience' number of epochs
              else optimizer.lr
          )
  
  Note that the maximum lr equals to optimizer.lr in this scheduler.
class_docstr_tok: ["The","WarmupReduceLROnPlateau","scheduler",".","This","scheduler","is","the","combination","of","WarmupLR","and","ReduceLROnPlateau",":","WarmupLR",":","lr","=","optimizer.lr","*","warmup_step","*","*","0.5","*","min","(","step","*","*","-0.5",",","step","*","warmup_step","*","*","-1.5",")","WarmupReduceLROnPlateau",":","if","step","<","=","warmup_step",":","lr","=","optimizer.lr","*","warmup_step","*","*","0.5","*","min","(","step","*","*","-0.5",",","step","*","warmup_step","*","*","-1.5",")","else",":","lr","=","(","optimizer.lr","*","factor","if","no","improvement","for","a","'patience","'","number","of","epochs","else","optimizer.lr",")","Note","that","the","maximum","lr","equals","to","optimizer.lr","in","this","scheduler","."]
code: def __init__(
      self,
      optimizer: torch.optim.Optimizer,
      # for WarmupLR
      warmup_steps: Union[int, float] = 25000,
      # for ReduceLROnPlateau
      mode="min",
      factor=0.1,
      patience=10,
      threshold=1e-4,
      threshold_mode="rel",
      cooldown=0,
      min_lr=0,
      eps=1e-8,
      verbose=False,
  ):
      assert check_argument_types()
      self.warmup_steps = warmup_steps
      self.step_num = 0
      self.lr_scale = warmup_steps**-1
      # Initialize base learning rates
      for group in optimizer.param_groups:
          if "initial_lr" not in group:
              group.setdefault("initial_lr", group["lr"])
      self.base_lrs = [
          group["initial_lr"] for group in optimizer.param_groups
      ]
  
      if factor >= 1.0:
          raise ValueError("Factor should be < 1.0.")
      self.factor = factor
  
      # Attach optimizer
      self.optimizer = optimizer
  
      if isinstance(min_lr, list) or isinstance(min_lr, tuple):
          if len(min_lr) != len(optimizer.param_groups):
              raise ValueError(
                  "expected {} min_lrs, got {}".format(
                      len(optimizer.param_groups), len(min_lr)
                  )
              )
          self.min_lrs = list(min_lr)
      else:
          self.min_lrs = [min_lr] * len(optimizer.param_groups)
  
      self.patience = patience
      self.verbose = verbose
      self.cooldown = cooldown
      self.cooldown_counter = 0
      self.mode = mode
      self.threshold = threshold
      self.threshold_mode = threshold_mode
      self.best = None
      self.num_bad_epochs = None
      self.mode_worse = None  # the worse value for the chosen mode
      self.eps = eps
      self.last_epoch = 0
      self._init_is_better(
          mode=mode, threshold=threshold, threshold_mode=threshold_mode
      )
      self._reset()
  
file_path: espnet/espnet2/schedulers/warmup_reducelronplateau.py
imports: from typing import Union
  import torch
  from torch import inf
  from typeguard import check_argument_types
  from espnet2.schedulers.abs_scheduler import AbsBatchStepScheduler, AbsValEpochStepScheduler
label_desc: Use image node_id 1 to create a new WarmupReduceLROnPlateau object from inherited base classes: AbsBatchStepScheduler, AbsValEpochStepScheduler with example: obj = WarmupReduceLROnPlateau(optimizer, warmup_steps, mode, factor, patience, threshold, threshold_mode, cooldown, min_lr, eps, verbose)