Where The Decay Goes
Two optimizer inner loops, identical except for where the decay term sits:
# variant A
g = grad(loss, w) + wd * w
m = b1 * m + (1 - b1) * g
v = b2 * v + (1 - b2) * g * g
w -= lr * m_hat / (sqrt(v_hat) + eps)
# variant B
g = grad(loss, w)
m = b1 * m + (1 - b1) * g
v = b2 * v + (1 - b2) * g * g
w -= lr * (m_hat / (sqrt(v_hat) + eps) + wd * w)
Which is AdamW, and what is the observable consequence of the difference?
Sign in to answer questions and track your progress
Sign In