Integer-only inference

Also known as: integer arithmetic inference

On this page 7

Integer-only inference, also called integer arithmetic inference, is the execution of a quantized neural network in which every operation uses integer arithmetic, including matrix multiplication, bias addition, activation functions and the rescaling between layers. In Edge AI, it is the strictest form of quantized deployment: no floating-point value is computed at run time, so the model can run on microcontrollers, DSPs and neural processing units that lack or avoid floating-point hardware.

The technique differs from ordinary quantization, where integer weights are often converted back to floating point for some steps. Integer-only pipelines replace those steps with fixed-point multipliers, bit shifts and lookup tables, which yields predictable latency, lower energy use and bit-exact results across devices, a property valued in artificial intelligence products that ship to millions of phones and sensors.

How integer-only inference represents real numbers

Integer-only inference relies on affine quantization, which maps a real value r to an integer q through the relation r = S(q – Z). The scale S is a positive real constant and the zero point Z is an integer that represents real zero exactly. Weights and activations are typically stored as 8-bit integers, while products are summed in 32-bit accumulators to avoid overflow.

The key trick concerns rescaling. After a layer multiplies integer inputs by integer weights, the result must be converted to the scale of the next layer. The combined factor M, equal to the input scale times the weight scale divided by the output scale, is a real number, but it is computed offline and stored as a normalized 32-bit integer multiplier with a right shift. At run time, the device performs one integer multiplication, a rounding shift and a clamp, so no floating-point operation is needed.

The data types used at each stage of a typical integer-only layer are shown below.

ElementTypical typePurpose
Weightsint8, symmetric, per-channelCompact storage and fast multiply
Activationsint8 or uint8, asymmetricCover skewed ranges such as ReLU outputs
Biasint32 at input scale times weight scaleAdded directly to the accumulator
Accumulatorint32Holds sums of many 8-bit products safely
Requantization multiplierint32 multiplier plus shiftRescales results without floating point
Data types in a typical integer-only layer

Handling nonlinear operations with integers

Linear layers convert to integers naturally, but nonlinear functions are the hard part. Convolutional networks mostly use ReLU or ReLU6, which reduce to simple clamping of integer values. Transformers, by contrast, depend on softmax, GELU and layer normalization, which involve exponentials, error functions and square roots.

Research such as I-BERT showed that these operations can be replaced with low-order polynomial approximations and an integer square root routine with small accuracy loss. Other systems use lookup tables indexed by the 8-bit input, which are exact for the quantized domain and very fast on microcontrollers.

OperationInteger strategyAccuracy impact
ReLU and ReLU6Clamp to the quantized rangeNone beyond quantization error
Sigmoid and tanhLookup table or piecewise approximationVery small
SoftmaxPolynomial exponent with integer normalizationSmall, depends on bit width
GELUSecond-order polynomial approximationSmall after calibration
Layer normalizationInteger mean, variance and square rootSmall, sensitive to outliers
Residual additionRescale both inputs to a common scaleMinor rounding error
Integer strategies for common operations

Integer-only inference compared with other quantization modes

Not every quantized model is integer-only. Many deployments keep floating-point steps for convenience or accuracy, and the distinction determines which hardware can run the model. The comparison below clarifies the most common modes in edge deployment.

ModeWeightsActivationsFloating point at run time
Integer-only inferenceint8int8None
Static quantization with float fallbackint8int8Some unsupported operators
Dynamic quantizationint8Quantized on the flyScale computation per input
Weight-only quantizationint4 or int8fp16 or fp32All compute after dequantization
Mixed-precision quantizationVaries per layerVaries per layerDepends on layer choices
Quantization modes and their run-time arithmetic

Integer-only models are usually produced by post-training static quantization with a calibration dataset or by quantization-aware training, which simulates integer rounding during training with fake quantization nodes and the straight-through estimator.

Hardware targets and practical benefits

The strongest case for integer-only inference is hardware that cannot run floating point efficiently. Many low-cost microcontrollers have no floating-point unit, and several accelerators execute only integer tensors, rejecting any model that contains float operators.

  • Microcontrollers: TinyML runtimes with CMSIS-NN style kernels execute int8 layers within a few hundred kilobytes of memory.
  • Neural processing units: phone and PC NPUs reach their highest throughput with int8 tensors.
  • Fixed-function accelerators: some edge TPUs require fully integer models to delegate the whole graph.
  • DSPs: vector integer instructions process many 8-bit values per cycle.

Typical gains include about a fourfold reduction in model size compared with fp32, lower memory bandwidth and, on suitable hardware, two to four times faster inference with proportionally lower energy. The exact speedup depends on kernel quality and memory layout, so it must be measured on the target device.

Limitations and common mistakes

Integer-only deployment introduces accuracy and engineering risks that floating-point inference does not have. Compact architectures with depthwise convolutions and models with large activation outliers, such as language models, are especially sensitive to 8-bit rounding.

SymptomLikely causeFix
Large accuracy dropPer-tensor weight scalesUse per-channel weight quantization
Saturated activationsUnrepresentative calibration dataCalibrate on realistic inputs
Model fails to delegateUnsupported float operator remainsReplace or approximate that operator
Mismatch with reference outputDifferent rounding modesMatch the runtime rounding specification
Outlier-driven errorsExtreme activation channelsApply outlier smoothing or quantization-aware training
Frequent problems and their fixes

A common misconception is that integer-only inference always loses accuracy. With careful calibration or quantization-aware training, convolutional vision models often stay within about one percentage point of their floating-point baseline.

The idea in brief

Computers handle whole numbers more cheaply than numbers with decimals. Integer-only inference rewrites an AI model so it uses only whole numbers while it works. Every step, even the tricky ones, becomes simple integer math.

This lets the model run on tiny, inexpensive chips. Think of a cashier who rounds prices to whole cents and keeps a small rule card for conversions. The answers stay almost the same, but the work is faster and uses less power.

A practical scenario

A manufacturer of battery-powered smart doorbells wants on-device person detection on a microcontroller with 512 KB of RAM and no floating-point unit. The floating-point model is too large and too slow for the chip. Engineers train a small convolutional network with quantization-aware training, then convert it to a fully int8 model with per-channel weights and int32 biases.

Every layer, including the final sigmoid, now runs as integer kernels, with the sigmoid implemented as a 256-entry lookup table. The model shrinks from about 1.2 MB to roughly 300 KB, inference takes around 120 milliseconds per frame, and detection accuracy falls by less than one percentage point. Because the camera only wakes the radio when a person is detected, battery life improves by several months compared with streaming video to the cloud.