ViTGAN: Training GANs with Vision Transformers

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

Abstract

Vision Transformers (ViTs) have recently challenged the long-standing dominance of Convolutional Neural Networks (CNNs) in various computer vision tasks. However, training Generative Adversarial Networks (GANs) with ViTs remains notoriously difficult due to inherent instabilities in the adversarial training process. In this work, we present ViTGAN, a framework that successfully leverages pure ViT architectures for image generation. By introducing novel regularization techniques for the discriminator and architectural enhancements for the generator, we demonstrate that ViTGAN can match the performance of state-of-the-art CNN-based GANs like StyleGAN2 on benchmarks such as CIFAR-10 and LSUN.

1. Introduction

For over a decade, the inductive biases of CNNs—specifically locality and translation equivariance—have made them the standard for image synthesis. While ViTs offer greater global context through self-attention, they lack these built-in biases, leading to significant training volatility when used in GANs. Standard stabilization techniques for CNN-based GANs, such as R1 gradient penalties or Spectral Normalization, often fail to prevent divergence or lead to underfitting in ViT-based models. ViTGAN addresses these challenges through a suite of targeted architectural and training improvements designed to enforce Lipschitz continuity and improve local context.

2. Methodology

The ViTGAN architecture replaces the traditional convolutional backbones of both the generator and discriminator with Transformer-based encoders.

Overview of the ViTGAN architecture, showing the generator (left) and discriminator (right) components.

2.1 Discriminator Regularization

To stabilize the discriminator, we identify that the high capacity of self-attention can lead to a "strong" discriminator that prevents the generator from learning. We propose three key stabilizers:

  • L2 Self-Attention: Replacing standard dot-product attention with L2 distance-based attention to enforce a bounded Lipschitz constant, ensuring smoother gradients.
  • Improved Spectral Normalization (ISN): A modified spectral normalization that scales weights relative to their initial values, providing stability without stifling the model's learning capacity.
  • Overlapping Patches: Introducing slight overlaps between patches to provide the discriminator with better local spatial context and prevent it from memorizing the rigid grid structure.

2.2 Generator Architecture

The generator is designed to effectively propagate the latent code through the Transformer layers while maintaining spatial smoothness.

Detailed view of generator variants and the Self-Modulated LayerNorm (SLN) mechanism.
  • Self-Modulated LayerNorm (SLN): Instead of simple latent injection, we use the latent vector to modulate the normalization layers throughout the encoder, ensuring the latent code influences every stage of the generation process.
  • Implicit Neural Representation (INR): To avoid "blocky" artifacts at patch boundaries, we employ a small MLP with Fourier features to map patch embeddings to pixels, facilitating the generation of continuous textures.

3. Experiments and Results

We evaluated ViTGAN on CIFAR-10, CelebA, and LSUN Bedroom datasets. On CIFAR-10, ViTGAN achieved an FID of 4.92, outperforming the baseline StyleGAN2 implementation (5.60). On the LSUN Bedroom dataset at 256x256 resolution, the model achieved an FID of 4.67, demonstrating its scalability to higher resolutions. Qualitatively, ViTGAN produces sharp, diverse images with global structures that often appear smoother than those generated by CNN-based counterparts, though it handles background textures differently due to its global attention mechanism.

4. Conclusion

ViTGAN demonstrates that pure Vision Transformers are a viable and competitive alternative to CNNs for adversarial image generation. While challenges remain regarding the quadratic memory cost of self-attention at very high resolutions, the stabilization techniques introduced here—particularly L2 attention and self-modulated normalization—provide a foundation for future Transformer-based generative models.

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