Adaptive per-parameter updates
Training models whose gradient scales vary substantially across parameters.
PyTorch · Class
RMSprop is a PyTorch optimizer that scales parameter updates using a moving average of squared gradients. It also supports momentum, weight decay, centered normalization, graph capture, maximization, and differentiable optimization steps.
RMSprop maintains a moving average of squared gradients and uses it to scale each parameter’s update. Optional momentum, weight decay, and centered variance normalization modify that update; maximize reverses the optimization direction, while differentiable enables autograd through the step.
class torch.optim.RMSprop(params, lr=0.01, alpha=0.99, eps=1e-08, weight_decay=0, momentum=0, centered=False, capturable=False, foreach=None, maximize=False, differentiable=False)| Name | Type | Description |
|---|---|---|
params | iterable | Iterable of parameters, named parameters, or parameter-group dictionaries to optimize. |
lr | float or Tensor, optional | Learning rate; default 0.01. |
alpha | float, optional | Smoothing constant; default 0.99. |
eps | float, optional | Denominator stabilizer; default 1e-8. |
weight_decay | float, optional | L2 penalty; default 0. |
momentum | float, optional | Momentum factor; default 0. |
centered | bool, optional | Whether to use centered RMSprop. |
capturable | bool, optional | Whether the optimizer is safe for graph capture, including CUDA graphs or torch.compile. |
foreach | bool, optional | Whether to use the foreach implementation when available. |
maximize | bool, optional | Whether to maximize the objective instead of minimize it. |
differentiable | bool, optional | Whether to record the optimizer step through autograd. |
An RMSprop optimizer object that stores optimizer state and updates the supplied parameters.
import torch
model = torch.nn.Linear(10, 1)
optimizer = torch.optim.RMSprop(model.parameters(), lr=1e-3)
x = torch.randn(8, 10)
y = torch.randn(8, 1)
loss = torch.nn.functional.mse_loss(model(x), y)
optimizer.zero_grad()
loss.backward()
optimizer.step()Creates an RMSprop optimizer for a linear model and performs one standard gradient-update step.
Training models whose gradient scales vary substantially across parameters.
Optimizing objectives with recurrent or non-stationary gradient behavior.
Running optimizer steps inside CUDA graphs or torch.compile workflows.
Learning optimization policies or other procedures requiring gradients through updates.
RMSprop adapts parameter updates using a weighted moving average of squared gradients. Its effective learning rate is the scheduled learning rate divided by the square root of that average plus epsilon.
Follow-up: How does centered RMSprop differ? It also tracks an average gradient and normalizes using an estimate of gradient variance rather than only the second-moment average.
The smoothing constant alpha controls the moving average of squared gradients, with a default of 0.99. Epsilon is added to the denominator for numerical stability, and its default is 1e-8.
Follow-up: What happens if epsilon is changed? It changes the denominator’s stabilizing offset and therefore can affect updates, especially when the running average is very small.
The optimizer accepts parameters or parameter groups and supports options including learning rate, weight decay, momentum, centered, capturable, foreach, maximize, and differentiable. The default learning rate is 1e-2.
Follow-up: When would differentiable be relevant? Use it when the optimizer step itself must participate in autograd, such as differentiating through an optimization procedure.
torch.optim.Optimizertorch.optim.SGDtorch.optim.Adagradtorch.optim.Adamtorch.optim.AdamWtorch.optim.lr_scheduler