Introduction
In the deployment of Large Language Models (LLMs), request variability presents a significant challenge for system efficiency. Unlike traditional web services, LLM inference is autoregressive; the time required to fulfill a request is directly proportional to the number of tokens generated. A user requesting a brief summary and another requesting a long-form essay impose vastly different computational loads. This variability, if unmanaged, leads to the "head-of-line blocking" problem in First-Come-First-Serve (FCFS) systems, where short requests are delayed by a few "heavy" tasks. This paper introduces a mathematical framework based on queueing theory to optimize LLM inference latency through strategic clipping and elastic batching.
Background: LLM Architecture and Inference
Modern LLMs like LLaMA-2 utilize a transformer-based architecture that relies on Key-Value (KV) caching to avoid redundant computations during the autoregressive decoding phase. As shown in Figure 2, the inference process is divided into a "prefill" stage (processing the input prompt) and a "decode" stage (generating output tokens one by one).
The decode stage is the primary source of variable latency, as the total service time depends on the stochastic length of the generated sequence. Traditional batching methods often pad shorter sequences to match the longest one in a batch, leading to significant computational waste and increased latency for all requests within that batch.
Methodology
The authors bridge systems engineering and probability theory by modeling LLM inference as an M/G/1 queueing system. This model assumes Poisson arrivals (M) and a general service time distribution (G) determined by the output token length. Key components of the methodology include:
- Max-Token Clipping Optimization: An optimization problem is formulated to balance user utility (the value of a complete response) against the cost of waiting. By identifying an optimal cutoff point for the longest responses, the system can significantly reduce average wait times.
- Bulk Queue and Elastic Batching: To analyze batching, the authors use a bulk queue model. They specifically advocate for "elastic batching" (iteration-level scheduling), where finished requests are released immediately, effectively shrinking the batch size dynamically and minimizing the lower bound of queueing delay.
Empirical Validation and Results
The mathematical models were validated using real-world datasets like Instruction-in-Wild and models including LLaMA-2-7b-chat and ChatGLM3-6b. A critical empirical finding is the linear relationship between the number of output tokens and inference latency, as illustrated in Figure 6(a).
Key Findings:
- Latency Reduction: For LLaMA-2-7b-chat, implementing an optimal max token limit of 1600 reduced the mean queueing delay by 58.93% (from 56s to 23s).
- The Clipping Paradox: Enforcing limits on only the top 1-5% of the longest requests—the "heavy tail"—drastically stabilizes the queue with minimal impact on overall response quality.
- Batching Efficiency: Figure 6(b) demonstrates how throughput increases with batch size, but so does the latency for the first output token. Elastic batching was shown to consistently outperform traditional dynamic batching by eliminating intra-batch waiting.
Discussion and Future Work
While this framework provides a robust tool for capacity planning, it primarily focuses on the decode stage. The authors note that the "prefill" stage also contributes to latency, though its relationship with input length is less linear due to parallel processing. Future research will explore extending these queueing models to multi-node, distributed inference environments where load balancing across clusters adds another layer of complexity. Furthermore, the hardware-specific constants used in these models would require recalibration for different GPU architectures or memory bandwidths.
Summary updated