-
Notifications
You must be signed in to change notification settings - Fork 3k
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
base: main
Are you sure you want to change the base?
Conversation
* 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. |
There was a problem hiding this comment.
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.
if (dq_attrs.find("axis") != dq_attrs.end()) { | ||
axis = dq_attrs.at("axis").i(); | ||
} |
There was a problem hiding this comment.
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
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(); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.