Robust KV Cache Management for LLM Serving under Output Token Length Uncertainty
提出了一种基于Wasserstein DRO的鲁棒KV cache管理框架,联合优化GPU并行配置、KV cache预留、请求路由和前缀缓存,在输出token长度不确定性下实现自适应内存分配和尾延迟控制。核心贡献包括临界分位数结构理论证明、BCD-DRO分解算法和滚动时域自适应策略。
Robust KV Cache Management for LLM Serving under Output Token Length Uncertainty: 基于分布鲁棒优化的KV Cache自适应管理
一、论文概述
| 字段 | 内容 |
|---|---|
| 标题 | Robust KV Cache Management for LLM Serving under Output Token Length Uncertainty |
| 作者 | Jingren Cheng (Amazon.com Services LLC), H. Vincent Poor (Princeton University) |
| 机构 | Amazon.com Services LLC, Princeton University |
| arXiv | arXiv:2607.11211 |
| 代码 | N/A (paper mentions simulation, no code link) |
| 日期 | 2025 |
| License | N/A |
二、核心思想
问题定义
大规模LLM推理服务系统中,GPU显存主要用于存储每个请求的KV cache,其大小正比于输入+输出token长度。然而输出token长度存在高度不确定性——不同任务类型(对话、代码生成、数据分析)的输出分布差异巨大。传统的KV cache预留方法(如固定分位数P90/P95/P99)面临一个根本性难题:任何单一的分位数只能在特定cost ratio下最优,当实际工作负载变化时,固定策略要么浪费GPU显存(over-reserve),要么导致频繁的preemption(under-reserve)。这个问题在实际部署中尤为突出,因为不同应用对preemption和waiting的相对成本不同,且常常是未知的或动态变化的。
具体而言,设第 类请求的类型为 ,实际输出长度为随机变量 。系统为每类请求预留 个token的KV cache空间,若 则发生preemption(代价 ),若 则产生wasted memory slot(代价 )。目标是最小化总期望cost:,其中 是包含preemption和waste的stochastic cost function。同时,系统还需联合决策GPU parallelism configuration 、routing probabilities 、prefix caching fraction ,以及SLO-based request admission,在满足吞吐量和尾延迟约束的前提下最大化整体throughput。
解决方案概述
本文提出一个统一框架,核心包含三个层次:(1)分布鲁棒优化(DRO) — 使用Wasserstein ambiguity set保护预知之外的分布偏移,替代传统sample-average approximation (SAA);(2)临界分位数结构 — 证明了最优预留量具有closed-form quantile structure,,自动根据cost ratio选择最佳分位数;(3)Block Coordinate Descent (BCD) — 将原始混合整数问题分解为GPU configuration、kv cache reservation、routing/prefix-caching等子问题,使production-scale实例可在数分钟内求解。
框架进一步结合排队论模型(M/G/1 Pollaczek-Khinchin公式)估计每组的queueing delay,引入rolling-horizon adaptation机制在deployment期间periodically re-optimize以适应workload演化。实验在三个真实trace(BurstGPT, Azure LLM 2024, ShareGPT)上验证了DRO在不同cost regime下的cross-regime稳定性。
三、技术架构
整体框架图
+------------------------------------------+
| Rolling Horizon Adaptation |
| (Periodically re-optimize with |
| recent observations to track drift) |
+------------------+-----------------------+
|
+---------------+---------------+
| BCD-DRO Optimizer |
| Block Coordinate Descent |
+---+-----------+-----------+---+
| | |
+----------------+ +--------+---+ +----+----------------+
| | | |
+-----v------+ +------v-----+ +----v------+
| GPU Config | | KV Cache | | Admission |
| z in Z | | Reservations| | & Routing |
| (TP, PP) | | r_i (DRO) | | (pi, delta)|
+------------+ +------------+ +-----------+
|
+----------------------+----------------------+
| Waiting Cost Model |
| M/G/1 Pollaczek-Khinchin (queueing delay) |
+----------------------+----------------------+
|
+----------------------+----------------------+
| Wasserstein Ambiguity Set |
| P_hat_N (empirical) + epsilon ball |
| Protects against distribution shift |
+----------------------------------------------+
核心公式
Stochastic Preemption/Waste Cost:
Total Cost Optimization (Primal):
Optimal Reservation Quantile (Critical Fractile Structure):
Critical Fractile Simplification (zero-pretrain case):
Wasserstein Ambiguity Set:
Tractable DRO Reformulation (LP):
Multi-quantile DRO Reformulation (Proposition III.2):
Cost Ratio from SLO Parameters:
Queueing Delay (M/G/1 Pollaczek-Khinchin):
模型组件
| 组件 | 符号 | 作用 | 决策变量 |
|---|---|---|---|
| GPU Parallelism | 配置每组的张量/流水线并行度 | Discrete config in | |
| KV Cache Reservation | 为类型 请求预留的output token数 | Continuous | |
| Request Routing | 类型 请求路由到组 的概率 | Probability simplex | |
| Prefix Caching | 类型 在组 的前缀缓存比例 | Continuous | |
| Admission Control | 是否允许类型 请求接入 | Binary | |
| DRO Dual Variable | Wasserstein ambiguity set的对偶变量 | Continuous | |
| Epi Variables | 的上界epigraph变量 | Continuous | |
| Quantile Parameter | Continuous |
训练流程
- 数据收集: 从生产trace(BurstGPT/Azure LLM/ShareGPT)收集历史output length样本
- Empirical Distribution: 构建经验分布
- 构建Ambiguity Set: 设置Wasserstein半径 (推荐 )
- DRO求解: 求解LP reformulation (式6/7),获得最优
- BCD分解迭代:
- Step 1: 固定 ,求解inner LP得到
- Step 2: 固定 ,枚举 找最优config
- Rolling Horizon: 部署后periodically用recent data re-optimize
四、核心创新
| # | 创新点 | 说明 | 与传统方法的差距 |
|---|---|---|---|
| 1 | 临界分位数结构(Critical Fractile Structure) | 证明了最优KV cache预留具有closed-form quantile形式 ,其中 。消除了manual heuristic tuning的需要 | 固定分位数(P90/P95/P99)只在特定时最优;此公式自动生成最优分位数 |
| 2 | Wasserstein DRO鲁棒性 | 使用Wasserstein ambiguity set保护distribution shift,而非传统SAA仅拟合训练数据。提供了可证明的out-of-sample保证 | SAA在分布偏移时cost显著恶化(shift 3x时P99从9s变为18s vs DRO的9s) |
| 3 | Tractable LP Reformulation | 通过Kantorovich duality将无限维鲁棒优化转化为有限LP。对于固定 的问题复杂度仅为 | 直接MIBLP求解在 $ |
| 4 | BCD分解算法 | 将混合整数问题分解为GPU configuration和外层LP交替优化。生产规模(15类请求, 12种config, 2000样本)257秒求解 | 与monolithic solver相比,15倍加速且能扩展到production scale |
| 5 | Unified Joint Optimization | 首次将GPU config、KV reserve、routing、prefix caching、admission unified在一个DRO框架内 | 现有系统通常单独优化其中一个方面 |
| 6 | SLO-to-Cost-Ratio映射 | 从LLM serving常见的SLO参数推导出cost ratio: | 传统方法没有将业务SLO参数与优化参数关联的方法 |
五、代码实现分析
当前论文未公开code repository。文中描述的实现基于:
- Solver: Gurobi (用于求解MIBLP baseline和BCD子问题LP)
- Language: Python (simulation framework)
- Key Dependencies: Gurobi optimization, queueing theory models
参考实现的推测文件结构:
kv-cache-robust/
├── dro_optimizer.py # Wasserstein DRO LP formulation
├── bcd_solver.py # Block coordinate descent
├── gpu_config.py # GPU parallelism configuration space
├── queueing_model.py # M/G/1 Pollaczek-Khinchin delay model
├── simulation.py # Request-level simulator
├── trace_datasets.py # BurstGPT, Azure, ShareGPT loaders
├── baselines.py # P90/P95/P99/Mean/Max/SAA
└── ablation.py # Component ablation studies
六、实验结果
基准测试
硬件配置: 8xA100-80GB GPUs serving a 70B model
- : TP=2, PP=1
- : TP=4, PP=1
- : TP=2, PP=2
- : TP=4, PP=2
Cost参数: , , ,
Table II: DRO vs Fixed-Quantile Baselines across Scenarios
| Scenario | DRO Cost | P90 | P95 | DRO Gain | |
|---|---|---|---|---|---|
| Batch | 2 | 184 | 255 | 365 | 28-50% |
| Async API | 5 | 360 | 380 | 459 | 5-22% |
| User-facing | 10 | 587 | 588 | 617 | 0-5% |
| Latency-sensitive | 20 | 931 | 1003 | 931 | 0-7% |
| Critical | 50 | 1575 | 2250 | 1875 | 16-30% |
| Real-time | 100 | 1919 | 4328 | 3448 | 44-56% |
关键发现:
- DRO在所有cost ratio下表现最优
- 在real-time场景()下,DRO相比P90节省 56% cost(1919 vs 4328)
- 在critical场景()下,DRO相比P90节省 30% cost
消融实验
Table V: Ablation on Heterogeneous Instance (, load , 2.5x shifted)
| Variant | Cost | P99 (s) | Goodput | SLO viol. (%) |
|---|---|---|---|---|
| BCD-DRO (ours) | 13,476 ± 208 | 8.12 ± 0.65 | 5.01 ± 0.25 | 26.4 ± 3.7 |
| - Routing (uniform ) | 93,878 ± 5,152 | 177.62 ± 11.90 | 0.63 ± 0.06 | 93.8 ± 0.6 |
| - DRO (SAA, ) | 24,864 ± 1,534 | 11.02 ± 1.55 | 3.68 ± 0.35 | 45.8 ± 5.2 |
| - Prefix caching () | 13,476 ± 208 | 9.95 ± 1.29 | 4.39 ± 0.37 | 35.4 ± 5.4 |
关键发现:
- 移除Routing是最致命的:cost暴增7x(13,476 -> 93,878),SLO violation达93.8%
- 移除DRO鲁棒性():cost增加85%,SLO violation提高73%
- 移除Prefix Caching:不改变preemption/waste cost,但P99 latency增加22.6%(8.12 -> 9.95s)
与现有方法对比
Table IV: Cost across Three Cost-Ratio Regimes and Latency at
| Method | Cost | Cost | Cost | P99 (s) @ | SLO viol. @ |
|---|---|---|---|---|---|
| DRO (ours) | 1,270 | 3,083 | 4,807 | 11.47 | 15.6% |
| P90 | 1,852 | 3,095 | 17,080 | 11.39 | 14.8% |
| P95 | 2,890 | 3,320 | 8,153 | 12.50 | 23.2% |
| P99 | 4,308 | 4,349 | 4,811 | 17.12 | 33.7% |
| Mean | 1,275 | 4,666 | 42,811 | 12.03 | 21.7% |
| Max | 4,752 | 4,756 | 4,807 | 19.04 | 36.7% |
| LP+1σ | 1,729 | 3,143 | 19,055 | 11.30 | 13.2% |
| LP+2σ | 2,615 | 3,207 | 9,865 | 11.80 | 18.0% |
关键发现:
- DRO是唯一在所有三个 regime下都bounded的方法
- P90在时cost暴涨5.5x(3,095 -> 17,080)
- Mean在时cost暴涨13.8x(4,666 -> 42,811)
- DRO的cost跨regime范围仅从1,270到4,807(3.8x),远优于所有baseline
- LP+1σ在时latency略优(P99 11.30s vs 11.47s),但在时cost差4x
Algorithm Scalability (Table III):
| Problem Size | MIBLP Time(s) | MIBLP Status | BCD-DRO Time(s) | Gap |
|---|---|---|---|---|
| 3×4×100 | 0.07 | Optimal | 0.17 | 0.00% |
| 4×4×150 | 1.2 | Optimal | 0.8 | 0.00% |
| 5×5×200 | 33.7 | Optimal | 4.3 | 0.00% |
| 6×6×300 | >300 | Timeout | 10.5 | — |
| 8×6×500 | >300 | Timeout | 22.4 | — |
| 10×8×1000 | — | — | 81.2 | — |
| 15×12×2000 | — | — | 257.7 | — |
BCD-DRO在production规模(15×12×2000)仅需257.7秒,而MIBLP在6×6×300就timeout。
七、相关工作
| 类别 | 论文 | 主要方法 | 与本文差异 |
|---|---|---|---|
| KV Cache Management | PagedAttention [1] | virtualized memory pages | 底层内存管理,不涉及optimization |
| KV Cache Management | Orca [2] | disaggregated prefill/decode | system architecture,非adaptive |
| KV Cache Management | Sarathi-Serve [3] | speculative batching for long outputs | batching only |
| KV Cache Eviction | H2O [4] | heavy-hitter oracle | eviction only |
| KV Cache Compression | SnapKV [5] | token-level importance scoring | compression |
| Prefill Decoding | S³ [6] | increasing GPU utilization | throughput-focused |
| Length Prediction | Response Length Perception [7] | LLM-empowered length prediction | 仅length perception |
| System Design | DistServe [24] | disaggregated prefill/decode | system level |
| 本文 | DRO-based KV Cache | joint optimization + robustness | unified framework with theoretical guarantees |
八、总结
核心贡献
- 首个将Distributionally Robust Optimization应用于LLM KV Cache管理的统一框架,同时考虑GPU parallelism、reservation、routing和prefix caching
- 临界分位数理论(Critical Fractile Structure):证明了最优预留量具有closed-form quantile结构,自动适配任意cost ratio
- Wasserstein DRO的可解重构:通过Kantorovich duality将无限维鲁棒优化转化为线性规划
- BCD分解算法:实现了production-scale问题的有效求解(15×12×2000在258秒内收敛)
- 全面实证评估:在三个真实生产trace上验证了跨regime的鲁棒性和优越性
技术影响
- 为LLM serving系统提供了一种无需手动调参的自适应KV cache管理方案
- 理论上的critical fractile公式可直接嵌入现有serving system(如vLLM、TGI)作为dynamic reservation policy
- Wasserstein DRO framework可扩展到其他LLM资源管理问题(attention cache、batch size scheduling)
局限性
- 参数敏感性:最优性能依赖于准确的cost ratio 估计,虽然框架自动选择optimal quantile,但本身的设定仍需domain knowledge
- Wasserstein半径选择: 影响robustness-optimality trade-off,建议值 缺乏systematic选择方法
- 计算开销:在生产规模(15×12×2000)下需258秒重新优化,虽在re-optimization budget内但仍有改进空间
- SLO模型简化:使用M/G/1队列近似,实际系统可能有更复杂的调度协议和preemption cost
九、参考资源
- Paper: https://arxiv.org/abs/2607.11211
- LaTeXML HTML: https://ar5iv.labs.arxiv.org/html/2607.11211
- 参考文献:
- [1] PagedAttention (SOSP 2023) — vLLM的基础
- [2] Orca (OSDI 2022) — disaggregated prefill/decode
- [3] Sarathi-Serve (OSDI 2024) — speculative batching
- [4] H2O (NeurIPS 2023) — heavy-hitter KV cache eviction
- [5] SnapKV (arXiv 2024) — token-level importance
- [6] S³ (NeurIPS 2023) — GPU utilization for generative inference
- [7] Response Length Perception (NeurIPS 2024) — LLM-empowered scheduling
- [11] MT-Bench / Chatbot Arena (NeurIPS 2023) — LLM evaluation
- [12] Scalable Joint Resource Allocation (arXiv 2025) — similar topic
- [13] Green-LLM (arXiv 2025) — energy-aware distributed inference
- [14] Wasserstein DRO (Math. Program. 2018) — foundational DRO paper
- [15] Edgeworth (1888) — early critical fractile
- [16] Arrow et al. (1951) — classical newsvendor problem
- [17] Data-driven DR Newsvendor (JORS 2021) — Wasserstein newsvendor
- [18] Kleinrock (1975) — Queueing Theory
- [19] Queueing-theoretic Low-Latency LLM (WiOpt 2024) — related queueing approach
- [20] Blockwise CD for Integer Programs (MMOR 2020) — BCD algorithm
- [21] BurstGPT (KDD 2025) — real-world LLM workload dataset
- [22] DynamoLLM (HPCA 2025) — LLM inference cluster design
- [23] ShareGPT — crowdsourced ChatGPT conversations
- [24] DistServe (OSDI 2024) — disaggregated goodput-optimized serving