Slides · Fine-tuning

When to tune, and what it costs

When to tune, and what it costs

Before anyone books a training run: sort the failure, price the project against its cheapest rival, and size the memory and compute on paper.

By the end you can classify a failure and name the baseline a tune must beat, write a break-even with its recurring costs, estimate model-state memory for full tuning, LoRA and QLoRA, and estimate training time from parameters and tokens.

Concept

Three kinds of wrong message

  • Aarav keeps fumbling the same three message types: delays, address changes and cancellations. Kavya has a folder of examples ready.
  • Each training run takes the model off the line for an afternoon and costs real money.
  • Ananya reads the three types twice and says nothing, then asks one question: what has been tried without training?
  • The rest of the deck turns that question into steps: what failed, what the alternatives cost, and what the run itself needs.

Concept

Tuning changes the model; everything else changes the input

  • Fine-tuning continues training a pretrained model on a smaller task dataset, so the weights themselves move.
  • A better prompt, retrieved documents and tool calls all change what goes into a model whose weights stay fixed.
  • A tune is therefore welded to one base model. A new base means a new tune.
  • That one fact drives most of the economics later in this deck.

Compare

Sort the symptom before choosing a lever

Failure kindTypical symptomFirst lever
Missing or changing knowledgeStale price, outdated policy, no source to showRetrieval or a tool
Wrong behaviourOutput format drifts, tone is off, a routine is skippedBetter prompt and examples; tune if that stays short
Cost or latencyA long instruction block on every call, or a big model on a narrow jobCheaper or cached setup; tune or distil if still too costly
  • This table is course judgment, not a statement from any one source.

Diagram

From symptom to lever

Diagram: Facts that are missing or change go to retrieval or tools, while behaviour and cost problems go first to a stronger prompt or a cheaper...

Recurring failure

Which kind?

Missing or stale facts

Wrong behaviour

Cost or latency

Retrieval or tools

Prompt and examples first

Cheaper setup first

Tune only if still short

Gate: beat the best baseline

Diagram summary: Facts that are missing or change go to retrieval or tools, while behaviour and cost problems go first to a stronger prompt or a cheaper setup. Tuning is reached only when those fall short, and it must still pass the gate against the strongest baseline.

Concept

Why changing facts suit tuning poorly

  • Weights cannot show a source, cannot be corrected by editing one document, and cannot hide a document from one user.
  • The Ovadia comparison of knowledge injection reports that retrieval consistently beat unsupervised fine-tuning, for facts seen in training and for new ones. The authors add that models struggle to learn new facts this way.
  • The Gekhman study (EMNLP 2024) found that examples carrying new facts take longer to learn, and that fitting them raises the tendency to hallucinate.
  • Both are specific experiments. Read them as evidence about a mechanism, not as a law that no tune can ever help with facts.

Sources1 Fine-Tuning or Retrieval? Comparing Knowledge Injection in LLMs2 Does Fine-Tuning LLMs on New Knowledge Encourage Hallucinations?

Compare

Reasons that hold up, and reasons that do not

SoundWeak
A routine a strong prompt still misses at volume“So it knows our wiki”
A small model that must match a big one on a narrow task“To stop hallucinations”
One tone or policy across millions of calls“We have no evaluation set yet”
A long fixed prefix you would rather bake in than resend“Competitors do it”
A requirement to run an open model you host
  • There is no universal minimum number of examples. The right count depends on the task, so start small and measure.
  • Both the table and this point are course judgment, not findings from one source.

Worked example

The gate: beat the strongest cheap baseline

A tune must outscore the strongest prompt-and-retrieval setup, run on the newest base you could use, using a held-out set. All scores below are illustrative.

CandidateScore on held-out set
First-draft prompt on the old base70
Tuned model on the old base88
Best prompt plus retrieval on the newest base86
  • Against the first-draft prompt the tune looks like +18. Against the real rival it is +2.
  • Two points may not cover hosting, labelling and a re-tune when the base changes. The decision needs the cost columns from the next slides.

Check yourself

Check: sort three symptoms

Provenance: generated practice.

A claims-help assistant shows three problems. (1) It quotes last year’s filing fee, which changes each January. (2) On about 4 percent of 200,000 daily calls it answers in prose when the intake form needs exactly five labelled fields, even with a strong prompt and examples. (3) A 6,000-token policy block rides along on every call and dominates the bill. For each: which kind of failure, and what is the first lever?

Answer

(1) Changing knowledge: retrieval or a lookup, because one document edit updates the answer. (2) Wrong behaviour that survives a strong prompt at volume: measure the best-prompt baseline, then a small tune is justified if it beats that baseline. (3) Cost: first try a cached or trimmed prefix and a smaller model; tuning enters only if those fall short and the saving survives the break-even test.

Math

The break-even, written first

gross saving per day=calls per day×saving per call\text{gross saving per day} = \text{calls per day} \times \text{saving per call}net saving per day=gross−hosting per day−re-tune costre-tune interval in days\text{net saving per day} = \text{gross} - \text{hosting per day} - \frac{\text{re-tune cost}}{\text{re-tune interval in days}}payback in days=one-off costnet saving per day\text{payback in days} = \frac{\text{one-off cost}}{\text{net saving per day}}
TermMeaning
Saving per callTokens no longer sent times their price, or the price gap between a large and a small model
HostingExtra serving cost of the tuned model
One-off costData creation and labelling, training, and evaluation
Re-tuneRepeat cost when the base model is replaced
  • If net saving is zero or negative there is no payback at all.

Worked example

Worked example: a long prefix on every call

Illustrative inputs, not quotes: a 2,400-token prefix on 600,000 calls a day, input at $0.50 per million tokens, hosting $300 a day, a $9,000 re-tune every 60 days, $24,000 one-off.

StepCalculationResult
Tokens per day2,400×600,0002{,}400 \times 600{,}0001.44 billion
Gross saving1,440 million×$0.50 per million1{,}440\ \text{million} \times \$0.50\ \text{per million}$720 a day
Maintenance$9,000/60\$9{,}000 / 60$150 a day
Net saving720−300−150720 - 300 - 150$270 a day
Payback$24,000/$270\$24{,}000 / \$270about 89 days
  • A payback of about 89 days is longer than the 60-day re-tune interval, so the base may change before the project earns its money back. The case is thin even before a rival is priced; the next slide tests the cheaper rival.

Worked example

The baseline moves: price the cached alternative

The Anthropic caching page, read on 25 October 2026, prices cache reads at 0.1 times the base input rate for most listed models, with lower multipliers for a few, and cache writes above base price. Other providers differ, so this is one example. Assume 10 percent here. The 2,400-token prefix clears the minimum cacheable length on the models the page lists at 512, 1,024 or 2,048 tokens, but not on those listed at 4,096, so this example assumes the first group. The table leaves out the write premium (1.25 times base for the five-minute lifetime on that page), which at this call volume is paid only when the cache lapses.

Per dayAgainst current setupAgainst cached prefix
Gross saving$720$72
Hosting-$300-$300
Maintenance-$150-$150
Net+$270-$378
Payback of $24,000about 89 daysnever
  • With caching, the prefix costs only $72 a day, so moving the prefix into weights removes at most $72.
  • Caching has its own conditions: the same page sets a minimum cacheable prompt length that differs by model (512 to 4,096 tokens in the listing read), and the default cache lifetime is five minutes. Check that your traffic keeps it warm.

Source3 Prompt caching

Code

The calculator, with its edge cases tested

Python

import math

def payback_days(one_off, gross_per_day, hosting_per_day, retune_cost, retune_every_days):
    if not all(math.isfinite(x) for x in (one_off, gross_per_day, hosting_per_day, retune_cost)):
        raise ValueError("inputs must be finite numbers")
    if not (math.isfinite(retune_every_days) and retune_every_days > 0):
        raise ValueError("retune_every_days must be positive")
    net = gross_per_day - hosting_per_day - retune_cost / retune_every_days
    return None if net <= 0 else one_off / net      # None means never pays back

def prefix_gross(prefix_tokens, calls_per_day, usd_per_m, cache_rate=1.0):
    return prefix_tokens * calls_per_day / 1e6 * usd_per_m * cache_rate
Test (Python 3.14, 2026-10-25)Result
2,400 tokens×600,000 calls2{,}400\ \text{tokens} \times 600{,}000\ \text{calls} at $0.50 per milliongross 720.0
Payback with the inputs above88.9 days
Same prefix at cache rate 0.1gross 72.0, payback None
Net saving exactly 0None, no division by zero
Re-tune interval of 0 or -60 days, or a NaN inputValueError
  • Returning None for a non-positive net keeps a loss from printing as a negative or infinite number. The two guards stop a zero or negative interval, or a NaN, from producing a plausible-looking payback.

Check yourself

Check: which input breaks the case?

Provenance: generated practice.

A repeated prefix costs $5,000 a day uncached. A provider would bill it at 12 percent when cached. A tune would cost $9,000 once, $450 a day to host, and $3,000 every 30 days to re-tune. (a) What is the most the tune can save, and what is the payback? (b) Hosting is negotiable. At what daily hosting cost would payback drop to 90 days?

Answer

(a) The cached baseline already costs 12 percent of $5,000, which is $600 a day, so that is the most a tune can remove. Re-tune is $3,000/30=$100\$3{,}000 / 30 = \$100 a day. Net is 600−450−100=$50600 - 450 - 100 = \$50 a day, so payback is $9,000/$50=180\$9{,}000 / \$50 = 180 days. (b) For 90 days the net must be $9,000/90=$100\$9{,}000 / 90 = \$100 a day, so 600−hosting−100=100600 - \text{hosting} - 100 = 100 and hosting must be $400 a day.

Concept

Costs people leave out

  • The model treadmill. Base models improve every few months and a tune is frozen to its base. Before re-investing, score the best prompt-and-retrieval setup again on the latest base.
  • Evaluation and labelling. They can cost more than the training run (course judgment, not a measured figure), so they belong in the one-off cost.
  • Where it runs. If a hosted tuning product is an option, compare its price and limits with self-hosting. One provider’s optimisation guide, checked in October 2026, says that provider is winding down its fine-tuning platform and has closed it to new users, so availability is itself something to check.
  • The decision has a shelf life. Write down the condition under which you will re-run it.

Source4 Model optimization

Math

Memory for full fine-tuning: 16 bytes per parameter

model states=2P⏟16-bit weights+2P⏟16-bit gradients+12P⏟optimiser=16P bytes\text{model states} = \underbrace{2P}_{\text{16-bit weights}} + \underbrace{2P}_{\text{16-bit gradients}} + \underbrace{12P}_{\text{optimiser}} = 16P\ \text{bytes}optimiser=4P⏟32-bit weight copy+4P⏟momentum+4P⏟variance\text{optimiser} = \underbrace{4P}_{\text{32-bit weight copy}} + \underbrace{4P}_{\text{momentum}} + \underbrace{4P}_{\text{variance}}
ItemBytes per parameter
16-bit weights2
16-bit gradients2
32-bit weight copy4
Adam momentum4
Adam variance4
Total16
  • This is the ZeRO paper’s accounting for mixed-precision Adam. Its own example: 1.5 billion parameters need at least 24 GB, against 3 GB for the 16-bit weights alone.

Source5 ZeRO: Memory Optimizations Toward Training Trillion Parameter Models

Compare

What freezing the base changes

MethodFormula for model statesWhy
Full fine-tune16 x PEverything trains
LoRA, 16-bit base2 x P + 16 x AFrozen weights need only storage; the adapter A pays the full 16
QLoRA, 4-bit base0.5 x P + 16 x ASame, with the base stored in 4 bits
  • P is the base parameter count and A the adapter parameter count. The adapter share depends on rank and on which matrices you adapt, so state it as an assumption.
  • A frozen weight needs no gradient and no optimiser state.

Worked example

Worked example: a 20-billion-parameter model

Assumption: the adapter holds 1 percent of PP, so A=200A = 200 million. Decimal GB.

PlanCalculationModel states
Full16×2016 \times 20320 GB
LoRA, 16-bit2×20=402 \times 20 = 40, plus 16×0.2=3.216 \times 0.2 = 3.243.2 GB
QLoRA, 4-bit0.5×20=100.5 \times 20 = 10, plus 3.213.2 GB
  • Full tuning needs at least four 80 GB cards for states alone (320/80320 / 80), before anything else.
  • LoRA sits just under a 48 GB card, QLoRA under a 16 GB card, each only as a floor.

Concept

What the state count leaves out

  • Activations. The ZeRO paper’s example: a 1.5-billion-parameter model at sequence length 1K and batch 32 needs about 60 GB of activations. Activation checkpointing cuts that to about 8 GB for a recompute overhead the paper puts at 33 percent.
  • Temporary buffers. The same paper notes a flattened 32-bit gradient buffer for that model takes 6 GB.
  • Logits. A score for every vocabulary entry at every token position. For 8,192 tokens, a 150,000-entry vocabulary (an assumption) and 2 bytes each: 8,192×150,000×2=2.46 GB8{,}192 \times 150{,}000 \times 2 = 2.46\ \text{GB}, or 4.92 GB at 4 bytes.
  • Quantisation constants. QLoRA stores constants beside the 4-bit weights: 0.5 bits per parameter, or 0.127 with double quantisation, for the paper’s blocksize of 64, so about 0.516 bytes per parameter rather than 0.5.
  • Treat every state estimate as a floor.

Sources5 ZeRO: Memory Optimizations Toward Training Trillion Parameter Models6 QLoRA: Efficient Finetuning of Quantized LLMs

Worked example

Measured on a tiny network

Eight 512-by-512 linear layers (2,097,152 base parameters), 256 tokens per step, PyTorch 2.14.1 on CPU, 32-bit throughout. The LoRA copy adds rank-8 adapters.

QuantityFullLoRA
Trainable parameters2,097,15265,536
Bytes per base parameter: weights + gradients + Adam state16.04.5
FLOPs of one forward and backward step, divided by (base parameters×tokens)(\text{base parameters} \times \text{tokens})5.753.93
  • The 16.0 matches the rule only because 32-bit weights also cost 4 bytes; the point is that the frozen base gets no gradient and no optimiser state.
  • The step ratio LoRA/full\text{LoRA} / \text{full} is 0.684, near the two-thirds argued below.

Python

# model: the test network, x: a 256-token input, base_params: its base parameter count
from torch.utils.flop_counter import FlopCounterMode
with FlopCounterMode(display=False) as fc:
    model(x).sum().backward()          # one forward and backward step
ratio = fc.get_total_flops() / (base_params * 256)
  • Full shows 5.75 and not 6 because the first layer never needs a gradient for its input.

Check yourself

Check: will it fit a 24 GB card?

Provenance: generated practice.

You plan to tune a 12-billion-parameter model with an adapter holding 0.4 percent of the base. Compute the model states for LoRA with a 16-bit base and for QLoRA. Which, if either, plausibly fits a card with 24 GB of memory (decimal GB, as in the lesson), and what must you still add?

Answer

The adapter has 48 million parameters, so 16×0.048=0.768 GB16 \times 0.048 = 0.768\ \text{GB}. LoRA: 2×12=242 \times 12 = 24 plus 0.768 = 24.77 GB, which already exceeds 24 GB before activations. QLoRA: 0.5×12=60.5 \times 12 = 6 plus 0.768 = 6.77 GB, leaving room on a 24 GB card for activations, logits, buffers and quantisation constants, depending on batch size and sequence length.

Math

Training compute: about 6 x N x D

FLOPs≈6ND\text{FLOPs} \approx 6NDtime=FLOPssustained FLOP per second\text{time} = \frac{\text{FLOPs}}{\text{sustained FLOP per second}}
SymbolMeaning
NNParameters (the source counts non-embedding ones)
DDTraining tokens processed, epochs included
66About 2 for the forward pass, plus a backward pass of about twice the forward cost
  • Kaplan et al. state the backward pass as roughly twice the forward pass and give 6N6N per training token. Splitting the backward half into input gradients and weight gradients is a first-principles reading, not something the paper measures.

Source7 Scaling Laws for Neural Language Models

Compare

Why LoRA saves memory far more than compute

Part of a stepFullLoRA
Forward pass2ND2ND
Gradients passed back through layers2ND2ND
Gradients for the weights2NDadapter only
Total6ND6NDabout 4ND4ND
  • Frozen layers still pass the learning signal back to reach the adapters, so only the weight-gradient share disappears.
  • The LoRA paper reports a 25 percent training speedup on GPT-3 175B against full fine-tuning. Its footnote gives 32.5 against 43.1 tokens per second per V100 GPU, so the 25 percent is about a quarter less time, or about a third more throughput. That is a little less than the one third less time the arithmetic gives. The paper does not explain the gap; overheads the formula ignores are one plausible reason (course inference). Treat the estimate as a rough guide.
  • The tiny-network test gave 0.684. Anyone claiming a hundredfold compute cut has confused memory with compute.

Source8 LoRA: Low-Rank Adaptation of Large Language Models

Worked example

Worked example: hours, and a headline trap

A 2-billion-parameter model, 5 billion training tokens, a job assumed to sustain 250 TFLOP/s.

StepCalculationResult
FLOPs6×2×109×5×1096 \times 2 \times 10^{9} \times 5 \times 10^{9}6×10196 \times 10^{19}
Full run6×1019/(2.5×1014)=240,000 s6 \times 10^{19} / (2.5 \times 10^{14}) = 240{,}000\ \text{s}66.7 hours
LoRA at two thirds66.7×2/366.7 \times 2/344.4 hours
Dividing by 1,979 TFLOP/s instead6×1019/(1.979×1015)6 \times 10^{19} / (1.979 \times 10^{15})8.4 hours
  • The NVIDIA H100 page, checked in October 2026, prints 1,979 teraFLOPS for BF16 on the SXM card with an asterisk reading “With sparsity”. It is a peak under a special condition, not a rate a training job sustains.
  • Sustained rate divided by peak is model FLOPs utilisation. Measure it on your own job or state the assumed rate aloud.

Sources7 Scaling Laws for Neural Language Models9 NVIDIA H100 Tensor Core GPU (product page)

Check yourself

Check: turn a budget into tokens

Provenance: generated practice.

A team has 20 GPU-hours at a sustained 300 TFLOP/s and wants to tune an 8-billion-parameter model. Using the 6ND estimate, how many training tokens (epochs included) fit in the budget for a full tune? How many for LoRA, if LoRA costs two thirds as much per token? Then name one thing the answer ignores.

Answer

Budget in FLOPs =20×3,600 s×3×1014=2.16×1019= 20 \times 3{,}600\ \text{s} \times 3 \times 10^{14} = 2.16 \times 10^{19}. Full: tokens =2.16×1019/(6×8×109)=450= 2.16 \times 10^{19} / (6 \times 8 \times 10^{9}) = 450 million. LoRA at two thirds of the cost per token: 450 million×1.5=675 million450\ \text{million} \times 1.5 = 675\ \text{million}. The estimate ignores the activation-checkpointing recompute, multi-GPU efficiency losses (8B model states need several cards), and every rerun during iteration.

Diagram

A project is a loop

Diagram: The project fixes the task and baseline, then loops through data, a small training run and evaluation, returning to the data whenever the...

fails the gate

passes

Define task and metric

Measure best baseline

Collect, clean, split data

Small LoRA run first

Evaluate on held-out set

Ship with canary and rollback

Monitor, gather new examples

Diagram summary: The project fixes the task and baseline, then loops through data, a small training run and evaluation, returning to the data whenever the gate fails. A passing model ships with a canary and rollback, and monitoring feeds new examples back in.

Concept

How this is asked

Provenance: Common industry pattern.

  • Questions this topic tends to draw: when to tune instead of retrieving, how much memory a 7B-class tune needs, whether LoRA is cheaper in compute, and how to justify the cost. None is verified as asked by a named company.
  • A strong answer splits knowledge from behaviour, names the baseline and a held-out set, states 16 bytes per parameter and what LoRA changes, gives 6ND with the two-thirds point, and adds maintenance.
  • Say your assumptions aloud: adapter share, sustained rate, cache rate. The numbers are estimates.

Summary

Recap

  • Sort the failure first: changing facts go to retrieval, behaviour and cost go to a prompt or cheaper setup, and a tune is a last step.
  • A tune must outscore the strongest prompt-and-retrieval setup on the latest base, using held-out data.
  • Payback is the one-off spend over (gross saving minus hosting minus the spread re-tune cost); a cheaper alternative such as prefix caching can turn it into a loss.
  • Mixed-precision Adam tuning of every weight needs about 16 bytes per parameter in states; LoRA and QLoRA pay 16 only for the adapter. All of it is a floor.
  • Compute is about 6ND and LoRA about 4ND, so LoRA is a memory saving far more than a compute saving.
  • Use a sustained rate, not a vendor peak, for time estimates.

References

References & Sources (1 of 2)

  1. Fine-Tuning or Retrieval? Comparing Knowledge Injection in LLMs (opens in a new tab)

    Oded Ovadia, Menachem Brief, Moshik Mishaeli, Oren Elisha2024EMNLP 2024Paper

    Used for Retrieval consistently outperformed unsupervised fine-tuning for knowledge injection, for seen and new facts, and models struggle to learn new facts through fine-tuning.

  2. Does Fine-Tuning LLMs on New Knowledge Encourage Hallucinations? (opens in a new tab)

    Zorik Gekhman, Gal Yona, Roee Aharoni, Matan Eyal, et al.2024EMNLP 2024Paper

    Used for Fine-tuning examples that introduce new knowledge are learned more slowly than consistent ones, and once learned they raise the tendency to hallucinate.

  3. Prompt caching (opens in a new tab)

    Anthropic2026Documentation

    Used for Cache reads priced as a fraction of the base input rate (0.1 times for most listed models, lower for a few), cache writes above base price, and a default cache lifetime of five minutes. The minimum cacheable prompt length differs by model.

  4. Model optimization (opens in a new tab)

    OpenAI2026Documentation

    Used for The note that the provider is winding down its fine-tuning platform to new users.

  5. ZeRO: Memory Optimizations Toward Training Trillion Parameter Models (opens in a new tab)

    Samyam Rajbhandari, Jeff Rasley, Olatunji Ruwase, Yuxiong He2019Preprint

    Used for Model states for mixed-precision Adam: 2P plus 2P plus 12P, 16 bytes per parameter (24 GB at 1.5 billion parameters), plus the activation, buffer and checkpointing figures quoted for a 1.5-billion-parameter model.

References

References & Sources (2 of 2)

  1. QLoRA: Efficient Finetuning of Quantized LLMs (opens in a new tab)

    Tim Dettmers, Artidoro Pagnoni, Ari Holtzman, Luke Zettlemoyer2023NeurIPS 2023Paper

    Used for QLoRA quantisation constants cost 0.5 bits per parameter, reduced to 0.127 bits with double quantisation.

  2. Scaling Laws for Neural Language Models (opens in a new tab)

    Jared Kaplan, Sam McCandlish, Tom Henighan, Tom B. Brown, et al.2020Preprint

    Used for Training compute of about 6N floating-point operations per token, with the backward pass about twice the forward pass.

  3. LoRA: Low-Rank Adaptation of Large Language Models (opens in a new tab)

    Edward J. Hu, Yelong Shen, Phillip Wallis, Zeyuan Allen-Zhu, et al.2022ICLR 2022Paper

    Used for A 25 percent training speedup on GPT-3 175B against full fine-tuning, because most parameters need no gradient.

  4. NVIDIA H100 Tensor Core GPU (product page) (opens in a new tab)

    NVIDIA2026Documentation

    Used for The H100 BF16 teraFLOPS figure on the product page is marked 'With sparsity'.