Neural Networks & Deep Learning Guide 4 of 6 · tap to switch
Gradient Descent, Learning Rate & Adam Optimizer
Master the engine that trains every deep model: tune learning rates, race SGD vs. Momentum vs. Adam, pick mini-batches, and schedule cosine decay.
Picture standing on a foggy hillside at night trying to reach the lowest valley floor. Backpropagation hands you a compass pointing straight downhill. Now you face the single most important knob in Deep Learning: how big a stride should you take? Stepping downhill again and again to shrink prediction error is gradient descent, powered in modern deep learning by well-chosen step sizes and the Adam optimizer.
That stride size is called the Learning Rate (often written with the Greek letter η, pronounced “eta”). Take tiny shuffling steps and sunrise arrives before you move halfway down. Take giant leaps past the bowl’s safe speed limit and you sail straight over the valley floor onto an even higher opposite cliff until the error overflows and crashes into NaN (“Not a Number”)!
Slide the Step Size / Learning Rate (η) dial below (or tap the 4 presets) to watch all four behaviors unfold live on a simple U-shaped error bowl, L(w) = (w - 3)², where error hits zero at w = 3.
In real training, checking every single row of a massive dataset before taking one step is painfully slow. Instead, networks almost always estimate the downhill slope from small random batches of data, a method called Stochastic Gradient Descent (SGD) (“stochastic” simply means random). Plain, unassisted downhill steps are known as Vanilla SGD.
Adam Optimizer vs. Vanilla SGD & Momentum
Real neural networks do not sit inside neat round bowls: their error landscapes resemble steep, skinny mountain canyons, sloping 60 times steeper across the canyon walls than lengthwise down the valley floor!
Watch what happens when we drop three classic optimizers onto the exact same canyon ridge below for 26 steps (press Play Race or drag the Step slider to watch every bounce unfold):
- Vanilla SGD only looks at the slope right under its feet, so it slams back and forth across the steep walls while barely inching sideways toward the goal.
- SGD + Momentum keeps a rolling memory of past steps like a heavy bowling ball rolling downhill: opposite up-and-down bounces cancel each other out while steady forward pushes build speed!
- Adam combines two superpowers at once: Momentum (rolling memory that smooths zig-zags) plus Automatic Per-Knob Braking (watching how steep each individual weight has been recently, slowing down steep directions while speeding up flat ones)!
Stochastic Gradient Descent (SGD) vs. Mini-Batch vs. Full-Batch
Suppose your training dataset has 1 million photos. Showing the model all 1 million photos once is called one Epoch (one full pass through the entire dataset).
Before taking a single downhill step, how many photos should you check? You have three choices:
- Full-Batch Gradient Descent: average the slope over all 1 million photos before taking just one slow step per epoch. It overflows GPU memory on big datasets and can settle into narrow dead-end traps.
- Single Example (Batch = 1): update weights after every individual photo. One mislabeled photo yanks the weights sideways, and it leaves almost all of the GPU’s parallel math lanes idle.
- Mini-Batch (32 to 256 photos): grab tidy random chunks of 64 photos at a time. Mini-batches fit inside GPU memory, keep parallel GPU math running at full speed, update weights thousands of times per epoch, and add just enough gentle random wobble to shake loose from narrow dead-end traps!
Compare all three trajectories below on the exact same GPU time budget!
Why one fixed learning rate is never enough (Warmup + Cosine Decay)
Early in training, you want brisk strides to cover big distance quickly, yet not on Step 1 when freshly randomized weights and Adam’s first few speed estimates can jump wildly. Late in training, you want to ease off the throttle like a landing aircraft, taking tiny, delicate adjustments so weights touch down softly at the lowest floor without rattling off the valley walls.
That two-stage speed plan is called Warmup + Cosine Decay: ramp the step size up gently over the first few passes (Warmup), then curve it smoothly down along a gentle wave (Cosine Decay) toward zero.
Switch between Constant, Step Decay, and Warmup + Cosine below and drag the Pass (Epoch) slider to inspect the exact schedule used to train modern language and vision models!
See Momentum, Adam & Decoupled AdamW Update EquationsThesis / Reference
1. Convex Step-Size Stability Bound: On an -smooth quadratic bowl with largest Hessian eigenvalue , vanilla Gradient Descent converges if and only if . In our Lab 1 bowl , , yielding the exact divergence threshold !
2. Polyak Momentum & Adam (Kingma & Ba, 2015): Given mini-batch gradient , Adam tracks exponentially decayed moving averages of the 1st moment (mean direction) and 2nd raw moment (uncentered variance) with bias correction for early steps:
Standard defaults are , (or for LLMs), and .
3. Why Modern Practice Uses AdamW (Loshchilov & Hutter, 2019): Classic L2 regularization adds inside , which Adam mistakenly rescales by , weakening regularization on large-gradient weights. AdamW decouples weight decay directly onto the parameter update: .
See AdamW + Cosine Annealing Schedule in PyTorchOptional Code
import torch
# Modern Deep Learning default: AdamW (decoupled weight decay) + Cosine Decay
optimizer = torch.optim.AdamW(
model.parameters(),
lr=3e-4, # Andrej Karpathy's classic AdamW starting sweet spot
weight_decay=0.01, # decoupled L2 shrinkage
)
scheduler = torch.optim.lr_scheduler.CosineAnnealingLR(
optimizer,
T_max=100, # total epochs
eta_min=1e-5, # gentle landing floor
)
for epoch in range(100):
train_one_epoch(model, train_loader, optimizer)
scheduler.step()Fast optimization creates a new danger: memorizing the training set!
With activation functions like ReLU and GELU, Backpropagation, and Adam (plus its weight-shrinking variant, AdamW) working together, a deep neural network is so powerful that it can memorize every single training photo or sentence cleanly in minutes.
How do deep learning engineers keep million-parameter networks stable AND force them to generalize to unseen data?
Next up: Dropout, Batch Norm & Weight Decay.
Quick Intuition Check
Four quick real-world scenarios. No scores, just test your intuition.
You launch training and notice the error jumps from 2.4 -> 18.7 -> 410.5 -> NaN within 5 steps. What is the very first lever you should check?
Why does Adam navigate steep, narrow canyons dramatically faster than plain Vanilla SGD?
Why do almost all deep learning models train on Mini-Batches (such as 32, 64, or 256 examples) instead of Full-Batch Gradient Descent?
Warmup + Cosine Decay starts with a gently rising learning rate to prevent wild early jumps on fresh random weights, then smoothly lowers the step size toward zero late in training so weights settle softly at the bottom.
Common Questions
What is Stochastic Gradient Descent (SGD) vs Mini-Batch Gradient Descent?
What does the Adam optimizer do, and does it change the learning rate?
Does gradient descent always find the global minimum?
What is Gradient Descent in simple terms?
Why does a learning rate that is too large make training explode?
Why is Adam (or AdamW) the default optimizer in modern Deep Learning?
Why do neural networks train on mini-batches (32 to 256) instead of the entire dataset at once?
Why do modern LLMs and vision models use Learning Rate Warmup + Cosine Decay?
Related Visual Guides
Derivatives, Slopes & the Gradient
Zoom into a curve to turn a chord into a derivative, slice a 2D bowl into partial slopes, and follow the Gradient compass downhill.
Backpropagation
See how neural networks pass blame backward from a wrong guess to every weight in one efficient Chain Rule sweep.
Feature Scaling: Normalization vs Standardization
Why salary in pounds bullies age in years, how Min-Max, Standardization, and RobustScaler compare under outliers, and which models actually care.
Written & illustrated by Muhammad Aashir Irshad · Updated December 2026 · Free open-access reference
Cite this guide in a paper, thesis, or course (BibTeX & APA)
@misc{irshad2026gradientdescent,
author = {Irshad, Muhammad Aashir},
title = {Gradient Descent, Learning Rate & Adam Optimizer: Interactive Visual Guide},
howpublished = {SeeingML},
year = {2026},
month = {dec},
url = {https://seeingml.com/learn/gradient-descent/},
note = {Interactive visual guide}
} Irshad, M. A. (2026). Gradient Descent, Learning Rate & Adam Optimizer: Interactive Visual Guide. SeeingML. https://seeingml.com/learn/gradient-descent/