Static quantization

Also known as: static post-training quantization

On this page 7

Static quantization is a post-training technique that converts both the weights and the activations of a neural network from floating point to low-precision integers, typically 8-bit, using scale factors and zero points that are fixed before deployment from a small calibration dataset. In edge AI, it is the standard route to integer-only inference on phones, microcontrollers and neural processing units, where floating-point arithmetic is slow, power-hungry or unavailable.

The word static refers to the activation ranges. Unlike dynamic quantization, which measures activation ranges at run time for every input, static quantization precomputes those ranges once, so the deployed model performs no range estimation and can run entirely in integer arithmetic. The method is also called static post-training quantization.

How static quantization maps values to integers

Static quantization uses an affine mapping between real values and integers: a real value equals the scale multiplied by the difference between the integer and the zero point. The scale sets the step size between representable values, and the zero point is the integer that represents real zero exactly, which matters for padding and ReLU outputs.

The workflow has four steps. The tool first inserts observers at every tensor to be quantized, then runs a few hundred representative inputs through the floating-point model while observers record activation statistics. Next, it computes scales and zero points from those statistics, and finally it converts the graph so that operators consume and produce integer tensors, with weights stored as int8 and biases usually as int32.

The table below lists the parameters that define a statically quantized tensor.

ParameterTypical valueWhat it controls
Bit width8 bits; 4 bits for weights in some runtimesNumber of representable levels
ScalePositive floating-point constantStep size between integer levels
Zero pointInteger within the quantized rangeExact representation of real zero
GranularityPer-tensor activations, per-channel weightsHow many scales a tensor uses
SymmetrySymmetric weights, asymmetric activationsWhether the zero point is fixed at zero
Core parameters of a statically quantized tensor

Calibration: choosing activation ranges

Calibration determines which range of activation values each integer grid covers, and it is the step where most accuracy is won or lost. A range that is too wide wastes integer levels on rare outliers and coarsens the common values, while a range that is too narrow clips large activations. Calibration data should match the deployment distribution; 100 to 1,000 samples are usually sufficient for vision models.

The following table compares the common range-selection methods used in quantization toolkits.

MethodHow the range is chosenTrade-off
Min-maxObserved minimum and maximumSimple, but sensitive to outliers
Moving average min-maxSmoothed extremes across batchesMore stable, still outlier-prone
PercentileClips at, for example, the 99.99th percentileRobust; percentile needs tuning
Entropy (KL divergence)Minimizes information loss of the histogramGood for CNNs; slower to compute
MSE minimizationMinimizes squared quantization errorAccurate; more computation per tensor
Calibration methods for activation ranges

Static quantization compared with other approaches

Static quantization sits between the cheapest and the most accurate options. Dynamic quantization quantizes weights ahead of time but computes activation scales per input, which suits LSTMs and transformer linear layers on CPUs but leaves overhead in every call. Quantization-aware training simulates quantization during training with fake quantization nodes and the straight-through estimator, recovering accuracy that static post-training quantization loses, at the cost of a training pipeline.

ApproachActivation rangesRetraining neededTypical use
Static quantizationFixed from calibrationNoCNNs on NPUs, DSPs and MCUs
Dynamic quantizationComputed at run timeNoRNNs and transformers on CPU
Weight-only quantizationKept in floating pointNoLarge language models on GPUs
Quantization-aware trainingLearned during trainingYesAccuracy-critical compact models
Static quantization and related methods

For large language models, static activation quantization is harder because activations contain extreme outlier channels. Methods such as SmoothQuant shift difficulty from activations to weights so that W8A8 static schemes remain accurate, while many local LLM deployments use weight-only formats instead.

Benefits and costs on edge hardware

The benefits are substantial. Moving from 32-bit floats to 8-bit integers cuts model size by about four times, reduces memory bandwidth by the same factor and enables integer matrix units. On CPUs and mobile accelerators, speedups of two to four times are common, and integer operations consume markedly less energy per operation than floating-point ones.

Accuracy cost depends on the architecture. Well-behaved convolutional networks such as ResNet typically lose less than one percentage point of top-1 accuracy with per-channel weights and good calibration, whereas compact models such as MobileNet with depthwise convolutions can lose several points without careful handling.

  • Fuse operators first: folding batch normalization into convolutions and fusing convolution with ReLU avoids needless requantization steps.
  • Use per-channel weight scales for convolutions and linear layers, which most edge runtimes support.
  • Keep sensitive layers in floating point, such as the first convolution or the final classifier, when the target runtime allows mixed precision.
  • Verify operator coverage on the target delegate, because unsupported operators fall back to the CPU and erase speed gains.

Common failure modes and how to fix them

Most problems with static quantization trace back to unrepresentative calibration data or to layers with unusual value distributions. The table below links symptoms to causes and remedies.

SymptomLikely causeRemedy
Large accuracy drop overallCalibration data unlike real inputsCalibrate on deployment-like samples
One layer dominates errorOutliers in that layer’s activationsPercentile clipping or keep layer in float
No speedup on deviceUnsupported operators fall back to CPUReplace or fuse unsupported operators
Accuracy loss after conversion onlyBatch normalization not foldedFuse modules before calibration
Troubleshooting static quantization

When post-training methods cannot meet the accuracy target, the usual escalation path is quantization-aware fine-tuning for a few epochs, starting from the statically quantized configuration.

Stripped to the essentials

An AI model normally stores its numbers with many decimal places. Small devices handle such numbers slowly. Static quantization rounds them to simple whole numbers so the device can work faster and use less battery.

To round well, the system first watches the model on a few sample inputs. It learns the usual range of values and fixes the rounding rules in advance. After that, the device just follows those rules. The model becomes about four times smaller and usually stays almost as accurate.

Where it is applied

A manufacturer of battery-powered security cameras wants person detection to run on the camera itself instead of in the cloud. The floating-point detection model is 24 MB and runs too slowly on the camera’s low-power chip, which includes a small int8 neural accelerator.

The engineering team fuses batch normalization into the convolutions, calibrates with 500 frames recorded by real cameras at day and night, and applies static quantization with per-channel weight scales. The resulting model is about 6 MB, runs entirely on the accelerator and processes frames roughly three times faster. Detection accuracy on the validation set drops by less than one percentage point, and battery life improves enough to extend the time between charges noticeably.