qubee.configs.quantization_config¶
CalibrationConfig¶
Configuration for calibration during quantization.
Defines calibration and quantization parameterization used to derive activation/weight scales and related statistics during quantized compilation.
Attributes¶
| Name | Description |
|---|---|
optional |
|
method_list |
|
output_list |
|
mode_list |
|
DEFAULTS |
|
py_to_cpp_name |
|
min_max_check |
optional¶
method_list¶
output_list¶
mode_list¶
mode_list = [
"percentile",
"max",
"maxPercentile",
"fastPercentile",
"histogramKL",
"histogramMSE",
]
DEFAULTS¶
DEFAULTS = {
"quantization_method": 1,
"quantization_output": 0,
"quantization_mode": 2,
"percentile": 0.9999,
"topk_ratio": 0.01,
"max_each": 128,
"max_total": 65536,
"kernel_size": 9,
"stack_size": 32768,
"hist_num_cluster": 4,
"hist_search_percentile_min": 0.9999,
"hist_epsilon": 0.01,
"hist_adjust_coeff": 0.5,
"act_scale_min": 0.0005,
"weight_scale_min": 1e-6,
"min_clip_ratio": -1,
"layer_overrides": {"actScaleMin": {"0.0005": []}},
}
py_to_cpp_name¶
py_to_cpp_name = {
"quantization_method": "method",
"quantization_output": "output",
"quantization_mode": "mode",
"percentile": "percentile",
"topk_ratio": "topKRatio",
"max_each": "maxEach",
"max_total": "maxTotal",
"kernel_size": "kernelSize",
"stack_size": "stackSize",
"hist_num_cluster": "numCluster",
"hist_search_percentile_min": "searchPercentileMin",
"hist_epsilon": "epsilon",
"hist_adjust_coeff": "adjustCoeff",
"act_scale_min": "actScaleMin",
"weight_scale_min": "weightScaleMin",
"min_clip_ratio": "minClipRatio",
}
min_max_check¶
min_max_check = {
"quantization_method": [0, 3],
"quantization_output": [0, 2],
"quantization_mode": [0, 5],
"percentile": [0, 1],
"topk_ratio": [0, 1],
"max_each": [0, None],
"max_total": [0, None],
"kernel_size": [0, None],
"stack_size": [0, None],
"hist_num_cluster": [0, None],
"hist_search_percentile_min": [0, 1],
"hist_epsilon": [0, 1],
"hist_adjust_coeff": [0, None],
"act_scale_min": [0, 1],
"weight_scale_min": [0, 1],
"min_clip_ratio": [-1, 1],
}
Methods¶
| Name | Description |
|---|---|
__init__ |
Initialize the CalibrationConfig. |
default_config |
|
from_kwargs |
|
from_dict |
Create CalibrationConfig from dictionary (JSON structure) |
to_dict |
__init__¶
def __init__(
self,
quantization_method: int,
quantization_output: int,
quantization_mode: int,
percentile: numbers.Number,
topk_ratio: numbers.Number,
max_each: int,
max_total: int,
kernel_size: int,
stack_size: int,
hist_num_cluster: int,
hist_search_percentile_min: numbers.Number,
hist_epsilon: numbers.Number,
hist_adjust_coeff: numbers.Number,
act_scale_min: numbers.Number,
weight_scale_min: numbers.Number,
min_clip_ratio: numbers.Number,
layer_overrides: Dict,
optional: bool = optional,
)
Initialize the CalibrationConfig.
Parameters
quantization_method— int. Calibration method index:
0: WChALayer - Weight per-channel, Activation per-layer.
1: WChAMulti - Weight per-channel, Activation multi-layer.
2: WChALayerZeropoint - Weight per-channel, Activation per-layer with zeropoint.
3: WChAMultiZeropoint - Weight per-channel, Activation multi-layer with zeropoint.quantization_output— int. Output quantization type index:
0: Layer - Per-layer quantization.
1: Ch - Per-channel quantization.
2: Sigmoid - Sigmoid-based quantization.quantization_mode— int. Quantization mode index:
0: percentile.
1: max.
2: maxPercentile.
3: fastPercentile.
4: histogramKL.
5: histogramMSE.percentile— float. Percentile value used whenquantization_modeis 0 (percentile).topk_ratio— float. Top-k ratio used whenquantization_modeis 2 (maxPercentile).max_each— int. Maximum number of samples processed per iteration.max_total— int. Total maximum number of samples processed across all iterations.kernel_size— int. Kernel size used for fast distribution estimation (typically forquantization_mode3).stack_size— int. Stack size used for fast distribution estimation (typically forquantization_mode3).hist_num_cluster— int. Number of clusters/bins used in histogram-based calibration modes.hist_search_percentile_min— float. Minimum search percentile for histogram-based calibration.hist_epsilon— float. Numerical epsilon used in histogram-based calibration to avoid instability.hist_adjust_coeff— float. Adjustment coefficient applied in histogram-based calibration.act_scale_min— float. Minimum allowed activation scale (lower bound clamp).weight_scale_min— float. Minimum allowed weight scale (lower bound clamp).min_clip_ratio— float. Minimum clip ratio constraint applied during calibration.layer_overrides— Dict. Layer-specific override settings. Keys are layer identifiers; values override one or more calibration parameters for the specified layer.optional— bool. Indicates whether this config is optional. Use the default value defined as a class variable.
default_config¶
from_kwargs¶
from_dict¶
Create CalibrationConfig from dictionary (JSON structure)
to_dict¶
BitConfig¶
Configuration for bit precision.
Defines bit-width parameterization for activations and weights used in mixed-precision quantization (e.g., attention and FFN components).
Attributes¶
| Name | Description |
|---|---|
optional |
|
DEFAULTS |
|
py_to_cpp_name |
|
min_max_check |
optional¶
DEFAULTS¶
DEFAULTS = {
"query_act_bits": 8,
"key_act_bits": 8,
"value_act_bits": 8,
"output_act_bits": 16,
"ffn_act_bits": 16,
"head_act_bits": 8,
"query_weight_bits": 8,
"key_weight_bits": 8,
"value_weight_bits": 8,
"output_weight_bits": 8,
"ffn_weight_bits": 8,
"head_weight_bits": 8,
"mixed_precision_apply": False,
"save_path": "",
"load_path": "",
"activation_16bits": [],
"weight_16bits": [],
}
py_to_cpp_name¶
py_to_cpp_name = {
"query_act_bits": "queryActBits",
"key_act_bits": "keyActBits",
"value_act_bits": "valueActBits",
"output_act_bits": "outputActBits",
"ffn_act_bits": "ffnActBits",
"head_act_bits": "headActBits",
"query_weight_bits": "queryWeightBits",
"key_weight_bits": "keyWeightBits",
"value_weight_bits": "valueWeightBits",
"output_weight_bits": "outputWeightBits",
"ffn_weight_bits": "ffnWeightBits",
"head_weight_bits": "headWeightBits",
"mixed_precision_apply": "mixedPrecisionApply",
"save_path": "savePath",
"load_path": "loadPath",
}
min_max_check¶
min_max_check = {
"query_act_bits": [1, None],
"key_act_bits": [1, None],
"value_act_bits": [1, None],
"output_act_bits": [1, None],
"ffn_act_bits": [1, None],
"head_act_bits": [1, None],
"query_weight_bits": [1, None],
"key_weight_bits": [1, None],
"value_weight_bits": [1, None],
"output_weight_bits": [1, None],
"ffn_weight_bits": [1, None],
"head_weight_bits": [1, None],
}
Methods¶
| Name | Description |
|---|---|
__init__ |
Initialize the BitConfig. |
default_config |
|
from_kwargs |
|
from_dict |
Create BitConfig from dictionary (JSON structure) |
to_dict |
__init__¶
def __init__(
self,
query_act_bits: int,
key_act_bits: int,
value_act_bits: int,
output_act_bits: int,
ffn_act_bits: int,
head_act_bits: int,
query_weight_bits: int,
key_weight_bits: int,
value_weight_bits: int,
output_weight_bits: int,
ffn_weight_bits: int,
head_weight_bits: int,
mixed_precision_apply: bool,
save_path: str,
load_path: str,
activation_16bits: List[str],
weight_16bits: List[str],
optional: bool = optional,
)
Initialize the BitConfig.
Parameters
query_act_bits— int. Query activation bit-width.key_act_bits— int. Key activation bit-width.value_act_bits— int. Value activation bit-width.output_act_bits— int. Output activation bit-width.ffn_act_bits— int. FFN activation bit-width.head_act_bits— int. Head activation bit-width.query_weight_bits— int. Query weight bit-width.key_weight_bits— int. Key weight bit-width.value_weight_bits— int. Value weight bit-width.output_weight_bits— int. Output weight bit-width.ffn_weight_bits— int. FFN weight bit-width.head_weight_bits— int. Head weight bit-width.mixed_precision_apply— bool. If true, apply mixed-precision according to the specified bit-widths.save_path— str. (optional) Path to save the bit allocation. If empty, the allocation is not saved.load_path— str. (optional) Path to load the bit allocation. If empty, allocation is not loaded.activation_16bits— List[str]. (optional) Layer names to force 16-bit activations.weight_16bits— List[str]. (optional) Layer names to force 16-bit weights.
default_config¶
from_kwargs¶
from_dict¶
Create BitConfig from dictionary (JSON structure)
to_dict¶
QuantizationConfig¶
Unified quantization configuration.
Groups calibration and bit-precision configurations into a single configuration.
Attributes¶
| Name | Description |
|---|---|
optional |
|
py_to_cpp_name |
|
min_max_check |
optional¶
py_to_cpp_name¶
min_max_check¶
Methods¶
| Name | Description |
|---|---|
__init__ |
Initialize the QuantizationConfig. |
default_config |
|
from_kwargs |
|
from_dict |
|
to_dict |
__init__¶
def __init__(
self,
optional: bool,
calibration: Optional[CalibrationConfig] = None,
bit: Optional[BitConfig] = None,
)
Initialize the QuantizationConfig.
Parameters
calibration— CalibrationConfig. Calibration configuration.bit— BitConfig. Bit precision configuration.
default_config¶
from_kwargs¶
from_dict¶
to_dict¶
Functions¶
| Name | Description |
|---|---|
get_calibration_config |
Create CalibrationConfig with partial parameters merged with defaults. |
get_bit_config |
Create BitConfig with partial parameters merged with defaults. |
get_quantization_config |
Create QuantizationConfig with partial parameters merged with defaults. |
get_calibration_config¶
Create CalibrationConfig with partial parameters merged with defaults.
get_bit_config¶
Create BitConfig with partial parameters merged with defaults.
get_quantization_config¶
def get_quantization_config(
calibration: Optional[CalibrationConfig] = None,
bit: Optional[BitConfig] = None,
) -> QuantizationConfig
Create QuantizationConfig with partial parameters merged with defaults.