NearFormer: Linear-Size Sparse Attention via Randomized Near Neighbors

cs.LG cs.AI Ali Parviz, Alex Cloninger, Gal Mishne · Nov 9, 2026
Local to this browser
What it does
NearFormer tackles the quadratic cost of dense graph attention by restricting global interactions to a randomized near-neighbor graph. For each node, it samples $k$ neighbors from a broader $K$-nearest-neighbor candidate set using...
Why it matters
For each node, it samples $k$ neighbors from a broader $K$-nearest-neighbor candidate set using efficient randomized binning, yielding $\mathcal{O}(|E| + nk)$ attention complexity while preserving the original graph for local message...
Main concern
NearFormer introduces a practical mechanism for geometry-dependent sparse attention with linear edge complexity. The randomized binning construction is computationally efficient and the separation of local message-passing edges from...
Community signal
0
0 up · 0 down
Sign in to vote with arrows
AI Review AI reviewed
Plain-language introduction

NearFormer tackles the quadratic cost of dense graph attention by restricting global interactions to a randomized near-neighbor graph. For each node, it samples $k$ neighbors from a broader $K$-nearest-neighbor candidate set using efficient randomized binning, yielding $\mathcal{O}(|E| + nk)$ attention complexity while preserving the original graph for local message passing. This offers a geometry-aware alternative to data-independent expander overlays and costly graph rewiring, with experiments showing scalability to 65,536 nodes and competitive accuracy on several benchmarks.

Critical review
Verdict
Bottom line

NearFormer introduces a practical mechanism for geometry-dependent sparse attention with linear edge complexity. The randomized binning construction is computationally efficient and the separation of local message-passing edges from attention edges is architecturally clean. However, the strongest theoretical guarantees apply to an idealized with-replacement surrogate rather than the implemented binning procedure, and the empirical gains are inconsistent across benchmarks.

“The identities below apply to $\widetilde{E}_{\mathrm{NN}}$, not exactly to the bin-based implementation used in the experiments.”
NearFormer paper · Section 4.4
“NearFormer (NN) 0.5368±0.0056; GraphGPS 0.6535±0.0041; Exphormer 0.6527±0.0043 on Peptides-Func AP.”
NearFormer paper · Table 3
What holds up

The decoupling of candidate neighborhood scale $K$ from retained degree $k$ is a meaningful design insight: the ablation in Table 2 shows that increasing $K$ from 25 to 100 at fixed $k=2$ improves LRIM-32-hard LogMSE, PascalVOC-SP F1, and COCO-SP F1 relative to both ordinary $k$-NN and Exphormer. On the Long-Range Ising Model, NearFormer scales practically to $n=65{,}536$ where dense GPS variants run out of memory, and on superpixels plus PCQM-Contact the NN-bias variant ranks first among all tested models.

“Retaining $k$ neighbors per node yields at most $2nk$ directed edge instances after symmetrization, and hence linear edge complexity for fixed $k$.”
NearFormer paper · Section 3
“On LRIM-32-hard and both superpixel datasets, performance improves as $K$ increases, and the default neighborhood outperforms both ordinary $k$-NN and Exphormer.”
NearFormer paper · Section 5.2
“On both superpixel datasets and on PCQM-Contact, NearFormer (NN-bias) ranks first and NearFormer (NN) ranks second.”
NearFormer paper · Section 5.3
Main concerns

The theoretical analysis is bifurcated in a problematic way. Proposition 4.2 gives exact rank-selection probabilities for the bin construction, but the subsequent results on expected path compression, candidate impurity, and region-cut bounds (Lemmas 4.3 and B.1, Theorem B.2) apply only to an exact-candidate surrogate that samples with replacement from fixed $K$-nearest-neighbor lists. The paper explicitly warns that these "do not apply exactly to the bin-based implementation used in the experiments," which substantially weakens their explanatory value for the actual method. Empirically, performance on Peptides-Func and Peptides-Struct is poor: NearFormer (NN) achieves only 0.5368 AP and 0.2636 MAE, far below GraphGPS (0.6535 AP, 0.2500 MAE) and Exphormer (0.6527 AP, 0.2481 MAE). Even the best NearFormer variant there, NN-MP, trails both baselines. The paper notes that "the advantage of NN edges does not transfer uniformly across task families," but offers no diagnosis of why the feature or spectral geometry is uninformative for peptides or whether the tiny default $k$ is simply too sparse.

“The identities below apply to $\widetilde{E}_{\mathrm{NN}}$, not exactly to the bin-based implementation used in the experiments.”
NearFormer paper · Section 4.4
“NearFormer (NN) 0.5368±0.0056; GraphGPS 0.6535±0.0041; Exphormer 0.6527±0.0043 on Peptides-Func AP. NearFormer (NN) 0.2636±0.0028; GraphGPS 0.2500±0.0005; Exphormer 0.2481±0.0007 on Peptides-Struct MAE.”
NearFormer paper · Table 3
“Thus, the advantage of NN edges does not transfer uniformly across task families.”
NearFormer paper · Section 5.3
Evidence and comparison

The matched-budget ablation in Table 2 is the strongest evidence: at identical retained degree $k=2$, broadening the geometric candidate set from $K=25$ to $K=100$ improves results, supporting the claim that geometry-aware sampling at scale matters. However, the comparison is less informative on smaller graphs where $K_0=100$ is not meaningfully smaller than $n$, and the paper itself cautions that "results on graphs with $n \lesssim K_0$ should be interpreted accordingly." The omission of wall-clock runtime comparisons against Exphormer and GPS in the main text also weakens the practical scalability argument. The ECHO results are mixed: competitive on eccentricity and mean distance targets, but weaker on diameter and graph-level energy prediction.

“On LRIM-32-hard and both superpixel datasets, performance improves as $K$ increases, and the default neighborhood outperforms both ordinary $k$-NN and Exphormer.”
NearFormer paper · Section 5.2
“Results on graphs with $n \lesssim K_0$ should be interpreted accordingly.”
NearFormer paper · Section 4.3
Reproducibility

The architectural description and randomized binning algorithm are precise enough to reimplement, but the main paper omits public code availability and does not state software versions or exact random seeds. Hyperparameters are deferred to Appendix D.3. The spectral geometry variant uses "$q$ lowest-frequency eigenvectors" without defining $q$ in the main text, and the default $k$ formula depends on $n$ and $K$ in a way that is deterministic but dataset-specific. The reported means and standard deviations are over three seeds that resample both the overlay and the training run, which is good practice, but full reproduction would need the exact data preprocessing pipeline and seed values.

“If attributes are absent or constant within a graph, feature distances cannot distinguish its nodes. Then we use $q$ lowest-frequency eigenvectors of the symmetric normalized graph Laplacian after omitting the first trivial mode.”
NearFormer paper · Section 3.1
“Appendix D records the training settings.”
NearFormer paper · Section 5
Abstract

Graph transformers can capture long-range interactions, but their quadratic attention cost limits their use on large graphs. We introduce \emph{NearFormer}, a graph transformer whose global attention is restricted to a randomized near-neighbor (NN) graph. NearFormer uses an efficient randomized construction to connect each node to a small number of near neighbors from a broader neighborhood defined by a label-independent feature or spectral geometry. For a fixed retained budget \(k\), the resulting attention support has linear size \(\mathcal{O}(|E|+nk)\). The NN graph is built once by within-bin search and then held fixed. We use these edges as sparse global-attention supports, with optional learned attention biases, while preserving the original graph for local message passing. Experiments on long-range graph benchmarks and synthetic structural tasks show that NearFormer provides a favorable accuracy--scalability trade-off relative to local message passing, dense and sparse attention.

Challenge the Review

Pick a starting point or write your own. Challenges run in the background, so you can keep reading while the AI investigates.

No challenges yet. Disagree with the review? Ask the AI to revisit a specific claim.