advanced28 min studyLesson 616 in Engineering

Define the schedule clock and every endpoint

Specify update indexing, warmup, cosine decay, skipped steps, and restored scheduler state so the learning rate applied to an update is reproducible.

On this page

What you’ll understand

  • Evaluate a fully indexed warmup-and-decay schedule at its boundaries.
  • Distinguish applied-update, attempted-update, and token-based schedule clocks.
  • Test framework scheduler ordering and resume behavior against expected rates.

A schedule is not fully defined by saying warmup followed by cosine decay. It needs a clock, an indexing convention, endpoints, and a rule for which rate is applied to which parameter update. A scheduler API may initialize an internal counter or advance it at a different point than expected. Off-by-one differences can change the first update, the peak, and recovery behavior. Write a small table of expected applied rates before launching the run, then compare it with the optimizer's actual parameter groups.

Choose a clock that survives accumulation and failure

Here u numbers successfully applied optimizer updates from one through U, and η(u) is the rate used by update u. Accumulation microbatches do not each advance this clock. Under this explicitly chosen policy, an overflow-skipped update does not advance u, though consumed tokens and attempted updates are still counted separately. Other experiments can schedule by attempted updates or valid tokens, but that is a different policy and must state what happens when a step is skipped or replayed.

Token-based scheduling can make exposure boundaries more comparable when valid-token batches vary, but it also needs an exact counter definition. Consumed tokens that failed to influence an applied update are not automatically the same as accepted trajectory exposure. Record schedule configuration, current progress, and the last applied rate in checkpoints. If the batch policy changes, a fixed number of updates no longer implies the same number of valid targets, so comparisons should report both clocks rather than silently renaming one as the other.

tu=∑v=1uTv,u∈{1,…,U}t_u=\sum_{v=1}^{u}T_v,\qquad u\in\{1,\ldots,U\}
T_v is the declared valid-token count associated with applied update v, so t_u is accepted-trajectory token exposure in this convention. This does not count discarded work or extra recovery recomputation. A different schedule clock is permissible when its semantics are documented.↔ Scroll wide equations horizontally.

Write the warmup and decay branches explicitly

Use a linear warmup for updates one through W, reaching ηmax at update W. For subsequent updates through U, use one half-cosine down to ηmin at U. Require integers 1≤W<U and nonnegative rates ηmin≤ηmax. No update zero is applied in this example, and behavior after U is deliberately outside the scheduled run. These choices remove ambiguities that a bare pair of hyperparameters cannot resolve, including whether the first update has zero rate.

The original Transformer paper used an inverse-square-root schedule with warmup, showing that cosine is not a universal architectural requirement. The pinned Transformers 4.57.1 implementation provides concrete schedule variants with explicit counter formulas, while PyTorch 2.9 documents optimizer/scheduler call ordering. Our formula is an independent stated example, not a promise that every named cosine helper uses the same endpoints. Inspect the selected helper's actual rates, including initialization, instead of equating a function name with this convention.

η(u)={ηmax⁡u/W,1≤u≤W,ηmin⁡+ηmax⁡−ηmin⁡2 ⁣[1+cos⁡ ⁣(πu−WU−W)],W<u≤U.\eta(u)=\begin{cases}\eta_{\max}u/W,&1\le u\le W,\\ \eta_{\min}+\dfrac{\eta_{\max}-\eta_{\min}}2\!\left[1+\cos\!\left(\pi\dfrac{u-W}{U-W}\right)\right],&W<u\le U.\end{cases}
u, W, and U are integer update counts under the applied-update convention. The rates have the optimizer's declared parameter-update scaling convention; model coordinates are treated as dimensionless here. This schedule alone does not guarantee stability, and it is not asserted to match every framework helper's zero-based indexing.↔ Scroll wide equations horizontally.

Audit the applied rate around boundaries and resume

Log rates used by the first few updates, the last warmup update, the first decay update, and the final update. Test an overflow skip with a controlled fixture and confirm the chosen clock policy, then restore a checkpoint and compare the next applied rate. Also inspect every optimizer parameter group when rates differ. Reconstructing a scheduler from its defaults while restoring only weights can restart warmup or advance decay incorrectly, even when the resumed loss initially looks plausible.

The optimization lab isolates constant-step sensitivity on a quadratic, not this schedule. Reset, set both step η=0.5 and nonzero initial position x0=2, predict contraction, then take four Steps to reach x4=0.125. Reset and set both η=1.5,x0=2 for alternating contraction to the same fourth value. Each Step is one recurrence update. The lab has no warmup, cosine decay, Adam state, skipped updates, or token clock; it explains why the actual applied step sequence deserves inspection without validating a pretraining schedule.

Evaluate the first, peak, midpoint, and final rates

Use the stated schedule with W=2, U=6, ηmax=0.01 and ηmin=0.001. Rates are applied to updates numbered from one, and only successful applied updates advance this example's clock.

  1. Warmup gives η(1)=0.01×1/2=0.005 and η(2)=0.01. The second update reaches the peak; there is no applied update zero.

  2. At u=4, decay progress is (4−2)/(6−2)=1/2. Since cos(π/2)=0, η(4)=0.001+0.009/2=0.0055.

  3. At u=6, progress is one and cos(π)=−1, so η(6)=0.001. A restored checkpoint after update four must next apply η(5), not restart η(1) or reuse η(4).

The result

The expected rates at updates one, two, four, and six are 0.005, 0.01, 0.0055, and 0.001. This table is an executable-oracle target for the chosen convention.

Explore the model

Interactive lab

Interactive lab · optimization

Inspect a constant-step recurrence before discussing schedules

Reset → set both η=0.5,x0=2; predict x4=0.125 and take four Steps. Reset → set both η=1.5,x0=2 for alternating contraction to the same x4. This exact quadratic model has no schedule, Adam state, overflow skip, or token clock.

Inspect a constant-step recurrence before discussing schedulesGradient descent on f(x) = x²/2: xₙ = (1 − η)ⁿx₀. Playback advances two discrete iterations per second. Values outside |x| ≤ 4 are explicitly reported. Current readings: Position x0: 2; Objective x²/2: 2; Iteration behavior: Stable step. All parameters are adjustable with the labeled controls below.−4−202402.174.356.528.7Parameter xf(x) = x²/2n = 0
ObjectiveDiscrete iterate
Position x0
2
Objective x²/2
2
Iteration behavior
Stable step
n = 0 · t = 0 s

Gradient descent on f(x) = x²/2: xₙ = (1 − η)ⁿx₀. Playback advances two discrete iterations per second. Values outside |x| ≤ 4 are explicitly reported. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forThe rates actually applied to updates matter; a schedule name is not an indexing specification.

Check your understanding

Under this lesson's successful-applied-update clock, an overflow skips the optimizer step. What should happen to u?

Try it yourself

For the same W=2,U=6 schedule, calculate η(5). A checkpoint contains completed update u=4, and the next attempt is overflow-skipped under the stated policy. Which rate should the next successful update use?

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

For update five, cosine progress is three quarters. The failed attempt does not change the successful-update index.

Compare with the solution

η(5)=0.001+0.0045[1+cos(3π/4)]≈0.001+0.0045×0.292893≈0.00231802. After a skipped attempt, the next successful update is still update five and uses that rate under the declared policy. Its data and attempt counters may differ from an uninterrupted run, which must be recorded separately. A framework integration test should inspect the applied optimizer rate rather than infer it solely from the scheduler object's counter.

Take it with you

  • Schedules require an explicit progress clock, index origin, and applied-rate convention.
  • Warmup and decay endpoints should be tested as numerical fixtures.
  • Resume and skipped-step policies must preserve the chosen clock rather than silently restarting it.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.