Berlin Tech Meetup: The Future of Relational Foundation Models, Systems, and Real-World Applications

Register now:
PyG/Guide7 min read

Graph Partitioning: Dividing Large Graphs for Distributed Processing

A graph with 100 million nodes and a billion edges does not fit on one GPU. Graph partitioning splits it into manageable pieces while minimizing the cross-partition edges that require expensive inter-machine communication.

PyTorch Geometric

TL;DR

  • 1Large graphs (millions to billions of nodes) must be split across machines. Graph partitioning divides the graph into balanced subgraphs while minimizing cross-partition edges (which require inter-machine communication).
  • 2METIS is the standard algorithm: coarsen the graph, partition the small graph, uncoarsen and refine. It minimizes edge cuts while balancing partition sizes. PyG integrates METIS via ClusterData.
  • 3Cross-partition edges create a tradeoff: more partitions mean smaller subgraphs (faster per-machine) but more cross-partition communication (slower overall). The optimal partition count depends on graph structure and hardware.
  • 4Halo expansion mitigates boundary effects: include 1-2 hop neighbors from adjacent partitions. This gives boundary nodes their full message passing neighborhood at the cost of redundant storage.
  • 5Partitioning is complementary to neighbor sampling. Partition first for distributed storage, then sample within partitions for mini-batch training.

Graph partitioning is the foundation of distributed graph neural network training. A social network with 100 million users, a financial transaction graph with a billion edges, an enterprise database with 50 million rows: these graphs exceed the memory of any single machine. Partitioning splits them into pieces that fit on individual machines while preserving as much local graph structure as possible.

The partitioning problem

Given a graph G with N nodes and E edges, partition it into k subgraphs such that:

  1. Balance: each partition has approximately N/k nodes (no partition is much larger than others)
  2. Minimum edge cut: as few edges as possible cross partition boundaries

These objectives often conflict. Perfectly balanced partitions may cut many edges. Minimizing edge cuts may create imbalanced partitions (one large community stays together). Algorithms find practical tradeoffs.

Why edge cuts matter for GNNs

During message passing, each node aggregates from its neighbors. If a neighbor is in a different partition (on a different machine), the message must be communicated over the network. This inter-machine communication is orders of magnitude slower than local memory access.

Minimizing edge cuts minimizes inter-machine communication. If 95% of edges are within partitions, only 5% of messages require network communication.

METIS: the standard algorithm

METIS uses a three-phase multilevel approach:

  1. Coarsening: iteratively collapse pairs of connected nodes into super-nodes, reducing the graph size by 50% each round. After 5-10 rounds, the graph has thousands (not millions) of nodes.
  2. Partitioning: partition the small coarsened graph using a simple algorithm (e.g., recursive bisection). This is fast because the graph is small.
  3. Uncoarsening: expand super-nodes back to original nodes, refining the partition at each level using local search (swap nodes between partitions to reduce edge cuts).

METIS runs in O(|E|) time and produces high-quality partitions. It is the default choice for graph partitioning in most GNN frameworks.

Halo expansion

Nodes at partition boundaries lose some neighbors (those in other partitions). For a 2-layer GNN, boundary nodes need their 2-hop neighborhood to be complete. Halo expansion addresses this:

  • For each partition, include all nodes within k hops of the partition boundary (where k = number of GNN layers)
  • These “halo nodes” are stored redundantly (they exist in their home partition AND as halos in adjacent partitions)
  • During message passing, halo nodes provide the full neighborhood context for boundary nodes

The tradeoff: halo expansion increases storage (redundant node copies) and requires halo synchronization (updating halo node embeddings between layers). But it eliminates the accuracy loss from partition boundaries.

Partitioning strategies beyond METIS

  • Random partitioning: assign nodes randomly. Simple but high edge cut. Useful as a baseline.
  • Hash-based partitioning: partition by hashing node IDs. Simple, deterministic, but ignores structure.
  • Community-based: detect communities first (Louvain), then assign each community to a partition. Low edge cut but potentially imbalanced.
  • Streaming partitioning: for graphs that arrive as edge streams, assign nodes as they arrive. Does not require the full graph in memory.

Frequently asked questions

Why is graph partitioning necessary?

Large graphs (millions to billions of nodes) do not fit in the memory of a single GPU or machine. Partitioning splits the graph into smaller subgraphs that can be processed independently on different machines. The challenge is minimizing cross-partition edges (which require inter-machine communication during message passing) while keeping partition sizes balanced.

What is the METIS algorithm?

METIS is the most widely used graph partitioning algorithm. It uses a multilevel approach: (1) coarsen the graph by collapsing connected nodes, (2) partition the small coarsened graph, (3) uncoarsen and refine. METIS minimizes edge cuts (edges that cross partition boundaries) while balancing partition sizes. PyG integrates METIS through the ClusterData and ClusterLoader classes.

How does graph partitioning affect GNN accuracy?

Partitioning introduces approximation: nodes near partition boundaries lose some of their neighbors (in other partitions). This means message passing does not see the full neighborhood. The effect is small if partitions are large relative to the GNN's receptive field (2-3 hops). Halo expansion (including 1-2 hop neighbors from adjacent partitions) mitigates this at the cost of some redundant computation.

What is the difference between partitioning and neighbor sampling?

Partitioning splits the graph once into fixed subgraphs. Neighbor sampling dynamically samples a different subgraph around each target node at each training step. Partitioning is deterministic and reusable; sampling introduces variance but sees different subgraphs each epoch. For very large graphs, both can be combined: partition first, then use neighbor sampling within partitions.

Learn more about graph ML

PyTorch Geometric is the open-source foundation for graph neural networks. Explore more layers, concepts, and production patterns.