优化大模型推理的键值缓存,提升多轮对话的准确性和连贯性。
Stateful KV Cache Management for LLMs: Balancing Space, Time, Accuracy, and Positional Fidelity
- 通过保持上下文连续性,避免因缓存压缩打乱位置编码
- 当缓存接近8192令牌时生成质量急剧下降,与显存无关
- 简单保留初始片段比复杂策略更有效,适合实际部署
键值(KV)缓存对大语言模型的高效自回归推理至关重要,但在有状态多轮对话中其无限制增长带来重大挑战。本文通过状态化基准测试框架的实证分析发现,当累积的KV缓存接近或超过模型训练上下文窗口(如Llama 3的8192令牌)时,生成质量会显著下降,这一失效模式不同于显存耗尽。常见的淘汰策略,即使高保留率(如99%的AttentionTop),若破坏位置一致性也会恶化性能。由于大模型依赖稳定的相对位置信号(如RoPE),非连续性删除缓存会导致位置信号错乱,引发退化输出。研究进一步表明,仅保留初始连续上下文块的简单策略,反而比复杂且破坏位置结构的方法更优。因此,我们主张采用尊重模型架构限制、保护位置结构、全面评估缓存健康度的淘汰机制。
原文摘要 · Abstract (English)
The Key-Value (KV) cache is integral to efficient autoregressive inference in large language models (LLMs), yet its unbounded growth in stateful multi-turn scenarios presents major challenges. This paper examines the interplay between KV cache management strategies, the architectural context limits of models like meta-llama/Meta-Llama-3-8b-instruct, and the often-overlooked integrity of positional encodings. Through empirical analysis using a stateful benchmarking framework, we show that LLM generation quality degrades sharply when the accumulated KV cache approaches or exceeds the model's trained context window (e.g., 8192 tokens for Llama 3), a failure mode distinct from GPU memory exhaustion. Common eviction strategies, even high-retention ones (e.g., 99% via AttentionTop), can worsen performance if they disrupt positional coherence. Because LLMs rely on consistent positional signals (e.g., RoPE), compacting a cache by removing non-contiguous tokens can scramble these signals and lead to degenerative outputs. We further show that simple strategies preserving contiguous context blocks (e.g., keeping an initial "gist") can yield more coherent generations than complex or positionally disruptive ones. We advocate for eviction techniques that respect architectural limits, preserve positional structure, and view "cache health" holistically beyond mere size.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。