4.3.9 · D1Pretraining & Fine-Tuning LLMs

Foundations — Adapter layers and prefix tuning

2,205 words10 min readBack to topic

This page assumes nothing. If the parent note used a symbol, we build it here from the ground up, in an order where each brick rests on the previous one.


0. What is a "parameter"? (the atom of everything)

Picture a mixing desk with millions of sliders. Each slider is one number. "The model has 7 billion parameters" means 7 billion sliders. Fine-tuning means grabbing sliders and moving them.

  • Full fine-tuning = you are allowed to move every slider.
  • PEFT (Parameter-Efficient Fine-Tuning) = you glue most sliders in place and add a small handful of new sliders you're allowed to move.
Figure — Adapter layers and prefix tuning

Why the topic needs this: the whole point of adapters and prefixes is how few new numbers you must move. Without the idea of a "parameter", "0.1–3% of parameters" is meaningless.


1. The vector — "what the model is thinking at one spot"

Read out loud as "a list of real numbers." The symbol means "is a member of / lives in." So = " is a point in -dimensional space."

Picture: if , is an arrow in 3D space. Real models use or — we can't draw 768 dimensions, so we always draw 2 or 3 and trust the pattern.

Why the topic needs it: an adapter is a machine that takes in and gives a corrected out. The prefix injects extra vectors of the same length . Every formula in the parent is a story about vectors of length .


2. Matrices as machines that reshape vectors

So a matrix is a machine: it eats a length- vector and spits out a length- vector. The shape tells you the plumbing:

Figure — Adapter layers and prefix tuning

Why: every trainable block (adapters, prefix keys/values) is just one or two of these matrices. Counting their entries is how we get " parameters."


3. Why is expensive and is cheap

A full map from length to length needs a matrix = numbers. Squeeze through a bottleneck of size instead:

  • down: numbers,
  • up: numbers,
  • total .

Why the topic needs it: the inequality (defined in section 2) is the mathematical reason PEFT is cheap. This inequality is the hinge of the whole idea.


4. Nonlinearity — the reason two matrices aren't one

Figure — Adapter layers and prefix tuning

Why: this is exactly step 2 of the parent's derivation. See also Full fine-tuning vs PEFT for why low-capacity curved corrections are enough.


5. The residual "+ h" — adding, not replacing

If , then and nothing changed — the model behaves exactly as before. This is why we start the adapter with : at step 0 the correction is zero, so we begin from the known-good pretrained model and gently drift away.

This whole idea is the same one from Residual connections — the adapter is glued into the network the same way a transformer already glues its sublayers.

Why: the "" in is not decoration — it is why adapters don't destroy pretrained knowledge (see Catastrophic forgetting).


6. Q, K, V — the three roles inside attention

Figure — Adapter layers and prefix tuning

Why the topic needs it: prefix tuning doesn't touch . It adds extra Keys and Values — the learned matrices — so every real token's query can also attend to a few trainable "fake" slots. The notation means "stick the prefix keys on the front of the real keys" ( = concatenation, stacking rows on top of each other). Contrast with Prompt tuning and soft prompts, which only edits the very first layer's input, and LoRA and low-rank adaptation, which edits weights with a bottleneck like the adapter.


How it all feeds the topic

parameter = one number

freeze vs train

hidden vector h in R^d

matrix as reshaping machine

count entries = params

bottleneck 2dr much less than d squared

nonlinearity sigma

residual add h

Adapter layers

Query Key Value

softmax mixing

Prefix tuning

PEFT: freeze giant train tiny


Equipment checklist

Test yourself — cover the right side and answer out loud.

What does mean in plain words?
is a list of real numbers — one hidden vector for one token, drawn as an arrow in -dimensional space.
What does the shape tell you about a matrix as a machine?
It eats a length- vector and outputs a length- vector; it holds numbers.
What is the bottleneck dimension and how does it relate to ?
A small width we pick inside the adapter, with (much smaller), chosen to make the add-on cheap.
How many numbers does a full map cost, and how many does a bottleneck of size cost?
Full map ; bottleneck (down + up ).
Do biases count in our parameter budget?
We count only matrix entries; biases add just one number per output row — negligible, so we round them away.
Why must a nonlinearity sit between the two adapter matrices?
Without it, collapses to a single linear map, so the second matrix adds nothing.
What are and as named functions?
is any block's transformation; with .
What does the residual "" guarantee if the block outputs ?
The output stays , so an adapter initialized near zero starts as the identity and preserves pretrained behaviour.
Write the softmax formula and say what it guarantees.
; all weights are positive and sum to .
What are , their shapes, and their parameter cost?
Learned prefix key/value matrices, each for fake tokens; cost per layer, total.
In attention, which of does prefix tuning add to, and which stays untouched?
It adds learned rows to and (via ); queries come only from real tokens and are untouched.
What does "freeze the backbone" mean precisely?
The pretrained weights still run in the forward pass but are taped down — training cannot change them; only the tiny new params move.