RMSprop optimiser — gradient normalisation by EMA of squared magnitude, with optional centring and Polyak-style momentum.
The plain rule replaces Adagrad's monotonic accumulator with an exponential moving average, so the effective learning rate stops shrinking and tracks the current gradient regime instead.
Math
Uncentred:
Centred — subtract the squared mean to recover the true variance:
With momentum the normalised gradient is folded into a velocity buffer first:
References
Tieleman & Hinton, "Lecture 6.5 — RMSProp" (Coursera 2012).
See Also
Adadelta, Adagrad, Rprop
Parameters
paramsvector of TensorImpllrfloat, default 1e-2alphafloat, default 0.99epsfloat, default 1e-8weight_ decayfloat, default 0.0momentumfloat, default 0.0centeredbool, default falseAttributes
square_ avg_vector of Storagegrad_ avg_vector of Storagecentered == true).moment_ buf_vector of Storagemomentum != 0).Notes
State buffers are allocated lazily — code that only ever uses the plain variant does not pay the memory cost of the centred or momentum-augmented variants.
Constructors
1Construct the optimiser and resize per-slot state vectors.
Parameters
paramsvector of TensorImpllrfloat, default 1e-2alphafloat, default 0.99epsfloat, default 1e-8weight_ decayfloat, default 0.0momentumfloat, default 0.0centeredbool, default falseStatic methods
1check_hyperparams
void check_hyperparams(double lr, double alpha, double eps, double weight_decay, double momentum)Check RMSprop's hyper-parameters — the reference framework's constructor checks, run by the constructor and set_hyperparams.
Raises
InvalidArgumentlr, alpha, eps, weight_decay or momentum is negative or NaN.Virtual methods
2Methods
5Allocate per-slot state buffers for parameter i.
Parameters
iintNotes
square_avg_[i] is always allocated. grad_avg_[i] is
allocated only when centered_ is true and moment_buf_[i]
only when momentum_ is non-zero — see Attributes on
RMSprop.
set_hyperparams
void set_hyperparams(double lr, double alpha, double eps, double weight_decay, double momentum, bool centered)Replace the hyper-parameters between steps; nothing is applied when check_hyperparams rejects them.
Notes
Switching on centered or momentum gives each slot that holds state
a zero grad_avg / momentum buffer, as a fresh optimizer built with
the feature on would start from. Switching one off keeps the buffer,
so switching it on again resumes it, as the reference framework's
state does.
Return the versioned state-dict identifier.
Returns
str"rmsprop_v1".
Apply one RMSprop update to parameter i.
Parameters
iintgStoragep on this step.Notes
Dispatches to a fused MLX kernel on GPU and a scalar Accelerate loop on CPU; the four variant combinations (plain / centred / momentum / both) share a single branchy path that elides the unused buffer reads.