This repo contains PyTorch model definitions, pre-trained weights and training/sampling code for our paper exploring
interpolant models with scalable transformers (SiTs).
We present Scalable Interpolant Transformers (SiT), a family of generative models built on the backbone of Diffusion Transformers (DiT). The interpolant framework, which allows for connecting two distributions in a more flexible way than standard diffusion models, makes possible a modular study of various design choices impacting generative models built on dynamical transport: using discrete vs. continuous time learning, deciding the model to learn, choosing the interpolant connecting the distributions, and deploying a deterministic or stochastic sampler. By carefully introducing the above ingredients, SiT surpasses DiT uniformly across model sizes on the conditional ImageNet 256x256 benchmark using the exact same backbone, number of parameters, and GFLOPs. By exploring various diffusion coefficients, which can be tuned separately from learning, SiT achieves an FID-50K score of 2.06.
1git clone https://github.com/willisma/SiT.git
2cd SiT
We provide an environment.yml file that can be used to create a Conda environment. If you only want
to run pre-trained models locally on CPU, you can remove the cudatoolkit and pytorch-cuda requirements from the file.
bash
1conda env create -f environment.yml
2conda activate SiT
Pre-trained SiT checkpoints. You can sample from our pre-trained SiT models with sample.py. Weights for our pre-trained SiT model will be
automatically downloaded depending on the model you use. The script has various arguments to adjust sampler configurations (ODE & SDE), sampling steps, change the classifier-free guidance scale, etc. For example, to sample from
our 256x256 SiT-XL model with default ODE setting, you can use:
python sample.py ODE --image-size 256 --seed 1
For convenience, our pre-trained SiT models can be downloaded directly here as well:
Custom SiT checkpoints. If you've trained a new SiT model with train.py (see below), you can add the --ckpt
argument to use your own checkpoint instead. For example, to sample from the EMA weights of a custom
256x256 SiT-L/4 model with ODE sampler, run:
Interpolant settings. We also support different choices of interpolant and model predictions. For example, to launch SiT-XL/2 (256x256) with Linear interpolant and noise prediction:
Caution. Resuming training will automatically restore both model, EMA, and optimizer states and training configs to be the same as in the checkpoint.
Evaluation (FID, Inception Score, etc.)
We include a sample_ddp.py script which samples a large number of images from a SiT model in parallel. This script
generates a folder of samples as well as a .npz file which can be directly used with ADM's TensorFlow
evaluation suite to compute FID, Inception Score and
other metrics. For example, to sample 50K images from our pre-trained SiT-XL/2 model over N GPUs under default ODE sampler settings, run:
Precision in likelihood calculation could likely be improved by:
Uniform / Gaussian Dequantization
Differences from JAX
Our models were originally trained in JAX on TPUs. The weights in this repo are ported directly from the JAX models.
There may be minor differences in results stemming from sampling on different platforms (TPU vs. GPU). We observed that sampling on TPU performs marginally worse than GPU (2.15 FID
versus 2.06 in the paper).
License
This project is under the MIT license. See LICENSE for details.