Why LLM Inference Costs Keep Falling: The Engineering Behind KV Cache

    This article explains why large language model inference costs can drop so sharply, looking beyond pricing moves to the underlying cost structure: GPU memory usage, compute (FLOPs), and request scheduling efficiency. It shows how KV Cache turns full-sequence recomputation into incremental decoding, how to estimate its memory footprint, what a high cache hit rate delivers in latency, throughput, and cost amortization, and which engineering practices improve reuse while keeping memory in check.

    1. What the Price Cuts Reveal About the Real Cost of Inference

    A major model service recently announced a permanent price cut to one quarter of the previous level for its flagship model, sparking discussion across developer communities. Much of the attention has focused on the “price war,” but from an engineering perspective, falling inference costs are not simply a commercial concession. They reflect space that opens up naturally once inference efficiency improves at the foundation. Understanding this requires a clear look at the cost structure of LLM inference.

    The cost of a single online inference request breaks down into three parts: GPU memory usage, compute (FLOPs), and request scheduling efficiency. Memory is the hardest constraint, since it determines how many concurrent requests a single GPU can serve. Compute determines the latency of each forward pass. Scheduling efficiency determines whether the hardware can be fully utilized. Among the three, memory usually becomes the bottleneck first, and KV Cache is one of the largest variables in memory consumption.

    When the cache hit rate rises substantially, the server can skip a large amount of repeated prefix computation. This effectively turns “full computation per request” into “incremental computation,” increasing the number of concurrent requests a single GPU can carry and lowering the amortized cost per token. That is the technical logic behind the community joke that a fourfold price cut amounts to “almost free.”

    2. KV Cache: The Memory Optimization Foundation of Autoregressive Generation

    2.1 What Happens Without a Cache

    Large language models generate text autoregressively: each step produces a single token, appends it to the end of the sequence, and generates the next one. Given the input “what is the weather today,” the process looks like this:

    1. Step 1: input [what, is, the, weather, today] -> predict "good"
    2. Step 2: input [what, is, the, weather, today, good] -> predict the next token
    3. Step 3: input [what, is, the, weather, today, good, ...] -> predict the next token

    In the attention mechanism, every token produces three vectors: Q (Query), K (Key), and V (Value). The problem is that in Step 2, the K and V vectors for the earlier tokens are identical to those from Step 1, yet they are computed all over again. The longer the sequence, the worse this repeated computation becomes, and overall complexity degrades from an ideal linear increment to something close to quadratic.

    2.2 What the Cache Does

    The core idea of KV Cache is straightforward: after computing each token, write its K and V into GPU memory. On the next inference step, the K and V of historical tokens are read directly, and only the newest token needs a full Q, K, V computation. The new Q is then scored against all cached K, and multiplied by the cached V to complete the weighting.

    1. # Pseudocode: single-step decoding with KV Cache
    2. def decode_step(new_token, kv_cache):
    3. q, k, v = forward_qkv(new_token) # compute only the new token
    4. kv_cache.append(k, v) # append to cache
    5. scores = softmax(q @ kv_cache.K.T) # new Q against all historical K
    6. out = scores @ kv_cache.V # weighted sum over historical V
    7. return out

    The compute for a single step drops from “processing the entire sequence” to “processing one token,” which is the key to the qualitative jump in inference speed.

    3. How Much GPU Memory KV Cache Actually Uses: A Quantitative Estimate

    The cache is not free; it trades memory for compute. Its size can be estimated with a general formula:

    1. KV Cache = 2 × num_layers × num_heads × head_dim × sequence_length × bytes_per_value

    For 32 layers, 32 heads, a head dimension of 128, a sequence length of 4096, and FP16 (2 bytes):

    1. Per token, per layer: 2 × 32 × 128 × 2 = 16384 bytes = 16 KB
    2. Total cache: 16 KB × 32 layers × 4096 tokens ≈ 2 GB
    3. With a concurrent batch = 10, roughly 20 GB

    In long-context or high-concurrency scenarios, KV Cache memory usage can exceed the model parameters themselves, directly capping how many concurrent requests a single GPU can handle. This is also why “raising the cache hit rate” and “compressing the cache footprint” have become the two main lines of inference optimization.

    4. What a High Cache Hit Rate Means

    The cache hit rate is the proportion of a request’s reusable prefix (system prompt, few-shot examples, long document context, multi-turn conversation history) that matches an existing cache. As the hit rate approaches 100%, the server barely recomputes the shared prefix, and the benefits show up in three places:

    1. Lower latency: time to first token (TTFT) drops significantly, with the strongest effect in scenarios with long system prompts.
    2. Higher throughput: the memory and compute saved can serve more concurrent requests, raising single-GPU QPS.
    3. Cost amortization: the cost per token falls, which is what creates room for a permanent price cut.

    It is worth stressing that a high hit rate is not a proprietary feature of any single vendor. It is an engineering outcome of prefix reuse, tiered cache management, and request scheduling working together, and it is a common optimization direction across the industry.

    5. Engineering Practice: Improving Hit Rate and Controlling Memory

    • Stable prefix design: place the unchanging system prompt, tool definitions, and examples at the front, and variable content after them, so the prefix does not become invalid and void the cache.
    • Session-sticky scheduling: route multi-turn conversations to the same instance where possible, reducing cache migration and rebuilding.
    • Tiered caching: keep hot data in GPU memory, use host memory or object storage for warm and cold data, and monitor hit rate and eviction rate with alerts.
    • Precision and quantization: use lower precision or KV quantization within an acceptable quality loss to compress the cache footprint directly.
    • Observability: build logging and metric dashboards for TTFT, hit rate, memory水位, and batch size, and tune parameters based on data.

    6. Conclusion

    Framing the price cut as a technical problem points to a single main line: whoever makes KV Cache more efficient, more memory-frugal, and easier to reuse can serve more requests on the same hardware. For developers, understanding the caching mechanism, mastering memory estimation, and optimizing prefix structure offer more long-term value than tracking any single price number.