class
ConstantLR
extends
_LRSchedulerConstantLR(optimizer: Optimizer, factor: float = 1.0 / 3, total_iters: int = 5, last_epoch: int = -1, verbose: bool = False)Hold the learning rate at a constant scaled value, then restore the base LR.
For the first total_iters epochs the learning rate is scaled by
factor; after that it is restored to the original base learning rate:
where .
Parameters
optimizerOptimizerWrapped optimizer.
factorfloat= 1.0 / 3Multiplicative factor applied to the base LR during the constant
phase (default:
1/3).total_itersint= 5Number of epochs to hold the scaled LR before restoring the base
value (default:
5).last_epochint= -1The index of the last epoch (default:
-1).verbosebool= FalsePrint the updated LR after each step if
True (default: False).Attributes
factorfloatLR scaling factor during the constant phase.
total_itersintDuration of the constant phase in epochs.
Notes
ConstantLR is useful as the first stage in a SequentialLR
chain, e.g. to hold a reduced LR during an initial burn-in period
before switching to a main decay schedule.
Examples
>>> import lucid.optim as optim
>>> optimizer = optim.SGD(model.parameters(), lr=0.1)
>>> # Hold LR at 0.1/3 for 5 epochs, then jump back to 0.1
>>> scheduler = optim.ConstantLR(optimizer, factor=1/3, total_iters=5)
>>> for epoch in range(50):
... train(...)
... optimizer.step()
... scheduler.step()Methods (2)
dunder
__init__
→None__init__(optimizer: Optimizer, factor: float = 1.0 / 3, total_iters: int = 5, last_epoch: int = -1, verbose: bool = False)Initialise the ConstantLR. See the class docstring for parameter semantics.
fn
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.