ML Systems Review

Quantization for On-Device Vision

The failure mode is almost never the weights, and almost never the bit width. It is a handful of activation channels with pathological dynamic range, and a calibration set that does not look like production.

Computer Vision
By Priya Ramachandran , MS Reviewed by Dr. Nadia Volkov , PhD
Last updated: 14 min read
TL;DR
  • Per-channel scales beat more bits. Per-channel INT8 routinely outperforms naive per-tensor INT16 on the same model.
  • Classification tolerates quantization; regression does not. A classifier needs the argmax to survive. A depth or portion-volume head needs the magnitude.
  • The failure is activation outliers, not weights. A few channels with 10–100× the dynamic range force a scale that crushes everything else.
  • INT4 weights, yes. INT4 activations on vision, no. Most published INT4 wins are bandwidth-bound LLMs; mobile CNNs are frequently compute-bound.
  • Calibration representativeness > calibration size. A few hundred production-like samples beat a thousand studio images.
  • Profile on the target silicon. Operator fallbacks off the accelerator dominate any arithmetic you saved.

The question that is usually asked wrong

"Can we quantize to INT8?" is not answerable as posed, because the answer is a property of the head rather than the network. And the head is the part that gets least attention in quantization write-ups, because the benchmark everyone reaches for is ImageNet top-1.

Classification is the easy case. A classifier only has to preserve the ordering of its logits; the absolute values can drift substantially and the argmax survives. Well-executed per-channel post-training quantization to INT8 typically costs a fraction of a percent of top-1, and frequently nothing you can measure above run-to-run noise.

Regression is a different problem. A depth head, a keypoint head, or a volume-estimation head has to preserve magnitude. There is no argmax to hide behind, and the quantization error propagates directly into the output units you care about. The same PTQ recipe that costs 0.3% top-1 on a classifier can cost several percent of relative error on a regression output — and several percent of relative error is often the entire accuracy budget of the product.

This is the single most common way a quantization plan fails review: it was validated on the wrong task. We made a related argument about benchmark selection in why accuracy benchmarks mislead, and it applies with more force here.

What actually breaks: activation outliers

Weights are well behaved. Per channel, they are roughly zero-centred and roughly Gaussian, with dynamic range that fits comfortably into 8 bits once you scale per channel. Quantizing weights is close to a solved problem.

Activations are not. After certain layers — particularly the ones following a residual add, and the projections in attention blocks — a small number of channels carry dynamic range one to two orders of magnitude above the rest.

Now consider what a single per-tensor scale has to do. It must cover the outlier channel, or the outlier clips. If it covers the outlier, then the other several hundred channels — whose values live in the bottom 1–2% of that range — get mapped into a handful of the 256 available levels. You have effectively quantized most of the tensor to 3 or 4 bits in order to represent one channel correctly.

per-tensor scale:   [────────────────────── outlier ──────────────────────]
                     ^^^ 250 channels live here, in ~4 levels

per-channel scale:  [── ch0 ──] [── ch1 ──] ... [───── outlier ─────]
                     full 256 levels each

Hence the headline result that surprises people: per-channel INT8 routinely beats per-tensor INT16. The bit width was never the binding constraint; the scale granularity was.

The practical ladder

  1. Per-channel (per-output-channel) weight scales. Nearly free, supported nearly everywhere, and the largest single win.
  2. Per-token or per-group activation scales where the runtime supports them.
  3. Keep the first and last layers in higher precision. The stem sees raw input distribution and the head produces the output you are measuring; both are disproportionately sensitive and together they are a small fraction of the FLOPs.
  4. Run a per-layer sensitivity sweep and promote only what the sweep flags. Mixed precision guided by measurement beats a uniform policy chosen by taste.
  5. Only then consider QAT.

Calibration: representativeness, not volume

Post-training quantization needs activation statistics, which means running a calibration set through the network. Two things about this are consistently got wrong.

Size is not the issue. A few hundred samples is usually enough to estimate the statistics you need. Going from 256 to 2,048 samples rarely changes the resulting scales meaningfully.

Distribution is the issue. Calibrate on 1,000 clean, well-lit, centred images and you get scales tuned for a distribution your users do not produce. The failure then shows up as a tail — a small fraction of inputs with badly wrong outputs — while your mean accuracy metric looks fine. Tail failures are much worse in a product than a uniform small degradation, and mean-based evaluation is blind to them.

So: draw calibration data from production traffic, including the ugly end — dim rooms, motion blur, oblique angles, partial occlusion. Then evaluate on a held-out set that also contains the ugly end, and look at the error distribution rather than its mean.

INT4, and why the LLM results do not transfer

The published INT4 successes of the last few years come overwhelmingly from transformer language models, and they rest on a property those models have:

Autoregressive decoding is memory-bandwidth-bound. Weights dominate the traffic, so halving weight size roughly halves the time per token.

Convolutional vision models on mobile accelerators are frequently compute-bound instead. Shrinking weights from INT8 to INT4 reduces footprint — which is a real and sometimes decisive win for app download size and memory pressure — but buys much less latency, because you were not waiting on memory.

And the asymmetry between weights and activations holds:

ConfigurationVision viability
W8A8 per-channelProduction default
W4A8 (weight-only INT4)Viable; footprint win, modest latency win
W4A4Generally not — activation outliers make this expensive
W8A16 per-tensorOften worse than W8A8 per-channel, for more memory

Before adopting an INT4 plan from a language-model paper, establish whether you are bandwidth-bound. A roofline estimate takes an afternoon and saves a quarter.

The hardware constrains the strategy more than the literature does

This is where portable plans tend to die.

The operational consequence: profile the exact graph on the exact hardware, and instrument which delegate actually ran. A quantization result measured on a laptop, or on one flagship phone, predicts very little about your fleet. We covered the deployment side of this in on-device versus cloud inference.

A recipe that survives review

  1. Define the accuracy budget in output units, before quantizing. "Within 2% relative error on the regression head" is a budget. "No significant degradation" is not.
  2. Build the calibration set from production traffic, ugly end included, a few hundred samples.
  3. PTQ to per-channel W8A8. Measure.
  4. Keep stem and head in higher precision. Measure.
  5. Per-layer sensitivity sweep; promote only the flagged layers. Measure.
  6. Evaluate the error distribution, not the mean. Report the tail.
  7. Profile on the real target devices, asserting which delegate executed.
  8. QAT only if 3–5 missed the budget, and cost it as an ongoing pipeline rather than a one-off.

Related