What is fine-tuning an LLM, and when should you do it?
Fine-tuning is continuing to train a pretrained language model on a smaller set of your own examples so it behaves differently: following a format, adopting a style or getting better at a narrow task. It changes the model's weights, unlike prompting or retrieval, which only change what the model sees.
Fine-tuning teaches a model how to behave; it is a poor way to teach it what to know. Most teams that reach for fine-tuning first would get a better result, sooner, from clearer prompts, examples or retrieval.
How does fine-tuning work?
Fine-tuning takes a model that has already been pretrained and runs more training on a much smaller dataset, usually hundreds to tens of thousands of examples of inputs paired with the outputs you want. The training nudges the model's weights so that, given similar inputs in future, it produces outputs like your examples. This is called supervised fine-tuning (SFT). Chat models are themselves built this way: a base model is fine-tuned on instruction-and-response examples, then refined further with preference training such as RLHF.
What is LoRA?
LoRA (low-rank adaptation), published by Microsoft researchers in 2021, is a way to fine-tune without updating all of a model's weights. It freezes the original model and trains small extra matrices added to certain layers. The paper reported cutting the number of trainable parameters for GPT-3 by about 10,000 times, with quality comparable to full fine-tuning on the tasks tested. QLoRA, from 2023, combined LoRA with a compressed 4-bit copy of the base model, making it possible to fine-tune a 65 billion parameter model on a single large GPU.
- Full fine-tuning
- Updating every weight in the model; most flexible and most expensive
- PEFT
- Parameter-efficient fine-tuning, a family of methods that train only a small number of extra parameters
- LoRA
- A popular PEFT method that trains small low-rank matrices alongside frozen weights
- Adapter
- The small set of trained extra weights, which can be swapped in and out of one base model
- Overfitting
- When a model memorises its training examples and gets worse on new inputs
Should I use fine-tuning, RAG or prompting?
Use prompting first, RAG when the model needs facts it does not have, and fine-tuning when you need consistent behaviour that prompts cannot reliably produce.
| Need | Best first tool | Why |
|---|---|---|
| Follow a new instruction or format | Prompt engineering and few-shot examples | Instant to change and test |
| Answer from company documents or recent data | RAG | Facts stay current and citable without retraining |
| A consistent style, tone or output format at scale | Fine-tuning | Behaviour is learned, so prompts get shorter |
| A narrow task done by a smaller, cheaper model | Fine-tuning | A tuned small model can match a large general one on one task |
| Specialised vocabulary or domain language | Fine-tuning plus RAG | Tuning adapts language; retrieval supplies facts |
Fine-tuning is weak at adding knowledge. A model tuned on your product manual may pick up its style and some facts, but it will still mix them with things it made up, and you cannot easily update it when the manual changes. Retrieval handles facts better because the source is visible and replaceable.
What does fine-tuning need?
- 1A clear goalWrite down the behaviour you want and how you will measure it before collecting data.
- 2A baselineMeasure the best prompt-only version on your eval set, so you know whether tuning helped.
- 3Good examplesHundreds of high-quality, varied examples usually beat thousands of noisy ones. Every flaw in the data is learned too.
- 4A held-out test setKeep examples out of training to check the model generalises instead of memorising.
- 5A plan for updatesBase models improve every few months; decide how you will re-tune or re-evaluate when they do.
Hosted APIs from OpenAI, Google and others let you fine-tune some of their models by uploading a file of examples. Open-weight models such as Llama, Mistral and Qwen can be tuned on your own hardware with LoRA.
- Do: Fine-tune to make outputs consistent, shorter or cheaper to produce
- Do: Compare against a well-prompted base model on the same test set
- Do: Keep the training data under version control with the resulting model
- Avoid: Fine-tune to teach facts that change
- Avoid: Skip the baseline; many fine-tunes turn out no better than a good prompt
- Avoid: Tune on examples you have not read
Frequently asked questions
What is the difference between fine-tuning and training from scratch?
Training from scratch builds a model from random weights using enormous amounts of data and compute. Fine-tuning starts from a model that is already trained and adjusts it with a small dataset, which is far cheaper and faster.
How many examples do I need to fine-tune an LLM?
It depends on the task, but useful results often start at a few hundred high-quality examples, and many projects use one to ten thousand. Quality and variety matter more than raw count.
Is fine-tuning better than RAG?
They solve different problems. RAG supplies up-to-date facts at answer time and is better for knowledge. Fine-tuning changes behaviour such as style, format or task skill. Many production systems use both.
Can fine-tuning make a model worse?
Yes. A model can overfit to narrow examples, lose some general ability, or learn mistakes present in the data. Always compare the tuned model with the base model on a held-out test set.
Last checked for accuracy on . Written by the solidcoder team.