The Flaw in Adapters That Prefix Tuning Sidesteps
In one sentence: adapters insert extra computation steps into the model; prefix tuning inserts nothing into the computation, it lengthens the input of every attention layer with learned vectors.
When you write an instruction for a model (a prompt) you are limited to words in the vocabulary. You fumble between "Summarize this text concisely", "Give me a short summary" and "Give me the gist". Each phrasing gives a different result, and finding the good one is guesswork.
Prefix tuning turns the question around: instead of hunting for the right words, learn directly the vectors those words would have produced. Vectors that match no word in the vocabulary, tuned by gradient descent, that is, by nudging their values step by step in whatever direction improves the result.
Prefix-Tuning: Optimizing Continuous Prompts for Generation (Li & Liang, 2021)Hunting for the right phrasing of an instruction is trying every key on a finite keyring. Prefix tuning is cutting a key to measure. The result is not a readable sentence: it is a string of numbers, unreadable to us, that steers the model better than any sentence could.
How It Works: Vectors Injected at Every Layer
What sets prefix tuning apart from prompt tuning: instead of adding vectors only at the model's input, you add them inside every attention layer.
Concretely, in each layer, learned vectors are glued in front of the keys and the values:
The brackets here just mean "placed end to end". and are the usual keys and values, and the learned vectors, and , the lengthened lists attention will actually consult.
The formula above puts two things of completely different natures side by side, and this is exactly where readers trip.
- and are activations: recomputed on every pass, for every text, by pushing the text's words through the weight matrices and . They do not exist outside a text being processed.
- and are learned parameters, frozen after training. They, and only they, are what gets saved and shipped. They are identical no matter what text is processed.
Put another way, prefix tuning learns ready-made activations and pretends to have computed them. That is why it needs no new weight matrix at all.
And the base model? Entirely frozen: neither , nor , nor anything else moves.
The real words of the text can then "consult" the prefix through attention and find information useful to the task, like a crib sheet planted at the start of each layer.
and hold vectors each, where is the prefix length: the number of fake words added.
Stabilization via Reparameterization
Optimizing these vectors directly turns out to be unstable: training oscillates and refuses to converge. The paper's remedy:
- Keep a smaller matrix of size .
- Push it through a small multi-layer perceptron (MLP, two or three layers of neurons): . It is that serves as the prefix.
- Once training is over, throw the MLP away and keep only .
Why this works: forcing every prefix vector to come out of one small shared network stops them from each wandering off on their own. The MLP constrains the search space. It is drawing with a template rather than freehand.

Number of Parameters
The count reads left to right:
Where does the factor of 2 come from? From needing one prefix for the keys and one for the values. Queries get none: queries are asked by the words of the text, and a fake prefix word has nothing to ask, it is there to be consulted, not to consult.
Concrete numbers, on GPT-2 Medium (, layers, prefix of ):
Against the model's 345 million parameters, that is . The paper rounds to 0.1%, and that is the figure it leads with.
Too short, five fake words, and the prefix has no room to encode the task. Too long, five hundred, and it eats the available context while the model risks overfitting: memorizing the examples instead of extracting a rule. The common range runs from ten to two hundred.
Watch the real cost: parameters grow in proportion to . The same calculation with gives million parameters, about 10 MB in 16 bits. That is no longer negligible at all.
Prompt Engineering vs Prefix Tuning
| Aspect | Written instruction | Prefix tuning |
|---|---|---|
| What you pick | words from the vocabulary | any string of numbers |
| How you find it | by hand, by trial | by gradient descent |
| Where it acts | at the input only | in every layer |
| Readability | you can reread your instruction | unreadable |
| What you store | a text | a matrix of a few hundred thousand numbers |
The decisive difference is the third row. A written instruction enters the model only through the front door, and its influence dilutes layer by layer. The prefix is replanted at every floor.
Empirical Results
The paper tests on two families of task:
- Table-to-text (the E2E, WebNLG and DART datasets): turning a record of structured data into a readable sentence, "name: Starbucks, type: coffee shop" becomes "Starbucks serves coffee".
- Summarization (the XSUM dataset): reducing news articles to a single sentence.
What the abstract claims, and this is checkable: by learning only 0.1% of the parameters, prefix tuning matches full fine-tuning when data is plentiful, beats it when data is scarce, and generalizes better to topics unseen during training.

The abstract says it outright: when training examples are few, prefix tuning does better than full fine-tuning.
The explanation fits in an image. With millions of free parameters and two hundred examples, the model has room to memorize all two hundred, which teaches it nothing general. With only half a million parameters, it has no room to cheat: it is forced to find a rule. Few parameters, when data is scarce, is an advantage rather than a concession.
Ideal Use Case: Massive Multi-Task
Imagine a service that has to cover a thousand different tasks: legal summarization, technical translation, code generation. Under full fine-tuning you would need a thousand copies of the model. With prefix tuning, one model stays in memory and you swap the prefix per task.
The prefix's weight is computable: with on GPT-2 Medium, 491,520 numbers in 16 bits come to about 1 MB. A thousand tasks therefore fit in a gigabyte, against 1,000 x 700 MB (700 GB) for a thousand copies of the model.

The Limits
It Eats the Available Context
The prefix occupies slots in the context window exactly as real words do. A hundred fake words on a 2,048-token window is of the budget gone before the document is even read. On long-document tasks, that hurts.
Its Influence Only Passes Through Attention
The prefix can act in one way only: by making itself consultable by the words of the text. It does not touch the small neural networks that follow attention, nor the weights themselves. For a deep adaptation (a new language, a far-off domain) that influence is too indirect.
Prefix tuning has a reputation for sensitivity to its settings: a learning rate slightly too high and training goes off the rails. That is precisely the reason for the MLP reparameterization described above.
LoRA is better behaved, because its correction starts from zero and stays confined to low rank. Budget time for tuning.
Scaling Up
On models of several billion parameters, prefix tuning generally sits below LoRA. It was designed in the era of GPT-2 and T5, models a hundred times smaller, and growth has not favoured it. We put no number on that gap: it varies by task and we found no reference measurement to cite.
Place in the Ecosystem
Prefix tuning matters above all for what it established: a model can be adapted without a single new weight, by learning only activations to glue in front of the real ones. It opened the way to prompt tuning, which pushes the same idea to its extreme by keeping only the model's input.
In practice it is rarely the first choice today, LoRA having taken over. It stays relevant for:
- thousands of tasks served by one model in memory;
- very constrained storage, provided the prefix stays short;
- generation with a fixed output format.
Available in Hugging Face's PEFT library via PrefixTuningConfig. The full comparison is in PEFT: comparing the methods.
1. In the formula K' = [P_K ; K], what distinguishes P_K from K?
2. The parameter count has a factor of 2: one prefix for the keys, one for the values. Why no third one for the queries?
3. What separates prefix tuning from a carefully written instruction at the top of the prompt?
4. Why can prefix tuning beat full fine-tuning when training examples are scarce?
5. The page warns that training prefix tuning is trickier than training LoRA. Why?