Bookmarks

Fine-tuning

Further training of an existing model on your own data so that it handles a specific task better: style, answer format, domain terminology.

Also: fine tuning, finetuning, model tuning

checked 9 Nov

All terms

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.

ApproachWhat is trainedResourcesWhen to choose
Full fine-tuningall weightsa lot of memory and computationa large dataset and a markedly new domain
LoRA and other adaptersa small addition to the weights, fractions of a percentnoticeably less memory; the adapter is a separate filestyle, 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 pages

Verified 9 Nov

Not to be confused with

what it is mixed up with and how it differs

  • RAGretrieval-augmented generation

    RAG inserts the retrieved documents into the context without changing the weights; fine-tuning changes the weights and teaches behaviour — style and format.

  • LoRALoRA method

    LoRA is not a separate way of using a model but a fine-tuning method: a small addition to the frozen weights is trained instead of all the weights.

In depth in the references

where the topic is covered in detail

Appears in the references