Skip to content

Post-training quantization (PTQ)

Post-training quantization (PTQ) converts a trained floating-point model to use integer math for efficient on-device deployment. It calibrates the model on representative data without retraining, making it a fast and simple way to reduce model size and improve inference performance.

For complete working examples, see the Tutorials page.

import dg

# Calibrate on representative data and freeze
quantized = dg.post_training_quantize(model, calib_dataset, num_samples=1024)
schema = dg.export(quantized)

dg.post_training_quantize takes any torch.utils.data.Dataset and streams num_samples samples through to measure activation ranges, then freezes the quantization.