llmcompressor.modifiers.quantization.quantization.base
QuantizationModifier
Bases: Modifier, QuantizationMixin
Enables post training quantization (PTQ) and quantization aware training (QAT) for a given module or its submodules. After calibration (PTQ) or the start epoch (QAT), the specified module(s) forward pass will emulate quantized execution and the modifier will be enabled until training is completed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_groups | dictionary specifying quantization schemes to apply to target modules. Modules not matching a scheme target will NOT be quantized. | required | |
targets | list of layer names to quantize if a scheme is provided. Defaults to Linear layers | required | |
ignore | optional list of module class names or submodule names to not quantize even if they match a target in config_groups. Defaults to empty list. | required | |
scheme | a single quantization scheme to apply to the model. This is a dictionary that supports all keys from QuantizationScheme except targets, which will be set to the targets parameter set at the modifier level. Can also be set to a dictionary of the format | required | |
kv_cache_scheme | optional QuantizationArgs, that specify the quantization of the kv cache. If None, kv cache is not quantized. When applying kv cache quantization to transformer AutoModelForCausalLM, the kv_cache_scheme gets converted into a QuantizationScheme that: - targets the | required |
Source code in llmcompressor/modifiers/quantization/quantization/base.py
on_end(state, event, **kwargs)
Finish calibrating by removing observers and calibration hooks
Source code in llmcompressor/modifiers/quantization/quantization/base.py
on_initialize(state, **kwargs)
Prepare to calibrate activations and weights
According to the quantization config, a quantization scheme is attached to each targeted module. The module's forward call is also overwritten to perform quantization to inputs, weights, and outputs.
Then, according to the module's quantization scheme, observers and calibration hooks are added. These hooks are disabled until the modifier starts.
Source code in llmcompressor/modifiers/quantization/quantization/base.py
on_start(state, event, **kwargs)
Begin calibrating activations and weights. Calibrate weights only once on start