Switch Scheduler#

Module for the SwitchScheduler callback.

class SwitchScheduler(new_schedulers, epoch_switch)[source]#

Bases: Callback

Lightning 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 SwitchScheduler class.

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_switch is 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
>>> )
on_train_epoch_start(trainer, __)[source]#

Switch the scheduler at the start of the specified training epoch.

Parameters:
  • trainer (Trainer) – The trainer object managing the training process.

  • __ – Placeholder argument, not used.