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

Quantize Weight for Gemm/Conv on Quantized Model #22969

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

Conversation

centwang
Copy link
Contributor

Some quantized models have QDQ around Conv/Gemm but the weight and/or bias are not quantized. This PR adds WeightBiasQuantization optimizer to quantize float weight and/or bias to INT8 and INT32 tensors respectively. We only do this for weight and/or bias initializer so that ConstantFolding will fold the sub-graph to real quantized initializers during the graph optimization next round.

@centwang centwang marked this pull request as ready for review November 28, 2024 10:20
Comment on lines 15 to 16
* For weight, it's quantized to symmetric per-tensor INT8 tensor.
* For bias, it's quantized to a INT32 tensor with scale = scale_input_0 * scale_input_1 and zero_point = 0.
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we say we insert a Q and DQ after the weight to allow it to potentially be quantized? As that's not guaranteed to happen I assume (e.g. EP wants to use full precision) it may be slightly clearer to the reader what is happening.

Comment on lines 89 to 91
if (dq_attrs.find("axis") != dq_attrs.end()) {
axis = dq_attrs.at("axis").i();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can avoid doing 2 lookups

Suggested change
if (dq_attrs.find("axis") != dq_attrs.end()) {
axis = dq_attrs.at("axis").i();
}
if (auto axis_iter = dq_attrs.find("axis"); axis_iter != dq_attrs.end()) {
axis = axis_iter->second.i();
}

Copy link
Contributor

@skottmckay skottmckay left a comment

Choose a reason for hiding this comment

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

:shipit:

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