Search

Search papers and lessons

RMSProp

Level 2 · 12 min read

RMSProp divides each parameter's gradient step by a running average of its recent gradient sizes, so every parameter moves at a similar pace even when their gradients differ widely.

On this page

  • Colour = topic mix
  • Discrete math
  • Calculus
  • Probability
  • Optimizers
  • Linear algebra
  • Losses & regularization
  • ReadReady to readNot yet

TL;DR

Gradient descent moves each parameter by the learning rate times its gradient, so a parameter with large gradients takes large steps and one with small gradients crawls. RMSProp keeps a running average of the squared gradients for each parameter and divides the step by its square root. Parameters with consistently large gradients get smaller steps, and parameters with small gradients get relatively larger ones.

Builds on: Stochastic Gradient Descent, Exponential Moving Average, Learning Rate · Leads to: asynchronous actor-critic training and the Adam family of optimisers

Where it's used

Training recurrent networks. In recurrent networks, the gradients for different weights can differ widely in size. RMSProp was a common choice for these models because it kept every weight moving at a reasonable pace without a hand-tuned learning rate for each one.

Reinforcement learning. The asynchronous actor-critic method, used in several reinforcement learning agents that play games, ran many workers that each computed noisy gradients. RMSProp was used with a shared running average, so the noisy and unusually large gradients from one worker did not make the step size jump.

A default for many deep networks. Before Adam became the usual default, RMSProp was one of the first methods practitioners tried for image models. It still appears in older codebases and in some reinforcement learning libraries, because it is simple and needs only one extra number per parameter.

How it works

Take one parameter θ\theta and follow it for two steps. The learning rate is η=0.1\eta = 0.1, the decay is β=0.9\beta = 0.9, and the gradients are g1=10g_1 = 10 and then g2=1g_2 = 1. Start with θ=0\theta = 0 and a running average v=0v = 0.

  1. Measure the gradient. The first gradient is g1=10g_1 = 10. Check: the gradient says the loss would fall if θ\theta went down.
  2. Update the running average of squared gradients. Set v1=0.9⋅0+0.1⋅102=10v_1 = 0.9 \cdot 0 + 0.1 \cdot 10^2 = 10. Check: the average is a weighted mix of the old average and the new squared gradient, so it stays a positive number near the typical squared gradient.
  3. Scale the step. Divide the gradient by v1=10≈3.162\sqrt{v_1} = \sqrt{10} \approx 3.162, so the scaled gradient is 10/3.162≈3.16210 / 3.162 \approx 3.162. Multiply by the learning rate: the step is 0.1×3.162≈0.3160.1 \times 3.162 \approx 0.316. Check: the step is about 0.3160.316, not 1.01.0 as plain gradient descent with the same learning rate would take.
  4. Move the parameter. Set θ1=0−0.316=−0.316\theta_1 = 0 - 0.316 = -0.316. Check: the parameter moved down, the direction the gradient asked for.
  5. Second gradient. The gradient falls to g2=1g_2 = 1. Update the average: v2=0.9⋅10+0.1⋅1=9.1v_2 = 0.9 \cdot 10 + 0.1 \cdot 1 = 9.1. Check: the average remembers the big first gradient, so it decays only slowly.
  6. Scale the second step. 9.1≈3.017\sqrt{9.1} \approx 3.017, so the step is 0.1×1/3.017≈0.0330.1 \times 1 / 3.017 \approx 0.033. Check: a gradient one-tenth the size of the first produces a step about one-tenth the size, because the average is still large. Plain gradient descent would have taken a step of 0.10.1 here.
  7. Move again. Set θ2=−0.316−0.033=−0.349\theta_2 = -0.316 - 0.033 = -0.349.

The pattern is the point. The running average changes slowly, so the scaling does not jump from step to step.

flowchart LR
  A["Gradient g_t"] --> B["Average: v_t = 0.9 v_prev + 0.1 g_t^2"]
  B --> C["Step: eta g_t / sqrt(v_t)"]
  C --> D["Move: theta_t = theta_prev - step"]
  D -->|next step| A

The math

Step 1 in symbols: the gradient

Let L(θ)L(\theta) be the loss and gt=∇θL(θt)g_t = \nabla_\theta L(\theta_t) the partial derivative of the loss with respect to θ\theta at step tt, computed on one example or a small batch as in stochastic gradient descent.

Step 2 in symbols: the running average

Keep, for each parameter, an exponential moving average of the squared gradient:

vt=β vt−1+(1−β) gt2,v0=0.v_t = \beta\, v_{t-1} + (1 - \beta)\, g_t^2, \qquad v_0 = 0.

Here β\beta is the decay, a number between 00 and 11 close to 11; a common default is 0.90.9. The new squared gradient gets the weight 1−β1 - \beta, and the old average keeps the weight β\beta. In the example, v1=0.9⋅0+0.1⋅100=10v_1 = 0.9 \cdot 0 + 0.1 \cdot 100 = 10 and v2=0.9⋅10+0.1⋅1=9.1v_2 = 0.9 \cdot 10 + 0.1 \cdot 1 = 9.1.

Step 3 in symbols: the scaled step

Divide the gradient by the square root of the average, and multiply by the learning rate:

θt=θt−1−η gtvt+ε.\theta_{t} = \theta_{t-1} - \eta \, \frac{g_t}{\sqrt{v_t} + \varepsilon}.

The small constant ε\varepsilon, often 10−810^{-8}, stops the division from blowing up when vtv_t is tiny. In the example ε\varepsilon is set to 00 so the arithmetic stays clean; with ε=10−8\varepsilon = 10^{-8} the results change only in the eighth decimal place.

Read the fraction as "gradient divided by typical gradient size". If the gradient is always about 55, the fraction stays near ±1\pm 1 and the step is about η\eta. If the gradient is always about 0.050.05, the fraction also stays near ±1\pm 1. The scale of the gradient cancels out.

Step 4 in symbols: the first step is special

When v0=0v_0 = 0, the first average is v1=(1−β)g12v_1 = (1 - \beta) g_1^2, so v1=1−β ∣g1∣\sqrt{v_1} = \sqrt{1 - \beta}\,|g_1|. The first step is therefore

Δθ1=−η g11−β ∣g1∣=−η1−βsign⁡(g1).\Delta\theta_1 = -\eta \, \frac{g_1}{\sqrt{1 - \beta}\,|g_1|} = -\frac{\eta}{\sqrt{1 - \beta}} \operatorname{sign}(g_1).

With β=0.9\beta = 0.9, 10.1≈3.162\dfrac{1}{\sqrt{0.1}} \approx 3.162, so the first step has size about 3.16 η3.16\,\eta no matter how large the gradient is. The example gave 0.3160.316 with η=0.1\eta = 0.1, which matches. This early inflation is a known quirk of RMSProp; it fades as vtv_t fills in.

Two parameters, one step

Take two parameters with gradients g=(4,0.5)g = (4, 0.5) on the first step, and η=0.01\eta = 0.01, β=0.9\beta = 0.9. Then v1=(0.1⋅16,0.1⋅0.25)=(1.6,0.025)v_1 = (0.1 \cdot 16, 0.1 \cdot 0.25) = (1.6, 0.025), whose square roots are (1.265,0.158)(1.265, 0.158). The steps are

Δθ=−0.01⋅(41.265,0.50.158)=−0.01⋅(3.162,3.162)=(−0.0316,−0.0316).\Delta\theta = -0.01 \cdot \left(\frac{4}{1.265}, \frac{0.5}{0.158}\right) = -0.01 \cdot (3.162, 3.162) = (-0.0316, -0.0316).

The two parameters move by the same amount, although their gradients differ by a factor of eight.

Worked examples

Example
1. A single parameter with a shrinking gradient

Parameter θ\theta, learning rate η=0.1\eta = 0.1, decay β=0.9\beta = 0.9, ε=0\varepsilon = 0. The gradients are g1=10g_1 = 10 and g2=1g_2 = 1.

  1. Step 1: v1=0.9⋅0+0.1⋅102=10v_1 = 0.9 \cdot 0 + 0.1 \cdot 10^2 = 10.
  2. Step 1 size: η⋅g1/v1=0.1⋅10/3.1623=0.3162\eta \cdot g_1 / \sqrt{v_1} = 0.1 \cdot 10 / 3.1623 = 0.3162.
  3. Set θ1=0−0.3162=−0.3162\theta_1 = 0 - 0.3162 = -0.3162.
  4. Step 2: v2=0.9⋅10+0.1⋅1=9.1v_2 = 0.9 \cdot 10 + 0.1 \cdot 1 = 9.1.
  5. Step 2 size: η⋅g2/v2=0.1⋅1/3.0166=0.0332\eta \cdot g_2 / \sqrt{v_2} = 0.1 \cdot 1 / 3.0166 = 0.0332.
  6. Set θ2=−0.3162−0.0332=−0.3494\theta_2 = -0.3162 - 0.0332 = -0.3494.

Interpretation: the second gradient is one-tenth of the first, but the step is only about one-tenth of the first step, not one-tenth of what plain gradient descent would take. The big earlier gradient keeps the average high for a while, which damps the step.

Example
2. Two parameters, one common and one rare

Two weights in a text model. The common-word weight has gradient 22 on every step. The rare-word weight has gradient 0.010.01 on every step. Use η=0.001\eta = 0.001, β=0.9\beta = 0.9, ε=0\varepsilon = 0, and look at the first step.

  1. Common weight: v=0.1⋅22=0.4v = 0.1 \cdot 2^2 = 0.4, 0.4=0.6325\sqrt{0.4} = 0.6325.
  2. Common weight step: 0.001⋅2/0.6325=0.003160.001 \cdot 2 / 0.6325 = 0.00316.
  3. Rare weight: v=0.1⋅0.012=0.00001v = 0.1 \cdot 0.01^2 = 0.00001, 0.00001=0.00316\sqrt{0.00001} = 0.00316.
  4. Rare weight step: 0.001⋅0.01/0.00316=0.003160.001 \cdot 0.01 / 0.00316 = 0.00316.

Interpretation: under plain gradient descent the rare weight would move 0.001⋅0.01=0.000010.001 \cdot 0.01 = 0.00001, two hundred times less than the common weight's 0.0020.002. Under RMSProp both move 0.003160.00316. The rare word is no longer starved of updates.

Example
3. A realistic check on a noisy gradient

A regression weight sees gradients that alternate between +4+4 and −4-4, starting from v=0v = 0, with η=0.001\eta = 0.001, β=0.9\beta = 0.9 and ε=10−8\varepsilon = 10^{-8}. Compute the size of the second step, which is the first step where the running average has seen two different gradients.

  1. Step 1: g1=+4g_1 = +4, so v1=0.1⋅16=1.6v_1 = 0.1 \cdot 16 = 1.6 and v1=1.2649\sqrt{v_1} = 1.2649.
  2. Step 1 size: 0.001⋅4/(1.2649+10−8)≈0.003160.001 \cdot 4 / (1.2649 + 10^{-8}) \approx 0.00316, moving the weight up.
  3. Step 2: g2=−4g_2 = -4, so v2=0.9⋅1.6+0.1⋅16=1.44+1.6=3.04v_2 = 0.9 \cdot 1.6 + 0.1 \cdot 16 = 1.44 + 1.6 = 3.04 and v2=1.7436\sqrt{v_2} = 1.7436.
  4. Step 2 size: 0.001⋅(−4)/1.7436≈−0.002290.001 \cdot (-4) / 1.7436 \approx -0.00229, moving the weight down by less than the first step.

Interpretation: the average keeps growing while the gradient swings, so the steps shrink. The swings partly cancel in the weight's path, and the scaled steps keep the update from overshooting by the full learning rate each time.

Try it: a weight's gradient is 0.50.5 on the first step, with η=0.001\eta = 0.001 and β=0.9\beta = 0.9. What is the step size? Answer: v1=0.1⋅0.25=0.025v_1 = 0.1 \cdot 0.25 = 0.025, 0.025=0.1581\sqrt{0.025} = 0.1581, so the step is 0.001⋅0.5/0.1581=0.003160.001 \cdot 0.5 / 0.1581 = 0.00316. It is the same as in example 2, because the first step always has size about η/1−β\eta / \sqrt{1 - \beta}.

Common mistakes and tradeoffs

It is tempting to think RMSProp makes the learning rate irrelevant. In fact the learning rate still sets the size of each step, roughly η\eta times a number near 11 per parameter. A learning rate that is too large still overshoots, so you still tune it.

It is tempting to think a small gradient always means a small step. In fact the step is scaled by the parameter's own history. A parameter with consistently small gradients takes steps of about η\eta, which can be larger than plain gradient descent takes. That is the intended effect, but it can also amplify noise in parameters whose gradients are mostly noise.

It is tempting to think the first steps are reliable. In fact v0=0v_0 = 0 makes the first steps about 33 times larger than η\eta when β=0.9\beta = 0.9, as shown above. Some implementations warm up the learning rate for this reason. Adam adds a bias correction for the same problem.

When to use it. Use RMSProp when gradients for different parameters have very different sizes, when the problem is non-stationary, or in reinforcement learning where gradients are noisy. It needs only one extra number per parameter.

When not to use it. Do not use it when you need a method with well-studied defaults that work across many tasks; Adam is usually easier. Do not use it when you need the exact step rules of plain gradient descent, for example in theory that assumes a fixed step size.

Alternatives. Momentum smooths the direction of the steps rather than their size. AdaGrad uses the total sum of squared gradients instead of a decaying average, so its steps keep shrinking over training.

History

Gradient descent and its stochastic version were old tools in optimisation by the time neural networks were trained with them. By the early 2010s, practitioners had a problem: a single global learning rate suited some weights and broke others. AdaGrad, published by Duchi, Hazan and Singer in 2011, scaled each parameter's step by the square root of its accumulated squared gradients. It worked well for sparse features, but the accumulated sum grew forever, so steps eventually became tiny.

Geoffrey Hinton proposed RMSProp in 2012 in a lecture of his online neural networks course, as a fix: replace the sum with a decaying average, so the scale can recover. The method was never published as a paper, and it spread through lecture notes and code. Its success in training deep networks helped motivate Adam in 2014, which combines it with momentum and bias correction.

Recap

  • Each parameter has its own running average of squared gradients, updated with an exponential moving average.
  • The step is the learning rate times the gradient divided by the square root of that average.
  • The effect is that each parameter moves at a similar pace, whatever the size of its own gradients.
  • Early steps are inflated when the average starts at zero, which is the reason for warm-up and bias correction.
  • Next, read momentum to see how the direction of steps can be smoothed, then the A3C paper to see RMSProp in an asynchronous reinforcement learning setting.

Check yourself

QuestionA parameter has gradient g1=4g_1 = 4 on its first step, with β=0.9\beta = 0.9. What is v1v_1?Show answer

Use v1=βv0+(1−β)g12v_1 = \beta v_0 + (1 - \beta) g_1^2 with v0=0v_0 = 0. So v1=0.1⋅16=1.6v_1 = 0.1 \cdot 16 = 1.6. The average holds only a tenth of the new squared gradient, because 1−β=0.11 - \beta = 0.1.

QuestionWith η=0.01\eta = 0.01, β=0.9\beta = 0.9, ε=0\varepsilon = 0 and first gradient g1=4g_1 = 4, what is the size of the first step?Show answer

The first step is ηg1/v1=0.01⋅4/1.6\eta g_1 / \sqrt{v_1} = 0.01 \cdot 4 / \sqrt{1.6}. Since 1.6≈1.265\sqrt{1.6} \approx 1.265, the step is 0.04/1.265≈0.03160.04 / 1.265 \approx 0.0316. Check with the general form η/1−β=0.01/0.3162≈0.0316\eta / \sqrt{1 - \beta} = 0.01 / 0.3162 \approx 0.0316.

QuestionWhy does RMSProp move a rare feature, with tiny gradients, as far as a common feature with large gradients?Show answer

Each parameter's step is its gradient divided by its own typical gradient size. For the rare feature the typical size is small, so the division scales its tiny gradient up to about the same size as the common feature's scaled gradient. Plain gradient descent does not do this, so the rare feature moves much less.

QuestionA weight's running average is vt=0.4v_t = 0.4, and its gradient on the next step is 0.20.2. With decay β=0.9\beta = 0.9, give vt+1v_{t+1}.Show answer

Use vt+1=0.9⋅0.4+0.1⋅0.22=0.36+0.1⋅0.04=0.36+0.004=0.364v_{t+1} = 0.9 \cdot 0.4 + 0.1 \cdot 0.2^2 = 0.36 + 0.1 \cdot 0.04 = 0.36 + 0.004 = 0.364. The old average gets most of the weight, so a small new gradient barely changes it.

QuestionWhy might a learning rate that works for plain gradient descent need retuning before RMSProp?Show answer

Because RMSProp's step is about η\eta times a number that depends on the gradient history, not on the gradient itself. The step size per parameter is therefore roughly η\eta in magnitude, while plain gradient descent takes steps proportional to the gradient. A learning rate chosen for large gradients can give too-large steps under RMSProp, and one chosen for small gradients can give too-small steps.

Sources