-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Quantization tool supporting Conv and MatMul nodes #1892
Quantization tool supporting Conv and MatMul nodes #1892
Conversation
|
# Load the onnx model | ||
model = onnx.load('path/to/the/model.onnx') | ||
# Quantize | ||
quantized_model = quantize(model, per_channel=False, quantization_mode=QuantizationMode.IntegerOps_Dynamic) |
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.
Static mode involves more inputs right? like the quantization params… can you include an example for static mode too...
max_range = max(abs(rmin), abs(rmax)) | ||
scale = (float(max_range)*2) / quantize_range | ||
zero_point = 0 | ||
quantized_data = (np.asarray(data) / scale).round().astype('b') #signed byte type |
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.
Does this round half to even?
S: scale | ||
z: zero point | ||
''' | ||
rmin = min(data) |
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.
what happens when range does not include 0? For example is the range is 2-10 then in this case we dont have a unique representation for 0. Can you do rmin = min(min(data), 0) and similar for max...
scale_name = weight.name + '_scale' | ||
zero_point_name = weight.name + '_zero_point' | ||
|
||
# Remove existing weight initializer |
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.
What happens when this input is also being used by another node? This condition should be checked.
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.
Please address the comments and update the branch by merging with master
Quantization tool for converting an onnx model into quantized onnx model. Currently only conversion of Conv and MatMul nodes is supported.