Pidoku
12LLM Inference
On this page

LLM Inference

Module 1217 lessons~24h 15m

Lessons, in order

12.a Transformer Inference OverviewModule 10 taught what a transformer computes. This module is about running one to generate text. These terms appear in every lesson; each is explained properly later, but here is what they … 45 min 12.b Tokenization and Its ConsequencesTokenization converts text into integers the model can process, and converts the model's output integers back into text. 1h 12.c Prefill vs DecodeThe single most important distinction in LLM serving. Everything else in this module follows from it. 2h 12.d Autoregressive GenerationAutoregressive generation means producing a sequence one element at a time, where each new element depends on all the previous ones — including the ones the model itself just produced. 1h 12.e The KV CacheThe most important optimization in LLM inference — and the source of most of its problems. 2h 12.f KV Cache MathPure arithmetic. Work every example with a calculator. These calculations are what you'll be asked to do in an interview and what you'll do weekly on the job. 1h 30m 12.g Attention Variants: MQA, GQA, MLA, Sparse and HybridYou know from 12.e that every token leaves a key and a value per head per layer in the KV cache, and that the cache, not the weights, limits how many users fit on a GPU. Model designers can … 1h 15m 12.h Context Length and How It ScalesContext length is the number of tokens one request holds at once: the prompt plus everything generated so far, including hidden reasoning tokens. A model's maximum context is the most it was … 1h 15m 12.i Batching: Static and DynamicBatching means running several requests through the model in the same forward pass. 2.d showed why it pays: the expensive part of a decode step is reading the weights, and one read can serve … 1h 15m 12.j Continuous BatchingThe single largest throughput win in modern LLM serving — typically 3-10x. Also called iteration-level scheduling (Orca) or in-flight batching (TensorRT-LLM). 2h 12.k Chunked PrefillFrom 12.c: a prefill processes thousands of tokens and takes a long time; a decode step processes one token per request and is quick. If the engine runs a whole long prefill as one step, … 1h 12.l PagedAttentionIf you read 3.f (virtual memory), this file will feel inevitable rather than clever. That's the point — PagedAttention is operating systems applied to KV cache. 2h 12.m Prefix and Prompt CachingReusing the KV cache computed for a shared prompt prefix across requests, instead of recomputing it. 1h 30m 12.n Speculative DecodingUse a cheap model to guess the next few tokens, then use the expensive model to verify all of them in one forward pass. Accept the guesses that match what the big model would have produced; … 1h 30m 12.o Sampling and Decoding StrategiesThe model produces a probability distribution over the vocabulary. Sampling is choosing one token from it. 1h 15m 12.p Streaming InferenceSending tokens to the client as they're generated, rather than waiting for the complete response. 1h 12.q Capacity Math: Worked ExamplesThe capstone of Module 12. Work every example with a calculator. This is the skill that gets you hired and that you'll use weekly. 2h

About this module

How a large language model actually generates text, and every mechanism a serving engine is built from: tokenisation, prefill and decode, the KV cache and its arithmetic, MQA, GQA and MLA, context length, batching from static to continuous, chunked prefill, PagedAttention, prefix caching, speculative decoding, sampling, streaming and capacity maths.

Lessons#

#LessonTime
12.aTransformer Inference Overview60 min
12.bTokenization and Its Consequences60 min
12.cPrefill vs Decode120 min
12.dAutoregressive Generation60 min
12.eThe KV Cache120 min
12.fKV Cache Math90 min
12.gMQA, GQA, and MLA75 min
12.hContext Length and How It Scales75 min
12.iBatching: Static and Dynamic75 min
12.jContinuous Batching120 min
12.kChunked Prefill60 min
12.lPagedAttention120 min
12.mPrefix and Prompt Caching90 min
12.nSpeculative Decoding90 min
12.oSampling and Decoding Strategies75 min
12.pStreaming Inference60 min
12.qCapacity Math: Worked Examples120 min

Previous: Models as Computation · Next: Optimization

↑↓ navigate↵ openesc close

100% drag to pan · scroll or pinch to zoom · double-click to zoom in