Simplified Quantization Configuration File
To automatically control the quantization process, for example, to specify whether individual layers are quantized and which quantization algorithm to adopt, you can use the configuration file (.cfg).
Parameter |
Required/Optional |
Type |
Field |
Description |
|---|---|---|---|---|
AMCTConfig |
- |
- |
- |
Simplified AMCT-based PTQ configuration. |
Optional |
Boolean |
activation_offset |
Whether offset is enabled for activation quantization. It is a global configuration parameter.
|
|
Optional |
Boolean |
joint_quant |
Whether to perform joint quantization for Eltwise. The default value is false, indicating that joint quantization is disabled. When it is set to true, performance may improve for some networks at the cost of accuracy degradation. |
|
repeated |
String |
skip_layers |
Layers to skip quantization. |
|
repeated |
String |
skip_layer_types |
Types of layers to skip quantization. |
|
Optional |
int32 |
version |
Version of the simplified configuration file. |
|
Optional |
CalibrationConfig |
common_config |
Common quantization configuration, which is a global parameter. This configuration is used if a layer is not overridden by override_layer_types or override_layer_configs. Parameter priority: override_layer_configs > override_layer_types > common_config |
|
repeated |
OverrideLayerType |
override_layer_types |
Types of layers to be overridden. It is used to specify which layers use differentiated quantization. By using this parameter, you can perform differentiated quantization on some layers by changing the quantization factor search step from 0.01 to 0.02. Parameter priority: override_layer_configs > override_layer_types > common_config |
|
repeated |
OverrideLayer |
override_layer_configs |
Layer to override. It is used to specify which layers use differentiated quantization. By using this parameter, you can perform differentiated quantization on some layers by changing the quantization factor search step from 0.01 to 0.02. Parameter priority: override_layer_configs > override_layer_types > common_config |
|
Optional |
Boolean |
do_fusion |
Whether to enable BN fusion. The default value is true, indicating that BN fusion is enabled. |
|
repeated |
String |
skip_fusion_layers |
Layers to skip BN fusion. |
|
repeated |
TensorQuantize |
tensor_quantize |
Nodes whose input tensors undergo tensor quantization in PTQ for improved inference performance during data movement. Currently, tensor quantization can be performed only on the MaxPool/Add/Eltwise operator. |
|
OverrideLayerType |
Required |
String |
layer_type |
Quantizable layer type. |
Required |
CalibrationConfig |
calibration_config |
Quantization configuration for override. |
|
OverrideLayer |
- |
- |
- |
Quantization configuration for override by layer. |
Required |
String |
layer_name |
Layer to override. |
|
Required |
CalibrationConfig |
calibration_config |
Quantization configuration for override. |
|
CalibrationConfig |
- |
- |
- |
Calibration-based quantization configuration. |
- |
ARQuantize |
arq_quantize |
Weight quantization algorithm configuration. arq_quantize: ARQ algorithm configuration. |
|
- |
FMRQuantize |
ifmr_quantize |
Activation quantization algorithm configuration. ifmr_quantize: IFMR algorithm configuration. |
|
Optional |
Boolean |
weight_compress_only |
Whether to perform weight-only quantization. In weight-only quantization scenarios, the supported data types must be float32 and float16.
|
|
ARQuantize |
- |
- |
- |
ARQ algorithm configuration. |
Optional |
Boolean |
channel_wise |
Whether to use different quantization factors for each channel.
|
|
Optional |
Boolean |
asymmetric |
Whether to perform asymmetric quantization on weights. It is used to select the layer-wise quantization algorithm. This parameter is valid only when weight_compress_only is set to true. If weight_compress_only is set to false, asymmetric can only be set to false.
If this parameter is set for override_layer_configs, override_layer_types, and common_config, the priority is as follows: override_layer_configs > override_layer_types > common_config |
|
Optional |
uint32 |
quant_bits |
Weight quantization bit width. The value can be INT6, INT7, or INT8 (default). This field can be set to INT6 or INT7 only for Conv2d operators. If quant_bits is set to INT6 or INT7 in common_config, the setting takes effect only for Conv2d operators. For other operators, the default value INT8 is used. For the ONNX network model, if quant_bits of the Conv operator is set to INT6 or INT7 in override_layer_types, the setting takes effect only when weight dim is 4. |
|
FMRQuantize |
- |
- |
- |
FMR algorithm configuration for activation quantization. |
Optional |
float |
search_range_start |
Start of the quantization factor search range. |
|
Optional |
float |
search_range_end |
End of the quantization factor search range. |
|
Optional |
float |
search_step |
Quantization factor search step. |
|
Optional |
float |
max_percentile |
Upper percentile for threshold search. |
|
Optional |
float |
min_percentile |
Lower percentile for threshold search. |
|
Optional |
Boolean |
asymmetric |
Whether to perform asymmetric quantization on activations. It is used to select the layer-wise quantization algorithm.
If this parameter is set for override_layer_configs, override_layer_types, and common_config, or if activation_offset is set, the priority is as follows: override_layer_configs > override_layer_types > common_config > activation_offset |
|
Optional |
CalibrationDataType |
dst_type |
Quantization bit width for activation quantization, either INT8 (default) or INT16 quantization. The current version supports only INT8 quantization. |
|
TensorQuantize |
- |
- |
- |
Configuration for input tensors requiring PTQ. |
Required |
String |
layer_name |
Name of the node whose input tensors require PTQ. Currently, only the input tensors of the MaxPool operator can be quantized. |
|
Required |
uint32 |
input_index |
Input index of the node whose input tensors require PTQ. |
|
- |
FMRQuantize |
ifmr_quantize |
Activation quantization algorithm configuration. ifmr_quantize: IFMR algorithm configuration. The IFMR quantization algorithm is used by default. |
- The following is an example of the simplified configuration file (quant.cfg) for uniform quantization. Set Optype to an Ascend IR–defined operator type. For details about the mapping, see Quantifiable Layers and Constraints.
# global quantize parameter activation_offset : true joint_quant : false enable_auto_nuq : false version : 1 skip_layers : "Optype" skip_layer_types: "Optype" do_fusion: true skip_fusion_layers : "Optype" common_config : { arq_quantize : { channel_wise : true quant_bits : 7 } ifmr_quantize : { search_range_start : 0.7 search_range_end : 1.3 search_step : 0.01 max_percentile : 0.999999 min_percentile : 0.999999 asymmetric : true } } override_layer_types : { layer_type : "Optype" calibration_config : { arq_quantize : { channel_wise : false } ifmr_quantize : { search_range_start : 0.8 search_range_end : 1.2 search_step : 0.02 max_percentile : 0.999999 min_percentile : 0.999999 asymmetric : false } } } override_layer_configs : { layer_name : "Opname" calibration_config : { arq_quantize : { channel_wise : true } ifmr_quantize : { search_range_start : 0.8 search_range_end : 1.2 search_step : 0.02 max_percentile : 0.999999 min_percentile : 0.999999 asymmetric : false } } } tensor_quantize { layer_name: "Opname" input_index: 0 ifmr_quantize: { search_range_start : 0.7 search_range_end : 1.3 search_step : 0.01 min_percentile : 0.999999 asymmetric : false } } tensor_quantize { layer_name: "Opname" input_index: 0 } - The following is an example of the simplified configuration file for weight-only quantization (quant.cfg):
activation_offset : true joint_quant : false version : 1 do_fusion: true common_config : { weight_compress_only : true arq_quantize : { channel_wise : true asymmetric : false } } override_layer_types : { layer_type : "Optype" calibration_config : { weight_compress_only : true arq_quantize : { channel_wise : true asymmetric : true quant_bits : 6 } } } override_layer_configs : { layer_name : "Opname" calibration_config : { weight_compress_only : true arq_quantize : { channel_wise : true asymmetric : true } } }