mode
This module contains the mode descriptor for the quantization mode.
Classes
Base class for quantization calibration algorithm modes. |
- class BaseCalibrateModeDescriptor
Bases:
ModeDescriptor
Base class for quantization calibration algorithm modes.
All calibration algorithm modes must be derived from this base class. In addition, the config_class for the mode must return a subclass of
QuantizeAlgorithmConfig
.This base class also provides some convenient wrappers/utilities for calibration algorithms to be translated into ModelOpt mode.
- It includes:
- A utility to convert the algorithm name to a mode name. This is useful since many algorithm names
are trivial and not a good fit as a mode name. For example,
"max"
orNone
.
- Conversion of the
algorithm
andkwargs
arguments of calibrate
API to a mode config list compatible withapply_mode
.
- Conversion of the
- Wrapper for the calibration functions in
modelopt.torch.quantization.model_calib
to be compatible with the ModelOpt convert entrypoint.
- Wrapper for the calibration functions in
- __init__(*args, **kwargs)
Initialize Base calibrate mode descriptor.
- abstract property config_class: type[QuantizeAlgorithmConfig]
Specifies the config class for the mode.
- property convert: Callable[[Module, ModeloptBaseConfig], tuple[Module, dict[str, Any]]] | Callable[[Module, ModeloptBaseConfig, Any], tuple[Module, dict[str, Any]]]
The calibrate algorithm mode’s entrypoint for converting a model.
This method is called by the ModelOpt framework when applying this calibration mode to a model. See
wrapped_calib_func()
for more details on the logic.Note: Subclasses must specify the _calib_func class attribute with the appropriate calibration function to be used or override this method.
- property name: str
Returns the value (str representation) of the mode.
- property restore: Callable[[Module, ModeloptBaseConfig, dict[str, Any]], Module]
The mode’s entrypoint for restoring a model.
- property update_for_new_mode: Callable[[Module, ModeloptBaseConfig, dict[str, Any]], None]
The mode’s entrypoint for updating the models state before new mode.
- property update_for_save: Callable[[Module, ModeloptBaseConfig, dict[str, Any]], None]
The mode’s entrypoint for updating the models state before saving.