Skip to content

Tutorials

Guides to the parts of mlx-graphs you build on, and Jupyter notebooks that train complete models, most of them side by side with PyTorch Geometric on accuracy and runtime. New to mlx-graphs? Start with the Quickstart.

Guides

  • Writing your own layers


    The MessagePassing contract, aggregations, attention layers, fused message passing, and how to check a layer against PyG.

  • Custom GPU kernels


    Fuse an operation of your own in Metal, with gradients, a fallback, tests and a benchmark: a per-edge score whose forward pass runs about 5.5x faster than with MLX operations on 2 million edges (M5 Pro).

  • Large graphs


    Train on graphs larger than the memory with memory-mapped feature stores, and sample neighborhoods that respect time.

  • Datasets


    The built-in datasets, their sizes and how to load them, and how to add your own.

Notebooks

Each page shows the notebook with the outputs of its last run; download it to run it yourself.

Graph classification

Classify the MUTAG molecules with a GCN, mini-batches and global pooling.

beginnergraph-level

Node2Vec

Node embeddings from biased random walks on Cora, sampled on the GPU, compared with PyG.

embeddings

MetaPath2Vec

Embeddings of a heterogeneous graph from meta-path guided random walks, on a toy graph and on DBLP.

embeddingsheterogeneous

Mini-batch training on large graphs

Train on ogbn-arxiv one subgraph at a time with NeighborLoader, ClusterLoader and GraphSAINT.

scalingsamplers

Link prediction

Split edges without leakage, train a GCN encoder and dot-product decoder, rank with LinkPred metrics.

edge-levelvs PyG

Temporal graph networks

A TGN with memory, trained on the JODIE Wikipedia stream of events, against PyG.

temporalvs PyG

Heterogeneous graphs with to_hetero

Turn a homogeneous GraphSAGE or GAT into a heterogeneous model on DBLP, as in PyG.

heterogeneousvs PyG

Graph transformers with GPS

GPSConv with random-walk encodings on Peptides-func, plus Performer, SGFormer and Polynormer.

transformersvs PyG

GNNs for cybersecurity

Intrusion detection on provenance graphs, anti-money laundering, network flows and malware classification.

applications

Graph RAG with G-reasoner

Run the G-reasoner checkpoint with a custom Metal kernel as the retriever of a local LLM.

applicationsLLM

Molecular properties on QM9

Predict quantum-chemical properties of small molecules with a GNN.

chemistrygraph-level

Example scripts

The examples/ folder of the repository has runnable scripts that train models end to end from the command line: node classification, GCN and GAT on Cora, link prediction, heterogeneous GraphSAGE, MetaPath2Vec, TGN on JODIE and TGB, GPS, PointNet++ and more. See all the example scripts.