OpenPPL / ppq

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

请教一个onnx的问题 #486

Closed HIT-Wang closed 1 year ago

HIT-Wang commented 1 year ago

hello,最近在弄openvino的量化,感谢您之前详细的回答 最近我换了一种模型结构,并转了一个onnx出来,通过onnxruntime检验这个onnx是没有问题的,但是在用脚本跑的时候,quantize_onnx_model函数会报错,

Traceback (most recent call last):
  File "anaconda3/envs/lib/python3.8/site-packages/ppq/executor/torch.py", line 536, in __forward
    outputs = operation_forward_func(operation, inputs, self._executing_context)
  File "anaconda3/envs/lib/python3.8/site-packages/ppq/executor/op/torch/default.py", line 1457, in Resize_forward
    scale_factor = values[2].cpu() if len(values) > 2 else None
AttributeError: 'NoneType' object has no attribute 'cpu'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "Example_PTQ.py", line 135, in <module>
    qir = quantize_onnx_model(
  File "", line 54, in _wrapper
    return func(*args, **kwargs)
  File "anaconda3/envs/lib/python3.8/site-packages/ppq/api/interface.py", line 263, in quantize_onnx_model
    quantizer.quantize(
  File "anaconda3/envs/lib/python3.8/site-packages/ppq/core/defs.py", line 54, in _wrapper
    return func(*args, **kwargs)
  File "anaconda3/envs/lib/python3.8/site-packages/ppq/quantization/quantizer/base.py", line 52, in quantize
    executor.tracing_operation_meta(inputs=inputs)
  File "anaconda3/envs/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "anaconda3/envs/lib/python3.8/site-packages/ppq/core/defs.py", line 54, in _wrapper
    return func(*args, **kwargs)
  File "anaconda3/envs/lib/python3.8/site-packages/ppq/executor/torch.py", line 598, in tracing_operation_meta
    self.__forward(
  File "/anaconda3/envs/lib/python3.8/site-packages/ppq/executor/torch.py", line 563, in __forward
    raise RuntimeError(f'Op Execution Error: {str(operation)}') from _
RuntimeError: Op Execution Error: Resize_49(Type: Resize, Num of Input: 4, Num of Output: 1)

不知道是否是框架的bug?因为用onnxruntime读取检查这个onnx,效果和文件都没有问题。Resize_49是一个upsample操作,用来做残差的,大致示意是:out = F.interpolate(x10, size=x2.shape[-2:], mode='bilinear') + x2,这样测reisze操作会报错

ZhangZhiPku commented 1 year ago

哦豁,看起来ppq读到了一个空的东西,让我看看咋回事

HIT-Wang commented 1 year ago

哦豁,看起来ppq读到了一个空的东西,让我看看咋回事

是滴,但是看样子我的onnx是没有问题,因为用onnxruntime跑了一些图片,结果啥的都是正常的。但是量化的时候读到了空值NoneType,就有点奇怪

ZhangZhiPku commented 1 year ago

之前一个用户也有与您类似的问题,但是貌似是因为他没有更新PPQ到最新版本,您是否将PPQ更新到了0.6.6?

HIT-Wang commented 1 year ago

之前一个用户也有与您类似的问题,但是貌似是因为他没有更新PPQ到最新版本,您是否将PPQ更新到了0.6.6?

最近没有空尝试啦,感谢回答 我先关闭帖子了,等有空的时候去尝试一下