Adam Optimizer › The Adam Update Rule

Michael BrenndoerferApril 24, 20252 min read
Language AI HandbookAll chapters
Part 10 of 67Neural Network Foundations
Chapter 68Adam Optimizer › The Adam Update Rule
Reading section 5 of 18 · The Adam Update Rule · 2 minSection 5 of 18 · 2 min

Book contents

Section 5 of 18 · 2 min read

Adam Optimizer › The Adam Update RuleOne section · Sections in this chapter5 / 18 ↓
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

With bias-corrected moment estimates in hand, the Adam parameter update is:

θt+1=θt−αv^t+ϵm^t\theta_{t+1} = \theta_t - \frac{\alpha}{\sqrt{\hat{v}_t} + \epsilon} \hat{m}_t

where:

  • θt\theta_t: the parameter vector at step tt
  • α\alpha: the global learning rate (typically 0.001)
  • m^t\hat{m}_t: bias-corrected first moment (direction and momentum)
  • v^t\hat{v}_t: bias-corrected second moment (per-parameter scale)
  • ϵ\epsilon: a small constant for numerical stability, typically 10−810^{-8}

The full Adam algorithm, written out step by step, is:

gt=∇θL(θt−1)(compute gradient)mt=β1mt−1+(1−β1)gt(update first moment)vt=β2vt−1+(1−β2)gt2(update second moment)m^t=mt1−β1t(bias-correct first moment)v^t=vt1−β2t(bias-correct second moment)θt=θt−1−αv^t+ϵm^t(update parameters)\begin{aligned} g_t &= \nabla_\theta \mathcal{L}(\theta_{t-1}) && \text{(compute gradient)} \\ m_t &= \beta_1 m_{t-1} + (1 - \beta_1) g_t && \text{(update first moment)} \\ v_t &= \beta_2 v_{t-1} + (1 - \beta_2) g_t^2 && \text{(update second moment)} \\ \hat{m}_t &= \frac{m_t}{1 - \beta_1^t} && \text{(bias-correct first moment)} \\ \hat{v}_t &= \frac{v_t}{1 - \beta_2^t} && \text{(bias-correct second moment)} \\ \theta_t &= \theta_{t-1} - \frac{\alpha}{\sqrt{\hat{v}_t} + \epsilon} \hat{m}_t && \text{(update parameters)} \end{aligned}

where:

  • L\mathcal{L}: the loss function
  • All other variables are as defined above

The Role of Epsilon

The ϵ\epsilon term in the denominator prevents division by zero when v^t≈0\hat{v}_t \approx 0, which happens for parameters that have received no gradients. But ϵ\epsilon has an additional effect on Adam's behavior that is often overlooked.

Consider a parameter where v^t\hat{v}_t is very small, say 10−1210^{-12}. Then v^t+ϵ≈ϵ=10−8\sqrt{\hat{v}_t} + \epsilon \approx \epsilon = 10^{-8}, and the effective learning rate is α/ϵ=0.001/10−8=100,000\alpha / \epsilon = 0.001 / 10^{-8} = 100,000. This is enormous. In practice, if a parameter truly receives near-zero gradients consistently, its m^t\hat{m}_t is also near zero, so the actual update (α/ϵ)⋅m^t(\alpha / \epsilon) \cdot \hat{m}_t remains small. The two small quantities cancel out.

However, if ϵ\epsilon is set too small (e.g., 10−1610^{-16}), numerical precision issues can cause v^t\hat{v}_t to underflow to zero in floating-point arithmetic, resulting in infs or nans in the updates. If ϵ\epsilon is set too large (e.g., 1.0), Adam degenerates toward vanilla SGD because the denominator becomes dominated by ϵ\epsilon rather than v^t\sqrt{\hat{v}_t}, eliminating the adaptive behavior. The default ϵ=10−8\epsilon = 10^{-8} is a pragmatic choice that avoids both failure modes in typical float32 computation.

PyTorch's torch.optim.Adam uses ϵ=10−8\epsilon = 10^{-8} by default but exposes it as a tunable parameter. Some practitioners increase it to 10−710^{-7} or even 10−510^{-5} when training with mixed precision (float16), since smaller values can cause numerical instability at reduced precision.