Skip to main content
QUICK REVIEW

[Paper Review] MInference 1.0: Accelerating Pre-filling for Long-Context LLMs via Dynamic Sparse Attention

Huiqiang Jiang, Yucheng Li|arXiv (Cornell University)|Jul 2, 2024
Advancements in Photolithography TechniquesEngineering3 citations
TL;DR

MInference 1.0 accelerates pre-filling inference in long-context LLMs by exploiting dynamic sparse attention patterns—A-shape, Vertical-Slash, and Block-Sparse—identified through analysis of attention matrices. It achieves up to 10× speedup on a single A100 GPU for 1M-token prompts without model fine-tuning, maintaining high accuracy across benchmarks like Needle In A Haystack and InfiniteBench.

ABSTRACT

The computational challenges of Large Language Model (LLM) inference remain a significant barrier to their widespread deployment, especially as prompt lengths continue to increase. Due to the quadratic complexity of the attention computation, it takes 30 minutes for an 8B LLM to process a prompt of 1M tokens (i.e., the pre-filling stage) on a single A100 GPU. Existing methods for speeding up prefilling often fail to maintain acceptable accuracy or efficiency when applied to long-context LLMs. To address this gap, we introduce MInference (Milliontokens Inference), a sparse calculation method designed to accelerate pre-filling of long-sequence processing. Specifically, we identify three unique patterns in long-context attention matrices-the A-shape, Vertical-Slash, and Block-Sparsethat can be leveraged for efficient sparse computation on GPUs. We determine the optimal pattern for each attention head offline and dynamically build sparse indices based on the assigned pattern during inference. With the pattern and sparse indices, we perform efficient sparse attention calculations via our optimized GPU kernels to significantly reduce the latency in the pre-filling stage of long-context LLMs. Our proposed technique can be directly applied to existing LLMs without any modifications to the pre-training setup or additional fine-tuning. By evaluating on a wide range of downstream tasks, including InfiniteBench, RULER, PG-19, and Needle In A Haystack, and models including LLaMA-3-1M, GLM4-1M, Yi-200K, Phi-3-128K, and Qwen2-128K, we demonstrate that MInference effectively reduces inference latency by up to 10x for pre-filling on an A100, while maintaining accuracy. Our code is available at https://aka.ms/MInference.

Motivation & Objective

  • Address the high computational cost of pre-filling in long-context LLMs, which can take up to 30 minutes for 1M-token prompts on a single A100.
  • Overcome the limitations of existing sparse attention methods that require fine-tuning or fail to adapt to dynamic attention patterns in long-context settings.
  • Enable efficient, low-overhead inference acceleration by identifying and leveraging stable, data-driven sparse attention patterns in long-context LLMs.
  • Design a system that dynamically assigns optimal sparse patterns per attention head at inference time, minimizing estimation overhead.
  • Achieve significant latency reduction while preserving model accuracy across diverse long-context benchmarks and model architectures.

Proposed method

  • Identify three recurring sparse attention patterns—A-shape, Vertical-Slash, and Block-Sparse—through empirical analysis of attention matrices in long-context LLMs.
  • Perform kernel-aware search to assign the optimal sparse pattern to each attention head based on offline analysis of attention dynamics.
  • Dynamically construct sparse indices at inference time using lightweight, input-dependent approximations: for Vertical-Slash, use last-q query and key vectors; for Block-Sparse, apply mean pooling over 64-token blocks.
  • Implement three optimized GPU kernels—based on PIT, Triton, and FlashAttention—tailored to the three sparse patterns for high-efficiency sparse matrix multiplication.
  • Integrate the method into existing LLMs without modifying pre-training or requiring fine-tuning, enabling plug-and-play deployment.
  • Use dynamic sparse masks that adapt per input while maintaining low computational cost for pattern estimation.

Experimental results

Research questions

  • RQ1Can stable, generalizable sparse attention patterns be identified in long-context LLMs that enable efficient pre-filling without fine-tuning?
  • RQ2How can dynamic sparse attention be estimated online with minimal computational overhead to maintain low latency?
  • RQ3To what extent can pattern-specific sparse computation reduce FLOPs and inference latency in long-context LLMs while preserving accuracy?
  • RQ4How does the performance of dynamic sparse attention compare to fixed sparse or dense attention across diverse long-context benchmarks?
  • RQ5Can the method be universally applied across different LLM architectures and context lengths without architectural modifications?

Key findings

  • MInference reduces pre-filling latency by up to 10× for 1M-token prompts on a single A100 GPU, achieving 30-minute pre-filling time reduced to under 3 minutes.
  • The method maintains high accuracy across benchmarks, matching or surpassing baselines on Needle In A Haystack, InfiniteBench, RULER, and PG-19.
  • Attention matrices in long-context LLMs exhibit up to 96.8% sparsity at 128K context length, validating the feasibility of sparse computation.
  • The A-shape, Vertical-Slash, and Block-Sparse patterns are consistently observed across multiple models including LLaMA-3-1M, GLM-4-1M, and Qwen2-128K.
  • The dynamic sparse mask construction introduces negligible overhead, enabling real-time inference with minimal impact on latency.
  • The technique is model-agnostic and can be applied to existing LLMs without fine-tuning or architectural changes, as demonstrated on LLaMA-3-8B-1M, Phi-3-Mini-128K, and Qwen-2-7B-128K.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.