Skip to main content
Quantization-Aware Training (QAT) fine-tunes a model with quantization simulated during training. The model learns to cope with lower precision, recovering accuracy that post-training quantization (PTQ) often loses, especially at low bit widths. Unlike PTQ, QAT does train, so it costs a training run on GPU and needs representative images. The training runs on the R3AL platform; the SDK uploads your model and images and downloads the quantized result.
QAT uses MSE on the model output to update weights and quantization thresholds to restore accuracy.

Minimal call

Defaults: epochs=1, qat_wbit=8, qat_abit=8.

What happens on the platform

QAT is a black box you drive with a few parameters. End to end:
1

You provide the model and images

Upload your ONNX model (or a checkpoint the SDK exports first) and a representative set of calibration images.
2

The engine fine-tunes with quantization in the loop

R3AL’s engine trains the model on GPU with lower precision simulated during the forward pass, and automatically protects accuracy-sensitive layers.
3

You get a standard quantized ONNX bundle

The engine exports a standard quantized ONNX model plus r3alai_manifest.json, downloaded into your output_dir.

Key fields

epochs

How many times the model trains over your calibration data.

qat_wbit: weight bits

Precision of the model’s weights.
  • 8: safe default
  • 4: aggressive, roughly 4x smaller weights, needs QAT to recover accuracy
  • 3: very aggressive, only with QAT and enough epochs
Set it on the config: QuantConfig(qat_wbit=...).

qat_abit: activation bits

Precision of the intermediate tensors (layer outputs). Activations typically have different value ranges than weights, so you can set qat_abit independently:
  • qat_wbit=4, qat_abit=8: aggressive weight compression, safer activations
  • qat_wbit=8, qat_abit=8: conservative, minimal accuracy risk (recommended starting point)
Set it on the config: QuantConfig(qat_abit=...).

Full example

Calibration images for QAT

QAT uses calibration_data for both calibration and training, unlike PTQ where calibration is only a measurement pass. Calibration runs first and sets each layer’s starting clip threshold; training then tunes those thresholds together with the weights. qat_calib_method chooses how the starting value is derived: percentile (the default, at quantile qat_calib_q), max, or entropy.
Use images that match your production distribution. Random unrelated photos teach the model the wrong ranges and hurt accuracy.
See Calibration for building a good image set.