TL;DR
Rotary Position Encodings (RoPE) are ubiquitous in modern LLMs and vision transformers, but adapting them to graph neural networks has remained difficult because graphs lack an obvious global coordinate grid. WIRE (Wavelet-Induced Rotary Encodings) resolves this by using graph spectral features (such as Laplacian eigenvectors) as spatial coordinates to rotate queries and keys. WIRE directly generalizes standard RoPE, naturally modulates attention by graph resistive distance, and maintains full compatibility with $O(N)$ linear attention.
What Problem Does This Paper Address?
In transformers, position encodings provide crucial inductive bias about how tokens relate in space or sequence order:
- Absolute Position Encodings (APEs) add coordinate or Laplacian spectral embeddings directly to node features.
- Relative Position Encodings (RPEs) typically modulate attention logits with pair-wise biases (e.g., shortest-path distances, as in Graphormer).
While RPEs generally perform best on graphs, they require computing and materializing the full $N \times N$ attention matrix, creating an $O(N^2)$ computational bottleneck that is incompatible with linear attention mechanisms (such as Performers) or efficient key-value caching. Meanwhile, RoPE applies multiplicative rotations directly to token representations in $O(N)$ time, but assumes fixed Euclidean coordinate axes ($m=1$ for text, $m=2$ for images, $m=3$ for point clouds). The authors ask: Can we extend RoPE to arbitrary graph topologies without losing its linear scaling?
Methods
WIRE operates by mapping graph spectral properties into token rotations:
- Extract Spectral Coordinates: Compute the first $m$ low-frequency eigenvectors $\{u_k\}_{k=0}^{m-1}$ (and corresponding eigenvalues $\lambda_k$) of the graph Laplacian $L = D - A$. Each node $i$ receives an $m$-dimensional spectral coordinate $r_i$ (e.g., $r_i = [u_k[i]]_{k=0}^{m-1}$ or normalized by $1/\sqrt{\lambda_k}$).
- Project and Rotate: Queries $q_i$ and keys $k_i$ are partitioned into 2D blocks and rotated by angles $\theta_n = \omega_n^\top r_i$, exactly as in standard RoPE, using learnable frequency vectors $\omega_n \in \mathbb{R}^m$.
- Linear Attention Integration: Because WIRE modifies token vectors before computing attention, it drops directly into $O(N)$ kernelized linear attention (such as ReLU Performers): $$\text{sim}(q_i, k_j) = \varphi(\text{RoPE}(r_i) q_i)^\top \varphi(\text{RoPE}(r_j) k_j)$$
- Generalizations: Beyond raw Laplacian eigenvectors, WIRE supports other graph features, such as Random Walk Position Encodings (RWPE) or multiscale heat-kernel wavelets (WavePE).
Datasets
The authors evaluate WIRE across diverse domains:
- Synthetic Benchmarks:
- Monochromatic Connected Subgraph Regression: $5 \times 5$ grid graphs with varying edge-removal levels ($0, 5, 10, 15$).
- Shortest Path Distance (SPD) Prediction: Random Watts-Strogatz small-world graphs ($N=10, k=2, p=0.6$).
- 3D Point Clouds: ModelNet40 (object classification) and ShapeNet (part segmentation) represented as 20-nearest-neighbor graphs.
- GNN Benchmarking Suite & OGB: 12 standard benchmarks including MNIST, CIFAR-10, 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: On 1D and 2D grid graphs, the leading non-trivial Laplacian eigenvectors are monotonic cosine functions of node indices. Applying WIRE to these eigenvectors precisely reconstructs standard 1D/2D RoPE, revealing that standard RoPE is fundamentally a spectral encoding on grid graphs.
-
Implicit Topological Masking via Resistive Distance: When WIRE frequencies are randomly initialized, the expected attention logit scales as: $$\mathbb{E}[(\text{RoPE}(r_i) q_i)^\top \text{RoPE}(r_j) k_j] = q_i^\top k_j \left(1 - \frac{\omega^2}{2} R(i,j)\right) + \mathcal{O}(\omega^4)$$ where $R(i, j)$ is the effective resistance between nodes $i$ and $j$ (a lower bound to shortest path distance). WIRE downweights distant node interactions without ever computing or storing pairwise resistance matrices.
-
SE(3) Invariance for Point Clouds: Unlike Cartesian RoPE (which alters rotations under global translations and rotations), spectral graph representations of $k$-NN graphs are invariant under 3D rigid-body transformations.
Key Results
- Synthetic Tasks: Adding WIRE nearly halves test RMSE on Watts-Strogatz shortest path distance (dropping from $0.065$ baseline to $0.038$ with $m=5$ spectral coordinates).
- Point Clouds: On ModelNet40, a standard Transformer with WIRE reaches 93.4% classification accuracy, outperforming both the unencoded baseline (91.8%) and 3D Cartesian RoPE (91.8%).
- Graph Benchmarks with Performers: Adding WIRE to GraphGPS with $O(N)$ linear Performer attention yields consistent improvements across all 12 benchmark datasets. For example:
- MalNet-Tiny: Performer accuracy improves from $92.81\%$ to $93.46\%$, matching the full $O(N^2)$ transformer ($93.36\%$) while fitting on a single 12 GB GPU.
- ogbg-molpcba: Average Precision increases from $0.238$ to $0.264$.
- Peptides-struct: Regression MAE drops from $0.2616$ to $0.2566$.
- Negligible Parameter Overhead: The learnable frequencies $\omega_n$ add fewer than 1% additional parameters to typical GraphGPS layers.
Limitations and Future Work
- Precomputation Cost: Exact eigendecomposition of the Laplacian scales as $O(N^3)$. Although sparse/iterative methods (Lanczos, coarsening) or random walk proxies (RWPE) run in $O(N)$ or $O(N + E)$, spectral preprocessing remains an extra pipeline step.
- Sign and Basis Ambiguities: Laplacian eigenvectors are subject to arbitrary sign flips ($\pm u_k$) and rotational indeterminacy in degenerate eigenspaces. While pairwise distances in spectral space $\|r_i - r_j\|_2^2$ are gauge-invariant, exact equivariance of the final rotation requires sign-canonicalization techniques (e.g., SignNet).
- Scope of Architectures: While tested on Performers, SGFormer, and BigBird, the authors leave exploration on other sparse graph attention mechanisms (like Exphormers and GATs) to future work.
Summary updated