Fine-Tuning
Fine-tuning is a transfer learning technique where a pre-trained model is further trained on a smaller, task-specific dataset. This adapts the model's knowledge to a particular domain, style, or task without training from scratch.
For LLMs, fine-tuning can teach the model to follow specific output formats, adopt a particular writing style, or gain expertise in a niche domain. Common approaches include full fine-tuning (updating all parameters), LoRA (Low-Rank Adaptation, updating a small set of additional parameters), and QLoRA (quantized LoRA for memory efficiency).
Fine-tuning is appropriate when you need consistent behavior that prompt engineering alone can't achieve, when you have high-quality training examples, or when you need to reduce token usage by encoding instructions into the model's weights.
The process typically involves preparing a dataset of input-output pairs, choosing a base model, configuring hyperparameters (learning rate, epochs, batch size), and evaluating the fine-tuned model against a held-out test set.
How it works
Fine-tuning continues training a pre-trained model on a smaller, task-specific dataset, usually pairs of inputs and desired outputs. The model's weights are updated by gradient descent so that it produces outputs more like the examples, without training from scratch.
Full fine-tuning updates every weight, which for a large model needs a lot of GPU memory and produces a full-size copy per task. Parameter-efficient methods avoid this. LoRA freezes the original weights and trains small low-rank matrices added to Transformer layers; its paper reports that, compared with GPT-3 175B fine-tuned with Adam, LoRA can reduce the number of trainable parameters by 10,000 times and the GPU memory requirement by 3 times.
Fine-tuning is also how assistants are made. The InstructGPT paper fine-tuned GPT-3 with supervised learning on labeler-written demonstrations, then fine-tuned it further with reinforcement learning from human feedback based on rankings of model outputs; human evaluators preferred the resulting 1.3B-parameter model's outputs to those of the original 175B model.
The usual workflow is: collect and clean examples, hold some back for evaluation, train, then compare the tuned model against the base model and a well-prompted baseline on the held-out set. Without that comparison it is hard to tell whether the tuning helped.
Example
Fine-tuning data is commonly stored as JSON Lines, one training conversation per line. This illustrative record, wrapped here for readability but a single line in the file, teaches a fixed output format for support-ticket triage.
{"messages": [
{"role": "system", "content": "Classify the ticket. Reply as JSON."},
{"role": "user", "content": "I was charged twice for March."},
{"role": "assistant", "content": "{\"category\": \"billing\", \"priority\": \"high\"}"}
]} Hundreds of records like this teach the model the categories and the exact JSON shape, so production prompts can be shorter. If the category list changes, the model must be retrained, which is the main maintenance cost of fine-tuning.
Common confusion
Should facts be added to a model by fine-tuning or by RAG?
Facts that change or must be cited usually belong in retrieval: updating them means re-indexing documents rather than retraining. Fine-tuning suits consistent behaviour, such as a format, tone or classification scheme. Many systems use both.
Is LoRA different from fine-tuning?
LoRA is a type of fine-tuning. It trains a small set of added parameters instead of all the original weights, so it is cheaper to train and store, and several task adapters can share one base model.
Related tools & demos
- LoRA The most common parameter-efficient fine-tuning method.
- Prompt Playbook Prompting patterns worth trying before investing in a fine-tune.
- Local LLM Hardware Cheatsheet Memory and GPU guidance for running models locally.
- Self-Host vs API Calculator Weigh hosting a tuned open model against calling an API.
- Retrieval-Augmented Generation The usual alternative for adding knowledge.
Further reading
Want to learn more?
Explore more developer terms or read in-depth articles on the blog.
Browse all terms