Graph Transformers

Global attention on graphs - Graphormer, GPS, positional encodings, and when they beat message passing.

1. Why Transformers on Graphs?

Message passing only mixes local neighborhoods per layer. Distant nodes need many layers → oversmoothing and over-squashing.

Transformers let every node attend to every other node in one layer - global receptive field.

Tradeoff: MPNN is $O(|E|)$ per layer - cheap on sparse graphs. Full graph attention is $O(n^2)$ - expensive but fixes long-range bottlenecks.

2. Graph Positional Encodings

Unlike sequences, graphs have no built-in order. Transformers need position info injected:

3. Graphormer

Three structural encodings added to attention:

$$\text{Attn}(i,j) = \text{softmax}\left(\frac{Q_i K_j^T}{\sqrt{d}} + b_{\text{spatial}}(i,j) + b_{\text{edge}}(i,j)\right)$$

4. GPS and Hybrid Models

GPS = MPNN + Transformer:

$$\mathbf{h}_i' = \text{MLP}\left(\text{MPNN}(\mathbf{h})_i + \text{Transformer}(\mathbf{h})_i\right)$$

Local message passing captures neighborhood structure; global attention fixes over-squashing. State-of-the-art on many OGB benchmarks.

Also see: GRIT, SAN, Exphormer (sparse expander attention).

5. Complexity and Scaling

6. MPNN vs Transformer

Choose MPNNChoose Graph Transformer
Sparse, million-node graphsSmall/medium graphs needing long-range
Strong local structure (molecules)Over-squashing in deep MPNN
Latency-sensitive productionBenchmark chasing on OGB