|
|
5.1 Prefill vs. Decode: Roofline & Arithmetic IntensityLLM inference divides into two physically distinct regimes governed by the hardware ridge point Iridge = Peak FLOP/s ÷ HBM Bandwidth (~295 FLOPs/byte on an H100 SXM in BF16):
|
Prof. PJ routing attention selectively to the tennis-ball expert while keeping 90% of park parameters inactive. |
Because output sequence lengths are unknown a priori, naive contiguous KV-cache pre-allocation wastes 60–80% of GPU VRAM to internal fragmentation. PagedAttention (vLLM; Kwon et al., 2023) borrows virtual memory paging from operating systems: KV states are stored in non-contiguous fixed-size physical blocks mapped via a logical block table, enabling near-zero fragmentation, prefix caching (copy-on-write shared system prompts), and continuous (iteration-level) batching.
Because decode is HBM-bandwidth-bound, verifying K candidate tokens in parallel costs nearly the same latency as generating 1 token! Speculative Decoding (Leviathan et al., 2023; Chen et al., 2023) uses a tiny fast draft model q(x) to propose K tokens, scores all K+1 positions in one target forward pass p(x), and accepts each token xi via rejection sampling with probability:
Lossless Exactness Proof: Summing the probability of directly accepting x plus rejecting some earlier draft token and sampling x from the residual distribution yields q(x) min(1, p(x)/q(x)) + [1 − ∑y min(p(y), q(y))] · max(0, p(x) − q(x)) / ∑y max(0, p(y) − q(y)) = min(p(x), q(x)) + max(0, p(x) − q(x)) = p(x) identically! Speculative decoding achieves 2×–3.5× decode speedup with mathematically zero quality degradation.
Dense Transformers couple parameter capacity linearly to FLOPs per token. Sparse MoE replaces each dense FFN with E parallel expert FFNs (e.g., 64–256 fine-grained experts plus 1–2 always-active shared experts) and a learned linear router Wg that activates only the top-k experts per token (e.g., 671B total parameters, only 37B active per token!). To prevent routing collapse (all tokens saturating a single expert), training adds a differentiable auxiliary load-balancing loss (or auxiliary-loss-free dynamic bias routing as in DeepSeek-V3):
Reducing weight precision from 16-bit BF16 to 8-bit FP8 or 4-bit INT4 cuts HBM traffic by 2×–4×, directly multiplying decode tokens/second. Because LLM activations exhibit massive channel-wise outlier features (100× larger than median activations), naive round-to-nearest (RTN) INT4 collapses perplexity. Two surgical remedies dominate:
| « Previous: Ch. 4 — RLHF, DPO & GRPO | [ Table of Contents ] | Next: Snout-Glossary of AI Terms » |