LLM Inference Engineering

Master the systems mechanics, memory hierarchies, and algorithmic optimizations powering production-grade large language model inference runtimes.

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
┌────────────────────────────────────────────────────────────────────────┐
│ GPU Streaming Multiprocessors (SMs) / Tensor Cores                    │
│ Peak Compute: 300 - 2000 TFLOP/s (FP16/BF16/FP8)                      │
│                                                                        │
│   ┌──────────────────────────────────────────────────────────────┐     │
│   │ On-Chip SRAM / L1 & Shared Memory Cache                      │     │
│   │ Bandwidth: ~15 - 20 TB/s | Size: ~100 - 250 KB per SM        │     │
│   │ (Where FlashAttention keeps intermediate Softmax matrices)   │     │
│   └──────────────────────────────▲───────────────────────────────┘     │
└──────────────────────────────────┼─────────────────────────────────────┘
                                   │
                                   ▼
┌────────────────────────────────────────────────────────────────────────┐
│ High Bandwidth Memory (HBM3 / HBM3e)                                   │
│ Bandwidth: 2.0 - 5.3 TB/s | Capacity: 80 - 192 GB                      │
│ Stores: Model Weights, Paged KV-Cache, Activation Buffers              │
└──────────────────────────────────▲─────────────────────────────────────┘
                                   │ PCIe Gen 5 / NVLink (900 GB/s)
                                   ▼
┌────────────────────────────────────────────────────────────────────────┐
│ Host System Memory (CPU RAM) & NVMe Tiered Offload                     │
│ Bandwidth: ~50 - 200 GB/s | Capacity: 512 GB - 2 TB                    │
│ Stores: Cold KV Prefixes, Swapped Request Buffers                      │
└────────────────────────────────────────────────────────────────────────┘

Core Pillars of Inference Optimization

  1. 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.
  2. 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.
  3. 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.

2Part II: Kernel & Serving Architecture

How modern inference engines overcome hardware bottlenecks through algorithmic memory management.

3Part III: Distributed Serving & Parallelism

Multi-device scaling, speculative generation, and sparse mixture-of-experts architectures.

4Part IV: Production Benchmarking & SLOs

Monitoring, measuring, and scaling high-availability inference clusters.