MultiplicativeLR
_LRSchedulerMultiplicativeLR(optimizer: Optimizer, lr_lambda: Callable[[int], float], last_epoch: int = -1, verbose: bool = False)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):
This means the schedule depends on the entire history of lr_lambda
values, not only the current epoch index.
Parameters
optimizerOptimizerlr_lambdacallablef(epoch: int) -> float returning the multiplicative
factor to apply at that epoch.last_epochint= -1-1).verbosebool= FalseTrue (default: False).Attributes
lr_lambdacallableNotes
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)
__init__
→None__init__(optimizer: Optimizer, lr_lambda: Callable[[int], float], last_epoch: int = -1, verbose: bool = False)Initialise the MultiplicativeLR. See the class docstring for parameter semantics.
get_lr
→list[float]get_lr()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.