QuantizationConfig¶
Class to configure the quantization process of the model:
- class model_compression_toolkit.core.QuantizationConfig(activation_error_method=QuantizationErrorMethod.MSE, weights_error_method=QuantizationErrorMethod.MSE, relu_bound_to_power_of_2=False, weights_bias_correction=True, weights_second_moment_correction=False, input_scaling=False, softmax_shift=False, shift_negative_activation_correction=True, activation_channel_equalization=False, z_threshold=math.inf, min_threshold=MIN_THRESHOLD, l_p_value=2, linear_collapsing=True, residual_collapsing=True, shift_negative_ratio=0.05, shift_negative_threshold_recalculation=False, shift_negative_params_search=False, concat_threshold_update=False)¶
Class to wrap all different parameters the library quantize the input model according to.
- Parameters:
activation_error_method (QuantizationErrorMethod) – Which method to use from QuantizationErrorMethod for activation quantization threshold selection.
weights_error_method (QuantizationErrorMethod) – Which method to use from QuantizationErrorMethod for activation quantization threshold selection.
relu_bound_to_power_of_2 (bool) – Whether to use relu to power of 2 scaling correction or not.
weights_bias_correction (bool) – Whether to use weights bias correction or not.
weights_second_moment_correction (bool) – Whether to use weights second_moment correction or not.
input_scaling (bool) – Whether to use input scaling or not.
softmax_shift (bool) – Whether to use softmax shift or not.
shift_negative_activation_correction (bool) – Whether to use shifting negative activation correction or not.
activation_channel_equalization (bool) – Whether to use activation channel equalization correction or not.
z_threshold (float) – Value of z score for outliers removal.
min_threshold (float) – Minimum threshold to use during thresholds selection.
l_p_value (int) – The p value of L_p norm threshold selection.
block_collapsing (bool) – Whether to collapse block one to another in the input network
shift_negative_ratio (float) – Value for the ratio between the minimal negative value of a non-linearity output to its activation threshold, which above it - shifting negative activation should occur if enabled.
shift_negative_threshold_recalculation (bool) – Whether or not to recompute the threshold after shifting negative activation.
shift_negative_params_search (bool) – Whether to search for optimal shift and threshold in shift negative activation.
Examples
One may create a quantization configuration to quantize a model according to. For example, to quantize a model’s weights and activation using thresholds, such that weights threshold selection is done using MSE, activation threshold selection is done using NOCLIPPING (min/max), enabling relu_bound_to_power_of_2, weights_bias_correction, one can instantiate a quantization configuration:
>>> import model_compression_toolkit as mct >>> qc = mct.core.QuantizationConfig(activation_error_method=mct.core.QuantizationErrorMethod.NOCLIPPING, weights_error_method=mct.core.QuantizationErrorMethod.MSE, relu_bound_to_power_of_2=True, weights_bias_correction=True)
The QuantizationConfig instanse can then be passed to
keras_post_training_quantization()