Base class for epoch-driven learning-rate schedules.
Holds a reference to the target optimiser, snapshots its initial
learning rate, and exposes a templated update loop driven by the
virtual compute_lr_at hook.
The internal counter epoch_ is 0-indexed and is incremented
before compute_lr_at is consulted, so the first call to
step queries epoch 1 (matching the reference framework's
convention).
See Also
StepLR, MultiStepLR, ExponentialLR,
CosineAnnealingLR, CyclicLR, NoamScheduler,
LambdaLR, ReduceLROnPlateau.
Attributes
opt_Optimizer&base_lr_floatopt_ at construction time.epoch_intNotes
Copy-constructed and copy-assigned by design — the bound optimiser reference makes a copied scheduler ambiguous.
Constructors
1LRScheduler
void LRScheduler(Optimizer & opt)Construct a scheduler bound to opt and snapshot base_lr_.
Parameters
optOptimizerNotes
base_lr_ is read from opt.lr() once at construction —
later external changes to the optimiser's lr are ignored.
Destructor
1~LRScheduler
void ~LRScheduler()Virtual destructor — ensures derived StepLR / CosineAnnealingLR / etc. destructors run when held by a base-class pointer. Defaulted; opt_ is a reference and epoch_ / base_lr_ are PODs, so nothing to clean up at this layer.
Operators
1Virtual methods
1Methods
3Return the current epoch counter.
Returns
intValue of epoch_.
Jump the epoch counter to epoch and refresh the optimiser lr.
Parameters
epochintNotes
Unlike step this does not pre-increment — useful when
restoring from a checkpoint where the saved epoch is the value
to resume from.
Advance the epoch counter by one and push the new lr.
Notes
Idiomatic placement is after the optimiser's own
step inside the training loop so the next iteration sees
the freshly computed lr.