Practice in Lab: Train through per-channel fake quantization and saturation →
Train through per-channel fake quantization and saturation
Quantization-aware training simulates rounding during training so the model can adapt to a finite grid. Rounding has almost-everywhere zero derivative; a declared straight-through rule supplies the training surrogate. Saturation still needs a policy: this exercise passes gradients inside the representable interval and stops them outside it. Per-channel scales prevent one large output row from determining every row’s resolution. The result remains floating point and is not evidence of compressed storage, integer execution or faster inference.
Prepare offline
Choose Download entire course or Download entire category first. After completion, code and checks run locally on CPU. The independent example needs no account, remote service or API key.
import torch
x = torch.tensor([.5, 1.5, 2.5])
print(x.round())Review the evidence
Inspect clipping rates, the scale calibration set and post-conversion error separately. Compare a floating baseline with a real deployed quantized runtime before claiming memory or latency savings.
Your task
Implement symmetric signed per-output-channel fake quantization of floating [out,in] weights with qmax=2**(bits-1)-1 and qmin=-qmax, bits in 2..8. Infer detached scales=max(abs(channel))/qmax with floor 1e-8, or accept explicit finite positive detached [out] scales. Round ties to even, simulate quantize/dequantize in floating point and use straight-through rounding with zero gradient outside the clipping interval. Return a floating tensor; this is QAT simulation, not a packed int8 kernel or a speed benchmark.
The explanation opens here once every check passes.