Dimba: Transformer-Mamba Diffusion Models

Zhengcong Fei, Mingyuan Fan, Changqian Yu, Debang Li, Youqiang Zhang, Junshi Huang

TL;DR

Dimba is a novel text-to-image diffusion model that introduces a hybrid architecture, interleaving Transformer and Mamba (State Space Model) layers. By combining the global modeling strengths of attention with the linear-scaling efficiency of Mamba, Dimba achieves state-of-the-art image quality and semantic control with significantly lower memory overhead and higher throughput than pure Transformer-based models.

What Problem Does This Paper Address?

Current text-to-image (T2I) diffusion models primarily rely on either U-Net (CNN-based) or Transformer architectures. While Transformers are exceptionally powerful at capturing global dependencies, they suffer from quadratic computational complexity ($O(N^2)$) relative to sequence length. As we push toward higher-resolution images and longer text prompts, the memory footprint of the "KV cache" and the sheer number of FLOPs become prohibitive.

On the other hand, State Space Models (SSMs) like Mamba offer near-linear scaling ($O(N)$), making them highly efficient for long sequences. However, using SSMs alone can sometimes struggle with the complex, multi-modal alignment required for precise text-to-image synthesis. Dimba seeks to bridge this gap, creating a "best of both worlds" backbone for diffusion.

Methods

The core innovation of Dimba is the Dimba Block, a hybrid unit that alternates between different layer types to balance efficiency and expressive power.

  • Hybrid Architecture: Each block sequentially stacks a Self-Attention layer, a Cross-Attention layer (for text conditioning), and a Bi-Mamba layer, followed by a standard FeedForward network.
  • Conditioning: Text features are extracted using a T5-XXL encoder and integrated via cross-attention. Time-step information is injected using Adaptive Layer Normalization (AdaLN), a standard technique in models like DiT (Diffusion Transformer).
  • Staged Training: The authors employ a progressive strategy:
  • Large-scale Pre-training: Training on a broad, noisy dataset.
  • Resolution Adaptation: Using Position Embedding (PE) interpolation to transition the model from low-resolution to high-resolution processing without starting from scratch.
  • Quality Tuning: A final fine-tuning stage on a small, highly curated set of aesthetic images.
Figure 2: Model architecture of Dimba. Mamba and Transformer layers are interleaved in a stacked manner. The text feature is incorporated with a cross-attention layer. Time information is projected with shared MLP before inserting to different AdaLN layers.

Datasets

The authors emphasize that data quality is as important as architecture.

  • Internal Dataset: A massive collection of 43 million image-text pairs.
  • Quality Tuning Set: A highly refined subset of 600,000 images filtered for high aesthetic scores (using LAION-Aesthetics-Predictor V2) and high resolution (>1024px).
  • Dense Captioning: To improve semantic alignment, they used ShareCaptioner to relabel their data. This transformed short, noisy web alt-text into dense, descriptive captions, increasing the average word count from ~30 to 185 words.
Figure 3: Training data illustration and histogram visualization of the caption length. (a) Auto- labeling caption provides accurate textual descriptions for images, and we outline the valid nouns and verbs in red color; (b) We randomly select 1M captions from the raw captions and re-labeled captions to draw the corresponding histogram.

Key Insights and Ideas

  • The KV Cache Solution: By replacing a portion of the attention layers with Mamba layers, Dimba drastically reduces the size of the memory cache required during inference. This allows for higher throughput and the generation of higher-resolution images on consumer-grade hardware.
  • Implicit Positioning: The authors found that Mamba layers, which process sequences recurrently, provide implicit positional information. This synergy makes the model more robust when interpolating position embeddings for high-resolution fine-tuning.
  • Efficiency over Brute Force: Dimba-G (1.8B parameters) achieved a competitive FID score of 8.15 on COCO using only ~2,000 A100 GPU days. For context, models like SDv1.5 required over 6,000 GPU days to reach similar performance, demonstrating that the hybrid architecture is significantly more sample-efficient.
  • Aesthetic Refinement: The "Quality Tuning" stage proved vital. Even a short fine-tuning burst on high-quality data significantly improved the "artistic" feel and detail of the generated images compared to the base pre-trained model.
Qualitative comparison showing the impact of quality tuning on image detail and aesthetics.

Key Results

  • Performance: Dimba-G outperforms many larger models in zero-shot FID scores on the COCO dataset.
  • Semantic Control: On the T2I-CompBench (a benchmark for attribute binding and spatial relations), Dimba-G showed exceptional performance, particularly in "Color" and "Texture" binding, outperforming SDXL and PixArt-alpha.
  • Throughput: Due to the linear scaling of the Mamba layers, Dimba offers a reduced memory footprint and higher image-per-second throughput compared to pure Transformer benchmarks of equivalent parameter counts.
Figure 1: Images generated from Dimba. The Dimba model can output high aesthetic, objective natural and consistent, and follow user textual instructions.

Limitations and Future Work

Despite its efficiency, Dimba shares some common "DNA" with other diffusion models and faces similar hurdles:

  • Text and Anatomy: The model still occasionally struggles with rendering legible text within images and complex human anatomy (like hands).
  • Prompt Alignment: While dense captions help, extremely complex or contradictory user prompts can still lead to semantic misalignment.
  • Safety and Bias: The authors acknowledge that the model may inherit biases present in the large-scale web-crawled training data, necessitating future work on safety filters and debiasing techniques.

The team plans to release code and checkpoints to encourage further research into hybrid Attention-Mamba backbones for generative AI.

Summary updated

BibTeX
@misc{fei2024dimba,
  author = {Zhengcong Fei and Mingyuan Fan and Changqian Yu and Debang Li and Youqiang Zhang and Junshi Huang},
  title = {{Dimba: Transformer-Mamba Diffusion Models}},
  year = {2024},
  eprint = {2406.01159},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2406.01159},
}
Figure