Switch Scheduler#

class SwitchScheduler(new_schedulers, epoch_switch)[source]#

Bases: Callback

Callback to switch scheduler during training.

This callback allows switching between different schedulers during training, enabling the exploration of multiple optimization strategies without interrupting the training process.

Parameters:
  • new_schedulers (pina.optim.TorchScheduler | list[pina.optim.TorchScheduler]) – 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 less than 1.

  • ValueError – If each scheduler in new_schedulers is not an instance of pina.optim.TorchScheduler.

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 (lightning.pytorch.Trainer) – The trainer object managing the training process.

  • __ – Placeholder argument (not used).