---
title: create_quant_config_ascend
description: "| 产品 | 是否支持 |"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/devaids/amct/atlasamct_16_0329.html
sourcePath: /source/zh/canncommercial/900/devaids/amct/atlasamct_16_0329.html
indexId: 5264b95ebb9d2325cbfee83e9a10881d3da7e702dcd22b942361a523abe86f9265
---
# create_quant_config_ascend

#### 产品支持情况

| 产品 | 是否支持 |
| --- | --- |
| Atlas 350 加速卡 | x |
| Atlas A3 训练系列产品 / Atlas A3 推理系列产品 | x |
| Atlas A2 训练系列产品 / Atlas A2 推理系列产品 | x |
| Atlas 200I/500 A2 推理产品 | x |
| Atlas 推理系列产品 | x |
| Atlas 训练系列产品 | √ |


#### 功能说明

训练后量化接口，根据图的结构找到所有可量化的层，自动生成量化配置文件，并将可量化层的量化配置信息写入文件。


#### 函数原型

```
create_quant_config_ascend(config_file, graph, skip_layers=None, activation_offset=True, config_defination=None)
```


#### 参数说明

| 参数名 | 输入/输出 | 说明 |
| --- | --- | --- |
| config\_file | 输入 | 含义：待生成的量化配置文件存放路径及名称。 如果存放路径下已经存在该文件，则调用该接口时会覆盖已有文件。 数据类型：string |
| graph | 输入 | 含义：用户传入的待量化模型的tf.Graph图。 数据类型：tf.Graph |
| skip\_layers | 输入 | 含义：tf.Graph图中不需要量化层的层名。 默认值：None 数据类型：list，列表中元素类型为string 使用约束：如果使用简易配置文件作为入参，则该参数需要在简易配置文件中设置，此时输入参数中该参数配置不生效。 |
| activation\_offset | 输入 | 含义：数据量化是否带offset。 默认值：True 数据类型：bool 使用约束：如果使用简易配置文件作为入参，则该参数需要在简易配置文件中设置，此时输入参数中该参数配置不生效。 |
| config\_defination | 输入 | 含义：基于calibration\_config\_ascend\_tf.proto文件生成的简易量化配置文件quant.cfg，\*.proto文件所在路径为：AMCT安装目录/amct\_tensorflow/proto/。\*.proto文件参数解释以及生成的quant.cfg简易量化配置文件样例请参见简易配置文件。 默认值：None 数据类型：string 使用约束：当取值为None时，使用输入参数生成配置文件；否则，忽略输入的其他量化参数（skip\_layers，activation\_offset），根据简易量化配置文件参数config\_defination生成JSON格式的配置文件。 |


#### 返回值说明

无


#### 调用示例

```
import amct_tensorflow as amct
# 建立待量化的网络图结构
network = build_network()
# 生成量化配置文件
amct.create_quant_config_ascend(config_file="./configs/config.json",
                    graph=tf.get_default_graph(),
                    skip_layers=None,
                    activation_offset=True)
```

落盘文件如下：生成一个JSON格式的量化配置文件（重新执行量化时，该接口输出的量化配置文件将会被覆盖）。

```
{
    "version":1,
    "activation_offset":true,
    "do_fusion":true,
    "skip_fusion_layers":[],
    "MobilenetV2/Conv/Conv2D":{
        "quant_enable":true,
        "activation_quant_params":{
            "max_percentile":0.999999,
            "min_percentile":0.999999,
            "search_range":[
                0.7,
                1.3
            ],
            "search_step":0.01,
            "act_algo":"ifmr",
            "asymmetric":false
        },
        "weight_quant_params":{
            "wts_algo":"arq_quantize",
            "channel_wise":true
        }
    },
    "MobilenetV2/Conv_1/Conv2D":{
        "quant_enable":true,
        "activation_quant_params":{
            "max_percentile":0.999999,
            "min_percentile":0.999999,
            "search_range":[
                0.7,
                1.3
            ],
            "search_step":0.01,
            "act_algo":"ifmr",
            "asymmetric":false
        },
        "weight_quant_params":{
            "wts_algo":"arq_quantize",
            "channel_wise":true
        }
    }
}
```
