class
MultiplicativeLR
extends
_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
optimizerOptimizerWrapped optimizer.
lr_lambdacallableA function
f(epoch: int) -> float returning the multiplicative
factor to apply at that epoch.last_epochint= -1The index of the last epoch (default:
-1).verbosebool= FalsePrint the updated LR after each step if
True (default: False).Attributes
lr_lambdacallableThe 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.nn as nn
>>> model = nn.Linear(4, 2)
>>> import lucid.optim as optim
>>> optimizer = optim.SGD(model.parameters(), lr=0.1)
>>> scheduler = optim.MultiplicativeLR(optimizer, lr_lambda=lambda t: 0.95)
>>> for epoch in range(50):
... optimizer.step()
... scheduler.step()