A pre-trained model can already work with language and code, but it only knows what it saw during training and writes in the style that prevailed in its training set. Fine-tuning continues its training on a comparatively small set of your own examples: the model is not trained from scratch but re-tuned — hence the name fine-tuning, from “fine tuning”.
How fine-tuning works
A model with ready-made weights is taken, and training continues by the same method as in pre-training: the loss function is computed on labelled examples, and the weights are adjusted by gradient descent. Fine-tuning is usually done on “instruction — correct answer” pairs, on dialogues or on texts in the desired style, and the result is checked on held-out examples: a small training set overfits easily, and the model starts repeating what it has memorised instead of generalising.
Full fine-tuning and LoRA
With full fine-tuning, all the weights of the model change: the optimiser stores its states for every parameter, so a great deal of memory and computation is needed. The economical path is adapters (PEFT): the weights of the base model are frozen and only a small addition is trained, which is easy to store and share. The LoRA method (2021) inserts low-rank matrices into selected layers: by the authors’ estimate for GPT-3 with 175 billion parameters, fine-tuning requires three times less GPU memory and 10,000 times fewer trainable parameters — the adapter checkpoint is 35 MB against 350 GB for a model fine-tuned in full without an adapter.
| Approach | What is trained | Resources | When to choose |
|---|---|---|---|
| Full fine-tuning | all weights | a lot of memory and computation | a large dataset and a markedly new domain |
| LoRA and other adapters | a small addition to the weights, fractions of a percent | noticeably less memory; the adapter is a separate file | style, answer format, language; one base — many adapters |
Fine-tuning or RAG
Fine-tuning changes the model’s behaviour but does not add fresh facts to it: knowledge is frozen as of the training date, and repeating the fine-tuning cycle on every document update is expensive. When the model needs up-to-date or private documents, RAG is the choice — before the answer, the retrieved fragments are inserted into the context and the weights are left untouched. A working rule: a knowledge problem calls for RAG, a behaviour problem for fine-tuning; the two are often combined.
Sources
the term is written from these pagesVerified 9 Nov