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

#### 产品支持情况

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


#### 功能说明

量化感知训练接口，将输入的待量化的图结构按照给定的量化感知训练配置文件进行量化处理，在传入的图结构中插入量化感知训练相关的算子（数据和权重的量化感知训练层以及找N的层），生成量化因子记录文件record_file，加载训练过程中保存的checkpoint权重参数，返回修改后的torch.nn.Module量化感知训练模型。


#### 函数原型

```
quant_retrain_model = restore_quant_retrain_model (config_file, model, record_file, input_data, pth_file, state_dict_name=None)
```


#### 参数说明

| 参数名 | 输入/输出 | 说明 |
| --- | --- | --- |
| config\_file | 输入 | 含义：用户生成的量化感知训练配置文件，用于指定模型network中量化层的配置情况。 数据类型：string 使用约束：该接口输入的config.json必须和create\_quant\_retrain\_model接口输入的config.json一致。 |
| model | 输入 | 含义：待进行量化感知训练的原始模型，未加载权重。 数据类型：torch.nn.Module |
| record\_file | 输入 | 含义：量化因子记录文件路径及名称。 数据类型：string |
| input\_data | 输入 | 含义：模型的输入数据。一个torch.tensor会被等价为tuple（torch.tensor）。 数据类型：tuple |
| pth\_file | 输入 | 含义：训练过程中保存的权重文件。 数据类型：string |
| state\_dict\_name | 输入 | 含义：权重文件中的权重对应的键值。 默认值：None 数据类型：string |


#### 返回值说明

返回修改后的torch.nn.Module量化感知训练模型。


#### 调用示例

```
import amct_pytorch as amct
# 建立待量化的网络图结构
model = build_model()
input_data = tuple([torch.randn(input_shape)])
 
scale_offset_record_file = os.path.join(TMP, 'scale_offset_record.txt')
# 插入量化API
quant_retrain_model = amct.restore_quant_retrain_model(
               config_json_file,
               model,
               scale_offset_record_file,
               input_data,
               pth_file)
```
