Recurrent Aggregators in Neural Algorithmic Reasoning

Kaijia Xu, Petar Veličković

TL;DR

Standard Graph Neural Networks (GNNs) enforce permutation equivariance, treating all neighboring nodes symmetrically—a constraint that hurts performance on inherently ordered, sequential algorithmic tasks like sorting and searching. This paper introduces Recurrent Neural Algorithmic Reasoner (RNAR), which replaces permutation-invariant aggregators with an LSTM running over canonical node orderings. RNAR smashes previous records on notoriously difficult tasks, boosting Quickselect from under 20% to 87.08% and Heapsort to 93.07%.

What Problem Does This Paper Address?

Neural Algorithmic Reasoning (NAR) explores whether neural networks can learn to execute classical algorithms step-by-step and generalize out-of-distribution (OOD) to larger inputs. Modern reasoners rely on GNNs because their message-passing framework aligns naturally with dynamic programming.

To handle arbitrary graphs, standard GNN aggregators (e.g., sum or max) are strictly permutation invariant: they produce the same result regardless of the order in which neighbor messages arrive. However, many classical algorithms (such as sorting, searching, and list operations) operate on ordered lists, where element positions are fundamental to correctness. Imposing permutation symmetry forces the network to treat all neighbors identically, limiting model expressivity. The authors ask a simple, contrarian question: What happens if we deliberately break permutation invariance and process messages sequentially?

Methods

The authors propose RNAR (Recurrent Neural Algorithmic Reasoner):

  • Base Architecture: Built on top of the state-of-the-art Triplet-GMPNN architecture with hint reversals.
  • Recurrent Aggregator: Instead of aggregating incoming edge messages via a commutative monoid reduction (like max), RNAR feeds messages sequentially into a Long Short-Term Memory (LSTM) network.
  • Message Ordering: In a fully connected graph of $N$ nodes, each node $u$ receives $N$ messages ordered canonically by the algorithm's input list positions (provided by CLRS positional features). The LSTM runs for $N$ steps, and the hidden state at step $N$ serves as the aggregated neighborhood embedding.
  • Standard vs. Novel: While using LSTMs in GNN aggregators dates back to GraphSAGE, prior work either assumed random orderings or averaged over sampled permutations (e.g., Janossy pooling). RNAR directly embraces fixed canonical list orderings within modern NAR architectures featuring triplet representations and gating.

Datasets

The model is evaluated on the standard CLRS-30 benchmark, comprising 30 algorithmic tasks spanning sorting, searching, dynamic programming, graph algorithms, string matching, and computational geometry. Performance is measured using micro-$F_1$ score on out-of-distribution (OOD) test inputs that are larger than those seen during training.

Key Insights and Ideas

  • Symmetry isn't always the answer: Permutation invariance is an inductive bias designed for unordered sets. For sequential algorithms, enforcing symmetry needlessly restricts the model from learning directional, order-dependent logic.
  • A major breakthrough on open challenges: Quickselect has long been an Achilles' heel for neural reasoners (prior models achieved roughly 0.5%–19%). RNAR cracks this task, achieving 87.08%.
  • Modern backbones amplify recurrent benefits: Ablations show that coupling an LSTM aggregator with modern architectural components (triplet reasoning and gating) improves OOD performance by 11% compared to a vanilla MPNN baseline.
  • Explicit positional inputs still matter: Even though the LSTM's message processing sequence provides implicit order, retaining explicit positional features contributes an extra 5% average accuracy, largely helping resolve tie-breaking in graph algorithms.

Key Results

  • Sequential Tasks: RNAR outperforms its Triplet-GMPNN baseline on 8 out of 10 sequential tasks and establishes a new state-of-the-art on 6 of them:
  • Quickselect: 87.08% (vs. 0.47% Triplet-GMPNN, 19.18% Relational Transformers, 6.30% G-ForgetNet).
  • Heapsort: 93.07% (vs. 49.13% Triplet-GMPNN, 57.47% G-ForgetNet).
  • Quicksort: 94.73% (vs. 85.69% Triplet-GMPNN).
  • Bubble Sort: 95.78% (vs. 80.51% Triplet-GMPNN).
  • Find Max Subarray: 83.53% (vs. 76.36% Triplet-GMPNN).
  • Benchmark-Wide Performance: Across all 30 CLRS tasks, RNAR achieves an overall average of 75.78% (compared to 80.04% for Triplet-GMPNN and 82.89% for G-ForgetNet). Performance drops only slightly on non-sequential tasks, proving that non-commutative aggregation does not fatally break graph processing.
  • With RNAR's gains, only three tasks in CLRS-30 remain below 80% micro-$F_1$ across existing literature (Floyd-Warshall, Knuth-Morris-Pratt, and Strongly Connected Components).

Limitations and Future Work

  • Memory Constraints (OOM): Combining triplet message passing with recurrent aggregators causes out-of-memory errors on 4 tasks on a 16GB V100 GPU (requiring fallback to a simpler MPNN base without triplets).
  • Computational Overhead: Sequentially processing $N$ messages per node adds notable wall-clock training time, especially for algorithms requiring many execution steps.
  • String Matching Failures: Despite Knuth-Morris-Pratt (KMP) being a sequential string algorithm, RNAR struggles significantly (achieving only 4.54%), indicating that recurrent aggregators alone are insufficient without architectural alignment to finite automata.
  • Future Directions: Exploring tree-structured, non-commutative aggregators (like Binary-GRUs) to curb memory costs, and investigating principled regularization strategies to satisfy symmetries in expectation without sacrificing sequential expressivity.

Summary updated

BibTeX
@inproceedings{xu2024recurrent,
  author = {Kaijia Xu and Petar Veličković},
  title = {{Recurrent Aggregators in Neural Algorithmic Reasoning}},
  booktitle = {LoG},
  year = {2024},
  url = {https://openreview.net/forum?id=TcQZGWWEeg},
}
Figure