create_distill_model

产品支持情况

产品

是否支持

Atlas A2 训练系列产品/Atlas 800I A2 推理产品/A200I A2 Box 异构组件

Atlas 200I/500 A2 推理产品

Atlas 推理系列产品

Atlas 训练系列产品

功能说明

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

函数原型

1
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模型。

调用示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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)