Lune

ICLR2025Top-tier venue

FlexPrefill: A Context-Aware Sparse Attention Mechanism for Efficient Long-Sequence Inference

Xunhao Lai, Jianqiao Lu, Yao Luo, Yiyuan Ma, Xun Zhou

Abstract

Large language models (LLMs) encounter computational challenges during long-sequence inference, especially in the attention pre-filling phase, where the complexity grows quadratically with the prompt length. Previous efforts to mitigate these challenges have relied on fixed sparse attention patterns or identifying sparse attention patterns based on limited cases. However, these methods lacked the flexibility to efficiently adapt to varying input demands. In this paper, we introduce FlexPrefill, a Flexible sparse Pre-filling mechanism that dynamically adjusts sparse attention patterns and computational budget in real-time to meet the specific requirements of each input and attention head. The flexibility of our method is demonstrated through two key innovations: 1) Query-Aware Sparse Pattern Determination: By measuring Jensen-Shannon divergence, this component adaptively switches between query-specific diverse attention patterns and predefined attention patterns. 2) Cumulative-Attention Based Index Selection: This component dynamically selects query-key indexes to be computed based on different attention patterns, ensuring the sum of attention scores meets a predefined threshold.FlexPrefill adaptively optimizes the sparse pattern and sparse ratio of each attention head based on the prompt, enhancing efficiency in long-sequence inference tasks. Experimental results show significant improvements in both speed and accuracy over prior methods, providing a more flexible and efficient solution for LLM inference.

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.

57 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 Big Bird: Transformers for Longer Sequences
  • 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 FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning
  • Block-Sparse Global Attention for Efficient Multi-View Geometry Transformers cites FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness
  • Block-Sparse Global Attention for Efficient Multi-View Geometry Transformers cites FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning
  • Flow Caching for Autoregressive Video Generation cites Sparse VideoGen2: Accelerate Video Generation with Sparse Attention via Semantic-Aware Permutation
  • FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness cites Big Bird: Transformers for Longer Sequences
  • FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness cites Efficiently Modeling Long Sequences with Structured State Spaces
  • FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning cites Big Bird: Transformers for Longer Sequences
  • FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning cites FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness
  • InfLLM-V2: Dense-Sparse Switchable Attention for Seamless Short-to-Long Adaptation cites Efficient Streaming Language Models with Attention Sinks
  • InfLLM-V2: Dense-Sparse Switchable Attention for Seamless Short-to-Long Adaptation cites Big Bird: Transformers for Longer Sequences
  • InfLLM-V2: Dense-Sparse Switchable Attention for Seamless Short-to-Long Adaptation cites FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning
  • Neural Attention Search cites Efficient Streaming Language Models with Attention Sinks
  • Neural Attention Search cites FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness
  • Neural Attention Search cites FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning
  • Sparse VideoGen2: Accelerate Video Generation with Sparse Attention via Semantic-Aware Permutation cites Efficient Streaming Language Models with Attention Sinks
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers57

  1. Neural Attention SearchDifan Deng, Marius LindauerNeurIPS 2025 · 431 citations
  2. Sparse VideoGen2: Accelerate Video Generation with Sparse Attention via Semantic-Aware PermutationShuo Yang, Haocheng Xi, Yilong Zhao, Muyang Li et al.NeurIPS 2025 · 114 citations
  3. InfLLM-V2: Dense-Sparse Switchable Attention for Seamless Short-to-Long AdaptationWeilin Zhao, Zihan Zhou, Zhou Su, Chaojun Xiao et al.ICLR 2026 · 32 citations
  4. Block-Sparse Global Attention for Efficient Multi-View Geometry TransformersChung-Shien Brian Wang, Christian Schmidt, Jens Piekenbrinck, Bastian LeibeCVPR 2026 · 22 citations
  5. Flow Caching for Autoregressive Video GenerationYuexiao Ma, Xuzhe Zheng, Jing Xu, Xiwei Xu et al.ICLR 2026 · 20 citations

Builds on35

  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. Efficiently Modeling Long Sequences with Structured State SpacesAlbert Gu, Karan Goel, Christopher RéICLR 2022 · 3,482 citations
  3. Big Bird: Transformers for Longer SequencesManzil Zaheer, Guru Guruganesh, Kumar Avinava Dubey, Joshua Ainslie et al.NeurIPS 2020 · 3,159 citations
  4. FlashAttention-2: Faster Attention with Better Parallelism and Work PartitioningTri DaoICLR 2024 · 2,600 citations
  5. Efficient Streaming Language Models with Attention SinksGuangxuan Xiao, Yuandong Tian, Beidi Chen, Song Han et al.ICLR 2024 · 1,714 citations

Related papers

  1. Elastic Attention: Test-time Adaptive Sparsity Ratios for Efficient TransformersZecheng Tang, Quantong Qiu, Yi Yang, Zhiyi Hong et al.ICML 2026 · 4 citations
  2. MInference 1.0: Accelerating Pre-filling for Long-Context LLMs via Dynamic Sparse AttentionHuiqiang Jiang, Yucheng Li, Chengruidong Zhang, Qianhui Wu et al.NeurIPS 2024 · 479 citations
  3. ProxyAttn: Guided Sparse Attention via Representative HeadsYixuan Wang, Huang He, Siqi Bao, Hua Wu et al.ICLR 2026 · 9 citations
  4. AnchorAttention: Difference-Aware Sparse Attention with Stripe GranularityYu Zhang, Dong Guo, Fang Wu, Guoliang Zhu et al.EMNLP 2025
  5. DAM: Dynamic Attention Mask for Long-Context Large Language Model Inference AccelerationHanzhi Zhang, Heng Fan, Kewei Sha, Yan Huang et al.ACL Findings 2025 · 1 citation
Dusk over the sea between two cliffs drawn in fine vertical lines