Inferensys

Glossary

Quantization Scale and Zero-Point

Quantization scale and zero-point are the two parameters that define an affine transformation mapping floating-point values to a quantized integer range, enabling efficient low-precision neural network inference.
Developer testing AI inference on mobile phone in hand, laptop with optimization code visible, casual tech review moment.
NEURAL NETWORK QUANTIZATION

What is Quantization Scale and Zero-Point?

The core parameters that define the affine transformation for converting floating-point values to integers.

Quantization scale and zero-point are the two parameters that define an affine transformation for mapping a range of floating-point values to a range of integers. The scale (a floating-point number) determines the step size between quantized levels, while the zero-point (an integer) represents the quantized value that corresponds to the real number zero, enabling the accurate representation of both positive and negative values. Together, they implement the formula: real_value = scale * (quantized_value - zero_point).

The choice of these parameters determines whether symmetric quantization (zero-point = 0) or asymmetric quantization is used. Asymmetric schemes, by aligning the quantized range to the actual min/max of the tensor data, often yield lower quantization error for asymmetric distributions like ReLU activations. These parameters are calculated during a calibration step in Post-Training Quantization (PTQ) or learned during Quantization-Aware Training (QAT) to minimize accuracy loss.

QUANTIZATION PARAMETERS

Key Characteristics of Scale and Zero-Point

The quantization scale (S) and zero-point (Z) define an affine transformation that maps floating-point values to a quantized integer range. These two parameters are the core of modern integer quantization, enabling both symmetric and asymmetric schemes.

01

The Affine Transformation Formula

The mapping from a real (float) value r to a quantized integer q is defined by the equation:

q = round(r / S) + Z

The inverse operation, dequantization, reconstructs an approximate float value r' from the integer:

r' = S * (q - Z)

  • Scale (S): A positive floating-point number that defines the step size between consecutive integer values. It's calculated as S = (rmax - rmin) / (qmax - qmin).
  • Zero-Point (Z): An integer within the quantized range that corresponds exactly to the real value zero. It ensures that the value zero is representable without error, which is critical for operations like padding.
02

Symmetric vs. Asymmetric Quantization

The choice of how to set Z defines the two primary quantization schemes.

  • Symmetric Quantization: The zero-point Z is forced to be 0. The quantized range is symmetric around zero (e.g., [-127, 127] for 8-bit). This simplifies the arithmetic because the (q - Z) term becomes just q. It is most effective when the tensor's value distribution is roughly symmetric around zero, which is common for weight tensors after normalization.
  • Asymmetric Quantization: The zero-point Z is calculated to exactly map the observed minimum value of the tensor (rmin). The quantized range covers [rmin, rmax] precisely. This uses the full integer range more efficiently for data with an asymmetric distribution (e.g., ReLU activations, which are all non-negative), typically resulting in lower quantization error.
03

Granularity: Per-Tensor vs. Per-Channel

Scale and zero-point parameters can be applied at different levels of granularity, trading off accuracy for complexity.

  • Per-Tensor Quantization: A single scale and zero-point are calculated for an entire tensor. This is the simplest and most common scheme, supported by all hardware. However, it can introduce significant error if the tensor's values vary widely across channels.
  • Per-Channel Quantization: A unique scale and zero-point are calculated for each output channel of a weight tensor (e.g., each filter in a convolutional layer). This provides a much tighter fit to the actual data distribution, dramatically reducing error, especially for depthwise convolutions. It is a key technique for low-bit quantization (e.g., INT4). The increased parameter overhead is minimal.
04

Determining Parameters: Calibration

For Static Quantization, the optimal S and Z must be determined before deployment via a calibration process.

  1. Data Collection: A small, representative dataset (the calibration set) is passed through the model.
  2. Range Observation: For each tensor to be quantized (weights and activations), the observed minimum (rmin) and maximum (rmax) values are recorded. For activations, this often involves tracking a running histogram.
  3. Scheme Selection: Choose symmetric or asymmetric based on the observed distribution.
  4. Parameter Calculation: Apply the formulas:
    • S = (rmax - rmin) / (qmax - qmin)
    • Z = round(qmin - rmin / S)

Advanced calibration methods use entropy minimization or mean-square-error minimization to find the optimal clipping range, a process known as quantization clipping or saturation.

05

Hardware Implications and Integer Arithmetic

The primary purpose of S and Z is to enable efficient integer-only inference. Consider a core operation like a fully connected layer: Y = X * W.

With quantized inputs (Xq, Sx, Zx) and weights (Wq, Sw, Zw), the operation is decomposed into integer arithmetic:

  1. Perform the integer matrix multiplication: M = Xq * Wq.
  2. Account for zero-points and scales in a fixed-point adjustment. Modern frameworks and Neural Processing Units (NPUs) fuse these adjustments into efficient, fixed-point operations, avoiding floating-point computation entirely.

The zero-point ensures that common operations like adding a bias (which is also quantized) or performing a ReLU on zero work correctly in the integer domain.

06

Error Sources and Mitigation

Quantization is a lossy process. The scale and zero-point parameters directly influence the quantization error.

  • Clipping Error: Occurs when values outside [rmin, rmax] are saturated to the nearest quantized limit. Setting the range too narrow increases this error.
  • Rounding Error: The round() operation in the quantization formula introduces small errors for values not exactly aligned with the quantization grid.
  • Zero-Point Mismatch: In asymmetric quantization, if Z is not an integer, it is rounded, causing a shift in the entire mapping.

Mitigation Techniques:

  • Quantization-Aware Training (QAT): Simulates quantization during training, allowing the model to adapt its weights to the S and Z parameters.
  • Bias Correction: A post-training quantization method that adjusts layer biases to compensate for the change in output distribution caused by weight quantization.
  • Mixed-Precision Quantization: Using higher precision (e.g., FP16) for sensitive layers with problematic distributions, while quantizing others to INT8.
AFFINE TRANSFORMATION SCHEMES

Symmetric vs. Asymmetric Quantization

A comparison of the two primary schemes for defining the affine mapping between floating-point and quantized integer ranges, based on their use of the zero-point parameter.

Feature / CharacteristicSymmetric QuantizationAsymmetric Quantization

Zero-Point (ZP) Value

0

Non-zero integer (typically positive)

Quantized Range Symmetry

Mapping to Float Range

Centered on zero (e.g., [-α, +α])

Mapped to [min, max] of tensor

Typical Data Fit

Optimal for zero-centered distributions (e.g., weights post-normalization)

Optimal for asymmetric distributions (e.g., ReLU activations, which are ≥ 0)

Computational Overhead

Lower (ZP = 0 simplifies integer math)

Higher (requires ZP addition/subtraction in ops)

Quantization Error for Asymmetric Data

Higher (wastes representable range on unused negative values)

Lower (uses full integer range)

Common Hardware Support

Universal

Universal, but may require explicit ZP handling

Calibration Complexity

Lower (determine single scale factor from max(abs(min), abs(max)))

Higher (determine both min and max to calculate scale and ZP)

QUANTIZATION PARAMETERS IN ACTION

Practical Applications and Examples

The scale (s) and zero-point (z) are not just theoretical constructs; they are the critical parameters that enable efficient integer arithmetic in real-world systems. This section explores their concrete applications across hardware, frameworks, and deployment scenarios.

01

Enabling Integer-Only Inference on CPUs

The primary application of scale and zero-point is to convert floating-point matrix multiplications into pure integer operations. For a layer operation (Y = XW + b), where (X) and (W) are quantized to INT8, the calculation becomes:

[Y_{int} = (X_{int} - z_x)(W_{int} - z_w) * \frac{s_x s_w}{s_y} + \text{... bias terms} ]

  • Hardware Acceleration: Modern CPU instruction sets (e.g., Intel VNNI, ARM DOT) have dedicated integer multiply-accumulate (IMAC) units that execute 8-bit operations in a single cycle, offering massive throughput gains over floating-point units (FPUs).
  • Memory Bandwidth: Loading 8-bit integers instead of 32-bit floats reduces memory traffic by 4x, a critical bottleneck for performance.
02

Asymmetric Quantization for Activation Tensors

Asymmetric quantization, defined by a non-zero zero-point, is essential for quantizing activation tensors (layer outputs like ReLU).

  • Real-World Example: The output of a ReLU activation function has a range of [0, +max]. A symmetric range (e.g., [-127, 127] for INT8) would waste half its quantization levels on negative values that never occur.
  • Zero-Point's Role: By setting (z) to map the floating-point 0.0 to an integer (e.g., 0 for uint8, or a mid-range value for int8), the scheme efficiently uses the full integer range [0, 255] to represent only the positive values, minimizing quantization error.
  • Framework Implementation: TensorFlow Lite's tf.quantization.quantize function uses asymmetric quantization by default for activations, calculating scale = (max - min) / (qmax - qmin) and zero_point = qmin - round(min / scale).
03

Per-Channel Quantization for Convolution Weights

Per-channel quantization applies a unique scale and zero-point to each output channel of a weight tensor (e.g., each filter in a convolutional layer).

  • Why it's Superior: Weight distributions often vary significantly across channels. A single scale for the entire tensor (per-tensor) must accommodate the widest range, causing high error for channels with narrow distributions.
  • Accuracy Impact: For models like MobileNet, using per-channel (vs. per-tensor) INT8 quantization can improve Top-1 accuracy by 2-5% with no runtime overhead.
  • Implementation: During calibration, statistics (min/max or histograms) are collected independently per channel. The quantization formula (W_{int}^{(c)} = \text{round}(W_{float}^{(c)} / s^{(c)}) + z^{(c)}) is applied channel-wise.
  • Hardware Support: Most modern NPUs (e.g., Qualcomm Hexagon, Google TPU) natively support per-channel quantized weights.
04

Calibration: Determining Optimal Parameters

Calibration is the process of finding the optimal scale and zero-point for a pre-trained model using a small, representative dataset (unlabeled).

Common Calibration Methods:

  • Min-Max: Uses the absolute observed min/max values. Simple but vulnerable to outliers.
  • Moving Average Min-Max: Tracks a running average to smooth outliers.
  • Entropy (KL Divergence): Selects a threshold that minimizes the information loss (KL divergence) between the float and quantized distributions. This is often the most accurate method for activations.

Example Workflow in PyTorch:

  1. Run calibration data through the model in evaluation mode.
  2. Observers attached to layers record tensor statistics.
  3. Post-calibration, observers compute scale and zero_point using the chosen method.
  4. These parameters are embedded into the model's state dict for export.
05

Dequantization: The Reverse Transformation

Dequantization is the affine transformation back to floating-point: (r = s (q - z)). It's crucial for operations that cannot be quantized or for debugging.

Key Applications:

  • Mixed-Precision Layers: Some layers (e.g., certain ops in LSTMs) may remain in FP16. Inputs from INT8 layers must be dequantized before use.
  • Residual Connections: When adding a quantized tensor to a higher-precision tensor, the quantized tensor is dequantized first.
  • Model Outputs: Final logits are often dequantized to FP32 for softmax or loss calculation.
  • Accuracy Validation: During quantization debugging, dequantizing intermediate tensors allows direct comparison against the original FP32 model's outputs to isolate error sources.
06

Hardware-Specific Optimization (NPUs/TPUs)

Scale and zero-point parameters are tailored to exploit specific hardware accelerators.

  • Google TPU: Uses bfloat16 for most operations but employs int8/int32 'dynamic fixed-point' for matrix units. The scale factor is often constrained to a power-of-two, allowing implementation via a simple bit-shift instead of a full integer multiplication.
  • Qualcomm Hexagon NPU: Supports asymmetric per-channel INT8 quantization. The DSP firmware is optimized for the affine transformation (s(q-z)), fusing scale and zero-point correction into a single operation.
  • Apple Neural Engine (ANE): Uses a proprietary 16-bit floating-point (FP16) or 8-bit integer format. The MLModel tools in Core ML automatically determine and encode the optimal scale/zero-point during model conversion from PyTorch/TensorFlow.
  • Implication: Exporting a quantized model requires using the target hardware's specific toolchain (e.g., TensorRT, Core ML Tools, TFLite Converter) to ensure these parameters are correctly formatted and leveraged.
QUANTIZATION SCALE AND ZERO-POINT

Frequently Asked Questions

The quantization scale and zero-point are the core parameters that define the affine transformation mapping floating-point values to a quantized integer range. This FAQ addresses common questions about their role, calculation, and impact on model performance.

The quantization scale and zero-point are the two parameters that define an affine transformation for converting between floating-point and quantized integer representations. The scale is a floating-point multiplier that determines the resolution of the quantization, representing the size of each integer step in the original float range. The zero-point is an integer offset that aligns the integer quantization grid with the floating-point range, ensuring that a specific integer value (often zero) corresponds to the real value zero, which is critical for operations like padding. Together, they implement the mapping: float_value = scale * (int_value - zero_point) and its inverse for quantization.

These parameters are calculated per-tensor (or per-channel) based on the observed range of values (min/max) and the target quantization bit-width. They are fundamental to both symmetric quantization (where zero-point is typically forced to 0) and asymmetric quantization (where zero-point is non-zero to better fit asymmetric data distributions).

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.