class
OneCycleLR
extends
_LRSchedulerOneCycleLR(optimizer: Optimizer, max_lr: float, total_steps: int, pct_start: float = 0.3, anneal_strategy: str = 'cos', div_factor: float = 25.0, final_div_factor: float = 10000.0, last_epoch: int = -1, verbose: bool = False)1Cycle learning rate policy.
Implements the 1cycle policy: the learning rate first rises from an
initial value to max_lr over a warmup phase, then anneals down to
a minimum value over the remaining steps.
Three special learning rates are derived from max_lr:
The schedule has two phases:
- Warmup (first
pct_start * total_stepssteps): anneal from up to . - Cooldown (remaining steps): anneal from down to .
Each phase uses either cosine or linear annealing depending on
anneal_strategy.
Parameters
optimizerOptimizerWrapped optimizer.
max_lrfloatPeak learning rate reached at the end of the warmup phase.
total_stepsintTotal number of steps (batches) in the training run.
pct_startfloat= 0.3Fraction of
total_steps devoted to the warmup phase
(default: 0.3).anneal_strategystr= 'cos'Annealing function:
"cos" for cosine annealing or
"linear" for linear annealing (default: "cos").div_factorfloat= 25.0Determines the initial LR as
max_lr / div_factor
(default: 25.0).final_div_factorfloat= 10000.0Determines the minimum LR as
initial_lr / final_div_factor
(default: 1e4).last_epochint= -1The index of the last epoch (default:
-1).verbosebool= FalsePrint the updated LR after each step if
True (default: False).Attributes
max_lrfloatPeak learning rate.
total_stepsintTotal training steps.
pct_startfloatWarmup fraction.
anneal_strategystr"cos" or "linear".div_factorfloatInitial LR divisor.
final_div_factorfloatMinimum LR divisor relative to initial LR.
Notes
The 1cycle policy should be called once per training step (per batch), not once per epoch. It is designed for super-convergence and often allows training with much larger learning rates than standard schedules.
Examples
>>> import lucid.nn as nn
>>> model = nn.Linear(4, 2)
>>> import lucid.optim as optim
>>> optimizer = optim.SGD(model.parameters(), lr=0.1)Used by 1
Constructors
1dunder
__init__
→None__init__(optimizer: Optimizer, max_lr: float, total_steps: int, pct_start: float = 0.3, anneal_strategy: str = 'cos', div_factor: float = 25.0, final_div_factor: float = 10000.0, last_epoch: int = -1, verbose: bool = False)Initialise the OneCycleLR. See the class docstring for parameter semantics.