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. |
|
Base class for schedulers that use dataclasses. |
|
A scheduler produced by composing transformations. |
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. |
|
Scheduler adding scaling to existing logic. |
|
Scheduler adding periodic restarts to existing logic. |
|
Step-wise learning rate scheduler. |
|
Base class for scheduler transformations. |
|
Scheduler adding warmup to existing logic. |
- 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:
- class CosineScheduler(decay_steps: int = 250, min_decay: float = 0.01)[source]
Bases:
BaseSchedulerSchedule 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:
BaseSchedulerSchedule 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 - 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:
BaseSchedulerPolynomial 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 - f(x) is a polynomial of degree C3.
After the number of decay steps, returns min value.
- class RescaleScheduler(logic: Callable[[float, int], float], factor: float)[source]
Bases:
TransformSchedulerScheduler adding scaling to existing logic.
- logic
callable to calculate the scheduling.
- factor
factor to multiply the output by.
Initialize.
- Parameters:
logic (_SchedulingLogic) – callable to calculate the scheduling.
factor (float) – factor to multiply the output by.
- class RestartScheduler(logic: Callable[[float, int], float], restart_interval: int, restart_fraction: float = 1.0, max_restart: int | None = None)[source]
Bases:
TransformSchedulerScheduler adding periodic restarts to existing logic.
- logic
callable to calculate the scheduling.
- restart_interval
number of epochs between restarts.
- restart_fraction
fraction to use when restarting.
- max_restart
maximum number of restarts before deactivating.
Initialize.
- class StepScheduler(milestones: Iterable[int] = <factory>, gamma: float = 0.1)[source]
Bases:
BaseSchedulerStep-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:
- class WarmupScheduler(logic: Callable[[float, int], float], warmup_steps: int)[source]
Bases:
TransformSchedulerScheduler adding warmup to existing logic.
- logic
callable to calculate the scheduling.
- warmup_steps
number of warmup steps.
Initialize.
- Parameters:
logic (_SchedulingLogic) – callable to calculate the scheduling.
warmup_steps (int) – number of warmup steps.
- rescale(factor: float) Callable[[Callable[[float, int], float]], RescaleScheduler][source]
Create a scaling transformation.
- restart(restart_interval: int, restart_fraction: float = 1.0, max_restart: int | None = None) Callable[[Callable[[float, int], float]], RestartScheduler][source]
Create a restart transformation.
- Parameters:
- Returns:
A decorator that adds restarting to the scheduling logic.
- Return type: