NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Einsum Networks: Fast and Scalable Learning of Tractable Probabilistic Circuits

Robert Peharz, Steven Lang, Antonio Vergari, Karl Stelzner, Alejandro Molina, Martin Trapp, Guy Van den Broeck, Kristian Kersting, Zoubin Ghahramani

The Representation vs. Inference Trade-off

In generative modeling, there is a fundamental trade-off between representation and inference. Deep models like GANs and VAEs excel at representing complex data and generating realistic samples, but they struggle with basic probabilistic queries. Calculating the exact probability of a sample or computing a conditional density (e.g., predicting missing pixels) is often computationally intractable or requires biased approximations.

Probabilistic Circuits (PCs) offer a compelling alternative. By representing probability distributions as computational graphs of sums (mixtures) and products (factorizations), PCs guarantee exact, polynomial-time inference for a wide range of queries. However, this tractability comes at a cost: PCs have historically been implemented as sparse, "cluttered" graphs, making them incredibly slow and memory-inefficient to train on modern GPUs compared to standard deep learning models.

Einsum Networks (EiNets)

To bridge the gap between the tractability of PCs and the hardware efficiency of deep learning, the authors introduce Einsum Networks (EiNets). This novel implementation design condenses massive numbers of arithmetic operations into dense, highly optimized tensor contractions.

Vectorized Operations

Instead of allocating and computing each node in the circuit individually, EiNets group nodes into vectors. A "leaf" becomes a vector of densities, and a "sum node" becomes a vector of weighted sums. This vectorization allows the model to compute entire layers of the circuit in parallel.

EiNets group multiple sum and product nodes into vectorized operations, allowing parallel computation across the circuit.

The Monolithic Einsum

The core innovation of EiNets is rephrasing the sum and product operations as a single Einstein summation (einsum). By leveraging tensor contractions, the model avoids explicitly allocating memory for intermediate product nodes. This transforms the sparse PC graph into a dense, high-performance computation that modern GPU kernels can execute efficiently.

The core einsum operation in EiNets, representing sum and product nodes as a single tensor contraction.

Log-Einsum-Exp and Auto-Diff

To maintain numerical stability in the log-domain (which is standard for probabilities), the authors developed a stable version of the einsum operation, analogous to the well-known "log-sum-exp" trick. Furthermore, they demonstrate that the Expectation-Maximization (EM) algorithm—the gold standard for learning PCs—can be implemented elegantly using automatic differentiation, significantly simplifying the underlying codebase.

Key Results and Capabilities

EiNets were evaluated across a variety of benchmarks, including 20 standard binarized datasets, SVHN, and CelebA.

  • Massive Performance Gains: By avoiding the explicit storage of every product node, memory becomes much less of a bottleneck. EiNets consistently achieved speedups of 10x to 100x over existing PC libraries (like LibSPN and SPFlow) while consuming significantly less VRAM.
  • Unprecedented Scalability: Thanks to these optimizations, this paper marks the first time PCs have been successfully trained on high-resolution image datasets like CelebA ($128 \times 128$).
  • Tractable Generative Modeling: EiNets prove that exact inference does not have to be sacrificed for high-quality generative results. For instance, they can perform exact "image inpainting" (reconstructing missing halves of faces) by directly computing the conditional distribution $p(\mathbf{x}_{missing} | \mathbf{x}_{visible})$—a task that GANs cannot perform exactly.
  • Outlier Detection: When trained on MNIST, EiNets demonstrated excellent outlier detection, assigning significantly lower log-probabilities to out-of-distribution samples (like SVHN or SEMEION) compared to inliers.

Limitations and Future Work

While EiNets represent a massive leap forward for PCs, some limitations remain. Images generated by likelihood-based models can sometimes exhibit "stripy" artifacts or appear over-smoothed compared to adversarial models. Additionally, the current framework focuses on fixed or randomized graph structures. Integrating efficient structure learning—dynamically deciding how nodes are connected—into the EiNet framework is a promising direction for future research. Finally, the "mixing layer" used to handle sum nodes with many children introduces some computational waste due to zero-padding, leaving room for further optimization.

Summary updated

BibTeX
@inproceedings{peharz2020einsum,
  author = {Robert Peharz and Steven Lang and Antonio Vergari and Karl Stelzner and Alejandro Molina and Martin Trapp and Guy Van den Broeck and Kristian Kersting and Zoubin Ghahramani},
  title = {{Einsum Networks: Fast and Scalable Learning of Tractable Probabilistic Circuits}},
  booktitle = {International Conference on Machine Learning},
  year = {2020},
  url = {https://openreview.net/forum?id=-OVW4TlLueC},
}
Figure