← Reference · Nestor G Pestelos Jr · Print this page

Reference Document

LLM Inference

A citable reference on Large Language Model inference: the two-phase prefill-decode lifecycle, operational bottlenecks, KV cache management, and high-throughput serving systems.

See Also & Related References

Jump to Section

1. Definition & The Two-Phase Lifecycle

LLM inference is the runtime evaluation process in which a trained language model processes prompt tokens and generates output text without adjusting network parameters. Inference divides into two distinct operational regimes:

2. Arithmetic Intensity & The Roofline Model

The operational limit of each phase is described by the Roofline Model, which relates arithmetic intensity (FLOPs per byte transferred from memory) to system performance bounds:

Execution Phase Matrix Operation Arithmetic Intensity Hardware Bottleneck
Prefill GEMM (Matrix-Matrix) High (\(\approx T_{\text{in}}\) FLOPs/byte) Tensor Core FLOP capacity (Compute-bound)
Decode GEMV (Matrix-Vector) Low (\(\approx 1\text{--}2\) FLOPs/byte) High Bandwidth Memory (HBM) transfer speed

In single-sequence generation, a 70B parameter model in FP16 format occupies 140 GB of VRAM. Producing one token requires transferring all 140 GB across the memory bus. On an accelerator with 2.0 TB/s memory bandwidth, theoretical single-user decode speed cannot exceed \(2000 / 140 \approx 14.3\) tokens per second, regardless of compute FLOP head-room [1].

3. The Key-Value (KV) Cache

To prevent recalculating key and value projections for preceding tokens at every decode iteration, inference engines store calculated keys and values in GPU memory as the KV Cache.

The memory consumed by the KV cache per token across the network is:

$$\text{KV Bytes per Token} = 2 \times 2 \times n_{\text{layers}} \times n_{\text{heads}} \times d_k \times \text{precision bytes}$$

For large batch sizes and extended context windows, the KV cache footprint quickly surpasses the parameter footprint of the model itself. Several architectural advances compress this footprint:

4. Serving Optimizations & Scheduling

Modern inference servers employ specialized scheduling and memory management frameworks:

5. Serving Performance Metrics

Production inference performance is measured across three primary service-level indicators:

1. Time to First Token (TTFT): The wall-clock latency between request submission and the delivery of the initial generated token. TTFT reflects queuing delay plus prompt prefill duration.

2. Inter-Token Latency (ITL): The average time elapsed between subsequent generated tokens during the decode phase. Crucial for real-time user-facing streaming applications.

3. Aggregate Throughput: The total volume of tokens (input plus output) processed per second across the server cluster (\(\text{tokens/sec}\)), governing total serving cost efficiency.