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

#### 产品支持情况

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


#### 功能说明

蒸馏接口，根据图的结构找到所有可蒸馏量化的层和可蒸馏量化的结构，自动生成蒸馏量化配置文件，并将可蒸馏量化层的量化配置和蒸馏结构写入配置文件。


#### 函数原型

```
create_distill_config(config_file, model, input_data, config_defination=None)
```


#### 参数说明

| 参数名 | 输入/输出 | 说明 |
| --- | --- | --- |
| config\_file | 输入 | 含义：待生成的蒸馏量化配置文件存放路径及名称。如果存放路径下已经存在该文件，则调用该接口时会覆盖已有文件。 数据类型：string |
| model | 输入 | 含义：待进行蒸馏量化的原始浮点模型，已加载权重。 数据类型：torch.nn.Module |
| input\_data | 输入 | 含义：模型的输入数据。一个torch.tensor会被等价为tuple(torch.tensor)。 数据类型：tuple |
| config\_defination | 输入 | 含义：简易配置文件。基于distill\_config\_pytorch.proto文件生成的简易配置文件distill.cfg，\*.proto文件所在路径为：AMCT安装目录/amct\_pytorch/proto/。\*.proto文件参数解释以及生成的distill.cfg简易量化配置文件样例请参见蒸馏简易配置文件。 默认值：None。 数据类型：string |


#### 返回值说明

无


#### 调用示例

```
import amct_pytorch as amct
# 建立待进行蒸馏量化的网络图结构
model = build_model()
model.load_state_dict(torch.load(state_dict_path))
input_data = tuple([torch.randn(input_shape)])
 
# 生成蒸馏配置文件
amct.create_distill_config(config_file="./configs/config.json",
                           model,
                           input_data,
                           config_defination="./configs/distill.cfg")
```

落盘文件说明：

生成JSON格式的蒸馏量化配置文件，样例如下（重新执行蒸馏时，该接口输出的配置文件将会被覆盖，如下为INT8量化场景下的配置文件）：

```
{
    "version":1,
    "batch_num":1,
    "group_size":1,
    "data_dump":false,
    "distill_group":[
        [
            "conv1",
            "bn",
            "relu"
        ],
        [
            "conv2",
            "bn2",
            "relu2"
        ]
    ],
    "conv1":{
        "quant_enable":true,
        "distill_data_config":{
            "algo":"ulq_quantize",
            "dst_type":"INT8"
        },
        "distill_weight_config":{
            "algo":"arq_distill",
            "channel_wise":true,
            "dst_type":"INT8"
        }
    },
    "conv2":{
        "quant_enable":true,
        "distill_data_config":{
            "algo":"ulq_quantize",
            "dst_type":"INT8"
        },
        "distill_weight_config":{
            "algo":"arq_distill",
            "channel_wise":true,
            "dst_type":"INT8"
        }
    }
}
```
