Switch Scheduler#
Module for the SwitchScheduler callback.
- class SwitchScheduler(new_schedulers, epoch_switch)[source]#
Bases:
CallbackLightning callback for dynamically replacing schedulers during training.
This callback enables switching to new scheduler(s) at a specified epoch without interrupting the training loop. It is useful for staged training strategies where different learning rate policies are applied sequentially.
Initialization of the
SwitchSchedulerclass.- Parameters:
new_schedulers (SchedulerInterface | list[SchedulerInterface]) – The scheduler or list of schedulers to switch to. Use a single scheduler for single-model solvers, or a list of schedulers when working with multiple models.
epoch_switch (int) – The epoch at which the scheduler switch occurs.
- Raises:
AssertionError – If
epoch_switchis not a positive integer.ValueError – If any of the provided schedulers are not instances of
pina.optim.SchedulerInterface.
Example
>>> scheduler = TorchScheduler( >>> torch.optim.lr_scheduler.StepLR, step_size=5 >>> ) >>> switch_callback = SwitchScheduler( >>> new_schedulers=scheduler, epoch_switch=10 >>> )