LLM inference is a side of AI that is less spoken about in general AI forums and discussions, but that is where an engineer optimizes for performance in a production environment. During tuning, accuracy and alignment are the two major pillars on which an LLM gets benchmarked. But what truly matters in a real chat is: how fast does the model respond, and how much does it cost?

Depending on the task, a developer can tune the response in multiple ways based on customer requirements, operational cost, and hardware constraints. The most common metrics used to evaluate serving systems are TTFT, TPOT, and Throughput.


Core Serving Metrics: TTFT, TPOT, and Throughput

  • TTFT (Time To First Token): The time elapsed between the user sending a request and the model returning the very first token. In an interactive chat, this is the time the user stares at a blank screen waiting for a response. It is mostly decided by the prefill phase, where the model must process the entire prompt before emitting anything. Longer prompts invariably lead to higher TTFT.

  • TPOT (Time Per Output Token): Once the first token is emitted, this is the average time taken to generate each subsequent token. This determines how smooth or fast the text streams on the screen. It is governed by the decode phase, where the model produces one token at a time autoregressively. As a rough rule of thumb, anything under ~50ms per token streams faster than human reading speed.

  • Throughput: The total volume of tokens the server generates per second across all concurrent users. While an individual user does not directly feel throughput, the person paying for GPU compute certainly does. Higher throughput means serving more requests on the same hardware, drastically reducing the cost per request.

These three metrics continually pull against one another. Pushing more requests into a batch increases overall throughput, but individual users may observe degraded TTFT and higher TPOT. That is the fundamental engineering tradeoff in LLM serving.

The Two Phases: Prefill vs. Decode

To understand why these metrics behave differently, we have to look at the two distinct operational phases of LLM inference:

  1. Prefill Phase (Compute-Bound): When a prompt arrives, the model processes all input tokens in parallel to generate the Key and Value vectors for the prompt and predict the very first output token. Because all prompt tokens are processed simultaneously in a single forward pass, matrix multiplications are large and compute-dense, saturating the GPU’s Tensor Cores. Prefill directly determines TTFT.
  2. Decode Phase (Memory Bandwidth-Bound): Once prefill completes, the model generates output tokens one by one. Each step requires reading the entire model weights and the accumulated KV cache from GPU High Bandwidth Memory (HBM) into SRAM just to produce a single token. Since arithmetic intensity is low, the GPU is bound by memory bandwidth. Decode directly determines TPOT.

Serving Optimization Techniques

In most production environments, LLM engines are primarily tuned to maximize throughput—maximizing tokens generated per second per GPU. This is achieved by combining several specialized memory and scheduling techniques:

  • KV Caching: During generation, every new token must attend to all previous tokens. Instead of recomputing the Key and Value representations of earlier tokens on every step, the engine caches them in GPU memory and reuses them. While this eliminates redundant computation, the cache consumes massive amounts of VRAM. For long-context workloads and multi-turn conversations, the KV cache can easily outgrow the model weights themselves. Efficiently managing this memory footprint remains an active area of systems research.

  • PagedAttention: Historically, memory for the KV cache was allocated as contiguous blocks per request, sized to the maximum possible sequence length. In practice, most of that pre-allocated memory went unused, leading to severe fragmentation. PagedAttention borrows the concept of virtual memory and paging from operating systems: it divides the KV cache into small, fixed-size blocks allocated non-contiguously across VRAM on demand. By eliminating external fragmentation, significantly more concurrent requests can fit onto the same GPU.

  • Continuous Batching: In traditional static batching, the engine waits for all sequences in a batch to finish generation before accepting new requests—meaning one verbose response stalls the entire batch. Continuous batching operates at the token step level: as soon as an individual request completes, it is evicted, and a new request is immediately admitted into the running batch. The GPU remains continuously saturated. Both PagedAttention and Continuous Batching are core design primitives that are permanently enabled in vLLM.

  • Prefix Caching: Many real-world workloads share identical prompt prefixes—such as common system prompts, few-shot examples, or static RAG context documents. Prefix caching retains the KV cache of these shared prefixes across requests in an in-memory Radix Tree. When a new query arrives with an existing prefix, the engine reuses the precomputed KV blocks, skipping prefill computation entirely for that segment. This dramatically cuts down TTFT.

  • Chunked Prefill: Processing a massive prompt in a single forward pass can monopolize GPU compute, causing concurrent decoding streams to stall. Chunked prefill breaks long prompts into smaller token chunks and co-schedules them alongside decoding steps within the same batch. This maintains consistent TPOT for active users, though the newly arrived prompt experiences a slight increase in TTFT as its prefill spans multiple steps. It acts as an adjustable tuning knob based on application latency targets.


The Serving Stack: vLLM and GuideLLM

To evaluate these tradeoffs systematically, we use two industry-standard tools:

  • vLLM: An open-source, high-throughput LLM serving engine developed at UC Berkeley’s Sky Computing Lab and introduced alongside the PagedAttention paper in 2023. It exposes an OpenAI-compatible API, natively supports open model architectures from Hugging Face, and integrates PagedAttention, Continuous Batching, Prefix Caching, Chunked Prefill, quantization, and tensor parallelism. Its initial benchmarks demonstrated up to 24x higher throughput compared to standard Hugging Face Transformers, making it a prevailing default for enterprise deployments. (Other notable runtimes include TensorRT-LLM, TGI, and Ollama, though they fall outside the scope of this benchmark.)

  • GuideLLM: An open-source performance evaluation tool developed by Neural Magic (now part of Red Hat) specifically for benchmarking LLM deployments. It generates realistic synthetic workloads against OpenAI-compatible endpoints, measuring TTFT, TPOT, throughput, and end-to-end request latency across controlled load sweeps. While real production latency is also influenced by network hops, load balancers, and external cache layers, GuideLLM provides a clean, isolated view of engine-level serving performance.


Evaluated Model Architectures

We evaluated three open-weight architectures, each representing distinct attention mechanisms and vocabulary designs:

  • Qwen2.5-7B-Instruct: Developed by Alibaba Cloud’s Qwen team and released under the Apache 2.0 license. The 7B model features 28 layers pretrained on ~18 trillion tokens. It utilizes an aggressive Grouped-Query Attention (GQA) layout with 28 query heads sharing just 4 KV heads (a 7:1 ratio). Having fewer KV heads drastically reduces the KV cache footprint per token, allowing higher concurrency in VRAM. However, its large ~152k vocabulary increases the computational weight of the final projection layer during decode.

  • Llama-3.1-8B-Instruct: Meta’s ubiquitous open-weight reference architecture. Featuring 32 layers trained on over 15 trillion tokens with native 128k context support, it uses a balanced GQA setup of 32 query heads to 8 KV heads (a 4:1 ratio). Its KV cache footprint per token is roughly double that of Qwen, but preserves higher attention capacity. With a 128k vocabulary, it serves as our baseline reference.

  • Gemma-2-9B-It: Google’s open architecture derived from Gemini research. With 42 layers trained on ~8 trillion tokens (utilizing knowledge distillation from larger models), its signature characteristic is a dual-attention mechanism: alternating layers between a 4096-token sliding-window local attention and global attention. Sliding-window layers only retain the latest 4096 tokens in their KV cache, limiting memory growth on long sequences. It also features the largest vocabulary of the group (256k tokens) and an 8k context window, yielding distinct latency characteristics under long-prompt workloads.


Operational Evaluation Dimensions

We evaluated three distinct operational dimensions for each architecture:

1. Workload Persona Profiles

Different applications place different demands on an inference engine. We defined three workload personas based on token balance:

  • Ingestion-Heavy (1024 In / 32 Out): Long prompt, short answer. Typical of RAG workflows or document summarization. Prefill dominates total execution time, making TTFT the primary bottleneck.
  • Generation-Heavy (128 In / 256 Out): Short prompt, long answer. Typical of code generation or step-by-step reasoning. Autoregressive decoding dominates, making TPOT and throughput the critical metrics.
  • Interactive Chat (512 In / 128 Out): Balanced multi-turn dialogue. Users demand both a prompt response (low TTFT) and fluid streaming (low TPOT).

GuideLLM generates synthetic requests configured to these exact input/output ratios, sending traffic to vLLM across increasing concurrency levels to measure latency degradation.

2. Chunked Prefill Granularity

The scheduling chunk budget in vLLM is governed by max_num_batched_tokens, which defines the maximum token capacity processed in a single forward pass across both prefill chunks and decode steps. Decode requests claim 1 token each, and remaining token slots are filled by prefill chunks.

  • Small Budgets (e.g., 128): Large prompts are divided into numerous small slices. Decoding streams experience minimal latency jitter, but incoming queries take many iterations to complete prefill, degrading TTFT.
  • Large Budgets (e.g., 2048): Prefills complete in fewer iterations, reducing TTFT. However, each batch execution becomes compute-heavy, increasing TPOT for active streams.

We swept max_num_batched_tokens across 128, 256, 512, 1024, and 2048 to identify the optimal configuration for this hardware.

3. Prefix Overlap Elasticity

We measured the empirical acceleration of prefix caching (--enable-prefix-caching) across prompt sharing ratios from 0% (completely unique queries) to 100% (fully cached prompts). The acceleration factor is defined as:

$$ Acceleration Factor = \frac{TTFT_{\text{cold (no cache)}}}{\text{TTFT}_{\text{cached}}} $$

A factor of $1.0\times$ indicates no improvement, while $4.0\times$ represents a fourfold reduction in time to first token.


Empirical Results on RTX 5090

All experiments were conducted on a single NVIDIA GeForce RTX 5090 (32 GB VRAM) running vLLM v0.31.0 with workloads orchestrated via GuideLLM.

Dimension 1: Workload Personas

Comparing the three models side by side within each workload persona highlights architectural strengths across different inference regimes:

Workload PersonaModelTTFT (ms)TPOT (ms/tok)Throughput (tok/s)
Ingestion-Heavy
(1024 In / 32 Out)
Qwen2.5-7B-Instruct19,489.5776.131.46
Llama-3.1-8B-Instruct513.732.0155.37
Gemma-2-9B-It1,177.354.6024.16
Generation-Heavy
(128 In / 256 Out)
Qwen2.5-7B-Instruct398.0512.4471.46
Llama-3.1-8B-Instruct470.1514.6960.50
Gemma-2-9B-It1,168.8636.5324.34
Interactive
(512 In / 128 Out)
Qwen2.5-7B-Instruct898.707.0271.21
Llama-3.1-8B-Instruct1,070.408.3659.79
Gemma-2-9B-It2,606.8820.3724.55

TTFT and TPOT across workload personas for Qwen2.5-7B, Llama-3.1-8B, and Gemma-2-9B on RTX 5090

Persona Analysis

  • Ingestion-Heavy: Llama leads with a 513.73 ms TTFT, followed by Gemma at ~1.18 s (consistent with Gemma’s larger 9B footprint and 42 layers). However, Qwen recorded an anomalous 19.49 s TTFT and 1.46 tok/s throughput—starkly contrasting its top performance in all other regimes. Given that Qwen’s architecture does not exhibit any theoretical bottleneck on 1024-token prompts, this data point likely stems from a cold-run queue stall or scheduler memory lock during that specific benchmark iteration. Furthermore, Llama’s 2.01 ms TPOT on a 32-token output reflects batch-averaged amortized latency rather than sustained single-stream decode speed.

  • Generation-Heavy: Here the architectural differences manifest cleanly. Autoregressive decode is strictly memory bandwidth-bound. Qwen achieves the lowest TPOT (12.44 ms/tok) and highest throughput (~71.46 tok/s) thanks to its 7:1 GQA ratio requiring minimal KV cache read volume per step. Llama trails closely (14.69 ms/tok, 60.50 tok/s) due to doubling the KV heads (4:1 ratio). Gemma trails significantly at 36.53 ms/tok and 24.34 tok/s—driven by its 42-layer depth and the computational overhead of projecting across its 256k vocabulary.

  • Interactive: The hierarchy remains consistent: Qwen finishes first (898.70 ms TTFT, 7.02 ms TPOT), Llama closely follows (1,070.40 ms TTFT, 8.36 ms TPOT), and Gemma trails at 2,606.88 ms TTFT and 20.37 ms TPOT. The 15–20% performance advantage of Qwen over Llama aligns cleanly with differences in model size and KV head count. While all three models stream well within comfortable human reading speeds, Gemma’s 2.6 s initial latency is noticeably perceptible in interactive settings.


Dimension 2: Chunked Prefill Granularity

TTFT and TPOT versus max_num_batched_tokens from 128 to 2048 for three models

In theory, chunked prefill involves an explicit trade-off: smaller chunk budgets should protect active decoding streams (lower TPOT jitter) at the expense of prompt processing latency (higher TTFT). In our empirical sweep across max_num_batched_tokens (128 to 2048):

  • Qwen2.5-7B: TTFT fluctuated narrowly between 421 ms and 456 ms; TPOT stayed between 8.04 ms and 8.71 ms.
  • Llama-3.1-8B: TTFT varied from 483 ms to 506 ms; TPOT hovered between 9.23 ms and 9.67 ms.
  • Gemma-2-9B: TTFT ranged from 1,174 ms to 1,282 ms; TPOT remained between 22.43 ms and 24.49 ms.

Across all architectures, overall metric variance remained under 10%. The clearest trend is that 128 tokens is universally the least optimal chunk budget, yielding the highest TTFT and TPOT. At 128 tokens, chunk fragmentation incurs repeated kernel launch and scheduler dispatch overheads that degrade performance. Beyond 256 tokens, curves flatten out entirely.

Takeaway: At moderate concurrency levels where prefill and decode queues are not heavily contended, chunked prefill granularity has minimal impact on latency. Setting max_num_batched_tokens between 512 and 2048 represents a safe default on the RTX 5090.


Dimension 3: Prefix Overlap Elasticity

TTFT and acceleration factor versus prefix overlap percentage for three models

Prefix caching demonstrated the most substantial impact of any tested optimization. On the left chart, TTFT scales downward almost linearly as prefix overlap increases from 0% to 75%:

  • Qwen2.5-7B: Decreases from 406.33 ms (0%) to 133.99 ms (75%).
  • Llama-3.1-8B: Decreases from 468.28 ms (0%) to 150.38 ms (75%).
  • Gemma-2-9B: Decreases from 1,206.99 ms (0%) to 386.54 ms (75%).

Remarkably, the relative acceleration factors are identical across all three architectures: 1.29x at 25%, 1.82x at 50%, and 3.08x at 75% overlap. The relative speedup is independent of model internals—it is strictly proportional to the fraction of prompt attention skipped.

However, in absolute time saved, larger models benefit far more. At 75% overlap, Gemma saves ~820 ms per query, whereas Qwen saves ~272 ms.

At 100% overlap, TTFT drops to exactly 5.0 ms across all three models. This indicates reaching the measurement floor of the test harness (HTTP request roundtrip, scheduler dispatch, and initial token emit). While this produces massive calculated speedups (85x for Qwen, 94x for Llama, and 240x for Gemma), the higher multiplier for Gemma simply reflects dividing its larger cold baseline by the same 5 ms floor.

Note on TPOT under Prefix Caching: As prefix overlap increases, measured TPOT rose slightly (e.g., Qwen TPOT increased from 7.76 ms at 0% to 14.73 ms at 100%). Because requests bypass prefill and reach the decode stage almost instantaneously, concurrent decode density increases, resulting in heavier decode batch steps.


Key Takeaways

  1. GQA Ratio Governs Decode Economics: Qwen’s 7:1 GQA ratio consistently yielded the fastest generation speed and highest throughput, with Llama (4:1) trailing by 15–20% and Gemma (sliding-window + 256k vocab) trailing by 2.5–3x.
  2. Prefix Caching is the Primary Latency Lever: Prefix caching provides near-linear TTFT reductions proportional to shared token depth, making --enable-prefix-caching essential for multi-turn chats and RAG architectures.
  3. Chunked Prefill Defaults: Avoid setting max_num_batched_tokens below 256. A budget between 512 and 1024 balances scheduling overhead and pipeline fairness on modern 32GB GPUs.
  4. Sanity Checking Benchmarks: In production benchmarking, anomalies (such as the ingestion-heavy cold outlier) underscore the necessity of verifying warmups and queue saturation before relying on raw numbers.