APB: Accelerating Distributed Long-Context Inference by Passing Compressed Context Blocks across GPUs

Yuxiang Huang, Mingye Li, Xu Han, Chaojun Xiao, Weilin Zhao, Ao Sun, Hao Zhou, Jie Zhou, Zhiyuan Liu, Maosong Sun

Abstract

While long-context inference is crucial for advancing large language model (LLM) applications, its prefill speed remains a significant bottleneck. Current approaches, including sequence parallelism strategies and compute reduction through approximate attention mechanisms, still fall short of delivering optimal inference efficiency. This hinders scaling the inputs to longer sequences and processing long-context queries in a timely manner. To address this, we introduce APB, an efficient long-context inference framework that leverages multi-host approximate attention to enhance prefill speed by reducing compute and enhancing parallelism simultaneously. APB introduces a communication mechanism for essential key-value pairs within a sequence parallelism framework, enabling a faster inference speed while maintaining task performance. We implement APB by incorporating a tailored FlashAttn kernel alongside optimized distribution strategies, supporting diverse models and parallelism configurations. APB achieves speedups of up to 9.2×, 4.2×, and 1.6× compared with FlashAttn, RingAttn, and StarAttn, respectively, without any observable task performance degradation.

Introduction

As Large Language Models (LLMs) move toward processing millions of tokens, the "prefill" stage—where the model processes the initial prompt—becomes a massive bottleneck. The quadratic computational cost of standard attention means that a single GPU quickly runs out of memory (OOM) or takes far too long to respond.

Existing solutions generally fall into two camps:

  1. Sequence Parallelism (SP): Distributing the sequence across multiple GPUs (e.g., RingAttention, DeepSpeed-Ulysses). This solves the memory problem but doesn't reduce the total amount of computation.
  2. Approximate Attention: Reducing computation by pruning "unimportant" tokens (e.g., H2O, SnapKV). However, these usually require a "global view" of the entire sequence to decide what to prune, which is difficult to do when the sequence is split across different GPUs.

The authors introduce APB (Approximate Passing Blocks) to bridge this gap, creating a system that is both distributed and computationally efficient.

Methodology: The APB Framework

APB introduces a "compress-and-share" workflow integrated into a sequence parallelism framework. The core idea is to allow GPUs to share only the most critical context fragments, reducing both communication and computation overhead.

The APB framework architecture, illustrating context splitting, block compression via a learned compressor (C), and the AllGather communication of passing blocks (P) across hosts.

The workflow consists of several key stages:

  • Context Splitting & Anchor Blocks: The input document is split across $H$ GPUs. Each GPU also receives a small "Anchor Block" (the very beginning of the document) to ensure the model maintains a consistent global starting point.
  • Block Compression: Instead of calculating full attention scores, each GPU uses a lightweight "compressor" (a small MLP trained on long-context data) to assign importance scores to its local Key-Value (KV) pairs. It then selects only the top-scoring "essential" units.
  • Passing Blocks: These compressed summaries are shared across all GPUs via an AllGather communication. This means every GPU sees its own full local context, the global anchor, and a "highlight reel" (Passing Blocks) of what every other GPU is holding.
  • Custom FlashAttention Kernel: To make this work efficiently, the authors implemented a modified FlashAttention kernel that handles this specific layout (Anchor + Passing + Local) using a specialized attention mask.

Experimental Evaluation

The authors evaluated APB using two major long-context benchmarks:

  • $∞$Bench: A suite of 10 tasks (synthetic and real-world) with an average context length exceeding 100K tokens.
  • RULER: A benchmark with 13 synthetic tasks designed to test retrieval and reasoning at controllable context lengths (up to 512K in this paper).

To train the compressor MLPs, they utilized subsets of LongAlign, LongAlpaca, and AntiHaystack.

Key Results and Discussion

APB demonstrates a superior trade-off between inference speed and task performance across various model architectures, including Llama-3.1-8B, Qwen-2.5-14B, and Yi-34B.

Speed vs. Performance comparison across multiple models and benchmarks. APB (red star) consistently achieves the highest speed while maintaining near-baseline performance.

Performance Highlights

  • Speedups: APB achieved speedups of up to 9.2× compared to FlashAttention, 4.2× over RingAttention, and 1.6× over StarAttention.
  • Efficiency: At a 512K context length, APB's inference speed remains relatively stable, while standard methods either crash (OOM) or slow down significantly.
  • Task Performance: On the RULER benchmark (Llama-3.1-8B), APB maintained an average score of 81.63, very close to the Full Attention baseline of 82.20, and significantly higher than other approximate methods like StarAttention (76.84).
  • Noise Filtering: Interestingly, in some tasks, APB outperformed full attention. The authors suggest the compressor acts as a noise filter, removing "distractor" tokens that might confuse the model during retrieval.

Conclusion

APB effectively addresses the prefill bottleneck in long-context LLM inference by combining sequence parallelism with learned context compression. By sharing only essential "Passing Blocks," it achieves significant speedups without sacrificing accuracy. While currently focused on the prefill stage, APB sets a new standard for efficient distributed inference in the era of million-token contexts.

Summary updated

BibTeX
@inproceedings{huang2025apb,
  author = {Yuxiang Huang and Mingye Li and Xu Han and Chaojun Xiao and Weilin Zhao and Ao Sun and Hao Zhou and Jie Zhou and Zhiyuan Liu and Maosong Sun},
  title = {{APB: Accelerating Distributed Long-Context Inference by Passing Compressed Context Blocks across GPUs}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2025},
  url = {https://openreview.net/forum?id=x7LqvxMUk6},
}
Figure