Profile

Settings

Loading…

← Papers

Help

FAQ

Which features require signing in?

You can read the commentary, paper info, Model Structure and related papers of public papers without signing in. Sign in to manage your account or contact us about your inquiries.

Can I upload a PDF file?

Upload papers with an arXiv or DOI link; the commentary is public to everyone. Papers whose source and terms of use can't be verified, so the commentary can't be made public, can't be uploaded. Uploading PDF files and keeping papers private are for subscribers only, and a paper uploaded as a file is saved as private only. Searching for official info by title runs only when you press the button.

Are the figures and AI commentary accurate?

Figures come only from the original paper, and only those whose terms of use are verified are shown. The commentary is written by AI and may be wrong. Check important claims, numbers and figure context against the evidence in the original paper.

I want to report a copyright issue.

Terms of use and the source of the original paper are on the Paper info tab. If there's a problem, choose "Paper content, figures and copyright" under Contact us and send the paper link, the part in question, and evidence that you hold the rights. Receiving your report doesn't confirm any rights or remove anything right away. You can see the result of the review under My inquiries.

I forgot my password.

If you signed up with email, use Forgot password in the sign-in window to reset it with your verified email. If you signed up with Google, Naver or Kakao, change your password with that service.

What should I include in an inquiry?

Tell us which screen you were on and what you were doing when the problem happened, along with the paper link. Don't include personal information such as passwords, API keys, verification codes or phone numbers. Inquiries and replies are stored in Refivu and you can see them under My inquiries.

How do I delete my account?

In Settings, under My account, press Delete account. Review what will be deleted and complete identity verification to delete your account. For other requests, choose "Account" under Contact us.

Paper commentary

SpargeAttention: Accurate and Training-free Sparse Attention Accelerating Any Model Inference

SpargeAttn skips most attention computation for any model without training

  • Problem Fixed sparse attention patterns don't generalize across models, because the attention pattern changes from task to task. A pattern that suits one model family can miss important blocks in another.
  • Method SpargeAttn predicts the sparse mask from the input itself, instead of using a preset pattern. It merges each self-similar block into one token, then skips the blocks that score low.
  • Results On Mochi, SpargeAttn finished end-to-end generation in 1037 s, versus 1897 s for full attention. The abstract reports no loss in end-to-end quality metrics.

Why fixed sparse patterns don't carry over

Pattern-based sparse attention struggles to generalize because the attention pattern changes from task to task. The paper's own examples show CogvideoX, Stable-Diffusion3.5 and Llama3.1 each producing a different attention map pattern. Methods such as H2O, InfLLM and DUOAttention rely on a sliding window pattern. SampleAttention, MOA and StreamingLLM combine a sliding window with an attention sink pattern.

DitFastAttn adds similarities between different attention maps on top of its sliding window patterns. The authors note that DitFastAttn is restricted to simple diffusion transformers, so it isn't compatible with language models. A pattern that suits one model family can therefore miss important blocks in another.

Dynamic sparse methods build the mask from each input, so they avoid a fixed pattern. Channel compression methods such as SparQAttn and LokiAttn carry full attention with reduced dimensionality. At dimensions such as 64 or 128, the speedup potential of channel compression might be limited. Token compression methods such as MInference and FlexPrefill pool each block of tokens into a single token.

That approximation is too aggressive, because a block can be missed if it has a low score on the compressed sequence. Training-based methods such as Reformer require retraining the entire model, which is much more expensive than training-free methods. SeerAttention needs training of additional parameters, which is expensive to use.

Accuracy needs precise prediction of the sparse regions, while efficiency needs that prediction to cost very little. SpargeAttn predicts the sparse mask from the input itself, which removes the dependence on a preset pattern.

Compressing only self-similar blocks

Block-level prediction works because neighbouring queries and keys in these models tend to look alike. The authors found this common trait across various models, so the method doesn't need a model-specific pattern. When a block's tokens are highly similar, SpargeAttn merges them into one representative token. The method then uses that token to score the block in the compressed attention map.

Each block's self-similarity is measured as a mean cosine similarity across its tokens.

A block whose similarity falls below the threshold θ has no good representative token. SpargeAttn treats such a block as a fix block and always computes it. Skipping fix blocks would lose critical information, so the authors compress only the self-similar blocks. In the mask, the rows of fix blocks in Q and the columns of fix blocks in K are set to 1.

Figure 4 shows query and key patterns from CogvideoX, Stable-Diffusion3.5, Llama3.1 and Flux. The method's reach therefore depends on how many models show this neighbouring similarity.

Figure 4: Exemplary patterns of the query and key in the attention
of various models

Figure 4 . Exemplary patterns of the query and key in the attention of various models.

Original paper · CC BY 4.0

Building the block mask from block similarities and compressed scores

The mask starts from the compressed attention map, which SpargeAttn builds from one averaged token per block. For each block of Q and K, the method computes a mean cosine similarity across its tokens, so each block gets a self-similarity score. It then averages the tokens of each block into one vector, giving a row q_i for each query block and a row k_j for each key block.

Multiplying these averaged rows gives a small compressed score matrix, and the method then masks it using the block similarities. Key columns whose block similarity falls below θ are set to minus infinity, so non-self-similar blocks can't interfere with the softmax. A row-wise softmax then yields the compressed attention map P̂.

For each row of P̂, the method keeps the top values whose cumulative sum reaches τ times the row sum. The kept positions become 1 in the block mask Mg, and all other positions become 0. The TopCdf selection sorts each row in descending order, takes a cumulative sum, and compares it with τ times the row total. The hyper-parameter τ lies between 0 and 1, so a larger τ keeps more blocks.

After the TopCdf step, the method overrides the mask so that fix blocks are always computed. Every row of a non-self-similar block of Q is set to all 1, and every column of a non-self-similar block of K is set to all 1. Only selective blocks compete under TopCdf, while fix blocks stay in the computation, because omitting them can lose critical information.

Figure 3 lays out the prediction, the masking and the warp-level softmax steps in order.

Figure 3: Workflow ofSpargeAttn

Figure 3 .Workflow ofSpargeAttn.

Original paper · CC BY 4.0 · Jintao Zhang, Chendong Xiang, Haofeng Huang, Jia Wei, Haocheng Xi, Jun Zhu, Jianfei Chen · SpargeAttention: Accurate and Training-free Sparse Attention Accelerating Any Model Inference · Original paper figure · Extracted the figure area from page 4 of the original PDF.

Skipping products inside the FlashAttention loop

The mask is applied inside FlashAttention's tiled loop, where each query block \( Q_i \) is combined with key and value blocks \( K_j \) and \( V_j \). When \( M_g[i,j] = 0 \), the method skips both \( Q_i K_j^\top \) and the product of \( \tilde P_{ij} \) with \( V_j \). A second mask \( M_{pv} \) can skip only the \( \tilde P_{ij} V_j \) product.

Online softmax keeps a running row maximum and rescales the previous output by exp of the old maximum minus the new one. If a block's local row maximum stays far below the running maximum, all of its exp terms are close to zero and its V product adds almost nothing. The check runs per GPU warp: when the largest gap between local and running maxima over the warp's rows, \( \max(m_{local}[I_w] - m_{ij}[I_w]) \), is below \( \lambda \), the warp skips that update.

Because \( \lambda \) is negative, the condition fires only when the gap is strongly negative.

SpargeAttn is integrated into SageAttention, whose per-block quantization and dequantization are orthogonal to skipping. One check at the top of the inner loop skips the whole loop for a block, and a second check before the O update skips the \( \tilde P_{ij} V_j \) product. The prediction is implemented in CUDA with kernel fusion to keep its overhead small.

Setting τ, θ and λ per layer

SpargeAttn has three hyper-parameters, τ in (0,1), θ in (-1,1), and λ below zero. The parameter search runs separately for each attention layer, and the authors aim to maximize sparsity while limiting attention error. Attention error is measured with the Relative L1 distance, defined as L1 = Σ|O−O′| / Σ|O|, which compares the sparse output O′ with the full output O.

The procedure starts by setting two L1 error thresholds, l1 and l2. The authors first grid-search τ and θ for the pair that maximizes sparsity while keeping L1 below l1. They then grid-search λ to find the value that pushes sparsity further while keeping L1 below l2.

The threshold values differ by model, so each model gets its own pair of l1 and l2. For Llama3.1, the authors use l1 = 0.08 and l2 = 0.09. For CogvideoX and Mochi, they use l1 = 0.05 and l2 = 0.06. For Stable-Diffusion3.5 and Flux, they use l1 = 0.07 and l2 = 0.08. For Open-Sora-Plan, they use l1 = 0.03 and l2 = 0.035.

The sparsity a model reaches depends on how much error its layers tolerate, so one shared setting doesn't fit every layer. On CogvideoX, the authors found that sparsity varied across layers and heads. That variation is why the paper sets hyper-parameters for each layer and head. They also found that for diffusion models, sparsity increases with the sample timesteps.

On Llama3.1, sparsity rises from 6.8% at 8K to 54% at 128K under a constant accuracy bound.

Hilbert curve ordering for visual tokens

Attention output doesn't change when tokens are permuted, so the token order is a free choice. The authors observe that adjacent pixels in image and video are likely to be similar. Their key idea is that a token order which keeps neighbours adjacent makes each block more self-similar. More self-similar query and key blocks mean fewer fix blocks, so more selective blocks can enter the TopCdf selection.

The HilbertCurve permutation takes 3D visual tokens of shape T×H×W×d and fills the 3D space with a Hilbert curve. It then flattens the tokens along that curve into a sequence of length L=T×H×W, instead of using row-major order. The authors say the curve preserves locality, traversing the 3D space without crossing rows or columns.

Figure 5: Illustration of different token permutation methods in
1×6×6space, with block size of 4

Figure 5 . Illustration of different token permutation methods in 1×6×6space, with block size of 4.

Original paper · CC BY 4.0

On Mochi, the authors compare three metrics across row-major order, time-major order, Hilbert curve and random order. Hilbert ordering reaches a Sparsity of 0.392, versus 0.363 for row-major order and 0.048 for random order. Its query block self-similarity Sim-q is 0.572, compared with 0.551 for row-major order. Its key block self-similarity Sim-k is 0.479, compared with 0.390 for row-major order.

The relative L1 error rises to 0.0389 from 0.0307 for row-major order. The authors read this as a marginal accuracy difference, since Hilbert ordering wins on block similarity and sparsity.

What the self-similarity judge and each filter contribute

Removing the self-similarity judge lowers the Mochi video metrics in Table 5. VQA-a drops from 54.179 to 34.664 and VQA-t drops from 67.219 to 44.722. FScore falls from 1.807 to 1.138 when the judge is removed. The judge decides which blocks get compressed, so the attention result depends on it. Blocks without self-similarity are always computed as fix blocks instead of being compressed.

The authors explain that omitting computations for fix blocks can lose critical information.

The judge works in the prediction step, where blocks below the threshold θ are excluded from compression. The paper says the judge guarantees end-to-end accuracy, and Appendix A.2 gives more analysis. Without the judge, Mochi's video quality drops, so the judge is what keeps those metrics up.

On Llama3.1 at 128K, the two filters are measured separately and together in Table 6. The block-mask filter alone reaches 51.2% sparsity. The warp-level softmax filter alone reaches 27.7% sparsity. Using both filters together gives 54% sparsity, so the warp-level softmax adds to the block-mask filter. Most of the skipping comes from the block-mask filter.

The sparsity from both filters grows with sequence length, which the authors measure on Llama3.1. Table 7 reports sparsity of 6.8% at 8K and 54% at 128K. The authors suggest that longer contexts give SpargeAttn a higher speedup.

Quality across language, video and image models

SpargeAttn keeps end-to-end quality on Llama3.1 at 128K, with a sparsity of 0.54. Its WikiText perplexity is 6.020, against 6.013 for full attention. MInference at sparsity 0.5 reaches a perplexity of 10.631 and an InfiniteBench score of 0.5152. So at a similar sparsity the baseline loses far more quality than SpargeAttn does here. SpargeAttn reaches an InfiniteBench score of 0.6638, compared to 0.6594 for full attention.

On Mochi at sparsity 0.47, SpargeAttn scores FScore 1.807, compared to 1.681 for full attention. Its VQA-a is 54.179, below the 56.472 of full attention, so the aesthetic score is lower. FlexPrefill gives no valid FScore on Mochi at sparsity 0.48 or 0.4. The authors mark these entries as not generated with a cross in the table.

On Flux at sparsity 0.38, SpargeAttn reaches FID 163.982 and IR 0.9207, compared to 166.103 and 0.8701 for full attention. On Stable-Diffusion3.5 at sparsity 0.31, FID is 166.193, slightly above 166.101 for full attention. Its IR is 0.9727, against 0.9699 for full attention. Quality holds in these settings, with FID essentially tied on Stable-Diffusion3.5.

They compare it with MInference and FlexPrefill at several sparsity levels.

Does the sparsity turn into wall-clock time on Mochi and Llama3.1

Mochi on an L40 GPU shows the clearest end-to-end gain, so this section checks whether the sparsity becomes real generation time. Full attention took 1897 s for end-to-end generation on Mochi on an L40 GPU. SageAttn cut that time to 1544 s, because it runs attention with 8-bit quantization. SpargeAttn finished the same generation in 1037 s, a 1.83x speedup over full attention.

Against SageAttn alone, the time falls from 1544 s to 1037 s, so the sparse mask adds speed on top of the quantized kernel.

The Mochi run is the only one in Table 2 measured on the same GPU for all three settings. Table 2 also reports CogvideoX on RTX4090, where generation dropped from 87 s to 53 s with SpargeAttn. On Llama3.1 at 128K on an L40, SpargeAttn cut the time from 52 s to 29.98 s. The authors used different GPUs for each model, so these rows are not directly comparable.

The speed metric in Table 1 is the inverse latency for attention alone, not end-to-end time. On Llama3.1 at 128K, SpargeAttn reaches an inverse latency of 708.1 at sparsity 0.54. Full attention reaches 156.9 on the same setting. SpargeAttn keeps the WikiText perplexity at 6.020, against 6.013 for full attention.

The sparse block prediction adds its own cost, so the authors measured it separately in Table 3.

Prediction overhead and sparsity by sequence length

The sparse block prediction runs on every attention call, so its cost has to stay small to be worth paying. Table 3 measures that cost against full attention at five sequence lengths, from 8k to 128k. At 8k, the prediction takes 0.251 ms against 6.649 ms of full attention, an overhead of 3.78%. At 128k, the prediction takes 8.764 ms against 1696.2 ms of full attention, an overhead of 0.516%.

The overhead falls as the sequence grows, because full attention cost rises faster than the prediction cost.

The authors measure sparsity on Llama3.1 under a constant accuracy bound, across sequence lengths from 8K to 128K. Sparsity is 6.8% at 8K, 26.4% at 16K, 35.7% at 24K, 49.8% at 48K, and 54% at 128K. The authors read this as longer contexts leaving more to skip, so the speedup of SpargeAttn grows with length. They didn't test lengths beyond 128K in this table.

Limitations of the tested models, thresholds and comparisons

The evaluation covers only six models, Llama3.1, CogvideoX, Mochi, Open-Sora-Plan, Flux and Stable-Diffusion3.5. Its universality claim therefore rests on these models and doesn't extend to others. Thresholds are set per model and per layer by a grid search over L1 error limits. A new model needs its own search, using l1 and l2 values chosen for that model.

The paper gives l1 and l2 for each of the six models, so those values are the only ones it validates.

Open-Sora-Plan appears in Table 1 at a single sparsity, 0.34, with no baseline row. So the comparison against MInference and FlexPrefill on that model isn't shown.

The baselines run at the sparsity levels the authors picked, 30% and 70% for MInference. FlexPrefill uses γ of 0.95 and 0.99, taken from its paper. The Mochi VQA-a of SpargeAttn is 54.179, below 56.472 for full attention. Latency rows use different GPUs, RTX4090 and L40, so cross-model timings aren't comparable. The authors note an updated SageAttention2 implementation gives a further 30% speedup, which the reported numbers don't include.

Paper info

Authors
Jintao Zhang, Chendong Xiang, Haofeng Huang, Jia Wei, Haocheng Xi, Jun Zhu, Jianfei Chen
Venue
arXiv · Preprint
First published
2025-2-25
Added
2026-10-29
Updated
2025-11-19
Version
v8
arXiv
2502.18137
Category
cs.LG · cs.AI · cs.CV · cs.PF
Original paper terms
CC BY 4.0
What we show
Paper info, commentary and permitted figures from the original paper

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

Abstract

An efficient attention implementation is essential for large models due to its quadratic time complexity. Fortunately, attention commonly exhibits sparsity, i.e., many values in the attention map are near zero, allowing for the omission of corresponding computations. Many studies have utilized the sparse pattern to accelerate attention. However, most existing works focus on optimizing attention within specific models by exploiting certain sparse patterns of the attention map. A universal sparse attention that guarantees both the speedup and end-to-end performance of diverse models remains elusive. In this paper, we propose SpargeAttn, a universal sparse and quantized attention for any model. Our method uses a two-stage online filter: in the first stage, we rapidly and accurately predict the attention map, enabling the skip of some matrix multiplications in attention. In the second stage, we design an online softmax-aware filter that incurs no extra overhead and further skips some matrix multiplications. Experiments show that our method significantly accelerates diverse models, including language, image, and video generation, without sacrificing end-to-end metrics. The code is available at https://github.com/thu-ml/SpargeAttn.

Quote from the paper

Jintao Zhang, Chendong Xiang, Haofeng Huang, Jia Wei, Haocheng Xi, Jun Zhu, Jianfei Chen (2025). SpargeAttention: Accurate and Training-free Sparse Attention Accelerating Any Model Inference. arXiv:2502.18137v8. https://arxiv.org/abs/2502.18137v8

BibTeX
@misc{zhang2025spargeattention,
  title = {{SpargeAttention: Accurate and Training-free Sparse Attention Accelerating Any Model Inference}},
  author = {Jintao Zhang and Chendong Xiang and Haofeng Huang and Jia Wei and Haocheng Xi and Jun Zhu and Jianfei Chen},
  year = {2025},
  eprint = {2502.18137},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2502.18137v8}
}

See related papersBrowse other papers

Paper preview
Account security

Connect Google account

If you connect a Google account, you can sign in with it too.

Refivu

Delete account

Refivu
Refivu

Sign up