When to tune, and what it costs

  • Production
  • 40 min
  • Lesson 1 of 7 in Fine-tuning
  • Last verified

Open slides(30 slides)

Before you start

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 kindExample symptomUsual lever
Missing or changing knowledgeWrong price, outdated policy, no source to citeRetrieval or tools
Wrong behaviourFormat drifts, tone is off, a routine is skippedBetter prompt and examples first; tuning if that is not enough
Cost or latencyLong instructions on every call, or a large model for a narrow taskA smaller or cached setup; tuning or distillation if those fall short
Diagram: Start from the symptom.

Missing or changing knowledge

Wrong behaviour:
format, tone, skipped routine

still wrong at volume

Cost or latency

still too costly

A recurring failure

What kind is it?

Retrieval or tools

Better prompt and examples first

Consider tuning

Smaller or cached setup first

Gate: beat the best prompt-plus-retrieval baseline
on the newest base, on a held-out set

Diagram summary: Start from the symptom. Missing or changing knowledge goes to retrieval or tools. Wrong behaviour and cost problems go first to a better prompt or a cheaper setup, and only when those fall short is tuning considered, and then only if it passes the gate against the strongest baseline.

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.

gross saving per day=calls per day×saving per call\text{gross saving per day} = \text{calls per day} \times \text{saving per call}

The saving per call is either the tokens you no longer send (tokens saved×price per token\text{tokens saved} \times \text{price per token}) or the price gap between the large model and the small tuned one.

net saving per day=gross saving−extra hosting cost per day−maintenance cost spread over its interval\text{net saving per day} = \text{gross saving} - \text{extra hosting cost per day} - \text{maintenance cost spread over its interval} payback time=one-off costnet saving per day\text{payback time} = \frac{\text{one-off cost}}{\text{net saving per day}}

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 1,500×2,000,000=31{,}500 \times 2{,}000{,}000 = 3 billion input tokens a day. Every price and cost below is an assumption for the exercise, not a quote. Use your own.

AssumptionValue
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: 3,000 million tokens×$1 per million=$3,0003{,}000\ \text{million tokens} \times \$1\ \text{per million} = \$3{,}000 a day.
  • Maintenance spread over its interval: $10,000÷90≈$111\$10{,}000 \div 90 \approx \$111 a day.
  • Net saving: 3,000−800−111≈$2,0893{,}000 - 800 - 111 \approx \$2{,}089 a day.
  • Payback: 30,000÷2,089≈1430{,}000 \div 2{,}089 \approx 14 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.

AspectAgainst the current setupAgainst provider prefix caching (10% rate)
Gross saving per day$3,000at most $300
Extra hosting per day−$800−$800
Maintenance per day (10,000÷9010{,}000 \div 90)−$111−$111
Net per day+$2,089−$611
Payback of the $30,000 one-offabout 14 daysnever: 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 PP parameters trained with the Adam optimiser in mixed precision, the ZeRO paper counts the model states like this: 2P2P bytes for 16-bit parameters, 2P2P bytes for 16-bit gradients, and an optimiser-state term it writes as K⋅PK \cdot P with K=12K = 12 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 2P+2P+12P=16P2P + 2P + 12P = 16P, 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 16×1.516 \times 1.5 billion.

What is stored during full fine-tuningBytes per parameter
16-bit parameters2
16-bit gradients2
Optimiser state: 32-bit parameter copy, momentum, variance12
Total model states16

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.

full fine-tune=16×P\text{full fine-tune} = 16 \times P LoRA (16-bit base)=2×P+16×(adapter parameters)\text{LoRA (16-bit base)} = 2 \times P + 16 \times (\text{adapter parameters}) QLoRA (4-bit base)=0.5×P+16×(adapter parameters)\text{QLoRA (4-bit base)} = 0.5 \times P + 16 \times (\text{adapter parameters})

For the table, assume the adapter holds 0.5 percent of PP (an assumption; it depends on rank and which matrices you adapt). Sizes are in decimal GB.

ModelFull fine-tuneLoRA, 16-bit baseQLoRA, 4-bit base
7B112 GB14.6 GB4.1 GB
13B208 GB27.0 GB7.5 GB
70B1,120 GB145.6 GB40.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 16,384×128,000×4≈8.4 GB16{,}384 \times 128{,}000 \times 4 \approx 8.4\ \text{GB} 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 6ND6ND floating-point operations, where NN is the number of parameters and DD is the number of tokens processed. Kaplan et al. give the form 6N6N per training token, built from about 2N2N 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 NN 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 4ND4ND, 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 stepFull fine-tuneLoRA
Forward pass2ND2ND2ND2ND
Gradients flowing back through layers2ND2ND2ND2ND
Gradients for the weights2ND2NDonly the small adapter
Total6ND6NDabout 4ND4ND

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 D=30D = 30 million tokens. Assume the job sustains 400 TFLOP/s on one GPU.

  • FLOPs: 6×7×109×3×107=1.26×10186 \times 7 \times 10^{9} \times 3 \times 10^{7} = 1.26 \times 10^{18}.
  • Time: 1.26×1018÷(400×1012)=3,150 s1.26 \times 10^{18} \div (400 \times 10^{12}) = 3{,}150\ \text{s}, 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.

Python

# 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) / 3600

The project loop

A tuning project is a loop, not a line.

Diagram: The project starts by defining the task and measuring the baseline, then loops through data, a small training run and evaluation.

fails the gate

passes

Define the task
and the metric

Measure the best
prompt and retrieval baseline

Collect, clean
and split data

Train a small LoRA run first

Evaluate: task,
regressions, safety

Ship with a canary
and a rollback

Monitor and collect
new examples

Diagram summary: The project starts by defining the task and measuring the baseline, then loops through data, a small training run and evaluation. A model that fails the gate sends you back to the data; one that passes ships with a canary and rollback, and monitoring feeds new examples back in.

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.

  1. 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.
  2. Notice. Which of the three still does not fit a single 80 GB card, and which numbers did you leave out?
  3. 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.
  • break-even=one-off costsaving−hosting−maintenance per day\text{break-even} = \dfrac{\text{one-off cost}}{\text{saving} - \text{hosting} - \text{maintenance per day}}. 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.”

Resources & Further Reading

Checked sources to go deeper. The essential ones come first in each group.

Official documentation

Further reading

  • LoRA Without Regret (opens in a new tab)

    John Schulman2025Article

    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)

    Dan Biderman, Jacob Portes, Jose Javier Gonzalez Ortiz, Mansheej Paul, et al.2024PaperTMLR 2024 (Featured Certification)

    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.

0 of 13 answered

Keyboard: arrow keys move between options. Space or Enter selects the focused option.

ObjectiveClassify a failure as missing knowledge, wrong behaviour, or cost and latency, say whether tuning is justified, and name the baseline a tune must beat.

  1. Question 1 of 13A shop's assistant keeps quoting last quarter's delivery fees, and the fees change every month. A manager proposes tuning on the fee table. What is the best reading of the failure?

    Choose one answer.

  2. Question 2 of 13A strong prompt with examples still returns the wrong ticket category on a few percent of 3 million daily calls, always in the same pattern. Labelled examples exist. Which is the best next step?

    Choose one answer.

  3. Question 3 of 13A tuned model scores 20 points above the team's first-draft prompt, and the team wants to ship it. What is the main thing missing from the claim?

    Choose one answer.

ObjectiveWrite 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.

  1. Question 4 of 13A tune costs $18,000 once and earns $2,000 a day gross. Hosting adds $600 a day, and a $13,500 re-tune comes every 90 days. About how long is the payback?

    Choose one answer.

  2. Question 5 of 13A provider bills cached input at 20 percent of the normal rate. A job's repeated prefix costs $2,000 a day at the normal rate. What is the most that baking it into a tuned model can save?

    Choose one answer.

  3. Question 6 of 13A new base model is released that is much better. Your adapter beat the old baseline last spring. What should you do first?

    Choose one answer.

ObjectiveEstimate the model-state memory of full fine-tuning with Adam, LoRA and QLoRA, and name what that estimate leaves out.

  1. Question 7 of 13How much memory do the model states take for full fine-tuning of an 8-billion-parameter model with Adam in mixed precision?

    Choose one answer.

  2. Question 8 of 13A 4-bit frozen 8B base needs about 0.5 bytes per parameter. With a 40-million-parameter adapter at 16 bytes each, about how much do the QLoRA model states come to?

    Choose one answer.

  3. Question 9 of 13A memory plan for a tuning run lists only the model states. Which items does it leave out? Select all that apply.

    Choose all that apply.

  4. Question 13 of 13You must choose between two plans for a 34B-class task. Plan one fully fine-tunes it. Plan two uses LoRA on a 16-bit frozen base with a 0.5 percent adapter. About how do the model-state sizes compare?

    Choose one answer.

ObjectiveEstimate training compute and time from parameters and tokens, and explain why LoRA saves memory far more than it saves compute.

  1. Question 10 of 13A model has 3 billion parameters and trains on 2 billion tokens. The job sustains 300 TFLOP/s. Using the 6ND estimate, about how long does a full fine-tune take?

    Choose one answer.

  2. Question 11 of 13A teammate says LoRA will cut GPU time to about a hundredth because only about one percent of the weights train. What is the best response?

    Choose one answer.

  3. Question 12 of 13Which breakdown best explains the 6 in the 6ND estimate for training a dense model?

    Choose one answer.