Subject 07 / Course

Inference engineering

How large models are served: prefill and decode, KV cache memory, batching, quantization, serving engines, vLLM internals, and running inference in production.

7 modules24 lessons≈ 5 h reading
Start with lesson 1.a

Serving a large model is a memory and scheduling problem before it is a model problem. Each generated token reads the full weights and the growing KV cache, so throughput, latency, and cost are set by how the server packs requests into GPU memory and time.

The course starts from the arithmetic of a single forward pass, builds up batching and paged KV memory, follows a request through a serving engine and through vLLM, and ends with distributed and production concerns: parallelism, disaggregation, SLOs, capacity, and fairness. It assumes you can read Python and know what a transformer is at the level of “layers of attention and MLPs”.

What you need#

  • Python 3.10 or newer. Every program runs offline and simulates the GPU with arithmetic; nothing needs a GPU.

The modules

1

Inference mechanics

What one forward pass costs: prefill and decode, the size of the KV cache, and why generating tokens is limited by memory bandwidth rather than arithmetic.

  1. 1.aPrefill and decode13 min
  2. 1.bKV cache math12 min
  3. 1.cWhy decode is memory-bound11 min
2

Batching and scheduling

How a serving engine packs many requests into each GPU step: continuous batching, paged KV memory, chunked prefill, priorities, and preemption.

  1. 2.aContinuous batching11 min
  2. 2.bPaged KV memory11 min
  3. 2.cChunked prefill and priority11 min
3

Making it cheaper

Three ways to get more tokens from the same GPU: store fewer bits, verify several guessed tokens per weight read, and skip prefill work already done.

  1. 3.aQuantization12 min
  2. 3.bSpeculative decoding12 min
  3. 3.cPrefix caching12 min
4

Serving systems

What a serving engine is made of, how the main open engines differ in mechanism, and how tokens get from the engine to a client.

  1. 4.aAnatomy of a serving engine14 min
  2. 4.bChoosing a stack16 min
  3. 4.cStreaming APIs13 min
5

vLLM internals

One request through the vLLM V1 engine: processes and wires, the token-budget scheduler, the paged KV cache manager, model execution, and running it in production.

  1. 5.aThe request path14 min
  2. 5.bThe scheduler16 min
  3. 5.cThe KV cache manager16 min
  4. 5.dModel execution13 min
  5. 5.eOperating vLLM14 min
6

Distributed inference

Serving one model across many GPUs: how tensor, pipeline, and expert parallelism split the work and what each costs in communication, when to split prefill from decode, and how mixture-of-experts models are served.

  1. 6.aTensor, pipeline, and expert parallelism18 min
  2. 6.bDisaggregated prefill and decode17 min
  3. 6.cServing mixture-of-experts models16 min
7

Production inference

Running inference as a service: latency SLOs and goodput, capacity plans that hold at peak, autoscaling when a replica takes minutes to start, and sharing a fleet among tenants without one starving the rest.

  1. 7.aLatency SLOs and goodput12 min
  2. 7.bCapacity planning13 min
  3. 7.cAutoscaling and model loading13 min
  4. 7.dMulti-tenancy and fairness14 min
← Back to the library