Skip to content

utils

OptimizerFactory

Factory for creating optimizers and schedulers.

After initialization, the factory can be called to create an optimizer with an optional scheduler.

__call__(parameters)

Create an optimizer with an optional scheduler for the given parameters.

The object returned by this method is a lightning optimizer config and can be the return value of configure_optimizers.

Parameters:

Name Type Description Default
parameters Iterable[Parameter]

The model parameters to optimize.

required

Returns:

Type Description
OptimizerLRSchedulerConfig

A lightning optimizer config.

__init__(optim_type='adam', lr=0.001, scheduler_type=None, **kwargs)

Create a new factory to efficiently create optimizers and schedulers.

The factory creates an optimizer of the specified optim_type and adds an optional scheduler of the specified scheduler_type. Additional keyword arguments for the optimizer can be passed by adding the 'optim_' prefix and for the scheduler by adding the 'scheduler_' prefix. The factory will ignore any other keyword arguments.

Available optimizers are 'adam', 'sgd' and 'rmsprop'. Available schedulers are 'step', 'cosine', 'linear' and 'lambda'.

Parameters:

Name Type Description Default
optim_type str

The type of optimizer to create.

'adam'
lr float

The learning rate to use.

0.001
scheduler_type Optional[str]

The optional type of scheduler to create.

None
**kwargs Any

Additional keyword arguments for the optimizer and scheduler.

{}

get_loss(loss_type)

Get a loss instance by specifying a string.

pairwise(iterable)

s -> (s0,s1), (s1,s2), (s2, s3), ...

str2callable(cls, restriction='')

Dynamically import a callable from a string.