Context Parametrization with Compositional Adapters

Josip Jukić, Martin Tutek, Jan Šnajder

TL;DR

COMPAS introduces a meta-learning framework that bypasses the high costs of long-context prompting by translating text chunks (like few-shot examples or retrieved documents) directly into LoRA adapter parameters. Crucially, these generated adapters can be merged via simple algebraic addition, allowing LLMs to seamlessly integrate multiple pieces of context in parameter space rather than input space. This approach drastically reduces inference latency and memory overhead while outperforming standard in-context learning.

What Problem Does This Paper Address?

When adapting Large Language Models (LLMs) to new tasks, practitioners usually choose between two paradigms: In-Context Learning (ICL), where demonstrations are crammed into the prompt, or Supervised Fine-Tuning (SFT), which updates the model's weights. Both have steep downsides. ICL suffers from quadratic computational overhead as prompts grow, and long contexts often destabilize attention mechanisms (the "lost in the middle" phenomenon). SFT, on the other hand, is computationally expensive and lacks the flexibility to switch tasks on the fly.

An emerging alternative is context parametrization—using a secondary network to translate context directly into adapter parameters (like LoRA). However, prior methods only generated adapters from a single, monolithic block of text. In reality, context is modular: we use chains of instructions, multiple distinct examples, or sets of documents retrieved from a database. Prior hypernetwork approaches lacked a principled way to combine these separate pieces of information without reprocessing everything from scratch.

Methods

The authors introduce COMPAS (Compositional Adapters), a teacher-student meta-learning framework designed to enforce linear additivity in parameter space.

Figure 1. Overview of the COMPAS framework. Each context ci is mapped into an adapter by the generator G, while the query q is processed by the student S. The teacher T processes the concatenated input [c; q], and G is trained so that composed adapters in S align ys with yt, effectively transferring contextual information from input space to parameter space.

The architecture consists of three main parts:

  1. The Teacher: A frozen base LLM that processes the fully concatenated context and query in the standard text space.
  2. The Generator ($G$): A lightweight network that takes an individual context chunk, passes it through the base LLM with a specialized adapter, pools the hidden states, and uses a linear bottleneck to project it into a compact latent space. It then outputs LoRA weights ($A$ and $B$ matrices) via bias-free linear projections.
  3. The Student: The same frozen base LLM, but instead of reading the context tokens, it only receives the query. The context is injected by simply summing the LoRA adapters generated for each individual context chunk.

To train the generator to behave like a mathematical homomorphism (where text concatenation equals parameter addition), COMPAS optimizes a joint loss function with three components:

  • Student-Teacher Alignment ($L_{ST}$): Minimizes the KL-divergence between the student's and teacher's output distributions.
  • Additivity Regularization ($L_{ADD}$): Explicitly penalizes the generator if the adapter it creates for a concatenated text differs from the sum of the adapters it creates for the individual pieces.
  • Context Reconstruction ($L_{RECON}$): Forces the student model to autoregressively reconstruct the original context from the adapter parameters when prompted with a special [RECON] token, ensuring that information isn't lost or collapsed during the mapping.

Datasets

The framework was evaluated across three distinct base models (LLaMA-3.1 8B, Llama-3.2 3B, and Qwen-2.5 7B) using the following benchmarks:

  • MMLU & ARC-Challenge: Used to evaluate few-shot in-context learning by turning blocks of 4 demonstrations into individual adapters.
  • HotpotQA: Used to evaluate extractive question answering, where retrieved gold text passages were encoded as parametric memories.
  • XSUM: Used to test the framework's generalization to long-form abstractive summarization.

Key Insights and Ideas

  • Collapsing Text Order for Stability: Text concatenation is inherently ordered, making LLMs highly sensitive to prompt ordering. By forcing the generator to be additive ($G(c_1) + G(c_2) = G(c_2) + G(c_1)$), COMPAS treats context as an unordered set rather than a sequence. This eliminates order-sensitivity and stabilizes performance across long contexts.
  • Weak-to-Strong Generalization: Interestingly, the student model often corrects the teacher's errors. During training, the student receives weak pseudo-labels from the teacher but progressively refines them, allowing COMPAS to outperform the very teacher it learns from on harder tasks.
  • The Necessity of Generator Capacity: The authors found that simple linear hypernetworks fail to scale as more demonstrations are added. An adapter-based generator is required to capture the complex semantics necessary for high-fidelity parameter generation.

Key Results

  • Performance Gains: COMPAS consistently outperformed standard ICL and prior generative adapter baselines (like GenAda). In high-shot scenarios (e.g., 16-shot on MMLU and ARC), COMPAS even beat specialized context-specific fine-tuning (WILDA).
  • Decoupled Inference Cost: Because context tokens are completely removed from the prompt during inference, COMPAS achieved up to a 4.1× FLOPs speedup at 16-shot compared to standard ICL, while keeping peak memory usage nearly flat.
Figure 2. Effect of generator capacity on accuracy with LLaMA 8B on ARC-Challenge. Shaded areas show deviation over 10 runs.
  • High Reconstruction Fidelity: COMPAS retained excellent text reconstruction capabilities, scoring around 80-91% token-level F1 scores, proving that the adapters faithfully preserve the underlying context.

Limitations and Future Work

  • Order-Insensitivity: While commutativity helps with robustness, it is a double-edged sword. COMPAS cannot natively handle tasks where sequence order is vital, such as multi-step instruction chaining or narrative reasoning. The authors showcased a proof-of-concept "Slot-PE" positional embedding to fix this, but leave full exploration to future work.
  • Linearity vs. Expressivity: Enforcing strict linear additivity means the model might struggle with complex, non-linear interactions between different context chunks (e.g., cross-document contradiction resolution).
  • Generator Overhead: While inference is incredibly fast, the generator itself requires a large up-projection layer, which introduces a non-trivial parameter overhead during the initial context-encoding phase.

Summary updated

BibTeX
@misc{jukic2025context,
  author = {Josip Jukić and Martin Tutek and Jan Šnajder},
  title = {{Context Parametrization with Compositional Adapters}},
  year = {2025},
  eprint = {2509.22158},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2509.22158},
}
Figure