In this lesson
Fine-tuning is the last tool.
Fine-tuning a model means training a ready-made model on your own examples. It is powerful, but expensive and easy to get wrong. Before you train, it pays to try cheaper paths.
- Decide between a prompt, document search and fine-tuning
- Understand what LoRA is, without formulas
- Measure the result without fooling yourself
Three rungs, from cheapest to most expensive
Every "the model doesn't do what I want" has three solutions, in order of cost.
| Rung | Good for | Example |
|---|---|---|
| 1. Prompt | Tone and format | "Answer in 3 lines, with the deadline at the end" |
| 2. Document search | Company facts that change | This month's price list |
| 3. Fine-tuning | A stable style or task | Sorting emails into six departments |
A quick test: write twenty examples of a question and its ideal answer in a spreadsheet. If you can, you have training data. If you can't, fine-tuning will not help.
The memory math
Training is more than just using the model. During training, the computer keeps several copies of each number: the weights, the gradients (which say which way each number should move) and the optimizer state (which guides each step). According to the Transformers documentation, it all adds up to about 18 bytes per parameter, before counting the activations.
A 7-billion-parameter model takes up about 14 GB just to use. To train all of it, the total goes past 100 GB. That does not fit on an ordinary card.
What the pros know
Anyone who has watched a training run blow past the memory knows this: the math for using a model is not the math for training it. The Transformers documentation lists what mixed-precision training keeps per parameter: 6 bytes for the weights, 8 for the Adam optimizer and 4 for the gradients. That adds up to 18 bytes, and the activations, which vary with the batch, still come on top. Multiply by 7 billion and the total goes past 120 GB. That is why professionals do this multiplication before renting or buying a card, and turn to adapters such as LoRA.
LoRA and QLoRA: training a small part
With LoRA, the whole model stays frozen and you add pairs of small matrices to some of the layers. Only those matrices are trained. Memory use drops a lot, and the result is a file of a few megabytes that sits on top of the base model. You can have ten adapters for ten subjects, all on the same model.
QLoRA goes further: it loads the base model compressed, in 4 bits, and trains only the adapters. That way, a model of 7 to 8 billion parameters fits on a 16 to 24 GB card. The trade-off is a little quality and a little speed.
Split the data before anything else
Split the data into three parts. The training set adjusts the model. The validation set decides when to stop. The test set is read only once, at the end, and it gives the number you report. If validation and test are the same set, the result comes out inflated.
Careful
The model memorizes what it sees. Customer names, CPF numbers (the Brazilian individual taxpayer ID) and phone numbers in the training data can resurface in the answers, and that is a personal data incident. Replace the identifiers with generic placeholders before you train.
Measuring without fooling yourself
In classification, accuracy is misleading when one class is rare. Use the F1 score for each class. For text generation, no automatic metric replaces reading. Write thirty test questions before training, grade each answer with yes-or-no criteria, such as "did it follow the format?", and compare the base model with the fine-tuned one without knowing which is which.
Example: an accounting firm wants to route emails to six departments. If the fine-tuned model does not beat a simple set of rules on the test, the fine-tuning does not pay for itself.
Practice · 5 min
- Do the memory math for a model you want to use: parameters times 18 bytes. Does it fit on your card?
- Write twenty pairs of a question and its ideal answer for a task of yours and set five aside for testing.
- Write three yes-or-no criteria for grading the answers.
Summary
- Try the prompt first, then search, and only then fine-tuning.
- Training costs about 18 bytes per parameter. Adapters bring that down.
- Split training, validation and test. The test set is read once.
- Remove personal data before you train.
Sources
Read on October 30, 2026.
- Hugging Face. GPU memory usage: training memory per parameter.
- Hugging Face. LoRA conceptual guide.
- Dettmers, T. et al. QLoRA (2023).
Lesson quiz
Three situations to apply what you learned.
Isaque Victor free courses