JJava Stack Lab
论文雷达 · arXiv AI

MemOnce:面向大语言模型的可扩展记忆架构

摘要

MemOnce 是一种基础架构,它让语言模型学习可扩展的记忆状态。它只用记忆编码器-解码器缓存最后一层的少量隐藏状态,再动态解码回 KV 缓存;同时用记忆稀疏注意力为每个连续输入自适应检索相关记忆,且稀疏索引只计算一次并跨层共用。论文称,在 1M 上下文下用 MemOnce 适配 Qwen3.5-4B,可将记忆状态缓存减少 1313 倍、prefill 延迟降低 6.9 倍、吞吐提升 3.5 倍,整体记忆性能提升 +5.77%。

查看原始标题和摘要

MemOnce: A Scalable Memory Architecture for Large Language Models

Deploying large language models (LLMs) in long-horizon and continual interactions requires maintaining reusable memory states for future inference, posing challenges for existing architectures. Standard Transformers accumulate layer-wise, token-level KV caches, incurring linear GPU memory growth and quadratic computational complexity as the context expands. In contrast, linear-time architectures compress history into fixed-size states, but struggle to retain fine-grained details. We introduce MemOnce, a foundation architecture that learns scalable memory states for language models. MemOnce is based on two core designs: (a) Memory encoder-decoder: it caches only a small subset of final-layer hidden states as compact memory representations and dynamically decodes them back into KV caches for attention layers; (b) Memory sparse attention: for each continual input, MemOnce adaptively retrieves relevant memory representations, with the sparse indices computed only once across layers. Coupling these two designs enables efficient on-the-fly memory loading and KV cache decoding, drastically reducing the GPU memory footprint and achieving linear-time complexity. We conduct extensive experim

核心要点

  • 标准 Transformer 会累积逐层、token 级的 KV 缓存,导致 GPU 显存近似线性增长、计算复杂度随上下文呈二次增长;线性时间架构虽然能压缩历史,但难以保留细粒度细节。
  • 记忆编码器-解码器只缓存最后一层少量隐藏状态作为紧凑记忆表示,并按需解码回注意力层所需的 KV 缓存。
  • 记忆稀疏注意力针对每个连续输入检索相关记忆表示,稀疏索引跨层只计算一次,从而支持运行时高效加载记忆和解码 KV 缓存。
  • 在 1M 上下文下适配 Qwen3.5-4B:记忆状态缓存减少 1313 倍,prefill 延迟降低 6.9 倍,吞吐提升 3.5 倍,整体记忆性能提升 +5.77%。
  • 在模型规模、上下文长度以及预训练和后训练适配等不同设置下,MemOnce 的表现优于 Transformer 等架构,并能零样本泛化到下游表示任务。

为什么值得后端工程师关注

对需要长上下文和持续交互的后端服务,KV 缓存是显存与延迟的主要瓶颈。MemOnce 的思路是把历史压缩成少量末层记忆状态、按需解码 KV,并跨层复用稀疏检索索引,从而在 1M 上下文场景下显著降低缓存占用和 prefill 延迟、提升吞吐。Java 和后端工程师可关注其减少显存占用、提高并发吞吐的潜力,以及推理服务中记忆缓存与稀疏检索的实现方式;但这些数据来自论文实验。