Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error exporting to onnx qops due to bit overflow #697

Open
surajpandey353 opened this issue Aug 24, 2023 · 1 comment
Open

Error exporting to onnx qops due to bit overflow #697

surajpandey353 opened this issue Aug 24, 2023 · 1 comment

Comments

@surajpandey353
Copy link

surajpandey353 commented Aug 24, 2023

Hi,

I am trying to export QAT model, which has Addition / Multiplication operation with the QuantTensor. These operations result in increased bit_width to tackle the overflow, e.g. multiplying two 8-bit QuantTensor will give 16 bit QuantTensor. This raises an error during export_onnx_qops, which doesn't support bit_width > 8bits.

One solution I tried it to fallback to torch.tensor (QuantTensor.value) during these operation, which seems to work fine with QuantConv layers but not with the quant activation.

Error:

File "anaconda3/envs/e2enc/lib/python3.9/site-packages/brevitas/export/init.py", line 32, in export_onnx_qop
return StdQOpONNXManager.export(*args, **kwargs)
File "anaconda3/envs/e2enc/lib/python3.9/site-packages/brevitas/export/onnx/manager.py", line 162, in export
return cls.export_onnx(
File "anaconda3/envs/e2enc/lib/python3.9/site-packages/brevitas/export/onnx/standard/manager.py", line 46, in export_onnx
output = super().export_onnx(
File "anaconda3/envs/e2enc/lib/python3.9/site-packages/brevitas/export/onnx/manager.py", line 121, in export_onnx
cls.set_export_mode(module, enabled=True)
File "anaconda3/envs/e2enc/lib/python3.9/site-packages/brevitas/export/onnx/standard/qoperator/manager.py", line 87, in set_export_mode
_set_layer_export_mode(module, enabled)
File "anaconda3/envs/e2enc/lib/python3.9/site-packages/brevitas/export/manager.py", line 115, in _set_layer_export_mode
m.export_mode = enabled
File "anaconda3/envs/e2enc/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1225, in setattr
object.setattr(self, name, value)
File "anaconda3/envs/e2enc/lib/python3.9/site-packages/brevitas/common.py", line 42, in export_mode
self.export_handler.prepare_for_export(self)
File "anaconda3/envs/e2enc/lib/python3.9/site-packages/brevitas/export/onnx/standard/qoperator/handler/act.py", line 51, in prepare_for_export
'input_axis': input_quant_symbolic_kwargs['input_axis']}
KeyError: 'input_axis'

I am feeding quant_input with QuantIdentity(return_quant_tensor=True. Thus I am keeping input_quant = None, return_quant_tensor=True in all the activation layers.

Dependencies:
Torch version 1.10.0+cu111
ONNX version 1.14.0
Brevitas version 0.9.1

@surajpandey353
Copy link
Author

surajpandey353 commented Sep 5, 2023

Hi,

Alternatively, if elementwise ops QuantEltwiseAdd , QuantCat is supported for q_ops export, this could be a solution.
QuantElementwiseOps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant