Tensor Variable Elimination for Plated Factor Graphs

Fritz Obermeyer, Eli Bingham, Martin Jankowiak, Neeraj Pradhan, Justin T. Chiu, Alexander M. Rush, Noah D. Goodman

Introduction

In probabilistic modeling, researchers frequently encounter "repeated structure"—such as multiple users in a social network, successive time steps in a sequence, or individual pixels in an image. Directed graphical models traditionally use "plates" to represent this repetition compactly. However, standard inference algorithms, like variable elimination on factor graphs, usually "unroll" these plates into a giant, flat graph before performing any computation.

This unrolling process is highly inefficient. It discards the structural information indicating that many parts of the graph are identical, leading to massive memory consumption and slow, sequential computation for large models. This paper addresses a critical challenge: How can we perform inference directly on the compact, plated representation to exploit modern hardware (like GPUs) and keep computation efficient?

To solve this, the authors introduce plated factor graphs, a framework that brings the plate notation of directed models into the realm of factor graphs. By leveraging a novel Tensor Variable Elimination (TVE) algorithm, they demonstrate how to perform exact inference using high-performance tensor algebra, enabling massive parallelization and polynomial-time complexity for models that would otherwise be computationally overwhelming.

Plated Factor Graphs and Tensor Variable Elimination

The paper proposes two primary methodological contributions to avoid the wasteful unrolling of probabilistic models:

  1. Plated Factor Graphs: This is a formal generalization of undirected factor graphs where nodes (both variables and factors) are assigned to "plates." This compact representation allows a single factor to represent an entire tensor of potential functions.
A plated factor graph with nested plates
  1. Tensor Variable Elimination (TVE): Instead of eliminating variables one by one in a sequential loop, TVE operates on entire plates of variables simultaneously. It achieves this by using tensor contractions—mathematically equivalent to the einsum operations found in libraries like NumPy or PyTorch.

The core insight here is treating inference as tensor algebra. Variable elimination on a plated graph translates directly to a sequence of tensor contractions, bridging the gap between abstract probabilistic logic and low-level, hardware-optimized linear algebra. Because the algorithm recognizes that variables within a plate are conditionally independent, it can process thousands of instances at once on a GPU without requiring any extra parallel programming effort from the user.

The Geometry of Tractability

Crucially, the paper identifies a strict "tractability boundary" for these operations. The authors prove that if a plated graph contains a specific "graph minor"—a certain pattern of overlapping plates—inference becomes exponentially difficult.

An example of overlapping plates that create an intractable graph minor

This discovery provides a simple geometric rule for researchers: if your plates overlap in a "nested" or "disjoint" way, your model will likely run fast. However, if they overlap like a grid (intersecting without nesting), the model hits an intractability wall. If a model avoids this forbidden minor, inference scales polynomially with the size of the plates and can be perfectly parallelized.

The authors integrated this logic into the Pyro probabilistic programming language, allowing users to write high-level model code that automatically compiles down to these optimized tensor operations.

Experimental Evaluation

The researchers evaluated their TVE approach across three distinct domains to prove its flexibility and efficiency:

  • Polyphonic Music Modeling: Tested various Hidden Markov Model (HMM) architectures using the JSB Chorales, Piano-midi.de, and Nottingham datasets.
  • Animal Movement: Analyzed a Harbour Seal tracking dataset from the UK, modeling GPS and diving activity for 17 individuals using group-level random effects.
  • Sentiment Analysis: Applied structured NLP tasks (CRFs) to the Sentihood dataset, which contains sentences about London neighborhoods tagged with specific aspect sentiments (e.g., "price" or "safety").

Key Results

  • Computational Efficiency: On an Nvidia Quadro P6000 GPU, the authors demonstrated that runtime remains nearly constant as plate sizes increase, right up until the GPU is saturated. After saturation, it scales linearly, confirming "perfect efficiency" in parallelization.
  • Model Performance: Their neural-network-enhanced HMMs (nnHMM) achieved state-of-the-art negative log-likelihood results on the polyphonic music datasets, outperforming several complex baseline models like the Deep Markov Model.
  • Flexibility: The exact same TVE engine successfully handled vastly different models, from temporal sequences to structured NLP tasks, proving its general-purpose utility.

Limitations and Future Work

While highly effective, the current TVE implementation has limitations. Most notably, it hits an intractability wall: the algorithm simply fails and throws an error if it encounters an intractable plate structure (the forbidden minor). The authors suggest that future work could involve "partial unrolling"—selectively expanding only the problematic plates while keeping the rest of the graph compact.

Additionally, while this paper focuses on the "sum-product" semiring (used for calculating marginals), the underlying logic can be extended to the "max-product" semiring for MAP inference, as well as other algebraic structures. Finally, the current implementation in Pyro uses a "nonstandard interpretation" to extract the graph at runtime; moving toward more static analysis could potentially unlock even deeper compiler-level optimizations in the future.

Summary updated

BibTeX
@inproceedings{obermeyer2019tensor,
  author = {Fritz Obermeyer and Eli Bingham and Martin Jankowiak and Neeraj Pradhan and Justin T. Chiu and Alexander M. Rush and Noah D. Goodman},
  title = {{Tensor Variable Elimination for Plated Factor Graphs}},
  booktitle = {International Conference on Machine Learning},
  year = {2019},
}
Figure