TL;DR
Serving large language models (LLMs) that can process very long sequences is a major bottleneck. LServe tackles this by introducing a unified sparse attention mechanism that intelligently skips computations during both the initial "prefilling" phase and the subsequent "decoding" phase, leading to significant speedups without sacrificing accuracy.
What Problem Does This Paper Address?
LLMs are becoming increasingly capable of handling long contexts, enabling applications like multi-turn conversations, document analysis, and complex reasoning. However, serving these models efficiently is a significant challenge. The core issue lies in the attention mechanism, which has a computational complexity that grows quadratically with sequence length during prefilling and requires a large amount of memory for the Key-Value (KV) cache during decoding. Existing solutions often focus on optimizing only one of these stages or use sparsity patterns that can degrade accuracy. This paper aims to provide a unified system that accelerates both prefilling and decoding for long-context LLMs by combining various sparsity techniques.
Methods
LServe introduces a unified block sparse attention framework that integrates multiple hardware-friendly sparsity patterns. The key ideas are:
- Block-wise Sparsity: Instead of processing all tokens, LServe skips entire blocks of computations in the attention mechanism. This is applied to both prefilling and decoding.
- Hybrid Static and Dynamic Sparsity:
- Static Sparsity (Streaming Heads): Half of the attention heads are converted into "streaming heads" that only attend to immediate neighbors and a few initial "sink" tokens. This is a fixed pattern applied offline.
- Dynamic Sparsity (Hierarchical KV Page Selection): For the remaining "dense" heads, LServe uses a dynamic approach. It employs a hierarchical KV page selection policy that prunes KV pages based on query-centric similarity. This ensures that only a constant number of KV pages are needed to maintain long-context capabilities, regardless of the actual context length.
- System-Algorithm Co-optimization: LServe unifies these sparsity patterns with KV cache quantization and optimizes them for GPU kernels. It also introduces a reusable page selector to reduce the overhead of dynamic page selection.
Datasets
The paper evaluates LServe on several benchmarks:
- LongBench: A benchmark for long-context understanding tasks.
- Needle-in-a-Haystack (NIAH): A test for evaluating retrieval capabilities in long contexts.
- RULER: A benchmark for challenging tasks like multi-hop tracing and aggregation.
- AIME2024 and MATH500: Datasets for complex reasoning tasks.
The paper does not introduce new datasets but uses existing ones to evaluate performance across diverse long-context scenarios.
Key Insights and Ideas
- Orthogonality of Sparsity: Static and dynamic sparsity patterns are compatible and can be combined for multiplicative speedups.
- Constant KV Cache Requirement: Surprisingly, only a constant number of KV pages are needed to preserve long-context reasoning capabilities, irrespective of the actual context length. This is a crucial insight for efficient KV cache management.
- Hierarchical Paging for Accuracy-Efficiency Tradeoff: The hierarchical paging system effectively balances the need for larger page sizes (for hardware efficiency) with maintaining accuracy, mitigating the issues seen with simpler page selection methods.
- Reusable Page Selection: The overhead of dynamic page selection can be a bottleneck. Reusing selection results for consecutive tokens significantly reduces this overhead.
Key Results
LServe demonstrates significant improvements over existing systems like vLLM and TensorRT-LLM:
- Prefilling Speedup: LServe accelerates LLM prefilling by an average of 2.4x over TensorRT-LLM (and up to 2.9x over vLLM).
- Decoding Speedup: LServe achieves an average decoding speedup of 1.3x-2.1x over vLLM (and up to 3.3x over TensorRT-LLM).
- Accuracy Preservation: LServe maintains long-context accuracy comparable to dense, floating-point models across various benchmarks, including complex reasoning tasks.
- Efficiency on Different GPUs: The system shows good performance on both NVIDIA A100 and L40S GPUs.
Limitations and Future Work
- Hardware Dependency: The system is optimized for NVIDIA GPUs, and its performance on other hardware might differ.
- Offline Profiling: While LServe's sparse patterns are determined offline, future work could explore more dynamic online adaptation of these patterns.
- Further Optimization: The paper mentions that while the attention kernel is optimized, further work could explore more aggressive quantization or other hardware-specific optimizations.
The authors suggest that their unified framework and techniques can be extended to further improve the efficiency of serving increasingly large and capable LLMs.
Summary updated