When to tune, and what it costs
- Production
- 40 min
- Lesson 1 of 7 in Fine-tuning
- Last verified
Select text in the lesson first to keep it with your note. With the keyboard, move focus here and press the button: the note goes with the section you are reading.
In this module
On this page
Before you start
- Completed:Fine-tuning vs RAG vs promptingEvaluation and model adaptation
- Completed:Fine-tuning methods: SFT, LoRA, QLoRA and DPOEvaluation and model adaptation
You will be able to
- Classify a failure as missing knowledge, wrong behaviour, or cost and latency, say whether tuning is justified, and name the baseline a tune must beat.
- Write the break-even for a tuning project from its one-off, hosting and maintenance costs, and test it against a cheaper alternative such as prefix caching.
- Estimate the model-state memory of full fine-tuning with Adam, LoRA and QLoRA, and name what that estimate leaves out.
- Estimate training compute and time from parameters and tokens, and explain why LoRA saves memory far more than it saves compute.
Aarav keeps getting the same three kinds of message wrong: delays, address changes and cancelled orders. Kavya has a folder of example conversations ready.
Every training run takes the model off the line for an afternoon and costs real money. Ananya reads the three kinds twice and says nothing.
What does she want to see before anyone starts training?
Concept
The training run in the story is fine-tuning: continuing to train an already pretrained model on a smaller, task-specific dataset, so that its weights change. Everything else you do to a model (a better prompt, retrieved documents, tools) changes what goes in. Tuning changes the model itself.
You already know the first-pass choice between prompting, retrieval and tuning from Fine-tuning vs RAG vs prompting, and the methods (SFT, LoRA, QLoRA, DPO) from Fine-tuning methods. This lesson goes one step deeper, to the questions that decide whether a project is approved: what exactly failed, what it will cost, how much memory and compute the run needs, and how the project loops from data to a shipped model. The arithmetic is the part interviewers like to check, so every figure below is derived, with its assumptions in plain sight.
Why It Matters
“Should we fine-tune?” is usually answered with a feeling. A better answer is a short calculation and a test. Two mistakes are common. One is to tune when the real failure is missing or stale facts, which tuning handles poorly. The other is to approve a project that is right in principle but loses money once hosting, re-tuning and a cheaper alternative are counted. A candidate who can size the memory of a run on a whiteboard, and say what the estimate leaves out, shows they have thought about the real work.
Mental Model
Think of a tuning project as a booking you have to justify. Before booking it you want three things: proof that the same mistake keeps recurring (not a one-off), the best result you could already get without tuning (the baseline), and an honest bill for the run, including the runs you will repeat when the base model is replaced.
Where the analogy breaks: a person keeps what rehearsal taught them when they move to a new job. A tuned model is tied to its base model. When you switch to a newer base, you repeat the rehearsal.
Reading the failure
Start from the symptom, not from the technique. Sort the failure into one of three kinds, because each points to a different lever.
| Failure kind | Example symptom | Usual lever |
|---|---|---|
| Missing or changing knowledge | Wrong price, outdated policy, no source to cite | Retrieval or tools |
| Wrong behaviour | Format drifts, tone is off, a routine is skipped | Better prompt and examples first; tuning if that is not enough |
| Cost or latency | Long instructions on every call, or a large model for a narrow task | A smaller or cached setup; tuning or distillation if those fall short |
Why knowledge is the weak case for tuning: weights cannot cite a source, cannot be updated by editing one document, and cannot hide a document from one user. The research also points one way. Ovadia et al. (2024) compared the two for injecting knowledge and report that retrieval beat unsupervised fine-tuning, both for facts the model had seen in training and for new ones. Gekhman et al. (2024) found that examples introducing new facts were learned slowly, and that as the model fit them its tendency to hallucinate rose. These are particular experiments, so treat them as evidence about the mechanism, not as a law. The earlier lesson covers the full list of limits.
Legitimate reasons to tune follow from the other two rows:
- A format or routine that a strong prompt with examples still gets wrong at volume.
- A small model that must match a large one on a narrow task, to cut cost or latency (distillation is one way).
- A consistent tone or policy across millions of calls.
- A long fixed prefix of instructions and examples that you would rather bake in than pay for on every call.
- A requirement to run an open model you host yourself.
Weak reasons: “so it knows our wiki”, “to stop hallucinations”, “no evaluation set yet”, or “competitors do it”. There is no universal minimum number of examples. The earlier lesson says the right number depends on the task and advises starting small and measuring.
The test that follows from all this is a gate, not a feeling: the tuned model must beat the best prompt-plus-retrieval baseline, on the newest base model you could use, on a held-out evaluation set. A baseline that is a lazy first-draft prompt makes any tune look good.
The economics
Write the formula before the caveats.
The saving per call is either the tokens you no longer send () or the price gap between the large model and the small tuned one.
The one-off cost covers data creation and labelling, training, and evaluation.
Worked example (illustrative figures)
A pipeline sends a 1,500-token instruction-and-examples prefix on 2 million calls a day. That is billion input tokens a day. Every price and cost below is an assumption for the exercise, not a quote. Use your own.
| Assumption | Value |
|---|---|
| Input price | $1 per million tokens |
| Extra hosting for the tuned model | $800 per day |
| One-off cost (data, training, evaluation) | $30,000 |
| Re-tune after a base-model change | $10,000 every 90 days |
- Gross saving: a day.
- Maintenance spread over its interval: a day.
- Net saving: a day.
- Payback: days.
Looks like an easy yes. Now test the cheaper alternative. Suppose your provider caches a repeated prefix and bills cached input at 10 percent of the normal rate (an assumption; caching rules and discounts differ by provider, so check yours). The prefix then costs about $300 a day, not $3,000. Baking it into a model can save at most that $300, which is less than the $800 hosting bill. The same project is now a loss.
The lesson in the example is not the numbers. It is that the baseline moves. Compute the saving against the cheapest competent alternative, not against the current setup. See Cost and latency for the levers that make the baseline cheaper.
| Aspect | Against the current setup | Against provider prefix caching (10% rate) |
|---|---|---|
| Gross saving per day | $3,000 | at most $300 |
| Extra hosting per day | −$800 | −$800 |
| Maintenance per day () | −$111 | −$111 |
| Net per day | +$2,089 | −$611 |
| Payback of the $30,000 one-off | about 14 days | never: a loss |
Two more costs people forget:
- The model treadmill. Base models improve every few months. A tune is frozen to the base it was trained on. Budget for re-tuning, or for the day a better base with a good prompt beats your tune. Before you re-invest, re-run the baseline on the newest base.
- Evaluation and labelling. In many projects these cost more than the training run, as the illustrative example below suggests.
Memory for training
Training stores far more than the weights. For a model with parameters trained with the Adam optimiser in mixed precision, the ZeRO paper counts the model states like this: bytes for 16-bit parameters, bytes for 16-bit gradients, and an optimiser-state term it writes as with for Adam. That term is a 32-bit copy of the parameters, the momentum and the variance, at 4 bytes per parameter each. The total is , that is 16 bytes per parameter. The paper’s own example is a 1.5-billion-parameter model needing at least 24 GB, which is billion.
| What is stored during full fine-tuning | Bytes per parameter |
|---|---|
| 16-bit parameters | 2 |
| 16-bit gradients | 2 |
| Optimiser state: 32-bit parameter copy, momentum, variance | 12 |
| Total model states | 16 |
LoRA and QLoRA change the arithmetic because the base model is frozen. A frozen weight needs no gradient and no optimiser state, so it costs only its storage: 2 bytes per parameter in 16-bit, about 0.5 bytes in 4-bit. Only the small adapter pays the 16 bytes.
For the table, assume the adapter holds 0.5 percent of (an assumption; it depends on rank and which matrices you adapt). Sizes are in decimal GB.
| Model | Full fine-tune | LoRA, 16-bit base | QLoRA, 4-bit base |
|---|---|---|---|
| 7B | 112 GB | 14.6 GB | 4.1 GB |
| 13B | 208 GB | 27.0 GB | 7.5 GB |
| 70B | 1,120 GB | 145.6 GB | 40.6 GB |
Read the table with three cautions.
- It is a floor. It leaves out activations, the temporary tensors of the forward and backward passes, framework overhead, and the extra constants a 4-bit format stores. These grow with batch size and sequence length and can add many gigabytes. A real plan adds them.
- The logits are one of the big ones. The output tensor has one value per token per vocabulary entry. For 16,384 tokens in a batch, a vocabulary of 128,000 and 4 bytes each, that is for a single tensor.
- What it means for hardware. Full fine-tuning of a 7B model needs 112 GB of states, more than one 80 GB card holds, so it must be spread over several GPUs or offloaded (lesson 4). LoRA on 7B comes to about 15 GB of states, so a 24 GB card is plausible at a modest batch size and sequence length. QLoRA on 70B comes to about 41 GB of states, close to the limit of a 48 GB card before activations, so batch size and sequence length decide whether it fits at all.
The LoRA paper’s headline figures (see Fine-tuning methods) show the same pattern: its memory saving is far smaller than its parameter saving, because the frozen base still has to be stored and the activations are unchanged.
Compute and time
For a dense transformer, the common estimate for training compute is about floating-point operations, where is the number of parameters and is the number of tokens processed. Kaplan et al. give the form per training token, built from about for the forward pass and a backward pass of about twice the forward cost. Kaplan et al. do not split the backward pass further. The split into two halves is a first-principles approximation: roughly 2 for the forward pass, 2 for the gradient with respect to each layer’s inputs, and 2 for the gradient with respect to the weights. The paper’s counts non-embedding parameters, so the estimate is approximate.
Now apply it to LoRA. The frozen layers still need the input gradients, because the signal has to flow back through them to reach the adapters. They skip the weight gradients, the third “2”. So LoRA costs roughly , about two thirds of full fine-tuning, plus a small adapter term. This is a derivation, not a measurement. The LoRA paper reports a 25 percent training speedup on GPT-3 175B against full fine-tuning (section 4.2), which fits a saving of about a third once overheads are counted. LoRA is a memory trick much more than a compute trick. Anyone who says it makes training a hundred times cheaper in compute has mixed up the two.
| Part of one training step | Full fine-tune | LoRA |
|---|---|---|
| Forward pass | ||
| Gradients flowing back through layers | ||
| Gradients for the weights | only the small adapter | |
| Total | about |
Activation checkpointing, which re-runs part of the forward pass to save memory, adds some compute on top.
Wall-clock time is FLOPs divided by the compute you actually sustain, which is the hardware’s peak times its utilisation. The share of peak you reach is called model FLOPs utilisationModel FLOPs utilisation (MFU)The share of a GPU's peak arithmetic rate that a training job actually sustains. Wall-clock time is the job's FLOPs divided by peak times MFU.Open the glossary entry. Vendor headline figures can be misleading: NVIDIA’s H100 page, for example, marks its bf16 teraFLOPS figure as “with sparsity”, so do not divide by a headline number. Measure the sustained rate on your own job, or assume a round figure and say so.
Worked example (illustrative)
A 7B model, a dataset of 10 million tokens, 3 epochs, so million tokens. Assume the job sustains 400 TFLOP/s on one GPU.
- FLOPs: .
- Time: , about 53 minutes.
- LoRA: two thirds of that, about 35 minutes.
At an assumed $3 per GPU-hour, the full run is under $3 of compute. This ignores the memory problem (it does not fit one 80 GB GPU, so in practice you use several and lose some efficiency) and runs many times as you iterate. The point is the proportion: for a small job, compute is often cheaper than the labelling and the evaluation. Do not spend the whole planning effort on GPU hours.
# Illustrative: a calculator for the numbers above. Assumptions are arguments.
def state_gb(params_b, mode, adapter_frac=0.005):
p = params_b * 1e9
adapter = 16 * adapter_frac * p
base = {"full": 16 * p, "lora": 2 * p + adapter, "qlora": 0.5 * p + adapter}
return base[mode] / 1e9
def train_hours(params_b, tokens_m, epochs, sustained_tflops, lora=False):
flops = 6 * params_b * 1e9 * tokens_m * 1e6 * epochs
if lora:
flops *= 2 / 3
return flops / (sustained_tflops * 1e12) / 3600The project loop
A tuning project is a loop, not a line.
The loop that matters is evaluate, fix the data, retrain. Most disappointing results are data or evaluation problems, not hyperparameter problems. Lesson 2 covers the data; lesson 6 covers the gate.
Real-World Application
A team wants a support bot to answer from 5,000 help articles and asks to fine-tune a 7B model on them. A good response: the failure is knowledge, so retrieval comes first. If after retrieval the bot still answers in the wrong format, that is a behaviour failure, and a small LoRA run on a few thousand clean examples of the format may be justified. Then size it: about 15 GB of model states with LoRA plus activations, under an hour of compute on the example scale, and a gate against the best prompt-plus-retrieval baseline. If a hosted provider’s tuning product is an option, compare its price and limits with self-hosting before deciding.
Interview Perspective
Expect: “When would you fine-tune instead of using RAG?”, “How much memory does it take to fine-tune a 7B model?”, “Is LoRA cheaper in compute?”, “How would you justify the cost?”.
A strong answer separates knowledge from behaviour, names the baseline and the held-out evaluation, states the 16-bytes-per-parameter rule with Adam and what LoRA and QLoRA change, gives 6ND and the two-thirds point for LoRA, and mentions maintenance and the model treadmill. Common mistakes: comparing against a weak prompt, forgetting activations, and claiming LoRA saves a hundredfold in compute.
Provenance: Common industry pattern. These are questions this topic tends to draw; none is verified for a named company. Numbers are estimates, so state your assumptions aloud.
Practice Questions
Provenance: generated practice.
- Basic: Give three good and three weak reasons to fine-tune.
- Intermediate: Why does full fine-tuning of a 7B model need about 112 GB of states, and how does LoRA change that?
- Advanced: A pipeline sends a 1,000-token prefix on 5 million calls a day. Compare prefix caching, a distilled small model and a LoRA-tuned mid-size model on cost, quality risk and maintenance.
- Product: A manager wants a tune “because it will pay for itself in a month”. What do you ask for before agreeing?
Activity
Do, notice, apply.
- Do. Using the formulas, compute the model-state memory for a 13B model under full fine-tuning, LoRA and QLoRA with a 0.5 percent adapter.
- Notice. Which of the three still does not fit a single 80 GB card, and which numbers did you leave out?
- Apply. Pick a feature you know. Write its break-even with your own assumptions, then replace the baseline with the cheapest alternative you can think of and see whether the answer survives.
Homework
Write a one-page go or no-go note for a fine-tuning proposal of your choice. Include the failure kind, the baseline and its measured score, the break-even with every assumption labelled, the memory and compute estimate for one model size, and the condition under which you would re-run the decision.
Quick Revision
- Retrieval for what the model should know; tuning for how it should behave.
- A tune must beat the best prompt-plus-retrieval baseline on the newest base, on a held-out set.
- . The baseline can move, for example with prefix caching.
- Full fine-tuning with Adam in mixed precision: about 16 bytes per parameter in states, before activations.
- LoRA and QLoRA pay 16 bytes only for the adapter; the frozen base costs 2 or about 0.5 bytes per parameter.
- Training compute is about 6ND; LoRA is about two thirds of that, so it saves memory, not a hundredfold in compute.
Check yourself
- Checkpoint (answer aloud, no notes): A PM wants to tune on 5,000 support articles so the bot answers accurately. Walk through your decision, and if tuning is justified, estimate memory and time for a 7B model.
- Re-test (nearby variant): Repeat for a 70B model with 20,000 labelled extraction examples on one 80 GB GPU. What do you drop or accept?
- Misconception to avoid: “LoRA makes training about 100 times cheaper in compute.”
Related
Resources & Further Reading
Checked sources to go deeper. The essential ones come first in each group.
Official documentation
Automatic Prefix Caching (opens in a new tab)
The self-hosted counterpart to provider caching; price this rival before baking a long prefix into weights.
Further reading
LoRA Without Regret (opens in a new tab)
A practitioner write-up of when LoRA matches full fine-tuning, which layers to adapt and how to set the learning rate; useful before you commit to a full run.
Research papers
LoRA Learns Less and Forgets Less (opens in a new tab)
A measured comparison that finds LoRA learns less than full fine-tuning on code and maths but forgets less, which tempers the memory-saving story.
More for this module: Fine-tuning resources
Practice
Test what you just read. Quizzes and cards are grouped by module: Fine-tuning.
Check yourself13 questions on what this lesson set out to teach
Checking answers needs JavaScript. You can still read every question and option below.
Keyboard: arrow keys move between options. Space or Enter selects the focused option.