LLM Learning Hub

workspace/llm-course/home

Asymmetric Quantization

Asymmetric quantization uses both a scale and a zero point to map the float range [min, max] to the full integer range [0, 255] (for uint8). This utilizes all integer levels even when the data is not centered at zero, reducing quantization error for asymmetric distributions.

What is Asymmetric Quantization?

Asymmetric quantization uses both a scale and a zero point to map the float range [min, max] to the full integer range [0, 255] (for uint8). This utilizes all integer levels even when the data is not centered at zero, reducing quantization error for asymmetric distributions.

Asymmetric quantization uses both a scale and a zero point to map the float range [min, max] to the full integer range [0, 255] (for uint8). This utilizes all integer levels even when the data is not centered at zero, reducing quantization error for asymmetric distributions.

Where is it used?

Asymmetric quantization is used for activations in TFLite, ONNX Runtime, and some LLM inference engines. Post-Training Quantization (PTQ) in TensorFlow uses asymmetric for activations and symmetric for weights. It is essential for ReLU outputs which range [0, max].

How to build it

Compute: `scale = (x.max() - x.min()) / 255; zero_point = round(-x.min() / scale)`. Quantize: `q = torch.clamp(torch.round(x / scale + zero_point), 0, 255).to(torch.uint8)`. Dequantize: `deq = scale * (q.float() - zero_point)`. Store both `scale` and `zero_point`.