Attention and Compression is all you need for Controllably Efficient Language Models

Jatin Prakash, Aahlad Manas Puli, Rajesh Ranganath · DOI

TL;DR

This paper introduces the Compress & Attend Transformer (CAT), a novel architecture that efficiently models long sequences by compressing chunks of tokens. CAT offers a unique test-time control over the quality-efficiency trade-off, allowing a single model to adapt to different compute budgets without retraining, outperforming existing efficient models and matching dense transformers in performance.

What Problem Does This Paper Address?

The self-attention mechanism in Transformers, while powerful, has a quadratic computational cost with respect to sequence length, making it expensive for long contexts. Existing efficient alternatives like sparse attention, linear attention, and recurrent methods often compromise in-context recall performance or require complex architectural designs and heuristics. Furthermore, these methods typically fix the compute-efficiency trade-off during training, forcing users to train multiple models for different needs. This paper addresses the need for a single, adaptable, and efficient Transformer architecture that can maintain high performance across various compute budgets and downstream tasks.

Methods

The core innovation is the Compress & Attend Transformer (CAT) architecture. It consists of two main components:

  • Compressor: A bidirectional Transformer that takes a chunk of tokens and compresses it into a fixed-size representation. This compression happens in parallel for all chunks.
  • Decoder: A causal Transformer that autoregressively generates tokens. Crucially, it attends to the compressed representations of past chunks, not the raw past tokens.

This design allows CAT to process sequences by attending to compressed summaries of past information, significantly reducing the effective sequence length for attention. A key feature is the adaptive nature: by adjusting the "chunk size" parameter at test-time, users can control the trade-off between quality (in-context recall) and efficiency (compute/memory usage) without any retraining. The authors also developed a scalable and efficient PyTorch implementation for training and generation.

Datasets

The paper evaluates CAT on a variety of benchmarks, including:

  • Language Modeling: WikiText-103, FineWeb-Edu.
  • Common-Sense Reasoning: PIQA, HellaSwag, ARC-challenge, ARC-Easy, Winogrande, OpenBookQA, TriviaQA, TREC.
  • Long-Context Understanding: LongBench (various tasks like QAS, MQA, HQA, 2WMQ, TQA, TREC).
  • Real-world In-context Recall: SWDE, FDA, SQUAD, DROP, RULER (needle-in-haystack tasks).
  • State-tracking Tasks: BabiLong (qal subset).

No new benchmarks were introduced.

Key Insights and Ideas

  • Compression as a Test-Time Knob: The most significant insight is that chunk size can act as a direct control for the quality-efficiency trade-off, allowing a single model to adapt to diverse needs without retraining. This is a departure from previous methods that require separate models for different budgets.
  • Decoupling Compression and Decoding: CAT separates the task of compressing past context from the task of generating new tokens. This allows for efficient parallel compression and a focused decoder.
  • Memory Efficiency Through Compression: By only keeping compressed representations of past chunks, CAT drastically reduces the KV cache size, a major bottleneck in generation.
  • Scalable Training: The parallel nature of compression and the clever use of attention masks enable efficient end-to-end training, unlike some other recurrent or compressed-context approaches.
  • Performance Beyond Efficiency: CAT not only achieves efficiency but also matches or surpasses dense transformers in performance, particularly in in-context recall tasks, suggesting that compression can be done without significant information loss.

Key Results

  • Performance: A single adaptive CAT model outperforms many popular efficient baselines across various compute-memory budgets.
  • Speed and Memory: CAT models are 1.4-3x faster and require 2-9x less memory than dense transformers of comparable scales.
  • In-context Recall: CAT-4 (the least efficient setting) outperforms dense transformers on real-world in-context recall tasks, while being 1.5x faster and 2x more memory efficient.
  • Adaptability: CAT demonstrates that a single model can achieve strong results across different compute-memory budgets, as shown by the red dots in Figure 1 representing a single model evaluated at different settings.
  • Scaling: CATs scale similarly to their dense counterparts, as shown in Figure 5.

Limitations and Future Work

  • Training Cost: The current implementation for training CATs can be twice as slow due to inefficient compilation (using PyTorch FlexAttention API). Developing custom kernels could mitigate this.
  • Compression Limits: For very large chunks, there might be limits to what information a fixed-sized representation can capture, potentially impacting recall (as seen in finetuning CAT-32 on S-NIAH-U). More pre-training or smaller chunk sizes might be needed for tasks requiring very high recall.
  • Future Work:
    • Exploring other sequence mixers (e.g., linear attention) for the compressor.
  • Developing data-dependent adaptivity, where CAT learns to allocate budgets itself via RL post-training.
  • Instantiating CAT as a layer rather than a full architecture, enabling hybrid models.
  • Investigating parallel compression of older context only (e.g., after 1K tokens).
  • Further scaling up CATs to larger model sizes and longer training regimes.
  • Developing efficient attention kernels for training.

Summary updated

BibTeX
@misc{prakash2025attention,
  author = {Jatin Prakash and Aahlad Manas Puli and Rajesh Ranganath},
  title = {{Attention and Compression is all you need for Controllably Efficient Language Models}},
  year = {2025},
  eprint = {2511.05313},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2511.05313},
}
Figure