experiment_runner.optimizers
Optimizer lookup: the config string to a torch.optim factory.
Unlike a loss, an optimizer cannot be fully constructed here: it needs
model.parameters(), which only exists inside
train_model(). So this returns the class, or
a functools.partial() carrying the configured arguments, and the package
calls it with (self.parameters(), lr=learn_rate). That keeps the package API
at one object per family - the same shape as the loss and the encoder - and uses
the partial idiom the metric registry already relies on.
Attributes
Config name -> optimizer class. Anything else resolves by dotted path. |
Functions
|
Return the optimizer factory for the config value name. |
Module Contents
- experiment_runner.optimizers.logger
- experiment_runner.optimizers.OPTIMIZERS: dict[str, type[torch.optim.Optimizer]]
Config name -> optimizer class. Anything else resolves by dotted path.
- experiment_runner.optimizers.build_optimizer(name: str | None, params: dict | None = None) collections.abc.Callable | None
Return the optimizer factory for the config value name.
- Parameters:
name (str or None) – A key of
OPTIMIZERS(matched case-insensitively), or a dotted import path to an optimizer class.NonereturnsNone, which leavestrain_model()on its own default so the default lives in one place.params (dict, optional) – Constructor arguments beyond the parameters and the learning rate, e.g.
{"momentum": 0.9, "nesterov": true}. They are bound into afunctools.partial();learn_ratestays atrain_modelparameter and is applied there.
- Returns:
The class, a partial of it, or
Nonewhen no name was given.- Return type:
Callable or None
- Raises:
ValueError – If name resolves to nothing, or if params were given without a name to apply them to.