mojolearn.RMSprop#
- class mojolearn.RMSprop(params, lr=0.01, alpha=0.99, eps=1e-08, weight_decay=0.0, momentum=0.0, centered=False, numeric_mode=None)[source]#
Bases:
_SeqOptimizerRMSprop optimizer, as
torch.optim.RMSprop.Keeps a running average of squared gradients,
v = alpha * v + (1 - alpha) * g**2, and divides the gradient bysqrt(v) + eps. Withcentered=Truethe squared running mean of the gradient is subtracted fromv; withmomentum > 0a momentum buffer accumulates the scaled gradient. Defaults are torch’s.- Parameters:
params (ndarray or list of ndarray) – Parameters to update in place.
lr (float, default 1e-2) – Learning rate.
alpha (float, default 0.99) – Smoothing constant of the squared-gradient average.
eps (float, default 1e-8) – Term added to the denominator.
weight_decay (float, default 0.0) – L2 penalty added to the gradient.
momentum (float, default 0.0) – Momentum factor.
centered (bool, default False) – Normalize by the estimated gradient variance.
numeric_mode ({‘identical’, ‘deterministic’, ‘fast’} or None, default None) – Numeric mode of the update. None uses the library default.
- Variables:
t (int) – Number of steps taken.
square_avg (ndarray) – Running average of squared gradients, flat over all parameters.
Notes
paramsmust be C-contiguous float32 NumPy arrays, updated in place; anything else raisesTypeError.step(grads)takes one gradient per parameter, in the same order and shapes; float64 gradients raiseTypeError.lris read at every step, so you can changeopt.lrbetween steps, or setopt.lr_scheduleto a schedule (StepLR,ExponentialLR,OneCycleLR, or any object with a one-basedlr_at(t)), which setslrbefore each step.state_dict()andload_state_dict()save and restore the step count, learning rate and state buffers.Not supported: parameter groups,
maximize,foreach/fused/capturable/differentiable, sparse gradients and float64 parameters.Examples
>>> import numpy as np, mojolearn >>> w = np.zeros((64, 8), dtype=np.float32) >>> opt = mojolearn.RMSprop([w], lr=1e-2) >>> opt = opt.step([np.ones_like(w)])
- __init__(params, lr=0.01, alpha=0.99, eps=1e-08, weight_decay=0.0, momentum=0.0, centered=False, numeric_mode=None)[source]#
Methods
load_state_dict(sd)state_dict()step(grads)One update of every param from
grads(same shapes, same order).Attributes
resident_True once the state lives on the device.
Running average of squared gradients, flat over all parameters.
state- property square_avg#
Running average of squared gradients, flat over all parameters.