TorchScheduler#

class TorchScheduler(scheduler_class, **kwargs)[source]#

Bases: SchedulerInterface

The wrapper class for PyTorch schedulers.

This class wraps a torch.optim.lr_scheduler.LRScheduler class and defers its instantiation until runtime, once the optimizer instance is available.

Example:
>>> from pina.optim import TorchScheduler
>>> import torch
>>> scheduler = TorchScheduler(
...     torch.optim.lr_scheduler.StepLR, step_size=5)
>>> scheduler.scheduler_class
<class 'torch.optim.lr_scheduler.StepLR'>

Initialization of the TorchScheduler class.

Parameters:
  • scheduler_class (torch.optim.LRScheduler) – The subclass of torch.optim.lr_scheduler.LRScheduler to be instantiated.

  • kwargs (dict) – Additional keyword arguments forwarded to the scheduler constructor. See more here.

Raises:

ValueError – If scheduler_class is not a subclass of torch.optim.lr_scheduler.LRScheduler.

hook(optimizer)[source]#

Initialize the scheduler instance with the given parameters.

Parameters:

optimizer (OptimizerInterface) – The optimizer instance associated with the scheduler.

Raises:

ValueError – If optimizer is not an instance of OptimizerInterface.

property instance#

The underlying scheduler object.

Returns:

The scheduler instance.

Return type:

torch.optim.lr_scheduler.LRScheduler