Inferensys

Glossary

Decoding Phase

The decoding phase is the iterative, memory-bandwidth-bound stage of autoregressive inference where a model generates output tokens one at a time, conditioned on previous outputs and cached key-value states.
ML engineer managing model training cluster on laptop, GPU utilization visible, technical deep learning setup.
INFERENCE OPTIMIZATION

What is the Decoding Phase?

A technical definition of the decoding phase in autoregressive language model inference.

The decoding phase is the iterative, memory-bandwidth-bound stage of autoregressive inference where a language model generates its output sequence token-by-token. Each forward pass consumes the previously generated token and the cached key-value (KV) states to produce the next token's logits, a process repeated until a stop condition is met. This phase is characterized by small, sequential computations dominated by memory reads, making it fundamentally different from the parallel prefilling phase.

Optimizing the decoding phase is critical for reducing inference latency and cost. Techniques like continuous batching and KV cache management directly target its bottlenecks by maximizing GPU utilization and minimizing redundant memory transfers. Its performance is a primary determinant of user-perceived speed in applications like chatbots and code completion, making it a central focus of inference serving architectures.

INFERENCE BOTTLENECK

Key Characteristics of the Decoding Phase

The decoding phase is the primary latency and cost driver in autoregressive text generation. Its defining characteristics stem from its iterative, sequential nature and heavy reliance on memory bandwidth.

01

Autoregressive and Sequential

The decoding phase operates autoregressively, meaning each generated output token becomes part of the input for generating the next token. This creates a fundamental sequential dependency where token N cannot be generated until token N-1 is produced. This serial nature prevents the full parallelization possible in the prefill phase, making it inherently slower per token. The process is defined as: P(output_token | prompt, all_previous_tokens).

02

Memory-Bound (Bandwidth Limited)

Unlike the compute-heavy prefill phase, decoding is predominantly memory-bound. Each forward pass to generate a single token involves:

  • Loading the model's weights from GPU memory (HBM).
  • Loading the growing KV Cache for all previous tokens.
  • Performing relatively small matrix operations. The time is dominated by the memory transfer of these large tensors, not the arithmetic itself. This is characterized by low arithmetic intensity (FLOPs per byte of memory access).
03

KV Cache Intensive

The Key-Value (KV) Cache is the critical state maintained during decoding. It stores the intermediate key and value vectors from the attention mechanism for all previously generated tokens, preventing their recomputation. Its size grows linearly with the batch size and sequence length, consuming significant GPU memory. Efficient management of this cache—its allocation, eviction, and memory layout—is paramount for performance. Techniques like paged attention are designed specifically to optimize KV cache usage.

04

Small, Frequent Kernel Launches

Each token generation requires launching a full set of GPU kernels for a forward pass, but for a very small amount of new computation (one token per sequence). This results in high kernel launch overhead relative to useful work. The small, per-token matrix multiplications often fail to fully utilize the GPU's massive parallel compute units (SMs), leading to low hardware utilization if not carefully batched. This contrasts with the large, efficient matmuls of the prefill phase.

05

Governed by Continuous Batching

Continuous batching (or iteration-level scheduling) is the essential optimization for this phase. It dynamically groups multiple user requests (sequences) into a single batch for each decoding step. New requests can join the active batch, and finished sequences can exit, without waiting for the entire original batch to complete. This maximizes GPU utilization and throughput by ensuring the GPU is always working on a sufficiently large batch of token generations, amortizing kernel launch and memory access overheads.

06

Primary Source of Inference Latency

For long generations, the time spent in the decoding phase dwarfs the initial prefill time. Latency is determined by: Total Latency = Prefill Time + (Number of Tokens * Per-Token Iteration Time). The per-token iteration time is the key metric for decoding efficiency. Furthermore, tail latency (p95, p99) is heavily influenced by variability in this phase, caused by factors like different sequence lengths in a batch leading to head-of-line blocking in naive batching schemes.

INFERENCE OPTIMIZATION

Decoding Phase vs. Prefill Phase

A technical comparison of the two primary computational stages in autoregressive transformer inference, highlighting their distinct resource constraints and optimization targets.

Feature / CharacteristicPrefill PhaseDecoding Phase

Primary Computational Constraint

Compute-Bound (FLOPs)

Memory-Bound (Bandwidth)

Parallelism Granularity

Token-Level (Full prompt processed in parallel)

Batch-Level (Multiple sequences processed in parallel)

Dominant Operation

Dense Matrix Multiplication (MatMul)

Gather & MatMul (Attention with KV Cache)

Key-Value (KV) Cache Activity

Populated (Initial cache is created)

Read & Extended (Cache is read and appended to)

Typical Latency Profile

High, one-time cost proportional to prompt length

Low, repeated cost per generated token

Optimization Priority

Maximizing FLOP/s utilization

Minimizing memory bandwidth consumption

Impact of Batch Size

Throughput increases significantly with larger batches

Throughput increases but latency per token also rises

Common Optimization Techniques

Operator FusionTensor Parallelism
Continuous BatchingKV Cache QuantizationSpeculative Decoding
DECODING PHASE

Frequently Asked Questions

The decoding phase is the iterative, memory-bandwidth-bound stage of autoregressive inference where a model generates output tokens one at a time. This section answers common technical questions about its mechanics, bottlenecks, and optimization strategies.

The decoding phase is the sequential, token-by-token generation stage of an autoregressive language model, where each new output token is produced conditioned on the model's previous outputs and the cached key-value (KV) states from the initial prompt.

During this phase, the model performs a small, memory-bound forward pass for each token. The primary computational pattern shifts from the large, parallel matrix multiplications of the prefilling phase to repeated, smaller operations that are heavily constrained by the speed of reading the model's parameters and the growing KV cache from GPU memory. This iterative nature makes the decoding phase the dominant contributor to latency in text generation tasks.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.