TorchLean API

NN.Spec.Quantization

Tensor Quantization #

This module lifts FloatLib's RealAffineQuantizer pointwise over TorchLean's shape-indexed tensors. The real-domain specification retains arbitrary valid rounding rules. The rational tensor API imports FloatLib's executable affine quantizer directly.

FloatLib's RealAffineQuantizer supplies a real-valued scale, bounded integer codes, and a caller-chosen rounding rule. Its AffineQuantizer supplies executable rational nearest-even quantization, and the Flocq adapter proves agreement with the real specification. Scalar definitions and rounding proofs stay in FloatLib so tensor clients use the same grids and error bounds.

The equations follow Jacob et al., "Quantization and Training of Neural Networks for Efficient Integer-Arithmetic-Only Inference," CVPR 2018, doi:10.1109/CVPR.2018.00286.

Apply the affine quantizer independently at every coordinate of an arbitrary-rank tensor.

Instances For

    Reconstruct every code in an arbitrary-rank tensor on the quantizer's real grid.

    Instances For

      Pointwise condition saying that quantization does not clip any coordinate of x.

      Instances For

        Pointwise condition saying that every stored code belongs to the quantizer's code set.

        Instances For

          Every coordinate produced by tensor quantization lies in the declared code interval.

          Pointwise order is preserved by tensor quantization.

          An in-range code tensor survives pointwise dequantization and requantization exactly.

          If no coordinate clips, every tensor reconstruction error is at most half a step.