Skip to content

Benchmarks

MLX-graphs is compared with PyTorch Geometric (PyG) on the same Mac, on both PyTorch backends: MPS (the Apple GPU) and CPU. Every framework trains the same models, with the same hyperparameters, on the same data, and the training loss and test accuracy are recorded alongside the times: being faster only counts at the same results.

Each section below is one machine. Click a figure to see it at full size.

Apple M5 Pro

Apple M5 Pro, 64 GB, macOS 27.2.1 · mlx-graphs 0.1.0 (c5f1246) · mlx 0.32.4 · PyTorch 2.15.0 · PyG 2.8.1

mlx-graphs trains GNNs 5.6× faster than PyG on the Mac's GPU (MPS) and 5.8× faster than PyG on the CPU (median over 35 training benchmarks, up to 58×), and reaches the same accuracy.

Time of PyG on MPS and on CPU relative to mlx-graphs for one layer, node classification and graph classification, and the test accuracy of each framework

Time of PyG on MPS and on CPU relative to mlx-graphs for one layer, node classification and graph classification, and the test accuracy of each framework

One layer

One convolution layer, forward + backward, on random graphs with 128 input and output features (4 heads for GAT and GATv2).

Forward and backward time per layer and graph size, relative to mlx-graphs, for mlx-graphs, PyG on MPS and PyG on CPU

Forward and backward time per layer and graph size, relative to mlx-graphs, for mlx-graphs, PyG on MPS and PyG on CPU

Peak memory per layer on the largest graph, for mlx-graphs, PyG on MPS and PyG on CPU

Peak memory per layer on the largest graph, for mlx-graphs, PyG on MPS and PyG on CPU

Node classification

Full-batch training of 2-layer models (64 hidden units, Adam, lr 0.01), the whole graph at every step.

Node classification: time per training epoch per dataset and model, for mlx-graphs, PyG on MPS and PyG on CPU

Node classification: time per training epoch per dataset and model, for mlx-graphs, PyG on MPS and PyG on CPU

Same training, same results. The training loss of every framework at every epoch, overlaid, and the test accuracy reached at the epoch with the best validation accuracy.

Node classification: training loss per epoch for each dataset and model, mlx-graphs, PyG on MPS and PyG on CPU overlaid

Node classification: training loss per epoch for each dataset and model, mlx-graphs, PyG on MPS and PyG on CPU overlaid

Node classification: test accuracy per dataset and model, mean and range over seeds, for mlx-graphs, PyG on MPS and PyG on CPU

Node classification: test accuracy per dataset and model, mean and range over seeds, for mlx-graphs, PyG on MPS and PyG on CPU

Graph classification

3 layers + mean pooling, batches of 64 graphs, random 80/10/10 split. The time per epoch includes batching the graphs.

Graph classification: time per training epoch per dataset and model, for mlx-graphs, PyG on MPS and PyG on CPU

Graph classification: time per training epoch per dataset and model, for mlx-graphs, PyG on MPS and PyG on CPU

Same training, same results. The training loss of every framework at every epoch, overlaid, and the test accuracy reached at the epoch with the best validation accuracy.

Graph classification: training loss per epoch for each dataset and model, mlx-graphs, PyG on MPS and PyG on CPU overlaid

Graph classification: training loss per epoch for each dataset and model, mlx-graphs, PyG on MPS and PyG on CPU overlaid

Graph classification: test accuracy per dataset and model, mean and range over seeds, for mlx-graphs, PyG on MPS and PyG on CPU

Graph classification: test accuracy per dataset and model, mean and range over seeds, for mlx-graphs, PyG on MPS and PyG on CPU

Apple M1 Pro

Apple M1 Pro, 32 GB, macOS 27.0 · mlx-graphs 0.1.0 (c5f1246) · mlx 0.32.4 · PyTorch 2.15.0 · PyG 2.8.1

mlx-graphs trains GNNs 6.0× faster than PyG on the Mac's GPU (MPS) and 3.5× faster than PyG on the CPU (median over 34 training benchmarks, up to 125×), and reaches the same accuracy.

Time of PyG on MPS and on CPU relative to mlx-graphs for one layer, node classification and graph classification, and the test accuracy of each framework

Time of PyG on MPS and on CPU relative to mlx-graphs for one layer, node classification and graph classification, and the test accuracy of each framework

One layer

One convolution layer, forward + backward, on random graphs with 128 input and output features (4 heads for GAT and GATv2).

Forward and backward time per layer and graph size, relative to mlx-graphs, for mlx-graphs, PyG on MPS and PyG on CPU

Forward and backward time per layer and graph size, relative to mlx-graphs, for mlx-graphs, PyG on MPS and PyG on CPU

Peak memory per layer on the largest graph, for mlx-graphs, PyG on MPS and PyG on CPU

Peak memory per layer on the largest graph, for mlx-graphs, PyG on MPS and PyG on CPU

Node classification

Full-batch training of 2-layer models (64 hidden units, Adam, lr 0.01), the whole graph at every step.

Node classification: time per training epoch per dataset and model, for mlx-graphs, PyG on MPS and PyG on CPU

Node classification: time per training epoch per dataset and model, for mlx-graphs, PyG on MPS and PyG on CPU

Same training, same results. The training loss of every framework at every epoch, overlaid, and the test accuracy reached at the epoch with the best validation accuracy.

Node classification: training loss per epoch for each dataset and model, mlx-graphs, PyG on MPS and PyG on CPU overlaid

Node classification: training loss per epoch for each dataset and model, mlx-graphs, PyG on MPS and PyG on CPU overlaid

Node classification: test accuracy per dataset and model, mean and range over seeds, for mlx-graphs, PyG on MPS and PyG on CPU

Node classification: test accuracy per dataset and model, mean and range over seeds, for mlx-graphs, PyG on MPS and PyG on CPU

Graph classification

3 layers + mean pooling, batches of 64 graphs, random 80/10/10 split. The time per epoch includes batching the graphs.

Graph classification: time per training epoch per dataset and model, for mlx-graphs, PyG on MPS and PyG on CPU

Graph classification: time per training epoch per dataset and model, for mlx-graphs, PyG on MPS and PyG on CPU

Same training, same results. The training loss of every framework at every epoch, overlaid, and the test accuracy reached at the epoch with the best validation accuracy.

Graph classification: training loss per epoch for each dataset and model, mlx-graphs, PyG on MPS and PyG on CPU overlaid

Graph classification: training loss per epoch for each dataset and model, mlx-graphs, PyG on MPS and PyG on CPU overlaid

Graph classification: test accuracy per dataset and model, mean and range over seeds, for mlx-graphs, PyG on MPS and PyG on CPU

Graph classification: test accuracy per dataset and model, mean and range over seeds, for mlx-graphs, PyG on MPS and PyG on CPU

What is measured

  • One layer: one forward + backward pass of GCN, GraphSAGE, GIN, GAT and GATv2 on random graphs of 100k, 500k and 2M edges.
  • Node classification: full-batch training of GCN, GraphSAGE and GAT on Cora, CiteSeer, PubMed, Amazon Photo / Computers, Coauthor CS / Physics and ogbn-arxiv, 3 seeds.
  • Graph classification: mini-batch training of GCN, GraphSAGE and GIN on the TU datasets MUTAG, PROTEINS, NCI1 and DD, 3 seeds.

The scripts are in benchmarks/pyg_comparison. Its README describes how the comparison is kept fair, and every number of the figures is in a table in the results.md file next to them.

Reproducing

pip install -e '.[benchmarks]'
python benchmarks/pyg_comparison/run.py    # ~1.5 hours, results/<chip>/<version>/
python benchmarks/pyg_comparison/plot.py   # figures, results.md and this page's section

Every configuration runs in its own process under a 16 GB memory cap; a run over the cap is reported as out of memory.