llmcompressor.observers.mse
Classes:
-
MovingAverageMSEObserver–Compute quantization parameters by finding the optimal min/max values which minimize
MemorylessMSEObserver
Bases: Observer
Search candidate min/max ranges independently for each observed tensor.
For each candidate range, the observer computes the powered QDQ error
abs(QDQ(w) - w) ** norm and sums it over each quantization group. When
magnitude_normalization is enabled, each element's error is also
multiplied by sqrt(w**2 + group_absmax**2). The selected range is the
candidate with the lowest error. This observer does not average statistics
across calls; :class:MovingAverageMSEObserver smooths the selected ranges.
The options below are read from QuantizationArgs.observer_kwargs. The
expanded MSE observer inherits these options and overrides some defaults.
Observer kwargs:
maxshrink (float): Maximum fraction of the expanded range to shrink.
The linear grid tests multipliers 1 - i / grid for
i < maxshrink * grid. For the exponential grid, candidates are
powers of two starting at 1 and stop before shrinking past
1 - maxshrink. Defaults to 0.20.
patience (int): Number of consecutive candidates without strict
improvement before early stopping in the eager implementation.
Triton always evaluates the full grid. 0 scans the full grid.
Defaults to 5.
grid (float): Search resolution and candidate budget. For a linear
grid, adjacent multipliers differ by 1 / grid. For an
exponential grid, this is an upper bound on the number of
candidates. Defaults to 100.
norm (float): Power applied to the absolute QDQ error. 2 gives
squared error; defaults to 2.4.
expand (float): Multiplier applied to the observed min/max range before
shrink candidates are searched. Must be at least 1. Defaults
to 1.
grid_type (str or None): "linear" or "exponential". If
None, uses exponential spacing when MX scales are generated
(E8M0) and linear spacing otherwise. Exponential candidates are
1, 1/2, 1/4, ... times the expanded range. Defaults to None.
magnitude_normalization (bool): If true, multiply each powered error
by sqrt(w**2 + group_absmax**2), where group_absmax is the
largest absolute observed value in that quantization group.
Defaults to False.
averaging_constant (float): Additional option for the moving-average
mse observer only. Controls how much each newly selected range
contributes to the running range; defaults to 0.01.
Source code in src/llmcompressor/observers/mse.py
MovingAverageMSEObserver
Bases: Observer
Compute quantization parameters by finding the optimal min/max values which minimize the mean of quantization error squared, with moving average smoothing.
Source code in src/llmcompressor/observers/mse.py
NVFP4ExpandedMSEObserver
Bases: MemorylessMSEObserver
MSE observer with defaults tuned for NVFP4 range expansion.
Searches from expand times the observed range down to
(1 - maxshrink) * expand times the observed range.
With the defaults below, this covers 1.8x down to ~0.8x of
the original per-group range in 112 search steps.
Usage::
QuantizationArgs(
...
observer="nvfp4_expanded_mse",
)