TL;DR
This paper introduces JointDistributions, a new family of declarative representations for directed graphical models within TensorFlow Probability (TFP). By extending TFP’s standard Distribution contract to composite structures of Tensors, it allows users to specify complex joint distributions using their preferred programming idiom (sequential lists, named dictionaries, or coroutines) while providing seamless, hardware-accelerated vectorization for modern inference algorithms.
What Problem Does This Paper Address?
In probabilistic programming, there is a classic tension between low-level distribution abstractions and high-level modeling tools. Furthermore, users have diverse preferences for how they want to write models: some prefer an imperative, "probabilistic program" style, while others prefer a declarative, graphical model structure.
Beyond syntax, executing these models efficiently on modern hardware (like GPUs and TPUs) requires vectorization. Manually writing vectorized code for complex joint distributions—where shapes must be carefully aligned across independent draws, batches, and event dimensions—is notoriously difficult and error-prone. The authors set out to create a unified interface that accommodates multiple modeling flavors, integrates cleanly with existing inference algorithms, and exploits hardware acceleration without forcing users to write cumbersome vectorization code.
Methods
The core innovation is the JointDistribution interface, which refines TFP's existing Distribution contract. While standard distributions operate on single Tensors, a joint distribution operates on a structure of Tensors (such as Python lists, tuples, or dictionaries).
To accommodate different user preferences, the authors implement three "flavors" of joint distributions, all of which flatten under the hood into a canonical sequential list based on the chain rule of probability:
JointDistributionSequential: Models are specified as a list of distributions. Conditional dependencies are captured using lambda functions whose arguments are implicitly matched to preceding distributions in the list.
JointDistributionNamed: Similar to the sequential flavor, but models are specified via a dictionary. This provides explicit naming for variables, and TFP uses a topological sort to determine the correct execution order.JointDistributionCoroutine: Uses Python generators (yieldstatements) to provide an imperative, clean look for complex models. Users wrap root nodes (those without parents) in aRootfunction to explicitly denote where sampling shapes originate.
Vectorization Strategies
To achieve high performance on SIMD hardware, JointDistributions support two vectorization paradigms:
- Manual Vectorization: The user manually provides indexing hints (e.g.,
z[..., :2]) to ensure shapes align during parallel execution. - Automatic Vectorization: Powered by
tf.vectorized_map, this approach treats a simple, single-world model specification as a blueprint and automatically lifts the tensor operations to preserve batch dimensions, shielding the user from shape-matching math.
Datasets
Not discussed in the paper. As a systems and software architecture paper, it focuses on framework design and code abstractions rather than empirical evaluation on specific datasets.
Key Insights and Ideas
- The "Distribution" Uniformity: Because
JointDistributioninherits from the baseDistributionclass, joint models expose the exact samesample()andlog_prob()methods as a simple Univariate Normal distribution. This allows downstream inference algorithms (like HMC or Variational Inference) to treat single variables and massive graphical models completely interchangeably. - Organic Shape Propagation: Instead of forcing global shape constraints everywhere, TFP plumbs the
sample_shapeonly into the root nodes of the graphical model. The shapes then propagate "organically" downstream through the conditional parameters of child distributions. - Seamless Parameter Optimization: Models natively track learnable parameters via
jd.trainable_variables. If a distribution depends on a mutabletf.Variable(or a constrained proxy likeTransformedVariable), gradients can flow directly through the joint log-density for maximum likelihood estimation or variational optimization.
Key Results
The paper demonstrates the expressive power of these abstractions by implementing sophisticated models in just a few lines of elegant code:
- Probabilistic Matrix Factorization: Achieved using
JointDistributionSequentialcombined withtfd.Sampleandtfd.Independentto cleanly manage matrix dimensions as single event blocks.
- Latent Dirichlet Allocation (LDA): Implemented via
JointDistributionCoroutine, showing how fixed-width arrays can be maintained for bag-of-words data to preserve SIMD parallelism, avoiding the need for ragged arrays.
Limitations and Future Work
- Static Structures: The current architecture assumes that the structure of the Tensors (the execution graph topology) remains identical across all parallel threads. It does not natively support stochastic control flow (e.g., loops or conditionals that change the number of variables per sample), which the authors note as an area for future work.
- Auto-Vectorization Limits: Automatic vectorization relies on
tf.vectorized_map, meaning it is constrained by the subset of TensorFlow operations supported by that utility. If a model uses an unsupported custom operation, users must fall back to manual vectorization.
Summary updated