在分页服务引擎中仅存储一次 Gemma 4 的 K=V 缓存:注意力内核不变下的精确全局 KV 内存节省 Storing the Gemma 4 K=V Cache Once: Exact Global-KV Memory Savings in a Paged Serving Engine with Unchanged Attention Kernels 预印本

⚠️ 本文为 预印本(arXiv 公开版本),尚未经过正式同行评审。作者自发公开,结论未经期刊审稿验证,阅读时请知悉。
发布时间:2026-11-17
👁️ 预览文献
💡 AI 中文简介
Gemma 4 31B 的全局注意力层中,值(V)是归一化后的键(K)投影,键是值乘以固定权重,且仅四分之一维度加旋转位置编码。理论上可减少 37.5% 的全局 KV 缓存,但现有服务引擎仍存完整 K 和 V。本文提出只存一行 640 个值,通过两个重叠的跨步视图让未修改的分页注意力内核分别读取为 K 缓存和 V 缓存。在 vLLM 原型中,输出与标准缓存模拟逐位一致,解码 KV 内存降低 1.34-1.40 倍(32K-64K tokens),解码吞吐提升 1.11-1.38 倍,且模型预测比率误差在 1% 以内。
领域大语言模型推理与 serving 系统
适合谁读需要一定专业背景(了解 Transformer 注意力机制和推理引擎)
核心贡献1. 利用 Gemma 4 全局注意力层中 K 和 V 的线性关系,仅存储一行 640 个值,通过两个重叠跨步视图让未修改的分页注意力内核分别作为 K 缓存和 V 缓存读取,实现精确(实数算术下)的全局 KV 内存节省。2. 在 vLLM 原型中验证了输出与标准缓存模拟逐位一致,并量化了内存和吞吐收益。
关键数据解码 KV 内存每请求降低 1.34-1.40 倍(32K-64K tokens);解码吞吐提升 1.38 倍(16K prompts)和 1.24 倍(8K prompts);eager 解码吞吐提升 1.30 和 1.11 倍;模型预测比率误差在 1% 以内;eager 步骤在相同 batch 下慢 4%-9%;尚未与 8-bit KV 缓存叠加。
推荐理由如果你关心大模型推理的内存和吞吐优化,这篇工作用巧妙的视图技巧在不改内核的情况下省下大量 KV 缓存,实测收益显著,值得一读。
关键词["KV 缓存", "Gemma 4", "分页注意力", "vLLM", "内存优化", "大语言模型服务"]

原文摘要

查看英文原文摘要

In the global attention layers of Gemma 4 31B, the value is the normalized key projection, and the key is the value scaled by a fixed weight, with rotary position encoding on one quarter of its dimensions. The Gemma 4 report states that this design reduces the global KV cache by up to 37.5%, but the open serving engines that we checked still store a full key and a full value: 1,024 values per KV head and token. We store one 640-value row instead, exact in real arithmetic, and an unchanged paged attention kernel reads it through two overlapping strided views as its key cache and its value cache. In a vLLM prototype with the 16-bit 31B model, the outputs are bit-identical to an emulation of the same arithmetic on the stock cache, 2 of 432 final answers differ from the stock engine (within its run-to-run noise), and the steady decode KV memory per request falls by a factor of 1.34 to 1.40 at 32K to 64K tokens. On a prefill/decode pair of two A100 GPUs with NIXL transfer and CPU offload, a decode engine with a full 15 GiB pool ran 1.38 times the stock decode tokens per step for 16K-token prompts (repeated to 0.06%) and 1.24 times for 8K-token prompts; a model of the vLLM block pool predicted both ratios to within 1% (the engine was 0.7% to 0.9% higher) and matched the change between them. The eager decode throughput rose by 1.30 and 1.11 times, and on this path the compact engine gave the same output tokens as the emulation for 8 prompts at batch 1. The run-time prototype makes an eager step 4% to 9% slower at equal batch, and the method does not yet stack with an 8-bit KV cache at the default scale.