Training Stability › Understanding Loss Spike Anatomy: A Numerical Walkthrough

Michael BrenndoerferJanuary 28, 20264 min read
Language AI HandbookAll chapters
Part 32 of 67Training Optimization
Chapter 237Training Stability › Understanding Loss Spike Anatomy: A Numerical Walkthrough
Reading section 9 of 15 · Understanding Loss Spike Anatomy: A Numerical Walkthrough · 4 minSection 9 of 15 · 4 min

Book contents

Section 9 of 15 · 4 min read

Training Stability › Understanding Loss Spike Anatomy: A Numerical WalkthroughOne section · Sections in this chapter9 / 15 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

To build deeper intuition, it is worth walking through the exact sequence of events that happens at the parameter level during a loss spike. This makes the abstract mechanisms concrete and clarifies why the interventions in this chapter are effective.

The Spike as a Three-Phase Event

A loss spike is not instantaneous; it unfolds over several steps. Understanding each phase clarifies what can be done at each point.

Phase 1: The trigger step. A batch arrives with unusually high loss. This could be an outlier document, a sharp curvature cliff in the landscape, or a sudden change in the effective learning rate. The gradient computed from this batch has a norm that is much larger than the running average, say 50x. The optimizer applies this gradient to all parameters.

Phase 2: Parameter displacement. After the large update, model parameters are in a different region of the loss landscape than they were a step earlier. If the update was large enough, they have moved past a local minimum and are now in a high-loss region. This is when the loss curve shows the spike: the next batch sees a higher loss than before the trigger.

Phase 3: Optimizer state corruption. Even if the parameters are eventually restored (by gradient descent pulling them back toward a good region), the Adam optimizer's second moment estimate vtv_t has absorbed a large gradient squared value. Because β2=0.999\beta_2 = 0.999, this inflated estimate decays slowly:

vt+k=β2kvt+(1−β2k)vˉv_{t+k} = \beta_2^k v_t + (1 - \beta_2^k) \bar{v}

where vˉ\bar{v} is the typical second moment value. With β2=0.999\beta_2 = 0.999 and a typical training run, the spike's influence on vtv_t is not halved until about 693 steps later (kk such that 0.999k=0.50.999^k = 0.5). During those 693 steps, Adam's adaptive step size for the affected parameters is artificially suppressed, because the denominator v^t+ϵ\sqrt{\hat{v}_t} + \epsilon is larger than it should be. The model is effectively frozen in those parameters while they slowly "forget" the spike.

A Concrete Numerical Example

Let us trace through the numbers for a single parameter to make this vivid. Suppose a parameter θ\theta has:

  • Current value: θt=0.5\theta_t = 0.5
  • Typical gradient: g∼0.1g \sim 0.1 (normal)
  • Adam state before spike: mt=0.1m_t = 0.1, vt=0.01v_t = 0.01 (so vt=0.1\sqrt{v_t} = 0.1)
  • Learning rate: η=0.001\eta = 0.001, ϵ=10−8\epsilon = 10^{-8}

The normal update magnitude is:

Δθ=ηvt+ϵ⋅mt≈0.0010.1⋅0.1=0.001\Delta\theta = \frac{\eta}{\sqrt{v_t} + \epsilon} \cdot m_t \approx \frac{0.001}{0.1} \cdot 0.1 = 0.001

That is a small, reasonable update. Now a spike batch arrives with gradient gspike=5.0g_{\text{spike}} = 5.0 (50x normal). After one Adam step:

mt+1=0.9×0.1+0.1×5.0=0.59vt+1=0.999×0.01+0.001×25.0=0.034899\begin{aligned} m_{t+1} &= 0.9 \times 0.1 + 0.1 \times 5.0 = 0.59 \\ v_{t+1} &= 0.999 \times 0.01 + 0.001 \times 25.0 = 0.034899 \end{aligned}

The update magnitude at step t+1t+1 is:

Δθt+1=0.0010.034899⋅0.59≈0.0010.1868⋅0.59≈0.00316\Delta\theta_{t+1} = \frac{0.001}{\sqrt{0.034899}} \cdot 0.59 \approx \frac{0.001}{0.1868} \cdot 0.59 \approx 0.00316

That is 3.16x larger than the normal update: the momentum-inflated first moment drives a much larger step. Three hundred steps later, the second moment has decayed to approximately:

vt+300≈0.999300×0.034899+(1−0.999300)×0.01≈0.027+0.0026≈0.0296v_{t+300} \approx 0.999^{300} \times 0.034899 + (1 - 0.999^{300}) \times 0.01 \approx 0.027 + 0.0026 \approx 0.0296

So even 300 steps after the spike, vtv_t is still 3x its pre-spike value, and the adaptive step size for this parameter is still suppressed by a factor of 3≈1.73\sqrt{3} \approx 1.73. The parameter is learning at 58% of its normal rate for 300+ steps after a single bad gradient. At scale, with thousands of affected parameters, this explains the "loss plateau" that practitioners often observe after a spike even when the loss appears to have recovered.

Gradient clipping prevents all of this from happening. By capping gspikeg_{\text{spike}} at 1.0 (assuming a clip threshold of 1.0), the spike's contribution to mtm_t and vtv_t is:

mt+1=0.9×0.1+0.1×1.0=0.19vt+1=0.999×0.01+0.001×1.0=0.011\begin{aligned} m_{t+1} &= 0.9 \times 0.1 + 0.1 \times 1.0 = 0.19 \\ v_{t+1} &= 0.999 \times 0.01 + 0.001 \times 1.0 = 0.011 \end{aligned}

This is only slightly above normal. The optimizer state remains well-behaved, and training continues smoothly after the clipped step.