260M的MNN超分模型,resizeSession()的耗时太长
我的模型:
Onnx转MNN:MNNConvert -f ONNX --modelFile XXX.onnx --MNNModel XXX.mnn --bizCode biz --optimizeLevel 2 --fp16 MNN文件大小:260M Config:
ScheduleConfig netConfig;
netConfig.type = MNN_FORWARD_CPU; // MNN_FORWARD_OPENCL; // MNN_FORWARD_VULKAN; // MNN_FORWARD_CPU
netConfig.numThread = 1;
BackendConfig backendConfig;
backendConfig.precision = BackendConfig::Precision_Low;
backendConfig.power = BackendConfig::Power_Normal;
netConfig.backendConfig = &backendConfig;
耗时log: create model time: 777ms CPU Group: [ 0 1 2 3 4 5 ], 500000 - 2000000 CPU Group: [ 6 7 ], 725000 - 2200000 The device supports: i8sdot:1, fp16:1, i8mm: 0, sve2: 0 MNN session created successfully. create session time: 2ms get input time: 0ms resize tensor time: 0ms resize session time: 16787ms Input shape: 1 3 512 512 Output shape: 1 3 1024 1024
主要问题是resizeSession()的耗时实在太长了,有什么办法优化这部分的耗时吗?🥳🥳🥳
- 加载时会做权重重排,后续的 resizeSession 时间就少了。
- fp16 的模型目前需要先 fp16 -> fp32 再重排,如果开了 arm82 还需要再转 fp16 ,是当前加载最慢的。
- 可以换用量化模型 (模型转换时加上 --weightQuantBits=8 --weightQuantBlock=64),并开启动态量化 (设置 memory = low),加载速度有优化,性能也可以提升
https://mnn-docs.readthedocs.io/en/latest/tools/compress.html
- 加载时会做权重重排,后续的 resizeSession 时间就少了。
- fp16 的模型目前需要先 fp16 -> fp32 再重排,如果开了 arm82 还需要再转 fp16 ,是当前加载最慢的。
- 可以换用量化模型 (模型转换时加上 --weightQuantBits=8 --weightQuantBlock=64),并开启动态量化 (设置 memory = low),加载速度有优化,性能也可以提升
https://mnn-docs.readthedocs.io/en/latest/tools/compress.html
关于第2点,意思是fp16的输入模型的初始化时间反而会比fp32的更长吗?
- 加载时会做权重重排,后续的 resizeSession 时间就少了。
- fp16 的模型目前需要先 fp16 -> fp32 再重排,如果开了 arm82 还需要再转 fp16 ,是当前加载最慢的。
- 可以换用量化模型 (模型转换时加上 --weightQuantBits=8 --weightQuantBlock=64),并开启动态量化 (设置 memory = low),加载速度有优化,性能也可以提升
https://mnn-docs.readthedocs.io/en/latest/tools/compress.html
关于第3点,我的模型做动态量化后,fp16精度推理耗时比非动态量化的模型多了50%,这是正常的吗?🤣🤣🤣
Marking as stale. No activity in 60 days.