Slides · Inference engineering
Request lifecycle, metrics and the roofline
1 / 31
Request lifecycle, metrics and the roofline
Predict how fast a model can possibly run before anything is started, then measure against that ceiling.
By the end you can trace a request, define the serving metrics precisely, place decode and prefill against the ridge, bound batch-1 speed from bytes and bandwidth, and map each serving technique to the fact it exploits.
Concept
Nobody wrote the number down
- The team is about to serve a model on its own GPUs. Someone says, “Start it and see how fast it goes.”
- Ananya asks the better question first: how fast could it possibly go?
- Without a ceiling, a benchmark result has no meaning. 40 tokens per second is excellent against a ceiling of 48 and alarming against a ceiling of 210.
- Two numbers set the ceiling: how much arithmetic the model needs and how many bytes it must move. One comparison tells you which one is the limit.
Process
One request, five stages
- Tokenize the prompt into tokens (CPU work).
- Queue: the scheduler holds the request until it can join a batch.
- Prefill: one pass over all prompt tokens builds the KV-cache and yields the first token.
- Decode: one pass per new token, reusing the cache, until an end token or a length limit.
- Detokenize and stream the text back.
NVIDIA’s inference-optimization post (2023) describes the same two phases: a prefill over the whole prompt, then token-by-token decoding.
Diagram
Where the wait comes from
Concept
Two different waits, two different causes
- Before anything appears: queueing plus prefill. A long prompt or a crowded server stretches it.
- After text starts: the decode step time. Bandwidth, batch size and context length stretch it.
- The fixes differ, so measure them separately. A single “latency” number hides which phase is hurting.
- A user who sees a long blank and then fast text has a prefill or queue problem. A user who sees an instant start and then slow words has a decode problem.
Compare
The metrics, defined
| Metric | Definition (NVIDIA NIM benchmarking docs, version 2.0.0; the ITL formula is the AIPerf tool’s) |
|---|---|
| TTFT | Query submission to the first received token; empty initial responses are ignored |
| ITL (also TPOT) | (e2e latency−TTFT)/(output tokens−1) |
| End-to-end latency | Submission to the full response: TTFT+generation time |
| TPS per system | Output tokens across all requests divided by the run’s time window |
| TPS per user | One request’s output length divided by its end-to-end latency; approaches 1/ITL for long outputs |
Goodput and cost per million tokens are defined on the next slides. Tools differ in details, such as whether TTFT counts toward ITL, so compare results only when their definitions match.
Worked example
Worked: from timings to ITL
A request produces 100 tokens. TTFT is 0.5 s and the full response arrives 5.45 s after submission.
| Quantity | Calculation | Value |
|---|---|---|
| Generation time | 5.45−0.50 | 4.95 s |
| Gaps between 100 tokens | 100−1 | 99 |
| ITL | 4.95/99 | 50 ms |
| TPS per user | 100/5.45 | about 18.3 |
| Ceiling of 1/ITL | 1/0.050 | 20 |
The per-user rate sits below 1/ITL because the first-token wait is counted in the end-to-end time.
Check yourself
Check: the alert fired, but is the model slower?
An alert on end-to-end latency fires after a release. Typical TTFT is 0.4 s and typical ITL is 25 ms, both unchanged. Average output length went from 800 to 1,500 tokens. Estimate the end-to-end time before and after. Is decode slower, and which two numbers would make a better alert?
Answer
Before: 0.4 s plus 799 gaps at 25 ms is about 20.4 s. After: 0.4 s plus 1,499 gaps at 25 ms is about 37.9 s. End-to-end time nearly doubled although neither phase got slower, because it grows with output length. Decode is not slower. Alert on TTFT and ITL, which isolate the queue and prefill from the decode step, and watch output length as its own signal.
Worked example
Goodput counts only requests that met the targets
Eight requests finish in a 4-second window. The promised targets: TTFT at most 1.0 s and ITL at most 50 ms.
| Request | TTFT (s) | ITL (ms) | Meets both? |
|---|---|---|---|
| 1 | 0.4 | 35 | yes |
| 2 | 0.9 | 48 | yes |
| 3 | 1.3 | 30 | no, TTFT |
| 4 | 0.6 | 62 | no, ITL |
| 5 | 0.7 | 45 | yes |
| 6 | 1.0 | 50 | yes |
| 7 | 2.1 | 70 | no, both |
| 8 | 0.5 | 40 | yes |
Throughput is 8/4=2 requests per second. Goodput is 5/4=1.25 per second. The gap is the work that was done but did not serve a user well. The DistServe paper (OSDI 2024) frames serving performance in a similar way: the maximum request rate served within both TTFT and per-token latency constraints.
Concept
Quote throughput with its conditions
- State which tokens. Input and output tokens cost the hardware different amounts.
- State the concurrency. Larger batches raise tokens per second and can lengthen each user’s wait.
- State the TTFT and ITL users experienced under that load.
- A throughput figure with none of these is a marketing number, not a result.
Math
Cost per million tokens
cost per million tokens=tokens per second×3600price per hour×1,000,000| Symbol | Meaning |
|---|---|
| price per hour | What the GPU (or the whole replica) costs per hour, whether busy or idle |
| tokens per second | Output tokens actually produced, averaged over the hour |
| 3600 | Seconds per hour |
The price is fixed; the tokens are not. Keeping the GPU busier lowers the unit cost, so one figure from a full-load test is not a constant.
Check yourself
Check: faster by one number, worse by another
A server at batch 16 completes 10 requests per second and every request sees an ITL near 40 ms. At batch 32 it completes 14 per second and every request sees an ITL near 65 ms. The target is an ITL of at most 50 ms, and TTFT is fine in both runs. Predict the throughput and the goodput of each run, then say what to try next.
Answer
Batch 16: throughput 10 per second, and all requests meet the target, so goodput is 10 per second. Batch 32: throughput 14 per second, but all requests miss the 50 ms target, so goodput falls to 0. The run with more throughput serves nobody within the promise. Next, try batch sizes between 16 and 32 and keep the largest one whose ITL stays within the target, quoting TTFT and ITL beside the throughput.
Math
FLOPs and bytes per decoded token
FLOPs per token≈2Pweight bytes=P×b| Symbol | Meaning |
|---|---|
| P | Number of parameters |
| b | Bytes per parameter: 2 in BF16 or FP16, 1 in FP8 or INT8, 0.5 in INT4 |
| 2 | One multiply and one add per weight |
kipply’s 2022 post makes the 2P argument: a pass multiplies through all the parameters. Attention adds terms that grow with context, set aside here. The NVIDIA post says decode is a matrix-vector-like operation that is memory-bound: the speed at which weights, keys, values and activations move from memory dominates the latency. The weight-bytes line above is the weights’ share of that traffic.
Sources[4] Transformer Inference Arithmetic[1] Mastering LLM Techniques: Inference Optimization
Diagram
The roofline question
The roofline model comes from a 2008 UC Berkeley technical report by Williams, Waterman and Patterson.
Compare
Reading a datasheet for the ridge
| Part (NVIDIA product page, fetched 2026-10-24) | BF16 TFLOPS on the page | Dense figure | Bandwidth | Ridge |
|---|---|---|---|---|
| H100 SXM | 1,979 (with sparsity) | about 990, halved estimate | 3.35 TB/s | about 295 |
| A100 80 GB SXM | 312 and 624 (with sparsity) | 312, printed | 2,039 GB/s | about 153 |
- The A100 page prints both figures, 312 dense and 624 with sparsity. The H100 page prints only the figure marked “with sparsity”, so its dense value is that number halved, an estimate to check against the datasheet.
- Ridge = dense FLOP/s divided by bandwidth. Other variants and newer parts have other numbers.
- kipply’s post uses 312 TFLOPS and 1.5 TB/s and gets 208, a reminder that the ridge depends on the bandwidth used.
Sources[6] NVIDIA H100 Tensor Core GPU[7] NVIDIA A100 Tensor Core GPU[4] Transformer Inference Arithmetic
Check yourself
Check: read the batch off a profiler
A profile of BF16 decode on an A100 80 GB SXM (312 dense TFLOPS, 2,039 GB/s) shows tensor-core utilization of 4.4 percent and memory-bandwidth utilization of 85 percent. What arithmetic intensity does that imply, what batch size does it suggest, and how does it sit against the ridge?
Answer
Achieved compute is 0.044×312=13.7 TFLOPS and achieved traffic is 0.85×2.039=1.73 TB/s. Their ratio is about 7.9 FLOP per byte. For BF16 the intensity is about the batch size, so the server was running a batch of roughly 8. The ridge is about 153, so the step sits far to the left of it, and a near-saturated memory bus with idle arithmetic is exactly what that position predicts.
Math
Decode intensity and the batch that reaches the ridge
intensity≈P⋅b2BP=b2BBridge=2ridge×b| Symbol | Meaning |
|---|---|
| B | Batch size: sequences decoded together in one step |
| b | Bytes per weight |
| ridge | Peak dense FLOP/s divided by peak bandwidth |
The weights are read once per step and serve all B tokens. For BF16 (b=2) the intensity is simply B.
Worked example
Worked: decode against the A100 ridge
BF16 weights, ridge about 153 FLOP per byte.
| Batch size B | Intensity (about B) | Side of the ridge | Limit |
|---|---|---|---|
| 1 | 1 | far left | memory bandwidth |
| 16 | 16 | left | memory bandwidth |
| 64 | 64 | left | memory bandwidth |
| 153 | 153 | at the ridge | both |
| 256 | 256 | right | compute |
At ordinary batch sizes decode sits far left of the ridge. The arithmetic units idle, which is why decode is slow per user and why a bigger batch costs almost nothing in step time.
Concept
Prefill is not always compute-bound
- One pass over the weights serves all n prompt tokens, so BF16 prefill intensity is about n.
- On the A100 ridge of 153, a 600-token prompt is compute-bound and a 100-token prompt is memory-bound.
- Compare n with the ridge instead of memorising a phase label.
- Prefill FLOPs are about 2Pn plus attention terms that grow with n2. For an 8B model and 512 tokens at an estimated dense 990 TFLOPS, the floor is 990×10122×8×109×512≈8.3 ms, an optimistic minimum.
Math
The batch-1 ceiling
step time≥bandwidth×GPUsweight bytestokens per second≤step time1| Symbol | Meaning |
|---|---|
| weight bytes | Parameters times bytes per weight |
| bandwidth | Peak memory bandwidth of one GPU |
| GPUs | Number of GPUs sharing the weights, assuming ideal splitting |
The bound counts only weight traffic. It is a ceiling, never a prediction.
Worked example
Worked: three ceilings on 3.35 TB/s GPUs
| Case | Weight bytes | Aggregate bandwidth | Step at least | Tokens/s at most |
|---|---|---|---|---|
| 8B, BF16, 1 GPU | 16 GB | 3.35 TB/s | 4.8 ms | about 209 |
| 70B, BF16, 2 GPUs | 140 GB | 6.7 TB/s | 20.9 ms | about 48 |
| 70B, INT4, 1 GPU | about 35 GB | 3.35 TB/s | 10.4 ms | about 96 |
The bandwidth is the H100 SXM page figure. The 140 GB case needs two 80 GB GPUs just to hold the weights. INT4 weights fit on one and cut the step time to about half.
Code
A calculator that rejects bad input
Python
def decode_step_ms(params_b, bytes_per_param, bw_tb_s, n_gpus=1):
"""Lower bound on one decode step, in ms."""
if not (params_b > 0 and bytes_per_param > 0 and bw_tb_s > 0 and n_gpus >= 1):
raise ValueError("sizes and bandwidth must be positive, n_gpus at least 1")
weight_bytes = params_b * 1e9 * bytes_per_param
return weight_bytes / (bw_tb_s * 1e12 * n_gpus) * 1e3
def ridge(dense_tflops, bw_tb_s):
"""FLOP per byte where a chip stops being memory-bound."""
if not (dense_tflops > 0 and bw_tb_s > 0):
raise ValueError("peak compute and bandwidth must be positive")
return dense_tflops / bw_tb_s
step = decode_step_ms(20, 1, 2.039) # 20B model, 8-bit weights, A100 bandwidth
print(round(step, 1), round(1000 / step)) # 9.8 102
print(round(ridge(450, 3.0))) # 150A zero, negative or NaN size or bandwidth, or fewer than one GPU, raises ValueError instead of dividing by zero or returning a nonsense ceiling.
Check yourself
Check: predict what the calculator prints
Using decode_step_ms from the code slide, predict the result of each call. (a) round(decode_step_ms(30, 2, 1.5, 2), 1) (b) round(decode_step_ms(30, 0.5, 1.5), 1) (c) decode_step_ms(30, 2, 1.5, 0.5). For (a), also give the token-per-second ceiling it implies.
Answer
(a) The weights are 60 GB and the aggregate bandwidth is 2×1.5=3 TB/s, so it prints 20.0 ms, a ceiling of 50 tokens per second. (b) The weights are 15 GB (half a byte per parameter) on 1.5 TB/s, so it prints 10.0. (c) Half a GPU is fewer than one, so the guard raises ValueError and nothing is returned. The ceiling still ignores cache reads and overhead, so real engines land below 50.
Concept
What the ceiling leaves out
- KV-cache reads, which add bytes to every step and grow with context and batch.
- GPU-to-GPU communication when the model is split.
- Quantization scale factors, which make real files a little larger than the format suggests.
- Kernels that reach only part of peak bandwidth, plus launch overhead, sampling, CPU scheduling and framework cost.
- Real engines land below the ceiling. Use it to judge whether a measurement is plausible, then profile before theorising.
Concept
Why batching helps, and what stops it
- For an 8B BF16 model on a 3.35 TB/s GPU, a step reads 16 GB of weights in about 4.8 ms whether the batch holds 1 sequence or 32. Ideal aggregate output rises from about 209 to about 6,700 tokens per second.
- Three things stop it before the ridge: KV-cache memory (every request holds a cache), attention reads (each cache adds bytes that sharing the weights cannot hide), and the latency target (users feel the step time).
- The PagedAttention arXiv preprint (its comments field says SOSP 2023) starts from the same point: high throughput needs many requests batched, and cache memory lost to fragmentation limits how many.
Source[8] Efficient Memory Management for Large Language Model Serving with PagedAttention
Diagram
The optimization map
Compare
Each family answers a roofline fact
| Family | Roofline fact it uses | Examples |
|---|---|---|
| Do less work | Prefill FLOPs scale with prompt length | prefix caching, shorter prompts, routing to a smaller model |
| Move fewer bytes | Decode time is bytes over bandwidth | weight and cache quantization, grouped-query attention |
| Use hardware better | Batching raises intensity toward the ridge; more GPUs add aggregate bandwidth; idle gaps waste the ceiling | continuous batching, chunked prefill, parallelism, CUDA graphs |
| Run reliably | A fast design still fails if it falls over | autoscaling, routing, load shedding, fallback |
Check yourself
Check: which change closes the gap?
A 9B model in BF16 on one 3.0 TB/s GPU has a batch-1 ceiling of 6.0 ms per step. The measured step is 10.5 ms, and a trace shows 4.5 ms of idle gaps between kernels, from launch and scheduling overhead. Option X stores the weights in INT8. Option Y removes the idle gaps entirely, for example with CUDA graphs. Assuming the gaps stay at 4.5 ms under X, predict the step time and tokens per second for each. Which family on the map does each belong to?
Answer
Measured: 10.5 ms, about 95 tokens per second. X halves the weight bytes, so the floor drops from 6.0 to 3.0 ms, but the gaps remain: 7.5 ms, about 133 tokens per second. Y keeps the 6.0 ms floor and removes the gaps: 6.0 ms, about 167 tokens per second. Y wins even though X looks like the bigger roofline lever, because most of this step is not bandwidth at all. X is in the fewer-bytes family; Y is in the use-hardware-better family (the map lists CUDA graphs there). The ceiling does not include launch overhead, so profile before choosing a lever.
Summary
Summary
- A request is tokenize, queue, prefill, decode loop, stream. TTFT is the queue plus prefill; ITL is the decode step.
- ITL is (e2e−TTFT)/(tokens−1). Goodput counts only requests that met the targets.
- Quote throughput with the token type, concurrency and latency. Busier GPUs mean cheaper tokens.
- Decode intensity is about 2B/b; the ridge is dense FLOP/s over bandwidth. Compare B or the prompt length with it.
- Batch-1 ceiling: weight bytes over aggregate bandwidth. It ignores cache reads, communication and overhead.
- Use dense datasheet numbers, not the “with sparsity” ones.
References
References & Sources (1 of 2)
Mastering LLM Techniques: Inference Optimization (opens in a new tab)
Shashank Verma, Neal Vaidya2023Article
https://developer.nvidia.com/blog/mastering-llm-techniques-inference-optimization/
Used for The prefill and decode phases, and that decode is a memory-bound, matrix-vector-like operation because moving weights, keys, values and activations dominates the latency.
Metrics (NVIDIA NIM Benchmarking for LLMs) (opens in a new tab)
NVIDIA2026Documentation
https://docs.nvidia.com/nim/benchmarking/llm/latest/metrics.html
Used for Definitions of TTFT, ITL, end-to-end latency, tokens per second per system and per user.
Yinmin Zhong, Shengyu Liu, Junda Chen, Jianbo Hu, et al.2024OSDI 2024Paper
arXiv 2401.09670 (opens in a new tab)https://www.usenix.org/conference/osdi24/presentation/zhong-yinmin
Used for Performance framed as the maximum request rate served within both TTFT and per-token latency constraints.
Transformer Inference Arithmetic (opens in a new tab)
kipply2022Article
https://kipp.ly/transformer-inference-arithmetic/
Used for About 2P FLOPs per token, and a ridge of about 208 from 312 TFLOPS and 1.5 TB/s.
Samuel Williams, Andrew Waterman, David Patterson2008Article
https://www2.eecs.berkeley.edu/Pubs/TechRpts/2008/EECS-2008-134.html
Used for The roofline model as a visual performance model, and its origin as a 2008 Berkeley technical report.
References
References & Sources (2 of 2)
NVIDIA H100 Tensor Core GPU (opens in a new tab)
NVIDIA2026Documentation
https://www.nvidia.com/en-us/data-center/h100/
Used for H100 SXM memory bandwidth of 3.35 TB/s and the 1,979 teraFLOPS BF16 figure marked as with sparsity.
NVIDIA A100 Tensor Core GPU (opens in a new tab)
NVIDIA2026Documentation
https://www.nvidia.com/en-us/data-center/a100/
Used for A100 memory bandwidth of 2,039 GB/s, and the BF16 figures of 312 TFLOPS dense and 624 TFLOPS with sparsity, both printed on the page.
Woosuk Kwon, Zhuohan Li, Siyuan Zhuang, Ying Sheng, et al.2023Preprint
arXiv 2309.06180 (opens in a new tab)https://arxiv.org/abs/2309.06180
Used for The motivation that wasted KV-cache memory limits how many requests can be batched.
Keys: ← → move, Home End first and last, F full screen.