Cosine LR with Linear Warmup

The learning-rate schedule is the second most important decision after the loss function. AdamW with a cosine decay and a linear warmup is the modern default for language-model training because it lets the model see a small effective step size during the brittle first thousand updates, ramps up to a configured peak, and decays smoothly back toward zero. This lesson builds that schedule, plots the curve over training steps, logs gradient norms next to the schedule, and proves the schedule honors warmup, peak, and decay boundaries.

Build 1.5 hr Python

Prerequisites: Phase 19 lessons 30-37

#Learning Objectives

  • Implement an AdamW optimizer wired to a cosine learning-rate schedule with linear warmup.
  • Compute the schedule's exact value at any step without floating-point drift across runs.
  • Log gradient L2 norm side by side with the learning rate so training health is observable.
  • Render the schedule to a text plot the eye can read and a CSV any tool can consume.
Full Access lesson

Keep going. The rest of this lesson is one step away.

Unlock all 503 lessons, video, code, quizzes and every future update. Pay in your own currency with Paystack.

The text and code of this lesson are based on AI Engineering from Scratch by Rohit Ghumare, MIT licensed.