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

Large Language Models (LLMs) frequently get overwhelmed by long documents, leading to diluted attention and forgotten details. This paper introduces GDWM (Gated Differentiable Working Memory), a test-time adaptation framework that uses an information-theoretic metric to dynamically allocate compute only to the most critical parts of a text. By focusing on context-heavy regions rather than processing everything uniformly, GDWM matches or exceeds state-of-the-art performance while using 4× fewer gradient steps and delivering a 39% wall-clock speedup.

What Problem Does This Paper Address?

As context windows expand, transformers face a fundamental challenge: attention scores dilute over thousands of tokens, causing models to miss critical information hidden in the middle of a document.

A promising recent solution is Test-Time Adaptation (TTA) or Test-Time Training (TTT). Instead of relying purely on static weights, TTA updates a set of temporary "fast weights" (like LoRA adapters) on the fly as the model reads the input context. However, existing TTA methods use uniform write policies, stochastically sampling tokens across the entire document. This is highly inefficient because it wastes precious compute on low-value regions (e.g., words that are easily predicted from immediate local context) and suffers from high gradient variance when conflicting updates from semantically disparate sections of a long text interfere with each other.

Methods

GDWM reframes test-time adaptation as a budget-constrained memory consolidation problem: Given a limited computational budget, which parts of the context actually deserve to be written into working memory?

The framework operates in four distinct stages:

  1. Chunking: The long input text is partitioned into fixed-size chunks (defaulting to 1,024 tokens) to serve as semantic proxies.
  2. Gating (Utility Estimation): For each chunk, a Write Controller estimates its Contextual Utility. This metric uses Conditional Pointwise Mutual Information (CPMI) to calculate the absolute divergence between predictions made with full global context versus those made with only a short local context window (512 tokens).
  3. Allocation: Compute is distributed using a Coverage-First Softmax Allocation policy. To prevent the model from hyper-focusing on a single high-utility section (mode collapse), every chunk is guaranteed a baseline allocation ($k_{min}$). The remaining gradient budget is then distributed proportionally based on the chunks' utility scores.
  4. Consolidation: Finally, the model executes chunk-restricted gradient updates on the fast weights (specifically targeting the Query $W_Q$ and Output $W_O$ projection matrices) using a next-token prediction loss, while keeping the global Key-Value (KV) cache frozen.
High-level overview of the four-stage GDWM pipeline

Datasets

The authors evaluated GDWM across three model scales (Qwen3 1.7B, 4B, and 8B) using two major long-context benchmarks:

  • ZeroSCROLLS: A zero-shot benchmark spanning six tasks, including query-based summarization (GovReport, QMSum), long-context QA (Qasper, NarrativeQA), multiple-choice comprehension (QuALITY), and multi-hop QA (MuSiQue).
  • LongBench v2: A realistic long-context benchmark consisting of 503 complex multiple-choice questions with contexts ranging from 8k to 2M words, covering domains like single/multi-document QA, code repository understanding, and long dialogue history.

Key Insights and Ideas

  • Absolute Divergence Captures "Surprisal": Instead of just looking at where long context helps, GDWM takes the absolute value of the divergence between global and local predictions. This captures both positive surprises (where long context clarifies text) and negative conflicts (where long context contradicts local text)—both of which are critical signals that the model needs calibration.
  • Variance Reduction via Isolation: By restricting gradient updates to individual chunks rather than sampling globally, GDWM mathematically eliminates inter-chunk variance (proven via the Law of Total Variance). This prevents destructive interference between unrelated topics within the same document.
  • The Danger of Evidence Fragmentation: The authors identify a strict lower bound for chunk sizing based on a task's "evidence span." If chunks are cut too small (e.g., 256 tokens) for a multi-hop reasoning task that requires connecting facts across 1,000 tokens, the individual fragments appear low-utility in isolation, causing the gating mechanism to fail catastrophically.

Key Results

  • New Pareto Frontier: GDWM with only 8 gradient steps (GDWM-8) achieves comparable or superior performance to uniform baselines utilizing 32 steps (qTTT-32), representing a 4× reduction in compute steps.
  • Wall-Clock Speedup: Despite the extra forward passes required to calculate the utility scores, GDWM achieves a 39% net wall-clock time reduction compared to the 32-step uniform baseline.
  • Dominance on Sparse Tasks: GDWM excels on tasks where information is localized and sparse, yielding massive improvements of up to +12.7% on Qasper and +11.2% on GovReport (using the 1.7B model).
Efficiency vs Performance Pareto Frontier on ZeroSCROLLS

Limitations and Future Work

While highly effective, the authors note a few limitations:

  1. Fixed Chunking: Rigidly splitting text every 1,024 tokens can accidentally fragment coherent paragraphs or semantic units in irregularly structured documents.
  2. Dense-Coverage Trade-offs: For tasks that inherently require uniform attention across the entire document (like holistic summarization or long dialogues), selective allocation offers narrower benefits.
  3. Hyperparameters: The framework introduces parameters like temperature ($\tau$) and minimum coverage ($k_{min}$), which might require recalibration under extreme domain shifts.

Future Directions: The team aims to explore semantic-aware dynamic chunking, task-adaptive temperature scheduling, and extending the framework to handle long-context multimodal inputs.

Summary updated

BibTeX
@inproceedings{mei2026gated,
  author = {Lingrui Mei and Shenghua Liu and Yiwei Wang and Yuyao Ge and Baolong Bi and Jiayu Yao and Jun Wan and Ziling Yin and Jiafeng Guo and Xueqi Cheng},
  title = {{Gated Differentiable Working Memory for Long-Context Language Modeling}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2026},
  doi = {10.18653/v1/2026.acl-long.1471},
}
Figure