Manuscript Offprint

arXiv:2610.05885

The Optimization Landscape of Learning Compacted Context Models

Thomas Villeneuve, Alex Sandomirsky, Charles O'Neill, Max Kirkby, Michael Psenka

Thomas Villeneuve

Base Labs

thomas.villeneuve@baseten.co

Alex Sandomirsky

Base Labs

alex.sandomirsky@baseten.co

Charles O'Neill

Base Labs

charles.oneill@baseten.co

Max Kirkby

Base Labs

max.kirkby@baseten.co

Michael Psenka

Base Labs

psenka@baseten.co

Abstract

Many works approach continual learning through the lens of infinite context windows. As an agent puts more observation into context (concretely the KV cache), compacting said context is akin to direct memory manipulation, without affecting the base model's weights. Many works pose KV compaction as an optimization problem: learn a smaller set of KV vectors that matches the behavior of the full KV cache. While this preserves base model behavior, optimizing through a frozen base model results in a highly nontrivial optimization problem with a brittle and flat loss landscape. In this paper, we characterize what makes these optimization problems difficult and demonstrate that a heavily simplified Perceiver-based architecture not only matches performance of a full Perceiver transformer in continuous context compaction, but outperforms baselines on compaction utility. Results are presented on MCQ tasks across Finance, Legal, Gutenberg, and Code.

1 Introduction

A key component of any continually-deployed model, whether text-based or robotic, is its memory management; what to keep, what can be forgotten, and what can be compressed down. Most language models today are at least in some part attention-based: as tokens are observed and the context grows (in the form of the KV cache), computation time scales quadratically, and observed tokens are less attended to. As such, rather than designing new architectures that bound memory or linearly scale with context, a growing line of work revolves around compacting the KV cache: either by evicting entries [Zhang et al., 2023, Li et al., 2024], by optimizing a cache per document [Eyuboglu et al., 2025, Zweiger et al., 2026], or by training a model that writes compact entries [Chari et al., 2025, O'Neill et al., 2026]. We refer to these kinds of models as compacted context models.

However, this optimization can often be difficult: per-document methods spend minutes of optimization per document, and optimizing through a fixed deep model introduces a highly nonlinear, highly non-convex structure. Without a deeper understanding of where and how these optimization difficulties arise, many of the same mistakes are silently made in parallel.

This paper provides a deeper characterization of the difficulty in optimizing through KV caches, starting from the smallest setting that exhibits the difficulty. A compression-free linear map already showcases difficulty in the optimization: near-identity maps can still fall into bad local minima. Measuring the loss surface directly shows why: the global solution sits in a needle-sharp basin surrounded by a wide, flat plateau (Figure 1b).

40th Conference on Neural Information Processing Systems (NeurIPS 2026). Workshop: Continual Learning in the Era of Foundation Models and Embodied Agents.

Figure

(a) Diagram for optimizing through the context via the KV cache.

Figure

(b) KL loss landscape.

Figure 1: Optimizing directly through context is appealing in keeping as much of the main model behavior as possible, but the loss landscape can be quite sharp. The loss landscape is given by the 2-parameter family in eq. (4), applied to all heads and layers instead of one, thus being much sharper than Figure 3.

Each of the loss landscape characteristics point to a specific potential fix that has been explored in some form in the literature. For the flat landscape, one could hope that a loss more densely supervised over the model could unflatten the landscape. This could be through the base model's forward pass in regulating attention passes through the full network the same way, or through more generated self-study examples on the input context. For the sharp basin, one could hope that relaxing the base model weights could make the overall optimization smoother and more tractable. However, we find that attempted fixes to the KV landscape quickly fail once compressions ratios increase, or compactions are iterated on each other (an inevitability for continually compacted memory models).

We then find that the most performant compacted context model is a heavily simplified, single-layer single head attention layer, depicted in Figure 6 and detailed in Section 5. Our KV compactor beats all compared baselines, both in terms of MCQ accuracy and compaction speed.

In summary, our contributions are:

  1. A set of synthetic experiments to visualize and characterize the optimization landscape of KV space optimization,

  2. An empirical account of why common fixes, including proxy losses, more data, and weight relaxation, do not reliably help, and

  3. A minimal cache writer, which we call Fast Diamond, that matches or beats more expressive writers and standard baselines under matched MCQ evaluation.

References (44)