Optimization in Transformers
Optimization in Transformers
- Estimated duration
- 25 minutes
- Related questions
- 2
- Related algorithms
- 3
- Status
- Log in to track
Lesson objectives
- Know the sensitive hyperparameters of transformers.
- Understand the limits of metaheuristic methods with large models.
- Get to know parameter-efficient fine-tuning.
Explanation
Transformers are large and costly, and optimization focuses on fine-tuning and its hyperparameters rather than on the weights directly.
Sensitive hyperparameters: the learning rate, Warmup and learning-rate schedule, batch size, weight decay, Dropout, and the number of fine-tuning epochs. In parameter-efficient fine-tuning (such as LoRA), the matrix rank and the scaling factor are added.
Why are swarm algorithms not used to update the weights of a large transformer? Because there are millions or billions of weights, and the gradient is available and efficient. Metaheuristics keep a role in the outer space: hyperparameters, architecture (the number of layers and heads in small models), and sometimes data or prompt selection.
Empirical evidence on transformers in the lab repository is scarce, so most relationships appear in the Explorer with the status "theoretical fit".
Mathematics
Linear warmup then decay
\eta_t = \eta_{max}\cdot\min\left(\frac{t}{t_w}, \sqrt{\frac{t_w}{t}}\right)The original paper's formula also uses d_model^{-0.5}.
Python code
def warmup_rsqrt(step, warmup=4000, peak=1e-3):
step = max(step, 1)
return peak * min(step / warmup, (warmup / step) ** 0.5)Simplified teaching code that works with NumPy only; for research experiments use a documented library and fix the random seed.
Practical exercise
In the Explorer open Transformer and BERT and note the evidence status of each optimization relationship.
Common mistakes
- Trying to train the weights of a language model with a swarm algorithm.
- Generalizing results from small models to large ones.
Summary
In transformers the gradient stays for training weights, metaheuristics serve hyperparameters and small architectures, and registered evidence is limited.
References
There are no references recorded for this lesson.
Short quiz
2 questions are chosen at random from 2 questions linked to this lesson, and the quiz is graded on the server.
Links within the lab
- Algorithms
- Models
- Optimization types
- Related lessons
- In the paths
