Abstract
A new breed of gated-linear recurrent neural networks (RNNs) has reached state-of-the-art performance on a range of sequence modeling problems. Such models naturally handle long sequences efficiently, as the cost of processing a new input is independent of sequence length. Here, we explore another advantage of these stateful sequence models, inspired by the success of model merging through parameter interpolation. Building on parallels between fine-tuning and in-context learning, we investigate whether we can treat internal states as task vectors that can be stored, retrieved, and then linearly combined, exploiting the linearity of recurrence. We study this form of fast model merging on Mamba-2.8b, a pretrained recurrent model, and present preliminary evidence that simple linear state interpolation methods suffice to improve next-token perplexity as well as downstream in-context learning task performance.
Introduction
While Transformers currently dominate sequence modeling, they suffer from a major efficiency bottleneck: the computational cost of processing a new input grows quadratically with the length of the context. This has led to a resurgence of interest in modern RNNs, such as Mamba, which scale linearly. Beyond efficiency, these models possess a unique architectural property—the internal state. This paper investigates how to leverage the internal "memory" of gated-linear RNNs by treating these states as modular, combinable representations of skills learned in-context.
Methods: The Mechanics of State Mixing
The core innovation of this work relies on the linearity of recurrence found in modern RNN architectures. In models like Mamba, the state update mechanism is largely linear, which allows for several novel operations that are not easily achievable in standard Transformer architectures.
1. State Library Construction and Retrieval
The researchers processed various tasks to generate "skill-representing states," which were then stored in a library. When presented with a new, short query (e.g., a 1-shot example of a translation task), the system uses cosine similarity to retrieve the most relevant state from the library. This effectively creates a "cache" for skills, allowing the model to inject pre-computed expertise directly into the state without requiring a long prefix of examples.
2. State Mixing (The "Soup")
By exploiting linear recurrence, multiple states can be combined through simple mathematical averaging. The authors experimented with taking the mean of multiple independent states. For instance, they tested whether averaging 32 different 1-shot states could match or exceed the performance of a single 32-shot sequence.
3. A-decay Mixing
For sequential data, the authors introduced "A-decay mixing." This method combines states from consecutive chunks of text while accounting for the natural decay of information over time within an RNN. While mathematically exact for a single layer, it serves as a robust approximation for deep, stacked models like Mamba-2.8b.
Experimental Setup
The study utilized Mamba-2.8b and evaluated it across a suite of In-Context Learning (ICL) tasks:
- Linguistic tasks: Antonym, Capitalize, Present-Past, Singular-Plural.
- Knowledge/Translation tasks: Country-Capital, English-French.
- Algorithmic tasks: First Letter, Second Letter, and randomized versions to test noise resistance.
- Sequential data: 10,000 sequences from the realnewslike dataset were used for next-token prediction and sequential mixing tests.
Key Insights
States as Task-Specific Clusters
Visualization using t-SNE revealed that internal states naturally cluster by task. Interestingly, even when the model fails to successfully perform a task, the states associated with that task still group together. This suggests that the "essence" of a task is encoded within the state vector regardless of the final output accuracy.
Fast Model Merging
Because the recurrence is linear, states can be added and averaged in a process the authors call "fast model merging." Unlike traditional model merging, which involves interpolating the weights of two separate models (a slow and permanent process), State Soup merges the temporary "thoughts" or activations of the model on the fly.
Task Arithmetic
Preliminary evidence suggests that states can undergo "arithmetic" operations. In one notable example, mixing a state representing a "counting" task with a state representing "English-to-French" translation resulted in the model counting in French. This points toward a future where disparate skills can be systematically combined via their internal representations.
Results
- Reliable Retrieval: The model successfully identified the correct task from the library with as few as one or two examples.
- Performance Gains: Mixing 32 independent 1-shot states performed as well as, or better than, processing a single 32-shot sequence. This indicates that parallel processing of examples followed by state-averaging is a viable and efficient way to scale ICL.
- Sequential Approximation: A-decay mixing outperformed simple mean-averaging for sequential text, proving to be a strong approximation for deep-stacked models.
Discussion and Limitations
While the results are promising, the authors categorize them as "preliminary evidence." Current limitations include the relative simplicity and consistent formatting of the ICL tasks used. It remains to be seen how State Soups handle complex, reasoning-heavy tasks. Furthermore, while individual recurrences are linear, the interaction between layers in a deep stack is non-linear, meaning state-mixing becomes less precise as it propagates through deeper layers of the network. Future work will focus on formalizing task arithmetic and testing these methods on more diverse, real-world datasets.
Summary updated