For the complete documentation index, see llms.txt. This page is also available as Markdown.

Updaters

Optimization algorithms in ND4J — Adam, SGD, AdaGrad, learning rate schedules, and per-layer updater configuration

Updaters control how gradients are used to update network parameters during training. They implement different optimization algorithms that adapt learning rates, accumulate momentum, or both. All updater classes are in org.nd4j.linalg.learning.config.

Usage

Pass an updater instance to the network configuration builder:

import org.nd4j.linalg.learning.config.Adam;

new NeuralNetConfiguration.Builder()
    .updater(new Adam(1e-3))       // learning rate = 0.001
    // ... layers ...
    .build();

Migration note (beta4 to M2.1): The enum-based form .updater(Updater.ADAM) and .learningRate(0.001) are removed. Pass the learning rate directly to the updater constructor: new Adam(1e-3).

Available Updaters

Adam

new Adam(learningRate)
new Adam(learningRate, beta1, beta2, epsilon)

The default and recommended updater for most tasks. Combines momentum (exponential moving average of gradients) with adaptive per-parameter learning rates (exponential moving average of squared gradients).

Parameters:

  • learningRate: Step size (default: 1e-3)

  • beta1: Exponential decay rate for first moment estimates (default: 0.9)

  • beta2: Exponential decay rate for second moment estimates (default: 0.999)

  • epsilon: Small constant for numerical stability (default: 1e-8)

Update rule:

AMSGrad

A variant of Adam with guaranteed convergence. Uses the maximum of all past squared gradient moving averages instead of the current one, preventing the effective learning rate from increasing.

Reference: On the Convergence of Adam and Beyond — Reddi et al., 2018

AdaBelief

Adapts the learning rate based on the "belief" in the gradient — how much the observed gradient deviates from the predicted gradient. Combines the fast convergence of Adam with the stability of SGD.

Reference: AdaBelief Optimizer: Adapting Stepsizes by the Belief in Observed Gradients — Zhuang et al., 2020

Nadam

Adam with Nesterov momentum. Uses the look-ahead gradient (Nesterov momentum) in the update step instead of the current gradient. Often converges faster than standard Adam.

Reference: Incorporating Nesterov Momentum into Adam — Dozat, 2016

AdaMax

A variant of Adam based on the infinity norm. More robust to large gradients than standard Adam. Uses the max of the exponentially weighted infinity norm of past gradients.

Reference: Adam: A Method for Stochastic Optimization — Kingma & Ba, 2014 (Section 7)

AdaGrad

Adapts the learning rate per parameter based on the history of gradients. Parameters with large historical gradients get smaller learning rates, and vice versa. Useful for sparse features (NLP, recommender systems).

Downside: Learning rate monotonically decreases and can become too small, effectively stopping training.

AdaDelta

An extension of AdaGrad that addresses the monotonically decreasing learning rate. Uses a running window of gradient updates instead of accumulating all past gradients. Does not require a learning rate parameter.

Parameters:

  • rho: Decay rate for the running average (default: 0.95)

  • epsilon: Numerical stability constant (default: 1e-6)

Nesterovs (SGD with Nesterov Momentum)

Stochastic gradient descent with Nesterov's accelerated gradient. Evaluates the gradient at the "look-ahead" position rather than the current position, leading to faster convergence than standard momentum.

Parameters:

  • learningRate: Step size

  • momentum: Momentum coefficient (default: 0.9)

RmsProp

Divides the learning rate by an exponentially decaying average of squared gradients. Effective for recurrent neural networks and non-stationary objectives.

Parameters:

  • learningRate: Step size (default: 1e-3)

  • rmsDecay: Decay rate for moving average (default: 0.95)

  • epsilon: Numerical stability constant (default: 1e-8)

SGD

Basic stochastic gradient descent with a fixed learning rate. No momentum, no adaptive rates. Simple but often requires more careful tuning of the learning rate and benefits from learning rate schedules.

Update rule: theta = theta - lr * gradient

NoOp

No-operation updater — gradients are computed but parameters are not updated. Use this to freeze specific layers:

Updater Comparison

Updater
Learning Rate Required
Adaptive
Momentum
Best For

Adam

Yes

Yes

Yes

Default choice — works well for most tasks

AMSGrad

Yes

Yes

Yes

When Adam doesn't converge

AdaBelief

Yes

Yes

Yes

When Adam is unstable

Nadam

Yes

Yes

Yes (Nesterov)

Faster convergence than Adam

AdaMax

Yes

Yes

Yes

Large/sparse gradients

AdaGrad

Yes

Yes

No

Sparse features (NLP)

AdaDelta

No

Yes

No

When learning rate tuning is difficult

Nesterovs

Yes

No

Yes (Nesterov)

Classic CNN training

RmsProp

Yes

Yes

No

RNNs, non-stationary objectives

SGD

Yes

No

No

Simple tasks, fine-tuning with small LR

NoOp

No

N/A

N/A

Freezing layers

Learning Rate Schedules

Instead of a fixed learning rate, pass a schedule to any updater. All schedules implement ISchedule and are in org.nd4j.linalg.schedule.

Available Schedules

ExponentialSchedule

Multiplies the learning rate by gamma every epoch (or iteration).

lr = initialRate * gamma^(epoch)

StepSchedule

Reduces the learning rate by decayRate every step epochs.

lr = initialRate * decayRate^(floor(epoch/step))

PolySchedule

Polynomial decay from initial rate to zero over maxIter iterations.

lr = initialRate * (1 - iter/maxIter)^power

SigmoidSchedule

Sigmoid-based decay, providing a smooth transition.

InverseSchedule

lr = initialRate * (1 + gamma * iter)^(-power)

CycleSchedule

Cyclic learning rate that oscillates between minRate and maxRate. Useful for escaping local minima.

MapSchedule

Manually specify the learning rate at specific epochs or iterations:

FixedSchedule

Constant learning rate — equivalent to passing a double directly. Useful when you need an ISchedule type but want a fixed rate.

ScheduleType

The ScheduleType enum controls whether the schedule advances per epoch or per iteration (mini-batch):

Value
Advances Every
Use When

EPOCH

End of each epoch

Most common. Rate changes once per full pass through data

ITERATION

Each mini-batch

Fine-grained control. Useful for cyclic/warm-up schedules

Per-Layer Updater Configuration

Different layers can use different updaters or learning rates:

This is particularly useful for transfer learning, where pretrained layers might use a smaller learning rate while new layers train with a larger one.

Practical Recommendations

  1. Start with Adam(1e-3) — it works well out of the box for most tasks.

  2. If Adam isn't converging, try AMSGrad or reduce the learning rate.

  3. For fine-tuning pretrained models, use SGD with a small learning rate (1e-4 to 1e-5) and momentum.

  4. For RNNs, Adam or RmsProp tend to work better than SGD.

  5. Use learning rate schedules when training for many epochs — a fixed rate that's good early on may be too large later.

  6. Use per-layer updaters for transfer learning — freeze early layers with NoOp and train later layers with Adam.

Last updated

Was this helpful?