Inferensys

Glossary

Post-Training Quantization (PTQ)

Post-Training Quantization (PTQ) is a model compression technique that reduces the numerical precision of a trained neural network's weights and activations to decrease memory footprint and accelerate inference.
ML engineer working on model compression and quantization, laptop showing performance benchmarks, technical workspace.
MODEL COMPRESSION

What is Post-Training Quantization (PTQ)?

A core technique for deploying efficient models by reducing their numerical precision after training.

Post-Training Quantization (PTQ) is a model compression technique that reduces the numerical precision of a trained neural network's weights and activations (e.g., from 32-bit floating-point to 8-bit integers) to decrease memory footprint and accelerate inference, without requiring retraining. It applies a calibration process using a small, representative dataset to determine optimal scaling factors that map the float range to the integer range, minimizing accuracy loss from the precision reduction. This makes PTQ a fast, low-cost method for model deployment, especially on resource-constrained edge devices and hardware accelerators like Neural Processing Units (NPUs).

The process typically quantizes weights statically and activations dynamically, though static quantization fixes both. Common schemes include symmetric quantization (zero-centered) and asymmetric quantization (with zero-point offset). PTQ is distinct from Quantization-Aware Training (QAT), which simulates quantization during training for higher accuracy at the cost of compute. For embedding models and small language models (SLMs), PTQ is critical for enabling efficient semantic search and on-device inference as part of agentic memory and retrieval-augmented generation (RAG) architectures.

POST-TRAINING QUANTIZATION

Key PTQ Techniques and Methods

Post-training quantization reduces a model's memory footprint and accelerates inference by converting its parameters to lower-precision formats after training is complete. These are the primary algorithmic approaches used to perform this compression.

01

Static Quantization

Static quantization (or static range quantization) pre-computes the quantization parameters (scale and zero-point) for both weights and activations using a calibration dataset before deployment. The calibration process involves running inference on representative data to observe the range of activation values.

  • Process: A calibration run captures the min/max ranges of activations. These ranges are then fixed and used to quantize all subsequent inputs.
  • Advantage: Eliminates runtime overhead for computing quantization parameters, leading to the fastest inference.
  • Limitation: Requires a representative calibration dataset and is less flexible if input data distribution shifts.
  • Typical Use: Production deployments where latency is critical and input data is stable.
02

Dynamic Quantization

Dynamic quantization determines the quantization range (scale and zero-point) for activations on-the-fly at runtime, for each input. The model's weights are quantized statically ahead of time.

  • Process: During inference, the algorithm observes the actual range of activation values for each layer and quantizes them dynamically.
  • Advantage: No calibration dataset is required, making it more adaptable to varying input distributions.
  • Trade-off: Introduces computational overhead for calculating ranges during inference, which can impact latency.
  • Typical Use: Models like LSTMs or transformers where activation ranges vary significantly per input (e.g., in natural language processing tasks).
03

Quantization-Aware Training (QAT)

While not strictly a PTQ method, Quantization-Aware Training is a critical related technique. QAT simulates quantization effects during the training or fine-tuning process, allowing the model to adapt its weights to minimize the accuracy loss from the subsequent quantization step.

  • Process: Fake quantization nodes are inserted into the model graph. These nodes round and clamp values during the forward pass to mimic 8-bit precision, but gradients are calculated using the full-precision values (Straight-Through Estimator).
  • Advantage: Typically yields higher accuracy than standard PTQ, as the model learns to compensate for quantization error.
  • Trade-off: Requires retraining or fine-tuning, which adds computational cost and time.
  • Typical Use: When PTQ alone causes unacceptable accuracy degradation for a sensitive model.
04

Per-Tensor vs. Per-Channel Quantization

This distinction defines the granularity at which quantization parameters are applied.

  • Per-Tensor Quantization: A single set of scale and zero-point values is used for an entire tensor (e.g., all weights in a 2D kernel). This is simpler but can be less accurate if the tensor's values have a wide range.
  • Per-Channel Quantization: A separate set of scale and zero-point values is used for each channel (e.g., each output channel of a convolutional filter). This accounts for variation across channels, leading to higher accuracy but slightly more complex hardware support.
  • Example: In a convolutional layer with 64 output channels, per-channel quantization would use 64 different scale factors, while per-tensor would use just one.
  • Hardware Note: Modern AI accelerators (like NPUs and GPUs) now commonly support efficient per-channel quantization.
05

SmoothQuant

SmoothQuant is an advanced PTQ algorithm designed to address the challenge of quantizing large language models and vision transformers, where activation outliers can cause significant accuracy loss. It migrates the quantization difficulty from activations to weights.

  • Core Idea: It applies a per-channel smoothing factor to mathematically scale the activations down and the corresponding weights up, thereby reducing the range of activations while keeping the layer's mathematical output approximately the same.
  • Process: 1) Identify the channel with the largest activation magnitude. 2) Calculate a smoothing factor to scale that channel's activations down. 3) Apply the inverse scaling to the corresponding weights.
  • Result: Activations become easier to quantize (fewer outliers), enabling effective 8-bit weight and activation (W8A8) quantization for models that previously required 16-bit for activations.
  • Impact: Enables the deployment of models like OPT-175B and BLOOM-176B on consumer-grade GPUs.
06

GPTQ & AWQ

GPTQ and AWQ are state-of-the-art, layer-wise PTQ methods for compressing Large Language Model weights to ultra-low precisions like 4-bit, 3-bit, or even 2-bit.

  • GPTQ (GPT Quantization): An approximate second-order method. It quantizes weights one column at a time, using the Hessian matrix (a measure of curvature) to update the remaining, not-yet-quantized weights to compensate for the error introduced. This is highly accurate but computationally intensive during the quantization process.
  • AWQ (Activation-aware Weight Quantization): A more recent method based on the observation that not all weights are equally important. AWQ identifies and preserves a small fraction (e.g., 1%) of salient weights in higher precision (FP16) by analyzing activation scales, as these weights have an outsized impact on output quality. The rest are aggressively quantized.
  • Comparison: GPTQ often provides marginally better accuracy but is slower to apply. AWQ is faster and hardware-friendly, offering a better trade-off for many deployment scenarios. Both are foundational for running 70B+ parameter models on a single consumer GPU.
QUANTIZATION METHODOLOGY COMPARISON

PTQ vs. Quantization-Aware Training (QAT)

A technical comparison of the two primary approaches for reducing the numerical precision of neural network models to optimize for inference efficiency.

Feature / MetricPost-Training Quantization (PTQ)Quantization-Aware Training (QAT)

Primary Objective

Fast model compression post-training with minimal data.

Maximize post-quantization accuracy by simulating quantization during training.

Required Data Volume

Small calibration set (100-1000 samples).

Full or substantial portion of the original training dataset.

Compute & Time Cost

Low. Minutes to hours on CPU/GPU.

High. Requires retraining/fine-tuning, similar to original training cost.

Typical Accuracy Drop (FP32 -> INT8)

0.5% - 5% (model & calibration dependent).

< 1% (often negligible with proper training).

Integration Complexity

Low. Applied directly to a trained model file.

High. Requires modifying the training loop and model forward pass.

Support for Complex Operators

Limited. May require custom quantization for non-standard layers.

High. Can learn to adapt non-linear, attention, or custom ops.

Best For

Rapid deployment, batch inference optimization, embedding models.

Mission-critical applications, edge deployment, models with sensitive non-linearities.

Toolchain Examples

TensorRT, ONNX Runtime, TFLite Converter, PyTorch FX Graph Mode.

PyTorch's torch.ao.quantization, TensorFlow Model Optimization Toolkit, NVIDIA TAO.

POST-TRAINING QUANTIZATION

Frequently Asked Questions

Post-training quantization (PTQ) is a critical technique for deploying efficient machine learning models, particularly relevant for embedding models used in semantic indexing and retrieval. These FAQs address its core mechanisms, trade-offs, and practical applications for engineers.

Post-training quantization (PTQ) is a model compression technique that reduces the numerical precision of a trained neural network's weights and activations after training is complete, without requiring any retraining. It works by mapping the continuous range of 32-bit floating-point (FP32) values to a discrete set of lower-bit integer (e.g., INT8) values. This process typically involves:

  1. Calibration: Running a small, representative dataset (the calibration set) through the FP32 model to observe the statistical range (min/max) of activation values for each layer.
  2. Quantization: Applying a scaling factor and zero-point to linearly transform the observed FP32 ranges into the target integer range (e.g., -128 to 127 for INT8).
  3. Dequantization (at runtime): During inference, the integer weights and activations are scaled back to floating-point values in a lower-precision format for computation, or operations are performed directly using integer arithmetic kernels.

The primary goal is to shrink the model size and accelerate inference by leveraging hardware that is optimized for low-precision integer math.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.