How Learning Rate Affects the Training of a Neural Network

How does the learning rate affect the training of a neural network

If I had to pick the single hyperparameter that most dramatically affects whether a neural network trains successfully at all, it would be the learning rate. I’ve seen models that never converge, models that explode into NaN losses within a handful of steps, and models that take forever to train — all because of a poorly chosen learning rate. Get this one number right, and everything else about training tends to go much more smoothly. Get it wrong, and no amount of architectural cleverness will save you.

This article explores the learning rate in depth: what it is mathematically, how it shapes the optimization process, the consequences of setting it too high or too low, and the modern techniques used to manage it effectively.

What Is the Learning Rate?

The learning rate ($\eta$ or $\alpha$) is a scalar hyperparameter that controls the size of the steps a neural network’s optimizer takes when updating its weights during training. In gradient-based optimization, the most basic update rule looks like this:

$$ \theta_{t+1} = \theta_t – \eta \nabla_{\theta} \mathcal{L}(\theta_t) $$

Here, $\theta_t$ represents the model’s parameters at step $t$, $\nabla_{\theta} \mathcal{L}(\theta_t)$ is the gradient of the loss function with respect to those parameters, and $\eta$ is the learning rate that scales how large a step is taken in the direction opposite the gradient (since gradients point toward increasing loss, and we want to minimize loss).

An Analogy: Walking Down a Hill

Picture yourself standing on a foggy hillside, trying to reach the valley floor (the point of minimum loss) using only your sense of the ground’s slope beneath your feet. The learning rate is essentially your stride length. Take steps that are too small, and you’ll inch toward the valley at a painfully slow pace. Take steps that are too large, and you risk overshooting the valley entirely, possibly bouncing back and forth across it or even climbing higher up the opposite slope.

The Loss Landscape and Why Learning Rate Matters

Neural network training involves navigating a high-dimensional, non-convex loss surface with countless local minima, saddle points, and plateaus. The learning rate determines how the optimizer traverses this landscape.

graph TD
    A[Initialize Weights] --> B[Compute Gradient]
    B --> C{Learning Rate Size?}
    C -->|Too Small| D[Very Slow Convergence, May Get Stuck]
    C -->|Too Large| E[Overshooting, Oscillation, or Divergence]
    C -->|Well-Tuned| F[Smooth, Efficient Convergence]
    D --> G[Update Weights]
    E --> G
    F --> G
    G --> B

Effects of a Learning Rate That’s Too High

When the learning rate is too large, weight updates overshoot the minimum of the loss function. This can manifest in several ways:

Mathematically, consider a simple quadratic loss $\mathcal{L}(\theta) = \frac{1}{2} a \theta^2$. The gradient descent update becomes:

$$ \theta_{t+1} = \theta_t – \eta a \theta_t = (1 – \eta a)\theta_t $$

For convergence, we need $|1 – \eta a| < 1$, which means $\eta$ must satisfy $0 < \eta < \frac{2}{a}$. Exceed this bound, and the sequence of $\theta_t$ values diverges rather than converging to zero.

Effects of a Learning Rate That’s Too Low

A learning rate that’s too small leads to different, but equally problematic, issues:

Finding the Right Learning Rate

Learning Rate Range Test

A widely used technique, popularized by Leslie Smith, involves training the model for a few iterations while exponentially increasing the learning rate from a very small value to a very large one, and plotting loss against learning rate. The ideal learning rate is typically found just before the point where loss starts increasing sharply.

import torch
import matplotlib.pyplot as plt

def lr_range_test(model, train_loader, optimizer, criterion, start_lr=1e-7, end_lr=10, num_iters=100):
    lrs, losses = [], []
    lr_mult = (end_lr / start_lr) ** (1 / num_iters)
    lr = start_lr

    for i, (xb, yb) in enumerate(train_loader):
        if i >= num_iters:
            break
        for g in optimizer.param_groups:
            g['lr'] = lr

        optimizer.zero_grad()
        loss = criterion(model(xb), yb)
        loss.backward()
        optimizer.step()

        lrs.append(lr)
        losses.append(loss.item())
        lr *= lr_mult

    plt.plot(lrs, losses)
    plt.xscale('log')
    plt.xlabel('Learning Rate')
    plt.ylabel('Loss')
    plt.title('Learning Rate Range Test')
    plt.show()

Learning Rate Schedules

Rather than using a single fixed learning rate throughout training, most modern deep learning pipelines use a learning rate schedule that adjusts $\eta$ over time.

Step Decay

The learning rate is reduced by a fixed factor every set number of epochs:

$$ \eta_t = \eta_0 \cdot \gamma^{\lfloor t / s \rfloor} $$

where $\gamma$ is the decay factor and $s$ is the step size (number of epochs between decays).

Exponential Decay

$$ \eta_t = \eta_0 \cdot e^{-kt} $$

Cosine Annealing

$$ \eta_t = \eta_{\min} + \frac{1}{2}(\eta_{\max} – \eta_{\min})\left(1 + \cos\left(\frac{t\pi}{T}\right)\right) $$

This smoothly decreases the learning rate following a cosine curve, often producing better final performance than step decay in practice.

Warmup

Many modern architectures, especially transformers, benefit from a “warmup” phase where the learning rate starts near zero and increases linearly for the first several hundred or thousand steps before decaying. This helps stabilize training early on, when weight initialization and gradient statistics are least reliable.

import torch.optim as optim

model_params = model.parameters()
optimizer = optim.Adam(model_params, lr=1e-3)

scheduler = optim.lr_scheduler.CosineAnnealingLR(optimizer, T_max=50, eta_min=1e-6)

for epoch in range(50):
    train_one_epoch(model, train_loader, optimizer)
    scheduler.step()
    print(f"Epoch {epoch}, LR: {scheduler.get_last_lr()}")

Adaptive Learning Rate Optimizers

Instead of manually crafting schedules, adaptive optimizers adjust the effective learning rate for each parameter individually based on historical gradient information.

Adam

Adam combines momentum with per-parameter adaptive learning rates:

$$ m_t = \beta_1 m_{t-1} + (1-\beta_1) g_t, \quad v_t = \beta_2 v_{t-1} + (1-\beta_2) g_t^2 $$ $$ \hat{m}_t = \frac{m_t}{1-\beta_1^t}, \quad \hat{v}t = \frac{v_t}{1-\beta_2^t} $$ $$ \theta_t = \theta{t-1} – \eta \frac{\hat{m}_t}{\sqrt{\hat{v}_t}+\epsilon} $$

RMSprop

RMSprop divides the learning rate by an exponentially decaying average of squared gradients, helping stabilize updates in the presence of noisy or sparse gradients.

Comparison Table: Learning Rate Behaviors

Learning RateConvergence SpeedRisk of DivergenceFinal Model QualityTypical Fix
Too highFast initially, then unstableHighPoor or NaN lossReduce LR, use gradient clipping
Too lowVery slowLowMay be stuck in poor minimaIncrease LR, use warmup/adaptive optimizer
Well-tunedEfficientLowGoodMaintain with schedule/monitoring
Adaptive (Adam, etc.)Generally fast and stableLow-moderateGood, but can generalize slightly worse than well-tuned SGDTune betas, consider SGD for final fine-tuning

Advantages of Careful Learning Rate Tuning

Disadvantages and Challenges

Real-World Use Cases

Best Practices

Summary

The learning rate governs the step size of weight updates during neural network training and is arguably the most consequential hyperparameter to get right. Too high a learning rate causes oscillation or divergence; too low a learning rate causes painfully slow convergence and susceptibility to poor local minima. Modern practice combines careful initial tuning (via techniques like the learning rate range test), learning rate schedules (step decay, cosine annealing, warmup), and adaptive optimizers (Adam, RMSprop) to navigate the loss landscape efficiently and land on high-quality, generalizable solutions.

References

Exit mobile version