Skip to content

Chapter 6 · Bonus — Additional experiments

What Actually Matters in Fine-tuning

The main chapter made a dozen choices — classify the last token, unfreeze the last block, pad to 120. This bonus notebook re-runs the classifier 19 ways to find out which of those choices carried the result.

Adapted from the original notebook by Sebastian Raschka · the Python shown is the book's; the demos run a faithful JavaScript port in your browser

What-if · Ablation experiments

last_block
95.0

test accuracy · axis from 60%

01 / 05

The bonus notebook re-runs the classifier 19 ways to test the choices we made. The baseline — last token, last block, 124M — hits 95% test accuracy. Everything else is measured against it.

The lab

All nineteen runs, sortable. Click a column to rank by it — accuracy or training time — and read off the trade-offs yourself.

Ablation table

19 classifier variants; published A100 results. Click a numeric header to sort.

modelweightstokentrainedcontext
1124Mpretrainedlastlast blocklongest (120)96.699.395.00.28
2124Mpretrainedfirstlast blocklongest (120)78.580.575.00.28
3124Mpretrainedlastlast layerlongest (120)78.779.972.00.25
4124Mpretrainedlastlast two blockslongest (120)98.898.798.30.33
5124Mpretrainedlastalllongest (120)99.696.696.70.69
6355Mpretrainedlastlast blocklongest (120)87.591.384.70.75
7774Mpretrainedlastlast blocklongest (120)99.598.796.71.50
81558Mpretrainedlastlast blocklongest (120)99.899.898.32.83
91558Mpretrainedlastalllongest (120)100.098.798.78.12
10124Mrandomlastalllongest (120)100.096.693.70.69
11124MpretrainedlastLoRAlongest (120)100.097.396.70.75
121558MpretrainedlastLoRAlongest (120)100.098.798.35.79
13124Mpretrainedlastlast blockfull 102483.187.978.32.46
14124Mpretrainedlastlast blockno padding (bs 1)100.098.798.01.75
15124Mpretrainedlastlast blockno padding (bs 1, accum 8)99.398.798.31.70
16124Mpretrainedlast (flexible)last blocklast non-pad token99.498.798.30.30
17124Mpretrainedlastlast blockno causal mask99.298.795.30.29
18124Mpretrainedlastlast blockignore_index padding96.699.395.00.28
19124Mpretrainedlast + pooledlast blocklongest (120)97.899.396.30.32

Published results on an A100 GPU (ch06/02 bonus). Row 1 (●) is the main-chapter configuration; accuracies are percentages. Attributed data — these runs aren't reproduced in the browser.

The real code

Every row is one command-line flag on the same script:

ch06/02_bonus_additional-experiments
python additional_experiments.py                              # row 1 (baseline)
python additional_experiments.py --trainable_token_pos first  # row 2
python additional_experiments.py --trainable_layers last_two_blocks  # row 4
python additional_experiments.py --trainable_layers all       # row 5
python additional_experiments.py --model_size "gpt2-large (774M)"    # row 7
python additional_experiments.py --trainable_layers lora --lora_rank 16 --lora_alpha 16  # row 11
python additional_experiments.py --context_length "model_context_length"  # row 13
python additional_experiments.py --disable_causal_mask        # row 17

Three things to remember

  1. Ablations turn choices into evidence. Change one knob, hold the rest, re-measure — the only honest way to know which decision mattered.
  2. The causal mask dictates the token position. Classifying the last token isn't arbitrary; it's the only position with full context, and the 20-point gap versus the first token proves it.
  3. More capacity has diminishing — sometimes negative — returns. Bigger models and more trainable layers don't monotonically help; the last two blocks of a 124M model are a sweet spot.

Adapted from Build a Large Language Model (From Scratch) by Sebastian Raschka — additional experiments (Apache 2.0). The results shown are its published A100 benchmarks, quoted as attributed data.