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

Jintao Zhang, Chendong Xiang, Haofeng Huang, Jia Wei, Haocheng Xi, Jun Zhu, Jianfei Chen

arXiv:2502.18137 · 2026-07-27 공개 · arXiv · PDF

video-generation language-models image-generation training-free sparse-attention model-inference online-filtering quantized-attention

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.

한국어 요약

한 줄 요약

SpargeAttn은 훈련 없이도 다양한 모델의 추론 속도를 2.5~5배 가속화하는 투버스 스파스 어텐션 기법이다.

핵심 기여도

핵심 아이디어

기존 스파스 어텐션은 특정 태스크나 모델에 최적화되어 일반화가 어려웠다. SpargeAttn은 **모든 모델에 적용 가능한 훈련 없는 스파스 어텐션**을 목표로, **두 단계의 온라인 필터**를 도입한다. 첫 번째 단계는 **Q, K 블록의 유사도 기반 압축**을 통해 어텐션 매트릭스의 스파스 마스크를 예측하고, 두 번째 단계는 **GPU warp 수준의 온라인 softmax 알고리즘**을 사용해 추가 연산을 생략한다. 특히, **Hilbert Curve 순열**을 통해 블록 내 유사도를 높여 스파스성을 극대화한다. 이는 **정확도 손실 없이 추론 속도 향상**을 가능하게 한다.

기술적 접근법

주요 결과

의의 및 한계

SpargeAttn은 **모델 종류와 시퀀스 길이에 관계없이 적용 가능한 훈련 없는 스파스 어텐션**으로, 대규모 모델의 추론 효율성을 극대화한다. 특히, **SageAttention2 기반 구현**은 기존 성능을 30% 더 개선하며, **GPU warp 수준 최적화**를 통해 실용성도 높인다. 그러나, **모든 어텐션 패턴에 대한 보장은 없으며**, 특정 어텐션 구조가 스파스성을 낮출 수 있는 한계가 있다. 또한, **동적 마스크 예측의 오버헤드**는 긴 시퀀스일수록 줄어들지만, 짧은 시퀀스에서는 상대적으로 높을 수 있다.

실용적 활용

SpargeAttn은 **대규모 언어 모델, 이미지 생성, 비디오 생성** 등 다양한 생성 모델에서 **추론 속도 향상**에 활용 가능하다. 특히, **128K 이상의 긴 시퀀스 처리**가 필요한 어플리케이션에서 **성능 유지와 속도 향상**을 동시에 달성할 수 있다. 산업적으로는 **실시간 번역, 콘텐츠 생성, 대화형 AI** 등에 적용 가능하다.