class

MultiStepLR

extends_LRScheduler
MultiStepLR(optimizer: Optimizer, milestones: list[int], gamma: float = 0.1, last_epoch: int = -1, verbose: bool = False)
source

Decay the learning rate by a fixed factor at a list of epoch milestones.

Unlike StepLR, the decay epochs need not be evenly spaced. At each epoch listed in milestones the learning rate is multiplied by gamma:

ηt=η0γmmilestones1[tm]\eta_t = \eta_0 \cdot \gamma^{\sum_{m \in \text{milestones}} \mathbf{1}[t \ge m]}

Parameters

optimizerOptimizer
Wrapped optimizer.
milestoneslist of int
Sorted list of epoch indices at which the learning rate is decayed. If unsorted, the list is sorted internally.
gammafloat= 0.1
Multiplicative factor applied at each milestone (default: 0.1).
last_epochint= -1
The index of the last epoch (default: -1).
verbosebool= False
Print the updated LR after each step if True (default: False).

Attributes

milestoneslist of int
Sorted epoch indices where decay is applied.
gammafloat
Multiplicative decay factor.

Notes

Useful when natural training phases occur at irregular intervals (e.g., decay at epochs 50, 100, and 150 in a 200-epoch run).

Examples

>>> import lucid.optim as optim
>>> optimizer = optim.SGD(model.parameters(), lr=0.1)
>>> scheduler = optim.MultiStepLR(optimizer, milestones=[50, 100, 150], gamma=0.1)
>>> for epoch in range(200):
...     train(...)
...     optimizer.step()
...     scheduler.step()

Methods (2)

dunder

__init__

None
__init__(optimizer: Optimizer, milestones: list[int], gamma: float = 0.1, last_epoch: int = -1, verbose: bool = False)
source

Initialise the MultiStepLR. See the class docstring for parameter semantics.

fn

get_lr

list[float]
get_lr()
source

Compute the learning rate for each parameter group at the current step.

Returns

list[float]

One learning rate per param group, derived from the schedule formula documented in the class docstring.