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

Add new INT4 quantization features to model builder #940

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

kunal-vaishnavi
Copy link
Contributor

Description

This PR adds new INT4 quantization features to the model builder.

  1. The model builder can now quantize the embedding layer and the language modeling head to INT4 precision by default.
  2. For already-quantized PyTorch models that are passed to the model builder, any ops that are still created with MatMul can now be quantized to MatMulNBits via RTN.
  3. A new optional flag in the extra options called int4_op_type_to_quantize has been added to allow more flexibility with INT4 quantization.

Motivation and Context

With these PR changes, the size of the ONNX models can be reduced by quantizing the embedding layer and/or the language modeling head.

For the ONNX models built from already-quantized PyTorch models, one example is with using AutoAWQ. AutoAWQ does not quantize the language modeling head. The resulting ONNX model typically contains a MatMul op for the language modeling head. Now, that MatMul op will be quantized via RTN to MatMulNBits to reduce memory.

"accuracy_level": int(extra_options["int4_accuracy_level"]) if "int4_accuracy_level" in extra_options else 0, # Default is 0 for non-QDQ formats, default is 4 for QDQ formats
"block_size": int(extra_options["int4_block_size"]) if "int4_block_size" in extra_options else 32,
"op_types_to_quantize": (extra_options["op_type_to_quantize"], ) if "int4_op_type_to_quantize" in extra_options else ("MatMul", "Gather", ),
Copy link
Member

@yufenglee yufenglee Sep 30, 2024

Choose a reason for hiding this comment

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

Could we make the default "MatMul"? The reason is that the quantization of Gather is optional and not all the EPs support it.

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.

2 participants