llmcompressor.modeling.offset_norm
Calibration context for offset-norm layers.
Some architectures (Gemma, Qwen3Next) use an offset normalization pattern where
the forward pass computes output * (1 + weight) instead of the standard
output * weight. This breaks any modifier that smooths norm weights
(AWQ, SmoothQuant, SpinQuant) because dividing a (1+weight) parameter by scales
produces incorrect results.
This module provides the infrastructure to temporarily replace offset-norm modules with standard-norm equivalents during calibration, and restore the original convention after modifiers have run.
Key components: - NormCalibrationModule: Abstract base class for norm calibration modules - norm_calibration_context: Context manager that applies norm conversion
Classes:
-
NormCalibrationModule–Abstract base class for norm calibration modules.
Functions:
-
norm_calibration_context–Context manager that converts offset-norm modules to standard-norm.
CalibrationOffsetNorm
Bases: NormCalibrationModule
Replaces offset-norm modules (output * (1 + weight)) with standard-norm
equivalents (output * weight) during calibration.
On enter: self.weight = 1 + original.weight
On restore: original.weight = self.weight - 1
Source code in src/llmcompressor/modeling/offset_norm.py
NormCalibrationModule
Bases: ABC, Module, RegistryMixin
Abstract base class for norm calibration modules.
Calibration modules replace original norm modules during the calibration
phase so that modifiers see standard output * weight semantics.
Methods:
-
restore–Restore the original module with updated weights.
restore
abstractmethod
Restore the original module with updated weights.
Returns: The original module with weights converted back to offset convention
Source code in src/llmcompressor/modeling/offset_norm.py
norm_calibration_context
Context manager that converts offset-norm modules to standard-norm.
This scans all modules in the model and replaces any offset-norm modules
(output * (1 + weight)) with standard-norm equivalents
(output * weight). After the context exits, modules are restored
to their original convention with updated weights.
The model is modified in-place, so the same model object should be used within the context.
Args: model: The model to apply norm conversion to (modified in-place)
Example: with norm_calibration_context(model): # Modifiers see standard norm weights run_calibration(model) # Norms restored to offset convention with smoothed weights