Concepts / Evaluating a Fine-Tuned LLM

Evaluating a Fine-Tuned LLM

Instruction fine-tuning is a three-stage process: preparing the dataset, fine-tuning the LLM, and evaluating the LLM.

  • Programming

Why Training Is Not the Last Step

By the time the chapter reaches this point, two large pieces of work are already finished. The first is a model that has been pre-trained and loaded into memory. The second is a dataset of instructions that has been cleaned, formatted, and turned into batches. Instruction fine-tuning is the step that connects these two pieces. The model is trained further, this time on instruction examples, so that it learns to respond to the kind of input the dataset describes.

Fine-tuning changes a model's behavior, but a changed model is not automatically a better one. After training, you still have to find out how well the model performs on the task you cared about. That question is the subject of this article: how a fine-tuned model is evaluated once training has finished. Keep one idea in mind as you read. Evaluation is a process that produces a number from a collection of model outputs, and each step hands a slightly different collection to the next step. The final number only makes sense if you understand what each step did to that collection.

The Three Stages at a Glance

Instruction fine-tuning is organized as a three-stage process. Stage 1 prepares the dataset. Stage 2 fine-tunes the LLM. Stage 3 evaluates the LLM. The diagram below places the steps described in this lesson under the stage each one belongs to, in the order they run. The full layout in the chapter numbers nine steps in total, and the steps shown here are the ones the lesson names.

Stage 1: Preparedatasetdataset sideBatched data loadersoutput of Stage 1Load pretrained LLMstarting modelExtract modelresponseson the test setStage 2: Fine-tuneLLMonly stage that trainsweightsRun instructionfine-tuningconsumes data loadersScore responsesone score per responseInspect modeling lossloss and training checksStage 3: EvaluateLLMlooks at responsesafterwardAverage scoressingle performance numberthenthenconsumed by trainingtrained furtherthentuned model respondsraw responsesscores
Which stage does each step belong to, and in what order do the stages run?

Notice where the fine-tuning work sits. Stage 1 and Stage 3 surround it. Stage 1 produces the batched data loaders that the training step will consume, and Stage 3 looks at the responses the tuned model produces afterward. Stage 2 is the only stage in which the model's weights are trained, and it contains three steps: loading the pretrained LLM, running instruction fine-tuning, and inspecting the modeling loss.

What the Pretrained Model and Dataset Each Contribute

Fine-tuning does not begin from random weights. The starting model is the one loaded in the previous section, and fine-tuning continues training that model. The data side is the instruction dataset prepared earlier in the chapter. That dataset was processed at the start of the chapter, so the fine-tuning step does not repeat that preparation work. In other words, the pretrained LLM supplies the starting weights and the general capability already learned, while the instruction dataset supplies the examples that shape how the model should respond.

Fine-tuning also needs a way to compute loss and run training. The chapter already contains code for both, so the fine-tuning code imports two functions from chapter 5 instead of writing those routines again: calc_loss_loader, which handles the loss calculation, and train_model_simple, which runs the training procedure. Four inputs meet at the single fine-tuning step: the pretrained LLM, which is loaded and then trained further; the instruction dataset, which supplies the examples; and the two chapter 5 functions, which supply the loss calculation and the training procedure. The diagram below shows how these inputs feed that one step.

Fine-tuning stepPretrained LLMloaded, then trainedfurtherInstruction datasetsupplies training examplescalc_loss_loaderloss calculationtrain_model_simpletraining procedurestarting weightsexampleslosstraining
Which inputs feed the fine-tuning step, and what does each one contribute?

Finding Which Stage a Problem Belongs To

Suppose a run of the process produces a result you did not expect. The three-stage structure gives you a way to narrow the search. Ask first which stage the problem most likely belongs to, then look only at the steps inside that stage. If the data loaders are wrong, the cause lies in Stage 1. If the model is loaded incorrectly or the loss and training steps misbehave, the cause lies in Stage 2. If the responses look wrong after training finishes, the cause may lie in Stage 3, where responses are extracted and scored.

What do you think happens?

An averaged evaluation score is poor after training, and you then discover the batched data loaders were built incorrectly. Which stage does the cause belong to?

  • Stage 1: Prepare dataset

  • Stage 2: Fine-tune LLM

  • Stage 3: Evaluate LLM

Reveal answer
Answer:

Stage 1: Prepare dataset

Stage 1 produces the batched data loaders that the training step consumes, so a fault in the loaders is a Stage 1 fault even though its symptom appears in the final score.

From Test Set to One Score

Evaluation has its own internal progression. Each step changes the collection it works on: from inputs, to raw responses, to scored responses, and finally to a single average. The diagram below traces that collection. Read it from left to right and notice what the collection holds after each step.

Test set inputsmany items the model nevertrained onRaw text responsesnothing judged yetScored responseseach response paired with anumberAveraged scoreone value for the wholetest setrun fine-tuned model on each itemscore each responseaverage the scores
What does the evaluation hold after each step, and how does that change?

Worked Example: Two Sets With the Same Average

Worked example

Two response sets that share one average

Imagine a test set of four items, and a hypothetical scorer that gives each response a score from 1 to 5. The source does not specify a scoring scale, so this scale is an assumption made only for illustration. Set A and Set B each have four scored responses. Do they have the same performance?

  1. 1
    Record the per-item scores for Set A

    Set A scores are 3, 3, 3, and 3. Every response is middling.

  2. 2
    Record the per-item scores for Set B

    Set B scores are 5, 5, 1, and 1. Some responses are excellent and some are poor.

  3. 3
    Average each set

    Adding the scores and dividing by the count gives 3 for Set A and 3 for Set B. The single averaged number is identical.

  4. 4
    Compare the per-item scores

    The averages hide the spread. Set B has two responses scored 1, which the average alone does not reveal.

Result

Both sets report an average of 3, but their per-item scores differ sharply. Keeping the per-item scores is what shows that Set B contains both strong and weak responses.

Mistakes When Reading an Averaged Score

What the average showsWhat the average hidesWhat to keep when you need detail
One summary number for the whole test setThe spread of individual scoresThe per-item scores from the scored collection
A single overall level of performanceWhich specific items scored poorlyThe list of responses paired with their scores
A comparison between two runsWhether two runs with equal averages differ per itemPer-item scores for both runs side by side

What an averaged score reports and what it leaves out

  • Common mistake

    Treating the average as a complete description of quality

    What it looks like

    Reporting that a model scored 3 and assuming every response was adequate.

    Why it fails

    An average summarizes the test set but hides the spread of individual scores.

    Do this instead

    Keep the per-item scores when you need detail about which responses succeeded or failed.

  • Common mistake

    Assuming two equal averages mean equal quality

    What it looks like

    Set A and Set B both average 3, so they are judged the same.

    Why it fails

    Different per-item distributions can produce the same average.

    Do this instead

    Compare the per-item scores of both sets before drawing a conclusion.

  • Common mistake

    Blaming the scoring step for every poor number

    What it looks like

    Assuming a low average means the scorer is broken, without checking the stage the fault belongs to.

    Why it fails

    A low score can come from loaders, the loaded model, or the training steps, which sit in other stages.

    Do this instead

    Map the symptom to a stage first, then narrow the search inside that stage.

  • Common mistake

    Trying to explain a single example from the final average alone

Practice: Locate the Problem

EASY

A fine-tuned model was trained correctly and its loader and loss checks passed, but after training finished its extracted responses look wrong. Which stage should you examine first, and why?

Hints
  • Recall which stage is described as the one where responses are extracted and scored.
  • Stage 2 is the only stage in which the model's weights are trained.

Summary

At a glance

  • Instruction fine-tuning is a three-stage process: Stage 1 prepares the dataset, Stage 2 fine-tunes the LLM, and Stage 3 evaluates it.
  • Fine-tuning continues training a pretrained LLM on the instruction dataset, reusing calc_loss_loader and train_model_simple from chapter 5 instead of rewriting them.
  • Evaluation runs the fine-tuned model on a test set, collects raw responses, scores each one, and averages the scores into a single number.
  • An average hides the spread of individual scores, so keep per-item scores whenever you need detail.
  • When a result looks wrong, map the symptom to a stage first, then narrow the search to the steps inside that stage.

Related concepts

More concepts starting with E