All models

Graphormer-Large

A plain Transformer encoder taught graph structure through centrality, shortest-path and edge attention biases.

Graphs and geometry · 1,043 operations Checked

100%

Showing the top corner; full diagram not loaded yetShowing a small copy; full diagram not loaded yetLarge diagram, not loaded yet

Open SVG

Loading diagram (10 KB)

Open in a new tab

Click or tap a spot to read it up close. Scroll or drag inside the diagram to move through it. Zoom with + and − or Ctrl and scroll. Press 0 for the whole graph. Swipe inside the diagram to move through it. Use + and − to zoom.

At a glance

Parameters
153M
Operations
1,043
Framework
PyTorch
Recurrent
No
Published
NeurIPS 2021
Cited by
146 (as of 18 October 2026)
Authors
Chengxuan Ying, Tianle Cai, Shengjie Luo and others
License
MIT
Checked
Passed: the trace was replayed operation by operation and matched the model's own output for this input.

Files

The diagram is a drawing of a TorchLens trace of the source code. It contains no code or weights.

Details
Stable ID
m1260
Graph hash
9ede528fabf3b1bddb4b632a6035613642c6c873328881840ad7e75ffa7197d1
Skeleton hash
b486a4d92910a0b44c2fdf073011017fd269f579d7b2ea796c6e6ef2032ea08f
Architecture hash
12fdc50e02d01cc955f4aae9b2590d9299fb4d62a60bb82c30fc3f9bbbc44517
Diagram SHA-256
d982aa8fa5ac7572ee6eaebd4fb7c76f3114dde0ecf4a0004e077ce7b05bdf6f
TorchLens version
2.36.0
Renderer
graphviz 2.43.0+pyvips 3.2.0+libvips 8.18.7+render-opts@06c1f0d3
Check
Forward pass replayed in PyTorch

What it is

About this model's family

Graphormer is a graph Transformer built upon the standard Transformer architecture, aimed at graph representation learning tasks. The question behind the title is why the Transformer, dominant elsewhere, had not achieved competitive performance on popular leaderboards of graph-level prediction compared to mainstream GNN variants. The key insight is that the structural information of a graph has to be encoded effectively into the model.

Centrality Encoding assigns each node two real-valued embedding vectors according to its indegree and outdegree and simply adds them to the node features at the input. Spatial Encoding uses the distance of the shortest path between two connected nodes, with a special value of -1 when they are not connected. Each feasible distance value gets a learnable scalar that serves as a bias term in the self-attention module. If that bias is learned to decrease with distance, each node will likely pay more attention to the nodes near it and less to those far away. Edge Encoding computes an average of the dot-products of the edge feature and a learnable embedding along the shortest path, and feeds it in as another bias term to the attention module. The layer itself applies layer normalization before the multi-head self-attention and feed-forward blocks instead of after. A special node called [VNode] is added and connected to each node individually. The representation of the entire graph is the node feature of [VNode] in the final layer. By choosing proper weights and distance function, a Graphormer layer can represent the AGGREGATE and COMBINE steps of popular GNN models such as GIN, GCN and GraphSAGE.

The paper primarily reports two model sizes on PCQM4M-LSC: Graphormer with L = 12 and d = 768, and GraphormerSMALL with L = 6 and d = 512. Compared to the previous state-of-the-art GNN architecture, Graphormer surpasses GIN-VN by a large margin, an 11.5% relative decline in validate MAE. With an ensemble with ExpC the team got a 0.1200 MAE on the complete test set and won first place of the graph-level track in the OGB Large-Scale Challenge. In the ablations, degree-based centrality encoding yields a large margin performance boost over models without centrality information. The authors note that the quadratic complexity of the self-attention module restricts Graphormer's application on large graphs. The Hugging Face model card adds that the model is resource intensive for large graphs and might lead to OOM errors.

Key idea. A standard Transformer made graph-aware through three structural encodings, centrality, spatial and edge, that works surprisingly well across popular graph benchmarks.

  • graphormer
  • graph transformer
  • do transformers really perform bad for graph representation
  • centrality encoding
  • spatial encoding
  • shortest path distance
  • edge encoding
  • ogb-lsc
  • pcqm4m
  • molecule modeling
  • microsoft graphormer
  • graphormerforgraphclassification

AI-written summary, based on the paper and checked automatically against it; not reviewed by a person. Corrections welcome.

Cite the paper

@misc{ying2021transformersreallyperformbad,
      title={Do Transformers Really Perform Bad for Graph Representation?}, 
      author={Chengxuan Ying and Tianle Cai and Shengjie Luo and Shuxin Zheng and Guolin Ke and Di He and Yanming Shen and Tie-Yan Liu},
      year={2021},
      eprint={2106.05234},
      archivePrefix={arXiv},
      primaryClass={cs.LG},
      url={https://arxiv.org/abs/2106.05234}, 
}