Quantizing Models for Fast, Low-Latency Inference in the Cloud
Moving Large Language Models (LLMs) and other state-of-the-art Deep Learning models into cloud production quickly runs into a hard limit: memory bandwidth. Raw compute (FLOPs) has grown exponentially from one generation of cloud GPUs to the next, but memory bandwidth has lagged behind. Serve a model with billions of parameters in the cloud and the system ends up spending more time shuttling weights from High Bandwidth Memory (HBM) into the compute registers than it spends on the matrix multiplications themselves. This “memory wall” leads to latency nobody can accept, inflated cloud infrastructure bills and limited concurrency.
Model quantization addresses the problem by lowering the precision of the numbers that represent a model’s weights and activations. Engineering teams that convert the usual 32-bit floating-point (FP32) values into lower-precision formats, such as FP16/BF16 (16-bit float), INT8 (8-bit integer) or even INT4 (4-bit integer), can shrink the model’s memory footprint dramatically. Inference becomes faster as a direct result: caches are used more fully, batches can grow larger, and specialized integer compute units (AWS Inferentia chips or NVIDIA Tensor Cores, for example) can be put to work for low-latency serving in the cloud.
How Neural Network Quantization Works
Mathematically, quantization comes down to mapping a continuous span of floating-point values onto a discrete set of integers. Affine quantization rests on one basic transformation, given by the equation:
$r = S(q – Z)$
In this equation:
- $r$ stands for the original floating-point (real) value.
- $S$ denotes the scaling factor, which is a positive floating-point number.
- $q$ denotes the integer value after quantization.
- $Z$ is the zero-point, an integer that lets the real value zero be represented exactly; this matters a great deal for operations such as padding and ReLU activations.
Symmetric Compared with Asymmetric Quantization
Whether to use symmetric or asymmetric quantization depends on how the model’s weights and activations are distributed.
With Symmetric Quantization, the zero-point ($Z$) is fixed at exactly zero, and the quantization range is laid out evenly on both sides of zero (for INT8, -127 to +127, for example). The math becomes simpler, and matrix multiplication needs fewer computational steps, because no zero-point offset has to be subtracted on the fly during inference. The method works very well for model weights, whose distribution is usually normal and centred on zero.
With Asymmetric Quantization, the zero-point is free to move, so skewed distributions can be handled. When an activation function such as ReLU produces only positive outputs, a symmetric scheme would spend half of the INT8 bit space on negative values that never occur. Asymmetric quantization instead maps the tensor’s real minimum and maximum onto the outer limits of the integer range (0 to 255, for example), which keeps considerably more accuracy when the activation data is skewed.
Quantizing After Training (PTQ)
PTQ is the standard industry route for preparing a model for cloud deployment quickly, without paying the huge compute bill that retraining would bring. PTQ starts from a model that has already been fully trained in FP32 or FP16 and quantizes it offline, before the model is loaded into the inference engine.
There are two main ways to carry out PTQ:
- Dynamic Quantization: The model’s weights are converted to INT8 in advance, while activations stay in floating point and are quantized on the fly during the forward pass at runtime. It is very simple to put in place and avoids serious accuracy loss, since activation statistics are computed precisely for every input. The catch is that working out scales and zero-points at runtime adds overhead that can cancel part of the latency gain, so this approach fits CPU-bound microservices better than high-throughput GPU endpoints.
- Static Quantization: Weights and activations alike are converted to INT8 before deployment. Activation ranges cannot be predicted without data, so static quantization depends on a calibration dataset: a representative slice of production data, usually somewhere between a few hundred and a thousand samples, is passed through the model while the minimum and maximum of every intermediate activation are recorded. Those statistics are then fused into the model graph. Because every operation is purely integer-based, static quantization delivers the best throughput on cloud GPUs, though it needs careful calibration to prevent severe drops in accuracy.
Quantization-Aware Training (QAT)
Sometimes PTQ costs too much accuracy. This happens most often when highly sensitive models, such as object detectors or multi-modal transformers, are pushed hard down to INT4. In those cases Quantization-Aware Training (QAT) is the only workable option.
QAT does not quantize after the fact. It reproduces the effects of quantization while the model is actually being trained or fine-tuned, by placing “fake quantization” nodes into the computational graph. These nodes let floating-point values through but limit their precision and clamp their ranges, mimicking what INT8 deployment will do to them.
The rounding operations involved in quantization are not differentiable: their gradient is zero everywhere apart from the jumps, and at the jumps it is undefined. Ordinary backpropagation therefore breaks down. QAT gets around this with the Straight-Through Estimator (STE), which disregards the step-function behaviour of rounding during the backward pass and hands the gradients straight through to the continuous weights. The network can then gradually tune its weights to offset the precision loss it will face in production, and the resulting quantized models frequently reach the same accuracy as their FP32 versions.
Advanced Quantization Techniques for Large Language Models (LLMs)
Conventional PTQ methods tend to break down on modern LLMs of 7B parameters and more because of activation outliers. Large transformers develop particular activation channels whose values are 10x to 100x bigger than average. Under a standard static quantization scale, those huge outliers push the scaling factor very high, squashing all the ordinary values to zero and wrecking the model’s ability to produce coherent text.
Today’s cloud deployments handle this with advanced algorithms built specifically for LLMs:
- SmoothQuant: This method mathematically shifts the difficulty of quantization away from the activations, which resist quantization because of their outliers, and onto the weights, which are easy to quantize since they follow a normal distribution. Shrinking the activation outliers while enlarging the matching weights offline lets ordinary INT8 matrix multiplication run cleanly in production, so LLMs can be served quickly on ordinary cloud GPUs.
- GPTQ (GPT-oriented accurate post-training quantization): GPTQ concentrates on weight-only quantization, for example squeezing weights into 4 bits while activations stay in FP16. It reaches high accuracy by working through the model one layer at a time and using the inverse Hessian matrix to offset each weight’s quantization error, adjusting the weights in that layer that have not yet been quantized. It has become the de facto standard for running very large models on infrastructure with limited memory.
- AWQ (Activation-aware Weight Quantization): AWQ starts from the premise that some weights matter more than others. Using a small calibration dataset, it finds the small fraction of weights (typically about 1%) tied to the largest activation outliers. That critical 1% is left unquantized in FP16, and everything else is quantized aggressively to INT4. The mixed approach preserves perplexity far better than standard PTQ while still producing very large speedups.
Hardware and Cloud Deployment Architecture
The choice of cloud infrastructure goes hand in hand with the quantization strategy, since the specialized accelerators that cloud providers offer determine how well a quantized model will run.
| Quantization Format | Cloud Hardware Targeted | Typical Workload |
| FP16 / BF16 | AWS Trainium, NVIDIA A100 / H100 | Reference serving for models that need full mathematical precision; expensive. |
| INT8 | NVIDIA L4 / T4, AWS Inferentia2 | Computer vision at high throughput, embedding models and typical NLP pipelines. |
| INT4 (AWQ/GPTQ) | NVIDIA L40S / A10G | Generative LLMs such as Llama-3 or Mistral, served through frameworks like vLLM or TGI. |
The latency gains from quantization only materialize when these models run on purpose-built inference servers instead of plain REST APIs. vLLM (with PagedAttention) and TensorRT-LLM are frameworks designed precisely to fuse quantization kernels into the execution graph.
Take an INT4 GPTQ model deployed on an AWS instance of type g5.2xlarge (NVIDIA A10G) through TensorRT-LLM. The system can use custom CUDA kernels that move 4-bit weights out of global GPU memory and into the SM registers, convert them back to FP16 on the fly, and run the matrix multiplication on the Tensor Cores. Since loading the weights, that is, memory bandwidth, is the bottleneck, making the weights 4x smaller raises generation throughput in tokens per second by close to 3x to 3.5x, which sharply lowers the cost of each inference.
Frequently Asked Questions
1. How does weight-only quantization differ from full quantization?
Weight-only quantization shrinks just the model’s parameters (to INT4 or INT8, for example) and keeps activations at a higher precision such as FP16 during inference, which relieves memory bandwidth bottlenecks. Full quantization converts weights and activations alike to INT8; that is what you need to speed up the arithmetic itself (the compute bottleneck) through integer matrix multiplication.
2. Is some loss of model accuracy unavoidable with quantization?
Yes. Rounding floating-point values to integers always adds some mathematical noise. With advanced calibration methods such as GPTQ or SmoothQuant, or by simulating the loss during training (QAT), the drop is usually held below 1% in relative terms, which goes unnoticed in most production settings.
3. Why not simply run an INT4 model on any ordinary cloud CPU?
Quantized models do run on CPUs, but very low latency depends on hardware that physically includes dedicated low-precision matrix multiplication units. Without dedicated support, such as Intel’s AMX instructions or NVIDIA’s Tensor Cores, a processor has to expand the INT4 values back into FP32 in software before computing, and that can leave inference slower than just running at standard precision.
4. When is QAT a better choice than PTQ for an enterprise?
Start with PTQ every time, since it is cheap and quick to iterate on. Turn to QAT only when PTQ causes a serious loss of performance, which happens most often with models that depend on fine pixel-level detail (medical imaging segmentation, for instance) or when small models (< 1B parameters) are pushed below 4 bits for deployment on edge devices.
Sources & References
- A survey of quantization approaches for efficient neural network inference. Gholami, A., et al., 2021. arXiv:2103.13630.
- GPTQ, a method for accurate post-training quantization of generative pre-trained transformers. Frantar, E., et al., 2022. arXiv:2210.17323.
- AWQ, which applies activation-aware weight quantization to compress and accelerate LLMs. Lin, J., et al., 2023. arXiv:2308.00222.
- SmoothQuant, an accurate and efficient post-training quantization approach for large language models. Xiao, G., et al., 2022. ICML (International Conference on Machine Learning) proceedings.
- Running large language models on Triton Inference Server with TensorRT-LLM. NVIDIA Technical Blog, 2023.