Slides · Inference engineering

Request lifecycle, metrics and the roofline

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

  1. Tokenize the prompt into tokens (CPU work).
  2. Queue: the scheduler holds the request until it can join a batch.
  3. Prefill: one pass over all prompt tokens builds the KV-cache and yields the first token.
  4. Decode: one pass per new token, reusing the cache, until an end token or a length limit.
  5. 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.

Source1 Mastering LLM Techniques: Inference Optimization

Diagram

Where the wait comes from

Diagram: A request waits in the queue, then prefill processes every prompt token and the first token streams out; that span is the time to first...

Prompt arrives

Queue until admitted

Prefill all prompt tokens

First token streamed

Decode: one token per step

Diagram summary: A request waits in the queue, then prefill processes every prompt token and the first token streams out; that span is the time to first token. The decode loop then repeats one step per token, and the gap between steps is the inter-token latency.

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

MetricDefinition (NVIDIA NIM benchmarking docs, version 2.0.0; the ITL formula is the AIPerf tool’s)
TTFTQuery submission to the first received token; empty initial responses are ignored
ITL (also TPOT)(e2e latency−TTFT)/(output tokens−1)(\text{e2e latency} - \text{TTFT}) / (\text{output tokens} - 1)
End-to-end latencySubmission to the full response: TTFT+generation time\text{TTFT} + \text{generation time}
TPS per systemOutput tokens across all requests divided by the run’s time window
TPS per userOne request’s output length divided by its end-to-end latency; approaches 1/ITL1 / \text{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.

Source2 Metrics (NVIDIA NIM Benchmarking for LLMs)

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.

QuantityCalculationValue
Generation time5.45−0.505.45 - 0.504.95 s
Gaps between 100 tokens100−1100 - 199
ITL4.95/994.95 / 9950 ms
TPS per user100/5.45100 / 5.45about 18.3
Ceiling of 1/ITL1 / \text{ITL}1/0.0501 / 0.05020

The per-user rate sits below 1/ITL1 / \text{ITL} because the first-token wait is counted in the end-to-end time.

Source2 Metrics (NVIDIA NIM Benchmarking for LLMs)

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.

RequestTTFT (s)ITL (ms)Meets both?
10.435yes
20.948yes
31.330no, TTFT
40.662no, ITL
50.745yes
61.050yes
72.170no, both
80.540yes

Throughput is 8/4=28 / 4 = 2 requests per second. Goodput is 5/4=1.255 / 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.

Source3 DistServe: Disaggregating Prefill and Decoding for Goodput-optimized Large Language Model Serving

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=price per hourtokens per second×3600×1,000,000\text{cost per million tokens} = \frac{\text{price per hour}}{\text{tokens per second} \times 3600} \times 1{,}000{,}000
SymbolMeaning
price per hour\text{price per hour}What the GPU (or the whole replica) costs per hour, whether busy or idle
tokens per second\text{tokens per second}Output tokens actually produced, averaged over the hour
36003600Seconds 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≈2P\text{FLOPs per token} \approx 2Pweight bytes=P×b\text{weight bytes} = P \times b
SymbolMeaning
PPNumber of parameters
bbBytes per parameter: 2 in BF16 or FP16, 1 in FP8 or INT8, 0.5 in INT4
22One multiply and one add per weight

kipply’s 2022 post makes the 2P2P 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.

Sources4 Transformer Inference Arithmetic1 Mastering LLM Techniques: Inference Optimization

Diagram

The roofline question

Diagram: A workload’s arithmetic intensity is compared with the chip’s ridge point, which is peak FLOP per second divided by peak bytes per second.

below

above

Workload intensity
FLOP per byte moved

Compare with ridge

Memory-bound

Compute-bound

Diagram summary: A workload’s arithmetic intensity is compared with the chip’s ridge point, which is peak FLOP per second divided by peak bytes per second. Below the ridge, memory bandwidth limits speed; above it, the arithmetic units do.

The roofline model comes from a 2008 UC Berkeley technical report by Williams, Waterman and Patterson.

Source5 Roofline: An Insightful Visual Performance Model for Floating-Point Programs and Multicore Architectures

Compare

Reading a datasheet for the ridge

Part (NVIDIA product page, fetched 2026-10-24)BF16 TFLOPS on the pageDense figureBandwidthRidge
H100 SXM1,979 (with sparsity)about 990, halved estimate3.35 TB/sabout 295
A100 80 GB SXM312 and 624 (with sparsity)312, printed2,039 GB/sabout 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.

Sources6 NVIDIA H100 Tensor Core GPU7 NVIDIA A100 Tensor Core GPU4 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 TFLOPS0.044 \times 312 = 13.7\ \text{TFLOPS} and achieved traffic is 0.85×2.039=1.73 TB/s0.85 \times 2.039 = 1.73\ \text{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≈2BPP⋅b=2Bb\text{intensity} \approx \frac{2BP}{P \cdot b} = \frac{2B}{b}Bridge=ridge×b2B_{\text{ridge}} = \frac{\text{ridge} \times b}{2}
SymbolMeaning
BBBatch size: sequences decoded together in one step
bbBytes per weight
ridge\text{ridge}Peak dense FLOP/s divided by peak bandwidth

The weights are read once per step and serve all BB tokens. For BF16 (b=2b = 2) the intensity is simply BB.

Worked example

Worked: decode against the A100 ridge

BF16 weights, ridge about 153 FLOP per byte.

Batch size BIntensity (about B)Side of the ridgeLimit
11far leftmemory bandwidth
1616leftmemory bandwidth
6464leftmemory bandwidth
153153at the ridgeboth
256256rightcompute

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 nn prompt tokens, so BF16 prefill intensity is about nn.
  • On the A100 ridge of 153, a 600-token prompt is compute-bound and a 100-token prompt is memory-bound.
  • Compare nn with the ridge instead of memorising a phase label.
  • Prefill FLOPs are about 2Pn2Pn plus attention terms that grow with n2n^{2}. For an 8B model and 512 tokens at an estimated dense 990 TFLOPS, the floor is 2×8×109×512990×1012≈8.3 ms\dfrac{2 \times 8 \times 10^{9} \times 512}{990 \times 10^{12}} \approx 8.3\ \text{ms}, an optimistic minimum.

Math

The batch-1 ceiling

step time≥weight bytesbandwidth×GPUs\text{step time} \ge \frac{\text{weight bytes}}{\text{bandwidth} \times \text{GPUs}}tokens per second≤1step time\text{tokens per second} \le \frac{1}{\text{step time}}
SymbolMeaning
weight bytes\text{weight bytes}Parameters times bytes per weight
bandwidth\text{bandwidth}Peak memory bandwidth of one GPU
GPUs\text{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

CaseWeight bytesAggregate bandwidthStep at leastTokens/s at most
8B, BF16, 1 GPU16 GB3.35 TB/s4.8 msabout 209
70B, BF16, 2 GPUs140 GB6.7 TB/s20.9 msabout 48
70B, INT4, 1 GPUabout 35 GB3.35 TB/s10.4 msabout 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.

Source6 NVIDIA H100 Tensor Core GPU

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)))               # 150

A 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/s2 \times 1.5 = 3\ \text{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.

Source8 Efficient Memory Management for Large Language Model Serving with PagedAttention

Diagram

The optimization map

Diagram: One goal, lower cost per token inside the latency targets, splits into four families: less work, fewer bytes, better hardware use and...

Lower cost per token

Less work

Fewer bytes

Better hardware use

Reliability

Diagram summary: One goal, lower cost per token inside the latency targets, splits into four families: less work, fewer bytes, better hardware use and reliability. The next slide ties each family to a roofline fact and lists its techniques.

Compare

Each family answers a roofline fact

FamilyRoofline fact it usesExamples
Do less workPrefill FLOPs scale with prompt lengthprefix caching, shorter prompts, routing to a smaller model
Move fewer bytesDecode time is bytes over bandwidthweight and cache quantization, grouped-query attention
Use hardware betterBatching raises intensity toward the ridge; more GPUs add aggregate bandwidth; idle gaps waste the ceilingcontinuous batching, chunked prefill, parallelism, CUDA graphs
Run reliablyA fast design still fails if it falls overautoscaling, 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)(\text{e2e} - \text{TTFT}) / (\text{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/b2B / b; the ridge is dense FLOP/s over bandwidth. Compare BB 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)

  1. Mastering LLM Techniques: Inference Optimization (opens in a new tab)

    Shashank Verma, Neal Vaidya2023Article

    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.

  2. Metrics (NVIDIA NIM Benchmarking for LLMs) (opens in a new tab)

    NVIDIA2026Documentation

    Used for Definitions of TTFT, ITL, end-to-end latency, tokens per second per system and per user.

  3. DistServe: Disaggregating Prefill and Decoding for Goodput-optimized Large Language Model Serving (opens in a new tab)

    Yinmin Zhong, Shengyu Liu, Junda Chen, Jianbo Hu, et al.2024OSDI 2024Paper

    Used for Performance framed as the maximum request rate served within both TTFT and per-token latency constraints.

  4. Transformer Inference Arithmetic (opens in a new tab)

    kipply2022Article

    Used for About 2P FLOPs per token, and a ridge of about 208 from 312 TFLOPS and 1.5 TB/s.

  5. Roofline: An Insightful Visual Performance Model for Floating-Point Programs and Multicore Architectures (opens in a new tab)

    Samuel Williams, Andrew Waterman, David Patterson2008Article

    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)

  1. NVIDIA H100 Tensor Core GPU (opens in a new tab)

    NVIDIA2026Documentation

    Used for H100 SXM memory bandwidth of 3.35 TB/s and the 1,979 teraFLOPS BF16 figure marked as with sparsity.

  2. NVIDIA A100 Tensor Core GPU (opens in a new tab)

    NVIDIA2026Documentation

    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.

  3. Efficient Memory Management for Large Language Model Serving with PagedAttention (opens in a new tab)

    Woosuk Kwon, Zhuohan Li, Siyuan Zhuang, Ying Sheng, et al.2023Preprint

    Used for The motivation that wasted KV-cache memory limits how many requests can be batched.