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

Jatin Prakash, Aahlad Manas Puli, Rajesh Ranganath · Submission to ICLR 2026 · Rejected

TL;DR

The Compress & Attend Transformer (CAT) reduces transformer decoding overhead by breaking inputs into chunks, compressing each chunk in parallel, and letting a causal decoder attend across past compressed representations. By training across multiple chunk sizes simultaneously, a single CAT checkpoint acts as an adaptive model where developers can dial a single test-time knob (chunk size) to trade recall quality for inference speed and memory footprint without any retraining.

What Problem Does This Paper Address?

Standard dense self-attention incurs quadratic computational complexity and linear KV-cache growth during autoregressive generation, which quickly becomes memory-bound at long sequence lengths. While linear attention, state-space models (e.g., Mamba2, GatedDeltaNet), and sparse attention mitigate this overhead, they introduce steep trade-offs:

  • Fixed-size recurrent states or aggressive local windows cause models to fail on in-context retrieval and copy tasks.
  • Static efficiency trade-offs are "baked in" during pre-training; an email drafting assistant cannot easily allocate more memory when switched to repository-level code completion.
  • Prior chunked or recurrent compression models often suffer from training instability (e.g., backpropagation through time) or bottleneck the entire sequence history into a single global vector.

Methods

CAT splits a sequence of length $N$ into non-overlapping chunks of size $C$. Its architecture relies on two standard dense transformer components:

  1. Compressor ($f_\theta$): A shallow bidirectional transformer (depth $L/4$, hidden size $D$) that processes each chunk in parallel using torch.vmap and linearly projects each chunk into a single vector representation in $\mathbb{R}^{D_g}$.
  2. Decoder ($g_\theta$): A causal transformer with a wider hidden size ($D_g = 2D$, depth $L$). While generating tokens inside the current chunk autoregressively, it attends to tokens within the active chunk and all past compressed chunk embeddings.
Original tokens:  [ Chunk 1 ]   [ Chunk 2 ]  ...  [ Active Chunk ]
                      ↓               ↓                  ↓
Compressor:       [  f(c₁)  ]     [  f(c₂)  ]            |
                      \               /                  |
Decoder Attention: ----\-------------/----> [ Autoregressive decoding ]
                   (KV cache retains only past f(c) representations)
  • Parallelized Training: Training avoids recurrence by interleaving chunks and their compressed vectors into a single sequence [c1, f(c1), c2, f(c2), ...]. A custom 2D attention mask (implemented via PyTorch's FlexAttention) ensures chunk tokens only attend to intra-chunk causal tokens and prior chunk summary tokens.
  • Test-Time Adaptivity: CAT is trained with chunk sizes $C \in \{4, 8, 16, 32\}$ sampled dynamically per iteration. A shared linear projection matrix is dynamically interpolated across chunk sizes alongside a learned chunk-indicator token, allowing chunk-size adjustment at test time with zero retraining.
  • Pure PyTorch Serving: The past token KV-cache is discarded; only $N/C$ compressed vectors are cached, slashing KV memory by a factor of $C$ and avoiding custom CUDA kernels.

Datasets

  • Pre-training: 15B tokens from FineWeb-Edu (4K context window).
  • Language Modeling & Commonsense Reasoning: WikiText-103, LAMBADA, PIQA, HellaSwag, WinoGrande, ARC-Easy, ARC-Challenge, and OpenBookQA.
  • Long-Context Understanding: LongBench suite (Qasper, MultiFieldQA, HotpotQA, 2WikiMQA, TriviaQA, TREC).
  • In-Context Recall & Retrieval: EVAPORATE benchmark (SWDE, FDA, SQuAD, DROP, TriviaQA), Multi-Query Associative Recall (MQAR), RULER (S-NIAH-N, S-NIAH-U), and BabiLong (qa1).

Key Insights and Ideas

  • Flexible Memory vs. Fixed Recurrent States: Rather than compressing the entire past into a constant-size hidden vector (like Block Transformer or SSMs), CAT maintains a memory that grows linearly with sequence length, but at an $N/C$ slope. This avoids information collapse while retaining massive cache savings.
  • Parameter Capacity $\neq$ Inference Cost: Mirroring Mixture-of-Experts (MoEs), CAT widens its decoder to $2D$ to handle decoding from compressed latents. Even with more parameters (~1B vs. ~260M dense baseline), CAT runs significantly faster because LLM inference is bound by memory bandwidth and KV-cache access, not raw parameter count.
  • Identical Computation Re-use: Computing forward passes across chunks shares duplicate key-values for historical chunks. Structuring the mask over interleaved tokens turns an otherwise $O((N/C)^3)$ computation into scalable $O(N^2/C)$ training.

Key Results

  • Inference Speed and Memory: Compared to a standard dense transformer at 4K context, CAT generates tokens $1.4\times$ to $3.2\times$ faster while slashing total memory footprint by $2.2\times$ to $9.5\times$ as chunk size scales from 4 to 32.
  • Real-World Recall: On long-document information extraction (SWDE and FDA datasets), CAT-4 achieves 47.1% average zero-shot recall versus 32.0% for Dense Transformer, 9.0% for Mamba2, and 31.0% for a 1:1 GatedDeltaNet Hybrid.
  • Needle-in-a-Haystack (RULER): At 4K sequence lengths on numeric needle recall (S-NIAH-N), CAT-4 maintains 96.0% accuracy, whereas the dense transformer degrades to 43.0% and Mamba2 drops to 18.6%.
  • Competitive Language Modeling: CAT matches dense baseline perplexity across LAMBADA (38.0 vs. 38.7) and WikiText-103 (18.1 vs. 19.6).

Limitations and Future Work

  • Training Wall-Clock Overhead: Because specialized training kernels are not yet available, PyTorch's FlexAttention incurs compilation overhead; CAT currently takes $\approx 2.35\times$ longer wall-clock time per training step than FlashAttention-optimized dense baselines.
  • Information Bottlenecks at Large Chunks: On high-density retrieval tasks (e.g., retrieving a 32-character UUID in S-NIAH-U), CAT-32 drops to near-zero accuracy without task-specific fine-tuning, demonstrating the physical capacity limit of compressing 32 tokens into a single latent vector.
  • Future Directions: Developing dedicated training kernels, exploring reinforcement learning to dynamically select chunk sizes per prompt/context, and instantiating CAT as a drop-in layer within hybrid architectures.

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