Rewirable Circuits in Transformers with Loom Attention

Da Xiao, Qingye Meng, Shengping Li, Xingyuan Yuan

Imagine you’re building a complex electronic circuit. In a standard Transformer, once the "training" phase is over, the wires connecting your components are soldered in place. You can turn a component on or off, but you can't suddenly decide that the sensor in Layer 2 should talk to the processor in Layer 10 instead of Layer 5.

The authors of "Rewirable Circuits in Transformers with Loom Attention" argue that this fixed wiring is a massive bottleneck. They introduce Loom Attention, a mechanism that lets a Transformer dynamically "rewire" its internal circuits for every single token it processes. The result? A model that punches way above its weight class, matching the performance of models three times its size.

TL;DR

Loom Attention allows Transformer heads to dynamically choose which earlier heads to listen to, not just which tokens to attend to. By interweaving "vertical" attention (across layers) with "horizontal" attention (across tokens), the resulting LoomFormer architecture achieves the performance of models with 3x more compute while adding only a tiny (~2-4%) overhead.

What Problem Does This Paper Address?

In a traditional Transformer, information flows "horizontally" across tokens via attention and "vertically" through layers via the residual stream. While horizontal attention is highly dynamic (a head chooses which tokens to focus on), the vertical flow is surprisingly rigid.

As shown in Figure 3, standard Transformers are "node-gated." This means a head can be turned on or off (often by attending to a "sink token"), but the underlying "virtual weights" that define which head's output feeds into another head's input are fixed after training. If a task requires a different circuit for a different input, the model has to keep all possible circuits "wired" at once and just gate them, which is inefficient and leads to "interference" between circuits.

Figure 3. Effective wiring for three wiring patterns. Transformers (top two rows) can only gate whole heads, i.e., rows and columns, on and off, so they connect only rectangles within the fixed support of their virtual weights. LoomFormer (bottom row) connects exactly the required pairs.

Methods

The authors propose Loom Attention, inspired by the warp and weft of a loom.

  • Horizontal Attention (Weft): The standard attention we know, moving information across tokens.
  • Vertical Attention (Warp): A new mechanism where a head attends over the outputs of all previous heads at the same token position to compute its own Query, Key, and Value.

To make this efficient, they introduce a dual-stream architecture called LoomFormer:

  1. Vector Stream: The traditional residual stream, which now primarily carries "control" information (deciding where to attend and how to wire).
  2. Matrix Memory ($M$): A per-token memory that stores compressed head outputs. This acts as a second residual stream for "content."

Heads use MRead and MWrite modules to interact with this matrix memory. Instead of attending to every previous head (which would be computationally ruinous), they attend to "slots" in this matrix memory. This keeps the cost independent of the model's depth.

Figure 1. Conceptual sketch of loom attention. At each token, each head chooses which slots of that token’s matrix memory M to read and write (i.e., vertical attention, every head does both; only one is shown per layer) and which tokens to attend to (horizontal attention), so a different circuit is woven for each token.

Datasets

The models were trained on The Pile (a 300B token subset for the larger models). Evaluation was performed across 10 standard downstream benchmarks, including LAMBADA, PIQA, HellaSwag, and ARC. They also tested on the FLAN collection to evaluate out-of-domain instruction following and in-context learning.

Key Insights and Ideas

  • The "3x" Efficiency Gain: By allowing the model to specialize its wiring per token, LoomFormer achieves a massive leap in efficiency. A 2.8B parameter LoomFormer matches a standard 12B parameter Pythia model.
  • Ending the "Sink Token" Waste: In standard models, many heads are "wasted"—they attend to a meaningless sink token just to turn themselves off because they aren't needed for a specific token. LoomFormer keeps ~75% of its heads active and useful by simply rewiring them to relevant inputs instead of silencing them.
  • Control vs. Content: Splitting the architecture into a control-heavy vector stream and a content-heavy matrix stream allows for much more sophisticated information routing without the quadratic cost explosion usually associated with cross-layer attention.

Key Results

  • Performance: LoomPythia-2.8B matches the 0-shot performance of Pythia-12B and actually surpasses it in 5-shot scenarios.
  • Compute Savings: Across various scales, LoomFormer matches the validation loss of standard Transformers trained with 3.19x to 3.25x more compute.
  • Overhead: The analytical FLOP overhead is minimal, ranging from 1.95% to 3.70% depending on the model size. Real-world throughput remains high, sustaining ~90% of a standard Transformer's speed.
Figure 2. Downstream accuracy averaged over 10 tasks.

Limitations and Future Work

  • Memory I/O: While FLOP-efficient, the matrix memory increases the demand for high-bandwidth memory (HBM) I/O, which can be a bottleneck on some hardware.
  • Arithmetic Intensity: The per-token matrix contractions have lower arithmetic intensity than large batch GEMMs, making them harder to optimize fully.
  • Future Directions: The authors suggest that combining Loom Attention with linear or sparse attention along the sequence axis (the "horizontal" dimension) is a natural next step for building even more efficient foundation models.

Not discussed in the paper: The impact of Loom Attention on long-context window performance beyond the tested 4096 tokens.

Summary updated

Abstract

We propose loom attention, which allows a Transformer to dynamically rewire its circuits at every token by interweaving a head's vertical attention over the outputs of earlier heads (to obtain its query, key and value) with its horizontal attention over tokens. We instantiate vertical attention efficiently with normalized and gated linear attention over a per-token matrix memory, which stores the compressed head outputs and serves as a second residual stream. This yields LoomFormer, a dual-stream architecture that splits control and content between the vector and matrix streams. Across model sizes and training token budgets in language modeling and downstream tasks, LoomFormer matches Transformers trained with over 3x compute and recent residual-stream baselines (HC/mHC, MUDDFormer, AttnRes) trained with ~1.7-2.8x. For example, trained on the same 300B tokens with only 2% extra FLOPs, LoomPythia-2.8B achieves ~1.6x the average downstream gain of mHC-Pythia-2.8B over Pythia-2.8B, and matches (0-shot) or surpasses (5-shot) Pythia-12B. Code is available at https://github.com/Caiyun-AI/LoomFormer
BibTeX
@misc{xiao2026rewirable,
  author = {Da Xiao and Qingye Meng and Shengping Li and Xingyuan Yuan},
  title = {{Rewirable Circuits in Transformers with Loom Attention}},
  year = {2026},
  eprint = {2611.30634},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.30634},
}
Figure