Fine-tuning

On this page 7

Fine-tuning is the process of continuing to train an already pretrained model on a smaller, task-specific dataset so that it adapts to a particular task, domain, output format or style. Instead of learning from scratch, the model starts from weights that already encode broad knowledge and adjusts them, which makes fine-tuning far cheaper than pretraining and effective with relatively little data.

In artificial intelligence, fine-tuning is the main form of transfer learning for large models. It covers several methods, from updating every weight to training small add-on matrices, and it is the stage in which a raw base language model becomes an instruction-following assistant or a specialist for one job.

How fine-tuning works

Fine-tuning uses the same gradient-descent training loop as pretraining, but with three key differences: the starting point is a pretrained checkpoint, the dataset is small and curated, and the learning rate is much lower so that existing knowledge is adjusted rather than overwritten.

For language models, each training example is usually a prompt and a target response. The loss is typically computed only on the response tokens, so the model learns what to answer, not how to repeat the question. Training runs for a small number of passes over the data, often one to five epochs, while a held-out validation set shows when the model starts to overfit.

The table summarizes how fine-tuning differs from pretraining in practice.

AspectPretrainingFine-tuning
Starting pointRandom weightsPretrained checkpoint
Data volumeTrillions of tokensHundreds to hundreds of thousands of examples
Data typeMostly unlabeled raw textCurated, task-specific examples
ComputeLarge GPU clusters for weeks or monthsOne to a few GPUs for hours or days
GoalGeneral language and world knowledgeSpecific behavior, format or domain
Pretraining and fine-tuning compared

Types of fine-tuning

Fine-tuning methods differ in which weights change and what kind of signal the model learns from. The choice drives cost, risk and the kind of improvement that is possible.

MethodWhat is trainedTraining signalTypical purpose
Full fine-tuningAll model weightsLabeled examplesMaximum adaptation when compute allows
LoRASmall low-rank matrices beside frozen weightsLabeled examplesEfficient task or style adaptation
QLoRALoRA matrices over a 4-bit quantized base modelLabeled examplesFine-tuning large models on one GPU
Supervised fine-tuningAll weights or adaptersPrompt and ideal response pairsInstruction following, output format
Preference tuningAll weights or adaptersPreferred versus rejected responses via RLHF or DPOHelpfulness, tone, safety
Continued pretrainingAll weightsUnlabeled domain textVocabulary and knowledge of a new domain
Main fine-tuning methods

Parameter-efficient methods change very few weights. For a single 4,096 by 4,096 weight matrix with 16,777,216 parameters, a LoRA adapter of rank 8 adds 8 times (4,096 plus 4,096), or 65,536 trainable parameters, about 0.39 percent of that matrix. Adapters can be stored separately and swapped per task on one shared base model.

Key settings and resource needs

Most fine-tuning outcomes depend on data quality and a few hyperparameters more than on the choice of framework. The ranges below are common starting points for language models, not universal rules.

SettingTypical starting rangeEffect if too high
Learning rate, full fine-tuningAbout 0.00001 to 0.00005Forgetting of general skills, unstable loss
Learning rate, LoRAAbout 0.0001 to 0.0003Overfitting to training phrasing
Epochs1 to 5Memorization of examples
LoRA rank8 to 64More memory with diminishing gains
Dataset sizeA few hundred to tens of thousands of examplesHigher cost; quality matters more than volume
Common fine-tuning hyperparameters

Memory is the practical constraint. Full fine-tuning with the Adam optimizer in mixed precision needs roughly 16 bytes per parameter for weights, gradients and optimizer states, so a 7-billion-parameter model needs about 112 GB before activations. With QLoRA, the frozen base model stored in 4 bits takes about 3.5 GB, which is why a 7-billion-parameter model can be fine-tuned on a single 24 GB GPU.

When to fine-tune and when not to

Fine-tuning is the right tool for teaching how to respond, not for supplying facts that change. Before fine-tuning, teams should confirm that prompting and retrieval cannot meet the goal, because those options are cheaper to build and easier to update.

SituationRecommended approachReason
Answers must reflect frequently updated documentsRetrieval-augmented generationKnowledge updates without retraining
Strict output format or schemaSupervised fine-tuningConsistency beyond what prompts achieve
Distinct brand voice or toneFine-tuning with LoRAStyle is learned from examples
High volume, narrow taskFine-tune a smaller modelLower latency and cost per request
Few examples, early prototypePrompting with examplesFast iteration, no training needed
Decision guide for model adaptation

Fine-tuning and retrieval are often combined: a model fine-tuned to use retrieved passages faithfully and answer in a fixed format, with facts supplied at request time.

Risks and common mistakes

The most frequent fine-tuning failures come from data problems and missing evaluation, not from the training code. Typical issues include:

  • Catastrophic forgetting: aggressive training erodes general abilities the base model had.
  • Overfitting: the model repeats training phrasing and fails on new inputs; validation loss rises while training loss falls.
  • Eroded safety behavior: even benign fine-tuning data can weaken refusals learned in alignment, so safety must be re-tested after training.
  • Inconsistent or wrong labels: the model faithfully learns the errors in its examples.
  • Test data leakage: evaluation examples that also appear in training data inflate scores.
  • No baseline: without comparing against a well-prompted base model, gains cannot be proven.

A sound process fixes a held-out test set before training, compares against the prompted baseline and checks both task metrics and general capability after every run.

The simple explanation

Fine-tuning is like giving an experienced professional focused on-the-job training. A pretrained model already knows a great deal about language in general; fine-tuning shows it hundreds or thousands of examples of one specific job until it does that job the way you want.

It works best for teaching habits such as a format, a tone or a narrow task. It is not a good way to teach facts that keep changing, because every change would require another round of training.

How it is used in practice

A software company receives thousands of support tickets a day and wants each one turned into a structured record: product, category, severity and a one-sentence summary in a fixed JSON format. A large general model prompted with examples handles the task, but it is slow and expensive at that volume, and about 18 percent of its records have a wrong field or a format error.

The team collects 4,000 tickets with verified records, keeps 500 more aside as a test set and fine-tunes an 8-billion-parameter open model with LoRA at rank 16 for three epochs on a single GPU. Training takes a few hours.

On the held-out test set, the fine-tuned small model produces correct records for about 95 percent of tickets, compared with about 82 percent for the prompted large model, and it runs at a fraction of the cost per request. The team retrains quarterly with newly corrected tickets so the model keeps up with new products and categories.