Evaluation, deployment and special cases

  • Production
  • 45 min
  • Lesson 6 of 7 in Fine-tuning
  • Last verified

Open slides(36 slides)

Before you start

You will be able to

  • Design a ship gate for a tuned model: the baseline ladder, a task metric with a confidence interval and slices, and separate regression, safety and format checks, each with a pass rule written down in advance.
  • Detect forgetting and safety regression by running the same suites on the base and the tuned model, and choose the mitigation each signal points to.
  • Choose between merged weights and separate adapters for serving, say what task arithmetic, TIES and DARE each do, and name what to re-check after a merge.
  • Plan an embedding, reranker or distillation tune: what is trained, what it forces downstream, and how to evaluate it.

The retrained Aarav answers refund questions perfectly, clear and warm and right on cue.

Then a delay message arrives, a kind he has seen a thousand times. He tells the customer the order is “arriving at its own pace”.

Kavya checks the message and finds nothing wrong with it. Aarav now does what the training data taught him. What should the test include before anyone signs him off?

Concept

The story is still about fine-tuning and, in this lesson, about the part that comes after training: the sign-off. Fine-tuning data, risks and shipping already gave you the basic gate (beat the best prompt-plus-retrieval baseline, run regression and safety checks, canary, roll back). This lesson does not repeat it. It goes deeper in four places: how to design the gate so it can actually fail, how to detect forgetting and safety regression in practice, how to combine and serve adapters, and three special cases (embedding modelsEmbedding modelA model whose job is to turn text into one fixed-length vector. Index and query must use the same one, because each model builds its own vector space.Open the glossary entry, rerankersRerankingRe-ordering a shortlist of retrieved candidates with a more accurate model. It cannot recover a chunk the first stage failed to return.Open the glossary entry and distillationDistillationTraining a small model on a large model's outputs to keep a narrow task's quality at lower cost and latency.Open the glossary entry) where what you train is not a chat model.

Why It Matters

A training run that finishes only produces a candidate. Most expensive tuning failures are discovered after launch: a model that is better on the headline metric and worse on a slice nobody measured, one that quietly lost its refusals, or an embedding tune that was shipped without re-indexing. A gate written in advance, with numbers, turns “it looks better” into a decision you can defend and repeat.

Mental Model

Think of the sign-off as a driving test with several examiners, not one. The task examiner asks whether Aarav does the new job. The regression examiner asks whether he still does the old jobs. The safety examiner asks whether he still refuses what he must refuse, and does not refuse what he should help with. The format examiner checks that every reply is well formed. A pass needs all of them, and the pass marks are written before the test starts.

Where the analogy breaks: a person who passes the test is the same person tomorrow. A model that is later merged, quantised or moved to a new base is a different artefact and needs the test again.

A designed evaluation gate

Write the gate as a short spec before training, so the result cannot move the goalposts. It has five parts.

1. A baseline ladder, in order. Base model zero-shot, then the best prompt with examples, then prompt plus retrieval or tools, then a cheaper small model if one is plausible. The tune must beat the highest rung you could realistically ship, on the newest base. Lesson 1 explains why a weak baseline makes any tune look good.

Diagram: The baseline is a ladder, not a single rung.

Base model zero-shot

Best prompt with examples

Prompt plus retrieval or tools

A cheaper small model, if plausible

The tune must beat the highest rung
you could realistically ship, on the newest base

Diagram summary: The baseline is a ladder, not a single rung. The tuned model must beat the best option you could actually ship, not a first-draft prompt, and it must do so on the newest base model.

2. A task metric that fits the task, with an interval. Use exact match or F1 for extraction, schema-valid rate plus field accuracy for JSON, pass rate for code, pairwise win rate with a validated judge for style. A single score on a few hundred items is noisy, so report an interval. A bootstrapBootstrapResampling the test cases with replacement many times and recomputing a metric each time, to get an uncertainty interval without a formula.Open the glossary entry resamples the test items many times and shows how far the score moves.

Worked example (illustrative). On 400 test items a model scores 0.90 and a candidate scores 0.92. For one model, the standard error of an accuracy near 0.90 is 0.90×0.10÷400=0.000225=0.015\sqrt{0.90 \times 0.10 \div 400} = \sqrt{0.000225} = 0.015. For the difference between two independently scored models the standard error is about 2×0.015=0.021\sqrt{2} \times 0.015 = 0.021, so a 95 percent interval is about plus or minus 0.042, roughly four points. A two-point gain sits inside that. Scoring both models on the same items and bootstrapping the paired differences usually gives an interval tighter than the unpaired one, because the two models tend to fail on the same hard items, but the habit is the same: do not call a gain real until the interval excludes zero, or collect more items.

Python

# Illustrative sketch of a paired bootstrap. Not run here.
import random

def paired_bootstrap(base_correct, tuned_correct, n=2000):
    # lists of 0/1 per test item, same items in the same order
    diffs = []
    for _ in range(n):
        idx = [random.randrange(len(base_correct)) for _ in base_correct]
        diffs.append(sum(tuned_correct[i] - base_correct[i] for i in idx) / len(idx))
    diffs.sort()
    return diffs[int(0.025 * n)], diffs[int(0.975 * n)]  # about a 95% interval

3. Slices. An average can rise while one group gets worse. Split the test set by the things that matter: document type, language, customer tier, input length, and the cases where the baseline already failed. A slice needs enough items to be read, so keep a minimum size per slice, or say it is too small to judge.

4. Separate suites for regression, safety and format. These are different questions and they fail differently, so score them apart.

  • Regression: a fixed set of general abilities and instruction-following prompts the model could do before. Compare against the base model on the same prompts.
  • Safety: a red-team set of requests the model should refuse, plus a set of harmless requests it should answer, because a model can fail by refusing too much as well as too little.
  • Format and tool validity: the share of outputs that parse and match the schema. Valid format is not correct content, so this check sits next to the accuracy check and never replaces it.

5. Pass rules, written first. For example (illustrative, choose your own): task accuracy interval above the best baseline; no slice worse than the baseline by more than a set margin; general suite within a set drop of the base; refusal set at or above the base; schema-valid rate at the target. One failed rule is a failed gate.

Diagram: The candidate model is scored in four separate suites: task with interval and slices, regression against the base, safety including...

yes

no

Candidate tuned model

Task eval
interval and slices

Regression suite
vs the base model

Safety suite
refusals and over-refusal

Format and tool validity

Every pass rule met?

Shadow, canary, ship

Fix data or recipe,
retrain, re-run all four

Diagram summary: The candidate model is scored in four separate suites: task with interval and slices, regression against the base, safety including over-refusal, and format validity. All pass rules must be met to move to shadow traffic and a canary; any miss sends you back to fix the data or recipe and re-run every suite.

Catching forgetting and safety regression

Both failures share one detection method: run the same suite on the base model and on the tuned model, and read the difference. An absolute score means little, because a hard suite scores low for a healthy model. The drop relative to the base is the signal.

Forgetting

ForgettingForgetting (catastrophic forgetting)The loss of general abilities a model was not trained to keep after fine-tuning. Mix in general data and re-run regression tests.Open the glossary entry shows as a fall on the regression suite while the task score rises. Typical causes are a high learning rate, many epochs, a narrow dataset, or full fine-tuning of all weights. Mitigations follow the cause:

  • Lower the learning rate or the number of epochs.
  • Use a LoRALoRALow-rank adaptation: freeze the base weights and train a small low-rank update, a tiny fraction of the parameters. Adapters are small, swappable and mergeable.Open the glossary entry adapter, and a smaller one, so fewer weights can move.
  • Mix a share of general or earlier data into the training set. The right share is something you measure on the regression suite, not a fixed rule.
  • Interpolate the tuned weights back toward the base (see the merging section).

Related but different: overfittingOverfittingA model memorising its training examples and generalising worse.Open the glossary entry shows as a held-out score that is worse than the training score, and can include repeating training text word for word. Forgetting is about abilities the data never touched. Check the held-out set for one and the regression suite for the other.

Safety regression

Qi et al. (2023) report that fine-tuning an aligned model can erode its safety behaviour. In their red-team study, GPT-3.5 Turbo was made responsive to harmful instructions after tuning on only 10 adversarially designed examples, at a cost of under $0.20 through the provider’s API. They also found that tuning on benign, commonly used datasets can weaken alignment too, to a lesser degree. Two practical consequences follow. A safety result for the base model does not carry over to the tuned model, so the safety suite runs on the candidate itself. And “our data is harmless” is not evidence; the suite is.

Safety has two error directions. A tune on refusal-heavy data can make the model refuse harmless requests, which costs honest users. So the suite measures both the refusal rate on harmful prompts and the answer rate on harmless ones.

When the safety suite fails, the options are to add safety and refusal examples to the training mix, lower the training strength, add a guardrail outside the model, or decide the tune is not worth its risk. The suite is then re-run, because each fix is itself a change.

A signal-to-action table

Signal on the tuned model, relative to baseLikely causeFirst action
General suite falls, task risesNarrow data, high learning rate, many epochsLower strength, smaller adapter, mix in general data
Held-out worse than training, verbatim repeatsOverfitting, duplicatesDeduplicate, fewer epochs, stop earlier
Harmful-prompt refusals fallSafety alignment weakenedAdd safety examples, re-run the suite, consider a guardrail
Harmless requests refused moreOver-correctionAdd harmless examples near the refusal boundary
Valid-JSON rate fallsTemplate or end-of-sequence mismatchFix the template, add the format check

Merging adapters and models

There are two different jobs under the word “merge”.

Folding an adapter into its base. A LoRA adapter is a small correction applied on top of frozen weights. Adding it into the base weights produces one ordinary model that serves with no extra step per request. The PEFT documentation describes this as a way to remove the adapter’s latency, notes that the merged model has to be kept and used (the guide says the call is not in place, but in a test with PEFT 0.21.2 it merged the wrapped base model’s weights in place and stripped the wrapper’s adapter layers, so deep-copy the model first if you still need the adapter version), and warns that on a quantised base the merge re-quantises the weights, so un-merging is not exact and repeated merge-and-unmerge cycles can accumulate rounding error. The practical rule: merge in higher precision if you can, then re-run the gate on the merged artefact.

Combining several tuned models or adapters. Here you want one model with several abilities, or a model that has drifted pulled back toward the base. The ideas to know:

  • Task arithmetic. A task vector is the tuned weights minus the base weights. Ilharco et al. show these vectors can be added to give a model several abilities and negated to reduce one, so the merged weights are the base plus a scaled sum of task vectors. The scales are chosen by evaluation.
  • TIES-Merging. Yadav et al. identify two sources of interference when merging: parameters that changed only slightly, and disagreement over the sign of a parameter across models. TIES trims the small changes, elects a sign per parameter, and merges only the values that agree with it.
  • DARE. Yu et al. observe that the fine-tuning deltas are small and highly redundant, randomly drop most of them (they report that 90 percent or even 99 percent can be dropped), and rescale the rest to compensate. It is used before combining to reduce interference. Unlike TIES, which trims by size, DARE drops at random.
  • Interpolating toward the base. A weighted blend of tuned and base weights trades some of the new skill for more of the old. It is one of the mitigations for forgetting.

The PEFT documentation also lists combination types for adapters, including TIES and DARE variants, and describes plain linear combination as an efficient but very rough approximation to avoid when you can afford a more precise method.

Diagram: A task vector is the tuned weights minus the base weights.

Base weights

Task vector A = tuned A − base

Tuned model A

Task vector B = tuned B − base

Tuned model B

Base + scaled sum of task vectors

Merged model: a new model, so run the whole gate

Diagram summary: A task vector is the tuned weights minus the base weights. Scaled task vectors can be added to give one model several abilities, or negated to reduce one, and TIES and DARE reduce interference before combining. The merged result is a new model and must pass the whole gate.

Two cautions apply to every method. These papers are research results from particular experiments, and merging works best when the models share a base. And a merge is a new model: no training happened, but nothing guarantees the result keeps the abilities of its parents. Run the whole gate on it.

Serving adapters in production

You have two ways to serve a tuned model, and the trade-off is flexibility against simplicity.

ChoiceMerged into the baseSeparate adapters on a shared base
Per-request costNone extraSmall extra step per request
Many tenants or tasksOne full copy of the weights per variantOne base in memory, many small adapters
RollbackRedeploy the previous weightsPoint to the previous adapter
A/B testTwo full deploymentsTwo adapters, one server
Best forOne dominant modelPer-tenant or per-task variants

The vLLM documentation describes the second pattern: a request names the adapter it wants, much as it would name a model, and adapter requests run alongside base-model requests. Adapters can be loaded when the server starts, and the server can also add and remove them at runtime, and the documentation warns that runtime updating “should not be used in production unless it is an isolated, fully trusted environment”. The server also has settings that cap how many adapter requests run together, which is a capacity you plan for.

Operational habits that make this safe:

  • Register every artefact with the base model revision, the adapter, the data version, the chat template, the training settings and the evaluation report. When the template and the adapter drift apart, quality falls with no error message.
  • Roll out in stages. Shadow traffic first, so the new adapter sees real inputs without answering users, then a canaryCanary releaseSending a small share of real traffic to a new version before full rollout, with a way to roll back.Open the glossary entry on a small share, comparing the same dashboards as the gate.
  • Roll back by switching the pointer to the previous adapter, and test that switch before launch.
  • Re-tune on triggers, not on a calendar: a new base model, a schema or policy change, measurable drift, or a new cluster of failures in the logs. Before re-tuning, re-run the baseline on the new base (lesson 1).
  • Feed logs back with care. Use production examples for the next dataset only with consent and after removing personal data, and check that you are not training the model on its own mistakes.
Diagram: A new adapter is released in stages: shadow traffic first, then a small canary, then full rollout, with rollback as a pointer switch to the...

problem

problem

Shadow traffic:
new adapter sees real inputs, answers nobody

Canary on a small share

Full rollout

Roll back: point to the previous adapter

Registry: base revision, adapter, data version,
template, settings, eval report

Diagram summary: A new adapter is released in stages: shadow traffic first, then a small canary, then full rollout, with rollback as a pointer switch to the previous adapter. A registry records every artefact so the template and adapter can never silently drift apart.

Special cases

Sometimes the model you tune is not the one that writes the answer.

Tuning an embedding model

If retrieval fails because the domain’s vocabulary is far from the embedding model’s training data, tune the embedding model. The usual method is contrastive trainingContrastive trainingTraining that pulls matching pairs of texts together and pushes others apart in vector space. It is why close vectors tend to mean similar meaning.Open the glossary entry on pairs of a query and a passage that answers it. The Sentence Transformers documentation names MultipleNegativesRankingLoss (also called InfoNCE or the in-batch negatives loss) as a common default for pairs and for triplets, and says the pair data it needs is often relatively cheap to obtain. In-batch negatives mean that other passages in the batch count as wrong answers for a query. Adding hard negatives, passages that look relevant but are not, teaches finer distinctions. Queries can be generated by an LLM from your documents, then sampled and checked by a person.

Diagram: Tuning an embedding model changes the vector space, so the old and new vectors cannot be mixed.

Query and answering-passage pairs

Contrastive training of the embedding model

New embedding model

Re-embed the whole corpus into a new index

Re-check similarity thresholds

Evaluate with retrieval metrics, then swap by alias

Diagram summary: Tuning an embedding model changes the vector space, so the old and new vectors cannot be mixed. The whole corpus must be re-embedded into a new index, thresholds re-checked, and retrieval metrics compared before switching over.

What it forces downstream: vectors from the old and new models live in different spaces, so you cannot mix them. A new embedding model means re-embeddingRe-embeddingRecomputing all vectors with a new embedding model. Build a new index version in the background, test it, then swap an alias.Open the glossary entry the whole corpus into a new index, and re-checking any similarity thresholds, since score ranges change. Evaluate with retrieval metrics (recall at k, ranking quality) on held-out queries and passages that were not used to build training pairs, and compare against the untuned embedding model and against a reranker.

Tuning a reranker

A cross-encoderCross-encoderA model that reads query and passage together and outputs a relevance score. More accurate, but one call per pair, so it reranks a shortlist.Open the glossary entry reranker scores a query together with each retrieved passage and reorders the top results. If the right passages are retrieved but ranked badly, tuning the reranker is often the smallest change that helps: it needs no re-embedding of the corpus and does not touch the generator. Train it on query-passage relevance labels, ideally with hard negatives drawn from what your own retriever returns. Evaluate the ranking before and after on held-out queries, and check latency, because the reranker runs on every query.

Distillation

DistillationDistillationTraining a small model on a large model's outputs to keep a narrow task's quality at lower cost and latency.Open the glossary entry trains a small student to reproduce a larger teacher on a narrow task, to cut cost and latency. Hinton, Vinyals and Dean framed the idea as compressing an expensive ensemble into one model that is cheap to run. Two common forms in language models:

  • Train on the teacher’s outputs. Fine-tune the student on text the teacher generated. This is simple and works across different tokenisers.
  • Match the teacher’s output probabilities. This gives the student a richer signal, but the two models must share a vocabulary so that the probabilities line up.
Diagram: A small student is trained on a larger teacher’s outputs for a narrow task to cut cost and latency.

Large teacher model

Teacher outputs on your task inputs

Fine-tune the small student on them

Score the student on the teacher's
failure slices and long tail

Compare with the cheaper baseline rungs,
check the terms of use

Diagram summary: A small student is trained on a larger teacher’s outputs for a narrow task to cut cost and latency. Because a student can match the average and still fail rare cases, it is scored on the teacher’s failure slices and compared against cheaper baselines before it ships.

Three checks matter. Score the student on the teacher’s failure slices and the long tail, because a student can match the average and still fail rare cases. Compare it against the cheaper rungs of the baseline ladder. And check the terms of use of the teacher’s outputs before using them as training data.

Other cases in brief

Continued pretraining, long-context extension, tool-use tuning, reasoning-model recipes and multimodal tuning follow the same pattern: name what changes, build a suite for what it can break, and gate on both.

Managed tuning or self-hosting

Hosted tuning products let you prototype quickly and usually keep the tuned model on the provider, with limited control over method and settings. Self-hosting an open model gives full control and portability, in return for running the pipeline and serving yourself, and keeps data inside your boundary. The gate does not change between the two.

Real-World Application

A team tunes a small model to turn support tickets into JSON triage records. Their gate: the best prompt-plus-retrieval baseline with prompt caching on; paired-bootstrap accuracy against it on a held-out set; slices by ticket language and by length; a general-ability suite compared to the base; a safety suite with both refusal and answer rates; schema-valid rate. The tune passes the task gate but the long-ticket slice is worse than the baseline, so it fails. They add long examples and retrain. After it passes, they serve it as an adapter on a shared base with a shadow period and a one-step rollback, and they keep the baseline numbers in the registry for the next base-model upgrade.

Interview Perspective

Expect: “Define the ship or no-ship gate for a fine-tuned model”, “The tuned model’s general benchmark dropped, what do you do?”, “Merge the adapter or serve it separately?”, “When would you tune the embedding model, and what changes in production?”, “Does the student match the teacher?”.

A strong answer names the baseline ladder, an interval and slices, the base-versus-tuned comparison on regression and safety (with over-refusal), format validity separate from accuracy, pass rules fixed in advance, and then shadow, canary and rollback. For special cases it states the downstream cost: re-embedding for an embedding tune, latency for a reranker, tail failures and licence terms for distillation. Common mistakes: reporting an average only, treating a merge as free of risk, running safety checks on the base instead of the tune, and forgetting to re-index.

Provenance: Common industry pattern. These are questions this topic tends to draw; none is verified for a named company.

Practice Questions

Provenance: generated practice.

  • Basic: List four checks you run besides task accuracy before shipping a tune.
  • Intermediate: Your tuned model’s general suite dropped by several points while the task score rose. Give three causes and the fix for each.
  • Advanced: Design the rollout of a LoRA update for 200 tenants, each with its own adapter.
  • Product: A team wants to tune the embedding model because “search feels off”. What do you check first, and what does shipping it require?

Activity

Do, notice, apply.

  1. Do. For a task you know, write the five-part gate spec: ladder, metric and interval, slices, the three separate suites, and pass rules with numbers.
  2. Notice. Which of your pass rules could the training process itself make easy to satisfy by accident, and which one would catch a model that got worse for one customer group?
  3. Apply. Pick an adapter you would serve for three tenants. Decide merged or separate, write the rollback step, and list what you would re-test if the base model were quantised.

Homework

Write the evaluation and deployment section of a fine-tuning proposal. Include the gate spec with pass rules, the signal-to-action table for your task, the serving choice with its rollback step, and, if retrieval is involved, an explicit decision on tuning the embedding model, the reranker, or neither.

Quick Revision

  • The gate is written before training and has separate suites: task (interval, slices), regression, safety (both directions) and format.
  • Detect forgetting and safety loss by comparing tuned with base on the same suites. Base results do not transfer to the tune.
  • Task arithmetic adds scaled task vectors; TIES trims small changes and resolves sign conflicts; DARE drops most deltas and rescales. A merge is a new model, so test it.
  • Merge for one dominant model; keep adapters separate for many tenants, A/B tests and a one-step rollback.
  • An embedding tune forces re-embedding and re-indexing. A reranker tune does not. A distilled student needs checking on the teacher’s failure slices.

Check yourself

  • Checkpoint (answer aloud, no notes): Define the ship or no-ship gate for a fine-tuned model, and say what you do when it fails on safety.
  • Re-test (nearby variant): Retrieval quality is the problem in a RAG product. Would you tune the generator? What would you tune instead, and what does each option force downstream?
  • Misconception to avoid: “The tuned model beats my first prompt, so it is ready to ship.”

Resources & Further Reading

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

Official documentation

Hands-on

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.

ObjectiveDesign a ship gate for a tuned model: the baseline ladder, a task metric with a confidence interval and slices, and separate regression, safety and format checks, each with a pass rule written down in advance.

  1. Question 1 of 13A tuned invoice-extraction model raises overall field accuracy over the best prompt. The team proposes shipping. Which addition to the gate matters most before the decision?

    Choose one answer.

  2. Question 2 of 13On 300 held-out items the baseline scores 0.75 and the tuned model 0.78, scored independently. The standard error of each score is about 0.025. How should the gate read the 3-point gain?

    Choose one answer.

  3. Question 3 of 13A tuned model produces valid JSON on 99.6 percent of calls, up from 96 percent. A teammate says the format suite makes the accuracy suite unnecessary. What is the best reply?

    Choose one answer.

  4. Question 13 of 13A tuned summariser beats the team's first-draft prompt. A stronger prompt with retrieval exists, and a newer base model was released last month. Which comparison does the gate need?

    Choose one answer.

ObjectiveDetect forgetting and safety regression by running the same suites on the base and the tuned model, and choose the mitigation each signal points to.

  1. Question 4 of 13A tuned model scores 61 on a hard general-knowledge suite. The team calls that fine, since 61 is well above chance. What is missing before it can be called free of forgetting?

    Choose one answer.

  2. Question 5 of 13A team tuned on harmless customer-service chats and says safety testing is unnecessary. They ran the base model's safety suite last month. Which response is best?

    Choose one answer.

  3. Question 6 of 13Relative to the base, a tuned model's general suite fell and its task score rose. The run used full fine-tuning, a high learning rate and a narrow dataset. Which first action fits?

    Choose one answer.

ObjectiveChoose between merged weights and separate adapters for serving, say what task arithmetic, TIES and DARE each do, and name what to re-check after a merge.

  1. Question 7 of 13A platform serves 200 tenants, each with its own tuned behaviour on one base model, and needs to undo a bad update within minutes. Which setup fits best?

    Choose one answer.

  2. Question 8 of 13Which statements about model-merging methods are true? Select all that apply.

    Choose all that apply.

  3. Question 9 of 13An adapter that passed the gate is merged into a 4-bit quantised base for serving, and users report slightly worse answers. What is the most likely explanation and next step?

    Choose one answer.

ObjectivePlan an embedding, reranker or distillation tune: what is trained, what it forces downstream, and how to evaluate it.

  1. Question 10 of 13A tuned embedding model raises recall on held-out queries. The index was built with the old model. What must the rollout include?

    Choose one answer.

  2. Question 11 of 13A RAG system retrieves the right passages in its top 20 but often ranks them below position 5. Which tune is the smallest change that targets the problem?

    Choose one answer.

  3. Question 12 of 13A distilled student matches its teacher on the average score of a held-out set. What should the team check next?

    Choose one answer.