Skip to content
mandt-labPublic

About

Official implementation of Representation Augmented Diffusion Models

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Representation-Augmented Diffusions

Farrin Marouf Sofian *  ·  Kushagra Pandey *  ·  Stephan Mandt
University of California, Irvine   (* equal contribution)

Paper (arXiv)  ·  Project page  ·  Checkpoints (coming soon)

(a) ImageNet 256x256 samples from RAD. (b) FID-50k against training iterations for RAD-XL/2, REPA-XL/2 and SiT-XL/2. (c) Text-to-image samples at 256x256 with their prompts.

Overview

Diffusion models reach state-of-the-art sample quality but have no built-in mechanism for learning semantic representations of the data. Representation-Augmented Diffusions (RAD) add one: every denoising step first predicts a representation u_t from the noisy state and then conditions the denoiser on it.

Animation of RAD's generative process as a graphical model. Starting from Gaussian noise x_T, each step first samples a representation u_t from the noisy state x_t and then takes a denoising step to x_{t-1} conditioned on it, until the clean sample x_0.

The generative process of RAD: every denoising step first samples a representation ut from the noisy state xt, then denoises conditioned on it. The token grids drawn for ut are schematic.

  • Training. The representation is supervised by a frozen pretrained encoder (DINOv2). The objective is a variational bound with a denoising term and an alignment term, and it recovers representation alignment methods such as REPA as special cases.
  • Sampling. The model generates the representation from its own features, so no external encoder is needed. Any flow-matching sampler applies unchanged.
  • The difference to REPA. REPA predicts the representation but never feeds it back into the denoiser. RAD does.

Results

In the paper, RAD is compared against REPA with the same backbone, encoder, data and training schedule:

  • Training. RAD reaches a given FID in far fewer training iterations, at every model scale (panel (b) above), and needs fewer parameters and less training data.
  • Sampling. RAD needs fewer sampling steps for the same sample quality, with the Euler ODE and SDE samplers and with UniPC.
  • Representations. Hidden states stay linearly separable deeper into the network.

See our paper for full results.

Quickstart

git clone https://github.com/mandt-lab/RAD.git && cd RAD

# 1. Environment (Python 3.10)
conda create -n rad python=3.10 -y && conda activate rad
pip install torch==2.11.0 torchvision==0.26.0 --index-url https://download.pytorch.org/whl/cu128
pip install -r requirements.txt

# 2. Data: preprocess ImageNet once into data/imagenet_vae (see "Data" below)

# 3. Train RAD-B/2 on 4 GPUs (400K iterations, global batch size 256)
bash scripts/train.sh --dataset-root data/imagenet_vae --output-root exps --model sit-b-2

# 4. Sample 50K images from the 400K checkpoint and compute FID
pip install -r evaluations/requirements.txt
bash scripts/generate.sh --exp-dir exps/<run name> --steps "[400000]" --num-gpus 4 \
    --mode sde --num-steps "[250]" --betas "[0.7]" --num-fid-samples 50000 \
    --ref-batch data/VIRTUAL_imagenet256_labeled.npz

<run name> is the experiment folder that train.py creates under --output-root; its name is built from the configuration and printed at the start of training. The sections below describe each step in detail.

Installation

The code was developed with Python 3.10, PyTorch 2.11.0 and CUDA 12.8. Install PyTorch first, choosing the wheel index that matches your CUDA version (instructions), then the remaining packages:

git clone https://github.com/mandt-lab/RAD.git
cd RAD

conda create -n rad python=3.10 -y && conda activate rad
pip install torch==2.11.0 torchvision==0.26.0 --index-url https://download.pytorch.org/whl/cu128
pip install -r requirements.txt

Evaluation uses the TensorFlow-based ADM evaluation suite, which has its own requirements file:

pip install -r evaluations/requirements.txt

If TensorFlow cannot use the GPU inside the PyTorch environment, install it in a separate environment and pass that interpreter to the sampling script with EVAL_PYTHON=/path/to/python bash scripts/generate.sh ....

Pretrained models

The pretrained RAD checkpoints are coming soon and will be linked here.

The models that training and evaluation build on are downloaded automatically on first use:

Model Used for Source
DINOv2-B/14 (default) Encoder that supervises the representation during training torch hub
Stable Diffusion VAE Latent space of the images (sd-vae-ft-mse to encode the dataset, sd-vae-ft-ema to decode samples) Hugging Face
Inception network FID, sFID, Inception Score, precision and recall ADM

Data

Training reads ImageNet 256x256 as center-cropped images plus precomputed Stable Diffusion VAE latents. Download ImageNet (ILSVRC 2012), then run the three steps in preprocessing/README.md. The result is one directory:

data/imagenet_vae/
├── imagenet_256_vae/    256x256 center-cropped training images (input of the DINOv2 encoder)
├── vae-sd/              one SD-VAE latent (mean, std) per image
└── latents.npy, latents_fnames.json, labels.npy    optional packed copy of vae-sd/

For evaluation, download the ADM ImageNet 256x256 reference batch (about 2 GB):

wget -P data https://openaipublic.blob.core.windows.net/diffusion/jul-2021/ref_batches/imagenet/256/VIRTUAL_imagenet256_labeled.npz

Linear probing also needs the validation set, preprocessed the same way into data/imagenet_vae_val.

Code layout

Path Contents
train.py Training loop (Hydra config in configs/)
loss.py Training objectives: RAD, REPA, REG
models/sit.py SiT backbone, representation policy and the pathway that injects the representation
models/flows.py Conditional normalizing flow of the flow policy
samplers.py Euler ODE, Euler-Maruyama SDE and UniPC samplers, guidance
generate.py Distributed sampling for evaluation
sample_visuals.py Class-conditional sample grids
linear_probe.py Linear probing of hidden states
evaluations/ ADM evaluation suite and the metrics.csv writer
preprocessing/ ImageNet to images and SD-VAE latents
scripts/ train.sh, generate.sh and linear_probe.sh with the settings of the paper
tests/ CPU smoke tests of the samplers

Running experiments

The scripts in scripts/ run on one node and use every GPU through accelerate launch or torchrun. Their defaults are the settings of the paper.

Training

scripts/train.sh launches train.py. The defaults are a global batch size of 256, AdamW at a constant learning rate of 1e-4, EMA decay 0.9999, fp16 mixed precision, 400K iterations, adaptive alignment weighting with p = 1, and the representation injected after block 2 for RAD-B/2 and after block 8 for RAD-L/2 and RAD-XL/2.

bash scripts/train.sh --dataset-root data/imagenet_vae --model sit-b-2    # RAD-B/2
bash scripts/train.sh --dataset-root data/imagenet_vae --model sit-l-2    # RAD-L/2
bash scripts/train.sh --dataset-root data/imagenet_vae --model sit-xl-2   # RAD-XL/2

Useful options (run bash scripts/train.sh --help for all of them):

Option Meaning
--loss Method: rad_cn_mod_flow (RAD, default), rad_flow, rad_v1, repa, reg
--model Backbone: sit-b-2, sit-l-2, sit-xl-2
--encoder Pretrained encoder: dinov2-vit-b (default), dinov2-vit-l, siglip-vit-l
--encoder-depth Block whose hidden state is aligned with the encoder and after which the representation is injected. Default: 2 for RAD on sit-b-2, otherwise the value in the model config (4 for sit-b-2, 8 for sit-l-2 and sit-xl-2)
--proj-p Power p of the adaptive weighting of the alignment loss (0 disables it). Default: 1 for rad_cn_mod_flow, 0 for the other methods
--beta Policy scale during training
--num-gpus, --batch-size Number of GPUs and global batch size
--max-train-steps, --checkpointing-steps Training length and checkpoint interval
--use-packed-latents true Read latents from the packed latents.npy (faster on network filesystems)
--logging wandb Log to Weights & Biases instead of TensorBoard

Any additional key=value argument is passed to train.py as a Hydra override of configs/config.yaml. Training resumes from the latest checkpoint of the same configuration if one exists (--resume-step 0 starts from scratch). train.py can also be called directly:

accelerate launch --num_processes 4 train.py model=sit-b-2 model.encoder_depth=2 \
    data.data_dir=data/imagenet_vae output_dir=exps

Each run writes config.yaml, log.txt and checkpoints/<step>.pt to <output root>/<run name>/. The TensorBoard event files of all runs go to <output root>/logs/RAD/. On 4 NVIDIA RTX PRO 6000 Blackwell GPUs, 400K iterations take about 11, 16 and 22 hours for B/2, L/2 and XL/2.

Sampling and evaluation

scripts/generate.sh samples from one or more checkpoints with generate.py and evaluates every batch with the ADM suite (FID, sFID, Inception Score, precision, recall). Each batch adds one row, with all sampling settings, to <run dir>/samples/metrics.csv. The model configuration is read from the checkpoint.

# Default protocol: Euler-Maruyama SDE, 250 steps, no guidance, 50K samples.
# The inference policy scale is 0.7 for B/2 and 0.8 for L/2 and XL/2.
bash scripts/generate.sh --exp-dir exps/<run name> --steps "[400000]" --num-gpus 4 \
    --mode sde --num-steps "[250]" --betas "[0.8]" --num-fid-samples 50000

# Few-step sampling: Euler ODE and UniPC at several step budgets
bash scripts/generate.sh --exp-dir exps/<run name> --steps "[400000]" \
    --mode ode --num-steps "[5, 10, 25, 50]" --betas "[0.8]" --num-fid-samples 50000
bash scripts/generate.sh --exp-dir exps/<run name> --steps "[400000]" \
    --mode unipc --unipc-order 2 --num-steps "[5, 10, 25, 50]" --betas "[0.8]" --num-fid-samples 50000

# Sweep the inference policy scale
bash scripts/generate.sh --exp-dir exps/<run name> --steps "[400000]" \
    --mode ode --num-steps "[50]" --betas "[0.2, 0.4, 0.6, 0.75, 0.8, 1.0]" --num-fid-samples 50000

List arguments (--steps, --num-steps, --betas, --cfg-scale) are swept: every combination is sampled and evaluated in turn. By default the generated images are deleted once their metrics are recorded; pass --remove false to keep them. The noise streams depend on the seed, the number of GPUs and the per-GPU batch size, so a batch is reproduced exactly only with the same --num-gpus.

Guided sampling

Classifier-free guidance and autoguidance are combined with noise coupling, which shares part of the policy noise across the tokens of the representation. The setting below is the one used for RAD-XL/2 at 400K iterations (for the 1M checkpoint: --control-rho 0.10 and --cfg-scale "[2.5]"). The autoguidance weak model is the 100K checkpoint of the same run.

bash scripts/generate.sh --exp-dir exps/<run name> --steps "[400000]" --num-gpus 8 \
    --mode sde --num-steps "[50]" --betas "[0.8]" \
    --control-noise fixed --control-rho 0.12 \
    --cfg-scale "[3.25]" --cfg-controls shared --guidance-low 0.0 --guidance-high 0.75 \
    --guide-ckpt exps/<run name>/checkpoints/0100000.pt --guide-scale 1.5 --guide-beta 0.8 \
    --balanced-labels --num-fid-samples 50000

Ablations

# Gaussian policy and flow policy (block 4, no adaptive weighting)
bash scripts/train.sh --dataset-root data/imagenet_vae --loss rad_v1
bash scripts/train.sh --dataset-root data/imagenet_vae --loss rad_flow

# Full model at block 4 without adaptive weighting, then other encoders,
# injection depths and weighting powers
bash scripts/train.sh --dataset-root data/imagenet_vae --encoder-depth 4 --proj-p 0
bash scripts/train.sh --dataset-root data/imagenet_vae --encoder-depth 4 --proj-p 0 --encoder siglip-vit-l
bash scripts/train.sh --dataset-root data/imagenet_vae --encoder-depth 6 --proj-p 0
bash scripts/train.sh --dataset-root data/imagenet_vae --encoder-depth 4 --proj-p 0.5

# Training policy scale of the Gaussian policy
bash scripts/train.sh --dataset-root data/imagenet_vae --loss rad_v1 --beta 0.5

Baselines

# REPA with the same data, backbone and schedule (aligned at block 4)
bash scripts/train.sh --dataset-root data/imagenet_vae --model sit-b-2 --loss repa

scripts/baselines/wrap_baseline.py converts a checkpoint released by a REPA-family codebase into this repository's checkpoint format, so that it can be sampled and evaluated with the commands above.

Linear probing

linear_probe.py measures how linearly separable the hidden states are. Noised ImageNet latents are passed through the frozen EMA model with the null class label (RAD samples its representation from the policy, as at inference), the tokens of each block are average-pooled, and a linear classifier (parameter-free BatchNorm + Linear; Adam, learning rate 1e-3, cosine decay, 90 epochs, batch size 16,384) is trained per block and diffusion time and scored by top-1 accuracy on the ImageNet validation set.

It needs the packed latents of the training and the validation set (preprocessing/README.md):

bash scripts/linear_probe.sh --exp-dir exps/<run name> --steps "[400000]" --num-gpus 4 \
    --train-dir data/imagenet_vae --val-dir data/imagenet_vae_val \
    --timesteps 0.1 0.25 0.5 0.75 --beta 0.7

Results are written to <run dir>/probe/linear_probe.csv, one row per block and diffusion time. The B/2 models probed in the paper are aligned at block 4 (--encoder-depth 4 at training time).

Sample grids

torchrun --nproc_per_node 4 sample_visuals.py --ckpt exps/<run name>/checkpoints/0400000.pt --out-dir visuals \
    --class-labels 88,279,388,979 --samples-per-class 64 --mode ode --num-steps 50 --beta 0.8

Acknowledgements

This code builds on REPA and REG, which in turn build on SiT and DiT. The evaluation suite is from ADM, the preprocessing code from EDM2, and the encoder from DINOv2. We thank the authors for releasing their code.

Citation

@misc{sofian2026representationaugmenteddiffusions,
      title={Representation-Augmented Diffusions}, 
      author={Farrin Marouf Sofian and Kushagra Pandey and Stephan Mandt},
      year={2026},
      eprint={2611.38485},
      archivePrefix={arXiv},
      primaryClass={cs.CV},
      url={https://arxiv.org/abs/2611.38485}, 
}

License

The code is released under the CC BY-NC-SA 4.0 license (LICENSE): it may be used, shared and adapted for non-commercial purposes with attribution, and adaptations must be shared under the same license. Portions that originate from REPA, REG, SiT and ADM keep their MIT license notices, which are in licenses/. The files in preprocessing/ that derive from EDM2 are licensed by NVIDIA under CC BY-NC-SA 4.0 (see the file headers).

Contact

Farrin Marouf Sofian (fmaroufs@uci.edu) and Kushagra Pandey (pandeyk1@uci.edu).

About

Official implementation of Representation Augmented Diffusion Models

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages