Lune

EMNLP Findings2024

LongHeads: Multi-Head Attention is Secretly a Long Context Processor

Yi Lu, Xin Zhou, Wei He, Jun Zhao, Tao Ji, Tao Gui, Qi Zhang, Xuanjing Huang

Abstract

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, 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 and 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.

Ask Lune

Know this paper in minutes, not an afternoon.

Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.

8 top-tier papers have cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

the full paper · the top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Lineage

  • Efficient Streaming Language Models with Attention Sinks cites Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation
  • Efficient Streaming Language Models with Attention Sinks cites FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness
  • Efficient Streaming Language Models with Attention Sinks cites YaRN: Efficient Context Window Extension of Large Language Models
  • Efficient Streaming Language Models with Attention Sinks cites Compressive Transformers for Long-Range Sequence Modelling
  • MoBA: Mixture of Block Attention for Long-Context LLMs cites Efficient Streaming Language Models with Attention Sinks
  • MoBA: Mixture of Block Attention for Long-Context LLMs cites FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness
  • Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation cites Compressive Transformers for Long-Range Sequence Modelling
  • FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness cites Compressive Transformers for Long-Range Sequence Modelling
  • YaRN: Efficient Context Window Extension of Large Language Models cites Compressive Transformers for Long-Range Sequence Modelling
  • LongRAG: A Dual-Perspective Retrieval-Augmented Generation Paradigm for Long-Context Question Answering cites Efficient Streaming Language Models with Attention Sinks
  • LongRAG: A Dual-Perspective Retrieval-Augmented Generation Paradigm for Long-Context Question Answering cites FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness
  • LongRAG: A Dual-Perspective Retrieval-Augmented Generation Paradigm for Long-Context Question Answering cites YaRN: Efficient Context Window Extension of Large Language Models
  • Beyond Real: Imaginary Extension of Rotary Position Embeddings for Long-Context LLMs cites Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation
  • Beyond Real: Imaginary Extension of Rotary Position Embeddings for Long-Context LLMs cites YaRN: Efficient Context Window Extension of Large Language Models
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers8

  1. MoBA: Mixture of Block Attention for Long-Context LLMsEnzhe Lu, Zhejun Jiang, Jingyuan Liu, Yulun Du et al.NeurIPS 2025 · 219 citations
  2. LongRAG: A Dual-Perspective Retrieval-Augmented Generation Paradigm for Long-Context Question AnsweringQingfei Zhao, Ruobing Wang, Yukuo Cen, Daren Zha et al.EMNLP 2024 · 13 citations
  3. Symbolic Working Memory Enhances Language Models for Complex Rule ApplicationSiyuan Wang, Zhongyu Wei, Yejin Choi, Xiang RenEMNLP 2024 · 6 citations
  4. FidelityGPT: Correcting Decompilation Distortions with Retrieval Augmented GenerationZhiping Zhou, Xiaohong Li, Ruitao Feng, Yao Zhang et al.NDSS 2026 · 5 citations
  5. Beyond Real: Imaginary Extension of Rotary Position Embeddings for Long-Context LLMsXiaoran Liu, Yuerong Song, Zhigeng Liu, Zengfeng Huang et al.ICLR 2026 · 2 citations

Builds on10

  1. FlashAttention: Fast and Memory-Efficient Exact Attention with IO-AwarenessTri Dao, Daniel Y. Fu, Stefano Ermon, Atri Rudra et al.NeurIPS 2022 · 5,493 citations
  2. Efficient Streaming Language Models with Attention SinksGuangxuan Xiao, Yuandong Tian, Beidi Chen, Song Han et al.ICLR 2024 · 1,714 citations
  3. Train Short, Test Long: Attention with Linear Biases Enables Input Length ExtrapolationOfir Press, Noah A. Smith, Mike LewisICLR 2022 · 1,168 citations
  4. Compressive Transformers for Long-Range Sequence ModellingJack W. Rae, Anna Potapenko, Siddhant M. Jayakumar, Chloe Hillier et al.ICLR 2020 · 833 citations
  5. YaRN: Efficient Context Window Extension of Large Language ModelsBowen Peng, Jeffrey Quesnelle, Honglu Fan, Enrico ShippoleICLR 2024 · 508 citations

Related papers

  1. Training-Free Long-Context Scaling of Large Language ModelsChenxin An, Fei Huang, Jun Zhang, Shansan Gong et al.ICML 2024 · 68 citations
  2. ReAttention: Training-Free Infinite Context with Finite Attention ScopeXiaoran Liu, Ruixiao Li, Zhigeng Liu, Qipeng Guo et al.ICLR 2025
  3. PoSE: Efficient Context Window Extension of LLMs via Positional Skip-wise TrainingDawei Zhu, Nan Yang, Liang Wang, Yifan Song et al.ICLR 2024 · 110 citations
  4. Parallel Context Windows for Large Language ModelsNir Ratner, Yoav Levine, Yonatan Belinkov, Ori Ram et al.ACL 2023 · 37 citations
  5. InfLLM: Training-Free Long-Context Extrapolation for LLMs with an Efficient Context MemoryChaojun Xiao, Pengle Zhang, Xu Han, Guangxuan Xiao et al.NeurIPS 2024 · 223 citations
Dusk over the sea between two cliffs drawn in fine vertical lines