Skip to content
class

LRScheduler

LRScheduler

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

Optimiser whose learning rate is driven by this scheduler.
base_lr_float
Learning rate captured from opt_ at construction time.
epoch_int
0-indexed epoch counter.

Notes

Copy-constructed and copy-assigned by design — the bound optimiser reference makes a copied scheduler ambiguous.

Constructors

1
ctor

LRScheduler

void LRScheduler(Optimizer & opt)

Construct a scheduler bound to opt and snapshot base_lr_.

Parameters

Optimiser whose learning rate this scheduler will drive.

Notes

base_lr_ is read from opt.lr() once at construction — later external changes to the optimiser's lr are ignored.

Destructor

1
dtor

~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

1
op

operator=

LRScheduler & operator=(const LRScheduler &)

Virtual methods

1
= 0const

compute_lr_at

→float
double compute_lr_at(int epoch)

Compute the learning rate at the given epoch.

Parameters

epochint
Epoch index queried by step / set_epoch after they have updated epoch_.

Returns

float

Learning rate for that epoch.

Methods

3
fnconst

epoch

→int
int epoch()

Return the current epoch counter.

Returns

int

Value of epoch_.

fn

set_epoch

void set_epoch(int epoch)

Jump the epoch counter to epoch and refresh the optimiser lr.

Parameters

epochint
Absolute epoch index to set.

Notes

Unlike step this does not pre-increment — useful when restoring from a checkpoint where the saved epoch is the value to resume from.

fn

step

void step()

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.