Full text not available for this paper
Rewirable Circuits in Transformers with Loom Attention
Authors: Da Xiao, Qingye Meng, Shengping Li, Xingyuan Yuan
Affiliations: Beijing University of Posts and Telecommunications, ColorfulClouds Technology
Summary (Overview)
- Novel architecture (LoomFormer): Proposes loom attention, which interweaves vertical attention over earlier heads' outputs (to obtain query, key, and value) with standard horizontal attention over tokens, enabling per-token circuit rewiring.
- Dual-stream design: Introduces a per-token matrix memory serving as a second residual stream (matrix stream) alongside the vector stream, splitting control (vector) from content (matrix).
- Efficiency: Adds only 2.0–3.7% extra FLOPs while matching Transformers trained with >3× compute and recent residual-stream baselines (HC/mHC, MUDDFormer, AttnRes) trained with ~1.7–2.8× compute.
- Key empirical result: LoomPythia-2.8B trained on 300B tokens achieves ~1.6× the downstream gain of mHC-Pythia-2.8B over Pythia-2.8B, matching (0-shot) or surpassing (5-shot) Pythia-12B.
- Mechanistic insights: Trained LoomFormer keeps 3.3–4.2× more deep-layer heads off attention sinks compared to Pythia and mHC, with dynamic wiring rank up to 64 vs. rank ≤1 for baselines.
Introduction and Theoretical Foundation
Background and Motivation
Transformers solve tasks by composing attention heads into circuits (Elhage et al., 2020; Olsson et al., 2022): an earlier head writes a feature into the residual stream, and a later head reads it. However, the composition between two heads is fixed after training—determined by the product of their output and input projections (a virtual weight). While horizontal attention makes token-to-token flow input-dependent, the vertical flow across layers is static: a head cannot choose which heads to read from.
The paper asks: Can circuits be made rewirable per token?
Theoretical Framework
Writers, readers, and circuits: A head's output is a writer ; its query, key, and value are readers . Writer reaches reader through the virtual weight .
Dynamic wiring matrix: At a token, reader receives:
where per-token scalars form the wiring matrix .
Key definitions:
Definition 2.1. An architecture with fixed virtual weights is rewirable w.r.t. a set of wiring patterns if every pattern is realized by some wiring matrix that it admits at a token.
Definition 2.2. An architecture is node-gated if its wiring matrix has the form (rank ≤ 1), with gate vectors marking which writers/readers are on.
Theorem 2.4 (node-gating cost): To realize all independent wiring patterns, a node-gated architecture needs at least heads per reader, where , for , and for . At practical sizes, node gating needs heads per reader.
Naive loom attention: The direct solution—letting every reader attend over all earlier heads' outputs with per-token attention weights:
—is rewirable but expensive: parameters, growing quadratically in total heads .
Methodology
From Naive to Affordable Loom Attention
The key insight: compress head outputs along depth into a matrix memory with slots of width , analogous to how linear attention compresses a KV cache.
Dual ports (Eq. 4):
Architecture Components
MRead module (Eq. 5): Generates query to read from :
MWrite module (Eq. 6): Generates key and writes output as outer product:
LoomMHA (Eq. 7–8): Each head reads four vectors from memory (query, key, value, output bypass ), applies RoPE to a -dimensional projection, and writes outputs back:
FFN with MWrite (Eq. 9): A second, smaller FFN writes content into :
Residual updates (Eq. 11):
Default settings: slots (memory size ), (2× compression bottleneck).
Rewiring Capacity (Proposition 3.1)
- (i) With fixed ports, LoomFormer reduces to a standard Transformer (node-gated).
- (ii) With per-token generated ports, LoomFormer is rewirable with one head per reader for patterns with at most writers, replacing the heads per reader needed by node gating.
The wiring matrix is with rank at most , versus rank 1 for Transformers/HC/mHC and rank 3 for MUDDFormer.
Empirical Validation / Results
Scaling Laws (Section 5.1)
Across Medium (432M), Large (778M), and XL (1.4B) scales:
- LoomFormer achieves the lowest validation loss at every scale.
- Matches Transformer++ trained with 3.19–3.25× compute (3.10× net after FLOP overhead).
- Matches residual-stream baselines at 1.73–2.76× compute.
- At XL: loss reduced from 2.101 to 1.979 (ΔL = 0.122, 1.8× MUDDFormer's gain of 0.068) at 2.8% extra FLOPs.
Large-Scale Pretraining (300B tokens, Section 5.2)
Table 2 (key results):
| Model | Pile ppl ↓ | FLAN ppl ↓ | 0-shot Avg | 5-shot Avg | Δ acc (mean) |
|---|---|---|---|---|---|
| Pythia-2.8B | 6.63 | 8.16 | 56.3 | 57.3 | — |
| Pythia-6.9B | 6.29 | 7.85 | 58.1 | 59.3 | — |
| mHC-Pythia-2.8B | 6.24 | 7.35 | 58.8 | 59.9 | +2.55 |
| Pythia-12B | 6.01 | 7.26 | 59.9 | 60.8 | — |
| LoomPythia-2.8B | 6.02 | 6.94 | 59.9 | 61.6 | +3.95 |
LoomPythia-2.8B:
- 1.6× the average downstream gain of mHC-Pythia-2.8B.
- Matches Pythia-12B in 0-shot, surpasses in 5-shot.
- Best FLAN perplexity (6.94), beating Pythia-12B (7.26) and mHC (7.35).
- 0/5-shot mean matches ~4.9× compute extrapolation of Pythia.
Mechanistic Analysis (Section 5.3)
- Dynamic wiring rank: LoomPythia reaches effective rank 41.0 at layer 32 (mean 26.4), with 71.0% of dynamic wiring energy outside rank 1.
- Port rewiring: Cross-token cosine distance of ports averages 0.33–0.46 (up to 0.68), vs. zero for static/gated baselines.
- Head utilization: In layers 17–32, LoomPythia keeps 74.4% of heads on vs. 22.9% (Pythia) and 17.7% (mHC)—a 3.3× and 4.2× improvement.
- Within-head specialization: Per-writer correlation within the same head drops to 0.71–0.84, with top-32 writer overlap of only 0.38–0.49.
Computational Efficiency (Section 5.4)
| Model | +FLOPs (%) | Train (% v5p) | Prefill (% bs1/8) | Decode (% bs1/16/64) |
|---|---|---|---|---|
| Medium | 3.70 | 90.5 | 87.4/90.4 | 91.7/89.2/92.3 |
| Large | 3.13 | 89.2 | 85.3/86.2 | 85.4/87.8/84.9 |
| XL | 2.77 | 92.3 | 83.8/85.3 | 86.9/84.6/86.6 |
| 2.8B | 1.95 | 92.4 | 87.5/90.5 | 86.4/87.6/88.9 |
Ablation Studies (Section 5.5)
Key findings (Medium scale, gain relative to full LoomFormer):
| Ablation | Loss | Retained Gain |
|---|---|---|
| Full LoomFormer | 2.266 | 100% |
| Static read & write (qᵐ, kᵐ) | 2.344 | 56.0% |
| Static read queries only | 2.310 | 75.4% |
| Static write keys only | 2.283 | 90.3% |
| Remove FFN_M write | 2.300 | 80.7% |
| Remove output bypass oᵐ | 2.299 | 81.8% |
| Remove MShift | 2.277 | 94.2% |
Memory capacity: Default sits at the knee of the loss-vs-slots curve; even (2D state) outperforms DHC (4D) and MUDDFormer (9D average).
Theoretical and Practical Implications
Theoretical Contributions
- Formal framework for circuit rewiring: Introduces the wiring matrix formalism and distinguishes node-gated (rank ≤ 1) from rewirable architectures, with a rigorous lower bound (Theorem 2.4) on the head cost of node gating.
- Dual-stream architecture principle: Shows that splitting control (vector stream) from content (matrix stream) enables per-token circuit selection at one head per reader, replacing heads with memory slots.
- Unified view of prior work: Table 1 positions LoomFormer among residual-stream mechanisms, showing its wiring rank of vs. rank 1 (Transformer, DenseFormer, HC/mHC, AttnRes) and rank 3 (MUDDFormer).
Practical Implications
- Compute efficiency: Matches Transformers trained with >3× compute at only 2–3.7% extra FLOPs—a substantial cost reduction for large-scale pretraining.
- In-context learning: The widening 0-shot → 5-shot gain (+3.6 → +4.3) indicates stronger in-context learning, traced to per-token rewiring freeing deep heads from attention sinks.
- Architecture design: The head-level granularity of rewiring uses memory far more effectively than layer-wise mechanisms, suggesting a new design axis for foundation models.
Conclusion
Main takeaways:
- Standard Transformers and layer-wise residual-stream mechanisms are restricted to low-rank (node) gating, requiring many heads per reader to avoid circuit interference.
- Loom attention interweaves vertical linear attention over a per-token matrix memory with horizontal attention, making circuits rewirable per token at one head per reader.
- LoomFormer matches Transformers trained with >3× compute and recent baselines with ~1.7–2.8× compute, while keeping >75% of attention heads active and dynamically rewiring ports.
Future directions:
- Combining loom attention with linear or sparse attention along the sequence axis (the matrix memory operates along depth at each token, making the two orthogonal).
- The Jacquard loom analogy suggests potential connections to programmable computation and mixture-of-experts-style routing, where "experts" are wirings sharing all other weights.
Related papers
- FlyingStart: Learned Cross-Token Warm Starts for Fixed-Point Decoding in Recurrent-Depth Language Models
FlyingStart learns a linear warm-start map for recurrent-depth language models, cutting decoding layers by 14–19% while matching accuracy and preserving the exit rule's safety certificate.
- Looped Models are Fast Multi-Token Predictors
Floodgates achieves up to 7.5x lossless decoding speedup on looped language models by using a single loop with low-rank adapters to draft multiple future tokens in parallel.
- Third Eye: Beyond Immediate Gains in Recursive Self-Improvement
Third Eye shows a model's immediate performance after self-update can look neutral while a further native update causes significant utility decline, varying by backbone.