Fun with Learning Technology
LearnCoursesQuestionsTracksToolsNewsExplorePractice
Fun with Learning Technology

A new problem, explained clearly, every day.

Subscribe
Learn
  • Lessons
  • Topics
  • News
  • Tools
  • Courses
  • Career tracks
  • Everything
Site
  • About
  • Contact
  • Support
  • Privacy
  • Terms
Get the daily one

One email per new problem. No spam.

Request a tutorial

Requests shape what gets made next.

© 2026 Fun with Learning TechnologyRSS
Home›Courses›Machine Learning›Learning Rate and Schedulers

Model Training Deep Dive

Learning Rate and Schedulers

The learning rate acts as the step size in optimization, directly determining how quickly a model converges toward the global minimum of the loss landscape. If the rate is too high, the model overshoots the minimum, while a rate that is too low leads to agonizingly slow progress or premature convergence in poor local optima. Schedulers dynamically adjust this parameter during training to balance rapid initial learning with the stability required for fine-tuning.

The Fundamentals of Gradient Descent

The learning rate is the primary hyperparameter in gradient descent, dictating the magnitude of updates applied to model weights based on the gradient of the loss function. Think of the loss landscape as a vast mountain range; the gradient provides the direction toward the valley floor, but the learning rate tells the algorithm how large of a leap to take. If your leap is massive, you might jump right over the deepest point of the valley, landing on a different slope entirely. Conversely, if your leap is microscopic, you will take an eternity to reach the bottom, potentially getting stuck in shallow indentations or flat regions known as saddle points. By understanding the learning rate as a control mechanism for the trade-off between speed and stability, you can better diagnose training failures. A loss that explodes instantly is a classic sign of an oversized learning rate, whereas a loss that barely changes over thousands of iterations suggests your steps are too cautious.

# Simple Gradient Descent update rule
# weights_new = weights_old - learning_rate * gradient
def update_weights(weights, gradient, lr=0.01):
    # Adjusting weights in the negative direction of the gradient
    return weights - (lr * gradient)

Learning Rate Decay Strategies

As training progresses, the model reaches regions of the loss landscape that are increasingly narrow or steep. Using a constant learning rate throughout this journey is akin to driving a car at high speed into a parking space; you need to slow down to park accurately. Step-based decay reduces the learning rate by a factor at specific intervals, allowing the model to make significant progress early on and settle into a sharp, narrow minimum later. This ensures that the weights do not oscillate wildly when they approach the target, providing the granular resolution necessary for final convergence. Without decay, the model might remain trapped in a high-loss zone, unable to navigate the finer curvature of the objective function. By systematically lowering the rate, you trade the ability to move across large distances in parameter space for the precision required to hone in on the optimal configuration of the network's internal representations.

# Implement step decay scheduler
class StepDecay:
    def __init__(self, initial_lr, decay_factor, step_size):
        self.lr = initial_lr
        self.decay = decay_factor
        self.step_size = step_size
    
    def get_lr(self, epoch):
        # Reduce learning rate every N steps
        return self.lr * (self.decay ** (epoch // self.step_size))

Cosine Annealing for Smooth Convergence

Cosine annealing is a sophisticated scheduler that follows a periodic, smooth decline of the learning rate. Unlike step-based decay, which introduces sudden shocks to the optimization process, cosine annealing mimics the natural cooling process of simulated annealing. By gradually reducing the learning rate along a cosine curve, the model experiences a more fluid transition between exploration and exploitation. This method is particularly effective for deep neural networks where the loss surface can be erratic. Because it slowly brings the learning rate near zero, it encourages the model to seek out the most stable, flat minima, which often generalize better than sharp, narrow ones. The smoothness prevents the optimizer from being 'startled' by abrupt changes in step size, allowing the optimization trajectory to remain harmonious and consistent throughout the training lifecycle, even as the scale of weight updates shrinks significantly over time.

import math

# Cosine annealing implementation
def cosine_lr(epoch, total_epochs, initial_lr):
    # Returns the learning rate following a cosine curve
    return 0.5 * initial_lr * (1 + math.cos(math.pi * epoch / total_epochs))

The Impact of Warm-up Periods

In many modern deep learning architectures, particularly those with complex attention mechanisms or high-depth backbones, initiating training with a high learning rate can lead to catastrophic instability. This is because, at the very beginning of training, the weight gradients are noisy and potentially misleading, as the model has not yet learned a coherent internal representation of the data. Warm-up strategies gradually increase the learning rate from zero to the target maximum over a set number of initial iterations. This allows the model to 'warm up' and stabilize its weight distribution before moving at high speed. By preventing large, erratic updates when the loss is high, warm-up helps the optimizer avoid divergence and sets a stronger foundation for the subsequent optimization path. It acts as a necessary safeguard, ensuring that the model does not prematurely collapse into a sub-optimal region of the parameter space during the most volatile phase of initial optimization.

# Linear warm-up logic
def get_warmup_lr(current_step, warmup_steps, max_lr):
    if current_step < warmup_steps:
        # Gradually increase from 0 to max_lr
        return max_lr * (current_step / warmup_steps)
    return max_lr

Cyclical Learning Rates

Cyclical Learning Rates (CLR) introduce the concept of oscillation, intentionally moving the learning rate between a lower and an upper bound throughout training. By periodically increasing the learning rate, the model is 'kicked' out of small, suboptimal local minima that might capture it. When the learning rate drops again, the optimizer settles into a more stable, potentially deeper valley. This cycle allows for more robust exploration of the loss landscape, preventing the model from becoming complacent or getting stuck in low-quality regions early in the process. It serves as a form of regularization because the periodic 'reset' of high step sizes prevents the model from overly focusing on specific noisy gradients. Mastering this technique requires careful tuning of the cycle length and the bounds, but it often yields superior final accuracy by forcing the network to visit diverse regions of the weight space during the standard training run.

# Triangular cyclic schedule
def triangular_clr(step, cycle_len, min_lr, max_lr):
    # Calculate position in the cycle
    cycle = 1 + (step // (2 * cycle_len))
    x = abs(step / cycle_len - 2 * cycle + 1)
    # Interpolate between bounds
    return min_lr + (max_lr - min_lr) * max(0, (1 - x))

Key points

  • The learning rate determines the size of the step the optimizer takes in the direction of the gradient.
  • A learning rate that is too large causes the loss to diverge, while one that is too small leads to stagnation.
  • Decay schedules help the model settle into precise minima by reducing step sizes toward the end of training.
  • Cosine annealing provides a smooth transition that often improves generalization compared to abrupt step decay.
  • Warm-up periods are essential for preventing instability in deep networks at the start of the training process.
  • Cyclical learning rates force the model to explore more of the loss landscape to avoid getting stuck in local minima.
  • Training dynamics rely on balancing the speed of convergence with the requirement for eventual stability.
  • Schedulers are critical tools for fine-tuning the optimization trajectory without manual intervention during the training run.

Common mistakes

  • Mistake: Choosing a static learning rate that is too high. Why it's wrong: High rates cause the loss to oscillate or diverge, preventing convergence. Fix: Start with a smaller rate and use a scheduler to decay it over time.
  • Mistake: Assuming a smaller learning rate is always better. Why it's wrong: Excessively low rates lead to agonizingly slow convergence and increase the risk of getting trapped in local minima or saddle points. Fix: Use learning rate range tests to find an optimal balance.
  • Mistake: Resetting the learning rate scheduler every mini-batch. Why it's wrong: Schedulers are designed to adjust based on epochs or total iterations; resetting too frequently prevents the decay from ever taking effect. Fix: Only update the scheduler at the frequency intended by the design, typically per epoch.
  • Mistake: Failing to scale the learning rate when increasing batch size. Why it's wrong: Larger batches provide a more stable estimate of the gradient, often allowing for a higher learning rate. Fix: Apply the linear scaling rule where you increase the learning rate proportionally with the batch size.
  • Mistake: Using a scheduler that reduces the rate too aggressively. Why it's wrong: If the learning rate drops to near-zero before the model converges, the model stops learning entirely. Fix: Use monitoring to reduce the learning rate only when validation loss plateaus.

Interview questions

What is the learning rate, and why is its selection critical in training neural networks?

The learning rate is a fundamental hyperparameter that controls how much we adjust the weights of our network with respect to the loss gradient during optimization. It determines the size of the steps taken toward a local minimum. If the learning rate is too high, the optimizer may overshoot the minimum and cause the loss to diverge. Conversely, if it is too low, the model converges very slowly or gets stuck in suboptimal local minima, leading to poor performance or excessive training time.

What happens if the learning rate is set too high during training?

Setting the learning rate too high often leads to instability in the training process. When the steps taken are too large, the optimizer may skip over the global minimum, causing the objective function value to oscillate or even explode, resulting in 'NaN' loss values. Effectively, the model fails to settle into a stable state. You might observe the loss graph violently fluctuating instead of decreasing, indicating that the weight updates are destructive rather than constructive, ultimately preventing the model from learning any meaningful patterns.

Can you explain what a learning rate scheduler is and why we use it?

A learning rate scheduler is a technique used to adjust the learning rate during training, typically by decaying it as the number of epochs increases. We use schedulers because, at the beginning of training, we want a larger learning rate to make rapid progress, but as we get closer to the optimal weights, we want smaller steps to refine the solution. For instance, using a code snippet like `scheduler = torch.optim.lr_scheduler.StepLR(optimizer, step_size=30, gamma=0.1)` allows the model to converge more precisely in the final stages, preventing it from overshooting the minimum.

How does the 'Cosine Annealing' scheduler differ from a simple 'Step Decay' approach?

The Step Decay approach reduces the learning rate by a fixed factor at specific epoch intervals, resulting in a step-wise decline that can be abrupt and cause localized convergence issues. In contrast, the Cosine Annealing scheduler follows a continuous, smooth cosine curve that decreases the learning rate gradually over a period. This smoother transition helps the model escape narrow local minima more effectively early on and provides a more stable, refined descent toward the global minimum, leading to better final generalization compared to the sudden drops of step-based scheduling.

Compare the behavior of an Adam optimizer with a constant learning rate versus one paired with a 'ReduceLROnPlateau' scheduler.

An Adam optimizer with a constant learning rate relies on the algorithm's built-in adaptive moment estimation to handle individual parameter updates, but it does not account for the overall training trajectory's health. By adding 'ReduceLROnPlateau', you create a feedback loop: the scheduler monitors a validation metric and reduces the learning rate only when that metric stops improving. This is superior because it waits for the model to actually stagnate before forcing a smaller step size, preventing premature decay and allowing the optimizer to fully explore the landscape before tightening the focus.

Describe the concept of 'Warm-up' steps in learning rate scheduling and why they are necessary for complex architectures like Transformers.

Learning rate warm-up is a strategy where the learning rate starts at a very small value and gradually increases to the target rate over the first few thousand iterations. In complex architectures like Transformers, the initial gradients can be highly unstable due to random initialization. If we use a high learning rate immediately, these large gradients can lead to catastrophic forgetting or model divergence. Warm-up provides a 'stabilization period' that allows the normalization layers and weights to find a reasonable subspace before the full-strength updates begin, significantly improving both convergence speed and final model robustness.

All Machine Learning interview questions →

Check yourself

1. What is the primary purpose of using a learning rate warmup phase at the start of training?

  • A.To allow the model to memorize the training data faster.
  • B.To prevent gradient explosion in early iterations when weights are random.
  • C.To ensure the learning rate is exactly equal to the loss value.
  • D.To bypass the need for weight initialization techniques.
Show answer

B. To prevent gradient explosion in early iterations when weights are random.
Warmup stabilizes training when gradients are volatile due to random initialization. Option 0 is false because memorization is overfitting; option 2 is nonsensical; option 3 is incorrect as initialization is still necessary.

2. If your training loss is fluctuating wildly, what is the most appropriate first adjustment?

  • A.Increase the learning rate significantly.
  • B.Replace the loss function with a simpler one.
  • C.Reduce the learning rate or implement a decay schedule.
  • D.Increase the number of layers in the network.
Show answer

C. Reduce the learning rate or implement a decay schedule.
Wild fluctuations indicate the step size is too large to settle into the minimum. Option 0 worsens the issue; option 1 is irrelevant; option 3 adds unnecessary complexity without addressing the step size.

3. Why is the Cosine Annealing scheduler generally preferred over simple step-based decay?

  • A.It performs a discrete jump in accuracy.
  • B.It provides a smooth, gradual reduction that prevents sudden shocks to the model.
  • C.It automatically optimizes the number of hidden neurons.
  • D.It keeps the learning rate constant throughout the training.
Show answer

B. It provides a smooth, gradual reduction that prevents sudden shocks to the model.
Cosine annealing provides a smooth curve that mimics the geometry of the loss landscape better than abrupt steps. Option 0 is false; option 2 is not the role of a scheduler; option 3 contradicts the definition of a scheduler.

4. In the context of 'ReduceLROnPlateau', why should you monitor validation loss rather than training loss?

  • A.Because training loss is always lower than validation loss.
  • B.Because validation loss indicates how well the model generalizes to unseen data.
  • C.Because monitoring training loss requires less computational power.
  • D.Because the scheduler only works with training loss in modern frameworks.
Show answer

B. Because validation loss indicates how well the model generalizes to unseen data.
We care about generalization. Reducing the rate based on training loss might just lead to overfitting. Option 0 is not a universal truth; option 2 is false regarding computation; option 3 is factually incorrect.

5. How does increasing the batch size interact with the optimal learning rate?

  • A.You should decrease the learning rate because the gradient estimate is noisier.
  • B.You should keep the learning rate the same regardless of batch size.
  • C.You should increase the learning rate because the gradient estimate is more accurate.
  • D.You should stop using a scheduler entirely.
Show answer

C. You should increase the learning rate because the gradient estimate is more accurate.
Larger batches provide a more reliable gradient direction, allowing for larger steps. Option 0 is backwards; option 1 ignores the statistical reality of batches; option 3 is arbitrary.

Take the full Machine Learning quiz →

← PreviousStochastic Gradient DescentNext →Regularization — L1 (Lasso) and L2 (Ridge)

Machine Learning

35 lessons, free to read.

All lessons →

Track your progress

Sign in to mark lessons done, score quizzes and keep notes.

Open in the app