Tuple Packing: Efficient Batching of Small Graphs in Graph Neural Networks

Mario Michael Krell, Manuel Lopez Roldan, Sreenidhi Anand, Hatem Helal, Andrew William FitzgibbonarXiv 2022 · DOI

Introduction

In the landscape of deep learning, computational efficiency is a primary driver of progress. While Natural Language Processing (NLP) has long utilized "sequence packing" to optimize training throughput, Graph Neural Networks (GNNs) have faced unique challenges in achieving similar density. Researchers from Graphcore recently introduced Tuple Packing, a hardware-agnostic methodology designed to minimize wasted computation when processing batches of small, heterogeneously sized graphs.

The Padding Problem in GNNs

Modern hardware accelerators, such as GPUs and IPUs, perform optimally with "static shapes"—fixed-size input tensors. However, real-world graph datasets are inherently irregular; a single dataset may contain graphs ranging from a few nodes to hundreds. To accommodate this on static-shape hardware, multiple graphs are typically aggregated into a single "super-graph" batch.

The traditional approach involves padding every batch to the maximum possible number of nodes and edges found in the dataset. This results in a significant "padding tax"—empty space that consumes memory and compute cycles without contributing to learning. In many large-scale molecular datasets, this inefficiency can result in hardware utilization as low as 60%.

Tuple Packing: A 2D Bin-Packing Solution

Tuple Packing addresses this by reframing batching as a 2D bin-packing problem. Unlike NLP, which primarily manages a 1D constraint (sequence length), GNNs must simultaneously satisfy two constraints: the number of nodes ($|V|$) and the number of edges ($|E|$).

The proposed method employs several key innovations:

  • Histogram-Based Packing: To avoid the overhead of sorting individual graphs, the algorithm operates on a 2D histogram of graph sizes. This allows the packing process to complete in milliseconds, even for large datasets.
  • Monotone Heuristics: The system uses priority heuristics (such as the sum or product of tuple values) to determine the optimal combination of graphs to fill a batch "bin" as densely as possible.
  • Optimized Batch Limits: A counter-intuitive finding of the research is that setting batch limits slightly higher than the maximum graph size in the dataset can significantly improve overall efficiency. This extra "headroom" provides the packing algorithm with more flexibility to combine smaller graphs.

Leveraging Structural Correlations

A critical insight of the paper is the strong correlation between node and edge counts in many real-world datasets, particularly in molecular chemistry. Tuple Packing exploits this linear relationship to find optimal fits that 1D packing strategies would overlook.

Figure 5: The distribution of nodes and edges in the ogbg-molpcba dataset shows a strong linear correlation, which Tuple Packing exploits for efficient batching.

As seen in the distribution for ogbg-molpcba, the density of samples follows a predictable path, allowing the packing algorithm to create batches that are nearly 100% full in both dimensions simultaneously.

Figure 6: Similar to molpcba, the ogbg-molhiv dataset exhibits a tight correlation between node and edge counts, facilitating high-density packing.

Performance and Results

The researchers evaluated Tuple Packing across several Open Graph Benchmark (OGB) datasets and the large-scale PCQM4Mv2 dataset. The results demonstrate substantial improvements:

  • Efficiency: On PCQM4Mv2, edge efficiency jumped from ~58% with standard batching to 98.8% using Tuple Packing with optimized limits.
  • Throughput: The method provided an average 1.15x speedup over classical 1D packing across various OGB benchmarks.
  • Generality: While developed by Graphcore, the technique is hardware-agnostic and provides performance benefits for any system that relies on static-shape execution, including NVIDIA GPUs.

Conclusion

Tuple Packing represents a significant step forward in making GNN training as efficient as modern NLP pipelines. By treating graph batching as a multi-dimensional packing problem and exploiting the inherent structural correlations in graph data, researchers can drastically reduce the "padding tax." Future work will focus on automating the search for optimal batch limits and extending the algorithm to handle datasets with higher variance in graph topology.

Summary updated

BibTeX
@misc{krell2022tuple,
  author = {Mario Michael Krell and Manuel Lopez Roldan and Sreenidhi Anand and Hatem Helal and Andrew William Fitzgibbon},
  title = {{Tuple Packing: Efficient Batching of Small Graphs in Graph Neural Networks}},
  year = {2022},
  eprint = {2209.06354},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2209.06354},
}
Figure