ViTGAN: Training GANs with Vision Transformers

Kwonjoon Lee, Huiwen Chang, Lu Jiang, Han Zhang, Zhuowen Tu, Ce Liu

Introduction

ViTGAN introduces the first framework to successfully train Generative Adversarial Networks (GANs) using pure Vision Transformers (ViTs) for both the generator and the discriminator. By introducing specialized regularization techniques and architectural modifications, the authors match the performance of state-of-the-art CNN-based models like StyleGAN2. This breakthrough proves that convolutions and their inherent inductive biases are not a strict requirement for high-quality image synthesis.

The Challenge: Bringing Transformers to GANs

For years, Convolutional Neural Networks (CNNs) have been the undisputed kings of computer vision. Their success is largely due to "inductive biases"—built-in assumptions like translation equivariance, which dictate that an object remains the same regardless of its position in the frame. Recently, Vision Transformers (ViTs) have challenged this dominance in image classification by treating images as sequences of patches and using self-attention to model global dependencies.

However, adapting ViTs for GANs has been notoriously difficult. GAN training is a delicate balancing act between a generator creating fake images and a discriminator trying to spot them. When CNNs are swapped for ViTs, this balance often collapses. Standard ViTs lead to extreme training instability and "spiky" gradients. Furthermore, conventional tricks used to stabilize CNN-based GANs, such as spectral normalization or gradient penalties, do not translate well to the self-attention mechanisms of Transformers.

Methods: Stabilizing the Architecture

To overcome these hurdles, the authors propose several key innovations designed to stabilize training and improve the quality of generated images.

Overall ViTGAN Architecture

Discriminator Enhancements (Stability)

  • L2 Attention: Standard self-attention uses dot-product similarity, which can have an unbounded Lipschitz constant—meaning small input changes can cause massive output swings. The authors replace this with Euclidean distance ($L2$) to ensure the discriminator remains mathematically "well-behaved" (Lipschitz continuous).
  • Improved Spectral Normalization (ISN): Standard spectral normalization often leads to underfitting in Transformers. Instead, the authors scale the weight matrices by their spectral norm at initialization. This provides necessary stability without crippling the model's expressive power.
  • Overlapping Patches: To prevent the discriminator from simply memorizing the edges of the grid patches, the model allows patches to overlap slightly. This provides a better sense of local context and continuity.

Generator Enhancements (Quality)

  • Self-Modulated LayerNorm (SLN): Similar to how StyleGAN uses "styles" to shift and scale features, ViTGAN uses the latent noise vector to modulate the LayerNorm layers. This allows the global latent code to influence every patch in the generated image.
  • Implicit Neural Representation (INR): Instead of using a simple linear layer to turn patch embeddings into pixels, ViTGAN uses an INR. This involves a small Multi-Layer Perceptron (MLP) that uses Fourier features to map embeddings to continuous pixel values, resulting in smoother, more natural-looking image patches.

Key Insights and Results

The model was evaluated on three standard image synthesis benchmarks: CIFAR-10 (32x32), CelebA (64x64), and LSUN Bedroom (scaled up to 256x256).

  • Lipschitzness is the Secret Sauce: The most critical finding is that the instability of ViT-based GANs stems from the lack of Lipschitz continuity in dot-product attention. Switching to $L2$ distance proved to be the crucial adjustment that made stable training possible.
  • Performance Parity: ViTGAN achieves a Fréchet Inception Distance (FID) of 4.92 on CIFAR-10, outperforming the authors' replication of StyleGAN2 (5.60). Lower FID scores indicate higher quality and more realistic images.
  • Scalability: On the LSUN Bedroom dataset, ViTGAN successfully scaled to 256x256 resolution, producing sharp, diverse images that rival traditional CNN outputs.
  • Cross-Compatibility: Interestingly, the authors found that their ViT-based generator could be paired with a StyleGAN2 discriminator to achieve an even better FID of 4.57 on CIFAR-10, suggesting that the ViT generator is a highly capable standalone component.

Limitations and Future Work

While ViTGAN marks a significant step forward, it is not without limitations. Standard ViTs suffer from quadratic computational complexity relative to the number of patches, making the generation of very high-resolution images (like 1024x1024) computationally expensive compared to CNNs. Additionally, the proposed regularization methods require careful hyperparameter tuning to balance stability and image quality.

Future work may look toward incorporating hierarchical Transformer architectures, such as Swin Transformers, to further reduce computational costs and improve performance at higher resolutions.

Summary updated

BibTeX
@inproceedings{lee2022vitgan,
  author = {Kwonjoon Lee and Huiwen Chang and Lu Jiang and Han Zhang and Zhuowen Tu and Ce Liu},
  title = {{ViTGAN: Training GANs with Vision Transformers}},
  booktitle = {International Conference on Learning Representations},
  year = {2022},
  url = {https://openreview.net/forum?id=rrWPTRhudbj},
}
Figure