When the KV Cache Is Slower Than Compute: Rethinking a Common Assumption

    This article explains why long-context LLM inference is often bottlenecked by memory bandwidth rather than compute, and how low-rank latent attention reduces KV cache size by decoupling it from the number of attention heads. It covers capacity estimation, block and quantization layouts, a simplified block manager, a performance analysis workflow, common pitfalls, and general practices for running inference services in the cloud.

    When the KV Cache Is Slower Than Compute: Rethinking a Common Assumption

    1. The intuition that no longer holds: compute is not the only bottleneck

    For a long time, the first question about model inference performance has been whether there is enough compute. In real long-context serving, however, a counterintuitive pattern keeps showing up: GPU compute utilization is not high, yet requests are painfully slow. The reason is simple—every generated token requires reading the key-value (KV) cache for the entire history again, and the volume of data that must be moved grows linearly with context length. Once the time spent moving data exceeds the time spent computing, the cache becomes the slower link in the chain.

    Understanding this requires separating two kinds of resources: compute (how many floating-point operations can be done per second) and bandwidth (how many bytes can be moved out of GPU memory per second). During decoding, each step processes only one token, so the matrix operations degenerate into “tall and skinny” shapes with very low arithmetic intensity, leaving the hardware inherently bandwidth-bound. At that point, latency is determined not by peak compute but by how many bytes this step must read.

    2. Low-rank latent attention: compressing the KV cache into shared vectors

    A widely adopted improvement is to introduce a low-rank latent representation into the attention mechanism. Instead of storing a full key and value for every token and every attention head, the token’s key-value information is projected and compressed into a shared low-rank vector, and each head reconstructs what it needs from that shared representation through its own projection matrices.

    This design has a key property: the amount of intermediate data stored per token is decoupled from the number of attention heads. No matter how many heads the model is configured with, the cache footprint stays a fixed and small constant. Take a tiled quantization layout as an example: at FP8 precision, every 256 tokens are packed into one block of roughly 12.4MB, which averages only about 48.4KB per token. Compared with the linear growth of “heads × dimension × layers” in traditional multi-head attention, this difference in magnitude directly changes the baseline for capacity planning.

    The logic of a rough capacity estimate is as follows (illustrative of the order of magnitude only, not a specific implementation):

    1. # Traditional KV cache: scales linearly with heads and layers
    2. bytes_per_token_trad = 2 * layers * heads * head_dim * dtype_size
    3. # Low-rank latent cache: decoupled from heads, depends only on the compressed dimension
    4. bytes_per_token_mla = (latent_dim + rope_dim) * layers * dtype_size
    5. # Cache footprint per request and maximum concurrency
    6. cache_per_request = bytes_per_token * context_len
    7. max_concurrency = available_memory // cache_per_request

    It is worth stressing that the compression is not lossless. Low-rank projection introduces a trade-off in representational capacity, position-related components usually need to be kept separately to preserve long-range modeling ability, and quantization adds another layer of error. In engineering practice, you must empirically calibrate the balance between “smaller cache” and “acceptable quality” rather than copying theoretical numbers.

    3. Why a smaller cache is actually faster

    The benefits of a smaller cache are cumulative:

    • Lower bandwidth pressure: fewer bytes need to be moved at each decoding step, which reduces latency in bandwidth-bound scenarios.
    • Higher capacity: the same GPU memory can hold a longer context or more concurrency, directly improving throughput per unit of cost.
    • Lower transfer and partitioning cost: when the cache must be passed across devices or nodes, both communication volume and the overhead of block scheduling drop.
    • More flexible scheduling: a fixed block granularity makes pre-allocation, reuse, and swap-in/swap-out policies easier.

    But the benefits do not materialize automatically. If the implementation repeatedly decompresses the compressed representation back into full keys and values at every layer and every head, the saved bandwidth is spent again, and the extra projection computation can even make things slower. The real optimization is to let downstream computation consume the latent representation directly, avoiding the materialization of intermediate tensors.

    4. Block and quantization layouts: turning theoretical gains into memory savings

    Fixed-size blocks (for example, 256 tokens per block) are a pragmatic choice: small blocks waste less on the tail block, while large blocks keep metadata and scheduling overhead low. Combined with low-precision storage, the footprint can be reduced further within an acceptable quality loss. Three things matter in practice: block alignment and index structures, how cross-block attention is addressed, and when blocks are appended and committed during incremental decoding.

    A simplified skeleton of a block manager:

    1. class BlockPool:
    2. def __init__(self, block_tokens, block_bytes, capacity_blocks):
    3. self.block_tokens = block_tokens
    4. self.block_bytes = block_bytes
    5. self.free = list(range(capacity_blocks))
    6. self.table = {} # request_id -> [block_id]
    7. def append(self, req_id, n_new_tokens):
    8. need = (n_new_tokens + self.block_tokens - 1) // self.block_tokens
    9. blocks = [self.free.pop() for _ in range(need)]
    10. self.table.setdefault(req_id, []).extend(blocks)
    11. return blocks
    12. def release(self, req_id):
    13. self.free.extend(self.table.pop(req_id, []))

    5. Performance analysis: locate the issue before optimizing

    Do not optimize on intuition. Start by collecting three categories of metrics with general monitoring and logging capabilities: memory usage and fragmentation, effective bandwidth per decoding step, and the distributions of time-to-first-token and per-token latency. If compute utilization stays low while latency remains high, the system is almost certainly bandwidth- or scheduling-bound; if latency does not improve after compression, check for implicit decompression and redundant copies.

    The diagnosis flow can be simplified as follows:

    1. Fix the input length and output length, and measure baseline latency.
    2. Gradually increase the context length and observe whether latency grows roughly linearly.
    3. Compare the throughput inflection points under different concurrency levels to confirm where the capacity bottleneck is.
    4. Check cache hit rates and eviction frequency to rule out scheduling jitter.

    6. Common pitfalls

    • Treating compression as free: both low-rank projection and quantization carry quality risks, so quality regression testing is required.
    • Looking only at single-request latency: service cost depends on concurrency and throughput, which must be evaluated at the same time.
    • Ignoring tail blocks and fragmentation: long-tail requests amplify memory waste.
    • Micro-optimizing too early: confirm whether the bottleneck is bandwidth or scheduling before deciding where to invest.

    7. General practices for running in the cloud

    If you use a container platform to host inference services, you can place model weights and the cache pool on high-bandwidth instances, distribute versioned models with object storage, use a message queue to smooth out request spikes, and build percentile views of latency and memory with logging services and monitoring alerts. Baidu AI Cloud is typically used in these scenarios to provide the combination of general capabilities described above, but the specific selection should still be based on measured data.

    8. Conclusion

    “The cache is slower than compute” is not a paradox but the norm for bandwidth-bound systems. By compressing the per-token cache to a fixed magnitude that is independent of the number of heads, low-rank latent attention opens up room for long context and high concurrency. To actually capture the gains, however, the compressed representation must run through the entire computation path, and rigorous capacity and performance analysis must validate the result. Re-deriving common sense from scratch is often more valuable than memorizing the conclusion.