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 and follow it for two steps. The learning rate is , the decay is , and the gradients are and then . Start with and a running average .
- Measure the gradient. The first gradient is . Check: the gradient says the loss would fall if went down.
- Update the running average of squared gradients. Set . 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.
- Scale the step. Divide the gradient by , so the scaled gradient is . Multiply by the learning rate: the step is . Check: the step is about , not as plain gradient descent with the same learning rate would take.
- Move the parameter. Set . Check: the parameter moved down, the direction the gradient asked for.
- Second gradient. The gradient falls to . Update the average: . Check: the average remembers the big first gradient, so it decays only slowly.
- Scale the second step. , so the step is . 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 here.
- Move again. Set .
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 be the loss and the partial derivative of the loss with respect to at step , 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:
Here is the decay, a number between and close to ; a common default is . The new squared gradient gets the weight , and the old average keeps the weight . In the example, and .
Step 3 in symbols: the scaled step
Divide the gradient by the square root of the average, and multiply by the learning rate:
The small constant , often , stops the division from blowing up when is tiny. In the example is set to so the arithmetic stays clean; with 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 , the fraction stays near and the step is about . If the gradient is always about , the fraction also stays near . The scale of the gradient cancels out.
Step 4 in symbols: the first step is special
When , the first average is , so . The first step is therefore
With , , so the first step has size about no matter how large the gradient is. The example gave with , which matches. This early inflation is a known quirk of RMSProp; it fades as fills in.
Two parameters, one step
Take two parameters with gradients on the first step, and , . Then , whose square roots are . The steps are
The two parameters move by the same amount, although their gradients differ by a factor of eight.
Worked examples
Parameter , learning rate , decay , . The gradients are and .
- Step 1: .
- Step 1 size: .
- Set .
- Step 2: .
- Step 2 size: .
- Set .
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.
Two weights in a text model. The common-word weight has gradient on every step. The rare-word weight has gradient on every step. Use , , , and look at the first step.
- Common weight: , .
- Common weight step: .
- Rare weight: , .
- Rare weight step: .
Interpretation: under plain gradient descent the rare weight would move , two hundred times less than the common weight's . Under RMSProp both move . The rare word is no longer starved of updates.
A regression weight sees gradients that alternate between and , starting from , with , and . Compute the size of the second step, which is the first step where the running average has seen two different gradients.
- Step 1: , so and .
- Step 1 size: , moving the weight up.
- Step 2: , so and .
- Step 2 size: , 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 on the first step, with and . What is the step size? Answer: , , so the step is . It is the same as in example 2, because the first step always has size about .
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 times a number near 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 , 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 makes the first steps about times larger than when , 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 on its first step, with . What is ?Show answer
Use with . So . The average holds only a tenth of the new squared gradient, because .
QuestionWith , , and first gradient , what is the size of the first step?Show answer
The first step is . Since , the step is . Check with the general form .
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 , and its gradient on the next step is . With decay , give .Show answer
Use . 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 times a number that depends on the gradient history, not on the gradient itself. The step size per parameter is therefore roughly 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.