TensorTau PathToAGI Training Deep Networks Level 07

Level 07 · Training Deep Networks · Chapter 093

Momentum

Can an optimizer move through noisy ravines more smoothly by remembering its recent direction?

Plain SGD uses only the current gradient. Momentum maintains a velocity:

vt=βvt−1+gt,v_t=\beta v_{t-1}+g_t,

θt=θt−1−ηvt.\theta_t=\theta_{t-1}-\eta v_t.

1. Ball rolling downhill

Imagine a ball in a narrow valley. Gradients may alternate left/right across the valley while consistently pointing forward along it.

SGD:      /\/\/\/\/→
momentum: ─────────→

Repeated forward components accumulate. Oscillating components partially cancel.

2. Exponential memory

Expanding the recurrence shows

vt=gt+βgt−1+β2gt−2+⋯ .v_t=g_t+\beta g_{t-1}+\beta^2g_{t-2}+\cdots.

Recent gradients matter most; older ones fade geometrically. With β=0.9\beta=0.9, the optimizer remembers a substantial history without storing every gradient.

3. Why it can overshoot

Velocity has inertia. Near a minimum, momentum may carry parameters past the optimum. Learning rate and momentum must be tuned together.

4. PyTorch

opt = torch.optim.SGD(model.parameters(), lr=0.01, momentum=0.9)

The optimizer stores one velocity tensor per parameter.

What to Remember

Momentum smooths noisy directions and accelerates persistent ones by accumulating an exponentially weighted gradient history.

Next → RMSProp: momentum remembers direction; can we also adapt step sizes to the scale of each parameter’s gradients?

Six ways to work the chapter, climbing from explaining it in your own words to investigating it like a researcher. Reading is not enough — this is where the chapter lands.

  1. Explain: Momentum with a rolling-ball analogy.
  2. Calculate: Compute three velocity updates for given gradients and β=0.9.
  3. Predict: What does β=0 reduce to?
  4. Break: Combine high learning rate with high momentum and observe overshoot.
  5. Build: Implement SGD+momentum from scratch.
  6. Investigate: Compare SGD and momentum on an elongated quadratic loss surface.