Module 3 · Working with Your Own Data

Fine-tuning: when training is worth it

Lesson 7 of 15 9 min lesson Updated on October 30, 2026
Progress in the course47%

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.

Three rungs, from cheapest to most expensive

Every "the model doesn't do what I want" has three solutions, in order of cost.

RungGood forExample
1. PromptTone and format"Answer in 3 lines, with the deadline at the end"
2. Document searchCompany facts that changeThis month's price list
3. Fine-tuningA stable style or taskSorting 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

  1. Do the memory math for a model you want to use: parameters times 18 bytes. Does it fit on your card?
  2. Write twenty pairs of a question and its ideal answer for a task of yours and set five aside for testing.
  3. Write three yes-or-no criteria for grading the answers.
Deliverable: a file called "Fine-tuning plan", with the memory math, the decision between prompt, search and fine-tuning, the examples and the criteria.

Summary

Sources

Read on October 30, 2026.

  1. Hugging Face. GPU memory usage: training memory per parameter.
  2. Hugging Face. LoRA conceptual guide.
  3. Dettmers, T. et al. QLoRA (2023).

Lesson quiz

Three situations to apply what you learned.

Lesson 7 of 15

Before moving on to the next lesson

Put what you saw into practice. The boxes stay checked in this browser, so you can come back later.

Have a question about this lesson? The IV Help team answers personally on WhatsApp.

Ask on WhatsApp