Abstract
Large Language Model (LLM) inference is primarily memory-bound due to the dynamic growth of the Key-Value (KV) cache. Conventional serving frameworks often reserve memory for the maximum possible sequence length to prevent crashes, resulting in substantial memory waste and low GPU utilization. We introduce $S^3$ (Speculative Sequence Scheduling), a system-algorithm co-design that predicts output sequence lengths a priori to optimize memory allocation. $S^3$ utilizes a lightweight predictor, a length-aware sequence scheduler, and a supervisor for real-time memory management. Our evaluation demonstrates that $S^3$ achieves up to 6.49$\times$ higher throughput than state-of-the-art frameworks and significantly improves cost efficiency by enabling larger batch sizes within strict latency constraints.
Introduction
Serving LLMs is computationally expensive due to the "memory-bound" nature of text generation. During inference, models utilize a KV cache to store information from previous tokens, avoiding redundant computations. However, the final length of an output sequence is unknown at the start of generation. To ensure stability, many systems allocate memory based on the maximum possible sequence length (e.g., 2048 tokens). This "worst-case" allocation leads to significant idle memory when actual outputs are short, forcing small batch sizes and resulting in GPU utilization as low as 0.4%. This phenomenon creates a "memory cliff" where systems operate far below their potential capacity to avoid out-of-memory (OOM) errors.
Methods
$S^3$ addresses these inefficiencies through three integrated components:
- Output Sequence Length Predictor: A lightweight DistilBERT model (66M parameters) analyzes input prompts to predict the output length bucket. This prediction occurs in approximately 3.7ms, a negligible overhead compared to the generation process.
- Length-Aware Sequence Scheduler: Using predicted lengths, the scheduler treats memory allocation as a bin-packing problem. It employs a decreasing first-fit algorithm to maximize the number of sequences packed into the GPU memory, significantly increasing batch sizes.
- Supervisor: To handle mispredictions, the supervisor monitors memory usage in real-time. If a sequence exceeds its predicted length, it is preempted, its memory allocation is doubled, and it is re-queued. The supervisor also collects these instances to retrain the predictor.
Results
The system was evaluated using datasets such as Alpaca, Google Natural-Question, and The Pile. $S^3$ demonstrated substantial improvements in throughput and resource efficiency.
- Throughput and Batch Size: $S^3$ achieved up to a 6.49$\times$ throughput increase over the ORCA baseline. For the LLAMA-33B model, the average batch size increased from 4 to over 42.
- Cost Efficiency: The efficiency gains allow 6 GPUs running $S^3$ to match the throughput of 10 GPUs using standard allocation methods.
- Latency SLOs: $S^3$ maintains the Pareto frontier of latency versus throughput, allowing for higher request volumes while meeting strict Service Level Objectives (SLOs), such as human reading speed.
Conclusion
$S^3$ demonstrates that a priori knowledge of sequence lengths, even if imperfect, can dramatically improve LLM serving efficiency. While the predictor shows some domain sensitivity—with accuracy varying between 98.6% on Alpaca and 65% on the diverse Pile dataset—the system's supervisor ensures robustness. Future work will focus on developing more domain-agnostic predictors and further optimizing the preemption recovery process to minimize latency spikes.
Summary updated