ReduceLROnPlateau
ReduceLROnPlateau(optimizer: Optimizer, mode: str = 'min', factor: float = 0.1, patience: int = 10, verbose: bool = False, threshold: float = 0.0001, min_lr: float = 0)Reduce the learning rate when a monitored metric stops improving.
Once the metric fails to improve by more than threshold for
patience consecutive epochs, the learning rate is multiplied by
factor. This is useful when progress stalls and a smaller step
size may help escape a plateau:
Parameters
optimizerOptimizermodestr= 'min'"min" or "max". In "min" mode the LR is
reduced when the metric has stopped decreasing; in "max" mode
it is reduced when the metric has stopped increasing
(default: "min").factorfloat= 0.10.1). Must be less than 1.patienceint= 1010).verbosebool= FalseFalse).thresholdfloat= 0.00011e-4).min_lrfloat= 00).Attributes
optimizerOptimizermodestr"min" or "max".factorfloatpatienceintthresholdfloatmin_lrfloatNotes
Unlike the epoch-based schedulers that inherit from _LRScheduler,
ReduceLROnPlateau does not inherit from _LRScheduler
because it requires a metric value at each step call rather
than advancing by a fixed epoch count.
A typical use-case is to monitor validation loss:
.. code-block:: python
scheduler = optim.ReduceLROnPlateau(optimizer, mode="min", patience=5)
for epoch in range(epochs):
train(...)
val_loss = validate(...)
scheduler.step(val_loss)
Examples
>>> import lucid.optim as optim
>>> optimizer = optim.Adam(model.parameters(), lr=1e-3)
>>> scheduler = optim.ReduceLROnPlateau(
... optimizer, mode="min", factor=0.5, patience=5
... )
>>> for epoch in range(100):
... val_loss = evaluate(...)
... scheduler.step(val_loss)Methods (2)
__init__
→None__init__(optimizer: Optimizer, mode: str = 'min', factor: float = 0.1, patience: int = 10, verbose: bool = False, threshold: float = 0.0001, min_lr: float = 0)Initialise the ReduceLROnPlateau. See the class docstring for parameter semantics.
step
→Nonestep(metrics: float)Update the scheduler with the latest monitored metric value.
Checks whether the metric has improved relative to the stored best.
If it has not improved for more than patience epochs, the
learning rate is reduced by factor.
Parameters
metricsfloatmode).Examples
>>> scheduler.step(val_loss)