GraphSPNs: Sum-Product Networks Benefit From Canonical Orderings

Milan Papez, Martin Rektoris, Vaclav Smidl, Tomáš Pevný

TL;DR

Deep generative models for graphs can generate compelling structures, but answering exact probabilistic queries (like conditioning on subgraphs or marginalizing components) remains computationally intractable. This paper introduces GraphSPNs, adapting tractable Sum-Product Networks (SPNs) to graph generation and inference. The authors demonstrate that enforcing graph permutation invariance through canonical sorting drastically simplifies the learning problem, allowing tractable models to compete with complex neural graph generators.

What Problem Does This Paper Address?

Graph generative models (e.g., Graph VAEs, normalizing flows, diffusion models) excel at generating realistic structures such as molecules. However, they are fundamentally intractable: querying exact marginals, conditioning on arbitrary subgraphs, or computing exact likelihoods without approximations is typically impossible.

Sum-Product Networks (SPNs)—a family of probabilistic circuits—guarantee polynomial-time, exact probabilistic inference for a broad suite of queries (e.g., marginals, conditionals, expectations). Applying SPNs to graphs introduces two core challenges:

  1. Variable graph size: Standard SPNs require fixed-dimensional tensor inputs, whereas graphs have varying numbers of nodes and edges.
  2. Permutation invariance: A graph with $n$ nodes has $n!$ equivalent adjacency configurations. An ideal graph distribution must assign identical probability to isomorphic representations, but vanilla SPNs are sensitive to input ordering.

Methods

GraphSPNs formulate graph modeling as learning a joint distribution $p(G) = g_n(p^{\text{spn}}_{m,n}(X, A))$ over node feature matrix $X$ and adjacency tensor $A$:

  • Virtual Node Padding: To handle variable graph size up to a maximum number of nodes $m$, the model pads empty node/edge slots with extra categorical "virtual" types. Nodes and their corresponding edge rows are linearized into a structured sequence: $(X_1, A_1, \dots, X_m, A_m)$.
  • Permutation Invariance Strategies ($g_n$): The authors compare four distinct paradigms:
  • Exact Permutation Invariance (Janossy mixture): Averaging over all $n!$ node permutations (computationally prohibitive beyond tiny graphs).
  • Random Sampling: Approximating the $n!$ average by sampling a subset of $N$ permutations during training and inference.
  • $k$-ary Subgraphs: Averaging induced subgraphs over all $k$-element subsets (probabilistic generalization of Deep Sets / Janossy pooling).
  • Canonical Sorting: Preprocessing graphs into a unique canonical node ordering before feeding them to the SPN, effectively eliminating the $n!$ summation via $p(G) = p^{\text{spn}}(\text{sort}(X, A))$.
  • Architecture: The underlying SPN is implemented via tensorized Einsum Networks (EiNets) with categorical leaf distributions.

Datasets

  • QM9: A standard benchmark of ~134,000 small, stable organic molecules with up to 9 heavy atoms (C, N, O, F).
  • No new benchmark datasets were introduced.

Key Insights and Ideas

  • Canonical sorting tames multi-modality: Learning a permutation-invariant distribution directly forces the density estimator to cover $n!$ equivalent modes for every single graph. Imposing a deterministic canonical ordering collapses this combinatorial explosion into a single mode, drastically easing optimization for SPNs.
  • Tractability retained: Unlike $k$-ary approximations (which break SPN smoothness constraints without explicit smoothing operations), canonical sorting preserves exact, polynomial-time tractability for omni-compatible queries (such as conditioning on an arbitrary fragment or marginalizing unobserved nodes).
  • Conditioning out-of-the-box: Because SPNs provide exact conditional probabilities, GraphSPNs can perform conditional molecular generation (e.g., scaffold elaboration or fragment completion) without task-specific retraining.

Key Results

Molecules were evaluated on Validity ($V$), Validity without post-hoc valency check ($V \text{ w/o check}$), Uniqueness ($U$), and Novelty ($N$):

  • Sorting vastly outperforms other invariant variants:
  • GraphSPN: sort reached 81.62% validity without valency corrections ($98.65\%$ uniqueness, $69.08\%$ novelty).
  • In contrast, random permutation averaging (rand) achieved only 15.38%, no invariance (none) achieved 19.75%, and 2-ary subgraph pooling (k-ary) achieved just 2.10% validity without checks.
  • Competitive with intractable baselines: With post-hoc validity correction, GraphSPN: sort attained 100% validity and remained competitive with leading flow-based and VAE-based models (e.g., GraphAF at 67.0% and GraphDF at 82.7% uncorrected validity).
  • Exact conditional generation: Demonstrated successful conditional sampling of chemically realistic molecules given fixed chemical scaffolds of varying sizes (Figure 2 in the paper).

Limitations and Future Work

  • Dependence on canonicalization heuristics: The performance of the sort variant hinges on the quality and domain-specificity of canonical ordering algorithms (e.g., RDKit’s molecular canonicalization). For general graphs lacking clear domain heuristics, canonical labeling can be computationally expensive (graph isomorphism).
  • Scalability to large graphs: Padded representations scale with the square of the maximum graph size ($m(m+1)$ entries), making scaling to large graphs (hundreds of nodes) computationally demanding.
  • Novelty trade-off: GraphSPN: sort showed lower novelty ($69.08\%$) compared to random variants ($>98\%$), suggesting canonical models trade exploratory coverage for structural validity.

Summary updated

BibTeX
@inproceedings{papez2024graphspns,
  author = {Milan Papez and Martin Rektoris and Vaclav Smidl and Tomáš Pevný},
  title = {{GraphSPNs: Sum-Product Networks Benefit From Canonical Orderings}},
  booktitle = {TPM @ UAI},
  year = {2024},
  url = {https://openreview.net/forum?id=NKdl7FHlFK},
}
Figure