
Source: RMSprop |Cloudfactory
Introduction
RMSProp (Root Mean Square Propagation) is an adaptive learning rate optimization algorithm proposed by Geoffrey Hinton. It is designed to address the problems of non-stationary objectives and oscillations in steep dimensions during training, which often occur with standard gradient descent.
RMSProp adapts the learning rate for each parameter individually by dividing the gradient by a moving average of the magnitude of recent gradients, making it well-suited for training deep neural networks and non-convex problems like RNNs.
How RMSProp Works
RMSProp improves upon AdaGrad by introducing an exponentially decaying average of past squared gradients, rather than accumulating all of them. This allows the optimizer to forget distant past gradients and focus more on recent updates, making it well-suited for non-convex optimization problems like training deep neural networks.
The update rule is as follows:
Where:
- $\theta$: model parameters
- $g_t$: gradient at time step $t$
- $E[g^2]_t$: exponentially weighted moving average of squared gradients
- $\gamma$: decay rate (e.g., 0.9), controlling how much past gradients influence the average
- $\eta$: global learning rate
- $\epsilon$: small constant (e.g., $1e^{-8}$) to avoid division by zero
Intuition Behind RMSProp
When optimizing a loss surface, it’s common to encounter directions where the slope is much steeper (e.g., parameter $b$) compared to others (e.g., parameter $w$). Standard SGD takes similarly-sized steps in all directions, which can lead to oscillations in steep areas and slow progress in flat ones.
RMSProp addresses this by applying an adaptive learning rate to each parameter, using an exponentially decaying average of the squared gradients: $ E[g^2]t = \gamma \cdot E[g^2]{t-1} + (1 – \gamma) \cdot g_t^2 $. This formula keeps a running average of the recent squared gradients:
- Recent gradients have higher weight
- Older gradients fade away exponentially (controlled by the decay rate $\gamma$, typically 0.9)
This allows RMSProp to:
- Respond quickly to recent changes in the gradient direction
- Forget outdated history that might no longer be relevant
The learning rate for each parameter is then scaled inversely by the square root of this moving average:
What does this achieve?
- In directions with large recent gradients, $E[g^2]_t$ becomes large → smaller step size
- In directions with small or stable gradients, $E[g^2]_t$ remains small → larger step size
As a result, it gets:
- Faster convergence in flat regions
- Smoothed updates in noisy or sharp regions
- Particularly effective for non-convex problems like training deep or recurrent networks
Difference Between AdaGrad and RMSProp
Both algorithms adapt the learning rate based on gradient history, but they differ in how that history is maintained:
- AdaGrad accumulates all past squared gradients:
Issue: The accumulated $G_t$ grows without bound, causing learning rates to become excessively small over time.
- RMSProp uses an exponentially decaying average:
Benefit: By forgetting older gradients, RMSProp maintains a more stable and effective learning rate, making it better suited for deep learning and non-convex optimization problems.
Code Example
This code snippet demonstrates how to apply RMSProp to train a simple neural network in PyTorch. The model consists of two linear layers with a ReLU activation in between. The optimizer is configured with a learning rate of 0.01, a decay rate (alpha) of 0.9 for the moving average of squared gradients, and a small constant eps to ensure numerical stability.
import torch
import torch.nn as nn
import torch.optim as optim
# Simple neural network
model = nn.Sequential(
nn.Linear(784, 128),
nn.ReLU(),
nn.Linear(128, 10)
)
# Loss function
criterion = nn.CrossEntropyLoss()
# Optimizer using RMSProp
optimizer = optim.RMSprop(model.parameters(), lr=0.01, alpha=0.9, eps=1e-8)
# Dummy input and target
x = torch.randn(64, 784) # batch of 64 samples
y = torch.randint(0, 10, (64,)) # random targets
# Training step
optimizer.zero_grad()
output = model(x)
loss = criterion(output, y)
loss.backward()
optimizer.step()Advantages of RMSProp
RMSProp performs well in online learning and non-stationary settings by adapting the learning rate for each parameter individually. It helps dampen oscillations along steep directions and can converge faster than standard SGD in complex landscapes. RMSProp is particularly effective in training RNNs, where traditional optimizers struggle.
Disadvantages of RMSProp
While RMSProp adapts well to many scenarios, it still introduces extra hyperparameters (like $\gamma$ and $\epsilon$) that must be tuned carefully. It may also plateau or become unstable in some cases without careful learning rate scheduling. RMSProp does not use momentum by default (though PyTorch supports a version with it), so it might underperform in tasks that benefit from accumulated gradients.
Video Explanation
- In this lecture video, Neil Rhodes provides a detailed explanation of the RMSProp optimization algorithm (Runtime: 10 mins)
- The video by Andrew Ng provides a clear explanation of RMSProp, illustrating how it adaptively scales learning rates using an exponentially decaying average of squared gradients (Runtime: 7 mins)
Related Questions:

