OpenVINO int8 Gives Wrong Masks on Intel VNNI CPUs
Int8 quantization is the usual way to make an AI model faster on a CPU. In an automated product-photo pipeline, the BiRefNet-lite background-removal model was quantized to int8 with NNCF (OpenVINO’s quantization tool) and ran about 1.5 times faster. The masks looked fine on a Ryzen machine. With the exact same model file on an Intel N100 mini PC, some photos came out broken: a cosmetics bottle lost half its body, a pump nozzle disappeared. The bug appeared in both the Python and the Node.js version, so it was not in the image-processing code.
How it was measured
Each photo went through the int8 model and the fp32 model (the original, unquantized) at the same resolution. The two masks (the area kept) were compared with IoU: overlap divided by union. IoU 1 means identical; below 0.95 counts as a visible difference. Timings cover only the segmentation step, each configuration in its own process, on an otherwise idle machine.
Finding the cause
The worst photo (a cosmetics bottle) was used to test each hypothesis, 512 int8 model:
| Attempt | IoU vs fp32 | s/image |
|---|---|---|
| Original int8 | 0.601 | 1.29 |
Force fp32 compute (INFERENCE_PRECISION_HINT=f32) |
0.601 | 1.29 |
Disable dynamic quantization (DYNAMIC_QUANTIZATION_GROUP_SIZE=0) |
0.715 | 1.36 |
| Force the AVX2 path + no dynamic quantization (like a non-VNNI CPU) | 0.966 | 1.86 |
| Remove quantization before attention | 0.573 | 1.30 |
| Remove quantization before Convolution | 0.981 | 1.50 |
| Remove quantization before MatMul (66 of 277 points) | 0.984 | 1.38 |
What this shows:
- Forcing fp32 changed nothing. That setting only affects floating-point operations; int8 operations still run in int8.
- Forcing OpenVINO onto the AVX2 path (as on a CPU without VNNI) gave a nearly correct mask, but at fp32 speed. This fits the hypothesis: on a CPU without VNNI, the int8 operations are effectively computed close to floating point, so the result matches fp32; on the N100, VNNI runs real int8 and the error accumulates.
- The error sits in the matrix multiplications (MatMul) of the Linear layers in the Swin backbone, adding up across stages 0–2. Removing quantization from a single stage or block (attention, MLP) was not enough. Removing stages 0–2 was as fast as removing every MatMul, so the chosen fix removes every FakeQuantize node in front of a MatMul and keeps int8 everywhere else.
The fix edits only the already-quantized model file (IR). No retraining or re-quantization is needed.
Results on 57 photos
Median seconds per image, segmentation only, Intel N100:
| Configuration | 512, 4 threads | 512, 1 thread | 768, 4 threads | 768, 1 thread |
|---|---|---|---|---|
| fp32 | 2.06 | – | 4.47 | – |
| Original int8 | 1.32 | 3.20 | 2.97 | 6.92 |
| int8 without MatMul quantization | 1.53 (+16%) | 3.58 (+12%) | 3.19 (+7%) | 7.71 (+11%) |
| Weight-only int8 (w8) | 3.80 | – | 4.88 | – |
Photos that differ from fp32 (IoU < 0.95):
- Original int8, 512: cosmetics bottle 0.60, an electronics product 0.63, plus 3 inherently ambiguous photos.
- Original int8, 768: cosmetics bottle 0.94 (pump missing), a baby product 0.92.
- int8 without MatMul quantization: only ambiguous regions differ (handles, chocolate pieces, shelf bases).
The fix is 7–16% slower than the original int8 but still about 1.35–1.4 times faster than fp32 at 4 threads. The openvino-node version shows similar numbers: 768 int8 from 3.15 to 3.33 s/image, 512 from 1.43 to 1.56 s/image.
One surprise: the weight-only int8 model (w8) gives masks close to fp32 but is slower than fp32 on the N100 (3.80 vs 2.06 s at 512). On this CPU, w8 saves disk space, not time.
Two photos (a teddy bear on a bag, a product with a large logo) fail even at fp32 512. That is a limit of the model at this resolution, not an int8 issue.
Safety net: detecting broken masks automatically
Fixing the model is the main remedy, but a cheap check was added to catch anything left. The metric is the grey-pixel ratio: pixels with uncertain confidence (0.1–0.9) divided by pixels that belong to the product.
- Good masks: mostly below 0.05. Hard photos (logos, handles): 0.1–0.4 even at fp32.
- Masks broken by int8 on Intel: 0.108–0.274.
- Mask area alone does not work: the bottle missing half its body still covers 29% of the frame.
The threshold is 0.1. Above it, that photo is re-run with the fp32 model (or w8 if fp32 is not present). On 57 photos, 512 at 4 threads: with the old int8 model, the check caught the cosmetics bottle (0.109 down to 0.040 after the re-run, matching fp32). With the fixed model, 3 of 57 photos were re-run (all hard ones), each adding 2.1 s; the average went from 1.56 to 1.75 s/image. At 768, no photo needed a re-run.
The check only catches large errors (wide grey areas). A small one like the missing pump at 768 original int8 has a ratio below 0.08 and slips through. That is why fixing the model comes first.
Limits of this measurement
- 57 photos, mostly e-commerce product shots. No people or landscapes.
- One model (BiRefNet-lite, Swin backbone) and one quantization setup (NNCF defaults). Other models may break elsewhere.
- The error was seen on one VNNI-capable Intel CPU (N100). Other Intel generations and newer AMD CPUs with VNNI (Zen 4 and later) were not tested.
- The speed of the fixed model on the Ryzen 5600X was not measured; it is expected to be about the same, since that machine never ran the real int8 path.
- The explanation that the non-VNNI path computes close to floating point is inferred from the forced-AVX2 test, not confirmed in OpenVINO’s source code.
Takeaway
An int8 model needs to be checked on the same kind of CPU it will run on in production. A check on a dev machine can give different results on another machine, even with the same model file and library. Comparing IoU against fp32 on a few dozen real photos is enough to catch it early.
Need to shrink product photos after removing the background: try the image compressor, which runs right in the browser.