by rtqichen

rtqichen /residual-flows

code for "Residual Flows for Invertible Generative Modeling".

166 Stars 23 Forks Last release: about 1 year ago (v1.0.0) MIT License 6 Commits 1 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

Residual Flows for Invertible Generative Modeling [arxiv]

Building on the use of Invertible Residual Networks in generative modeling, we propose: + Unbiased estimation of the log-density of samples. + Memory-efficient reformulation of the gradients. + LipSwish activation function.

As a result, Residual Flows scale to much larger networks and datasets.


  • PyTorch 1.0+
  • Python 3.6+


ImageNet: 1. Follow instructions in

. 2. Convert .npy files to .pth using
. 3. Place in

CelebAHQ 64x64 5bit:

  1. Download from
  2. Convert .npy files to .pth using
  3. Place in

CelebAHQ 256x256: ```

Download Glow's preprocessed dataset.

wget tar -C data/celebahq -xvf celeb-tfr.tar python extractcelebafrom_tfrecords ```

Density Estimation Experiments

NOTE: By default, O(1)-memory gradients are enabled. However, the logged bits/dim during training will not be an actual estimate of bits/dim but whatever scalar was used to generate the unbiased gradients. If you want to check the actual bits/dim for training (and have sufficient GPU memory), set

. Note however that the memory cost can stochastically vary during training if this flag is


python --data mnist --imagesize 28 --actnorm True --wd 0 --save experiments/mnist


python --data cifar10 --actnorm True --save experiments/cifar10

ImageNet 32x32:

python --data imagenet32 --actnorm True --nblocks 32-32-32 --save experiments/imagenet32

ImageNet 64x64:

python --data imagenet64 --imagesize 64 --actnorm True --nblocks 32-32-32 --factor-out True --squeeze-first True --save experiments/imagenet64

CelebAHQ 256x256:

python --data celebahq --imagesize 256 --nbits 5 --actnorm True --act elu --batchsize 8 --update-freq 5 --n-exact-terms 8 --fc-end False --factor-out True --squeeze-first True --nblocks 16-16-16-16-16-16 --save experiments/celebahq256

Pretrained Models

Model checkpoints can be downloaded from releases.

Use the argument

--resume [checkpt.pth]
to evaluate or sample from the model.

Each checkpoint contains two sets of parameters, one from training and one containing the exponential moving average (EMA) accumulated over the course of training. Scripts will automatically use the EMA parameters for evaluation and sampling.


  title={Residual Flows for Invertible Generative Modeling},
  author={Chen, Ricky T. Q. and Behrmann, Jens and Duvenaud, David and Jacobsen, J{\"{o}}rn{-}Henrik},
  booktitle = {Advances in Neural Information Processing Systems},

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.