让大模型生成长文本时内存不变,还能更准更稳。
Dialogue Without Limits: Constant-Sized KV Caches for Extended Responses in LLMs
- 用动态筛选机制替换传统缓存,保持固定内存占用
- 长文本生成准确率提升18.2%,内存减少52.9%
- 适合需要实时响应的聊天机器人和代码生成场景
自回归Transformer依赖键值(KV)缓存加速推理,但其随上下文长度线性增长,导致内存消耗过大且带宽受限。这一瓶颈在对话机器人等实时应用中尤为严重。现有方法通过丢弃远距离标记或有损压缩状态来缓解,但牺牲了准确性。我们提出MorphKV,一种推理时技术,在维持恒定大小的KV缓存的同时保持高精度。该方法通过相关性感知的自适应排序,平衡长程依赖与局部连贯性,消除早期标记偏差,保留高保真上下文。不同于启发式保留或有损压缩,MorphKV通过近期标记注意力模式引导轻量级迭代更新,更精准捕捉标记间相关性,对内容创作和代码生成等任务至关重要。在长文本生成任务上的实验表明,相比先进方法,内存节省52.9%,平均准确率提升18.2%,实现高效真实部署。
原文摘要 · Abstract (English)
Autoregressive Transformers rely on Key-Value (KV) caching to accelerate inference. However, the linear growth of the KV cache with context length leads to excessive memory consumption and bandwidth constraints. This bottleneck is particularly problematic in real-time applications -- such as chatbots and interactive assistants -- where low latency and high memory efficiency are critical. Existing methods drop distant tokens or compress states in a lossy manner, sacrificing accuracy by discarding vital context or introducing bias. We propose MorphKV, an inference-time technique that maintains a constant-sized KV cache while preserving accuracy. MorphKV balances long-range dependencies and local coherence during text generation. It eliminates early-token bias while retaining high-fidelity context by adaptively ranking tokens through correlation-aware selection. Unlike heuristic retention or lossy compression, MorphKV iteratively refines the KV cache via lightweight updates guided by attention patterns of recent tokens. This approach captures inter-token correlation with greater accuracy, crucial for tasks like content creation and code generation. Our studies on long-response tasks show 52.9$\%$ memory savings and 18.2$\%$ higher accuracy on average compared to state-of-the-art prior works, enabling efficient real-world deployment.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。