MonoFormer: One Transformer for Both Diffusion and Autoregression

Chuyang Zhao, Yuxing Song, Wenhao Wang, Haocheng Feng, Errui Ding, Yifan Sun, Xinyan Xiao, Jingdong WangarXiv 2024 · DOI

Abstract

MonoFormer is a unified transformer architecture that performs both discrete autoregressive text generation and continuous diffusion-based image generation using a single set of shared weights. By simply toggling between causal and bidirectional attention masks, the model achieves state-of-the-art image synthesis quality while successfully preserving its foundational language modeling capabilities.

Introduction

In the current generative AI landscape, a "divided house" exists between Large Language Models (LLMs) and high-fidelity image generators. LLMs typically utilize Autoregression (AR) to predict discrete tokens, whereas image generation is dominated by Diffusion Models that denoise continuous data. Existing attempts to unify these modalities often rely on separate backbones or force images into discrete "visual tokens," which can degrade image quality. MonoFormer addresses this by using the exact same Transformer weights for both tasks, bridging the gap between discrete text sequences and continuous visual distributions.

Methods

The core innovation of MonoFormer is the realization that a Transformer can act as a general-purpose sequence processor where the information flow is controlled by the attention mask.

The MonoFormer architecture toggles between causal masks for autoregressive text generation and bidirectional masks for diffusion-based image generation.

Architecture and Training

MonoFormer utilizes a pre-trained TinyLlama-1.1B backbone. For visual data, a Variational Autoencoder (VAE) compresses images into a latent space, which are then "patchified" and projected into the transformer's embedding dimension.

  • Autoregression (Text): The model employs a causal attention mask, where each token attends only to preceding tokens.
  • Diffusion (Images): The model switches to a bidirectional attention mask. Since diffusion requires predicting noise across the entire image simultaneously, every visual patch attends to every other patch.

The model is jointly trained on a dual objective: cross-entropy loss for language modeling and Mean Squared Error (MSE) for diffusion denoising, with all Transformer blocks shared across tasks.

Results

MonoFormer demonstrates that a single model can excel in both modalities without significant interference.

Qualitative examples of MonoFormer performing text-to-image generation and conversational text tasks.

Image Synthesis Performance

On the ImageNet 256×256 benchmark, MonoFormer achieved a Fréchet Inception Distance (FID) of 2.57. This performance surpasses the AR-based LlamaGen-3B (2.81) and approaches the specialized DiT-XL/2 (2.27), despite MonoFormer's multi-purpose nature.

Language Capability Preservation

The model maintained a competitive average score of 51.12 across commonsense reasoning benchmarks (e.g., HellaSwag, PIQA), representing only a minor decrease from the original TinyLlama baseline of 52.97. This indicates that joint training for diffusion does not severely compromise the model's linguistic foundations.

Discussion and Conclusion

MonoFormer highlights that the primary differentiator between AR and Diffusion in Transformers is the attention mechanism's information flow rather than the data type. Furthermore, LLM initialization was found to significantly boost image generation quality, likely due to pre-existing spatial and semantic understandings.

Future work includes mitigating the slight performance "tax" on text tasks through larger-scale joint training and extending the architecture to interleaved multimodal understanding. Scaling MonoFormer beyond the 1.1B parameter level remains a promising direction for achieving a truly unified generative foundation.

Summary updated

BibTeX
@misc{zhao2024monoformer,
  author = {Chuyang Zhao and Yuxing Song and Wenhao Wang and Haocheng Feng and Errui Ding and Yifan Sun and Xinyan Xiao and Jingdong Wang},
  title = {{MonoFormer: One Transformer for Both Diffusion and Autoregression}},
  year = {2024},
  eprint = {2409.16280},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2409.16280},
}
Figure