On Size Generalization in Graph Neural Networks

Gilad Yehudai, Ethan Fetaya, Eli A. Meirom, Gal Chechik, Haggai Maron

Introduction

Graph Neural Networks (GNNs) are widely celebrated for their "size invariance"—the theoretical ability to apply the same learned parameters to graphs of any scale, from a few dozen nodes to millions. However, empirical evidence suggests that while a model can execute on larger graphs, its predictive performance often degrades significantly when the test graphs are substantially larger than those seen during training. This phenomenon is known as the size-generalization problem.

The Size-Generalization Problem

The core issue identified in this research is that local structural "patterns" are not necessarily invariant to graph size. In many real-world distributions, such as social networks or biological systems, the local neighborhood of a node shifts as the global graph grows. For instance, in a social network, the average node degree often increases with the total number of users.

Shift in degree distribution between training and test sets.

As illustrated above, a GNN trained on graphs with a narrow degree distribution (the "small-town" scenario) may fail to generalize to a test set with a much broader distribution (the "metropolis" scenario). The model encounters local structures it has never seen before, leading to catastrophic failure at test time.

Methodology: Formalizing Local Structures

To address this, the authors formalize the concept of local neighborhoods using $d$-patterns. A $d$-pattern is a recursive encoding of a node's neighborhood up to $d$ hops away, which corresponds exactly to the receptive field of a $d$-layer GNN.

Recursive definition of d-patterns for a node.

The researchers prove theoretically that if a test set contains $d$-patterns absent from the training set, "bad" global minima can exist—solutions that achieve zero loss on training data but fail to generalize.

Pattern-Tree Self-Supervised Learning (SSL)

To mitigate this discrepancy, the authors propose a novel Self-Supervised Learning task called Pattern-Tree Pretraining (PT). This approach uses Unsupervised Domain Adaptation:

  1. Pattern-Tree Representation: A node's $d$-pattern is represented as a "pattern-tree."
  2. Numerical Descriptors: A descriptor is created for this tree, typically a histogram of features across layers.
  3. SSL Task: The GNN is trained to predict these descriptors on unlabeled large graphs from the target domain.

By forcing the model to learn meaningful representations of the complex local structures found in large graphs before supervised training, the GNN becomes better equipped to handle the structural shifts encountered during inference.

Experimental Results and Insights

The proposed method was evaluated across synthetic models (Erdos-Renyi, Preferential Attachment), molecular datasets (NCI1, PROTEINS), and social networks (Twitch, IMDB).

  • Performance Gains: Pattern-tree pretraining improved average classification accuracy from 63.5% to 67.5% across real-world benchmarks. The most significant improvements were observed in social networks (e.g., a 4% jump on Twitch), where structural shifts are most pronounced.
  • Neighborhood vs. Size: A key insight is that size generalization fails not because of the number of nodes, but because of the shift in neighborhood distributions. If the average degree remains constant as size increases, GNNs generalize remarkably well.
  • The Cost of Depth: Interestingly, deeper GNNs are more susceptible to size-generalization issues. Because they aggregate information from larger neighborhoods, the discrepancy in $d$-patterns between small and large graphs becomes even more severe.

Conclusion and Future Work

This work highlights that size generalization in GNNs is fundamentally a problem of local structural distribution shift. While the Pattern-Tree SSL task provides a robust bridge for domain adaptation, limitations remain. Current descriptors assume categorical features and bidirectional edges, and performance on complex benchmarks like OGB remains inconclusive. Future research will focus on extending the $d$-pattern framework to handle continuous features and more diverse graph topologies.

Summary updated

BibTeX
@inproceedings{yehudai2021size,
  author = {Gilad Yehudai and Ethan Fetaya and Eli A. Meirom and Gal Chechik and Haggai Maron},
  title = {{On Size Generalization in Graph Neural Networks}},
  booktitle = {International Conference on Machine Learning},
  year = {2021},
  url = {https://openreview.net/forum?id=4NS4qseZbBq},
}
Figure