Gated Differentiable Working Memory for Long-Context Language Modeling
Lingrui Mei, Shenghua Liu, Yiwei Wang, Yuyao Ge, Baolong Bi, Jiayu Yao, Jun Wan, Ziling Yin, Jiafeng Guo, Xueqi Cheng
TL;DR
Gated Differentiable Working Memory (Gdwm) reframes test-time adaptation for long-context LLMs as budget-constrained memory consolidation, introducing a Write Controller that gates updates based on Contextual Utility. Contextual Utility, grounded in CPMI, identifies high-value long-range dependencies, enabling a budget-aware allocation that guarantees global coverage across context chunks. Through chunk-restricted consolidation of LoRA adapters with a prefilled KV cache, Gdwm reduces gradient steps by up to $4\times$ while maintaining or improving performance, achieving a notable speedup of approximately $39\%$ in wall-clock time on ZeroSCROLLS and LongBench v2. The approach yields the strongest gains on sparse-information tasks, provides ablations validating each component, and offers theoretical variance-reduction guarantees via chunked updates, representing a meaningful advance in efficient long-context adaptation for LLMs.
Abstract
Long contexts challenge transformers: attention scores dilute across thousands of tokens, critical information is often lost in the middle, and models struggle to adapt to novel patterns at inference time. Recent work on test-time adaptation addresses this by maintaining a form of working memory -- transient parameters updated on the current context -- but existing approaches rely on uniform write policies that waste computation on low-utility regions and suffer from high gradient variance across semantically heterogeneous contexts. In this work, we reframe test-time adaptation as a budget-constrained memory consolidation problem, focusing on which parts of the context should be consolidated into working memory under limited computation. We propose Gdwm (Gated Differentiable Working Memory), a framework that introduces a write controller to gate the consolidation process. The controller estimates Contextual Utility, an information-theoretic measure of long-range contextual dependence, and allocates gradient steps accordingly while maintaining global coverage. Experiments on ZeroSCROLLS and LongBench v2 demonstrate that Gdwm achieves comparable or superior performance with 4$\times$ fewer gradient steps than uniform baselines, establishing a new efficiency-performance Pareto frontier for test-time adaptation.
