Learning-Rate Schedules #
Pure learning-rate schedules used by TorchLean training loops and examples. A Config describes a
schedule, and learningRateAt evaluates it at an optimizer step.
References #
- PyTorch schedulers:
torch.optim.lr_scheduler.*(https://pytorch.org/docs/stable/optim.html#how-to-adjust-learning-rate)
Small learning-rate scheduler surface for higher-level training code.
This file keeps the interface compact: a Config is just a description of a schedule,
and learningRateAt config stepIndex computes the learning rate at that optimizer step or epoch.
PyTorch mapping #
Config.step and Config.exponential correspond to the schedule math of:
torch.optim.lr_scheduler.StepLRtorch.optim.lr_scheduler.ExponentialLR
Config.warmupCosine is the schedule commonly used for Transformer pretraining: a short linear
warm-up followed by cosine decay to a nonzero floor.
- constant (learningRate : Float) : Config
- step (baseLearningRate : Float) (stepSize : Nat) (decayFactor : Float := 0.1) : Config
- exponential (baseLearningRate decayFactor : Float) : Config
- warmupCosine (peakLearningRate minimumLearningRate : Float) (warmupSteps totalSteps : Nat) : Config
Instances For
Constant learning-rate schedule.
Instances For
Exponential learning-rate schedule.
Instances For
Linearly warm up to peakLearningRate, then follow a cosine curve down to
minimumLearningRate.
warmupSteps counts optimizer updates. The first update uses
peakLearningRate / warmupSteps, and the last warm-up update reaches peakLearningRate. Once
totalSteps updates have been scheduled, the learning rate remains at minimumLearningRate.
A warm-up longer than the run is clamped to totalSteps. When totalSteps = 0, no update belongs
to the schedule and learningRateAt returns minimumLearningRate.
Instances For
Validate a learning-rate schedule before it is attached to optimizer state.
The checks keep every scheduled rate finite and nonnegative. Step and exponential schedules use
decay factors in [0, 1]; a zero step size is rejected instead of silently changing the schedule
to a constant rate.
Instances For
Learning rate at a given step or epoch index.