Exphormer: Sparse Transformers for Graphs

Hamed Shirzad, Ameya Velingker, Balaji Venkatachalam, Danica J. Sutherland, Ali Kemal Sinop

Graph transformers (GTs) have rapidly emerged as a powerful architecture for graph learning, offering a compelling way to model long-range dependencies that traditional Message-Passing Neural Networks (MPNNs) often struggle to capture. However, despite their success, GTs suffer from a massive Achilles' heel: scalability.

Standard transformers rely on "global attention," where every node computes attention scores with every other node. This results in quadratic computational and memory complexity, $O(N^2)$, meaning that doubling the number of nodes quadruples the resource requirements. Consequently, dense GTs are largely restricted to tiny graphs, such as small molecules. While researchers have attempted to adapt sparse attention mechanisms from Natural Language Processing (like BigBird or Performer), these were designed for linear sequences and often perform poorly on the complex, non-linear topologies of graphs.

To overcome this bottleneck, researchers have introduced Exphormer, a novel framework for building powerful and scalable graph transformers. Exphormer replaces dense attention with a sparse mechanism based on expander graphs and virtual nodes, achieving linear complexity $O(V + E)$ while maintaining the theoretical "universal approximation" power of dense transformers.

The Exphormer Framework

Exphormer tackles the scalability problem by constructing a sparse "interaction graph" for the attention mechanism. This interaction graph is built using three distinct components:

  1. Expander Graphs: This is the core mathematical innovation of the paper. Expander graphs are sparse (having a constant degree) but possess exceptionally high connectivity. Mathematically, they "spectrally approximate" a fully connected graph. This property allows information to propagate across the entire graph in just $O(\log N)$ layers without requiring $N^2$ edges.
  2. Virtual Global Nodes: The framework adds a small number of "hub" nodes connected to every other node in the graph. These virtual nodes act as a global memory sink, enabling any node to pass information to any other node in just two steps.
  3. Local Neighborhoods: To ensure the model remains grounded in the actual topology of the data, Exphormer explicitly includes the edges of the original input graph in its attention pattern.

By combining these three components, the total number of edges processed in the attention mechanism scales linearly relative to the number of nodes and edges in the original graph.

Key Theoretical and Practical Insights

Exphormer is not just computationally efficient; it also introduces favorable theoretical properties and inductive biases:

  • Universal Approximation: The paper provides a theoretical proof that, despite its sparsity, Exphormer retains the ability to approximate any continuous function on graphs, provided it utilizes a "Hamiltonian path" or virtual nodes.
  • Sparsity as an Inductive Bias: Interestingly, Exphormer often outperforms dense transformers. The authors suggest that the sparse attention pattern acts as a helpful "soft inductive bias." By restricting attention, the model is forced to focus on relevant structural pathways rather than getting lost in the noise of a fully connected graph.
  • Extreme Memory and Parameter Efficiency: The efficiency gains are massive. On the MalNet-Tiny dataset, a standard GraphGPS model crashes with an "Out of Memory" (OOM) error on a 40GB A100 GPU at a batch size of 16. On the same hardware, Exphormer comfortably handles a batch size of 256. Furthermore, Exphormer models often achieve superior results with 3 to 4 times fewer parameters than their dense counterparts (e.g., 90k vs. 340k parameters on the PATTERN dataset).

Empirical Evaluation and Results

The authors evaluated Exphormer across a rigorous battery of 15 datasets, integrating it into the recently proposed GraphGPS framework. The datasets spanned standard GNN benchmarks (CIFAR10, MNIST, CLUSTER, PATTERN), the Long-Range Graph Benchmark (Peptides-Func, Peptides-Struct, PCQM-Contact), large-scale transductive graphs (ogbn-arxiv, Amazon Computer/Photo, Coauthor CS/Physics), and code graphs (MalNet-Tiny).

Key results include:

  • State-of-the-Art (SOTA) Performance: Exphormer achieved SOTA or near-SOTA results on several benchmarks, including CIFAR10, MNIST, and MalNet-Tiny.
  • Superiority Over Sparse Baselines: It consistently outperformed other sparse transformer variants, such as BigBird and Performer, across all tested datasets.
  • Unprecedented Scalability: Exphormer successfully trained on the ogbn-arxiv dataset (over 169k nodes and 1.1M edges). This is a feat impossible for standard dense GTs, which suffer OOM errors even on heavily downsampled versions of such networks.
  • Long-Range Success: On the LRGB datasets, Exphormer outperformed traditional MPNNs and matched or exceeded the performance of full transformers, proving that its sparse edges effectively capture long-distance dependencies.

Limitations and Future Work

While Exphormer represents a significant leap forward for scalable graph learning, it does come with a few limitations. The model exhibits hyperparameter sensitivity; performance can vary depending on the degree of the expander graph and the number of virtual nodes, requiring manual tuning for new datasets. Additionally, the authors noted that expander edges can occasionally "interfere" with the model's ability to utilize local graph structures if not tuned carefully.

Finally, the current framework is designed for static graphs. Adapting these expander-based mechanisms for dynamic graphs that evolve over time remains an exciting open area for future research.

Summary updated

BibTeX
@inproceedings{shirzad2023exphormer,
  author = {Hamed Shirzad and Ameya Velingker and Balaji Venkatachalam and Danica J. Sutherland and Ali Kemal Sinop},
  title = {{Exphormer: Sparse Transformers for Graphs}},
  booktitle = {International Conference on Machine Learning},
  year = {2023},
  url = {https://openreview.net/forum?id=3Ge74dgjjU},
}
Figure