Block Sparse Flash Attention

Daniel Ohayon, Itay Lamprecht, Itay Hubara, Israel Cohen, Daniel Soudry +1 more
12/7/2025
cs.LGcs.CLcs.PF

Official code: Danielohayon/Block-Sparse-Flash-Attention (36 stars, BSD-3-Clause, last commit 2025-12-10).

Abstract

Modern large language models increasingly require long contexts for reasoning and multi-document tasks, but attention's quadratic complexity creates a severe computational bottleneck. We present Block-Sparse FlashAttention (BSFA), a drop-in replacement that accelerates long-context inference while preserving model quality. Unlike methods that predict importance before computing scores, BSFA computes exact query-key similarities to select the top-k most important value blocks for each query. By comparing per-block maximum scores against calibrated thresholds, we skip approximately 50% of the computation and memory transfers for pruned blocks. Our training-free approach requires only a one-time threshold calibration on a small dataset to learn the per-layer and per-head attention score distributions. We provide a CUDA kernel implementation that can be used as a drop-in replacement for FlashAttention. On Llama-3.1-8B, BSFA achieves up to 1.10x speedup on real-world reasoning benchmarks and up to 1.24x for needle-in-a-haystack retrieval tasks while maintaining above 99% baseline accuracy, with certain configurations even improving accuracy by focusing on the most relevant content, substantially outperforming existing sparse attention methods. The implementation is available at https://github.com/Danielohayon/Block-Sparse-Flash-Attention

View on arXivView PDF

Code Implementations(1)

BSD-3-Clause
360C++, CudaDec 10, 202510 months agoBSD-3-Clause

Similar Papers

Cite this paper

@article{ohayon2025block,
  title  = {Block Sparse Flash Attention},
  author = {Daniel Ohayon and Itay Lamprecht and Itay Hubara and Israel Cohen and Daniel Soudry and Noam Elata},
  year   = {2025},
  eprint = {2512.07011},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2512.07011v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2512.07011.svg)](https://codeofpaper.com/paper/2512.07011)

Discussion