03.05

Making attention cheaper

skillmaxingInference EngineeringMaking attention cheaper
Visual lesson

Making attention cheaper

Included with Pro · 4:21
Lessons · 1,222 words

Most of a transformer costs the same per token whether the context holds 100 tokens or 100,000. The matrix multiplies in the MLP and the projections see one token at a time. Attention is different: every token looks at every earlier token, so its work and its memory grow with context length. Computed from scratch over a prompt, attention is quadratic in sequence length. With a KV cache, each decode step is linear in the length of the context so far.

That growth shows up as four separate problems, and the techniques you will meet in every serving engine each fix one of them. FlashAttention avoids building the score matrix. Grouped-query attention, latent attention and sliding windows shrink the KV cache. PagedAttention stops the KV cache from wasting memory on reservations. Chunked prefill stops one long prompt from freezing everyone else's stream.

Pro

Continue reading

Pro unlocks every video lesson, the full notes, worked sizing and cost calculations, and runnable configs across the Inference Engineering course, from GPUs and kernels to quantization, speculative decoding, disaggregation and production autoscaling.

Unlock full access to
Python with AIInference EngineeringAI researchComplete system design
30% off with LAUNCH30first payment
Buy now
View all plans ·Already Pro? Sign in