Skip to content

Chapter 3 · Inference Acceleration

3.1 What is continuous batching, and why does it raise throughput? ★★

One-sentence answer

Continuous batching changes the scheduling granularity from "a batch of requests" to "each decode step": at the end of every step, requests that have finished leave the batch immediately and free their KV cache, and queued requests join immediately, so the batch stays full. It raises throughput because decode is memory-bandwidth-bound, so the larger the batch, the more sequences a single read of the weights serves; with static batching, sequences that finish early just occupy their slots and new requests must wait for the whole batch to end, so the GPU is underused most of the time. The new problem it creates is that a long prompt's prefill stalls the decodes in the same step, which is usually eased with chunked prefill.

I will address three aspects: why batching raises throughput, the problem with static batching and how continuous batching works, and the new problem it creates along with the supporting techniques.

(1) A larger batch raises throughput, fundamentally because decode is memory-bandwidth-bound.

Every decode step reads all the weights from GPU memory but computes only one token per sequence, so its bottleneck is memory bandwidth rather than compute (see Chapter 0). If \(B\) sequences decode together, the weights are read once and serve one token for each of the \(B\) sequences, so the amount of computation per byte read (the arithmetic intensity) grows roughly linearly with \(B\). While the batch is still small, enlarging it therefore barely increases the time per step, yet throughput grows almost linearly, until the system becomes compute-bound. However, each sequence's KV cache is its own and cannot be read once for the whole batch the way the weights can, and the memory taken by the KV cache also caps how large the batch can be, which is exactly why KV cache memory management matters so much (see Chapter 1).

(2) Static batching wastes resources by making "the whole batch wait for the longest request", whereas continuous batching re-forms the batch at every step.

The simplest approach is static batching: gather a batch of requests and run them together until every sequence in the batch has finished, then start the next batch. The problem is that output lengths vary enormously: some requests end after 10 tokens, others need 2,000. Sequences that finish early just occupy their slots while waiting for the longest one, and newly arrived requests must wait for the whole batch to end before joining. The GPU is therefore lightly loaded most of the time, and queueing latency is high. Continuous batching (Orca, Yu et al. 2022, also called iteration-level scheduling) moves the scheduling granularity to each decode step: at the end of every step, finished sequences leave the batch immediately and free their KV cache, and queued requests join at the very next step. To fit requests at different stages into the same step, Orca proposed selective batching: attention is computed separately per request, since each request has a different length and KV cache, while per-token operations such as linear layers and the FFN concatenate the tokens of all requests and compute them together. A new request's prefill and older requests' decodes can thus be done in the same step, and the batch stays full. It needs flexible memory management such as PagedAttention to admit and release requests at any time (see Chapter 1). Inference frameworks such as vLLM, SGLang and TensorRT-LLM now all use continuous batching by default.

(3) Continuous batching introduces a new problem, prefill interfering with decode, and chunked prefill and scheduling policies are the supporting solutions.

  • Chunked prefill: When a very long prompt joins, its prefill is so heavy that every request decoding in the same step has to wait, and the output visibly stutters. Sarathi and Sarathi-Serve (Agrawal et al. 2023, 2024) split a long prompt's prefill into chunks and set a token budget per step, processing one prefill chunk per step alongside other requests' decodes. The work per step becomes more even, decode no longer stalls suddenly, and the compute that decode leaves unused is filled by prefill.
  • Preemption and admission control: When KV cache memory runs short, the scheduler has to pause some requests, either swapping their KV cache out to CPU memory or dropping it and recomputing later (see Chapter 1); the scheduler also has to decide at each step whether to prioritize new requests' prefill or older requests' decode, where the former helps lower the time to first token and the latter helps keep generation smooth.

If one wants to eliminate the interference between prefill and decode entirely, the two kinds of work can be placed on different GPUs, which is prefill/decode disaggregation (see 3.4).

In summary: the essence of continuous batching is letting the composition of the batch change dynamically at every step, so that decode's property of "being bandwidth-bound, with larger batches being more efficient" is actually exploited.

Going deeper: deriving the arithmetic intensity, comparing batching schemes, and published numbers

(1) Arithmetic intensity including the KV cache.

\[ I(B) \approx \frac{2N \cdot B}{2N + B \cdot M_{\text{KV}}} \]

Here \(I\) is the arithmetic intensity (floating-point operations per byte read), \(N\) is the parameter count, \(B\) is the number of sequences in the batch, and \(M_{\text{KV}}\) is the KV cache size per sequence in bytes (which grows with context length). The numerator is the computation in this step: about \(2N\) floating-point operations per token, for \(B\) tokens; the denominator is the data read in this step: the bf16 weights take \(2N\) bytes and are read once, and each sequence additionally reads its own KV cache. When \(M_{\text{KV}}\) is small, \(I \approx B\) and enlarging the batch helps a lot; when \(B\) is large, \(I\) approaches \(2N/M_{\text{KV}}\) and stops growing with the batch, so the longer the context, the smaller the gain from a larger batch. For reference, an H100 has about 989 TFLOPS of dense bf16 compute and about 3.35 TB/s of memory bandwidth, a ratio of about 300 floating-point operations per byte.

(2) Comparing batching schemes.

Static batching Dynamic batching Continuous batching
When the batch is formed Run as a whole once enough requests are gathered Sent after a short wait or once enough requests arrive Re-formed at every decode step
When a request leaves After the whole batch finishes After the whole batch finishes As soon as it finishes
When a new request joins When the next batch starts When the next batch starts At the next step
Suitable for Offline tasks with similar lengths Models with fixed-size outputs (e.g. classification, embeddings) LLM generation with highly variable output lengths
GPU utilization Low Medium High

(3) Published numbers.

On GPT-3 175B, Orca reported 36.9 times the throughput of NVIDIA FasterTransformer at the same latency level (Yu et al. 2022). This number comes from a specific latency target and system configuration and also includes the contribution of other system optimizations, so it should not be read as a general speedup from continuous batching in every setting.

Follow-up questions

Follow-up 1: Why does vLLM achieve much higher throughput than naive Hugging Face generate?

Because it fixes inefficiencies in scheduling, memory and kernels at the same time. Naive generate is essentially static batching: the whole batch waits for the longest sequence, and each sequence gets contiguous KV cache memory reserved for the maximum length; vLLM uses continuous batching to keep the batch full and PagedAttention to allocate the KV cache in blocks with almost no waste, so it can fit much larger batches; it also uses optimizations such as prefix caching, CUDA graphs and efficient attention kernels (see Chapter 1). Since decode is bandwidth-bound, a larger batch translates directly into higher throughput.

Follow-up 2: How should the chunk size for chunked prefill be chosen?

It is a trade-off between time to first token and smooth generation. Larger chunks make prefill more compute-efficient and lower the time to first token for long prompts, but each step takes longer, so the token gaps of decoding requests in the same step show larger spikes; smaller chunks make decode smoother, but prefill is split over more steps, each chunk has to re-read the weights and the KV cache of the earlier chunks, total overhead grows, and the time to first token also gets longer. In practice the size is set via a per-step token budget, so that each step's duration stays within the decode latency target.

Follow-up 3: Is a larger batch always better?

No. The larger the batch, the more computation and KV cache reading each step involves, so each step gets slower and the time per generated token rises; once the system becomes compute-bound, throughput stops growing as well. In addition, KV cache memory caps the batch size, and with long contexts the gain from a larger batch diminishes. Real deployments therefore choose the batch size subject to meeting latency targets (SLOs), and measure a system's real capacity by goodput (throughput counting only requests that meet their latency targets).

Common mistakes

  • Do not say that continuous batching reduces the computation per request: It raises GPU utilization; each request's computation is unchanged.
  • Do not conflate continuous batching with PagedAttention: The former solves scheduling and the latter solves memory management; they work together.
  • Do not say that enlarging the batch does not affect latency: The larger the batch, the slower each step, and the time per generated token rises.

3.2 How does speculative decoding work, and why is the output distribution unchanged? ★★

One-sentence answer

Speculative decoding exploits the fact that "decode is bandwidth-bound, so one forward pass of a large model takes about as long to verify a few tokens as to generate one": a cheap draft first guesses \(\gamma\) tokens in a row, the target model then verifies them in parallel in a single forward pass, each candidate is accepted with probability \(\min(1, p/q)\), and at the earliest rejected position a token is resampled from the corrected distribution \(\max(0, p-q)\). One can prove that the distribution of the token output at every position is exactly the target model's distribution \(p\), so the speedup is lossless. Each forward pass yields \((1-\alpha^{\gamma+1})/(1-\alpha)\) tokens in expectation, and real speedups are commonly 2–3 times; variants such as Medusa, EAGLE and multi-token prediction let the target model "bring its own draft".

I will address four aspects: the draft–verify loop, why the acceptance rule is exact, what determines the speedup, and the common variants.

(1) The draft–verify loop: a small model guesses several tokens in a row, and the large model verifies them all at once.

Speculative decoding (Leviathan et al. 2022; Chen et al. 2023) starts from the observation that decode time is spent mostly on reading the weights, so one forward pass of a large model takes about the same time for 1 token as for 5. If the next few tokens can be guessed cheaply, the large model can therefore check them all in one forward pass. Concretely, a much smaller draft model \(q\) (e.g. a 1B model from the same family as a 70B target; the two need to share a vocabulary) first autoregressively generates \(\gamma\) candidate tokens in a row, which is cheap; the prefix plus these \(\gamma\) candidates is then fed into the target model \(p\) in a single forward pass, which, just like teacher forcing in training, yields the target model's distributions at all \(\gamma+1\) positions at once; the candidates are then accepted or rejected one by one from left to right, and at the earliest rejected position that position is resampled from a corrected distribution, while all later candidates and their KV cache entries are discarded; if all \(\gamma\) candidates are accepted, one bonus token is sampled for free from the target model's distribution at position \(\gamma+1\). Every forward pass of the target model therefore produces at least 1 token (the same as ordinary decoding) and at most \(\gamma+1\).

(2) The acceptance rule guarantees that the output distribution at every position equals the target model's distribution exactly.

Let \(p(x)\) be the target model's probability for token \(x\) and \(q(x)\) the draft's. The acceptance rule is: a token \(x\) proposed by the draft is accepted with probability \(\min\big(1, p(x)/q(x)\big)\); if it is rejected, a token is resampled from the corrected distribution \(p'(x) \propto \max\big(0, p(x)-q(x)\big)\). The intuition is: if \(p(x) \ge q(x)\), the draft "under-proposes" this token, so it is always accepted; if \(p(x) < q(x)\), the draft "over-proposes" it, so it is accepted only with probability \(p(x)/q(x)\), rejecting the excess. Why is the resulting distribution exactly \(p\)? Compute it in two parts: the probability of outputting \(x\) via "the draft proposes it and it is accepted" is \(q(x)\cdot\min\big(1, p(x)/q(x)\big) = \min\big(p(x), q(x)\big)\), which falls short of the target probability by \(\max\big(0, p(x)-q(x)\big)\); resampling from \(p'\) after a rejection fills exactly this gap, and the two parts add up to exactly \(p(x)\) (the full derivation is in "Going deeper" below). Every position is handled this way: while all earlier candidates are accepted, the current position has exactly the prefix the target model would have produced itself; once a position is rejected and resampled, the later candidates were guessed from the old prefix and are all discarded. By induction over positions, the whole sequence therefore follows the target model's distribution. This means speculative decoding is not an approximation but lossless: the output distribution is exactly the same as sampling token by token from the large model, only faster. With greedy decoding the rule simplifies to: accept the draft token if it equals the target model's argmax, otherwise replace it with the target's argmax.

(3) The speedup is determined jointly by the acceptance rate, the draft's cost and the system load.

  • The acceptance rate: Let \(\alpha = \sum_x \min\big(p(x), q(x)\big)\) be the probability that each candidate is accepted; it measures how close the draft is to the target model. Assuming positions are independent, each target forward pass yields \((1-\alpha^{\gamma+1})/(1-\alpha)\) tokens in expectation, e.g. about 3.4 tokens with \(\alpha=0.8\) and \(\gamma=4\). When writing code, producing structured output or restating the input, the draft guesses right easily and \(\alpha\) is high; open-ended creative writing has a much lower \(\alpha\).
  • The draft's cost and the choice of \(\gamma\): The real speedup must subtract the draft's own cost. With \(\gamma\) too small, each pass gains few extra tokens; with \(\gamma\) too large, most of the later candidates are rejected and the draft's computation is wasted.
  • Batch size: Speculative decoding assumes the target model has spare compute. At large batch sizes the system is already close to compute-bound, so verifying extra tokens is no longer "free", and rejected tokens waste compute; the gain drops sharply and can even turn into a slowdown. It therefore suits low-batch, latency-sensitive settings best.

(4) The common goal of the variants is to remove the separate draft model and let the target model "bring its own draft".

A separate draft model has plenty of hassles: you need a small model with a close distribution and the same vocabulary, it takes extra memory, and the two models must be scheduled together in deployment. This led to the following families of methods:

  • Medusa (Cai et al. 2024): Several extra decoding heads are added on the target model's last hidden state, with head \(k\) directly predicting the token \(k+1\) positions ahead. The heads' candidates are combined into a candidate tree, and tree attention (a special attention mask that lets each path in the tree see only its own ancestors) verifies all branches in one forward pass. Its weakness is that all heads start from the same hidden state and predict later tokens without knowing what was actually sampled in between, so later heads are less accurate; moreover, by default it uses a relaxed acceptance rule and is not strictly lossless.
  • EAGLE (Li et al. 2024): A very light draft head (about one Transformer layer) is autoregressive at the feature level: its input is the target model's top-layer features plus the tokens already sampled, and it predicts the following tokens step by step. It uses the large model's rich features and also knows what was actually sampled, so its acceptance rate is much higher than Medusa's, and it uses the standard acceptance rule, so it is lossless. EAGLE-3 (Li et al. 2025) goes further by dropping feature prediction and instead fusing features from several layers to predict tokens directly, simulating multi-step generation at inference during training; the paper reports speedups of up to about 6.5 times.
  • Multi-token prediction (MTP): The model is trained during pretraining to predict several upcoming tokens at every position, and at inference the extra prediction heads serve as the draft. Gloeckle et al. (2024) use several output heads on a shared trunk to predict the next 4 tokens, speeding up inference by up to about 3 times; DeepSeek-V3's MTP module predicts sequentially, keeping the full causal chain, and when used as the draft at inference the acceptance rate of the extra predicted token is 85%–90%, raising generation speed (tokens per second) to about 1.8 times (DeepSeek-AI 2024).

(There are also training-free methods, such as prompt lookup decoding, which copies n-grams directly from the context as candidates and is very effective on tasks that restate much of the input, such as summarization, rewriting and code editing.)

In summary: speculative decoding uses cheap guesses plus one parallel verification to turn compute that sits idle during decode into fewer sequential steps; the acceptance rule guarantees that this speedup is exact in distribution.

Going deeper: the full derivation of the acceptance rule, the speedup formula, and a comparison of variants

(1) The acceptance rule and the output distribution.

\[ \text{Accept } x \sim q \text{ with probability } \min\!\left(1, \frac{p(x)}{q(x)}\right); \qquad \text{if rejected, resample from } \ p'(x) = \frac{\max\big(0,\ p(x) - q(x)\big)}{\sum_{x'} \max\big(0,\ p(x') - q(x')\big)} \]
\[ P(\text{output} = x) = \underbrace{q(x) \min\!\left(1, \tfrac{p(x)}{q(x)}\right)}_{=\ \min(p(x),\ q(x))} + \underbrace{P(\text{reject}) \cdot p'(x)}_{=\ \max(0,\ p(x) - q(x))} = p(x) \]

Here \(x'\) ranges over the vocabulary. The rejection term equals \(\max(0, p(x)-q(x))\) because of the total rejection probability: \(P(\text{reject}) = \sum_x q(x)\big(1-\min(1, p(x)/q(x))\big) = \sum_x \max\big(0, q(x)-p(x)\big)\). Since \(p\) and \(q\) both sum to 1, \(\sum_x \max(0, q(x)-p(x)) = \sum_x \max(0, p(x)-q(x))\), which is exactly the normalizer of \(p'\), so \(P(\text{reject})\cdot p'(x) = \max\big(0, p(x)-q(x)\big)\). Finally, \(\min(p, q) + \max(0, p-q) = p\).

(2) The speedup.

\[ \alpha = \sum_x \min\big(p(x), q(x)\big), \qquad \mathbb{E}[\text{tokens per target forward}] = \sum_{i=0}^{\gamma} \alpha^{i} = \frac{1 - \alpha^{\gamma + 1}}{1 - \alpha}, \qquad \text{speedup} \approx \frac{1 - \alpha^{\gamma + 1}}{(1 - \alpha)(\gamma c + 1)} \]

Here \(\alpha\) is the acceptance rate (which also equals 1 minus the total variation distance between \(p\) and \(q\)), \(\gamma\) is the number of tokens guessed per round, and \(c\) is the ratio of the time of one draft forward pass to that of one target forward pass. The sum means: the probability that the first \(i\) candidates are all accepted is \(\alpha^i\), each additional accepted candidate yields one more token, and one more token comes from the final resampled or bonus token. The factor \(\gamma c + 1\) in the denominator is the time per round (\(\gamma\) draft forward passes plus one target forward pass), in units of one target forward pass (Leviathan et al. 2022). For example, with \(\alpha=0.8\) and \(\gamma=4\), each forward pass yields about 3.36 tokens in expectation; with \(c=0.05\), the speedup is about \(3.36/1.2 \approx 2.8\).

(3) Comparing the variants.

Method Source of the draft Training needed Strictly lossless Characteristics
Standard speculative decoding A separate small model Usually not (can be distilled to raise acceptance) Yes Needs a small model with the same vocabulary; extra memory
Medusa Several prediction heads on the target model Train the heads Not by default (uses a relaxed acceptance rule) Later heads are less accurate
EAGLE / EAGLE-3 A light autoregressive head on the target model's features Train the draft head Yes High acceptance; integrated into mainstream inference frameworks
MTP Multi-token prediction modules present from pretraining Trained together with pretraining Yes No extra draft needed; built into the model
Prompt lookup n-grams copied from the context No Yes Effective only on tasks that restate much of the input

Follow-up questions

Follow-up 1: Why does verifying \(\gamma\) tokens take only one forward pass?

Because under a causal mask a Transformer computes the outputs at all positions in parallel, just as in teacher forcing during training. When the prefix and the \(\gamma\) candidates are concatenated and fed to the model, each position sees only the tokens before it, so one forward pass yields, at every position, the next-token distribution "assuming all earlier candidates are correct". Since decode is bandwidth-bound, processing a few more tokens barely adds to the time spent reading the weights, so this verification takes about as long as generating one token.

Follow-up 2: When does speculative decoding give little speedup?

When the acceptance rate is low, when the draft is too expensive, or when the system is already compute-bound. When the draft's distribution is far from the target's, for example in open-ended creative writing, or when the draft has not been aligned to the target model, candidates are rejected quickly and most guesses are wasted; when the draft itself is not light enough, its cost eats the gain; and when the batch is large, the target model's compute is already saturated, so verifying extra tokens is no longer free and rejected tokens waste compute outright.

Follow-up 3: How does Medusa's default typical acceptance differ from standard rejection sampling?

Standard rejection sampling is lossless, whereas typical acceptance trades a small distribution shift for a higher acceptance rate. Typical acceptance accepts a candidate token as long as its probability under the target model exceeds a threshold (which depends on the entropy of the target distribution: the higher the entropy, the lower the threshold), instead of deciding at random with probability \(\min(1, p/q)\). More tokens are accepted and generation is faster, but the output distribution no longer equals the target model's exactly; if strict losslessness is required, Medusa can use standard rejection sampling instead.

Follow-up 4: How does MTP as a training objective relate to MTP as a draft for speculative decoding?

The same module provides a denser learning signal during training and serves as the draft at inference. During training, asking the model to also predict tokens further ahead at each position amounts to requiring its representations to contain a plan for what comes next, which can improve quality, especially on tasks such as code (see the LLM Training Pipeline direction, Chapter 2); at inference, these prediction heads are already aligned with the main model and can be used directly as the draft, with no need to train or deploy a separate small model. DeepSeek-V3 can also discard the MTP modules at inference, in which case the main model runs on its own as usual.

Common mistakes

  • Do not say that speculative decoding is an approximation that lowers quality: With the standard acceptance rule the output distribution is identical to the target model's; only relaxed rules such as Medusa's typical acceptance introduce a bias.
  • Do not treat "accept the draft token only if it equals the target's argmax" as the general rule: That is the special case for greedy decoding; with sampling, the \(\min(1, p/q)\) rule must be used.
  • Do not say that speculative decoding speeds things up at any batch size: The larger the batch, the smaller the gain, and it can even slow things down.
  • Do not say that any small model will do as the draft: The standard approach requires a shared vocabulary, and the closer the draft's distribution is to the target's, the higher the acceptance rate.

3.3 What quantization methods are there, and what problems do GPTQ, AWQ and SmoothQuant each solve? ★★

One-sentence answer

Quantization represents weights or activations with fewer bits: by whether training is needed, it divides into post-training quantization (PTQ) and quantization-aware training (QAT); by what is quantized, it divides into weight-only quantization (e.g. W4A16, which saves memory and speeds up bandwidth-bound decode) and weight-and-activation quantization (e.g. W8A8, FP8, which speeds up compute-bound prefill and large batches). GPTQ uses second-order information to compensate quantization error column by column, solving the accuracy problem of low-bit weight quantization; AWQ uses activation magnitudes to find the roughly 1% of salient weight channels and protects them with an equivalent scaling; SmoothQuant migrates the outliers that sit in fixed activation channels onto the weights through an equivalent transformation, making W8A8 feasible. By 2025–2026, FP8 is the standard configuration for serving large models, and FP4 on Blackwell (NVFP4, MXFP4) and "natively low-bit releases" of models are spreading.

I will address four aspects: the basic principle and difficulty of quantization, the two ways to classify methods, the problems the three representative methods each solve, and the trends of 2025–2026.

(1) The benefit of quantization comes from fewer bytes, and the difficulty comes from outliers.

The most common symmetric quantization maps the largest absolute value in a group to the largest integer, with scale \(s = \max|x| / (2^{b-1}-1)\), where \(b\) is the number of bits; each number is divided by \(s\) and rounded to an integer for storage, then multiplied back by \(s\) at use time. This formula reveals the single most important fact about quantization: the scale is set by the largest value in the group. A single large outlier inflates \(s\), and all the normally sized numbers get only a few integer levels, losing a lot of precision. Granularity therefore matters: one scale for the whole tensor (per-tensor) is simplest but most easily hurt by outliers, while one scale per output channel (per-channel) or per group of 64 or 128 weights (per-group) is more accurate, at the cost of storing more scales. The benefits of quantization show up in three ways: it saves memory, since a 70B model needs 140 GB in bf16 but only about 35 GB in INT4; it speeds up decode, since decode is bandwidth-bound and fewer bytes per weight cut the time to read the weights almost proportionally; and when both weights and activations are quantized to INT8 or FP8, it can also use low-precision Tensor Cores, making the matrix multiplications themselves faster.

(2) Quantization methods can be classified in two ways: whether training is needed, and what is quantized.

  • Post-training quantization vs quantization-aware training: Post-training quantization (PTQ) quantizes an already trained model directly, needing only a few hundred calibration samples to measure value ranges or compensate for error, and finishes in minutes to hours; at 8 bits it is nearly lossless, and 4-bit weight quantization with good methods also keeps most of the quality. Quantization-aware training (QAT) simulates quantization during training: in the forward pass, the weights are quantized and then dequantized (fake quantization), so the model adapts to the quantization error while training; since the round function has zero derivative almost everywhere, the backward pass uses the straight-through estimator (STE), approximating its derivative as 1. QAT clearly beats PTQ at 4 bits and below, at the cost of training compute; for example, Gemma 3 released QAT INT4 checkpoints (Gemma Team 2025).
  • Weight-only vs weight-and-activation quantization: Weight-only quantization (e.g. W4A16: 4-bit weights, 16-bit activations) dequantizes the weights back to 16 bits inside the kernel and then performs an ordinary matrix multiplication, so it does not reduce computation; what it reduces is memory and the amount of weight data read, which gives clear speedups when bandwidth is the bottleneck, as in decode and small batches. Quantizing both weights and activations (e.g. W8A8, in INT8 or FP8) runs the matrix multiplication directly on low-precision Tensor Cores, so the computation itself gets faster, with the largest gains in prefill and large-batch serving; the difficulty lies in the activations, which change with every input, must be quantized at runtime, and contain severe outliers.

(3) GPTQ, AWQ and SmoothQuant each target a different difficulty.

  • GPTQ addresses the excessive error of rounding each weight independently at low bit widths: GPTQ (Frantar et al. 2022) quantizes layer by layer, aiming to keep each quantized layer's output as close as possible to the original. It quantizes the weights one column at a time, and after each column it uses second-order information (the inverse Hessian) to spread that column's error onto the columns not yet quantized, adjusting their values to cancel the error. The intuition is that input dimensions are correlated, so one weight's quantization error can be partly compensated by other weights related to it. The paper reports quantizing a 175B model to 3–4 bits in about 4 GPU hours; its risk is some overfitting to the calibration data.
  • AWQ addresses the problem that a few weights matter much more than others: AWQ (Lin et al. 2023) observed that protecting only about 1% of salient weights greatly reduces quantization error, and that which weights are salient is decided by the size of the corresponding activations, since errors in channels with large input activations are amplified the most. Keeping these weights in 16 bits directly is hardware-unfriendly, so AWQ uses an equivalent scaling instead: multiply the salient channels' weights by \(s>1\) and divide the corresponding activations by \(s\), which is mathematically equivalent; the absolute error of the scaled-up weight after quantization stays about the same, but that error is ultimately multiplied by an activation that is \(s\) times smaller, so its effect on the output shrinks. It needs no backpropagation and no column-by-column error reconstruction, so it depends less on the calibration data.
  • SmoothQuant addresses activation outliers that break W8A8: LLM.int8() (Dettmers et al. 2022) found that once models reach about 6.7B parameters, systematic outliers appear in the activations: a few hidden dimensions have values far larger than the rest, and they appear in the same channels in every layer and for most tokens, so direct INT8 quantization makes quality collapse. SmoothQuant (Xiao et al. 2022) exploits the fact that "the outliers are concentrated in fixed channels, while the weights themselves are smooth": it chooses a scaling factor for each input channel, divides that column of the activations by it and multiplies the corresponding row of the weights by it, leaving the matrix product unchanged, which migrates part of the quantization difficulty from the activations to the weights. The scaling can be folded offline into the parameters of the previous layer, so it costs nothing at inference, enabling nearly lossless W8A8 inference.

(4) The trends of 2025–2026: FP8 has become the default configuration, and FP4 and "natively low-bit releases" are spreading.

On the H100 and H200 generation of GPUs, FP8 (E4M3) W8A8 inference has become the standard configuration for serving large models: the levels of a floating-point format are denser near small values and sparser near large ones, so it accommodates both outliers and small values better than uniform INT8, and with block-wise scaling factors the accuracy loss is usually small. DeepSeek-V3 was trained directly in FP8 and released its weights in FP8 (DeepSeek-AI 2024). The Blackwell generation adds FP4 Tensor Cores, and both mainstream formats handle outliers by sharing a scaling factor within small blocks: MXFP4 shares one power-of-two scale per 32 values, while NVFP4 shares one FP8 scale per 16 values plus an additional tensor-level scale. NVIDIA reports that post-training quantization of DeepSeek-R1-0528 to NVFP4 loses no more than 1% accuracy relative to FP8 (NVIDIA 2025). Meanwhile, more and more models are released directly in low-bit formats: gpt-oss quantized its MoE weights, which make up over 90% of the parameters, to MXFP4 during post-training, so that the 120B model fits on a single 80 GB GPU (OpenAI 2025); Kimi K2 Thinking applied INT4 weight-only quantization-aware training to its MoE components during post-training, improving generation speed by about 2 times (Moonshot AI 2025). The overall trend is that quantization is shifting from "compression after training" to "part of the training pipeline", and MoE expert weights, which dominate the parameter count and are bandwidth-bound at inference, have become the primary target of low-bit quantization.

In summary: the core tension in quantization is representing a distribution with outliers using very few bits; GPTQ relies on error compensation, AWQ on protecting salient channels, and SmoothQuant on migrating outliers from activations to weights, while block-scaled formats supported natively by hardware are handing part of the problem to the data format itself.

Going deeper: formulas, comparison tables and low-bit formats

(1) Symmetric quantization.

\[ x_q = \mathrm{clip}\!\left(\mathrm{round}\!\left(\frac{x}{s}\right),\ -2^{b-1},\ 2^{b-1} - 1\right), \qquad s = \frac{\max |x|}{2^{b-1} - 1}, \qquad \hat x = s \cdot x_q \]

Here \(x\) is the original value, \(b\) the number of bits, \(s\) the scale, \(x_q\) the stored integer, and \(\hat x\) the dequantized approximation; each number's error is at most \(s/2\). (Asymmetric quantization adds a zero point, which suits data not centered at 0.)

(2) GPTQ's objective and error compensation.

\[ \min_{\hat W}\ \big\| WX - \hat W X \big\|_2^2, \qquad H = 2XX^\top, \qquad \delta = -\frac{w_q - \hat w_q}{[H^{-1}]_{qq}}\, (H^{-1})_{:,q} \]

Here \(W\) is the layer's weight, \(\hat W\) the quantized weight, \(X\) the calibration inputs to this layer, and \(H\) the Hessian of this quadratic objective. After column \(q\) is quantized, \(w_q - \hat w_q\) is that column's quantization error, \(\delta\) is the update to the remaining, not-yet-quantized columns, \([H^{-1}]_{qq}\) is the \(q\)-th diagonal entry of \(H^{-1}\), and \((H^{-1})_{:,q}\) is its \(q\)-th column. This update comes from the classic Optimal Brain Surgeon.

(3) The equivalent transformation behind AWQ and SmoothQuant.

\[ Y = XW = \big(X\, \mathrm{diag}(s)^{-1}\big)\big(\mathrm{diag}(s)\, W\big), \qquad s_j^{\text{SmoothQuant}} = \frac{\max |X_{:,j}|^{\alpha}}{\max |W_{j,:}|^{1-\alpha}} \]

Here \(X\) is the activation, \(W\) the weight, \(\mathrm{diag}(s)\) the diagonal matrix of per-channel scaling factors, \(X_{:,j}\) column \(j\) of the activation, \(W_{j,:}\) row \(j\) of the weight, and \(\alpha\) (usually 0.5) controls how much difficulty is migrated: the larger \(\alpha\), the more goes to the weights. The two methods use the same equivalent transformation for different purposes: AWQ scales up the salient channels' weights so they are protected during weight quantization, while SmoothQuant scales down the outlier channels' activations so the activations become easy to quantize.

(4) Weight-only vs weight-and-activation quantization.

Weight-only (W4A16, W8A16) Weights and activations (W8A8, FP8)
What is low-precision Weights only; dequantized to 16 bits inside the kernel Weights and activations; the matmul runs in INT8 or FP8
Computation Unchanged Runs on faster low-precision Tensor Cores
Main benefit Less memory and less weight data read Faster matmuls
Best suited to Small-batch decode (bandwidth-bound) Prefill and large-batch serving (compute-bound)
Main difficulty Accuracy at 4 bits and below Activation outliers
Representative methods GPTQ, AWQ LLM.int8(), SmoothQuant, FP8

(5) Low-bit formats common in inference.

Format Bits and scaling Hardware support Typical use
INT8 (W8A8) 8-bit integers, scaled per channel or per token Broadly supported by mainstream GPUs SmoothQuant-style methods
FP8 E4M3 4 exponent bits and 3 mantissa bits, often with block-wise scaling The Hopper (H100) generation onward The standard configuration for serving large models today
INT4 (W4A16) 4-bit integers, one scale per group of 64 or 128 weights General (computed after dequantization) GPTQ, AWQ; memory-constrained deployments
MXFP4 4-bit floats, one power-of-two scale shared by 32 values, about 4.25 bits per value Native on Blackwell gpt-oss's MoE weights
NVFP4 4-bit floats, one FP8 scale shared by 16 values plus a tensor-level scale, about 4.5 bits per value Native on Blackwell Low-bit weight and activation inference

(The KV cache can also be quantized separately to FP8 or fewer bits; see Chapter 1. For FP8 training, see the LLM Training Pipeline direction, Chapter 3.)

Follow-up questions

Follow-up 1: Why are LLM activations harder to quantize than weights?

Because activations change with the input, and they contain systematic outliers. Weights are fixed after training and can be quantized carefully offline; activations differ for every input and must be quantized dynamically at runtime. Worse, once models reach about 6.7B parameters, a few hidden dimensions show values far larger than the rest for most tokens. With per-tensor quantization the scale is inflated by these outliers, all the normal values are squeezed into one or two levels near zero, and quality collapses.

Follow-up 2: Does weight-only quantization speed up inference?

Yes for decode and small batches, and essentially no for prefill and large batches. Weight-only quantization reduces the amount of weight data read, while the computation still runs in 16 bits. In decode the bottleneck is bandwidth, so halving or quartering the bytes read clearly speeds things up; in prefill and large batches the bottleneck is compute, the computation is not reduced, and dequantization even adds overhead.

Follow-up 3: In QAT the round function is not differentiable. How do gradients flow back?

With the straight-through estimator (STE), which treats the derivative of round as 1 during backpropagation. The round function is a staircase with zero derivative almost everywhere, so differentiating it directly makes the gradient vanish. STE quantizes as usual in the forward pass, so the model experiences the quantization error, and in the backward pass pretends round does not exist, letting the gradient pass straight through to update the high-precision master weights. The approximation is crude but works well in practice.

Follow-up 4: Why is FP8 better suited than INT8 for quantizing activations?

Because a floating-point format has roughly constant relative precision and a larger dynamic range. INT8's 256 levels are spread uniformly over the value range, so once the scale is inflated by outliers, small values are squeezed into a handful of levels; FP8's levels are denser near small values and sparser near large ones, so it can accommodate both outliers and the many small values. FP8 is therefore more tolerant of outliers and often reaches near-lossless quality without extra transformations such as SmoothQuant.

Common mistakes

  • Do not say that W4A16 reduces computation: The weights are dequantized to 16 bits before computing, so the computation is unchanged; what is saved is memory and bandwidth.
  • Do not say that AWQ judges importance by the size of the weights themselves: It looks at the size of the corresponding activations.
  • Do not say that SmoothQuant itself changes the model's output: The scaling is a mathematically equivalent transformation; error comes only from the quantization that follows.
  • Do not say that 4-bit quantization is always lossless: The result depends on the method, the model and the task, and errors are more visible at lower bit widths and on harder tasks, so evaluate on the target tasks rather than on perplexity alone.

3.4 What is prefill/decode disaggregation, and why disaggregate? ★

One-sentence answer

Prefill/decode (PD) disaggregation places the two phases on separate GPU pools: prefill instances only process prompts and compute the KV cache, which is then sent over a fast interconnect to decode instances that continue generating. The reason is that the two phases have different bottlenecks (prefill is compute-bound, decode is bandwidth-bound), so mixing them makes them interfere with each other and prevents each from choosing its best parallelism and batch size; once disaggregated, each can be optimized separately for time to first token and time per output token, raising goodput under latency targets. The costs are KV cache transfer and more complex scheduling, so it is mainly used in large-scale deployments.

I will address three aspects: the problems with colocated deployment, how disaggregation works and what it gains, and its costs and where it applies.

(1) Prefill and decode have different bottlenecks, and mixing them makes each drag the other down.

Prefill processes the whole prompt at once, with large matrix multiplications, and is compute-bound; decode processes only one token per step and is memory-bandwidth-bound (see Chapter 0). When they run mixed on the same GPUs, they interfere: a long prompt's prefill cutting in makes every request decoding in the same batch wait, causing spikes in token gaps; conversely, protecting decode latency forces limits on batch or prefill size, wasting compute. More fundamentally, the two phases want different configurations: prefill benefits from more tensor parallelism to shorten the time to first token, while decode needs large batches and ample memory for the KV cache. Chunked prefill (see 3.1) eases the interference but cannot give the two phases different configurations.

(2) Once disaggregated, the two phases can be configured and scaled independently.

PD disaggregation works as follows: a request first goes to a prefill instance, which computes the full KV cache and the first token; the KV cache is then sent over NVLink or an RDMA network to a decode instance, which continues generating token by token. This brings three benefits:

  • Interference is eliminated: No prefill cuts in on the decode instances, so token gaps are stable; the prefill instances also need not limit prompt processing to protect decode.
  • Configurations are chosen independently: Each pool can choose its own parallelism, batch size and even hardware. For example, Splitwise (Patel et al. 2023) explored running prefill on compute-strong GPUs and decode on cheaper GPUs.
  • Scaling is independent: The ratio of the two kinds of instances can be adjusted to the load; for example, a workload with very long prompts and very short outputs needs more prefill instances.

DistServe (Zhong et al. 2024) reported that, while meeting latency targets, PD disaggregation can serve 7.4 times more requests than the best prior systems, or still meet targets that are 12.6 times tighter. Kimi's Mooncake (Qin et al. 2024) goes further and designs the whole serving architecture around the KV cache; in the production inference system DeepSeek has described publicly, prefill uses 4 nodes (32 GPUs) as one deployment unit and decode uses 18 nodes (144 GPUs) as one unit (DeepSeek-AI 2025). By 2025, frameworks such as vLLM, SGLang and NVIDIA Dynamo all support PD disaggregation.

(3) The costs are KV cache transfer and scheduling complexity, so it is mainly used in large-scale deployments.

  • KV cache transfer: The amount transferred equals the prompt length times the KV cache size per token. For Llama 3 70B (80 layers, 8 KV heads, head dimension 128, bf16), each token takes about 320 KB, so an 8K prompt is about 2.5 GB, which needs a high-bandwidth RDMA network and layer-by-layer pipelined transfer overlapped with computation. Architectures that shrink the KV cache, such as GQA and MLA, become all the more valuable as a result (see the Model Architecture direction, Chapter 2).
  • Scheduling and load balancing: The ratio of the two kinds of instances must match the load, but real workloads keep changing in input and output lengths, and with the wrong ratio one side idles while the other queues.
  • Not worthwhile at small scale: With few GPUs it is hard to keep both pools busy, and colocated deployment with chunked prefill is often enough; the advantages of PD disaggregation only fully show in large-scale settings with strict latency requirements.

In summary: the essence of PD disaggregation is acknowledging that prefill and decode are two different workloads, trading one KV cache transfer for independent optimization of each phase.

Going deeper: comparing the two deployment modes and estimating the transfer size

(1) Colocated deployment vs PD disaggregation.

Colocated + chunked prefill PD disaggregation
Interference between prefill and decode Reduced, but still present Essentially eliminated
Parallelism and batch One configuration shared by both phases Chosen independently for each
Hardware The same Can differ
Extra overhead No KV transfer One KV cache transfer per request
Scheduling complexity Lower Higher; the two pools must be balanced
Suitable scale Small to medium Large, with strict latency requirements

(2) Estimating the KV cache transfer size.

\[ M_{\text{transfer}} = 2 \cdot L \cdot n_{\text{kv}} \cdot d_{\text{head}} \cdot \text{bytes} \cdot n_{\text{prompt}} \]

Here 2 stands for K and V, \(L\) is the number of layers, \(n_{\text{kv}}\) the number of KV heads, \(d_{\text{head}}\) the dimension of each head, bytes the number of bytes per value, and \(n_{\text{prompt}}\) the number of prompt tokens. Plugging in Llama 3 70B's configuration: \(2 \times 80 \times 8 \times 128 \times 2 = 327{,}680\) bytes per token, which times 8,192 tokens is about 2.5 GB.

(3) Disaggregating further.

(The same idea can be pushed further: MegaScale-Infer (Zhu et al. 2025) and Step-3 (StepFun 2025) also place attention and the FFN (or MoE experts) on different GPUs during decode, so that attention, which is limited by the KV cache, and the experts, which are limited by their weights, can each scale as needed.)

Follow-up questions

Follow-up 1: With chunked prefill available, why still disaggregate prefill and decode?

Because chunked prefill can only reduce the interference; it cannot let the two phases use different configurations. Under chunked prefill, each step still contains both prefill and decode, so decode's token gaps are still affected by the prefill chunk size; moreover, the two phases are forced to share one parallelism scheme, one batch and one kind of hardware, so they cannot be optimized separately for time to first token and time per output token, nor scaled independently with the load.

Follow-up 2: Can KV cache transfer become a bottleneck, and how can it be mitigated?

Yes, especially with long prompts; the common mitigations are overlapping the transfer, compressing the KV cache and reusing caches. The KV cache can be transferred layer by layer while prefill computes layer by layer, so transfer overlaps with computation; high-bandwidth networks such as RDMA can be used; architectures such as GQA and MLA, or quantizing the KV cache to FP8, reduce the amount transferred; and, as Mooncake does, a distributed KV cache pool can be built so that prefixes that hit the cache need neither recomputation nor retransfer.

Follow-up 3: How is the ratio of prefill to decode instances decided?

It depends on the workload's input and output lengths and the latency targets, and it needs to be adjusted dynamically with the load. One can measure the request rate a single prefill instance and a single decode instance can each handle while meeting their latency targets, and then set the ratio for the workload so that the two sides' capacities match; DistServe maximizes goodput by searching over the two phases' parallelism and instance placement. Real loads keep changing, so production systems usually also need to adjust the ratio dynamically; for example, NVIDIA Dynamo has a dedicated planner component that reallocates GPUs.

Common mistakes

  • Do not say that PD disaggregation reduces computation: The computation is unchanged; what improves is interference and resource allocation.
  • Do not say that PD disaggregation is better at any scale: In small deployments it is hard to keep both pools busy, and colocated deployment with chunked prefill is often more cost-effective.
  • Do not ignore KV cache transfer bandwidth: A long prompt's KV cache can reach several GB, and without enough network bandwidth the transfer cancels out the gains of disaggregation.

3.5 How is inference for large models parallelized? ★

One-sentence answer

The goals of inference parallelism differ from training: there are no gradients or optimizer states, and what matters is fitting the model, per-request latency and overall throughput. Tensor parallelism splits each layer within a node, so each GPU reads only \(1/t\) of the weights, which lowers per-token latency at the cost of all-reduce communication in every layer; pipeline parallelism splits by layers across machines, mainly to fit larger models and raise throughput, but it does not lower per-request latency; MoE models use expert parallelism, spreading the experts over many GPUs together with large batches and all-to-all communication. Real deployments combine these along the lines of "tensor parallelism when latency comes first, more replicas and expert parallelism when throughput comes first".

I will address three aspects: how inference parallelism differs from training parallelism, what each of the three parallelism schemes does, and how to combine them from the perspective of latency and throughput.

(1) The goal of inference parallelism is to fit the model and run it fast, not to spread training state.

Parallelism in training has to spread weights, gradients, optimizer states and activations (see the LLM Training Pipeline direction, Chapter 3); inference only needs to hold the weights and the KV cache, but it has strict latency requirements. Inference parallelism therefore has three motivations: first, fitting the model, e.g. a 70B model's bf16 weights take about 140 GB, more than one 80 GB GPU can hold, and MoE models with hundreds of billions of parameters such as DeepSeek-V3 need several machines; next, lowering latency, since decode is bandwidth-bound and splitting the weights across \(t\) GPUs means each reads only \(1/t\) of them, which effectively adds up the memory bandwidth of several GPUs; finally, raising throughput, by serving more requests at once with several replicas (data parallelism). For the same reason, ZeRO or FSDP, common in training, are unsuitable for online inference: they need to gather the sharded weights back at every step, which is far too much communication for decode, where each step computes only one token.

(2) The three parallelism schemes differ in what they split, how they communicate and what they gain.

  • Tensor parallelism (TP): Each layer's matrices are split across \(t\) GPUs (first by columns, then by rows; for the splitting details see the LLM Training Pipeline direction, Chapter 3), with 2 all-reduces per layer in the forward pass. Each GPU reads only \(1/t\) of the weights, so it directly lowers per-token latency; the KV heads are split along with it, so each GPU stores only \(1/t\) of the KV cache. Because every layer communicates and the communication sits on the critical path, it needs a fast intra-node interconnect such as NVLink, and \(t\) generally does not exceed 8. In addition, when \(t\) exceeds the number of KV heads, the KV heads can only be replicated across GPUs and the KV cache becomes redundant; for example, for a GQA model with 8 KV heads, TP beyond 8 is not worthwhile.
  • Pipeline parallelism (PP): Consecutive groups of layers are placed on different GPUs or machines, and adjacent stages pass only activations, so communication is light and can cross machines. But a request still has to pass through all stages in sequence, so it does not lower per-request latency and even adds transfers between stages; its role is to make deployable a model that would not otherwise fit, and to raise throughput by having different batches occupy different stages at the same time.
  • Expert parallelism (EP): An MoE model places different experts on different GPUs; after routing, each token is sent via all-to-all communication to the GPUs hosting its selected experts for computation, and the results are sent back (for the engineering challenges of MoE serving, see 5.6 in the Model Architecture direction, Chapter 5). Each GPU stores only a few experts, and the memory saved can hold more KV cache; but it needs a large enough batch for every expert to receive enough tokens, otherwise the cost of reading the expert weights is not amortized, and the load imbalance among experts also has to be handled. The attention part commonly uses data parallelism instead: MLA and GQA have very few KV heads, so splitting attention with tensor parallelism would duplicate the KV cache across GPUs, whereas data parallelism keeps each request's KV cache on a single GPU. In DeepSeek's production system, prefill uses 32-way expert parallelism with 32-way data-parallel attention, and decode scales this up to 144-way (DeepSeek-AI 2025).

(3) From the perspective of latency and throughput: tensor parallelism buys latency, replicas and expert parallelism buy throughput, and pipeline parallelism buys capacity.

Latency-sensitive online services (small batches, interactive use) usually apply tensor parallelism within a node to lower the time per generated token; but the larger \(t\) is, the larger the share of all-reduce overhead and the smaller the matrices on each GPU, so per-GPU efficiency drops. Throughput-oriented services prefer the smallest tensor-parallel degree that "just fits" and scale out with several replicas, which uses each GPU more efficiently. For example, when deploying a 70B model on 8 H100s, a single replica with 8-way tensor parallelism has the lowest latency, while two replicas with 4-way tensor parallelism usually give higher total throughput, with each request somewhat slower. For large MoE models with hundreds of billions of parameters, large-scale expert parallelism is combined with very large batches to amortize the reading of expert weights. Pipeline parallelism is introduced only when the model must span machines and the inter-machine bandwidth cannot support tensor parallelism. In addition, combined with PD disaggregation (see 3.4), the prefill pool and the decode pool can choose different parallel configurations.

In summary: choosing inference parallelism is essentially a trade-off between per-request latency and per-GPU throughput: tensor parallelism trades communication for latency, pipeline parallelism trades sequential stages for capacity, and expert and data parallelism trade large batches for throughput.

Going deeper: a latency model for tensor parallelism, a comparison of four schemes, and a published deployment

(1) Per-token decode time under tensor parallelism.

\[ T_{\text{token}}(t) \approx \frac{2N}{t \cdot \mathrm{BW}} + 2L \cdot T_{\text{AR}}(t) \]

Here \(N\) is the parameter count (the bf16 weights take \(2N\) bytes), \(t\) the number of tensor-parallel GPUs, \(\mathrm{BW}\) the memory bandwidth of one GPU, \(L\) the number of layers, and \(T_{\text{AR}}(t)\) the time of one all-reduce, of which each layer needs 2 in the forward pass. The first term falls as \(t\) grows, but the second does not (and may even grow with \(t\)), so the gain from increasing \(t\) diminishes; once the all-reduce has to cross machines, the second term rises sharply. KV cache reading is ignored here; with long contexts it is also divided evenly by \(t\).

(2) Comparing four schemes.

Tensor parallelism Pipeline parallelism Expert parallelism Data parallelism (replicas)
What is split The matrices of each layer Consecutive layers The MoE experts Nothing; the whole model is copied
Communication All-reduce in every layer Point-to-point between adjacent stages Two all-to-alls per MoE layer Essentially none at inference
Effect on per-request latency Lower Not lower; slightly higher Depends on batch and load balance Unchanged
Effect on throughput Per-GPU efficiency falls with \(t\) Higher Much higher with large batches Grows linearly
Where it applies Within a node, over NVLink Across machines Large MoE, multi-node Anywhere

(3) A published deployment.

In the inference system DeepSeek described publicly in 2025, prefill uses 4 nodes (32 H800s) as one unit, with 32-way expert parallelism for the experts and 32-way data parallelism for attention and the shared experts; decode uses 18 nodes (144 GPUs) as one unit, scaling up to 144-way expert and data parallelism, and splits each batch into two micro-batches that execute alternately so that one micro-batch's communication overlaps with the other's computation (DeepSeek-AI 2025). The SGLang team reproduced this deployment on 96 H100s with PD disaggregation plus large-scale expert parallelism, reaching throughput close to the level of DeepSeek's official report (LMSYS 2025). (For prefill of very long prompts, the sequence dimension can also be split, i.e. context parallelism.)

Follow-up questions

Follow-up 1: At inference, is more tensor parallelism always better?

No. Tensor parallelism performs all-reduces in every layer, and this overhead does not shrink with \(t\), so its share grows as \(t\) grows; once the matrices on each GPU get smaller, GPU utilization also drops; when \(t\) exceeds the number of KV heads, the KV cache becomes redundant; and once it extends beyond a single machine, the all-reduce has to go over a much slower inter-machine network, so latency actually rises. \(t\) therefore usually does not exceed the number of GPUs in a node, and is set to the smallest value that meets the latency target.

Follow-up 2: Why does MoE inference often use data parallelism for attention and expert parallelism for the experts?

Because the two parts differ in parameter count and in how their KV cache behaves. The experts account for the vast majority of an MoE model's parameters, so spreading them with expert parallelism saves the most memory; attention has relatively few parameters, and its main memory cost is each request's KV cache. MLA has only a single shared latent vector and GQA has few KV heads, so splitting attention with tensor parallelism forces the KV cache to be replicated across GPUs; data parallelism instead keeps each request's KV cache on a single GPU, with no redundancy.

Follow-up 3: How does parallelism in inference differ from parallelism in training?

Inference has no gradients or optimizer states, and it cares more about per-request latency. Training uses ZeRO or FSDP to spread optimizer states and gradients, which inference does not need; sharding the weights in the FSDP manner would require gathering the full weights at every decode step, which is far too much communication. In training the main problem with pipeline parallelism is the bubble, whereas at inference the pipeline can be kept busy by having different batches occupy different stages, but it can never lower per-request latency. In training, tensor parallelism is mainly about fitting the model and activations; at inference its more important role is adding up memory bandwidth to lower per-token latency.

Common mistakes

  • Do not say that pipeline parallelism lowers per-request latency: A request still passes through all stages in sequence; what it raises is capacity and throughput.
  • Do not apply training-style ZeRO or FSDP directly to online inference: Gathering the weights at every step is too much communication for decode.
  • Do not ignore the relationship between the tensor-parallel degree and the number of KV heads: When \(t\) exceeds the number of KV heads, the KV cache is replicated across GPUs.
  • Do not say that expert parallelism is efficient even with small batches: When the batch is too small, each expert receives too few tokens, and the cost of reading the expert weights is not amortized.