neural-compressor icon indicating copy to clipboard operation
neural-compressor copied to clipboard

Quantizer cannot quantize HBONet

Open hoshibara opened this issue 2 years ago • 6 comments

Hi. When we use inc to convert HBONet, we get an exception. Hope you can help me to fix it.

Version info: neural-compressor: 1.13.1 torch: 1.12.1

We use inc like this: https://github.com/intel-analytics/BigDL/blob/2fdd7254f80810c2dab5a2e7e840872bfd59de76/python/nano/src/bigdl/nano/deps/neural_compressor/core/quantization.py#L104

The exception is as follow:

Traceback (most recent call last):
  File "/disk3/xingyuan/miniconda3/envs/nano-lxy/lib/python3.7/site-packages/neural_compressor/experimental/quantization.py", line 148, in execute
    self.strategy.traverse()
  File "/disk3/xingyuan/miniconda3/envs/nano-lxy/lib/python3.7/site-packages/neural_compressor/strategy/strategy.py", line 402, in traverse
    tune_cfg, self.model, self.calib_dataloader, self.q_func)
  File "/disk3/xingyuan/miniconda3/envs/nano-lxy/lib/python3.7/site-packages/neural_compressor/utils/utility.py", line 262, in fi
    res = func(*args, **kwargs)
  File "/disk3/xingyuan/miniconda3/envs/nano-lxy/lib/python3.7/site-packages/neural_compressor/adaptor/onnxrt.py", line 168, in quantize
    quantizer.quantize_model()
  File "/disk3/xingyuan/miniconda3/envs/nano-lxy/lib/python3.7/site-packages/neural_compressor/adaptor/ox_utils/quantizer.py", line 133, in quantize_model
    self.convert_qdq_to_operator_oriented()
  File "/disk3/xingyuan/miniconda3/envs/nano-lxy/lib/python3.7/site-packages/neural_compressor/adaptor/ox_utils/quantizer.py", line 240, in convert_qdq_to_operator_oriented
    op_converter.convert()
  File "/disk3/xingyuan/miniconda3/envs/nano-lxy/lib/python3.7/site-packages/neural_compressor/adaptor/ox_utils/operators/conv.py", line 46, in convert
    inputs.append(parents[0].output[2])
IndexError: list index (2) out of range

hoshibara avatar Nov 30 '22 09:11 hoshibara

Hi, do you quantize HBONet with onnx format or torch format? I see you provide the information of torch but the log shows it is related to onnx.

mengniwang95 avatar Dec 06 '22 01:12 mengniwang95

I quantize model with onnx format. I convert a torch model to onnx model, and then use inc to quantize it.

hoshibara avatar Dec 07 '22 01:12 hoshibara

It looks like there is an error when the code is trying to access the third element of a list of parents (inputs) for the convolution operation. This error is likely caused by the fact that the list of parents does not have enough elements to satisfy the index being accessed (i.e., the list only has two elements, so there is no third element at index 2).

To fix this issue, you could try modifying the code to check if the list of parents has at least three elements before trying to access the third element. This would prevent the IndexError from being thrown.

Alternatively, you could try updating the neural-compressor and torch versions that you are using to the latest versions, as this error may have been fixed in a newer version of the library. It's also possible that this error is specific to the HBONet model, so you may want to try using a different model to see if the error persists.

FMCalisto avatar Dec 08 '22 21:12 FMCalisto

@hoshibara Hi, do you quantize this model with static or dynamic quantization approach? If the program runs into line 46, the optype of parent[0] should be DynamicQuantizeLinear. Could you check the optype of the parent[0]? Or could you provide the onnx model to us so we can try to reproduce the error?

mengniwang95 avatar Dec 13 '22 06:12 mengniwang95

I checked the optype of parents[0]. Its value is DequantizeLinear. I also use pickle to dump the onnx model, upload it as attachment. ONNXModel.zip

hoshibara avatar Dec 14 '22 14:12 hoshibara

Hi @hoshibara , sorry for my late reply, could you try our nightly version to do quantization? I use your QDQ model and it can be converted successfully.

mengniwang95 avatar Dec 23 '22 08:12 mengniwang95

Sorry for late reply. Thank you for your reply, because we have no plan to update inc version recently, this issue needs to wait for our future version updates.

hoshibara avatar Dec 26 '22 03:12 hoshibara