2025-02-19 · 专家 · 自然语言处理 · 机器学习

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

HEADINFER通过头部级别的卸载策略,显著减少了大型语言模型(LLM)推理过程中的内存占用,使得在消费级GPU上实现长上下文推理成为可能。

更新于 2026-02-27。作者:Cheng Luo、Zefan Cai、Hanshi Sun、Jinqi Xiao、Bo Yuan、Wen Xiao、Junjie Hu、Jiawei Zhao、Beidi Chen、Anima Anandkumar。

中文摘要

基于Transformer的大型语言模型(LLMs)在长上下文生成方面表现出令人印象深刻的能力。扩展上下文长度不成比例地增加了LLMs在推理过程中的内存占用,主要转移到键值缓存(KV缓存)上。在本文中,我们提出了HEADINFER,该方案将KV缓存卸载到CPU RAM中,同时避免了在GPU上完全存储任何Transformer层的KV缓存的需求。HEADINFER采用细粒度、按头部卸载的策略,只在GPU上保留选定的注意力头部KV缓存,并动态计算注意力输出。通过屋顶线分析,我们证明了HEADINFER在显著减少内存占用同时保持了计算效率。我们在Llama-3-8B模型上评估了HEADINFER,使用了包含100万个标记的序列,将KV缓存的GPU内存占用从128 GB减少到1 GB,总GPU内存占用从207 GB减少到17 GB,与BF16基线推理相比实现了92%的减少。值得注意的是,HEADINFER使得使用8B模型在单个24GB内存的消费级GPU(例如NVIDIA RTX 4090)上实现400万个标记的推理成为可能,而不需要使用近似方法。

英文摘要

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.

解读

一句话总结

HEADINFER通过头部级别的卸载策略,显著减少了大型语言模型(LLM)推理过程中的内存占用,使得在消费级GPU上实现长上下文推理成为可能。

问题1:这篇论文想要解决什么具体问题?

问题2:论文的核心创新点是什么?

问题3:实验结果如何验证了方法的有效性?

问题4:这个研究的实际应用价值是什么?

来源

机器可读索引:llms.txt