AI Engineering and Architecture

A Few Good Edges: How Expander Graphs Make Sparse AI Wiring Smarter

How optimal sparse graphs deliver dense-model connectivity at a fraction of the cost, and what that means for scalable neural intelligence.

Guillermo Perry 11 min read
expander graphs Ramanujan graphs spectral gap sparse attention Exphormer graph transformers AI architecture neural network efficiency KNIRV
🕸️
AI Engineering and Architecture

A Few Good Edges: How Expander Graphs Make Sparse AI Wiring Smarter

What if every node in a neural network could reach every other node in a few hops, while each node only talks to three neighbors? Expander graphs make that possible, and they are reshaping how we think about efficient, scalable AI.

By Guillermo Perry 11 min read KNIRV

🎧 Listen to the episode

Expander Graphs: Sparse Wiring with Complete Reach

The Wiring Question

In the previous episode, we saw that a ReLU neural network can be viewed as a tropical object in disguise: a maximum of straight lines. Today, we ask the wiring question. What if every node in a network could reach every other node in just a few hops, while each node only talks to three neighbors?

Three neighbors, and still a few hops to anywhere? In a grid, that is impossible, even with four neighbors per node, because grids have bottlenecks. Cut a large grid in half and only a thin line of edges crosses the cut. Messages take a long time to travel.

An expander graph is the opposite. It is sparse. Every node has only a few neighbors, but there are no bottlenecks anywhere. Any group of nodes (up to half the graph), no matter how you choose it, has many edges leading out of it. A random walk spreads fast, and a message crosses the whole graph in a number of steps that grows like the logarithm of the size. If the graph grows ten times bigger, the distance grows by only a step or two.

Key insight: Connectivity is not something you buy with density. With the right wiring, sparse can behave like dense.

The Spectrum: How Mathematicians Score Wiring

Mathematicians measure expansion quality with a list of numbers called the spectrum. Picture a table, the adjacency matrix, that records which nodes are linked to which. The eigenvalues of that table tell you how fast a random walk spreads.

For a connected regular graph where every node has degree d, the largest eigenvalue is d itself. Everything interesting lives in the second-largest eigenvalue, λ₂. The difference d − λ₂ is called the spectral gap: the bigger the gap, the faster the graph mixes and the better the expansion.

The link between the spectrum and "no bottlenecks" is exact, not a metaphor. The discrete Cheeger inequality bounds the edge expansion h(G) (the fewest edges leaving any set of at most half the nodes, per node in that set) on both sides by the spectral gap: (d − λ₂)/2 ≤ h(G) ≤ √(2d(d − λ₂)). A large gap guarantees no thin cut exists. And a random walk on the graph converges to uniform at a rate governed by the largest non-trivial eigenvalue in absolute value, which is where the logarithmic diameter comes from.

There is a hard floor. The Alon–Boppana bound says that for large d-regular graphs, λ₂ cannot be meaningfully smaller than 2√(d−1), the spectral radius of the infinite d-regular tree. That creates a best possible score. The question becomes: can we build graphs that actually reach it?

Ramanujan Graphs: Optimal Expanders

A d-regular graph is a Ramanujan graph when every non-trivial eigenvalue has absolute value at most 2√(d−1). The name honors Srinivasa Ramanujan, because the first constructions relied on his conjecture about the coefficients of modular forms. For AI engineering, the takeaway is practical: by the Alon–Boppana bound, Ramanujan graphs are the best expanders that can exist, spectrally speaking.

For decades, the challenge was to build them explicitly for any degree at any size, without rolling dice. A random regular graph is nearly Ramanujan with high probability, a result proven by Joel Friedman (published 2008, arXiv:cs/0405020). Existence was not the problem. Design was. A random graph is not something you can hand to a chip designer or a formal proof and say, "trust me."

Milestones in Explicit Construction

  • 1988: Lubotzky, Phillips, and Sarnak, and independently Margulis, gave the first explicit Ramanujan graphs using deep number theory. Those constructions cover degrees d = p + 1 for primes p (later extended to prime powers), not every degree.
  • 2013–2015: Marcus, Spielman, and Srivastava used interlacing families to prove that bipartite Ramanujan graphs exist in every degree (arXiv:1304.4132, Annals of Mathematics 2015) and then at every size (arXiv:1505.08010). In 2016, Michael B. Cohen turned this into a deterministic polynomial-time algorithm for the bipartite case (arXiv:1604.03544).
  • September 2026: OpenAI released an 85-page preprint, Deterministic nonbipartite Ramanujan graphs in every fixed degree, claiming a deterministic polynomial-time construction of simple non-bipartite d-regular Ramanujan graphs for every fixed d ≥ 3 at every sufficiently large even number of vertices, with every non-trivial eigenvalue strictly inside (−2√(d−1), 2√(d−1)).

If the 2026 result holds up, it closes the remaining non-bipartite gap: exact Ramanujan graphs in any fixed degree, at essentially any size, with no randomness and no error term.

Caveat: The 2026 OpenAI result is a preprint. It has not been peer-reviewed, and independent verification matters. Even if correct, the running time is polynomial in the number of vertices with an exponent that may depend on the degree, and the constants may be large. Treat it as promising, not settled.

Why Determinism Matters for AI

If a random graph is nearly as good, why insist on exact? Because real systems need predictable, auditable structure. In AI engineering, one of the clearest use cases is sparse attention.

A transformer attends to everything, which costs O(n²) in sequence length. Graph transformers face the same scaling pressure on graphs. A practical fix is Exphormer, introduced by Hamed Shirzad and colleagues at ICML 2023 (arXiv:2303.06147).

How Exphormer Uses an Expander

Exphormer builds its attention pattern from three ingredients:

  1. Input graph edges for local structure.
  2. A constant-degree expander overlay for long-range connections.
  3. A small number of virtual nodes connected to every node, acting as global hubs.

The result is attention cost that scales linearly in the number of nodes plus edges, rather than quadratically. The expander is not decorative. The authors prove that the expander overlay spectrally approximates the complete graph, so a few sparse attention layers can stand in for dense attention.

72.4% Test accuracy on ogbn-arxiv (about 169K papers, 1.17M citation links). The dense SAN and GraphGPS transformers ran out of memory on a 40GB A100 GPU.
74.7% CIFAR-10 image-graph accuracy for Exphormer vs. about 72.3% for the dense GraphGPS transformer.
~4x fewer Parameters on the PATTERN benchmark: about 90K for Exphormer matching the dense GraphGPS model at about 340K.

These are results reported in the Exphormer paper and should be read in context: task type, graph structure, and implementation details matter. The broader signal is clear: principled sparse wiring can be competitive with, and sometimes better than, dense wiring. Related work uses the same idea inside message-passing GNNs: Expander Graph Propagation by Deac, Lackenby, and Veličković (arXiv:2210.02997) propagates information over an expander template to fight bottlenecks and over-squashing.

What Changed Since 2023

The field has kept pushing on the same principle: choose wiring deliberately.

Spexphormer: Learn the Sparse Wiring

Spexphormer, from Even Sparser Graph Transformers (arXiv:2411.16278), uses a two-stage process. First, train a narrow network on the full expander-augmented graph and observe which connections are actually used. Then train a wider network on only those active connections. The insight is that attention scores turn out to be quite consistent across network widths, so a cheap pass can guide an expensive one.

NearFormer: Geometry-Guided Neighbors

NearFormer (Parviz, Cloninger, and Mishne, November 2026, arXiv:2611.12186) restricts global attention to a randomized near-neighbor graph built once from label-independent features or spectral geometry. Its attention support has linear size, with a favorable accuracy-scalability trade-off on long-range graph benchmarks. Different mechanism, same direction: sparse structure by design.

Where Expanders Show Up Beyond Attention

Mixture-of-Experts Routing

In mixture-of-experts models, a router sends each token to a few experts. The routing pattern is a sparse web of token-to-expert links. If that web has a bottleneck, some experts starve while others overload. Expansion is a natural lens for diagnosing and designing that routing fabric.

Sparse Networks, Initialization, and Pruning

Expander wiring inside neural networks has a track record. Deep Expander Networks (X-Nets, arXiv:1711.08757) wire convolutional filters as expander graphs and prove every node influences every node in a layer within a logarithmic number of steps. RadiX-Net (arXiv:1905.00416) builds structured sparse layers with guaranteed connectivity, and Ramanujan Bipartite Graph Products (arXiv:2006.13486) uses Ramanujan structure for efficient block-sparse networks.

The lottery-ticket line of work points the same way. Pal and colleagues (ICML 2022) observed that winning tickets tend to preserve the Ramanujan property layer by layer, and newer work under review uses deterministic Ramanujan graphs to wire a pruned network from the start: zero-shot, data-independent, with accuracy competitive with established pruning-at-initialization methods. The picture is not settled, though; Hoang and colleagues (ICLR 2023) found that the Ramanujan property alone does not reliably predict which sparse structure performs best. Still, the pattern repeats: when wiring is an expander, sparse stops meaning weak.

Hardware-Constrained AI

Photonic and neuromorphic systems cannot afford all-to-all wiring. Wiring is cost: area, energy, latency, and complexity. Expanders provide a wiring diagram with a fixed small number of connections per node, logarithmic diameter, and no bottlenecks. Deterministic, verifiable constructions make that even more attractive for hardware layout and certification.

Honest Caveats

  1. The 2026 OpenAI construction is a preprint. It has not been peer-reviewed, and even if the proof is correct it is a theoretical construction first, with a running-time exponent that may depend on the degree.
  2. Expanders help where the interaction graph is the bottleneck. That is clear for graph transformers and sparse routing. Nobody has shown that a large language model wants expander attention yet.
  3. Not every expander result is an AI result. The April 2025 construction of the first explicit constant-degree lossless vertex expanders by Hsieh, Lubotzky, Mohanty, Reiner, and Zhang (arXiv:2504.15087) is aimed at coding theory, including new families of quantum LDPC codes, not at AI. The ideas cross over, but the applications are still being built.

What is solid is the principle: sparse wiring with a spectral guarantee behaves like dense wiring at a fraction of the cost, and we are getting better at building that wiring on purpose.

What This Means for KNIRV

At KNIRV, we build around a simple belief: efficient AI is not just bigger models. It is smarter systems. Systems that move information with intent, preserve context without waste, and scale without turning every interaction into dense all-to-all computation.

Expander-style thinking fits that vision. When neural intelligence systems need to route context, coordinate specialized capabilities, and remain responsive under load, wiring matters as much as model size. Sparse, well-designed connectivity is a path to speed, clarity, and scale without sacrificing quality.

The future of agentic and conversational AI will not be won by density alone. It will be won by systems that know which connections matter.

Frequently Asked Questions

What is an expander graph in AI?

An expander graph is a sparse graph with strong connectivity: few edges per node, but no bottlenecks. In AI, it can support efficient routing, attention, or communication patterns that approximate dense connectivity at lower cost.

Why are Ramanujan graphs called "optimal"?

For large regular graphs, the Alon–Boppana bound says the second-largest eigenvalue cannot be meaningfully smaller than 2√(d−1). Ramanujan graphs keep every non-trivial eigenvalue within that bound, so they achieve the best possible spectral gap.

Is expander attention ready for every LLM workload?

No. The strongest evidence today is in graph transformers and sparse interaction settings. Applying expander wiring to general language-model attention is promising, but it requires workload-specific validation.

Sources and Further Reading

  • Shlomo Hoory, Nathan Linial, Avi Wigderson. Expander Graphs and Their Applications. Bulletin of the AMS 43 (2006). doi:10.1090/S0273-0979-06-01126-8
  • Noga Alon. Eigenvalues and Expanders. Combinatorica, 1986. A. Nilli. On the Second Eigenvalue of a Graph. Discrete Mathematics, 1991. (Alon–Boppana bound)
  • A. Lubotzky, R. Phillips, P. Sarnak. Ramanujan Graphs. Combinatorica, 1988.
  • Joel Friedman. A Proof of Alon's Second Eigenvalue Conjecture and Related Problems. Memoirs of the AMS, 2008. arXiv:cs/0405020
  • Adam W. Marcus, Daniel A. Spielman, Nikhil Srivastava. Interlacing Families I: Bipartite Ramanujan Graphs of All Degrees. Annals of Mathematics, 2015. arXiv:1304.4132
  • Adam W. Marcus, Nikhil Srivastava, Daniel A. Spielman. Interlacing Families IV: Bipartite Ramanujan Graphs of All Sizes. 2015. arXiv:1505.08010
  • Michael B. Cohen. Ramanujan Graphs in Polynomial Time. 2016. arXiv:1604.03544
  • OpenAI. Deterministic Nonbipartite Ramanujan Graphs in Every Fixed Degree. Preprint, September 23, 2026; unreviewed at time of writing. PDF
  • Hamed Shirzad, Ameya Velingker, Balaji Venkatachalam, Danica J. Sutherland, Ali Kemal Sinop. Exphormer: Sparse Transformers for Graphs. ICML 2023. arXiv:2303.06147
  • Hamed Shirzad, Honghao Lin, Balaji Venkatachalam, Ameya Velingker, David Woodruff, Danica Sutherland. Even Sparser Graph Transformers (Spexphormer). 2024. arXiv:2411.16278
  • Ali Parviz, Alex Cloninger, Gal Mishne. NearFormer: Linear-Size Sparse Attention via Randomized Near Neighbors. 2026. arXiv:2611.12186
  • Andreea Deac, Marc Lackenby, Petar Veličković. Expander Graph Propagation. 2022. arXiv:2210.02997
  • Ameya Prabhu, Girish Varma, Anoop Namboodiri. Deep Expander Networks: Efficient Deep Networks from Graph Theory. ECCV 2018. arXiv:1711.08757
  • Ryan A. Robinett, Jeremy Kepner. RadiX-Net: Structured Sparse Matrices for Deep Neural Networks. 2019. arXiv:1905.00416
  • Dharma Teja Vooturi, Girish Varma, Kishore Kothapalli. Ramanujan Bipartite Graph Products for Efficient Block Sparse Neural Networks. 2020. arXiv:2006.13486
  • Bithika Pal, Arindam Biswas, Sudeshna Kolay, Pabitra Mitra, Biswajit Basu. A Study on the Ramanujan Graph Property of Winning Lottery Tickets. ICML 2022. PMLR v162
  • Jun-Ting Hsieh, Alexander Lubotzky, Sidhanth Mohanty, Assaf Reiner, Rachel Yun Zhang. Explicit Lossless Vertex Expanders. 2025. arXiv:2504.15087

Key Takeaways

  • Expander graphs give sparse networks dense-like reach with logarithmic path lengths, and the Cheeger inequality ties that reach directly to the spectral gap.
  • Ramanujan graphs sit at the spectral optimum set by the Alon–Boppana bound, making them the gold standard for expansion.
  • Exphormer proved the architectural value: sparse, principled attention can scale where dense attention breaks.
  • Determinism matters for verifiable systems, but new claims should be treated cautiously until peer-reviewed.
  • For KNIRV, smarter wiring is a product principle: efficient, intentional connectivity beats brute-force density.

A few good edges beat a lot of mediocre ones.

By Guillermo Perry · KNIRV
Expander Graphs Ramanujan Graphs Sparse Attention AI Architecture