Activation quantization

On this page 7

Activation quantization is the conversion of the intermediate values that flow between neural network layers from floating-point formats such as FP32 or FP16 into low-precision formats such as INT8, FP8 or INT4, using a scale factor and often a zero point. In Edge AI, it is the step that allows a model to run on integer-only accelerators, because both operands of each matrix multiplication can then be processed by fast, energy-efficient integer units.

It is usually paired with weight quantization, and the combination is written in the form W8A8 or W4A8, where the number after A gives the activation bit width. Activation quantization is generally harder than weight quantization, because activations change with every input and cannot be inspected fully in advance.

How activation quantization maps values to integers

Each activation tensor is mapped with the affine rule q = round(x / s) + z, where s is the scale and z is the zero point. Values outside the representable range are clipped. The quality of the result depends almost entirely on choosing a range that covers the important values without wasting resolution on rare extremes.

Weights are fixed after training, so their ranges can be measured exactly. Activations, by contrast, are input-dependent: an image of a dark room produces different feature magnitudes from an image of a sunny beach. This is why activation ranges are either estimated from calibration data or computed at run time for every input.

The following table compares common activation formats on edge hardware.

FormatBitsTypical hardware supportAccuracy risk
FP16 or BF1616Mobile GPUs, most NPUsNegligible
FP88Recent data center and some edge chipsLow for most models
INT88Nearly all NPUs, DSPs and microcontrollersLow with good calibration
INT44Limited, mostly research or new NPUsHigh without special methods
Activation precision formats and their typical use

Static and dynamic ranges

There are two ways to obtain activation ranges, and the choice drives both latency and accuracy. In static quantization, ranges are fixed before deployment by running a few hundred representative samples through the model, a process called quantization calibration. In dynamic quantization, the range is measured for each input during inference.

PropertyStatic rangesDynamic ranges
When ranges are setOffline, from calibration dataAt run time, per input or token
Run-time overheadNoneExtra min and max reduction
Robustness to unusual inputsLower, values may clipHigher, range adapts
Integer-only pipelinesFully supportedOften unsupported on NPUs
Typical useVision and audio models on NPUsLanguage models on CPUs
Static versus dynamic activation quantization

Calibration methods differ in how they pick the range from observed data. Min-max calibration keeps every observed value but is sensitive to outliers, while percentile and entropy-based methods deliberately clip rare extremes to give more resolution to typical values. The best choice is model-specific and should be evaluated on held-out data.

Granularity and symmetry choices

Activation scales can be shared at different granularities. Per-tensor scales are cheapest and best supported by hardware, whereas per-token scales in transformers adapt to each position at the cost of more bookkeeping. Per-channel scaling, common for weights, is rarely applied to activations because it breaks the efficient factorization of integer matrix multiplication.

Symmetry matters as well. Outputs of ReLU are never negative, so asymmetric or unsigned quantization uses all 256 INT8 levels, while symmetric quantization would waste half of them. Activations from GELU, SiLU or normalization layers span both signs and often suit symmetric quantization better.

SituationRecommended settingReason
CNN on a mobile NPUStatic per-tensor INT8Widest hardware support
ReLU outputsAsymmetric or unsigned INT8Uses the full integer range
LLM on a laptop CPUDynamic per-token INT8Handles varying token magnitudes
Accuracy loss above budgetKeep sensitive layers in FP16Mixed precision isolates errors
Choosing activation quantization settings

The outlier problem in large models

Large transformers show systematic activation outliers: a small number of hidden channels carry values one to two orders of magnitude larger than the rest. A single range must cover these extremes, so ordinary values collapse into a few integer levels and accuracy can drop sharply at INT8, especially in models above several billion parameters.

Several methods address this. SmoothQuant divides outlier channels in the activations by a per-channel factor and multiplies the matching weights by the same factor, which migrates the difficulty from activations to weights. Other approaches apply rotations that spread outliers evenly or keep outlier channels in higher precision. Because of this problem, many edge deployments of language models use weight-only quantization and leave activations in FP16.

Limitations and common mistakes

Activation quantization delivers its benefit only when the whole operator chain stays in integers. If the runtime must dequantize and requantize between unsupported operators, the conversion overhead can erase the speed gain.

  • Unrepresentative calibration data, such as daylight images for a night camera, causes systematic clipping.
  • Quantizing sensitive layers, such as the first and last layers or attention softmax, often costs disproportionate accuracy.
  • Ignoring residual connections leads to mismatched scales when two branches are added.
  • Measuring only average accuracy hides failures on rare but important inputs.

When post-training methods are insufficient, quantization-aware training simulates activation rounding with fake quantization during fine-tuning, letting the model adapt its ranges before deployment.

Explained without jargon

A neural network passes numbers between layers, from one layer to the next, like a relay team passing a baton. Normally these numbers are very precise. Precise numbers take more space and more work to handle.

Activation quantization rounds the passed numbers to a short, simple form. It is like writing prices in whole euros instead of exact cents. Small chips in phones and cameras can work much faster with simple numbers.

The risk is that rounding loses detail. Engineers therefore test carefully on real examples to make sure the answers stay correct.

A typical use case

A company builds a battery-powered doorbell camera that detects people and parcels. Its object detection model runs in FP32 at about 20 milliseconds per frame on a test board, but the target chip has an INT8 neural accelerator and only a slow floating-point path.

The engineers apply static INT8 activation quantization together with INT8 weights. They calibrate ranges on 500 frames recorded at the door, covering daylight, dusk, rain and porch lighting, and keep the final detection head in FP16 after tests show it is the most sensitive layer.

On the device, inference drops to a few milliseconds per frame, and energy per detection falls enough to extend battery life by weeks. Detection accuracy on their validation set stays within about one percentage point of the floating-point model, which the product team accepts as an acceptable trade-off.