How Fine-Tuning Actually Works

 


AI EXPLAINED

How Fine-Tuning Actually Works

A general-purpose chatbot knows a little about everything and nothing about your work. Fine-tuning is how you teach it your job, your format, and your voice — without training a model from scratch.

By Saksham Dogra · Oct 28, 2026 · 6 min read

Imagine you run a small support team. You want a chatbot that answers refund questions the way your team does: same tone, same steps, and always in the same tidy format your ticketing tool can read.

A general model won't do that reliably. It knows what a refund is, but it doesn't know your policy, your tone, or your format. You could paste instructions into every prompt, and that works up to a point. But the moment you want the behaviour baked in — consistent, every time, without a giant prompt — you're talking about fine-tuning.

Fine-tuning means changing the model, not just talking to it

A language model is, underneath everything, a giant pile of numbers called weights. They decide how it responds to any input. Prompting doesn't touch those weights — it just gives better instructions for one conversation. Retrieval doesn't touch them either; it just hands the model documents to read before it answers.

Fine-tuning is different. You show the model examples of the exact behaviour you want, and you let it adjust its weights so that behaviour becomes its default. It's the difference between telling someone how to do a job and actually training them to do it. As Google Cloud's fine-tuning guide puts it, the process starts with collecting and cleaning task-specific data, then splitting it into training, validation, and test sets.

So why doesn't everyone just fine-tune everything?

Because the straightforward version is brutally expensive. Full fine-tuning updates every single weight in the model. For a model with billions of parameters, that means huge amounts of GPU memory just to hold the training state, and a full copy of the model for every version you train.

The researchers behind LoRA gave a vivid example: deploying many independently fine-tuned copies of GPT-3, with its 175 billion parameters, is prohibitively expensive. Each copy is the whole model, all over again. And full fine-tuning on a narrow dataset can damage what the model already knew — a phenomenon called catastrophic forgetting, where the model gets better at your task and worse at everything else.

The LoRA trick: freeze the model, train a tiny sidecar

This is where LoRA comes in. LoRA stands for Low-Rank Adaptation, and it's the technique most real fine-tuning runs use today. The idea, from Hu and colleagues' 2021 paper, is almost cheeky in its simplicity: freeze the model's weights completely, then bolt on two tiny trainable matrices next to each weight you want to adapt. During training, only those tiny matrices change. The original model never moves.

Why does that work? Because the change a model actually needs for a new task turns out to be small — it lives in a much lower-dimensional space than the full weight matrix. The paper's name for this is "low rank": you don't need a full-size update, just a compact one that captures the direction of the change.

Here's the maths on one layer, using the example from a practical LoRA guide. A typical weight matrix in a 7-billion-parameter model is 4,096 by 4,096 — about 16.7 million numbers. With a rank of 8, LoRA replaces that update with two matrices totalling just 65,536 numbers. That's a 256-fold reduction, for one layer alone.

Across the whole model, the paper reports cutting trainable parameters by up to 10,000 times and GPU memory by 3 times compared to full fine-tuning — while matching or beating full fine-tuning on quality. And because the little matrices can be merged back into the original weights when training is done, there's no extra latency at inference time. The merged model is just a model.

A real fine-tuning run, step by step

Here's what a run actually looks like, using Hugging Face's PEFT library — the standard toolkit for this, documented in Hugging Face's LoRA guide.

1. Pick a base model that's already close to your task. If you want a support bot, start from an instruction-tuned model, not a raw base model. Fine-tuning steers; it doesn't build the car.

2. Format your examples exactly like real usage. This is the step people mess up most. If the model will see a chat template at inference time, your training examples must use that same template. Train on one format and deploy another, and the model will underperform for reasons that look mysterious but aren't.

3. Configure the adapter. The whole setup is a few lines:

from peft import LoraConfig, get_peft_model, TaskType

lora_config = LoraConfig(
    r=16,                  # rank: higher = more capacity
    lora_alpha=32,         # scaling factor, usually 2x the rank
    target_modules=["q_proj", "v_proj"],
    lora_dropout=0.05,
    bias="none",
    task_type=TaskType.CAUSAL_LM,
)
model = get_peft_model(model, lora_config)

The knobs that matter are rank (8, 16, or 32 to start), which layers get adapters (the attention layers q_proj and v_proj are the memory-efficient default), and the learning rate — around 2e-4 is a sensible default.

4. Train for a few epochs, and watch the validation set. An epoch is one full pass over your training data. Fine-tuning rarely benefits from more than two or three — past that, the model starts memorising your examples instead of learning the pattern.

5. Evaluate the adapter before you merge it. Test it on examples it never saw during training, and check two things: does it do your task well, and has it got worse at general stuff? Only merge it into the base weights once both answers look good.

On a single decent GPU, this whole loop is now routine. Combine LoRA with 4-bit quantization — the combination known as QLoRA, where the frozen base model is stored in 4 bits — and a 7-billion-parameter model can be fine-tuned on hardware most developers actually own.

What trips people up

Messy data. If your assistant replies mix JSON, YAML, and free prose, the model learns to be inconsistent. Pick one output schema and apply it to every single example.

Overfitting on a tiny dataset. Training loss keeps dropping, validation loss climbs, and the model starts parroting your examples word for word. The fix order is: reduce the rank, raise dropout, cut epochs, then add more data.

Expecting new knowledge. This is the big one. Fine-tuning is great at teaching style, format, and task behaviour. It's a poor way to teach facts. If your model needs to know this week's prices or your company's internal docs, that's a retrieval job, not a fine-tuning job — retraining every time a fact changes is a losing game.

Skipping the "did it get worse?" check. A model that nails your task but forgot basic reasoning is a liability. Compare against the base model on general prompts before shipping.

Should you fine-tune, or just prompt better?

Try prompting first. If a good prompt plus retrieved documents gets you most of the way there, stop — you've saved yourself a training pipeline. Reach for fine-tuning when you need consistency at scale: the same format on every one of ten thousand outputs, a tone no prompt reliably holds, or latency that rules out stuffing examples into every request.

That's the real test. Fine-tuning isn't magic. It's a tool for one job: making a behaviour permanent. When that's what you need, LoRA means you no longer need a data centre — a single GPU, a clean dataset, and an afternoon will get you there.

Try this first: take a small open model, write 50 examples of exactly the output format you want, and run a rank-16 LoRA job on them. You'll learn more from that one afternoon than from a week of reading about it — including, most usefully, where it breaks.

Questions people actually ask

Can I fine-tune a model on my own laptop?

For a small model, yes — that's what QLoRA is for. The base model is stored in 4-bit precision to save memory, and only the small LoRA matrices are trained at higher precision. A 7-billion-parameter model becomes feasible on a single consumer GPU; a frontier-scale model does not.

Will fine-tuning teach the model my company's private facts?

Only shallowly, and unreliably. Fine-tuning nudges the model toward patterns in your data; it doesn't build a reliable database in its weights. For facts that change or must be exactly right, pair the model with retrieval over your documents instead.



×