DiTFastAttn: Attention Compression for Diffusion Transformer Models

Zhihang Yuan, Pu Lu, Hanling Zhang, Xuefei Ning, Linfeng Zhang, Tianchen Zhao, Shengen Yan, Guohao Dai, Yu Wang · DOI

Introduction

Diffusion Transformers (DiTs) have emerged as the state-of-the-art backbone for high-fidelity generative modeling, powering leading systems such as Sora and PixArt-Sigma. Despite their superior scalability compared to traditional U-Net architectures, DiTs face a significant computational bottleneck: the self-attention mechanism. The computational complexity of self-attention scales quadratically ($O(L^2)$) with the number of input tokens. As the industry moves toward 2K resolution images and long-form video generation, the token count explodes, making real-time inference increasingly difficult.

While architectural modifications like Local Attention or Group Query Attention (GQA) can mitigate these costs, they typically require retraining the model from scratch—an expensive and often impractical requirement. DiTFastAttn introduces a post-training compression framework that accelerates inference by exploiting spatial, temporal, and conditional redundancies inherent in the diffusion process, achieving up to a 1.8× end-to-end speedup without additional training.

Methodology

DiTFastAttn identifies and targets three specific types of redundancy within the DiT denoising loop through three novel techniques:

1. Window Attention with Residual Sharing (WA-RS)

Most attention heads in DiTs focus primarily on local spatial information. While "window attention" (restricting attention to a local neighborhood) reduces computation, it often results in a loss of global context and degraded image quality. DiTFastAttn addresses this by caching the residual—the difference between full global attention and local window attention—during a full-attention step. This residual is then reused for several subsequent window-attention steps, allowing the model to maintain global coherence while processing local details more efficiently.

2. Attention Sharing across Timesteps (AST)

Diffusion is an iterative process where the model gradually refines noise into an image. The researchers observed that the outputs of specific attention heads change minimally between neighboring denoising steps. AST exploits this temporal stability by reusing the attention output from a previous step, skipping the computation entirely for defined intervals.

3. Attention Sharing across CFG (ASC)

Classifier-Free Guidance (CFG) is essential for prompt adherence but effectively doubles the computational load by requiring both a conditional and an unconditional pass. The authors discovered that the attention maps for these two passes are remarkably similar, often reaching an SSIM of 0.95 or higher. ASC reuses the conditional attention output for the unconditional pass, significantly reducing the overhead of CFG.

Optimization: Greedy Search Algorithm

To maximize efficiency without sacrificing quality, DiTFastAttn employs a greedy search algorithm. This algorithm determines the optimal compression configuration (which technique to apply to which layer at which timestep), ensuring that the most sensitive parts of the denoising process remain intact while aggressive compression is applied to redundant sections.

Experimental Evaluation

The framework was evaluated across multiple models and benchmarks:

  • DiT-XL: Tested on ImageNet for class-conditional image generation.
  • PixArt-Sigma: Evaluated on MS-COCO 2014 for high-resolution (up to 2K) text-to-image generation.
  • OpenSora: Utilized to assess video generation performance and temporal consistency.

Performance was measured using standard generative metrics, including Inception Score (IS), Fréchet Inception Distance (FID), and CLIP score.

Key Results and Insights

  • Efficiency Gains: For 2048 × 2048 image generation, DiTFastAttn achieved a 1.8× end-to-end speedup. In high-resolution settings, attention-related FLOPs were reduced by up to 76%.
  • Quality Preservation: The compressed models maintained visual fidelity. In the "D1-D3" configurations, FID and IS scores were nearly indistinguishable from the original uncompressed models.
  • Dynamic Redundancy: The study revealed that redundancy is not uniform across the denoising process. Early steps (focused on global structure) and later steps (focused on fine details) exhibit different sensitivities, justifying the use of a per-layer, per-step compression plan.
  • Video Performance: On OpenSora, the method reduced total computation by approximately 40% while preserving temporal consistency and visual quality.

Limitations and Future Work

Despite its success, DiTFastAttn involves certain trade-offs. The AST technique requires caching hidden states from previous timesteps, which increases VRAM usage. Additionally, as a post-training method, it is limited to exploiting existing redundancies rather than learning more efficient representations. Future research may explore integrating these techniques into the training phase or extending similar redundancy-skipping logic to the Feed-Forward Networks (FFN) within transformer blocks to further reduce the computational footprint of generative models.

Summary updated

BibTeX
@inproceedings{yuan2024ditfastattn,
  author = {Zhihang Yuan and Pu Lu and Hanling Zhang and Xuefei Ning and Linfeng Zhang and Tianchen Zhao and Shengen Yan and Guohao Dai and Yu Wang},
  title = {{DiTFastAttn: Attention Compression for Diffusion Transformer Models}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=51HQpkQy3t},
}
Figure