SequentialLR
SequentialLR(optimizer: Optimizer, schedulers: list[_LRScheduler], milestones: list[int], last_epoch: int = -1)Chain multiple schedulers and switch between them at epoch milestones.
SequentialLR runs its list of schedulers one at a time, activating
the next scheduler whenever the epoch counter crosses a milestone.
Before the first milestone, schedulers[0] is active; between
milestone k-1 and k, schedulers[k] is active.
Parameters
optimizerOptimizerschedulerslist of _LRSchedulerlen(schedulers) == len(milestones) + 1.milestoneslist of intlast_epochint= -1-1).Attributes
optimizerOptimizerschedulerslist of _LRSchedulermilestoneslist of intlast_epochintstep calls completed.Notes
A common pattern is to combine a short warmup with a long cosine decay:
.. code-block:: python
warmup = optim.LinearLR(optimizer, start_factor=0.1, total_iters=5)
cosine = optim.CosineAnnealingLR(optimizer, T_max=95)
combined = optim.SequentialLR(
optimizer,
schedulers=[warmup, cosine],
milestones=[5],
)
Examples
>>> import lucid.optim as optim
>>> optimizer = optim.SGD(model.parameters(), lr=0.1)
>>> s1 = optim.ConstantLR(optimizer, factor=0.1, total_iters=5)
>>> s2 = optim.ExponentialLR(optimizer, gamma=0.9)
>>> scheduler = optim.SequentialLR(optimizer, schedulers=[s1, s2], milestones=[5])
>>> for epoch in range(50):
... train(...)
... optimizer.step()
... scheduler.step()Methods (3)
__init__
→None__init__(optimizer: Optimizer, schedulers: list[_LRScheduler], milestones: list[int], last_epoch: int = -1)Initialise the SequentialLR. See the class docstring for parameter semantics.
step
→Nonestep()Advance the active scheduler by one epoch, switching if a milestone is reached.
Increments the internal epoch counter, checks whether any
milestone has been crossed, and delegates to the currently active
scheduler's _LRScheduler.step.
Examples
>>> for epoch in range(100):
... optimizer.step()
... scheduler.step()get_last_lr
→list of floatget_last_lr()Return the last learning rates from the currently active scheduler.
Returns
list of floatCurrent learning rate of each optimizer param group, as reported by the active scheduler.