Calibration dataset in INT8 Qunatization #44
-
Why does quantization INT8 need to have calibration dataset, but FP16, FP32 don't need ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @phanben110, Since we generally train models in FP32, we don't require any further calibration. And when you convert your model from FP32 to FP16, we just drop half of those 32bits and you loose some precision. However, if we do the same to go from FP16 to INT8, we'd loose all the precision and most of the numbers would just become zero. That's why instead of dropping bits, we map FP16 values to INT8 values to capture the range. And to capture this range properly, we run our FP16 models with a group of expected inputs values, which helps us in minimizing precision loss. To know more about this topic, I'd recommend this article Now what should be your calibration dataset, depends on your use case. Sometimes people just randomly sample from their training dataset, or sometimes they selectively sample for a specific use case. For example, let's say you trained a model with animal dataset where images were captured in all conditions (i.e. different weathers, low light, etc.). But you're deploying this model to certain parts of the forest and you expect to capture only certain types of images. So when doing the INT8 quantization, you'd want to calibrate with a more selective and relevant dataset to minimize precision loss for that specific use case. Hope this helps. |
Beta Was this translation helpful? Give feedback.
Hi @phanben110,
Since we generally train models in FP32, we don't require any further calibration. And when you convert your model from FP32 to FP16, we just drop half of those 32bits and you loose some precision.
However, if we do the same to go from FP16 to INT8, we'd loose all the precision and most of the numbers would just become zero. That's why instead of dropping bits, we map FP16 values to INT8 values to capture the range. And to capture this range properly, we run our FP16 models with a group of expected inputs values, which helps us in minimizing precision loss. To know more about this topic, I'd recommend this article
Now what should be your calibration dataset, depends on you…