Phase 8: Fine-tuning
Change how a model behaves, and prove it helped. Fine-tuning teaches a model a style, a format or a narrow skill, not new facts. It is the last rung after prompting and RAG, and it only pays off with clean data, a cheap method such as LoRA, and a fair test against the base model. This phase shows how to decide, prepare, train and judge.
After this phase you can
- Decide between prompting, RAG and fine-tuning, with a break-even calculation
- Prepare a dataset: validate, de-duplicate, scrub, split without leakage, mask the loss
- Size a LoRA or QLoRA run and judge the result against the base model on held-out data
Before you start: Phase 3, especially fine-tuning, quantization and LoRA. Basic Python. No GPU is needed for the code here.
Lessons in this phase
- Prompting vs RAG vs Fine-Tuning Beginner · 9 min
Prompting changes what you ask, RAG changes what the model can see, and fine-tuning changes how the model behaves, so you pick the cheapest one that fixes your actual problem and you do the sums before you train.
- Supervised and Instruction Tuning Intermediate · 10 min
Supervised fine-tuning (SFT) shows a model finished conversations and trains it to predict the assistant's tokens, with the loss switched off on everything else.
- Dataset Preparation Intermediate · 10 min
A small, clean, correctly split dataset beats a large messy one, so you validate every record, remove duplicates, scrub personal data, split by group so nothing leaks into the test set.
- LoRA in Depth Intermediate · 11 min
LoRA freezes a weight matrix W and learns two thin matrices B and A whose scaled product is added to it, W' = W + (alpha/r) B A, so you train a fraction of a percent of the parameters.
- QLoRA and Quantized Training Advanced · 10 min
QLoRA keeps the base model frozen in 4-bit NormalFloat (NF4) to shrink its memory, trains ordinary LoRA adapters in higher precision on top, and uses two more tricks named in the paper.
- Training Pipelines and Hyperparameters Intermediate · 10 min
A fine-tuning run is a loop with a handful of dials (learning rate, epochs, batch size, accumulation, warmup), and you steer it by reading the training and validation loss curves, saving checkpoints.
- Evaluating Fine-Tuned Models Advanced · 12 min
You only know a fine-tune helped if it beats the base model on held-out examples it never saw, with a margin of error you can defend, no regressions on things that used to work.