4.3.9 · D4Pretraining & Fine-Tuning LLMs

Exercises — Adapter layers and prefix tuning

2,198 words10 min readBack to topic

Before we count anything, let's pin down the symbols so nobody is lost on line one.

The two counting formulas we will lean on all page:

Figure — Adapter layers and prefix tuning

L1 — Recognition

Problem 1.1

Which components are frozen and which are trained in (a) adapter tuning, (b) prefix tuning? Name the trainable matrices for each.

Recall Solution 1.1

(a) Adapters. Frozen: all original weights (attention , the FFN, embeddings). Trained: only the adapter's and (plus tiny biases). (b) Prefix tuning. Frozen: everything the model shipped with, including . Trained: only the prefix matrices per layer. Slogan: freeze the giant, train the tiny.

Problem 1.2

Match each statement to Adapter or Prefix:

  1. "New params live in attention keys/values."
  2. "A bottleneck feed-forward block is added after a sublayer."
  3. "Cost at inference = a longer effective sequence."
  4. "Initialize the up-projection to so it starts as identity."
Recall Solution 1.2

1 → Prefix (we prepend to ). 2 → Adapter. 3 → Prefix (sequence grows from to ). 4 → Adapter ().


L2 — Application

Problem 2.1

A model has , layers, one adapter per layer (), bottleneck . Count the adapter trainable parameters (weights only, ignore biases).

Recall Solution 2.1

WHAT: use . WHY: each adapter holds () and (), each with numbers → per adapter; multiply by adapters.

Problem 2.2

Same model (, ). Prefix tuning with . Count prefix trainable parameters and compare to Problem 2.1's adapter count.

Recall Solution 2.2

So this prefix (M) is a bit cheaper than the adapter of 2.1 (M). Notice the swap: (adapter) plays the same "capacity dial" role that (prefix) plays — both multiply .

Problem 2.3

The full model has M parameters. Express the adapter count from 2.1 as a percentage of .

Recall Solution 2.3

Well under 1% — the PEFT promise holds.


L3 — Analysis

Problem 3.1

For a fixed layer with , when does an adapter with bottleneck cost more parameters than a full learned map (which costs )? Find the break-even .

Recall Solution 3.1

WHAT: compare (adapter) vs (full map). WHY: the whole point of the bottleneck is ; find where the inequality flips. So the adapter is only cheaper while . Beyond that a full map is smaller — which is why we always pick (e.g. 16–64). At the two are exactly equal.

Problem 3.2

Why can't we drop the nonlinearity and just use ? What is the rank of the resulting linear map, and why does that limit expressiveness?

Recall Solution 3.2

Without , is a single matrix . Because it is a product of a and an matrix, . So the "correction" can only live in an -dimensional subspace — it is a rank- linear map, incapable of any nonlinear reshaping. Adding (ReLU/GeLU) breaks the linearity so the two projections no longer collapse, letting the adapter bend the vector nonlinearly. This is the same low-rank story behind LoRA, except LoRA deliberately keeps it linear and adds it to a weight matrix instead.

Problem 3.3

Prefix tuning grows the attention sequence from real tokens to . Attention cost is . If and you raise from to , by what factor does the attention compute grow?

Recall Solution 3.3

WHAT: ratio of at the two prefix lengths. A ~37.5% increase in attention compute. Lesson: is a capacity dial, but you pay for it quadratically-ish through the sequence length, so bigger prefixes are not free.


L4 — Synthesis

Problem 4.1

You must serve 200 customers, each with a private task, on one 7B model ( params, 4 bytes each in fp32). (a) Storage for full fine-tuning (200 separate copies). (b) Storage for PEFT: one shared backbone + a per-task adapter delta of M params each. Compare.

Recall Solution 4.1

(a) Full FT. One copy bytes GB. For 200 tasks: GB TB. (b) PEFT. Backbone once: GB. Each delta: bytes MB. For 200 deltas: MB GB. Total PEFT GB vs GB. Ratio less storage. This is the whole business case for PEFT over full FT.

Problem 4.2

Design a hybrid: adapters () and a prefix () on the same model (, , ). Give the total trainable count and the percentage of a M model.

Recall Solution 4.2

Adapters: . Prefix: . Total M. Percentage: . Both mechanisms coexist because they touch different places (adapters after the FFN sublayer via a residual; prefix inside attention K/V) — they don't fight over the same weights.


L5 — Mastery (edge cases & judgement)

Problem 5.1 (degenerate )

What happens to an adapter as ? As ? Interpret each extreme.

Recall Solution 5.1

: the bottleneck has zero width — and collapse, the correction term is empty, and exactly. The adapter is a pure identity: zero new capacity, the model is unchanged. (This is also the initialization target via .) : the bottleneck is as wide as the hidden state — no squeeze at all. Params , twice the cost of a plain full map (), and you've lost every efficiency reason to use an adapter. So both extremes are useless; the sweet spot is .

Problem 5.2 (init edge case)

Suppose you (wrongly) initialize with the same random scheme as a normal layer instead of . Describe the forward-pass effect at training step 0 and why it's harmful.

Recall Solution 5.2

At step 0, is a random nonzero vector added to . So — the pretrained forward pass is immediately perturbed at every inserted adapter. Errors compound across layers, the model's outputs become garbage on step 0, and gradients start from a bad, unfamiliar point (harder optimization, possible forgetting). Near-zero init keeps , so training departs from the known-good pretrained behaviour rather than from noise.

Problem 5.3 (queries edge case)

In prefix tuning we set and but we do not prepend to the queries . Why must the queries stay real-token-only? What would prepending prefix queries do?

Recall Solution 5.3

The attention output has one row per query. Real tokens are what we want outputs for. If we also prepended prefix queries, we'd produce extra output rows for positions that correspond to no real token — meaningless, and they'd mess up the residual stream shape ( in, out). Keeping real-only means: real tokens attend over the extra learned slots (soft-mixing in task info via softmax attention) but the number and identity of outputs stays exactly the real positions. The prefix influences what each real token reads, never how many outputs exist.

Problem 5.4 (limiting behaviour)

As prefix length , what does prefix tuning reduce to? As grows very large relative to , where does most of the attention mass risk going, and why is that a caution?

Recall Solution 5.4

: , — the concatenation adds nothing, so the model is exactly the frozen original. Zero steering (mirrors for adapters). : the softmax now competes over keys where of them are learned. With enough learned slots the attention distribution can be dominated by prefix keys, and real-token context gets drowned out. Plus attention cost is , so it becomes expensive. The caution: bigger = more steering and more risk of overriding genuine context, so tune to task complexity (small for classification, larger for open generation).


Recall One-line summary to self-test

Both methods freeze the backbone. Adapters cost ; prefix costs . The factor 2 = two learned matrices. and are capacity dials with degenerate limits at 0 (no effect) and at their max (: no savings; : drowns context).

Freeze the giant :::- train the tiny. Break-even where adapter stops being cheaper than a full map :::- . What and both give :::- a pure identity — the unchanged frozen model.