Why KV Cache Drops to One-Quarter in Long-Input Scenarios
This article explains why a long-context inference architecture can reduce its global KV cache to roughly one-quarter of the previous generation. Using a representative workload—a coding agent that reads back tens of thousands of tokens of source code, test logs, and tool output but generates only a few hundred tokens—it shows that the savings do not come from truncating context. Instead, they come from three combined trade-offs: cross-layer KV cache sharing, lower storage precision, and lighter sequence compression. The article walks through attention mechanics, the prefill/decode split, asymmetric layer partitioning, and the engineering implications and limits of this design.
Evaluating a long-context inference architecture should not rely on the model name or a single performance number. What matters is the workload it actually serves. A recent public technical report describes a representative case: after modifying a file, a coding agent may read back tens of thousands of tokens of source code, test logs, and tool output, then generate only a few hundred tokens describing the next step. Run after run, the resources a model spends on “reading” can easily exceed those spent on “writing.” For this kind of workload—long input, short output, frequent context continuation—the report proposes an asymmetric layer split with a cross-layer shared KV cache, and reports an observation that the global KV cache drops to about one-quarter of the previous generation. That result is worth unpacking: it is not simply truncating the context, but a set of trade-offs across three directions—cross-layer sharing, storage precision, and sequence compression.
1. The Workload Has Changed: Reading Context Costs More Than Writing Answers
In traditional dialogue or short-text generation, output length is often on the same order as input length, so inference cost is easily attributed to “how many tokens were generated.” But in coding agents, code review, log analysis, and tool-call orchestration, the input side keeps expanding: source files, failing test stack traces, command output, and retrieved document snippets are repeatedly concatenated into the context. What the model actually generates—the next step—may be only a short plan, a patch description, or a set of tool-call arguments.
This has two direct consequences. First, the prefill stage must process more historical tokens, increasing both attention computation and cache writes. Second, during token-by-token decoding, each step adds only one new token but must read a large amount of information from the historical KV cache. In other words, cost shifts from “writing” to “reading.” If every layer keeps its own full KV cache, then the more layers and the longer the context, the more pronounced the cache footprint and memory-bandwidth pressure become. When evaluating this kind of architecture, you must put the workload profile first; otherwise it is easy to misread long-input optimization as ordinary generation speedup.
2. Why the KV Cache Grows: Starting from the Attention Formula
A language model splits text into tokens, and each token forms hidden vectors at different layers as it passes through the network. The attention mechanism is usually described with Q, K, and V. You can think of Q as the query issued from the current position, K as what determines which historical positions are relevant, and V as carrying the information to be read back. For a single query and a single ordinary attention head, the computation can be written as:
o = softmax(qK^T / sqrt(c)) V
Here q is the current query vector, K and V contain the keys and values of visible historical positions, c is the number of channels, and o is the read-back result. This expression is only for building intuition; real implementations also involve multi-head attention, masking, grouping, and compression.
When generating the next token, the K and V of historical positions can be reused, so the system stores them—this is the KV cache. The problem is that if every layer keeps its own KV cache, the cache size is roughly proportional to “number of independently cached layers × visible history length × number of heads × number of channels × bytes per element.” The longer the context and the more layers, the larger the cache; even when generating a single new token, the system must read from these caches. The long-input, short-output agent workload exactly amplifies this tension.
3. Two-Phase Requests: Prefill and Token-by-Token Decoding
A single autoregressive request is usually split into two phases. The first is prefill: the existing context is fed into the network all at once to build the K and V cache for historical tokens and compute the representations needed for subsequent decoding. The second is decoding: each step generates one new token, reads the historical cache, and updates it. Prefill is compute-intensive; decoding is memory-bandwidth-intensive. Long input raises prefill cost and also makes each decoding step’s cache reads heavier.
So optimizing for long input cannot focus only on “generation speed.” If the cache organization stays the same, then even with a fast generation phase, the model gets held back by reading and writing the historical cache. The report’s design starts precisely from this two-phase structure: when processing long input, it mainly runs the first half of the network; when generating new tokens, it still runs the full network. This asymmetric execution is the premise for understanding the cache reduction that follows.
4. Asymmetric Layer Split: Long Input Runs Half the Way, Generation Runs the Full Way
The configuration disclosed in the report divides the network into a front and a back half: the first half handles causal encoding, and the second half handles decoding and generation processing. When processing long input, it mainly runs the first half; when generating new tokens, it still runs the full network. In other words, “reading in” a long context does not require every layer to run in full, while the generation phase keeps the full network to preserve output quality.
The key of this design is not “running fewer layers” itself, but that during training the front half’s output must be aligned with the back half’s decoding. Otherwise, the representations formed by the front half cannot support the later layers’ processing, and cache sharing would cause quality loss. You can understand it as a workload-oriented asymmetric computation: the input side pursues high throughput and low cache footprint, while the output side retains full expressive power. The pseudocode can be sketched as:
def prefill(tokens, shared_kv_cache):h = embed(tokens)for layer in encoder_layers: # Front half: process long inputh = layer(h, cache=shared_kv_cache)return h, shared_kv_cachedef decode_step(token, shared_kv_cache):h = embed(token)for layer in full_layers: # Generation phase: run the full networkh = layer(h, cache=shared_kv_cache)return next_token, shared_kv_cache
The pseudocode omits masking, multi-head attention, and cache-indexing details, but it conveys the core idea: long input mainly runs the front half, generation runs the full network, and the cache is managed centrally by a shared region.
5. Cross-Layer Sharing: From “One Copy per Layer” to “One Global Copy”
The first source of the cache reduction is cross-layer sharing. In the traditional approach, each layer stores its own KV cache, so more layers mean more independent copies. The report’s idea is for multiple layers to share a global KV cache, with some layers even reusing retrieval results together. Sharing does not mean all layers are fully equivalent; rather, through compatible key-value representations, sharing granularity, and access patterns, it reduces redundant storage.
The benefit is direct: the “number of independently cached layers” term in the cache-size formula goes down. In a long-input agent scenario, tool output, source snippets, and retrieval results may recur repeatedly; if every layer keeps an independent copy, redundancy is high. After sharing, repeated information can be reused from the global cache. Having some layers include retrieval results in the reuse scope means recurring tool output does not need an independent copy at every layer. Of course, sharing has a cost: the greater the representational difference between layers, the higher the error risk from sharing, which must be paired with training-time alignment and error control.
6. Precision and Sequence Compression Trade-offs: Why Not Just Truncation
The second source of the cache reduction is lower storage precision. The fewer bytes each element in the KV cache occupies, the lower the total footprint. Reducing storage bit width cuts memory usage and bandwidth pressure, but introduces quantization error—especially unfriendly to fine-grained references, code symbols, and log numbers in long contexts. So low-precision storage must be paired with quantization-error control, outlier handling, and calibration strategies; it cannot be understood as “unconditional compression.”
The third direction is sequence compression. The report mentions that the new scheme compresses more lightly along the sequence dimension. This can be confusing: if compression is lighter, why does the cache still shrink? The reason is that total cache size is not determined by sequence compression alone. Lighter sequence compression means retaining more historical detail, which suits coding agents that need to precisely reference source code and logs; but cross-layer sharing reduces the number of independent copies, and low precision reduces bytes per element—together these savings exceed the increase from lighter sequence compression. A rough estimate can be written as:
C_total ≈ L_indep × T_visible × H × d × B
Here L_indep is the number of independently cached layers, T_visible is the visible history length, H is the number of heads, d is the number of channels, and B is bytes per element. Sharing lowers L_indep, low precision lowers B, and lighter sequence compression may raise T_visible; the net effect can still bring the global KV cache down to about one-quarter of the previous generation. This result is not the victory of a single trick, but an engineering outcome of multiple stacked trade-offs.
7. Where the One-Quarter Comes From: Order-of-Magnitude Estimate and Engineering Meaning
Breaking down “about one-quarter,” it can be understood as a change in how the cache is organized: previously each layer stored its own copy, now multiple layers share a global cache, so the number of independent copies drops; previously each element was stored at a higher bit width, now at lower precision, so the per-element cost drops; meanwhile the sequence dimension is not aggressively truncated, retaining more historical detail. Together, these three effects substantially shrink the global KV cache.
In engineering terms, this has several impacts. First, the cache footprint after long-input prefill is lower, so a single machine can carry longer concurrent contexts. Second, the cache read per decoding step drops, easing memory-bandwidth pressure and making per-token latency more controllable under long context. Third, cache sharing raises the bar for scheduling and indexing: how to allocate and reclaim the shared region, and how to avoid cross-request contamination, all become system-design problems. Fourth, low precision and cross-layer sharing require end-to-end evaluation—not just the cache ratio, but also code-completion accuracy, log-reference correctness, and tool-call success rate.
8. Applicability Limits: Not All Workloads Benefit Equally
This architecture clearly favors workloads with “long input, short output, frequent context continuation.” For short-input, long-output tasks, strong creative generation, or tasks extremely sensitive to numerical precision, the benefit may be limited, and a more conservative precision strategy may even be needed. Cross-layer sharing has limits too: if different layers need very different key-value representations, sharing constrains expressive power; if retrieval-result reuse granularity is too coarse, it may pull irrelevant information into later layers.
So evaluating this kind of scheme should return to workload fit. What it solves is not the generalized problem of “all inference is faster,” but the structural cost of “read-heavy, write-light” in long-context agent scenarios. To judge its value, look at end-to-end throughput, first-token latency, subsequent-token latency, cache hit rate, quality regression, and system complexity—not just a single cache-reduction multiple.
9. Conclusion: Evaluate Whether the Structure Fits the Workload
The value of this technical report is that it does not reduce long-context optimization to “truncation” or “swapping in faster operators.” Instead, it restructures cache cost across multiple levels: network layer split, global KV cache sharing, storage precision, and sequence compression. Long input mainly runs the front half, and generation runs the full network; multiple layers share a global KV cache, with some layers reusing retrieval results; sequence compression is lighter but storage precision is lower, ultimately bringing the global KV cache down to about one-quarter of the previous generation. This result shows that the optimization space for long-context inference lies not only in the attention algorithm itself, but also in how the cache is organized and in its read/write paths.
For developers and system designers, the more valuable takeaway is the methodology: first identify the ratio of “reading” to “writing” in the workload, then determine whether the cache bottleneck comes from layer count, sequence length, or storage bit width, and finally use sharing, precision, and computational asymmetry as combined trade-offs. Only by placing the architecture choice back into the specific workload does the cache-reduction ratio carry engineering meaning.
