drytorch.lib.schedulers
Module containing schedulers for the learning rates.
Functions
|
Create a scaling transformation. |
|
Create a restart transformation. |
|
Create a warmup transformation. |
Classes
|
Abstract class for the scheduler. |
Constant learning rate. |
|
|
Schedule cosine decay: f(x) = C0 + C1(1 + cos(πx/C2)). |
|
Schedule exponential decay: f(x) = C0 + C1(C2^x). |
|
Polynomial learning rate scheduler: f(x) = C0 + C1(1 - x/C2)^C3. |
|
Scale the output of an existing scheduler. |
|
Wraps another scheduler to provide periodic restarts. |
|
Step-wise learning rate scheduler. |
|
Adds a warmup phase to any scheduler. |
- class AbstractScheduler(*args, **kwargs)[source]
Bases:
SchedulerProtocol,ABCAbstract class for the scheduler.
- __call__(base_lr: float, epoch: int) float[source]
Modify the learning rate according to a schedule.
- Parameters:
- Returns:
scheduled value for the learning rate.
- Raises:
ValueError – if base_lr or epoch are non-positive.
- Return type:
- bind(f: Callable[[AbstractScheduler], AbstractScheduler], /) AbstractScheduler[source]
Allow transformation of the scheduler.
- Parameters:
f (Callable[[AbstractScheduler], AbstractScheduler]) – a function specifying the transformation.
- Returns:
the transformed scheduler.
- Return type:
- class ConstantScheduler[source]
Bases:
AbstractSchedulerConstant learning rate.
- class CosineScheduler(decay_steps: int = 250, min_decay: float = 0.01)[source]
Bases:
AbstractSchedulerSchedule cosine decay: f(x) = C0 + C1(1 + cos(πx/C2)).
C0, C1 and C2 are defined so that: - f(x) = base_value when epoch = 0 and, - f(x) = min value when epoch is C2 = number of decay steps.
After the number of decay steps, returns min value.
- class ExponentialScheduler(exp_decay: float = 0.975, min_decay: float = 0.0)[source]
Bases:
AbstractSchedulerSchedule exponential decay: f(x) = C0 + C1(C2^x).
C0, C1 and C2 are defined so that: - f(x) = base_value when epoch = 0, - f(x) = min value when the epoch goes to infinite and, - f(x) is an exponential function with decay factor C2.
After the number of decay steps, returns min value.
- class PolynomialScheduler(max_epochs: int = 1000, power: float = 1.0, min_decay: float = 0.0)[source]
Bases:
AbstractSchedulerPolynomial learning rate scheduler: f(x) = C0 + C1(1 - x/C2)^C3.
C0, C1, C2, C3 are defined so that: - f(x) = base_value when epoch = 0, - f(x) = min value when epoch is C2 = number of decay steps and, - f(x) is a polynomial of degree C3.
After the number of decay steps, returns min value.
- class StepScheduler(milestones: Iterable[int] = <factory>, gamma: float = 0.1)[source]
Bases:
AbstractSchedulerStep-wise learning rate scheduler.
Reduces learning rate by a factor at specified milestones.
- milestones
iterable of epochs at which to reduce the learning rate.
- Type:
- rescale(factor: float) Callable[[AbstractScheduler], AbstractScheduler][source]
Create a scaling transformation.
- Parameters:
factor (float) – factor that rescales the value.
- Returns:
A decorator that wraps a scheduler with scaling.
- Return type:
- restart(restart_interval: int, restart_fraction: float = 1.0) Callable[[AbstractScheduler], AbstractScheduler][source]
Create a restart transformation.
- Parameters:
- Returns:
A decorator that wraps a scheduler with restarts.
- Return type:
- warmup(warmup_steps: int = 10) Callable[[AbstractScheduler], AbstractScheduler][source]
Create a warmup transformation.
- Parameters:
warmup_steps (int) – number of warmup steps.
- Returns:
A decorator that wraps a scheduler with warmup.
- Return type: