Smart Optimiser¶
Vanguard defines its own optimiser wrapper to enable additional features.
- class vanguard.optimise.optimiser.GreedySmartOptimiser(optimiser_class, *initial_modules, early_stop_patience=None, **optimiser_kwargs)[source]¶
Always choose parameters with the minimum loss value, regardless of the iteration at which they occur.
Note
This is the default smart optimiser for some
vanguard.vanilla.GaussianGPController. To disable the greedy loss behaviour and revert to keeping the parameters at the final iteration of training, usingvanguard.optimise.optimiser.SmartOptimiseror a different subclass thereof.- Parameters:
- __init__(optimiser_class, *initial_modules, early_stop_patience=None, **optimiser_kwargs)[source]¶
Initialise self.
- Parameters:
optimiser_class (
type[Optimizer]) – An uninstantiated subclass oftorch.optim.Optimizerto be used to create the internal optimiser.initial_modules (
Module) – Initial modules whose parameters will be added to the internal optimiser.early_stop_patience (
Optional[int]) – How many consecutive gradient steps of worsening loss to allow before stopping early. Defaults toNonewhich disables early stopping.optimiser_kwargs (
Any) – Additional keyword arguments to be passed to the internal optimiser.
- reset()[source]¶
Reset all parameters to start values and clear record of best parameters.
- Return type:
- class vanguard.optimise.optimiser.MaxLengthHeapQ(max_length)[source]¶
A heapq of fixed maximum length.
- Parameters:
max_length (
int)
- exception vanguard.optimise.optimiser.NoImprovementError[source]¶
Raised when the loss of the model is consistently increasing.
- class vanguard.optimise.optimiser.Parameters(module_state_dicts, value=inf)[source]¶
Wrapped for module state_dicts and an objective value of their quality.
- class vanguard.optimise.optimiser.SmartOptimiser(optimiser_class, *initial_modules, early_stop_patience=None, **optimiser_kwargs)[source]¶
A smart wrapper around the standard optimisers found in PyTorch which can enable early stopping.
Warning
When setting the learning rate, using the
learning_rate()property, the parameters for each registered module are re-initialised.- Parameters:
- __init__(optimiser_class, *initial_modules, early_stop_patience=None, **optimiser_kwargs)[source]¶
Initialise self.
- Parameters:
optimiser_class (
type[Optimizer]) – An uninstantiated subclass oftorch.optim.Optimizerto be used to create the internal optimiser.initial_modules (
Module) – Initial modules whose parameters will be added to the internal optimiser.early_stop_patience (
Optional[int]) – How many consecutive gradient steps of worsening loss to allow before stopping early. Defaults toNonewhich disables early stopping.optimiser_kwargs (
Any) – Additional keyword arguments to be passed to the internal optimiser.
- update_registered_module(module)[source]¶
Update the parameters of a registered module if the module has been modified.
- zero_grad(set_to_none=False)[source]¶
Set the gradients of all optimized
torch.Tensors to zero.