Fake quantization

Also known as: simulated quantization

On this page 7

Fake quantization, also called simulated quantization, is an operation that rounds floating-point values to a low-precision integer grid and immediately converts them back to floating point, so that a model experiences quantization error while it still runs in full-precision arithmetic. In Edge AI, it is the core mechanism of quantization-aware training (QAT), which prepares neural networks to run accurately as INT8 or lower-precision models on phones, microcontrollers and neural processing units.

The name reflects that no real integer arithmetic takes place during training. The tensors remain in FP32 or BF16, but their values are restricted to the levels an integer format can represent, which lets gradient-based training adapt the weights to the precision loss that real integer inference will later introduce.

How fake quantization works

A fake quantization node performs a quantize-dequantize pair, often abbreviated QDQ. Given a real value x, a scale s and a zero point z, it computes the integer q = clamp(round(x / s) + z, q_min, q_max) and then returns the dequantized value s × (q − z). The output has the same data type as the input, but only a finite set of 2^b distinct values, where b is the bit width.

The difference between the input and the output is the quantization error, consisting of rounding error for values inside the representable range and clipping error for values outside it. Choosing the range is therefore a balance: a wide range reduces clipping but makes each step coarser.

ParameterRoleTypical setting
Bit widthNumber of integer levels8 bits, sometimes 4 or fewer
ScaleStep size between levelsDerived from observed range or learned
Zero pointInteger that represents real zero0 for symmetric, nonzero for asymmetric
GranularityHow many scales per tensorPer-tensor or per-channel
Range observerTracks minimum and maximumMoving average or histogram
Parameters of a fake quantization node

Fake quantization nodes are inserted wherever the deployed model will hold integers, typically on weights before each convolution or linear layer and on activations after each layer or fused block. Frameworks such as PyTorch and TensorFlow provide these nodes as built-in modules, and the resulting graph is later converted into a true integer model.

Gradients through rounding: the straight-through estimator

Rounding has a derivative of zero almost everywhere, so ordinary backpropagation through a fake quantization node would stop learning. The standard workaround is the straight-through estimator (STE), which treats the rounding step as the identity function in the backward pass.

In the common clipped variant, gradients pass through unchanged for inputs inside the quantization range and are set to zero for clipped inputs. The forward pass therefore sees the quantized values, while the backward pass behaves almost as if no quantization existed. This mismatch between forward and backward behavior is a known source of instability, especially at very low bit widths.

Methods such as learned step size quantization (LSQ) and PACT extend the idea by making the scale or clipping threshold a trainable parameter with its own gradient, allowing the network to learn the best range for each layer instead of relying only on observed statistics.

Fake quantization compared with real integer inference

Fake quantization is a training and simulation tool, not a deployment format. A model containing fake quantization nodes is no smaller or faster than the original; the savings appear only after conversion to an integer model in which weights are stored as integers and kernels execute integer arithmetic.

AspectFake quantizationReal integer inference
Storage typeFP32 or BF16 tensorsINT8, INT4 or similar
ArithmeticFloating-point operationsInteger multiply-accumulate
Model sizeUnchangedRoughly 4x smaller at INT8 versus FP32
SpeedSlightly slower than baselineFaster on supporting hardware
PurposeTrain or evaluate under quantizationDeploy on edge devices
Simulated versus real quantization

Because the two paths differ in accumulation width, operator fusion and rounding modes, a small numerical mismatch often remains between the simulated accuracy and the accuracy on the target device. Reliable workflows therefore validate the converted model on the actual runtime, not only the fake-quantized graph.

Where fake quantization fits in the quantization workflow

Fake quantization appears in more than one workflow. In quantization-aware training, it stays active during fine-tuning so that weights adapt. In post-training quantization, the same QDQ nodes can be used only for calibration and accuracy estimation, without any weight updates.

WorkflowRole of fake quantizationWhen to choose it
Post-training quantizationSimulate accuracy after calibrationQuick conversion, tolerant models
Quantization-aware trainingActive during fine-tuningAccuracy loss after PTQ is too high
Mixed-precision searchTest bit widths per layerTight memory or latency budget
QDQ model exportMark quantization points in the graphRuntimes that fuse QDQ into integer kernels
Uses of fake quantization across workflows

A common recipe starts from a pretrained floating-point model, folds batch normalization into the preceding layers, inserts fake quantization nodes, and fine-tunes for a small fraction of the original training schedule at a reduced learning rate. Observers are usually frozen after a few epochs so that the ranges stop moving while the weights settle.

Limitations and common mistakes

  • Mismatched fusion: simulating unfused layers when the runtime fuses convolution, batch normalization and activation produces misleading accuracy estimates.
  • Unfrozen observers: letting ranges drift until the end of training can destabilize convergence.
  • Ignoring unsupported operators: layers the target hardware cannot run in integer form fall back to floating point and erode the speedup.
  • Too few calibration samples: unrepresentative data produces poor activation ranges and large clipping error.
  • Assuming 8-bit results transfer to 4-bit: lower bit widths often need per-channel or group-wise scales and learned ranges.

Fake quantization also increases training cost, because each node adds computation and memory for observers. For very large language models, full quantization-aware training is often too expensive, which is why weight-only post-training methods are more common there, with fake quantization reserved for evaluation or targeted fine-tuning.

The simple explanation

Small devices such as phones run AI models faster when the numbers inside the model are rough whole numbers instead of precise decimals. Rounding, however, can make the model less accurate.

Fake quantization is a rehearsal for that rounding. During training, every number is rounded the way the device will round it, then turned back into a normal decimal. The model practices with imperfect numbers and learns to cope. It is like training for a race while wearing the same shoes you will wear on race day.

The rehearsal does not make the model smaller by itself. That happens later, when the model is converted for the device.

How it is used in practice

A team building a smart doorbell camera needs a person-detection model to run on a low-power neural accelerator that supports only INT8. After standard post-training quantization, the model loses about four points of detection accuracy, mostly on people seen at night.

The engineers insert fake quantization nodes with per-channel weight scales and fine-tune the network for three epochs on their own day and night footage, freezing the observers after the first epoch. They then convert the model to integer form and test it on the actual device, not only in the training framework.

The quantization-aware model recovers most of the lost accuracy, ending within about half a point of the floating-point original, while it runs at the frame rate and power budget the battery-powered doorbell requires.