What is dynamic quantisation?
Dynamic quantisation is a post-training quantisation method converting a model's weights to low-bit integers in advance while computing activation ranges at runtime for each input instead of fixing them beforehand.
Unlike static quantisation, where activation ranges are measured once with a calibration dataset and fixed, dynamic quantisation recomputes them per input. It needs no calibration set and copes better with distribution changes, at the cost of runtime work.
- Topic
- Machine learning, models and training
- Also known as
- Dynamic quantization
How dynamic quantisation works
- Weights are quantised once during conversion and stored that way.
- At inference, each layer's input minimum and maximum or a similar statistic is measured on the spot, often per token in large language models.
- A scale is computed from this range, activations become integers and integer matrix multiplication runs.
- The result is converted back to floating point; scale computation repeats every step.
In more detail
Quantisation granularity and activation outliers
Granularity determines accuracy: per-tensor dynamic scaling computes one scale for the entire activation tensor, whereas per-token or per-group scaling computes a separate scale for each row or block. In Transformers, where isolated activation channels carry extreme outlier magnitudes, per-token dynamic scaling or pre-smoothing (such as SmoothQuant) is often needed to prevent sharp accuracy drops.
Commonly confused terms
| Term | How it differs |
|---|---|
| Weight-only quantisation | Weight-only quantisation (such as W4A16 GPTQ or AWQ) compresses weights to 4 or 8 bits and dequantises them back to FP16 or BF16 during matrix multiplication without ever quantising activations; dynamic quantisation actively quantises activations at runtime to run integer or FP8 GEMMs. |
| Quantisation-aware training | Quantisation-aware training (QAT) simulates quantisation rounding error during model training or fine-tuning so weights adapt; dynamic quantisation is a post-training quantisation (PTQ) technique applied without retraining. |
Why dynamic quantisation matters for on-premises AI
Needing no calibration data, dynamic quantisation is among the easiest quantisation routes and reduces errors fixed ranges cause in models with highly variable inputs. A technical guide to quantisation notes post-training quantisation needs no retraining or labelled data and usually gives 8-bit accuracy close to floating point. A study proposing integer-arithmetic inference aims to improve latency on hardware with integer units such as CPUs; INT8 and FP8 units on current GPUs have also made dynamic quantisation common in LLM inference.
To run its document classifier on CPU servers without GPUs, a public body converts it to dynamic 8-bit quantisation; it gains speed without preparing calibration data and compares accuracy with the original on the same test documents.
Common questions
How do dynamic and static quantisation differ?
In static quantisation activation ranges are fixed beforehand by calibration. In dynamic quantisation they are computed at runtime per input.
When is dynamic quantisation preferred?
When no calibration data exists, inputs vary widely or a quick, easy CPU solution is needed.
Related terms
- Quantisation
- Static quantisation
- Activation quantisation
- Calibration dataset
- Post-training quantisation
- 8-bit integer
Sources
- Nagel et al., A White Paper on Neural Network Quantization, 2021
- Jacob et al., Quantization and Training of Neural Networks for Efficient Integer-Arithmetic-Only Inference, 2018
In the glossary: Glossary, A to D