KV Cache Compression for Long-Input Workloads: Why Reading Costs More Than Writing

    This article explains why long-input LLM workloads are often read-heavy and memory-bandwidth bound, and how KV cache growth drives capacity planning, concurrency, and time-to-first-token issues. It covers the attention formula behind cache expansion, the resource profiles of prefill and decode phases, and three general cost-reduction paths: segmented encoding, cross-layer global cache sharing, and lower-precision storage. It also provides a practical capacity estimation formula and engineering recommendations for cache limits, prefix reuse, observability, and load testing.

    1. The Problem: Why Reading Costs More Than Writing

    In applications such as AI coding assistants, document Q&A, and long-log analysis, a typical turn often works like this: a tool modifies several files, then the model has to read back tens of thousands of words of source code, test output, and stack traces, only to produce a few hundred words describing the next action. In other words, the compute and GPU memory consumed on the input side are often several times larger than on the output side. If an inference system still estimates resources based on generation length, it leads to distorted capacity planning, limited concurrency, and unstable time-to-first-token (TTFT).

    These workloads share three characteristics: very long inputs, frequently continued contexts, and very short new output per turn. Together, they mean the optimization focus is not on faster decoding, but on making repeated reads of long contexts cheaper.

    2. Why the Cache Grows: Starting from the Attention Formula

    A language model splits text into tokens. Each token passes through multiple layers of hidden representations: attention pulls information from historical positions, and the feed-forward network continues the processing. The read for a single query and a single attention head can be written as:

    1. o = softmax(q * K^T / sqrt(c)) * V
    2. q ∈ R^{1×c}, K,V ∈ R^{t×c}, o ∈ R^{1×c}

    Here, t is the visible history length and c is the number of channels. When generating a new token, the K and V of historical positions do not need to be recomputed, so they are cached. This is the KV cache. If each layer stores its own copy, the cache size is roughly proportional to “number of layers × sequence length × number of channels × bytes per element,” and long-input scenarios can quickly saturate GPU memory bandwidth.

    3. Two-Phase Workloads: Resource Profiles of Prefill and Decode

    A request is usually split into two phases. The prefill phase processes the entire input in parallel; it is compute-intensive, and memory access is relatively one-off. The decode phase computes only one new token at a time, but it has to read the entire historical cache each time, which is a typical memory-bound workload. Optimization therefore needs to be considered separately: prefill focuses on parallelism and chunking strategies, while decode focuses on cache size and bandwidth.

    4. Three Cost-Reduction Paths

    The technical report of a recent lightweight inference model is built around the workloads described above, and its approach can be abstracted into three general paths:

    1. Segmented encoding: split a deeper network into a first-half causal encoder and a second-half decoder. Long inputs mainly go through the first half, and the full network is used only when generating new tokens, reducing repeated computation.
    2. Cross-layer sharing of a global cache: multiple layers share the same global KV, and some layers even reuse intermediate retrieval results. The cache no longer grows linearly with the number of layers.
    3. Lower storage precision: store cache elements at a lower bit width, combined with chunking and quantization strategies to control error.

    The combined result is lighter compression along the sequence dimension, while the global cache can be reduced to about one quarter of the previous generation. The savings come mainly from sharing and precision, not from sacrificing context length.

    5. Capacity Estimation and Engineering Recommendations

    For a rough estimate, engineers can use the following formula:

    1. cache_bytes ≈ layers_effective × seq_len × channels × bytes_per_elem × batch

    Here, layers_effective is significantly smaller than the physical number of layers because of sharing. Practical recommendations include: set cache limits by input-length tiers; reuse prefix caches for continued sessions; connect monitoring alerts, logging services, and object storage into an observability loop; run canary releases and load tests on a container platform, using real long-input samples to regression-test TTFT and throughput. If managed inference capabilities are needed, evaluate the general model service offerings from cloud providers first, rather than building the entire underlying stack in-house.

    6. Conclusion

    The core tension in long-input workloads is the conflict between “read-heavy, write-light” access patterns and a cache that grows linearly with layers and length. Segmented encoding, cross-layer sharing, and low-precision storage provide a reusable cost-reduction path: without noticeably hurting quality, they compress the global cache to roughly one quarter, giving high-concurrency, long-context applications a practical cost structure.