Fine-tune a small open model
Train a small adapter (LoRA) on your dataset and prove with the test rows whether it beat the baselines.
You build: A trained adapter and a three-row table: classic baseline, untuned model, tuned model.
- An Apple Silicon Mac (mlx-lm) or a free cloud notebook with a GPU (PEFT)
- Lab 23 done
-
01Convert train and validation rows to chat format: the email in, the label out
head -n 1 data/train.chat.jsonlYou pass when: One JSON line with a messages list: a user message and a one-word assistant message.
-
02Score the untuned small model on the test rows
uv run eval_tuned.py --baseYou pass when: An accuracy number, usually below your classic baseline.
-
03Train an adapter and log training and validation loss every 50 steps
An adapter trains a few million numbers and leaves the model untouched, which is why it fits on a laptop.
tail -n 5 train.logYou pass when: Both losses went down from the first line of the log. The adapter is a small file, not a new model.
-
04Find the step where validation loss stops falling and keep that checkpoint
When training loss keeps falling and validation loss turns up, the model is memorising. Stop there.
uv run eval_tuned.py --adapter adapters/You pass when: A tuned accuracy on the same 30 rows. In RESULTS.md, say which step you kept and why.
The check runs on the computer, not on your word: a step passes when its command exits with 0 there.
Computers are not set up on this site yet. Run each command on your own machine and compare with "You pass when".
Commands run in labs/24-fine-tune and may take up to 60 seconds each. Every command starts a new shell: put keys and settings in a .env file there, it is loaded each time.