Native Learning-Rate Schedulers #
TorchLean-native schedules with explicit state and total formulas. Zero-length warmup or cycle
phases have defined fallback behavior, which makes the schedules convenient for direct execution
and theorem statements. currentStep is zero-indexed and step advances it once.
Schedulers.Core documents the shared arithmetic, state convention, and literature. Use the
separate PyTorch module when exact PyTorch phase and step-count behavior is required.
Native Schedulers #
Constant scheduler (no learning rate changes).
- lr : α
Fixed learning rate.
Instances For
Get the learning rate for a constant schedule.
The step argument is ignored (the LR never changes).
PyTorch analogy: no scheduler (or a scheduler that keeps LR fixed).
Instances For
Advance a constant scheduler by one step.
This is the identity since there is no state to update.
PyTorch analogy: scheduler.step() for a scheduler that does nothing.
Instances For
Create a constant learning-rate scheduler.
PyTorch analogy: constructing training code with a fixed lr and no lr_scheduler.
Instances For
Exponential decay #
Exponential decay scheduler: lr(step) = initial_lr * decay_rate^step.
PyTorch analogy: similar spirit to ExponentialLR, but we keep state as a simple counter.
- initialLr : α
Learning rate at step
0. - decayRate : α
Multiplicative decay factor per step (
gammain PyTorch terminology). - currentStep : ℕ
Current step counter (0-indexed).
Instances For
Get the learning rate for an exponential decay schedule at the current step.
Formula: initial_lr * decay_rate ^ current_step.
PyTorch analogy: torch.optim.lr_scheduler.ExponentialLR (but here kept as a pure counter-based
record).
Instances For
Advance the exponential decay scheduler by one step.
PyTorch analogy: scheduler.step().
Instances For
Create an exponential decay scheduler starting at step 0.
PyTorch analogy: torch.optim.lr_scheduler.ExponentialLR(optimizer, gamma=decay_rate).
Instances For
Step decay #
Piecewise-constant decay: every step_size steps, multiply the learning rate by decay_factor.
- initialLr : α
Learning rate at step
0. - decayFactor : α
Multiplicative decay factor applied every
step_sizesteps. - stepSize : ℕ
Number of steps between decays.
- currentStep : ℕ
Current step counter (0-indexed).
Instances For
Get the learning rate for step decay at the current step.
Every step_size steps, the LR is multiplied by decay_factor. When step_size = 0, this falls
back to a constant LR.
PyTorch analogy: torch.optim.lr_scheduler.StepLR.
Instances For
The totalized step_size = 0 case is constant.
PyTorch would reject this configuration; TorchLean keeps scheduler evaluation total so configs can be validated separately from pure schedule semantics.
Advance the step-decay scheduler by one step.
PyTorch analogy: scheduler.step().
Instances For
Create a step-decay scheduler starting at step 0.
PyTorch analogy: torch.optim.lr_scheduler.StepLR(optimizer, step_size=..., gamma=decay_factor).
Instances For
Cosine annealing #
Cosine annealing down to min_lr over max_steps steps.
PyTorch analogy: CosineAnnealingLR (without restarts).
- initialLr : α
Learning rate at step
0. - minLr : α
Minimum learning rate after annealing completes.
- maxSteps : ℕ
Number of steps over which to anneal.
- currentStep : ℕ
Current step counter (0-indexed).
Instances For
Get the learning rate for cosine annealing at the current step.
We anneal from initial_lr to min_lr over max_steps steps (clamping once we pass max_steps).
PyTorch analogy: torch.optim.lr_scheduler.CosineAnnealingLR (without restarts).
Instances For
Advance the cosine annealing scheduler by one step.
PyTorch analogy: scheduler.step().
Instances For
Create a cosine annealing scheduler starting at step 0.
PyTorch analogy: torch.optim.lr_scheduler.CosineAnnealingLR(optimizer, T_max=max_steps, eta_min=min_lr).
Instances For
Linear warmup #
Linear warmup from start_lr to initial_lr over warmup_steps, then constant.
Warmup is a practical trick commonly used when training large models (e.g. Transformers) to avoid instability at the start of training.
- initialLr : α
Target learning rate after warmup.
- warmupSteps : ℕ
Number of warmup steps.
- startLr : α
Starting learning rate during warmup.
- currentStep : ℕ
Current step counter (0-indexed).
Instances For
Get the learning rate for linear warmup (then constant).
Before warmup_steps, linearly interpolate from start_lr to initial_lr. Afterwards, keep
initial_lr fixed.
PyTorch analogy: warmup logic commonly implemented in training scripts (and in some scheduler helpers).
Instances For
Advance the linear warmup scheduler by one step.
PyTorch analogy: scheduler.step().
Instances For
Create a linear warmup scheduler starting at step 0.
PyTorch analogy: a warmup wrapper around an optimizer or a base scheduler.
Instances For
Warmup + cosine #
Warmup followed by cosine annealing.
This is a common “default” schedule for Transformer-style training: warm up for a few thousand steps, then gradually anneal.
- initialLr : α
Peak learning rate (reached at the end of warmup).
- warmupSteps : ℕ
Number of warmup steps.
- totalSteps : ℕ
Total number of steps for the whole schedule (warmup + anneal).
- currentStep : ℕ
Current step counter (0-indexed).
Instances For
Get the learning rate for the warmup-then-cosine schedule at the current step.
- During warmup, LR increases linearly from
0toinitial_lr. - After warmup, LR follows a cosine anneal over the remaining steps.
- At and after
total_steps, LR remains at0instead of beginning another cosine period.
PyTorch analogy: a common Transformer schedule, often implemented by composing warmup with cosine decay.
Instances For
Advance the warmup+cosine scheduler by one step.
PyTorch analogy: scheduler.step().
Instances For
Create a warmup+cosine scheduler starting at step 0.
PyTorch analogy: composing a warmup schedule with cosine annealing in a training script.
Instances For
Cyclic LR #
Cyclic learning rate schedule.
This corresponds to the “triangular” family of schedules where the LR increases linearly from
base_lr to max_lr and then decreases back, repeating in cycles.
We keep mode as a String so this runtime layer can be configured from simple config files or
CLI arguments (mirroring how training scripts are usually written).
- baseLr : α
Minimum learning rate within the cycle.
- maxLr : α
Maximum learning rate within the cycle (before any mode-specific adjustment).
- stepSize : ℕ
Half-cycle size (in steps).
- mode : String
"triangular","triangular2", or"exp_range". - gamma : α
Decay factor used by
"exp_range". - currentStep : ℕ
Current step counter (0-indexed).
Instances For
Get the learning rate for the cyclic schedule at the current step.
Supports the common "triangular", "triangular2", and "exp_range" variants (matching the
flavor of PyTorch's CyclicLR).
PyTorch analogy: torch.optim.lr_scheduler.CyclicLR.
Instances For
Advance the cyclic scheduler by one step.
PyTorch analogy: scheduler.step().
Instances For
Create a cyclic learning-rate scheduler starting at step 0.
PyTorch analogy: torch.optim.lr_scheduler.CyclicLR(base_lr=..., max_lr=..., step_size_up=...).
Instances For
Triangular cycle (special case) #
A specialized cyclic schedule with fixed amplitude.
This is essentially CyclicScheduler in "triangular" mode, but we provide it as a separate type
so callers don't have to thread mode strings around.
- baseLr : α
Minimum learning rate within the cycle.
- maxLr : α
Maximum learning rate within the cycle.
- stepSize : ℕ
Half-cycle size (in steps).
- currentStep : ℕ
Current step counter (0-indexed).
Instances For
Get the learning rate for the triangular cycle schedule at the current step.
This is the canonical "triangle up then down" schedule with fixed amplitude.
PyTorch analogy: CyclicLR in "triangular" mode.
Instances For
Advance the triangular cycle scheduler by one step.
PyTorch analogy: scheduler.step().
Instances For
Create a triangular cycle scheduler starting at step 0.
PyTorch analogy: CyclicLR(base_lr=..., max_lr=..., mode=\"triangular\").
Instances For
1cycle Learning Rate Schedule #
One-cycle learning-rate schedule.
- increase LR from
initial_lrtomax_lrover the firstpct_startfraction of steps, - then decrease to
final_lrover the rest.
In the original 1cycle policy, momentum is also scheduled; we keep this runtime version LR-only.
- maxLr : α
Peak learning rate (reached at
pct_startof the schedule). - totalSteps : ℕ
Total number of steps in the schedule.
- initialLr : α
Learning rate at step
0. - finalLr : α
Learning rate after the full schedule finishes.
- divFactor : α
Divides
max_lrto getinitial_lrin the factory constructor. - pctStart : α
Fraction of the schedule spent increasing LR (0..1).
- currentStep : ℕ
Current step counter (0-indexed).
Instances For
Get the learning rate for the one-cycle schedule at the current step.
This ramps up to max_lr over the pct_start fraction of the schedule, then anneals down to
final_lr.
PyTorch analogy: torch.optim.lr_scheduler.OneCycleLR, restricted here to the learning-rate curve.
Instances For
Advance the 1cycle scheduler by one step.
PyTorch analogy: scheduler.step().
Instances For
Create a simplified 1cycle schedule starting at step 0.
We derive initial_lr := max_lr / div_factor and final_lr := max_lr / final_div_factor.
PyTorch analogy: torch.optim.lr_scheduler.OneCycleLR(max_lr=..., total_steps=...).
Instances For
LR finder #
Get the learning rate for the LR-finder exponential sweep at the current step.
This increases LR exponentially from initial_lr toward final_lr across num_steps.
PyTorch analogy: LR finder utilities used by libraries like fastai, often implemented as a custom schedule.
Instances For
Advance the LR finder by one step.
PyTorch analogy: stepping a custom LR schedule inside a training loop.
Instances For
Create an LR finder schedule starting at step 0.
PyTorch analogy: setting up an LR finder run to sweep learning rates.