# Prefix-Tuning: Optimizing Continuous Prompts for Generation

Xiang Lisa Li, Percy Liang · arXiv · 2021-1-1

- **Problem** Fine-tuning changes every weight of a large pretrained language model, so each downstream task needs its own stored copy of the model.
- **Method** Prefix-tuning freezes the Transformer and trains only a continuous prefix that later positions attend to as virtual tokens.

## Why a full model copy per task is costly

Fine-tuning adapts a pretrained language model by updating all of its parameters, so every downstream task leaves behind a modified copy of the whole model. The cost grows with model size: the paper cites 774M parameters for GPT-2 and 175B parameters for GPT-3. Lightweight fine-tuning keeps most pretrained weights frozen and adds small trainable modules, and adapter-tuning does this by inserting task-specific layers between the layers of the pretrained model.

Adapter-tuning reaches performance comparable to fine-tuning while adding roughly 2-4% task-specific parameters.

Prompting offers another route that changes nothing in the weights: GPT-3 receives an instruction and a few examples in its input, a setup known as in-context learning. That route is bounded by context length, because a Transformer conditions only on a limited window, 2048 tokens for GPT-3, so training sets larger than the window cannot be fully used.

The open question is whether a frozen model can be steered by a learned input that is much smaller than a model copy and is not limited to real words.

## A prefix that later positions attend to as virtual tokens

The method prepends a sequence of continuous, task-specific vectors to the input, and the authors call this sequence the prefix. Positions after the prefix attend to it as if it were a set of virtual tokens, but its entries are free parameters that need not match the embedding of any real word. Only the prefix is trained while the Transformer weights stay fixed, so one stored model can serve many tasks by swapping prefixes.

Figure 2 shows the layout for an autoregressive LM and for an encoder-decoder model.

For an autoregressive LM the input and output are concatenated as z = \[PREFIX; x; y\], and for an encoder-decoder model prefixes are placed on the encoder side and on the decoder side. Ordinary positions follow the usual recurrence, in which the activation at position i depends on the input token z\_i and the activations to its left. \\\[ h\_i = \\mathrm{LM}\_{\\varphi}(z\_i, h\_{\<i}) \\\] Prefix positions follow a different rule: their activation is copied from the trainable matrix P\_θ, and all other positions still run through the frozen LM.

\\\[ h\_i = \\begin{cases} P\_{\\theta}\[i,:\] & \\text{if } i \\in P\_{idx}, \\\\ \\mathrm{LM}\_{\\varphi}(z\_i, h\_{\<i}) & \\text{otherwise} \\end{cases} \\\]

The reasoning starts from prompting: a suitable context can steer a frozen LM toward a target word or behaviour without changing its parameters. Searching over discrete instructions is computationally hard, so the method optimizes continuous word embeddings instead, and their effects propagate upward through all Transformer layers and to later tokens.

The authors argue that intervening on all layers is more expressive than tuning only the embeddings, and the method therefore optimizes the prefix at every layer.

## How the prefix is trained and reparametrized

Training uses the same log-likelihood objective as fine-tuning, summed over the output positions in Y\_idx for y given x. The language model parameters φ are held fixed, and only the prefix parameters θ are updated by gradients. Because the prefix stays in the left context of every later position, the states to its right depend on θ as well.

Optimizing P\_θ directly was found to be unstable and to lower performance slightly. In preliminary experiments the authors also found direct optimization very sensitive to the learning rate and the initialization. They therefore write each row of P\_θ as an MLP applied to a smaller matrix P'\_θ that has the same number of rows.

The width of the smaller matrix is k, set to 512 for table-to-text and 800 for summarization, and the MLP maps k to the hidden dimension of the model. After training, the reparametrization is dropped and only P\_θ is saved.

## Datasets, baselines and training setup

The table-to-text benchmarks are E2E, with about 50K examples, 8 distinct fields and an average output length of 22.9, WebNLG, with 22K examples, and DART, with 82K examples and an average output length of 21.6. E2E covers a single domain of restaurant reviews, WebNLG covers 14 domains, and DART is open-domain and built from Wikipedia tables.

WebNLG training and validation use 9 DBpedia categories, while the test split adds 5 unseen categories used to measure extrapolation.

E2E is scored with BLEU, NIST, METEOR, ROUGE-L and CIDEr, WebNLG with BLEU, METEOR and TER, and DART with BLEU, METEOR, TER, MoverScore, BERTScore and BLEURT. The summarization task uses XSUM, which has 225K examples of news articles averaging 431 words, with summaries averaging 23.3 words, and it is reported with ROUGE-1, ROUGE-2 and ROUGE-L.

For table-to-text the prefix is compared with fine-tuning, fine-tuning of only the top two layers (FT-TOP2) and adapter-tuning, and the summarization comparison is against fine-tuning BART. The state-of-the-art rows come from prior published systems, Shen et al. (2019) for E2E and Kale (2020) for WebNLG, and no official model is available for DART.

The authors use GPT-2 MEDIUM and GPT-2 LARGE for table-to-text, with the linearized tables as inputs, and BART LARGE for summarization, with articles truncated to 512 BPE tokens.

Training uses AdamW with a linear learning rate schedule, following the Hugging Face default setup, and the hyperparameters that were tuned include epochs, batch size, learning rate and prefix length. Prefix-tuning takes about 0.2 hours per epoch on 22K examples, against about 0.3 hours for fine-tuning, and summarization takes 1.25 hours per epoch on XSUM.

## Table-to-text results

With 0.1% task-specific parameters, the prefix outperforms the lightweight baselines ADAPTER (0.1%) and FT-TOP2 and reaches performance comparable to fine-tuning on E2E, WebNLG and DART. The prefix and the adapter were given the same 0.1% budget, and on average the prefix scores 4.1 BLEU higher per dataset than ADAPTER (0.1%). The per-task cost is 250K parameters for E2E, 250K for WebNLG and 500K for DART, against 345M GPT-2 parameters.

Storing one shared Transformer plus a prefix means the stored prefix is 1000x smaller than a fine-tuned copy.

Table 1 reports these E2E scores alongside WebNLG and DART results, with the best score per model in bold.

The authors describe prefix-tuning as more Pareto efficient than adapter-tuning, since it uses far fewer parameters while improving generation quality. Going from GPT-2 MEDIUM to GPT-2 LARGE keeps the advantage, which the authors read as a sign the approach may scale to larger models with a similar architecture, such as GPT-3, a possibility they did not test.

## Summarization results

The gap is larger than on the table-to-text datasets, and the authors name three differences: XSUM has about 4x more examples, its input articles are about 17x longer than linearized tables, and summarization needs reading comprehension and the identification of key content. The authors also note that fine-tuning GPT-2 underperformed fine-tuning BART in a preliminary experiment, so GPT-2 was left out of the summarization comparison.

## Low-data results

For each size five datasets were sampled and two training random seeds were averaged, so each low-data estimate averages 10 models. A development split of 30% of the training size was used to choose hyperparameters and for early stopping.

Both methods tend to undergenerate in low-data regimes, leaving out table content, but the prefix output is more faithful. For example, fine-tuning trained on 100 examples falsely describes the customer rating as low, while the true rating is average, and the prefix trained on 100 and 200 examples describes it faithfully.

## Extrapolation to unseen topics

For WebNLG, the models train on the 9 seen categories and are tested on the 5 unseen ones.

For XSUM the authors built two splits: news-to-sports trains on news articles and tests on sports articles, and within-news trains on the world, UK and business categories and tests on the remaining news categories. On within-news the prefix reached 39.41, 16.87 and 31.47, against 39.20, 16.35 and 31.15 for fine-tuning. The authors report that the prefix extrapolates better than fine-tuning under all metrics on both table-to-text and summarization.

Adapter-tuning also extrapolates well and is comparable with the prefix, which the authors take as evidence that keeping the LM parameters intact helps on unseen topics. The authors leave the reason for these gains open.

## Prefix length and infix placement

Longer prefixes lower the training loss but give slightly worse test results, which the authors read as overfitting. Longer prefixes add little inference cost, which the authors attribute to attention over the prefix being parallelized on GPUs.

Infix-tuning places the trainable activations between x and y instead of at the start of the sequence. The authors explain the gap by noting that a prefix can affect the activations of both x and y, whereas an infix can only influence the activations of y.

## Embedding-only tuning and initialization

The embedding-only ablation makes the word embeddings the free parameters while the upper layers are computed by the Transformer. The authors order the methods by expressive power: discrete prompting is less expressive than embedding-only tuning, which is less expressive than prefix-tuning.

Random initialization of the prefix gives low performance with high variance in low-data settings. The authors connect this choice to keeping the pretrained LM as close to its original state as possible.

## Personalization and batching

The authors suggest personalization as a setting where each user is an independent task with a separate prefix, so data stays separated and users can be added or deleted without cross-contamination. Since the shared LM is unchanged, requests from different users can be batched together by prepending each user's prefix to the input, whereas the authors say adapter-tuning cannot batch across users.

The authors argue that preserving the pretrained parameters may help generalization to domains unseen in training, and they link this to the extrapolation results. They cite concurrent work that uses intrinsic dimension to explain why updating a small number of parameters can be enough, and they say their results show that a very small prefix can attain good generation performance.

## Limitations

The experiments use GPT-2 MEDIUM and GPT-2 LARGE for table-to-text and BART LARGE for summarization. In the preliminary experiments GPT-2 and BART failed to follow natural language instructions in this setting, and GPT-3 was the only model that did, so the method was not tested with GPT-3.

The mechanism behind the extrapolation gains is an open question, and the authors do not explain it.

Long prefixes overfit, and direct optimization of the prefix is sensitive to learning rate and initialization. Timings for the two tasks come from different GPUs, so the training times for table-to-text and summarization are not directly comparable.

## Paper info

- **Authors**: Xiang Lisa Li, Percy Liang
- **Venue**: arXiv · Preprint
- **First published**: 2021-1-1
- **Added**: 2026-10-20
- **Updated**: 2021-1-1
- **Version**: v1
- **arXiv**: 2101.00190
- **Category**: cs.CL
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/2101.00190v1) · [PDF ↗](https://arxiv.org/pdf/2101.00190v1)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Xiang Lisa Li, Percy Liang (2021). Prefix-Tuning: Optimizing Continuous Prompts for Generation. arXiv:2101.00190v1. https://arxiv.org/abs/2101.00190v1

**BibTeX**

```
@misc{li2021prefix,
  title = {{Prefix-Tuning: Optimizing Continuous Prompts for Generation}},
  author = {Xiang Lisa Li and Percy Liang},
  year = {2021},
  eprint = {2101.00190},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2101.00190v1}
}
```

## Other paper commentary

- [Neural Machine Translation of Rare Words with Subword Units](https://refivu.com/en/papers/0950e659-f6cc-4852-b244-bbb2742bf059-neural-machine-translation-of-rare-words-with-subword.md)
- [SQuAD: 100,000+ Questions for Machine Comprehension of Text](https://refivu.com/en/papers/b88d7f5b-b008-4a74-a452-4513427bbf9f-squad-100-000-questions-for-machine-comprehension-of.md)
- [Measuring Massive Multitask Language Understanding](https://refivu.com/en/papers/c93df260-9bcd-49a6-95e1-3da2df6130ee-measuring-massive-multitask-language-understanding.md)
- [GShard: Scaling Giant Models with Conditional Computation and Automatic Sharding](https://refivu.com/en/papers/2481fdbe-b100-433d-877a-6976f982ccaa-gshard-scaling-giant-models-with-conditional-computation-and.md)
- [GLUE: A Multi-Task Benchmark and Analysis Platform for Natural Language Understanding](https://refivu.com/en/papers/a5e0caad-afbf-4fa4-b072-f6f5cab0c916-glue-a-multi-task-benchmark-and-analysis-platform.md)
- [ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators](https://refivu.com/en/papers/0e7c3940-ee80-4356-b951-389a0a857775-electra-pre-training-text-encoders-as-discriminators-rather.md)
- [WebGPT: Browser-assisted question-answering with human feedback](https://refivu.com/en/papers/b41258c0-ce1e-478c-ad2b-6bccd936ae34-webgpt-browser-assisted-question-answering-with-human.md)
- [Reflexion: Language Agents with Verbal Reinforcement Learning](https://refivu.com/en/papers/a572f458-b121-4d38-bfc9-7a77309a3aba-reflexion-language-agents-with-verbal-reinforcement-learning.md)
- [SparseGPT: Massive Language Models Can Be Accurately Pruned in One-Shot](https://refivu.com/en/papers/98e70bdf-a832-4686-b3f8-e3eefd5887c4-sparsegpt-massive-language-models-can-be-accurately-pruned.md)
- [GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints](https://refivu.com/en/papers/11792bcd-8c73-4a2d-8b43-c855c3d7ad48-gqa-training-generalized-multi-query-transformer-models-from.md)
- [Fast Transformer Decoding: One Write-Head is All You Need](https://refivu.com/en/papers/65f892e7-2a21-4ce7-9e89-c75f7ec6b23c-fast-transformer-decoding-one-write-head-is-all.md)
- [Finetuned Language Models Are Zero-Shot Learners](https://refivu.com/en/papers/3dedf278-64d7-4653-93ff-bf4504ae70ac-finetuned-language-models-are-zero-shot-learners.md)

## Terms in this paper

- [in-context learning](https://refivu.com/en/terms/d53d2af6b551-in-context-learning)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/01cf041e-b71c-444b-8b44-e94ac976a9db-prefix-tuning-optimizing-continuous-prompts-for-generation)
