Pidoku

Quantization in vLLM

Module 18 Lesson 18.j 45 min Difficulty 3/5

Prerequisites 13.b, 13.e, 13.f, 13.g, 13.h, 17.h, 18.a, 18.c


Before you start: words you need#

WordPlain meaning
QuantizationStoring numbers in fewer bits (8 or 4 instead of 16), with a scale that maps the small numbers back to roughly the original values.
W8A8, W4A16Shorthand for “weights in 8 bits, activations in 8 bits” and “weights in 4 bits, activations kept in 16 bits”. Weight-only schemes (A16) shrink memory but still compute in 16 bits.
CheckpointThe model files on disk: weights plus config.json. A quantized checkpoint also says which scheme it uses.
CalibrationRunning a few hundred sample prompts through the model to choose good scales before quantizing.
KernelThe GPU program that does one operation, here a matrix multiply. A quantized format is fast only if a kernel computes on it directly.
MarlinA family of fast vLLM kernels for 4-bit and 8-bit weights with 16-bit activations. It is a kernel, not a file format.
Compute capability (SM)NVIDIA’s generation number: 8.0 Ampere (A100), 8.9 Ada (L40S), 9.0 Hopper (H100), 10.0 Blackwell (B200). It decides which number formats the hardware runs natively.
KV cache dtypeThe number format of the cached keys and values (17.h), chosen separately from the weights.

1. What is it?#

A model’s weights are normally stored as 16-bit numbers. Quantization stores them in 8 or 4 bits. vLLM, in the usual case, does not quantize a model itself: it loads a model that another tool has quantized, reads the scheme from the checkpoint, and builds every layer with a kernel matched to that scheme. It can also quantize a 16-bit model while loading it (online quantization), and it can store the KV cache in a smaller format, independently of the weights.

The theory of the methods lives in Module 13 (13.b to 13.h). This lesson is about what vLLM does with them: how it detects a format, which formats run fast on which GPU, and what changes inside the engine. Facts checked on 13 November 2026 against vLLM v0.32.0.

flowchart LR
  FP[":i-hard-drive: <b>16-bit model</b><br/><small>15 GiB</small>"] --> T[":i-wrench: <b>Quantization tool</b><br/><small>LLM Compressor, ModelOpt,<br/>GPTQModel, Quark…</small>"]
  T --> Q[":i-archive: <b>Quantized checkpoint</b><br/><small>+ a config naming the scheme</small>"]
  Q --> LD[":vllm: <b>vLLM loader</b><br/><small>reads the config,<br/>builds quantized layers</small>"]
  LD --> K[":nvidia: <b>Quantized kernel</b><br/><small>CUTLASS, Marlin, FlashInfer,<br/>DeepGEMM, Triton…</small>"]
  LD --> MEM["weights: 4–8 GiB<br/><small>the rest becomes KV blocks</small>"]
  ONL[":i-zap: <b>Online quantization</b><br/><small>--quantization fp8_per_tensor</small>"] -.->|"no pre-quantized checkpoint"| LD
  KV[":i-layers: <b>--kv-cache-dtype fp8</b><br/><small>independent of the weights</small>"] -.-> MEM
  class FP,Q memory
  class T,LD,K compute
  class MEM neutral
  class ONL,KV queue

2. Why does it exist?#

In a serving engine quantization buys two separate things.

  • Faster decode. Each decode step reads every weight once, so its speed is limited by memory bandwidth (2.e). Half the bytes is close to twice the steps per second, if a kernel computes on the packed weights.

  • More concurrent requests. The memory freed from weights becomes KV cache blocks. Recall the arithmetic of 17.h:

    KV cache memory = total × gpu_memory_utilization (0.92) − weights − working memory

    Weights are the largest term subtracted, so shrinking them raises concurrency more than proportionally. This second effect is invisible in a single-request benchmark and is often the larger one in production.


3. Simple analogy#

A removal van (the GPU) has a fixed size. Vacuum-packing the furniture (the weights) leaves room for more boxes of customers’ belongings (the KV cache), so one trip serves more customers. But packed furniture is only quick to use if the new house has the right tool to unpack it in place (a kernel). Without that tool, someone has to unpack every piece by hand each time it is needed, and the move gets slower even though the van is emptier.


4. Tiny example: one 24 GiB GPU, one 8B model#

Llama 3.1 8B on a 24 GiB GPU, with about 0.8 GiB of working memory:

16-bit weights   15.0 GiB  →  about  6.3 GiB of KV cache
 8-bit weights    7.5 GiB  →  about 13.8 GiB of KV cache     2.2× the tokens in flight
 4-bit weights    3.7 GiB  →  about 17.5 GiB of KV cache     2.8×

Halving the weights more than doubled the cache, because the fixed costs did not shrink. Add --kv-cache-dtype fp8 and each of those pools holds twice as many tokens again.


5. Technical explanation#

How vLLM knows a model is quantized#

You normally pass nothing. A quantized checkpoint’s config.json (or a file such as ModelOpt’s hf_quant_config.json) names its scheme. Each supported scheme is a QuantizationConfig subclass that declares:

MethodRole
get_name()The scheme’s name, as used by --quantization
get_supported_act_dtypes()Activation types it accepts, such as torch.bfloat16
get_min_capability()Minimum GPU compute capability, e.g. 75 for Turing, 80 for Ampere
get_config_filenames()Files to look for in the model directory
from_config(config)Build the scheme from the checkpoint’s quantization config
get_quant_method(layer, prefix)The implementation for one layer, or None to leave it unquantized

The last method is why mixed-precision models work: different layers can return different methods. It relies on the prefix (the layer’s dotted name) that every vLLM module receives (18.a, 19.g), and on the rule that layers are built quantized from the start, with quantized parameter shapes, rather than converted after loading.

--quantization <name> forces a scheme when detection is ambiguous, and selects the online schemes below. In v0.32.0 the in-tree names include fp8, compressed-tensors (LLM Compressor’s format), modelopt, modelopt_fp4, modelopt_mxfp8, awq, gptq, awq_marlin, gptq_marlin, mxfp4, gpt_oss_mxfp4, quark, torchao, inc, moe_wna16, experts_int8, humming and the online shorthands. @register_quantization_config("name") adds an out-of-tree scheme (19.f).

Formats#

FormatBits (weights / activations)Produced byNotes
FP8 W8A88 / 8LLM Compressor, ModelOptSmall quality loss; native on Ada, Hopper, Blackwell (13.e)
INT8 W8A88 / 8LLM CompressorRuns on older GPUs and on x86 and Arm CPUs
INT4 W4A164 / 16LLM Compressor, GPTQModelThe common “4-bit” format; weights only (13.f)
AWQ, GPTQ4 (typically) / 16LLM Compressor, GPTQModelCalibrated weight-only methods (13.c)
NVFP4, MXFP4, MXFP84 or 8 / variesNVIDIA Model Optimizer, LLM Compressor, AMD QuarkBlock-scaled formats; native on Blackwell (13.g)
bitsandbytes4 or 8 / 16Quantized on the fly, or pre-quantizedNow an out-of-tree plugin, vllm-bnb-plugin
GGUFvariousllama.cpp ecosystemNow an out-of-tree plugin, vllm-gguf-plugin; the docs call it “highly experimental and under-optimized”

LLM Compressor is the vLLM project’s own quantization library and the documentation’s recommended starting point: its outputs (compressed-tensors checkpoints) are the formats vLLM’s fast paths are built for. The older AutoAWQ library is deprecated; its AWQ functionality was adopted into LLM Compressor.

Hardware support is uneven#

From the v0.32.0 documentation’s compatibility table (NVIDIA columns plus AMD and CPUs):

ImplementationVoltaTuringAmpereAdaHopperAMD GPUx86 CPUArm CPU
AWQ❌✅✅✅✅❌✅❌
GPTQ✅✅✅✅✅❌✅❌
Marlin (GPTQ/AWQ/FP8/FP4)❌✅*✅✅✅❌❌❌
LLM Compressor INT8 (W8A8)❌✅✅✅✅❌✅✅
LLM Compressor FP8 (W8A8)❌❌❌✅✅✅❌❌
bitsandbytes✅✅✅✅✅❌❌❌
GGUF✅✅✅✅✅✅❌❌

*Turing does not support Marlin MXFP4. The table also has an Intel GPU column (AWQ and GPTQ supported), and LLM Compressor INT8 W4A8 runs on Arm CPUs only. Blackwell is not a column; the FP4 and MX formats are aimed at it.

Two rows to read carefully:

  • FP8 W8A8 needs Ada or newer. An A100 (Ampere) has no FP8 arithmetic. vLLM still loads an FP8 checkpoint there (the fp8 scheme’s minimum capability is 75), but runs it as weight-only W8A16 through FP8 Marlin: memory is saved, but the matrix multiply happens in 16 bits.
  • Marlin is a kernel family, not a format. A format that runs through Marlin, CUTLASS or another native kernel is fast. One that does not can be slower than the 16-bit model despite being smaller.

That second point is the general warning about quantization in any engine: a smaller file is not automatically faster. Speed comes from a kernel that computes directly on the packed weights. Without one, weights are unpacked to 16 bits on every use, and you have saved memory but not time.

Online quantization#

For a model with no quantized checkpoint, vLLM can quantize while loading:

Shell
vllm serve meta-llama/Llama-3.1-8B --quantization fp8_per_tensor

The documentation describes it: “take a BF16/FP16 model and quantize its Linear and MoE weights to lower precision (such as FP8) at load time, without needing a pre-quantized checkpoint or calibration data. Weights are converted during model loading and activations are dynamically scaled during each forward pass.”

Scheme (v0.32.0)WeightsActivations
fp8_per_tensorFP8, one scale per tensorFP8, per tensor (per token on some GPUs, for speed)
fp8_per_blockFP8, one scale per 128×128 blockFP8, one scale per 1×128 block
fp8_per_channelFP8, one scale per output channelFP8, per token
mxfp8FP8 with a shared exponent per 32 valuesthe same on SM100+; other GPUs fall back to W8A16
mxfp4FP4 with a shared exponent per 32 valuesdepends on the linear backend chosen; some use BF16
int8_per_channel_weight_onlyMoE experts only: INT8, one scale per channel16-bit (weight-only)
nvfp4_per_tokenMoE experts only: NVFP4per-token scales; Blackwell with FlashInfer TensorRT-LLM kernels only

A --quantization-config dictionary refines this. linear and moe choose different schemes for dense layers and MoE experts; ignore skips layers by exact name, re: regex or fnmatch pattern; targets maps layer patterns to schemes one by one (and is exclusive with linear/moe):

Shell
vllm serve Qwen/Qwen3.5-35B-A3B --quantization mxfp4 \
    --quantization-config '{"linear":{"activation":null,"weight":null}}'   # quantize only the experts

The same mechanism can add online quantization to the layers a partly quantized checkpoint left in 16 bits. Online quantization is the quickest way to try a quantized deployment. A calibrated, pre-quantized checkpoint is usually more accurate, and loads faster because nothing is converted at startup.

The KV cache is quantized separately#

--kv-cache-dtype sets the cache format whatever the weights are. fp8 (an alias of fp8_e4m3) halves bytes per token and so doubles the pool (17.h). How the 16-bit values are scaled into 8 bits matters for quality (13.h):

ApproachScalesAccuracy
No calibration (--kv-cache-dtype fp8 on a plain model)All 1.0Works; least accurate
Per-tensor calibrationOne scale each for Q, K and VBetter
Per-attention-head calibrationOne scale per headBest; FlashAttention backend only, calibrated with LLM Compressor

Details that interact with earlier lessons:

  • The attention backend must support it. The cache type is one of the inputs to backend selection (18.c). With FlashAttention 3 and an FP8 cache, attention itself runs in FP8, and the queries are quantized too.
  • Some layers are more sensitive. --kv-cache-dtype-skip-layers leaves chosen layers (by index, or by type such as sliding_window) at the model’s own precision.
  • Some models default to it. DeepSeek-V3.2-style sparse-attention models default to an FP8 cache, and GLM-5.x (GlmMoeDsaForCausalLM) switches auto to FP8 on Blackwell (SM100). For DeepSeek-V3.2, --kv-cache-dtype bfloat16 opts out.
  • Cached blocks are not portable across the setting. A KV cache moved between instances (19.b) must be produced and consumed with the same cache type.

6. Under the hood#

Picking the kernel#

Once a layer knows its scheme, vLLM picks a kernel for it at load time and logs a line of the form Selected <kernel> for <module>. For block-quantized FP8 on CUDA the documentation gives the order it tries: a FlashInfer/DeepGEMM hybrid (Hopper only), DeepGEMM, CUTLASS, Marlin, Triton, Humming, then a PyTorch fallback. You can override the choice:

Shell
vllm serve <model> --linear-backend cutlass                     # every quantized linear layer
vllm serve <model> --moe-backend flashinfer_cutlass             # MoE experts
vllm serve <model> --linear-backend cutlass \
    --kernel-config '{"linear_backend_per_quant":{"nvfp4_w4a16":"humming"}}'   # per scheme

--linear-backend touches only quantized linear layers, not MoE experts. The documentation’s advice for an FP8 server that hangs without an error is VLLM_USE_DEEP_GEMM=0 or --linear-backend cutlass. Optional kernel packages exist for particular GPUs, such as b12x (vllm[b12x]) for SM120/SM121.

More KV cache formats#

Beyond FP8, v0.32.0 accepts a growing list of cache types, each tied to specific attention backends:

--kv-cache-dtypeWhat it is
nvfp4, nvfp4_4over64-bit NVFP4 cache through FlashInfer: on Blackwell SM100 via TensorRT-LLM attention kernels, on SM8x/SM12x via a FlashAttention-2 path. nvfp4_4over6 picks between two scale choices per 16 values to reduce error.
fp8_per_token_head, int8_per_token_head, int4_per_token_headScales computed at runtime per token and head, instead of a fixed calibrated scale
turboquant_k8v4, turboquant_4bit_nc, turboquant_k3v4_nc, turboquant_3bit_ncTurboQuant presets with their own attention backend: keys rotated with a Hadamard transform and quantized to 8, 4 or 3 bits, values to 4 or 3 bits
fp8_ds_mla, nvfp4_ds_mlaLayouts specific to DeepSeek’s latent attention

These change quickly between releases; check vllm serve --help=kv-cache-dtype on your version.

What does not change#

Quantization does not alter the scheduler, the block pool’s logic, or the prefix cache’s behaviour (17.a to 17.f). Hashes are still over token IDs, and blocks still hold a fixed number of tokens. Only the number of blocks and the time per step change. This is why quantization composes freely with every scheduling feature in these vLLM modules.

The serving effect in numbers#

For one GPU and one model, how weight precision and cache precision change capacity and the decode-rate bound:

Go
package main

import "fmt"

const GiB = 1 << 30

func main() {
	const (
		gpuGiB       = 24.0
		util         = 0.92     // --gpu-memory-utilization default
		otherGiB     = 0.8      // activations, CUDA graphs, non-torch memory
		params       = 8.03     // billions of parameters (Llama 3.1 8B)
		kvPerTok16   = 131072.0 // bytes per token at 16 bits: 32 layers × 8 KV heads × 128 × 2 (K,V) × 2 bytes
		avgReqTokens = 3000.0   // prompt + output of a typical request
		bandwidthGBs = 700.0    // GPU memory bandwidth, GB/s (order of magnitude)
	)

	type cfg struct {
		name       string
		weightBits float64
		kvBits     float64
		fastKernel bool // false: weights are unpacked to 16 bits on every use
	}
	cfgs := []cfg{
		{"16-bit weights, 16-bit KV", 16, 16, true},
		{"16-bit weights,  8-bit KV", 16, 8, true},
		{" 8-bit weights, 16-bit KV", 8, 16, true},
		{" 8-bit weights,  8-bit KV", 8, 8, true},
		{" 4-bit weights, 16-bit KV", 4, 16, true},
		{" 4-bit weights,  8-bit KV", 4, 8, true},
		{" 4-bit, no native kernel ", 4, 16, false},
	}

	fmt.Printf("%-28s %9s %9s %12s %12s %14s\n",
		"configuration", "weights", "KV pool", "tokens", "requests", "decode steps/s")
	for _, c := range cfgs {
		weights := params * 1e9 * c.weightBits / 8 / GiB
		kv := gpuGiB*util - weights - otherGiB
		tokens := kv * GiB / (kvPerTok16 * c.kvBits / 16)

		// A decode step must read every weight once: steps/s is bounded by bandwidth.
		readGB := params * c.weightBits / 8
		if !c.fastKernel {
			readGB = params*c.weightBits/8 + params*2 // read packed, then touch the 16-bit copy
		}
		fmt.Printf("%-28s %6.1f GiB %6.1f GiB %12.0f %12.0f %14.0f\n",
			c.name, weights, kv, tokens, tokens/avgReqTokens, bandwidthGBs/readGB)
	}
}

Output:

configuration                  weights   KV pool       tokens     requests decode steps/s
16-bit weights, 16-bit KV      15.0 GiB    6.3 GiB        51798           17             44
16-bit weights,  8-bit KV      15.0 GiB    6.3 GiB       103595           35             44
 8-bit weights, 16-bit KV       7.5 GiB   13.8 GiB       113062           38             87
 8-bit weights,  8-bit KV       7.5 GiB   13.8 GiB       226123           75             87
 4-bit weights, 16-bit KV       3.7 GiB   17.5 GiB       143694           48            174
 4-bit weights,  8-bit KV       3.7 GiB   17.5 GiB       287387           96            174
 4-bit, no native kernel        3.7 GiB   17.5 GiB       143694           48             35

Three things to take from the table. Moving from 16-bit to 4-bit weights with a native kernel roughly quadruples the decode-rate bound and nearly triples concurrent requests. Quantizing only the cache doubles concurrency without touching the weights. And the last row, 4-bit weights without a kernel that computes on them, has all the memory benefit and is slower than the 16-bit model. (The bound ignores the KV cache reads each step also makes; with long contexts those grow, which is where an 8-bit cache helps speed as well as capacity.)


7. Performance implications#

  • Weight-only schemes help decode, not prefill. Decode is bandwidth-bound, so fewer weight bytes help. Prefill is compute-bound (2.e), and W4A16 still multiplies in 16 bits; W8A8 FP8 or INT8, or FP4 on Blackwell, also speeds up prefill.
  • The kernel decides. Read the Selected <kernel> for <module> lines at startup. A fallback to a PyTorch or emulation path explains most “quantized but slow” reports.
  • An 8-bit cache also cuts attention reads, which dominate decode at long contexts.
  • Online quantization costs startup time, since every weight is converted while loading.

8. Production implications#

SituationReasonable choice
Hopper/Ada or newer, quality-sensitiveFP8 W8A8 from LLM Compressor or ModelOpt
Blackwell, maximum throughputNVFP4 (or MXFP4) checkpoints, after measuring quality
Ampere (A100, A10G)INT4 W4A16 or AWQ/GPTQ through Marlin; or INT8 W8A8. FP8 checkpoints run, but only as W8A16
Model does not fit at all4-bit weights, then measure quality on your own task
Model fits, the cache is the constraintKeep the weights; --kv-cache-dtype fp8
No quantized checkpoint, want to tryOnline fp8_per_tensor or fp8_per_block
CPU servingINT8 W8A8
A bitsandbytes or GGUF modelInstall the matching plugin first; prefer a native format for production

Always evaluate on your own workload. Aggregate benchmark scores hide task-specific losses, and 4-bit models in particular degrade unevenly: fluent prose survives, exact arithmetic and long structured outputs suffer first. Pin the cache type on both sides of a disaggregated deployment, and record the --linear-backend you validated so an upgrade that changes the automatic choice shows up as a change you can test.


9. Common mistakes#

  1. Assuming smaller means faster. Without a native kernel, a 4-bit model can be slower than the 16-bit one.
  2. Expecting FP8 speed on an A100. It loads, but runs as weight-only W8A16 through Marlin.
  3. Measuring only one request. The concurrency gain from a bigger KV pool is invisible then.
  4. Using an uncalibrated FP8 cache on a sensitive task without checking quality; calibrated scales or --kv-cache-dtype-skip-layers are the fixes.
  5. Mixing cache types across a prefill/decode pair in a disaggregated deployment.
  6. Looking for bitsandbytes or GGUF in a plain vLLM install. Both moved to plugins.

10. Hands-on exercise#

  1. Change the GPU to 80 GiB and the model to 70 billion parameters (and kvPerTok16 to 327,680 bytes: 80 layers instead of 32). Which configurations fit on one GPU at all?
  2. With avgReqTokens at 30,000 (long documents), which matters more for concurrency: weight precision or cache precision?
  3. On a real server, compare the Available KV cache memory log line and tokens per second for the same model at 16 bits and with --quantization fp8_per_tensor. Find the Selected <kernel> lines.
  4. On an Ampere GPU, load an FP8 checkpoint and confirm from the log that a Marlin kernel was selected. Then compare its throughput with an INT4 W4A16 checkpoint of the same model.

11. Interview questions#

  1. Why does quantizing weights increase the number of requests a server can hold, by more than the ratio of bits?
  2. An INT4 model is smaller but slower than the 16-bit original on your GPU. What is the likely reason, and how would you confirm it from the logs?
  3. What happens when you serve an FP8 W8A8 checkpoint on an A100?
  4. What does --kv-cache-dtype fp8 change, and what does it leave unchanged?
  5. Why can different layers of one model use different quantization schemes in vLLM?
  6. When would you choose online quantization over a pre-quantized checkpoint?

12. Further reading#

Checked on 13 November 2026 against vLLM v0.32.0.

↑↓ navigate↵ openesc close

100% drag to pan · scroll or pinch to zoom · double-click to zoom in