DiM: Diffusion Mamba for Efficient High-Resolution Image Synthesis

Yao Teng, Yue Wu, Han Shi, Xuefei Ning, Guohao Dai, Yu Wang, Zhenguo Li, Xihui LiuarXiv 2024 · DOI

Introduction

State-of-the-art diffusion models have increasingly adopted Vision Transformers (ViTs) as their primary backbone due to their superior scalability compared to traditional U-Nets. However, Transformers face a significant computational bottleneck: the self-attention mechanism scales quadratically ($O(N^2)$) with the number of tokens. As the demand for high-resolution image synthesis (e.g., 1024×1024 and beyond) grows, the resulting explosion in token counts makes Transformers prohibitively expensive for both training and inference.

To address this, we introduce Diffusion Mamba (DiM), a model that replaces the attention-heavy backbone with a linear-complexity State Space Model (SSM) based on the Mamba architecture. While Mamba offers $O(N)$ scaling, it is inherently 1D and causal. DiM overcomes these limitations through spatial-aware architectural modifications, enabling efficient, high-quality 2D image synthesis.

Methodology

The core of DiM is the adaptation of the Mamba block for 2D diffusion tasks. The architecture incorporates several key innovations to handle spatial data and maintain efficiency:

  1. Multi-Directional Scans: To mitigate Mamba’s 1D causal bias, DiM blocks alternate between four distinct scanning directions: row-major, reverse row-major, column-major, and reverse column-major. This ensures that every image patch can eventually establish a global receptive field across the entire 2D grid.
  2. Learnable Padding Tokens: Standard raster scanning can create artificial discontinuities where the end of one row is adjacent to the start of the next in a 1D sequence. DiM introduces learnable padding tokens at the end of each row and column. These tokens act as structural signals, helping the model recognize boundaries and maintain spatial continuity.
  3. Local Feature Enhancement: To preserve fine-grained details often lost during the initial "patchification" process, DiM utilizes 3×3 depth-wise convolution layers at the network's entry and exit points.
The DiM architecture, illustrating the multi-directional scan patterns and the insertion of learnable padding tokens to preserve 2D spatial structure.

Furthermore, the model employs a "weak-to-strong" training strategy, pretraining on 256×256 images before fine-tuning at 512×512. For ultra-high resolutions, a training-free "upsample-guidance" strategy is used during the early stages of the reverse diffusion process, allowing the model to generate 1536×1536 images without additional training.

Results and Discussion

DiM was evaluated on standard benchmarks including CIFAR-10, ImageNet, and FFHQ. On ImageNet 256×256, DiM-Huge achieved an FID of 2.21, matching or exceeding the performance of established Transformer-based models like DiT and U-ViT while maintaining a more efficient footprint for long sequences.

The Efficiency Crossover

A critical finding of this work is the "efficiency crossover" point. Due to the overhead of multiple scanning directions and the high optimization of current attention kernels (like FlashAttention), DiM is slightly slower than Transformers at low resolutions. However, as resolution increases, the linear scaling of Mamba becomes dominant.

Comparison of inference speed (FPS) across resolutions. DiM demonstrates superior scaling, becoming significantly faster than the Transformer-based U-ViT at resolutions above 1280×1280.

At a resolution of 2048×2048, DiM is approximately 2.2x faster than U-ViT. Moreover, DiM successfully handled FFHQ 1024×1024 experiments involving over 16,000 tokens—a regime where standard Transformers frequently encounter out-of-memory (OOM) errors.

Conclusion and Future Work

Diffusion Mamba demonstrates that State Space Models are a viable and efficient alternative to Transformers for high-resolution image synthesis. By solving the 1D-to-2D mapping problem with multi-directional scans and padding tokens, DiM achieves competitive quality with superior scaling properties.

While the model occasionally exhibits anatomical instability or repetitive patterns at extreme upsampling ratios, future work integrating DiM with latent space techniques (similar to Stable Diffusion) holds great promise for unlocking ultra-high-resolution generative modeling.

Summary updated

BibTeX
@misc{teng2024dim,
  author = {Yao Teng and Yue Wu and Han Shi and Xuefei Ning and Guohao Dai and Yu Wang and Zhenguo Li and Xihui Liu},
  title = {{DiM: Diffusion Mamba for Efficient High-Resolution Image Synthesis}},
  year = {2024},
  eprint = {2405.14224},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2405.14224},
}
Figure