Abstract
Finetuning large language models (LLMs) is essential for task adaptation, yet today's serving stacks isolate inference and finetuning on separate GPU clusters—wasting resources and under-utilizing hardware. We introduce FlexLLM, the first system to co-serve LLM inference and PEFT-based finetuning on shared GPUs by fusing computation at the token level. FlexLLM's static compilation optimizations—dependent parallelization and graph pruning—significantly shrink activation memory, leading to end-to-end GPU memory savings by up to 80%. At runtime, a novel token-level finetuning mechanism paired with a hybrid token scheduler dynamically interleaves inference and training tokens within each co-serving iteration, meeting strict latency SLOs while maximizing utilization. In end-to-end benchmarks on LLaMA-3.1-8B, Qwen-2.5-14B, and Qwen-2.5-32B, FlexLLM maintains inference SLO compliance at up to 20 req/s, and improves finetuning throughput by $1.9-4.8\times$ under heavy inference workloads and $2.5-6.8\times$ under light loads, preserving over 76% of peak finetuning progress even at peak demand.
The Challenge of Resource Isolation
Today’s Large Language Model (LLM) infrastructure typically isolates inference (serving user requests) and finetuning (adapting models to new tasks) on separate GPU clusters. This separation leads to significant inefficiencies. Inference workloads are notoriously bursty and unpredictable. To meet strict Service Level Objectives (SLOs), providers must overprovision hardware for peak demand, leaving GPUs underutilized—often as low as 10-52%—during normal operation.
Furthermore, finetuning is traditionally memory-intensive due to "activation bloat," where intermediate data must be stored to calculate gradients. This makes it difficult to run both tasks on the same hardware without running out of memory or severely impacting the latency of user-facing inference requests.
The FlexLLM Architecture
FlexLLM addresses these challenges by treating inference and training tokens as part of a single computational stream. The system architecture consists of three primary stages: a PEFT-as-a-Service (PaaS) interface, static compilation optimizations, and a distributed co-serving runtime.
Static Compilation Optimizations
To overcome memory constraints, FlexLLM employs two key static optimizations:
- Dependent Parallelization: This automatically aligns the parallelization strategy of small Parameter-Efficient Finetuning (PEFT) layers (like LoRA adapters) with the large frozen backbone model. This avoids redundant data movement and minimizes memory overhead.
- Graph Pruning: Since the backbone model remains frozen during PEFT, FlexLLM identifies and prunes activations that are not required for gradient calculations. This optimization reduces activation memory by up to 8×, enabling both tasks to fit within the same GPU memory footprint.
Token-Level Co-Serving
The core innovation of FlexLLM is its ability to fuse inference and finetuning at the token level. Unlike traditional methods that rely on resource isolation or temporal sharing, FlexLLM's hybrid token scheduler dynamically interleaves inference and training tokens within the same GPU kernels.
As shown in the figure above, traditional approaches like resource isolation (a) or temporal sharing (b) often lead to missed SLOs or idle resources. FlexLLM (e) prioritizes inference tokens to ensure latency guarantees are met and then "fills the gaps" in each iteration with finetuning tokens. This opportunistic approach treats finetuning as a background task that reclaims idle GPU capacity during the "valleys" of bursty inference traffic.
Performance and Efficiency
FlexLLM was evaluated against state-of-the-art separate systems (vLLM for inference and LlamaFactory for finetuning) using realistic workloads derived from ShareGPT and Azure ChatGPT traces.
- Throughput Gains: Under heavy inference loads, FlexLLM improved finetuning throughput by $1.9\times–4.8\times$. Under light loads, these gains increased to $2.5\times–6.8\times$.
- SLO Compliance: Even at high request rates of 20 req/s, FlexLLM maintained near-perfect SLO attainment for inference. Remarkably, it preserved over 76% of peak finetuning progress even during periods of peak demand.
- Memory Savings: The combination of graph pruning and dependent parallelization resulted in overall GPU memory savings of up to 80%.
Conclusion
FlexLLM demonstrates that inference and finetuning do not need to be isolated. By fusing these tasks at the token level and applying aggressive memory optimizations, FlexLLM allows providers to maximize hardware utilization and significantly increase finetuning throughput without compromising the strict latency requirements of user-facing inference services. FlexLLM is publicly available at https://flexllm.github.io.
Summary updated