GrapHist++: Edge-Aware Graph Self-Supervision for Histopathology

Pre-trained weights, cell graphs and embeddings for the edge-informed extension of GrapHist. GrapHist encodes each 224×224 tile as a sparse graph of cells and pre-trains an ACM-GIN encoder with masked feature reconstruction. GrapHist++ builds on that recipe and adds two things: each edge carries, besides the centroid distance, 74 descriptors of an oriented box between the two cells and of its relation to them (75 dimensions in all), and a VICReg variance/covariance term is added to the objective to mitigate the collapse of the representation. The comparison with vanilla GrapHist is not a controlled ablation of the edge features: the baseline also differs in its node input projection, distance weighting, normalization between layers, input standardization and training recipe, so the margins below measure the extension as a whole.

Results

Region-level MIL, transfer to unseen cohorts (test macro-F1 %, best of three MIL heads):

BRACS BreakHis BACH
GrapHist 60.30 89.37 69.16
GrapHist++ 69.00 95.53 68.98

On BACH the two are on par: the 0.18-point gap is below either standard deviation.

Survival on TCGA-BRCA (Cox PH, C-index): 0.793, against 0.76 for GrapHist, 0.72 MAE and 0.63 DINOv2 as published. Every C-index is in-sample, and the comparison with the published values is not paired. Cell-type identification (test macro-F1 %, GrapHist++ against GrapHist): better on the four PanNuke settings, 20× breast 58.57 vs 55.26, 20× pan-cancer 63.25 vs 58.78, 40× breast 58.38 vs 56.43 and 40× pan-cancer 63.35 vs 59.47; on par on both NuCLS taxonomies, 7-class 27.09 vs 26.57 and 4-class 45.74 vs 46.24. The encoder is 7.98 M parameters, 9.29 M with the projection embed() runs through, inside a 10.53 M pre-training checkpoint; it embeds a patch in 0.093 ms at 0.327 GB peak memory (BACH, batch size 48, H200).

Without VICReg the full pre-training run collapsed (pca_1 0.50 at the end of training; effective dimension 5.4-6.2 of 512 in-domain and below 2 on the transfer cohorts). A second 100-epoch run with the same settings plus VICReg mitigates the collapse: its last logged spectrum, at epoch 90, has pca_1 0.17 and effective dimension 11.9. The term is training-only.

What's here

graphist_v2.pt      the released encoder (127 MB, md5 81a2e6b91cefff0bbbc13c6fd318ee78)
modeling/           build_model factory and the ACM-GINEConv backbone
graphs/             cell graphs: TCGA-BRCA, BACH, BRACS, BreakHis, SPIDER-breast
embeddings/         precomputed slide- and cell-level embeddings
baselines/          DINOv2, MAE and GrapHist v1 embeddings for comparison
labels/             slide labels and the TCGA-BRCA clinical export
studies/            homophily, AdapterGNN and preprocessing-runtime artifacts
upstream_v1/        the original GrapHist graphs, unchanged

The repository is ~1.05 TB, so fetch file by file rather than cloning it. DATA.md gives the per-cohort commands; the model alone is the seven files in the snippet below.

Requirements

pip install torch torch-geometric huggingface_hub pandas numpy

pandas and numpy are needed only by modeling/graphist_utils.py, which holds the input transforms.

Graphs are PyTorch Geometric objects with x (n, 96), edge_index (2, e) and edge_attr (e, 75); batch is added when they are collated with Batch.from_data_list. Column 0 of edge_attr is the centroid distance in µm and is used as the message weight, not as a feature.

Usage

import os, sys, torch
from huggingface_hub import hf_hub_download

# Fetch file by file. snapshot_download(allow_patterns=...) is equivalent on
# huggingface-hub >= 1.27, but silently skips LFS files on 1.7.1, which is the
# version the code repository pins, so it would return no checkpoint there.
for f in ["graphist_v2.pt", "modeling/graphist_utils.py",
          "modeling/models/__init__.py", "modeling/models/acm_gin.py",
          "modeling/models/acm_gineconv.py", "modeling/models/edcoder.py",
          "modeling/models/utils.py"]:
    hf_hub_download(repo_id="Ace3Z/graphist-v2", filename=f)

path = os.path.dirname(hf_hub_download(repo_id="Ace3Z/graphist-v2",
                                       filename="graphist_v2.pt"))
sys.path.insert(0, f"{path}/modeling")
from models import build_model

class Args:
    encoder = decoder = "acm_gineconv"
    num_features = 96                # per-cell features
    num_edge_features = 75           # projection sees 74; distance excluded
    num_hidden = 512
    num_layers = 5
    concat_hidden = True             # load-critical
    encoder_norm = "layer"           # load-critical
    edge_distance_in_proj = False    # load-critical
    input_norm = "none"
    batchnorm = False
    activation = "prelu"
    loss_fn = "sce"
    alpha_l = 3
    mask_rate = 0.5
    replace_rate = 0.1
    drop_edge_rate = 0.0
    vicreg_var_weight = 0.05         # training only
    vicreg_cov_weight = 0.002
    vicreg_gamma = 1.0

model = build_model(Args())
ckpt = torch.load(f"{path}/graphist_v2.pt", map_location="cpu", weights_only=False)
model.load_state_dict(ckpt["model_state_dict"], strict=True)
model.eval()

A graph has to go through the same three transforms the release was trained and evaluated with, or the embeddings will not match. They ship here, in modeling/graphist_utils.py:

import json
from torch_geometric.data import Batch
from torch_geometric.transforms import ToUndirected
from graphist_utils import NormalizeData, AddVirtualNode

scale_vals = json.load(open("normalization.json"))   # ships beside each cohort's graphs
graph = torch.load("some_graph.pt", weights_only=False)
for t in (ToUndirected(),
          NormalizeData(scale_vals, edge_attr_skip_cols=[0], min_std=0.01, clip=10),
          AddVirtualNode(mean_edge_distance=scale_vals["edge_attr"]["mean"][0])):
    graph = t(graph)

batch = Batch.from_data_list([graph])
with torch.no_grad():
    h = model.embed(batch.x, batch.edge_index, batch.edge_attr, batch.batch)
patch = h.mean(dim=0)   # patch embedding: the virtual node is averaged in, as in the release

Skipping the transforms raises no error; it just yields different numbers. embed() returns one row per node including the synthetic virtual node, so a 16-cell graph gives (17, 512). The released patch and slide embeddings average all rows, virtual node included; drop the last row only for per-cell embeddings.

Four settings decide whether the weights load at all. The encoder/decoder type must be "acm_gineconv"; encoder_norm must be "layer" and edge_distance_in_proj must be False, since both defaults are wrong for this checkpoint; and concat_hidden must be True, which has no default. Any other setting raises an error instead of loading.

Licence and citation

Released under the MIT licence, matching the code repository.

That covers what this repository adds. It cannot relicense the source data, and three upstream terms travel with the derivatives:

What Upstream terms
upstream_v1/, studies/adaptergnn/graphs_v1/, graphs/tcga_brca/, graphs/bach/, graphs/bracs/, graphs/breakhis/ cc-by-nc-sa-4.0 from the GrapHist v1 datasets, whose cells and edges the four graphs/ cohorts reuse: non-commercial and share-alike
graphs/spider_breast/ cc-by-nc-4.0, research use only
baselines/graphist_v1/graphist_v1.pt apache-2.0, byte-identical to the released GrapHist v1 checkpoint

labels/tcga_brca_clinical.tsv is the open-access GDC clinical export, redistributed under TCGA's open-access terms. The source cohorts keep their own licences, so cite their papers alongside GrapHist.

The architecture adapts GraphMAE and ACM-GNN; the regularizer follows VICReg.

@misc{ogut2026graphist,
    title  = {GrapHist: Graph Self-Supervised Learning for Histopathology},
    author = {Sevda {\"O}{\u{g}}{\"u}t and C{\'e}dric Vincent-Cuaz and Natalia Dubljevic and
              Carlos Hurtado and Vaishnavi Subramanian and Pascal Frossard and Dorina Thanou},
    year   = {2026},
    eprint = {2603.00143v1},
    url    = {https://arxiv.org/abs/2603.00143v1},
}

This extension was carried out by Mahbod Tajdini and Tomás Gadea Alcaide at LTS4, EPFL, in collaboration with the University of Zurich.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Papers for Ace3Z/graphist-v2