Skip to content
induwara.lk
Premium
induwara.lkAI · Training

Learning Rate Scheduler Calculator

Plot the exact per-step learning rate for warmup, cosine, linear, constant, and Transformer (Noam) schedules — enter your peak LR, total steps, and warmup, then copy the matching Hugging Face code. Free, no signup, formulas cited below.

By Induwara AshinsanaUpdated Jul 8, 2026
Learning rate scheduleCosine with warmup
Matches Hugging Face transformers

The maximum LR reached at the end of warmup, e.g. 5e-4.

Total optimizer steps for the whole run.

Steps to ramp LR up from 0 to peak.

LR the schedule decays down to. 0 = full decay.

0.5 = one half-cosine (peak → floor). 1 = full wave.

Presets
Peak LR
0.0005
at step 100
LR at 50%
0.000293
step 500
Final LR
0
step 1,000
Peak : final
→ 0
decays to zero

LR vs. step

warmup ends at step 100
step 0peak 0.0005step 1,000
25% · step 250
0.000467
50% · step 500
0.000293
75% · step 750
8.93e-5
End · step 1,000
0

Code snippet

from transformers import get_cosine_schedule_with_warmup

# optimizer created with lr=0.0005 (your peak LR)
scheduler = get_cosine_schedule_with_warmup(
    optimizer,
    num_warmup_steps=100,
    num_training_steps=1000,
)

Sampled schedule

StepLearning rate
00
560.00028
1000.0005
1110.0005
1670.000493
2220.000478
2780.000453
3330.000422
3890.000383
4440.00034
5000.000293
5560.000245
6110.000197
6670.000151
7220.000109
7787.14e-5
8334.13e-5
8891.85e-5
9444.76e-6
1,0000
Factors reproduce the reference training-loop schedules.

How it works

A learning rate schedule multiplies your optimizer's learning rate (LR) by a factor that changes at every training step. Almost every modern transformer recipe follows the same two-part shape: a short warmup where the LR ramps up from 0 to the peak, then a decay back down. Warmup exists because a fresh model with random weights produces large, noisy gradients; starting at full LR can destabilise training, so the LR is eased in gradually (Goyal et al., 2017, §2.2).

For the linear, cosine, and constant schedules this tool reproduces the exact lr_lambda factors used by Hugging Face transformers, so the numbers match what the Trainer applies during real training:

  • Warmup (all schedules): factor = step / max(1, warmup), so the LR reaches the peak exactly at step = warmup.
  • Linear decay: factor = max(0, (total − step) / (total − warmup)) — a straight line from peak to 0.
  • Cosine decay: with progress = (step − warmup) / (total − warmup), factor = ½(1 + cos(π · num_cycles · 2 · progress)). At the default num_cycles = 0.5this is a single half-cosine from peak to 0, matching the SGDR annealing form of Loshchilov & Hutter (2017).
  • Constant with warmup: the LR holds at the peak after warmup (factor = 1).

You can add a floor with the Min LR field: the LR then follows lr = min_lr + (peak_lr − min_lr) · factor, so cosine and linear decay to your floor instead of 0. The Transformer (Noam) schedule is different — it is absolute rather than a multiple of a peak you choose. From Vaswani et al. (2017, §5.3): lr = d_model^(-0.5) · min(step^(-0.5), step · warmup^(-1.5)). It rises during warmup, peaks at step = warmup with value d_model^(-0.5) · warmup^(-0.5), then decays as the inverse square root of the step. The tool derives and shows that computed peak so you can compare schedules on the same axis.

Worked examples

Cosine with warmup

peak 5e-4 · total 1000 · warmup 100 · floor 0

  1. Step 50 (warmup): factor = 50 / 100 = 0.5 → lr = 5e-4 × 0.5 = 2.5e-4
  2. Step 100 (peak): progress = 0, factor = ½(1 + cos 0) = 1 → lr = 5e-4
  3. Step 550: progress = (550 − 100) / 900 = 0.5
  4. factor = ½(1 + cos(π × 0.5)) = ½(1 + 0) = 0.5 → lr = 2.5e-4
  5. Step 1000: progress = 1, factor = ½(1 + cos π) = 0 → lr = 0

Linear with warmup

peak 2e-5 · total 10,000 · warmup 500 · floor 0

  1. Step 250 (warmup): factor = 250 / 500 = 0.5 → lr = 1e-5
  2. Step 500 (peak): factor = 9500 / 9500 = 1 → lr = 2e-5
  3. Step 5250: factor = (10000 − 5250) / 9500 = 4750 / 9500 = 0.5 → lr = 1e-5
  4. Step 10000: factor = 0 / 9500 = 0 → lr = 0

Transformer (Noam) — edge of decay

d_model 512 · warmup 4000 (paper base config)

  1. d_model^(-0.5) = 1 / √512 = 0.044194
  2. Peak at step 4000: 0.044194 × 4000^(-0.5) = 0.044194 × 0.0158114 = 6.99e-4
  3. Step 1000 (warmup): 0.044194 × 1000 × 4000^(-1.5) = 0.044194 × 3.953e-3 = 1.75e-4
  4. Step 16000 (= 4× warmup): 0.044194 × 16000^(-0.5) = 0.044194 × 0.0079057 = 3.49e-4
  5. Note 16000 is 4× the peak step, and the LR is ≈ half the peak — the inverse-sqrt signature.

Frequently asked questions

Sources & references

The factors on this page were last cross-checked against the Hugging Face transformers source and the Vaswani formula on 2026-07-08. They are reviewed whenever the reference schedule implementations change.

Related tools

Rate this tool
Be the first to rate

Comments & feedback

Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.

Found a bug, edge case, or want another schedule added?

Email me at [email protected] — most fixes ship within 24 hours.