Skip to Content
OchreML
Training (Losses, Optimizers & Schedulers)

LR Schedulers

Learning rate scheduling with StepLR, CosineAnnealingLR, and WarmupCosineLR backed by Rust.

ochreml.nn provides three learning rate schedulers — StepLR, CosineAnnealingLR, and WarmupCosineLR. Each accepts either an Optimizer instance (automatically updating optimizer.lr on every .step()) or a raw float base learning rate.

Import & Signatures

import ochreml.nn as nn

s1 = nn.StepLR(optimizer_or_lr, step_size, gamma=0.1)
s2 = nn.CosineAnnealingLR(optimizer_or_lr, T_max, eta_min=0.0)
s3 = nn.WarmupCosineLR(optimizer_or_lr, warmup_steps, total_steps, min_lr=0.0)

Parameters

SchedulerParametersBehavior
StepLRoptimizer_or_lr, step_size, gamma=0.1Multiplies learning rate by gamma every step_size calls to .step().
CosineAnnealingLRoptimizer_or_lr, T_max, eta_min=0.0Smooth cosine decay from initial LR down to eta_min over T_max steps.
WarmupCosineLRoptimizer_or_lr, warmup_steps, total_steps, min_lr=0.0Linear warmup over warmup_steps, followed by cosine decay to min_lr.

Methods

  • scheduler.get_lr() -> float — returns the current learning rate.
  • scheduler.step() -> float — advances the schedule by one step, updates optimizer.lr if attached, and returns the new LR.

Usage Example

import ochreml.nn as nn

model = nn.Linear(32, 4)
optimizer = nn.AdamW(model.parameters(), lr=1e-3)
scheduler = nn.WarmupCosineLR(optimizer, warmup_steps=10, total_steps=100, min_lr=1e-5)

for step in range(100):
    # ... forward, backward, optimizer.step() ...
    current_lr = scheduler.step()

On this page