KV Cache Architecture for Long-Input, Short-Output Workloads

    This article explains why read-heavy, write-light LLM workloads make KV cache and prefill the main bottlenecks, and how asymmetric prefill/decode execution, cross-layer shared global KV cache, and lower storage precision can cut cache size to about one quarter of prior designs without aggressive token compression.

    In intelligent coding tools, a common workload is: after a file change, the model rereads large amounts of source, test logs, and tool output, then after several reasoning turns produces only a small next action. The signature is long input, short output, and frequent context continuation. Resources spent on “reading” often exceed those spent on “writing.” Around this pattern, the industry has developed lightweight architectures for long-input, short-output loads: run mainly the first half of the network on long inputs, and the full network when generating new tokens; compress cache via multi-layer shared global KV cache and lower storage precision. Public reports describe configurations where global KV cache falls to about one quarter of the previous generation. This article does not evaluate products. It explains, at the mechanism level, why KV cache still drops sharply when input only runs halfway, which scenarios fit, and what engineering trade-offs exist.

    1. The workload: why “read” becomes the main cost

    Language models split text into tokens. Each token produces hidden vectors at different layers. Attention reads from history; feed-forward layers process further. When generating the next token, past keys and values can be reused, so the system caches them—the KV cache. A request typically has two stages:

    • Prefill: process existing input and build state for later generation
    • Decode: generate tokens one by one while reading historical cache

    Short-input, long-output workloads are decode-heavy. Coding assistants, log analysis, code review, and multi-turn tool calls are often long prefill and short decode. The model repeatedly rereads tens of thousands of words of source, logs, and tool output, then writes only a few hundred words. Even with short output, each continuation still reads a large historical KV cache. Cache capacity, cache read bandwidth, and prefill compute become the bottlenecks.

    2. Why KV cache grows

    For single-layer, single-head attention, with query, key, and value Q, K, V:

    Attention(Q,K,V)=softmax(QK^T/√d_k)V

    Q is the current-position query, K scores relevance of history, V carries information to read back. Past K and V remain usable when generating new tokens, so they must be stored. If every layer keeps its own copy, cache size is roughly:

    M≈2×L×t×c×b

    L is layer count, t visible history tokens, c channels, b bytes per element, and 2 for K and V. Longer sequences, more layers, and higher precision all enlarge cache. Multi-turn continuation accumulates history tokens and inflates occupancy further.

    Traditional optimizations focus on the sequence axis: token eviction, sparsity, quantization, or block compression. Long-input settings are sensitive to token-level compression: details in source, logs, and tool output can affect later decisions, and aggressive compression hurts quality. Some designs therefore compress the sequence axis lightly and save space mainly via cross-layer sharing and storage precision.

    3. Input runs halfway: split prefill and decode

    “Input runs halfway” does not mean generation uses only half the network. It means asymmetric prefill and decode. Split the network into two segments: on long input, mainly run the first-half causal encoder and build a global cache for later reads; when generating new tokens, still run the full network to keep output quality. The direct gain is lower prefill compute, because the input stage need not emit tokens, and some later-layer work can wait until generation.

    Simplified pseudocode:

    1. for request:
    2. if prefill:
    3. for layer in encoder_layers:
    4. k, v = project(x)
    5. shared_cache.write(group(layer), pos, k, v)
    6. x = layer_forward(x, read=shared_cache)
    7. for each decode step:
    8. for layer in all_layers:
    9. k, v = project(x)
    10. shared_cache.write(group(layer), pos, k, v)
    11. x = layer_forward(x, read=shared_cache)

    This is simplified. Real systems must handle positional encoding, cache consistency, layer read/write protocols, and alignment of front- and back-half representations. If the first-half output mismatches the second-half input, generation quality drops. If a shared cache lacks layer-specific adapters, layers can conflict over the same K and V. Halfway execution must be co-designed with training objectives, cache layout, and inference scheduling.

    4. Cache down to about one quarter: sharing and precision dominate

    Halfway execution mainly saves prefill compute. Cutting global KV cache to about one quarter comes mainly from cross-layer sharing and lower storage precision. Sharing means not every layer stores a full K, V; several layers share one global cache, and some layers read it through light adapters. If the network has L layers and G share groups, stored copies fall from L to G. Some layers can also reuse intermediate retrieval results and avoid duplicate storage.

    Lower-precision storage reduces bytes per element b. If sharing cuts effective copies by about half and lower precision cuts bytes per copy by about half, the product is near one quarter. Actual ratios depend on grouping, precision policy, metadata overhead, and eviction. The gain is not a single compression trick but a system combination: lighter sequence-axis compression, less layer redundancy, and cheaper per-copy storage.

    The engineering value is avoiding overly aggressive token compression on long inputs while targeting inter-layer redundancy and storage cost. For read-heavy, write-light loads, cache capacity and prefill latency often matter more than decode throughput, so this trade-off fits the scene.

    5. Applicability and engineering notes

    The architecture fits long-input, short-output, multi-turn continuation, relatively stable prefixes, and short outputs—for example code edits, log diagnosis, and tool-call orchestration. If the product is long generation, high-precision reasoning, or tasks with large inter-layer differences, quality loss from shared cache and low precision needs careful evaluation.

    In production, watch time to first token, prefill throughput, decode throughput, cache occupancy, hit rate, eviction frequency, quality regression, and long-context stability. Practically, run layer sensitivity tests to decide which layers can share and which need private cache; calibrate low-precision storage and protect outliers; then gray-release and watch latency, memory watermarks, and quality. Monitoring should cover share-group hits, cache consistency, and precision overflow.

    Overall, the point is not simply “compress the sequence,” but combining asymmetric prefill/decode, cross-layer sharing, and low-precision storage. For intelligent coding tools with very long input and very short output, cache and prefill are the main constraints; understanding that logic matters more than memorizing a ratio.