Zebra: Extending Context Window with Layerwise Grouped Local-Global Attention

Kaiqiang Song, Xiaoyang Wang, Sangwoo Cho, Xiaoman Pan, Dong YuarXiv 2023 · DOI

Introduction

Large Language Models (LLMs) have revolutionized natural language processing, yet they remain constrained by the "quadratic wall" of the standard Transformer architecture. The computational complexity and memory requirements of the self-attention mechanism scale with the square of the sequence length ($O(N^2)$), making the processing of extensive documents—such as entire books or complex codebases—prohibitively expensive. Furthermore, long-context models often suffer from the "lost in the middle" phenomenon, where information in the center of a prompt is ignored, and a data imbalance where models trained on short sequences fail to generalize to long-range dependencies.

The Zebra Architecture: Layerwise Grouped Local-Global Attention

To address these challenges, we introduce Zebra, a novel architecture that employs Layerwise Grouped Local-Global Attention. Instead of applying full global attention at every layer, Zebra organizes layers into groups of size $L$.

In this "zebra stripe" pattern, only the first layer of each group performs Global Attention, attending to all previous tokens in the sequence. The subsequent $L-1$ layers utilize Local Attention, restricting their focus to a fixed window of recent tokens (e.g., 512 or 1024). This hybrid approach ensures that global information is captured and propagated through the network via the "anchor" global layers, while the local layers handle fine-grained, nearby dependencies with significantly reduced computational overhead.

Comparison of attention mechanisms including Zebra's Group Attention.

Beyond the attention pattern, Zebra incorporates Rotary Positional Embedding (RoPE) with an adjusted base frequency (theta = 131,072) to improve extrapolation to sequence lengths beyond those seen during training. During inference, the architecture allows for a massive reduction in GPU memory usage; a full Key-Value (K-V) cache is only required for global layers, while local layers only need to store a small, fixed-size window of K-V pairs.

Experimental Setup

The Zebra architecture was evaluated through a multi-stage process. Initial design choices were validated on a 10% subset of The Pile. For full-scale implementation, a base Llama-2-7B model was adapted using Long Context Adaptation Training (LCAT) on a curated 100B-token dataset comprising Books3, Wikipedia, GitHub, and Stack Exchange.

Evaluation spanned three domains:

  1. Long-Range Language Modeling: Tested on the Gutenberg (PG-19) dataset.
  2. General Reasoning: Standard benchmarks including MMLU and PIQA to ensure no degradation in short-context performance.
  3. Complex Long-Context Tasks: The ZeroScrolls benchmark, focusing on summarization and question answering.

Performance and Efficiency

Empirical results demonstrate that Zebra achieves a 2x training speedup over full-attention models when processing long sequences. Crucially, this efficiency does not come at the cost of accuracy. On the Gutenberg dataset, Zebra-LCAT (32k context) achieved a perplexity of 6.79, nearly identical to the full-attention Llama-2-LCAT (6.78).

Validation perplexity vs. computational cost across different context lengths.

As shown in the efficiency plots, Zebra (group attention) consistently reaches lower perplexity levels at lower TFlops compared to global attention, particularly as the sequence length increases from 1k to 16k. This confirms that the "zebra" pattern effectively maintains model quality while slashing resource requirements.

Furthermore, Zebra maintained competitive scores on short-context benchmarks like MMLU (41.8), proving the robustness of the architecture. In instruction-tuning scenarios (Zebra-LIT), the model outperformed Llama-2-7b-chat on several long-context QA and summarization tasks within the ZeroScrolls benchmark.

Conclusion and Future Work

Zebra presents a compelling path forward for scaling LLM context windows. By alternating global and local attention, it bypasses the quadratic complexity of standard Transformers while maintaining high performance. The ability to use a local K-V cache during inference is particularly significant for deploying long-context models on hardware with limited VRAM.

Future research will focus on scaling the Zebra architecture to larger parameter counts (13B, 70B+) and refining long-context alignment techniques. Additionally, developing more nuanced evaluation metrics beyond ROUGE and F1 will be essential to fully capture the qualitative improvements in long-form generation.

Summary updated

Abstract

This paper introduces a novel approach to enhance the capabilities of Large Language Models (LLMs) in processing and understanding extensive text sequences, a critical aspect in applications requiring deep comprehension and synthesis of large volumes of information. Recognizing the inherent challenges in extending the context window for LLMs, primarily built on Transformer architecture, we propose a new model architecture, referred to as Zebra. This architecture efficiently manages the quadratic time and memory complexity issues associated with full attention in the Transformer by employing grouped local-global attention layers. Our model, akin to a zebra's alternating stripes, balances local and global attention layers, significantly reducing computational requirements and memory consumption. Comprehensive experiments, including pretraining from scratch, continuation of long context adaptation training, and long instruction tuning, are conducted to evaluate the Zebra's performance. The results show that Zebra achieves comparable or superior performance on both short and long sequence benchmarks, while also enhancing training and inference efficiency.
BibTeX
@misc{song2023zebra,
  author = {Kaiqiang Song and Xiaoyang Wang and Sangwoo Cho and Xiaoman Pan and Dong Yu},
  title = {{Zebra: Extending Context Window with Layerwise Grouped Local-Global Attention}},
  year = {2023},
  eprint = {2312.08618},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2312.08618},
}
Figure