Module 4 — Optimization Algorithms
Optimization algorithms are the core of deep learning. They update neural network parameters to minimize the loss function and improve model performance. Every Transformer model, including BERT, GPT, LLaMA, Gemma, and Qwen, relies on these optimization techniques during training.
Topics
- Gradient Descent
- Stochastic Gradient Descent (SGD)
- Mini-Batch Gradient Descent
- Momentum
- RMSProp
- Adam
- AdamW
- Learning Rate Scheduling
1. Gradient Descent
Gradient Descent updates model parameters by moving them in the opposite direction of the gradient.
Formula
where
- = Model parameters
- = Learning rate
- = Loss function
- = Gradient
2. Stochastic Gradient Descent (SGD)
SGD updates parameters using one training sample at a time.
Formula
where
- represents the loss of a single training example.
3. Mini-Batch Gradient Descent
Mini-Batch Gradient Descent updates parameters using a small batch of samples.
Formula
where
- = Batch size
4. Momentum
Momentum accelerates optimization by accumulating gradients from previous updates.
Formula
Velocity Update
Parameter Update
where
- = Current gradient
- = Momentum coefficient
5. RMSProp
RMSProp adapts the learning rate for each parameter individually.
Formula
Gradient Average
Parameter Update
6. Adam Optimizer
Adam combines Momentum and RMSProp.
First Moment
Second Moment
Bias Correction
Parameter Update
7. AdamW
AdamW separates weight decay from gradient optimization.
Formula
where
- = Weight decay coefficient
8. Learning Rate Scheduling
Learning rate scheduling gradually changes the learning rate during training.
Exponential Decay
Step Decay
Cosine Annealing
Transformer Warmup Schedule
Used in the original Transformer paper.
Why Optimization Matters in Transformers
Optimization algorithms are responsible for training billions of parameters efficiently.
They are used in:
- Transformer Training
- BERT
- GPT
- T5
- Vision Transformers
- LLaMA
- Gemma
- Mistral
- Qwen
- DeepSeek
- Large Language Models (LLMs)
Summary
| Algorithm | Formula |
|---|---|
| Gradient Descent | |
| SGD |