FOSCAR:通过仿射折叠加速2比特和4比特KV缓存的解码注意力 FOSCAR: Accelerating Decode Attention over 2- and 4-Bit KV Caches through Affine Folding 预印本

⚠️ 本文为 预印本(arXiv 公开版本),尚未经过正式同行评审。作者自发公开,结论未经期刊审稿验证,阅读时请知悉。
发布时间:2026-11-06
👁️ 预览文献
💡 AI 中文简介
大模型生成每个词都要读取KV缓存,把缓存压成2比特或4比特能省内存带宽,但现有内核速度慢。FOSCAR提出“仿射折叠”方法,把原本对每个KV值做的缩放和偏移操作转移到矩阵乘法的另一操作数或输出上,操作量减少最多两个数量级,同时用位操作高效喂数据给Tensor Core。在H100和B200上,INT2/INT4内核比FlashInfer BF16快2.3到3.36倍,集成到SGLang后长上下文服务吞吐最高提升341%。
领域大语言模型推理加速/GPU内核优化
适合谁读需要一定专业背景(熟悉GPU架构、量化推理和注意力机制)
核心贡献1. 提出仿射折叠技术,将反量化中的缩放和偏移操作从每个KV值转移到矩阵乘法另一操作数或输出,大幅减少指令数;2. 针对Hopper和Blackwell架构设计warp特化的GPU流水线,实现高效的2/4比特解码注意力内核。
关键数据在H100上,INT2/INT4内核比FlashInfer BF16快3.36倍/2.83倍,比TensorRT-LLM FP8快2.03倍/1.71倍;在B200上,比FlashInfer BF16快2.67倍/2.30倍,比TensorRT-LLM NVFP4快1.16倍/1.00倍;长上下文服务吞吐比2比特和16比特基线分别提升170%和341%。
推荐理由如果你关心大模型推理速度,这篇论文用巧妙的数学变换把2比特KV缓存真正变快,实测提升显著,代码已开源,值得一读。
关键词["KV缓存量化", "解码注意力", "仿射折叠", "Tensor Core", "大语言模型推理", "GPU内核优化"]

原文摘要

查看英文原文摘要

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.