等价幻觉:KV缓存自回归推断中的系统性FP16差异
The Illusion of Equivalence: Systematic FP16 Divergence in KV-Cached Autoregressive Inference
AI总结:
研究揭示KV缓存推断在FP16精度下与无缓存计算存在系统性差异,通过实验验证了浮点数非结合性导致的确定性偏差,并提出机制框架解释现代LLM推理中的数值不稳定性。
摘要:
KV缓存是自回归Transformer推理中的常见优化,长期被认为在数值上等同于无缓存计算。但在标准FP16精度下,缓存开启与关闭的执行路径采用不同的浮点数累积顺序,由于FP16非结合性,导致解码令牌序列出现确定性差异。在三个开源模型(LLaMA-2-7B、Mistral-7B-v0.3、Gemma-2-2B)上评估GSM8K数据集时,所有采样策略均出现100%的令牌差异率,排除了采样随机性作为原因,并发现缓存开启在9种情况下中表现更准确,表明差异方向是系统性的而非随机的。受控FP32验证将差异减少八个数量级,消除令牌翻转并使翻转率降至0.0%,证实FP16非结合性是唯一因果驱动因素。逐层漂移分析揭示了可预测的传播模式:使用分组查询注意力的模型在第一层出现急剧差异,而Gemma的较大头维度和滑动窗口注意力在所有层产生均匀累积。最后,对整个残差流的激活修补无法恢复无缓存轨迹,将因果变量本地化到状态ful的KV缓存。这些发现确立了FP16 KV缓存推断与重新计算本质上不等同,并提供了一种理解现代LLM推理系统中数值不稳定的机制框架。
英文摘要:
KV caching is a ubiquitous optimization in autoregressive transformer inference, long presumed to be numerically equivalent to cache-free computation. This assumption fails under standard FP16 precision: cache-ON and cache-OFF execution paths employ different floating-point accumulation orderings which, due to FP16 non-associativity, produce a deterministic divergence in decoded token sequences. Across three open-weight models (LLaMA-2-7B, Mistral-7B-v0.3, Gemma-2-2B) evaluated on GSM8K, we observe a 100\% token divergence rate across all sampling strategies, including greedy decoding, which rules out sampling randomness as a cause, and also with cache-ON yielding higher accuracy in 8 of 9 conditions, where the accuracy difference serves as an indicator that the divergence direction is systematic rather than random. Controlled FP32 falsification reduces divergence by eight orders of magnitude, eliminates token flips, and drops the flip rate to exactly 0.0\%, confirming FP16 non-associativity as the sole causal driver. Layer-wise drift profiling reveals architecturally predictable propagation patterns: models using Grouped-Query Attention exhibit sharp divergence at the first layer, while Gemma's larger head dimension and sliding window attention produce uniform accumulation across all layers. Finally, activation patching of the entire residual stream fails to recover the cache-free trajectory, localizing the causal variable to the stateful KV cache. These findings establish that FP16 KV cache inference is fundamentally non-equivalent to recomputation and provide a mechanistic framework for understanding numerical instability in modern LLM inference systems.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。