Skip to content

GraphSSL

A modular Python library for Self-Supervised Learning on graphs, built on PyTorch and PyTorch Geometric, and the instrument of a controlled study of how graph SSL methods are evaluated. No Lightning, no Hydra — clean, readable training loops you can step through with a debugger.

Status: Alpha

All eight SSL objectives train end-to-end with every backbone and pass the test suite. The Evaluation Study compares them under one protocol on six node-classification datasets and ogbn-arxiv, with three backbones, and measures how much of a result comes from the objective, the backbone, the probe and the training settings. Benchmarks has the per-method tables of the citation graphs and ZINC, and a reproduction of BGRL on ogbn-arxiv with the protocol of its paper.

Supported methods

Method Family Paper
DGI Mutual Information Veličković et al., ICLR 2019
GraphCL Contrastive (NT-Xent) You et al., NeurIPS 2020
BGRL Teacher-Student + EMA Thakoor et al., ICLR 2022
AFGRL Augmentation-Free Mining Lee et al., AAAI 2022
VICReg Variance-Invariance-Covariance Bardes et al., ICLR 2022
Barlow Twins Cross-Correlation Zbontar et al., ICML 2021
GraphDINO Self-Distillation Adapted from Caron et al., ICCV 2021
GraphMAE Masked Feature Reconstruction Hou et al., KDD 2022

Plus a Supervised baseline for comparison.

Encoder backbones: GCN, GIN, Graph Transformer — all swappable via one config line.

Why GraphSSL

Comparing SSL paradigms on graphs today usually means stitching together several papers' official repositories — different frameworks, different encoders, different evaluation protocols — before you can trust that a difference in reported accuracy reflects the method and not the harness. GraphSSL puts bootstrapping (BGRL, AFGRL), redundancy-reduction (VICReg, Barlow Twins), self-distillation (GraphDINO), contrastive (GraphCL), mutual-information (DGI) and masked-reconstruction (GraphMAE) methods behind one identical construction and training API, so swapping one for another is a one-line config change — see Architecture for how that's enforced, not just documented.

Holding everything else fixed also makes the harness itself measurable. Every result is stored with its configuration and code version, every model can be saved and scored again with another probe or split without retraining, and every number is read against the same encoder left untrained. The Evaluation Study uses this to show that a frozen representation resembles its backbone more than its objective, and that the probe decides how large the objective's contribution looks.

Quick start

from graphssl.models import BGRL
from graphssl.training import DINOTrainer
from torch.optim import AdamW

config = {
    "encoder": {
        "name": "gcn",         # 'gcn', 'gin' or 'transformer'
        "hidden_dim": 256,
        "num_layers": 3,
        "norm_type": "batch",  # 'batch', 'layer', or 'none'
        "pool": False,         # False = node-level task
    },
    "augment": [
        {"name": "edge_drop", "p": 0.5},
        {"name": "feat_mask", "p": 0.1},
    ],
    "pred_hidden": 512,
    "ema_tau": 0.99,
    "ema_tau_end": 1.0,
    "total_steps": 0,
}

model = BGRL(config, in_channels=dataset.num_features)
optimizer = AdamW(model.student_parameters(), lr=1e-3)
trainer = DINOTrainer(device="cuda")
losses = trainer.train(model, loader, optimizer, num_epochs=1000)

Continue with Getting Started for installation and a full worked example, or jump straight to a model page if you already know which method you want.

Project

Developed at NECSTLab, Politecnico di Milano. Source on GitHub, package on PyPI.