LLM Inference Engineering
Inference engineering is the discipline of maximizing throughput, minimizing Time-to-First-Token (TTFT) and Inter-Token Latency (ITL), and fitting massive autoregressive transformer models into distributed accelerator memory.
While model training focuses on gradient descent, loss convergence, and data pipelines, inference operates under strict physical hardware constraints: memory bandwidth, SRAM capacity, interconnect latency, and KV-cache expansion.
The Physical GPU Memory Hierarchy
Modern LLM serving engines like vLLM, TensorRT-LLM, and TGI succeed by orchestrating data movement across memory tiers:
text
Core Pillars of Inference Optimization
-
The Two Serving Regimes:
- Prefill (Prompt Processing): Highly compute-bound. Processes $N$ prompt tokens in parallel via dense matrix multiplications ($GEMM$).
- Decode (Token Generation): Highly memory-bandwidth bound. Generates one token at a time via vector-matrix multiplications ($GEMV$), requiring weights and KV cache to cross from HBM to compute cores for every single token.
-
KV-Cache Memory Management:
- Without paging, dynamic sequence lengths lead to 60-80% memory waste due to internal and external fragmentation.
- PagedAttention and chunked prefill transform KV caches into manageable virtual memory pages.
-
High-Throughput Scheduling:
- Iteration-level scheduling allows newly arriving requests to join running batches without waiting for long sequences to finish.
Explore each detailed chapter in the curriculum above to master the complete mathematics, systems architecture, and engineering recipes of modern AI inference.
Learning Path
10 topics across 4 sections
1Part I: Hardware, Quantization & Memory Ceilings
Physical GPU bounds, memory bandwidth, arithmetic intensity, and precision reduction.
- The Roofline Model for AI Inference — Operational intensity, peak FLOP/s, sustainable bandwidth, the ridge point, and why prefill and decode occupy opposite regimes.
- KV-Cache Mechanics & Memory Formulas — Deriving exact KV-cache tensor bytes, MHA vs GQA vs MQA architectures, FP8 quantization, and GPU capacity planning.
- Quantization: FP8, INT4 & NVFP4 — Weight-only vs weight-activation quantization, calibration scales, and hardware kernel execution across FP8, INT8, AWQ, and NVFP4.
2Part II: Kernel & Serving Architecture
How modern inference engines overcome hardware bottlenecks through algorithmic memory management.
- FlashAttention vs PagedAttention — SRAM IO-aware attention tiling vs virtual memory paging for KV caches, eliminating fragmentation and enabling zero-copy sharing.
- Continuous Batching & Iteration Scheduling — Moving from static request batches to iteration-level scheduling (Orca), prompt prefill chunking, and preemption budgets.
- Disaggregated Prefill & Decode Architecture — Decoupling compute-bound prompt evaluation from bandwidth-bound token generation into dedicated accelerator pools (DistServe & Splitwise).
3Part III: Distributed Serving & Parallelism
Multi-device scaling, speculative generation, and sparse mixture-of-experts architectures.
- Speculative Decoding & Parallel Verification — Draft model generation, target verification, rejection sampling distribution preservation, and wall-clock speedup bounds.
- Mixture of Experts & Parallelism — Top-k token routing, router z-loss, expert capacity limits, load balancing auxiliary loss, and Expert Parallelism (EPLB) vs Tensor Parallelism.
- Tensor, Pipeline & Ring Attention Parallelism — Choosing between Tensor Parallelism, Pipeline Parallelism, and Sequence Parallelism based on interconnect bandwidth and context length.
4Part IV: Production Benchmarking & SLOs
Monitoring, measuring, and scaling high-availability inference clusters.
- Serving Metrics: Goodput, SLOs & Tail Latency — Deconstructing TTFT, ITL, Goodput vs Throughput, SLO attainment fractions, and tail latency variance in production LLM systems.