dymad.utils.scheduler¶
Functions
|
Factory function to create a scheduler instance. |
Classes
Base class for schedulers. |
|
|
Standard scheduler that wraps a PyTorch scheduler. |
|
Scheduler to manage sweep lengths during training. |
- class dymad.utils.scheduler.SchedulerBase¶
Bases:
objectBase class for schedulers.
As wrapper of standard schedulers, with customized inputs and outputs. Also for other custom schedulers.
- diagnostic_info()¶
Return diagnostic information about the scheduler.
- Returns:
Diagnostic information.
- Return type:
str
- load_state_dict(state_dict)¶
Load the state dictionary.
- Return type:
None
- state_dict()¶
Return the state dictionary for saving.
- Return type:
dict[str,Any]
- step(**kwargs)¶
Step through the scheduler logic.
- Returns:
True if the scheduler indicates to stop training, False by default.
- Return type:
bool
- class dymad.utils.scheduler.StandardScheduler(scheduler)¶
Bases:
SchedulerBaseStandard scheduler that wraps a PyTorch scheduler.
- Parameters:
scheduler (torch.optim.lr_scheduler._LRScheduler) – PyTorch scheduler instance.
- diagnostic_info()¶
Return diagnostic information about the scheduler.
- Returns:
Diagnostic information.
- Return type:
str
- load_state_dict(state_dict)¶
Load the state dictionary into the wrapped scheduler.
- Return type:
None
- state_dict()¶
Return the state dictionary of the wrapped scheduler.
- Return type:
dict[str,Any]
- step(**kwargs)¶
Step through the wrapped scheduler.
- Return type:
tuple[bool,bool]
- class dymad.utils.scheduler.SweepScheduler(sweep_lengths=None, sweep_tols=None, epoch_step=10, mode='skip')¶
Bases:
SchedulerBaseScheduler to manage sweep lengths during training. Cycles through predefined sweep lengths and tolerances.
It operates in four modes:
No sweep_lengths or sweep_tols: Does nothing.
Only sweep_lengths: Change lengths every epoch_step.
sweep_lengths AND sweep_tols: Change lengths either every epoch_step or a tolerance is reached, whichever comes first. In particular, when the last tolerance is reached,
If mode=’full’: the scheduler resets to the initial length.
If mode=’skip’: the scheduler keeps using the current length.
Note
If sweep_tols is set, the optimization ends when the last tolerance is reached.
- Parameters:
sweep_lengths (list) – List of sweep lengths to cycle through.
sweep_tols (list, optional) – List of tolerances for each sweep length.
epoch_step (int) – Number of epochs after which to switch to the next sweep length.
mode (str) – Mode of operation (‘full’ or ‘skip’). Default is ‘skip’.
- diagnostic_info()¶
Return diagnostic information about the scheduler.
- Returns:
Diagnostic information.
- Return type:
str
- get_length()¶
- Return type:
int
- load_state_dict(state_dict)¶
Load the state dictionary.
- Return type:
None
- state_dict()¶
Return the state dictionary for saving.
- Return type:
dict[str,Any]
- step(eploss=None)¶
Step through the scheduler logic.
- Returns:
True if the scheduler indicates to stop training, False by default.
- Return type:
bool
- dymad.utils.scheduler.make_scheduler(scheduler=None, scheduler_type='', **kwargs)¶
Factory function to create a scheduler instance.
- Parameters:
scheduler_type (str) – Type of the scheduler to create.
**kwargs – Additional arguments for the scheduler.
- Returns:
An instance of the specified scheduler type.
- Return type: