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

Fix ONNX export for MobileBERT #1539

Merged
merged 3 commits into from
Apr 26, 2023
Merged

Fix ONNX export for MobileBERT #1539

merged 3 commits into from
Apr 26, 2023

Conversation

anmarques
Copy link
Member

Simple fixes for ONNX export of MobileBERT.

Before the fix, a MatMul in the Embedding section of MobileBERT was not being converted to MatMulInteger, even though the inputs are quantized.

In short, a DequantizeLinear node used as part of the embedding quantization must be propagated down a few Slice and Concat nodes such that it can sit next to the MatMul node. This allows the proper pattern matching to convert that MatMul to MatMulInteger.

This behavior was already present in the onnx export logic, but there is a data type check on the embedding weights and it expected uint8. However, the weights were defined as int8 (conversion to uint8 happens at a later step). This PR adds logic to support int8, and also accounts for non-zero zero-point.

Testing plan:
Did the onnx export for the model below and checked that the MatMul is converted to ConvInteger. Checked that deepsparse now supports 99.35% of ops. Accuracy matches value reported in the zoo.

zoo:nlp/question_answering/mobilebert-none/pytorch/huggingface/squad/14layer_pruned50_quant-none-vnni

@eldarkurtic
Copy link
Contributor

I have just tested export to onnx and eval-downstream of the exported model, and everything looks as expected

Copy link
Member

@mgoin mgoin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent fix, thanks!

@mgoin mgoin linked an issue Apr 26, 2023 that may be closed by this pull request
@anmarques anmarques merged commit d360f12 into main Apr 26, 2023
@anmarques anmarques deleted the fix/mobilebert/onnx_export branch April 26, 2023 20:00
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

Successfully merging this pull request may close these issues.

Failure of reproducing sparsification of MobileBERT-oBERT-SQuAD
3 participants