Switching Linear Attention

Hyun Dong Lee, Xavier Gonzalez, Nicolas Zucchet, E. Kelly Buchanan, Emily B. Fox, Scott W. Linderman

TL;DR

Switching Linear Attention (SwiLA) is a new sequence layer that combines the constant-memory efficiency of linear attention with the high expressivity of standard softmax attention. By treating the recurrent state update as an online expectation-maximization (EM) process in a mixture of linear regressors, SwiLA allows models to dynamically route information through specialized memory components, significantly narrowing the performance gap with Transformers on memory-intensive tasks.

What Problem Does This Paper Address?

Modern sequence modeling is dominated by two paradigms, both with significant drawbacks:

  1. Softmax Attention (Transformers): Highly expressive because it can route information nonlinearly based on token similarity. However, it requires a "Key-Value (KV) cache" that grows linearly with sequence length, making long-context inference slow and memory-hungry.
  2. Linear Attention: Reformulates attention as a linear recurrence with a fixed-size state. While this enables efficient, constant-memory inference, it forces the model to compress all history into a single linear mapping. This "retrieval bottleneck" often leads to poor performance on tasks requiring precise associative recall.

The authors introduce SwiLA to bridge this gap. They aim to create a layer that retains the fixed-size state of linear attention but gains the nonlinear, context-dependent retrieval power of softmax attention.

Methods

SwiLA is built on the Test-Time Regression (TTR) framework, which views the forward pass of a sequence model as fitting a regressor to observed data in real-time.

Instead of the single linear regressor used in standard linear attention, SwiLA uses a Mixture of Linear Regressors. The key technical innovations include:

  • Online Expectation-Maximization (EM): The recurrent state update is derived from online EM. At each step, the model computes "responsibilities" (an E-step) to determine which mixture component best explains the current input, then updates those specific weights (an M-step).
  • Exponential Mixture Capacity: To handle high-dimensional data, SwiLA allows each output dimension to independently select its own mixture component. This means the number of effective mixtures scales exponentially ($J^D$), even though the state size only grows polynomially ($JD^2$).
  • Temporal Persistence: The authors extend the model with a Markovian prior, allowing a "context" (mixture assignment) to persist across consecutive tokens—essential for tasks like reading a paragraph about a specific topic.
  • Load Balancing: To prevent "expert collapse" (where only one mixture component is used), they employ an auxiliary mutual information loss and inject noise into the routing logits during training.
Figure 1: (A) Piecewise regression vs linear. (B) SwiLA architecture vs Linear/Softmax. (C) SwiLA better approximates softmax attention at every state budget.

Datasets

The authors evaluated SwiLA across a diverse range of benchmarks:

  • Synthetic Regression: A task specifically designed to see how well models can approximate the output of a single causal softmax attention head.
  • Context-Dependent Associative Recall (CDAR): A new synthetic benchmark where the same key maps to different values depending on a preceding "context token," testing the model's ability to maintain multiple separate memories.
  • RegBench: A benchmark for in-context language learning using probabilistic finite automata (PFAs).
  • FineWeb-Edu: Used for large-scale pretraining of 374M parameter models (15B tokens).
  • Downstream Benchmarks: Standard commonsense reasoning tasks (HellaSwag, PIQA, etc.) and recall-intensive tasks (SQuAD, TriviaQA, etc.).

Key Insights and Ideas

  • Piecewise is the Path Forward: The core "aha moment" is that a single linear map is a fundamental bottleneck for memory. By switching between multiple linear maps (piecewise linear), the model can approximate complex nonlinear functions—like those in softmax attention—much more effectively.
  • EM as a Principled Update: Most recurrent models use simple gradient descent (the "Delta rule") for state updates. Deriving the update from EM provides a more robust way to handle latent variables (the "mixtures") in a streaming setting.
  • State Expansion via Mixtures: SwiLA shows that "state expansion" doesn't just mean making a matrix bigger; it means making the structure of the state more sophisticated.

Key Results

  • Softmax Approximation: In synthetic tests, SwiLA configurations consistently achieved higher $R^2$ scores than DeltaNet (a strong linear attention baseline) at the same recurrent state budget.
  • Superior Recall: On the CDAR task, Temporal SwiLA achieved near-perfect accuracy with a state size of $2^{12}$, whereas other recurrent models required significantly larger states to solve the task.
  • Language Modeling Parity: In 374M parameter pretraining, Gated SwiLA variants outperformed other linear attention baselines and even surpassed Transformer++ on several commonsense reasoning benchmarks.
  • Efficiency: SwiLA achieves 4–5× higher inference throughput than standard Transformers because it eliminates the need for a growing KV cache, allowing for much larger batch sizes.
Figure 2: Synthetic Benchmarks. (A) Context-Dependent Associative Recall with 4 contexts and 32 key-value pairs per context: test accuracy vs. state size. (B) RegBench: test accuracy as a function of training set size.

Limitations and Future Work

  • Fixed Capacity: While SwiLA is more expressive than linear attention, its capacity is still ultimately bounded by a fixed state size, unlike softmax attention which can (in theory) grow indefinitely.
  • Parallelization Complexity: Standard linear attention is easy to parallelize during training. SwiLA’s nonlinear recurrence is harder to parallelize. While the authors propose a "chunkwise parallel Newton algorithm," they note that highly optimized custom CUDA kernels are still needed to reach the full speed potential of linear models.
  • Distillation Potential: The authors suggest that SwiLA’s ability to approximate softmax attention makes it a prime candidate for distillation—converting heavy, pretrained Transformers into efficient, recurrent SwiLA models.

Summary updated

BibTeX
@inproceedings{lee2026switching,
  author = {Hyun Dong Lee and Xavier Gonzalez and Nicolas Zucchet and E. Kelly Buchanan and Emily B. Fox and Scott W. Linderman},
  title = {{Switching Linear Attention}},
  booktitle = {COLM},
  year = {2026},
  url = {https://openreview.net/forum?id=dJCS3RC5fP},
}
Figure