← Back to Blog

Optimization Techniques: Training Networks Faster

Introduction

Neural networks learn through gradient descent: compute gradients, update weights, repeat. But simple gradient descent is slow. For large networks training on massive datasets, slow means impractical.

Optimization techniques accelerate training by making gradient descent smarter. Some preprocess data, others adjust how gradients are applied, and some use adaptive learning rates. Together, they can substantially reduce training time and sometimes improve final performance, though the size of the effect depends on the problem.

Feature Scaling

When input features have vastly different scales (height in meters vs. age in years), gradient descent struggles. The loss function becomes elongated, forcing the optimizer to take smaller steps.

Standardization

Transform each feature to have mean 0 and standard deviation 1:

x_normalized = (x - mean) / std

This puts all features on the same scale, allowing the optimizer to find the direction of steepest descent more directly.

Normalization

Scale features to a range, typically [0, 1]:

x_normalized = (x - min) / (max - min)

Advantages

  • Faster convergence
  • Better gradient flow
  • Simple to implement

Disadvantages

  • Requires knowing data statistics
  • Must be applied consistently

Batch Normalization

Feature scaling normalizes inputs. Batch normalization normalizes the activations at the layers where it is inserted, using mini-batch statistics during training and running averages at inference, then applies a learned scale and shift.

y_normalized = (y - batch_mean) / sqrt(batch_var + epsilon)
output = gamma * y_normalized + beta  # gamma and beta are learned

Batch normalization keeps activations in favorable ranges and often allows higher learning rates and faster training. Its original motivation was reducing "internal covariate shift" (Ioffe & Szegedy, 2015), but why it works is debated: Santurkar et al. (2018) argue that smoothing the optimization landscape matters more.

Advantages

  • Faster training
  • Reduces sensitivity to weight initialization
  • Can have a mild regularizing effect
  • Allows higher learning rates

Disadvantages

  • Adds computational cost
  • Behavior differs during training vs. testing
  • Requires tracking running statistics

Mini-Batch Gradient Descent

Strictly, stochastic gradient descent (SGD) computes gradients on one sample, which is noisy. Full-batch gradient descent computes gradients on all samples, which is stable but slow per update. In practice, and in library names, "SGD" usually means the mini-batch version below.

Mini-batch gradient descent splits the dataset into small batches (typically 32-256 samples) and updates weights based on each batch. This balances noise and stability.

Batch size is a critical hyperparameter. Larger batches are more stable but require more memory. Smaller batches are noisier but allow more frequent updates.

Momentum

Standard gradient descent updates weights with the current gradient. Momentum adds history: it accumulates an exponentially decaying sum of past gradients.

velocity = beta * velocity + gradient
weights = weights - learning_rate * velocity

Think of it as rolling a ball downhill. The ball builds speed in consistent directions, while oscillating components partly cancel. This often speeds convergence and can carry the optimizer across small bumps, but neither faster convergence nor escaping local minima is guaranteed.

β (typically 0.9) controls how much history to remember. Higher β means more momentum.

RMSProp

RMSProp adapts the learning rate per parameter based on the magnitude of recent gradients. Parameters with large gradients get smaller updates (lower effective learning rate).

rms = beta * rms + (1 - beta) * gradient²
weights = weights - learning_rate * gradient / (sqrt(rms) + epsilon)

This helps with parameters that consistently have large or small gradients, allowing the optimizer to use appropriate step sizes per parameter.

Advantages

  • Adaptive learning rates
  • Works well in practice
  • Handles different gradient magnitudes

Disadvantages

  • More hyperparameters to tune
  • More memory for storing running averages

Adam Optimizer

Adam combines momentum and RMSProp. It maintains both a running average of gradients (momentum) and a running average of gradient magnitudes (adaptive learning rates).

t = t + 1 # initialize t=0, m=0, v=0
m = beta1 * m + (1 - beta1) * gradient
v = beta2 * v + (1 - beta2) * gradient²
m_hat = m / (1 - beta1^t)  # bias correction
v_hat = v / (1 - beta2^t)  # m and v start at zero
weights = weights - learning_rate * m_hat / (sqrt(v_hat) + epsilon)

Adam is a very widely used optimizer and a reasonable default across many architectures and datasets, although the learning rate often still needs tuning. Because m and v start at zero, the bias-correction step above stops early estimates from being too small.

Advantages

  • Often fast early progress
  • Robust to different problems
  • Widely supported and used
  • Reasonable default hyperparameters

Disadvantages

  • L2 added to the gradient interacts poorly with adaptive scaling; prefer AdamW for weight decay
  • Requires more memory
  • Sometimes performs worse than SGD + momentum on some tasks
Common defaults, from the Adam paper: learning_rate=0.001, beta1=0.9, beta2=0.999, epsilon=1e-8.
3D surface unavailable — WebGL could not start. The loss curves alongside remain accurate.

Drag the surface to orbit; toggle any optimizer with the chips above. The surface is illustrative — a synthetic function chosen to contain a plateau, two local minima and one global minimum, because real loss landscapes have millions of dimensions and cannot be drawn. The optimizers are not. Each runs its real update rule on the analytic gradient of that surface, so every difference you see is produced by the algorithm itself. Try the Plateau start to watch SGD stall where Adam does not — then try Shallow, where the adaptive methods settle for a worse minimum than plain SGD.

Learning Rate Decay

A fixed learning rate can be too aggressive early in training and too conservative late in training. Learning rate decay reduces the learning rate over time.

learning_rate = initial_lr * decay_rate^epoch

With decay, the optimizer takes larger steps initially to explore the loss landscape, then smaller steps to fine-tune weights. This often results in better final solutions.

Common strategies include exponential decay (reduce by a fixed percentage each epoch), step decay (reduce by a factor every N epochs), and cosine decay (follow a cosine curve).

Practical Pipeline

Stage Technique Impact
Data Preparation Feature Scaling Better conditioning; often faster training
Training Setup Mini-Batch + Batch Norm Stable, fast convergence
Optimization Adam Optimizer Often fast early progress
Fine-tuning Learning Rate Decay Can improve final performance

Recommended Training Setup

Start with: standardized features + mini-batch (32-256) + Adam optimizer (lr=0.001) + batch normalization.

If the loss oscillates or diverges, lower the learning rate first, then consider momentum or a decay schedule. If underfitting, check for bugs, tune the learning rate, train longer, or use a larger model. If overfitting, apply regularization (covered in another article). Larger batches can increase throughput on suitable hardware, but they do not automatically train a better model.

Conclusion

Modern optimization isn't just about gradient descent—it's about preprocessing data, using adaptive learning rates, normalizing layer activations, and decaying learning rates over time.

These techniques can make the difference between a network that barely trains and one that trains well. Adam with batch normalization is a common starting point, not a universal answer: SGD with momentum remains competitive on many vision tasks, and batch norm behaves poorly with very small batches.

But these aren't one-size-fits-all. Different problems may require different approaches. The key is understanding what each technique does and when to apply it.