Concepts / Post-Training Quantization

Post-Training Quantization

Inference quantization reduces the precision of parameters and values during serving, which can reduce memory footprint and improve computation speed, but reduced precision does not always reduce latency because of format conversion overhead.

  • Programming

Testing the Belief That Fewer Bits Means Faster

A common first reaction to quantization is that storing a model with fewer bits must make it faster. Fewer bits means less data to move, less memory to fill, and, it seems, less arithmetic to perform. That reasoning is partly right, which is exactly why it is easy to over-trust. This article starts from that belief, tests it, and then builds up the more accurate picture that the rest of the topic depends on.

What do you think happens?

If a model's weights are stored in fewer bits, will it always produce answers faster?

  • Yes, fewer bits always means faster answers

  • No, the speed depends on more than the number of bits

Reveal answer
Answer:

No, the speed depends on more than the number of bits

Reduced precision can speed things up, but it does not always reduce latency. Converting values between formats takes time, and that conversion overhead can cancel out the gain from moving fewer bits.

What Reducing Precision Changes in Stored Values

Definition

Inference quantization means reducing the precision of a model's parameters and values while the model is being served. Serving is the stage where a trained model is used to answer inputs, as opposed to the stage where it is learned.

In the early days of deep learning, models were trained and served using 32-bit floating-point values, written FP32. Since the late 2010s it has become increasingly common to serve models at 16 bits and below. The motivation is that quantization can improve computation speed and reduce the memory footprint of the model. The memory footprint is the amount of storage the model's values occupy while it runs.

Once you reach 8 bits and below, the choice of number format becomes more delicate. One option is to keep values as floats in a minifloat format, such as FP8 with 8 bits or FP4 with 4 bits. The more common option is to convert parameter values into an integer format, such as INT8 or INT4. The table below lists the formats mentioned in the source material, ordered from widest to narrowest.

FormatBitsKind of value
FP3232Floating-point
16-bit formats16Floating-point, reduced width
FP88Minifloat
INT88Integer
FP44Minifloat
INT44Integer

Number formats named in the source, from widest to narrowest

Reducing the width of stored values changes what each value can represent. The diagram below shows the change in stored parameter values. Before quantization, a parameter occupies a wide floating-point slot. After quantization, the same parameter is held in a narrower integer slot. The values are not identical after conversion, which is the central trade-off of this topic.

0.62original value-1.0code -2-0.5code -10.0code 00.5code 11.0code 2rounds to nearest level
How does a float value get mapped to the nearest representable low-precision level, and what information is lost in the process?

The diagram is an illustration of the general idea rather than a specific format. A value between two levels is assigned to one of them, so the stored result is an approximation. Each conversion can shift values slightly. Values that fall outside a format's range are a more serious problem, because they can become infinity or an arbitrary value. For that reason, quality has to be checked after quantization rather than assumed.

Why Fewer Bits Can Speed Up Inference

Reduced precision helps in two linked ways. First, a smaller footprint allows a larger batch size, so the model can process more inputs in parallel. Second, reduced precision speeds up the computation itself, which lowers inference latency. Latency is the time it takes to produce a response for one request. The arithmetic argument is easiest to see with a bit-by-bit model of addition, which is why the source uses it as the starting point for the mechanism.

Worked example

Tracing one parameter through a quantized serving step

A parameter is stored as a wide floating-point value and then converted to a narrower integer format for serving. Follow what happens to its value and where the cost appears.

  1. 1
    Start with the stored value

    The parameter begins as a value in a wide floating-point slot, such as FP32. It holds a fine-grained number, for example 0.62.

  2. 2
    Map it to a narrower format

    Quantization converts the value into a narrower integer slot, such as INT8. The value is snapped to the nearest representable level, so the stored result is an approximation rather than the exact original.

  3. 3
    Move less data

    Because each stored value is narrower, the parameter occupies less memory and less data has to move. This is the source of the footprint and bandwidth benefit.

  4. 4
    Convert before computing

    The compute unit may need the value in a different format from the one it is stored in. The conversion step takes time, and this is the cost that can offset the savings from moving fewer bits.

Result

Fewer bits reduce data movement and memory use, but the value changes slightly, and any conversion needed before computing adds time back. Whether the net effect is faster depends on that balance.

Where Format Conversion Adds Time Back

Reduced precision does not always reduce latency. The reason is format conversion overhead in the inference path. The pipeline below follows a stored low-precision weight from memory to the compute unit. Each step that changes the format is a place where time can return, even though the stored values are smaller.

Storedlow-precisionweightsfewer bits per valueMove data to computeless data to moveConvert to computeformatadds conversion timeComputearithmeticConvert resultadds conversion timeOutputresponsefewer bytes
What steps does data go through from stored low-precision weights to the compute unit, and where do conversion steps add time back?

The two conversion steps in the pipeline are where the gain can be lost. Moving fewer bits is a real saving, but a conversion before the arithmetic and a conversion after it can consume that saving. This is why the simple rule that fewer bits means faster does not hold in every case. The benefit has to be measured on the actual serving path, not inferred from the bit width alone.

Four Ways to Use Lower Precision

Post-training quantization is only one of several ways lower precision enters the model lifecycle. The table below sets the four approaches side by side. The key question for each is at what stage reduced precision is applied, and whether it is aimed at inference quality, training cost, or both.

ApproachWhere reduced precision appliesMain goal
Post-training quantization (PTQ)Only at inference, after training in higher precisionLower serving cost and speed up computation
Quantization-aware training (QAT)Simulated during training while computing in high precisionGood quality when the model is later run in low precision
Mixed precision trainingDifferent precisions for weights, gradients, and activationsReduce training cost while keeping sensitive values precise
Training directly in lower precisionThroughout training itselfReduce training time and cost; harder to get right

Where each approach applies reduced precision

Quantization during training is less common than PTQ, but it is gaining traction. It has two distinct goals, and a given technique may serve one, both, or neither. The subsections below take each approach in turn.

How 1-Bit and 1.58-Bit Weights Work

Quantization has a limit. A value cannot use fewer than 1 bit, and several efforts have tried 1-bit representations, including BinaryConnect, Xnor-Net, and BitNet. In 2024, Microsoft researchers declared the era of 1-bit LLMs by introducing BitNet b1.58, a transformer-based language model that requires only 1.58 bits per parameter.

The number 1.58 is not a bit pattern that a single stored bit can hold. It describes information content: a weight that can take one of three values, such as -1, 0, or +1, carries $\log_2 3 \approx 1.58$ bits of information. The diagram below shows the three states. A few states, arranged across a whole weight matrix, are what allow the representation to approximate full-precision weights.

-1negative state0zero state+1positive state
What set of values can a 1.58-bit weight take (for example -1, 0, +1), and how do those few states still approximate a full-precision weight matrix?

The reported performance of BitNet b1.58 is comparable to 16-bit Llama 2 up to 3.9B parameters. A benchmark comparison with Llama models at several sizes is the source's evidence for this claim. Read it with care: the comparison is about benchmark scores, not about speed, and the gap varies from benchmark to benchmark. A benchmark result does not, by itself, show that the model runs faster.

Mistakes Beginners Make About Lower Precision

  • Common mistake

    Assuming fewer bits always means faster inference

    What it looks like

    A model is quantized to a narrower format, and its latency is expected to drop by the same ratio as its bit width.

    Why it fails

    Format conversion can add time back, and the conversion steps may consume the gain from moving fewer bits.

    Do this instead

    Measure latency on the actual serving path rather than inferring it from the bit width.

  • Common mistake

    Assuming quantized values are identical to the originals

    What it looks like

    A parameter stored as a wide float is assumed to keep exactly the same value after being stored in an integer slot.

    Why it fails

    Each conversion can shift values slightly, so the stored result is an approximation.

    Do this instead

    Check output quality after quantization.

  • Common mistake

    Confusing QAT with a way to train faster

    What it looks like

    Quantization-aware training is adopted expecting shorter training runs.

    Why it fails

    QAT simulates low-precision behavior while computing in high precision, so it does not reduce training time.

    Do this instead

    Use QAT to improve low-precision inference quality, and use other approaches if the goal is cheaper training.

  • Common mistake

    Believing low-precision training is always the easier option

    What it looks like

    Training directly in lower precision is assumed to be a simple cost reduction.

    Why it fails

    Backpropagation is more sensitive to lower precision, so the learning signal can be disturbed.

    Do this instead

    Expect extra difficulty and validate training behavior carefully.

  • Common mistake

    Treating a 1.58-bit weight as a stored 1.58-bit field, rather than a value with three states

Applying the Ideas to a Deployment Decision

MEDIUM

A team has a model trained in FP32 and wants to serve it on an edge device that only supports quantized inference. Which approach matches this situation, and what must they check before shipping? Explain your answer in terms of when reduced precision is applied and what could change in the outputs.

Hints
  • Ask whether the reduction happens before, during, or only after training.
  • Consider what the edge device requires and what changes when values are converted.
  • Think about whether quality must be re-checked after the change.

Key Takeaways

  • Inference quantization reduces the precision of a model's parameters and values during serving, which can shrink the memory footprint and speed up computation.
  • Reduced precision does not always reduce latency, because format conversion can add time back and each conversion can shift values.
  • Post-training quantization applies reduced precision after training; quantization-aware training simulates low precision during training to improve low-precision inference quality without reducing training time; mixed precision assigns different precisions to weights, gradients, and activations.
  • 1-bit and 1.58-bit models are possible because a few discrete states can approximate weights, but a value cannot use fewer than 1 bit, and benchmark quality is not the same as speed.

More concepts starting with P