Block Sparse Flash Attention

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Ohayon, Daniel, Lamprecht, Itay, Hubara, Itay, Cohen, Israel, Soudry, Daniel, Elata, Noam
Format: Preprint
Published: 2025
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866909948005318656
author Ohayon, Daniel
Lamprecht, Itay
Hubara, Itay
Cohen, Israel
Soudry, Daniel
Elata, Noam
author_facet Ohayon, Daniel
Lamprecht, Itay
Hubara, Itay
Cohen, Israel
Soudry, Daniel
Elata, Noam
contents 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
format Preprint
id arxiv_https___arxiv_org_abs_2512_07011
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle Block Sparse Flash Attention
Ohayon, Daniel
Lamprecht, Itay
Hubara, Itay
Cohen, Israel
Soudry, Daniel
Elata, Noam
Machine Learning
Computation and Language
Performance
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
title Block Sparse Flash Attention
topic Machine Learning
Computation and Language
Performance
url https://arxiv.org/abs/2512.07011