LLM Serving Optimization with Variable Prefill and Decode Lengths
This paper addresses the NP-hard problem of offline LLM serving scheduling under fixed KV-cache constraints with heterogeneous request lengths by proposing the Sorted-F algorithm, which achieves a constant-factor approximation guarantee and significantly reduces end-to-end latency compared to standard baselines.
Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer
Imagine you are the manager of a very busy, high-tech kitchen (the AI server). Your job is to cook meals (generate answers) for customers (users) as fast as possible.
In this kitchen, every meal has two parts:
- Prep Work (Prefill): Reading the recipe and chopping ingredients. This takes up counter space immediately.
- Cooking (Decode): Actually cooking the dish. This happens step-by-step, and as you cook, you keep the pot on the stove, which continues to take up space.
The big problem? Your kitchen has a fixed amount of counter space (KV-cache memory). You can’t just throw every order onto the counter at once; you have to manage who gets space and when.
The Old Way vs. The New Problem
Previously, researchers assumed all recipes were roughly the same size. If everyone had similar prep work and cooking times, the best strategy was simple: "Shortest Job First." You’d cook the quick meals first to clear the counter.
But in the real world, orders are messy.
- Order A: A tiny recipe (short prep) but takes forever to simmer (long cooking). It takes up little space but stays on the stove for a long time.
- Order B: A massive recipe (huge prep) but cooks in seconds (short cooking). It hogs the counter instantly but clears out quickly.
The paper shows that if you stick to the old "Shortest Job First" rule in this messy environment, you can make a huge mistake. You might pick Order A because it’s "short" to cook, but it blocks the counter for ages, preventing you from handling the quick, space-hogging Order B. The authors prove that this old method can perform terribly—mathematically speaking, its performance can get infinitely worse than the best possible schedule.
The Solution: The "F-Metric"
The authors propose a new scheduling algorithm called Sorted-F. Instead of just looking at how long the cooking takes, it uses a new score called the F-Metric.
Think of the F-Metric as a "Throughput Density" score. It asks: "How many meals can we finish per unit of time, given how much counter space we’re using?"
- It balances batch size (how many orders we can fit on the counter at once) against cooking time (how long they stay there).
- It prefers batches that are "efficient"—meaning they pack a lot of work into the available space without clogging the kitchen for too long.
Why It Works
The authors prove that this new method is mathematically robust. Even in the worst-case scenarios, Sorted-F will never be more than 48 times worse than the absolute perfect schedule (which is impossible to calculate in real-time because the problem is too complex). In practice, it performs much better than that, often coming very close to the theoretical best.
Real-World Test
They tested this on real data, mixing short chat messages with long document summaries.
- The Result: Sorted-F was significantly faster than the old methods.
- The Insight: The biggest gains happened when the workload was mixed (some short, some long) and the kitchen was nearly full. If everyone had similar orders, the old methods were okay. But when orders varied wildly, Sorted-F shone.
Practical Tweaks
Since calculating the perfect "F-Metric" batch for thousands of orders is hard, they also provided simpler, faster versions for different situations:
- Exact Method: For small batches, calculate the perfect score.
- Local Swap: For medium batches, make a good guess and then swap orders around to improve it.
- Quantile Greedy: For huge batches, use a quick statistical shortcut to pick the best candidates.
They also addressed the fact that we don’t always know exactly how long an answer will be. They integrated a "safety valve" system that starts with an optimistic guess but adjusts in real-time if an answer turns out to be longer than expected, kicking out the least efficient orders to make room.
The Bottom Line
This paper says: Don’t just look at how long an AI answer takes to write. Look at how much memory it uses while writing. By balancing the "prep space" and "cooking time" with the new F-Metric, AI servers can handle mixed workloads much more efficiently, reducing wait times for everyone.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.