AllMem: A Memory-centric Recipe for Efficient Long-context Modeling

Ziming Wang, Xiang Xiang Wang, Kailong Peng, Lang Qin, Juan Gabriel Kostelec, Christos Sourmpis, Axel Laborieux, Qinghai Guo · DOI

Abstract

Large Language Models (LLMs) encounter significant performance bottlenecks in long-sequence tasks due to the computational complexity and memory overhead inherent in the self-attention mechanism. To address these challenges, we introduce \textsc{AllMem}, a novel and efficient hybrid architecture that integrates Sliding Window Attention (SWA) with non-linear Test-Time Training (TTT) memory networks. \textsc{AllMem} enables models to effectively scale to ultra-long contexts while mitigating catastrophic forgetting. This approach not only overcomes the representation constraints typical of linear memory models but also significantly reduces the computational and memory footprint during long-sequence inference. Furthermore, we implement a Memory-Efficient Fine-Tuning strategy to replace standard attention layers in pre-trained models with memory-augmented sliding window layers. This framework facilitates the efficient transformation of any off-the-shelf pre-trained LLM into an \textsc{AllMem}-based architecture. Empirical evaluations confirm that our 4k window model achieves near-lossless performance on 37k LongBench with a marginal 0.83 drop compared to full attention. Furthermore, on InfiniteBench at a 128k context, our 8k window variant outperforms full attention, which validates the effectiveness of our parameterized memory in mitigating noise and maintaining robust long-range modeling without the prohibitive costs of global attention.

Introduction

Standard Large Language Models (LLMs) rely on the Transformer architecture, where the self-attention mechanism's computational cost grows quadratically ($O(L^2)$) and memory requirements for the KV cache grow linearly ($O(L)$) with sequence length. This "quadratic wall" makes processing ultra-long contexts—such as entire books or massive codebases—prohibitively slow and memory-intensive. While linear attention and State Space Models (SSMs) offer alternatives, they often struggle with high-precision backtracking. AllMem addresses this by treating memory as an active, trainable system rather than a passive cache.

The AllMem Architecture

AllMem utilizes a hybrid approach that splits each layer into two parallel branches to balance local precision with global context:

  1. Sliding Window Attention (SWA): This module maintains a fixed, local window of recent tokens (e.g., 4k or 8k). By focusing on local dependencies, it preserves the high-precision reasoning capabilities of standard attention.
  2. Non-linear TTT Memory: A Test-Time Training (TTT) network serves as the long-term parametric memory. Unlike static caches, this network's weights are updated during inference to compress and store global information.
The AllMem architecture consists of a high-level block combining SWA and a detailed Memory Layer utilizing non-linear TTT.

Key Technical Innovations

  • Non-linear Compression: AllMem employs a SwishGLU-based neural network as its memory unit, allowing for richer information compression than simple linear recurrences.
  • Internal Normalization: To ensure stability during online learning, the model follows a strict sequence: reading from memory, normalizing weights, and then updating. This decouples read stability from write plasticity.
  • Memory-Efficient Fine-Tuning (MEFT): Instead of training from scratch, AllMem uses a distillation pipeline to "upgrade" existing pre-trained models (like Qwen3). The original model acts as a teacher, allowing the AllMem variant to inherit its foundational knowledge.

Experimental Evaluation

Models were evaluated across a diverse suite of benchmarks:

  • Short-Context: C-Eval, ARC, HellaSwag, MMLU-Redux, and MATH-500 to verify general knowledge retention.
  • Long-Context: LongBench (37k tokens), InfiniteBench (128k tokens), and LV-Eval (128k tokens).

Performance and Efficiency

On the 37k-token LongBench, the AllMem 4k-window model achieved performance nearly identical to full attention, with only a 0.83 point drop. Remarkably, on InfiniteBench (128k context), the AllMem 8k-variant outperformed the full-attention baseline. This suggests that the parameterized memory acts as a filter, focusing on salient information while ignoring the "noise" that often plagues global attention in ultra-long sequences.

Comparison of standard Qwen3 models versus their AllMem-augmented counterparts across various short-context benchmarks.

Efficiency gains are equally significant. At a 128k context length, AllMem reduces FLOPs and KV cache storage to approximately 11% (1/9th) of a standard Transformer's requirements. Furthermore, as shown in the table above, the MEFT process successfully maintains or improves performance on standard short-form benchmarks, proving that the architecture does not suffer from catastrophic forgetting.

Conclusion

AllMem demonstrates that a hybrid architecture combining local sliding windows with active, non-linear memory can overcome the scaling limitations of standard Transformers. By achieving near-lossless performance at a fraction of the computational cost, AllMem provides a scalable recipe for the next generation of long-context LLMs. Future work will focus on scaling this architecture to 70B+ parameter models and exploring more complex hierarchical memory structures.

Summary updated

BibTeX
@misc{wang2026allmem,
  author = {Ziming Wang and Xiang Xiang Wang and Kailong Peng and Lang Qin and Juan Gabriel Kostelec and Christos Sourmpis and Axel Laborieux and Qinghai Guo},
  title = {{AllMem: A Memory-centric Recipe for Efficient Long-context Modeling}},
  year = {2026},
  eprint = {2602.13680},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2602.13680},
}
Figure