Home › Learning Rate Scheduler Visualizer (Cosine, OneCycle, Warmup)

Learning Rate Scheduler Visualizer (Cosine, OneCycle, Warmup)

Interactively compare and visualize PyTorch learning rate schedules including CosineAnnealingLR, OneCycleLR, StepLR, Warmup, and Exponential decay.

📖 Mastering Learning Rate Schedules in Deep Learning Optimization

The learning rate (LR) is the single most impactful hyperparameter in neural network training. A constant learning rate rarely achieves optimal convergence: a high LR accelerates early exploration out of saddle points but oscillates around narrow local minima later in training. The DevPanda LR Scheduler Visualizer lets you simulate, overlay, and compare standard PyTorch schedulers—including CosineAnnealingLR, Warmup + Cosine, OneCycleLR, StepLR, and ExponentialLR—across custom epoch budgets.

🚀 How to Use This Tool

  1. Set your Base Learning Rate (initial_lr), Minimum Learning Rate (eta_min), and Total Epochs.
  2. Configure schedule-specific parameters such as Warmup Epochs, Step Size (decay interval), and Gamma (multiplicative decay factor).
  3. Toggle multiple schedules on the comparison chart to inspect how aggressively each policy decays the learning rate at any specific epoch.
  4. Use the generated PyTorch code reference and epoch-by-epoch inspection table to copy exact hyperparameter values into your training script.

📐 Mathematical Formulations of Popular LR Schedulers

  • Cosine Annealing (Loshchilov & Hutter): lr(t) = lr_min + 0.5 × (lr_max - lr_min) × (1 + cos(π × t / T_max)). Provides a smooth, parameter-free decay that spends significant time at medium learning rates before gently settling into a minimum.
  • Linear Warmup + Decay: During the first T_warmup epochs, LR increases linearly from ~0 to lr_max. Warmup is mandatory for Transformers (ViT, BERT, LLMs) because adaptive optimizers like Adam have high variance in their second-moment estimates during the first few hundred steps.
  • OneCycleLR (Super-Convergence): Ramps LR from initial_lr up to max_lr over the first ~30% of training, then anneals down to a tiny fraction of initial_lr over the remaining 70%. The high peak LR acts as a built-in regularizer that helps models converge in fewer epochs.

❓ Frequently Asked Questions (FAQ)

Q. How should I scale my learning rate when I change the batch size?

For SGD with momentum, follow the Linear Scaling Rule: if you multiply batch size by k, multiply peak learning rate by k. For Adam/AdamW, the Square Root Scaling Rule (multiply LR by sqrt(k)) often provides more stable convergence.

Q. Why is warmup necessary when training Vision Transformers or LLMs?

At initialization, attention layer gradients can be large and poorly conditioned. Applying a full learning rate on step 1 pushes weights into saturated regions from which layer normalization and softmax attention struggle to recover.

Q. Should scheduler.step() be called per batch or per epoch?

StepLR and MultiStepLR are traditionally stepped once per epoch. OneCycleLR and Warmup+Cosine schedules used in modern Transformer training are typically stepped once per optimizer update (per mini-batch).