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

#### 产品支持情况

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


#### 功能说明

蒸馏接口，将输入的待量化压缩的图结构按照给定的蒸馏量化配置文件进行量化处理，在传入的图结构中插入量化相关的算子（数据和权重的蒸馏量化层以及找N的层），返回修改后可用于蒸馏的torch.nn.Module模型。


#### 函数原型

```
compress_model = create_distill_model(config_file, model, input_data)
```


#### 参数说明

| 参数名 | 输入/输出 | 说明 |
| --- | --- | --- |
| config\_file | 输入 | 含义：用户生成的蒸馏量化配置文件，用于指定模型network中量化层的配置情况和蒸馏结构。 数据类型：string 使用约束：该接口输入的config.json必须和create\_distill\_config接口输入的config.json一致 |
| model | 输入 | 含义：待进行蒸馏量化的原始浮点模型，已加载权重。 数据类型：torch.nn.Module |
| input\_data | 输入 | 含义：模型的输入数据。一个torch.tensor会被等价为tuple(torch.tensor)。 数据类型：tuple |


#### 返回值说明

修改后可用于蒸馏的torch.nn.Module模型。


#### 调用示例

```
import amct_pytorch as amct
# 建立待进行蒸馏量化的网络图结构
model = build_model()
model.load_state_dict(torch.load(state_dict_path))
input_data = tuple([torch.randn(input_shape)])

# 生成压缩模型
compress_model = amct.create_distill_model(
                 config_json_file,
                 model,
                 input_data)
```
