C.W.K.
Stream
Lesson 02 of 08 · published

Optimizers

~9 min · training

Level 0Keras Apprentice
0 XP0/97 lessons0/20 achievements
0/120 XP to next level120 XP to go0% complete

What the optimizer decides

The loss tells you how wrong you are; the optimizer decides what to do about it. Given a gradient, it chooses the size and direction of each weight's update. That single choice is why the same model with the same data can converge cleanly or thrash forever — the optimizer is the policy, the gradient is just the raw signal.

Keras ships every optimizer that matters. Start here:

OptimizerKey FeatureWhen to Use
AdamAdaptive learning ratesDefault starting point
AdamWAdam + weight decayFine-tuning pretrained models
SGDSimple + momentumStill competitive, good with schedules
RMSpropAdaptive per-parameterRNNs, non-stationary objectives
MuonNewton-style updatesNew in Keras 3.10, experimental

If you're unsure, reach for Adam — it's the default for a reason, and it forgives a sloppy learning rate better than anything else. Switch to AdamW the moment you fine-tune a pretrained model, because decoupled weight decay is what keeps those large pretrained weights from drifting.

The learning rate is a curve, not a number

A fixed learning rate is a compromise: too high to finish cleanly, too low to start fast. A schedule resolves the tension by changing the LR over training. The Code section sets up cosine decay with a warmup — ramp up gently for the first few hundred steps so early noisy gradients don't blow up the weights, then decay smoothly toward a floor so the final epochs settle into a sharp minimum. Pass the schedule object straight into the optimizer's learning_rate and Keras advances it every step for you.

Code

Cosine decay with warmup, fed into Adam·python
# Cosine decay with warmup
lr_schedule = keras.optimizers.schedules.CosineDecay(
    initial_learning_rate=1e-3,
    decay_steps=10000,
    alpha=1e-6,       # Minimum learning rate
    warmup_target=1e-3,
    warmup_steps=1000,
)
optimizer = keras.optimizers.Adam(learning_rate=lr_schedule)

External links

Exercise

Train MNIST with learning rates [1e-1, 1e-2, 1e-3, 1e-4, 1e-5]. Plot training loss curves. Identify where it diverges, where it converges, where it's too slow.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.