Scaling Tractable Probabilistic Circuits: A Systems Perspective

Anji Liu, Kareem Ahmed, Guy Van den Broeck

TL;DR

PyJuice is a high-performance GPU library for Probabilistic Circuits (PCs) that delivers 10-100x speedups and 2-5x memory efficiency gains over existing systems. By compiling PCs into block-sparse matrix operations, it enables scaling these tractable generative models to billions of parameters, matching or exceeding the performance of traditional deep learning on large-scale image and language datasets.

Introduction

Probabilistic Circuits (PCs) are a powerful class of deep generative models that allow for exact and efficient answers to complex queries (like marginals or conditionals) that are typically intractable in models like VAEs or GANs. However, they have historically struggled to scale.

The primary bottleneck isn't algorithmic, but systemic. Unlike standard neural networks that rely on regular, dense matrix multiplications, PCs often have irregular, sparse computation graphs. This leads to two major issues on modern GPUs:

  1. Massive IO Overhead: Sum layers in PCs frequently reload the same child node probabilities from memory, wasting bandwidth.
  2. Hardware Underutilization: The irregular structure makes it difficult to leverage specialized hardware like Tensor Cores, which are designed for dense matrix operations.

PyJuice: Methods and Architecture

The authors introduce PyJuice, which bridges the gap between the theoretical tractability of PCs and the practical efficiency of modern GPU hardware through several key innovations:

  • Layering and Compilation: PyJuice first performs a topological sort to group nodes into layers that can be computed in parallel. It then uses a custom compiler to convert the PC's Directed Acyclic Graph (DAG) into a compact set of index tensors.
  • Block-Based Parallelization: Instead of computing one node at a time, PyJuice groups nodes into blocks (e.g., 16x16 or 32x32). This allows a single processor to load a block of inputs once and compute multiple outputs, drastically reducing memory reloads.
  • Tensor Core Integration: By treating these node blocks as small matrices, PyJuice can cast the core "sum-of-products" operations as matrix multiplications, enabling the use of high-speed Tensor Cores.
  • Memory-Efficient Backprop: To save GPU memory, PyJuice utilizes "PC flows" for gradients and employs a recomputation strategy. It doesn't store product node outputs during the forward pass, but recalculates them during the backward pass. Since product layers are computationally "cheap" compared to sum layers, this saves 2-5x memory with minimal time penalty.
The compilation process transforms irregular PC layers into structured, block-sparse representations.

Key Insights

  • IO is the Real Killer: A key "aha moment" came from profiling existing systems. As shown in the runtime breakdown, sum layers spend over 60% of their time on IO (memory movement) rather than actual computation. Grouping nodes into blocks is the most effective way to solve this.
Runtime breakdown showing that IO and computation in sum layers dominate the total execution time.
  • The "Block-Sparse" Sweet Spot: Even for highly irregular PCs, the authors found that they can be treated as "block-sparse." By padding a few zero-parameters, they can force the model into a structured format that runs significantly faster on GPUs. The speed gain from hardware acceleration far outweighs the cost of computing a few extra zeros.
  • Scaling is a Feature: The paper demonstrates that many "weaknesses" of PCs in previous literature were simply due to models being too small. By using PyJuice to train models with 10x more parameters for more epochs, they achieved state-of-the-art results without changing the underlying algorithms.

Results and Performance

The authors evaluated PyJuice across several standard generative modeling benchmarks, including images (ImageNet32, full-scale ImageNet, CelebA-HQ) and language (WikiText-103, CommonGen), testing common architectures like Probabilistic Decision Graphs (PD), RAT-SPNs, HMMs, and HCLTs. PyJuice consistently outperformed all baselines (SPFlow, EiNet, Juice.jl, and Dynamax) in both speed and scale:

  • Speed: PyJuice is 1-2 orders of magnitude faster. For a large PD model with 2 billion edges, PyJuice finished an epoch in ~200 seconds, while other frameworks either ran out of memory (OOM) or were projected to take over 7 hours.
  • Memory: It uses 2-5x less GPU memory, allowing researchers to fit much larger models on consumer-grade hardware like the RTX 4090.
  • Performance Gains: On the CommonGen language task, scaling an HMM with PyJuice improved perplexity from 9.78 to 8.65. On ImageNet32, they established a new baseline of 4.33 bits-per-dimension, significantly better than the previously reported 4.82.

Limitations and Future Work

  • Structure Learning: PyJuice currently focuses on speeding up parameter learning and inference for a fixed structure. Scaling the process of finding the optimal PC structure remains a challenge.
  • Sparse PC Optimization: While PyJuice handles sparse PCs better than previous tools, it cannot fully utilize its block-parallelization benefits on extremely irregular, non-block-sparse structures. Future research should focus on designing PC structures that are naturally block-sparse.
  • Compilation Overhead: There is a one-time compilation cost (e.g., ~30s for a 1B edge model). While negligible for long training runs, it is a factor for very short tasks.

Summary updated

BibTeX
@inproceedings{liu2024scaling,
  author = {Anji Liu and Kareem Ahmed and Guy Van den Broeck},
  title = {{Scaling Tractable Probabilistic Circuits: A Systems Perspective}},
  booktitle = {International Conference on Machine Learning},
  year = {2024},
  url = {https://openreview.net/forum?id=BIbjwcrg0V},
}
Figure