quantize_preprocess
产品支持情况
| 产品 | 是否支持 |
|---|---|
| Ascend 950PR/Ascend 950DT | √ |
| Atlas A3 训练系列产品/Atlas A3 推理系列产品 | √ |
| Atlas A2 训练系列产品/Atlas A2 推理系列产品 | √ |
功能说明
量化数据均衡预处理接口,将输入的待量化的图结构按照给定的量化配置文件进行量化处理,在传入的图结构中插入均衡量化相关的算子,生成均衡量化因子记录文件record_file,返回修改后的torch.nn.Module校准模型。
函数原型
calibration_model = quantize_preprocess(config_file, record_file, model, input_data)
参数说明
返回值说明
返回修改后的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)])
tensor_balance_factor_record_file = os.path.join(TMP, 'tensor_balance_factor_record.txt')
modified_model = os.path.join(TMP, 'modified_model.onnx')
# 插入量化API
calibration_model = amct.quantize_preprocess(config_json_file,
tensor_balance_factor_record_file,
model,
input_data)