Scientific
gnn
graph nn

Graph Machine Learning

Graph neural networks for molecular property prediction, social networks, knowledge graphs.

Setup walkthrough

  1. pip install torch-geometric (PyG — the standard library for graph neural networks, GNNs).
  2. For node classification (e.g., predict paper categories in a citation network):
from torch_geometric.datasets import Planetoid
from torch_geometric.nn import GCNConv
import torch

dataset = Planetoid(root="/tmp/Cora", name="Cora")  # citation network, 2,708 nodes
class GCN(torch.nn.Module):
    def __init__(self):
        super().__init__()
        self.conv1 = GCNConv(dataset.num_features, 16)
        self.conv2 = GCNConv(16, dataset.num_classes)
    def forward(self, data):
        x = self.conv1(data.x, data.edge_index).relu()
        return self.conv2(x, data.edge_index)

model = GCN()
optimizer = torch.optim.Adam(model.parameters(), lr=0.01)
for epoch in range(200):
    out = model(dataset[0])
    loss = torch.nn.functional.cross_entropy(out[dataset[0].train_mask], dataset[0].y[dataset[0].train_mask])
    loss.backward(); optimizer.step()
  1. First training in 30-60 seconds on GPU for Cora (small graph). 200 epochs on Cora: ~10-20 seconds.
  2. For molecular property prediction: PyG has built-in datasets (QM9, ZINC) and molecular GNN architectures (GIN, SchNet).
  3. For large-scale graphs (10M+ nodes): use GraphSAGE sampling or DGL (Deep Graph Library) with mini-batch training.

The cheap setup

Graph ML is modestly demanding. Cora (2,708 nodes) trains in <20 seconds on a $300 laptop CPU. For medium graphs (100K nodes, 1M edges): a used GTX 1060 6 GB (~$60) trains a GCN/GAT in 5-15 minutes. For molecular graphs (QM9, 130K molecules): training GIN on 12 GB GPU in 30-60 minutes. Pair with Ryzen 5 5600 + 32 GB DDR4 + 512 GB NVMe. Total: ~$320-370. Graph ML is often CPU-bound (graph loading, neighborhood sampling) rather than GPU-bound. Fast CPU + decent GPU is the sweet spot.

The serious setup

Used RTX 3090 24 GB (~$700-900, see /hardware/rtx-3090). Handles large graphs: OGB-LSC (2.5M nodes, 100M+ edges) trains in 2-6 hours on a single GPU. For knowledge graph reasoning, molecular dynamics simulation, and social network analysis: 24 GB VRAM enables full-batch training on medium-large graphs (1-5M nodes). For very large graphs (10M+ nodes): mini-batch + sampling strategies dominate — the GPU trains on sampled subgraphs. Total: ~$1,800-2,200. Graph ML at scale is limited by graph loading and sampling overhead, not raw GPU compute. Invest in a fast NVMe SSD and high-bandwidth RAM.

Common beginner mistake

The mistake: Using a GCN (Graph Convolutional Network) for every graph problem, including heterophilic graphs where connected nodes have different labels (e.g., transaction fraud graphs where fraudsters connect to legitimate users). Why it fails: GCN assumes homophily — connected nodes are similar. It smooths node features across edges. On a fraud graph, GCN averages fraudster features with legitimate user features → both become ambiguous → the classifier can't distinguish them. GCN performs worse than a simple MLP (ignoring the graph entirely) on heterophilic datasets. The fix: Check your graph's homophily ratio before choosing a model. High homophily (>0.7): GCN, GAT, GraphSAGE work well. Low homophily (<0.3): use H2GCN, GPRGNN, or ACM-GCN which are designed for heterophilic graphs. Or use an MLP as a baseline — if MLP beats GNN, your graph structure is misleading the model. Graph structure can hurt as much as it helps. Measure, don't assume.

Recommended setup for graph machine learning

Recommended runtimes

Browse all tools for runtimes that fit this workload.

Reality check

Local AI workloads have real hardware constraints that vary by task type. VRAM ceiling decides what model fits; bandwidth decides decode speed; compute decides prefill speed. Pick the GPU tier that fits your actual workload, not the spec sheet.

Common mistakes

  • Buying for spec-sheet VRAM without modeling KV cache + activation overhead
  • Underestimating quantization quality loss below Q4
  • Skipping flash-attention support (real perf gap on long context)
  • Ignoring sustained-load thermals (laptops thermal-throttle within 30 min)

What breaks first

The errors most operators hit when running graph machine learning locally. Each links to a diagnose+fix walkthrough.

Before you buy

Verify your specific hardware can handle graph machine learning before committing money.

Specialized buyer guides
Updated 2026 roundup