QParams
QParams(scale: Tensor, zero_point: Tensor, qscheme: QScheme, qdtype: QDtype, ch_axis: int | None = None)Immutable bundle of everything that defines a quantized tensor's grid.
A quantized tensor in Lucid's sidecar representation is an ordinary integer
lucid.Tensor plus the metadata needed to interpret its codes as real
numbers. QParams is that metadata gathered into one frozen value object:
the scale / zero_point produced by calibration, together with the
lucid.quantization.QScheme (grid geometry) and
lucid.quantization.QDtype (grid range) they were derived under, plus the
channel axis for per-channel schemes.
It is the return-shape of an observer's calibration: an observer records a range,
calls calculate_qparams to get (scale, zero_point), and packages the
result — with the scheme / dtype it used — into a QParams so downstream
quantize / dequantize / fake-quant calls have a single self-describing object to
read from.
Attributes
scaleTensorC vector for per-channel schemes.zero_pointTensorscale.qschemeQSchemeqdtypeQDtype[quant_min, quant_max]) the codes
clamp to.ch_axisint or None, default NoneNone for per-tensor.Notes
- Frozen (
@dataclass(frozen=True)): aQParamsis a value, safe to share and compare; re-calibration produces a new instance rather than mutating one. scaleandzero_pointalways share a shape, and it is that shape (scalar vs length-C) — notqschemealone — that a kernel broadcasts against.- The pair is consumed by
lucid.quantization.quantize/lucid.quantization.dequantize/lucid.quantization.fake_quantize, which broadcastscale/zero_pointalongch_axis.
Examples
>>> import lucid.quantization as Q
>>> scale, zp = Q.calculate_qparams(-2.0, 6.0, Q.per_tensor_affine, Q.quint8)
>>> p = Q.QParams(scale, zp, Q.per_tensor_affine, Q.quint8)
>>> p.qscheme.is_per_channel, p.ch_axis
(False, None)
>>> round(float(p.scale.item()), 4) # (6 - (-2)) / 255
0.0314See Also
calculate_qparams—Derives thescale/zero_pointaQParamsholds.- lucid.quantization.QScheme—The grid-geometry field.
- lucid.quantization.QDtype—The grid-range field.