Optimizer Hyperparameters: Complete Guide

Learn about optimizer hyperparameters in machine learning. Understanding SGD, Adam, and other optimizer parameters.

Introduction

Optimizer hyperparameters control how the optimization algorithm updates model parameters during training. Different optimizers have different parameters that significantly impact convergence speed, stability, and final performance. Understanding these parameters is essential for effective model training.

SGD Parameters

Learning Rate

Controls step size in parameter updates:

θ = θ - lr * ∇J(θ)

Momentum

Accumulates gradient information from previous steps:

v = momentum * v + lr * ∇J(θ) θ = θ - v

Weight Decay

L2 regularization term:

θ = θ - lr * (∇J(θ) + weight_decay * θ)

Adam Parameters

Learning Rate

Step size for parameter updates:

Beta1 (First Moment Decay)

Exponential decay rate for first moment estimates:

Beta2 (Second Moment Decay)

Exponential decay rate for second moment estimates:

Epsilon

Small constant for numerical stability:

RMSprop Parameters

Learning Rate

Step size for updates:

Alpha (Decay Rate)

Smoothing constant for moving average:

Epsilon

Numerical stability constant:

AdaGrad Parameters

Learning Rate

Initial learning rate:

Epsilon

Numerical stability constant:

AdaDelta Parameters

Rho

Decay rate for moving averages:

Epsilon

Numerical stability constant:

AdamW Parameters

Learning Rate

Step size for parameter updates:

Weight Decay

L2 regularization strength:

Beta1 and Beta2

Same as Adam:

Optimizer Selection Guidelines

When to Use SGD

When to Use Adam

When to Use RMSprop

Key Insight

Adam is often the best default choice due to its robustness and adaptive learning rates. For specific cases, SGD with momentum or RMSprop may work better. Always validate optimizer choice with your specific problem.

Parameter Tuning Strategies

Grid Search

learning_rates = [1e-4, 1e-3, 1e-2] momentums = [0.9, 0.95, 0.99] weight_decays = [1e-4, 1e-3, 1e-2]

Log Scale Search

learning_rates = [10**x for x in range(-4, -1)] # 0.0001 to 0.1

Frequently Asked Questions

What optimizer should I use?

Adam is often the best default choice due to its robustness and adaptive learning rates. For specific cases, SGD with momentum or RMSprop may work better. Test multiple optimizers.

How do I tune Adam parameters?

Start with default values (lr=0.001, beta1=0.9, beta2=0.999, eps=1e-8). Tune learning rate first, then beta values if needed. Adam is robust to parameter choices.

What's the difference between Adam and AdamW?

AdamW applies weight decay differently than Adam, often leading to better generalization. Use AdamW when you need L2 regularization, as it's more principled than Adam's weight decay.

How do I choose learning rate for different optimizers?

SGD: 0.01-0.1, Adam: 0.001-0.01, RMSprop: 0.001-0.01. Start with literature values, use learning rate finder, or try log scale search around default values.

Should I use momentum with SGD?

Yes, momentum (0.9-0.99) helps SGD escape local minima and converge faster. It's especially important for non-convex optimization problems like neural networks.