What is quantization and how does it work?
Quantization maps values onto a limited set of representations. In simple affine integer quantization, q is obtained by rounding x/s, adding a zero point z and clipping the result to the format range. Reconstruct the approximate value as s·(q − z). The scale s must be positive; a zero tensor requires a valid fallback scale rather than division by zero. [12]
For symmetric INT8 with range −127…127 and scale 0.01, 0.126 maps to 13 and reconstructs to 0.13, an error of 0.004. This is illustrative, not a model measurement. Signed INT8 normally ranges from −128 to 127; some symmetric schemes deliberately omit −128. Scales may be shared across a tensor, channel or group. Finer granularity limits outlier effects at the cost of more metadata. [1][2][12]
In affine integer quantization the zero point is the integer representing real zero. Rounding is implementation-dependent: ONNX QuantizeLinear rounds to nearest, ties to even. Without saturation, the rounding error in ideal arithmetic is at most s/2. Clipping invalidates that bound: with scale 0.01, 2.0 clips to 127 and reconstructs to 1.27 (error 0.73). A larger scale increases range but reduces integer quantization resolution. Symmetric signed schemes typically use z=0; affine schemes can accommodate asymmetric distributions. [12][18]
INT8, INT4 and FP8: format differences
| Format | Bits | Representation |
|---|---|---|
| INT8 | 8 | Signed integers (−128…127) |
| INT4 | 4 | Signed integers (−8…7) |
| FP8 | 8 | Floating point (E4M3FN / E5M2) |
| FP16 / BF16 | 16 | Floating point |
INT8 and INT4 encode integers; signed INT4 ranges from −8 to 7. Four-bit quantization is not necessarily INT4: NF4 uses a nonlinear codebook. FP8 has exponent and fraction fields. Common E4M3FN and E5M2 formats have maximum finite magnitudes of 448 and 57,344 respectively; E5M2 trades fraction precision for range. Other FP8 variants such as FNUZ can use different ranges and encodings. [2][3][4][14]
W4A16 denotes four-bit weights and 16-bit activations; W8A8 uses eight bits for both. The notation does not identify numeric types, scales, accumulator precision or compute paths. A kernel may dequantize weights to BF16 or FP16. FP8 also requires appropriate scaling; it is not simply another name for INT8. [2][3]
E4M3FN and E5M2 divide their eight bits into sign, exponent and fraction fields of 1/4/3 and 1/5/2 respectively. BF16 and FP16 both occupy 16 bits but differ in range and precision. FP8 training may use low precision only for selected matrix multiplications; gradients, updated parameters and optimizer states may retain higher precision. [2][14][16][17]
PTQ, QAT and language model quantization methods
Post-training quantization (PTQ) converts an already trained model without full retraining. Quantization-aware training (QAT) accounts for reduced-precision effects during training. Static scales can be estimated on calibration data; dynamic scales are calculated at runtime for selected tensors. Calibration is not final evaluation: use representative data without consuming the independent evaluation set. [13] Typical QAT simulates rounding and reconstruction during training (fake quantization), then stores the target representation on conversion. [13]
GPTQ uses approximate second-order information for weight quantization; AWQ uses activation-derived weight importance. SmoothQuant shifts part of the activation quantization difficulty to weights, enabling W8A8. LLM.int8() handles outliers at higher precision. These methods have different requirements and are not interchangeable. QLoRA freezes a quantized base model and trains LoRA adapters rather than fully training INT4 weights. [4][5][6][7][11]
How much memory do weights and KV cache require?
| Format | Size in GB | Size in GiB | Fraction of FP16 size |
|---|---|---|---|
| FP16 / BF16 | 16 | 14.90 | 100% |
| INT8 / FP8 | 8 | 7.45 | 50% |
| INT4 | 4 | 3.73 | 25% |
For N parameters and b bits, ideal raw weight storage is N·b/8 bytes. The table assumes eight billion parameters at uniform precision, excluding scales, zero points, alignment and other metadata. With groups of 128 INT4 weights and one 16-bit scale per group, the overhead is 0.125 bits per parameter: 4.125 GB total for eight billion weights, before other costs. GB = 10⁹ B; GiB = 2³⁰ B.
The KV cache stores attention keys and values. For ordinary full attention with uniform layers, one sequence requires approximately 2·L·Hkv·D·T·p bytes, where L is the layer count, Hkv the KV head count, D the head dimension, T cached tokens and p bytes per element. With 32 layers, 8 KV heads, D=128 and 8192 tokens, BF16 needs 1 GiB and FP8 0.5 GiB, excluding scales and allocation overhead. Sixteen independent BF16 sequences need 16 GiB. GQA, sliding windows, shared prefixes, sharding and other architectures change the actual figure. Add activations, buffers, runtime overhead and headroom. [8]
For mixed precision, sum individual tensor sizes: 90% INT4 and 10% BF16 parameters average 5.2 bits per parameter, or 5.2 GB for 8 billion parameters before metadata. MXFP8 stores one 8-bit E8M0 scale per 32 FP8 values, ideally 8.25 bits per value before padding and extra copies. For mixture-of-experts (MoE) models, storage for all experts depends on total parameters, not just those activated per token. Expert placement and RAM offloading change per-GPU memory requirements. [15][19]
Practical budget: the earlier grouped INT4 8B model needs about 3.84 GiB for weights and scales. Four independent 8192-token sequences add 4 GiB of BF16 cache or 2 GiB of FP8 cache. Totals are about 7.84 and 5.84 GiB before other costs; neither calculation guarantees operation on an 8 GiB GPU. If 8192 counts input tokens alone, budget for generated tokens too. In GQA the KV head count can be smaller than the query head count; use the actual KV head count in the formula. In vLLM FP8 cache scales can be calibrated, and per-head scaling availability depends on the attention backend. [8]
Does lower precision accelerate inference?
Prefill and autoregressive decoding stress hardware differently. At low concurrency, decoding is often limited by memory bandwidth; smaller weights can help. Large batches and long inputs can make compute throughput more important. Dequantization, scaling and conversion can offset savings. Without optimized kernels, a lower-precision model may run more slowly. [1][3]
Measure time to first token (TTFT), inter-token latency (ITL), output token throughput, end-to-end latency, p95 and peak memory. Keep the model, hardware, input and output lengths, load and generation settings equivalent. Report warm-up and prefix-cache behavior. Separate cold-start from steady-state measurements and compare cost per accepted result. Do not derive speedup from bit width alone. [9]
Choosing a runtime and file format
Transformers supports several methods, including bitsandbytes and prequantized GPTQ/AWQ checkpoints. GGUF is a model container format, not one quantization algorithm; different Q4 variants can have different effective bit widths and retain certain tensors at higher precision. Check architecture, file type and method compatibility with the specific runtime version. [1][4][10]
vLLM documents method and hardware compatibility. FP8 storage support does not guarantee native FP8 computation for every operation. NVIDIA Transformer Engine documents FP8 scaling and block formats including MXFP8; newer formats such as FP4 are not INT4. Before purchasing hardware or deploying, check driver and library versions, GPU/CPU model and actual selected kernels. A QLoRA adapter requires a compatible base model. [2][3][7][15][16]
One concrete limitation: TensorRT supports INT4 for weights, not activations. The Transformer Engine 2.21 matrix lists per-tensor FP8 from compute capability 8.9 (with additional library requirements on Ada); its MXFP8 support covers Blackwell compute capability 10.x, but not 12.x. These are library-specific support statements, not a universal GPU capability chart. Check for slower fallback paths and extra weight copies. [3][16][18]
Evaluating a quantized model
Compare the reference and quantized variants on an independent dataset covering classification, factual answers, code, long contexts, languages and product-specific safety cases. Perplexity measures token prediction on a fixed dataset and tokenization but does not replace task evaluation. Generation variability calls for repeated, paired comparisons and reporting dispersion. Check critical slices, tool calls and response schemas independently. [20][21][22]
Set acceptable quality loss, memory and p95 limits, and release-blocking conditions before testing. In a hypothetical example, success falling from 90% to 88% is a two-percentage-point change, not automatically acceptable. Sample size and uncertainty are necessary to judge significance. Record model and tokenizer versions, calibration, configuration and results. Gradual rollout and rollback reduce the consequences of regressions. [9]
An ACL study compared W8A8-FP, W8A8-INT and W4A16-INT on the Llama 3.1 family; quality and cost-efficiency varied with configuration and serving scenario. A newer Artificial Intelligence Review study covers several model families and device classes, highlighting configuration tuning and runtime support. Do not extrapolate these experiments to other models and hardware. Perplexity is exp(mean negative log-likelihood of tokens); hold the tokenizer, data and context segmentation fixed. Report generation failures and rejected requests, not only the speed of successful responses. [20][21][22]
When to choose INT8, INT4 or FP8
When memory is the main constraint, test INT4 weight-only quantization against INT8 and BF16. When throughput on compatible hardware is the priority, test W8A8 INT8 or FP8. If long contexts and concurrency are the issue, consider KV cache separately. Cache quantization requires its own quality evaluation, especially for long contexts. [2][8]
Quantization does not replace fine-tuning, RAG or authorization. It does not guarantee preservation of every model capability or automatically lower external API prices. For self-hosting, include hardware, energy, operations, incorrect outputs and retries in the cost. Choose the configuration that meets product requirements, not the smallest file.
A practical workflow is to preserve the original checkpoint, choose a method and calibration set, save the configuration, check runtime compatibility, then run independent quality and performance tests. For local deployment, account for memory during loading and conversion, not just steady state.
