HKUSTDial/flash-sparse-attention

Trainable fast and memory-efficient sparse attention

What it solves

Flash-Sparse-Attention (FSA) addresses the computational and memory bottlenecks associated with processing extremely long sequences in Transformer models. It combines the memory efficiency of Flash Attention with sparse computation to reduce the overhead of the attention mechanism.

How it works

FSA implements high-performance trainable sparse attention kernels. It utilizes a CuTe backend for optimal performance and provides support for various attention patterns including causal, local window, and gated attention. To optimize workload balancing and precision, it employs techniques like Split-KV (for forward/decode) and Split-QO (for backward passes), as well as fused quantization for low-precision computation on hardware lacking native FP8 support.

Who it’s for

Researchers and developers building large-scale Transformer models that require efficient handling of long-context windows and high-performance training and inference (decode) workloads.

Highlights

  • Versatile Attention Support: Supports dense, sparse, and gated attention, as well as Grouped Query Attention (GQA) and Multi Query Attention (MQA).
  • Memory & Compute Efficiency: Integrates Flash Attention's memory efficiency with sparse computation and Paged Attention.
  • Flexible Configuration: Offers per-head arbitrary window sizes and local ranges via Flex Local Window Attention.
  • Hardware Optimization: Includes fused quantization and workload balancing (Split-KV/Split-QO) to maximize GPU/XPU/NPU/PPU performance.

Related

  • Project
  • Project
  • Project
  • Project
  • Dispatch