techlist.io

Realnvp

1 posts

OpenAI2018-07-084 min readCurated summary

Glow: Better reversible generative models

# Glow: Reversible Generative Models with Invertible 1x1 Convolutions Glow is a reversible, flow-based generative model that simplifies the earlier RealNVP architecture by replacing fixed channel permutations with learned invertible 1x1 convolutions. The change yields significant log-likelihood gains on standard benchmarks while producing realistic high-resolution images and supporting efficient sampling. The authors argue that flow-based models, despite receiving far less attention than GANs and VAEs, offer exact inference, parallel synthesis, and a useful latent space for manipulating data. ## Why Flow-Based Models Are Worth Considering Generative models learn the structure of a dataset so they can produce outputs that resemble it, with applications in speech synthesis, text analysis, semi-supervised learning, and model-based control. Flow-based models, an extension of NICE and RealNVP, offer several advantages over alternatives: - **Exact inference and likelihood:** VAEs only approximate latent variables, and GANs have no encoder at all. Reversible models compute latents exactly and optimize the true log-likelihood rather than a lower bound. - **Efficient inference and synthesis:** Autoregressive models like PixelCNN are reversible but hard to parallelize for sampling. Flow-based models parallelize well for both directions. - **Useful latent spaces:** Reversible models and VAEs allow interpolation and meaningful edits of existing datapoints, which GANs and autoregressive models make difficult. - **Memory savings:** Gradients in reversible networks need memory constant in depth rather than linear, per the RevNet work. ## Benchmark Results Glow improves on RealNVP, the previous best flow-based result, on most benchmarks, measured in bits per dimension (lower is better): - CIFAR-10: 3.49 (RealNVP) vs. 3.55 (Glow), a slight regression - ImageNet 32x32: 4.28 vs. 4.09 - ImageNet 64x64: 3.98 vs. 3.81 - LSUN bedroom: 2.72 vs. 2.38 - LSUN tower: 2.81 vs. 2.46 - LSUN church outdoor: 3.08 vs. 2.67 Sampling a 256x256 image takes about 130ms on an NVIDIA 1080 Ti. Sampling from a reduced-temperature model (scaling latent standard deviation by 0.7) gives higher-quality samples. ## Latent Space Applications - **Interpolation:** Encoding two real face images and sampling intermediate points produces smooth transitions. Because the inputs are arbitrary faces rather than model samples, this suggests the model covers the full target distribution. - **Attribute manipulation:** The model trains without labels. Afterward, averaging latent encodings of inputs with and without an attribute (such as blonde hair) yields a direction vector that can shift new inputs toward that attribute. This needs only a small labeled set and no retraining, unlike GAN-based or Cycle-GAN approaches. ## Architectural Changes from RealNVP RealNVP alternates checkerboard-masked layers with channel-wise masked layers. Glow removes the checkerboard layers and changes the channel-wise layers in two ways: - **Learned 1x1 convolutions replace fixed permutations.** RealNVP's channel-wise coupling splits inputs into halves that update each other in a rigid bipartite pattern. Replacing the fixed reversal with a fixed shuffle improved performance, and learning the permutation improved it further. Since a permutation is a square linear transformation, it can be expressed as a 1x1 convolution and optimized with gradient descent. The weights start as a random rotation matrix and are efficiently computed via LU decomposition. - **Activation normalization replaces batch normalization.** This layer applies a learned per-channel shift and scale, initialized from a first minibatch. It allows a minibatch size of 1 for large images and lets the model scale up. ## Scaling Up Gradient checkpointing and other optimizations make training feasible at larger scale. The demo model was trained with Horovod across 5 machines of 8 GPUs each and has over 100 million parameters. ## Open Directions The authors identify two areas for future work: - **Likelihood competitiveness:** Autoregressive models and VAEs still score better on log-likelihood, but they sacrifice efficient sampling and exact inference, respectively. Combining these model families could capture the strengths of each. - **Efficiency:** The face model uses roughly 200M parameters and about 600 convolution layers, which is expensive to train. Shallower models learn long-range dependencies poorly, so self-attention or progressive training could reduce compute cost. Code and the paper are available on GitHub for anyone who wants to build on the work.