Skip to content
fn

get_default_qconfig

→QConfig
get_default_qconfig()

Return the standard static post-training-quantization recipe.

The recipe to reach for first when quantizing a trained float model for int8 inference without any fine-tuning. It pairs the two schemes the literature and the reference framework have settled on as the accuracy-preserving default for convolution / linear stacks:

  • Activations — a per-tensor-affine quint8 HistogramObserver. Activations are fed through a histogram so the calibrated (scale, zero_point) minimizes quantization error under the observed distribution rather than merely clamping to min/max; this matters because activations are typically heavy-tailed (a few large outliers would otherwise stretch the grid and starve the bulk of the mass of resolution). The affine (asymmetric) grid with a free zero_point fits post-ReLU ranges that start at 0 without wasting half the codes on negatives.
  • Weights — a per-channel-symmetric qint8 PerChannelMinMaxObserver on ch_axis=0. Each output channel gets its own scale, so channels with very different magnitudes are each tracked tightly; the symmetric grid pins zero_point to 0, which the low-precision GEMM kernels assume for the weight operand.

Returns

QConfig

A recipe whose activation factory builds a histogram observer and whose weight factory builds a per-channel min/max observer.

Notes

  • This is the global recipe installed by get_default_qconfig_mapping; override it per-type or per-name through a QConfigMapping when a specific layer needs different treatment (or should stay in float).
  • Both fields are with_args factories, so lucid.quantization.prepare builds an independent observer at every site (see QConfig).
  • The activation histogram is costlier to calibrate than a plain min/max observer but is the single biggest lever on PTQ accuracy for real activations; swap in a MinMaxObserver only when calibration speed dominates.

Examples

>>> import lucid.nn as nn
>>> import lucid.quantization as Q
>>> qcfg = Q.get_default_qconfig()
>>> type(qcfg.activation()).__name__
'HistogramObserver'
>>> type(qcfg.weight()).__name__
'PerChannelMinMaxObserver'
>>> # Apply it globally, then keep every Linear in float:
>>> mapping = (Q.QConfigMapping()
...     .set_global(qcfg)
...     .set_object_type(nn.Linear, None))

See Also

  • get_default_qat_qconfig—The QAT counterpart (same schemes, FakeQuantize-wrapped).
  • get_default_qconfig_mapping—Installs this recipe as a model-wide mapping.
  • QConfig—The recipe object this returns.

Used by 1