- Precision reduction (FP32/FP16 → INT8) reduces memory footprint and memory traffic, which is frequently the bottleneck in LLM inference.
- On modern GPUs, INT8 kernels can execute more operations per cycle and leverage specialized instructions for higher throughput.
- Using per-channel quantization and representative calibration data minimizes precision loss across layers.
- Smaller data types reduce cache/memory transfers.
- INT8 arithmetic increases compute density and uses optimized kernels.
- Mixed-precision fallback (keeping some ops in FP16/FP32) prevents accuracy degradation for sensitive operators.
- Export or convert the model to an intermediate format such as ONNX or SavedModel.
- Create a TensorRT builder and enable INT8 in the builder configuration.
- Provide a representative calibration dataset for post-training static quantization, or use QAT if needed.
- Build the TensorRT engine and validate generation quality. If accuracy drops, selectively keep sensitive layers in FP16/FP32 (mixed precision) or use QAT.
MyCalibrator with your calibrator implementation or use TensorRT utilities that provide calibrators.
Important considerations when using INT8
- The calibration dataset must be representative of inference inputs (token distributions, sequence lengths, etc.).
- Some layers/operators are more sensitive to quantization; leave those in FP16/FP32 if necessary (mixed precision).
- Generation tasks with rare tokens or long-range dependencies may require more careful calibration or QAT to maintain quality.
- Measure generation quality (e.g., perplexity, BLEU, human evaluation) and latency/throughput to validate trade-offs.
Practical recommendations
- Start with INT8 quantization using a representative calibration dataset and validate generation outputs.
- Use TensorRT engine-building best practices: export a stable ONNX/SavedModel, enable INT8 with a calibrator, and test mixed-precision fallbacks.
- Apply layer fusion and other graph-level optimizations as complementary steps.
- Consider pruning or distillation only when you need additional size or latency reductions and can invest in retraining.
- TensorRT: https://developer.nvidia.com/tensorrt
- NVIDIA Tensor Cores: https://developer.nvidia.com/tensor-cores
- ONNX: https://onnx.ai/
- SavedModel: https://www.tensorflow.org/guide/saved_model
- Quantization-aware training (QAT) guide: https://www.tensorflow.org/model_optimization/guide/quantization/training
Use a representative calibration dataset and validate generation quality after quantization. If specific layers degrade significantly under INT8, consider mixed-precision (INT8 + FP16) or QAT for those layers.