You Only Cache Once: Decoder-Decoder Architectures for Language Models

Yutao Sun, Li Dong, Yi Zhu, Shaohan Huang, Wenhui Wang, Shuming Ma, Quanlu Zhang, Jianyong Wang, Furu Wei

Introduction

In the current era of Large Language Models (LLMs), "context is king." However, standard decoder-only Transformers suffer from a massive bottleneck when scaling context lengths: the Key-Value (KV) cache. To avoid recomputing the entire history at every step, Transformers store the Key and Value vectors for every token at every layer.

This creates two major hurdles. First, memory explodes linearly with both sequence length and the number of layers. For a 65B model with a 512K context, the KV cache alone can exceed 80GB—more than the capacity of a high-end H100 GPU. Second, before generating the first new token, the model must "prefill" the cache by processing the entire input prompt, which is computationally expensive and slow for long sequences.

To address these issues, researchers introduce YOCO (You Only Cache Once), a novel "decoder-decoder" architecture that slashes the memory and computational costs of long-context LLMs while maintaining performance parity with standard Transformers.

The YOCO Architecture

YOCO departs from the standard stack of identical decoder layers. Instead, it uses a two-part design consisting of a self-decoder and a cross-decoder.

YOCO Architecture
  • The Self-Decoder (First Half): The first half of the layers process the input sequence using an efficient attention mechanism, such as Gated Retention (gRet) or sliding-window attention. These methods have $O(1)$ inference memory, meaning their local cache doesn't explode with sequence length. Crucially, the output of the final self-decoder layer serves as the single Global KV Cache for the rest of the model.
  • The Cross-Decoder (Second Half): The remaining layers do not generate their own KV caches. Instead, they use cross-attention to look back at the single Global KV Cache produced by the self-decoder.

By compressing the context into a single, high-quality global representation halfway through the model, YOCO demonstrates that we don't need unique KV representations at every single layer to perform complex reasoning.

Accelerating Inference with "Early Exit"

Beyond memory savings, YOCO introduces a system-level synergy designed for hardware efficiency: the "early exit" prefilling trick.

Prefilling and Generation Stages

Because the cross-decoder layers only rely on the output of the self-decoder, the model can skip the cross-decoder entirely during the prefilling stage for all tokens except the very last one. This effectively halves the layers needed for the initial prompt processing, drastically reducing prefilling latency. During the generation phase, the model utilizes both decoders normally.

Key Results and Performance

Evaluated across a rigorous suite of benchmarks—including language modeling, downstream tasks, and long-context retrieval—YOCO demonstrates remarkable efficiency without sacrificing capability:

  • Massive Memory Savings: By caching only once, YOCO changes the KV cache memory complexity from $O(LND)$ to $O((N+L)D)$. For a 65B model, this reduces KV cache memory by approximately 80x. For a 3B model at a 1M context length, total inference memory is reduced by 9x compared to a standard Transformer.
  • Lightning-Fast Prefilling: Thanks to the early exit mechanism, YOCO reduces prefilling latency at a 512K context length from 180 seconds to less than 6 seconds. At 1M tokens, it achieves a staggering 71.8x speedup.
  • Near-Perfect Retrieval: In the "Needle In A Haystack" test, YOCO-3B maintained near-100% accuracy up to 1 million tokens, outperforming many larger, specialized long-context models.
  • Competitive Performance: On standard benchmarks (like ARC and MMLU-style tasks), YOCO-3B performed on par with or better than well-known models like StableLM-3B and OpenLLaMA-v2-3B.

Limitations and Future Work

While YOCO presents a significant leap in efficient LLM design, the authors note a few areas for future exploration. The current paper defaults to a 1:1 split between self-decoder and cross-decoder layers, but a "scaling law" for this ratio likely exists and remains to be discovered. Additionally, while Gated Retention serves as a strong self-decoder backbone, the architecture is modular; future iterations could explore other linear-complexity or state-space models (SSMs). Finally, further research into "chunk parallelism" is suggested to ensure training remains efficient as context lengths scale toward the multi-million token range.

Summary updated

BibTeX
@inproceedings{sun2024you,
  author = {Yutao Sun and Li Dong and Yi Zhu and Shaohan Huang and Wenhui Wang and Shuming Ma and Quanlu Zhang and Jianyong Wang and Furu Wei},
  title = {{You Only Cache Once: Decoder-Decoder Architectures for Language Models}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=25Ioxw576r},
}
Figure