跪拜 Guibai
← All articles
AI Programming

The Prefill-Decode Split That Makes Every LLM Call Wasteful

By 周末程序猿 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Inference already eats 70% of global AI compute and the ratio keeps growing. Every redundant K-V recalculation in the decode phase burns GPU cycles and adds latency that compounds across billions of daily calls, so eliminating that waste is the difference between a product that scales and one that bleeds money.

Summary

Every autoregressive LLM call runs through a prefill phase that processes the full prompt in one forward pass, then a decode phase that generates output tokens sequentially. The split creates a fundamental inefficiency: during decode, the model recomputes Key and Value vectors for every token already in the context, even though those vectors never change. A walkthrough with a simple prompt shows how the attention mechanism compares Query vectors against Keys to produce attention weights, then mixes Value vectors to predict the next token. The repeated K-V computation in decode is pure waste — the vectors are identical each time. The engineering answer is to cache them, which is what KV cache solves. Inference now consumes 70% of global AI compute and that share is still climbing, making this optimization a cost-of-business problem, not a research curiosity.

Takeaways
LLM inference splits into prefill (one forward pass over the full prompt) and decode (sequential token-by-token generation).
TTFT — Time to First Token — measures the prefill phase; everything after the first token is decode.
During decode, the model recomputes Key and Value vectors for every token already in the context, even though those vectors are identical to the previous step's results.
The attention mechanism works by comparing a token's Query vector against every other token's Key vector, then mixing Value vectors according to the resulting attention weights.
Training compute accounts for only 30% of global AI usage; inference accounts for 70%, and that share is still increasing.
Open-source models are already sufficient for most use cases; the bottleneck is now deployment cost and efficiency.
Conclusions

The 70/30 inference-to-training compute split reframes the entire AI cost conversation: model quality is no longer the binding constraint, inference economics is.

Prefill and decode have fundamentally different compute profiles — prefill is parallel and compute-bound, decode is sequential and memory-bound — which means optimizing one often hurts the other.

The article's framing of inference as an engineering discipline rather than a research problem reflects a real industry shift as open-source models close the capability gap with commercial ones.

Concepts & terms
Prefill
The first phase of LLM inference where the model processes the entire input prompt in a single parallel forward pass, computing Key and Value vectors for all input tokens and predicting the first output token.
Decode
The second, sequential phase of LLM inference where the model generates one token at a time, appending each new token to the context and recomputing attention over the full sequence until a stop condition is met.
TTFT (Time to First Token)
The latency from sending a request to receiving the first generated token; it measures the duration of the prefill phase.
KV Cache
A technique that stores previously computed Key and Value vectors so the decode phase can reuse them instead of recomputing them for every token at each step.
Autoregressive Model
A model that predicts the next token based on all previous tokens in the sequence, generating output one token at a time in a causal, left-to-right fashion.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗