Rotary Position Encodings for Graphs

Isaac Reid, Arijit Sehanobish, Cederik Höfs, Bruno Mlodozeniec, Leonhard Vulpius, Federico Barbero, Adrian Weller, Krzysztof Choromanski, Richard E. Turner, Petar Veličković

TL;DR

This paper introduces Wave-Induced Rotary Encodings (WIRE), a novel method that extends the highly successful Rotary Position Encodings (RoPE) from language and vision models to graph-structured data. By rotating token embeddings based on the spectrum of the graph Laplacian, WIRE efficiently injects structural topology directly into the attention mechanism. Crucially, unlike previous graph position encodings, WIRE achieves this while remaining fully compatible with $O(N)$ linear attention mechanisms.

What Problem Does This Paper Address?

Transformers have revolutionized machine learning, but their core attention mechanism is permutation-invariant—it treats inputs as an unordered bag of tokens. To fix this, models rely on position encodings. In large language models (LLMs) and vision transformers (ViTs), RoPE has become the gold standard due to its performance and efficiency.

However, graphs don't have a simple, linear coordinate system like text or pixel grids. Existing graph position encodings fall into two flawed categories:

  1. Absolute Position Encodings (APEs): These add static structural vectors to node features but fail to capture relative distances or structural invariances effectively.
  2. Relative Position Encodings (RPEs): These modulate attention scores based on pairwise distances (like shortest paths). While powerful, RPEs require instantiating the full $N \times N$ attention matrix, completely breaking the scalability of efficient "linear attention" models (like Performers) and making them unusable for large graphs.

WIRE bridges this gap, bringing the benefits of rotary encodings to graphs without sacrificing computational efficiency.

Methods

WIRE maps graph structure to rotation angles by utilizing graph spectra—specifically, the eigenvectors of the graph Laplacian matrix. These eigenvectors act like structural "waves" across the graph: lower frequencies capture global, slowly varying shapes, while higher frequencies capture sharp, localized oscillations.

Figure 1. WIRE schematic. Rotary position encodings (RoPE) (Su et al., 2024) can be applied to graphs using graph spectra. The first few eigenvectors of the Laplacian vary slowly across 𝒢︀; higher frequencies oscillate sharply between adjacent nodes. The eigenvectors are projected down to obtain rotation angles for every query and key. WIRE enjoys desirable theoretical properties and is compatible with linear attention (Choromanski et al., 2021; Katharopoulos et al., 2020).

The algorithm proceeds as follows:

  1. Compute the lowest $m$ eigenvectors of the graph Laplacian.
  2. Define these spectral coordinates as the positional features for each node.
  3. Project these features to generate rotation angles, and apply standard RoPE-style 2D block rotations to the query and key vectors before computing attention.

Because WIRE modifies queries and keys independently before the attention step, it preserves the low-rank matrix factorization trick required for $O(N)$ linear attention scaling.

Datasets

The authors evaluated WIRE across a comprehensive set of benchmarks:

  • Synthetic Tasks: Monochromatic connected subgraph size prediction and Shortest Path Distance (SPD) prediction on Watts-Strogatz graphs.
  • 3D Point Clouds: ModelNet40 (object classification) and ShapeNet (part segmentation), modeled as sparse $k$-nearest neighbor graphs.
  • GNN Benchmarks (GraphGPS framework): MNIST, CIFAR10, PATTERN, CLUSTER, ogbg-molhiv, ogbg-molpcba, ogbg-ppa, ogbg-code2, Peptides-func, Peptides-struct, PascalVOC-SP, and MalNet-Tiny.

Key Insights and Ideas

  • RoPE is a Special Case of WIRE: The authors prove that on 1D and 2D grid graphs, WIRE naturally recovers standard sequential and spatial RoPE. This provides a beautiful, unified mathematical framework showing that text and image transformers are just special cases of graph transformers operating on rigid grids.
  • Implicit Effective Resistance Masking: The paper proves that when initialized with random weights, WIRE mathematically downweights attention logits based on the effective resistance (a robust structural distance metric) between nodes. Remarkably, it achieves this topological masking implicitly, without ever materializing an expensive $N \times N$ distance matrix.
  • Inherent Gauge Invariance: Laplacian eigenvectors suffer from sign-flip ambiguities (i.e., $\pm u$ are both valid eigenvectors). While other architectures require complex, explicit invariant networks (like SignNet) to handle this, the authors show that randomized WIRE is intrinsically gauge-invariant in expectation, explaining its real-world robustness.
Figure 2. RoPE ⊂ WIRE. The leading elements of the Laplacian eigenvectors of grid graphs (formally, Cartesian products of paths 𝑃𝑁) change monotonically in each direction. If we apply WIRE using just these coordinates, we recover regular RoPE as used in LLMs and ViTs. In this sense, RoPE is a special case of WIRE.

Key Results

  • Halving Error on Structural Tasks: In the synthetic shortest-path prediction task, WIRE nearly halved the test RMSE (dropping from 0.065 to 0.038) compared to the baseline model using only absolute position encodings.
  • Closing the Linear vs. Softmax Gap: On the heavily optimized GraphGPS benchmarks, adding WIRE to $O(N)$ Performer models yielded substantial accuracy gains. On ogbg-molpcba, it boosted average precision from 0.238 to 0.264. On MalNet-Tiny, WIRE Performers completely closed the performance gap with expensive $O(N^2)$ softmax transformers, allowing a linear model to achieve state-of-the-art results while training comfortably on a single commodity 12GB GPU.
  • Point Cloud Improvements: WIRE consistently outperformed the standard Point Cloud Transformer (PCT) baselines for both classification and segmentation tasks.

Limitations and Future Work

  • The $O(N^3)$ Bottleneck: Exactly diagonalizing the graph Laplacian to find eigenvectors scales cubically with the number of nodes. While the authors mitigate this by noting that practitioners only need the first few eigenvectors (which can be approximated in $O(N)$ time using Lanczos methods), it remains a precomputation hurdle for massive graphs.
  • Alternative Structural Features: To bypass spectral decomposition entirely, the authors briefly demonstrated that Random Walk Position Encodings (RWPE) can be plugged into WIRE, showing promising results that warrant deeper future study.
  • Expanding Attention Mechanisms: Future work includes exploring WIRE's compatibility with other sparse attention frameworks like Exphormers or Graph Attention Networks (GATs).

Summary updated

Abstract

We study the extent to which rotary position encodings (RoPE), a recent transformer position encoding algorithm broadly adopted in large language models (LLMs) and vision transformers (ViTs), can be applied to graph-structured data. We find that rotating tokens depending on the spectrum of the graph Laplacian efficiently injects structural information into the attention mechanism, boosting performance in synthetic and real-world graph learning tasks. This approach, coined _Wave-Induced Rotary Encodings_ (WIRE), enjoys intriguing theoretical properties: it recovers regular RoPE on grids, and depends asymptotically on the graph effective resistance. Unlike bias-based relative position encodings, WIRE is compatible with linear attention.
BibTeX
@inproceedings{reid2026rotary,
  author = {Isaac Reid and Arijit Sehanobish and Cederik Höfs and Bruno Mlodozeniec and Leonhard Vulpius and Federico Barbero and Adrian Weller and Krzysztof Choromanski and Richard E. Turner and Petar Veličković},
  title = {{Rotary Position Encodings for Graphs}},
  booktitle = {International Conference on Machine Learning},
  year = {2026},
  url = {https://openreview.net/forum?id=trn64znfNx},
}
Figure