基于mindspore的权重量化8bit,最终模型大小和float16大小一样
·
问题描述
采用下面的固定比特量化的方式得到的量化模型大小和fp16精度一样大,推理效率也一样,没有int8量化的效果,去掉'--optimize=ascend_oriented'后大小符合预期,但推理报错。
转换命令
./converter_lite --fmk=MINDIR --saveType=MINDIR --modelFile=model.mindir --outputFile=model --optimize=ascend_oriented
量化参数
[common_quant_param]
quant_type=WEIGHT_QUANT
# Weight quantization supports the number of bits [0,16]. Set to 0 is mixed bit quantization, otherwise it is fixed bit quantization
bit_num=8
# Layers with size of weights exceeds threshold `min_quant_weight_size` will be quantized.
min_quant_weight_size=0
# Layers with channel size of weights exceeds threshold `min_quant_weight_channel` will be quantized.
min_quant_weight_channel=16
解决方案
当前Ascend后端的量化支持不是特别的完善,当用户配置–optimize=ascend_oriented时候,表示使用的是ascend的推理,所以量化功能不是很完善;
建议通过torch或者onnxruntime进行量化,导出量化的onnx模型,然后通过MindSpore Lite离线转换工具进行转换,然后在ascend的硬件上部署推理;
最近MindSpore Lite代码仓提供了一个有关A8W8的量化skill,可以参考这个pr进行使用: AtomGit | GitCode - 全球开发者的开源社区,开源代码托管平台
鲲鹏昇腾开发者社区是面向全社会开放的“联接全球计算开发者,聚合华为+生态”的社区,内容涵盖鲲鹏、昇腾资源,帮助开发者快速获取所需的知识、经验、软件、工具、算力,支撑开发者易学、好用、成功,成为核心开发者。
更多推荐
所有评论(0)