All models

Graphormer molecular

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

Graphs and geometry · 305 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 (33 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
10.3M
Operations
305
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
m1258
Graph hash
1be1e3e50fe44b23524ca1d87a9a921b172ce0cd65ad37e1c9567cbf05538e22
Skeleton hash
7a4bbaf482bf4a9ca5184e42f310b61fd8972d554232f3851b66598ba3ad87da
Architecture hash
d6ba521f4cf203175c9043d87e966e9dd2341b826afb4534f5799e2178a08725
Diagram SHA-256
665a991abbfea745f97b0cb91898ad8bef2e31a33460508bdff727607902db91
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 smaller GraphormerSMALL size: 6 layers and hidden dimension 512.

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