All models

Graphormer-Base

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

Graphs and geometry · 551 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 (25 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
43.9M
Operations
551
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
m1259
Graph hash
66f78e27d6a944cdf1e0bfac64d1dd3d51ab98c89ceae28bc0ecb54c9c3c609b
Skeleton hash
630052011fe32f6992b95d4af048c7c964387f3100a5a5ab1375a13d29565d07
Architecture hash
90434f8420344b6fc87940c23bf6657e62954cfdd15b338c04e1871f80139115
Diagram SHA-256
93f94cd54779fca07b5b797f5c2909ecdcf5ef49b3c2796d459d6c502e5cd580
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

Matches the paper's main Graphormer size: 12 layers and hidden dimension 768.

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}, 
}