Simple, Distributed, and Accelerated Probabilistic Programming

Dustin Tran, Matthew D. Hoffman, Dave Moore, Christopher Suter, Srinivas Vasudevan, Alexey Radul

Overview

Edward2 is a lightweight probabilistic programming library for TensorFlow that distills the entire field down to a single, powerful abstraction: the random variable. By stripping away high-level "inference queries" in favor of a simple tracing mechanism, Edward2 allows probabilistic models to scale seamlessly across hundreds of TPUs and GPUs. This approach achieves massive speedups—up to 100x over traditional frameworks like Stan and PyMC3—while maintaining the flexibility required for modern deep learning.

The Problem: Bridging Two Worlds

Traditionally, the probabilistic programming community and the deep learning community have operated in separate silos. Probabilistic Programming Languages (PPLs) like Stan or PyMC3 typically treat models as black boxes and inference as a separate "query" step. While mathematically elegant, this strict separation makes it incredibly difficult to scale models to the sizes seen in modern deep learning, which often involve billions of parameters or massive datasets.

Conversely, deep learning frameworks like TensorFlow or PyTorch are built for massive scale and hardware acceleration but lack first-class support for probabilistic reasoning. To build the next generation of "differentiable programs," researchers need a system that doesn't hide the computation. They need a framework where they can explicitly manage computational, memory, and bandwidth costs while still benefiting from probabilistic abstractions.

Methods: Random Variables Are All You Need

The authors propose Edward2, a library built on a minimalist philosophy.

  1. The Random Variable Abstraction: In Edward2, a probabilistic program is simply a Python function. Random variables are reified as objects that wrap TensorFlow Distributions. They can act like standard tensors (returning samples) but also carry essential probabilistic metadata.
  2. Tracing: The core of Edward2 is a tiny tracing mechanism. A trace context manager intercepts calls to random variables. This allows the system to "meta-program"—for example, automatically transforming a generative model (which produces samples) into a log-joint density function (needed for training) without rewriting the model.
  3. Low-Level Flexibility: Unlike other PPLs, Edward2 doesn't provide a high-level, black-box infer() function. Instead, it provides the building blocks to write custom inference loops.
  4. Hardware Integration: Because it is embedded directly in TensorFlow, Edward2 natively supports TPU (Tensor Processing Unit) clusters and multi-GPU setups. This allows for complex setups like model-parallelism, where a single model is split across multiple TPU cores.
Distributed autoregressive flow mapped to TPU cores

Datasets

The paper evaluates the system using several high-dimensional benchmarks to prove its scalability:

  • 64x64 ImageNet: Used to test a Vector-Quantized Variational Auto-Encoder (VQ-VAE).
  • 256x256 CelebA-HQ: Used for a large-scale Image Transformer (an autoregressive model).
  • Covertype: A standard UCI dataset (581,012 observations) used to benchmark the No-U-Turn Sampler (NUTS) for Bayesian logistic regression.

Key Insights

  • Simplicity Scales: By removing high-level abstractions, the authors actually made it easier to scale. Because Edward2 "looks" like standard TensorFlow, it can leverage existing distributed training infrastructure (like CrossShardOptimizer) without modification.
  • Tracing as a User-Level Tool: Tracing isn't just an implementation detail; it’s a way for users to manipulate programs. Researchers can "mutilate" a program for causal intervention or "align" a model and a variational posterior simply by intercepting their random variable calls at runtime.
  • Differentiable Learning Algorithms: Because the learning process is just another composition of numerical operations, you can differentiate through the entire training loop. The paper demonstrates "learning-to-learn," optimizing a preconditioner for a gradient descent algorithm by treating the algorithm itself as a differentiable function.

Key Results

  • Linear Scaling: For both VAEs and Image Transformers, Edward2 achieved optimal linear speedup when scaling from 1 to 256 TPUv2 chips. This is a significant milestone for probabilistic modeling at scale, proving that hardware acceleration can be fully utilized.
Optimal linear speedup scaling up to 256 TPUv2 chips
  • Massive Speedups in Sampling: Using the No-U-Turn Sampler (NUTS) on GPUs, Edward2 was 100x faster than Stan and 37x faster than PyMC3.
  • Negligible Overhead: The authors show that the abstraction layer of Edward2 adds almost zero overhead compared to "handwritten" TensorFlow code, proving that you don't have to sacrifice performance for probabilistic flexibility.

Limitations and Future Work

Because Edward2 removes high-level "magic" inference buttons, it requires the user to have a deeper understanding of both the model and the optimization process. It is a tool designed for researchers and engineers rather than a "black-box" solver. Additionally, while Edward2 supports TensorFlow's Eager mode (which is great for debugging and dynamic models like NUTS), Eager mode still carries some performance overhead compared to compiled Graph mode.

Looking forward, the authors express interest in pushing these designs toward "giant" probabilistic models with over 1 trillion parameters and generating ultra-high-resolution (4K) images, further bridging the gap between deep learning scale and probabilistic rigor.

Summary updated

BibTeX
@inproceedings{tran2018simple,
  author = {Dustin Tran and Matthew D. Hoffman and Dave Moore and Christopher Suter and Srinivas Vasudevan and Alexey Radul},
  title = {{Simple, Distributed, and Accelerated Probabilistic Programming}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2018},
  url = {https://openreview.net/forum?id=rkZ5rvWdbH},
}
Figure