AI Wiki中文/EN

RMSProp: let old gradients fade

RMSProp

Track raw and centered moving moments, epsilon placement and a fitted scalar model.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

Remember recent scale instead of every old spike

Adagrad never forgets a large squared gradient. That can be useful memory, or it can keep shrinking an effective learning rate long after the gradient distribution changes. RMSProp replaces the cumulative sum with an exponential moving average.

The early Neural Networks for Machine Learning lecture 6e describes the squared-gradient average and credits Tijmen Tieleman’s unpublished work. The lecture is presented by Geoffrey Hinton with Nitish Srivastava and Kevin Swersky; it should not be described as a jointly authored RMSProp research paper. The fixed PyTorch 2.8 API supplies the precise epsilon and centered-option conventions used below.

The decay factor sets a memory timescale

With v₀=0, a smoothing factor ρ in [0,1), a positive rate η and offset ε, the uncentered update is:

vt=ρvt−1+(1−ρ)gt2,θt=θt−1−ηgtvt+ε.v_t=\rho v_{t-1}+(1-\rho)g_t^2,\qquad \theta_t=\theta_{t-1}-\frac{\eta g_t}{\sqrt{v_t}+\varepsilon}.

All operations can be applied coordinatewise. The denominator uses the second raw moment, not a standard deviation: a nonzero mean also contributes to E[g²]. Expanding the recurrence and then considering a run of zero gradients gives:

vt=(1−ρ)∑i=1tρt−igi2,vt+k=ρkvt(gt+1:t+k=0),h1/2=log⁡(1/2)log⁡ρ(0<ρ<1).v_t=(1-\rho)\sum_{i=1}^t\rho^{t-i}g_i^2,\qquad v_{t+k}=\rho^k v_t\quad(g_{t+1:t+k}=0),\qquad h_{1/2}=\frac{\log(1/2)}{\log\rho}\quad(0<\rho<1).

The half-life is measured in updates. With ρ=1/2, a stored contribution halves after each update. Zero gradients reduce v even when there is no parameter motion in this no-momentum version. A missing gradient that causes an optimizer to skip a parameter is a different operation; the program processes explicit numerical zeros.

For a constant gradient c, vₜ=c²(1−ρᵗ). Starting from zero therefore underestimates its steady second moment. Basic RMSProp does not apply Adam’s initialization correction. An early denominator can be smaller than its later value, so effective early steps can be larger even with a constant base rate.

What does centered RMSProp center?

The optional centered form also keeps the gradient’s moving mean a, initialized to zero:

at=ρat−1+(1−ρ)gt,ut=vt−at2,θt=θt−1−ηgtut+ε.a_t=\rho a_{t-1}+(1-\rho)g_t,\qquad u_t=v_t-a_t^2,\qquad \theta_t=\theta_{t-1}-\frac{\eta g_t}{\sqrt{u_t}+\varepsilon}.

In exact arithmetic u is nonnegative for states generated by these recurrences. The weights can be interpreted as an exponentially weighted set of past gradients plus the remaining mass on an initial zero. This is not an unbiased sample variance, nor necessarily the variance of the current gradient distribution. We allow only consistent initial moments and clamp a tiny negative roundoff residual to zero.

Epsilon is added after the square root. With v=0.01 and ε=0.1, the reciprocal denominator is 5; placing ε inside the root gives about 3.015. Changing epsilon placement changes its units and the update.

Watch the statistics change during silent steps

This complete Python 3.12 standard-library program feeds gradients (4,0,0,1) into both variants, then actually fits f(θ)=(θ−1)²/2 with uncentered RMSProp. It keeps the same gradient sequence for the variant comparison so their different denominators can be inspected directly.

from math import sqrt,isfinite


def rms_step(theta,second,average,gradient,rate=.2,rho=.5,eps=.1,centered=False):
    values=(theta,second,average,gradient,rate,rho,eps)
    if not all(isfinite(v) and abs(v)<=1e6 for v in values):raise ValueError('finite bounded values required')
    if second<0 or second-average*average < -1e-10*max(1.,second):raise ValueError('inconsistent running moments')
    if not 0<=rho<1 or not 0<rate<=1 or not 0<eps<=1:raise ValueError('invalid smoothing, rate or epsilon')
    second=rho*second+(1-rho)*gradient*gradient
    average=rho*average+(1-rho)*gradient
    scale=max(0.,second-average*average) if centered else second
    theta-=rate*gradient/(sqrt(scale)+eps)
    return theta,second,average


def replay(gradients,centered=False):
    state=(0.,0.,0.);rows=[]
    for g in gradients:
        state=rms_step(*state,g,centered=centered);rows.append(state)
    return rows


if __name__=='__main__':
    gradients=(4.,0.,0.,1.)
    plain=replay(gradients);centered=replay(gradients,True)
    print('running second moments:',[r[1] for r in plain])
    print('running means:',[r[2] for r in plain])
    print('plain / centered final positions:',round(plain[-1][0],9),round(centered[-1][0],9))
    theta,second,average=0.,0.,0.
    for _ in range(12):theta,second,average=rms_step(theta,second,average,theta-1,rate=.1)
    print('fitted point / loss:',round(theta,9),round((theta-1)**2/2,9))
    print('epsilon outside / inside root:',round(1/(sqrt(.01)+.1),9),round(1/sqrt(.01+.1),9))

Actual output:

running second moments: [8.0, 4.0, 2.0, 1.5]
running means: [2.0, 1.0, 0.5, 0.75]
plain / centered final positions: -0.424156659 -0.568175203
fitted point / loss: 0.902377911 0.004765036
epsilon outside / inside root: 5.0 3.015113446

The second moments are 8,4,2,1.5. The moving means are 2,1,0.5,0.75; the final centered quantity is 1.5−0.75²=15/16. The two zero-gradient steps change the stored scales while leaving each parameter fixed.

The scalar fit evaluates a fresh gradient at each current parameter. It is separate from the prescribed-gradient audit and does not assume those four audit gradients come from this quadratic. A d-coordinate implementation costs O(d) per step and keeps O(d) extra scale state, plus another O(d) mean if centered; our saved trace is an optional diagnostic.

A responsive denominator can also become small

Forgetting can restore responsiveness after a large gradient, but it can also make later steps sensitive to a small denominator. Epsilon and the base rate remain part of the algorithm. A shorter memory is not automatically better for noisy or infrequent informative gradients.

The example excludes momentum, weight decay and sparse updates. Combining RMSProp with a momentum buffer introduces another state and can move a parameter even when its current gradient is zero. Centering can reduce the scale substantially when the recent gradients have a persistent mean; with ρ=0 it leaves zero centered scale and epsilon entirely controls the denominator.

Neither variant is a general nonconvex convergence guarantee. Reproducing a framework requires checking its initialization, centering, epsilon, dtype and skipped-gradient behavior; matching the name is insufficient.

Distinguish a raw moment from a variance

  1. What is v after gradients 4,0,0 with ρ=1/2?

Answer 1: 2, starting from zero.

  1. Do those zero gradients leave all optimizer state unchanged?

Answer 2: No. The moving statistics decay even though the no-momentum parameter update is zero.

  1. Is v itself a centered variance?

Answer 3: No. It averages squared gradients; the centered option subtracts the squared moving mean.

  1. Is epsilon inside or outside the square root in this implementation?

Answer 4: Outside. The program divides by sqrt(scale)+epsilon.

The next addition is a moving numerator

The lecture establishes recent squared-gradient scaling, while the fixed API specifies the centered variant. All traces and fitting experiments here are original. Continue with Adagrad and Adam, which also averages the gradient in its numerator.

Make a prediction, then check

What happens to the square average during an explicit zero-gradient step?

Choose one answer

Learning objectives

  • Derive the fading history and its half-life.
  • Distinguish raw second moment and centered scale.

Prerequisites & connections

Explore related knowledge →

References

  1. Neural Networks for Machine Learning — Lecture 6e: rmsprop
    Geoffrey Hinton; with Nitish Srivastava and Kevin Swersky · 2012
  2. RMSprop — PyTorch 2.8
    PyTorch contributors

Version1 · Editorial status: Recorded technical checks completed

View technical check record (AI)

Codex · 2026-09-06 · Codex single-agent authored technical review: cited primary-source scope, explicit assumptions, original calculations and counterexamples, runnable tests and bilingual review; not independent human or second-agent review.

  • Single-agent authored technical review: bounded primary-source locations, assumptions, original derivations, exact/literal references and matching bilingual equations/examples/exercises. Not independent human or second-agent review.
  • Four focused CPython3.12.4 tests passed per chapter. Adaptive accumulators and moments, coefficient/update ordering, checkpoint continuation and schedule boundaries are checked against expanded histories, exact products, literal values and known stability cases. Adagrad/Adam/AdamW use NumPy1.26.4; the other five use the standard library.
  • Promoted the full prose, equations, code and exercises. Tests read formal MDX only; removed temporary fallbacks/draft skips and updated review assertion to checked. Algorithm and independent references are unchanged; final record binds both locale hashes.
  • Publication navigation points published topics to complete articles and removes corresponding pending wording, retaining directory entries for unwritten targets. Principles, equations, programs and exercises are unchanged; final article SHA values rebound.

Source locations checked:

Related topics

No matches. Try a synonym or acronym.

0 results shown

Wrap the whole query in double quotes for a phrase match.