The Adam / AdamW optimizer step over ℝ #
The ℝ reference for vit-train's optimizer. Coordinatewise over Vec, mirroring the
emitted StableHLO update (MlirCodegen.emitAdamUpdate) op-for-op so the faithfulness
theorem adamW_triple_faithful (Codegen/StableHLO/Basic.lean) is a structural match.
Unlike SgdDescent, this file proves no descent guarantee: Adam is not a
monotone descent method (Reddi et al. 2018, the AMSGrad counterexample), so the
verified target is faithfulness (the rendered update equals adamWStep of the
certified gradient) plus well-definedness (the √v̂ + ε denominator is strictly
positive) — NOT a loss-decrease bound.
bc₁/bc₂ are the bias-correction denominators 1 − β₁ᵗ / 1 − β₂ᵗ, passed in
(host-computed per step) rather than recomputed in-graph — matching the emitter,
which threads them as scalar tensor<f32> function arguments.
References #
- Kingma & Ba 2015, Adam: A Method for Stochastic Optimization. https://arxiv.org/abs/1412.6980
- Loshchilov & Hutter 2019, Decoupled Weight Decay Regularization (AdamW). https://arxiv.org/abs/1711.05101
AdamW parameter update (decoupled weight decay), coordinatewise:
θ' = θ − lr·( (m'/bc₁) / (√(v'/bc₂) + ε) ) − (wd·lr)·θ. The mh/den shape
and the trailing − wd·lr·θ mirror emitAdamUpdate exactly.
Equations
- Proofs.adamWParam β₁ β₂ ε lr wd bc₁ bc₂ θ m v g i = θ i - lr * (Proofs.adamMNext β₁ m g i / bc₁ / (√(Proofs.adamVNext β₂ v g i / bc₂) + ε)) - wd * lr * θ i
Instances For
One AdamW step: the new parameter together with the new moments
(θ', m', v') — the triple the rendered train step returns per parameter.
Equations
- Proofs.adamWStep β₁ β₂ ε lr wd bc₁ bc₂ θ m v g = (Proofs.adamWParam β₁ β₂ ε lr wd bc₁ bc₂ θ m v g, Proofs.adamMNext β₁ m g, Proofs.adamVNext β₂ v g)
Instances For
Second-moment invariant. v' stays nonnegative when 0 ≤ β₂ ≤ 1 and the
incoming v is nonnegative — so, starting from v = 0, every step keeps
√v̂ real and the denominator below well-defined.
Well-definedness of the AdamW update. The denominator √(v'/bc₂) + ε is
strictly positive whenever ε > 0 — Real.sqrt is unconditionally nonnegative,
so there is no division by zero in adamWParam (the analogue of the BatchNorm
0 < ε positivity side condition, but unconditional in v).