TL;DR
Serving increasingly long-context Large Language Models (LLMs) is a major challenge due to dynamic resource demands across different requests and inference phases. LoongServe introduces Elastic Sequence Parallelism (ESP), a novel paradigm that dynamically adjusts parallelism to match these demands, significantly boosting throughput and efficiency without compromising accuracy.
What Problem Does This Paper Address?
Large Language Models (LLMs) are rapidly expanding their context windows, enabling more sophisticated applications. However, serving these models efficiently, especially with long contexts, is a significant hurdle. The core problem lies in the dynamic nature of LLM inference:
- Variable Resource Demands: Different requests have varying input lengths, leading to vastly different computational and memory needs.
- Phase-Specific Demands: LLM inference is typically split into a compute-intensive "prefill" phase (processing the initial prompt) and a less intensive "decoding" phase (generating subsequent tokens). The resource requirements differ significantly between these two phases, even for the same request.
- Static Parallelism Limitations: Existing serving systems rely on static parallelism strategies (like tensor parallelism or sequence parallelism) that are configured before service starts. This rigidity makes them inefficient when faced with the dynamic and phase-dependent resource demands of long-context LLMs, leading to underutilized resources, GPU memory fragmentation, and communication overhead.
Methods
LoongServe tackles these challenges with its core innovation: Elastic Sequence Parallelism (ESP). Unlike static sequence parallelism, ESP dynamically adjusts the Degree of Parallelism (DoP) for requests in real-time, adapting to varying needs across requests and inference phases.
Key mechanisms enabling ESP include:
- Proactive Scale-Down (Prefill Phase): During the prefill phase, where compute demands are high, ESP can proactively scale down parallelism. This is achieved by intelligently retaining key-value (KV) cache tensors within the unified cache pool during the prefill computation itself, eliminating the need for costly migration after the phase.
- Multi-Master Distributed Decoding: For the decoding phase, LoongServe employs a multi-master approach. This allows multiple instances to participate in decoding a single batch, breaking memory fragmentation by distributing KV cache storage and enabling parallel computation of local layers.
- Unified Distributed KV Cache Pool: LoongServe manages KV caches across all instances in a unified pool. This breaks down the locality constraints of traditional methods, allowing any instance to store any token's KV cache, thus mitigating GPU memory fragmentation.
- Scalable Four-Step Scheduling Algorithm: To manage the complexity of dynamic scheduling, LoongServe uses a four-step algorithm that decouples dispatching, instance allocation, batching, and scaling plan generation. This allows for efficient, polynomial-time decision-making within tight latency constraints.
Datasets
The paper evaluates LoongServe using the following real-world datasets:
- ShareGPT: Real-world conversations with ChatGPT, limited to shorter sequences (4-2.3K tokens).
- L-Eval: Human-labeled query-response pairs for evaluating long-context capabilities (2.7K-210.5K tokens).
- LV-Eval: A dataset containing very long requests (15.1K-497.3K tokens).
- Mixed: A combination of the above datasets to simulate a more diverse workload.
Key Insights and Ideas
- Dynamic parallelism is crucial for long-context LLMs: Static parallelism strategies are fundamentally ill-suited for the highly dynamic nature of LLM inference, especially with increasing context lengths.
- ESP decouples resource needs from static configurations: By dynamically adjusting parallelism, ESP allows systems to efficiently utilize resources for both compute-heavy prefill and memory-intensive decoding phases.
- Zero-overhead scaling is achievable: Proactive migration during prefill and intelligent KV cache management in decoding allow for elastic scaling without incurring significant communication overhead.
- Unified KV cache pool breaks fragmentation: Eliminating locality constraints for KV caches is key to maximizing GPU memory utilization and preventing fragmentation.
- A sophisticated scheduler is needed: The complexity of dynamic scheduling requires a multi-step, decoupled approach to make real-time decisions effectively.
Key Results
LoongServe demonstrates significant performance improvements across various metrics:
- Throughput: Up to 3.85x improvement compared to chunked prefill and 5.81x compared to prefill-decoding disaggregation.
- Latency: Achieves low output latency by protecting the decoding phase from prefill interference.
- P90 Goodput: Improves P90 goodput by 2.33x, 1.98x, and 1.53x under different sequence length distributions compared to static parallelism strategies.
- Elastic Scale-up: Demonstrates a 2.87x higher P90 goodput with elastic scale-up enabled.
- Scaling Overhead: Elastic scaling down incurs negligible overhead (<2%), while elastic scaling up shows up to a 2x improvement in per-iteration latency for large batch sizes.
Limitations and Future Work
- Analytical Model Accuracy: While the analytical model for predicting iteration time shows high accuracy (less than 10% deviation), it relies on trained coefficients and may need re-training for significantly different hardware or model architectures.
- Multi-Node Performance: While LoongServe shows good multi-node scaling, further exploration of inter-node communication optimization could be beneficial.
- Future Work: The paper suggests exploring more advanced scheduling strategies and further optimizing the elastic scaling mechanisms for even greater efficiency. The compatibility with various attention mechanisms (MHA, MQA, GQA) and model architectures (MoE) is also highlighted as a strength for future adoption.
Summary updated