KV Cache Compression in Long-Input LLM Workloads: Principles and Design Trade-offs
This article explains why long-input, short-output agent workloads place pressure on KV cache memory rather than compute throughput, then breaks down three design ideas behind a recent efficient inference model: half-depth causal encoding, cross-layer global KV cache sharing, and lower-precision KV storage. It also outlines how developers can profile workloads and estimate cache budgets across layers, sequence length, and precision.
A Typical Scenario: Read-Heavy, Write-Light
When using an LLM to drive a coding agent, a common pattern emerges: after modifying a batch of files, the agent needs to read tens of thousands of words of source code, test logs, and tool outputs back into context, while the next action instruction it generates is often only a few hundred words. As the agent loop continues, the compute and GPU memory the model spends on “reading input” can easily exceed the resources spent on “generating output.”
This workload can be summarized as: long input, short output, and frequent context continuation. The core pressure on the inference system is not compute throughput, but the GPU memory occupied by the KV cache. A recent technical report on a next-generation efficient inference model was designed around exactly this workload shape. According to the report, its global KV cache was reduced to about one quarter of that of the previous model in the same series, while compression along the sequence dimension became lighter rather than more aggressive. This seemingly contradictory result is worth unpacking at the principle level.
First, Why Is the KV Cache So Large?
A language model splits text into tokens—a token may be a character, part of a word, or a symbol. After each token enters a Transformer, it produces different hidden vectors at different layers; the attention mechanism reads information from previous context, and the feed-forward network further processes it.
The three core tensors in attention are Q, K, and V:
- Q (query): the request from the current position for “what I want to read”;
- K (key): labels from historical positions used to judge relevance to the query;
- V (value): the vectors that actually carry the information read back.
For a single query and one ordinary attention head, the computation can be formalized as:
o = softmax(q · Kᵀ / √c) · V
Here q ∈ R^(1×c) is the current query vector; K, V ∈ R^(t×c) contain the keys and values of t visible historical positions; c is the number of channels per vector; and o ∈ R^(1×c) is the readback result. Softmax normalizes relevance scores into weighting coefficients.
When generating the next token, the K and V of historical positions can be fully reused, so the inference system caches them—this is the KV cache. If each layer stores its own copy, the cache grows with both sequence length and layer count. More importantly, even when generating only one new token, information must be read from the entire historical cache, so the cache persists throughout the generation process.
A request therefore naturally splits into two phases:
- Prefill phase: process all input tokens in parallel at once and generate the first round of KV cache;
- Decode phase: generate token by token, with each new token’s attention scanning the historical cache.
The coding-agent scenario is precisely the worst-case combination: extremely long prefill, very short decode, and repeated prefill.
Design Idea 1: Half-Depth Encoding, Running the Full Network Only When Needed
One core idea in the next-generation model is to treat the network’s “read” and “write” paths asymmetrically. According to the public technical report, the model splits a 40-layer network into two segments:
- The first 20 layers form a causal encoder: when processing long input and understanding context, mainly this segment runs;
- The last 20 layers form a decoder: the full network runs only when actually generating new tokens.
Intuitively, input tokens only need to be “understood and indexed,” not “generated one by one,” so a subset of layers can causally encode the input; the generation side requires the expressive capacity of the full network. This follows the same spirit as traditional encoder-decoder architectures, but retains a causal mask to support seamless continuation.
For agent workloads, the benefit is direct: input goes through only half the depth, meaning that during prefill nearly half of the layers do not create the intermediate computation burden associated with that input, and this also creates a structural basis for later cache sharing.
Design Idea 2: Cross-Layer Sharing, Amortizing the Cache at Every Layer
In a traditional Transformer, each layer maintains an independent KV cache, so total cache size grows approximately linearly with layer count. This model series adopts a multi-layer shared global KV cache: multiple attention layers read and write the same global cache instead of storing separate copies.
This means:
- The same sequence information is stored only once in the cache, rather than duplicated at every layer;
- Several decoder layers can directly reuse retrieval and cache results produced during the encoder stage, further reducing duplicate storage and duplicate encoding.
Cross-layer sharing is one of the main sources of the “cache reduced to one quarter” result—it cuts redundancy in the depth direction, not information along the sequence-length direction.
Design Idea 3: Lower Storage Precision
Another major cost of the cache comes from numerical precision. The report discloses that the model uses lower KV storage precision. KV vectors are used for relevance scoring and information readback, and they generally tolerate quantization error better than weight matrices. As a result, common industry practice is to store the KV cache at lower precision first (such as INT8 or even lower), compressing GPU memory proportionally without significantly damaging output quality.
The fact that “sequence-direction compression is lighter” is precisely what makes room for low precision and cross-layer sharing: aggressive compression along the sequence dimension (such as extremely small KV groups or overly strong sparse attention) may damage detail recall in long contexts. Cross-layer sharing plus low-precision storage can deliver substantial space savings with little impact on sequence fidelity. This is a pragmatic engineering trade-off.
Implications for Developers
From an engineering perspective, this design offers three lessons for developers of long-context applications:
- The workload profile determines the optimization direction. If your application is “long input + short output + frequent continuation” (agents, repeated RAG reads, code review), cache-sharing architectures offer the largest benefit. If it is long-output generation (writing, translation), decode-side optimization is more critical.
- Estimate the cache budget across three dimensions: layers × sequence × precision. Evaluating GPU memory only by context length can easily underestimate the redundancy cost in the depth direction.
- When deploying on cloud, pay attention to the elasticity of the inference service. On general cloud platforms, you can combine container platforms for dynamic scaling, object storage for persisting intermediate artifacts of long contexts, and logging plus monitoring and alerting to track cache hit rate and generation latency, turning architectural benefits into observable online gains.
Conclusion
Reducing the global cache to one quarter is not the product of a single trick, but a system-level result of “half-depth encoding + cross-layer sharing + low-precision storage”: half-depth encoding reduces the number of layers that need to write cache, cross-layer sharing eliminates redundancy in the depth direction, and low-precision storage compresses the size of each element. Understanding the workload analysis behind this combination—reads far outnumber writes—is what allows you to make sound judgments when selecting inference services and optimizing costs for your own systems.
