class

MultiplicativeLR

extends_LRScheduler
MultiplicativeLR(optimizer: Optimizer, lr_lambda: Callable[[int], float], last_epoch: int = -1, verbose: bool = False)
source

Multiply the learning rate by a factor returned by a function each epoch.

Unlike LambdaLR, which computes the learning rate as base_lr * fn(t), MultiplicativeLR accumulates the factor: each epoch the current learning rate is multiplied by lr_lambda(t):

ηt=ηt1λ(t)\eta_t = \eta_{t-1} \cdot \lambda(t)

This means the schedule depends on the entire history of lr_lambda values, not only the current epoch index.

Parameters

optimizerOptimizer
Wrapped optimizer.
lr_lambdacallable
A function f(epoch: int) -> float returning the multiplicative factor to apply at that epoch.
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

lr_lambdacallable
The factor function applied each epoch.

Notes

At epoch 0 the learning rate is left unchanged (the factor is not applied on the very first step so that the initial LR from the optimizer is honored).

Examples

>>> import lucid.optim as optim
>>> optimizer = optim.SGD(model.parameters(), lr=0.1)
>>> # Decay by 0.95 every epoch
>>> scheduler = optim.MultiplicativeLR(optimizer, lr_lambda=lambda t: 0.95)
>>> for epoch in range(50):
...     train(...)
...     optimizer.step()
...     scheduler.step()

Methods (2)

dunder

__init__

None
__init__(optimizer: Optimizer, lr_lambda: Callable[[int], float], last_epoch: int = -1, verbose: bool = False)
source

Initialise the MultiplicativeLR. 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.