restore_prune_retrain_model
产品支持情况
|
|
|
|
|
注:上述4选2结构化稀疏特性,标记“x”的产品,调用接口不会报错,但是获取不到性能收益。
功能说明
通道稀疏或4选2结构化稀疏接口,两种稀疏特性每次只能使能一个:将输入的待稀疏的图结构按照给定的record_file中稀疏记录进行稀疏,返回修改后可用于稀疏后训练的torch.nn.Module模型。
函数原型
prune_retrain_model = restore_prune_retrain_model (model, input_data, record_file, config_defination, pth_file, state_dict_name=None)
参数说明
含义:记录稀疏信息的文件路径及名称,由create_prune_retrain_model生成,确保两个接口生成的模型一致。 |
||
含义:简易配置文件。基于retrain_config_pytorch.proto文件生成的简易配置文件prune.cfg,*.proto文件所在路径为:AMCT安装目录/amct_pytorch/proto/。*.proto文件参数解释以及生成的prune.cfg简易量化配置文件样例请参见量化感知训练简易配置文件。 |
||
返回值说明
返回修改后可用于稀疏后训练的torch.nn.Module模型。
调用示例
import amct_pytorch as amct
# 建立待进行稀疏的网络图结构
config_defination = './prune_cfg.cfg'
model = build_model()
input_data = tuple([torch.randn(input_shape)])
save_pth_path = /your/path/to/save/tmp.pth
model.load_state_dict(torch.load(state_dict_path))
# 调用稀疏模型API
record_file = os.path.join(TMP, 'scale_offset_record.txt')
prune_retrain_model = amct.restore_prune_retrain_model(
model,
input_data,
record_file,
config_defination,
save_pth_path,
'state_dict')