Learn · Inference 101
Inference engineering – 101
A 1,000-foot overview of what inference engineering looks like: how a request moves through an LLM serving stack, what to measure, where the bottlenecks are, and which levers move them.
Request flow through the serving stack
Prompt plus parameters: max_new_tokens, sampling settings.
Text to token IDs. Apply chat template, add special tokens.
Admit, prioritize, form batches with continuous batching.
Builds K/V for each layer and produces the first token. Often compute-bound.
Per-layer K/V for every active sequence. Grows with prompt plus generated length.
Read prior KV and weights, append new KV. Often bandwidth-bound.
Tokens go to the client as they are generated.
Key metrics
| TTFT | Time to first token: request arrival to first token emitted. |
| ITL | Time between streamed tokens. |
| TPOT | ≈ (E2E latency − TTFT) / max(Nout − 1, 1) |
| Throughput | Total output tokens per second across all requests. |
| User rate | ≈ 1 / TPOT, tokens per second per user. |
| Goodput | Request rate that still meets the latency SLOs. |
High throughput can still mean poor latency, and low goodput.
Roofline and bottlenecks
Attainable ≤ min(peak compute, bandwidth × intensity)
Memory requirements
Weight memory
≈ parameters × bytes per parameter
KV cache memory
2 × L × T × Hkv × Dhead × b
Attention variants and cache
| Lower Hkv | Reduces KV storage and decode bandwidth. |
| Prefix caching | Reuses KV for identical prompt prefixes. Helps prefill and TTFT, not decode TPOT. |
| PagedAttention | Paged KV memory management with non-contiguous allocation. |
| FlashAttention | Exact attention kernel that reduces HBM traffic. Distinct from PagedAttention. |
| Complexity | FlashAttention does not make dense attention O(T). It stays O(T²), with better constant factors. |
Scheduling techniques
Continuous batching
Batch in-flight requests dynamically and add new ones as sequences finish. Improves GPU utilization and throughput.
Chunked prefill
Split long prompts into chunks so prefill interferes less with decode.
Prefill / decode disaggregation
Separate GPU pools for prefill and decode when their resource profiles differ. Adds KV-transfer overhead.
Optimization levers
Quantization
- Weight quantization cuts weight memory and bandwidth (INT8, INT4).
- KV quantization cuts cache memory and bandwidth (FP8, INT8).
| Target | Effect | Typical formats |
|---|---|---|
| Weights | ↓ memory, ↓ bandwidth | INT8, INT4 |
| KV cache | ↓ memory, ↓ bandwidth | FP8, INT8 |
Speculative decoding
- A small draft model proposes tokens and the larger model verifies them.
- Speedup depends on draft cost, acceptance rate and verification efficiency.
Parallelism strategies
Tensor parallelism
Shard tensors within layers, such as matmuls and attention.
Pipeline parallelism
Split layers across pipeline stages.
Data parallelism
Replicate the full model across GPUs; route different requests or batches.
Expert parallelism
Shard MoE experts across devices. Adds token dispatch and all-to-all.
What to watch in production
- TTFT, ITL, TPOT, E2E at p50 to p99
- Queue time in the scheduler
- Active sequences (concurrency)
- KV occupancy per GPU
- Prefix hit rate
- Offload bytes to CPU or disk
- Achieved HBM bandwidth
- Collective latency: all-reduce, all-to-all
- Network and KV-transfer time
Fast diagnosis
| High TTFT | Queue or prefill bottleneck. |
| Poor TPOT / ITL | Decode bandwidth or KV traffic. |
| OOM at concurrency | Weights plus KV plus workspace pressure. |
| Poor scale-out | Communication or topology issue. |