HeadInfer: Memory-Efficient LLM Inference by Head-wise Offloading
Luo, Cheng, Zefan Cai, Sun, Hanshi, Jinqi Xiao, Yuan, Bo, Xiao Wen et al. · 2025 · 18 citationsRead the paper
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.
What the full text shows
Working prototype- Reduced total GPU memory usage for Llama-3-8B with 1-million-token sequence compared to BF16 baseline. — 92% reduction (207 GB to 17 GB) (Llama-3-8B, 1M tokens, single RTX-4090 GPU)
- Reduced GPU memory footprint of the KV cache for Llama-3-8B with 1-million-token sequence. — 128 GB to 1 GB (Llama-3-8B, 1M tokens, single RTX-4090 GPU)
- Enabled inference of extremely long contexts on a single consumer GPU without approximation. — Up to 4 million tokens (Llama-3-8B, NVIDIA RTX 4090 (24GB))
- Increased maximum achievable sequence length on Ruler benchmark compared to other offloading methods. — 4x improvement (128K vs 32K) (Ruler benchmark)
- Outperformed other methods on LongBench v2 'Medium' and 'Long' categories. — Scores of 27.70 and 30.6 respectively (LongBench v2, single RTX-4090 GPU)
- Setup
- Single NVIDIA RTX 4090 (24GB HBM3), 256-core AMD EPYC 7B13 CPUs, 1TB DDR5 RAM, PCIe 4.0. Models tested include Llama-3-8B, Llama-2-7B, Mistral-7B, Qwen2-7B, and Gemma-2-9b.
- How
- The paper introduces HEADINFER, which uses a fine-grained head-wise offloading strategy to move the KV cache to CPU RAM, keeping only selective attention heads on the GPU. It combines this with chunked-prefill to minimize activation memory and employs asynchronous offloading to maintain computational efficiency.
- Limitations
- Decoding performance is primarily memory-bound, meaning PCIe bandwidth can degrade throughput. · Maximum context length is eventually constrained by available CPU RAM (512GB for KV cache in tests). · Offload-induced slowdowns occur for very short context lengths (S ≤ 1k).
Summarized by Gemma 4 from the open-access full text · 8 Nov 2026. Read it