arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2502.12574cs.LGcs.AI
收藏

HeadInfer:通过逐注意力头卸载实现内存高效的大语言模型推理

HeadInfer: Memory-Efficient LLM Inference by Head-wise Offloading

University of Wisconsin-Madison(威斯康星大学麦迪逊分校);Microsoft(微软公司);Rutgers University(罗格斯大学);California Institute of Technology(加州理工学院);Carnegie Mellon University(卡内基梅隆大学)

Cheng Luo, Zefan Cai, Hanshi Sun, Jinqi Xiao, Bo Yuan, Wen Xiao, Junjie Hu, Jiawei Zhao, Beidi Chen, Anima Anandkumar

AI总结:

针对长上下文LLM推理中KV缓存显存激增问题,本文提出HeadInfer,通过逐注意力头细粒度卸载至CPU内存并动态计算注意力,在保持效率的同时大幅降低GPU显存,使8B模型可在单张24GB消费级GPU上处理400万token。

摘要:

基于Transformer的大语言模型(LLMs)在长上下文生成中展现出令人印象深刻的性能。扩展上下文长度使得LLMs推理期间的内存占用不成比例地转移到键值缓存(KV cache)。本文提出HEADINFER,该方法将KV缓存卸载到CPU RAM,同时避免在GPU上完整存储任何Transformer层的KV缓存。HEADINFER采用细粒度的逐注意力头卸载策略,仅在GPU上保留选择性注意力头的KV缓存,同时动态计算注意力输出。通过屋顶线分析,我们证明HEADINFER在显著减少内存占用的同时保持计算效率。我们在Llama-3-8B模型上评估HEADINFER,处理100万token序列时,将KV缓存的GPU内存占用从128 GB降至1 GB,总GPU内存使用从207 GB降至17 GB,与BF16基线推理相比减少了92%。值得注意的是,HEADINFER无需近似方法即可在单张24GB内存的消费级GPU(如NVIDIA RTX 4090)上实现8B模型的400万token推理。

英文摘要:

Transformer-based large language models (LLMs) demonstrate impressive performance in long context generation. Extending the context length has disproportionately shifted the memory footprint of LLMs during inference to the key-value cache (KV cache). In this paper, we propose HEADINFER, which offloads the KV cache to CPU RAM while avoiding the need to fully store the KV cache for any transformer layer on the GPU. HEADINFER employs a fine-grained, head-wise offloading strategy, maintaining only selective attention heads KV cache on the GPU while computing attention output dynamically. Through roofline analysis, we demonstrate that HEADINFER maintains computational efficiency while significantly reducing memory footprint. We evaluate HEADINFER on the Llama-3-8B model with a 1-million-token sequence, reducing the GPU memory footprint of the KV cache from 128 GB to 1 GB and the total GPU memory usage from 207 GB to 17 GB, achieving a 92% reduction compared to BF16 baseline inference. Notably, HEADINFER enables 4-million-token inference with an 8B model on a single consumer GPU with 24GB memory (e.g., NVIDIA RTX 4090) without approximation methods.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑