Anchor-based Large Language Models

Jianhui Pang, Fanghua Ye, Derek F. Wong, Xin He, Wanshun Chen, Longyue Wang

Introduction

Modern Large Language Models (LLMs) are predominantly decoder-only Transformers. To maintain efficiency during text generation, they utilize a Keys/Values (KV) cache, which stores mathematical representations of previous tokens to prevent redundant computation. However, as input sequences lengthen—particularly in long-context retrieval or multi-shot prompting—the KV cache grows linearly, creating a "memory wall" that limits sequence length and slows inference. While techniques like FlashAttention optimize computation, they do not address the fundamental growth of the stored data.

Anchor-based Self-Attention Networks (AnSAN)

The proposed Anchor-based Large Language Models (AnLLMs) introduce Anchor-based Self-Attention Networks (AnSAN) to mitigate this memory bottleneck. The core innovation lies in forcing the model to compress information into specific "anchor tokens."

Anchor-based Attention Masks and Keys/Values Caching mechanism

Masking and Inference Strategy

AnSAN employs a custom attention mask where non-anchor tokens can only attend to previous anchor tokens and tokens within their local segment. Conversely, an anchor token (typically the last token in a segment) aggregates information from all preceding tokens in its segment. During inference, once a segment is processed, the KV caches for all non-anchor tokens are deleted, retaining only the anchor's representation for future steps.

Two primary strategies for anchor selection were evaluated:

  • AnLLM-EP (End-Point): Uses natural punctuation (e.g., periods, commas) as anchors.
  • AnLLM-AC (Anchor-token): Appends a dedicated <AC> token at the end of sentences to serve as an information compressor.

To implement this, the authors continually pre-trained a Llama2-7B model on 1 billion tokens from the RedPajama dataset to adapt it to the AnSAN masking strategy.

Experimental Results

The effectiveness of AnLLMs was tested across a wide array of standard NLP benchmarks, including OpenBookQA (OBQA), PIQA, and BoolQ.

Inference acceleration and KV cache reduction across benchmarks

Efficiency and Performance

The AnLLM-AC model demonstrated a 99% reduction in KV cache size for five-shot tasks. As shown in the performance metrics, this massive compression translated into significant inference speedups, reaching up to 3.5x on tasks with long input sequences like BoolQ. Remarkably, this efficiency comes with a minimal accuracy trade-off; across eight standard NLP benchmarks, the average accuracy dropped by only approximately 1.5% compared to the full-cache Llama2-7B baseline.

Conclusion and Future Work

AnLLMs represent a shift in how information flow is architected within Transformers. By creating an intentional information bottleneck, the model is compelled to pack semantic essence into anchors. This approach is orthogonal to hardware-level optimizations like FlashAttention or PagedAttention, making it a versatile tool for scaling LLM context. Future research will explore more sophisticated anchor selection methods and aim to further close the small accuracy gap observed in complex tasks like code generation or creative writing.

Summary updated

BibTeX
@inproceedings{pang2024anchor,
  author = {Jianhui Pang and Fanghua Ye and Derek F. Wong and Xin He and Wanshun Chen and Longyue Wang},
  title = {{Anchor-based Large Language Models}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.findings-acl.295},
}
Figure