Abstract
The increasing adoption of large language models (LLMs) necessitates inference serving systems that can deliver both high throughput and low latency. Deploying LLMs with hundreds of billions of parameters on memory-constrained GPUs exposes significant limitations in static batching methods. Current inference serving systems often treat batch sizes as fixed hyper-parameters, hindering real-time adaptation to varying system conditions. In this paper, we propose a dynamic batching method that continuously monitors memory utilization and adheres to service-level agreements (SLAs) to enable real-time batch size configuration adjustment. The method comprises two core components: a memory-aware batch scheduler that dynamically allocates GPU resources and a latency feedback mechanism that optimizes decoding processes under SLA constraints. The numerical experiments demonstrate throughput gains of 8% to 28% and capacity improvements of 22% compared to traditional static batching methods, while maintaining full compatibility with existing inference infrastructure.
Introduction
Deploying Large Language Models (LLMs) at scale is a balancing act between throughput (tokens processed per second) and latency (response speed). Current serving systems, including advanced frameworks like vLLM, typically treat the maximum batch size as a static hyper-parameter. This approach leads to two major inefficiencies:
- Underutilization: During low-demand periods, GPUs remain idle because the batch size is too small to saturate the hardware.
- Memory Overflows (OOM): During traffic surges or when processing long sequences, a fixed large batch size can exhaust GPU memory (specifically the KV cache), leading to system crashes or performance-degrading memory swapping.
This research argues that because request patterns and sequence lengths are inherently unpredictable, batch size must be adjusted dynamically in response to real-time system telemetry.
Methodology
The proposed dynamic batching framework frames batching as a real-time control problem, introducing two primary algorithms:
- Memory-aware Batch Scheduler: Utilizing the Central Limit Theorem, the system models token lengths as random variables. This allows for the calculation of a "safety buffer" ($L_0$) that prevents memory exhaustion while maximizing concurrent requests. It effectively transforms batch size calculation into a linear function of current average input and output lengths.
- SLA-constrained Feedback Mechanism: For applications with strict latency requirements, a binary search technique is employed to find the optimal batch size. By monitoring recent average decode latency, the system adjusts the batch size to remain within the Service Level Agreement (SLA) "sweet spot."
These methods are designed to be compatible with existing inference engines like vLLM and optimizations such as PagedAttention.
Key Insights: The Dynamics of Batching
A critical insight of this work is the shift from viewing batch size as a configuration setting to a dynamic decision variable. As shown in the figure below, while larger batches increase throughput, the marginal gain decreases as batches grow, whereas latency (decoding time) increases linearly.
By treating memory limits as "soft constraints" with probabilistic guarantees, the system can be more aggressive with batching without risking Out-of-Memory (OOM) errors. This allows the system to find the mathematically optimal point that changes continuously based on the workload.
Experimental Results
The framework was evaluated using LLaMA and PanGu architectures across diverse workloads. Key performance metrics include:
- Throughput Boost: Dynamic batching increased throughput by 8% to 28% across different LLM configurations compared to static baselines.
- Capacity Improvement: In scenarios with a 50ms latency target (SLA), the system's capacity—the maximum requests per second it could handle while meeting the target—improved by 22% (from 5.4 to 6.6 req/s).
- GPU Efficiency: Average GPU utilization rose from under 40% to nearly 50%.
Conclusion and Future Work
Dynamic batching provides a robust solution for balancing computational efficiency and quality-of-service requirements. While the current implementation uses heuristic approaches for computational efficiency, future work may involve more rigorous mathematical formulations. Additionally, extending this framework to Mixture-of-Experts (MoE) architectures and integrating it into Reinforcement Learning from Human Feedback (RLHF) sampling processes represent promising directions for further optimization.
Summary updated