skip to content

How do input-only prompt tuning, prefix tuning at every layer and a prompt encoder differ, and what does each cost in parameters?

level: middleimportance: should knowfreq 26%

answer

  1. where the vectors enter
  2. one layer or all of them
  3. a key and a value
  4. kept for training, dropped after
  5. stored count differs from trained count

basics

~20 s

Prompt tuning trains vectors at the input, costing tokens x width. Prefix tuning trains a key and value per layer, costing tokens x layers x 2 x width. A prompt encoder is a training-time network that produces the vectors.

solid answer

~50 s

They answer different questions. Input-only prompt tuning (Lester et al., 2021) adds vectors at the embedding layer only, costing `tokens x width`, and lets the frozen layers carry their effect upward. Prefix tuning (Li and Liang, 2021) supplies vectors at every layer as attention keys and values, costing `tokens x layers x 2 x width`, which is 48 times more on a 24-layer model. A prompt encoder is an axis of its own: a small network, such as an MLP or LSTM, that produces the vectors during training to stabilize learning or model dependencies between them. It can add far more trainable parameters than the vectors themselves, then be dropped, so you store the vectors alone. Results vary: input-only matched fine-tuning on a benchmark at about 11 billion parameters, deep variants close gaps on smaller models, and the encoder's benefit depends on the task.

code

plaintext · 9 lines
plaintext
Illustrative model: width w = 2,048, layers L = 24, virtual tokens k = 20

Input-only, stored:     k x w          = 20 x 2,048            =    40,960
Every layer, stored:    k x L x 2 x w  = 20 x 24 x 2 x 2,048   = 1,966,080
Ratio:                  L x 2          = 48

Prompt encoder, training only (hidden size 512, output 2 x L x w = 98,304):
Last layer weights:     512 x 98,304                           = 50,331,648
Against stored prefix:  50,331,648 / 1,966,080                 = 25.6 times

go deeper

for a junior

Recall the plain difference: prompt tuning touches only the input, and prefix tuning supplies vectors for every layer. Know that both keep the model's weights fixed in their standard forms.

for a middle

Work both parameter counts with stated sizes, and explain the factor of 2 as a key and a value. Say what a prompt encoder is, and separate stored parameters from trained ones.

for a senior

Keep the three axes apart and quote each result with its scope. A strong candidate notes that original P-tuning tuned the model on SuperGLUE and that encoder benefit varied by dataset.

for a principal

Weigh depth by what it costs a many-task platform: a 48-fold stored increase in this example, against a capacity gain that the papers show is largest on smaller models and harder tasks.

## Three separate axes These names get treated as rungs of one ladder, but they answer three different questions: - **Where do the vectors enter?** At the input only, or at every layer. - **How are they produced in training?** Trained directly, or as the output of a small network. - **Is the model frozen?** Most of this family freezes it, and one well-known paper partly does not. ## Input-only: prompt tuning In Lester et al. (2021), the vectors are prepended to the embedded input, and everything above is computed by the frozen layers as usual. Each layer still recalculates what the vectors mean for this input, so the frozen model carries their effect upward. The stored cost is `tokens x width`. The authors use no reparameterization, no task-specific output layer and no change to the input. ## Every layer: prefix tuning and deep prompts In Li and Liang (2021), the vectors at the prefix positions supply the activations of **all** layers directly, rather than being computed. Each activation is a key and value pair, which is where the factor of 2 comes from, so the stored cost is `tokens x layers x 2 x width`. The P-tuning v2 paper (Liu et al., 2021) adapts the same idea to understanding tasks and calls it deep prompt tuning. Qin and Eisner (2021) use another deep form, adding small learned changes to a prompt's activations at each layer. The argument for depth, from the v2 paper, is that the number of tunable parameters at the input is limited by sequence length, and input embeddings have a relatively indirect effect on predictions. Li and Liang tested an embedding-only variant on their models and report a significant drop. ## Prompt encoders: reparameterization A **prompt encoder** does not read your text. It is a small network that maps trainable values to the vectors the model sees. - Li and Liang use an MLP because updating the matrix directly was unstable and very sensitive to learning rate and initialization. Once trained, it can be dropped and only the prefix is saved. - Liu et al. (2021), in the original P-tuning, use an LSTM or MLP to model dependencies between vectors. Their few-shot ablation found direct embeddings unstable on some tasks. - Lester et al. report needing no encoder on their tasks and sizes. - The v2 paper finds the MLP's effect inconsistent: helpful on some datasets, neutral or harmful on others. So treat it as optional and test it. An encoder also inflates the trained count well past the stored one, as Lester et al. point out for prefix tuning. ## Other differences that get blurred Original P-tuning interleaves vectors with written prompt tokens. Its strong results on the SuperGLUE benchmark came with the model tuned jointly, and only its knowledge-probing runs kept the model frozen. The v2 paper keeps the backbone frozen but puts a trained linear head on top. | Method | Vectors enter | Frozen model | Stored cost | Reported at the time | |---|---|---|---|---| | Prompt tuning | Input | Yes | `k x w` | Matches model tuning at about 11B on SuperGLUE; smaller models lag | | Prefix tuning | Every layer | Yes | `k x L x 2 x w` | Comparable on table-to-text; slightly behind on summarization | | P-tuning | Input, interleaved | Knowledge probing only | `k x w` | Beat discrete prompts on knowledge probing | | P-tuning v2 | Every layer | Yes, plus a head | 0.1 to 3 percent | Comparable to fine-tuning from 330M to 10B on the tasks tested | ## Depth is not a free win The worked figures below show the price. Depth pays for itself on smaller models and harder tasks in the v2 paper, while Qin and Eisner typically saw only small gains from tuning all layers, with one model substantially hurt. At about 10 billion parameters, on classification benchmarks, the input-only form was already competitive. The v2 paper also found that prompts added to layers near the output did better than the same number near the input, on the two datasets it tested, so full depth may not be needed. ## Choosing between them 1. Start input-only, because it is the cheapest to store and has the fewest moving parts. 2. Move to vectors at every layer when held-out scores show a capacity gap, most likely on a smaller model or a token-level task. 3. Add an encoder only if training is unstable or sensitive, and compare it with direct vectors on the same data.

  • Do vectors at every layer slow inference down?
    Li and Liang (2021) report that longer prefixes had a negligible impact on inference speed, because attention over the prefix is parallelized on the GPU. That is one measurement on their setup. A large per-layer prefix still takes memory for each batch, so measure it on your own hardware if serving latency is tight.
  • Do you need all layers, or can deep vectors go on some of them?
    The P-tuning v2 paper tested this on a mid-sized model and two datasets. With the same amount of parameters, adding vectors to layers near the output always beat adding them near the input, and on one dataset the last third of the layers came very close to all of them. That suggests trying a subset, then checking on your task.

  • Prompt tuning and prefix tuning are the same method under two names.
  • A prompt encoder is the part that reads the user's prompt text.
  • You must ship the prompt encoder and run it for every request at inference.
  • Every learned prompt method in this family keeps the model frozen in all its results.
  • Vectors at every layer always beat vectors at the input, whatever the model size.