Chapter 37 of 40 · ~16 min read & lab+65 XP
Chapter 37 · Generative AI

LLM Inference Metrics Explained: TTFT, TPOT, Tokens/Sec & Memory-Bandwidth Bottlenecks

How to benchmark and size production LLM serving: Time-to-First-Token (prefill), Time-Per-Output-Token (decode), Throughput vs. Goodput, and why decode is memory-bandwidth bound

What Is It?

LLM Inference Metrics break perceived speed into TTFT (Time-to-First-Token, governed by prefill compute), TPOT / ITL (Time-Per-Output-Token, governed by GPU memory bandwidth), and Goodput (requests/sec meeting your latency SLAs).

Why Is It Required?

Optimizing total throughput alone can make streaming chat feel sluggish (high TTFT/TPOT), and misunderstanding compute-bound prefill vs. memory-bound decode leads to buying the wrong GPUs.

Everyday Analogy: TTFT is how long until the waiter brings your first bite; TPOT is the smooth rhythm between bites; Goodput is how many happy tables the restaurant serves per hour without anyone walking out.
Why ML Engineers & Data Scientists Actually Need This

Every LLM serving interview and GPU capacity plan boils down to Roofline math: Prefill = FLOPs, Decode = HBM Bandwidth!

ML / AI Engineer

Back-of-the-envelope formula max_tok_per_s ≈ HBM_Bandwidth / Active_Weights_GB immediately tells you why 4-bit quantization speeds up decode 3× on the same GPU.

Data Scientist

Knowing human reading speed (~5–8 tokens/sec) lets you set realistic TPOT SLAs (<100ms) while maximizing batch throughput.

Interview & Debug Edge

Classic infra question: 'A 70B FP16 model (140 GB) runs on an H100 (3,350 GB/s HBM). What is the theoretical ceiling on batch=1 decode tokens/sec?' (~24 tok/s!)

Step 0 · Test Your Gut Before Any Math!

You cut a 70B model's weights from FP16 (140 GB) to INT4 (35 GB) on the exact same GPU. Why does batch=1 decode speed jump nearly 3×–4×?

What You Will Master in This Chapter
  • Compute End-to-End Latency = TTFT + TPOT × (Output_Tokens − 1) and Tokens/Sec = 1000 / TPOT_ms.
  • Explain why Prefill is Compute-Bound (FLOPs) while Autoregressive Decode (batch=1) is Memory-Bandwidth-Bound (GB/s).
  • Estimate the theoretical maximum decode speed of any GPU from Memory_Bandwidth_GBps / Model_Size_GB.
  • Distinguish raw Throughput from SLA-compliant Goodput.
Plain-English Symbol Decoder · Click Any Symbol Before We Begin
1 / 2
Latency=TTFT+TPOT⋅(Tout−1)\text{Latency} = \text{TTFT} + \text{TPOT} \cdot (T_{\text{out}} - 1)Say aloud:“Total streaming latency”
Plain-English Meaning
Wait time for the first token (prefill) plus per-token decode time across remaining output tokens.
Everyday Example
TTFT=200ms, TPOT=25ms, 101 output tokens → 200 + 25×100 = 2.7s total.
Story-First Intuition, Visual Diagrams & Interactive Walkthroughs

Prefill processes 1,000 prompt tokens in parallel (matrix-matrix math → GPU compute engines roar at 100%). Decode processes 1 token at a time (matrix-vector math → compute engines sit idle waiting for weights to stream across GPU memory bandwidth!).

1. The 4 Core Serving Metrics

MetricWhat It MeasuresPrimary BottleneckTarget for Interactive Chat
TTFT (Time to First Token)Prompt prefill + queue waitGPU Compute (FLOPs)< 300–500 ms
TPOT / ITL (Time per Output Token)Streaming smoothnessGPU HBM Bandwidth (GB/s)< 30–50 ms (20–33 tok/s)
ThroughputTotal system tok/s across all usersBatch size & KV VRAMMaximize via Continuous Batching
GoodputRequests/sec meeting BOTH TTFT & TPOT SLAsBalanced scheduling (prefill/decode disaggregation)Primary production SLA KPI
“Wait, I'm Confused...” · Teacher Office Hours Q&A

The exact honest questions almost every beginner wonders — answered in plain English without hiding behind jargon.

Because long prefills stall streaming decode tokens on the same GPU, modern clusters (DistServe, vLLM/SGLang disaggregated serving) dedicate separate GPU pools to Prefill and Decode, transferring the KV-cache over fast NVLink/InfiniBand!

Interactive Visual Lab
Lab Challenge: See how continuous batching and PagedAttention boost serving throughput without wasting KV VRAM.
Interactive Animation • 6.2 Deep Lab

vLLM PagedAttention Physical Block Allocator & Shared Prefix Pool

Watch 3 concurrent users allocate non-contiguous 16-token KV pages on demand while sharing Page #0 (System Prompt).

Allocated: 1 / 6 Pages
Page #0
SYS (Shared)
Page #1
FREE
Page #2
FREE
Page #3
FREE
Page #4
FREE
Page #5
FREE
0%
Decode Iteration 1
Intuition Takeaway: Prefill is compute-bound (sets TTFT); single-user decode is memory-bandwidth-bound (sets TPOT ≈ Model_GB / HBM_GBps); optimize production serving for SLA-compliant Goodput.
Production NumPy & PyTorch Code Patterns
# Back-of-the-Envelope LLM Inference Roofline & SLA Calculator
def estimate_decode_ceiling(active_params_b: float, bytes_per_param: float, hbm_gb_s: float) -> float:
    model_gb = active_params_b * bytes_per_param
    return hbm_gb_s / model_gb  # theoretical max batch=1 tokens/sec

def total_latency_s(ttft_ms: float, tpot_ms: float, out_tokens: int) -> float:
    return (ttft_ms + tpot_ms * max(0, out_tokens - 1)) / 1000.0

# H100 SXM: ~3,350 GB/s HBM bandwidth on a 70B dense model
print(f"70B FP16 H100 ceiling: {estimate_decode_ceiling(70, 2.0, 3350):.1f} tok/s")
print(f"70B INT4 H100 ceiling: {estimate_decode_ceiling(70, 0.5, 3350):.1f} tok/s")
print(f"200-token reply latency (TTFT=300ms, TPOT=25ms): {total_latency_s(300, 25, 200):.2f}s")
Common ML Interview Traps & Numerical Pitfalls
Trap #1: Reporting peak offline throughput at batch=128 while ignoring that TTFT spiked to 12 seconds.
Best Practice: Always report Goodput (requests/sec under explicit TTFT and TPOT SLA ceilings).
Chapter Mastery Check (+65 XP)
Score: 0 / 1
1On an NVIDIA H100 (3,350 GB/s HBM bandwidth), roughly what is the theoretical maximum batch=1 decode speed of a 70B FP16 model (~140 GB)?

Apply What You Learned — Solve Matching Coding Problems