4.3.6 · D4Pretraining & Fine-Tuning LLMs

Exercises — Full fine-tuning vs feature extraction

2,185 words10 min readBack to topic
Recall Symbol cheat-sheet (open if any symbol is unfamiliar)
  • ::: one input example (a sentence, an image).
  • ::: the backbone — the big pretrained network. It turns into a feature vector. is its pile of weights.
  • ::: the head — a small new layer on top. is its (few) weights.
  • ::: the model's prediction.
  • ::: the loss — a number saying how wrong is.
  • ::: learning rate — how big a step gradient descent takes.
  • ::: how many numbers live in and .
  • "freeze" ::: mark params as requires_grad=False so no gradient is applied to them.
Figure — Full fine-tuning vs feature extraction

Level 1 — Recognition

L1.1

In feature extraction, which parameter set receives gradient updates: , , or both?

Recall Solution

Only (the head). The backbone is frozen — its gradient is discarded (or never computed), so never moves.

L1.2

Name the two anchor points of the fine-tuning spectrum, from fewest trainable params to most.

Recall Solution

Fewest → feature extraction (linear probing): train only the head. Most → full fine-tuning: train backbone + head. Everything else (PEFT/LoRA, partial unfreezing, discriminative LRs) sits between them.

L1.3

True or false: in feature extraction you can precompute once and reuse it every epoch.

Recall Solution

True. Because is frozen, is a constant vector for each . Compute it once, cache it, and train the head on the cached vectors — no repeated backbone forward passes.


Level 2 — Application

L2.1

A pretrained encoder outputs a 768-dimensional CLS vector. You attach a linear head for 3-class classification. How many trainable parameters does feature extraction train? (Include biases.)

Recall Solution

A linear layer from has a weight matrix plus biases: That is the entire trainable count in feature extraction.

L2.2

The same encoder has backbone params. In full fine-tuning (backbone + the 2307-param head), how many parameters are trainable, and what is the ratio full : feature-extraction?

Recall Solution

Full FT trains everything: Ratio to feature extraction: Full FT trains roughly 47 thousand times more parameters. This is why memory and compute blow up.

L2.3

Using the rule of thumb "Adam stores ~4 numbers per trainable param (weight + gradient + + ), 4 bytes each," estimate the optimizer-state memory for the full-FT backbone (110M params). Give the answer in gigabytes ( bytes).

Recall Solution

Compare feature extraction: bytes GB — effectively nothing. This is the "full FT is heavy" term from the parent note. See Learning Rate Schedules for how interacts with this cost.


Level 3 — Analysis

L3.1

You have 500 labeled examples and a task very close to the pretraining domain. Using the Bias-Variance Tradeoff framing, argue which strategy to pick.

Recall Solution

With only 500 examples, full FT's ~110M free params vastly outnumber the data → the model has huge variance and will fit noise (overfit). Since the task is close to the pretraining domain, the frozen features already encode what you need → bias is low even without adapting . Pick feature extraction. Few trainable params act as strong regularization; the domain closeness means you lose almost nothing by freezing.

L3.2

Frozen features give 71% accuracy. You unfreeze only the top 2 layers and reach 79%. Explain why unfreezing the top layers (not the bottom ones) is the sensible first move, using Layer-wise Representations in Deep Nets.

Recall Solution

In a deep net, shallow (bottom) layers learn general features (edges, generic token statistics) that transfer across domains; deep (top) layers learn task/domain-specific combinations. A 71→79% jump from unfreezing only the top 2 layers means the mismatch was in the specific features, exactly where the top layers live. Keeping the bottom frozen:

  • preserves transferable knowledge (avoids Catastrophic Forgetting),
  • trains far fewer params than full FT (cheaper, less overfitting). This is the partial fine-tuning middle of the spectrum.

L3.3

In full fine-tuning the backbone gradient is In feature extraction, which of these three factors is (a) still computed, (b) never needed? Explain what this means for the backward pass.

Recall Solution
  • still computed (needed to train the head).
  • — this factor would carry the signal into the backbone. In feature extraction you don't need to push it further because...
  • never needed / never computed. Since is frozen, there is no reason to backpropagate through the (huge) backbone.

Meaning: the backward pass stops at the boundary between head and backbone. No gradient flows through the expensive internals — that is precisely why feature extraction is cheap.


Level 4 — Synthesis

L4.1

You must serve 50 different downstream tasks from one shared pretrained backbone on limited GPU. Design a strategy and justify the trainable-parameter budget.

Recall Solution

Serving 50 full-FT copies means 50 × (backbone size) on disk/GPU — infeasible. Instead:

  • Freeze the shared backbone once (feature extraction style) → one copy of serves all tasks.
  • Give each task its own tiny head (or a LoRA/adapter module of a few million params).
  • At inference, load the shared backbone plus the small per-task module.

Budget: trainable params per task = head/adapter only (KB–MB), not the ~110M backbone. This is the "limited GPU / many tasks" row of the parent's decision table — feature extraction or PEFT, never 50 full fine-tunes.

L4.2

Dataset: 200k legal documents (large, big domain shift). Write the full-FT recipe (LR magnitude, warmup, weight decay) and justify each ingredient in terms of Catastrophic Forgetting and gradient stability.

Recall Solution
  • Unfreeze everything. 200k examples + big domain shift means frozen features are biased (wrong for legalese); there's enough data to justify full capacity.
  • Small LR, . The model already sits near a good optimum; a large step would overwrite pretrained knowledge → catastrophic forgetting. Small nudges features gently.
  • Warmup (see Learning Rate Schedules): start near 0 and ramp up. Early gradients through deep layers can be large and noisy; warmup stops them from wrecking the initialization.
  • Weight decay: mild regularization that keeps weights from drifting too far from their (good) pretrained values.

Result: the backbone reshapes toward legalese while retaining general language competence — beats feature extraction because the data justifies the extra capacity.


Level 5 — Mastery

L5.1

A frozen-backbone run underperforms. You must decide between full FT and partial (top-) fine-tuning with a fixed compute budget. Derive a principled ordering of experiments and the stopping criterion.

Recall Solution

Order experiments by increasing trainable params (cheapest, safest first):

  1. Feature extraction (baseline accuracy ).
  2. Unfreeze top 1 layer. Top 2. Continue while each added layer gives a worthwhile accuracy jump.
  3. Full FT only if the curve is still climbing at the top layers (signals deep, pervasive domain shift).

Stopping criterion: stop unfreezing when the marginal accuracy gain falls below your tolerance, or when validation accuracy starts dropping (overfitting from too many free params on your data size). This walks the spectrum from cheap/robust toward expensive/flexible, spending compute only where it pays.

L5.2

Two students train the same backbone. Student A does feature extraction; Student B does full FT. After training, they compare for a fixed input . Predict the outcome and justify from the update equations.

Recall Solution
  • Student A: frozen → is identical to the pretrained model's, unchanged.
  • Student B: applies each step → changes, so evolves and ends up different from the pretrained features.

Prediction: the two feature vectors differ. This kills the myth "both give the same features." Only full FT adapts internal representations; feature extraction keeps them fixed by construction.

L5.3 (Numeric synthesis)

Compare optimizer-memory of two designs for a 110M-param backbone (4 bytes/number, Adam ~4 buffers/param): (a) full FT (110M + 2307-param head), (b) LoRA adding 1.2M trainable params, backbone frozen. Give both in MB ( bytes) and the reduction factor.

Recall Solution

(a) Trainable . (b) Trainable . Reduction factor: less optimizer memory. This is why PEFT and LoRA dominates when GPUs are scarce.


Wrap-up recall

Recall One-line summaries
  • Feature extraction trains ::: only the head; backbone frozen; features cached.
  • Full FT trains ::: backbone + head; features evolve; heavy memory.
  • Small data → prefer ::: feature extraction (low variance).
  • Large data + domain shift → prefer ::: full fine-tuning (low bias).
  • Many tasks / low GPU → prefer ::: feature extraction or PEFT/LoRA.
  • Small LR + warmup in full FT to ::: avoid catastrophic forgetting.