Skip to content
class

Adamax

extendsOptimizer
Adamax

Adamax optimiser — Adam variant using the infinity norm.

Replaces Adam's ℓ2\ell_2 second-moment estimate with an exponentially decayed running maximum, giving a bounded effective step size that is well-behaved when occasional gradient components are very large.

Math

mt+1=β1mt+(1−β1)gt m_{t+1} = \beta_1 m_t + (1 - \beta_1) g_t ut+1=max⁡(β2ut,  ∣gt∣+ϵ) u_{t+1} = \max(\beta_2 u_t,\; |g_t| + \epsilon) θt+1=θt−η1−β1t+1⋅mt+1ut+1 \theta_{t+1} = \theta_t - \frac{\eta}{1 - \beta_1^{t+1}} \cdot \frac{m_{t+1}}{u_{t+1}}

The second-moment recursion is the limit of an Adam-style LpL^p EMA as p→∞p \to \infty, hence "max".

References

Kingma & Ba, "Adam: A Method for Stochastic Optimization", §7.1 "Adamax" (ICLR 2015).

See Also

Adagrad, Adadelta, RMSprop

Parameters

paramsvector of TensorImpl
Parameters to optimise; one update buffer per entry.
lrfloat, default 2e-3
Base step size η\eta.
beta1float, default 0.9
First-moment EMA decay.
beta2float, default 0.999
Decay used inside the running-max envelope.
epsfloat, default 1e-8
Numerical stabiliser added to ∣gt∣|g_t| inside the running-max envelope.
weight_decayfloat, default 0.0
L2 penalty applied to gtg_t before the update.

Attributes

m_vector of Storage
Per-parameter first-moment EMA.
u_vector of Storage
Per-parameter ℓ∞\ell_\infty envelope (the "infinity-norm" buffer).

Notes

Unlike Adam there is no bias correction on uu — the running max is naturally bounded, so dividing it by 1−β2t+11 - \beta_2^{t+1} would over-amplify the very first updates.

Constructors

1
ctor

Adamax

void Adamax(int)

Construct the optimiser and resize per-slot state vectors.

Parameters

paramsvector of TensorImpl
Parameters to optimise.
lrfloat, default 2e-3
Base step size.
beta1float, default 0.9
First-moment EMA decay.
beta2float, default 0.999
Infinity-norm envelope decay.
epsfloat, default 1e-8
Numerical stabiliser.
weight_decayfloat, default 0.0
L2 penalty coefficient.

Static methods

1
static

check_hyperparams

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

Check Adamax'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

→float
double lr()

Return the current learning rate.

Returns

float

Active value of η\eta.

virt

set_lr

void set_lr(double lr)

Set the active learning rate.

Parameters

lrfloat
New base step size η\eta used on subsequent steps.

Methods

5
fn

init_state_slot

void init_state_slot(int i, const int & p)

Allocate the per-slot state buffers for parameter i.

Parameters

iint
Slot index.
Parameter whose shape/dtype/device dictates the buffer layout.

Notes

Both m_[i] (first moment) and u_[i] (infinity norm) are zero-initialised.

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()

Return the versioned state-dict identifier.

Returns

str

"adamax_v1" — used by serialisation to validate state-dict layout.

fn

update_one

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

Apply one Adamax update to parameter i.

Parameters

iint
Index of the parameter in the optimiser's parameter list.
Parameter tensor (updated in place).
gStorage
Gradient for p on this step.

Notes

Advances mm via the EMA, refreshes the ℓ∞\ell_\infty envelope uu, then applies the bias-corrected step in one fused pass.