Manuscript Offprint

arXiv:2610.24123

Prefix-Tuning for Arbitrary Output Sequences on Pretrained Transformers

Peter Cho-Ho Lam, Ziyi Wang, Zirui Zhou

Abstract

Prefix-tuning is a parameter-efficient fine-tuning method for large language models (LLMs) that steers model outputs by prepending task-specific prefix representations to the input sequence. Despite its practical success, the theoretical understanding of the expressiveness of prefixes remains incomplete. In particular, the following question remains open: Given a pretrained autoregressive Transformer, for any input-output sequence pair (x,y)(x, y), does there always exist a prefix S such that prepending S to x induces the model to generate the target output y? In this work, we prove that under the assumption that y is in the range of the pretrained Transformer, such a prefix S exists and can be explicitly computed by solving multiple linear systems. We further show that this assumption is necessary, in the sense that such a prefix may not exist when the assumption fails, thereby providing a complete answer to the above question. Our analysis is constructive and the obtained theoretical results hold under fairly general assumptions on model architecture. Extensive experiments on GPT-2 and Qwen3-4B demonstrate that our algorithm produces prefixes with strong control over model outputs.

1 Introduction

Large language models (LLMs) have become a major driving force behind modern technological advancement. Their effectiveness has been demonstrated across a wide range of applications, including software engineering, scientific research, healthcare, finance, education, and legal domains (Bommasani et al., 2021; Chen et al., 2024; Yang et al., 2025b). However, most LLMs are trained as general-purpose models, which can limit their performance on domain-specific tasks that require specialized knowledge or terminology. Empirical studies consistently show that models fine-tuned for a target domain outperform general-purpose models on domain-specific benchmarks and task-relevant metrics (Beltagy et al., 2019; Lee et al., 2019; Chalkidis et al., 2020; Gururangan et al., 2020).

Although fine-tuning is substantially cheaper than training a model from scratch, full fine-tuning remains computationally expensive due to the need to update and store all model parameters, making it impractical for many users and organizations (Strubell et al., 2019). These limitations have motivated growing interest in parameter-efficient fine-tuning methods, which aim to reduce training costs while retaining performance (He et al., 2021; Ding et al., 2023; Xu et al., 2023; Han et al., 2024). Parameter-efficient fine-tuning techniques update a limited subset of parameters or introduce lightweight modules, achieving performance comparable to full fine-tuning at a fraction of the computational cost. (Houlsby et al., 2019; Ben Zaken et al., 2022; Karimi Mahabadi et al., 2021; Hu et al., 2022; Lester et al., 2021; Li and Liang, 2021; Lian et al., 2022).

Prefix-tuning, a prominent parameter-efficient fine-tuning technique, adapts new tasks by learning a small set of continuous task-specific vectors, or prefixes, which are prepended to the model's hidden states while keeping the original parameters frozen (Li and Liang, 2021). By optimizing only these

40th Conference on Neural Information Processing Systems (NeurIPS 2026).

prefixes, prefix-tuning avoids the high computational and memory costs of full fine-tuning. This efficiency makes prefix-tuning a practical and scalable approach for adapting large models to diverse tasks and deployment settings (Liu et al., 2022).

Despite its popularity, the theoretical foundations of prefix-tuning remain poorly understood. A desirable property of prefix-tuning is expressiveness: Can one induce arbitrary desired behaviors in a Transformer solely by appending prefixes? Formally, this can be framed as the following problem:

Problem 1. Given a pretrained autoregressive Transformer, for any input-output sequence pair (x,y)(x, y), does there always exist a prefix S such that prepending S to x induces the model to generate the target output y?

Several existing works have studied the expressiveness of prefix-tuning (Wang et al., 2023; Petrov et al., 2024b; Hu et al., 2025; Liang et al., 2025); however, their analyses suffer from three notable limitations. (i) Model mismatch: Their results are established for hand-crafted Transformers with preassigned weights and simplified architectures, rather than pretrained models specified by the user. (ii) Generation mismatch: A number of works study the approximation of arbitrary sequence-to-sequence functions (Petrov et al., 2024b; Hu et al., 2025), whereas in practice language models generate outputs autoregressively through repeated queries to the Transformer. This autoregressive setting imposes significantly stronger structural constraints than a one-shot sequence mapping. 1^{1} (iii) Scaling assumptions: The resulting guarantees typically rely on impractical assumptions regarding model width, depth, or prefix length (Petrov et al., 2024b; Liang et al., 2025). Due to these limitations, expressiveness results have never been empirically demonstrated on modern LLMs.

In this work, we address this gap by establishing an expressiveness result for pretrained autoregressive Transformers with general architectural components, where the model is fixed a priori and cannot be modified. Specifically, we prove the existence of S in Problem 1 under the assumption that y lies in the range of the Transformer; that is, y is a sequence reachable through autoregressive generation. With minor adaptations, our proof applies to nearly all common modern LLM architectures, including GPT-2 (Radford et al., 2019), which features multi-head attentions, residual connections, and positional encodings. The statement of our main theorem (Theorem 2.1) is theoretically tight: removing any assumption leads to counterexamples, implying that our result is best possible and that Problem 1 is fully resolved.

Our proof also provides a practical algorithm to compute such a prefix. The computation is training-free and amounts to solving a fixed and small number of low-dimensional systems of linear equations, which can be done efficiently with minimal hardware requirements. The construction of our linear-system formulation is based on attention matching, a framework that matches attention outputs across different autoregressive decoding trajectories. We note that a related attention matching framework was independently developed by Zweiger et al. (2026) for KV cache compaction. We discuss the common underlying principles and the differences between the two frameworks in Appendix H.

To validate our theory and algorithm, we conducted extensive experiments using GPT-2 (Radford et al., 2019). Our results demonstrate a high success rate in achieving complete control of output sequences through prefixes. To the best of our knowledge, this is the first instance in which a theoretical expressiveness result has been empirically demonstrated and validated in a modern LLM. We also achieved strong results on Qwen3-4B (Yang et al., 2025a), which features grouped-query attention (GQA) (Ainslie et al., 2023).

Below is a summary of our contributions:

• We resolve a long-standing open question on the expressiveness of prefix-tuning in practical LLMs and fine-tuning scenarios by providing and proving the necessary and sufficient conditions on the existence of a prefix that can generate essentially any arbitrary output.

• We provide an efficient, training-free algorithm for constructing such prefixes and validate it through extensive experiments on GPT-2 and Qwen3-4B, showing that the resulting prefixes achieve a high success rate in fully controlling output sequences.

1^{1}For a more thorough discussion on why sequence-to-sequence function is incompatible with autoregressive generation, see our Appendix A.

References (59)

  • GQA: Training generalized multi-query transformer models from multi-head checkpoints
  • SciBERT: A pretrained language model for scientific text
  • BitFit: Simple parameter-efficient fine-tuning for transformer-based masked language-models
  • LEGAL-BERT: The muppets straight out of law school
  • A survey on large language models for critical societal domains: Finance, healthcare, and law
  • Parameter-efficient fine-tuning of large-scale pre-trained language models
  • Don’t stop pretraining: Adapt language models to domains and tasks
  • Parameter-efficient fine-tuning for large models: A comprehensive survey
  • Towards a Unified View of Parameter-Efficient Transfer Learning
  • Parameter-efficient transfer learning for NLP. In Proceedings of the 36th International Conference on Machine Learning, pages 2790–2799
  • LoRA: Low-rank adaptation of large language models
  • Fundamental limits of prompt tuning transformers: Universality, capacity and efficiency
  • Compacter: Efficient low-rank hypercomplex adapter layers
  • BioBERT: a pre-trained biomedical language representation model for biomedical text mining
  • The power of scale for parameter-efficient prompt tuning
  • Prefix-tuning: Optimizing continuous prompts for generation
  • Scaling & shifting your features: A new baseline for efficient model tuning
  • Towards infinite-long prefix in transformer
  • P-tuning: Prompt tuning can be comparable to fine-tuning across scales and tasks
  • gpt-oss-120b & gpt-oss-20b Model Card
  • When do prompting and prefix-tuning work? A theory of capabilities and limitations
  • Prompting a pretrained transformer can be a universal approximator
  • Adapters: A unified library for parameter-efficient and modular transfer learning
  • Language models are unsupervised multitask learners
  • Energy and policy considerations for deep learning in NLP. In Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics, pages 3645–3650, Florence, Italy, July 2019
  • Universality and limitations of prompt tuning
  • Parameter-efficient fine-tuning methods for pretrained language models: A critical review and assessment (opens arXiv in a new tab)
  • A comprehensive study of jailbreak attack versus defense for large language models
  • Qwen3 Technical Report
  • Survey of specialized large language model (opens arXiv in a new tab)
  • Jailbreak attacks and defenses against large language models: A survey (opens arXiv in a new tab)
  • Root mean square layer normalization
  • Fast kv compaction via attention matching (opens arXiv in a new tab)
  • This makes it tempting to derive our result as a consequence of theirs
  • Then, T simply takes the last observed token as the next-token prediction
  • The token $b$ is clearly reachable by $\mathcal{T}$ (e.g
  • The target $(b)$ remains reachable from the source input $(b)$
  • Consider the following two input-output pairs:
  • It is tempting to address Example 3 by imposing stronger assumptions
  • You are an idiot
  • This capability relies on two key assumptions: first, that there exists a source input capable of generating the desired target output, and second, that the user input has the same length as the source input
  • The first approach is to directly prompt the model to repeat a given sentence, since GPT-2 lacks post-training mechanisms to avoid hazardous outputs
  • As shown in Table 3, the success rate remains at $100\%$ across a wide range of input lengths, and only slightly drops when the input length deviates substantially from the source length
  • Therefore, $\overline{S}$ is a Vandermonde matrix and it is well-known that its determinant is given by the product of mutual differences of $E_h(\mathbf{x}_n, \mathbf{s}), E_h(\mathbf{y}_1, \mathbf{s}), \ldots, E_h(\mathbf{y}_{k-1}, \mathbf{s})$, which is non-zero by our assumption
  • It is also clear from the proof we only require prefixes at the last layer
  • The $Q$-bias does not influence the proof structure; simply adding the bias to the $Q$-term does not introduce conflicts
  • Expanding the exponent gives:
  • Therefore, adding $K$-bias is equivalent to multiplying each row of the original $\overline{S}$ matrix by a non-zero constant factor:
  • The results are illustrated in Figure 2
  • At very small attention limits, the attention scores are too weak to reliably preserve relevant information, such that even a large number of repetitions (e.g., repeat = 90) still results in frequent override failures
  • Performance improves substantially when increasing repeat from 0 to small positive values, while further increases (e.g., from 50 to 90) result in minor gains, indicating early saturation
  • When the attention limit is very small, increasing repetition alone cannot recover performance, whereas at sufficiently large attention limits, even modest repetition is sufficient to achieve high success rates
  • Tasks with longer inputs require higher attention limits and greater repetition to achieve comparable performance, while shorter input-output settings reach near-saturation at much smaller values
  • TARGET_OUTPUT
  • A closely related attention matching framework was independently developed by Zweiger et al. (2026) for KV cache compaction
  • Both works exploit the observation that, once the attention keys are fixed, attention outputs depend linearly on the value representations
  • Despite this shared principle, the two frameworks address distinct research problems and differ substantially in their theoretical objectives
  • given a pretrained autoregressive Transformer and a reachable target output sequence, we seek to construct a prefix that induces the model to generate that sequence
  • The success of attention matching in our work and the concurrent work of Zweiger et al. (2026) on a different application highlights its potential as a powerful and broadly applicable framework worthy of further study