昇腾社区首页
中文
注册

简易配置文件

表1 calibration_config.proto参数说明

消息

是否必填

类型

字段

说明

AMCTConfig

-

-

-

昇腾模型压缩工具训练后量化的简易配置。

optional

bool

activation_offset

数据量化是否带offset。全局配置参数。

  • 带offset:数据量化使用非对称量化。
  • 不带offset:数据量化使用对称量化。

repeated

string

skip_layers

不需要量化层的层名。

repeated

string

skip_layer_types

不需要量化的层类型。

optional

int32

version

简易配置文件的版本。

optional

CalibrationConfig

common_config

通用的量化配置,全局量化配置参数。若某层未被override_layer_types或者override_layer_configs重写,则使用该配置。

参数优先级:override_layer_configs>override_layer_types>common_config

repeated

OverrideLayerType

override_layer_types

重写某一类型层的量化配置,即对哪些层进行差异化量化。

例如全局量化配置参数配置的量化因子搜索步长为0.01,可以通过该参数对部分层进行差异化量化,可以配置搜索步长为0.02。

参数优先级:override_layer_configs>override_layer_types>common_config

repeated

OverrideLayer

override_layer_configs

重写某一层的量化配置,即对哪些层进行差异化量化。

例如全局量化配置参数配置的量化因子搜索步长为0.01,可以通过该参数对部分层进行差异化量化,可以配置搜索步长为0.02。

参数优先级:override_layer_configs>override_layer_types>common_config

optional

bool

do_fusion

是否开启BN融合功能,默认为true,表示开启该功能。

repeated

string

skip_fusion_layers

跳过bn融合的层,配置之后这些层不会进行bn融合。

OverrideLayerType

required

string

layer_type

支持量化的层类型的名称。

required

CalibrationConfig

calibration_config

重置的量化配置。

OverrideLayer

-

-

-

重置某层量化配置。

required

string

layer_name

被重置层的层名。

required

CalibrationConfig

calibration_config

重置的量化配置。

CalibrationConfig

-

-

-

Calibration量化的配置。

-

ARQuantize

arq_quantize

权重量化算法配置。

arq_quantize:ARQ量化算法配置。

-

FMRQuantize

ifmr_quantize

数据量化算法配置。

ifmr_quantize:IFMR量化算法配置。

ARQuantize

-

-

-

ARQ量化算法配置。

optional

bool

channel_wise

是否对每个channel采用不同的量化因子。

  • true:每个channel独立量化,量化因子不同。
  • false:所有channel同时量化,共享量化因子。

FMRQuantize

-

-

-

FMR量化算法配置。

optional

float

search_range_start

量化因子搜索范围左边界。

optional

float

search_range_end

量化因子搜索范围右边界。

optional

float

search_step

量化因子搜索步长。

optional

float

max_percentile

最大值搜索位置。

optional

float

min_percentile

最小值搜索位置。

optional

bool

symmetric

是否进行对称量化。用于控制逐层量化算法的选择。

  • true:对称量化
  • false:非对称量化

如果override_layer_configs、override_layer_types、common_config配置项都配置该参数,或者配置了

activation_offset参数,则生效优先级为:

override_layer_configs>override_layer_types>common_config>activation_offset

基于该文件构造的简易配置文件quant.cfg样例如下所示:Optype需要配置为基于Ascend IR定义的算子类型,详细对应关系请参见表2

# global quantize parameter
activation_offset : true
version : 1
skip_layers : "conv_1"
skip_layer_types:"Optype"
do_fusion: true
skip_fusion_layers : "conv_1"
common_config : {
    arq_quantize : {
        channel_wise : true
    }
    ifmr_quantize : {
        search_range_start : 0.7
        search_range_end : 1.3
        search_step : 0.01
        max_percentile : 0.999999
        min_percentile : 0.999999
        symmetric : 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
            symmetric : false
        }
    }
}
 
override_layer_configs : {
    layer_name : "conv_2"
    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
            symmetric : false
        }
    }
}
表2 支持量化层以及对应Ascend IR定义的层

框架

支持的层类型

约束

对应Ascend IR定义的层类型

Caffe

InnerProduct:全连接层

transpose属性为false,axis为1

FullyConnection

Convolution:卷积层

dilation为1、filter维度为4

Conv2D

TensorFlow

MatMul:全连接层

transpose_a为False, transpose_b为False,adjoint_a为False,adjoint_b为False

MatMulV2

Conv2D:卷积层

weight的输入来源不含有placeholder等可动态变化的节点,且weight的节点类型只能是const。

Conv2D

DepthwiseConv2dNative:Depthwise卷积层

dilation为1

DepthwiseConv2D

ONNX

Conv:卷积层

-

Conv2D

Gemm:广义矩阵乘

transpose_a=false

MatMulV2