How LLMs Work
What Is Fine-Tuning? Teaching a Model a Special Skill
Fine-tuning adapts a pre-trained model to a narrower job. What gets changed, why it is cheaper than starting again, what LoRA is, and the risks.
Training a large model from nothing takes enormous amounts of data and computing. Fine-tuning is the shortcut: start with a model that has already been trained, then train it a little more for a narrower job.
A base model plus a small set of chosen examples gives a fine-tuned model.
The definition
Wikipedia describes fine-tuning as adapting a model trained for one task (the upstream task) to perform a different, usually more specific, task (the downstream task). It counts as a kind of transfer learning, because it reuses knowledge learned in the first round of training. Technically, fine-tuning applies additional training to the parameters of a network that has already been pre-trained. If you want to know what parameters are, see what are parameters.
The athlete analogy
A young athlete first builds general fitness. Later they practise one sport. The general fitness is the first training. The sport practice is fine-tuning. The analogy has a limit: the model is not "tired" or "motivated", and its extra practice changes numbers in the network.
How much of the model changes?
There are several ways to do it:
- The whole network. Wikipedia says fine-tuning the full model is common and often gives better results, but costs more computing.
- Only some layers. The other layers are "frozen", meaning they are not changed during training. For image networks, it is common to freeze the early layers closest to the input, because they pick up low-level features such as edges, while later layers relate more to the specific task.
- Adapters. These are small extra modules added to the model. They have far fewer parameters than the original model, and only they are trained.
Instruction tuning, a research example
Wei and colleagues (2021) report that instruction tuning, which means fine-tuning language models on a collection of datasets described through instructions, substantially improves zero-shot performance on unseen tasks. This is the authors' finding, from the paper's abstract.
LoRA, a popular shortcut
Low-rank adaptation, called LoRA, is an adapter technique. Wikipedia explains that a language model with billions of parameters may be fine-tuned with only several million new ones. It lets people get results close to full fine-tuning with much lower memory needs. LoRA has become popular in the Stable Diffusion image community, and it is supported in tools from Hugging Face.
What it is used for
- Making a model better at a specialist field, such as a type of text.
- Making a model follow instructions or hold a conversation. Wikipedia notes that fine-tuning can be combined with reinforcement learning from human feedback to produce models such as ChatGPT. See RLHF.
- Giving a model a particular style or format.
Fine-tuning versus RAG
Fine-tuning changes the model. Retrieval-augmented generation leaves the model alone and gives it documents to read at question time. If you want a chatbot to know today's opening hours, looking them up is usually simpler than retraining. See RAG.
Risks and limits
Fine-tuning does not make a model flawless, and mistakes and gaps can remain. Wikipedia also notes that fine-tuning can reduce a model's robustness when the data it meets later looks different from the fine-tuning data. One mitigation it describes is to blend the fine-tuned weights with the original weights, which can retain much of the benefit while improving performance on unfamiliar data.
A good question for any fine-tuned product is: what examples was it tuned on, and who checked them?