量化为何免费:一种int4 KV缓存性能超越fp16的苹果硅芯片
When Quantization Is Free: An int4 KV Cache That Outruns fp16 on Apple Silicon
AI总结:
本文提出一种int4 KV缓存方法,在苹果硅芯片上实现比fp16更快的性能,通过融合金属内核和内存压缩,保持质量并提升效率。
摘要:
KV缓存量化被视为质量与延迟的权衡。我们展示在苹果硅芯片的统一内存中,一种融合的金属内核(符号随机化FFT + 每通道λ + 每组abs-max + int4 nibble pack)作为HuggingFace的Cache子类,能够在Gemma-3 1B和Qwen2.5-1.5B上以256-4096个标记前缀运行得比fp16更快,内存压缩率提升3倍且质量保持(PPL=0.000 Qwen短提示;Gemma增加3.6 hook PPL)。内核的约25ns/vec开销低于3倍压缩带来的带宽节省。融合内核还解决了Qwen的4位每标记灾难(PPL从+7975降至+638.6,减少12.5倍)在182GFLOPS / D=128的情况下。支持发现:SRFT和SRHT在KV质量上统计上无法区分(我们选择SRFT用于混合基数和矩阵乘法对齐);学习旋转的消融显示固定随机SRFT基底的正则化作用(学习R+λ不使用SRFT降低校准MSE 84.9% vs 50.3%但产生更差PPL);Householder旋转在k=d/2反射器时在d=256时几乎无损。
英文摘要:
KV-cache quantization is framed as a quality--latency trade-off. We show it is \emph{inverted} on Apple Silicon's unified memory: a single fused Metal kernel (sign-randomized FFT $+$ per-channel $λ$ $+$ per-group abs-max $+$ int4 nibble pack), exposed as a HuggingFace \texttt{Cache} subclass, runs \emph{faster than fp16} across $256$--$4096$-token prefixes on Gemma-3 1B ($-3$ to $-8\%$ ms/tok) and at short context on Qwen2.5-1.5B ($-0.7$ to $-2.6\%$ through $1$K), with $3\times$ persistent memory compression and quality preserved ($\dPPL = 0.000$ Qwen short-prompt; $+3.6$ hook $\dPPL$ Gemma). The kernel's $\sim\!25$\,ns/vec overhead is below the bandwidth savings from $3\times$ compression. The fused kernel also closes Qwen's 4-bit per-token catastrophe ($\dPPL = +7975 \to +638.6$, $12.5\times$ reduction) at $182$\,GFLOPS / $D{=}128$. Supporting findings: $\SRFT$ and $\SRHT$ are statistically indistinguishable for KV quality (we pick $\SRFT$ for mixed-radix and matrix-multiply alignment); a learned-rotation ablation surfaces a regularization role for the fixed random SRFT base (learning $R+λ$ without SRFT lowers calibration MSE $84.9\%$ vs $50.3\%$ but yields worse PPL); Householder rotations at $k{=}d/2$ reflectors are effectively lossless at $d{=}256$.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。