TorchOptimizer#
- class TorchOptimizer(optimizer_class, **kwargs)[source]#
Bases:
OptimizerInterfaceThe wrapper class for PyTorch optimizers.
This class wraps a
torch.optim.Optimizerclass and defers its instantiation until runtime. It enables a consistent interface across different optimizer backends while leveraging PyTorch’s optimization algorithms.- Example:
>>> from pina.optim import TorchOptimizer >>> import torch >>> optimizer = TorchOptimizer(torch.optim.Adam, lr=0.001) >>> optimizer.optimizer_class <class 'torch.optim.adam.Adam'>
Initialization of the
TorchOptimizerclass.- Parameters:
optimizer_class (torch.optim.Optimizer) – The subclass of
torch.optim.Optimizerto be instantiated.kwargs (dict) – Additional keyword arguments forwarded to the optimizer constructor. See more here.
- Raises:
ValueError – If
optimizer_classis not a subclass oftorch.optim.Optimizer.
- hook(parameters)[source]#
Execute custom logic associated with the optimizer instance.
This method is intended to encapsulate any additional behavior that should be triggered during the optimization process.
- Parameters:
parameters (dict) – The parameters of the model to be optimized.
- property instance#
The underlying optimizer object.
- Returns:
The optimizer instance.
- Return type: