Cortex consolidates context gains into FFN weights: 88.9% gain recovery, 99.8% retention after 50 edits

Cortex: Consolidating Context into Parametric Memory

Jintian Zhang, Feng He, Xinnian Liang, Ziwen Xu, Haoming Xu, Haojing Huang, Shuangzhi Wu, Ningyu Zhang

cs.CL, cs.AI, cs.CV, cs.LG, cs.MA

2026-10-15

Cortex distills context gains into mergeable FFN updates: after 50 sequential edits on a 14B model it recovers 88.9% of the gain and keeps 99.8% of non-target performance.

What problem this solves

Give an LLM a piece of context and it gets better on the spot: unfamiliar API docs, a summary of past agent experience, an updated fact. Remove the material and the gain vanishes, because in-context inference never touches the parameters. RAG and external memory can store the raw content, but whether it gets used depends on retrieval at inference time, and indirectly relevant experience may never make it into the prompt.

This paper from Zhejiang University and ByteDance Seed formalizes the goal as Memory Consolidation (MC): given a model and a context that measurably helps, learn an updated model that works without the context, recovers the context-induced gain on target queries, and leaves behavior elsewhere untouched. Knowledge editing, skill learning, steering, and unlearning each previously came with its own interface; MC uses context as the common description and folds the four into one learning problem. Progress is tracked by a pair of metrics: Consolidation Rate (CR), the fraction of the context-induced gain recovered after context removal, and Retention Rate (RR), the share of original performance kept on queries outside the intended change.

Method

Cortex is built on three decisions.

What to learn: the model quizzes itself. The frozen pre-update model reads the context, generates prospective queries anticipating where the context will matter, then writes context-conditioned answers as training targets. No evaluation data is touched and no external teacher is needed. Agent tasks are the exception: queries come from environment trajectories, with a filter keeping only successful ones.

Where to write: FFNs only. FFNs act as key-value memory in Transformers and carry much of the factual associations, and restricting updates to them limits collateral damage, which the ablations confirm. Two variants mirror two forms of biological plasticity:

Both fold back into a standard FFN after training, so inference carries no extra structure. On MoE backbones, Structural adds one shared branch that every token passes through; per-expert expansions only receive gradients from routed tokens, leaving some added parameters barely trained. The router stays frozen.

How to learn: context-to-memory distillation. A frozen teacher sees the context; the student does not, and trains only the new parameters. The loss combines KL divergence on output distributions with MSE on hidden states after the FFN residual. Removing the context necessarily changes attention outputs, and the MSE term hands the new FFN parameters a direct target for compensating that shift. Sequential updates freeze all earlier writes. Query replay keeps past queries and regenerates their answers with the current model; past contexts are never stored.

Results

The main event: 50 sequential factual edits on Qwen2.5-14B-Instruct under the ZsRE protocol, averaged over three seeds.

MethodFinal CRFinal RRParams per edit
Cortex-Structural88.9%99.8%0.74M
Cortex-Synaptic80.6%97.2%2.73M
ROME (best baseline CR)28.5%not separately reported—
AlphaEdit22.7%96.0%—

By edit 50, FT-M, ROME, MEMIT, and AlphaEdit hit repetition or over-length termination in 86.2–91.3% of responses; the Cortex variants sit at 0.0% and 0.8%. Writing into weights no longer collapses under continual updates.

Single and batch settings cover six backbones from 4B to 120B (Gemma3-12B, Qwen2.5-14B, Qwen3-4B instruct and thinking, GPT-OSS-20B/120B):

SettingCortexBaselines
Persona steering (single)95–100% CR, 99–100% RRRR measured by fluency only
Batch factual editing (three Qwen backbones)80–91% CRbest of FT-M/MEMIT/AlphaEdit 36–46%
Batch novel-API learning (Qwen2.5-14B)66–74% CR, 98–99% RRLoCAS/δ-Mem −9% to 11% CR; OPCD 41%
ALFWorld (Qwen2.5-14B, single)128–133% CR, 88% RRwith-context model: 86% RR

The last row carries the most information: the consolidated model beats the original model holding the full experience summary, so contextual prompting is a reference, not a ceiling. Failures show up too. On GPT-OSS-20B τ2-Bench, Synaptic lands at −92.3% CR, below the untouched model. Knowledge suppression reaches 97–100% CR but neighboring-entity knowledge (RWKU Neighbor probes) drops 9–20 points; selectivity is the weakest link.

Ablations pin down each choice. A full-layer LoRA trained on identical data lands 23.0 CR points below Structural, so the gains do not come from the data alone. FFN-only updates beat FFN-plus-attention by 3.8 CR and 4.0 RR. Without replay, 25 further edits leave Structural at 40.5% and Synaptic at 8.0%; freezing old parameters does not freeze old behavior. The shared MoE branch adds 4.6 CR on ALFWorld and 10.3 on code at the same weight budget, and the smallest capacity (k=1) is the best in the sweep.

Why it matters

Continual knowledge editing gets a recipe that survives 50 updates, at 0.74M parameters per edit folded into the weights with zero inference overhead and no test-time memory routing, unlike WISE, GRACE, or SERAC. Beating the with-context model on ALFWorld shows parametric memory buys more than token savings. The five-task testbed with paired CR/RR metrics is promised open-source alongside the implementation, giving the area a comparable evaluation base.

This is a framework contribution as much as a point win: on single-edit CR, Doc2LoRA still reaches 95% against Cortex's 84–89%, at the cost of lower retention (86% vs 103–110%).

Limitations

Stated by the authors: useful experience must be expressible as text context the model can already exploit, and anything that cannot be written this way needs other learning mechanisms. Training still requires forward and backward passes through the backbone, which stays expensive at scale. Folding Structural expansions into FFNs does not reduce parameter count; pruning and reorganizing accumulated capacity is left as future work.

Visible from the results: portability lands at 49.4% against 95.3% efficacy, so answering with an edited fact is far easier than reasoning with one. Steering retention is measured by fluency alone, which the authors themselves note is not broad capability retention. Multimodal backbones were evaluated with text inputs only. Batch novel-API learning degrades sharply on GPT-OSS-20B, from 91–93% single to 45–59% batch. Each context in the testbed was manually constructed to produce a substantial context gap, so CR depends directly on context quality and cross-paper comparisons deserve care.

Terms

Source

Related papers

All paper explainers