Source-linked AI summary

Your ViT is Secretly a Hybrid Discriminative-Generative Diffusion Model

Xiulong Yang, Sheng-Min Shih, Yinlin Fu, Xiaoting Zhao, Shihao Ji

arXiv:2208.07791v1cs.CV

TL;DR

DDPM and ViT had largely developed in separate generative and discriminative domains. The paper integrates ViT into DDPM through GenViT and extends it to the hybrid HybViT model, reporting superiority over prior state-of-the-art methods across generative and discriminative tasks while retaining stated limitations in quality, training speed, and sampling speed.

  • Problem

    DDPM and ViT have advanced generative and discriminative tasks separately, leaving open whether a single ViT can support image generation and classification jointly.

    Source: §1 · p. 1
  • Method

    The paper replaces the DDPM UNet with a ViT in GenViT and extends it to HybViT, where generation and classification share features through independent routines.

    Source: §1 · p. 2, §4.1 · p. 5
  • Results

    The proposed models achieve state-of-the-art results in most image classification and generation tasks, and HybViT outperforms previous state-of-the-art hybrid models on both tasks.

    Source: §1 · p. 2, §7 · p. 11
  • Takeaways & Limitations

    A single ViT can serve as a generative model and as a hybrid discriminative-generative model with stable training and shared statistical strengths.

    Source: §1 · p. 2, §7 · p. 11

    Compared with pure-generation and pure-classification models, the approach has relatively lower generation quality, needs more training iterations for high classification performance, and samples slowly with typically T ≥1000.

    Source: §6 · p. 11

Abstract

from arXiv · show

Diffusion Denoising Probability Models (DDPM) and Vision Transformer (ViT) have demonstrated significant progress in generative tasks and discriminative tasks, respectively, and thus far these models have largely been developed in their own domains. In this paper, we establish a direct connection between DDPM and ViT by integrating the ViT architecture into DDPM, and introduce a new generative model called Generative ViT (GenViT). The modeling flexibility of ViT enables us to further extend GenViT to hybrid discriminative-generative modeling, and introduce a Hybrid ViT (HybViT). Our work is among the first to explore a single ViT for image generation and classification jointly. We conduct a series of experiments to analyze the performance of proposed models and demonstrate their superiority over prior state-of-the-arts in both generative and discriminative tasks. Our code and pre-trained models can be found in https://github.com/sndnyang/Diffusion_ViT .

1 Introduction

The paper connects DDPM and ViT by introducing GenViT for generation and HybViT for joint classification and generation. HybViT shares features across independent reconstruction and classification routines and outperforms prior hybrid models.

1 Introduction

  • GenViT replaces the DDPM UNet with a single ViT for image generation, while HybViT extends this design to joint classification and generation.The paper presents these as direct connections between DDPM and ViT architectures.Source: §1 · pp. 1–2
  • Reconstruction of image patches and classification operate as independent routines that train a shared set of features together.Source: §1 · p. 2
  • The proposed models aim to combine DDPM-like simplicity and stability, shared statistical strengths, and ViT-derived computational efficiency and scalability.The paper contrasts these properties with collapse-prone GANs and EBMs and with the expensive sampling required by JEM.Source: §1 · p. 2
  • HybViT considerably outperforms previous state-of-the-art hybrid models on both classification and generation tasks while optimizing more effectively than MCMC-based JEM/JEM++ models.The authors also report stable training without expensive MCMC sampling.Source: §1 · p. 2

2 Related Work

DDPM models data distributions by reversing a multistep Gaussian diffusion process. Its variational objective can be efficiently estimated by sampling arbitrary diffusion steps, and noise prediction provides an alternative parameterization.

2.1 Denoising Diffusion Probabilistic Models

  • DDPM learns to reverse a sequence of Gaussian-noising steps, starting from noise and producing samples from the data distribution.The forward process adds Gaussian noise over timesteps, while the reverse process uses a neural network to recover data samples.Source: §2.1 · p. 2
  • The DDPM variational lower bound decomposes into timestep-specific terms, with L0 modeled by a discrete decoder and LT constant and ignorable.Source: §2.1 · p. 3
  • DDPM can sample an arbitrary forward timestep directly from x0 in closed form, allowing uniformly sampled timesteps to estimate the variational objective efficiently.Source: §2.1 · p. 3
  • The reverse-process mean can be parameterized directly or through predicted noise, with prior work finding noise prediction effective under a reweighted loss.Source: §2.1 · p. 3
  • The paper builds primarily on DDPM but notes that its objective can be replaced straightforwardly with a score-matching method.Source: §2.1 · p. 3

3 Vision Transformers

ViTs use self-attention over image patches to model non-local dependencies efficiently. Their flexible patch-based representation motivates applying a standard ViT to generation and extending it to a single-model hybrid setting.

3 Vision Transformers

  • Self-attention lets ViTs capture interactions across inputs regardless of spatial relationships, supporting non-local contextual modeling.Queries select values through keys, with attention scaled by the key dimension d_k.Source: §3 · pp. 3–4
  • The GenViT and HybViT backbone feeds noisy x_t with time embedding t for generation, while HybViT computes classification logits from CLS using x0.Source: Figure 2 · p. 4
  • ViT flattens an image into a sequence of patches, adds a classification token and positional embeddings, and processes the sequence with alternating attention and MLP blocks.The patch sequence length is L = H×W/P^2, and each patch has dimension P×P×C.Source: §3 · p. 4
  • ViTs have been used across discriminative and generative tasks, motivating experiments with a standard ViT for generative modeling with minimal modifications.Source: §3 · p. 4
  • Hybrid models jointly model density and classification with shared features, whereas this work focuses on a single ViT without an auxiliary model.The related JEM approach uses one network but relies on SGLD sampling, which remains impractical for high-dimensional data.Source: §3.1 · pp. 4–5, §3.2 · p. 5

4 Method

HybViT extends GenViT into hybrid discriminative-generative modeling by combining classification with diffusion-based image modeling in a shared ViT framework. Its training replaces the energy-model likelihood term with GenViT’s variational objective and uses a larger loss weight to improve generation while retaining comparable classification accuracy.

GenViT architecture

  • GenViT substitutes the DDPM UNet backbone with a single ViT and injects the timestep embedding into hidden features at every layer before reconstructing an image.The timestep embedding is produced by an MLP and modulates each layer’s hidden features.Source: §4.1 · p. 5

GenViT input and backbone

  • Given DDPM input x_t, GenViT raster-scans image patches into a sequence before processing them with the ViT.Source: §4.1 · p. 5

Hybrid ViT

  • HybViT replaces JEM’s energy-model likelihood optimization with GenViT’s variational objective, training classification with cross-entropy and image modeling with the diffusion simple loss.This avoids the contrastive-divergence and MCMC-based optimization used for the generative term in JEM.Source: §4.2 · p. 5
  • The model extends GenViT for hybrid modeling while retaining a single ViT-based architecture for joint discriminative and generative learning.Source: §4.2 · p. 5, §4.1 · p. 5

Training objective

  • Using α = 100 improves generation quality while retaining comparable classification accuracy.The resulting training pipeline is presented in Figure 3.Source: §4.2 · p. 6, Figure 3 · p. 6

5 Experiments

Experiments evaluate GenViT and HybViT across classification, generation, calibration, OOD detection, robustness, likelihood, ablations, and training efficiency. HybViT achieves strong hybrid performance and stability, while ViT-based models retain limitations in calibration, generation quality, and high-resolution settings.

5.1 Hybrid Modeling

  • 95.9% accuracy and 26.4 FID on CIFAR10 let HybViT outperform JEM and JEM++ while maintaining greater training stability.The original ViT reaches comparable accuracy to WRN 28-10, and JEM-based models can diverge early.Source: §5.1 · pp. 6–7, Table 1 · p. 7

5.3 Ablation Study

  • Generation quality remains below UNet-based DDPM for complex, high-resolution data, and smaller patches improve accuracy without resolving the high-resolution generation plateau.The authors identify linear and reconstruction projections, rather than multi-head self-attention alone, as possible bottlenecks.Source: §5.1 · p. 7, §5.3 · p. 10, Table 7 · p. 11

5.2.2 Out-of-Distribution Detection

  • ViTs distinguish in-distribution from out-of-distribution samples better using input density scores, while HybViT and ViT have worse ECE than WRN despite appearing well-calibrated.OOD detection uses AUROC, whereas calibration uses Expected Calibration Error on CIFAR10.Source: §5.2.1 · p. 8, §5.2.2 · p. 9, Table 3 · p. 9

5.2.3 Robustness

  • ViT and HybViT outperform WRN-based classifiers under white-box PGD attacks on CIFAR10.The comparison covers both L∞ and L2 perturbation constraints.Source: §5.2.3 · p. 9, Figure 7 · p. 9

5.2 Additional Analysis

  • HybViT and GenViT achieve comparable CIFAR10 NLL, but both are worse than other methods in bits per dimension.The reported likelihood comparison uses test negative log-likelihood.Source: §5.2.4 · p. 9, Table 4 · p. 10

5.3 Ablation Study

  • Training from 100 to 300 epochs substantially improves classification and generation, while larger α and model capacity favor generation with only small accuracy costs.More epochs slightly improve generation beyond 300, and larger depth or hidden dimensions improve both accuracy and generation quality.Source: §5.3 · p. 10, Table 5 · p. 10, Table 6 · p. 11

6 Limitations

GenViT and HybViT have promising results but remain limited relative to CNN-based and pure-task models, especially in synthesis quality, training efficiency, and inference speed.

  • Generation quality is relatively low compared with pure-generation state-of-the-art models.Source: §6 · p. 11
  • HybViT requires more training iterations to reach high classification performance than pure classification models.Source: §6 · p. 11
  • Inference sampling is slow, typically requiring T ≥1000, whereas GAN requires one forward pass.Source: §6 · p. 11
  • The authors hope these limitations motivate improvements in sampling speed and generative quality.Source: §6 · p. 11

7 Conclusion

The paper presents GenViT and HybViT as ViT-based generative and hybrid discriminative-generative models, reporting strong results across benchmark tasks while acknowledging remaining high-resolution challenges.

  • GenViT integrates a single ViT into DDPM, while HybViT trains a hybrid discriminative-generative model.Source: §7 · p. 11
  • The models achieve state-of-the-art results in most image-classification and image-generation tasks across multiple benchmark datasets.Source: §7 · p. 11
  • HybViT provides stable training and outperforms previous state-of-the-art hybrid models on discriminative and generation tasks.Source: §7 · p. 11
  • Runtime comparisons on CIFAR10 use 1170 iterations per ViT epoch and 390 iterations per WRN-based-model epoch.Source: Table 8 · p. 12
  • VAEBM requires an additional 25,000 CIFAR-10 iterations, or 16 epochs, after NVAE pretraining on one GPU.Source: §7 · p. 12

A Image Datasets

The experiments use image datasets spanning small natural-image benchmarks, a 64×64 object dataset, a 128×128 face dataset, and downsampled ImageNet.

  • CIFAR10 contains 60,000 32×32 RGB images across 10 classes, split into 50,000 training and 10,000 test images.Source: A Image Datasets · p. 15
  • CIFAR100 contains 60,000 32×32 RGB images across 100 classes, with 500 training and 100 test images per class.Source: A Image Datasets · p. 15
  • STL10 provides 500 training images and 800 test images per class across 10 classes.Source: A Image Datasets · p. 15
  • Tiny-ImageNet contains 100,000 downsized 64×64 color images across 200 classes, with training, validation, and test splits.Source: A Image Datasets · p. 15
  • CelebA-HQ is represented by a downsampled 128×128 human-face dataset.Source: A Image Datasets · p. 15
  • ImageNet 32×32 is a 1,000-class downsampled ImageNet variant with the original dataset's image count.Source: A Image Datasets · p. 15

B Experimental Details

The experimental details specify shared ViT and DDPM settings, report hyper-parameter documentation, and provide visual diagnostics for HybViT accuracy, FID, and sample quality.

  • Experiments follow vanilla ViT and DDPM settings, use SGD with initial learning rate 0.1, and apply cosine learning-rate decay.Source: B Experimental Details · p. 15
  • Table 9 lists the hyper-parameters used for ViT, GenViT, and HybViT.Source: Table 9 · p. 16
  • Figure 8 tracks HybViT classification accuracy and FID across training epochs on CIFAR10 and ImageNet 32x32.Source: Figure 8 · p. 16
  • Figure 9 compares samples with FID=40 and FID=20, whose difference is visually imperceptible to humans.Source: Figure 9 · p. 16

C.1 Qualitative Analysis of Samples

The analysis examines convergence, sample quality, augmentation, calibration, robustness, OOD detection, and runtime across ViT-based models. It finds that generation quality improves early, augmentation affects classification and calibration, and HybViT can retain strong robustness while training efficiently.

C.1 Qualitative Analysis of Samples

  • Generation-quality improvement becomes relatively small after 10% of training, with FID=40 and FID=20 samples nearly visually indistinguishable.The authors identify faster convergence as an important direction for future work.Source: §C.1 · p. 17
  • CIFAR10 qualitative analysis includes class-conditional samples and class-wise histograms, with some worst Plane samples becoming completely blank.Source: §C.1 · p. 17, Figure 10 · p. 17, Figure 11 · p. 17

Data Augmentation

  • Strong augmentation is essential for high classification performance, while its effect on generation is negative but tiny.Source: §C.2 · p. 18

OOD Detection and Runtime

  • The analysis also evaluates OOD detection with classifier maximum probability and reports memory-efficient, faster training on a single GPU.OOD results are reported as AUROC, and runtime is measured on ImageNet 32x32 for 100 epochs.Source: §C.3 · p. 18, Table 11 · p. 18, §C.6 · p. 19

Robustness

  • HybViT with weak augmentation is much more robust than other models, especially under L2 attacks.The authors hypothesize that diffusion exposes HybViT to noisy samples, implicitly improving flatness and robustness.Source: §C.4 · p. 18, Table 12 · p. 18

Calibration

  • Strong augmentation better calibrates ViT and HybViT predictions but makes them under-confident relative to the calibration comparison.The comparison includes WRN, JEM, and corresponding ViTs trained without strong augmentation.Source: §C.5 · p. 19, Figure 12 · p. 19

D Additional Generated Samples

The paper provides additional generated samples across several benchmark datasets and image resolutions. It reports low generation quality for preliminary ImageNet 128x128 and vanilla ImageNet 224x224 experiments under limited computation.

Additional Generated Samples

Class-Conditional Samples

Loading 2208.07791v1…