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

Quantization tool supporting Conv and MatMul nodes #1892

Closed

Conversation

PhaniShekhar
Copy link

Quantization tool for converting an onnx model into quantized onnx model. Currently only conversion of Conv and MatMul nodes is supported.

@CLAassistant
Copy link

CLAassistant commented Mar 29, 2019

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@PhaniShekhar PhaniShekhar requested a review from a team as a code owner April 17, 2019 03:07
# 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)
Copy link
Contributor

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
Copy link
Contributor

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)
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor

@askhade askhade left a 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

@askhade askhade closed this Jan 7, 2020
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.

None yet

3 participants