int8

INT8 quantization represents neural network weights and activations using 8-bit integers instead of 32-bit floats, achieving 4× memory reduction and 2-4× inference speedup with minimal accuracy loss through careful calibration. Quantization formula: q = round(x / scale) + zero_point, where x is FP32 value, scale is quantization scale, zero_point is offset. Dequantization: x ≈ (q - zero_point) × scale. Quantization schemes: (1) symmetric (zero_point = 0, range [-127, 127]), (2) asymmetric (zero_point ≠ 0, range [0, 255]—better for activations with non-zero mean). Per-tensor vs. per-channel: (1) per-tensor (single scale for entire tensor—simple, less accurate), (2) per-channel (separate scale per output channel—better accuracy, standard for weights). Calibration: determine optimal scale and zero_point from representative data—(1) min-max (scale = (max - min) / 255—simple, sensitive to outliers), (2) percentile (clip outliers at 99.9th percentile—more robust), (3) entropy minimization (minimize KL divergence between FP32 and INT8 distributions). Post-training quantization (PTQ): quantize trained FP32 model—(1) collect activation statistics on calibration dataset (100-1000 samples), (2) compute scales, (3) quantize weights and activations. Accuracy: typically <1% accuracy drop for CNNs, 1-3% for transformers. Quantization-aware training (QAT): simulate quantization during training—(1) insert fake quantization ops (quantize then dequantize), (2) train with quantization noise, (3) model learns to be robust to quantization. Better accuracy than PTQ but requires retraining. Hardware support: modern CPUs (AVX-512 VNNI, ARM dot product), GPUs (NVIDIA Tensor Cores), and accelerators (Google TPU, Apple Neural Engine) have INT8 instructions—2-4× faster than FP32. Inference frameworks: TensorRT, ONNX Runtime, TensorFlow Lite support INT8 quantization with automatic optimization. Limitations: (1) some layers sensitive to quantization (attention, layer norm—keep in FP16), (2) extreme outliers (clip or use mixed precision), (3) small models (less redundancy—harder to quantize). INT8 quantization is standard for production inference, enabling efficient deployment on edge devices and reducing cloud costs.

Go deeper with CFSGPT

Get AI-powered deep-dives, save terms, and run advanced simulations — free account.

Create Free Account