TL;DR
GPS is a recipe for building a graph Transformer from three parts: an encoding of each node's position and structure, a local message-passing layer, and a global attention layer. The authors show that the global attention can be made linear in the number of nodes and edges, so the model runs on graphs of several thousand nodes, where earlier graph Transformers were limited to a few hundred. Across 16 benchmarks it beats every other graph Transformer the paper compares against on 11 tasks.
Builds on: Transformer, Message Passing Neural Network, Graph Laplacian, Linear Attention, Weisfeiler-Lehman Test · Leads to: the open GraphGPS package, and the question of which encodings a graph Transformer actually needs.
Why it mattered
Before this paper, graph Transformers let every node attend to every other node, which is powerful but costs time that grows with the square of the number of nodes. The authors' main claim is practical: a hybrid layer that pairs message passing with linear attention scales to large graphs without giving up accuracy. The paper's largest test graphs are the MalNet-Tiny function-call graphs, with up to 5,000 nodes each, which the authors describe as far larger than earlier inductive graph benchmarks.
The paper also gave the field a shared vocabulary. It sorts positional and structural encodings into local, global and relative types, and it names the three design choices every hybrid model must make. The GraphGPS package released with the paper lets each choice be swapped without rewriting the model.
Concrete numbers from the paper make the point. On the OGB-LSC PCQM4Mv2 molecular property task, GPS-medium reaches a validation mean absolute error of 0.0858 with 19.4 million parameters, while GRPE (46.2 million parameters), EGT (89.3 million) and Graphormer (48.3 million) score 0.0890, 0.0869 and 0.0864. On ogbg-molpcba, the authors report 196 seconds per epoch for a model of about 6 million parameters, against 883 seconds for SAN on the same GPU type.
The problem
Message passing, the workhorse of Graph Neural Network models, has three known weaknesses that the paper relies on. First, after many layers the node features can become too similar to tell apart, which is called over-smoothing. Second, information from distant nodes must squeeze through every edge in between, which is called over-squashing. Third, a standard message-passing network cannot distinguish some pairs of non-isomorphic graphs: it is no more expressive than the Weisfeiler-Lehman Test.
Global attention fixes the first two problems, because any node can read from any other node in one step. But it creates two new ones. Full attention costs time that grows with the square of the number of nodes. And attention has no built-in sense of where a node sits in the graph, so the graph's structure has to be supplied separately. Fully-connected graph Transformers that did this used a pairwise distance table, which is quadratic in size and does not fit the linear-attention approximations that make large graphs affordable. The paper's answer is to keep the positional information on the nodes and real edges, and to run the global attention on node features only.
How it works
Here is the pipeline in the order it runs, for one graph with N nodes, E edges, node features X, edge features E and adjacency matrix A.
flowchart LR G["Graph: nodes X, edges E, adjacency A"] --> P["Positional and structural encodings"] P --> L["GPS layer, repeated L times"] L --> M["Local branch: MPNN with edge features"] L --> T["Global branch: linear attention over all nodes"] M --> S["Sum of the two branches"] T --> S S --> F["Two-layer MLP"] F --> H["Task head: node, edge or graph output"]
-
Compute the encodings once per graph. For each node, the paper uses the eigenvectors of the graph Laplacian as a global positional encoding, and the diagonal of the random-walk matrix as a local structural encoding. For each pair of nodes it can add a relative encoding, such as a distance, that is attached to the edge. These are cheap to store and add to the node features.
-
Run the local branch. A standard message-passing layer updates each node from its real neighbours and also updates the edge features. Its cost grows with the number of edges, E.
-
Run the global branch in parallel. The same node features go through a global attention layer in which every node looks at every other node. The paper uses a linear attention mechanism, such as Performer or BigBird, so no full N by N attention matrix is ever built. Edge features are not passed into this branch.
-
Add the two branches and mix. The outputs of steps 2 and 3 are summed, then passed through a two-layer MLP. The paper's equations leave out residual connections and batch normalization for clarity, but both are used in the implementation.
-
Repeat and read out. Steps 2 to 4 repeat for L layers. A task head then turns the final node features into a prediction for each node, each edge, or the whole graph by pooling.
A tiny instance. Take a path of three nodes, 1 to 2 to 3, and give only node 1 the feature 1, so X equals (1, 0, 0). Let the local branch simply add up each node's neighbours' features, so node 1 receives from node 2, node 2 receives from nodes 1 and 3, and node 3 receives from node 2. The local output is (0, 1, 0), since only node 2 has a neighbour with a nonzero value.
For the global branch, use a toy attention that gives every node the same weight, so it is the average of all three features: (1 + 0 + 0) divided by 3 is 1/3 for each node. Adding the two branches gives (0, 1, 0) + (1/3, 1/3, 1/3) = (1/3, 4/3, 1/3). Node 2 has moved most, because it is the one that received a message, and every node now carries a little global information. A real layer uses learned weights and a learned attention pattern, but the flow of information is the same.
The math
Definition (one GPS layer). Let hold the node features at layer and hold the edge features. Let be the adjacency matrix. A GPS layer computes
Here is a message-passing layer that uses edge features, is a global attention layer with its own learned weights, and is a two-layer perceptron. The symbol is the feature width at layer .
Step 1 in symbols: the encodings
The positional encoding is built from the eigen-decomposition of the graph Laplacian . If , the vector is an eigenvector, and node receives the -th entries of the first few eigenvectors as its features.
The local structural encoding uses the random-walk matrix , where is the diagonal matrix of node degrees. The -th diagonal entry of is the probability that a walk of steps starting at node ends where it started. Stacking these return probabilities for several values of gives each node a description of the small cycles around it.
Step 2 in symbols: the local branch
The message-passing layer updates each node from its neighbours and each edge from its endpoints. Writing for the set of neighbours of node ,
where and are small learned functions and is the feature of the edge from to . The sum runs only over real neighbours, so the cost is proportional to E.
Step 3 in symbols: the global branch
Standard attention for N nodes with query, key and value matrices is
The matrix has N squared entries, so the cost is about multiply-adds. Linear attention, as in Linear Attention, replaces the softmax with a feature map into m random features, which lets the product be regrouped as . The inner product is only m by d, so the cost is about , which is linear in N. Because the global branch never sees edge features, it works with node features alone.
Step 4 in symbols: combine and mix
The two branch outputs are added and passed through the MLP, . Adding is the simplest way to combine the two views, and the MLP then lets the layer mix channels. Together, the total cost per layer is for the local branch plus for the linear global branch. For sparse graphs, where E is proportional to N, the whole layer is linear in N.
Worked examples
Take two nodes joined by one edge, with features and .
- The local branch sums each node's neighbour. Node 1's only neighbour is node 2, so it receives 5. Node 2 receives 2. The local output is .
- The global branch uses uniform attention, which is the average of all features: for each node. The global output is .
- Add the two branches: .
- Take the MLP to be the identity for this toy case. The layer output is .
Interpretation: each node now carries both its neighbour's value and a summary of the whole graph.
Take a graph with N = 5,000 nodes (the largest MalNet-Tiny graphs have up to 5,000), a head width d = 64, and a linear attention with m = 256 random features.
- Full attention needs about multiply-adds. Since , this is , or .
- Linear attention needs about multiply-adds. Since and gives , times 2 is , or .
- The ratio is .
Interpretation: at this size, the linear version does about 20 times less work per layer. The gap grows with N, because full attention scales with N squared and the linear version with N.
The paper reports 196 seconds per epoch for a 6-million-parameter GPS model on ogbg-molpcba, against 883 seconds for SAN on the same GPU type.
- Divide the slower time by the faster one: .
- Since , the ratio is about 4.5.
- So the GPS epoch is roughly 4.5 times faster on this dataset.
Interpretation: the speedup is measured on a real chemistry benchmark, and it comes from avoiding the full attention matrix, not from a smaller model. The accuracy comparison is in the Results section.
Try it: a graph has N = 1,000 nodes and d = 32. Using the formula , how many multiply-adds does full attention need? Answer: multiply-adds.
Results
The table below gives a few headline numbers from the paper's main tables. Lower is better for MAE and higher is better for accuracy, F1 and AP.
| Benchmark | Metric | GPS | Closest comparison in the paper |
|---|---|---|---|
| ZINC (Benchmarking GNNs) | MAE, lower is better | 0.070 ± 0.004 | SAN: 0.139; GatedGCN: 0.282 |
| ogbg-molhiv | AUROC | 0.7880 ± 0.0101 | SAN: 0.7785 |
| ogbg-molpcba | Average precision | 0.2907 ± 0.0028 | GIN-AK+: 0.2930; CRaWl: 0.2986 |
| ogbg-ppa | Accuracy | 0.8015 ± 0.0033 | ExpC: 0.7976 |
| ogbg-code2 | F1 | 0.1894 ± 0.0024 | K-Subtree SAT: 0.1937 |
| PCQM4Mv2 (validation) | MAE, lower is better | 0.0858 (19.4M parameters) | Graphormer: 0.0864 (48.3M) |
| MalNet-Tiny | Accuracy | 92.72% ± 0.7 (Performer), 93.36% ± 0.6 (Transformer) | Best GIN: about 90% |
| LRGB Peptides-func | AP | 0.6535 ± 0.0041 | SAN+RWSE: 0.6439 |
What these numbers mean. On the five Benchmarking GNN tasks GPS is state of the art on ZINC and CIFAR10, and in the top three on MNIST, PATTERN and CLUSTER. On the OGB graph tasks it is in the top three on molpcba, ppa and code2, and it beats SAN on molhiv, where the authors note some overfitting. It beats every other graph Transformer on all four OGB tasks except SAT on code2. The MalNet-Tiny result shows the scaling claim in practice: the model is trained on graphs up to 5,000 nodes, and the Transformer version does better than the Performer version at about twice the run time.
The paper's ablations (Table 2) say which parts matter. Removing the local MPNN makes ZINC MAE jump from 0.070 to 0.217, so the local branch is not optional. Replacing full Transformer attention with Performer costs accuracy on CIFAR10 (72.31 to 70.67) and on MalNet-Tiny (93.50 to 92.64). On ZINC, global attention changes nothing, because that task depends mostly on local substructures.
Limits. The authors report that GPS overfits on ogbg-molhiv, and that on PascalVOC-SP the Laplacian positional encodings do not help, since removing them gives a higher F1 of 0.3846. The results use a fixed budget of about 500,000 parameters for the long-range benchmarks and per-dataset hyperparameter settings, so a different budget or setup could change the ranking. The paper hypothesises that explicit edge features are not needed inside the global attention; its experiments support this on the benchmarks it tests, not in general.
Reading guide
Read the paper in this order, and use the lessons listed for each part.
- Abstract and Section 1 (Introduction). The problems with message passing and the cost of full attention. Needs Message Passing Neural Network and Transformer.
- Section 2 (Related Work). Graph Transformers and linear Transformers such as Performer and BigBird. Performer is a linear attention method that approximates the softmax with random features; BigBird is a sparse attention pattern in which each position attends to a few local, random and global positions. Needs Linear Attention and Attention Mechanism.
- Section 3.1 (Positional and structural encodings). The local, global and relative categories in Table 1. Needs Graph Laplacian, Random Walk and Positional Encoding.
- Section 3.2 (Why PE and SE in MPNN). The counterexamples to 1-WL. Needs Weisfeiler-Lehman Test and Graph Isomorphism.
- Section 3.3 (GPS layer). The update equations and the modularity, scalability and expressivity arguments. Needs Residual Connection, Batch Normalization and Softmax.
- Section 4 (Experiments). The benchmark tables. Read it with the Results section above. The GIN paper, How Powerful are Graph Neural Networks?, is the reference for what message passing can and cannot tell apart.
- Appendices A to D. Dataset details, hyperparameters and the GPS schematic. Read these only when you want to reproduce a number.
Check yourself
QuestionWhat are the three ingredients of the GPS recipe?Show answer
A positional or structural encoding of the nodes, a local message-passing layer that uses real edges, and a global attention layer that lets every node read from every other node. The two layers run in parallel and their outputs are added before an MLP.
QuestionA graph has N = 1,000 nodes and width d = 32. Using full attention cost of 2 N squared d multiply-adds, how many does one layer need?Show answer
multiply-adds. The number grows with the square of N, so doubling N to 2,000 multiplies this cost by four.
QuestionWhy does GPS run the message-passing layer and the global attention layer in parallel instead of stacking many message-passing layers first?Show answer
Stacking many message-passing layers before a Transformer, as in the GraphTrans design the paper cites, risks losing information early through over-smoothing and over-squashing, before the global layer can act. Running a local layer and a global layer side by side at every depth lets each layer keep the local structure while still giving every node a global view.
QuestionYou have a set of molecules with about 30 atoms each. Should you use GPS with linear attention?Show answer
Probably not for the attention choice alone. Linear attention exists to make very large graphs affordable; at 30 nodes the full attention matrix is tiny, and the paper's own ablations show that full Transformer attention beats Performer on several tasks. Keep the full attention if it fits your budget, and keep the message-passing branch, since the paper shows the local branch is essential.
Sources
- Rampášek, L., Galkin, M., Dwivedi, V. P., Luu, A. T., Wolf, G., Beaini, D. (2022). Recipe for a General, Powerful, Scalable Graph Transformer. arXiv:2205.12454. https://arxiv.org/abs/2205.12454
- Xu, K., Hu, W., Leskovec, J., Jegelka, S. (2018). How Powerful are Graph Neural Networks? arXiv:1810.00826. https://arxiv.org/abs/1810.00826