Closed drakitLiu closed 6 months ago
发现即使没有scale文件,但也可以将量化后的静态图合并成onnx模型文件,使用的命令是: paddle2onnx --model_dir ./ --model_filename model.pdmodel --params_filename model.pdiparams --save_file quant_model.onnx --opset_version 13 --enable_dev_version True --deploy_backend onnxruntime --enable_onnx_checker True 但是失真度太大了! 于是我尝试改用这个量化方法:
quant_recon_static(
executor=exe,
model_dir=args__.model_path,
quantize_model_path=args__.save_path + 'quant_recon_static/',
data_loader=data_loader,
model_filename=args__.model_filename,
params_filename=args__.params_filename,
batch_size=32,
batch_nums=256,
region_weights_names=None,
onnx_format=args__.onnx_format,
recon_level='region-wise',
is_full_quantize=args__.is_full_quantize,
bias_correction=args__.bias_correction,
)
官方说是这个方法会很耗时,没想到不仅耗时,而且压根不会成功,跑了4天了,epoch使用的是默认值20,程序跑完20个epoch后又会从0开始跑,然后没完没了,第五天报错了: 此时此刻很想雨!
你好,首先回答下你提到的这个scale文件,在使用paddleslim压缩静态图模型后得到的只有model.pdmodel和model.pdiparams两个文件,你所描述的这个scale文件是calibration.cache文件,这个文件是在GPU上使用Tensorrt部署时,指令paddle2onnx --model_dir ./ --model_filename model.pdmodel --params_filename model.pdiparams --save_file float_model.onnx --opset_version 13 --enable_dev_version True --deploy_backend tensorrt --enable_onnx_checker True生成的。 关于精度损失的问题,quant_post_static和quant_recon_static属于比较老的接口,可能在某些模型使用上存在部分问题,这边建议去使用paddleslim的新接口,自动压缩接口,可参照https://github.com/PaddlePaddle/PaddleSlim/tree/develop/example/auto_compression 里面包括了训练后量化和量化训练,静态图模型适合使用此接口。 以下面是简单的接口示例: ac = AutoCompression( model_dir="./MobileNetV1_infer", model_filename="inference.pdmodel", params_filename="inference.pdiparams", save_dir="MobileNetV1_quant", config={"QuantPost": {}, "HyperParameterOptimization": {'ptq_algo': ['avg'], 'max_quant_count': 3}}, train_dataloader=train_loader, eval_dataloader=train_loader) ac.compress()
你好,首先回答下你提到的这个scale文件,在使用paddleslim压缩静态图模型后得到的只有model.pdmodel和model.pdiparams两个文件,你所描述的这个scale文件是calibration.cache文件,这个文件是在GPU上使用Tensorrt部署时,指令paddle2onnx --model_dir ./ --model_filename model.pdmodel --params_filename model.pdiparams --save_file float_model.onnx --opset_version 13 --enable_dev_version True --deploy_backend tensorrt --enable_onnx_checker True生成的。 关于精度损失的问题,quant_post_static和quant_recon_static属于比较老的接口,可能在某些模型使用上存在部分问题,这边建议去使用paddleslim的新接口,自动压缩接口,可参照https://github.com/PaddlePaddle/PaddleSlim/tree/develop/example/auto_compression 里面包括了训练后量化和量化训练,静态图模型适合使用此接口。 以下面是简单的接口示例: ac = AutoCompression( model_dir="./MobileNetV1_infer", model_filename="inference.pdmodel", params_filename="inference.pdiparams", save_dir="MobileNetV1_quant", config={"QuantPost": {}, "HyperParameterOptimization": {'ptq_algo': ['avg'], 'max_quant_count': 3}}, train_dataloader=train_loader, eval_dataloader=train_loader) ac.compress()
此外提醒一下onnx_format这个参数设置为True,便于导出的pdmodel是paddle的新格式,也便于后续转成onnx文件。
如果问题解决了的话,麻烦关闭该issue,谢谢
我的量化代码是基于官方提供的:quant_post.py:
运行结果:
确实得到了 模型文件和权重文件,但是没有官方说的 scale 文件
补充:我的前向计算的dataloader数据已经wav2lip模型前向计算测试过,没问题。 paddlepaddle版本最新稳定版本,python=3.8,paddleslim=2.6
谢谢~