Validation against PyG¶
mlx-graphs follows PyTorch Geometric (PyG), and every layer, sampler and model added for PyG parity was checked against PyG: layers by copying PyG's weights and comparing outputs and gradients, samplers statistically, and models by training them in both frameworks on the same data. This page describes how, summarizes the results, lists the bugs these checks found, and shows how to rerun them.
The full result tables are in the repository, under benchmarks/quality. The speed comparison is on the Benchmarks page.
Method¶
The checks work at three levels:
| Level | What is compared | Where |
|---|---|---|
| Layers | The same layer is built in both frameworks and PyG's weights are copied into the mlx-graphs one. Both run on the same random graph, with duplicate edges, self-loops and isolated nodes, and the outputs (and for many layers the gradients) must agree. | The unit tests, tests/ |
| Samplers and loaders | Exact comparisons with PyG's pure-Python code paths where they exist, and otherwise statistical properties: coverage of every node once per epoch, uniform neighbour sampling, unbiased normalizations. Then mini-batch training against full-batch training. | benchmarks/quality/sampler_quality.py |
| Training quality | The same model is trained in both frameworks, with the same data, splits and hyperparameters, over several seeds. The test metric is read at the epoch of best validation metric. | benchmarks/quality/node_quality.py, benchmarks/quality/graph_quality.py, and the TGN, GPS and to_hetero comparisons |
A training configuration passes when the gap between the means is within 1 point, or within 2 standard deviations of PyG's results: \(|\mathrm{gap}| \le 1\) or \(|\mathrm{gap}| \le 2\,\sigma_{\mathrm{PyG}}\). The node classification table also marks pass (noise) a gap within 2 standard errors of the difference of the means.
Keeping the comparison fair
- Same model and data. Both frameworks train the same architecture with the same hyperparameters, on identical arrays: the data is loaded once and handed to both, and the splits are the same. Each framework keeps its own default initialization, and mlx-graphs layers are initialized as in PyG.
- Adam's bias correction. MLX's
Adamis created withbias_correction=True, which is the update rule oftorch.optim.Adam. MLX's default has no bias correction and takes much larger first steps: it lowered GAT's accuracy on Cora by about 4 points in the speed benchmarks, and gave GPS on Peptides-func a clearly higher training loss. - L2 penalty vs weight decay.
torch.optim.Adam(weight_decay=...)addsweight_decay * pto the gradients (an L2 penalty), which is not the decoupled weight decay ofAdamW. The harnesses reproduce it in MLX by adding the same term to the gradients. Where the PyG script usesAdamW(theto_heterocomparison), both frameworks useAdamW. - Devices. mlx-graphs runs on the GPU and PyG on the CPU (with one or two torch threads per run), except for the slow deep models of the node classification harness (GCNII, DeeperGCN), for which PyG runs on MPS. The device changes the speed, not what is compared.
- One process per run. Every configuration and seed runs in its own process under a memory cap.
Numerical tolerance
MLX's float32 matmul on the Mac's GPU has a relative error of about 1e-3, where NumPy and torch on the CPU have about 1e-7. This is MLX behaviour, not mlx-graphs', and it is the source of the ~1e-3 differences of the forward passes. It can be larger for gradients that go through a cancellation: EdgeConv's first layer, whose inputs are differences x_j - x_i, has gradient differences of up to about 10 %. The layer tests therefore use a tolerance of 2e-2: a wrong formula is off by far more. It did not change any training result.
Results¶
Layers¶
108 of the 151 test files compare mlx-graphs with PyG or use PyG as a reference:
| Tests | Files using PyG | Examples |
|---|---|---|
Convolution layers (tests/nn/conv) |
39 of 44 | test_gat_conv.py, test_gine_conv.py, test_pna_conv.py |
Models (tests/nn/models) |
7 of 8 | autoencoders, KGE, LightGCN, label propagation, TGN |
Norms (tests/nn/norm) |
8 of 9 | GraphNorm, PairNorm, LayerNorm, MessageNorm |
Pooling (tests/nn/pooling) |
5 of 6 | TopK pooling, Set2Set, global pooling |
Aggregations (tests/nn/aggr) |
2 of 2 | the aggregation modules, including the learnable ones |
Message passing, to_hetero, graph transformers (tests/nn) |
3 of 5 | test_to_hetero.py, test_message_passing_aggr.py |
| Transforms, utilities, data, loaders, metrics | 27 of 52 | test_scatter_reductions.py, test_pyg_reference.py |
Datasets (slow tests, pytest --datasets) |
17 of 23 | a dataset's arrays against PyG's version of it |
Other (tests/algorithms, tests/test_hetero_linear.py) |
0 of 2 | (mlx-graphs only) |
12 of these files also compare gradients with torch's autograd, among them the GAT, GATv2, AGNN, GEN, MF and DirGNN convolutions, the aggregations, the scatter reductions and TGNMemory. The to_hetero tests copy PyG's weights into converted models, including on the full DBLP and IMDB graphs (slow tests). tests/pyg_copy.py holds the helpers that convert PyG state dicts. Message passing shows how to write such a test.
Some layers were also checked with copied weights on full datasets:
- On Cora: PairNorm, GraphNorm and GENConv (with and without MessageNorm) agree with PyG to GPU matmul precision, forward and input gradients; CorrectAndSmooth agrees to 3e-5; LabelPropagation gives identical accuracies.
- On PubMed: PNAConv's output and input gradients agree with PyG's to 1e-4 and 1e-8 (relative ~1e-3).
- On DBLP: the HGT model's forward pass matches PyG's on the full graph.
- On Peptides-func: the full GPS model gives the same train-mode loss (0.70363 vs 0.70362 on 16 graphs) and gradients within ~1 %.
Node classification¶
38 model configurations on the public splits of Cora, CiteSeer and PubMed, 5 seeds each (one deterministic run for LabelPropagation): 99 configurations, 96 pass. 81 of the 99 gaps are within 1 point.
| Family | Models | Configs | Pass |
|---|---|---|---|
| GCN and propagation | GCN, GCNII (64 layers), SSGConv, LGConv, ARMAConv, ClusterGCNConv, MixHopConv, SIGN, MaskLabel, NormalizeFeatures and Laplacian PE pipelines | 29 | 29 |
| Other convolutions | GatedGraphConv, ResGatedGraphConv, NNConv, CGConv, MFConv, LEConv, FiLMConv, GeneralConv | 24 | 24 |
| Attention | AGNNConv, FAConv (FAGCN), GeneralConv with attention | 7 | 7 |
| Aggregations | GENConv (softmax), lists of aggregations in SAGEConv and GENConv, PNAConv, PNA, DeeperGCN | 15 | 13 |
| Directed graphs | DirGNNConv with GCNConv and SAGEConv | 6 | 5 |
| Norms (4-layer GCN) | no norm, GraphNorm, PairNorm, DiffGroupNorm, and MessageNorm in GENConv | 10 | 10 |
| Label propagation and non-GNN models | LabelPropagation, CorrectAndSmooth, LINKX | 8 | 8 |
A few rows (test accuracy in %, mean ± std over seeds):
| Model | Dataset | PyG | mlx-graphs | Gap |
|---|---|---|---|---|
| GCNConv x2 (reference) | Cora | 80.5 ± 0.6 | 80.9 ± 0.5 | +0.4 |
| GCNII: 64 GCN2Conv layers | Cora | 82.7 ± 1.4 | 83.0 ± 1.0 | +0.3 |
| DeeperGCN: 7 GENConv layers | Cora | 75.2 ± 0.9 | 75.4 ± 1.3 | +0.2 |
| SAGEConv(aggr=["mean", "max"]) x2 | PubMed | 78.1 ± 0.7 | 78.3 ± 0.4 | +0.1 |
| LabelPropagation (deterministic) | CiteSeer | 49.9 | 49.9 | +0.0 |
| DirGNNConv(GCNConv) x2 | CiteSeer | 66.9 ± 0.7 | 68.7 ± 1.4 | +1.8, mismatch |
| PNAConv x2 | Cora | 75.0 ± 2.0 | 70.4 ± 1.8 | -4.6, mismatch |
| PNAConv x2 | CiteSeer | 52.0 ± 2.8 | 58.8 ± 2.1 | +6.8, mismatch |
Full table, with the training losses of both frameworks: node_results.md (setup and notes: node_notes.md).
Graph-level, heterogeneous, link and knowledge graph models¶
40 configurations, all pass, most of them set up after PyG's example scripts:
| Task | Models and datasets | Configs | Pass |
|---|---|---|---|
| Graph classification | GINE, PNA, TopK and SAG pooling, DGCNN, MultiAggregation, GraphNorm, Set2Set, DeepSets on MUTAG (10 seeds) and PROTEINS (5 seeds) | 17 | 17 |
| Hierarchical pooling | DiffPool, MinCutPool, DMoN, ASAPooling, EdgePooling, GraphUNet on PROTEINS (5 seeds, pooling_quality.py) |
6 | 6 |
| Heterogeneous graphs | HAN on IMDB, HGT on DBLP, RGAT and FastRGCN on DBLP as a homogeneous graph | 4 | 4 |
| Link prediction | GAE and VGAE on Cora and CiteSeer (and GAE with train_test_split_edges), LightGCN on MovieLens100K |
6 | 6 |
| Self-supervised | DeepGraphInfomax on Cora | 1 | 1 |
| Knowledge graph embeddings | TransE, DistMult, ComplEx, RotatE on FB15k-237 | 4 | 4 |
| Point clouds | EdgeCNN and DynamicEdgeConv on synthetic point clouds | 2 | 2 |
For example, HGT on DBLP reaches 71.8 ± 1.8 % in PyG and 73.0 ± 2.5 % in mlx-graphs, GAE on Cora a test AUC of 90.7 % in both, and LightGCN a recall@20 of 27.4 % in both. MUTAG has only 19-20 test graphs per split, so its accuracies move in steps of 5 points and its gaps are larger (up to 6 points), within 1.5 paired standard errors. Full table: graph_results.md.
Hierarchical pooling on PROTEINS¶
benchmarks/quality/pooling_quality.py trains the same architectures in both frameworks on PROTEINS, with the same data and splits (5 seeds, 100 epochs; test accuracy in % at the best validation epoch):
| Model | PyG | mlx-graphs | Gap |
|---|---|---|---|
| DiffPool | 71.4 ± 4.8 | 74.1 ± 4.8 | +2.8 |
| MinCutPool | 73.0 ± 4.3 | 74.5 ± 5.0 | +1.4 |
| DMoN | 72.7 ± 4.7 | 73.9 ± 4.2 | +1.2 |
| ASAPooling | 68.2 ± 6.8 | 70.7 ± 4.1 | +2.5 |
| EdgePooling | 70.2 ± 7.2 | 71.1 ± 4.0 | +0.9 |
| GraphUNet | 73.4 ± 3.7 | 75.5 ± 2.5 | +2.1 |
All six are within 2 PyG standard deviations (3 to 7 points with 5 random splits of PROTEINS). MinCut and DMoN hit non-finite gradients in both frameworks on nearly empty clusters; those steps are skipped in both (about twice as many in mlx-graphs, with the same final accuracy). The dense and sparse pooling layers are also compared with PyG with copied weights (outputs, auxiliary losses and gradients) in the test suite. Full table: pooling_results.md.
Point clouds on ModelNet10¶
PointNet++ (PyG's examples/pointnet2_classification.py: fps, radius, PointNetConv) trained for 5 epochs on ModelNet10, on the same fixed clouds of 1024 points sampled through mlx-graphs' ModelNet and SamplePoints, reaches a test accuracy of 80.9 % in mlx-graphs and 82.5 % in PyG (best epoch: 80.9 % and 82.9 %), with training losses of 0.26 and 0.31. DGCNN (DynamicEdgeConv, PyG's examples/dgcnn_classification.py) reaches 78.0 % and 80.2 % after 3 epochs. The point cloud layers, fps, voxel_grid, nearest, graclus and the point cloud transforms are also compared with PyG in the test suite (fps picks the same points as PyG with random_start=False, in 1.9 ms with its Metal kernel against 132 ms for torch_cluster on the CPU, for 32 clouds of 1024 points). Full table: pointcloud_results.md.
Molecular models¶
SchNet, DimeNet, DimeNet++ and AttentiveFP match PyG with copied weights (outputs, and gradients with respect to the parameters and to the atom positions, tests/nn/models/test_molecular.py). They were also trained in both frameworks (benchmarks/quality/molecular_quality.py, small budget): SchNet and DimeNet++ on the HOMO-LUMO gap of a random QM9 subset, AttentiveFP on ESOL (one-hot from_smiles features, random 80/10/10 splits).
| Model | Task | PyG | mlx-graphs |
|---|---|---|---|
| SchNet | QM9 gap, 10k molecules, 10 epochs, test MAE (eV), 2 seeds | 0.377 ± 0.004 | 0.384 ± 0.019 |
| DimeNet++ | QM9 gap, 5k molecules, 6 epochs, test MAE (eV), 1 seed | 0.270 | 0.279 |
| AttentiveFP | ESOL, 100 epochs, test RMSE, 3 seeds | 0.606 ± 0.058 | 0.593 ± 0.034 |
Full table, with the time per epoch: molecular_results.md.
Samplers and loaders¶
PyG's own neighbour samplers, GraphSAINT, ShaDow, ClusterData and knn / radius need compiled extensions (pyg-lib, torch_sparse, torch_cluster), so the samplers are checked against references that don't:
- Exactly, in the test suite:
RandomNodeLoader,ClusterLoader,DynamicBatchSamplerandImbalancedSampleragainst PyG's pure-Python classes; ShaDow subgraphs and full-fan-outNeighborLoaderagainst PyG'sk_hop_subgraph;knn/radiusagainst SciPy's KD-tree;KNNGraph/RadiusGraphagainst PyG's transforms. - Statistically: every seed node or item covered exactly once per epoch (
NeighborLoader,LinkNeighborLoader,ShaDowKHopSampler,RandomNodeLoader,ClusterLoader); uniform neighbour sampling (chi-squared tests on the highest-degree nodes of Cora); class balance ofImbalancedSampler; batch budgets ofDynamicBatchSampler; and the bias of GraphSAINT's normalizations. - By training: a 2-layer GraphSAGE trained with each mini-batch method against full-batch training.
Every mini-batch method lands within one standard deviation of full-batch training (test accuracy in %, 5 seeds):
| Training | Cora | PubMed |
|---|---|---|
| Full batch, PyG | 80.3 ± 0.7 | 76.9 ± 0.8 |
| Full batch, mlx-graphs | 80.2 ± 0.7 | 77.3 ± 0.8 |
NeighborLoader [10, 10] |
80.3 ± 0.9 | 76.6 ± 0.4 |
GraphSAINTRandomWalkSampler |
80.3 ± 1.1 | 77.0 ± 0.9 |
ClusterLoader (20 parts, 5 per batch) |
79.4 ± 1.4 | 76.9 ± 0.6 |
ShaDowKHopSampler (depth 2, 10) |
80.2 ± 0.8 | 76.9 ± 0.5 |
For link prediction, LinkNeighborLoader reaches a test AUC of 84.3 ± 1.4 % on Cora (full batch: 84.4 ± 3.2 % in mlx-graphs, 83.3 ± 1.6 % in PyG) and 89.2 ± 0.7 % on PubMed (full batch: 90.1 % in both). Full results: sampler_results.md.
Large graphs¶
Results of benchmarks/quality/ for the large datasets, temporal neighbour sampling and the memory-mapped feature store (Apple M5 Pro, 64 GB, shared with other jobs, so the times are indicative). Full results: large_graph_results.md.
The datasets are identical to PyG's. dataset_parity.py loads Flickr, Reddit, Reddit2, Yelp, AmazonProducts and PPI with both libraries and compares the edges (in the same order), features, labels and split masks: all equal. PPI is read from the GraphSAGE release (DGL's server, which PyG uses, is down) and gives exactly PyG's 20 / 2 / 2 graphs.
GraphSAGE mini-batch training (2 layers, NeighborLoader with fan-outs [25, 10], batches of 1,024; PyG on the CPU with 8 threads):
| Dataset | Framework | Seeds × epochs | Test accuracy | s / epoch |
|---|---|---|---|---|
| Flickr | mlx-graphs | 3 × 10 | 0.5095 ± 0.0001 | 3.6 |
| Flickr | mlx-graphs, MemmapFeatureStore |
3 × 10 | 0.5101 ± 0.0026 | 8.7 |
| Flickr | PyG | 3 × 10 | 0.5120 ± 0.0015 | 11.5 |
| mlx-graphs | 1 × 3 | 0.9558 | 27.6 | |
| PyG | 1 × 3 | 0.9583 | 79.7 |
Temporal sampling (temporal_sampler_quality.py, a random graph of 20,000 nodes and 400,000 timestamped edges): with temporal_strategy="last", the mini-batches are identical to PyG's with pyg-lib (8 of 8, with node- and edge-level time); neither library samples an edge later than its seed; with "uniform", the sampling frequencies are as close to uniform as PyG's (mean deviation 0.0267 against 0.0266 with node-level time, no seed rejected by a chi-squared test in either). pyg-lib's C++ sampler is 1.2 to 2.3 times faster than the vectorized numpy one.
Memory-mapped features (feature_store_memory.py): a NeighborLoader over a MemmapFeatureStore of 6.1 GB (1.5M nodes × 1,024 features) and a MemmapGraphStore gathers 250 MB of features per mini-batch and peaks at 2.8 GB of resident memory over 100 mini-batches, where loading the features in a GraphData would take 6.1 GB. See the large graphs guide.
Temporal graph networks¶
TGN link prediction on JODIE Wikipedia, examples/tgn_jodie.py against PyG's examples/tgn.py, with the same hyperparameters, 8 epochs, seeds 0 and 1:
| Run | Test AP, seeds 0 / 1 | Test AUC, seeds 0 / 1 |
|---|---|---|
| mlx-graphs | 0.957 / 0.955 | 0.953 / 0.951 |
| PyG | 0.950 / 0.949 | 0.946 / 0.948 |
PyG with the torch-scatter scatter_argmax |
0.952 / 0.952 | 0.949 / 0.952 |
Without torch-scatter, PyG's fallback scatter_argmax gives empty groups the index dim_size - 1, so its LastAggregator copies an unrelated message to the nodes that have none instead of zeros. mlx-graphs follows the torch-scatter semantics, so the comparison also runs PyG with that function patched. Results: results.json. The TGN tutorial compares the two in more detail.
Temporal Graph Benchmark¶
The TGB datasets are checked against the official py-tgb package (tests/datasets/test_tgb.py): for tgbl-wiki, tgbl-review, tgbn-trade and tgbn-genre, the events (src, dst, t, msg, w), the split masks, the negative samples of every validation and test event and the node label streams are identical to py-tgb's. The large datasets (tgbl-coin, tgbl-comment, tgbl-flight, tgbn-reddit, tgbn-token) are checked on the first 200,000 events of their raw files (benchmarks/tgn_comparison/check_tgb_slices.py), without their negative samples. TGBEvaluator returns the same MRR, Hits@10 and NDCG@10 as py-tgb's evaluators, ties included.
TGN with the TGB protocol (examples/tgn_tgbl.py / tgn_tgbn.py against py-tgb's PyG TGN examples, benchmarks/tgn_comparison/compare_tgb.py), same hyperparameters, 10 epochs, seeds 1 to 5 (mean ± sample std; time per epoch on a shared M-series machine, PyG on the CPU with 4 threads):
| Run | Val | Test | Train s/epoch | Val s/epoch |
|---|---|---|---|---|
tgbl-wiki MRR, mlx-graphs |
0.312 ± 0.039 | 0.281 ± 0.042 | 6.5 | 2.0 |
tgbl-wiki MRR, PyG |
0.275 ± 0.062 | 0.253 ± 0.062 | 15.6 | 10.7 |
tgbn-trade NDCG@10, mlx-graphs |
0.394 ± 0.002 | 0.374 ± 0.003 | 7.2 | 1.0 |
tgbn-trade NDCG@10, PyG |
0.388 ± 0.009 | 0.368 ± 0.010 | 9.8 | 2.1 |
The differences are within seed noise (Welch's t-test: p = 0.30 and 0.43 for the tgbl-wiki validation and test MRR, p = 0.24 and 0.27 for tgbn-trade). On tgbl-wiki both are still improving at epoch 10, the best epoch is 9 or 10 in every run, and the MRR at a fixed early epoch varies a lot with the seed (validation 0.25 to 0.35 in mlx-graphs, 0.18 to 0.34 in PyG). PyG scores the events of a mini-batch together; on the same seed this gives the same MRR as the edge-by-edge loop of the TGB example (val 0.0513, test 0.0559 after one epoch), whose validation pass takes 275 s instead of 7 s. Results: results_tgb.json.
GPS on Peptides-func¶
GPSConv (examples/graph_gps_peptides.py) against a PyG twin of the same model: 4 GPS layers (GINE and 4-head attention), the same data with random-walk encodings, Adam (lr 1e-3, L2 1e-5), 10 epochs, seeds 0 and 1. Average precision over the 10 tasks:
| Run | Final train loss | Best val AP | Test AP |
|---|---|---|---|
| PyG, seed 0 | 0.2522 | 0.4044 | 0.3881 |
| PyG, seed 1 | 0.2613 | 0.4194 | 0.4079 |
| mlx-graphs, seed 0 | 0.2588 | 0.4447 | 0.4288 |
| mlx-graphs, seed 1 | 0.2553 | 0.4437 | 0.4268 |
The full-model gradient check (above) gives the same loss and gradients within ~1 %. Details: benchmarks/gps_peptides.
to_hetero on DBLP¶
benchmarks/to_hetero/compare_dblp.py trains to_hetero(GraphSAGE) and to_hetero(GAT) for author classification on DBLP, full batch, in both frameworks with the same data, architecture and optimizer (AdamW, lr 0.005, weight decay 0.001), and reports the test accuracy at the best validation epoch over several seeds. Mini-batch training (NeighborLoader, HGTLoader) runs in mlx-graphs only, since PyG's heterogeneous samplers need pyg-lib or torch-sparse. Its results are not committed to the repository. The models it converts are also checked with copied weights in tests/nn/test_to_hetero.py, including on the full DBLP and IMDB graphs.
Remaining mismatches¶
Three node classification configurations don't pass.
PNAConv on Cora (-4.6) and CiteSeer (+6.8). The gaps have opposite signs. PNAConv on raw features, with amplification scalers, trains with large loss spikes in both frameworks: PyG's seed 0 on PubMed jumps to a loss of 3.0, and mlx-graphs' seed 3 to 4.9 near the end. With copied weights on PubMed, the layer's output and input gradients agree with PyG's to 1e-4 and 1e-8 (relative ~1e-3): the layer computes the same function, which points to the unstable training rather than to the layer. The PubMed row passes (-0.2), and so do the PNA model on Cora and CiteSeer (+1.7, +3.1) and PNA on MUTAG and PROTEINS.
DirGNNConv(GCNConv) on CiteSeer (+1.8). mlx-graphs is ahead: 68.7 ± 1.4 % against PyG's 66.9 ± 0.7 %, beyond 1 point and twice PyG's small standard deviation. The training losses are close (0.006 / 0.008 over epochs 25-75, 0.011 / 0.008 at the end, PyG / mlx-graphs), the Cora (+0.6) and PubMed (-0.4) rows pass, and with copied weights the layer gives the same outputs as PyG's DirGNNConv (tests/nn/conv/test_dir_gnn_conv.py). No cause has been identified.
Bugs found and fixed¶
Found by the training and sampler comparisons, each fixed with a regression test:
SAGEConvwith a non-linear aggregation ("max","min","std", lists, modules) and more input than output features projected the features before aggregating (max(W x)instead of PyG'sW max(x)), a trick only valid for sum and mean. Max error against PyG with copied weights: 1.7.- Lists of aggregations:
SAGEConvcrashed, andGENConvdid not accept them. Both now size their projections like PyG's. The other layers with a projection after the aggregation crashed with a shape error, or forGATConv/GATv2Convreturned twice as many rows; they now refuse concatenating lists with a clear error (supports_concat_aggr). - NaN gradients from L2 norms at zero in
AGNNConv,MessageNormandGENConv(msg_norm=True): a node whose features are all zero (common after ReLU and dropout) made every gradient NaN. Seen as AGNN on PubMed going NaN at epoch 145, and GENConv with MessageNorm reaching 66 % instead of 79 % on Cora (one seed). MixHopConvstored its per-power layers in a dict thatload_weightscould not load.AddLaplacianEigenvectorPEdid not converge on Cora (float64 eigensolver on float32 values).DirGNNConv(GCNConv(...)), PyG's usual way to build it, raised an error.DirGNNConv(SAGEConv)trained 2-3 points below PyG with twice its training loss:SAGEConvhad noroot_weight, so both directions kept a root projection.SAGEConvnow has PyG'sroot_weight, and the rows pass (+0.9 / +0.7 / +0.5).TUDatasetdropped edge labels (e.g. MUTAG's bond types) and did not reorder edge features with the edges. MUTAG, PROTEINS and NCI1 now equal PyG's arrays.IMDBstored its labels under"movies"instead of the"movie"node type.HeteroDictLinear(used byHGTConv) initialized with Glorot weights instead oftorch.nn.Linear's: HGT on DBLP reached 76.9 ± 2.3 % against PyG's 71.8 ± 1.8 %. With PyG's initialization it reaches 73.0 ± 2.5 %.GINEConv's edge projection was also initialized with Glorot weights (GINE on MUTAG: 80.0 ± 10.5 % before the fix, 82.0 ± 7.1 % after, 78.0 ± 13.6 % in PyG).- GraphSAINT's
edge_normused the count of the edge's source node, as PyG does, instead of its target (the paper's definition). On Cora, the median relative error of the normalized aggregation was about 50 % with the source count; with the target count it is sampling noise that shrinks withsample_coverage.
Other differences from PyG fixed in the same release (see the changelog):
LayerNormalization(mode="graph")gave wrong shapes with batch indices, andmode="node"ignored its ownweightandbias. Both now match PyG'sLayerNorm.- Max and min aggregations gave the full gradient to every tied value (e.g. the identical messages of duplicate edges). They now split it equally, as PyG does.
MultiAggregation(mode="std")had a NaN gradient for sets of a single element.GINandEdgeCNNdid not apply the model'sactandnormto the MLPs inside their convolutions, as PyG does.
Where mlx-graphs differs from PyG on purpose¶
- GraphSAINT normalization: target count in
edge_norm(see above). - GraphSAINT edge sampler: mlx-graphs samples edges with the paper's probabilities, \(1/\deg(u) + 1/\deg(v)\). PyG's
GraphSAINTEdgeSamplercomputes the inverse weighting, which favours edges between hubs. At the same number of edges, the paper's probabilities give a 3.5-4.4x smaller standard deviation of the estimated aggregation. - DynamicBatchSampler with
skip_too_big=Trueyields every graph once; PyG re-yields the graphs that follow a skipped one. Withoutskip_too_big, the batches are the same as PyG's. - TGN's
LastAggregatorgives zeros to nodes without messages, as PyG does with torch-scatter (see above). - TopK and SAG pooling break ties between equal scores differently. Both are valid, and training quality is the same.
Reproducing¶
Install the test and benchmark dependencies (some harnesses also use scikit-learn), then run:
pip install -e '.[test,benchmarks]'
# layer-level parity (add --datasets for the slow tests that download data)
pytest tests
# node classification (--configs gcn arma ... for a subset, --summarize for the table only)
python benchmarks/quality/node_quality.py
# graph-level, heterogeneous, link and KG models (--groups tu kge ... for a subset)
python benchmarks/quality/graph_quality.py
# hierarchical and dense pooling on PROTEINS (--models diffpool asap ... for a subset)
python benchmarks/quality/pooling_quality.py
# PointNet++ and DGCNN on ModelNet10 (--models pointnet2 --epochs 5 for a subset)
python benchmarks/quality/pointcloud_quality.py
# SchNet and DimeNet++ on QM9, AttentiveFP on ESOL (--tasks attentivefp for a subset)
python benchmarks/quality/molecular_quality.py
# large graphs: datasets equal to PyG's, GraphSAGE training, temporal sampling, feature store
python benchmarks/run_capped.py --gb 24 -- python benchmarks/quality/dataset_parity.py \
--data-dir .mlx_graphs_data --datasets flickr reddit2 yelp reddit ppi amazon_products
python benchmarks/run_capped.py --gb 16 -- python benchmarks/quality/large_graph_training.py \
--datasets flickr --seeds 0 1 2 --epochs 10
PYTHONPATH=<pyg-lib dir> python benchmarks/quality/temporal_sampler_quality.py
python benchmarks/quality/feature_store_memory.py --dir /tmp/fs_bench \
--num-nodes 1500000 --num-features 1024
# samplers and loaders (about 15 minutes)
python benchmarks/run_capped.py --gb 6 -- python benchmarks/quality/sampler_quality.py \
--data-dir .mlx_graphs_data --seeds 0 1 2 3 4
# TGN on JODIE Wikipedia
python benchmarks/tgn_comparison/compare.py --data <data_dir> --epochs 8
# GPS on Peptides-func: export the data, train both, check the gradients
python benchmarks/gps_peptides/export_npz.py <data_dir>
python examples/graph_gps_peptides.py --data_dir <data_dir> --epochs 10 --seed 0
python benchmarks/gps_peptides/gps_pyg.py --data_dir <data_dir> --epochs 10 --seed 0
python benchmarks/gps_peptides/grad_parity.py <data_dir>
# to_hetero on DBLP
python benchmarks/to_hetero/compare_dblp.py --data_dir .mlx_graphs_data
Note
The harnesses run every configuration in its own process under a hard memory cap, and kill it above the cap: 6 GB by default for the node and graph harnesses (--memory-gb), 4 GB for the TGN and to_hetero comparisons. The memory is the process' physical footprint, as shown by Activity Monitor, which, unlike RSS, includes the GPU (Metal) allocations of MLX and PyTorch MPS. Run any other script the same way with python benchmarks/run_capped.py --gb <cap> -- <command>. Mini-batches of varying shapes make MLX's buffer cache grow: the sampler harness caps it with mx.set_cache_limit.
The node and graph harnesses append one line per run to node_results.jsonl / graph_results.jsonl and skip the runs already there, so an interrupted run resumes where it stopped.
Not covered¶
- Training quality on the largest graphs (AmazonProducts, Yelp, ogbn): out of the memory budget of these checks; Flickr and Reddit are covered above. They are part of the speed Benchmarks, which also record accuracy.
- Mini-batch training in the node classification harness, which trains full batch only. Mini-batch training is checked for GraphSAGE by the sampler harness, and for
to_heteromodels in mlx-graphs only. - PyG's compiled samplers and operations: PyG's neighbour samplers, GraphSAINT, ShaDow,
ClusterData(METIS),DynamicEdgeConvandknn_graphneedpyg-lib,torch_sparseortorch_cluster, which were not installed. The samplers were checked against references instead, andClusterLoaderwas trained with the dependency-free balanced partitioner, not METIS. - NCI1 graph classification, which did not fit in the time budget.
- Converged knowledge graph embeddings: the KGE models trained for 20-40 epochs instead of PyG's 500, so the comparison covers the early training trajectories, not converged models.
- Attention variants of GeneralConv on CiteSeer and PubMed (Cora only).
- Compilation:
mx.compilefor mlx-graphs andtorch.compilefor PyG.