๐Ÿ”ฅLimited Offer: Get 50% OFFon AI & Full Stack Courses๐Ÿ”ฅ
Back to Deep Learning Notes
Topic #104

Learning Rate Scheduling

A single fixed learning rate for an entire training run is rarely optimal. Learning rate scheduling changes \(\eta\) systematically over the course of training โ€” typically starting higher for fast early progress, and decreasing later for fine, stable convergence. This note introduces the general idea before the next five notes cover specific schedules.

Why a Fixed Rate Is a Compromise

Training StageWhat's NeededProblem with a Fixed Rate
Early trainingLarge steps to make fast progress from a random initializationToo small a fixed rate wastes early training time
Late trainingSmall, precise steps to settle into a good minimum without overshootingToo large a fixed rate causes oscillation right when precision matters most

A schedule resolves this tension directly: use a larger rate early, and shrink it later โ€” getting the benefits of both regimes across a single training run.

General Notation

\[ \eta_t = \text{schedule}(\eta_0, t) \]

\(\eta_0\) is the initial (or peak) learning rate; \(t\) is the current training step or epoch; "schedule" is one of several functions covered in the next five notes.

Code โ€” The General Pattern in PyTorch

import torch.optim as optim
from torch.optim.lr_scheduler import StepLR

optimizer = optim.Adam(model.parameters(), lr=0.001)
scheduler = StepLR(optimizer, step_size=10, gamma=0.5)   # halves lr every 10 epochs

for epoch in range(30):
    for batch in dataloader:
        # ... forward pass, loss, backward pass ...
        optimizer.step()
        optimizer.zero_grad()
    scheduler.step()   # called once per epoch, AFTER the epoch's optimizer.step() calls
    print(f"Epoch {epoch}: lr={scheduler.get_last_lr()}")

Every PyTorch scheduler follows this same pattern: it wraps an existing optimizer and adjusts its learning rate according to a rule, called once per epoch (or sometimes per step, depending on the schedule).

A Quick Map of What's Coming

ScheduleShape
Step DecaySudden drops at fixed intervals
Exponential DecaySmooth, continuous exponential shrinkage every step
Cosine AnnealingSmooth decay following a cosine curve, popular for its gentle, non-linear shape
WarmupGradual increase at the very start, before the main schedule takes over
One-CycleRises then falls within a single training run โ€” a full cycle of increase and decrease

Common Mistakes

  • Calling scheduler.step() at the wrong point in the loop (e.g. before optimizer.step(), or once per batch for a schedule designed to run once per epoch) โ€” this silently shifts the schedule's timing relative to what was intended.
  • Treating "no schedule" as always a safe default โ€” for many modern architectures (especially Transformers), a well-chosen schedule (particularly warmup, covered later) isn't just a minor optimization โ€” training can fail to converge stably without it.

Interview Relevance

Q: "Why not just pick one good, fixed learning rate for the whole training run?" The ideal learning rate genuinely differs across training stages โ€” large early on for fast progress from a random initialization, small later on for precise convergence without overshooting a good minimum. A schedule captures both needs within one run, rather than compromising on a single fixed value that's suboptimal for at least part of training.

Practice Question

You're training a model for 100 epochs. Would you expect a schedule that decreases the learning rate to help more in the first 10 epochs or the last 10 epochs? Why?

Want to go beyond the notes?

Join CodingNow 2.0's Deep Learning course โ€” live mentorship, real projects, and 100% placement support.

Enroll Now โ€” Free Demo Available

Learning Rate Scheduling โ€“ FAQs

Quick answers about learning Learning Rate Scheduling in Deep Learning.

This free note from CodingNow 2.0 explains Learning Rate Scheduling in Deep Learning โ€” concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Deep Learning topic on CodingNow 2.0, including Learning Rate Scheduling, is 100% free with no signup required.
With focused practice, most students grasp Learning Rate Scheduling in 1โ€“3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) โ€” expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now