产品 |
是否支持 |
---|---|
|
|
|
|
|
|
|
|
|
注:上述4选2结构化稀疏特性,标记“x”的产品,调用接口不会报错,但是获取不到性能收益。
通道稀疏或4选2结构化稀疏接口,两种稀疏特性每次只能使能一个:将输入的待稀疏的图结构按照给定的record_file中稀疏记录进行稀疏,返回修改后可用于稀疏后训练的torch.nn.module模型。
1 | prune_retrain_model = restore_prune_retrain_model (model, input_data, record_file, config_defination, pth_file, state_dict_name=None) |
参数名 |
输入/输出 |
说明 |
---|---|---|
model |
输入 |
含义:待进行稀疏的模型,未加载权重。 数据类型:torch.nn.module |
input_data |
输入 |
含义:模型的输入数据。一个torch.tensor会被等价为tuple(torch.tensor)。 数据类型:tuple |
record_file |
输入 |
含义:记录稀疏信息的文件路径及名称,由create_prune_retrain_model生成,确保两个接口生成的模型一致。 数据类型:string |
config_defination |
输入 |
含义:简易配置文件。基于retrain_config_pytorch.proto文件生成的简易配置文件prune.cfg,*.proto文件所在路径为:AMCT安装目录/amct_pytorch/proto/。*.proto文件参数解释以及生成的prune.cfg简易量化配置文件样例请参见量化感知训练简易配置文件。 数据类型:string |
pth_file |
输入 |
含义:训练过程中保存的权重文件。 数据类型:string |
state_dict_name |
输入 |
含义:权重文件中的权重对应的键值。 默认值:None 数据类型:string |
返回修改后可用于稀疏后训练的torch.nn.module模型。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 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') |