TL;DR
Generating high-resolution videos with Diffusion Transformers (DiTs) is painfully slow, largely because their attention layers waste massive amounts of compute on near-zero scores. FG-Attn introduces a GPU-friendly, fine-grained sparse attention kernel that skips redundant calculations at block sizes as small as $16 \times 16$—without needing to retrain the model. On an NVIDIA H100, it outperforms FlashInfer by 2.45× in microbenchmarks and speeds up end-to-end video generation by up to 1.40× over Flash Attention 3.
What Problem Does This Paper Address?
Video Diffusion Transformers work by encoding noisy video frames into a latent space, flattening them into a giant sequence of embeddings, and iteratively denoising them.
Because video has both spatial and temporal dimensions, these sequences get huge fast. A 5-second, 720p video in Wan 2.1 1.3B translates to roughly 75,000 embedding vectors, taking 5 minutes to generate on an H100 GPU (and over 15 minutes for the 14B model). Attention layers dominate this runtime—accounting for up to 91% of generation time for 81-frame videos.
Fortunately, most of those attention scores are close to zero. Skipping them should make things much faster. The catch? Existing block-sparse attention kernels operate at coarse granularities (typically $128 \times 128$ blocks) to keep GPU tensor cores happy. If you shrink the block size to $16 \times 16$, you expose way more sparsity (around 70% vs. just 23% at $64 \times 64$), but naive GPU implementations fall apart due to hardware underutilization, irregular memory accesses, and scheduling overhead.
Methods
FG-Attn tackles both the systems challenge of running fine-grained sparse attention on GPUs and the algorithmic challenge of predicting which blocks to skip:
- Asynchronous Gather-Load: Instead of loading contiguous blocks of keys and values, FG-Attn introduces a parallelized
gather-loadprimitive. Producer warp groups fetch sparse key/value indices, translate them to memory addresses in parallel, and asynchronously pack them into $N=128$ tiles in shared memory—overlapping this memory traffic with the consumer warp groups' math. - Similarity-Based Query Merging (
merge-XOR): To keep tensor cores fed when query tiles are small ($M \le 128$), FG-Attn groups smaller query tiles into 128-query blocks. Rather than grouping consecutive tiles, it groups tiles that attend to similar key/value sets (measured via bitwise XOR distance on their sparse masks), minimizing redundant memory loads. - Persistent Work Scheduler: Because different query groups attend to different numbers of keys, some GPU Streaming Multiprocessors (SMs) finish early and sit idle. FG-Attn uses a GPU-side, work-stealing scheduler with a longest-processing-time-first (LPT) policy, eliminating CPU-side scheduling overhead.
- Training-Free Masking: To decide what to skip without computing the full attention matrix, FG-Attn averages the queries and keys within each tile, computes an approximate attention distribution, and keeps only the blocks selected by top-$p$ masking (after a few dense warmup steps).
Datasets
- Video Generation Evaluation: 20 prompts sampled from the Penguin dataset (Kong et al., 2024), evaluated across three open-source video models: HunyuanVideo, Wan 2.1 14B, and LTX-2 at multiple resolutions.
- Microbenchmarks: Randomly generated sparse masks with controlled sparsity levels (50%–90%) and workload skews.
Key Insights and Ideas
- Fine-grained sparsity is hiding in plain sight: Video DiT attention maps are highly irregular. Coarse $64 \times 64$ blocks leave most of the sparsity on the table, whereas $16 \times 16$ blocks unlock ~70% sparsity.
- You don't need expensive token clustering: Prior methods reorder tokens online to force coarse block-sparsity. FG-Attn's
merge-XORgroups query tiles after mask generation, reusing the groupings across denoising steps to amortize the cost. - CPU scheduling is a silent killer: At fine granularities, building work schedules on the CPU (as FlashInfer does) or expanding block masks into massive token-level index lists can bottleneck runtime—or even cause out-of-memory (OOM) crashes on 720p videos. Keeping scheduling on the GPU avoids this completely.
Key Results
- Microbenchmarks (NVIDIA H100): At 70% sparsity, FG-Attn is 2.45× faster than FlashInfer on average and reduces attention kernel latency by 14.7%. Its persistent scheduler boosts throughput by up to 11% under heavy workload skew.
- End-to-End Video Generation: Compared to dense Flash Attention 3, FG-Attn achieves up to 1.40× end-to-end speedup, averaging 1.07×, 1.14×, and 1.17× at block sizes of 16, 32, and 64, respectively.
- Video Quality: Across all block sizes, FG-Attn maintains an average PSNR of 24.04 dB relative to dense attention, rising to 24.71 dB at a block size of 16.
Limitations and Future Work
- Planning & Merging Overhead: At smaller query block sizes ($M=32$ or $64$), the planning time for
merge-XORbecomes noticeable in random-mask microbenchmarks (accounting for up to 54.2% and 29.1% of kernel time, respectively), though it remains much faster than FlashInfer. - Sparsity Dilution: Merging smaller query tiles into 128-query groups inevitably reduces effective sparsity (e.g., from 0.68 before merging down to 0.53 with
merge-XORat $16 \times 16$). - Dense Warmup: Like prior sparse video methods, FG-Attn still requires running dense attention for the first few denoising iterations before switching to sparse execution.
Summary updated