LongHeads: Multi-Head Attention is Secretly a Long Context Processor
Not on the map. Why?
Abstract (arXiv)
Large language models (LLMs) have achieved impressive performance in numerous domains but often struggle to process lengthy inputs effectively and efficiently due to limited length generalization and attention's quadratic computational demands. Many sought to mitigate this by restricting the attention window within the pre-trained length. However, these methods introduce new issues such as ignoring the middle context and requiring additional training. To address these problems, we propose LongHeads, a training-free framework that enhances LLM's long context ability by unlocking multi-head attention's untapped potential. Instead of allowing each head to attend to the full sentence, which struggles with generalizing to longer sequences due to out-of-distribution (OOD) issues, we allow each head to process in-distribution length by selecting and attending to important context chunks. To this end, we propose a chunk selection strategy that relies on the inherent correlation between the query and the key representations, efficiently distributing context chunks to different heads. In this way, each head ensures it can effectively process attended tokens within the trained length, while different heads in different layers can collectively process longer contexts. LongHeads works efficiently in linear time, fits seamlessly with many LLMs that use relative positional encoding. LongHeads achieves 100% accuracy at the 128k length on passkey retrieval task, verifying LongHeads's efficacy in extending the usable context window for existing models. We release our code at https://github.com/LuLuLuyi/LongHeads .
Key facts. Cited by 16 papers in the map (data through 7 Oct 2026). Builds on 11 of its 22 references that are in the map. First posted on arXiv 16 Feb 2024.
Builds on
11 of 22 references.
References · 11
- 2023Llama 2: Open Foundation and Fine-Tuned Chat Modelscited by 12,865
- 2023Retrieval-Augmented Generation for Large Language Models: A Surveycited by 2,185
- 2023Efficient Streaming Language Models with Attention Sinkscited by 2,115
- 2023LongBench: A Bilingual, Multitask Benchmark for Long Context Understandingcited by 1,378
- 2021Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolationcited by 1,085
- 2023Extending Context Window of Large Language Models via Positional Interpolationcited by 721
- 2022A Survey on In-context Learningcited by 717
- 2019Compressive Transformers for Long-Range Sequence Modellingcited by 699
- 2023Landmark Attention: Random-Access Infinite Context Length for Transformerscited by 206
- 2024LLM Maybe LongLM: Self-Extend LLM Context Window Without Tuningcited by 133
- 2021Do Long-Range Language Models Actually Use Long-Range Context?cited by 92
Built on by
Citing papers per year: 2024: 6; 2025: 10.
16 papers.
Sort:
By area:
- 2025MoBA: Mixture of Block Attention for Long-Context LLMscited by 188
- 2024LongRAG: A Dual-Perspective Retrieval-Augmented Generation Paradigm for Long-Context Question Answeringcited by 49
- 2025Cognitive Memory in Large Language Modelscited by 28
- 2024A Controlled Study on Long Context Extension and Generalization in LLMscited by 26
- 2025Softpick: No Attention Sink, No Massive Activations with Rectified Softmaxcited by 20
- 2024Symbolic Working Memory Enhances Language Models for Complex Rule Applicationcited by 17
- 2024ReAttention: Training-Free Infinite Context with Finite Attention Scopecited by 13
- 2024MemLong: Memory-Augmented Retrieval for Long Text Modelingcited by 11
- 2025Make It Efficient: Dynamic Sparse Attention for Autoregressive Image Generationcited by 7
- 2024CItruS: Chunked Instruction-aware State Eviction for Long Sequence Modelingcited by 4
- 2025Task-KV: Task-aware KV Cache Optimization via Semantic Differentiation of Attention Headscited by 4
- 2025Alleviating Forgetfulness of Linear Attention by Hybrid Sparse Attention and Contextualized Learnable Token Evictioncited by 3
4 more
- 2025FidelityGPT: Correcting Decompilation Distortions with Retrieval Augmented Generationcited by 2
- 2025Beyond Real: Imaginary Extension of Rotary Position Embeddings for Long-Context LLMscited by 2
- 2025MoSKA: Mixture of Shared KV Attention for Efficient Long-Sequence LLM Inferencecited by 1
- 2025Effective Length Extrapolation via Dimension-Wise Positional Embeddings Manipulationcited by 0
- 2025Beyond Real: Imaginary Extension of Rotary Position Embeddings for Long-Context LLMs8 Dec 2025
- 2025MoSKA: Mixture of Shared KV Attention for Efficient Long-Sequence LLM Inference8 Nov 2025
- 2025Alleviating Forgetfulness of Linear Attention by Hybrid Sparse Attention and Contextualized Learnable Token Eviction23 Oct 2025
- 2025FidelityGPT: Correcting Decompilation Distortions with Retrieval Augmented Generation22 Oct 2025
- 2025Make It Efficient: Dynamic Sparse Attention for Autoregressive Image Generation23 Jun 2025
- 2025Softpick: No Attention Sink, No Massive Activations with Rectified Softmax29 Apr 2025
- 2025Effective Length Extrapolation via Dimension-Wise Positional Embeddings Manipulation26 Apr 2025
- 2025Cognitive Memory in Large Language Models3 Apr 2025
- 2025MoBA: Mixture of Block Attention for Long-Context LLMs18 Feb 2025
- 2025Task-KV: Task-aware KV Cache Optimization via Semantic Differentiation of Attention Heads25 Jan 2025
- 2024LongRAG: A Dual-Perspective Retrieval-Augmented Generation Paradigm for Long-Context Question Answering23 Oct 2024
- 2024A Controlled Study on Long Context Extension and Generalization in LLMs18 Sep 2024
4 more
- 2024MemLong: Memory-Augmented Retrieval for Long Text Modeling30 Aug 2024
- 2024Symbolic Working Memory Enhances Language Models for Complex Rule Application24 Aug 2024
- 2024ReAttention: Training-Free Infinite Context with Finite Attention Scope21 Jul 2024
- 2024CItruS: Chunked Instruction-aware State Eviction for Long Sequence Modeling17 Jun 2024
- 2025Make It Efficient: Dynamic Sparse Attention for Autoregressive Image Generationcited by 7
- 2025Task-KV: Task-aware KV Cache Optimization via Semantic Differentiation of Attention Headscited by 4
- 2025Alleviating Forgetfulness of Linear Attention by Hybrid Sparse Attention and Contextualized Learnable Token Evictioncited by 3
- 2025Alleviating Forgetfulness of Linear Attention by Hybrid Sparse Attention and Contextualized Learnable Token Eviction23 Oct 2025
- 2025Make It Efficient: Dynamic Sparse Attention for Autoregressive Image Generation23 Jun 2025
- 2025Task-KV: Task-aware KV Cache Optimization via Semantic Differentiation of Attention Heads25 Jan 2025
- 2025MoBA: Mixture of Block Attention for Long-Context LLMscited by 188
- 2025MoBA: Mixture of Block Attention for Long-Context LLMs18 Feb 2025
- 2025Cognitive Memory in Large Language Modelscited by 28
- 2024A Controlled Study on Long Context Extension and Generalization in LLMscited by 26
- 2025Softpick: No Attention Sink, No Massive Activations with Rectified Softmaxcited by 20
- 2024ReAttention: Training-Free Infinite Context with Finite Attention Scopecited by 13
- 2024MemLong: Memory-Augmented Retrieval for Long Text Modelingcited by 11
- 2024CItruS: Chunked Instruction-aware State Eviction for Long Sequence Modelingcited by 4
- 2025Beyond Real: Imaginary Extension of Rotary Position Embeddings for Long-Context LLMscited by 2
- 2025MoSKA: Mixture of Shared KV Attention for Efficient Long-Sequence LLM Inferencecited by 1
- 2025Effective Length Extrapolation via Dimension-Wise Positional Embeddings Manipulationcited by 0
- 2025Beyond Real: Imaginary Extension of Rotary Position Embeddings for Long-Context LLMs8 Dec 2025
- 2025MoSKA: Mixture of Shared KV Attention for Efficient Long-Sequence LLM Inference8 Nov 2025
- 2025Softpick: No Attention Sink, No Massive Activations with Rectified Softmax29 Apr 2025
- 2025Effective Length Extrapolation via Dimension-Wise Positional Embeddings Manipulation26 Apr 2025
- 2025Cognitive Memory in Large Language Models3 Apr 2025
- 2024A Controlled Study on Long Context Extension and Generalization in LLMs18 Sep 2024
- 2024MemLong: Memory-Augmented Retrieval for Long Text Modeling30 Aug 2024
- 2024ReAttention: Training-Free Infinite Context with Finite Attention Scope21 Jul 2024
- 2024CItruS: Chunked Instruction-aware State Eviction for Long Sequence Modeling17 Jun 2024