起因,模型量化部署
- 最近想着量化模型了,我们知道一般模型是fp32格式的,而fp16我们已经尝试过,于是我想测试下torch2trt是否支持int8
torch2trt 是否支持int8?
-
关于这个问题,我回去官方的git上转了转,发现readme或者别的,都是以fp16为例子,转了一圈去issues看看,想着一定有人会有这种想法,并出错~
-
作者回复说不支持~
- https://github.com/NVIDIA-AI-IOT/torch2trt/issues/55
-
其他问题
- https://github.com/NVIDIA-AI-IOT/torch2trt/issues?q=int8
-
其中可能有用的有:TypeError: torch.uint8 is not supported by tensorrt
- https://github.com/NVIDIA-AI-IOT/torch2trt/issues/209
-
6天前有人尝试过int8但是失败
- https://github.com/NVIDIA-AI-IOT/torch2trt/issues/96
-
分段错误
- https://github.com/NVIDIA-AI-IOT/torch2trt/issues/267
-
但是看到源码,有int8的选项
-
而且这个int8_mode只是builder中的格式改变,那么理论上来说是可以实现的(TensorRT6.0应该支持int8)
- 带我去测试一番,虽然之前试过,但是还是不甘心,再去测一次,
测试结果(占坑)
- 测试结果是失败了
- 测试发现单单精度调成int8似乎是不行的,时间反而上升了
- 于是我将int8_mode去掉,用fp32转换模型测试一遍:得到相似结果,也就是这个int8_mode暂时不可用,或者说没用对,就默认用了fp32
- fp32的平均时间为0.411
- 初步断定torch2trt的int8mode是fp32的,或者int8没用对
结论
- 不支持,又在虎扑看到这一句说,再多方求证,判定是Jetson Nano不支持 Int 8 ,所以不确定说Torch2trt是否支持int8