class
CyclicLR
extends
_LRSchedulerCyclicLR(optimizer: Optimizer, base_lr: float, max_lr: float, step_size_up: int = 2000, mode: str = 'triangular', gamma: float = 1.0, last_epoch: int = -1, verbose: bool = False)Cycle the learning rate between base_lr and max_lr.
Implements the triangular, triangular2, and exp_range cyclic policies.
Within each cycle of length the
learning rate rises linearly from base_lr to max_lr and then
falls back:
where .
For mode="triangular2" the amplitude halves each cycle:
For mode="exp_range" the amplitude decays exponentially each step:
Parameters
optimizerOptimizerWrapped optimizer.
base_lrfloatLower boundary of the learning rate cycle.
max_lrfloatUpper boundary of the learning rate cycle.
step_size_upint= 2000Number of steps in the increasing half of the cycle (default:
2000).modestr= 'triangular'One of
"triangular" (constant amplitude), "triangular2"
(amplitude halves each cycle), or "exp_range" (amplitude
decays by each step). Default: "triangular".gammafloat= 1.0Decay factor used only in
"exp_range" mode (default: 1.0).last_epochint= -1The index of the last epoch (default:
-1).verbosebool= FalsePrint the updated LR after each step if
True (default: False).Attributes
base_lr_valfloatLower bound of the cycle.
max_lr_valfloatUpper bound of the cycle.
step_size_upintHalf-cycle length in steps.
modestrScaling policy name.
gammafloatDecay factor for
"exp_range" mode.Notes
Cyclic learning rates can reduce the need for careful manual tuning by
automatically exploring a range of rates. Use step_size_up between
2 and 10 times the number of iterations per epoch.
Examples
>>> import lucid.nn as nn
>>> model = nn.Linear(4, 2)
>>> import lucid.optim as optim
>>> optimizer = optim.SGD(model.parameters(), lr=0.01)
>>> scheduler = optim.CyclicLR(
... optimizer, base_lr=1e-4, max_lr=1e-2, step_size_up=500
... )