Skip to content
class

ASGD

extendsOptimizer
ASGD

Averaged Stochastic Gradient Descent (Polyak-Ruppert averaging).

Runs SGD with a decaying step size and a decay on the parameter itself, while also maintaining a running average θˉ\bar\theta (ax) of the parameter values. The algorithm is the reference framework's, state names and all: step, eta, mu and ax per parameter.

Math

With tt the slot's own step count (1 on its first update), ηt\eta_t and μt\mu_t the values carried over from the previous step (η1=η\eta_1 = \eta, μ1=1\mu_1 = 1):

gt←gt+w θt−1 g_t \leftarrow g_t + w\, \theta_{t-1} θt=θt−1 (1−λ ηt)−ηt gt \theta_t = \theta_{t-1}\,(1 - \lambda\,\eta_t) - \eta_t\, g_t θˉt={θtμt=1θˉt−1+μt (θt−θˉt−1)otherwise \bar\theta_t = \begin{cases} \theta_t & \mu_t = 1 \\ \bar\theta_{t-1} + \mu_t\,(\theta_t - \bar\theta_{t-1}) & \text{otherwise} \end{cases}

then, for the next step,

ηt+1=η(1+λ η t)α,μt+1=1max⁡(1,  t−t0). \eta_{t+1} = \frac{\eta}{(1 + \lambda\,\eta\,t)^{\alpha}}, \qquad \mu_{t+1} = \frac{1}{\max(1,\; t - t_0)}.

Before t0t_0 the average therefore tracks θ\theta exactly; after it, θˉ\bar\theta is the mean of the iterates since t0t_0.

References

Polyak and Juditsky, "Acceleration of stochastic approximation by averaging" (SIAM J. Control Optim., 1992).

See Also

SGD : the plain instantaneous update.

Attributes

lr_double
Learning rate η\eta. Read when eta is first set and each time it is advanced, so a scheduler's change takes effect from the next step's eta.
lambd_double
Decay term λ\lambda — of the step size and of the parameter.
alpha_double
Power of the step-size decay.
t0_double
Step at which averaging starts.
weight_decay_double
L2 penalty coefficient ww.
ax_std::vector<Storage>
Per-parameter running average θˉ\bar\theta, zero until the first update copies the parameter in.
eta_, mu_std::vector<double>
Per-parameter ηt\eta_t and μt\mu_t, held at the precision they are checkpointed at (round_to_state_scalar) so a restored run continues bit-identically.

Notes

tt is the slot's own update count (Optimizer::steps_), so a parameter introduced into training late (or temporarily frozen) starts its own schedule.

Constructors

1
ctor

ASGD

void ASGD(int)

Construct an ASGD optimizer.

Parameters

paramsstd::vector<std::shared_ptr<TensorImpl>>
Parameters to optimise.
lrdouble= None
Learning rate η\eta (default 1e-2). Must be non-negative.
lambddouble= None
Decay term λ\lambda (default 1e-4).
alphadouble= None
Power of the step-size decay (default 0.75).
t0double= None
Step at which averaging starts (default 1e6).
weight_decaydouble= None
L2 regularisation coefficient (default 0.0).

Static methods

1
static

check_hyperparams

void check_hyperparams(double lr, double weight_decay)

Check ASGD's hyper-parameters against its rules — the reference framework's constructor checks, run by the constructor and by set_hyperparams.

Raises

InvalidArgument
If lr or weight_decay is negative or NaN.

Virtual methods

2
virtconst

lr

double lr()

Current learning rate η\eta.

virt

set_lr

void set_lr(double lr)

Update the learning rate from a scheduler.

Methods

5
fn

init_state_slot

void init_state_slot(int i, const int & p)

Allocate per-slot state on the first observed gradient.

ax_ starts at zero, eta_ at the current learning rate and mu_ at one.

Parameters

istd::size_t
Slot index.
pconst std::shared_ptr<TensorImpl>&
Parameter whose layout dictates the state buffer shapes.
fn

set_hyperparams

void set_hyperparams(double lr, double lambd, double alpha, double t0, double weight_decay)

Replace the hyper-parameters between steps; nothing is applied when check_hyperparams rejects them. lr reaches the update through the next step's eta, which the reference framework computes at the end of each step.

fnconst

state_dict_id

int state_dict_id()

Checkpoint identifier ("asgd_v1").

fn

update_one

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

Apply the ASGD update for one parameter slot.

Decays and steps θ\theta with the slot's current ηt\eta_t, folds it into θˉ\bar\theta with μt\mu_t, then advances η\eta and μ\mu for the slot's next step.

Parameters

istd::size_t
Slot index into params_, ax_, eta_, mu_.
pstd::shared_ptr<TensorImpl>&
Parameter to update in place.
gconst Storage&
Accumulated gradient for this step.