Quantization

Quantization · node type · QuantizeLinear, DequantizeLinear, DynamicQuantizeLinear

Stores numbers as 8-bit integers with a scale, cutting model size by about four times.

Also called QuantizeLinear, DequantizeLinear, Int8, Dynamic quantization

Figure 1. Quantization inside Read text in an image, a real model in WeightSpace. The 14 outlined nodes are Quantization; select any node for its shapes and parameters.

What it does

Quantization maps floating-point values onto a small integer grid: divide by a scale, round, add a zero point, and clamp to the integer range. Dequantization does the reverse. Storing weights as int8 shrinks a model to roughly a quarter of its float32 size and lets integer kernels run faster, at the cost of a small rounding error. Dynamic quantization computes the activation scale on the fly for each input. In an exported graph it shows up as QuantizeLinear and DequantizeLinear pairs, or as integer operators such as MatMulInteger and ConvInteger with their scales nearby.

Formula

q = clamp(round(x / s) + z, qmin, qmax)x̂ = s · (q − z)

Shapes and parameters

Shapes
Any shape in, the same shape out; the scale and zero point are scalars or one value per channel.
Parameters
None learned, but every quantized tensor carries its scale and zero point (one per tensor, or one per output channel).
Used for
The int8 BERT models in the catalog (Chinese fill-mask, zero-shot labels), punctuation restoration, CRNN text recognition, and most models shipped to phones.

Figure 2. The typed ports of Quantization, in the same format as every model drawing. Letters such as N or C stand for any size.

In WeightSpace

Read-only in WeightSpace today. When an editable bias is stored as a quantized integer, WeightSpace converts your offset with the stored scale so edits are still entered in logit units.