MemFold: Learning Compact Soft Memory for Long-Context Personalization via On-Policy Optimization
Organizations: University of North Carolina at Chapel Hill · University of California, Santa Barbara · Harvard University · University of Wisconsin–Madison
Abstract
An assistant that serves the same user over a long horizon has to answer from what that user has revealed: which preferences still hold, which were revised, and which constraints apply now. Retaining that information is not the same as acting on it, and the two are usually optimized as if they were. Keeping the information as text makes the reader's input grow with the retained history, while compressing it into a fixed number of latent vectors bounds the interface but is typically trained to reconstruct text or imitate reference answers, both of which are scored on sequences the reader never produced. We present MemFold, which optimizes a fixed-budget soft memory by the behavior it supports. A query-conditioned textual memory is compressed into K continuous vectors that form the reader's memory interface, and the reader is then trained on its own rollouts under two complementary signals: group-relative rewards for task outcomes, and confidence-gated on-policy distillation in which a frozen textual-memory teacher re-scores the student's sampled tokens under the textual memory. The teacher is never sampled from, so supervision stays on the student's current distribution and adds no autoregressive decoding; at inference it is removed entirely. Across three Qwen backbones, MemFold attains the highest accuracy we measure on PersonaMem-32K and PersonaMem-128K, with margins that widen at the longer history length, and transfers to PrefEval and LongMemEval without target-domain training. Ablations attribute most of the task gain to the reward term and a smaller additional gain to the teacher signal, and memory interventions show that the reader depends on the instance-specific content of its soft memory.
Figures & tables
| Method | Initialization | On-Policy Objectives | Memory Interface | PersonaMem-32K | PersonaMem-128K | ||||
|---|---|---|---|---|---|---|---|---|---|
| Writer | Reader | OPD | GRPO | Mean | Pass@16 | Mean | Pass@16 | ||
| w/o Writer Initialization | ✗ | ✓ | ✓ | ✓ | Soft | 70.8 | 82.0 | 80.0 | 85.7 |
| w/o Reader Initialization | ✓ | ✗ | ✓ | ✓ | Soft | 47.9 | 76.0 | 46.2 | 67.0 |
| w/o OPD | ✓ | ✓ | ✗ | ✓ | Soft | 71.9 | 84.0 | 86.9 | 91.8 |
| w/o GRPO | ✓ | ✓ | ✓ | ✗ | Soft | 58.6 | 78.0 | 70.2 | 82.3 |
| Initialization Only | ✓ | ✓ | ✗ | ✗ | Soft | 60.5 | 82.0 | 70.8 | 85.1 |
Appendix figures & tables6 assets
Supplementary material from the paper’s appendix.
Appendix
| Backbone | Layer | Dev. Score | Update Top-1 | Update AUC | Margin |
|---|---|---|---|---|---|
| Qwen2.5-3B | L1 | 98.98 | 96.12 | 97.55 | 0.207 |
| L4 | 100.00 | 100.00 | 100.00 | 0.319 | |
| L12 | 94.39 | 79.61 | 90.37 | 0.091 | |
| L24 | 86.13 | 67.96 | 79.04 | 0.042 | |
| L36 (final) | 77.49 | 37.86 | 51.76 | ||
| Qwen3-4B | L1 | 95.92 | 93.20 | 96.35 | 0.148 |
| Hyperparameter | Setting |
|---|---|
| Memory representation and compressor | |
| Soft-memory budget | 256 soft tokens |
| Mean-pooling window | 32 hidden states |
| Compressor depth | 2 layers |
| Latent dimension | 768 |
| Attention heads | 12 |
| Procedure | Learning Rate | Duration | Updated Modules |
| Memory-interface initialization | |||
| Memory-writer initialization | 3 epochs | Adapter | |
| Compressor reconstruction | 25 updates | Compressor, projector | |
| Representation warmup | 100 updates | Compressor, projector | |
| Auxiliary reasoning adaptation | 3 epochs | Temporary LoRA , compressor, projector | |
| Reader initialization | 3 epochs | Adapter, selected compressor modules, projector | |
| Method | Student Input | Initialization | Supervision | Loss |
|---|---|---|---|---|
| GRPO | Full interaction history | Base model | Task reward | |
| OPSD | Full interaction history | Base model | On-policy self-distillation | |
| SDPO | Full interaction history | Base model | Successful-rollout feedback; EMA teacher | |
| GRPO+OPD | Full interaction history | Base model | Task reward; textual-memory teacher | |
| MemFold | soft-memory vectors | Reader-initialization checkpoint | Task reward; textual-memory teacher |
| Method | #Tok. | Accounting Note |
|---|---|---|
| Full Text / GRPO / OPSD | contains the full visible history, query, and instructions. | |
| xRAG | Counts retriever inputs and projected retrieval positions consumed by the reader. | |
| AutoCompressor | Each compression pass includes processed text and carried summary positions. | |
| MemGen | Weaver and reasoner computation are counted separately; repeated history reads are retained. | |
| MemFold | Counts memory generation and subsequent compressor encoding as separate operations. |
Persistent Memory for Language Models
Persistent memory for language models studies how models retain, update, and use information across interactions and beyond their context windows.
See all 272 papers