Why Local LLMs Are Becoming Practical on Desktop PCs: Optimizing Inference by Splitting It into "Prefill" and "Decode" Phases
What’s the Difference Between Prefill and Decode?
Prefill is the phase where the entire input text is loaded, and the first token is generated. This stage is primarily limited by GPU compute capacity. Decode is the phase where subsequent tokens (from the second one onward) are generated one by one. Because it reuses the KV cache computed during the prefill phase, the actual computation is light; instead, the bottleneck becomes the readout speed of weights from GPU memory (VRAM).
Tracing the Prefill Process Step by Step
This section explains the flow: tokenizing text, assigning IDs, vectorizing via embeddings to create an input matrix, and then iterating QKV calculations and knowledge addition across 32 transformer layers to predict the first token. It also covers the mechanism where Q is not saved, while K and V are stored in VRAM as a KV cache, allowing decode to compute only the differences.
Mixture of Experts and Memory Hierarchies
The article also touches on Mixture of Experts (MoE) models, which divide the dense knowledge layers into small experts, with a router selecting only a few to compute at any given time. It summarizes that optimization hinges on deciding where to place unused experts and the KV cache within the memory hierarchy of VRAM, RAM, and SSDs (NVMe).
Table of Contents
0:00 Diving into the Details of Local LLMs
2:27 The Two Phases: Prefill and Decode
3:46 What is Prefill?
5:16 KV Cache and Decode
7:59 VRAM Read Speed as the Bottleneck
9:55 Tokenization and Embeddings
12:12 The 32 Layers of the Transformer
14:26 QKV and KV Cache Storage
17:39 Optimization by Inference Engines
18:33 How Mixture of Experts Works
21:11 The Hierarchy of VRAM, RAM, and SSDs
23:01 Future Specialization and Summary
You can watch the video here: Watch on YouTube