Lessons › Chapter 11: Transformers and LLMs
Fine-tuning and LoRA
After pretraining you have a model that knows a lot about language in general. Now you want it to do your task, in your style.
Watch it move. This lesson is interactive on Gradient Lab: every step is an animated scene you can replay.
Start the interactive lessonStep by step
Teach it Brightbank
The base model knows nothing about Brightbank’s products or tone of voice.
A big, general model
After pretraining you have a model that knows a lot about language in general. Now you want it to do your task, in your style.
Full fine-tuning is heavy
You could keep training every weight on your examples: full fine-tuning. For billions of weights that takes a lot of memory and computing power, and a full copy of the model for every task.
LoRA: small add-ons
lora freezes the big model and bolts small adapter matrices onto some layers. Only the adapters are trained: a few million numbers instead of billions. Quality is often close to full fine-tuning.
Swap adapters, switch skills
Because adapters are tiny, you can keep one per task: one for customer support, one for legal summaries. Clip in the adapter you need, keep one shared base.
In real life: an assistant that knows your company
Companies fine-tune models on their own support conversations and style guides, so the assistant uses their product names, tone and procedures, without training a model from scratch.
Quick check: What does LoRA train?
- Small added adapter matrices (correct)
- Every weight from scratch
- Only the tokenizer
The base is frozen; only the small low-rank adapters are trained.
Pseudocode
base = a pre-trained language model (billions of weights) freeze base adapter = two small matrices added beside some layers # LoRA train only the adapter on your own examples # a few million trainable weights instead of billions # swap adapters to switch between tasks
Key terms
- fine-tuning
- Continuing to train a pre-trained model gently on your own data.
- lora
- Low-rank adaptation: fine-tuning by training small add-on matrices instead of the whole model.