OpenPPL / ppq

PPL Quantization Tool (PPQ) is a powerful offline neural network quantization tool.
Apache License 2.0
1.57k stars 236 forks source link

yolov5和yolov8模型量化时错误 #493

Closed zranguai closed 1 year ago

zranguai commented 1 year ago

你好,我在量化v5和v8都出现了这个问题,请问是什么原因? 量化时显示 Upsample_120(Upsample) has no backend implementation on target platform TargetPlatform.FP32 具体信息时

正准备量化你的网络,检查下列设置:
WORKING DIRECTORY    : working
TARGET PLATFORM      : TRT_INT8
NETWORK INPUTSHAPE   : [1, 3, 640, 640]
CALIBRATION BATCHSIZE: 8
10 File(s) Loaded.
Loaded sample 0, shape: torch.Size([1, 3, 640, 640])
Loaded sample 1, shape: torch.Size([1, 3, 640, 640])
Loaded sample 2, shape: torch.Size([1, 3, 640, 640])
Loaded sample 3, shape: torch.Size([1, 3, 640, 640])
Loaded sample 4, shape: torch.Size([1, 3, 640, 640])
Batch Shape: torch.Size([8, 3, 640, 640])
网络正量化中,根据你的量化配置,这将需要一段时间:
[17:51:41] PPQ Layerwise Equalization Pass Running ... 0 equalization pair(s) was found, ready to run optimization.
Finished.
Layerwise Equalization: 100%|██████████| 3/3 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "D:\cv-code\Quantization\ppq-0.6.3\ppq\executor\torch.py", line 332, in __forward
    f'Graph op: {operation.name}({operation.type}) '
NotImplementedError: Graph op: Upsample_120(Upsample) has no backend implementation on target platform TargetPlatform.FP32

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:/cv-code/Quantization/ppq-0.6.3/ProgramEntrance.py", line 67, in <module>
    dataloader=dataloader, calib_steps=32)
  File "D:\cv-code\Quantization\ppq-0.6.3\ppq\api\interface.py", line 714, in quantize
    platform=target_platform, device=executing_device, collate_fn=lambda x: x.to(executing_device)
  File "D:\cv-code\Quantization\ppq-0.6.3\ppq\core\defs.py", line 65, in _wrapper
    return func(*args, **kwargs)
  File "D:\cv-code\Quantization\ppq-0.6.3\ppq\api\interface.py", line 267, in quantize_onnx_model
    collate_fn=collate_fn
  File "D:\cv-code\Quantization\ppq-0.6.3\ppq\core\defs.py", line 65, in _wrapper
    return func(*args, **kwargs)
  File "D:\cv-code\Quantization\ppq-0.6.3\ppq\quantization\quantizer\base.py", line 59, in quantize
    executor.tracing_operation_meta(inputs=inputs)
  File "C:\anaconda\envs\mw_env\lib\site-packages\torch\autograd\grad_mode.py", line 28, in decorate_context
    return func(*args, **kwargs)
  File "D:\cv-code\Quantization\ppq-0.6.3\ppq\core\defs.py", line 65, in _wrapper
    return func(*args, **kwargs)
  File "D:\cv-code\Quantization\ppq-0.6.3\ppq\executor\torch.py", line 426, in tracing_operation_meta
    hooks=hooks)
  File "D:\cv-code\Quantization\ppq-0.6.3\ppq\executor\torch.py", line 387, in __forward
    raise RuntimeError(f'Error happens when dealing with operation {str(operation)}')
RuntimeError: Error happens when dealing with operation Upsample_120(TargetPlatform.FP32) - inputs:['499', '502'], outputs:['503']

Process finished with exit code 1
ZhangZhiPku commented 1 year ago

upsample这个算子在onnx opset 9 之后被删除了,ppq 会拒绝这个算子,你需要把模型升级到 onnx opset 11。

ONNX标准是真的给直接删掉了,没有向后兼容

zranguai commented 1 year ago

upsample这个算子在onnx opset 9 之后被删除了,ppq 会拒绝这个算子,你需要把模型升级到 onnx opset 11。

ONNX标准是真的给直接删掉了,没有向后兼容

好的,我升级下试试