Start studying
Module 16 · Advanced AI Module contents
Module 16  ·  Card 21 / 23advanced

Inference Optimization

Inference optimization makes serving a trained model cheaper and faster.

The KV cache avoids recomputing attention over previous tokens.

Continuous batching keeps the GPU busy across many concurrent requests.

Speculative decoding drafts tokens with a small model and verifies with the large one.

Together these can improve throughput by an order of magnitude.

Learn in depth ↓
Module 16 · Advanced AI · 23 concepts
In depth  /  15 lines

Inference Optimization, in more detail

Inference optimisation makes serving a trained model cheaper and faster.

It matters more than training cost for most deployed systems, since it is paid on every request.

The KV cache is the first and most important technique.

Without it, every new token would recompute attention over the whole history.

With it, only the new token is processed and the rest is read from the cache.

That changes generation from quadratic work to linear.

Continuous batching keeps the GPU busy across many concurrent requests.

Requests are admitted and retired at each step rather than in fixed groups.

Speculative decoding drafts several tokens with a small model and verifies them in one pass.

Quantization reduces the bytes read per token, which is what decoding is limited by.

PagedAttention manages KV cache memory in pages, cutting waste from fragmentation.

Flash Attention reduces memory traffic within attention itself.

Together these can improve throughput by an order of magnitude.

vLLM, TensorRT-LLM and similar servers implement most of them for you.

Writing your own serving loop is rarely worth it when these exist.

Test yourself

One question on this card. Every option explains itself once you pick, right or wrong.

Question 1
What does speculative decoding do?
Advanced AI

23 concepts in this module, then a graded test with every answer explained.

Study this module →
↑↓ move↵ openesc close