What is Quantization-aware training?

Training that simulates quantization rounding so weights adapt to its error, preserving accuracy even at low bit widths.

Field: AI Hardware & Software Stack

Japanese name: 量子化を考慮した学習

Imitating rounding during training

Quantization-aware training (QAT) inserts a step that imitates rounding into the forward pass. The step rounds a value to the quantization step and immediately converts it back to a real number. With a step of 0.1, for example, 0.26 is rounded to 0.3, an error of 0.04. The computation stays in floating point, but the loss now includes the effect of this error. The weights are adjusted in the direction that keeps the loss small even after rounding. Conversion to an actual low-bit format happens after training ends.

Handling the gradient of rounding

Rounding is a staircase-shaped function whose slope is 0 almost everywhere. Left as it is, the gradient becomes 0 and backpropagation cannot correct the weights. A common approximation is to treat rounding in the backward pass as a function that outputs its input unchanged. The forward pass computes with rounded values, and the backward pass lets the gradient through as if there were no rounding. Updates are applied to the high-precision weights from before rounding, so that small updates can accumulate.

Choosing between it and post-training quantization

Post-training quantization is easy because it converts a trained model as it is. The usual order is to try it first and use QAT when accuracy falls short. QAT keeps accuracy better, but it needs training data and training computation. The fewer the bits, the larger the rounding error, and the more QAT pays off. Besides training from scratch, it is also done by further training an already trained model.

Try it: questions about Quantization-aware training

What is the difference between post-training quantization (PTQ) and quantization-aware training (QAT)?

  1. APTQ quantizes before training, QAT after
  2. BPTQ quantizes a trained model as is; QAT simulates quantization during training so the weights adapt and errors stay small at low precision
  3. CNeither PTQ nor QAT actually quantizes
Show answer and explanation

Answer: B. PTQ quantizes a trained model as is; QAT simulates quantization during training so the weights adapt and errors stay small at low precision

Post-training quantization converts a trained model's weights (and activations) to lower precision after examining value ranges with a small representative dataset. It is easy but loses accuracy as bit width shrinks. Quantization-aware training simulates quantization rounding in the forward pass during training and adjusts weights with that error included, preserving accuracy even at precisions as low as 4 bits.

FAQ

How does it differ from post-training quantization?

The difference is whether the weights are readjusted. Post-training quantization converts trained weights to lower precision as they are. QAT trains while imitating rounding, which takes more effort but keeps accuracy better even at low bit widths.

Are the weights held as integers during training?

Usually they are kept in floating point. Rounding is only imitated inside the forward pass, and updates are applied to the weights at their original precision. Conversion to integers is done after training ends.

Books on AI Hardware & Software Stack Ad

As an Amazon Associate I earn from qualifying purchases.

This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.

Back to the glossary