How to build a graph Transformer? We provide a 3-part recipe on how to build graph Transformers with linear complexity. Our GPS recipe consists of choosing 3 main ingredients:
- positional/structural encoding: LapPE, RWSE, SignNet, EquivStableLapPE
- local message-passing mechanism: GatedGCN, GINE, PNA
- global attention mechanism: Transformer, Performer, BigBird
In this GraphGPS package we provide several positional/structural encodings and model choices, implementing the GPS recipe. GraphGPS is built using PyG and GraphGym from PyG2. Specifically PyG v2.0.4 is required.
conda create -n graphgps_cover python=3.9
conda activate graphgps_cover
conda install pytorch=1.10 torchvision torchaudio -c pytorch -c nvidia
conda install pyg=2.0.4 -c pyg -c conda-forge
# RDKit is required for OGB-LSC PCQM4Mv2 and datasets derived from it.
conda install openbabel fsspec rdkit -c conda-forge
pip install torchmetrics
pip install performer-pytorch
pip install ogb
pip install tensorboardX
pip install wandb
# For GraphCovers setup
pip install plotly
pip install dgl
pip install tqdm
conda clean --all
conda activate graphgps
# Running GPS with RWSE and tuned hyperparameters for ZINC.
python main.py --cfg configs/GPS/zinc-GPS+RWSE.yaml wandb.use False
# Running config with tuned SAN hyperparams for ZINC.
python main.py --cfg configs/SAN/zinc-SAN.yaml wandb.use False
# Running a debug/dev config for ZINC.
python main.py --cfg tests/configs/graph/zinc.yaml wandb.use False
python main.py --cfg configs/GPS/graphcovers-GPS+RWSE.yaml wandb.use False
python main.py --cfg configs/GPS/qm7-GPS+RWSE.yaml wandb.use False
See run/run_experiments.sh
script to run multiple random seeds per each of the 11 datasets. We rely on Slurm job scheduling system.
Alternatively, you can run them in terminal following the example below. Configs for all 11 datasets are in configs/GPS/
.
conda activate graphgps
# Run 10 repeats with 10 different random seeds (0..9):
python main.py --cfg configs/GPS/zinc-GPS+RWSE.yaml --repeat 10 wandb.use False
# Run a particular random seed:
python main.py --cfg configs/GPS/zinc-GPS+RWSE.yaml --repeat 1 seed 42 wandb.use False
To use W&B logging, set wandb.use True
and have a gtransformers
entity set-up in your W&B account (or change it to whatever else you like by setting wandb.entity
).
To run all unit tests, execute from the project root directory:
python -m unittest -v
Or specify a particular test module, e.g.:
python -m unittest -v unittests.test_eigvecs
If you find this work useful, please cite our paper:
@article{rampasek2022GPS,
title={{Recipe for a General, Powerful, Scalable Graph Transformer}},
author={Ladislav Ramp\'{a}\v{s}ek and Mikhail Galkin and Vijay Prakash Dwivedi and Anh Tuan Luu and Guy Wolf and Dominique Beaini},
journal={arXiv:2205.12454},
year={2022}
}