Skip to content
E
Educatum

RMSprop Optimizer

Curated by Educatum AI teamLast updated:
Basic Concepts
Direct Answer

RMSprop (Root Mean Square Propagation) is an adaptive gradient-based optimizer that normalizes each parameter's update by the root of an exponentially weighted moving average (EWMA) of its squared gradients. Unlike AdaGrad, whose monotonically growing gradient accumulation prematurely shrinks learning rates toward zero, RMSprop's moving average forgets distant history, dampening oscillations in steep directions while sustaining progress along flatter dimensions.

Study Card: RMSprop Optimizer

Direct Answer

RMSprop (Root Mean Square Propagation) is an adaptive per-parameter learning rate algorithm proposed by Tieleman and Hinton to improve stochastic gradient optimization across ill-conditioned loss surfaces. At iteration tt with gradient gt=∇θL(θt)g_t = \nabla_\theta \mathcal{L}(\theta_t), RMSprop maintains an exponentially weighted moving average vtv_t of squared gradients and scales updates element-wise:

vt=βvt−1+(1−β)gt2,θt+1=θt−ηvt+ϵ⊙gtv_t = \beta v_{t-1} + (1 - \beta) g_t^2, \qquad \theta_{t+1} = \theta_t - \frac{\eta}{\sqrt{v_t} + \epsilon} \odot g_t

where β∈[0,1)\beta \in [0, 1) is the decay factor (typically 0.9 or 0.99), η\eta is the base learning rate, and ϵ\epsilon (e.g., 1e-8) prevents division by zero.

Dividing by the recent root-mean-square gradient vt\sqrt{v_t} dampens oscillations along steep, high-curvature coordinates while taking relatively larger steps along gentle, flat directions. Crucially, unlike AdaGrad—which sums all past squared gradients so step sizes decay monotonically toward zero—RMSprop’s EWMA adapts smoothly to local curvature in non-convex deep learning landscapes.

Key Terms

  • Exponentially Weighted Moving Average (EWMA): Running average vt=βvt−1+(1−β)gt2v_t = \beta v_{t-1} + (1-\beta)g_t^2 emphasizing recent gradient magnitudes and decaying older history geometrically.
  • Per-Parameter Scaling: Dividing each coordinate’s gradient by its own vt+ϵ\sqrt{v_t} + \epsilon, giving every weight an adaptive effective step size.
  • Learning Rate (η\eta): Base step size scaling the normalized gradient updates.
  • Decay Rate (β\beta): Controls the memory window of past squared gradients (higher β\beta smooths across more steps).

Example

Suppose one parameter consistently experiences large oscillating gradients (g2≈100g^2 \approx 100) while another weight has consistently gentle gradients (g2≈0.01g^2 \approx 0.01). Plain SGD with a single learning rate either diverges along the steep coordinate or crawls along the flat one. RMSprop divides the first parameter’s update by vt≈10\sqrt{v_t} \approx 10 and the second parameter’s update by vt≈0.1\sqrt{v_t} \approx 0.1, keeping step magnitudes balanced across axes—and because vtv_t is a moving average rather than an unbounded cumulative sum, effective step sizes remain active throughout long training runs.

Code Implementation

import numpy as np

def rmsprop(weights, gradients, learning_rate=0.001, decay_rate=0.9, epsilon=1e-8, squared_grad_avg=None):
    """
    Single step of RMSprop optimization.

    Args:
        weights (np.ndarray): Current model parameters.
        gradients (np.ndarray): Loss gradients with respect to weights.
        learning_rate (float): Base learning rate.
        decay_rate (float): EWMA decay rate (beta).
        epsilon (float): Numerical stability constant.
        squared_grad_avg (np.ndarray or None): Previous EWMA of squared gradients.

    Returns:
        updated_weights, updated_squared_grad_avg
    """
    if squared_grad_avg is None:
        squared_grad_avg = np.zeros_like(weights)

    # Update moving average of squared gradients
    squared_grad_avg = decay_rate * squared_grad_avg + (1.0 - decay_rate) * (gradients ** 2)

    # Normalize gradient update per coordinate
    scaled_gradients = gradients / (np.sqrt(squared_grad_avg) + epsilon)
    updated_weights = weights - learning_rate * scaled_gradients

    return updated_weights, squared_grad_avg

# Sample usage
weights = np.array([0.5, -0.2, 0.1])
gradients = np.array([0.1, -0.05, 0.02])
squared_grad_avg = None

for i in range(5):
    weights, squared_grad_avg = rmsprop(
        weights, gradients, learning_rate=0.1, squared_grad_avg=squared_grad_avg
    )
    print(f"Step {i + 1}: Weights = {weights}")
  • AdaGrad vs. RMSprop vs. Adam: AdaGrad accumulates all historical squared gradients without decay (useful for sparse features, stalls on deep non-convex tasks); RMSprop replaces the sum with an EWMA; Adam combines RMSprop’s second-moment scaling with first-moment momentum and initial bias correction.
  • Momentum with RMSprop: torch.optim.RMSprop(..., momentum=0.9) adds heavy-ball momentum on top of RMSprop normalization to smooth step trajectories further.
  • Hyperparameter Tuning: Learning rate η\eta, decay β\beta, and ϵ\epsilon all affect convergence; ϵ\epsilon (sometimes set larger, e.g., 1e-5 in some settings) prevents overly aggressive steps when gradients are tiny.
  • Generalization vs. SGD+Momentum: Adaptive methods like RMSprop and Adam converge rapidly, though carefully tuned SGD with momentum and cosine decay remains competitive on certain vision benchmarks.
View all →

Try keywords like RoPE, FlashAttention, DPO, or Blind 75.