Inferensys

Glossary

Learning Rate Scheduler

A learning rate scheduler is an algorithm that dynamically adjusts the learning rate during model training according to a predefined policy to improve convergence and final performance.
ML engineer managing model training cluster on laptop, GPU utilization visible, technical deep learning setup.
RETRIEVAL-AUGMENTED FINE-TUNING

What is a Learning Rate Scheduler?

A learning rate scheduler is a core component of the training loop for neural networks, including those used in retrieval-augmented generation systems.

A learning rate scheduler is an algorithm that dynamically adjusts the learning rate during model training according to a predefined policy, such as linear decay or cosine annealing, to improve convergence and final performance. It is a critical hyperparameter tuning mechanism that replaces a static learning rate with an adaptive schedule, allowing the model to make large updates early in training and finer adjustments later. This systematic reduction helps the model navigate the loss landscape more effectively, avoiding overshooting minima and stabilizing in a flatter, more generalizable region.

Common policies include step decay, which reduces the rate at fixed intervals, and cosine annealing, which smoothly decreases the rate following a cosine curve, often with warm restarts to escape local optima. In retriever fine-tuning and end-to-end RAG training, schedulers are essential for balancing the adaptation of the retriever and generator components. Proper scheduling works in tandem with techniques like gradient clipping to ensure stable training, directly impacting the model's ability to learn accurate representations for semantic search and generation within the RAG pipeline.

RETRIEVAL-AUGMENTED FINE-TUNING

Common Learning Rate Schedules

Learning rate schedules are predefined policies that dynamically adjust the learning rate during neural network training to improve convergence, stability, and final model performance.

01

Step Decay

A piecewise constant schedule where the learning rate is reduced by a multiplicative factor (e.g., 0.1) at predefined epoch intervals. This is a classic, interpretable schedule.

  • Mechanism: After every N epochs, the learning rate is multiplied by a decay factor gamma.
  • Typical Use: Foundational model fine-tuning where training stability is paramount.
  • Hyperparameters: Initial learning rate, decay step (epoch interval), decay factor.
02

Exponential Decay

A schedule where the learning rate decays continuously by an exponential factor after each epoch or update step, providing a smooth decline.

  • Formula: lr = initial_lr * (decay_rate ^ (step / decay_steps)).
  • Behavior: Provides a smooth, aggressive early reduction that gradually plateaus.
  • Application: Often used in scenarios where a rapid initial reduction in learning rate is beneficial to navigate sharp loss landscapes.
03

Cosine Annealing

A schedule that decreases the learning rate from a maximum to a minimum following a half-cycle of a cosine curve, often combined with warm restarts (SGDR).

  • Mechanism: lr = min_lr + 0.5 * (max_lr - min_lr) * (1 + cos(π * T_cur / T_i)).
  • Key Benefit: The smooth, periodic reduction can help models escape local minima and converge to flatter, more generalizable solutions.
  • SGDR Variant: Stochastic Gradient Descent with Warm Restarts periodically resets the learning rate to its maximum, simulating multiple training runs.
04

Linear Warmup & Decay

A composite schedule that linearly increases the learning rate from zero to a peak over a warmup period, then linearly decays it to zero over the remaining training steps.

  • Warmup Phase: Mitigates instability during the initial phase of training, especially for large models and adaptive optimizers like Adam.
  • Decay Phase: Provides a predictable, linear reduction to fine-tune weights. This is the default schedule in many transformer-based model training recipes (e.g., for BERT, GPT).
  • Prevalence: The de facto standard for pre-training and fine-tuning large language models.
05

OneCycle Policy

A aggressive schedule where the learning rate first increases from a low value to a high peak, then decreases back, all within a single training cycle, often combined with momentum cycling.

  • Profile: Asymmetric, resembling a triangle. Learning rate peaks around the 30-50% point of training.
  • Philosophy: Based on the idea of super-convergence, allowing for faster training with larger learning rates by carefully managing the schedule.
  • Key Feature: Often uses a final annealing phase to a very low learning rate, helping the model settle into a minimum.
06

ReduceLROnPlateau

A dynamic, validation-driven schedule that reduces the learning rate by a factor when a monitored metric (e.g., validation loss) stops improving for a 'patience' number of epochs.

  • Reactive, Not Proactive: The schedule adapts to the model's observed progress rather than following a fixed timeline.
  • Key Hyperparameters: factor (e.g., 0.5), patience (epochs to wait), min_lr (lower bound).
  • Use Case: Ideal for fine-tuning where the optimal number of epochs or decay steps is unknown, as it automatically responds to convergence signals.
SCHEDULER TYPES

Learning Rate Schedule Comparison

A comparison of common learning rate scheduling algorithms used during neural network training, detailing their update mechanisms, typical use cases, and key hyperparameters.

Feature / ParameterStep DecayExponential DecayCosine AnnealingCosine Annealing with Warm Restarts

Core Update Mechanism

Multiplicative drop at fixed step intervals

Continuous exponential decrease per step/epoch

Gradual decrease following a cosine curve to a minimum

Cosine curve decrease followed by a restart to the initial rate

Primary Use Case

Standard supervised fine-tuning (SFT)

Rapid initial exploration, then stabilization

Convergence to a sharp minimum; common in paper implementations

Escaping local minima; cyclic exploration of loss landscape

Key Hyperparameters

Decay rate, step size (epoch interval)

Decay rate

Initial LR, minimum LR, T_max (period length)

Initial LR, minimum LR, T_0 (first restart period), T_mult (period multiplier)

Requires Validation Set for Scheduling?

Common in Retriever Fine-Tuning?

Stability for Large Batch Sizes

Typical Convergence Speed

Medium

Fast initial, slows later

Steady

Variable; can be slower per cycle

Helps Escape Poor Local Minima?

LEARNING RATE SCHEDULER

Implementation in ML Frameworks

Learning rate schedulers are implemented as callbacks or hooks within major machine learning frameworks, providing standardized interfaces for dynamic learning rate adjustment during training.

04

Custom Scheduler Implementation

For research or specialized needs, custom schedulers are often required.

PyTorch Pattern: Subclass torch.optim.lr_scheduler._LRScheduler and implement get_lr(self).

Example - Linear Warmup with Cosine Decay:

python
class WarmupCosineSchedule(torch.optim.lr_scheduler._LRScheduler):
    def __init__(self, optimizer, warmup_steps, total_steps, last_epoch=-1):
        self.warmup_steps = warmup_steps
        self.total_steps = total_steps
        super().__init__(optimizer, last_epoch)
    def get_lr(self):
        if self.last_epoch < self.warmup_steps:
            # Linear warmup
            return [base_lr * self.last_epoch / self.warmup_steps for base_lr in self.base_lrs]
        else:
            # Cosine decay to zero
            progress = (self.last_epoch - self.warmup_steps) / (self.total_steps - self.warmup_steps)
            return [base_lr * 0.5 * (1 + math.cos(math.pi * progress)) for base_lr in self.base_lrs]

Key Considerations:

  • Ensure get_lr returns a list of learning rates, one per parameter group.
  • The base class handles the calling of get_lr and updating the optimizer.
  • The last_epoch attribute tracks the number of step() calls.
05

Scheduler Chaining and Composition

Advanced training regimes may require chaining multiple scheduling policies (e.g., warmup followed by a plateau detector).

PyTorch's ChainedScheduler: Sequences multiple schedulers, transitioning from one to the next.

Common Pattern - Warmup + Plateau Reduction:

python
# 1. Linear warmup for first 10 epochs
warmup_scheduler = torch.optim.lr_scheduler.LambdaLR(
    optimizer, lr_lambda=lambda epoch: epoch / 10)
# 2. Then monitor validation loss and reduce on plateau
plateau_scheduler = torch.optim.lr_scheduler.ReduceLROnPlateau(
    optimizer, mode='min', patience=5)

for epoch in range(epochs):
    train(...)
    val_loss = validate(...)
    if epoch < 10:
        warmup_scheduler.step()
    else:
        plateau_scheduler.step(val_loss)  # Note: requires metric

Important Distinction: ReduceLROnPlateau is an exception; it is a metric-based scheduler and its step() method requires a metric value as an argument. It cannot be easily chained with epoch/step-based schedulers using ChainedScheduler.

06

Step-Based vs. Epoch-Based Invocation

A critical implementation detail is when the scheduler's step() method is called, which differs by framework and scheduler type.

Epoch-Based: Called at the end of each training epoch.

  • Default for most PyTorch schedulers (e.g., StepLR, MultiStepLR, CosineAnnealingLR).
  • Used in classic, epoch-counted training loops.

Step-Based: Called after each optimizer update (batch).

  • Default for Hugging Face Trainer and TensorFlow schedules.
  • Required for schedules with warmup defined in steps (e.g., constant_with_warmup).
  • More fine-grained control, aligning with total training steps.

Implementation Impact:

  • For epoch-based, scheduler.step() is placed after the inner training loop.
  • For step-based, scheduler.step() is placed inside the inner training loop, after optimizer.step().

PyTorch Conversion: Use scheduler = torch.optim.lr_scheduler.LambdaLR(optimizer, lr_lambda) where lr_lambda is a function of the global step counter, not epoch.

LEARNING RATE SCHEDULER

Frequently Asked Questions

A learning rate scheduler is a critical component of the training loop for neural networks, including those fine-tuned within Retrieval-Augmented Generation (RAG) pipelines. It dynamically adjusts the learning rate according to a predefined policy to optimize convergence and final model performance.

A learning rate scheduler is an algorithm that programmatically adjusts the learning rate—the step size for weight updates—during model training according to a predefined schedule or policy. It works by modifying the base learning rate after each epoch or batch based on rules like time-based decay, performance plateaus, or mathematical functions like cosine curves. The core mechanism involves the training loop calling the scheduler's .step() method after each optimizer update, which recalculates the learning rate for the next iteration. This dynamic adjustment helps navigate the loss landscape more effectively than a static learning rate, balancing rapid initial progress with fine-tuned convergence later in training.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.