Skip to content
class

CosineAnnealingLR

extendsLRScheduler
CosineAnnealingLR

Cosine-annealing schedule from ηmax⁡\eta_{\max} down to ηmin⁡\eta_{\min} over Tmax⁡T_{\max} epochs, following half a cosine wave.

Smoothly anneals the lr so training spends the early epochs at high lr (exploration) and the late epochs at low lr (convergence). Often combined with warm restarts (SGDR) for cyclic re-exploration.

Math

ηt=ηmin⁡+12(η0−ηmin⁡)(1+cos⁡ ⁣(tTmax⁡ π)) \eta_t = \eta_{\min} + \tfrac{1}{2}(\eta_0 - \eta_{\min}) \left(1 + \cos\!\left(\tfrac{t}{T_{\max}}\,\pi\right)\right)

for t∈[0,Tmax⁡]t \in [0, T_{\max}]; saturates at ηmin⁡\eta_{\min} for t>Tmax⁡t > T_{\max}.

References

Loshchilov & Hutter, "SGDR: Stochastic Gradient Descent with Warm Restarts" (ICLR 2017) — Lucid does not yet implement the warm-restart variant.

Attributes

T_max_int
Cycle length in optimiser epochs.
eta_min_float
Floor of the schedule. Defaults to 0.

Constructors

1
ctor

CosineAnnealingLR

void CosineAnnealingLR(Optimizer & opt, int T_max, double eta_min)

Build a cosine-annealing schedule.

Parameters

Target optimiser.
T_maxint
Number of epochs per half-cycle.
eta_minfloat, default 0.0
Floor of the schedule.

Methods

1
fnconst

compute_lr_at

→float
double compute_lr_at(int epoch)

Evaluate the cosine schedule at epoch.

Parameters

epochint
Current epoch.

Returns

float

Annealed learning rate.