FOSCAR:通过仿射折叠加速2位和4位KV缓存上的解码注意力
FOSCAR: Accelerating Decode Attention over 2- and 4-Bit KV Caches through Affine Folding
AI总结:
FOSCAR通过仿射折叠减少缩放偏移操作、用位操作适配Tensor Cores并构建专用GPU流水线,在H100/B200上大幅提升2/4位KV缓存解码注意力速度,集成SGLang后长上下文服务吞吐量显著提高。
摘要:
大型语言模型的解码注意力会为每个生成的令牌传输键值(KV)缓存。将该缓存打包为2位或4位量化整数可减少内存流量,但不会自动转化为延迟节省。现有2位融合内核在H100/B200上的峰值高带宽内存(HBM)吞吐量占比不足31%/15%。在输入Tensor Cores前对每个值进行转换并应用其缩放因子和偏移量是主要瓶颈,因为现代GPU上的指令发射吞吐量稀缺。FOSCAR不将缩放因子和偏移量应用于每个KV值,而是根据量化方案(按令牌或按通道),通过仿射折叠将它们应用于解码注意力矩阵乘积的另一个操作数或输出,这在保留去量化注意力输出精确运算的同时,将缩放和偏移操作减少了最多两个数量级。FOSCAR还使用位操作高效地将KV操作数输入Tensor Cores,在H100和B200上每个INT2元素分别仅需要1和0.19个算术逻辑单元(ALU)指令。最后,FOSCAR使用wgmma和tcgen05为Hopper(H100)和Blackwell(B200)构建 warp 专用GPU流水线。在H100上,FOSCAR的INT2和INT4内核相对于FlashInfer BF16的几何平均加速比为3.36倍和2.83倍,相对于TensorRT-LLM FP8的加速比为2.03倍和1.71倍;在B200上,对应的INT2和INT4相对于FlashInfer BF16的加速比为2.67倍和2.30倍,相对于TensorRT-LLM FP8的加速比为1.48倍和1.28倍,相对于TensorRT-LLM NVFP4的加速比为1.16倍和1.00倍。我们将FOSCAR集成到SGLang中以基准测试服务效率,在长上下文服务工作负载中,FOSCAR相对于2位和16位基线分别将峰值聚合吞吐量提高了最多170%和341%。我们将FOSCAR作为内核库开源,链接为该https URL。
英文摘要:
Large-language-model decode attention streams the key-value (KV) cache for every generated token. Packing that cache into 2-bit or 4-bit quantized integers reduces memory traffic but does not automatically translate into latency saving. Existing 2-bit fused kernels reach under 31%/15% of peak HBM throughput on H100/B200. Converting each value and applying its scale and offset before feeding Tensor Cores is a major bottleneck because instruction-issue throughput is scarce on modern GPUs. Instead of applying scale and offset to each KV value, FOSCAR uses affine folding to apply them to the other operand or the output of decode-attention matrix products, depending on the quantization scheme (token-wise or channel-wise). This reduces scale-and-offset operations by up to two orders of magnitude while preserving the dequantized attention output in exact arithmetic. FOSCAR also uses bit manipulation to feed KV operands to Tensor Cores efficiently, requiring only 1 and 0.19 ALU instructions per INT2 element on H100 and B200, respectively. Finally, FOSCAR builds warp-specialized GPU pipelines for Hopper (H100) and Blackwell (B200) using wgmma and tcgen05. On H100, FOSCAR INT2 and INT4 kernels achieve geo-mean speedups of $3.36\times$ and $2.83\times$ over FlashInfer BF16, and $2.03\times$ and $1.71\times$ over TensorRT-LLM FP8. On B200, the corresponding INT2 and INT4 speedups are $2.67\times$ and $2.30\times$ over FlashInfer BF16, $1.48\times$ and $1.28\times$ over TensorRT-LLM FP8, and $1.16\times$ and $1.00\times$ over TensorRT-LLM NVFP4. We integrate FOSCAR into SGLang to benchmark serving efficiency. On long-context serving workloads, FOSCAR increases peak aggregate throughput by up to 170% and 341% over 2-bit and 16-bit baselines, respectively. We open-source FOSCAR as a kernel library at https://github.com/FutureMLS-Lab/FOSCAR.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。