虚拟头注意力

·

研究论文 · 2026/10/16

针对长上下文大语言模型注意力机制在KV缓存大小、训练与预填充FLOPs及模型质量间的“不可能三角”,提出虚拟头注意力(VHA)。VHA通过两个轻量线性操作——Q Premix(对每个KV组内查询进行近恒等变换,从减半的物理查询头恢复虚拟头多样性)和Linear Postmix(通过低秩I + AB^top残差结构融合头间特征)——同时改善三个顶点。由于无非线性操作,推理时Premix可折叠进查询投影,Postmix可折叠进输出投影,使模型退化为标准GQA-2架构,直接复用现有GQA推理优化。仅用两个KV头,大模型中组大小可达64,充分释放解码时Tensor Core并行性。在四个规模、4K上下文、500亿token预训练中,VHA在每个规模均超越标准GQA基线(+0.05%至+0.81%),同时相比GQA-8在稠密规模减少4倍KV缓存,相比GQA-4在MoE规模减少2倍,并降低训练与预填充FLOPs 7.9%(1.7B,S=4096)。在工业级30B-A3B MoE模型(500B token、8K上下文)上,VHA在12基准基模型评估套件中分别超越MLA和GQA-4 +0.70%/+2.60%;在另一匹配的10B-A1B MoE长上下文中期训练后比较中,VHA在8K-128K上平均RULER得分84.4,而GQA为73.0,且全注意力层使用两个而非四个KV头。

VHA在保持或提升模型质量的同时,显著降低KV缓存和计算开销,且推理时退化为标准GQA-2,易于部署,对长上下文大模型的高效训练与推理具有重要实用价值。

The design of attention mechanisms in long-context large language models faces an ``impossible triangle'' among KV cache size, training and prefill FLOPs, and model quality. GQA achieves strong quality but incurs high KV cache overhead; alternative approaches such as MLA and MFA can compress the cache, but MLA suffers from quality loss while MFA substantially increases training and prefill compute. We propose Virtual Head Attention (VHA), which simultaneously improves all three vertices through two lightweight linear operations: Q Premix applies a near-identity transformation to queries within each KV group to recover virtual head diversity from halved physical query heads, and Linear Postmix fuses inter-head features via a low-rank I + AB^top residual structure. Since VHA introduces no nonlinear operations, Premix can be folded into the query projection and Postmix into the output projection at inference time, reducing the model to a standard GQA-2 architecture that directly reuses all existing GQA inference optimizations. With only two KV heads, the group size in large models readily reaches 64, fully exploiting Tensor Core parallelism during decoding. Across four scales with 4K-context 50B-token pretraining, VHA consistently surpasses the standard GQA baseline at every scale (+0.05\% to +0.81\%), while reducing KV cache by 4times vs.\ GQA-8 at dense scales and 2times vs.\ GQA-4 at the MoE scale, and lowering training and prefill FLOPs by 7.9\% (1.7B, S{=}4096). On an industrial 30B-A3B MoE model trained on 500B tokens at 8K context, VHA outperforms both MLA and GQA-4 by +0.70\,/\,+2.60\,\% on a 12-benchmark base-model evaluation suite; in a separate matched 10B-A1B MoE comparison after long-context mid-training, VHA attains an average RULER score of 84.4 over 8K--128K versus 73.0 for GQA, while using two rather than four KV heads in the full-attention layers.

阅读原文

参与讨论