Executable affine rational quantization #
For a positive rational scale s, zero point z, and integer code interval
[qmin, qmax], this module executes nearest-even affine quantization:
quantize x = clamp (roundEven (x / s) + z)
dequantize k = s * (k - z)
Exact rational parameters keep the scalar kernel executable and make its mathematical denotation independent of host floating-point behavior. Downstream tensor libraries can lift the scalar operation pointwise without introducing a second quantization semantics.
The equations follow the integer-arithmetic quantization scheme used by common neural-network runtimes. See Jacob et al., "Quantization and Training of Neural Networks for Efficient Integer-Arithmetic-Only Inference," CVPR 2018, doi:10.1109/CVPR.2018.00286.
Parameters of a bounded nearest-even affine quantizer.
- scale : ℚ
Exact distance between adjacent reconstructed values.
- zeroPoint : ℤ
Integer code representing zero when it lies in the code range.
- qmin : ℤ
Smallest stored code.
- qmax : ℤ
Largest stored code.
A quantization scale is strictly positive.
The code interval is nonempty.
Instances For
Saturate an integer to the quantizer's code interval, using the shared saturating clamp.
Instances For
Integer code before saturation.
Instances For
Quantize an exact rational and saturate the result to the stored code interval.
Instances For
Reconstruct the exact rational denoted by an integer code.
Instances For
Mathematical value produced by executable affine quantization.
Instances For
Saturation fixes a code already inside the representable interval.
Dequantizing the zero point gives exact zero.
Every in-range integer code survives an executable quantize/dequantize round trip.
Before saturation, reconstruction differs from the input by at most half a quantization step.
General numerical-system view #
Store the executable quantization result together with its erased range proof.
Instances For
Numerical system whose codes denote their exact affine reconstruction.
Instances For
An affine-quantized code with an erased proof of its complete denotation.
Instances For
An affine-quantized code with an erased proof of its reconstructed rational value.
Instances For
Representation in the affine system is equality with exact dequantization.
Executable quantization is a quantizer onto its own reconstructed value.
Since roundedValue is dequantize after quantize, this is the definitional contract used by
generic QuantizerOn automation. The error bound when clipping is inactive is
dequantize_quantize_error_le.
The numerical-system view inherits the inactive-saturation half-step guarantee.