AI Glossary: Fine-tuning
Fine-tuning is the process of adapting a pre-trained AI model to a specific task by continuing training on a smaller domain-specific dataset. It leverages existing knowledge to achieve high performance with less data and compute.
What is Fine-tuning?
Fine-tuning is a transfer learning technique where you take a machine learning model that has already been pre-trained on a large, general dataset, and you continue training it on a smaller, task-specific or domain-specific dataset. The goal is to adapt the existing knowledge the model already learned to the new specific task.
During pre-training, models learn general patterns, features, and representations from massive amounts of data. For example, a large language model learns grammar, facts, reasoning patterns, and language structure from trillions of tokens. A computer vision model learns edges, textures, shapes, and object concepts from millions of images.
Fine-tuning builds on this foundation. Instead of training a model from scratch—which requires enormous amounts of data, compute, and time—you take the pre-trained model and adjust its weights slightly to perform better on your specific problem.
Core Idea
Reuse general knowledge learned from big data and adapt it to your specific problem.
Key Benefit
Requires 10-100x less data and compute compared to training from scratch.
Common Use Cases
Text classification, sentiment analysis, named entity recognition, image segmentation, domain-specific chatbots.
Why Do We Need Fine-tuning?
Pre-trained models are general-purpose. A 7B parameter language model trained on internet text knows a lot about almost everything, but it may not be good at specific tasks like:
- Legal document analysis — requires understanding legal terminology and document structure
- Medical diagnosis — requires domain-specific knowledge and accuracy constraints
- Customer support automation — requires understanding your company's products and policies
- Code generation in a specific programming language or framework
Instead of training a whole new model from scratch (which would be prohibitively expensive), you can fine-tune an existing pre-trained model on your domain-specific data to get excellent performance.
Key Insight
The features learned during pre-training are generally useful across many tasks. Low-level features like edges in images or word semantics in text are transferable. Only higher-level features need to be adapted to the specific task. This is why fine-tuning works so well.
How Fine-tuning Works
The fine-tuning process follows a straightforward workflow:
- Start with a pre-trained model — You begin with a model that's already been trained on a large general dataset (e.g., BERT, GPT, ResNet, ViT).
- Modify the model architecture if needed — Sometimes you replace or add output layers to match your specific task requirements.
- Initialize with pre-trained weights — The model starts with all the knowledge it already learned.
- Train on task-specific data — You continue training using your smaller dataset, typically with a lower learning rate than pre-training.
- Update model weights — The model adjusts its internal weights to better fit the new task.
The fine-tuning workflow: start with pre-trained weights, train on task data, get a specialized model.
The Learning Rate Question
A key consideration in fine-tuning is the learning rate. You typically use a much lower learning rate for fine-tuning than you would for training from scratch. Why?
- The pre-trained weights are already good
- You just need to make small adjustments
- A high learning rate would overwrite good features and cause catastrophic forgetting
- A lower learning rate preserves the general knowledge while allowing adaptation
Common Fine-tuning Approaches
There are several approaches to fine-tuning, depending on your constraints and goals:
1. Full Fine-tuning
In full fine-tuning, you update all the parameters of the pre-trained model. This gives you the most flexibility and the potentially best performance, but it also requires the most compute and memory. For large models like 70B parameter LLMs, full fine-tuning is expensive.
2. Feature Extraction (Frozen Backbone)
In this approach, you keep the entire pre-trained model frozen (no updates to weights) and only train a classification or output head on top. This is the cheapest approach but typically gives lower performance because the features aren't adapted.
3. Partial Fine-tuning
You freeze the bottom layers (which capture general low-level features) and only fine-tune the top layers (which capture more task-specific high-level features). This is a good compromise between compute and performance.
4. Parameter-Efficient Fine-tuning (PEFT)
PEFT techniques keep the base model frozen and only train a small number of additional parameters. This gives performance comparable to full fine-tuning with much lower compute requirements.
LoRA (Low-Rank Adaptation)
Adds small low-rank matrices to transformer attention layers, only training those matrices.
Adapter Layers
Inserts small bottleneck layers into the model, only training those adapters.
Prefix Tuning
Keeps model frozen, only trains continuous prefix embeddings prepended to the input.
Prompt Tuning
Only trains soft prompt embeddings added to the input, keeping entire model frozen.
5. Progressive Unfreezing
This approach starts with the entire model frozen and gradually unfreezes layers from top to bottom during training. It helps preserve low-level features while adapting higher-level features gradually.
Best Practices for Fine-tuning
Following these best practices will help you get better results and avoid common pitfalls:
Data Preparation
- Clean your data — Fine-tuning is only as good as your data. Remove bad examples, correct errors, deduplicate.
- Use consistent formatting — Match the formatting the model expects in terms of prompt structure, special tokens, etc.
- Have a validation set — Always monitor performance on a held-out validation set to detect overfitting.
- Mix in some general data — If possible, include a small amount of general data to reduce catastrophic forgetting.
Training Hyperparameters
- Use smaller learning rates — Typically 1-10x smaller than pre-training. Common values: 1e-5 to 5e-5 for transformers.
- Use early stopping — Stop training when validation performance plateaus to avoid overfitting.
- Use batch size as large as your GPU allows — Larger batches give more stable gradients.
- Keep gradient accumulation in mind — If batch size is small, accumulate gradients over multiple steps.
Handling Catastrophic Forgetting
Catastrophic forgetting happens when fine-tuning causes the model to lose the general knowledge it had before. Strategies to mitigate:
- Use smaller learning rates
- Use parameter-efficient methods that only update a small subset of parameters
- Add regularization (weight decay, dropout)
- Use elastic weight consolidation to protect important weights
- Mix pre-training data into your fine-tuning batches
Pro Tip
When fine-tuning large language models for instruction following, use a learning rate around 2e-5 to 3e-5 and train for 3-10 epochs. Use early stopping based on validation loss. If you're using LoRA with rank 8-64, you can often use higher learning rates like 1e-4 since you're updating fewer parameters.
Fine-tuning vs Other Approaches
It's useful to understand how fine-tuning compares to other common approaches for leveraging pre-trained models:
| Approach | Parameters Updated | Compute Required | Memory Required | Performance | Best For |
|---|---|---|---|---|---|
| Training from scratch | All | Very High | Very High | Potentially best (needs huge data) | New architectures, novel domains |
| Full Fine-tuning | All | High | High | Excellent | Small-medium models, large datasets |
| PEFT / LoRA | < 1% | Low | Low | Very Good (close to full) | Large models, constrained compute |
| Feature Extraction | Only head | Very Low | Low | Good | Baselines, big model, small data |
| Prompt Engineering | None | None | None | Depends on task | Quick experimentation, APIs |
| RAG | None | Low (indexing) | Low | Good for knowledge retrieval | Up-to-date info, domain knowledge |
Fine-tuning vs RAG
A common question is when to use fine-tuning vs retrieval-augmented generation (RAG). The answer: they solve different problems.
- Use RAG when — You need the model to access specific, frequently changing information (e.g., your company's documentation, latest product specs). RAG retrieves relevant information at inference time and doesn't require changing model weights.
- Use Fine-tuning when — You need to adapt the model's behavior, output format, writing style, or to teach it new skills that require changing how the model thinks. Fine-tuning changes the model weights.
You can also use them together: fine-tune the model to follow instructions well, and use RAG to provide it with up-to-date specific information.
Frequently Asked Questions
Transfer learning is the broader concept of applying knowledge learned from one task to another task. Fine-tuning is a specific technique within transfer learning. In transfer learning, you might just use the pre-trained model as a feature extractor and only train a classifier on top. Fine-tuning means you actually update some or all of the pre-trained model's weights to better adapt to the new task.
It depends on the task and how different your domain is from the pre-training data. For simple classification tasks, you can get good results with hundreds or thousands of examples. For complex tasks like instruction tuning, you usually need thousands to tens of thousands of high-quality examples. The beauty of fine-tuning is that it requires dramatically less data than training from scratch.
Pre-training is the initial phase where a model is trained on a very large general dataset to learn general features and representations. This requires massive compute and data. Fine-tuning is the second phase where you take the pre-trained model and train it further on a smaller task-specific dataset to adapt it to your specific use case. Pre-training creates the general knowledge; fine-tuning adapts it to your needs.
Prompt engineering is free (no training needed) and works well when the model already has the capability but just needs guidance on output format. Use prompt engineering for quick experimentation, prototyping, or when you're using a black-box API you can't fine-tune. Use fine-tuning when you need to consistently get a specific behavior, style, or output format that's hard to achieve with prompting alone, or when you need to teach the model a new skill that it doesn't already know.
LoRA (Low-Rank Adaptation) is a parameter-efficient fine-tuning method that freezes the pre-trained model weights and injects small trainable low-rank decomposition matrices into the transformer layers. This means you only train a small percentage of the total parameters (often less than 1%), which drastically reduces memory and compute requirements while achieving performance very close to full fine-tuning. It's especially popular for fine-tuning large language models because you can fine-tune a 7B parameter model on a single consumer GPU.
Want to learn more about AI model training?
Check out our next entry on Zero-shot learning to continue expanding your AI knowledge.
Read Next: Zero-shot learning →