Learnable Commutative Monoids for Graph Neural Networks

Euan Ong, Petar Velickovic

Abstract

Graph neural networks (GNNs) have been shown to be highly sensitive to the choice of aggregation function. While summing over a node’s neighbours can approximate any permutation-invariant function over discrete inputs, Cohen-Karlik et al. [2020] proved there are set-aggregation problems for which summing cannot generalise to unbounded inputs, proposing recurrent neural networks regularised towards permutation-invariance as a more expressive aggregator. We show that these results carry over to the graph domain: GNNs equipped with recurrent aggregators are competitive with state-of-the-art permutation-invariant aggregators, on both synthetic benchmarks and real-world problems. However, despite the benefits of recurrent aggregators, their O(V) depth makes them both difficult to parallelise and harder to train on large graphs. Inspired by the observation that a well-behaved aggregator for a GNN is a commutative monoid over its latent space, we propose a framework for constructing learnable, commutative, associative binary operators. And with this, we construct an aggregator of O(log V) depth, yielding exponential improvements for both parallelism and dependency length while achieving performance competitive with recurrent aggregators. Based on our empirical observations, our proposed learnable commutative monoid (LCM) aggregator represents a favourable tradeoff between efficient and expressive aggregators.

Introduction

Graph Neural Networks (GNNs) rely on aggregation functions to pool data from a node's neighbors. Standard fixed functions, such as sum, mean, or max, often lack the expressivity required for complex logic. Conversely, recurrent neural network (RNN) aggregators offer high expressivity but suffer from $O(V)$ sequential depth, making them slow and difficult to train on large graphs. This paper introduces Learnable Commutative Monoids (LCMs), which utilize a learnable binary operator structured as a balanced tree. This approach achieves the high expressivity of recurrent aggregators with an exponential speedup ($O(\log V)$ depth), generalizing effectively on both complex algorithmic and real-world tasks.

The Homomorphism Bottleneck

When a GNN uses a fixed aggregator, it must learn a complex mapping (a homomorphism) to transform neighbor features into a space where the fixed operation (e.g., addition) yields the desired result. For tasks requiring non-trivial logic, such as finding the second-minimum value in a set, this mapping becomes highly discontinuous and fails to generalize to larger, out-of-distribution (OOD) graphs. While RNNs can learn these logic patterns, their sequential nature creates long dependency chains that hinder parallelization and training efficiency. The authors seek a "best of both worlds" aggregator: highly expressive, but highly parallelizable.

Methodology: Learnable Commutative Monoids

The authors propose constructing aggregators as learnable commutative monoids. A commutative monoid consists of a set with a commutative and associative binary operation and an identity element. Instead of a fixed operation, LCMs learn a binary operator using a neural network layer with specific structural constraints:

  1. Strongly Enforced Commutativity: A standard GRU cell is symmetrized such that for inputs $x$ and $y$, the output is $(GRU(x,y) + GRU(y,x)) / 2$, ensuring $x \oplus y = y \oplus x$.
  2. Weakly Enforced Associativity: An algebraic regularization penalty is added to the loss function to encourage $(x \oplus y) \oplus z \approx x \oplus (y \oplus z)$.

By satisfying these properties, the aggregation can be performed via a balanced binary tree. This reduces computational depth from $O(V)$ to $O(\log V)$, enabling significant parallelization.

Key Results

The effectiveness of LCMs was evaluated on synthetic tasks (e.g., 2nd-minimum), the PNA synthetic benchmark (graph algorithms), and real-world datasets (ZINC, MolHIV, CIFAR10).

Accuracy vs. set size for various aggregators on the 2nd-minimum task, demonstrating the superior OOD generalization of LCMs compared to fixed aggregators.

On the synthetic 2nd-minimum task, fixed aggregators (sum, max, PNA) failed to generalize as set sizes increased, with accuracy dropping below 11% for sets of size 200. In contrast, the regularized LCM maintained 82.2% accuracy, closely trailing the sequential RNN's 91.2%.

Crucially, the LCM provided an exponential speedup; for sets of size 200, the LCM took ~79 seconds per epoch compared to the RNN's ~397 seconds. On real-world benchmarks like CIFAR10 and MNIST, LCMs were highly competitive, outperforming fixed aggregators on image classification and tasks involving edge features.

Discussion and Future Work

The study highlights that tree-based aggregation is a powerful alternative to sequential or fixed pooling. While algebraic regularization effectively improves OOD generalization, future work is needed to architecturally enforce associativity without sacrificing expressivity. Additionally, while LCMs excel at complex discrete tasks, they can overfit on simpler continuous tasks where fixed aggregators like sum are naturally suited. Addressing parameter efficiency and the dimensionality requirements of learnable aggregators remains an open area for research.

Summary updated

BibTeX
@inproceedings{ong2022learnable,
  author = {Euan Ong and Petar Velickovic},
  title = {{Learnable Commutative Monoids for Graph Neural Networks}},
  booktitle = {LoG},
  year = {2022},
  url = {https://openreview.net/forum?id=UWhH9tirgb},
}
Figure