Optimizer callbacks#

class SwitchOptimizer(new_optimizers, epoch_switch)[source]#

Bases: Callback

PINA Implementation of a Lightning Callback to switch optimizer during training.

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

Parameters:
  • new_optimizers (pina.optim.TorchOptimizer | list) – The model optimizers to switch to. Can be a single torch.optim.Optimizer instance or a list of them for multiple model solver.

  • epoch_switch (int) – The epoch at which the optimizer switch occurs.

Example

>>> optimizer = TorchOptimizer(torch.optim.Adam, lr=0.01)
>>> switch_callback = SwitchOptimizer(
>>>     new_optimizers=optimizer, epoch_switch=10
>>> )
on_train_epoch_start(trainer, __)[source]#

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

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

  • _ – Placeholder argument (not used).