Efficiently Counting Substructures by Subgraph GNNs without Running GNN on Subgraphs

Zuoyu Yan, Junru Zhou, Liangcai Gao, Zhi Tang, Muhan Zhang · OpenReview

Abstract

Using graph neural networks (GNNs) to approximate specific functions such as counting graph substructures is a recent trend in graph learning. Among these works, a popular way is to use subgraph GNNs, which decompose the input graph into a collection of subgraphs and enhance the representation of the graph by applying GNN to individual subgraphs. Although subgraph GNNs are able to count complicated substructures, they suffer from high computational and memory costs. In this paper, we address a non-trivial question: can we count substructures efficiently with GNNs? To answer the question, we first theoretically show that the distance to the rooted nodes within subgraphs is key to boosting the counting power of subgraph GNNs. We then encode such information into structural embeddings, and precompute the embeddings to avoid extracting information over all subgraphs via GNNs repeatedly. Experiments on various benchmarks show that the proposed model can preserve the counting power of subgraph GNNs while running orders of magnitude faster.

Introduction

Standard Message Passing Neural Networks (MPNNs) are the workhorses of graph machine learning, but they possess a significant theoretical limitation: they are no more powerful than the 1-Weisfeiler-Lehman (1-WL) isomorphism test. This "blind spot" prevents them from distinguishing between certain non-isomorphic graphs and, crucially, from counting simple substructures like triangles or 4-cycles, which are vital for understanding molecular and social network data.

To overcome this, researchers developed Subgraph GNNs, which decompose a graph into many smaller subgraphs and run GNNs on each. While powerful and provably able to count substructures, they are computationally prohibitive. Running a GNN hundreds of times for a single input graph makes them impractical for large-scale datasets. This paper introduces ESC-GNN (Efficient Substructure Counting GNN) to achieve the counting power of Subgraph GNNs without the massive computational tax.

Methodology

The core insight of ESC-GNN is that the expressive power of Subgraph GNNs stems primarily from the distance information between nodes within those subgraphs. Instead of explicitly extracting and processing subgraphs during training, ESC-GNN precomputes this structural information and encodes it as augmented edge features.

The ESC-GNN pipeline: Input graphs are conceptually decomposed into subgraphs, but the structural information is precomputed as embeddings to allow a single GNN pass.

The model utilizes three types of precomputed structural embeddings:

  1. Degree Encoding: A histogram of node degrees within a local subgraph.
  2. Node-level Distance Encoding: Shortest path distance histograms from a node to the "root" nodes of a subgraph.
  3. Edge-level Distance Encoding: Labels for edges based on the distances of their endpoints to the root nodes.

By decoupling structural extraction from learning, ESC-GNN gains the theoretical expressive power of a Subgraph GNN while only requiring a single pass over the original graph with a standard MPNN.

Key Results

Efficiency and Speed

The most striking result is the efficiency gain. On the OGBG-HIV dataset, ESC-GNN ran approximately 165x faster than the state-of-the-art $I^2$-GNN (6,301 seconds vs. 1,042,963 seconds for 100 epochs). While there is a one-time preprocessing cost, it is amortized over many training epochs, making the overall training and inference cycles significantly more practical.

Comparison of preprocessing (Pre) and running (Run) times, demonstrating that ESC-GNN maintains high efficiency compared to other advanced GNN architectures.

Counting and Isomorphism

ESC-GNN achieved near-zero error (MAE < 0.01) in counting 3-cycles, 4-cycles, and 4-cliques, matching the performance of much heavier models. In isomorphism tests (EXP, SR25, and CSL), it achieved 100% accuracy, outperforming standard MPNNs and even high-order GNNs like PPGN on the difficult SR25 benchmark.

Real-World Molecule Modeling

On the ZINC-250K dataset, ESC-GNN achieved a state-of-the-art Mean Absolute Error (MAE) of 0.021, outperforming all other subgraph-based baselines. This suggests that the local substructures captured by the model are highly relevant for predicting chemical properties.

Conclusion

ESC-GNN bridges the gap between the theoretical power of high-order WL tests and the practical efficiency of standard MPNNs. By identifying distance information as the key driver for substructure counting and encoding it into precomputed embeddings, the authors demonstrate that it is possible to achieve high expressive power without the prohibitive cost of running GNNs on individual subgraphs.

Summary updated

BibTeX
@misc{yan2023efficiently,
  author = {Zuoyu Yan and Junru Zhou and Liangcai Gao and Zhi Tang and Muhan Zhang},
  title = {{Efficiently Counting Substructures by Subgraph GNNs without Running GNN on Subgraphs}},
  year = {2023},
  eprint = {2303.10576},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2303.10576},
}
Figure