TL;DR
When language models "think" out loud to solve hard problems, their memory footprint balloons with every generated word, creating a massive hardware bottleneck. Instead of relying on hand-crafted rules to clean up this memory, Neural Garbage Collection (NGC) uses reinforcement learning to let the model decide for itself what to forget—using nothing more than a simple reward for getting the final answer right. By treating efficiency as a learned skill rather than an engineering patch, NGC slashes peak memory usage by 2–3x while keeping reasoning sharp.
What Problem Does This Paper Address?
Allowing language models to generate long, step-by-step chains of thought has unlocked incredible problem-solving abilities. However, Transformers remember their past thoughts by storing internal representations of every token in a KV (Key-Value) cache. As a model ponders a complex math puzzle over thousands of steps, this cache grows linearly, rapidly eating up GPU memory.
Humans don't do this. When you multiply two large numbers on scratchpaper, you remember the final product and crumple up the intermediate carry-overs. Much of a model's KV cache is similarly transient scratch work. Until now, researchers have tried to prune the cache on the model's behalf using fixed heuristics (like dropping older tokens or those with low attention scores) or auxiliary compression losses. The problem? These hand-designed proxies only guess at what the model actually needs downstream to solve the task. The authors ask: If a model can learn to reason from scratch, why can't it learn to forget?
Methods
NGC extends standard reinforcement learning for reasoning—where generating a token is treated as a discrete action—by making cache eviction a discrete action, too.
Here is how the "grow-then-evict" cycle works (applied to a 1.5B-parameter model):
- Zero-Parameter Scoring: Every $\delta$ tokens, the model pauses for an eviction round. Rather than adding new neural network layers to judge memory utility, NGC repurposes the Transformer's native attention mechanism. It averages how much the 5 most recent tokens attend to past keys, grouping keys into contiguous 32-token blocks to simplify credit assignment and align with GPU memory pages.
- Stochastic Forgetting: Instead of deterministically keeping the highest-scored blocks, NGC adds Gumbel noise to sample a subset of blocks to keep (the Gumbel-top-$k$ trick). This makes the discrete choice mathematically compatible with policy gradients, allowing a single binary task reward (correct vs. incorrect final answer) to jointly update both how the model reasons and what it chooses to remember.
- Replay Attention Masks: In standard RL training, you re-evaluate a generated sequence in one parallel forward pass using a standard causal mask. Because NGC permanently deletes memories mid-thought, standard masks would let later tokens "cheat" by seeing evicted tokens during training. NGC records exact token visibility into a custom replay mask per layer, keeping training strictly on-policy with zero extra forward-pass overhead.
- Staircase Curriculum: To prevent early training collapse, the model starts with gentle eviction rates that gradually step up to aggressive memory cuts.
Datasets
No new benchmarks are introduced; the authors use established reasoning datasets to test learning from scratch and out-of-distribution generalization:
- Countdown: A combinatorial arithmetic game (combining 3–4 numbers via basic operations to hit a target). Used for controlled training (327,680 problems) and testing (1,024 problems).
- DAPO-17k: A large-scale, diverse mathematical reasoning dataset used for larger-scale RL training.
- AMC 2023, AMC 2025, and AIME 2025: Standard, challenging high-school math competition benchmarks used purely for held-out evaluation.
Key Insights and Ideas
- Efficiency is a learnable capability: You don't need auxiliary distillation losses or human-written summarization prompts to manage memory. Pure end-to-end pressure from an outcome reward forces the model to figure out what is scratch work and what is vital context.
- Heuristics are brittle across tasks: A fixed rule like SnapKV (which evicts based on raw attention weights) works decently on competition math yet fails miserably on Countdown. Learned garbage collection adapts its memory strategy to the task at hand.
- "Budget-Aware Interoception" helps models plan: Simply appending a tag like
<eviction_rate>50%</eviction_rate>to the prompt lets the model "sense" its memory constraints ahead of time, leading to much more graceful performance degradation—and an 8–13% accuracy boost on Countdown—even under extreme memory budgets never seen during training. - Both halves of the gradient matter: Ablations show that merely dropping KV entries during training ("KV dropout") fails (2.5% accuracy), and fixing the replay mask without sending gradients through the eviction decisions themselves falls short (35.7% vs. NGC's 49.6%).
Key Results
Across all experiments, NGC substantially outperforms heuristic eviction baselines (SnapKV, KeyDiff, KNorm, and StreamingLLM):
- Countdown: At a 2.4x reduction in peak KV cache size (evicting 50% of the cache each round), NGC achieves 49.6% pass@1 accuracy—more than doubling the next-best baseline, KeyDiff (21.2%), while SnapKV hits just 7.8%.
- Competition Math: Trained on DAPO-17k and evaluated at 3–5x peak cache reductions, NGC consistently beats all baselines on AMC 2023, AMC 2025, and AIME 2025 across pass@$k$ metrics ($k=1$ to $32$). At moderate 2–3x cache reductions, NGC closely approaches the upper-bound accuracy of an unconstrained, full-cache model.
Limitations and Future Work
Because of academic compute constraints, the study focuses exclusively on a single 1.5B-parameter model (DeepSeek-R1-Distill-Qwen-1.5B) and relies on cleanly verifiable math and logic tasks with unambiguous binary rewards. Furthermore, the authors evaluate algorithmic efficiency via peak KV cache size rather than wall-clock inference speedups, noting that timing is easily confounded by system-level batching effects. Natural next steps include scaling NGC up to frontier model sizes and extending the framework to domains with softer, non-binary reward signals.
Summary updated