Skip to content
class

RAdam

extendsOptimizer
RAdam

RAdam optimiser — Rectified Adam (Liu et al., 2019).

Computes a variance-based rectification factor rtr_t derived from the simple moving average length ρt\rho_t. When ρt\rho_t exceeds a threshold (the paper uses 55) the adaptive learning rate is well-conditioned and we apply the standard bias-corrected Adam step scaled by rtr_t; otherwise we fall back to a plain momentum step using only m^t\hat m_t, which avoids the early-training divergence caused by an under-sampled second moment.

Math

ρ∞=21−β2−1,ρt=ρ∞−2t β2t1−β2t \rho_\infty = \frac{2}{1 - \beta_2} - 1, \qquad \rho_t = \rho_\infty - \frac{2 t\, \beta_2^t}{1 - \beta_2^t}

If ρt>5\rho_t > 5:

rt=(ρt−4)(ρt−2) ρ∞(ρ∞−4)(ρ∞−2) ρt r_t = \sqrt{ \frac{(\rho_t - 4)(\rho_t - 2)\,\rho_\infty} {(\rho_\infty - 4)(\rho_\infty - 2)\,\rho_t} } θt+1=θt−η rt⋅m^tv^t+ϵ \theta_{t+1} = \theta_t - \eta\, r_t \cdot \frac{\hat m_t}{\sqrt{\hat v_t} + \epsilon}

otherwise (fallback to plain momentum):

θt+1=θt−η m^t \theta_{t+1} = \theta_t - \eta\, \hat m_t

References

Liu, Jiang, He, Chen, Liu, Gao & Han, "On the Variance of the Adaptive Learning Rate and Beyond" (ICLR 2020, arXiv 2019).

See Also

Adam, AdamW, NAdam.

Attributes

lr_float
Step size η\eta. Default 1e-3.
beta1_, beta2_, eps_, weight_decay_float
As in Adam.
m_, v_Storage[]
Per-parameter first- and second-moment buffers.

Notes

ρt\rho_t and rtr_t depend only on tt (the parameter's own update count) and β2\beta_2, so they are computed once per parameter outside the element loop. Weight decay (if non-zero) is added to gtg_t in the standard L2 form.

Constructors

1
ctor

RAdam

void RAdam(int)

Construct an RAdam optimiser bound to params.

Parameters

paramsvector of TensorImpl shared pointers
Parameters to optimise.
lrfloat= None
Step size η\eta. Default 1e-3.
beta1, beta2float= None
EMA decay rates. Defaults 0.9 / 0.999.
epsfloat= None
Denominator stabiliser. Default 1e-8.
weight_decayfloat= None
L2 penalty coefficient. Default 0.

Static methods

1
static

check_hyperparams

void check_hyperparams(double lr, double beta1, double beta2, double eps, double weight_decay)

Check RAdam's hyper-parameters — the reference framework's constructor checks, run by the constructor and set_hyperparams.

Raises

InvalidArgument
If lr, eps or weight_decay is negative or NaN, or a beta lies outside [0, 1).

Virtual methods

2
virtconst

lr

double lr()

Current learning rate η\eta.

virt

set_lr

void set_lr(double lr)

Set the learning rate.

Methods

5
fn

init_state_slot

void init_state_slot(int i, const int & p)

Allocate zero-initialised mm and vv buffers for this slot.

fn

set_hyperparams

void set_hyperparams(double lr, double beta1, double beta2, double eps, double weight_decay)

Replace the hyper-parameters between steps; nothing is applied when check_hyperparams rejects them.

fnconst

state_dict_id

→str
int state_dict_id()

Schema identifier for state_dict serialisation.

Returns

str

"radam_v1".

fn

update_one

void update_one(int i, int & p, const int & g)

Compute ρt\rho_t and rtr_t; apply the rectified adaptive update when ρt>5\rho_t > 5, else fall back to a plain momentum update.

Parameters

isize_t
Slot index into m_ / v_.
pTensorImpl shared pointer
In-place parameter.
gStorage
Gradient gtg_t.